local testimony = require("testimony") local litls = require("litls.core") local hex = litls.hex_encode local unhex = litls.hex_decode local testify = testimony.new("== LITLS Poly1305 ==") -- RFC 8439 Section 2.5.2 - Poly1305 test vector testify:that("Poly1305 test vector (RFC 8439 2.5.2)", function() local key = unhex("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b") local msg = "Cryptographic Forum Research Group" local tag = litls.poly1305_auth(key, msg) testimony.assert_equal("a8061dc1305136c6c22b8baf0c0127a9", hex(tag)) end) -- RFC 8439 Section 2.5.2 - Poly1305 keygen test testify:that("Poly1305 key generation via ChaCha20", function() -- Generate poly1305 key from chacha20 block 0 local key = unhex("808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f") local nonce = unhex("000000000001020304050607") local block = litls.chacha20_block(key, nonce, 0) -- First 32 bytes are the poly1305 key local poly_key = block:sub(1, 32) testimony.assert_equal("8ad5a08b905f81cc815040274ab29471a833b637e3fd0da508dbb8e2fdd1a646", hex(poly_key)) end) testify:conclude()