Skip to content

Commit

Permalink
Merge pull request #155 from Bisht13/test/1024-bit-rsa
Browse files Browse the repository at this point in the history
test: add 1024 bit rsa key test for rsa circuit
  • Loading branch information
Divide-By-0 committed Dec 30, 2023
2 parents 5c46156 + c168e7f commit ccdb8a2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/circuits/tests/rsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from "path";
import { DKIMVerificationResult } from "@zk-email/helpers/src/dkim";
import { generateCircuitInputs } from "@zk-email/helpers/src/input-helpers";
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
import { toCircomBigIntBytes } from "@zk-email/helpers/src/binaryFormat";

exports.p = Scalar.fromString(
"21888242871839275222246405745257275088548364400416034343698204186575808495617"
Expand Down Expand Up @@ -33,7 +34,7 @@ describe("RSA", () => {
dkimResult = await verifyDKIMSignature(rawEmail);
});

it("should verify rsa signature correctly", async function () {
it("should verify 2048 bit rsa signature correctly", async function () {
const emailVerifierInputs = generateCircuitInputs({
rsaSignature: dkimResult.signature,
rsaPublicKey: dkimResult.publicKey,
Expand All @@ -55,6 +56,29 @@ describe("RSA", () => {
await circuit.assertOut(witness, {})
});

it("should verify 1024 bit rsa signature correctly", async function () {
const signature = toCircomBigIntBytes(
BigInt(
102386562682221859025549328916727857389789009840935140645361501981959969535413501251999442013082353139290537518086128904993091119534674934202202277050635907008004079788691412782712147797487593510040249832242022835902734939817209358184800954336078838331094308355388211284440290335887813714894626653613586546719n
)
);

const pubkey = toCircomBigIntBytes(
BigInt(
106773687078109007595028366084970322147907086635176067918161636756354740353674098686965493426431314019237945536387044259034050617425729739578628872957481830432099721612688699974185290306098360072264136606623400336518126533605711223527682187548332314997606381158951535480830524587400401856271050333371205030999n
)
);

const witness = await circuit.calculateWitness({
signature: signature,
modulus: pubkey,
// TODO: generate this from the input
base_message: ["1156466847851242602709362303526378170", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
});
await circuit.checkConstraints(witness);
await circuit.assertOut(witness, {});
});

it("should fail when verifying with an incorrect signature", async function () {
const emailVerifierInputs = generateCircuitInputs({
rsaSignature: dkimResult.signature,
Expand Down

0 comments on commit ccdb8a2

Please sign in to comment.