auth.c 25 KB

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