Skip to content

Commit 2d571a4

Browse files
authored
removed unused code (#97)
* removed dated comments and unused code * opt notes
1 parent ac209d7 commit 2d571a4

17 files changed

+29
-800
lines changed

circuits/aes-gcm/aes-gcm-fold.circom

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template AESGCMFOLD(bytesPerFold, totalBytes) {
3434
for(var i = 0; i < 16; i++) {
3535
aes.lastTag[i] <== step_in[4 + i];
3636
}
37-
// TODO: range check, assertions, stuff.
37+
// TODO:tracy range check, assertions, stuff.
3838
aes.foldedBlocks <== step_in[20];
3939

4040
// Fold Outputs

circuits/aes-gcm/aes-gcm.circom

+4-20
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ template AESGCM(l) {
3838
zeroBlock.stream[i] <== 0;
3939
}
4040

41-
// Step 1: Let H = CIPHK(0128)
42-
component cipherH = Cipher(); // 128-bit key -> 4 32-bit words -> 10 rounds
41+
// Step 1: Let H = aes(key, zeroBlock)
42+
component cipherH = Cipher();
4343
cipherH.key <== key;
4444
cipherH.block <== zeroBlock.blocks[0];
4545

4646
// Step 2: Define a block, J0 with 96 bits of iv and 32 bits of 0s
47-
// you can of the 96bits as a nonce and the 32 bits of 0s as an integer counter
4847
component J0builder = ToBlocks(16);
4948
for (var i = 0; i < 12; i++) {
5049
J0builder.stream[i] <== iv[i];
@@ -71,11 +70,8 @@ template AESGCM(l) {
7170
gctr.plainText <== plainText;
7271

7372

74-
// Step 4: Let u and v
73+
// Step 4: Let u and v (v is always zero with out key size and aad length)
7574
var u = 128 * (l \ 128) - l;
76-
// when we handle dynamic aad lengths, we'll need to change this
77-
var v = 0;
78-
7975
var blockCount = l\16;
8076
if(l%16 > 0){
8177
blockCount = blockCount + 1;
@@ -110,7 +106,6 @@ template AESGCM(l) {
110106
ghashMessage[ghashblocks-1][0] <== [0x00, 0x00, 0x00, 0x00];
111107
ghashMessage[ghashblocks-1][1] <== [0x00, 0x00, 0x00, 0x80];
112108

113-
// TODO: constrain len to be u64 range.
114109
var len = blockCount * 128;
115110
for (var i=0; i<8; i++) {
116111
var byte_value = 0;
@@ -131,16 +126,7 @@ template AESGCM(l) {
131126
for (var i = 0 ; i<ghashblocks ; i++) {
132127
ghash.msg[i] <== ToStream(1, 16)([ghashMessage[i]]);
133128
}
134-
// ghash.msg <== msgToStream.stream;
135-
// In Steps 4 and 5, the AAD and the ciphertext are each appended with the minimum number of
136-
// ‘0’ bits, possibly none, so that the bit lengths of the resulting strings are multiples of the block
137-
// size. The concatenation of these strings is appended with the 64-bit representations of the
138-
// lengths of the AAD and the ciphertext, and the GHASH function is applied to the result to
139-
// produce a single output block.
140-
141-
// TODO: Check the endianness
142-
// TODO: this is underconstrained too
143-
// log("ghash bytes"); // BUG: Currently 0.
129+
144130
signal bytes[16];
145131
signal tagBytes[16 * 8] <== BytesToBits(16)(ghash.tag);
146132
for(var i = 0; i < 16; i++) {
@@ -151,10 +137,8 @@ template AESGCM(l) {
151137
byteValue += tagBytes[bitIndex]*sum;
152138
sum = sum*sum;
153139
}
154-
// log(byteValue);
155140
bytes[i] <== byteValue;
156141
}
157-
// log("end ghash bytes");
158142

159143
// Step 6: Let T = MSBt(GCTRK(J0, S))
160144
component gctrT = GCTR(16);

circuits/aes-gcm/aes/cipher.circom

+10-22
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ include "transformations.circom";
99
include "mix_columns.circom";
1010

1111
// Cipher Process
12-
// nk: number of keys which can be 4, 6, 8
13-
// AES 128, 192, 256 have 10, 12, 14 rounds.
12+
// AES 128 keys have 10 rounds.
1413
// Input Block Initial Round Key Round Key Final Round Key
1514
// │ │ │ │
1615
// ▼ ▼ ▼ ▼
@@ -31,16 +30,13 @@ include "mix_columns.circom";
3130
// Ciphertext
3231

3332

34-
// @param nk: number of keys which can be 4, 6, 8
3533
// @inputs block: 4x4 matrix representing the input block
36-
// @inputs key: array of nk*4 bytes representing the key
34+
// @inputs key: array of 16 bytes representing the key
3735
// @outputs cipher: 4x4 matrix representing the output block
3836
template Cipher(){
3937
signal input block[4][4];
4038
signal input key[16];
4139
signal output cipher[4][4];
42-
43-
// var nr = Rounds(nk);
4440

4541
component keyExpansion = KeyExpansion();
4642
keyExpansion.key <== key;
@@ -59,16 +55,21 @@ template Cipher(){
5955
}
6056

6157
interBlock[0] <== addRoundKey[0].newState;
58+
// for each round.
6259
for (var i = 1; i < 10; i++) {
60+
// SubBytes
6361
subBytes[i-1] = SubBlock();
6462
subBytes[i-1].state <== interBlock[i-1];
6563

64+
// ShiftRows
6665
shiftRows[i-1] = ShiftRows();
6766
shiftRows[i-1].state <== subBytes[i-1].newState;
6867

68+
// MixColumns
6969
mixColumns[i-1] = MixColumns();
7070
mixColumns[i-1].state <== shiftRows[i-1].newState;
7171

72+
// AddRoundKey
7273
addRoundKey[i] = AddRoundKey();
7374
addRoundKey[i].state <== mixColumns[i-1].out;
7475
for (var j = 0; j < 4; j++) {
@@ -78,32 +79,19 @@ template Cipher(){
7879
interBlock[i] <== addRoundKey[i].newState;
7980
}
8081

82+
// Final SubBytes
8183
subBytes[9] = SubBlock();
8284
subBytes[9].state <== interBlock[9];
8385

8486
shiftRows[9] = ShiftRows();
8587
shiftRows[9].state <== subBytes[9].newState;
8688

89+
// Final AddRoundKey
8790
addRoundKey[10] = AddRoundKey();
8891
addRoundKey[10].state <== shiftRows[9].newState;
8992
for (var i = 0; i < 4; i++) {
9093
addRoundKey[10].roundKey[i] <== keyExpansion.keyExpanded[i + (40)];
9194
}
9295

9396
cipher <== addRoundKey[10].newState;
94-
}
95-
96-
// @param nk: number of keys which can be 4, 6, 8
97-
// @returns number of rounds
98-
// AES 128, 192, 256 have 10, 12, 14 rounds.
99-
function Rounds (nk) {
100-
if (nk == 4) {
101-
return 10;
102-
} else if (nk == 6) {
103-
return 12;
104-
} else {
105-
return 14;
106-
}
107-
}
108-
109-
97+
}

circuits/aes-gcm/aes/key_expansion.circom

-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ template NextRound(){
106106
[0x36, 0x00, 0x00, 0x00]
107107
];
108108
rcon.index <== round-1;
109-
110-
// var rcon[4] = rcons[round-1];
111-
112109
component xorWord[4 + 1];
113110
xorWord[0] = XorWord();
114111
xorWord[0].bytes1 <== substituteWord[0].substituted;

circuits/aes-gcm/aes/tbox.circom

-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ template TBox(index) {
88
signal output out;
99

1010
if (index == 0) {
11-
// tbox[0] =>> multiplication by 2
1211
out <== FieldMul2()(subindex);
1312
} else if (index == 1) {
14-
// tbox[1] =>> multiplication by 3
1513
out <== FieldMul3()(subindex);
1614
}
1715
}

circuits/aes-gcm/aes/utils.circom

-30
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,4 @@ template AddCipher(){
168168
newState[i][j] <== xorbyte[i][j].out;
169169
}
170170
}
171-
}
172-
173-
// converts iv to counter blocks
174-
// iv is 16 bytes
175-
// TODO: this is definitely underconstrained
176-
template GenerateCounterBlocks(n){
177-
assert(n < 0xffffffff);
178-
signal input iv[16];
179-
signal output counterBlocks[n][4][4];
180-
181-
var ivr[16] = iv;
182-
183-
component toBlocks[n];
184-
185-
for (var i = 0; i < n; i++) {
186-
toBlocks[i] = ToBlocks(16);
187-
toBlocks[i].stream <-- ivr;
188-
counterBlocks[i] <== toBlocks[i].blocks[0];
189-
ivr[15] = (ivr[15] + 1)%256;
190-
if (ivr[15] == 0){
191-
ivr[14] = (ivr[14] + 1)%256;
192-
if (ivr[14] == 0){
193-
ivr[13] = (ivr[13] + 1)%256;
194-
if (ivr[13] == 0){
195-
ivr[12] = (ivr[12] + 1)%256;
196-
}
197-
}
198-
}
199-
200-
}
201171
}

circuits/aes-gcm/gctr.circom

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ include "utils.circom";
3131

3232

3333
// We are opperating on 128 bit blocks represented as 16 bytes
34-
3534
template GCTR(INPUT_LEN) {
3635
signal input key[16];
3736
signal input initialCounterBlock[4][4];
@@ -63,16 +62,15 @@ template GCTR(INPUT_LEN) {
6362
component inc32[nBlocks - 1];
6463
// For i = 2 to nBlocks, let CBi = inc32(CBi-1).
6564

66-
// TODO: Actually test me on a block larger than 16 bytes.
6765
for (var i = 1; i < nBlocks; i++) {
6866
inc32[i - 1] = IncrementWord();
69-
inc32[i - 1].in <== CounterBlocks[i - 1][3]; // idea: use the counterblock here directly so that we don't need to use this toCounterblock thing
67+
inc32[i - 1].in <== CounterBlocks[i - 1][3];
7068

7169
// copy the previous 12 bytes of the counter block
7270
for (var j = 0; j < 3; j++) {
7371
CounterBlocks[i][j] <== CounterBlocks[i - 1][j];
7472
}
75-
// should write the last 4 bytes of the incremented word
73+
// write the last 4 bytes of the incremented word
7674
CounterBlocks[i][3] <== inc32[i - 1].out;
7775
}
7876

@@ -102,7 +100,6 @@ template GCTR(INPUT_LEN) {
102100
// Step 3: Handle the last block separately
103101
// Y* = X* ⊕ MSBlen(X*) (CIPH_K (CB_n*))
104102

105-
// TODO: When we only have one block, this double Cipher's. We shouldnnt do this when l % 16 == 0
106103
// encrypt the last counter block
107104
aes[nBlocks] = Cipher();
108105
aes[nBlocks].key <== key;

circuits/aes-gcm/ghash-foldable.circom

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ include "ghash_gmul.circom";
1010
// Outputs:
1111
// - `tag` the authentication tag
1212
//
13-
// Computes:
14-
// Y_0 = 0^128
15-
// Y_{i+1} = (Y_i xor X_{i-1}) * H
16-
// output: Y_{n+1} where n is the number of blocks.
17-
// GHASH Process
1813
//
1914
// X1 X2 ... XM
2015
// │ │ │

circuits/aes-gcm/ghash.circom

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ include "ghash_gmul.circom";
1010
// Outputs:
1111
// - `tag` the authentication tag
1212
//
13-
// Computes:
14-
// Y_0 = 0^128
15-
// Y_{i+1} = (Y_i xor X_{i-1}) * H
16-
// output: Y_{n+1} where n is the number of blocks.
17-
// GHASH Process
18-
//
1913
// X1 X2 ... XM
2014
// │ │ │
2115
// │ ▼ ▼

circuits/aes-gcm/ghash_gmul.circom

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ template GhashMul() {
4747
signal bitsX[16*8];
4848
bitsX <== bytesToBits.out;
4949
for (var i = 0; i < 128; i++) {
50-
// log("i*8 + j", i*8 + j);
5150
// z_i_update
5251
z_i_update[i] = Z_UPDATE(16);
5352
z_i_update[i].Z <== Z[i];

circuits/aes-gcm/polyval.circom

-45
This file was deleted.

0 commit comments

Comments
 (0)