commit 453906ee609e92cacffe81fbb65f462b4ca6610a
parent 5b8f0a00f4e04bb306ced936af8ad96cee627298
Author: Florian Dold <dold@taler.net>
Date: Thu, 26 Nov 2026 00:17:58 +0100
taler-util: preserve age proof keys across coin refreshes
A derived Edx25519 scalar can lose low bits if it is divided by eight on
the next refresh. Multiply the scalars modulo the group order so the
derived private key still matches its public key.
Diffstat:
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/packages/taler-util/src/taler-crypto.test.ts b/packages/taler-util/src/taler-crypto.test.ts
@@ -422,6 +422,19 @@ test("taler age restriction crypto", async (t) => {
assert.deepStrictEqual(pub2, pub2Ref);
});
+test("age attestations survive successive refreshes", async () => {
+ const seed = Uint8Array.from({ length: 32 }, (_, i) => i);
+ let proof = await AgeRestriction.restrictionCommitSeeded(0x055501, 18, seed);
+ for (let generation = 0; generation < 4; generation++) {
+ proof = await AgeRestriction.commitmentDerive(
+ proof,
+ Uint8Array.of(generation),
+ );
+ const signature = encodeCrock(AgeRestriction.commitmentAttest(proof, 18));
+ assert.ok(AgeRestriction.commitmentVerify(proof.commitment, signature, 18));
+ }
+});
+
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);
diff --git a/packages/taler-util/src/taler-crypto.ts b/packages/taler-util/src/taler-crypto.ts
@@ -1284,13 +1284,6 @@ export function bigintFromNaclArr(arr: Uint8Array): bigint.BigInteger {
}
export namespace Edx25519 {
- const revL = [
- 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2,
- 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10,
- ];
-
- const L = bigint.fromArray(revL.reverse(), 256, false);
-
export async function keyCreateFromSeed(
seed: OpaqueData,
): Promise<Edx25519PrivateKey> {
@@ -1345,19 +1338,18 @@ export namespace Edx25519 {
seed: OpaqueData,
): Promise<Edx25519PrivateKey> {
const pub = await getPublic(priv);
- const privDec = priv;
- const a = bigintFromNaclArr(privDec.subarray(0, 32));
- const factorEnc = await deriveFactor(pub, seed);
- const factorModL = bigintFromNaclArr(factorEnc).mod(L);
-
- const aPrime = a.divide(8).multiply(factorModL).mod(L).multiply(8).mod(L);
- const bPrime = hash(
- typedArrayConcat([privDec.subarray(32, 64), factorEnc]),
- ).subarray(0, 32);
-
- const newPriv = typedArrayConcat([bigintToNaclArr(aPrime, 32), bPrime]);
-
- return newPriv;
+ const factor = await deriveFactor(pub, seed);
+ // A derived scalar has already been reduced modulo the group order and
+ // need not be a multiple of eight, even when the original key was clamped.
+ const scalar = ed25519Scalar.mul(
+ scalarFromBytes(priv.subarray(0, 32)),
+ scalarFromBytes(factor),
+ );
+ const prefix = hash(typedArrayConcat([priv.subarray(32), factor]));
+ return typedArrayConcat([
+ ed25519Scalar.toBytes(scalar),
+ prefix.subarray(0, 32),
+ ]);
}
export async function publicKeyDerive(