25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

poly1305.go 21 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  1. // Copyright 2012 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. package main
  5. // Based on original, public domain implementation from NaCl by D. J.
  6. // Bernstein.
  7. import (
  8. "crypto/subtle"
  9. "math"
  10. )
  11. const (
  12. alpham80 = 0.00000000558793544769287109375
  13. alpham48 = 24.0
  14. alpham16 = 103079215104.0
  15. alpha0 = 6755399441055744.0
  16. alpha18 = 1770887431076116955136.0
  17. alpha32 = 29014219670751100192948224.0
  18. alpha50 = 7605903601369376408980219232256.0
  19. alpha64 = 124615124604835863084731911901282304.0
  20. alpha82 = 32667107224410092492483962313449748299776.0
  21. alpha96 = 535217884764734955396857238543560676143529984.0
  22. alpha112 = 35076039295941670036888435985190792471742381031424.0
  23. alpha130 = 9194973245195333150150082162901855101712434733101613056.0
  24. scale = 0.0000000000000000000000000000000000000036734198463196484624023016788195177431833298649127735047148490821200539357960224151611328125
  25. offset0 = 6755408030990331.0
  26. offset1 = 29014256564239239022116864.0
  27. offset2 = 124615283061160854719918951570079744.0
  28. offset3 = 535219245894202480694386063513315216128475136.0
  29. )
  30. // poly1305Verify returns true if mac is a valid authenticator for m with the
  31. // given key.
  32. func poly1305Verify(mac *[16]byte, m []byte, key *[32]byte) bool {
  33. var tmp [16]byte
  34. poly1305Sum(&tmp, m, key)
  35. return subtle.ConstantTimeCompare(tmp[:], mac[:]) == 1
  36. }
  37. // poly1305Sum generates an authenticator for m using a one-time key and puts
  38. // the 16-byte result into out. Authenticating two different messages with the
  39. // same key allows an attacker to forge messages at will.
  40. func poly1305Sum(out *[16]byte, m []byte, key *[32]byte) {
  41. r := key
  42. s := key[16:]
  43. var (
  44. y7 float64
  45. y6 float64
  46. y1 float64
  47. y0 float64
  48. y5 float64
  49. y4 float64
  50. x7 float64
  51. x6 float64
  52. x1 float64
  53. x0 float64
  54. y3 float64
  55. y2 float64
  56. x5 float64
  57. r3lowx0 float64
  58. x4 float64
  59. r0lowx6 float64
  60. x3 float64
  61. r3highx0 float64
  62. x2 float64
  63. r0highx6 float64
  64. r0lowx0 float64
  65. sr1lowx6 float64
  66. r0highx0 float64
  67. sr1highx6 float64
  68. sr3low float64
  69. r1lowx0 float64
  70. sr2lowx6 float64
  71. r1highx0 float64
  72. sr2highx6 float64
  73. r2lowx0 float64
  74. sr3lowx6 float64
  75. r2highx0 float64
  76. sr3highx6 float64
  77. r1highx4 float64
  78. r1lowx4 float64
  79. r0highx4 float64
  80. r0lowx4 float64
  81. sr3highx4 float64
  82. sr3lowx4 float64
  83. sr2highx4 float64
  84. sr2lowx4 float64
  85. r0lowx2 float64
  86. r0highx2 float64
  87. r1lowx2 float64
  88. r1highx2 float64
  89. r2lowx2 float64
  90. r2highx2 float64
  91. sr3lowx2 float64
  92. sr3highx2 float64
  93. z0 float64
  94. z1 float64
  95. z2 float64
  96. z3 float64
  97. m0 int64
  98. m1 int64
  99. m2 int64
  100. m3 int64
  101. m00 uint32
  102. m01 uint32
  103. m02 uint32
  104. m03 uint32
  105. m10 uint32
  106. m11 uint32
  107. m12 uint32
  108. m13 uint32
  109. m20 uint32
  110. m21 uint32
  111. m22 uint32
  112. m23 uint32
  113. m30 uint32
  114. m31 uint32
  115. m32 uint32
  116. m33 uint64
  117. lbelow2 int32
  118. lbelow3 int32
  119. lbelow4 int32
  120. lbelow5 int32
  121. lbelow6 int32
  122. lbelow7 int32
  123. lbelow8 int32
  124. lbelow9 int32
  125. lbelow10 int32
  126. lbelow11 int32
  127. lbelow12 int32
  128. lbelow13 int32
  129. lbelow14 int32
  130. lbelow15 int32
  131. s00 uint32
  132. s01 uint32
  133. s02 uint32
  134. s03 uint32
  135. s10 uint32
  136. s11 uint32
  137. s12 uint32
  138. s13 uint32
  139. s20 uint32
  140. s21 uint32
  141. s22 uint32
  142. s23 uint32
  143. s30 uint32
  144. s31 uint32
  145. s32 uint32
  146. s33 uint32
  147. bits32 uint64
  148. f uint64
  149. f0 uint64
  150. f1 uint64
  151. f2 uint64
  152. f3 uint64
  153. f4 uint64
  154. g uint64
  155. g0 uint64
  156. g1 uint64
  157. g2 uint64
  158. g3 uint64
  159. g4 uint64
  160. )
  161. var p int32
  162. l := int32(len(m))
  163. r00 := uint32(r[0])
  164. r01 := uint32(r[1])
  165. r02 := uint32(r[2])
  166. r0 := int64(2151)
  167. r03 := uint32(r[3])
  168. r03 &= 15
  169. r0 <<= 51
  170. r10 := uint32(r[4])
  171. r10 &= 252
  172. r01 <<= 8
  173. r0 += int64(r00)
  174. r11 := uint32(r[5])
  175. r02 <<= 16
  176. r0 += int64(r01)
  177. r12 := uint32(r[6])
  178. r03 <<= 24
  179. r0 += int64(r02)
  180. r13 := uint32(r[7])
  181. r13 &= 15
  182. r1 := int64(2215)
  183. r0 += int64(r03)
  184. d0 := r0
  185. r1 <<= 51
  186. r2 := int64(2279)
  187. r20 := uint32(r[8])
  188. r20 &= 252
  189. r11 <<= 8
  190. r1 += int64(r10)
  191. r21 := uint32(r[9])
  192. r12 <<= 16
  193. r1 += int64(r11)
  194. r22 := uint32(r[10])
  195. r13 <<= 24
  196. r1 += int64(r12)
  197. r23 := uint32(r[11])
  198. r23 &= 15
  199. r2 <<= 51
  200. r1 += int64(r13)
  201. d1 := r1
  202. r21 <<= 8
  203. r2 += int64(r20)
  204. r30 := uint32(r[12])
  205. r30 &= 252
  206. r22 <<= 16
  207. r2 += int64(r21)
  208. r31 := uint32(r[13])
  209. r23 <<= 24
  210. r2 += int64(r22)
  211. r32 := uint32(r[14])
  212. r2 += int64(r23)
  213. r3 := int64(2343)
  214. d2 := r2
  215. r3 <<= 51
  216. r33 := uint32(r[15])
  217. r33 &= 15
  218. r31 <<= 8
  219. r3 += int64(r30)
  220. r32 <<= 16
  221. r3 += int64(r31)
  222. r33 <<= 24
  223. r3 += int64(r32)
  224. r3 += int64(r33)
  225. h0 := alpha32 - alpha32
  226. d3 := r3
  227. h1 := alpha32 - alpha32
  228. h2 := alpha32 - alpha32
  229. h3 := alpha32 - alpha32
  230. h4 := alpha32 - alpha32
  231. r0low := math.Float64frombits(uint64(d0))
  232. h5 := alpha32 - alpha32
  233. r1low := math.Float64frombits(uint64(d1))
  234. h6 := alpha32 - alpha32
  235. r2low := math.Float64frombits(uint64(d2))
  236. h7 := alpha32 - alpha32
  237. r0low -= alpha0
  238. r1low -= alpha32
  239. r2low -= alpha64
  240. r0high := r0low + alpha18
  241. r3low := math.Float64frombits(uint64(d3))
  242. r1high := r1low + alpha50
  243. sr1low := scale * r1low
  244. r2high := r2low + alpha82
  245. sr2low := scale * r2low
  246. r0high -= alpha18
  247. r0high_stack := r0high
  248. r3low -= alpha96
  249. r1high -= alpha50
  250. r1high_stack := r1high
  251. sr1high := sr1low + alpham80
  252. r0low -= r0high
  253. r2high -= alpha82
  254. sr3low = scale * r3low
  255. sr2high := sr2low + alpham48
  256. r1low -= r1high
  257. r1low_stack := r1low
  258. sr1high -= alpham80
  259. sr1high_stack := sr1high
  260. r2low -= r2high
  261. r2low_stack := r2low
  262. sr2high -= alpham48
  263. sr2high_stack := sr2high
  264. r3high := r3low + alpha112
  265. r0low_stack := r0low
  266. sr1low -= sr1high
  267. sr1low_stack := sr1low
  268. sr3high := sr3low + alpham16
  269. r2high_stack := r2high
  270. sr2low -= sr2high
  271. sr2low_stack := sr2low
  272. r3high -= alpha112
  273. r3high_stack := r3high
  274. sr3high -= alpham16
  275. sr3high_stack := sr3high
  276. r3low -= r3high
  277. r3low_stack := r3low
  278. sr3low -= sr3high
  279. sr3low_stack := sr3low
  280. if l < 16 {
  281. goto addatmost15bytes
  282. }
  283. m00 = uint32(m[p+0])
  284. m0 = 2151
  285. m0 <<= 51
  286. m1 = 2215
  287. m01 = uint32(m[p+1])
  288. m1 <<= 51
  289. m2 = 2279
  290. m02 = uint32(m[p+2])
  291. m2 <<= 51
  292. m3 = 2343
  293. m03 = uint32(m[p+3])
  294. m10 = uint32(m[p+4])
  295. m01 <<= 8
  296. m0 += int64(m00)
  297. m11 = uint32(m[p+5])
  298. m02 <<= 16
  299. m0 += int64(m01)
  300. m12 = uint32(m[p+6])
  301. m03 <<= 24
  302. m0 += int64(m02)
  303. m13 = uint32(m[p+7])
  304. m3 <<= 51
  305. m0 += int64(m03)
  306. m20 = uint32(m[p+8])
  307. m11 <<= 8
  308. m1 += int64(m10)
  309. m21 = uint32(m[p+9])
  310. m12 <<= 16
  311. m1 += int64(m11)
  312. m22 = uint32(m[p+10])
  313. m13 <<= 24
  314. m1 += int64(m12)
  315. m23 = uint32(m[p+11])
  316. m1 += int64(m13)
  317. m30 = uint32(m[p+12])
  318. m21 <<= 8
  319. m2 += int64(m20)
  320. m31 = uint32(m[p+13])
  321. m22 <<= 16
  322. m2 += int64(m21)
  323. m32 = uint32(m[p+14])
  324. m23 <<= 24
  325. m2 += int64(m22)
  326. m33 = uint64(m[p+15])
  327. m2 += int64(m23)
  328. d0 = m0
  329. m31 <<= 8
  330. m3 += int64(m30)
  331. d1 = m1
  332. m32 <<= 16
  333. m3 += int64(m31)
  334. d2 = m2
  335. m33 += 256
  336. m33 <<= 24
  337. m3 += int64(m32)
  338. m3 += int64(m33)
  339. d3 = m3
  340. p += 16
  341. l -= 16
  342. z0 = math.Float64frombits(uint64(d0))
  343. z1 = math.Float64frombits(uint64(d1))
  344. z2 = math.Float64frombits(uint64(d2))
  345. z3 = math.Float64frombits(uint64(d3))
  346. z0 -= alpha0
  347. z1 -= alpha32
  348. z2 -= alpha64
  349. z3 -= alpha96
  350. h0 += z0
  351. h1 += z1
  352. h3 += z2
  353. h5 += z3
  354. if l < 16 {
  355. goto multiplyaddatmost15bytes
  356. }
  357. multiplyaddatleast16bytes:
  358. m2 = 2279
  359. m20 = uint32(m[p+8])
  360. y7 = h7 + alpha130
  361. m2 <<= 51
  362. m3 = 2343
  363. m21 = uint32(m[p+9])
  364. y6 = h6 + alpha130
  365. m3 <<= 51
  366. m0 = 2151
  367. m22 = uint32(m[p+10])
  368. y1 = h1 + alpha32
  369. m0 <<= 51
  370. m1 = 2215
  371. m23 = uint32(m[p+11])
  372. y0 = h0 + alpha32
  373. m1 <<= 51
  374. m30 = uint32(m[p+12])
  375. y7 -= alpha130
  376. m21 <<= 8
  377. m2 += int64(m20)
  378. m31 = uint32(m[p+13])
  379. y6 -= alpha130
  380. m22 <<= 16
  381. m2 += int64(m21)
  382. m32 = uint32(m[p+14])
  383. y1 -= alpha32
  384. m23 <<= 24
  385. m2 += int64(m22)
  386. m33 = uint64(m[p+15])
  387. y0 -= alpha32
  388. m2 += int64(m23)
  389. m00 = uint32(m[p+0])
  390. y5 = h5 + alpha96
  391. m31 <<= 8
  392. m3 += int64(m30)
  393. m01 = uint32(m[p+1])
  394. y4 = h4 + alpha96
  395. m32 <<= 16
  396. m02 = uint32(m[p+2])
  397. x7 = h7 - y7
  398. y7 *= scale
  399. m33 += 256
  400. m03 = uint32(m[p+3])
  401. x6 = h6 - y6
  402. y6 *= scale
  403. m33 <<= 24
  404. m3 += int64(m31)
  405. m10 = uint32(m[p+4])
  406. x1 = h1 - y1
  407. m01 <<= 8
  408. m3 += int64(m32)
  409. m11 = uint32(m[p+5])
  410. x0 = h0 - y0
  411. m3 += int64(m33)
  412. m0 += int64(m00)
  413. m12 = uint32(m[p+6])
  414. y5 -= alpha96
  415. m02 <<= 16
  416. m0 += int64(m01)
  417. m13 = uint32(m[p+7])
  418. y4 -= alpha96
  419. m03 <<= 24
  420. m0 += int64(m02)
  421. d2 = m2
  422. x1 += y7
  423. m0 += int64(m03)
  424. d3 = m3
  425. x0 += y6
  426. m11 <<= 8
  427. m1 += int64(m10)
  428. d0 = m0
  429. x7 += y5
  430. m12 <<= 16
  431. m1 += int64(m11)
  432. x6 += y4
  433. m13 <<= 24
  434. m1 += int64(m12)
  435. y3 = h3 + alpha64
  436. m1 += int64(m13)
  437. d1 = m1
  438. y2 = h2 + alpha64
  439. x0 += x1
  440. x6 += x7
  441. y3 -= alpha64
  442. r3low = r3low_stack
  443. y2 -= alpha64
  444. r0low = r0low_stack
  445. x5 = h5 - y5
  446. r3lowx0 = r3low * x0
  447. r3high = r3high_stack
  448. x4 = h4 - y4
  449. r0lowx6 = r0low * x6
  450. r0high = r0high_stack
  451. x3 = h3 - y3
  452. r3highx0 = r3high * x0
  453. sr1low = sr1low_stack
  454. x2 = h2 - y2
  455. r0highx6 = r0high * x6
  456. sr1high = sr1high_stack
  457. x5 += y3
  458. r0lowx0 = r0low * x0
  459. r1low = r1low_stack
  460. h6 = r3lowx0 + r0lowx6
  461. sr1lowx6 = sr1low * x6
  462. r1high = r1high_stack
  463. x4 += y2
  464. r0highx0 = r0high * x0
  465. sr2low = sr2low_stack
  466. h7 = r3highx0 + r0highx6
  467. sr1highx6 = sr1high * x6
  468. sr2high = sr2high_stack
  469. x3 += y1
  470. r1lowx0 = r1low * x0
  471. r2low = r2low_stack
  472. h0 = r0lowx0 + sr1lowx6
  473. sr2lowx6 = sr2low * x6
  474. r2high = r2high_stack
  475. x2 += y0
  476. r1highx0 = r1high * x0
  477. sr3low = sr3low_stack
  478. h1 = r0highx0 + sr1highx6
  479. sr2highx6 = sr2high * x6
  480. sr3high = sr3high_stack
  481. x4 += x5
  482. r2lowx0 = r2low * x0
  483. z2 = math.Float64frombits(uint64(d2))
  484. h2 = r1lowx0 + sr2lowx6
  485. sr3lowx6 = sr3low * x6
  486. x2 += x3
  487. r2highx0 = r2high * x0
  488. z3 = math.Float64frombits(uint64(d3))
  489. h3 = r1highx0 + sr2highx6
  490. sr3highx6 = sr3high * x6
  491. r1highx4 = r1high * x4
  492. z2 -= alpha64
  493. h4 = r2lowx0 + sr3lowx6
  494. r1lowx4 = r1low * x4
  495. r0highx4 = r0high * x4
  496. z3 -= alpha96
  497. h5 = r2highx0 + sr3highx6
  498. r0lowx4 = r0low * x4
  499. h7 += r1highx4
  500. sr3highx4 = sr3high * x4
  501. h6 += r1lowx4
  502. sr3lowx4 = sr3low * x4
  503. h5 += r0highx4
  504. sr2highx4 = sr2high * x4
  505. h4 += r0lowx4
  506. sr2lowx4 = sr2low * x4
  507. h3 += sr3highx4
  508. r0lowx2 = r0low * x2
  509. h2 += sr3lowx4
  510. r0highx2 = r0high * x2
  511. h1 += sr2highx4
  512. r1lowx2 = r1low * x2
  513. h0 += sr2lowx4
  514. r1highx2 = r1high * x2
  515. h2 += r0lowx2
  516. r2lowx2 = r2low * x2
  517. h3 += r0highx2
  518. r2highx2 = r2high * x2
  519. h4 += r1lowx2
  520. sr3lowx2 = sr3low * x2
  521. h5 += r1highx2
  522. sr3highx2 = sr3high * x2
  523. p += 16
  524. l -= 16
  525. h6 += r2lowx2
  526. h7 += r2highx2
  527. z1 = math.Float64frombits(uint64(d1))
  528. h0 += sr3lowx2
  529. z0 = math.Float64frombits(uint64(d0))
  530. h1 += sr3highx2
  531. z1 -= alpha32
  532. z0 -= alpha0
  533. h5 += z3
  534. h3 += z2
  535. h1 += z1
  536. h0 += z0
  537. if l >= 16 {
  538. goto multiplyaddatleast16bytes
  539. }
  540. multiplyaddatmost15bytes:
  541. y7 = h7 + alpha130
  542. y6 = h6 + alpha130
  543. y1 = h1 + alpha32
  544. y0 = h0 + alpha32
  545. y7 -= alpha130
  546. y6 -= alpha130
  547. y1 -= alpha32
  548. y0 -= alpha32
  549. y5 = h5 + alpha96
  550. y4 = h4 + alpha96
  551. x7 = h7 - y7
  552. y7 *= scale
  553. x6 = h6 - y6
  554. y6 *= scale
  555. x1 = h1 - y1
  556. x0 = h0 - y0
  557. y5 -= alpha96
  558. y4 -= alpha96
  559. x1 += y7
  560. x0 += y6
  561. x7 += y5
  562. x6 += y4
  563. y3 = h3 + alpha64
  564. y2 = h2 + alpha64
  565. x0 += x1
  566. x6 += x7
  567. y3 -= alpha64
  568. r3low = r3low_stack
  569. y2 -= alpha64
  570. r0low = r0low_stack
  571. x5 = h5 - y5
  572. r3lowx0 = r3low * x0
  573. r3high = r3high_stack
  574. x4 = h4 - y4
  575. r0lowx6 = r0low * x6
  576. r0high = r0high_stack
  577. x3 = h3 - y3
  578. r3highx0 = r3high * x0
  579. sr1low = sr1low_stack
  580. x2 = h2 - y2
  581. r0highx6 = r0high * x6
  582. sr1high = sr1high_stack
  583. x5 += y3
  584. r0lowx0 = r0low * x0
  585. r1low = r1low_stack
  586. h6 = r3lowx0 + r0lowx6
  587. sr1lowx6 = sr1low * x6
  588. r1high = r1high_stack
  589. x4 += y2
  590. r0highx0 = r0high * x0
  591. sr2low = sr2low_stack
  592. h7 = r3highx0 + r0highx6
  593. sr1highx6 = sr1high * x6
  594. sr2high = sr2high_stack
  595. x3 += y1
  596. r1lowx0 = r1low * x0
  597. r2low = r2low_stack
  598. h0 = r0lowx0 + sr1lowx6
  599. sr2lowx6 = sr2low * x6
  600. r2high = r2high_stack
  601. x2 += y0
  602. r1highx0 = r1high * x0
  603. sr3low = sr3low_stack
  604. h1 = r0highx0 + sr1highx6
  605. sr2highx6 = sr2high * x6
  606. sr3high = sr3high_stack
  607. x4 += x5
  608. r2lowx0 = r2low * x0
  609. h2 = r1lowx0 + sr2lowx6
  610. sr3lowx6 = sr3low * x6
  611. x2 += x3
  612. r2highx0 = r2high * x0
  613. h3 = r1highx0 + sr2highx6
  614. sr3highx6 = sr3high * x6
  615. r1highx4 = r1high * x4
  616. h4 = r2lowx0 + sr3lowx6
  617. r1lowx4 = r1low * x4
  618. r0highx4 = r0high * x4
  619. h5 = r2highx0 + sr3highx6
  620. r0lowx4 = r0low * x4
  621. h7 += r1highx4
  622. sr3highx4 = sr3high * x4
  623. h6 += r1lowx4
  624. sr3lowx4 = sr3low * x4
  625. h5 += r0highx4
  626. sr2highx4 = sr2high * x4
  627. h4 += r0lowx4
  628. sr2lowx4 = sr2low * x4
  629. h3 += sr3highx4
  630. r0lowx2 = r0low * x2
  631. h2 += sr3lowx4
  632. r0highx2 = r0high * x2
  633. h1 += sr2highx4
  634. r1lowx2 = r1low * x2
  635. h0 += sr2lowx4
  636. r1highx2 = r1high * x2
  637. h2 += r0lowx2
  638. r2lowx2 = r2low * x2
  639. h3 += r0highx2
  640. r2highx2 = r2high * x2
  641. h4 += r1lowx2
  642. sr3lowx2 = sr3low * x2
  643. h5 += r1highx2
  644. sr3highx2 = sr3high * x2
  645. h6 += r2lowx2
  646. h7 += r2highx2
  647. h0 += sr3lowx2
  648. h1 += sr3highx2
  649. addatmost15bytes:
  650. if l == 0 {
  651. goto nomorebytes
  652. }
  653. lbelow2 = l - 2
  654. lbelow3 = l - 3
  655. lbelow2 >>= 31
  656. lbelow4 = l - 4
  657. m00 = uint32(m[p+0])
  658. lbelow3 >>= 31
  659. p += lbelow2
  660. m01 = uint32(m[p+1])
  661. lbelow4 >>= 31
  662. p += lbelow3
  663. m02 = uint32(m[p+2])
  664. p += lbelow4
  665. m0 = 2151
  666. m03 = uint32(m[p+3])
  667. m0 <<= 51
  668. m1 = 2215
  669. m0 += int64(m00)
  670. m01 &^= uint32(lbelow2)
  671. m02 &^= uint32(lbelow3)
  672. m01 -= uint32(lbelow2)
  673. m01 <<= 8
  674. m03 &^= uint32(lbelow4)
  675. m0 += int64(m01)
  676. lbelow2 -= lbelow3
  677. m02 += uint32(lbelow2)
  678. lbelow3 -= lbelow4
  679. m02 <<= 16
  680. m03 += uint32(lbelow3)
  681. m03 <<= 24
  682. m0 += int64(m02)
  683. m0 += int64(m03)
  684. lbelow5 = l - 5
  685. lbelow6 = l - 6
  686. lbelow7 = l - 7
  687. lbelow5 >>= 31
  688. lbelow8 = l - 8
  689. lbelow6 >>= 31
  690. p += lbelow5
  691. m10 = uint32(m[p+4])
  692. lbelow7 >>= 31
  693. p += lbelow6
  694. m11 = uint32(m[p+5])
  695. lbelow8 >>= 31
  696. p += lbelow7
  697. m12 = uint32(m[p+6])
  698. m1 <<= 51
  699. p += lbelow8
  700. m13 = uint32(m[p+7])
  701. m10 &^= uint32(lbelow5)
  702. lbelow4 -= lbelow5
  703. m10 += uint32(lbelow4)
  704. lbelow5 -= lbelow6
  705. m11 &^= uint32(lbelow6)
  706. m11 += uint32(lbelow5)
  707. m11 <<= 8
  708. m1 += int64(m10)
  709. m1 += int64(m11)
  710. m12 &^= uint32(lbelow7)
  711. lbelow6 -= lbelow7
  712. m13 &^= uint32(lbelow8)
  713. m12 += uint32(lbelow6)
  714. lbelow7 -= lbelow8
  715. m12 <<= 16
  716. m13 += uint32(lbelow7)
  717. m13 <<= 24
  718. m1 += int64(m12)
  719. m1 += int64(m13)
  720. m2 = 2279
  721. lbelow9 = l - 9
  722. m3 = 2343
  723. lbelow10 = l - 10
  724. lbelow11 = l - 11
  725. lbelow9 >>= 31
  726. lbelow12 = l - 12
  727. lbelow10 >>= 31
  728. p += lbelow9
  729. m20 = uint32(m[p+8])
  730. lbelow11 >>= 31
  731. p += lbelow10
  732. m21 = uint32(m[p+9])
  733. lbelow12 >>= 31
  734. p += lbelow11
  735. m22 = uint32(m[p+10])
  736. m2 <<= 51
  737. p += lbelow12
  738. m23 = uint32(m[p+11])
  739. m20 &^= uint32(lbelow9)
  740. lbelow8 -= lbelow9
  741. m20 += uint32(lbelow8)
  742. lbelow9 -= lbelow10
  743. m21 &^= uint32(lbelow10)
  744. m21 += uint32(lbelow9)
  745. m21 <<= 8
  746. m2 += int64(m20)
  747. m2 += int64(m21)
  748. m22 &^= uint32(lbelow11)
  749. lbelow10 -= lbelow11
  750. m23 &^= uint32(lbelow12)
  751. m22 += uint32(lbelow10)
  752. lbelow11 -= lbelow12
  753. m22 <<= 16
  754. m23 += uint32(lbelow11)
  755. m23 <<= 24
  756. m2 += int64(m22)
  757. m3 <<= 51
  758. lbelow13 = l - 13
  759. lbelow13 >>= 31
  760. lbelow14 = l - 14
  761. lbelow14 >>= 31
  762. p += lbelow13
  763. lbelow15 = l - 15
  764. m30 = uint32(m[p+12])
  765. lbelow15 >>= 31
  766. p += lbelow14
  767. m31 = uint32(m[p+13])
  768. p += lbelow15
  769. m2 += int64(m23)
  770. m32 = uint32(m[p+14])
  771. m30 &^= uint32(lbelow13)
  772. lbelow12 -= lbelow13
  773. m30 += uint32(lbelow12)
  774. lbelow13 -= lbelow14
  775. m3 += int64(m30)
  776. m31 &^= uint32(lbelow14)
  777. m31 += uint32(lbelow13)
  778. m32 &^= uint32(lbelow15)
  779. m31 <<= 8
  780. lbelow14 -= lbelow15
  781. m3 += int64(m31)
  782. m32 += uint32(lbelow14)
  783. d0 = m0
  784. m32 <<= 16
  785. m33 = uint64(lbelow15 + 1)
  786. d1 = m1
  787. m33 <<= 24
  788. m3 += int64(m32)
  789. d2 = m2
  790. m3 += int64(m33)
  791. d3 = m3
  792. z3 = math.Float64frombits(uint64(d3))
  793. z2 = math.Float64frombits(uint64(d2))
  794. z1 = math.Float64frombits(uint64(d1))
  795. z0 = math.Float64frombits(uint64(d0))
  796. z3 -= alpha96
  797. z2 -= alpha64
  798. z1 -= alpha32
  799. z0 -= alpha0
  800. h5 += z3
  801. h3 += z2
  802. h1 += z1
  803. h0 += z0
  804. y7 = h7 + alpha130
  805. y6 = h6 + alpha130
  806. y1 = h1 + alpha32
  807. y0 = h0 + alpha32
  808. y7 -= alpha130
  809. y6 -= alpha130
  810. y1 -= alpha32
  811. y0 -= alpha32
  812. y5 = h5 + alpha96
  813. y4 = h4 + alpha96
  814. x7 = h7 - y7
  815. y7 *= scale
  816. x6 = h6 - y6
  817. y6 *= scale
  818. x1 = h1 - y1
  819. x0 = h0 - y0
  820. y5 -= alpha96
  821. y4 -= alpha96
  822. x1 += y7
  823. x0 += y6
  824. x7 += y5
  825. x6 += y4
  826. y3 = h3 + alpha64
  827. y2 = h2 + alpha64
  828. x0 += x1
  829. x6 += x7
  830. y3 -= alpha64
  831. r3low = r3low_stack
  832. y2 -= alpha64
  833. r0low = r0low_stack
  834. x5 = h5 - y5
  835. r3lowx0 = r3low * x0
  836. r3high = r3high_stack
  837. x4 = h4 - y4
  838. r0lowx6 = r0low * x6
  839. r0high = r0high_stack
  840. x3 = h3 - y3
  841. r3highx0 = r3high * x0
  842. sr1low = sr1low_stack
  843. x2 = h2 - y2
  844. r0highx6 = r0high * x6
  845. sr1high = sr1high_stack
  846. x5 += y3
  847. r0lowx0 = r0low * x0
  848. r1low = r1low_stack
  849. h6 = r3lowx0 + r0lowx6
  850. sr1lowx6 = sr1low * x6
  851. r1high = r1high_stack
  852. x4 += y2
  853. r0highx0 = r0high * x0
  854. sr2low = sr2low_stack
  855. h7 = r3highx0 + r0highx6
  856. sr1highx6 = sr1high * x6
  857. sr2high = sr2high_stack
  858. x3 += y1
  859. r1lowx0 = r1low * x0
  860. r2low = r2low_stack
  861. h0 = r0lowx0 + sr1lowx6
  862. sr2lowx6 = sr2low * x6
  863. r2high = r2high_stack
  864. x2 += y0
  865. r1highx0 = r1high * x0
  866. sr3low = sr3low_stack
  867. h1 = r0highx0 + sr1highx6
  868. sr2highx6 = sr2high * x6
  869. sr3high = sr3high_stack
  870. x4 += x5
  871. r2lowx0 = r2low * x0
  872. h2 = r1lowx0 + sr2lowx6
  873. sr3lowx6 = sr3low * x6
  874. x2 += x3
  875. r2highx0 = r2high * x0
  876. h3 = r1highx0 + sr2highx6
  877. sr3highx6 = sr3high * x6
  878. r1highx4 = r1high * x4
  879. h4 = r2lowx0 + sr3lowx6
  880. r1lowx4 = r1low * x4
  881. r0highx4 = r0high * x4
  882. h5 = r2highx0 + sr3highx6
  883. r0lowx4 = r0low * x4
  884. h7 += r1highx4
  885. sr3highx4 = sr3high * x4
  886. h6 += r1lowx4
  887. sr3lowx4 = sr3low * x4
  888. h5 += r0highx4
  889. sr2highx4 = sr2high * x4
  890. h4 += r0lowx4
  891. sr2lowx4 = sr2low * x4
  892. h3 += sr3highx4
  893. r0lowx2 = r0low * x2
  894. h2 += sr3lowx4
  895. r0highx2 = r0high * x2
  896. h1 += sr2highx4
  897. r1lowx2 = r1low * x2
  898. h0 += sr2lowx4
  899. r1highx2 = r1high * x2
  900. h2 += r0lowx2
  901. r2lowx2 = r2low * x2
  902. h3 += r0highx2
  903. r2highx2 = r2high * x2
  904. h4 += r1lowx2
  905. sr3lowx2 = sr3low * x2
  906. h5 += r1highx2
  907. sr3highx2 = sr3high * x2
  908. h6 += r2lowx2
  909. h7 += r2highx2
  910. h0 += sr3lowx2
  911. h1 += sr3highx2
  912. nomorebytes:
  913. y7 = h7 + alpha130
  914. y0 = h0 + alpha32
  915. y1 = h1 + alpha32
  916. y2 = h2 + alpha64
  917. y7 -= alpha130
  918. y3 = h3 + alpha64
  919. y4 = h4 + alpha96
  920. y5 = h5 + alpha96
  921. x7 = h7 - y7
  922. y7 *= scale
  923. y0 -= alpha32
  924. y1 -= alpha32
  925. y2 -= alpha64
  926. h6 += x7
  927. y3 -= alpha64
  928. y4 -= alpha96
  929. y5 -= alpha96
  930. y6 = h6 + alpha130
  931. x0 = h0 - y0
  932. x1 = h1 - y1
  933. x2 = h2 - y2
  934. y6 -= alpha130
  935. x0 += y7
  936. x3 = h3 - y3
  937. x4 = h4 - y4
  938. x5 = h5 - y5
  939. x6 = h6 - y6
  940. y6 *= scale
  941. x2 += y0
  942. x3 += y1
  943. x4 += y2
  944. x0 += y6
  945. x5 += y3
  946. x6 += y4
  947. x2 += x3
  948. x0 += x1
  949. x4 += x5
  950. x6 += y5
  951. x2 += offset1
  952. d1 = int64(math.Float64bits(x2))
  953. x0 += offset0
  954. d0 = int64(math.Float64bits(x0))
  955. x4 += offset2
  956. d2 = int64(math.Float64bits(x4))
  957. x6 += offset3
  958. d3 = int64(math.Float64bits(x6))
  959. f0 = uint64(d0)
  960. f1 = uint64(d1)
  961. bits32 = math.MaxUint64
  962. f2 = uint64(d2)
  963. bits32 >>= 32
  964. f3 = uint64(d3)
  965. f = f0 >> 32
  966. f0 &= bits32
  967. f &= 255
  968. f1 += f
  969. g0 = f0 + 5
  970. g = g0 >> 32
  971. g0 &= bits32
  972. f = f1 >> 32
  973. f1 &= bits32
  974. f &= 255
  975. g1 = f1 + g
  976. g = g1 >> 32
  977. f2 += f
  978. f = f2 >> 32
  979. g1 &= bits32
  980. f2 &= bits32
  981. f &= 255
  982. f3 += f
  983. g2 = f2 + g
  984. g = g2 >> 32
  985. g2 &= bits32
  986. f4 = f3 >> 32
  987. f3 &= bits32
  988. f4 &= 255
  989. g3 = f3 + g
  990. g = g3 >> 32
  991. g3 &= bits32
  992. g4 = f4 + g
  993. g4 = g4 - 4
  994. s00 = uint32(s[0])
  995. f = uint64(int64(g4) >> 63)
  996. s01 = uint32(s[1])
  997. f0 &= f
  998. g0 &^= f
  999. s02 = uint32(s[2])
  1000. f1 &= f
  1001. f0 |= g0
  1002. s03 = uint32(s[3])
  1003. g1 &^= f
  1004. f2 &= f
  1005. s10 = uint32(s[4])
  1006. f3 &= f
  1007. g2 &^= f
  1008. s11 = uint32(s[5])
  1009. g3 &^= f
  1010. f1 |= g1
  1011. s12 = uint32(s[6])
  1012. f2 |= g2
  1013. f3 |= g3
  1014. s13 = uint32(s[7])
  1015. s01 <<= 8
  1016. f0 += uint64(s00)
  1017. s20 = uint32(s[8])
  1018. s02 <<= 16
  1019. f0 += uint64(s01)
  1020. s21 = uint32(s[9])
  1021. s03 <<= 24
  1022. f0 += uint64(s02)
  1023. s22 = uint32(s[10])
  1024. s11 <<= 8
  1025. f1 += uint64(s10)
  1026. s23 = uint32(s[11])
  1027. s12 <<= 16
  1028. f1 += uint64(s11)
  1029. s30 = uint32(s[12])
  1030. s13 <<= 24
  1031. f1 += uint64(s12)
  1032. s31 = uint32(s[13])
  1033. f0 += uint64(s03)
  1034. f1 += uint64(s13)
  1035. s32 = uint32(s[14])
  1036. s21 <<= 8
  1037. f2 += uint64(s20)
  1038. s33 = uint32(s[15])
  1039. s22 <<= 16
  1040. f2 += uint64(s21)
  1041. s23 <<= 24
  1042. f2 += uint64(s22)
  1043. s31 <<= 8
  1044. f3 += uint64(s30)
  1045. s32 <<= 16
  1046. f3 += uint64(s31)
  1047. s33 <<= 24
  1048. f3 += uint64(s32)
  1049. f2 += uint64(s23)
  1050. f3 += uint64(s33)
  1051. out[0] = byte(f0)
  1052. f0 >>= 8
  1053. out[1] = byte(f0)
  1054. f0 >>= 8
  1055. out[2] = byte(f0)
  1056. f0 >>= 8
  1057. out[3] = byte(f0)
  1058. f0 >>= 8
  1059. f1 += f0
  1060. out[4] = byte(f1)
  1061. f1 >>= 8
  1062. out[5] = byte(f1)
  1063. f1 >>= 8
  1064. out[6] = byte(f1)
  1065. f1 >>= 8
  1066. out[7] = byte(f1)
  1067. f1 >>= 8
  1068. f2 += f1
  1069. out[8] = byte(f2)
  1070. f2 >>= 8
  1071. out[9] = byte(f2)
  1072. f2 >>= 8
  1073. out[10] = byte(f2)
  1074. f2 >>= 8
  1075. out[11] = byte(f2)
  1076. f2 >>= 8
  1077. f3 += f2
  1078. out[12] = byte(f3)
  1079. f3 >>= 8
  1080. out[13] = byte(f3)
  1081. f3 >>= 8
  1082. out[14] = byte(f3)
  1083. f3 >>= 8
  1084. out[15] = byte(f3)
  1085. }