Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update aes-version and add updates aes-circuits #11

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/circom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: circom

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
circom:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: |
npm install
npm install -g snarkjs

- name: Download and install Circom
run: |
CIRCOM_VERSION=2.1.9
curl -L https://github.com/iden3/circom/releases/download/v$CIRCOM_VERSION/circom-linux-amd64 -o circom
chmod +x circom
sudo mv circom /usr/local/bin/
circom --version

- name: Run tests
run: npm run test

- name: Install Protocol Buffers
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler libprotobuf-dev

- name: Setup circom-witnesscalc
run: |
cd .. && git clone https://github.com/iden3/circom-witnesscalc.git
cd circom-witnesscalc
cargo install --path .
echo $(which build-circuit)

- name: Build witness for aes-gcm
run: |
build-circuit circuits/aes-gctr.circom aes-fold.bin -l node_modules

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.r1cs
*.bin
node_modules/*
node_modules/*

circuits/test/*.circom
9 changes: 9 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extension": [
"ts"
],
"require": "ts-node/register",
"spec": "circuits/test/**/*.test.ts",
"timeout": 100000,
"exit": true
}
8 changes: 8 additions & 0 deletions circomkit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "2.1.9",
"proofSystem": "groth16",
"curve": "bn128",
"includes": [
"node_modules"
]
}
91 changes: 0 additions & 91 deletions circuits/aes_gcm.circom

This file was deleted.

69 changes: 69 additions & 0 deletions circuits/aes_gctr.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
pragma circom 2.1.9;

include "aes-circuits/circuits/aes-gcm/aes-gctr-foldable.circom";
include "aes-circuits/circuits/aes-gcm/utils.circom";

// Compute AES-GCTR
template AESGCTRFOLD(INPUT_LEN) {
assert(INPUT_LEN % 16 == 0);
var DATA_BYTES = (INPUT_LEN * 2) + 4;
signal input key[16];
signal input iv[12];
signal input aad[16];
signal input plainText[16];

// step_in[0..INPUT_LEN] => accumulate plaintext blocks
// step_in[INPUT_LEN..INPUT_LEN*2] => accumulate ciphertext blocks
// step_in[INPUT_LEN*2..INPUT_LEN*2+4] => accumulate counter
signal input step_in[DATA_BYTES];
signal output step_out[DATA_BYTES];
signal counter;

// We extract the number from the 4 byte word counter
component last_counter_bits = BytesToBits(4);
for(var i = 0; i < 4; i ++) {
last_counter_bits.in[i] <== step_in[INPUT_LEN*2 + i];
}
component last_counter_num = Bits2Num(32);
// pass in reverse order
for (var i = 0; i< 32; i++){
last_counter_num.in[i] <== last_counter_bits.out[31 - i];
}

counter <== last_counter_num.out - 1;

// write new plain text block.
signal plainTextAccumulator[DATA_BYTES];
component writeToIndex = WriteToIndex(DATA_BYTES, 16);
writeToIndex.array_to_write_to <== step_in;
writeToIndex.array_to_write_at_index <== plainText;
writeToIndex.index <== counter * 16;
writeToIndex.out ==> plainTextAccumulator;

// folds one block
component aes = AESGCTRFOLDABLE();
aes.key <== key;
aes.iv <== iv;
aes.aad <== aad;
aes.plainText <== plainText;

for(var i = 0; i < 4; i++) {
aes.lastCounter[i] <== step_in[INPUT_LEN*2 + i];
}

// accumulate cipher text
signal cipherTextAccumulator[DATA_BYTES];
component writeCipherText = WriteToIndex(DATA_BYTES, 16);
writeCipherText.array_to_write_to <== plainTextAccumulator;
writeCipherText.array_to_write_at_index <== aes.cipherText;
writeCipherText.index <== INPUT_LEN + counter * 16;
writeCipherText.out ==> cipherTextAccumulator;

// get counter
signal counterAccumulator[DATA_BYTES];
component writeCounter = WriteToIndex(DATA_BYTES, 4);
writeCounter.array_to_write_to <== cipherTextAccumulator;
writeCounter.array_to_write_at_index <== aes.counter;
writeCounter.index <== INPUT_LEN*2;
writeCounter.out ==> step_out;
}
Loading
Loading