pub struct CocksPublicKey { /* private fields */ }Expand description
Public key for the Cocks primitive.
Implementations§
Source§impl CocksPublicKey
impl CocksPublicKey
Sourcepub fn max_plaintext_exclusive(&self) -> BigUint
pub fn max_plaintext_exclusive(&self) -> BigUint
Return a conservative public upper bound for byte-oriented plaintexts.
When p < q, the private prime q is strictly larger than
floor(sqrt(n)), so any message in [0, floor(sqrt(n))) will also be
in the range recovered by the private map c^pi mod q.
Sourcepub fn encrypt_raw(&self, message: &BigUint) -> BigUint
pub fn encrypt_raw(&self, message: &BigUint) -> BigUint
Encrypt the raw integer message.
Cocks uses the unusual public map c = m^n mod n, where the public
exponent is the modulus n itself.
Sourcepub fn encrypt(&self, message: &[u8]) -> Option<BigUint>
pub fn encrypt(&self, message: &[u8]) -> Option<BigUint>
Encrypt a byte string using the conservative public plaintext bound.
The Cocks private map only recovers integers modulo the private prime
q. This wrapper therefore accepts only messages strictly below
floor(sqrt(n)), which is a public bound guaranteed to stay below q
because the key generator enforces p < q.
Sourcepub fn encrypt_bytes(&self, message: &[u8]) -> Option<Vec<u8>>
pub fn encrypt_bytes(&self, message: &[u8]) -> Option<Vec<u8>>
Encrypt a byte string and return the ciphertext as a byte string.
The encoded ciphertext is the crate’s standard one-INTEGER DER
payload for non-RSA public-key values. That keeps the byte-oriented
helper unambiguous for this specific scheme without changing the
underlying arithmetic map.
Sourcepub fn to_key_blob(&self) -> Vec<u8> ⓘ
pub fn to_key_blob(&self) -> Vec<u8> ⓘ
Encode the public key in the crate-defined binary format.
Sourcepub fn from_key_blob(blob: &[u8]) -> Option<Self>
pub fn from_key_blob(blob: &[u8]) -> Option<Self>
Decode the public key from the crate-defined binary format.
Trait Implementations§
Source§impl Clone for CocksPublicKey
impl Clone for CocksPublicKey
Source§fn clone(&self) -> CocksPublicKey
fn clone(&self) -> CocksPublicKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CocksPublicKey
impl Debug for CocksPublicKey
Source§impl PartialEq for CocksPublicKey
impl PartialEq for CocksPublicKey
Source§fn eq(&self, other: &CocksPublicKey) -> bool
fn eq(&self, other: &CocksPublicKey) -> bool
self and other values to be equal, and is used by ==.