@@ -351,6 +351,26 @@ impl Ed25519KeyPair {
351
351
/// # Errors
352
352
/// `error::KeyRejected` if parse error, or if key is otherwise unacceptable.
353
353
pub fn from_seed_and_public_key ( seed : & [ u8 ] , public_key : & [ u8 ] ) -> Result < Self , KeyRejected > {
354
+ let this = Self :: from_seed_unchecked ( seed) ?;
355
+
356
+ constant_time:: verify_slices_are_equal ( public_key, & this. public_key . public_key_bytes )
357
+ . map_err ( |_| KeyRejected :: inconsistent_components ( ) ) ?;
358
+ Ok ( this)
359
+ }
360
+
361
+ /// Constructs an Ed25519 key pair from the private key seed `seed`.
362
+ ///
363
+ /// It is recommended to use `Ed25519KeyPair::from_pkcs8()` instead. If the public key is
364
+ /// available, prefer to use `Ed25519KeyPair::from_seed_and_public_key()` as it will verify
365
+ /// the validity of the key pair.
366
+ ///
367
+ /// CAUTION: Both an Ed25519 seed and its public key are 32-bytes. If the bytes of a public key
368
+ /// are provided this function will create an (effectively) invalid `Ed25519KeyPair`. This
369
+ /// problem is undetectable by the API.
370
+ ///
371
+ /// # Errors
372
+ /// `error::KeyRejected` if parse error, or if key is otherwise unacceptable.
373
+ pub fn from_seed_unchecked ( seed : & [ u8 ] ) -> Result < Self , KeyRejected > {
354
374
if seed. len ( ) < ED25519_SEED_LEN {
355
375
return Err ( KeyRejected :: inconsistent_components ( ) ) ;
356
376
}
@@ -372,9 +392,6 @@ impl Ed25519KeyPair {
372
392
}
373
393
debug_assert_eq ! ( derived_public_key. len( ) , out_len) ;
374
394
375
- constant_time:: verify_slices_are_equal ( public_key, & derived_public_key)
376
- . map_err ( |_| KeyRejected :: inconsistent_components ( ) ) ?;
377
-
378
395
Ok ( Self {
379
396
public_key : PublicKey {
380
397
public_key_bytes : derived_public_key,
0 commit comments