commit 31e32a271d9a2c7d1b0998dc01f5a74d2da7911a
parent 13b42e40652d78f4797c1e393ca03fa906dfc9f3
Author: Florian Dold <dold@taler.net>
Date: Mon, 20 Jul 2026 13:58:58 +0200
util: fix age restriction commit comparison, test
Diffstat:
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/taler-crypto.test.ts b/packages/taler-util/src/taler-crypto.test.ts
@@ -53,6 +53,7 @@ import {
hpkeSealOneshotNorand,
hpkeComputeNonce,
hpkeOpenOneshot,
+ AgeRestriction,
} from "./taler-crypto.js";
import { sha512 } from "./kdf.js";
import * as nacl from "./nacl-fast.js";
@@ -408,6 +409,31 @@ test("taler age restriction crypto", async (t) => {
assert.deepStrictEqual(pub2, pub2Ref);
});
+test("age restriction commitCompare accepts a matching derived commitment", async (t) => {
+ const mask = 0x7f; // arbitrary bitmask with bit 0 set, as required by restrictionCommit
+ const proof = await AgeRestriction.restrictionCommit(mask, 0);
+ const salt = getRandomBytes(32);
+ const derived = await AgeRestriction.commitmentDerive(proof, salt);
+
+ // By definition (see doc comment on commitCompare): derived.commitment
+ // should equal proof.commitment * salt.
+ const ok = await AgeRestriction.commitCompare(
+ derived.commitment,
+ proof.commitment,
+ salt,
+ );
+ assert.strictEqual(ok, true);
+
+ // A commitment derived with a different salt must not match.
+ const otherSalt = getRandomBytes(32);
+ const notOk = await AgeRestriction.commitCompare(
+ derived.commitment,
+ proof.commitment,
+ otherSalt,
+ );
+ assert.strictEqual(notOk, false);
+});
+
test("edx signing", async (t) => {
const priv1 = await Edx25519.keyCreate();
const pub1 = await Edx25519.getPublic(priv1);
diff --git a/packages/taler-util/src/taler-crypto.ts b/packages/taler-util/src/taler-crypto.ts
@@ -1445,7 +1445,7 @@ export namespace AgeRestriction {
decodeCrock(c2.publicKeys[i]),
salt,
);
- if (k1 != k2) {
+ if (!nacl.verify(k1, k2)) {
return false;
}
}