@@ -49,7 +49,7 @@ template AESGCMFOLDABLE(l, TOTAL_BLOCKS) {
49
49
}
50
50
51
51
// Step 1: Let H = CIPHK(0128)
52
- component cipherH = Cipher(4 ); // 128-bit key -> 4 32-bit words -> 10 rounds
52
+ component cipherH = Cipher(); // 128-bit key -> 4 32-bit words -> 10 rounds
53
53
cipherH.key <== key;
54
54
cipherH.block <== zeroBlock.blocks[0 ];
55
55
@@ -75,7 +75,7 @@ template AESGCMFOLDABLE(l, TOTAL_BLOCKS) {
75
75
J0[3 ] <== J0WordIncrementer.out;
76
76
77
77
// Step 3: Let C = GCTRK(inc32(J0), P)
78
- component gctr = GCTR(l, 4 );
78
+ component gctr = GCTR(l);
79
79
gctr.key <== key;
80
80
gctr.initialCounterBlock <== J0;
81
81
gctr.plainText <== plainText;
@@ -89,15 +89,16 @@ template AESGCMFOLDABLE(l, TOTAL_BLOCKS) {
89
89
// len(A) => u64
90
90
// len(b) => u64 (together, 1 block)
91
91
//
92
- var blockCount = l\16 + (l% 16 > 0 ? 1 : 0 ); // blocksize is 16 bytes
92
+ var blockCount = l\16 + (l% 16 > 0 ? 1 : 0 ); // blocksize is 16 bytes
93
93
var ghashBlocks = 1 + blockCount + 1 ;
94
94
95
- component targetMode = SelectGhashMode(TOTAL_BLOCKS, blockCount, ghashBlocks);
95
+ component targetMode = SelectGhashMode(TOTAL_BLOCKS, blockCount, ghashBlocks);
96
96
targetMode.foldedBlocks <== foldedBlocks;
97
97
98
+ // TODO(CR 2024-10-18): THIS BLOCK IS PROBLEM CHILD SO FAR
98
99
// S = GHASHH (A || 0^v || C || 0^u || [len(A)] || [len(C)]).
99
100
component selectedBlocks = SelectGhashBlocks(l, ghashBlocks, TOTAL_BLOCKS);
100
- selectedBlocks.aad <== aad;
101
+ selectedBlocks.aad <== aad;
101
102
selectedBlocks.cipherText <== gctr.cipherText;
102
103
selectedBlocks.targetMode <== targetMode.mode;
103
104
@@ -136,7 +137,7 @@ template AESGCMFOLDABLE(l, TOTAL_BLOCKS) {
136
137
}
137
138
138
139
// Step 6: Encrypt the tag. Let T = MSBt(GCTRK(J0, S))
139
- component gctrT = GCTR(16 , 4 );
140
+ component gctrT = GCTR(16 );
140
141
gctrT.key <== key;
141
142
gctrT.initialCounterBlock <== StartJ0.blocks[0 ];
142
143
gctrT.plainText <== selectTag.tag;
@@ -171,30 +172,30 @@ template SelectGhashBlocks(l, ghashBlocks, totalBlocks) {
171
172
signal targetBlocks[3 ][ghashBlocks* 4 * 4 ];
172
173
signal modeToBlocks[4 ] <== [0 , 0 , 1 , 2 ];
173
174
174
- component start = GhashStartMode(l, totalBlocks, ghashBlocks);
175
- start.aad <== aad;
175
+ component start = GhashStartMode(l, totalBlocks, ghashBlocks);
176
+ start.aad <== aad;
176
177
start.cipherText <== cipherText;
177
- targetBlocks[0 ] <== start.blocks;
178
+ targetBlocks[0 ] <== start.blocks;
178
179
179
- component stream = GhashStreamMode(l, ghashBlocks);
180
+ component stream = GhashStreamMode(l, ghashBlocks);
180
181
stream.cipherText <== cipherText;
181
- targetBlocks[1 ] <== stream.blocks;
182
+ targetBlocks[1 ] <== stream.blocks;
182
183
183
- component end = GhashEndMode(l, totalBlocks, ghashBlocks);
184
- end.cipherText <== cipherText;
184
+ component end = GhashEndMode(l, totalBlocks, ghashBlocks);
185
+ end.cipherText <== cipherText;
185
186
targetBlocks[2 ] <== end.blocks;
186
187
187
188
component mapModeToArray = Selector(4 );
188
- mapModeToArray.in <== modeToBlocks;
189
- mapModeToArray.index <== targetMode;
189
+ mapModeToArray.in <== modeToBlocks;
190
+ mapModeToArray.index <== targetMode;
190
191
191
192
component chooseBlocks = ArraySelector(3 , ghashBlocks* 4 * 4 );
192
- chooseBlocks.in <== targetBlocks;
193
- chooseBlocks.index <== mapModeToArray.out;
193
+ chooseBlocks.in <== targetBlocks;
194
+ chooseBlocks.index <== mapModeToArray.out;
194
195
195
196
component toBlocks = ToBlocks(ghashBlocks* 4 * 4 );
196
- toBlocks.stream <== chooseBlocks.out;
197
- blocks <== toBlocks.blocks;
197
+ toBlocks.stream <== chooseBlocks.out;
198
+ blocks <== toBlocks.blocks;
198
199
}
199
200
200
201
template SelectGhashTag (ghashBlocks ) {
@@ -230,10 +231,10 @@ template SelectGhashMode(totalBlocks, blocksPerFold, ghashBlocks) {
230
231
// May need to compute these differently due to foldedBlocks.
231
232
// i.e. using GT operator, Equal operator, etc.
232
233
signal isFinish <-- (blocksPerFold >= totalBlocks- foldedBlocks) ? 1 : 0 ;
233
- signal isStart <-- (foldedBlocks == 0 ) ? 1 : 0 ;
234
+ signal isStart <-- (foldedBlocks == 0 ) ? 1 : 0 ;
234
235
235
236
isFinish * (isFinish - 1 ) === 0 ;
236
- isStart * (isStart - 1 ) === 0 ;
237
+ isStart * (isStart - 1 ) === 0 ;
237
238
238
239
// case isStart && isFinish: START_END_MODE
239
240
// case isStart && !isFinish: START_MODE
@@ -247,9 +248,9 @@ template SelectGhashMode(totalBlocks, blocksPerFold, ghashBlocks) {
247
248
choice.s <== [isStart, isFinish];
248
249
249
250
signal isStartEndMode <== IsEqual()([choice.out, m.START_END_MODE]);
250
- signal isStartMode <== IsEqual()([choice.out, m.START_MODE]);
251
- signal isStreamMode <== IsEqual()([choice.out, m.STREAM_MODE]);
252
- signal isEndMode <== IsEqual()([choice.out, m.END_MODE]);
251
+ signal isStartMode <== IsEqual()([choice.out, m.START_MODE]);
252
+ signal isStreamMode <== IsEqual()([choice.out, m.STREAM_MODE]);
253
+ signal isEndMode <== IsEqual()([choice.out, m.END_MODE]);
253
254
254
255
isStartEndMode + isStartMode + isStreamMode + isEndMode === 1 ;
255
256
@@ -294,7 +295,8 @@ template GhashStartMode(l, totalBlocks, ghashBlocks) {
294
295
// Insert in reversed (big endian) order.
295
296
blocks[blockIndex+ 7 - i] <== byteValue;
296
297
}
297
- blockIndex+= 8 ;
298
+ // 16 + l + 8 + 8
299
+ blockIndex+= 8 ; // TODO(CR 2024-10-18): I don't think this does anything
298
300
}
299
301
300
302
// TODO: Mildly more efficient if we add this, maybe it's needed?
@@ -347,5 +349,10 @@ template GhashEndMode(l, totalBlocks, ghashBlocks) {
347
349
// Insert in reversed (big endian) order.
348
350
blocks[blockIndex+ 7 - i] <== byte_value;
349
351
}
350
- blockIndex+= 8 ;
351
- }
352
+ blockIndex+= 8 ;
353
+ // NOTE: Added this so all of blocks is written
354
+ for (var i = 0 ; i< 16 ; i++ ) {
355
+ blocks[blockIndex] <== 0 ;
356
+ blockIndex += 1 ;
357
+ }
358
+ }
0 commit comments