Skip to content

Commit

Permalink
added test for expand
Browse files Browse the repository at this point in the history
  • Loading branch information
yash25198 committed Nov 23, 2024
1 parent d8c5e56 commit f83b326
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions circuits/hkdf.circom
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma circom 2.1.5;
pragma circom 2.1.8;

include "./hmac/circuits/hmac.circom";

Expand Down Expand Up @@ -30,7 +30,7 @@ template HKDFSha256(ss,is,k,m,s){
// out : 32 bytes from sha256 hmac
template Expand(n,k){
signal input secret[n];
signal input key[n];
signal input key[k];

component hmac = HmacSha256(n, k);
signal output out[32];
Expand Down
32 changes: 32 additions & 0 deletions tests/hkdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@ import { WitnessTester } from "circomkit";
import { circomkit } from "./common";

describe("HKDF", () => {
describe("Expand", () => {
let circuit: WitnessTester<["secret", "key"], ["out"]>;
before(async () => {
circuit = await circomkit.WitnessTester(`Expand`, {
file: "hkdf",
template: "Expand",
params: [32, 32],
});
console.log("#constraints:", await circuit.getConstraintCount());
});

it("should expand master key from secret", async () => {
await circuit.expectPass(
{
secret: [
0x10, 0xd9, 0xcb, 0x53, 0xd1, 0xa4, 0x05, 0xcf, 0xe2, 0x68, 0x6e, 0x08, 0x35, 0x90, 0x4d, 0x48, 0x43, 0x5e,
0x80, 0x54, 0xa7, 0x9f, 0x98, 0x56, 0x83, 0xd0, 0xff, 0x72, 0x59, 0xf7, 0xa8, 0x04,
],
key: [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
},
{
out: [
0x8b, 0xeb, 0x33, 0x8d, 0x43, 0x1d, 0x24, 0x3c, 0xee, 0xaa, 0xa6, 0xf0, 0xcb, 0x57, 0x26, 0xfb, 0xc5, 0xa3,
0x5c, 0x5e, 0x45, 0xbf, 0x99, 0x2c, 0xc3, 0xe2, 0x3b, 0x5b, 0xc2, 0xe4, 0xcc, 0xea,
],
}
);
});
});
describe("Extract", () => {
let circuit: WitnessTester<["info", "key"], ["out"]>;
before(async () => {
Expand Down

0 comments on commit f83b326

Please sign in to comment.