@@ -38,13 +38,12 @@ template AESGCM(l) {
38
38
zeroBlock.stream[i] <== 0 ;
39
39
}
40
40
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();
43
43
cipherH.key <== key;
44
44
cipherH.block <== zeroBlock.blocks[0 ];
45
45
46
46
// 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
48
47
component J0builder = ToBlocks(16 );
49
48
for (var i = 0 ; i < 12 ; i++ ) {
50
49
J0builder.stream[i] <== iv[i];
@@ -71,11 +70,8 @@ template AESGCM(l) {
71
70
gctr.plainText <== plainText;
72
71
73
72
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)
75
74
var u = 128 * (l \ 128 ) - l;
76
- // when we handle dynamic aad lengths, we'll need to change this
77
- var v = 0 ;
78
-
79
75
var blockCount = l\16 ;
80
76
if (l% 16 > 0 ){
81
77
blockCount = blockCount + 1 ;
@@ -110,7 +106,6 @@ template AESGCM(l) {
110
106
ghashMessage[ghashblocks- 1 ][0 ] <== [0x00 , 0x00 , 0x00 , 0x00 ];
111
107
ghashMessage[ghashblocks- 1 ][1 ] <== [0x00 , 0x00 , 0x00 , 0x80 ];
112
108
113
- // TODO: constrain len to be u64 range.
114
109
var len = blockCount * 128 ;
115
110
for (var i= 0 ; i< 8 ; i++ ) {
116
111
var byte_value = 0 ;
@@ -131,16 +126,7 @@ template AESGCM(l) {
131
126
for (var i = 0 ; i< ghashblocks ; i++ ) {
132
127
ghash.msg[i] <== ToStream(1 , 16 )([ghashMessage[i]]);
133
128
}
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
+
144
130
signal bytes[16 ];
145
131
signal tagBytes[16 * 8 ] <== BytesToBits(16 )(ghash.tag);
146
132
for (var i = 0 ; i < 16 ; i++ ) {
@@ -151,10 +137,8 @@ template AESGCM(l) {
151
137
byteValue += tagBytes[bitIndex]* sum;
152
138
sum = sum* sum;
153
139
}
154
- // log(byteValue);
155
140
bytes[i] <== byteValue;
156
141
}
157
- // log("end ghash bytes");
158
142
159
143
// Step 6: Let T = MSBt(GCTRK(J0, S))
160
144
component gctrT = GCTR(16 );
0 commit comments