authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-09-28 15:02:11+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-09-29 17:10:04+02:00
log8d67f15d36bdd1a094596876796c77606a5e4a83
tree4ea23b42faea5cd77b10aaa10cbb5a7f56a1df65
parentbb1c6bc376f1a30d6dadd4aebcd1ebec6b4c8621

aegis: add test vectors, and link to the latest version of the spec


1 files changed, 34 insertions(+), 2 deletions(-)

lib/std/crypto/aegis.zig+34-2
......@@ -85,7 +85,7 @@ const State128L = struct {
8585/// The 128L variant of AEGIS has a 128 bit key, a 128 bit nonce, and processes 256 bit message blocks.
8686/// It was designed to fully exploit the parallelism and built-in AES support of recent Intel and ARM CPUs.
8787///
88/// https://eprint.iacr.org/2013/695.pdf
88/// https://competitions.cr.yp.to/round3/aegisv11.pdf
8989pub const AEGIS128L = struct {
9090 pub const tag_length = 16;
9191 pub const nonce_length = 16;
......@@ -247,7 +247,7 @@ const State256 = struct {
247247///
248248/// The 256 bit variant of AEGIS has a 256 bit key, a 256 bit nonce, and processes 128 bit message blocks.
249249///
250/// https://eprint.iacr.org/2013/695.pdf
250/// https://competitions.cr.yp.to/round3/aegisv11.pdf
251251pub const AEGIS256 = struct {
252252 pub const tag_length = 16;
253253 pub const nonce_length = 32;
......@@ -374,6 +374,22 @@ test "AEGIS128L test vector 2" {
374374 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
375375}
376376
377test "AEGIS128L test vector 3" {
378 const key: [AEGIS128L.key_length]u8 = [_]u8{0x00} ** 16;
379 const nonce: [AEGIS128L.nonce_length]u8 = [_]u8{0x00} ** 16;
380 const ad = [_]u8{};
381 const m = [_]u8{};
382 var c: [m.len]u8 = undefined;
383 var m2: [m.len]u8 = undefined;
384 var tag: [AEGIS128L.tag_length]u8 = undefined;
385
386 AEGIS128L.encrypt(&c, &tag, &m, &ad, nonce, key);
387 try AEGIS128L.decrypt(&m2, &c, tag, &ad, nonce, key);
388 testing.expectEqualSlices(u8, &m, &m2);
389
390 htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
391}
392
377393test "AEGIS256 test vector 1" {
378394 const key: [AEGIS256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30;
379395 const nonce: [AEGIS256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29;
......@@ -413,3 +429,19 @@ test "AEGIS256 test vector 2" {
413429 htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
414430 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
415431}
432
433test "AEGIS256 test vector 3" {
434 const key: [AEGIS256.key_length]u8 = [_]u8{0x00} ** 32;
435 const nonce: [AEGIS256.nonce_length]u8 = [_]u8{0x00} ** 32;
436 const ad = [_]u8{};
437 const m = [_]u8{};
438 var c: [m.len]u8 = undefined;
439 var m2: [m.len]u8 = undefined;
440 var tag: [AEGIS256.tag_length]u8 = undefined;
441
442 AEGIS256.encrypt(&c, &tag, &m, &ad, nonce, key);
443 try AEGIS256.decrypt(&m2, &c, tag, &ad, nonce, key);
444 testing.expectEqualSlices(u8, &m, &m2);
445
446 htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
447}