Skip to content

Commit

Permalink
[crypto, test-only] Add a test for pubkey desetrialization errors,
Browse files Browse the repository at this point in the history
huitseeker authored and bors-libra committed Aug 24, 2020
1 parent 596b804 commit fbc97a7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crypto/crypto/src/unit_tests/ed25519_test.rs
Original file line number Diff line number Diff line change
@@ -275,6 +275,19 @@ proptest! {
prop_assert!(keypair.public_key == backconverted_ed_negative || keypair.public_key == backconverted_ed_positive);
}

#[test]
fn test_pub_key_deserialization(bits in any::<[u8; 32]>()){
let pt_deser = curve25519_dalek::edwards::CompressedEdwardsY(bits).decompress();
let pub_key = Ed25519PublicKey::try_from(&bits[..]);
let check = match (pt_deser, pub_key) {
(Some(_), Ok(_)) => true, // we agree with Dalek,
(Some(_), Err(CryptoMaterialError::SmallSubgroupError)) => true, // dalek does not detect pubkeys in a small subgroup,
(None, Err(CryptoMaterialError::DeserializationError)) => true, // we agree on point decompression failures,
_ => false
};
prop_assert!(check);
}

#[test]
fn test_keys_encode(keypair in uniform_keypair_strategy::<Ed25519PrivateKey, Ed25519PublicKey>()) {
{
@@ -366,6 +379,7 @@ proptest! {
prop_assert!(deserialized.verify(&hashable, &keypair.public_key).is_ok());
}


// Check for canonical S.
#[test]
fn test_signature_malleability(

0 comments on commit fbc97a7

Please sign in to comment.