sub_per_box_encrypt

Function sub_per_box_encrypt 

Source
pub fn sub_per_box_encrypt(
    input: &[u8],
    key: u128,
    rounds: u32,
) -> Result<Vec<u8>, &'static str>
Expand description

Encrypts an array of bytes using the substitution-permutation network

§Arguments

  • input - The array of bytes to encrypt
  • key - The key to use for encryption
  • rounds - The number of rounds to use for encryption

§Returns

A Result containing the encrypted data on success, or an error message on failure.

§Errors

  • Input must not be empty - If the input array is empty
  • Number of rounds must be greater than 0 - If the number of rounds is less than 1
  • HMAC creation failed - If there is an error in creating the HMAC for the round function in the Key Derivation Function

§Example

use cryptographic_primitives::sub_per_box_encrypt;
 
let plaintext = b"Hello, world!";
let ciphertext = sub_per_box_encrypt(plaintext, 15, 3).unwrap();
 
assert_eq!(ciphertext, vec![88, 16, 91, 161, 233, 130, 28, 216, 159, 37, 150, 29, 125, 37, 247, 49]);