Skip to content

Commit

Permalink
rfc6979: add P-521 + SHA-512 test vectors
Browse files Browse the repository at this point in the history
These now work after #781
  • Loading branch information
tarcieri committed Jan 17, 2024
1 parent f6426cf commit 605fdd3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
33 changes: 31 additions & 2 deletions rfc6979/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ where

#[cfg(test)]
mod tests {
use crate::{consts::U21, generate_k};
use crate::{
consts::{U21, U66},
generate_k, Array,
};
use hex_literal::hex;
use sha2::Sha256;
use sha2::{Digest, Sha256, Sha512};

/// "Detailed Example" from RFC6979 Appendix A.1.
///
Expand All @@ -181,4 +184,30 @@ mod tests {
let k = generate_k::<Sha256, U21>(&x.into(), &q.into(), &h2.into(), aad);
assert_eq!(k, hex!("023AF4074C90A02B3FE61D286D5C87F425E6BDD81B"));
}

/// Example from RFC6979 Appendix A.2.7.
#[test]
fn p521_sha512() {
let q = hex!(
"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409"
);

let x = hex!(
"00FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75CAA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83538"
);

// Hash message and emulate `bits2octets` to produce the input digest
let message = "sample";
let mut h = Array::<u8, U66>::default();
h[2..].copy_from_slice(&Sha512::digest(message));

let aad = b"";
let k = generate_k::<Sha512, U66>(&x.into(), &q.into(), &h.into(), aad);

let expected_k = hex!(
"01DAE2EA071F8110DC26882D4D5EAE0621A3256FC8847FB9022E2B7D28E6F10198B1574FDD03A9053C08A1854A168AA5A57470EC97DD5CE090124EF52A2F7ECBFFD3"
);

assert_eq!(k, expected_k);
}
}
14 changes: 0 additions & 14 deletions rfc6979/tests/lib.rs

This file was deleted.

0 comments on commit 605fdd3

Please sign in to comment.