| 1983686f Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
use crate::cbor::{self, Value}; |
| 8 |
use crate::hash::{hash_object, KeyId, ObjectRef, ObjectType}; |
| 75167672 Andy McCall |
9 |
use crate::objects::{ |
| 10 |
array, bytes, check_version, field, oref, text, uint, ObjectError, FORMAT_VERSION, |
| 11 |
}; |
| 1983686f Andy McCall ↶ |
12 |
use ed25519_dalek::ed25519::signature::Signer as _; |
| 75167672 Andy McCall |
13 |
use ed25519_dalek::{ |
| 14 |
Signature as EdSignature, SigningKey as EdSigningKey, VerifyingKey as EdVerifyingKey, |
| 15 |
}; |
| 16 |
use ml_dsa::{ |
| 17 |
EncodedSignature, EncodedVerifyingKey, MlDsa65, Seed, Signature as MlSignature, |
| 18 |
SigningKey as MlSigningKey, VerifyingKey as MlVerifyingKey, |
| 19 |
}; |
| 1983686f Andy McCall ↶ |
20 |
use rand::RngCore; |
| 21 |
|
| 22 |
pub const ED25519_PK_LEN: usize = 32; |
| 23 |
pub const MLDSA65_PK_LEN: usize = 1952; |
| 24 |
pub const ED25519_SIG_LEN: usize = 64; |
| 25 |
pub const MLDSA65_SIG_LEN: usize = 3309; |
| 26 |
|
| 27 |
pub const ALG_COMPOSITE: u64 = 1; |
| 28 |
|
| 29 |
#[derive(Clone, Debug, PartialEq, Eq)] |
| 30 |
pub struct Identity { |
| 31 |
pub ed25519_pk: [u8; ED25519_PK_LEN], |
| 32 |
pub mldsa65_pk: Vec<u8>, |
| 33 |
pub name: String, |
| 34 |
pub email: String, |
| 35 |
pub created: u64, |
| 36 |
pub expires: Option<u64>, |
| 37 |
pub previous: Option<KeyId>, |
| 38 |
pub delegates: Vec<KeyId>, |
| 39 |
} |
| 40 |
|
| 41 |
impl Identity { |
| 42 |
pub fn to_value(&self) -> Value { |
| 43 |
Value::map([ |
| 44 |
(0, Value::Uint(FORMAT_VERSION)), |
| 45 |
(1, Value::Bytes(self.ed25519_pk.to_vec())), |
| 46 |
(2, Value::Bytes(self.mldsa65_pk.clone())), |
| 47 |
(3, Value::Text(self.name.clone())), |
| 48 |
(4, Value::Text(self.email.clone())), |
| 49 |
(5, Value::Uint(self.created)), |
| 50 |
(6, self.expires.map(Value::Uint).unwrap_or(Value::Null)), |
| 75167672 Andy McCall |
51 |
( |
| 52 |
7, |
| 53 |
self.previous |
| 54 |
.map(|p| Value::Bytes(p.0.to_vec())) |
| 55 |
.unwrap_or(Value::Null), |
| 56 |
), |
| 57 |
( |
| 58 |
8, |
| 59 |
Value::Array( |
| 60 |
self.delegates |
| 61 |
.iter() |
| 62 |
.map(|d| Value::Bytes(d.0.to_vec())) |
| 63 |
.collect(), |
| 64 |
), |
| 65 |
), |
| 1983686f Andy McCall ↶ |
66 |
]) |
| 67 |
} |
| 68 |
pub fn encode(&self) -> Vec<u8> { |
| 69 |
cbor::encode(&self.to_value()) |
| 70 |
} |
| 71 |
pub fn hash(&self) -> KeyId { |
| 72 |
hash_object(ObjectType::Identity, &self.encode()) |
| 73 |
} |
| 74 |
pub fn decode(b: &[u8]) -> Result<Identity, ObjectError> { |
| 75 |
let v = cbor::decode(b)?; |
| 75167672 Andy McCall |
76 |
let m = v |
| 77 |
.as_map() |
| 78 |
.ok_or_else(|| ObjectError::Schema("identity: expected map".into()))?; |
| 1983686f Andy McCall ↶ |
79 |
check_version(m)?; |
| 80 |
let ed = bytes(field(m, 1, "ed25519_pk")?, "ed25519_pk")?; |
| 81 |
let ml = bytes(field(m, 2, "mldsa65_pk")?, "mldsa65_pk")?; |
| 82 |
if ed.len() != ED25519_PK_LEN || ml.len() != MLDSA65_PK_LEN { |
| 75167672 Andy McCall |
83 |
return Err(ObjectError::Schema( |
| 84 |
"identity: wrong public key length".into(), |
| 85 |
)); |
| 1983686f Andy McCall ↶ |
86 |
} |
| 75167672 Andy McCall |
87 |
let opt_u = |v: &Value| -> Result<Option<u64>, ObjectError> { |
| 88 |
if v.is_null() { |
| 89 |
Ok(None) |
| 90 |
} else { |
| 91 |
uint(v, "expires").map(Some) |
| 92 |
} |
| 93 |
}; |
| 94 |
let opt_r = |v: &Value| -> Result<Option<KeyId>, ObjectError> { |
| 95 |
if v.is_null() { |
| 96 |
Ok(None) |
| 97 |
} else { |
| 98 |
oref(v, "previous").map(Some) |
| 99 |
} |
| 100 |
}; |
| 101 |
let mut delegates = array(field(m, 8, "delegates")?, "delegates")? |
| 102 |
.iter() |
| 103 |
.map(|d| oref(d, "delegate")) |
| 104 |
.collect::<Result<Vec<_>, _>>()?; |
| 1983686f Andy McCall ↶ |
105 |
delegates.sort(); |
| 106 |
delegates.dedup(); |
| 107 |
Ok(Identity { |
| 108 |
ed25519_pk: ed.try_into().unwrap(), |
| 109 |
mldsa65_pk: ml.to_vec(), |
| 110 |
name: text(field(m, 3, "name")?, "name")?.to_owned(), |
| 111 |
email: text(field(m, 4, "email")?, "email")?.to_owned(), |
| 112 |
created: uint(field(m, 5, "created")?, "created")?, |
| 113 |
expires: opt_u(field(m, 6, "expires")?)?, |
| 114 |
previous: opt_r(field(m, 7, "previous")?)?, |
| 115 |
delegates, |
| 116 |
}) |
| 117 |
} |
| 118 |
|
| 28fc23d7 Andy McCall ↶ |
119 |
|
| 120 |
pub fn is_expired_at(&self, now_ms: u64) -> bool { |
| 121 |
self.expires.is_some_and(|e| now_ms > e) |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
pub fn successor(&self, delegates: Vec<KeyId>, expires: Option<u64>, created: u64) -> Identity { |
| 127 |
let mut delegates = delegates; |
| 128 |
delegates.sort(); |
| 129 |
delegates.dedup(); |
| 75167672 Andy McCall |
130 |
Identity { |
| 131 |
previous: Some(self.hash()), |
| 132 |
delegates, |
| 133 |
expires, |
| 134 |
created, |
| 135 |
..self.clone() |
| 136 |
} |
| 28fc23d7 Andy McCall ↶ |
137 |
} |
| 138 |
|
| 1983686f Andy McCall ↶ |
139 |
fn ed_key(&self) -> Result<EdVerifyingKey, VerifyError> { |
| 140 |
EdVerifyingKey::from_bytes(&self.ed25519_pk).map_err(|_| VerifyError::BadKey) |
| 141 |
} |
| 142 |
fn ml_key(&self) -> Result<MlVerifyingKey<MlDsa65>, VerifyError> { |
| 75167672 Andy McCall |
143 |
let enc = EncodedVerifyingKey::<MlDsa65>::try_from(self.mldsa65_pk.as_slice()) |
| 144 |
.map_err(|_| VerifyError::BadKey)?; |
| 1983686f Andy McCall ↶ |
145 |
Ok(MlVerifyingKey::decode(&enc)) |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 150 |
pub enum Domain { |
| 151 |
Change, |
| 152 |
Attest, |
| 83e0677b Andy McCall ↶ |
153 |
Policy, |
| 1983686f Andy McCall ↶ |
154 |
} |
| 155 |
|
| 156 |
impl Domain { |
| 157 |
pub fn name(self) -> &'static str { |
| 158 |
match self { |
| 159 |
Domain::Change => "change", |
| 160 |
Domain::Attest => "attest", |
| 83e0677b Andy McCall ↶ |
161 |
Domain::Policy => "policy", |
| 1983686f Andy McCall ↶ |
162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
pub fn signing_message(domain: Domain, key: &KeyId, target: &ObjectRef) -> Vec<u8> { |
| 168 |
let mut m = Vec::with_capacity(80); |
| 169 |
m.extend_from_slice(b"oxy1 sig "); |
| 170 |
m.extend_from_slice(domain.name().as_bytes()); |
| 171 |
m.push(0); |
| 172 |
m.extend_from_slice(&key.0); |
| 173 |
m.extend_from_slice(&target.0); |
| 174 |
m |
| 175 |
} |
| 176 |
|
| 177 |
#[derive(Clone, PartialEq, Eq)] |
| 178 |
pub struct Signature { |
| 179 |
pub key: KeyId, |
| 180 |
pub ed: [u8; ED25519_SIG_LEN], |
| 181 |
pub ml: Vec<u8>, |
| 182 |
} |
| 183 |
|
| 184 |
impl std::fmt::Debug for Signature { |
| 185 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 186 |
write!(f, "Signature(key {:?})", self.key) |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
impl Signature { |
| 191 |
pub fn to_value(&self) -> Value { |
| 192 |
Value::map([ |
| 193 |
(0, Value::Bytes(self.key.0.to_vec())), |
| 194 |
(1, Value::Uint(ALG_COMPOSITE)), |
| 195 |
(2, Value::Bytes(self.ed.to_vec())), |
| 196 |
(3, Value::Bytes(self.ml.clone())), |
| 197 |
]) |
| 198 |
} |
| 199 |
pub fn from_value(v: &Value) -> Result<Signature, ObjectError> { |
| 75167672 Andy McCall |
200 |
let m = v |
| 201 |
.as_map() |
| 202 |
.ok_or_else(|| ObjectError::Schema("signature: expected map".into()))?; |
| 1983686f Andy McCall ↶ |
203 |
let alg = uint(field(m, 1, "alg")?, "alg")?; |
| 204 |
if alg != ALG_COMPOSITE { |
| 75167672 Andy McCall |
205 |
return Err(ObjectError::Schema(format!( |
| 206 |
"unknown signature algorithm {alg}" |
| 207 |
))); |
| 1983686f Andy McCall ↶ |
208 |
} |
| 209 |
let ed = bytes(field(m, 2, "ed")?, "ed")?; |
| 210 |
let ml = bytes(field(m, 3, "ml")?, "ml")?; |
| 211 |
if ed.len() != ED25519_SIG_LEN || ml.len() != MLDSA65_SIG_LEN { |
| 212 |
return Err(ObjectError::Schema("signature: wrong length".into())); |
| 213 |
} |
| 75167672 Andy McCall |
214 |
Ok(Signature { |
| 215 |
key: oref(field(m, 0, "key")?, "key")?, |
| 216 |
ed: ed.try_into().unwrap(), |
| 217 |
ml: ml.to_vec(), |
| 218 |
}) |
| 1983686f Andy McCall ↶ |
219 |
} |
| 220 |
pub fn encode_list(sigs: &[Signature]) -> Vec<u8> { |
| 221 |
cbor::encode(&Value::Array(sigs.iter().map(|s| s.to_value()).collect())) |
| 222 |
} |
| 223 |
pub fn decode_list(b: &[u8]) -> Result<Vec<Signature>, ObjectError> { |
| 224 |
let v = cbor::decode(b)?; |
| 75167672 Andy McCall |
225 |
array(&v, "signatures")? |
| 226 |
.iter() |
| 227 |
.map(Signature::from_value) |
| 228 |
.collect() |
| 1983686f Andy McCall ↶ |
229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)] |
| 233 |
pub enum VerifyError { |
| 234 |
#[error("signature names a different key than the identity")] |
| 235 |
KeyMismatch, |
| 236 |
#[error("identity holds a malformed public key")] |
| 237 |
BadKey, |
| 238 |
#[error("Ed25519 signature invalid")] |
| 239 |
Ed25519, |
| 240 |
#[error("ML-DSA-65 signature invalid")] |
| 241 |
MlDsa, |
| 242 |
} |
| 243 |
|
| 244 |
|
| 75167672 Andy McCall |
245 |
pub fn verify( |
| 246 |
identity: &Identity, |
| 247 |
sig: &Signature, |
| 248 |
domain: Domain, |
| 249 |
target: &ObjectRef, |
| 250 |
) -> Result<(), VerifyError> { |
| 1983686f Andy McCall ↶ |
251 |
let key = identity.hash(); |
| 252 |
if sig.key != key { |
| 253 |
return Err(VerifyError::KeyMismatch); |
| 254 |
} |
| 255 |
let msg = signing_message(domain, &key, target); |
| 256 |
let ed_sig = EdSignature::from_bytes(&sig.ed); |
| 75167672 Andy McCall |
257 |
identity |
| 258 |
.ed_key()? |
| 259 |
.verify_strict(&msg, &ed_sig) |
| 260 |
.map_err(|_| VerifyError::Ed25519)?; |
| 261 |
let enc = |
| 262 |
EncodedSignature::<MlDsa65>::try_from(sig.ml.as_slice()).map_err(|_| VerifyError::MlDsa)?; |
| 1983686f Andy McCall ↶ |
263 |
let ml_sig = MlSignature::<MlDsa65>::decode(&enc).ok_or(VerifyError::MlDsa)?; |
| 264 |
if !identity.ml_key()?.verify_with_context(&msg, b"", &ml_sig) { |
| 265 |
return Err(VerifyError::MlDsa); |
| 266 |
} |
| 267 |
Ok(()) |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
#[derive(Clone)] |
| 272 |
pub struct SecretKey { |
| 273 |
pub ed_seed: [u8; 32], |
| 274 |
pub ml_seed: [u8; 32], |
| 275 |
} |
| 276 |
|
| 277 |
impl std::fmt::Debug for SecretKey { |
| 278 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 279 |
f.write_str("SecretKey(..)") |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
impl SecretKey { |
| 284 |
pub fn generate() -> SecretKey { |
| 285 |
let mut ed_seed = [0u8; 32]; |
| 286 |
let mut ml_seed = [0u8; 32]; |
| 287 |
rand::rngs::OsRng.fill_bytes(&mut ed_seed); |
| 288 |
rand::rngs::OsRng.fill_bytes(&mut ml_seed); |
| 289 |
SecretKey { ed_seed, ml_seed } |
| 290 |
} |
| 291 |
|
| 292 |
fn ed(&self) -> EdSigningKey { |
| 293 |
EdSigningKey::from_bytes(&self.ed_seed) |
| 294 |
} |
| 295 |
fn ml(&self) -> MlSigningKey<MlDsa65> { |
| 296 |
MlSigningKey::from_seed(&Seed::from(self.ml_seed)) |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
pub fn identity(&self, name: &str, email: &str, created: u64) -> Identity { |
| 301 |
Identity { |
| 302 |
ed25519_pk: self.ed().verifying_key().to_bytes(), |
| 75167672 Andy McCall |
303 |
mldsa65_pk: self |
| 304 |
.ml() |
| 305 |
.expanded_key() |
| 306 |
.verifying_key() |
| 307 |
.encode() |
| 308 |
.as_slice() |
| 309 |
.to_vec(), |
| 1983686f Andy McCall ↶ |
310 |
name: name.into(), |
| 311 |
email: email.into(), |
| 312 |
created, |
| 313 |
expires: None, |
| 314 |
previous: None, |
| 315 |
delegates: vec![], |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
pub fn sign(&self, domain: Domain, key: &KeyId, target: &ObjectRef) -> Signature { |
| 320 |
let msg = signing_message(domain, key, target); |
| 321 |
let ed = self.ed().sign(&msg).to_bytes(); |
| 75167672 Andy McCall |
322 |
let ml = self |
| 323 |
.ml() |
| 324 |
.expanded_key() |
| 325 |
.sign_deterministic(&msg, b"") |
| 326 |
.expect("empty context is valid") |
| 327 |
.encode() |
| 328 |
.as_slice() |
| 329 |
.to_vec(); |
| 1983686f Andy McCall ↶ |
330 |
Signature { key: *key, ed, ml } |
| 331 |
} |
| 332 |
|
| 333 |
pub fn encode(&self, key: &KeyId) -> Vec<u8> { |
| 334 |
cbor::encode(&Value::map([ |
| 335 |
(0, Value::Uint(FORMAT_VERSION)), |
| 336 |
(1, Value::Bytes(key.0.to_vec())), |
| 337 |
(2, Value::Bytes(self.ed_seed.to_vec())), |
| 338 |
(3, Value::Bytes(self.ml_seed.to_vec())), |
| 339 |
])) |
| 340 |
} |
| 341 |
|
| 342 |
pub fn decode(b: &[u8]) -> Result<(KeyId, SecretKey), ObjectError> { |
| 343 |
let v = cbor::decode(b)?; |
| 75167672 Andy McCall |
344 |
let m = v |
| 345 |
.as_map() |
| 346 |
.ok_or_else(|| ObjectError::Schema("secret key: expected map".into()))?; |
| 1983686f Andy McCall ↶ |
347 |
check_version(m)?; |
| 348 |
let seed = |k: u64| -> Result<[u8; 32], ObjectError> { |
| 75167672 Andy McCall |
349 |
bytes(field(m, k, "seed")?, "seed")? |
| 350 |
.try_into() |
| 351 |
.map_err(|_| ObjectError::Schema("seed: expected 32 bytes".into())) |
| 1983686f Andy McCall ↶ |
352 |
}; |
| 75167672 Andy McCall |
353 |
Ok(( |
| 354 |
oref(field(m, 1, "key")?, "key")?, |
| 355 |
SecretKey { |
| 356 |
ed_seed: seed(2)?, |
| 357 |
ml_seed: seed(3)?, |
| 358 |
}, |
| 359 |
)) |
| 1983686f Andy McCall ↶ |
360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
#[cfg(test)] |
| 364 |
mod tests { |
| 365 |
use super::*; |
| 366 |
|
| 367 |
fn fixed_key() -> SecretKey { |
| 75167672 Andy McCall |
368 |
SecretKey { |
| 369 |
ed_seed: [1; 32], |
| 370 |
ml_seed: [2; 32], |
| 371 |
} |
| 1983686f Andy McCall ↶ |
372 |
} |
| 373 |
|
| 374 |
#[test] |
| 375 |
fn identity_round_trip_and_sizes() { |
| 376 |
let sk = fixed_key(); |
| 377 |
let id = sk.identity("Ada", "[email protected]", 1_700_000_000_000); |
| 378 |
assert_eq!(id.mldsa65_pk.len(), MLDSA65_PK_LEN); |
| 379 |
let d = Identity::decode(&id.encode()).unwrap(); |
| 380 |
assert_eq!(d, id); |
| 381 |
assert_eq!(d.hash(), id.hash()); |
| 382 |
|
| 75167672 Andy McCall |
383 |
assert_eq!( |
| 384 |
fixed_key() |
| 385 |
.identity("Ada", "[email protected]", 1_700_000_000_000) |
| 386 |
.hash(), |
| 387 |
id.hash() |
| 388 |
); |
| 1983686f Andy McCall ↶ |
389 |
let mut other = id.clone(); |
| 390 |
other.delegates.push(ObjectRef([9; 32])); |
| 391 |
assert_ne!(other.hash(), id.hash()); |
| 392 |
} |
| 393 |
|
| 394 |
#[test] |
| 395 |
fn sign_and_verify() { |
| 396 |
let sk = fixed_key(); |
| 397 |
let id = sk.identity("Ada", "[email protected]", 1); |
| 398 |
let key = id.hash(); |
| 399 |
let target = ObjectRef([7; 32]); |
| 400 |
let sig = sk.sign(Domain::Change, &key, &target); |
| 401 |
assert_eq!(sig.ml.len(), MLDSA65_SIG_LEN); |
| 402 |
assert_eq!(verify(&id, &sig, Domain::Change, &target), Ok(())); |
| 403 |
|
| 75167672 Andy McCall |
404 |
assert_eq!( |
| 405 |
verify(&id, &sig, Domain::Change, &ObjectRef([8; 32])), |
| 406 |
Err(VerifyError::Ed25519) |
| 407 |
); |
| 408 |
assert_eq!( |
| 409 |
verify(&id, &sig, Domain::Attest, &target), |
| 410 |
Err(VerifyError::Ed25519) |
| 411 |
); |
| 1983686f Andy McCall ↶ |
412 |
|
| 413 |
assert_eq!(sk.sign(Domain::Change, &key, &target), sig); |
| 414 |
|
| 75167672 Andy McCall |
415 |
let l = |
| 416 |
Signature::decode_list(&Signature::encode_list(std::slice::from_ref(&sig))).unwrap(); |
| 1983686f Andy McCall ↶ |
417 |
assert_eq!(l, vec![sig]); |
| 418 |
} |
| 419 |
|
| 420 |
#[test] |
| 421 |
fn stripping_or_forging_either_half_fails() { |
| 422 |
let sk = fixed_key(); |
| 423 |
let id = sk.identity("Ada", "a@b", 1); |
| 424 |
let key = id.hash(); |
| 425 |
let target = ObjectRef([7; 32]); |
| 426 |
let good = sk.sign(Domain::Change, &key, &target); |
| 427 |
|
| 428 |
let mut no_ml = good.clone(); |
| 429 |
no_ml.ml = vec![0; MLDSA65_SIG_LEN]; |
| 75167672 Andy McCall |
430 |
assert_eq!( |
| 431 |
verify(&id, &no_ml, Domain::Change, &target), |
| 432 |
Err(VerifyError::MlDsa) |
| 433 |
); |
| 1983686f Andy McCall ↶ |
434 |
|
| 435 |
let mut bad_ed = good.clone(); |
| 436 |
bad_ed.ed[10] ^= 1; |
| 75167672 Andy McCall |
437 |
assert_eq!( |
| 438 |
verify(&id, &bad_ed, Domain::Change, &target), |
| 439 |
Err(VerifyError::Ed25519) |
| 440 |
); |
| 1983686f Andy McCall ↶ |
441 |
|
| 442 |
|
| 75167672 Andy McCall |
443 |
let other = SecretKey { |
| 444 |
ed_seed: [3; 32], |
| 445 |
ml_seed: [4; 32], |
| 446 |
}; |
| 1983686f Andy McCall ↶ |
447 |
let other_id = other.identity("Bob", "b@b", 1); |
| 448 |
let theirs = other.sign(Domain::Change, &other_id.hash(), &target); |
| 75167672 Andy McCall |
449 |
assert_eq!( |
| 450 |
verify(&id, &theirs, Domain::Change, &target), |
| 451 |
Err(VerifyError::KeyMismatch) |
| 452 |
); |
| 1983686f Andy McCall ↶ |
453 |
let mut relabelled = theirs.clone(); |
| 454 |
relabelled.key = key; |
| 75167672 Andy McCall |
455 |
assert_eq!( |
| 456 |
verify(&id, &relabelled, Domain::Change, &target), |
| 457 |
Err(VerifyError::Ed25519) |
| 458 |
); |
| 1983686f Andy McCall ↶ |
459 |
|
| 460 |
|
| 461 |
let mut short = good.to_value(); |
| 462 |
if let Value::Map(m) = &mut short { |
| 463 |
m.insert(3, Value::Bytes(vec![0; 10])); |
| 464 |
} |
| 465 |
assert!(Signature::from_value(&short).is_err()); |
| 466 |
} |
| 467 |
|
| 468 |
#[test] |
| 469 |
fn secret_key_round_trip() { |
| 470 |
let sk = fixed_key(); |
| 471 |
let key = sk.identity("x", "y", 0).hash(); |
| 472 |
let (k, d) = SecretKey::decode(&sk.encode(&key)).unwrap(); |
| 473 |
assert_eq!(k, key); |
| 474 |
assert_eq!(d.ed_seed, sk.ed_seed); |
| 475 |
assert_eq!(d.ml_seed, sk.ml_seed); |
| 476 |
assert_ne!(SecretKey::generate().ed_seed, SecretKey::generate().ed_seed); |
| 477 |
} |
| 478 |
} |