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.

98 lines
2.0 KiB

  1. // Use of this source code is governed by an ISC
  2. // license that can be found in the LICENSE file.
  3. package x11
  4. import (
  5. "gitlab.com/nitya-sattva/go-x11/blake"
  6. "gitlab.com/nitya-sattva/go-x11/bmw"
  7. "gitlab.com/nitya-sattva/go-x11/cubed"
  8. "gitlab.com/nitya-sattva/go-x11/echo"
  9. "gitlab.com/nitya-sattva/go-x11/groest"
  10. "gitlab.com/nitya-sattva/go-x11/hash"
  11. "gitlab.com/nitya-sattva/go-x11/jhash"
  12. "gitlab.com/nitya-sattva/go-x11/keccak"
  13. "gitlab.com/nitya-sattva/go-x11/luffa"
  14. "gitlab.com/nitya-sattva/go-x11/shavite"
  15. "gitlab.com/nitya-sattva/go-x11/simd"
  16. "gitlab.com/nitya-sattva/go-x11/skein"
  17. )
  18. ////////////////
  19. // Hash contains the state objects
  20. // required to perform the x11.Hash.
  21. type Hash struct {
  22. tha [64]byte
  23. thb [64]byte
  24. blake hash.Digest
  25. bmw hash.Digest
  26. cubed hash.Digest
  27. echo hash.Digest
  28. groest hash.Digest
  29. jhash hash.Digest
  30. keccak hash.Digest
  31. luffa hash.Digest
  32. shavite hash.Digest
  33. simd hash.Digest
  34. skein hash.Digest
  35. }
  36. // New returns a new object to compute a x11 hash.
  37. func New() *Hash {
  38. ref := &Hash{}
  39. ref.blake = blake.New()
  40. ref.bmw = bmw.New()
  41. ref.cubed = cubed.New()
  42. ref.echo = echo.New()
  43. ref.groest = groest.New()
  44. ref.jhash = jhash.New()
  45. ref.keccak = keccak.New()
  46. ref.luffa = luffa.New()
  47. ref.shavite = shavite.New()
  48. ref.simd = simd.New()
  49. ref.skein = skein.New()
  50. return ref
  51. }
  52. // Hash computes the hash from the src bytes and stores the result in dst.
  53. func (ref *Hash) Hash(src []byte, dst []byte) {
  54. ta := ref.tha[:]
  55. tb := ref.thb[:]
  56. ref.blake.Write(src)
  57. ref.blake.Close(tb, 0, 0)
  58. ref.bmw.Write(tb)
  59. ref.bmw.Close(ta, 0, 0)
  60. ref.groest.Write(ta)
  61. ref.groest.Close(tb, 0, 0)
  62. ref.skein.Write(tb)
  63. ref.skein.Close(ta, 0, 0)
  64. ref.jhash.Write(ta)
  65. ref.jhash.Close(tb, 0, 0)
  66. ref.keccak.Write(tb)
  67. ref.keccak.Close(ta, 0, 0)
  68. ref.luffa.Write(ta)
  69. ref.luffa.Close(tb, 0, 0)
  70. ref.cubed.Write(tb)
  71. ref.cubed.Close(ta, 0, 0)
  72. ref.shavite.Write(ta)
  73. ref.shavite.Close(tb, 0, 0)
  74. ref.simd.Write(tb)
  75. ref.simd.Close(ta, 0, 0)
  76. ref.echo.Write(ta)
  77. ref.echo.Close(tb, 0, 0)
  78. copy(dst, tb)
  79. }