Skip to content

Commit 9ef822c

Browse files
fix: from_sec1_bytes should reject identity (#1747)
1 parent dba9714 commit 9ef822c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

extensions/ecc/guest/src/ecdsa.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ where
131131
let x = Coordinate::<C>::from_be_bytes(&bytes[1..]).ok_or_else(Error::new)?;
132132
let rec_id = bytes[0] & 1;
133133
let point = FromCompressed::decompress(x, &rec_id).ok_or_else(Error::new)?;
134+
// Decompressed point will never be identity
134135
Ok(Self { point })
135136
}
136137

@@ -139,7 +140,7 @@ where
139140
let x = Coordinate::<C>::from_be_bytes(x_bytes).ok_or_else(Error::new)?;
140141
let y = Coordinate::<C>::from_be_bytes(y_bytes).ok_or_else(Error::new)?;
141142
let point = <C as IntrinsicCurve>::Point::from_xy(x, y).ok_or_else(Error::new)?;
142-
Ok(Self { point })
143+
Self::from_affine(point)
143144
}
144145

145146
_ => Err(Error::new()),

extensions/ecc/tests/src/test_vectors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,9 @@ pub fn k256_sec1_decoding_test_vectors() -> Vec<Sec1DecodingTestVector> {
4747
bytes: hex!("04" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30" "4218f20ae6c646b363db68605822fb14264ca8d2587fdd6fbc750d587e76a7ee").to_vec(),
4848
ok: false,
4949
},
50+
Sec1DecodingTestVector {
51+
bytes: hex!("04" "0000000000000000000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000000000").to_vec(),
52+
ok: false,
53+
}
5054
]
5155
}

0 commit comments

Comments
 (0)