Message

Struct Message 

Source
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§

Source§

impl Message

Source

pub fn new(data: Vec<u8>) -> Message

Returns a new empty Message instance

Source

pub fn write_to_file(&self, filename: &str) -> Result<()>

Source

pub fn read_from_file(filename: &str) -> Result<Message, Box<dyn Error>>

Trait Implementations§

Source§

impl AesEncryptable for Message

Source§

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.data with the result of encryption.
  • Message.digest with the keyed hash of plaintext.
  • Message.sym_nonce with 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>

§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.data with the result of decryption.
  • Message.op_result with the result of verification against the keyed hash.
  • Message.sym_nonce is 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])

§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.data with the result of encryption.
  • Message.digest with the keyed hash of plaintext.
  • Message.sym_nonce with 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>

§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.data with the result of decryption.
  • Message.digest with 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 Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl KEMEncryptable for Message

Source§

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_ciphertext with the result of encryption using KEM public key 𝑉.
  • Message.digest with the keyed hash of the message using components derived from the encryption process.
  • Message.sym_nonce with 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>

§Key Encapsulation Mechanism (KEM) Decryption

Decrypts a Message using a KEM private key.

§Replaces:
  • Message.msg with the result of decryption.
  • Message.op_result with 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

Source§

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.data with result of encryption.
  • Message.t with keyed hash of plaintext.
  • Message.asym_nonce with 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>

§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.data with result of decryption.
  • Message.op_result with result of comparision of Message.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 CurvePoint encryption key.
  • d: u64: encryption security strength in bits. Can only be 224, 256, 384, or 512.
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Signable for Message

Source§

fn sign(&mut self, key: &KeyPair, d: SecParam)

§Schnorr Signatures

Signs a Message under passphrase pw.

§Algorithm:
  • s ← kmac_xof(pw, “”, 448, “K”); s ← 4s
  • k ← 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>

§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

Source§

fn sha3_encrypt(&mut self, pw: &[u8], d: SecParam)

§Symmetric Encryption

Encrypts a Message m symmetrically under passphrase pw.

§Replaces:
  • Message.data with result of encryption.
  • Message.t with keyed hash of plaintext.
  • Message.sym_nonce with 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 be
  • d: u64: requested security strength in bits. Supported bitstrengths are 224, 256, 384, or 512.
Source§

fn sha3_decrypt(&mut self, pw: &[u8]) -> Result<(), OperationError>

§Symmetric Decryption

Decrypts a Message (z, c, t) under passphrase pw.

§Replaces:
  • Message.data with result of decryption.
  • Message.op_result with result of comparision of Message.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

Source§

fn compute_sha3_hash(&mut self, d: SecParam)

§Message Digest

Computes SHA3-d hash of input. Does not consume input. Replaces Message.digest with result of operation.

§Arguments:
  • d: u64: requested security strength in bits. Supported bitstrengths are 224, 256, 384, or 512.
Source§

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.t with keyed hash of plaintext.
§Arguments:
  • pw: &mut Vec<u8>: symmetric encryption key, can be blank but shouldnt be
  • message: &mut Vec<u8>: message to encrypt
  • s: &mut str: domain seperation string
  • d: u64: requested security strength in bits. Supported bitstrengths are 224, 256, 384, or 512.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,