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.

541 lines
14 KiB

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