burn_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // burn_test.go - burn tests
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to the software, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. package hs1siv
  8. import (
  9. "crypto/rand"
  10. "encoding/binary"
  11. "testing"
  12. "github.com/stretchr/testify/require"
  13. )
  14. // While it seems somewhat silly to test memset, the unsafe implementation
  15. // uses trickery to reach into the runtime library, so it's worth exercising.
  16. func TestBurnBytes(t *testing.T) {
  17. require := require.New(t)
  18. var buf [1024]byte
  19. require.Zero(buf, "buf: Before random read")
  20. _, err := rand.Read(buf[:])
  21. require.NoError(err, "rand.Read()")
  22. require.NotZero(buf, "buf: After random read")
  23. burnBytes(buf[:])
  24. require.Zero(buf, "buf: After burnBytes()")
  25. }
  26. func TestBurnUint64s(t *testing.T) {
  27. require := require.New(t)
  28. var buf [1024]uint64
  29. require.Zero(buf, "buf: Before random read")
  30. err := binary.Read(rand.Reader, binary.LittleEndian, &buf)
  31. require.NoError(err, "binary.Read(rand.Reader)")
  32. require.NotZero(buf, "buf: After random read")
  33. burnUint64s(buf[:])
  34. require.Zero(buf, "buf: After burnUint64s()")
  35. }
  36. func TestBurnUint32s(t *testing.T) {
  37. require := require.New(t)
  38. var buf [1024]uint32
  39. require.Zero(buf, "buf: Before random read")
  40. err := binary.Read(rand.Reader, binary.LittleEndian, &buf)
  41. require.NoError(err, "binary.Read(rand.Reader)")
  42. require.NotZero(buf, "buf: After random read")
  43. burnUint32s(buf[:])
  44. require.Zero(buf, "buf: After burnUint32s()")
  45. }