You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 lines
909 B

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