1package wesh23import (4 "encoding/hex"5 "testing"67 "gno.land/p/nt/uassert/v0"8)910// TestHMACSHA256RFC4231 checks the HMAC construction against the published11// RFC 4231 vectors. Case 6 matters most: its key is longer than the block12// size, which is the branch that hashes the key down first and the one most13// easily got wrong.14func TestHMACSHA256RFC4231(t *testing.T) {15 cases := []struct {16 name string17 key []byte18 data []byte19 want string20 }{21 {22 "rfc4231 case 1",23 repeat(0x0b, 20),24 []byte("Hi There"),25 "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7",26 },27 {28 "rfc4231 case 2",29 []byte("Jefe"),30 []byte("what do ya want for nothing?"),31 "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",32 },33 {34 "rfc4231 case 6 (key longer than the block size)",35 repeat(0xaa, 131),36 []byte("Test Using Larger Than Block-Size Key - Hash Key First"),37 "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54",38 },39 }40 for _, tc := range cases {41 got := hex.EncodeToString(HMACSHA256(tc.key, tc.data))42 uassert.Equal(t, tc.want, got, tc.name)43 }44}4546// repeat returns n copies of b.47func repeat(b byte, n int) []byte {48 out := make([]byte, n)49 for i := range out {50 out[i] = b51 }52 return out53}54Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.