pub struct Message {
pub msg: Box<Vec<u8>>,
pub d: Option<SecParam>,
pub sym_nonce: Option<Vec<u8>>,
pub asym_nonce: Option<ExtendedPoint>,
pub digest: Vec<u8>,
pub sig: Option<Signature>,
pub kem_ciphertext: Option<Vec<u8>>,
}Expand description
Message struct for which cryptographic traits are defined.
Fields§
§msg: Box<Vec<u8>>Input message
d: Option<SecParam>The digest lengths in FIPS-approved hash functions
sym_nonce: Option<Vec<u8>>Nonce used in symmetric encryption
asym_nonce: Option<ExtendedPoint>Nonce used in asymmetric encryption
digest: Vec<u8>Hash value (also known as message digest)
sig: Option<Signature>Schnorr signatures on the input message
kem_ciphertext: Option<Vec<u8>>ML-KEM encrypted secret as a byte array
Implementations§
Trait Implementations§
Source§impl AesEncryptable for Message
impl AesEncryptable for Message
Source§fn aes_encrypt_cbc(&mut self, key: &[u8])
fn aes_encrypt_cbc(&mut self, key: &[u8])
§Symmetric Encryption using AES in CBC Mode
Encrypts a Message using the AES algorithm in CBC (Cipher Block Chaining) mode.
For more information refer to: NIST Special Publication 800-38A.
§Replaces:
Message.datawith the result of encryption.Message.digestwith the keyed hash of plaintext.Message.sym_noncewith the initialization vector (IV). SECURITY NOTE: ciphertext length == plaintext length
§Algorithm:
- iv ← Random(16)
- (ke || ka) ← kmac_xof(iv || key, “”, 512, “AES”)
- C1 = encrypt_block(P1 ⊕ IV)
- Cj = encrypt_block(Pj ⊕ Cj-1) for j = 2 … n Here:
- P: Represents plaintext blocks.
- C: Represents ciphertext blocks.
§Arguments:
key: &Vec<u8>: symmetric encryption key.
Source§fn aes_decrypt_cbc(&mut self, key: &[u8]) -> Result<(), OperationError>
fn aes_decrypt_cbc(&mut self, key: &[u8]) -> Result<(), OperationError>
§Symmetric Decryption using AES in CBC Mode
Decrypts a Message using the AES algorithm in CBC (Cipher Block Chaining) mode.
For more information refer to: NIST Special Publication 800-38A.
§Replaces:
Message.datawith the result of decryption.Message.op_resultwith the result of verification against the keyed hash.Message.sym_nonceis used as the initialization vector (IV). SECURITY NOTE: ciphertext length == plaintext length
§Algorithm:
- iv ← Symmetric nonce (IV)
- (ke || ka) ← kmac_xof(iv || key, “”, 512, “AES”)
- P1 = decrypt_block(C1) ⊕ IV
- Pj = decrypt_block(Cj) ⊕ Cj-1 for j = 2 … n Here:
- P: Represents plaintext blocks.
- C: Represents ciphertext blocks.
§Arguments:
key: &Vec<u8>: symmetric encryption key.
Source§fn aes_encrypt_ctr(&mut self, key: &[u8])
fn aes_encrypt_ctr(&mut self, key: &[u8])
§Symmetric Encryption using AES in CTR Mode
Encrypts a Message using the AES algorithm in CTR (Counter) mode.
For more information, refer to NIST Special Publication 800-38A.
§Replaces:
Message.datawith the result of encryption.Message.digestwith the keyed hash of plaintext.Message.sym_noncewith the initialization vector (IV). SECURITY NOTE: ciphertext length == plaintext length
§Algorithm:
- iv ← Random(12)
- CTR ← u32 counter starting at 0
- (ke || ka) ← kmac_xof(iv || key, “”, 512, “AES”)
- C1 = P1 ⊕ encrypt_block(IV || CTR1)
- Cj = Pj ⊕ encrypt_block(IV || CTRj) for j = 2 … n Here:
- P: Represents plaintext blocks.
- C: Represents ciphertext blocks.
§Arguments:
key: &[u8]: symmetric encryption key.
Source§fn aes_decrypt_ctr(&mut self, key: &[u8]) -> Result<(), OperationError>
fn aes_decrypt_ctr(&mut self, key: &[u8]) -> Result<(), OperationError>
§Symmetric Decryption using AES in CTR Mode
Decrypts a Message using the AES algorithm in CTR (Counter) mode.
For more information, refer to NIST Special Publication 800-38A.
§Replaces:
Message.datawith the result of decryption.Message.digestwith the keyed hash of plaintext. SECURITY NOTE: ciphertext length == plaintext length
§Algorithm:
- iv ← Message.sym_nonce
- CTR ← u32 counter starting at 0
- (ke || ka) ← kmac_xof(iv || key, “”, 512, “AES”)
- P1 = C1 ⊕ encrypt_block(IV || CTR1)
- Pj = Cj ⊕ encrypt_block(IV || CTRj) for j = 2 … n Here:
- P: Represents plaintext blocks.
- C: Represents ciphertext blocks.
§Arguments:
key: &[u8]: symmetric encryption key.
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl KEMEncryptable for Message
impl KEMEncryptable for Message
Source§fn kem_encrypt(
&mut self,
key: &KEMPublicKey,
d: SecParam,
) -> Result<(), OperationError>
fn kem_encrypt( &mut self, key: &KEMPublicKey, d: SecParam, ) -> Result<(), OperationError>
§Key Encapsulation Mechanism (KEM) Encryption
Encrypts a Message symmetrically under a KEM public key 𝑉. The KEM keys
are used to derive a shared secret which seeds the sponge, and is then
subsequently used for symmetric encryptions.
§Replaces:
Message.kem_ciphertextwith the result of encryption using KEM public key 𝑉.Message.digestwith the keyed hash of the message using components derived from the encryption process.Message.sym_noncewith random bytes 𝑧.
§Algorithm:
- Encrypt a secret using the KEM public key 𝑉 to generate shared secret.
- Generate a random nonce 𝑧
- (ke || ka) ← kmac_xof(𝑧 || secret, “”, 1024, “S”)
- 𝑐 ← kmac_xof(ke, “”, |m|, “SKE”) ⊕ m
- t ← kmac_xof(ka, m, 512, “SKA”)
§Arguments:
key: &KEMPublicKey: The public key 𝑉 used for encryption.d: SecParam: Security parameters defining the strength of cryptographic operations.
Source§fn kem_decrypt(&mut self, key: &KEMPrivateKey) -> Result<(), OperationError>
fn kem_decrypt(&mut self, key: &KEMPrivateKey) -> Result<(), OperationError>
§Key Encapsulation Mechanism (KEM) Decryption
Decrypts a Message using a KEM private key.
§Replaces:
Message.msgwith the result of decryption.Message.op_resultwith the result of the comparison of the stored and computed message digests.
§Algorithm:
- Retrieve the KEM ciphertext and decrypt it using the KEM private key to obtain the decrypted secret.
- Use the stored nonce 𝑧 and decrypted secret to derive two keys (ke and ka) using
kmac_xof. - m ← kmac_xof(ke, “”, |c|, “SKE”) ⊕ c
- t′ ← kmac_xof(ka, m, 512, “SKA”)
§Arguments:
key: &KEMPrivateKey: The private key used for decryption.
Source§impl KeyEncryptable for Message
impl KeyEncryptable for Message
Source§fn key_encrypt(&mut self, pub_key: &ExtendedPoint, d: SecParam)
fn key_encrypt(&mut self, pub_key: &ExtendedPoint, d: SecParam)
§Asymmetric Encryption
Encrypts a Message in place under the (Schnorr/ECDHIES) public key 𝑉.
Operates under Schnorr/ECDHIES principle in that shared symmetric key is
exchanged with recipient. SECURITY NOTE: ciphertext length == plaintext length
§Replaces:
Message.datawith result of encryption.Message.twith keyed hash of plaintext.Message.asym_noncewith z, as defined below.
§Algorithm:
- k ← Random(448); k ← 4k
- W ← kV; 𝑍 ← k*𝑮
- (ke || ka) ← kmac_xof(W x , “”, 448 * 2, “P”)
- c ← kmac_xof(ke, “”, |m|, “PKE”) ⊕ m
- t ← kmac_xof(ka, m, 448, “PKA”)
§Arguments:
- pub_key:
ExtendedPoint: X coordinate of public key 𝑉 - d: u64: Requested security strength in bits. Can only be 224, 256, 384, or 512.
Source§fn key_decrypt(&mut self, pw: &[u8]) -> Result<(), OperationError>
fn key_decrypt(&mut self, pw: &[u8]) -> Result<(), OperationError>
§Asymmetric Decryption
Decrypts a Message in place under private key.
Operates under Schnorr/ECDHIES principle in that shared symmetric key is
derived from 𝑍.
§Replaces:
Message.datawith result of decryption.Message.op_resultwith result of comparision ofMessage.t== keyed hash of decryption.
§Algorithm:
- s ← KMACXOF256(pw, “”, 448, “K”); s ← 4s
- W ← sZ
- (ke || ka) ← KMACXOF256(W x , “”, 448 * 2, “P”)
- m ← KMACXOF256(ke, “”, |c|, “PKE”) ⊕ c
- t’ ← KMACXOF256(ka, m, 448, “PKA”)
§Arguments:
- pw: &u8: password used to generate
CurvePointencryption key. - d: u64: encryption security strength in bits. Can only be 224, 256, 384, or 512.
Source§impl Signable for Message
impl Signable for Message
Source§fn sign(&mut self, key: &KeyPair, d: SecParam)
fn sign(&mut self, key: &KeyPair, d: SecParam)
§Schnorr Signatures
Signs a Message under passphrase pw.
§Algorithm:
s← kmac_xof(pw, “”, 448, “K”); s ← 4sk← kmac_xof(s, m, 448, “N”); k ← 4k𝑈← k*𝑮;ℎ← kmac_xof(𝑈ₓ , m, 448, “T”); 𝑍 ← (𝑘 – ℎ𝑠) mod r
§Arguments:
- key: &
KeyPair, : reference to KeyPair. - d: u64: encryption security strength in bits. Can only be 224, 256, 384, or 512.
Source§fn verify(&mut self, pub_key: &ExtendedPoint) -> Result<(), OperationError>
fn verify(&mut self, pub_key: &ExtendedPoint) -> Result<(), OperationError>
§Signature Verification
Verifies a Signature (h, 𝑍) for a byte array m under the (Schnorr/
ECDHIES) public key 𝑉.
§Algorithm:
- 𝑈 ← 𝑍*𝑮 + h𝑉
§Arguments:
- sig: &
Signature: Pointer to a signature object (h, 𝑍) - pubKey: CurvePoint key 𝑉 used to sign message m
- message: Vec
of message to verify
§Assumes:
- Some(key.pub_key)
- Some(
Message.sig)
Source§impl SpongeEncryptable for Message
impl SpongeEncryptable for Message
Source§fn sha3_encrypt(&mut self, pw: &[u8], d: SecParam)
fn sha3_encrypt(&mut self, pw: &[u8], d: SecParam)
§Symmetric Encryption
Encrypts a Message m symmetrically under passphrase pw.
§Replaces:
Message.datawith result of encryption.Message.twith keyed hash of plaintext.Message.sym_noncewith z, as defined below. SECURITY NOTE: ciphertext length == plaintext length
§Algorithm:
- z ← Random(512)
- (ke || ka) ← kmac_xof(z || pw, “”, 1024, “S”)
- c ← kmac_xof(ke, “”, |m|, “SKE”) ⊕ m
- t ← kmac_xof(ka, m, 512, “SKA”)
§Arguments:
pw: &[u8]: symmetric encryption key, can be blank but shouldnt bed: u64: requested security strength in bits. Supported bitstrengths are 224, 256, 384, or 512.
Source§fn sha3_decrypt(&mut self, pw: &[u8]) -> Result<(), OperationError>
fn sha3_decrypt(&mut self, pw: &[u8]) -> Result<(), OperationError>
§Symmetric Decryption
Decrypts a Message (z, c, t) under passphrase pw.
§Replaces:
Message.datawith result of decryption.Message.op_resultwith result of comparision ofMessage.t== keyed hash of decryption.
§Algorithm:
- (ke || ka) ← kmac_xof(z || pw, “”, 1024, “S”)
- m ← kmac_xof(ke, “”, |c|, “SKE”) ⊕ c
- t’ ← kmac_xof(ka, m, 512, “SKA”)
§Arguments:
pw: &[u8]: decryption password, can be blank
Source§impl SpongeHashable for Message
impl SpongeHashable for Message
Source§fn compute_sha3_hash(&mut self, d: SecParam)
fn compute_sha3_hash(&mut self, d: SecParam)
Source§fn compute_tagged_hash(&mut self, pw: &[u8], s: &str, d: SecParam)
fn compute_tagged_hash(&mut self, pw: &[u8], s: &str, d: SecParam)
§Tagged Hash
Computes an authentication tag t of a byte array m under passphrase pw.
§Replaces:
Message.twith keyed hash of plaintext.
§Arguments:
pw: &mut Vec<u8>: symmetric encryption key, can be blank but shouldnt bemessage: &mut Vec<u8>: message to encrypts: &mut str: domain seperation stringd: u64: requested security strength in bits. Supported bitstrengths are 224, 256, 384, or 512.
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more