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.

43 lines
915 B

  1. package keccak
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "testing"
  6. qt "github.com/frankban/quicktest"
  7. )
  8. func printS(n string, s []uint64) {
  9. jS, err := json.Marshal(s)
  10. if err != nil {
  11. panic(err)
  12. }
  13. fmt.Printf("%s: %s\n", n, string(jS))
  14. }
  15. func newS() ([25 * 64]bool, [25]uint64) {
  16. var s [25 * 64]bool
  17. var sU64 [25]uint64
  18. for i := 0; i < len(s)/64; i++ {
  19. copy(s[i*64:i*64+64], u64ToBits(uint64(i)))
  20. sU64[i] = uint64(i)
  21. }
  22. return s, sU64
  23. }
  24. func TestTheta(t *testing.T) {
  25. s, sU64 := newS()
  26. s = theta(s)
  27. sU64 = thetaU64Version(sU64)
  28. qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
  29. qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals,
  30. []uint64{26, 9, 13, 29, 47, 31, 14, 8, 22, 34, 16, 3, 3,
  31. 19, 37, 21, 24, 30, 12, 56, 14, 29, 25, 9, 51})
  32. // compute again theta on the current state
  33. s = theta(s)
  34. sU64 = thetaU64Version(sU64)
  35. qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:])
  36. }