local testimony = require("testimony") local litls = require("litls.core") local hex = litls.hex_encode local unhex = litls.hex_decode local testify = testimony.new("== LITLS ChaCha20 ==") -- RFC 8439 Section 2.3.2 - ChaCha20 block function test vector testify:that("ChaCha20 block function", function() local key = unhex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") local nonce = unhex("000000090000004a00000000") local counter = 1 local block = litls.chacha20_block(key, nonce, counter) testimony.assert_equal( "10f1e7e4d13b5915500fdd1fa32071c4c7d1f4c733c068030422aa9ac3d46c4e" .. "d2826446079faa0914c2d705d98b02a2b5129cd1de164eb9cbd083e8a2503c4e", hex(block) ) end) -- RFC 8439 Section 2.4.2 - ChaCha20 encryption test vector (Sunscreen) testify:that("ChaCha20 encryption (Sunscreen)", function() local key = unhex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") local nonce = unhex("000000000000004a00000000") local counter = 1 local plaintext = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it." local ct = litls.chacha20_encrypt(key, nonce, counter, plaintext) testimony.assert_equal( "6e2e359a2568f98041ba0728dd0d6981e97e7aec1d4360c20a27afccfd9fae0bf91b65c5524733ab8f593dabcd62b3571639d624e65152ab8f530c359f0861d807ca0dbf500d6a6156a38e088a22b65e52bc514d16ccf806818ce91ab77937365af90bbf74a35be6b40b8eedf2785e42874d", hex(ct) ) end) testify:conclude()