Skip to content

Commit

Permalink
add dilithium 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncolburne committed Aug 13, 2023
1 parent fb972b0 commit 9a83737
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/core/cigar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn validate_code(code: &str) -> Result<()> {
matter::Codex::ECDSA_256k1_Sig,
matter::Codex::ECDSA_256r1_Sig,
matter::Codex::CRYSTALS_Dilithium3_Sig,
matter::Codex::CRYSTALS_Dilithium5_Sig,
// matter::Codex::Ed448_Sig,
];

Expand Down
20 changes: 20 additions & 0 deletions src/core/indexer/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod Codex {
pub const ECDSA_256r1_Crt: &str = "F"; // ECDSA secp256r1 sig appears in current list.
pub const CRYSTALS_Dilithium3_Big: &str = "G"; // CRYSTALS Dilithium sig appears in both lists.
pub const CRYSTALS_Dilithium3_Big_Crt: &str = "H"; // CRYSTALS Dilithium sig appears in current list only.
pub const CRYSTALS_Dilithium5_Big: &str = "I"; // CRYSTALS Dilithium sig appears in both lists.
pub const CRYSTALS_Dilithium5_Big_Crt: &str = "J"; // CRYSTALS Dilithium sig appears in current list only.
pub const Ed448: &str = "0A"; // Ed448 signature appears in both lists.
pub const Ed448_Crt: &str = "0B"; // Ed448 signature appears in current list only.
pub const Ed25519_Big: &str = "2A"; // Ed25519 sig appears in both lists.
Expand All @@ -45,6 +47,8 @@ pub mod Codex {
pub const TBD4: &str = "4z"; // Test of index sig lead 1 big
pub const CRYSTALS_Dilithium3: &str = "1AAA"; // CRYSTALS Dilithium sig appears same in both lists if any.
pub const CRYSTALS_Dilithium3_Crt: &str = "1AAB"; // CRYSTALS Dilithium sig appears in current list.
pub const CRYSTALS_Dilithium5: &str = "1AAC"; // CRYSTALS Dilithium sig appears same in both lists if any.
pub const CRYSTALS_Dilithium5_Crt: &str = "1AAD"; // CRYSTALS Dilithium sig appears in current list.
}

/// SigCodex is all indexed signature derivation codes
Expand All @@ -59,6 +63,8 @@ pub mod SigCodex {
pub const ECDSA_256r1_Crt: &str = "F"; // ECDSA secp256r1 sig appears in current list.
pub const CRYSTALS_Dilithium3_Big: &str = "G"; // CRYSTALS Dilithium sig appears in both lists.
pub const CRYSTALS_Dilithium3_Big_Crt: &str = "H"; // CRYSTALS Dilithium sig appears in current list only.
pub const CRYSTALS_Dilithium5_Big: &str = "I"; // CRYSTALS Dilithium sig appears in both lists.
pub const CRYSTALS_Dilithium5_Big_Crt: &str = "J"; // CRYSTALS Dilithium sig appears in current list only.
pub const Ed448: &str = "0A"; // Ed448 signature appears in both lists.
pub const Ed448_Crt: &str = "0B"; // Ed448 signature appears in current list only.
pub const Ed25519_Big: &str = "2A"; // Ed25519 sig appears in both lists.
Expand All @@ -71,6 +77,8 @@ pub mod SigCodex {
pub const Ed448_Big_Crt: &str = "3B"; // Ed448 signature appears in current list only.
pub const CRYSTALS_Dilithium3: &str = "1AAA"; // CRYSTALS Dilithium sig appears same in both lists if any.
pub const CRYSTALS_Dilithium3_Crt: &str = "1AAB"; // CRYSTALS Dilithium sig appears in current list.
pub const CRYSTALS_Dilithium5: &str = "1AAC"; // CRYSTALS Dilithium sig appears same in both lists if any.
pub const CRYSTALS_Dilithium5_Crt: &str = "1AAD"; // CRYSTALS Dilithium sig appears in current list.
}

/// CurrentSigCodex is codex indexed signature codes for current list.
Expand All @@ -81,25 +89,29 @@ pub mod CurrentSigCodex {
pub const ECDSA_256k1_Crt: &str = "D"; // ECDSA secp256k1 sig appears in current list only.
pub const ECDSA_256r1_Crt: &str = "F"; // ECDSA secp256r1 sig appears in current list.
pub const CRYSTALS_Dilithium3_Big_Crt: &str = "H"; // CRYSTALS Dilithium sig appears in current list only.
pub const CRYSTALS_Dilithium5_Big_Crt: &str = "J"; // CRYSTALS Dilithium sig appears in current list only.
pub const Ed448_Crt: &str = "0B"; // Ed448 signature appears in current list only.
pub const Ed25519_Big_Crt: &str = "2B"; // Ed25519 sig appears in current list only.
pub const ECDSA_256k1_Big_Crt: &str = "2D"; // ECDSA secp256k1 sig appears in current list only.
pub const ECDSA_256r1_Big_Crt: &str = "2F"; // ECDSA secp256r1 sig appears in current list only.
pub const Ed448_Big_Crt: &str = "3B"; // Ed448 signature appears in current list only.
pub const CRYSTALS_Dilithium3_Crt: &str = "1AAB"; // CRYSTALS Dilithium sig appears in current list.
pub const CRYSTALS_Dilithium5_Crt: &str = "1AAD"; // CRYSTALS Dilithium sig appears in current list.

pub(crate) fn has_code(code: &str) -> bool {
const CODES: &[&str] = &[
Ed25519_Crt,
ECDSA_256k1_Crt,
ECDSA_256r1_Crt,
CRYSTALS_Dilithium3_Crt,
CRYSTALS_Dilithium5_Crt,
Ed448_Crt,
Ed25519_Big_Crt,
ECDSA_256k1_Big_Crt,
ECDSA_256r1_Big_Crt,
Ed448_Big_Crt,
CRYSTALS_Dilithium3_Big_Crt,
CRYSTALS_Dilithium5_Big_Crt,
];

CODES.contains(&code)
Expand All @@ -113,24 +125,28 @@ pub mod BothSigCodex {
pub const ECDSA_256k1: &str = "C"; // ECDSA secp256k1 sig appears same in both lists if any.
pub const ECDSA_256r1: &str = "E"; // ECDSA secp256r1 sig appears same in both lists if any.
pub const CRYSTALS_Dilithium3_Big: &str = "G"; // CRYSTALS Dilithium sig appears in both lists.
pub const CRYSTALS_Dilithium5_Big: &str = "I"; // CRYSTALS Dilithium sig appears in both lists.
pub const Ed448: &str = "0A"; // Ed448 signature appears in both lists.
pub const Ed25519_Big: &str = "2A"; // Ed25519 sig appears in both lists.
pub const ECDSA_256k1_Big: &str = "2C"; // ECDSA secp256k1 sig appears in both lists.
pub const ECDSA_256r1_Big: &str = "2E"; // ECDSA secp256r1 sig appears in both lists.
pub const Ed448_Big: &str = "3A"; // Ed448 signature appears in both lists.
pub const CRYSTALS_Dilithium3: &str = "1AAA"; // CRYSTALS Dilithium sig appears same in both lists if any.
pub const CRYSTALS_Dilithium5: &str = "1AAC"; // CRYSTALS Dilithium sig appears same in both lists if any.

pub(crate) fn has_code(code: &str) -> bool {
const CODES: &[&str] = &[
Ed25519,
ECDSA_256k1,
ECDSA_256r1,
CRYSTALS_Dilithium3,
CRYSTALS_Dilithium5,
Ed448,
Ed25519_Big,
ECDSA_256k1_Big,
ECDSA_256r1_Big,
CRYSTALS_Dilithium3_Big,
CRYSTALS_Dilithium5_Big,
Ed448_Big,
];

Expand Down Expand Up @@ -162,6 +178,8 @@ pub(crate) fn sizage(s: &str) -> Result<Sizage> {
"F" => Sizage { hs: 1, ss: 1, os: 0, fs: 88, ls: 0 },
"G" => Sizage { hs: 1, ss: 4, os: 2, fs: 4396, ls: 0 },
"H" => Sizage { hs: 1, ss: 4, os: 2, fs: 4396, ls: 0 },
"I" => Sizage { hs: 1, ss: 4, os: 2, fs: 6132, ls: 0 },
"J" => Sizage { hs: 1, ss: 4, os: 2, fs: 6132, ls: 0 },
"0A" => Sizage { hs: 2, ss: 2, os: 1, fs: 156, ls: 0 },
"0B" => Sizage { hs: 2, ss: 2, os: 1, fs: 156, ls: 0 },
"2A" => Sizage { hs: 2, ss: 4, os: 2, fs: 92, ls: 0 },
Expand All @@ -177,6 +195,8 @@ pub(crate) fn sizage(s: &str) -> Result<Sizage> {
"4z" => Sizage { hs: 2, ss: 6, os: 3, fs: 80, ls: 1 },
"1AAA" => Sizage { hs: 4, ss: 1, os: 0, fs: 4396, ls: 0 },
"1AAB" => Sizage { hs: 4, ss: 1, os: 0, fs: 4396, ls: 0 },
"1AAC" => Sizage { hs: 4, ss: 1, os: 0, fs: 6132, ls: 0 },
"1AAD" => Sizage { hs: 4, ss: 1, os: 0, fs: 6132, ls: 0 },
_ => return err!(Error::UnknownSizage(s.to_string())),
})
}
Expand Down
7 changes: 5 additions & 2 deletions src/core/matter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub trait Matter: Default {
tables::Codex::Ed448N,
tables::Codex::ECDSA_256r1N,
tables::Codex::CRYSTALS_Dilithium3N,
tables::Codex::CRYSTALS_Dilithium5N,
];

!CODES.contains(&self.code().as_str())
Expand Down Expand Up @@ -824,12 +825,14 @@ mod test {
#[case(TestMatter::new_with_code_and_raw(matter::Codex::ECDSA_256k1, b"000000000000000000000000000000000").unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::ECDSA_256r1, b"000000000000000000000000000000000").unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::Ed448, &[0u8; 57]).unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium3, &[0u8; 4000]).unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium3, &[0u8; 1952]).unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium5, &[0u8; 2592]).unwrap(), true)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::Ed25519N, b"00000000000000000000000000000000").unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::ECDSA_256k1N, b"000000000000000000000000000000000").unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::ECDSA_256r1N, b"000000000000000000000000000000000").unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::Ed448N, &[0u8; 57]).unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium3N, &[0u8; 4000]).unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium3N, &[0u8; 1952]).unwrap(), false)]
#[case(TestMatter::new_with_code_and_raw(matter::Codex::CRYSTALS_Dilithium5N, &[0u8; 2592]).unwrap(), false)]
fn transferable(#[case] matter: TestMatter, #[case] result: bool) {
assert_eq!(matter.transferable(), result);
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/siger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ fn validate_code(code: &str) -> Result<()> {
indexer::Codex::ECDSA_256r1_Crt,
indexer::Codex::CRYSTALS_Dilithium3,
indexer::Codex::CRYSTALS_Dilithium3_Crt,
indexer::Codex::CRYSTALS_Dilithium5,
indexer::Codex::CRYSTALS_Dilithium5_Crt,
// indexer::Codex::Ed448,
// indexer::Codex::Ed448_Crt,
indexer::Codex::Ed25519_Big,
Expand All @@ -43,6 +45,8 @@ fn validate_code(code: &str) -> Result<()> {
indexer::Codex::ECDSA_256r1_Big_Crt,
indexer::Codex::CRYSTALS_Dilithium3_Big,
indexer::Codex::CRYSTALS_Dilithium3_Big_Crt,
indexer::Codex::CRYSTALS_Dilithium5_Big,
indexer::Codex::CRYSTALS_Dilithium5_Big_Crt,
// indexer::Codex::Ed448_Big,
// indexer::Codex::Ed448_Big_Crt,
];
Expand Down
Loading

0 comments on commit 9a83737

Please sign in to comment.