authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-12-28 23:08:23+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-28 21:28:39-08:00
log8ab870cf56e499258e19b23062f1830c73dbe6a3
tree79a6ed975f9cb19856f4a39f5968a51de823c398
parent1dd5c032bf8116a8f75dd814e2450f7afe3f91eb

std/crypto: increment the correct words for vectorized salsa20

Add a test for this by the way. Fixes #7579

1 files changed, 12 insertions(+), 3 deletions(-)

lib/std/crypto/salsa20.zig+12-3
......@@ -146,9 +146,9 @@ const Salsa20VecImpl = struct {
146146 while (j < 64) : (j += 1) {
147147 xout[j] ^= buf[j];
148148 }
149 ctx[2][0] +%= 1;
150 if (ctx[2][0] == 0) {
151 ctx[2][1] += 1;
149 ctx[3][2] +%= 1;
150 if (ctx[3][2] == 0) {
151 ctx[3][3] += 1;
152152 }
153153 }
154154 if (i < in.len) {
......@@ -617,3 +617,12 @@ test "xsalsa20poly1305 sealedbox" {
617617 try SealedBox.seal(boxed[0..], msg[0..], kp.public_key);
618618 try SealedBox.open(msg2[0..], boxed[0..], kp);
619619}
620
621test "secretbox twoblocks" {
622 const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b };
623 const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc };
624 const msg = [_]u8{'a'} ** 97;
625 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
626 SecretBox.seal(&ciphertext, &msg, nonce, key);
627 htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
628}