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 {...@@ -85,7 +85,7 @@ const State128L = struct {
85/// The 128L variant of AEGIS has a 128 bit key, a 128 bit nonce, and processes 256 bit message blocks.85/// The 128L variant of AEGIS has a 128 bit key, a 128 bit nonce, and processes 256 bit message blocks.
86/// It was designed to fully exploit the parallelism and built-in AES support of recent Intel and ARM CPUs.86/// It was designed to fully exploit the parallelism and built-in AES support of recent Intel and ARM CPUs.
87///87///
88/// https://eprint.iacr.org/2013/695.pdf88/// https://competitions.cr.yp.to/round3/aegisv11.pdf
89pub const AEGIS128L = struct {89pub const AEGIS128L = struct {
90 pub const tag_length = 16;90 pub const tag_length = 16;
91 pub const nonce_length = 16;91 pub const nonce_length = 16;
...@@ -247,7 +247,7 @@ const State256 = struct {...@@ -247,7 +247,7 @@ const State256 = struct {
247///247///
248/// The 256 bit variant of AEGIS has a 256 bit key, a 256 bit nonce, and processes 128 bit message blocks.248/// The 256 bit variant of AEGIS has a 256 bit key, a 256 bit nonce, and processes 128 bit message blocks.
249///249///
250/// https://eprint.iacr.org/2013/695.pdf250/// https://competitions.cr.yp.to/round3/aegisv11.pdf
251pub const AEGIS256 = struct {251pub const AEGIS256 = struct {
252 pub const tag_length = 16;252 pub const tag_length = 16;
253 pub const nonce_length = 32;253 pub const nonce_length = 32;
...@@ -374,6 +374,22 @@ test "AEGIS128L test vector 2" {...@@ -374,6 +374,22 @@ test "AEGIS128L test vector 2" {
374 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);374 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
375}375}
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
377test "AEGIS256 test vector 1" {393test "AEGIS256 test vector 1" {
378 const key: [AEGIS256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30;394 const key: [AEGIS256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30;
379 const nonce: [AEGIS256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29;395 const nonce: [AEGIS256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29;
...@@ -413,3 +429,19 @@ test "AEGIS256 test vector 2" {...@@ -413,3 +429,19 @@ test "AEGIS256 test vector 2" {
413 htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);429 htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
414 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);430 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
415}431}
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}