Skip to content

Commit b6de7d9

Browse files
committed
rounds 13 -> 9, and some comments
1 parent e75dce5 commit b6de7d9

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

circuits/aes-gcm/aes_128_enc.circom

+12-20
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ include "aes_emulation.circom";
66
include "helper_functions.circom";
77

88

9-
/// AES-256 Encrypt template
10-
/// We will need to change this to AES-128 Encrypt
11-
/// Which means we will need to change the key size to 128
12-
/// And the number of rounds to 10
9+
/// AES-128 Encrypt template
10+
/// AES-128 has 10 rounds, 9 partial rounds, and 1 final round
1311

1412
// The number of full rounds for this key size (Not the last partial round)
1513
const ROUNDS = 10 - 1
@@ -28,21 +26,17 @@ template AES128Encrypt()
2826

2927
var ks_index = 0;
3028

31-
/// TODO(WJ 2024-08-09): what are these?
32-
/// 4 x 32 mattrix of field elements
29+
/// STATE: 4 x 32 mattrix of field elements
3330
var s[4][32], t[4][32];
3431

3532
var i,j,k,l,m;
3633

3734
component xor_1[4][32];
38-
/// state initialization, might have to do with key size being 240byte rather 256byte
3935
for(i=0; i<4; i++) // adding round key
4036
{
4137
for(j=0; j<32; j++)
4238
{
4339
xor_1[i][j] = XOR();
44-
/// example sequece [[0..31],[33..64]
45-
/// i see so they are 32 bit chunks
4640
/// Then XOR each chuck with parts of the keys
4741
xor_1[i][j].a <== in[i*32+j]; // plaintext
4842
xor_1[i][j].b <== ks[(i+ks_index)*32+j]; // key schedule
@@ -52,26 +46,24 @@ template AES128Encrypt()
5246
}
5347
ks_index += 4;
5448

55-
component xor_2[13][4][3][32];
56-
component bits2num_1[13][4][4];
57-
component num2bits_1[13][4][4];
58-
component xor_3[13][4][32];
49+
component xor_2[ROUNDS][4][3][32];
50+
component bits2num_1[ROUNDS][4][4];
51+
component num2bits_1[ROUNDS][4][4];
52+
component xor_3[ROUNDS][4][32];
5953

6054

6155
/// 14 rounds of encryption TODO(WJ 2024-08-09): Change this to 10 rounds to fit AES-128
62-
for(i=0; i<13; i++) // 13 iterations maybe one extra at the end or happened to generate the key above?
56+
for(i=0; i<ROUNDS; i++) // 9 iterations maybe one extra at the end or happened to generate the key above?
6357
{
64-
/// 5 steps in each round
58+
/// 3 steps in each round
6559
/// Step 1: SubBytes
6660
/// Step 2: ShiftRows:
6761
/// Step 3: MixColumns
68-
/// Step 4: AddRoundKeys
69-
///
7062
for(j=0; j<4; j++) // 4 iterations
7163
{
7264
for(k=0; k<4; k++) // 4 iterations // COLUMN MIXING ALGORITHM
7365
{
74-
/// initialize trace space for 13x4x4 uses of bits2num and num2bit
66+
/// initialize trace space for 9x4x4 uses of bits2num and num2bit
7567
bits2num_1[i][j][k] = Bits2Num(8);
7668
num2bits_1[i][j][k] = Num2Bits(32);
7769
/// 0 - 3 based on sum of index j and k
@@ -106,7 +98,6 @@ template AES128Encrypt()
10698
}
10799
}
108100
}
109-
/// Thought 1: is this maybe just copying memory?
110101
else
111102
{
112103
for(l=0; l<4; l++)
@@ -122,6 +113,7 @@ template AES128Encrypt()
122113
}
123114
}
124115
}
116+
/// AddRoundKey
125117
for(j=0; j<4; j++)
126118
{
127119
for(l=0; l<32; l++)
@@ -166,7 +158,7 @@ template AES128Encrypt()
166158

167159
component xor_4[4][32];
168160

169-
for(i=0; i<4; i++) // final key XOR?
161+
for(i=0; i<4; i++) // final key XOR
170162
{
171163
for(j=0; j<32; j++)
172164
{

0 commit comments

Comments
 (0)