block-generic.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2013 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. // Code generated by go run gen.go -output md5block.go; DO NOT EDIT.
  5. package md5simd
  6. import (
  7. "encoding/binary"
  8. "math/bits"
  9. )
  10. type digest struct {
  11. s [4]uint32
  12. x [BlockSize]byte
  13. nx int
  14. len uint64
  15. }
  16. func blockGeneric(dig *digest, p []byte) {
  17. // load state
  18. a, b, c, d := dig.s[0], dig.s[1], dig.s[2], dig.s[3]
  19. for i := 0; i <= len(p)-BlockSize; i += BlockSize {
  20. // eliminate bounds checks on p
  21. q := p[i:]
  22. q = q[:BlockSize:BlockSize]
  23. // save current state
  24. aa, bb, cc, dd := a, b, c, d
  25. // load input block
  26. x0 := binary.LittleEndian.Uint32(q[4*0x0:])
  27. x1 := binary.LittleEndian.Uint32(q[4*0x1:])
  28. x2 := binary.LittleEndian.Uint32(q[4*0x2:])
  29. x3 := binary.LittleEndian.Uint32(q[4*0x3:])
  30. x4 := binary.LittleEndian.Uint32(q[4*0x4:])
  31. x5 := binary.LittleEndian.Uint32(q[4*0x5:])
  32. x6 := binary.LittleEndian.Uint32(q[4*0x6:])
  33. x7 := binary.LittleEndian.Uint32(q[4*0x7:])
  34. x8 := binary.LittleEndian.Uint32(q[4*0x8:])
  35. x9 := binary.LittleEndian.Uint32(q[4*0x9:])
  36. xa := binary.LittleEndian.Uint32(q[4*0xa:])
  37. xb := binary.LittleEndian.Uint32(q[4*0xb:])
  38. xc := binary.LittleEndian.Uint32(q[4*0xc:])
  39. xd := binary.LittleEndian.Uint32(q[4*0xd:])
  40. xe := binary.LittleEndian.Uint32(q[4*0xe:])
  41. xf := binary.LittleEndian.Uint32(q[4*0xf:])
  42. // round 1
  43. a = b + bits.RotateLeft32((((c^d)&b)^d)+a+x0+0xd76aa478, 7)
  44. d = a + bits.RotateLeft32((((b^c)&a)^c)+d+x1+0xe8c7b756, 12)
  45. c = d + bits.RotateLeft32((((a^b)&d)^b)+c+x2+0x242070db, 17)
  46. b = c + bits.RotateLeft32((((d^a)&c)^a)+b+x3+0xc1bdceee, 22)
  47. a = b + bits.RotateLeft32((((c^d)&b)^d)+a+x4+0xf57c0faf, 7)
  48. d = a + bits.RotateLeft32((((b^c)&a)^c)+d+x5+0x4787c62a, 12)
  49. c = d + bits.RotateLeft32((((a^b)&d)^b)+c+x6+0xa8304613, 17)
  50. b = c + bits.RotateLeft32((((d^a)&c)^a)+b+x7+0xfd469501, 22)
  51. a = b + bits.RotateLeft32((((c^d)&b)^d)+a+x8+0x698098d8, 7)
  52. d = a + bits.RotateLeft32((((b^c)&a)^c)+d+x9+0x8b44f7af, 12)
  53. c = d + bits.RotateLeft32((((a^b)&d)^b)+c+xa+0xffff5bb1, 17)
  54. b = c + bits.RotateLeft32((((d^a)&c)^a)+b+xb+0x895cd7be, 22)
  55. a = b + bits.RotateLeft32((((c^d)&b)^d)+a+xc+0x6b901122, 7)
  56. d = a + bits.RotateLeft32((((b^c)&a)^c)+d+xd+0xfd987193, 12)
  57. c = d + bits.RotateLeft32((((a^b)&d)^b)+c+xe+0xa679438e, 17)
  58. b = c + bits.RotateLeft32((((d^a)&c)^a)+b+xf+0x49b40821, 22)
  59. // round 2
  60. a = b + bits.RotateLeft32((((b^c)&d)^c)+a+x1+0xf61e2562, 5)
  61. d = a + bits.RotateLeft32((((a^b)&c)^b)+d+x6+0xc040b340, 9)
  62. c = d + bits.RotateLeft32((((d^a)&b)^a)+c+xb+0x265e5a51, 14)
  63. b = c + bits.RotateLeft32((((c^d)&a)^d)+b+x0+0xe9b6c7aa, 20)
  64. a = b + bits.RotateLeft32((((b^c)&d)^c)+a+x5+0xd62f105d, 5)
  65. d = a + bits.RotateLeft32((((a^b)&c)^b)+d+xa+0x02441453, 9)
  66. c = d + bits.RotateLeft32((((d^a)&b)^a)+c+xf+0xd8a1e681, 14)
  67. b = c + bits.RotateLeft32((((c^d)&a)^d)+b+x4+0xe7d3fbc8, 20)
  68. a = b + bits.RotateLeft32((((b^c)&d)^c)+a+x9+0x21e1cde6, 5)
  69. d = a + bits.RotateLeft32((((a^b)&c)^b)+d+xe+0xc33707d6, 9)
  70. c = d + bits.RotateLeft32((((d^a)&b)^a)+c+x3+0xf4d50d87, 14)
  71. b = c + bits.RotateLeft32((((c^d)&a)^d)+b+x8+0x455a14ed, 20)
  72. a = b + bits.RotateLeft32((((b^c)&d)^c)+a+xd+0xa9e3e905, 5)
  73. d = a + bits.RotateLeft32((((a^b)&c)^b)+d+x2+0xfcefa3f8, 9)
  74. c = d + bits.RotateLeft32((((d^a)&b)^a)+c+x7+0x676f02d9, 14)
  75. b = c + bits.RotateLeft32((((c^d)&a)^d)+b+xc+0x8d2a4c8a, 20)
  76. // round 3
  77. a = b + bits.RotateLeft32((b^c^d)+a+x5+0xfffa3942, 4)
  78. d = a + bits.RotateLeft32((a^b^c)+d+x8+0x8771f681, 11)
  79. c = d + bits.RotateLeft32((d^a^b)+c+xb+0x6d9d6122, 16)
  80. b = c + bits.RotateLeft32((c^d^a)+b+xe+0xfde5380c, 23)
  81. a = b + bits.RotateLeft32((b^c^d)+a+x1+0xa4beea44, 4)
  82. d = a + bits.RotateLeft32((a^b^c)+d+x4+0x4bdecfa9, 11)
  83. c = d + bits.RotateLeft32((d^a^b)+c+x7+0xf6bb4b60, 16)
  84. b = c + bits.RotateLeft32((c^d^a)+b+xa+0xbebfbc70, 23)
  85. a = b + bits.RotateLeft32((b^c^d)+a+xd+0x289b7ec6, 4)
  86. d = a + bits.RotateLeft32((a^b^c)+d+x0+0xeaa127fa, 11)
  87. c = d + bits.RotateLeft32((d^a^b)+c+x3+0xd4ef3085, 16)
  88. b = c + bits.RotateLeft32((c^d^a)+b+x6+0x04881d05, 23)
  89. a = b + bits.RotateLeft32((b^c^d)+a+x9+0xd9d4d039, 4)
  90. d = a + bits.RotateLeft32((a^b^c)+d+xc+0xe6db99e5, 11)
  91. c = d + bits.RotateLeft32((d^a^b)+c+xf+0x1fa27cf8, 16)
  92. b = c + bits.RotateLeft32((c^d^a)+b+x2+0xc4ac5665, 23)
  93. // round 4
  94. a = b + bits.RotateLeft32((c^(b|^d))+a+x0+0xf4292244, 6)
  95. d = a + bits.RotateLeft32((b^(a|^c))+d+x7+0x432aff97, 10)
  96. c = d + bits.RotateLeft32((a^(d|^b))+c+xe+0xab9423a7, 15)
  97. b = c + bits.RotateLeft32((d^(c|^a))+b+x5+0xfc93a039, 21)
  98. a = b + bits.RotateLeft32((c^(b|^d))+a+xc+0x655b59c3, 6)
  99. d = a + bits.RotateLeft32((b^(a|^c))+d+x3+0x8f0ccc92, 10)
  100. c = d + bits.RotateLeft32((a^(d|^b))+c+xa+0xffeff47d, 15)
  101. b = c + bits.RotateLeft32((d^(c|^a))+b+x1+0x85845dd1, 21)
  102. a = b + bits.RotateLeft32((c^(b|^d))+a+x8+0x6fa87e4f, 6)
  103. d = a + bits.RotateLeft32((b^(a|^c))+d+xf+0xfe2ce6e0, 10)
  104. c = d + bits.RotateLeft32((a^(d|^b))+c+x6+0xa3014314, 15)
  105. b = c + bits.RotateLeft32((d^(c|^a))+b+xd+0x4e0811a1, 21)
  106. a = b + bits.RotateLeft32((c^(b|^d))+a+x4+0xf7537e82, 6)
  107. d = a + bits.RotateLeft32((b^(a|^c))+d+xb+0xbd3af235, 10)
  108. c = d + bits.RotateLeft32((a^(d|^b))+c+x2+0x2ad7d2bb, 15)
  109. b = c + bits.RotateLeft32((d^(c|^a))+b+x9+0xeb86d391, 21)
  110. // add saved state
  111. a += aa
  112. b += bb
  113. c += cc
  114. d += dd
  115. }
  116. // save state
  117. dig.s[0], dig.s[1], dig.s[2], dig.s[3] = a, b, c, d
  118. }