authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-11-10 19:00:00+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-11-10 19:00:00+01:00
log59af6417bbb93a2cca453d930320217a970040bd
treefd6967c4994cc8104c81c7a7867e4cf1affb5662
parent04b8ce5fd32776cb5c8d34c424efd40cee86412a
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

crypto.ghash: define aggregate tresholds as blocks, not bytes (#13507)

These constants were read as a block count in initForBlockCount() but at the same time, as a size in update(). The unit could be blocks or bytes, but we should use the same one everywhere. So, use blocks as intended. Fixes #13506

1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/crypto/ghash.zig+8-8
...@@ -19,10 +19,10 @@ pub const Ghash = struct {...@@ -19,10 +19,10 @@ pub const Ghash = struct {
19 pub const key_length = 16;19 pub const key_length = 16;
2020
21 const pc_count = if (builtin.mode != .ReleaseSmall) 16 else 2;21 const pc_count = if (builtin.mode != .ReleaseSmall) 16 else 2;
22 const agg_2_treshold = 5 * block_length;22 const agg_2_treshold = 5;
23 const agg_4_treshold = 22 * block_length;23 const agg_4_treshold = 22;
24 const agg_8_treshold = 84 * block_length;24 const agg_8_treshold = 84;
25 const agg_16_treshold = 328 * block_length;25 const agg_16_treshold = 328;
2626
27 hx: [pc_count]Precomp,27 hx: [pc_count]Precomp,
28 acc: u128 = 0,28 acc: u128 = 0,
...@@ -199,7 +199,7 @@ pub const Ghash = struct {...@@ -199,7 +199,7 @@ pub const Ghash = struct {
199199
200 var i: usize = 0;200 var i: usize = 0;
201201
202 if (builtin.mode != .ReleaseSmall and msg.len >= agg_16_treshold) {202 if (builtin.mode != .ReleaseSmall and msg.len >= agg_16_treshold * block_length) {
203 // 16-blocks aggregated reduction203 // 16-blocks aggregated reduction
204 while (i + 256 <= msg.len) : (i += 256) {204 while (i + 256 <= msg.len) : (i += 256) {
205 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[15 - 0]);205 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[15 - 0]);
...@@ -209,7 +209,7 @@ pub const Ghash = struct {...@@ -209,7 +209,7 @@ pub const Ghash = struct {
209 }209 }
210 acc = gcmReduce(u);210 acc = gcmReduce(u);
211 }211 }
212 } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_8_treshold) {212 } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_8_treshold * block_length) {
213 // 8-blocks aggregated reduction213 // 8-blocks aggregated reduction
214 while (i + 128 <= msg.len) : (i += 128) {214 while (i + 128 <= msg.len) : (i += 128) {
215 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[7 - 0]);215 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[7 - 0]);
...@@ -219,7 +219,7 @@ pub const Ghash = struct {...@@ -219,7 +219,7 @@ pub const Ghash = struct {
219 }219 }
220 acc = gcmReduce(u);220 acc = gcmReduce(u);
221 }221 }
222 } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_4_treshold) {222 } else if (builtin.mode != .ReleaseSmall and msg.len >= agg_4_treshold * block_length) {
223 // 4-blocks aggregated reduction223 // 4-blocks aggregated reduction
224 while (i + 64 <= msg.len) : (i += 64) {224 while (i + 64 <= msg.len) : (i += 64) {
225 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[3 - 0]);225 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[3 - 0]);
...@@ -229,7 +229,7 @@ pub const Ghash = struct {...@@ -229,7 +229,7 @@ pub const Ghash = struct {
229 }229 }
230 acc = gcmReduce(u);230 acc = gcmReduce(u);
231 }231 }
232 } else if (msg.len >= agg_2_treshold) {232 } else if (msg.len >= agg_2_treshold * block_length) {
233 // 2-blocks aggregated reduction233 // 2-blocks aggregated reduction
234 while (i + 32 <= msg.len) : (i += 32) {234 while (i + 32 <= msg.len) : (i += 32) {
235 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[1 - 0]);235 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[1 - 0]);