Skip to content

Commit 1031702

Browse files
authored
Merge pull request #7 from doublegate/dependabot/cargo/rand-0.9
deps(deps): Update rand requirement from 0.8 to 0.9
2 parents 45c3dc7 + 5ff42b6 commit 1031702

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ x25519-dalek = { version = "2.0", features = ["static_secrets"] }
5050
ed25519-dalek = { version = "2.1", features = ["rand_core"] }
5151
blake3 = "1.5"
5252
snow = "0.9"
53-
rand = "0.8"
53+
rand = "0.9"
54+
rand_core = "0.6"
5455
zeroize = { version = "1.7", features = ["derive"] }
5556
getrandom = "0.2"
5657

crates/wraith-crypto/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ x25519-dalek = { workspace = true }
1414
ed25519-dalek = { workspace = true }
1515
blake3 = { workspace = true }
1616
snow = { workspace = true }
17-
rand = { workspace = true }
17+
rand_core = { workspace = true }
1818
zeroize = { workspace = true }
1919
getrandom = { workspace = true }
2020
thiserror = { workspace = true }

crates/wraith-crypto/src/elligator.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! making key exchange indistinguishable from random data.
55
66
use crate::CryptoError;
7+
use rand_core::OsRng;
78

89
/// Elligator2 representative (encoded public key)
910
pub struct Representative([u8; 32]);
@@ -28,7 +29,7 @@ pub fn generate_encodable_keypair()
2829
-> Result<(x25519_dalek::StaticSecret, Representative), CryptoError> {
2930
// TODO: Implement proper Elligator2 encoding
3031
// For now, return a placeholder
31-
let secret = x25519_dalek::StaticSecret::random_from_rng(rand::thread_rng());
32+
let secret = x25519_dalek::StaticSecret::random_from_rng(OsRng);
3233
let public = x25519_dalek::PublicKey::from(&secret);
3334

3435
// Placeholder: just use the public key bytes
@@ -42,3 +43,46 @@ pub fn decode_representative(repr: &Representative) -> x25519_dalek::PublicKey {
4243
// For now, treat representative as raw public key bytes
4344
x25519_dalek::PublicKey::from(repr.0)
4445
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
use super::*;
50+
51+
#[test]
52+
fn test_generate_encodable_keypair() {
53+
// Test that keypair generation succeeds
54+
let result = generate_encodable_keypair();
55+
assert!(result.is_ok());
56+
57+
let (secret, representative) = result.unwrap();
58+
59+
// Verify representative has valid bytes
60+
let repr_bytes = representative.as_bytes();
61+
assert_eq!(repr_bytes.len(), 32);
62+
63+
// Verify the representative can be decoded back to a public key
64+
let decoded_public = decode_representative(&representative);
65+
66+
// The decoded public key should match the one derived from the secret
67+
let expected_public = x25519_dalek::PublicKey::from(&secret);
68+
assert_eq!(decoded_public.as_bytes(), expected_public.as_bytes());
69+
}
70+
71+
#[test]
72+
fn test_representative_roundtrip() {
73+
// Test Representative from_bytes and as_bytes
74+
let original_bytes = [0x42u8; 32];
75+
let repr = Representative::from_bytes(original_bytes);
76+
assert_eq!(repr.as_bytes(), &original_bytes);
77+
}
78+
79+
#[test]
80+
fn test_multiple_keypairs_are_unique() {
81+
// Generate multiple keypairs and verify they are different
82+
let (_, repr1) = generate_encodable_keypair().unwrap();
83+
let (_, repr2) = generate_encodable_keypair().unwrap();
84+
85+
// Representatives should be different (with overwhelming probability)
86+
assert_ne!(repr1.as_bytes(), repr2.as_bytes());
87+
}
88+
}

0 commit comments

Comments
 (0)