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

Golf aes gcm fold #103

Merged
merged 30 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fa03c1
add witness calc to CI
0xJepsen Oct 22, 2024
fa6dec4
idiomatic CI nameing
0xJepsen Oct 22, 2024
d7aeefd
constraints: 801698, removed redunant parameters
0xJepsen Oct 22, 2024
46d3b57
constraints: 801676, ghash modes?
0xJepsen Oct 22, 2024
28749f6
simplify a bit more
0xJepsen Oct 22, 2024
b6d1250
CI Fix
0xJepsen Oct 23, 2024
16a09eb
comments: tracing our ghash mode selectors
0xJepsen Oct 23, 2024
817ddf9
mode logs
0xJepsen Oct 23, 2024
9e3e7e0
removing unneeded generics and adding documentation
0xJepsen Oct 24, 2024
41d3a52
remove unused test
0xJepsen Oct 24, 2024
72693d7
removed all auth from ghash
0xJepsen Oct 24, 2024
60b9c0b
figure fix
0xJepsen Oct 24, 2024
bbe6cd7
compiling array builder
0xJepsen Oct 24, 2024
bb3ecad
accumulating all values
0xJepsen Oct 24, 2024
a830f22
witness calc works
0xJepsen Oct 24, 2024
496fc47
Update aes-gcm-fold.circom
0xJepsen Oct 24, 2024
c20fce7
fix bug in WriteToIndex component
0xJepsen Oct 24, 2024
4b0bd5f
squashing bugs 🐞
0xJepsen Oct 24, 2024
8bee83d
squashing bugs 🐞
0xJepsen Oct 24, 2024
d85a79f
tests passing for a single block
0xJepsen Oct 24, 2024
f6dba09
remove misleading logs
0xJepsen Oct 24, 2024
0a45262
remove unused components
0xJepsen Oct 24, 2024
2ecaca1
fix CI
0xJepsen Oct 24, 2024
93d53d6
cleanning up comments
0xJepsen Oct 25, 2024
1d901a7
cleanning up comments
0xJepsen Oct 25, 2024
842ba21
bug in to blocks?
0xJepsen Oct 25, 2024
4ac3335
passing non zero pr test
0xJepsen Oct 25, 2024
558f179
test passing for two block case
0xJepsen Oct 25, 2024
3021955
remove unused foldable ghash
0xJepsen Oct 25, 2024
d42a38f
fix ci
0xJepsen Oct 25, 2024
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
19 changes: 18 additions & 1 deletion .github/workflows/test.yml → .github/workflows/circom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ jobs:
circom --version

- name: Run tests
run: npm run test
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-gcm-fold/aes-gcm-fold.circom aes-fold.bin -l node_modules

11 changes: 0 additions & 11 deletions .github/workflows/ci.yml → .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ jobs:
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: rustup component add clippy
- run: cargo clippy -- -Dwarnings
# test:
# name: test project
# runs-on: ubuntu-latest
# strategy:
# matrix:
# toolchain:
# - nightly
# steps:
# - uses: actions/checkout@v4
# - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
# - run: cargo test --all-features --verbose

fmt:
name: fmt project
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ circuits/test/*.circom
circuits/main/*
ir_log/*
log_input_signals.txt
*.bin
*.bin
ghash_gmul.r1cs
main.r1cs
*.r1cs
5 changes: 5 additions & 0 deletions circuits/aes-gcm-fold/aes-gcm-fold.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../aes-gcm/aes-gcm-fold.circom";

component main = AESGCMFOLD(16);
78 changes: 46 additions & 32 deletions circuits/aes-gcm/aes-gcm-fold.circom
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
pragma circom 2.1.9;

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

// Compute AES-GCM
template AESGCMFOLD(bytesPerFold, totalBytes) {
// cannot fold outside chunk boundaries.
assert(bytesPerFold % 16 == 0);
assert(totalBytes % 16 == 0);
template AESGCMFOLD(INPUT_LEN) {
assert(INPUT_LEN % 16 == 0);

var DATA_BYTES = (INPUT_LEN * 2) + 5;
Comment on lines -6 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice complexity golf


signal input key[16];
signal input iv[12];
signal input aad[16];
signal input plainText[bytesPerFold];
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] => lastCounter
// step_in[INPUT_LEN*2+5] => foldedBlocks // TODO(WJ 2024-10-24): technically not needed if can read 4 bytes as a 32 bit number
signal input step_in[DATA_BYTES];
signal output step_out[DATA_BYTES];
signal counter <== step_in[INPUT_LEN*2 + 4];

// Output from the last encryption step
// Always use last bytes for inputs which are not same size.
// step_in[0..4] => lastCounter
// step_in[4..20] => lastTag
// step_in[20] => foldedBlocks
signal input step_in[21];
// 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;

// For now, attempt to support variable fold size. Potential fix at 16 in the future.
component aes = AESGCMFOLDABLE(bytesPerFold, totalBytes\16);
// folds one block
component aes = AESGCMFOLDABLE();
aes.key <== key;
aes.iv <== iv;
aes.aad <== aad;
aes.plainText <== plainText;

// Fold inputs
for(var i = 0; i < 4; i++) {
aes.lastCounter[i] <== step_in[i];
aes.lastCounter[i] <== step_in[INPUT_LEN*2 + i];
}
for(var i = 0; i < 16; i++) {
aes.lastTag[i] <== step_in[4 + i];
}
// TODO:tracy range check, assertions, stuff.
aes.foldedBlocks <== step_in[20];

// Fold Outputs
signal output step_out[21];
for(var i = 0; i < 4; i++) {
step_out[i] <== aes.counter[i];
}
for(var i = 0; i < 16; i++) {
step_out[4 + i] <== aes.authTag[i];
}
step_out[20] <== step_in[20] + bytesPerFold \ 16;
// 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 ==> counterAccumulator;

signal output authTag[16] <== aes.authTag;
signal output cipherText[bytesPerFold] <== aes.cipherText;
}
// accumulate number of folded blocks
component writeNumberOfFoldedBlocks = WriteToIndex(DATA_BYTES, 1);
writeNumberOfFoldedBlocks.array_to_write_to <== counterAccumulator;
writeNumberOfFoldedBlocks.array_to_write_at_index <== [step_in[INPUT_LEN*2 + 4] + 1];
writeNumberOfFoldedBlocks.index <== INPUT_LEN*2 + 4;
writeNumberOfFoldedBlocks.out ==> step_out;
}
Loading