Skip to content

Commit 42b707b

Browse files
UdjinM6claude
andcommitted
fix: reject identity elements in deserialization and key generation
Reject BLS identity elements (point at infinity for G1/G2) at the deserialization boundary in SetBytes(). Also reject zero private keys in MakeNewKey(), though these would not pass further validation. Identity elements are mathematically valid curve points but have no legitimate use in the protocol. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e6a225 commit 42b707b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/bls/bls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void CBLSSecretKey::MakeNewKey()
6666
GetStrongRandBytes({buf, sizeof(buf)});
6767
try {
6868
impl = bls::PrivateKey::FromBytes(bls::Bytes(reinterpret_cast<const uint8_t*>(buf), SerSize));
69+
if (impl == bls::PrivateKey()) {
70+
continue;
71+
}
6972
break;
7073
} catch (...) {
7174
}

src/bls/bls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ class CBLSWrapper
111111
} else {
112112
try {
113113
impl = ImplType::FromBytes(bls::Bytes(vecBytes.data(), vecBytes.size()), specificLegacyScheme);
114+
if (impl == ImplType()) {
115+
Reset();
116+
cachedHash.SetNull();
117+
return;
118+
}
114119
fValid = true;
115120
} catch (...) {
116121
Reset();

0 commit comments

Comments
 (0)