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 {
1919 pub const key_length = 16;
2020
2121 const pc_count = if (builtin.mode != .ReleaseSmall) 16 else 2;
22 const agg_2_treshold = 5 * block_length;
23 const agg_4_treshold = 22 * block_length;
24 const agg_8_treshold = 84 * block_length;
25 const agg_16_treshold = 328 * block_length;
22 const agg_2_treshold = 5;
23 const agg_4_treshold = 22;
24 const agg_8_treshold = 84;
25 const agg_16_treshold = 328;
2626
2727 hx: [pc_count]Precomp,
2828 acc: u128 = 0,
......@@ -199,7 +199,7 @@ pub const Ghash = struct {
199199
200200 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) {
203203 // 16-blocks aggregated reduction
204204 while (i + 256 <= msg.len) : (i += 256) {
205205 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[15 - 0]);
......@@ -209,7 +209,7 @@ pub const Ghash = struct {
209209 }
210210 acc = gcmReduce(u);
211211 }
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) {
213213 // 8-blocks aggregated reduction
214214 while (i + 128 <= msg.len) : (i += 128) {
215215 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[7 - 0]);
......@@ -219,7 +219,7 @@ pub const Ghash = struct {
219219 }
220220 acc = gcmReduce(u);
221221 }
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) {
223223 // 4-blocks aggregated reduction
224224 while (i + 64 <= msg.len) : (i += 64) {
225225 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[3 - 0]);
......@@ -229,7 +229,7 @@ pub const Ghash = struct {
229229 }
230230 acc = gcmReduce(u);
231231 }
232 } else if (msg.len >= agg_2_treshold) {
232 } else if (msg.len >= agg_2_treshold * block_length) {
233233 // 2-blocks aggregated reduction
234234 while (i + 32 <= msg.len) : (i += 32) {
235235 var u = clmul128(acc ^ mem.readIntBig(u128, msg[i..][0..16]), st.hx[1 - 0]);