Skip to content

Commit

Permalink
change aes input to data bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Nov 1, 2024
1 parent 784db46 commit 118d4cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
6 changes: 4 additions & 2 deletions circuits/aes-gcm/nivc/aes-gctr-nivc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ include "../../utils/array.circom";


// Compute AES-GCTR
template AESGCTRFOLD(INPUT_LEN) {
template AESGCTRFOLD(DATA_BYTES) {
// Length of plaintext
var INPUT_LEN = (DATA_BYTES - 4) / 2;
assert(INPUT_LEN % 16 == 0);
var DATA_BYTES = (INPUT_LEN * 2) + 4;

signal input key[16];
signal input iv[12];
signal input aad[16];
Expand Down
8 changes: 4 additions & 4 deletions circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [16], // input len is 16 bytes
params: [36], // input len is 16 bytes
});

let key = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand All @@ -30,7 +30,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [16], // input len is 16 bytes
params: [36], // input len is 16 bytes
});

let key = [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31];
Expand All @@ -54,7 +54,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [32], // input len is 32 bytes
params: [68], // input len is 32 bytes
});

let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand All @@ -78,7 +78,7 @@ describe("aes-gctr-nivc", () => {
circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", {
file: "aes-gcm/nivc/aes-gctr-nivc",
template: "AESGCTRFOLD",
params: [32], // input len is 32 bytes
params: [68], // input len is 32 bytes
});

let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand Down
30 changes: 17 additions & 13 deletions circuits/web_proof.circom
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,36 @@ include "json/nivc/masker.circom";
include "json/nivc/extractor.circom";

// AES -> HTTP Parse -> http lock header -> http body mask -> json parse -> json_mask_object/json_mask_array -> extract value
template WEPPROOF {
// DATA_BYTES = length of block * 2 + 4
// e.g. 36 = 16 * 2 + 4 for a single block
template WEPPROOF(DATA_BYTES) {

// template AESGCTRFOLD(INPUT_LEN)
component aes_gctr_nivc = AESGCTRFOLD(48);
// template AESGCTRFOLD(DATA)
component aes_gctr_nivc = AESGCTRFOLD(DATA_BYTES);

// template ParseAndLockStartLine(DATA_BYTES, MAX_STACK_HEIGHT, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH)
component http_parse = ParseAndLockStartLine(48, 16, 8, 3, 2);
component http_parse = ParseAndLockStartLine(DATA_BYTES, 16, 8, 3, 2);

// template LockHeader(DATA_BYTES, MAX_STACK_HEIGHT, MAX_HEADER_NAME_LENGTH, MAX_HEADER_VALUE_LENGTH)
component http_lock_header = LockHeader(48, 16, 12, 16);
component http_lock_header = LockHeader(DATA_BYTES, 16, 12, 16);

// template HTTPMaskBodyNIVC(DATA_BYTES, MAX_STACK_HEIGHT)
component http_body_mask = HTTPMaskBodyNIVC(48, 16);
component http_body_mask = HTTPMaskBodyNIVC(DATA_BYTES, 16);

// JsonParseNIVC(DATA_BYTES, MAX_STACK_HEIGHT)
component json_parse = JsonParseNIVC(48, 16);
component json_parse = JsonParseNIVC(DATA_BYTES, 16);
// need logic to specif which json type
// object or array

// template JsonMaskObjectNIVC(DATA_BYTES, MAX_STACK_HEIGHT, MAX_KEY_LENGTH)
component json_mask_object = JsonMaskObjectNIVC(DATA_BYTES, 16, 4);

component json_mask_object = JsonMaskObjectNIVC(48, 16, 4);
component json_mask_array = JsonMaskArrayIndexNIVC(48, 16);
// extract value
component extract_value = MaskExtractFinal(49, 32, 32);
// template JsonMaskArrayIndexNIVC(DATA_BYTES, MAX_STACK_HEIGHT)
component json_mask_array = JsonMaskArrayIndexNIVC(DATA_BYTES, 16);

// template MaskExtractFinal(DATA_BYTES, MAX_STACK_HEIGHT, MAX_VALUE_LENGTH)
component extract_value = MaskExtractFinal(DATA_BYTES, 32, 32);
}

// = AESGCTRFOLD(48);
component main = WEPPROOF();
component main = WEPPROOF(36);

0 comments on commit 118d4cb

Please sign in to comment.