#[cfg(test)]
mod tests {
use crate::{
traits::FromLeBytes,
utils::{
crypto::key::{X25519PrivateKey, X25519PublicKey},
curve_point::CurvePoint,
field::{BaseField, ScalarField},
},
};
#[test]
fn test_get_public_key() {
let test_data: [([u8; 32], [u8; 32]); 5] = [
(
[
40, 133, 122, 137, 100, 153, 102, 182, 168, 115, 88, 34, 139, 33, 94, 220, 131,
167, 202, 175, 18, 243, 146, 123, 80, 39, 196, 52, 151, 87, 253, 94,
],
[
128, 115, 79, 117, 240, 56, 206, 252, 74, 133, 102, 251, 21, 180, 198, 62, 199,
248, 128, 190, 52, 67, 188, 26, 107, 14, 236, 75, 128, 14, 92, 101,
],
),
(
[
103, 101, 169, 238, 167, 240, 147, 174, 236, 81, 42, 249, 69, 99, 155, 248, 94,
223, 205, 168, 153, 65, 66, 35, 133, 140, 236, 68, 48, 219, 216, 75,
],
[
54, 51, 168, 111, 241, 18, 1, 195, 243, 216, 23, 186, 213, 39, 232, 134, 108,
18, 158, 149, 103, 106, 112, 130, 233, 149, 102, 36, 142, 157, 195, 80,
],
),
(
[
156, 208, 141, 171, 251, 65, 120, 26, 101, 140, 37, 10, 43, 25, 206, 63, 2, 8,
226, 161, 62, 34, 53, 224, 44, 144, 245, 17, 51, 115, 13, 194,
],
[
116, 104, 58, 59, 239, 83, 16, 249, 76, 235, 160, 197, 223, 52, 225, 9, 50,
114, 122, 149, 158, 148, 75, 47, 251, 233, 59, 66, 22, 100, 2, 47,
],
),
(
[
93, 62, 49, 95, 108, 38, 133, 80, 60, 189, 7, 179, 250, 202, 53, 107, 159, 101,
88, 108, 38, 120, 178, 152, 14, 171, 66, 30, 219, 213, 233, 140,
],
[
9, 234, 7, 56, 151, 4, 239, 46, 111, 105, 50, 173, 189, 10, 41, 158, 34, 100,
178, 99, 67, 13, 149, 9, 4, 139, 217, 45, 62, 253, 182, 1,
],
),
(
[
159, 131, 199, 155, 47, 64, 100, 24, 186, 230, 173, 56, 87, 137, 173, 118, 68,
37, 88, 20, 117, 108, 87, 11, 167, 239, 133, 57, 235, 122, 16, 238,
],
[
205, 104, 97, 219, 73, 89, 119, 42, 237, 127, 47, 222, 77, 203, 82, 49, 97, 21,
242, 44, 104, 77, 109, 141, 78, 77, 25, 54, 179, 176, 75, 13,
],
),
];
test_data
.into_iter()
.for_each(|(private_key_bytes, expected)| {
let private_key = X25519PrivateKey::<ScalarField>::from_le_bytes(private_key_bytes);
let res = X25519PublicKey::<CurvePoint>::new_from_private_key(private_key)
.to_montgomery()
.0;
let expected = BaseField::from_le_bytes(expected);
assert_eq!(res, expected)
});
}
}