Skip to content

Commit

Permalink
Fix point validity checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Mar 10, 2024
1 parent 8dd474f commit dd3d000
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/bbs/blind/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export function CoreBlindSign({
commitment_with_proof, generators, api_id, ciphersuite
});
const {Q_1} = generators;
// Identity_G1 == ciphersuite.E1.ONE
// Identity_G1 == ciphersuite.Identity_E1
const Q_2 = commitment_with_proof.length === 0 ?
ciphersuite.E1.ONE : generators[1];
ciphersuite.Identity_E1 : generators[1];
const H = generators.slice(M + 1, M + L + 2);

/* Algorithm:
Expand Down Expand Up @@ -100,7 +100,7 @@ export function CoreBlindSign({
const {Fr} = ciphersuite;
const A = B.multiply(Fr.inv(Fr.add(SK, e)));
// if A == Identity_G1 throw invalid signature error
if(ciphersuite.E1.eql(A, ciphersuite.E1.ONE)) {
if(A.equals(ciphersuite.Identity_E1)) {
throw new Error('Invalid signature.');
}
return signature_to_octets({signature: [A, e], ciphersuite});
Expand Down
2 changes: 1 addition & 1 deletion lib/bbs/blind/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function octets_to_commitment_with_proof({
const C_octets = commitment_with_proof_octets.subarray(
0, octet_point_length);
const C = ciphersuite.octets_to_point_E1(C_octets);
if(ciphersuite.E1.eql(C, ciphersuite.E1.ONE)) {
if(C.equals(ciphersuite.Identity_E1)) {
throw new Error('Invalid point in commitment.');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bbs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function CoreSign({
const {Fr} = ciphersuite;
const A = B.multiply(Fr.inv(Fr.add(SK, e)));
// if A == Identity_G1 throw invalid signature error
if(ciphersuite.E1.eql(A, ciphersuite.E1.ONE)) {
if(A.equals(ciphersuite.Identity_E1)) {
throw new Error('Invalid signature.');
}
return signature_to_octets({signature: [A, e], ciphersuite});
Expand Down
6 changes: 3 additions & 3 deletions lib/bbs/pseudonym/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function CalculatePseudonym({verifier_id, pid, ciphersuite} = {}) {
*/
const OP = ciphersuite.hash_to_curve_g1(verifier_id, api_id);
// Identity_G1 == ciphersuite.E1.ONE
const {BP1, P1, E1} = ciphersuite;
if(E1.eql(OP, E1.ONE) || E1.eql(OP, BP1) || E1.eql(OP, P1)) {
// Identity_G1 == ciphersuite.Identity_E1
const {BP1, Identity_E1, P1} = ciphersuite;
if(OP.equals(Identity_E1) || OP.equals(BP1) || OP.equals(OP, P1)) {
throw new Error('Invalid verifier ID.');
}
const messages = [pid];
Expand Down
6 changes: 3 additions & 3 deletions lib/bbs/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function octets_to_proof({proof_octets, ciphersuite} = {}) {
for(let i = 0; i <= 2; ++i) {
A[i] = ciphersuite.octets_to_point_E1(
proof_octets.subarray(index, index + octet_point_length));
if(ciphersuite.E1.eql(A, ciphersuite.E1.ONE)) {
if(A[i].equals(ciphersuite.Identity_E1)) {
throw new Error('Invalid point in proof.');
}
index += octet_point_length;
Expand Down Expand Up @@ -339,7 +339,7 @@ export function octets_to_pubkey({PK, ciphersuite} = {}) {
// conversion handles checking that point is on the curve
const W = ciphersuite.octets_to_point_E2(PK);
// if W == Identity_E2 throw invalid public key error
if(ciphersuite.E2.eql(W, ciphersuite.E2.ONE)) {
if(W.equals(ciphersuite.Identity_E2)) {
throw new Error('Invalid public key.');
}
return W;
Expand Down Expand Up @@ -374,7 +374,7 @@ export function octets_to_signature({signature_octets, ciphersuite} = {}) {
// conversion handles checking that point is on the curve
const A = ciphersuite.octets_to_point_E1(A_octets);
// if A == Identity_G1 throw invalid signature error
if(ciphersuite.E1.eql(A, ciphersuite.E1.ONE)) {
if(A.equals(ciphersuite.Identity_E1)) {
throw new Error('Invalid signature.');
}
const e = os2ip(signature_octets.subarray(octet_point_length));
Expand Down

0 comments on commit dd3d000

Please sign in to comment.