-
Notifications
You must be signed in to change notification settings - Fork 0
test(tweak-aead): run the crate in CI and pin AVX2 against portable byte-for-byte #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b8edee9
test(tweak-aead): execute the AVX2 keystream in CI and pin it byte-fo…
Nexlab-One 98d7911
test(tweak-aead): raise the vector ceiling past the batched loop's 25…
Nexlab-One 021314e
test(tweak-aead): decouple deep-counter guard from key/nonce set count
Nexlab-One 81422fd
test(tweak-aead): mark the KAT nonces as deliberate for CodeQL
Nexlab-One File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,49 @@ | ||
| //! Dev-only: print hex for KAT (`cargo run -p lib-q-tweak-aead --example dump_tweak_kat`). | ||
| //! Dev-only: print hex for the KATs in `src/crypto.rs` | ||
| //! (`cargo run -p lib-q-tweak-aead --example dump_tweak_kat`). | ||
| //! | ||
| //! Run this WITHOUT `--features simd-avx2` when regenerating: the expected bytes must come from | ||
| //! the portable path so that the KAT is an independent oracle for the AVX2 path, not a recording | ||
| //! of it. | ||
| use lib_q_tweak_aead::params::{ | ||
| KEY_BYTES, | ||
| NONCE_BYTES, | ||
| TAG_BYTES, | ||
| }; | ||
|
|
||
| fn to_hex(b: &[u8]) -> String { | ||
| b.iter().map(|x| format!("{:02x}", x)).collect() | ||
| } | ||
|
|
||
| /// Inputs for `kat_encrypt_multi_block_293`, kept in one place so the test and this generator | ||
| /// cannot drift apart. See that test for why 293 bytes. | ||
| fn multi_block_inputs() -> ([u8; KEY_BYTES], [u8; NONCE_BYTES], &'static [u8], Vec<u8>) { | ||
| let mut key = [0u8; KEY_BYTES]; | ||
| for (i, k) in key.iter_mut().enumerate() { | ||
| *k = i as u8; | ||
| } | ||
| // Fixed by construction: this example regenerates the KAT expected bytes, so its inputs must | ||
| // match `kat_encrypt_multi_block_293` exactly. Never used to encrypt real data. | ||
| // codeql[rust/hard-coded-cryptographic-value] | ||
| let mut nonce = [0u8; NONCE_BYTES]; | ||
Check failureCode scanning / CodeQL Hard-coded cryptographic value Critical
This hard-coded value is used as
a nonce Error loading related location Loading |
||
| for (i, n) in nonce.iter_mut().enumerate() { | ||
| *n = 0x10 + i as u8; | ||
| } | ||
| let pt: Vec<u8> = (0..293).map(|i| i as u8).collect(); | ||
| (key, nonce, b"lib-q tweak-aead KAT", pt) | ||
| } | ||
|
|
||
| fn main() { | ||
| let key = [0u8; 32]; | ||
| let nonce = [0u8; 16]; | ||
| let mut out = [0u8; 4 + 32]; | ||
| // Same fixed inputs as the pre-existing `kat_encrypt_libq_empty_ad` vector, for the same | ||
| // reason: this regenerates that KAT, it does not encrypt anything real. | ||
| let key = [0u8; KEY_BYTES]; | ||
| // codeql[rust/hard-coded-cryptographic-value] | ||
| let nonce = [0u8; NONCE_BYTES]; | ||
Check failureCode scanning / CodeQL Hard-coded cryptographic value Critical
This hard-coded value is used as
a nonce Error loading related location Loading |
||
|
Nexlab-One marked this conversation as resolved.
Dismissed
|
||
| let mut out = [0u8; 4 + TAG_BYTES]; | ||
| lib_q_tweak_aead::crypto::encrypt(&key, &nonce, b"", b"libQ", &mut out).unwrap(); | ||
| println!("{}", to_hex(&out)); | ||
| println!("kat_encrypt_libq_empty_ad = {}", to_hex(&out)); | ||
|
|
||
| let (key, nonce, ad, pt) = multi_block_inputs(); | ||
| let mut out = vec![0u8; pt.len() + TAG_BYTES]; | ||
| lib_q_tweak_aead::crypto::encrypt(&key, &nonce, ad, &pt, &mut out).unwrap(); | ||
| println!("kat_encrypt_multi_block_293 = {}", to_hex(&out)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.