From f2dd3093e4f3e22b167f82b96cb9ee73c065faf2 Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:17:25 -0400 Subject: [PATCH 01/12] Add kupyna as a new member --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index e94b026b..03c663d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "groestl", "jh", "k12", + "kupyna", "md2", "md4", "md5", From b09a463539b486c3239ce75f4234e25b0be57450 Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:22:54 -0400 Subject: [PATCH 02/12] add a basic first-past cargo based on ascon's --- kupyna/Cargo.toml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 kupyna/Cargo.toml diff --git a/kupyna/Cargo.toml b/kupyna/Cargo.toml new file mode 100644 index 00000000..550dd013 --- /dev/null +++ b/kupyna/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "kupyna" +version = "0.1.0" +description = "Hashing algorithm for Kupyna, 8 to 512 length" +authors = [ + "Joshua Koudys ", + "RustCrypto Developers", +] +license = "MIT" +readme = "README.md" +edition = "2021" +documentation = "https://docs.rs/kupyna" +repository = "https://github.com/RustCrypto/hashes" +keywords = ["crypto", "hash", "kupyno"] +categories = ["cryptography", "no-std"] +rust-version = "1.71" + +[dependencies] +digest = { version = "=0.11.0-pre.8", default-features = false, features = ["core-api"] } +kupyna = { version = "0.1.0", default-features = false } + +[dev-dependencies] + +[features] +default = ["std"] +std = ["digest/std"] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] From 206813dabe18907efa9cdb3c1b0735b8ac64b741 Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:23:31 -0400 Subject: [PATCH 03/12] Add readme --- kupyna/LICENSE | 21 ++++++++++++ kupyna/README.md | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 kupyna/LICENSE create mode 100644 kupyna/README.md diff --git a/kupyna/LICENSE b/kupyna/LICENSE new file mode 100644 index 00000000..e4265a91 --- /dev/null +++ b/kupyna/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Joshua Koudys + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/kupyna/README.md b/kupyna/README.md new file mode 100644 index 00000000..52f2f292 --- /dev/null +++ b/kupyna/README.md @@ -0,0 +1,88 @@ +# Kupyna Hash Function Implementation in Rust + +## Overview + +The Kupyna hash function is a cryptographic hash developed in Ukraine, designed for high security and efficiency. This implementation supports generating hash codes of various lengths. + +## Author + +Joshua Koudys +Email: [josh@qaribou.com](mailto:josh@qaribou.com) + +## Summary + +Kupyna is a hash function standardized in Ukraine as DSTU 7564:2014. It is designed to provide a high level of security with a focus on robustness against various cryptographic attacks. The function supports different hash lengths, providing flexibility in usage depending on security requirements. + +### Key Features of Kupyna: +- **High Security:** Resistant to known cryptographic attacks. +- **Efficiency:** Optimized for performance. +- **Flexibility:** Supports variable hash output lengths. + +## Implementation Details + +### Functions + +- **`pad_message`**: Pads the input message according to the Kupyna padding scheme. +- **`divide_into_blocks`**: Divides the padded message into fixed-size blocks. +- **`t_xor_l`**: Placeholder for the T⊕l transformation (to be implemented). +- **`t_plus_l`**: Placeholder for the T+l transformation (to be implemented). +- **`r_l_n`**: Truncates the block to the desired number of bits. +- **`kupyna_hash`**: Main function to compute the Kupyna hash of a given message. +- **`xor_bytes`**: Utility function to perform bitwise XOR on two byte slices. + +### Usage + +To compute the hash of a message using this implementation, you can call the `kupyna_hash` function with your message and desired hash length. Below is a basic usage example: + +```rust +fn main() { + let message = b"hello world"; + let hash_code_length = 256; + + let hash = kupyna_hash(message, hash_code_length); + + println!("Hash: {:?}", hash); +} +``` + +### Running Tests + +This implementation includes several unit tests to verify the correctness of the functions. You can run these tests using the following command: + +```sh +cargo test +``` + +## Getting Started + +I'm working on getting this read to go into a crate, or possibly merge it into an existing set of hashing functions. In the meantime, feel free to work with it directly. + +### Installation + +Clone the repository: +```sh +git clone https://github.com/jkoudys/kupyna.git +cd kupyna-rust +``` + +### Building the Project + +Build the project using Cargo: +```sh +cargo build +``` + +### Running the Example + +Run the example provided in the `main` function: +```sh +cargo run +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. + +## Contact + +For any questions or suggestions, feel free to contact me at [josh@qaribou.com](mailto:josh@qaribou.com). Pull requests welcome! From 88efb066f2d873f4f76f4b8caf634c461f263627 Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:24:50 -0400 Subject: [PATCH 04/12] update usage in readme --- kupyna/README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/kupyna/README.md b/kupyna/README.md index 52f2f292..e98db3d8 100644 --- a/kupyna/README.md +++ b/kupyna/README.md @@ -20,15 +20,10 @@ Kupyna is a hash function standardized in Ukraine as DSTU 7564:2014. It is desig ## Implementation Details -### Functions - -- **`pad_message`**: Pads the input message according to the Kupyna padding scheme. -- **`divide_into_blocks`**: Divides the padded message into fixed-size blocks. -- **`t_xor_l`**: Placeholder for the T⊕l transformation (to be implemented). -- **`t_plus_l`**: Placeholder for the T+l transformation (to be implemented). -- **`r_l_n`**: Truncates the block to the desired number of bits. -- **`kupyna_hash`**: Main function to compute the Kupyna hash of a given message. -- **`xor_bytes`**: Utility function to perform bitwise XOR on two byte slices. +### TODO +Implement the excellent digest::Digest trait. +Work on streams of arbitrary size, so long as they have a known size by the end of them. Right +now it's just running on byte slices because it's easy. ### Usage @@ -37,9 +32,8 @@ To compute the hash of a message using this implementation, you can call the `ku ```rust fn main() { let message = b"hello world"; - let hash_code_length = 256; - let hash = kupyna_hash(message, hash_code_length); + let hash = kupyna::hash(message); println!("Hash: {:?}", hash); } From ba7f58f959415ff3ebff4625c794b25eee7d1352 Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:25:53 -0400 Subject: [PATCH 05/12] First pass, pushing up of @AnarchistHoneybun's matrix XORing code --- kupyna/src/lib.rs | 101 +++++++ kupyna/src/main.rs | 10 + kupyna/src/sub_units/mod.rs | 43 +++ kupyna/src/sub_units/t_xor_plus/mod.rs | 162 +++++++++++ kupyna/src/sub_units/t_xor_plus/tables.rs | 97 +++++++ kupyna/src/sub_units/t_xor_plus/tests/mod.rs | 2 + .../tests/test_individual_layers.rs | 146 ++++++++++ .../t_xor_plus/tests/test_xor_plus.rs | 63 ++++ kupyna/src/tests/blocking_tests.rs | 218 ++++++++++++++ kupyna/src/tests/hashing_tests.rs | 207 ++++++++++++++ kupyna/src/tests/mod.rs | 3 + kupyna/src/tests/padding_tests.rs | 268 ++++++++++++++++++ 12 files changed, 1320 insertions(+) create mode 100644 kupyna/src/lib.rs create mode 100644 kupyna/src/main.rs create mode 100644 kupyna/src/sub_units/mod.rs create mode 100644 kupyna/src/sub_units/t_xor_plus/mod.rs create mode 100644 kupyna/src/sub_units/t_xor_plus/tables.rs create mode 100644 kupyna/src/sub_units/t_xor_plus/tests/mod.rs create mode 100644 kupyna/src/sub_units/t_xor_plus/tests/test_individual_layers.rs create mode 100644 kupyna/src/sub_units/t_xor_plus/tests/test_xor_plus.rs create mode 100644 kupyna/src/tests/blocking_tests.rs create mode 100644 kupyna/src/tests/hashing_tests.rs create mode 100644 kupyna/src/tests/mod.rs create mode 100644 kupyna/src/tests/padding_tests.rs diff --git a/kupyna/src/lib.rs b/kupyna/src/lib.rs new file mode 100644 index 00000000..da4df891 --- /dev/null +++ b/kupyna/src/lib.rs @@ -0,0 +1,101 @@ +#[cfg(test)] +mod tests; +mod sub_units; + +const STATE_SIZE: usize = 1024; +const HASH_SIZE: usize = 512; + +const MAX_MESSAGE_LENGTH: usize = 18446744073709551615; + +fn pad_message(message: &[u8], msg_len_bits: usize, state_size: usize) -> Vec { + let round_msg_len = message.len() * 8; + let d = + ((-((round_msg_len + 97) as isize) % (state_size as isize)) + state_size as isize) as usize; + + // Calculate the length of padding to be added + let pad_len = d / 8; + + // We set the padded message size upfront to reduce allocations + let padded_len = (msg_len_bits + 7) / 8 + pad_len + 13; + let mut padded_message = vec![0x00; padded_len]; + + // Copy n bits from the input message + let full_bytes = msg_len_bits / 8; + let remaining_bits = msg_len_bits % 8; + + padded_message[..full_bytes].copy_from_slice(&message[..full_bytes]); + + if remaining_bits > 0 { + let last_byte = message[full_bytes]; + padded_message[full_bytes] = last_byte & ((1 << remaining_bits) - 1); + } + + // Set the n+1'th bit to high + padded_message[msg_len_bits / 8] |= 1 << (7 - (msg_len_bits % 8)); + + // Convert the length to a byte array and copy it into the padded message + let n_bytes = (msg_len_bits as u128).to_le_bytes(); // message length in little-endian + padded_message[padded_len - 12..].copy_from_slice(&n_bytes[0..12]); + + padded_message +} + +fn divide_into_blocks(padded_message: &[u8], state_size: usize) -> Vec<&[u8]> { + padded_message.chunks(state_size / 8).collect() +} + +fn truncate(block: &[u8], n: usize) -> Vec { + let bytes_to_keep = n / 8; + let start_index = if block.len() > bytes_to_keep { + block.len() - bytes_to_keep + } else { + 0 + }; + block[start_index..].to_vec() +} + +pub fn hash(message: Vec, length: Option) -> Result, &'static str> { + let mut message = message; + let message_length: usize; + if let Some(len) = length { + if len > MAX_MESSAGE_LENGTH { + return Err("Message is too long"); + } + if len > message.len() * 8 { + return Err("Message length is less than the provided length"); + } + + let mut trimmed_message = message[..(len/8)].to_vec(); + + if len % 8 != 0 { + let extra_byte = message[len/8]; + let extra_bits = len % 8; + let mask = 0xFF << (8 - extra_bits); + trimmed_message.push(extra_byte & mask); + } + + message = trimmed_message; + message_length = len; + + } else { + if message.len() * 8 > MAX_MESSAGE_LENGTH { + return Err("Message is too long"); + } + message_length = message.len() * 8; + } + + let padded_message = pad_message(&message, message_length, STATE_SIZE); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE); + + let mut init_vector: Vec = vec![0; STATE_SIZE/8]; + init_vector[0] = 0x80; // set the first bit of this init vector to high + + + let fin_vector = sub_units::plant(blocks, &init_vector); + + let hash = truncate(&fin_vector, HASH_SIZE); + + Ok(hash) +} + diff --git a/kupyna/src/main.rs b/kupyna/src/main.rs new file mode 100644 index 00000000..cf220702 --- /dev/null +++ b/kupyna/src/main.rs @@ -0,0 +1,10 @@ +use kupyna_512; + +fn main() { + let message = b"Hello, World!".to_vec(); + let _message_length = 0; + + let hash_code = kupyna_512::hash(message, None).unwrap(); + + println!("{:02X?}", hash_code); +} \ No newline at end of file diff --git a/kupyna/src/sub_units/mod.rs b/kupyna/src/sub_units/mod.rs new file mode 100644 index 00000000..beeae736 --- /dev/null +++ b/kupyna/src/sub_units/mod.rs @@ -0,0 +1,43 @@ +mod t_xor_plus; + +use t_xor_plus::{t_xor_l, t_plus_l}; + +const ROUNDS: usize = 14; + +fn xor_bytes(a: &[u8], b: &[u8]) -> Vec { + a.iter().zip(b.iter()).map(|(x, y)| x ^ y).collect() +} + +fn silo(message_block: &[u8], prev_vector: &[u8]) -> Vec { + + let m_xor_p = xor_bytes(message_block, prev_vector); + + let t_xor_mp = t_xor_l(&m_xor_p, ROUNDS); + + let t_plus_m = t_plus_l(&message_block, ROUNDS); + + let return_vector = xor_bytes(&(xor_bytes(&t_xor_mp, &t_plus_m)), prev_vector); + + return_vector + +} + +pub(crate) fn plant(message_blocks: Vec<&[u8]>, init_vector: &[u8]) -> Vec { + + let mut last_vector = init_vector.to_vec(); + + for block in message_blocks { + last_vector = silo(block, &last_vector); + } + + let last_vector = finalize(&last_vector); + + last_vector +} + +fn finalize(ult_processed_block: &[u8]) -> Vec { + let t_xor_ult_processed_block = t_xor_l(ult_processed_block, ROUNDS); + let final_state = xor_bytes(ult_processed_block, &t_xor_ult_processed_block); + final_state +} + diff --git a/kupyna/src/sub_units/t_xor_plus/mod.rs b/kupyna/src/sub_units/t_xor_plus/mod.rs new file mode 100644 index 00000000..bf385edf --- /dev/null +++ b/kupyna/src/sub_units/t_xor_plus/mod.rs @@ -0,0 +1,162 @@ +#[cfg(test)] +mod tests; + +mod tables; + +const ROWS: usize = 16; +const COLS: usize = 8; // For 512-bit state, adjust if needed + +const BITS_IN_BYTE: u8 = 8; +const REDUCTION_POLYNOMIAL: u16 = 0x011d; + +type Matrix = [[u8; COLS]; ROWS]; + +use tables::{MDS_MATRIX, SBOXES}; + + +pub(crate) fn block_to_matrix(block: &[u8]) -> Matrix { + let mut matrix = [[0u8; COLS]; ROWS]; + for i in 0..ROWS { + for j in 0..COLS { + matrix[i][j] = block[i * COLS + j]; + } + } + matrix +} + +fn matrix_to_block(matrix: Matrix) -> Vec { + let mut block = vec![0u8; ROWS * COLS]; + for i in 0..ROWS { + for j in 0..COLS { + block[i * COLS + j] = matrix[i][j]; + } + } + block +} + +pub(crate) fn add_constant_xor(mut state: Matrix, round: usize) -> Matrix { + for j in 0..ROWS { + let constant = ((j * 0x10) ^ round) as u8; + state[j][0] ^= constant; + } + state +} + +pub(crate) fn add_constant_plus(mut state: Matrix, round: usize) -> Matrix { + let state_ptr = state.as_mut_ptr() as *mut u64; + + for j in 0..ROWS { + // dbg!("{}",j); + unsafe { + *state_ptr.add(j) = state_ptr.add(j).read().wrapping_add( + 0x00F0F0F0F0F0F0F3u64 ^ (((((ROWS - j - 1) * 0x10) ^ round) as u64) << 56), + ); + } + } + + state +} + +pub(crate) fn s_box_layer(mut state: Matrix) -> Matrix { + for i in 0..COLS { + for j in 0..ROWS { + state[j][i] = SBOXES[i % 4][state[j][i] as usize]; + } + } + state +} + +pub(crate) fn rotate_rows(mut state: Matrix) -> Matrix { + let mut temp = [0u8; ROWS]; + let mut shift: i32 = -1; + for i in 0..COLS { + if (i == COLS - 1) && true { + shift = 11; + } else { + shift += 1; + } + for col in 0..ROWS { + temp[(col + shift as usize) % ROWS] = state[col][i]; + } + for col in 0..ROWS { + state[col][i] = temp[col]; + } + } + state +} + +fn multiply_gf(mut x: u8, mut y: u8) -> u8 { + let mut r = 0u8; + + for _ in 0..BITS_IN_BYTE { + if y & 1 == 1 { + r ^= x; + } + let hbit = (x & 0x80) >> 7; + x <<= 1; + if hbit == 1 { + x ^= REDUCTION_POLYNOMIAL as u8; + } + y >>= 1; + } + + r +} + +pub(crate) fn mix_columns(state: Matrix) -> Matrix { + let mut result = [[0u8; COLS]; ROWS]; + + for col in 0..ROWS { + for row in (0..COLS).rev() { + let mut product = 0u8; + for b in (0..COLS).rev() { + product ^= multiply_gf(state[col][b], MDS_MATRIX[row][b]); + } + result[col][row] = product; + } + } + + result +} + +/// Placeholder for the T⊕l transformation. +/// +/// # Arguments +/// +/// * `block` - A byte slice representing the block to be transformed. +/// * `_rounds` - The number of rounds to perform. +/// +/// # Returns +/// +/// * A `Vec` containing the transformed block. +pub fn t_xor_l(block: &[u8], rounds: usize) -> Vec { + let mut state = block_to_matrix(block); + for nu in 0..rounds { + state = add_constant_xor(state, nu); + state = s_box_layer(state); + state = rotate_rows(state); + state = mix_columns(state); + } + matrix_to_block(state) +} + +/// Placeholder for the T+l transformation. +/// +/// # Arguments +/// +/// * `block` - A byte slice representing the block to be transformed. +/// * `_rounds` - The number of rounds to perform. +/// +/// # Returns +/// +/// * A `Vec` containing the transformed block. +pub fn t_plus_l(block: &[u8], rounds: usize) -> Vec { + let mut state = block_to_matrix(block); + for nu in 0..rounds { + state = add_constant_plus(state, nu); + state = s_box_layer(state); + state = rotate_rows(state); + state = mix_columns(state); + } + matrix_to_block(state) +} \ No newline at end of file diff --git a/kupyna/src/sub_units/t_xor_plus/tables.rs b/kupyna/src/sub_units/t_xor_plus/tables.rs new file mode 100644 index 00000000..75dfd9db --- /dev/null +++ b/kupyna/src/sub_units/t_xor_plus/tables.rs @@ -0,0 +1,97 @@ +pub const MDS_MATRIX: [[u8; 8]; 8] = [ + [0x01, 0x01, 0x05, 0x01, 0x08, 0x06, 0x07, 0x04], + [0x04, 0x01, 0x01, 0x05, 0x01, 0x08, 0x06, 0x07], + [0x07, 0x04, 0x01, 0x01, 0x05, 0x01, 0x08, 0x06], + [0x06, 0x07, 0x04, 0x01, 0x01, 0x05, 0x01, 0x08], + [0x08, 0x06, 0x07, 0x04, 0x01, 0x01, 0x05, 0x01], + [0x01, 0x08, 0x06, 0x07, 0x04, 0x01, 0x01, 0x05], + [0x05, 0x01, 0x08, 0x06, 0x07, 0x04, 0x01, 0x01], + [0x01, 0x05, 0x01, 0x08, 0x06, 0x07, 0x04, 0x01], +]; + +pub const SBOXES: [[u8; 256]; 4] = [ + // The first subarray goes here + [ + 0xa8, 0x43, 0x5f, 0x06, 0x6b, 0x75, 0x6c, 0x59, 0x71, 0xdf, 0x87, 0x95, 0x17, 0xf0, 0xd8, + 0x09, 0x6d, 0xf3, 0x1d, 0xcb, 0xc9, 0x4d, 0x2c, 0xaf, 0x79, 0xe0, 0x97, 0xfd, 0x6f, 0x4b, + 0x45, 0x39, 0x3e, 0xdd, 0xa3, 0x4f, 0xb4, 0xb6, 0x9a, 0x0e, 0x1f, 0xbf, 0x15, 0xe1, 0x49, + 0xd2, 0x93, 0xc6, 0x92, 0x72, 0x9e, 0x61, 0xd1, 0x63, 0xfa, 0xee, 0xf4, 0x19, 0xd5, 0xad, + 0x58, 0xa4, 0xbb, 0xa1, 0xdc, 0xf2, 0x83, 0x37, 0x42, 0xe4, 0x7a, 0x32, 0x9c, 0xcc, 0xab, + 0x4a, 0x8f, 0x6e, 0x04, 0x27, 0x2e, 0xe7, 0xe2, 0x5a, 0x96, 0x16, 0x23, 0x2b, 0xc2, 0x65, + 0x66, 0x0f, 0xbc, 0xa9, 0x47, 0x41, 0x34, 0x48, 0xfc, 0xb7, 0x6a, 0x88, 0xa5, 0x53, 0x86, + 0xf9, 0x5b, 0xdb, 0x38, 0x7b, 0xc3, 0x1e, 0x22, 0x33, 0x24, 0x28, 0x36, 0xc7, 0xb2, 0x3b, + 0x8e, 0x77, 0xba, 0xf5, 0x14, 0x9f, 0x08, 0x55, 0x9b, 0x4c, 0xfe, 0x60, 0x5c, 0xda, 0x18, + 0x46, 0xcd, 0x7d, 0x21, 0xb0, 0x3f, 0x1b, 0x89, 0xff, 0xeb, 0x84, 0x69, 0x3a, 0x9d, 0xd7, + 0xd3, 0x70, 0x67, 0x40, 0xb5, 0xde, 0x5d, 0x30, 0x91, 0xb1, 0x78, 0x11, 0x01, 0xe5, 0x00, + 0x68, 0x98, 0xa0, 0xc5, 0x02, 0xa6, 0x74, 0x2d, 0x0b, 0xa2, 0x76, 0xb3, 0xbe, 0xce, 0xbd, + 0xae, 0xe9, 0x8a, 0x31, 0x1c, 0xec, 0xf1, 0x99, 0x94, 0xaa, 0xf6, 0x26, 0x2f, 0xef, 0xe8, + 0x8c, 0x35, 0x03, 0xd4, 0x7f, 0xfb, 0x05, 0xc1, 0x5e, 0x90, 0x20, 0x3d, 0x82, 0xf7, 0xea, + 0x0a, 0x0d, 0x7e, 0xf8, 0x50, 0x1a, 0xc4, 0x07, 0x57, 0xb8, 0x3c, 0x62, 0xe3, 0xc8, 0xac, + 0x52, 0x64, 0x10, 0xd0, 0xd9, 0x13, 0x0c, 0x12, 0x29, 0x51, 0xb9, 0xcf, 0xd6, 0x73, 0x8d, + 0x81, 0x54, 0xc0, 0xed, 0x4e, 0x44, 0xa7, 0x2a, 0x85, 0x25, 0xe6, 0xca, 0x7c, 0x8b, 0x56, + 0x80, + ], + // The second subarray goes here + [ + 0xce, 0xbb, 0xeb, 0x92, 0xea, 0xcb, 0x13, 0xc1, 0xe9, 0x3a, 0xd6, 0xb2, 0xd2, 0x90, 0x17, + 0xf8, 0x42, 0x15, 0x56, 0xb4, 0x65, 0x1c, 0x88, 0x43, 0xc5, 0x5c, 0x36, 0xba, 0xf5, 0x57, + 0x67, 0x8d, 0x31, 0xf6, 0x64, 0x58, 0x9e, 0xf4, 0x22, 0xaa, 0x75, 0x0f, 0x02, 0xb1, 0xdf, + 0x6d, 0x73, 0x4d, 0x7c, 0x26, 0x2e, 0xf7, 0x08, 0x5d, 0x44, 0x3e, 0x9f, 0x14, 0xc8, 0xae, + 0x54, 0x10, 0xd8, 0xbc, 0x1a, 0x6b, 0x69, 0xf3, 0xbd, 0x33, 0xab, 0xfa, 0xd1, 0x9b, 0x68, + 0x4e, 0x16, 0x95, 0x91, 0xee, 0x4c, 0x63, 0x8e, 0x5b, 0xcc, 0x3c, 0x19, 0xa1, 0x81, 0x49, + 0x7b, 0xd9, 0x6f, 0x37, 0x60, 0xca, 0xe7, 0x2b, 0x48, 0xfd, 0x96, 0x45, 0xfc, 0x41, 0x12, + 0x0d, 0x79, 0xe5, 0x89, 0x8c, 0xe3, 0x20, 0x30, 0xdc, 0xb7, 0x6c, 0x4a, 0xb5, 0x3f, 0x97, + 0xd4, 0x62, 0x2d, 0x06, 0xa4, 0xa5, 0x83, 0x5f, 0x2a, 0xda, 0xc9, 0x00, 0x7e, 0xa2, 0x55, + 0xbf, 0x11, 0xd5, 0x9c, 0xcf, 0x0e, 0x0a, 0x3d, 0x51, 0x7d, 0x93, 0x1b, 0xfe, 0xc4, 0x47, + 0x09, 0x86, 0x0b, 0x8f, 0x9d, 0x6a, 0x07, 0xb9, 0xb0, 0x98, 0x18, 0x32, 0x71, 0x4b, 0xef, + 0x3b, 0x70, 0xa0, 0xe4, 0x40, 0xff, 0xc3, 0xa9, 0xe6, 0x78, 0xf9, 0x8b, 0x46, 0x80, 0x1e, + 0x38, 0xe1, 0xb8, 0xa8, 0xe0, 0x0c, 0x23, 0x76, 0x1d, 0x25, 0x24, 0x05, 0xf1, 0x6e, 0x94, + 0x28, 0x9a, 0x84, 0xe8, 0xa3, 0x4f, 0x77, 0xd3, 0x85, 0xe2, 0x52, 0xf2, 0x82, 0x50, 0x7a, + 0x2f, 0x74, 0x53, 0xb3, 0x61, 0xaf, 0x39, 0x35, 0xde, 0xcd, 0x1f, 0x99, 0xac, 0xad, 0x72, + 0x2c, 0xdd, 0xd0, 0x87, 0xbe, 0x5e, 0xa6, 0xec, 0x04, 0xc6, 0x03, 0x34, 0xfb, 0xdb, 0x59, + 0xb6, 0xc2, 0x01, 0xf0, 0x5a, 0xed, 0xa7, 0x66, 0x21, 0x7f, 0x8a, 0x27, 0xc7, 0xc0, 0x29, + 0xd7, + ], + // The third subarray goes here + [ + 0x93, 0xd9, 0x9a, 0xb5, 0x98, 0x22, 0x45, 0xfc, 0xba, 0x6a, 0xdf, 0x02, 0x9f, 0xdc, 0x51, + 0x59, 0x4a, 0x17, 0x2b, 0xc2, 0x94, 0xf4, 0xbb, 0xa3, 0x62, 0xe4, 0x71, 0xd4, 0xcd, 0x70, + 0x16, 0xe1, 0x49, 0x3c, 0xc0, 0xd8, 0x5c, 0x9b, 0xad, 0x85, 0x53, 0xa1, 0x7a, 0xc8, 0x2d, + 0xe0, 0xd1, 0x72, 0xa6, 0x2c, 0xc4, 0xe3, 0x76, 0x78, 0xb7, 0xb4, 0x09, 0x3b, 0x0e, 0x41, + 0x4c, 0xde, 0xb2, 0x90, 0x25, 0xa5, 0xd7, 0x03, 0x11, 0x00, 0xc3, 0x2e, 0x92, 0xef, 0x4e, + 0x12, 0x9d, 0x7d, 0xcb, 0x35, 0x10, 0xd5, 0x4f, 0x9e, 0x4d, 0xa9, 0x55, 0xc6, 0xd0, 0x7b, + 0x18, 0x97, 0xd3, 0x36, 0xe6, 0x48, 0x56, 0x81, 0x8f, 0x77, 0xcc, 0x9c, 0xb9, 0xe2, 0xac, + 0xb8, 0x2f, 0x15, 0xa4, 0x7c, 0xda, 0x38, 0x1e, 0x0b, 0x05, 0xd6, 0x14, 0x6e, 0x6c, 0x7e, + 0x66, 0xfd, 0xb1, 0xe5, 0x60, 0xaf, 0x5e, 0x33, 0x87, 0xc9, 0xf0, 0x5d, 0x6d, 0x3f, 0x88, + 0x8d, 0xc7, 0xf7, 0x1d, 0xe9, 0xec, 0xed, 0x80, 0x29, 0x27, 0xcf, 0x99, 0xa8, 0x50, 0x0f, + 0x37, 0x24, 0x28, 0x30, 0x95, 0xd2, 0x3e, 0x5b, 0x40, 0x83, 0xb3, 0x69, 0x57, 0x1f, 0x07, + 0x1c, 0x8a, 0xbc, 0x20, 0xeb, 0xce, 0x8e, 0xab, 0xee, 0x31, 0xa2, 0x73, 0xf9, 0xca, 0x3a, + 0x1a, 0xfb, 0x0d, 0xc1, 0xfe, 0xfa, 0xf2, 0x6f, 0xbd, 0x96, 0xdd, 0x43, 0x52, 0xb6, 0x08, + 0xf3, 0xae, 0xbe, 0x19, 0x89, 0x32, 0x26, 0xb0, 0xea, 0x4b, 0x64, 0x84, 0x82, 0x6b, 0xf5, + 0x79, 0xbf, 0x01, 0x5f, 0x75, 0x63, 0x1b, 0x23, 0x3d, 0x68, 0x2a, 0x65, 0xe8, 0x91, 0xf6, + 0xff, 0x13, 0x58, 0xf1, 0x47, 0x0a, 0x7f, 0xc5, 0xa7, 0xe7, 0x61, 0x5a, 0x06, 0x46, 0x44, + 0x42, 0x04, 0xa0, 0xdb, 0x39, 0x86, 0x54, 0xaa, 0x8c, 0x34, 0x21, 0x8b, 0xf8, 0x0c, 0x74, + 0x67, + ], + // The fourth subarray goes here + [ + 0x68, 0x8d, 0xca, 0x4d, 0x73, 0x4b, 0x4e, 0x2a, 0xd4, 0x52, 0x26, 0xb3, 0x54, 0x1e, 0x19, + 0x1f, 0x22, 0x03, 0x46, 0x3d, 0x2d, 0x4a, 0x53, 0x83, 0x13, 0x8a, 0xb7, 0xd5, 0x25, 0x79, + 0xf5, 0xbd, 0x58, 0x2f, 0x0d, 0x02, 0xed, 0x51, 0x9e, 0x11, 0xf2, 0x3e, 0x55, 0x5e, 0xd1, + 0x16, 0x3c, 0x66, 0x70, 0x5d, 0xf3, 0x45, 0x40, 0xcc, 0xe8, 0x94, 0x56, 0x08, 0xce, 0x1a, + 0x3a, 0xd2, 0xe1, 0xdf, 0xb5, 0x38, 0x6e, 0x0e, 0xe5, 0xf4, 0xf9, 0x86, 0xe9, 0x4f, 0xd6, + 0x85, 0x23, 0xcf, 0x32, 0x99, 0x31, 0x14, 0xae, 0xee, 0xc8, 0x48, 0xd3, 0x30, 0xa1, 0x92, + 0x41, 0xb1, 0x18, 0xc4, 0x2c, 0x71, 0x72, 0x44, 0x15, 0xfd, 0x37, 0xbe, 0x5f, 0xaa, 0x9b, + 0x88, 0xd8, 0xab, 0x89, 0x9c, 0xfa, 0x60, 0xea, 0xbc, 0x62, 0x0c, 0x24, 0xa6, 0xa8, 0xec, + 0x67, 0x20, 0xdb, 0x7c, 0x28, 0xdd, 0xac, 0x5b, 0x34, 0x7e, 0x10, 0xf1, 0x7b, 0x8f, 0x63, + 0xa0, 0x05, 0x9a, 0x43, 0x77, 0x21, 0xbf, 0x27, 0x09, 0xc3, 0x9f, 0xb6, 0xd7, 0x29, 0xc2, + 0xeb, 0xc0, 0xa4, 0x8b, 0x8c, 0x1d, 0xfb, 0xff, 0xc1, 0xb2, 0x97, 0x2e, 0xf8, 0x65, 0xf6, + 0x75, 0x07, 0x04, 0x49, 0x33, 0xe4, 0xd9, 0xb9, 0xd0, 0x42, 0xc7, 0x6c, 0x90, 0x00, 0x8e, + 0x6f, 0x50, 0x01, 0xc5, 0xda, 0x47, 0x3f, 0xcd, 0x69, 0xa2, 0xe2, 0x7a, 0xa7, 0xc6, 0x93, + 0x0f, 0x0a, 0x06, 0xe6, 0x2b, 0x96, 0xa3, 0x1c, 0xaf, 0x6a, 0x12, 0x84, 0x39, 0xe7, 0xb0, + 0x82, 0xf7, 0xfe, 0x9d, 0x87, 0x5c, 0x81, 0x35, 0xde, 0xb4, 0xa5, 0xfc, 0x80, 0xef, 0xcb, + 0xbb, 0x6b, 0x76, 0xba, 0x5a, 0x7d, 0x78, 0x0b, 0x95, 0xe3, 0xad, 0x74, 0x98, 0x3b, 0x36, + 0x64, 0x6d, 0xdc, 0xf0, 0x59, 0xa9, 0x4c, 0x17, 0x7f, 0x91, 0xb8, 0xc9, 0x57, 0x1b, 0xe0, + 0x61, + ], +]; diff --git a/kupyna/src/sub_units/t_xor_plus/tests/mod.rs b/kupyna/src/sub_units/t_xor_plus/tests/mod.rs new file mode 100644 index 00000000..24971c08 --- /dev/null +++ b/kupyna/src/sub_units/t_xor_plus/tests/mod.rs @@ -0,0 +1,2 @@ +mod test_xor_plus; +mod test_individual_layers; \ No newline at end of file diff --git a/kupyna/src/sub_units/t_xor_plus/tests/test_individual_layers.rs b/kupyna/src/sub_units/t_xor_plus/tests/test_individual_layers.rs new file mode 100644 index 00000000..44bbc4e5 --- /dev/null +++ b/kupyna/src/sub_units/t_xor_plus/tests/test_individual_layers.rs @@ -0,0 +1,146 @@ +use crate::sub_units::t_xor_plus::*; + +#[test] +fn test_add_constant_xor() { + let input = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + let expected_output = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x30, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x78, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x50, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x48, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0xC0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0xD8, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0xF0, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0xE8, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0xA0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0xB8, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x90, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x88, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + let input_matrix = block_to_matrix(&input); + let result = add_constant_xor(input_matrix, 0); + assert_eq!(result, block_to_matrix(&expected_output)); +} + +#[test] +fn test_add_constant_plus() { + let input = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + let expected_output = [ + 0xF3, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xFB, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, + 0xEF, 0x03, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xE8, 0x0B, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0xE0, 0x13, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0xD8, 0x1B, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0xD0, 0x23, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0xC8, 0x2B, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0xC0, 0x33, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0xB8, 0x3B, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0xB0, 0x43, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0xA8, 0x4B, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0xA0, 0x53, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x98, 0x5B, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x90, 0x63, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x88, + 0x6B, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x80, + ]; + let input_matrix = block_to_matrix(&input); + let result = add_constant_plus(input_matrix, 0); + assert_eq!(result, block_to_matrix(&expected_output)); +} + +#[test] +fn test_s_box_layer() { + let input = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x30, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x78, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x50, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x48, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0xC0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0xD8, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0xF0, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0xE8, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0xA0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0xB8, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x90, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x88, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + let expected_output = [ + 0xA8, 0xBB, 0x9A, 0x4D, 0x6B, 0xCB, 0x45, 0x2A, 0x79, 0x3A, 0xDF, 0xB3, 0x17, 0x90, 0x51, + 0x1F, 0x92, 0x15, 0x2B, 0x3D, 0xC9, 0x1C, 0xBB, 0x83, 0x1F, 0x5C, 0x71, 0xD5, 0x6F, 0x57, + 0x16, 0xBD, 0x34, 0xF6, 0xC0, 0x02, 0xB4, 0xF4, 0xAD, 0x11, 0x8E, 0x0F, 0x7A, 0x5E, 0x49, + 0x6D, 0xD1, 0x66, 0x2E, 0x26, 0xC4, 0x45, 0xD1, 0x5D, 0xB7, 0x94, 0x9C, 0x14, 0x0E, 0x1A, + 0x58, 0x10, 0xB2, 0xDF, 0x2F, 0x6B, 0xD7, 0x0E, 0x42, 0x33, 0xC3, 0x86, 0xC4, 0x9B, 0x4E, + 0x85, 0x8F, 0x95, 0xCB, 0x99, 0x81, 0x63, 0x4F, 0xEE, 0x96, 0x3C, 0x55, 0x30, 0x12, 0x49, + 0x18, 0xB1, 0xBC, 0x37, 0xE6, 0x71, 0x78, 0x2B, 0x8F, 0xFD, 0x6A, 0x45, 0xB9, 0xAA, 0x1C, + 0x0D, 0x2F, 0xAB, 0x38, 0x8C, 0xDA, 0x60, 0xEB, 0xDC, 0x05, 0x0C, 0x36, 0xB5, 0x6C, 0xEC, + 0xCD, 0x62, 0xB1, 0x7C, 0x14, 0xA5, 0x5E, 0x5B, + ]; + let input_matrix = block_to_matrix(&input); + let result = s_box_layer(input_matrix); + assert_eq!(result, block_to_matrix(&expected_output)); +} + +#[test] +fn test_rotate_rows() { + let input = [ + 0xA8, 0xBB, 0x9A, 0x4D, 0x6B, 0xCB, 0x45, 0x2A, 0x79, 0x3A, 0xDF, 0xB3, 0x17, 0x90, 0x51, + 0x1F, 0x92, 0x15, 0x2B, 0x3D, 0xC9, 0x1C, 0xBB, 0x83, 0x1F, 0x5C, 0x71, 0xD5, 0x6F, 0x57, + 0x16, 0xBD, 0x34, 0xF6, 0xC0, 0x02, 0xB4, 0xF4, 0xAD, 0x11, 0x8E, 0x0F, 0x7A, 0x5E, 0x49, + 0x6D, 0xD1, 0x66, 0x2E, 0x26, 0xC4, 0x45, 0xD1, 0x5D, 0xB7, 0x94, 0x9C, 0x14, 0x0E, 0x1A, + 0x58, 0x10, 0xB2, 0xDF, 0x2F, 0x6B, 0xD7, 0x0E, 0x42, 0x33, 0xC3, 0x86, 0xC4, 0x9B, 0x4E, + 0x85, 0x8F, 0x95, 0xCB, 0x99, 0x81, 0x63, 0x4F, 0xEE, 0x96, 0x3C, 0x55, 0x30, 0x12, 0x49, + 0x18, 0xB1, 0xBC, 0x37, 0xE6, 0x71, 0x78, 0x2B, 0x8F, 0xFD, 0x6A, 0x45, 0xB9, 0xAA, 0x1C, + 0x0D, 0x2F, 0xAB, 0x38, 0x8C, 0xDA, 0x60, 0xEB, 0xDC, 0x05, 0x0C, 0x36, 0xB5, 0x6C, 0xEC, + 0xCD, 0x62, 0xB1, 0x7C, 0x14, 0xA5, 0x5E, 0x5B, + ]; + let expected_output = [ + 0xA8, 0x62, 0x05, 0xAB, 0x6A, 0x37, 0x55, 0x66, 0x79, 0xBB, 0xB1, 0x0C, 0x38, 0x45, 0xE6, + 0x94, 0x92, 0x3A, 0x9A, 0x7C, 0x36, 0x8C, 0xB9, 0xDF, 0x1F, 0x15, 0xDF, 0x4D, 0x14, 0xB5, + 0xDA, 0x86, 0x34, 0x5C, 0x2B, 0xB3, 0x6B, 0xA5, 0x6C, 0x99, 0x8E, 0xF6, 0x71, 0x3D, 0x17, + 0xCB, 0x5E, 0x30, 0x2E, 0x0F, 0xC0, 0xD5, 0xC9, 0x90, 0x45, 0x71, 0x9C, 0x26, 0x7A, 0x02, + 0x6F, 0x1C, 0x51, 0xAA, 0x2F, 0x14, 0xC4, 0x5E, 0xB4, 0x57, 0xBB, 0x60, 0xC4, 0x6B, 0x0E, + 0x45, 0x49, 0xF4, 0x16, 0xEC, 0x81, 0x9B, 0xD7, 0x1A, 0xD1, 0x6D, 0xAD, 0x5B, 0x12, 0x63, + 0x4E, 0x0E, 0x58, 0x5D, 0xD1, 0x2A, 0x78, 0x49, 0x4F, 0x85, 0x42, 0x10, 0xB7, 0x1F, 0x1C, + 0x2B, 0x18, 0xEE, 0x8F, 0x33, 0xB2, 0x83, 0xEB, 0x0D, 0x8F, 0xB1, 0x96, 0x95, 0xC3, 0xBD, + 0xCD, 0xDC, 0x2F, 0xFD, 0xBC, 0x3C, 0xCB, 0x11, + ]; + let input_matrix = block_to_matrix(&input); + let result = rotate_rows(input_matrix); + assert_eq!(result, block_to_matrix(&expected_output)); +} + +#[test] +fn test_mix_columns() { + let input = [ + 0xA8, 0x62, 0x05, 0xAB, 0x6A, 0x37, 0x55, 0x66, 0x79, 0xBB, 0xB1, 0x0C, 0x38, 0x45, 0xE6, + 0x94, 0x92, 0x3A, 0x9A, 0x7C, 0x36, 0x8C, 0xB9, 0xDF, 0x1F, 0x15, 0xDF, 0x4D, 0x14, 0xB5, + 0xDA, 0x86, 0x34, 0x5C, 0x2B, 0xB3, 0x6B, 0xA5, 0x6C, 0x99, 0x8E, 0xF6, 0x71, 0x3D, 0x17, + 0xCB, 0x5E, 0x30, 0x2E, 0x0F, 0xC0, 0xD5, 0xC9, 0x90, 0x45, 0x71, 0x9C, 0x26, 0x7A, 0x02, + 0x6F, 0x1C, 0x51, 0xAA, 0x2F, 0x14, 0xC4, 0x5E, 0xB4, 0x57, 0xBB, 0x60, 0xC4, 0x6B, 0x0E, + 0x45, 0x49, 0xF4, 0x16, 0xEC, 0x81, 0x9B, 0xD7, 0x1A, 0xD1, 0x6D, 0xAD, 0x5B, 0x12, 0x63, + 0x4E, 0x0E, 0x58, 0x5D, 0xD1, 0x2A, 0x78, 0x49, 0x4F, 0x85, 0x42, 0x10, 0xB7, 0x1F, 0x1C, + 0x2B, 0x18, 0xEE, 0x8F, 0x33, 0xB2, 0x83, 0xEB, 0x0D, 0x8F, 0xB1, 0x96, 0x95, 0xC3, 0xBD, + 0xCD, 0xDC, 0x2F, 0xFD, 0xBC, 0x3C, 0xCB, 0x11, + ]; + let expected_output = [ + 0x86, 0xC3, 0x77, 0x98, 0xD2, 0xC3, 0x41, 0xA0, 0x3D, 0x40, 0xB8, 0xB9, 0xE2, 0xD0, 0x21, + 0xB8, 0xED, 0xF7, 0xEC, 0x7C, 0x76, 0x24, 0x85, 0x2B, 0xE4, 0x54, 0xC7, 0xEE, 0x3A, 0x2A, + 0xAD, 0x4E, 0x9D, 0x55, 0x30, 0x9E, 0xD9, 0x95, 0x27, 0xD0, 0x92, 0x04, 0xD4, 0x0B, 0x63, + 0xDC, 0x5B, 0x6F, 0x4D, 0x25, 0x90, 0xF2, 0x22, 0x83, 0x18, 0x18, 0x18, 0x19, 0xA8, 0x01, + 0xE2, 0x6A, 0x90, 0x90, 0x2B, 0xE1, 0xE2, 0xD9, 0xF0, 0x51, 0x81, 0xF4, 0x59, 0x6E, 0xFA, + 0xBC, 0x35, 0xF9, 0x84, 0xEB, 0x0C, 0xCB, 0x22, 0xFC, 0xB2, 0x2A, 0xDC, 0x5C, 0x98, 0xD3, + 0xED, 0x83, 0x95, 0xCD, 0x50, 0xD4, 0xCE, 0x5A, 0x52, 0x16, 0x8E, 0xD8, 0x8C, 0x03, 0x08, + 0x1D, 0x60, 0xB9, 0xB2, 0x8B, 0xAE, 0x4D, 0xFE, 0xA8, 0x3F, 0xFB, 0x07, 0xF1, 0x35, 0xB5, + 0x71, 0x78, 0xE6, 0xC8, 0x9B, 0x20, 0x6A, 0xD3, + ]; + let input_matrix = block_to_matrix(&input); + let result = mix_columns(input_matrix); + assert_eq!(result, block_to_matrix(&expected_output)); +} diff --git a/kupyna/src/sub_units/t_xor_plus/tests/test_xor_plus.rs b/kupyna/src/sub_units/t_xor_plus/tests/test_xor_plus.rs new file mode 100644 index 00000000..01fecae9 --- /dev/null +++ b/kupyna/src/sub_units/t_xor_plus/tests/test_xor_plus.rs @@ -0,0 +1,63 @@ +use crate::sub_units::t_xor_plus::{t_plus_l, t_xor_l}; + +#[test] +fn test_t_xor_l() { + let input = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + + let expected_output = [ + 0x60, 0x4B, 0x9D, 0xCF, 0x7E, 0xAA, 0x57, 0x85, 0x94, 0xD1, 0x83, 0xEE, 0xF2, 0xDD, 0x97, + 0xA3, 0x2C, 0x11, 0x1C, 0x81, 0x70, 0xC0, 0xA5, 0x08, 0x6A, 0x08, 0xC9, 0xE4, 0x28, 0x81, + 0x11, 0x32, 0x31, 0xBE, 0xC7, 0xB7, 0x1D, 0x0E, 0xE3, 0x1D, 0xE8, 0x36, 0x3B, 0x4A, 0xA6, + 0xAF, 0x89, 0x0B, 0xDE, 0xEE, 0x5C, 0x96, 0x66, 0x3A, 0x44, 0x38, 0x3A, 0x40, 0x09, 0x30, + 0x60, 0xE7, 0x65, 0x15, 0x2D, 0xEB, 0xEC, 0xD2, 0x5B, 0x83, 0x42, 0xC4, 0xEF, 0x4E, 0x75, + 0x0F, 0xC3, 0xF4, 0x81, 0x4F, 0xA9, 0xE1, 0xD1, 0x1F, 0xE7, 0xF6, 0xF8, 0xCF, 0x32, 0x72, + 0xE7, 0xE1, 0x61, 0x4F, 0x91, 0xAD, 0x6F, 0x01, 0xF7, 0x28, 0xD8, 0xDB, 0xBE, 0x1F, 0x2A, + 0xC1, 0x97, 0x77, 0x1E, 0x37, 0x8F, 0x8D, 0xD7, 0xD1, 0x31, 0x32, 0x7B, 0xF1, 0xA9, 0x43, + 0xA9, 0x55, 0xF1, 0xF7, 0xC8, 0x32, 0xAD, 0xF3, + ]; + + let rounds = 14; + let result = t_xor_l(&input, rounds); + assert_eq!(result, expected_output); +} + +#[test] +fn test_t_plus_l() { + let input = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + + let expected_output = [ + 0x36, 0x57, 0x5D, 0x99, 0x30, 0x36, 0xAF, 0xDE, 0xB2, 0x65, 0x4C, 0x1E, 0x13, 0x66, 0x0A, + 0x9D, 0x4F, 0x0E, 0x10, 0x5C, 0xA2, 0x33, 0x6F, 0x2B, 0xB3, 0x69, 0x00, 0x45, 0x25, 0x9A, + 0x1A, 0x9D, 0x3F, 0x24, 0x85, 0x07, 0xC3, 0x42, 0xA7, 0x0B, 0x42, 0xF7, 0x49, 0x81, 0xEC, + 0xE4, 0x6D, 0xD0, 0x5E, 0x1D, 0x30, 0x9F, 0x77, 0x4E, 0x1E, 0xD2, 0x13, 0x24, 0x7C, 0xC8, + 0x21, 0x46, 0x16, 0x73, 0xC7, 0x41, 0x9A, 0xE1, 0x2B, 0x93, 0x61, 0xF3, 0x2C, 0x75, 0x38, + 0xC1, 0x59, 0x09, 0xB1, 0x97, 0xE2, 0x0F, 0x9E, 0x09, 0xDD, 0x28, 0xCD, 0xD4, 0xD7, 0xC2, + 0x34, 0xDB, 0xDB, 0x47, 0x93, 0x18, 0xA2, 0x58, 0xA7, 0x18, 0x0B, 0x18, 0x33, 0x17, 0x8A, + 0x20, 0xFC, 0xFE, 0x05, 0xA6, 0x06, 0x4F, 0xD7, 0xB1, 0xEA, 0x96, 0x07, 0x99, 0x5E, 0x98, + 0xD9, 0x0D, 0x2D, 0x55, 0xDC, 0xF7, 0x2F, 0x5F, + ]; + + let rounds = 14; + let result = t_plus_l(&input, rounds); + assert_eq!(result, expected_output); +} diff --git a/kupyna/src/tests/blocking_tests.rs b/kupyna/src/tests/blocking_tests.rs new file mode 100644 index 00000000..bb257df9 --- /dev/null +++ b/kupyna/src/tests/blocking_tests.rs @@ -0,0 +1,218 @@ +use crate::{pad_message, divide_into_blocks}; + + +const STATE_SIZE_512: usize = 1024; + +#[test] +fn block_test_0() { + let message: [u8; 0] = []; + + let expected_block_count = 1; + + let padded_message = pad_message(&message,0, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_8() { + let message: [u8; 1] = [0xFF]; + + let expected_block_count = 1; + + let padded_message = pad_message(&message,8, STATE_SIZE_512); + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_512() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + ]; + + let expected_block_count = 1; + + let padded_message = pad_message(&message,512, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_510() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3C, + ]; + + let expected_block_count = 1; + + let padded_message = pad_message(&message,510, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } + +} + +#[test] +fn block_test_1024() { + let message: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + + let expected_block_count = 2; + + let padded_message = pad_message(&message,1024, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_2048() { + let message: [u8; 256] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, + 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, + 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, + 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, + 0xFF, + ]; + + let expected_block_count = 3; + + let padded_message = pad_message(&message,2048, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_1536() { + let message: [u8; 192] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + ]; + + let expected_block_count = 2; + + let padded_message = pad_message(&message,1536, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} + +#[test] +fn block_test_655() { + let message: [u8; 82] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x50, + ]; + + let expected_block_count = 1; + + let padded_message = pad_message(&message,655, STATE_SIZE_512); + + let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); + + assert_eq!(blocks.len(), expected_block_count); + + // check that all the blocks have equal length + let block_len = STATE_SIZE_512 / 8; + for block in blocks { + assert_eq!(block.len(), block_len); + } +} \ No newline at end of file diff --git a/kupyna/src/tests/hashing_tests.rs b/kupyna/src/tests/hashing_tests.rs new file mode 100644 index 00000000..797f4fe3 --- /dev/null +++ b/kupyna/src/tests/hashing_tests.rs @@ -0,0 +1,207 @@ +use crate::hash; + +#[test] +fn hash_test_0() { + let message: [u8; 0] = []; + let message_length = 0; + + let expected_hash = [ + 0x65, 0x6B, 0x2F, 0x4C, 0xD7, 0x14, 0x62, 0x38, 0x8B, 0x64, 0xA3, 0x70, 0x43, 0xEA, 0x55, + 0xDB, 0xE4, 0x45, 0xD4, 0x52, 0xAE, 0xCD, 0x46, 0xC3, 0x29, 0x83, 0x43, 0x31, 0x4E, 0xF0, + 0x40, 0x19, 0xBC, 0xFA, 0x3F, 0x04, 0x26, 0x5A, 0x98, 0x57, 0xF9, 0x1B, 0xE9, 0x1F, 0xCE, + 0x19, 0x70, 0x96, 0x18, 0x7C, 0xED, 0xA7, 0x8C, 0x9C, 0x1C, 0x02, 0x1C, 0x29, 0x4A, 0x06, + 0x89, 0x19, 0x85, 0x38, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_8() { + let message: [u8; 1] = [0xFF]; + let message_length = 8; + + let expected_hash = [ + 0x87, 0x1B, 0x18, 0xCF, 0x75, 0x4B, 0x72, 0x74, 0x03, 0x07, 0xA9, 0x7B, 0x44, 0x9A, 0xBE, + 0xB3, 0x2B, 0x64, 0x44, 0x4C, 0xC0, 0xD5, 0xA4, 0xD6, 0x58, 0x30, 0xAE, 0x54, 0x56, 0x83, + 0x7A, 0x72, 0xD8, 0x45, 0x8F, 0x12, 0xC8, 0xF0, 0x6C, 0x98, 0xC6, 0x16, 0xAB, 0xE1, 0x18, + 0x97, 0xF8, 0x62, 0x63, 0xB5, 0xCB, 0x77, 0xC4, 0x20, 0xFB, 0x37, 0x53, 0x74, 0xBE, 0xC5, + 0x2B, 0x6D, 0x02, 0x92, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_510() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3C, + ]; + let message_length = 510; + + let expected_hash = [ + 0x2F, 0x3B, 0xBA, 0xC9, 0x8E, 0x87, 0x71, 0xD6, 0xE3, 0xB8, 0xAA, 0x30, 0x15, 0x3A, 0xBC, + 0x4D, 0x0C, 0x29, 0x85, 0xE9, 0x1D, 0xA1, 0xB5, 0x56, 0x8F, 0xD1, 0xBD, 0xD7, 0x05, 0xCC, + 0xAB, 0x7E, 0xE8, 0xD9, 0x5D, 0x2F, 0xC9, 0x8B, 0xFA, 0x53, 0x22, 0xA2, 0x41, 0xE0, 0x9C, + 0x89, 0x6B, 0x58, 0x28, 0x4C, 0x83, 0xF2, 0x48, 0x8C, 0xF9, 0x43, 0xE4, 0xB3, 0xDE, 0x43, + 0xE0, 0x5F, 0x0D, 0xEA, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_512() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + ]; + let message_length = 512; + + let expected_hash = [ + 0x38, 0x13, 0xE2, 0x10, 0x91, 0x18, 0xCD, 0xFB, 0x5A, 0x6D, 0x5E, 0x72, 0xF7, 0x20, 0x8D, + 0xCC, 0xC8, 0x0A, 0x2D, 0xFB, 0x3A, 0xFD, 0xFB, 0x02, 0xF4, 0x69, 0x92, 0xB5, 0xED, 0xBE, + 0x53, 0x6B, 0x35, 0x60, 0xDD, 0x1D, 0x7E, 0x29, 0xC6, 0xF5, 0x39, 0x78, 0xAF, 0x58, 0xB4, + 0x44, 0xE3, 0x7B, 0xA6, 0x85, 0xC0, 0xDD, 0x91, 0x05, 0x33, 0xBA, 0x5D, 0x78, 0xEF, 0xFF, + 0xC1, 0x3D, 0xE6, 0x2A, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_655() { + let message: [u8; 82] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x50, + ]; + let message_length = 655; + + let expected_hash = [ + 0x01, 0xB7, 0xBD, 0xA1, 0xDB, 0xA7, 0x7D, 0x73, 0x79, 0xF5, 0x3C, 0x2A, 0x49, 0x8A, 0x39, + 0x0D, 0xE5, 0xE6, 0x88, 0xA1, 0x2B, 0xC7, 0x5F, 0xEE, 0x9E, 0x01, 0x0C, 0xB6, 0xFE, 0xBE, + 0xD3, 0xB9, 0xC7, 0x02, 0x39, 0x31, 0xC7, 0x4A, 0x7B, 0x55, 0x16, 0x8A, 0x15, 0x04, 0x7D, + 0x5E, 0x2C, 0xB7, 0x8A, 0x8B, 0x5C, 0xA2, 0xF7, 0x5E, 0x05, 0xE8, 0x0C, 0xA3, 0x98, 0x03, + 0x0E, 0x02, 0xC7, 0xAA, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_1024() { + let message: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + let message_length = 1024; + + let expected_hash = [ + 0x76, 0xED, 0x1A, 0xC2, 0x8B, 0x1D, 0x01, 0x43, 0x01, 0x3F, 0xFA, 0x87, 0x21, 0x3B, 0x40, + 0x90, 0xB3, 0x56, 0x44, 0x12, 0x63, 0xC1, 0x3E, 0x03, 0xFA, 0x06, 0x0A, 0x8C, 0xAD, 0xA3, + 0x2B, 0x97, 0x96, 0x35, 0x65, 0x7F, 0x25, 0x6B, 0x15, 0xD5, 0xFC, 0xA4, 0xA1, 0x74, 0xDE, + 0x02, 0x9F, 0x0B, 0x1B, 0x43, 0x87, 0xC8, 0x78, 0xFC, 0xC1, 0xC0, 0x0E, 0x87, 0x05, 0xD7, + 0x83, 0xFD, 0x7F, 0xFE, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_1536() { + let message: [u8; 192] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + ]; + let message_length = 1536; + + let expected_hash = [ + 0xB1, 0x89, 0xBF, 0xE9, 0x87, 0xF6, 0x82, 0xF5, 0xF1, 0x67, 0xF0, 0xD7, 0xFA, 0x56, 0x53, + 0x30, 0xE1, 0x26, 0xB6, 0xE5, 0x92, 0xB1, 0xC5, 0x5D, 0x44, 0x29, 0x90, 0x64, 0xEF, 0x95, + 0xB1, 0xA5, 0x7F, 0x3C, 0x2D, 0x0E, 0xCF, 0x17, 0x86, 0x9D, 0x1D, 0x19, 0x9E, 0xBB, 0xD0, + 0x2E, 0x88, 0x57, 0xFB, 0x8A, 0xDD, 0x67, 0xA8, 0xC3, 0x1F, 0x56, 0xCD, 0x82, 0xC0, 0x16, + 0xCF, 0x74, 0x31, 0x21, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} + +#[test] +fn hash_test_2048() { + let message: [u8; 256] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, + 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, + 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, + 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, + 0xFF, + ]; + let message_length = 2048; + + let expected_hash = [ + 0x0D, 0xD0, 0x3D, 0x73, 0x50, 0xC4, 0x09, 0xCB, 0x3C, 0x29, 0xC2, 0x58, 0x93, 0xA0, 0x72, + 0x4F, 0x6B, 0x13, 0x3F, 0xA8, 0xB9, 0xEB, 0x90, 0xA6, 0x4D, 0x1A, 0x8F, 0xA9, 0x3B, 0x56, + 0x55, 0x66, 0x11, 0xEB, 0x18, 0x7D, 0x71, 0x5A, 0x95, 0x6B, 0x10, 0x7E, 0x3B, 0xFC, 0x76, + 0x48, 0x22, 0x98, 0x13, 0x3A, 0x9C, 0xE8, 0xCB, 0xC0, 0xBD, 0x5E, 0x14, 0x36, 0xA5, 0xB1, + 0x97, 0x28, 0x4F, 0x7E, + ]; + + let actual_hash = hash(message.to_vec(), Some(message_length)).unwrap(); + + assert_eq!(actual_hash, expected_hash); +} diff --git a/kupyna/src/tests/mod.rs b/kupyna/src/tests/mod.rs new file mode 100644 index 00000000..5071554b --- /dev/null +++ b/kupyna/src/tests/mod.rs @@ -0,0 +1,3 @@ +mod padding_tests; +mod blocking_tests; +mod hashing_tests; diff --git a/kupyna/src/tests/padding_tests.rs b/kupyna/src/tests/padding_tests.rs new file mode 100644 index 00000000..95415088 --- /dev/null +++ b/kupyna/src/tests/padding_tests.rs @@ -0,0 +1,268 @@ +use crate::pad_message; + +const STATE_SIZE_512: usize = 1024; + +#[test] +fn pad_test_0() { + let message: [u8; 0] = []; + + let expected_output: [u8; 128] = [ + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,0, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_8() { + let message: [u8; 1] = [0xFF]; + + let expected_output: [u8; 128] = [ + 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,8, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_510() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3C, + ]; + + let expected_output: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,510, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_512() { + let message: [u8; 64] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + ]; + + let expected_output: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,512, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_1024() { + let message: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + ]; + + let expected_output: [u8; 256] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, + ]; + + let padded_message = pad_message(&message,1024, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_2048() { + let message: [u8; 256] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, + 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, + 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, + 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, + 0xFF, + ]; + + let expected_output: [u8; 384] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, + 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, + 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, + 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, + 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,2048, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_1536() { + let message: [u8; 192] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + ]; + + let expected_output: [u8; 256] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, + 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, + 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, + ]; + + let padded_message = pad_message(&message,1536, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} + +#[test] +fn pad_test_655() { + let message: [u8; 82] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x50, + ]; + + let expected_output: [u8; 128] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, + 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8F, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ]; + + let padded_message = pad_message(&message,655, STATE_SIZE_512); + + assert_eq!(padded_message, expected_output); +} From 41031601797e147a55ee934140b5aafa5c12914d Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 22:29:10 -0400 Subject: [PATCH 06/12] fix: update correct crate name --- Cargo.lock | 7 +++++++ kupyna/Cargo.toml | 1 - kupyna/src/main.rs | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed207914..0be9de3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,6 +203,13 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "kupyna" +version = "0.1.0" +dependencies = [ + "digest", +] + [[package]] name = "libc" version = "0.2.155" diff --git a/kupyna/Cargo.toml b/kupyna/Cargo.toml index 550dd013..cc0499b2 100644 --- a/kupyna/Cargo.toml +++ b/kupyna/Cargo.toml @@ -17,7 +17,6 @@ rust-version = "1.71" [dependencies] digest = { version = "=0.11.0-pre.8", default-features = false, features = ["core-api"] } -kupyna = { version = "0.1.0", default-features = false } [dev-dependencies] diff --git a/kupyna/src/main.rs b/kupyna/src/main.rs index cf220702..7ba24d5d 100644 --- a/kupyna/src/main.rs +++ b/kupyna/src/main.rs @@ -1,10 +1,10 @@ -use kupyna_512; +use kupyna; fn main() { let message = b"Hello, World!".to_vec(); let _message_length = 0; - let hash_code = kupyna_512::hash(message, None).unwrap(); + let hash_code = kupyna::hash(message, None).unwrap(); println!("{:02X?}", hash_code); -} \ No newline at end of file +} From a8cff4857043861020aa2953c7b9bf32df28123f Mon Sep 17 00:00:00 2001 From: Joshua Koudys Date: Thu, 27 Jun 2024 23:16:46 -0400 Subject: [PATCH 07/12] Add kupyna to the list of algos --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 101c3fca..eee399c7 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Additionally all crates do not require the standard library (i.e. `no_std` capab | [Grøstl] (Groestl) | [`groestl`] | [![crates.io](https://img.shields.io/crates/v/groestl.svg)](https://crates.io/crates/groestl) | [![Documentation](https://docs.rs/groestl/badge.svg)](https://docs.rs/groestl) | ![MSRV 1.71][msrv-1.71] | :green_heart: | | [JH] | [`jh`] | [![crates.io](https://img.shields.io/crates/v/jh.svg)](https://crates.io/crates/jh) | [![Documentation](https://docs.rs/jh/badge.svg)](https://docs.rs/jh) | ![MSRV 1.71][msrv-1.71] | :green_heart: | | [KangarooTwelve] | [`k12`] | [![crates.io](https://img.shields.io/crates/v/k12.svg)](https://crates.io/crates/k12) | [![Documentation](https://docs.rs/k12/badge.svg)](https://docs.rs/k12) | ![MSRV 1.71][msrv-1.71] | :green_heart: | +| [Kupyna] | [`kupyna`] | [![crates.io](https://img.shields.io/crates/v/kupyna.svg)](https://crates.io/crates/kupyna) | [![Documentation](https://docs.rs/kupyna/badge.svg)](https://docs.rs/kupyna) | ![MSRV 1.71][msrv-1.71] | :green_heart: | | [MD2] | [`md2`] | [![crates.io](https://img.shields.io/crates/v/md2.svg)](https://crates.io/crates/md2) | [![Documentation](https://docs.rs/md2/badge.svg)](https://docs.rs/md2) | ![MSRV 1.71][msrv-1.71] | :broken_heart: | | [MD4] | [`md4`] | [![crates.io](https://img.shields.io/crates/v/md4.svg)](https://crates.io/crates/md4) | [![Documentation](https://docs.rs/md4/badge.svg)](https://docs.rs/md4) | ![MSRV 1.71][msrv-1.71] | :broken_heart: | | [MD5] | [`md5`] [:exclamation:] | [![crates.io](https://img.shields.io/crates/v/md-5.svg)](https://crates.io/crates/md-5) | [![Documentation](https://docs.rs/md-5/badge.svg)](https://docs.rs/md-5) | ![MSRV 1.72][msrv-1.72] | :broken_heart: | From 84702a9b9e8792b38072bae4f4c5d53bc1433e79 Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun Date: Sat, 29 Jun 2024 06:47:22 +0530 Subject: [PATCH 08/12] update algo link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index eee399c7..02b6a7d8 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted [Grøstl]: https://en.wikipedia.org/wiki/Grøstl [JH]: https://www3.ntu.edu.sg/home/wuhj/research/jh [KangarooTwelve]: https://keccak.team/kangarootwelve.html +[Kupyna]: https://eprint.iacr.org/2015/885.pdf [MD2]: https://en.wikipedia.org/wiki/MD2_(cryptography) [MD4]: https://en.wikipedia.org/wiki/MD4 [MD5]: https://en.wikipedia.org/wiki/MD5 From 11736e0adc23823485f6acead52a0d1220701e83 Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun Date: Sat, 29 Jun 2024 06:50:55 +0530 Subject: [PATCH 09/12] update author creds for kupyna readme --- kupyna/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kupyna/README.md b/kupyna/README.md index e98db3d8..0cf026b5 100644 --- a/kupyna/README.md +++ b/kupyna/README.md @@ -4,11 +4,14 @@ The Kupyna hash function is a cryptographic hash developed in Ukraine, designed for high security and efficiency. This implementation supports generating hash codes of various lengths. -## Author +## Authors Joshua Koudys Email: [josh@qaribou.com](mailto:josh@qaribou.com) +Raj Singh Bisen +Email: [typhoeusxoxo@gmail.com](mailto:typhoeusxoxo@gmail.com) + ## Summary Kupyna is a hash function standardized in Ukraine as DSTU 7564:2014. It is designed to provide a high level of security with a focus on robustness against various cryptographic attacks. The function supports different hash lengths, providing flexibility in usage depending on security requirements. From 54111ba51be56e7cc1a77769ceb0af6e3a026902 Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun Date: Sat, 29 Jun 2024 06:57:46 +0530 Subject: [PATCH 10/12] updating toml --- kupyna/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kupyna/Cargo.toml b/kupyna/Cargo.toml index cc0499b2..05d9264b 100644 --- a/kupyna/Cargo.toml +++ b/kupyna/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" description = "Hashing algorithm for Kupyna, 8 to 512 length" authors = [ "Joshua Koudys ", + "Raj Singh ", "RustCrypto Developers", ] license = "MIT" @@ -11,7 +12,7 @@ readme = "README.md" edition = "2021" documentation = "https://docs.rs/kupyna" repository = "https://github.com/RustCrypto/hashes" -keywords = ["crypto", "hash", "kupyno"] +keywords = ["crypto", "hash", "kupyna"] categories = ["cryptography", "no-std"] rust-version = "1.71" From 73ffc6e7418780bc2b2fbbfa79bd305f4ad0f368 Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun Date: Sat, 29 Jun 2024 20:47:22 +0530 Subject: [PATCH 11/12] resolving clippy warnings/errors --- kupyna/src/lib.rs | 8 -------- kupyna/src/main.rs | 2 -- kupyna/src/sub_units/mod.rs | 13 ++++--------- kupyna/src/sub_units/t_xor_plus/mod.rs | 10 +++++----- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/kupyna/src/lib.rs b/kupyna/src/lib.rs index da4df891..2e508b9e 100644 --- a/kupyna/src/lib.rs +++ b/kupyna/src/lib.rs @@ -5,8 +5,6 @@ mod sub_units; const STATE_SIZE: usize = 1024; const HASH_SIZE: usize = 512; -const MAX_MESSAGE_LENGTH: usize = 18446744073709551615; - fn pad_message(message: &[u8], msg_len_bits: usize, state_size: usize) -> Vec { let round_msg_len = message.len() * 8; let d = @@ -58,9 +56,6 @@ pub fn hash(message: Vec, length: Option) -> Result, &'static let mut message = message; let message_length: usize; if let Some(len) = length { - if len > MAX_MESSAGE_LENGTH { - return Err("Message is too long"); - } if len > message.len() * 8 { return Err("Message length is less than the provided length"); } @@ -78,9 +73,6 @@ pub fn hash(message: Vec, length: Option) -> Result, &'static message_length = len; } else { - if message.len() * 8 > MAX_MESSAGE_LENGTH { - return Err("Message is too long"); - } message_length = message.len() * 8; } diff --git a/kupyna/src/main.rs b/kupyna/src/main.rs index 7ba24d5d..09948246 100644 --- a/kupyna/src/main.rs +++ b/kupyna/src/main.rs @@ -1,5 +1,3 @@ -use kupyna; - fn main() { let message = b"Hello, World!".to_vec(); let _message_length = 0; diff --git a/kupyna/src/sub_units/mod.rs b/kupyna/src/sub_units/mod.rs index beeae736..fbb50d03 100644 --- a/kupyna/src/sub_units/mod.rs +++ b/kupyna/src/sub_units/mod.rs @@ -14,11 +14,9 @@ fn silo(message_block: &[u8], prev_vector: &[u8]) -> Vec { let t_xor_mp = t_xor_l(&m_xor_p, ROUNDS); - let t_plus_m = t_plus_l(&message_block, ROUNDS); + let t_plus_m = t_plus_l(message_block, ROUNDS); - let return_vector = xor_bytes(&(xor_bytes(&t_xor_mp, &t_plus_m)), prev_vector); - - return_vector + xor_bytes(&(xor_bytes(&t_xor_mp, &t_plus_m)), prev_vector) } @@ -30,14 +28,11 @@ pub(crate) fn plant(message_blocks: Vec<&[u8]>, init_vector: &[u8]) -> Vec { last_vector = silo(block, &last_vector); } - let last_vector = finalize(&last_vector); - - last_vector + finalize(&last_vector) } fn finalize(ult_processed_block: &[u8]) -> Vec { let t_xor_ult_processed_block = t_xor_l(ult_processed_block, ROUNDS); - let final_state = xor_bytes(ult_processed_block, &t_xor_ult_processed_block); - final_state + xor_bytes(ult_processed_block, &t_xor_ult_processed_block) } diff --git a/kupyna/src/sub_units/t_xor_plus/mod.rs b/kupyna/src/sub_units/t_xor_plus/mod.rs index bf385edf..a10c5b1b 100644 --- a/kupyna/src/sub_units/t_xor_plus/mod.rs +++ b/kupyna/src/sub_units/t_xor_plus/mod.rs @@ -35,9 +35,9 @@ fn matrix_to_block(matrix: Matrix) -> Vec { } pub(crate) fn add_constant_xor(mut state: Matrix, round: usize) -> Matrix { - for j in 0..ROWS { + for (j, row) in state.iter_mut().enumerate().take(ROWS) { let constant = ((j * 0x10) ^ round) as u8; - state[j][0] ^= constant; + row[0] ^= constant; } state } @@ -59,8 +59,8 @@ pub(crate) fn add_constant_plus(mut state: Matrix, round: usize) -> Matrix { pub(crate) fn s_box_layer(mut state: Matrix) -> Matrix { for i in 0..COLS { - for j in 0..ROWS { - state[j][i] = SBOXES[i % 4][state[j][i] as usize]; + for row in state.iter_mut() { + row[i] = SBOXES[i % 4][row[i] as usize]; } } state @@ -70,7 +70,7 @@ pub(crate) fn rotate_rows(mut state: Matrix) -> Matrix { let mut temp = [0u8; ROWS]; let mut shift: i32 = -1; for i in 0..COLS { - if (i == COLS - 1) && true { + if i == COLS - 1 { shift = 11; } else { shift += 1; From 0d75cf998728cc799fb6d662c97aab60cfa7f105 Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun Date: Sat, 29 Jun 2024 20:48:00 +0530 Subject: [PATCH 12/12] rustfmt pass --- kupyna/src/lib.rs | 11 ++++------ kupyna/src/sub_units/mod.rs | 6 +----- kupyna/src/sub_units/t_xor_plus/mod.rs | 3 +-- kupyna/src/sub_units/t_xor_plus/tests/mod.rs | 2 +- kupyna/src/tests/blocking_tests.rs | 22 +++++++++----------- kupyna/src/tests/mod.rs | 2 +- kupyna/src/tests/padding_tests.rs | 16 +++++++------- 7 files changed, 26 insertions(+), 36 deletions(-) diff --git a/kupyna/src/lib.rs b/kupyna/src/lib.rs index 2e508b9e..f692a931 100644 --- a/kupyna/src/lib.rs +++ b/kupyna/src/lib.rs @@ -1,6 +1,6 @@ +mod sub_units; #[cfg(test)] mod tests; -mod sub_units; const STATE_SIZE: usize = 1024; const HASH_SIZE: usize = 512; @@ -60,10 +60,10 @@ pub fn hash(message: Vec, length: Option) -> Result, &'static return Err("Message length is less than the provided length"); } - let mut trimmed_message = message[..(len/8)].to_vec(); + let mut trimmed_message = message[..(len / 8)].to_vec(); if len % 8 != 0 { - let extra_byte = message[len/8]; + let extra_byte = message[len / 8]; let extra_bits = len % 8; let mask = 0xFF << (8 - extra_bits); trimmed_message.push(extra_byte & mask); @@ -71,7 +71,6 @@ pub fn hash(message: Vec, length: Option) -> Result, &'static message = trimmed_message; message_length = len; - } else { message_length = message.len() * 8; } @@ -80,14 +79,12 @@ pub fn hash(message: Vec, length: Option) -> Result, &'static let blocks = divide_into_blocks(&padded_message, STATE_SIZE); - let mut init_vector: Vec = vec![0; STATE_SIZE/8]; + let mut init_vector: Vec = vec![0; STATE_SIZE / 8]; init_vector[0] = 0x80; // set the first bit of this init vector to high - let fin_vector = sub_units::plant(blocks, &init_vector); let hash = truncate(&fin_vector, HASH_SIZE); Ok(hash) } - diff --git a/kupyna/src/sub_units/mod.rs b/kupyna/src/sub_units/mod.rs index fbb50d03..9a2df880 100644 --- a/kupyna/src/sub_units/mod.rs +++ b/kupyna/src/sub_units/mod.rs @@ -1,6 +1,6 @@ mod t_xor_plus; -use t_xor_plus::{t_xor_l, t_plus_l}; +use t_xor_plus::{t_plus_l, t_xor_l}; const ROUNDS: usize = 14; @@ -9,7 +9,6 @@ fn xor_bytes(a: &[u8], b: &[u8]) -> Vec { } fn silo(message_block: &[u8], prev_vector: &[u8]) -> Vec { - let m_xor_p = xor_bytes(message_block, prev_vector); let t_xor_mp = t_xor_l(&m_xor_p, ROUNDS); @@ -17,11 +16,9 @@ fn silo(message_block: &[u8], prev_vector: &[u8]) -> Vec { let t_plus_m = t_plus_l(message_block, ROUNDS); xor_bytes(&(xor_bytes(&t_xor_mp, &t_plus_m)), prev_vector) - } pub(crate) fn plant(message_blocks: Vec<&[u8]>, init_vector: &[u8]) -> Vec { - let mut last_vector = init_vector.to_vec(); for block in message_blocks { @@ -35,4 +32,3 @@ fn finalize(ult_processed_block: &[u8]) -> Vec { let t_xor_ult_processed_block = t_xor_l(ult_processed_block, ROUNDS); xor_bytes(ult_processed_block, &t_xor_ult_processed_block) } - diff --git a/kupyna/src/sub_units/t_xor_plus/mod.rs b/kupyna/src/sub_units/t_xor_plus/mod.rs index a10c5b1b..2c99f2c5 100644 --- a/kupyna/src/sub_units/t_xor_plus/mod.rs +++ b/kupyna/src/sub_units/t_xor_plus/mod.rs @@ -13,7 +13,6 @@ type Matrix = [[u8; COLS]; ROWS]; use tables::{MDS_MATRIX, SBOXES}; - pub(crate) fn block_to_matrix(block: &[u8]) -> Matrix { let mut matrix = [[0u8; COLS]; ROWS]; for i in 0..ROWS { @@ -159,4 +158,4 @@ pub fn t_plus_l(block: &[u8], rounds: usize) -> Vec { state = mix_columns(state); } matrix_to_block(state) -} \ No newline at end of file +} diff --git a/kupyna/src/sub_units/t_xor_plus/tests/mod.rs b/kupyna/src/sub_units/t_xor_plus/tests/mod.rs index 24971c08..318c06d7 100644 --- a/kupyna/src/sub_units/t_xor_plus/tests/mod.rs +++ b/kupyna/src/sub_units/t_xor_plus/tests/mod.rs @@ -1,2 +1,2 @@ +mod test_individual_layers; mod test_xor_plus; -mod test_individual_layers; \ No newline at end of file diff --git a/kupyna/src/tests/blocking_tests.rs b/kupyna/src/tests/blocking_tests.rs index bb257df9..0aade34d 100644 --- a/kupyna/src/tests/blocking_tests.rs +++ b/kupyna/src/tests/blocking_tests.rs @@ -1,5 +1,4 @@ -use crate::{pad_message, divide_into_blocks}; - +use crate::{divide_into_blocks, pad_message}; const STATE_SIZE_512: usize = 1024; @@ -9,7 +8,7 @@ fn block_test_0() { let expected_block_count = 1; - let padded_message = pad_message(&message,0, STATE_SIZE_512); + let padded_message = pad_message(&message, 0, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -28,7 +27,7 @@ fn block_test_8() { let expected_block_count = 1; - let padded_message = pad_message(&message,8, STATE_SIZE_512); + let padded_message = pad_message(&message, 8, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); assert_eq!(blocks.len(), expected_block_count); @@ -52,7 +51,7 @@ fn block_test_512() { let expected_block_count = 1; - let padded_message = pad_message(&message,512, STATE_SIZE_512); + let padded_message = pad_message(&message, 512, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -77,7 +76,7 @@ fn block_test_510() { let expected_block_count = 1; - let padded_message = pad_message(&message,510, STATE_SIZE_512); + let padded_message = pad_message(&message, 510, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -88,7 +87,6 @@ fn block_test_510() { for block in blocks { assert_eq!(block.len(), block_len); } - } #[test] @@ -107,7 +105,7 @@ fn block_test_1024() { let expected_block_count = 2; - let padded_message = pad_message(&message,1024, STATE_SIZE_512); + let padded_message = pad_message(&message, 1024, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -145,7 +143,7 @@ fn block_test_2048() { let expected_block_count = 3; - let padded_message = pad_message(&message,2048, STATE_SIZE_512); + let padded_message = pad_message(&message, 2048, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -178,7 +176,7 @@ fn block_test_1536() { let expected_block_count = 2; - let padded_message = pad_message(&message,1536, STATE_SIZE_512); + let padded_message = pad_message(&message, 1536, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -204,7 +202,7 @@ fn block_test_655() { let expected_block_count = 1; - let padded_message = pad_message(&message,655, STATE_SIZE_512); + let padded_message = pad_message(&message, 655, STATE_SIZE_512); let blocks = divide_into_blocks(&padded_message, STATE_SIZE_512); @@ -215,4 +213,4 @@ fn block_test_655() { for block in blocks { assert_eq!(block.len(), block_len); } -} \ No newline at end of file +} diff --git a/kupyna/src/tests/mod.rs b/kupyna/src/tests/mod.rs index 5071554b..7127e38a 100644 --- a/kupyna/src/tests/mod.rs +++ b/kupyna/src/tests/mod.rs @@ -1,3 +1,3 @@ -mod padding_tests; mod blocking_tests; mod hashing_tests; +mod padding_tests; diff --git a/kupyna/src/tests/padding_tests.rs b/kupyna/src/tests/padding_tests.rs index 95415088..f358f98a 100644 --- a/kupyna/src/tests/padding_tests.rs +++ b/kupyna/src/tests/padding_tests.rs @@ -18,7 +18,7 @@ fn pad_test_0() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,0, STATE_SIZE_512); + let padded_message = pad_message(&message, 0, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -39,7 +39,7 @@ fn pad_test_8() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,8, STATE_SIZE_512); + let padded_message = pad_message(&message, 8, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -66,7 +66,7 @@ fn pad_test_510() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,510, STATE_SIZE_512); + let padded_message = pad_message(&message, 510, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -93,7 +93,7 @@ fn pad_test_512() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,512, STATE_SIZE_512); + let padded_message = pad_message(&message, 512, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -133,7 +133,7 @@ fn pad_test_1024() { 0x00, ]; - let padded_message = pad_message(&message,1024, STATE_SIZE_512); + let padded_message = pad_message(&message, 1024, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -190,7 +190,7 @@ fn pad_test_2048() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,2048, STATE_SIZE_512); + let padded_message = pad_message(&message, 2048, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -234,7 +234,7 @@ fn pad_test_1536() { 0x00, ]; - let padded_message = pad_message(&message,1536, STATE_SIZE_512); + let padded_message = pad_message(&message, 1536, STATE_SIZE_512); assert_eq!(padded_message, expected_output); } @@ -262,7 +262,7 @@ fn pad_test_655() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let padded_message = pad_message(&message,655, STATE_SIZE_512); + let padded_message = pad_message(&message, 655, STATE_SIZE_512); assert_eq!(padded_message, expected_output); }