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.

561 lines
16 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package cryptonight
  17. import "fmt"
  18. import "gitlab.com/nitya-sattva/go-x11/hash"
  19. // HashSize holds the size of a hash in bytes.
  20. const HashSize = int(32)
  21. // BlockSize holds the size of a block in bytes.
  22. const BlockSize = uintptr(64)
  23. ////////////////
  24. type digest struct {
  25. ptr uintptr
  26. cnt uintptr
  27. h [16]uint64
  28. b [BlockSize]byte
  29. }
  30. // New returns a new digest compute a JH256 hash.
  31. func NewJhash256() hash.Digest {
  32. ref := &digest{}
  33. ref.Reset()
  34. return ref
  35. }
  36. ////////////////
  37. // Reset resets the digest to its initial state.
  38. func (ref *digest) Reset() {
  39. ref.ptr = 0
  40. ref.cnt = 0
  41. copy(ref.h[:], kInit[:])
  42. }
  43. // Sum appends the current hash to dst and returns the result
  44. // as a slice. It does not change the underlying hash state.
  45. func (ref *digest) Sum(dst []byte) []byte {
  46. dgt := *ref
  47. hsh := [64]byte{}
  48. dgt.Close(hsh[:], 0, 0)
  49. return append(dst, hsh[32:]...)
  50. }
  51. // Write more data to the running hash, never returns an error.
  52. func (ref *digest) Write(src []byte) (int, error) {
  53. sln := uintptr(len(src))
  54. fln := len(src)
  55. buf := ref.b[:]
  56. ptr := ref.ptr
  57. if sln < (BlockSize - ptr) {
  58. copy(buf[ptr:], src)
  59. ref.ptr += sln
  60. return int(sln), nil
  61. }
  62. var hi, lo [8]uint64
  63. hi[0] = ref.h[0x0]
  64. lo[0] = ref.h[0x1]
  65. hi[1] = ref.h[0x2]
  66. lo[1] = ref.h[0x3]
  67. hi[2] = ref.h[0x4]
  68. lo[2] = ref.h[0x5]
  69. hi[3] = ref.h[0x6]
  70. lo[3] = ref.h[0x7]
  71. hi[4] = ref.h[0x8]
  72. lo[4] = ref.h[0x9]
  73. hi[5] = ref.h[0xA]
  74. lo[5] = ref.h[0xB]
  75. hi[6] = ref.h[0xC]
  76. lo[6] = ref.h[0xD]
  77. hi[7] = ref.h[0xE]
  78. lo[7] = ref.h[0xF]
  79. for sln > 0 {
  80. cln := BlockSize - ptr
  81. if cln > sln {
  82. cln = sln
  83. }
  84. sln -= cln
  85. copy(ref.b[ptr:], src[:cln])
  86. src = src[cln:]
  87. ptr += cln
  88. if ptr == BlockSize {
  89. m0h := decUInt64le(buf[0:])
  90. m0l := decUInt64le(buf[8:])
  91. m1h := decUInt64le(buf[16:])
  92. m1l := decUInt64le(buf[24:])
  93. m2h := decUInt64le(buf[32:])
  94. m2l := decUInt64le(buf[40:])
  95. m3h := decUInt64le(buf[48:])
  96. m3l := decUInt64le(buf[56:])
  97. hi[0] ^= m0h
  98. lo[0] ^= m0l
  99. hi[1] ^= m1h
  100. lo[1] ^= m1l
  101. hi[2] ^= m2h
  102. lo[2] ^= m2l
  103. hi[3] ^= m3h
  104. lo[3] ^= m3l
  105. for r := uint64(0); r < 42; r += 7 {
  106. slMutateExtend(r+0, 0, hi[:], lo[:])
  107. slMutateExtend(r+1, 1, hi[:], lo[:])
  108. slMutateExtend(r+2, 2, hi[:], lo[:])
  109. slMutateExtend(r+3, 3, hi[:], lo[:])
  110. slMutateExtend(r+4, 4, hi[:], lo[:])
  111. slMutateExtend(r+5, 5, hi[:], lo[:])
  112. slMutateBasic(r+6, hi[:], lo[:])
  113. }
  114. hi[4] ^= m0h
  115. lo[4] ^= m0l
  116. hi[5] ^= m1h
  117. lo[5] ^= m1l
  118. hi[6] ^= m2h
  119. lo[6] ^= m2l
  120. hi[7] ^= m3h
  121. lo[7] ^= m3l
  122. ref.cnt++
  123. ptr = 0
  124. }
  125. }
  126. ref.h[0x0] = hi[0]
  127. ref.h[0x1] = lo[0]
  128. ref.h[0x2] = hi[1]
  129. ref.h[0x3] = lo[1]
  130. ref.h[0x4] = hi[2]
  131. ref.h[0x5] = lo[2]
  132. ref.h[0x6] = hi[3]
  133. ref.h[0x7] = lo[3]
  134. ref.h[0x8] = hi[4]
  135. ref.h[0x9] = lo[4]
  136. ref.h[0xA] = hi[5]
  137. ref.h[0xB] = lo[5]
  138. ref.h[0xC] = hi[6]
  139. ref.h[0xD] = lo[6]
  140. ref.h[0xE] = hi[7]
  141. ref.h[0xF] = lo[7]
  142. ref.ptr = ptr
  143. return fln, nil
  144. }
  145. // Close the digest by writing the last bits and storing the hash
  146. // in dst. This prepares the digest for reuse by calling reset. A call
  147. // to Close with a dst that is smaller then HashSize will return an error.
  148. func (ref *digest) Close(dst []byte, bits uint8, bcnt uint8) error {
  149. if ln := len(dst); HashSize > ln {
  150. return fmt.Errorf("JHash Close: dst min length: %d, got %d", HashSize, ln)
  151. }
  152. var ocnt uintptr
  153. var buf [128]uint8
  154. {
  155. off := uint8(0x80) >> bcnt
  156. buf[0] = uint8((bits & -off) | off)
  157. }
  158. if ref.ptr == 0 && bcnt == 0 {
  159. ocnt = 47
  160. } else {
  161. ocnt = 111 - ref.ptr
  162. }
  163. l0 := uint64(bcnt)
  164. l0 += uint64(ref.cnt << 9)
  165. l0 += uint64(ref.ptr << 3)
  166. l1 := uint64(ref.cnt >> 55)
  167. encUInt64be(buf[ocnt+1:], l1)
  168. encUInt64be(buf[ocnt+9:], l0)
  169. ref.Write(buf[:ocnt+17])
  170. for u := uintptr(0); u < 8; u++ {
  171. encUInt64le(dst[(u<<3):], ref.h[u+8])
  172. }
  173. ref.Reset()
  174. return nil
  175. }
  176. // Size returns the number of bytes required to store the hash.
  177. func (*digest) Size() int {
  178. return HashSize
  179. }
  180. // BlockSize returns the block size of the hash.
  181. func (*digest) BlockSize() int {
  182. return int(BlockSize)
  183. }
  184. ////////////////
  185. func decUInt64le(src []byte) uint64 {
  186. return (uint64(src[0]) |
  187. uint64(src[1])<<8 |
  188. uint64(src[2])<<16 |
  189. uint64(src[3])<<24 |
  190. uint64(src[4])<<32 |
  191. uint64(src[5])<<40 |
  192. uint64(src[6])<<48 |
  193. uint64(src[7])<<56)
  194. }
  195. func encUInt64le(dst []byte, src uint64) {
  196. dst[0] = uint8(src)
  197. dst[1] = uint8(src >> 8)
  198. dst[2] = uint8(src >> 16)
  199. dst[3] = uint8(src >> 24)
  200. dst[4] = uint8(src >> 32)
  201. dst[5] = uint8(src >> 40)
  202. dst[6] = uint8(src >> 48)
  203. dst[7] = uint8(src >> 56)
  204. }
  205. func encUInt64be(dst []byte, src uint64) {
  206. dst[0] = uint8(src >> 56)
  207. dst[1] = uint8(src >> 48)
  208. dst[2] = uint8(src >> 40)
  209. dst[3] = uint8(src >> 32)
  210. dst[4] = uint8(src >> 24)
  211. dst[5] = uint8(src >> 16)
  212. dst[6] = uint8(src >> 8)
  213. dst[7] = uint8(src)
  214. }
  215. func slMutateBasic(r uint64, hi, lo []uint64) {
  216. var tmp uint64
  217. tmp = kSpec[(r<<2)+0]
  218. hi[6] = ^hi[6]
  219. hi[0] ^= tmp & ^hi[4]
  220. tmp = tmp ^ (hi[0] & hi[2])
  221. hi[0] ^= hi[4] & hi[6]
  222. hi[6] ^= ^hi[2] & hi[4]
  223. hi[2] ^= hi[0] & hi[4]
  224. hi[4] ^= hi[0] & ^hi[6]
  225. hi[0] ^= hi[2] | hi[6]
  226. hi[6] ^= hi[2] & hi[4]
  227. hi[2] ^= tmp & hi[0]
  228. hi[4] ^= tmp
  229. tmp = kSpec[(r<<2)+1]
  230. lo[6] = ^lo[6]
  231. lo[0] ^= tmp & ^lo[4]
  232. tmp = tmp ^ (lo[0] & lo[2])
  233. lo[0] ^= lo[4] & lo[6]
  234. lo[6] ^= ^lo[2] & lo[4]
  235. lo[2] ^= lo[0] & lo[4]
  236. lo[4] ^= lo[0] & ^lo[6]
  237. lo[0] ^= lo[2] | lo[6]
  238. lo[6] ^= lo[2] & lo[4]
  239. lo[2] ^= tmp & lo[0]
  240. lo[4] ^= tmp
  241. tmp = kSpec[(r<<2)+2]
  242. hi[7] = ^hi[7]
  243. hi[1] ^= tmp & ^hi[5]
  244. tmp = tmp ^ (hi[1] & hi[3])
  245. hi[1] ^= hi[5] & hi[7]
  246. hi[7] ^= ^hi[3] & hi[5]
  247. hi[3] ^= hi[1] & hi[5]
  248. hi[5] ^= hi[1] & ^hi[7]
  249. hi[1] ^= hi[3] | hi[7]
  250. hi[7] ^= hi[3] & hi[5]
  251. hi[3] ^= tmp & hi[1]
  252. hi[5] ^= tmp
  253. tmp = kSpec[(r<<2)+3]
  254. lo[7] = ^lo[7]
  255. lo[1] ^= tmp & ^lo[5]
  256. tmp = tmp ^ (lo[1] & lo[3])
  257. lo[1] ^= lo[5] & lo[7]
  258. lo[7] ^= ^lo[3] & lo[5]
  259. lo[3] ^= lo[1] & lo[5]
  260. lo[5] ^= lo[1] & ^lo[7]
  261. lo[1] ^= lo[3] | lo[7]
  262. lo[7] ^= lo[3] & lo[5]
  263. lo[3] ^= tmp & lo[1]
  264. lo[5] ^= tmp
  265. hi[1] ^= hi[2]
  266. hi[3] ^= hi[4]
  267. hi[5] ^= hi[6] ^ hi[0]
  268. hi[7] ^= hi[0]
  269. hi[0] ^= hi[3]
  270. hi[2] ^= hi[5]
  271. hi[4] ^= hi[7] ^ hi[1]
  272. hi[6] ^= hi[1]
  273. lo[1] ^= lo[2]
  274. lo[3] ^= lo[4]
  275. lo[5] ^= lo[6] ^ lo[0]
  276. lo[7] ^= lo[0]
  277. lo[0] ^= lo[3]
  278. lo[2] ^= lo[5]
  279. lo[4] ^= lo[7] ^ lo[1]
  280. lo[6] ^= lo[1]
  281. tmp = hi[1]
  282. hi[1] = lo[1]
  283. lo[1] = tmp
  284. tmp = hi[3]
  285. hi[3] = lo[3]
  286. lo[3] = tmp
  287. tmp = hi[5]
  288. hi[5] = lo[5]
  289. lo[5] = tmp
  290. tmp = hi[7]
  291. hi[7] = lo[7]
  292. lo[7] = tmp
  293. }
  294. func slMutateExtend(r, ro uint64, hi, lo []uint64) {
  295. var tmp uint64
  296. tmp = kSpec[(r<<2)+0]
  297. hi[6] = ^hi[6]
  298. hi[0] ^= tmp & ^hi[4]
  299. tmp = tmp ^ (hi[0] & hi[2])
  300. hi[0] ^= hi[4] & hi[6]
  301. hi[6] ^= ^hi[2] & hi[4]
  302. hi[2] ^= hi[0] & hi[4]
  303. hi[4] ^= hi[0] & ^hi[6]
  304. hi[0] ^= hi[2] | hi[6]
  305. hi[6] ^= hi[2] & hi[4]
  306. hi[2] ^= tmp & hi[0]
  307. hi[4] ^= tmp
  308. tmp = kSpec[(r<<2)+1]
  309. lo[6] = ^lo[6]
  310. lo[0] ^= tmp & ^lo[4]
  311. tmp = tmp ^ (lo[0] & lo[2])
  312. lo[0] ^= lo[4] & lo[6]
  313. lo[6] ^= ^lo[2] & lo[4]
  314. lo[2] ^= lo[0] & lo[4]
  315. lo[4] ^= lo[0] & ^lo[6]
  316. lo[0] ^= lo[2] | lo[6]
  317. lo[6] ^= lo[2] & lo[4]
  318. lo[2] ^= tmp & lo[0]
  319. lo[4] ^= tmp
  320. tmp = kSpec[(r<<2)+2]
  321. hi[7] = ^hi[7]
  322. hi[1] ^= tmp & ^hi[5]
  323. tmp = tmp ^ (hi[1] & hi[3])
  324. hi[1] ^= hi[5] & hi[7]
  325. hi[7] ^= ^hi[3] & hi[5]
  326. hi[3] ^= hi[1] & hi[5]
  327. hi[5] ^= hi[1] & ^hi[7]
  328. hi[1] ^= hi[3] | hi[7]
  329. hi[7] ^= hi[3] & hi[5]
  330. hi[3] ^= tmp & hi[1]
  331. hi[5] ^= tmp
  332. tmp = kSpec[(r<<2)+3]
  333. lo[7] = ^lo[7]
  334. lo[1] ^= tmp & ^lo[5]
  335. tmp = tmp ^ (lo[1] & lo[3])
  336. lo[1] ^= lo[5] & lo[7]
  337. lo[7] ^= ^lo[3] & lo[5]
  338. lo[3] ^= lo[1] & lo[5]
  339. lo[5] ^= lo[1] & ^lo[7]
  340. lo[1] ^= lo[3] | lo[7]
  341. lo[7] ^= lo[3] & lo[5]
  342. lo[3] ^= tmp & lo[1]
  343. lo[5] ^= tmp
  344. hi[1] ^= hi[2]
  345. hi[3] ^= hi[4]
  346. hi[5] ^= hi[6] ^ hi[0]
  347. hi[7] ^= hi[0]
  348. hi[0] ^= hi[3]
  349. hi[2] ^= hi[5]
  350. hi[4] ^= hi[7] ^ hi[1]
  351. hi[6] ^= hi[1]
  352. lo[1] ^= lo[2]
  353. lo[3] ^= lo[4]
  354. lo[5] ^= lo[6] ^ lo[0]
  355. lo[7] ^= lo[0]
  356. lo[0] ^= lo[3]
  357. lo[2] ^= lo[5]
  358. lo[4] ^= lo[7] ^ lo[1]
  359. lo[6] ^= lo[1]
  360. tmp = (hi[1] & (kWrapValue[ro])) << (kWrapOffset[ro])
  361. hi[1] = ((hi[1] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  362. tmp = (lo[1] & (kWrapValue[ro])) << (kWrapOffset[ro])
  363. lo[1] = ((lo[1] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  364. tmp = (hi[3] & (kWrapValue[ro])) << (kWrapOffset[ro])
  365. hi[3] = ((hi[3] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  366. tmp = (lo[3] & (kWrapValue[ro])) << (kWrapOffset[ro])
  367. lo[3] = ((lo[3] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  368. tmp = (hi[5] & (kWrapValue[ro])) << (kWrapOffset[ro])
  369. hi[5] = ((hi[5] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  370. tmp = (lo[5] & (kWrapValue[ro])) << (kWrapOffset[ro])
  371. lo[5] = ((lo[5] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  372. tmp = (hi[7] & (kWrapValue[ro])) << (kWrapOffset[ro])
  373. hi[7] = ((hi[7] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  374. tmp = (lo[7] & (kWrapValue[ro])) << (kWrapOffset[ro])
  375. lo[7] = ((lo[7] >> (kWrapOffset[ro])) & (kWrapValue[ro])) | tmp
  376. }
  377. ////////////////
  378. /* these constants are for 512 bit hash */
  379. /*var kInit = []uint64{
  380. uint64(0x17aa003e964bd16f), uint64(0x43d5157a052e6a63),
  381. uint64(0x0bef970c8d5e228a), uint64(0x61c3b3f2591234e9),
  382. uint64(0x1e806f53c1a01d89), uint64(0x806d2bea6b05a92a),
  383. uint64(0xa6ba7520dbcc8e58), uint64(0xf73bf8ba763a0fa9),
  384. uint64(0x694ae34105e66901), uint64(0x5ae66f2e8e8ab546),
  385. uint64(0x243c84c1d0a74710), uint64(0x99c15a2db1716e3b),
  386. uint64(0x56f8b19decf657cf), uint64(0x56b116577c8806a7),
  387. uint64(0xfb1785e6dffcc2e3), uint64(0x4bdd8ccc78465a54),
  388. }*/
  389. // these constants are for 256 bit hash
  390. var kInit = []uint64{
  391. uint64(0xEBD3202C41A398EB), uint64(0xC145B29C7BBECD92),
  392. uint64(0xFAC7D4609151931C), uint64(0x38A507ED6820026),
  393. uint64(0x45B92677269E23A4), uint64(0x77941AD4481AFBE0),
  394. uint64(0x7A176B0226ABB5CD), uint64(0xA82FFF0F4224F056),
  395. uint64(0x754D2E7F8996A371), uint64(0x62E27DF70849141D),
  396. uint64(0x948F2476F7957627), uint64(0x6C29804757B6D587),
  397. uint64(0x6C0D8EAC2D275E5C), uint64(0xF7A0557C6508451),
  398. uint64(0xEA12247067D3E47B), uint64(0x69D71CD313ABE389),
  399. }
  400. var kSpec = []uint64{
  401. uint64(0x67f815dfa2ded572), uint64(0x571523b70a15847b),
  402. uint64(0xf6875a4d90d6ab81), uint64(0x402bd1c3c54f9f4e),
  403. uint64(0x9cfa455ce03a98ea), uint64(0x9a99b26699d2c503),
  404. uint64(0x8a53bbf2b4960266), uint64(0x31a2db881a1456b5),
  405. uint64(0xdb0e199a5c5aa303), uint64(0x1044c1870ab23f40),
  406. uint64(0x1d959e848019051c), uint64(0xdccde75eadeb336f),
  407. uint64(0x416bbf029213ba10), uint64(0xd027bbf7156578dc),
  408. uint64(0x5078aa3739812c0a), uint64(0xd3910041d2bf1a3f),
  409. uint64(0x907eccf60d5a2d42), uint64(0xce97c0929c9f62dd),
  410. uint64(0xac442bc70ba75c18), uint64(0x23fcc663d665dfd1),
  411. uint64(0x1ab8e09e036c6e97), uint64(0xa8ec6c447e450521),
  412. uint64(0xfa618e5dbb03f1ee), uint64(0x97818394b29796fd),
  413. uint64(0x2f3003db37858e4a), uint64(0x956a9ffb2d8d672a),
  414. uint64(0x6c69b8f88173fe8a), uint64(0x14427fc04672c78a),
  415. uint64(0xc45ec7bd8f15f4c5), uint64(0x80bb118fa76f4475),
  416. uint64(0xbc88e4aeb775de52), uint64(0xf4a3a6981e00b882),
  417. uint64(0x1563a3a9338ff48e), uint64(0x89f9b7d524565faa),
  418. uint64(0xfde05a7c20edf1b6), uint64(0x362c42065ae9ca36),
  419. uint64(0x3d98fe4e433529ce), uint64(0xa74b9a7374f93a53),
  420. uint64(0x86814e6f591ff5d0), uint64(0x9f5ad8af81ad9d0e),
  421. uint64(0x6a6234ee670605a7), uint64(0x2717b96ebe280b8b),
  422. uint64(0x3f1080c626077447), uint64(0x7b487ec66f7ea0e0),
  423. uint64(0xc0a4f84aa50a550d), uint64(0x9ef18e979fe7e391),
  424. uint64(0xd48d605081727686), uint64(0x62b0e5f3415a9e7e),
  425. uint64(0x7a205440ec1f9ffc), uint64(0x84c9f4ce001ae4e3),
  426. uint64(0xd895fa9df594d74f), uint64(0xa554c324117e2e55),
  427. uint64(0x286efebd2872df5b), uint64(0xb2c4a50fe27ff578),
  428. uint64(0x2ed349eeef7c8905), uint64(0x7f5928eb85937e44),
  429. uint64(0x4a3124b337695f70), uint64(0x65e4d61df128865e),
  430. uint64(0xe720b95104771bc7), uint64(0x8a87d423e843fe74),
  431. uint64(0xf2947692a3e8297d), uint64(0xc1d9309b097acbdd),
  432. uint64(0xe01bdc5bfb301b1d), uint64(0xbf829cf24f4924da),
  433. uint64(0xffbf70b431bae7a4), uint64(0x48bcf8de0544320d),
  434. uint64(0x39d3bb5332fcae3b), uint64(0xa08b29e0c1c39f45),
  435. uint64(0x0f09aef7fd05c9e5), uint64(0x34f1904212347094),
  436. uint64(0x95ed44e301b771a2), uint64(0x4a982f4f368e3be9),
  437. uint64(0x15f66ca0631d4088), uint64(0xffaf52874b44c147),
  438. uint64(0x30c60ae2f14abb7e), uint64(0xe68c6eccc5b67046),
  439. uint64(0x00ca4fbd56a4d5a4), uint64(0xae183ec84b849dda),
  440. uint64(0xadd1643045ce5773), uint64(0x67255c1468cea6e8),
  441. uint64(0x16e10ecbf28cdaa3), uint64(0x9a99949a5806e933),
  442. uint64(0x7b846fc220b2601f), uint64(0x1885d1a07facced1),
  443. uint64(0xd319dd8da15b5932), uint64(0x46b4a5aac01c9a50),
  444. uint64(0xba6b04e467633d9f), uint64(0x7eee560bab19caf6),
  445. uint64(0x742128a9ea79b11f), uint64(0xee51363b35f7bde9),
  446. uint64(0x76d350755aac571d), uint64(0x01707da3fec2463a),
  447. uint64(0x42d8a498afc135f7), uint64(0x79676b9e20eced78),
  448. uint64(0xa8db3aea15638341), uint64(0x832c83324d3bc3fa),
  449. uint64(0xf347271c1f3b40a7), uint64(0x9a762db734f04059),
  450. uint64(0xfd4f21d26c4e3ee7), uint64(0xef5957dc398dfdb8),
  451. uint64(0xdaeb492b490c9b8d), uint64(0x0d70f36849d7a25b),
  452. uint64(0x84558d7ad0ae3b7d), uint64(0x658ef8e4f0e9a5f5),
  453. uint64(0x533b1036f4a2b8a0), uint64(0x5aec3e759e07a80c),
  454. uint64(0x4f88e85692946891), uint64(0x4cbcbaf8555cb05b),
  455. uint64(0x7b9487f3993bbbe3), uint64(0x5d1c6b72d6f4da75),
  456. uint64(0x6db334dc28acae64), uint64(0x71db28b850a5346c),
  457. uint64(0x2a518d10f2e261f8), uint64(0xfc75dd593364dbe3),
  458. uint64(0xa23fce43f1bcac1c), uint64(0xb043e8023cd1bb67),
  459. uint64(0x75a12988ca5b0a33), uint64(0x5c5316b44d19347f),
  460. uint64(0x1e4d790ec3943b92), uint64(0x3fafeeb6d7757479),
  461. uint64(0x21391abef7d4a8ea), uint64(0x5127234c097ef45c),
  462. uint64(0xd23c32ba5324a326), uint64(0xadd5a66d4a17a344),
  463. uint64(0x08c9f2afa63e1db5), uint64(0x563c6b91983d5983),
  464. uint64(0x4d608672a17cf84c), uint64(0xf6c76e08cc3ee246),
  465. uint64(0x5e76bcb1b333982f), uint64(0x2ae6c4efa566d62b),
  466. uint64(0x36d4c1bee8b6f406), uint64(0x6321efbc1582ee74),
  467. uint64(0x69c953f40d4ec1fd), uint64(0x26585806c45a7da7),
  468. uint64(0x16fae0061614c17e), uint64(0x3f9d63283daf907e),
  469. uint64(0x0cd29b00e3f2c9d2), uint64(0x300cd4b730ceaa5f),
  470. uint64(0x9832e0f216512a74), uint64(0x9af8cee3d830eb0d),
  471. uint64(0x9279f1b57b9ec54b), uint64(0xd36886046ee651ff),
  472. uint64(0x316796e6574d239b), uint64(0x05750a17f3a6e6cc),
  473. uint64(0xce6c3213d98176b1), uint64(0x62a205f88452173c),
  474. uint64(0x47154778b3cb2bf4), uint64(0x486a9323825446ff),
  475. uint64(0x65655e4e0758df38), uint64(0x8e5086fc897cfcf2),
  476. uint64(0x86ca0bd0442e7031), uint64(0x4e477830a20940f0),
  477. uint64(0x8338f7d139eea065), uint64(0xbd3a2ce437e95ef7),
  478. uint64(0x6ff8130126b29721), uint64(0xe7de9fefd1ed44a3),
  479. uint64(0xd992257615dfa08b), uint64(0xbe42dc12f6f7853c),
  480. uint64(0x7eb027ab7ceca7d8), uint64(0xdea83eaada7d8d53),
  481. uint64(0xd86902bd93ce25aa), uint64(0xf908731afd43f65a),
  482. uint64(0xa5194a17daef5fc0), uint64(0x6a21fd4c33664d97),
  483. uint64(0x701541db3198b435), uint64(0x9b54cdedbb0f1eea),
  484. uint64(0x72409751a163d09a), uint64(0xe26f4791bf9d75f6),
  485. }
  486. var kWrapValue = []uint64{
  487. uint64(0x5555555555555555),
  488. uint64(0x3333333333333333),
  489. uint64(0x0F0F0F0F0F0F0F0F),
  490. uint64(0x00FF00FF00FF00FF),
  491. uint64(0x0000FFFF0000FFFF),
  492. uint64(0x00000000FFFFFFFF),
  493. }
  494. var kWrapOffset = []uint64{
  495. 1, 2, 4, 8, 16, 32,
  496. }