Skip to content

Commit

Permalink
remove aes
Browse files Browse the repository at this point in the history
  • Loading branch information
lonerapier committed Dec 5, 2024
1 parent e4d22fa commit cd972f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions circuits/chacha20/nivc/chacha20_nivc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ template ChaCha20_NIVC(N) {

// the below can be both ciphertext or plaintext depending on the direction
// in => N 32-bit words => N 4 byte words
signal input plainText[N][32];
signal input plainText[N*4];
// out => N 32-bit words => N 4 byte words
signal input cipherText[N*4];

signal input step_in[1];
signal output step_out[1];

signal plaintextBits[N][32];
component toBits[N];
for (var i = 0 ; i < N ; i++) {
toBits[i] = fromWords32ToLittleEndian();
for (var j = 0 ; j < 4 ; j++) {
toBits[i].words[j] <== plainText[i*4 + j];
}
plaintextBits[i] <== toBits[i].data;
}

var tmp[16][32] = [
[
// constant 0x61707865
Expand Down Expand Up @@ -100,7 +110,7 @@ template ChaCha20_NIVC(N) {
// XOR block with input
for(j = 0; j < 16; j++) {
xors[i*16 + j] = XorBits(32);
xors[i*16 + j].a <== plainText[i*16 + j];
xors[i*16 + j].a <== plaintextBits[i*16 + j];
xors[i*16 + j].b <== rounds[i].out[j];
computedCipherText[i*16 + j] <== xors[i*16 + j].out;
}
Expand Down Expand Up @@ -130,17 +140,6 @@ template ChaCha20_NIVC(N) {
signal paddedCiphertextCheck <== IsEqualArrayPaddedLHS(N*4)([cipherText, bigEndianCiphertext]);
paddedCiphertextCheck === 1;

component toBytes[N];
signal bigEndianPlaintext[N*4];
for(var i = 0 ; i < N; i++) {
toBytes[i] = fromLittleEndianToWords32();
for(var j = 0 ; j < 32 ; j++) {
toBytes[i].data[j] <== plainText[i][j];
}
for(var j = 0; j < 4; j++) {
bigEndianPlaintext[i*4 + j] <== toBytes[i].words[j];
}
}
signal data_hash <== DataHasher(N*4)(bigEndianPlaintext);
signal data_hash <== DataHasher(N*4)(plainText);
step_out[0] <== data_hash;
}
4 changes: 2 additions & 2 deletions circuits/test/chacha20/chacha20-nivc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("chacha20-nivc", () => {
nonce: toInput(Buffer.from(nonceBytes)),
counter: counterBits,
cipherText: ciphertextBytes,
plainText: plaintextBits,
plainText: plaintextBytes,
step_in: 0
}, (["step_out"]));
assert.deepEqual(w.step_out, DataHasher(plaintextBytes));
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("chacha20-nivc", () => {
nonce: toInput(Buffer.from(nonceBytes)),
counter: counterBits,
cipherText: paddedCiphertextBytes,
plainText: plaintextBits,
plainText: paddedPlaintextBytes,
step_in: 0
}, (["step_out"]));
assert.deepEqual(w.step_out, DataHasher(paddedPlaintextBytes));
Expand Down
2 changes: 1 addition & 1 deletion circuits/test/full/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ describe("NIVC_FULL_CHACHA", async () => {
const ptIn = toInput(Buffer.from(http_response_plaintext));
const keyIn = toInput(Buffer.from(Array(32).fill(0)));
const nonceIn = toInput(Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00]));
let chacha20 = await chacha20Circuit.compute({ key: keyIn, nonce: nonceIn, counter: counterBits, plainText: ptIn, cipherText: chacha20_http_response_ciphertext, step_in: init_nivc_input }, ["step_out"]);
let chacha20 = await chacha20Circuit.compute({ key: keyIn, nonce: nonceIn, counter: counterBits, plainText: http_response_plaintext, cipherText: chacha20_http_response_ciphertext, step_in: init_nivc_input }, ["step_out"]);
console.log("ChaCha20 `step_out`:", chacha20.step_out);
assert.deepEqual(http_response_hash, chacha20.step_out);

Expand Down

0 comments on commit cd972f5

Please sign in to comment.