Skip to content

Commit 65e7ede

Browse files
jedisct1alexrp
authored andcommitted
crypto.Ed25519.KeyPair: return an error rather than assert
When runtime safety is turned on, `Ed25519.fromSecretKey()` can currently hit an assertion if the format of the secret key is invalid. Return an error instead, so that applications can recover.
1 parent 05d8b56 commit 65e7ede

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/std/crypto/25519/ed25519.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ pub const Ed25519 = struct {
299299
if (std.debug.runtime_safety) {
300300
const pk_p = try Curve.fromBytes(secret_key.publicKeyBytes());
301301
const recomputed_kp = try generateDeterministic(secret_key.seed());
302-
debug.assert(mem.eql(u8, &recomputed_kp.public_key.toBytes(), &pk_p.toBytes()));
302+
if (!mem.eql(u8, &recomputed_kp.public_key.toBytes(), &pk_p.toBytes())) {
303+
return error.NonCanonical;
304+
}
303305
}
304306
return KeyPair{
305307
.public_key = try PublicKey.fromBytes(secret_key.publicKeyBytes()),

0 commit comments

Comments
 (0)