chacha_test.go 749 B

1234567891011121314151617181920212223242526272829
  1. package chacha20
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. )
  6. func TestCore(t *testing.T) {
  7. // This is just a smoke test that checks the example from
  8. // https://tools.ietf.org/html/rfc7539#section-2.3.2. The
  9. // chacha20poly1305 package contains much more extensive tests of this
  10. // code.
  11. var key [32]byte
  12. for i := range key {
  13. key[i] = byte(i)
  14. }
  15. var input [16]byte
  16. input[0] = 1
  17. input[7] = 9
  18. input[11] = 0x4a
  19. var out [64]byte
  20. XORKeyStream(out[:], out[:], &input, &key)
  21. const expected = "10f1e7e4d13b5915500fdd1fa32071c4c7d1f4c733c068030422aa9ac3d46c4ed2826446079faa0914c2d705d98b02a2b5129cd1de164eb9cbd083e8a2503c4e"
  22. if result := hex.EncodeToString(out[:]); result != expected {
  23. t.Errorf("wanted %x but got %x", expected, result)
  24. }
  25. }