mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Fill in missing Serde impl for MontgomeryPoint.
This commit is contained in:
parent
0fc534d989
commit
70e46c9826
2 changed files with 18 additions and 1 deletions
|
|
@ -42,7 +42,7 @@ byteorder = { version = "^1.2.3", default-features = false, features = ["i128"]
|
|||
digest = { version = "0.8", default-features = false }
|
||||
clear_on_drop = "=0.2.3"
|
||||
subtle = { version = "2", default-features = false }
|
||||
serde = { version = "1.0", default-features = false, optional = true }
|
||||
serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] }
|
||||
packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true }
|
||||
|
||||
[features]
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ use subtle::ConstantTimeEq;
|
|||
/// Holds the \\(u\\)-coordinate of a point on the Montgomery form of
|
||||
/// Curve25519 or its twist.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct MontgomeryPoint(pub [u8; 32]);
|
||||
|
||||
/// Equality of `MontgomeryPoint`s is defined mod p.
|
||||
|
|
@ -312,6 +313,22 @@ mod test {
|
|||
#[cfg(feature = "rand")]
|
||||
use rand_os::OsRng;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serde_bincode_basepoint_roundtrip() {
|
||||
use bincode;
|
||||
|
||||
let encoded = bincode::serialize(&constants::X25519_BASEPOINT).unwrap();
|
||||
let decoded: MontgomeryPoint = bincode::deserialize(&encoded).unwrap();
|
||||
|
||||
assert_eq!(encoded.len(), 32);
|
||||
assert_eq!(decoded, constants::X25519_BASEPOINT);
|
||||
|
||||
let raw_bytes = constants::X25519_BASEPOINT.as_bytes();
|
||||
let bp: MontgomeryPoint = bincode::deserialize(raw_bytes).unwrap();
|
||||
assert_eq!(bp, constants::X25519_BASEPOINT);
|
||||
}
|
||||
|
||||
/// Test Montgomery -> Edwards on the X/Ed25519 basepoint
|
||||
#[test]
|
||||
fn basepoint_montgomery_to_edwards() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue