scalar_fiat.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. // Code generated by Fiat Cryptography. DO NOT EDIT.
  2. //
  3. // Autogenerated: word_by_word_montgomery --lang Go --cmovznz-by-mul --relax-primitive-carry-to-bitwidth 32,64 --public-function-case camelCase --public-type-case camelCase --private-function-case camelCase --private-type-case camelCase --doc-text-before-function-name '' --doc-newline-before-package-declaration --doc-prepend-header 'Code generated by Fiat Cryptography. DO NOT EDIT.' --package-name edwards25519 Scalar 64 '2^252 + 27742317777372353535851937790883648493' mul add sub opp nonzero from_montgomery to_montgomery to_bytes from_bytes
  4. //
  5. // curve description: Scalar
  6. //
  7. // machine_wordsize = 64 (from "64")
  8. //
  9. // requested operations: mul, add, sub, opp, nonzero, from_montgomery, to_montgomery, to_bytes, from_bytes
  10. //
  11. // m = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed (from "2^252 + 27742317777372353535851937790883648493")
  12. //
  13. //
  14. //
  15. // NOTE: In addition to the bounds specified above each function, all
  16. //
  17. // functions synthesized for this Montgomery arithmetic require the
  18. //
  19. // input to be strictly less than the prime modulus (m), and also
  20. //
  21. // require the input to be in the unique saturated representation.
  22. //
  23. // All functions also ensure that these two properties are true of
  24. //
  25. // return values.
  26. //
  27. //
  28. //
  29. // Computed values:
  30. //
  31. // eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192)
  32. //
  33. // bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) + (z[28] << 224) + (z[29] << 232) + (z[30] << 240) + (z[31] << 248)
  34. //
  35. // twos_complement_eval z = let x1 := z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) in
  36. //
  37. // if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256
  38. package edwards25519
  39. import "math/bits"
  40. type fiatScalarUint1 uint64 // We use uint64 instead of a more narrow type for performance reasons; see https://github.com/mit-plv/fiat-crypto/pull/1006#issuecomment-892625927
  41. type fiatScalarInt1 int64 // We use uint64 instead of a more narrow type for performance reasons; see https://github.com/mit-plv/fiat-crypto/pull/1006#issuecomment-892625927
  42. // The type fiatScalarMontgomeryDomainFieldElement is a field element in the Montgomery domain.
  43. //
  44. // Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
  45. type fiatScalarMontgomeryDomainFieldElement [4]uint64
  46. // The type fiatScalarNonMontgomeryDomainFieldElement is a field element NOT in the Montgomery domain.
  47. //
  48. // Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
  49. type fiatScalarNonMontgomeryDomainFieldElement [4]uint64
  50. // fiatScalarCmovznzU64 is a single-word conditional move.
  51. //
  52. // Postconditions:
  53. //
  54. // out1 = (if arg1 = 0 then arg2 else arg3)
  55. //
  56. // Input Bounds:
  57. //
  58. // arg1: [0x0 ~> 0x1]
  59. // arg2: [0x0 ~> 0xffffffffffffffff]
  60. // arg3: [0x0 ~> 0xffffffffffffffff]
  61. //
  62. // Output Bounds:
  63. //
  64. // out1: [0x0 ~> 0xffffffffffffffff]
  65. func fiatScalarCmovznzU64(out1 *uint64, arg1 fiatScalarUint1, arg2 uint64, arg3 uint64) {
  66. x1 := (uint64(arg1) * 0xffffffffffffffff)
  67. x2 := ((x1 & arg3) | ((^x1) & arg2))
  68. *out1 = x2
  69. }
  70. // fiatScalarMul multiplies two field elements in the Montgomery domain.
  71. //
  72. // Preconditions:
  73. //
  74. // 0 ≤ eval arg1 < m
  75. // 0 ≤ eval arg2 < m
  76. //
  77. // Postconditions:
  78. //
  79. // eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg2)) mod m
  80. // 0 ≤ eval out1 < m
  81. func fiatScalarMul(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement) {
  82. x1 := arg1[1]
  83. x2 := arg1[2]
  84. x3 := arg1[3]
  85. x4 := arg1[0]
  86. var x5 uint64
  87. var x6 uint64
  88. x6, x5 = bits.Mul64(x4, arg2[3])
  89. var x7 uint64
  90. var x8 uint64
  91. x8, x7 = bits.Mul64(x4, arg2[2])
  92. var x9 uint64
  93. var x10 uint64
  94. x10, x9 = bits.Mul64(x4, arg2[1])
  95. var x11 uint64
  96. var x12 uint64
  97. x12, x11 = bits.Mul64(x4, arg2[0])
  98. var x13 uint64
  99. var x14 uint64
  100. x13, x14 = bits.Add64(x12, x9, uint64(0x0))
  101. var x15 uint64
  102. var x16 uint64
  103. x15, x16 = bits.Add64(x10, x7, uint64(fiatScalarUint1(x14)))
  104. var x17 uint64
  105. var x18 uint64
  106. x17, x18 = bits.Add64(x8, x5, uint64(fiatScalarUint1(x16)))
  107. x19 := (uint64(fiatScalarUint1(x18)) + x6)
  108. var x20 uint64
  109. _, x20 = bits.Mul64(x11, 0xd2b51da312547e1b)
  110. var x22 uint64
  111. var x23 uint64
  112. x23, x22 = bits.Mul64(x20, 0x1000000000000000)
  113. var x24 uint64
  114. var x25 uint64
  115. x25, x24 = bits.Mul64(x20, 0x14def9dea2f79cd6)
  116. var x26 uint64
  117. var x27 uint64
  118. x27, x26 = bits.Mul64(x20, 0x5812631a5cf5d3ed)
  119. var x28 uint64
  120. var x29 uint64
  121. x28, x29 = bits.Add64(x27, x24, uint64(0x0))
  122. x30 := (uint64(fiatScalarUint1(x29)) + x25)
  123. var x32 uint64
  124. _, x32 = bits.Add64(x11, x26, uint64(0x0))
  125. var x33 uint64
  126. var x34 uint64
  127. x33, x34 = bits.Add64(x13, x28, uint64(fiatScalarUint1(x32)))
  128. var x35 uint64
  129. var x36 uint64
  130. x35, x36 = bits.Add64(x15, x30, uint64(fiatScalarUint1(x34)))
  131. var x37 uint64
  132. var x38 uint64
  133. x37, x38 = bits.Add64(x17, x22, uint64(fiatScalarUint1(x36)))
  134. var x39 uint64
  135. var x40 uint64
  136. x39, x40 = bits.Add64(x19, x23, uint64(fiatScalarUint1(x38)))
  137. var x41 uint64
  138. var x42 uint64
  139. x42, x41 = bits.Mul64(x1, arg2[3])
  140. var x43 uint64
  141. var x44 uint64
  142. x44, x43 = bits.Mul64(x1, arg2[2])
  143. var x45 uint64
  144. var x46 uint64
  145. x46, x45 = bits.Mul64(x1, arg2[1])
  146. var x47 uint64
  147. var x48 uint64
  148. x48, x47 = bits.Mul64(x1, arg2[0])
  149. var x49 uint64
  150. var x50 uint64
  151. x49, x50 = bits.Add64(x48, x45, uint64(0x0))
  152. var x51 uint64
  153. var x52 uint64
  154. x51, x52 = bits.Add64(x46, x43, uint64(fiatScalarUint1(x50)))
  155. var x53 uint64
  156. var x54 uint64
  157. x53, x54 = bits.Add64(x44, x41, uint64(fiatScalarUint1(x52)))
  158. x55 := (uint64(fiatScalarUint1(x54)) + x42)
  159. var x56 uint64
  160. var x57 uint64
  161. x56, x57 = bits.Add64(x33, x47, uint64(0x0))
  162. var x58 uint64
  163. var x59 uint64
  164. x58, x59 = bits.Add64(x35, x49, uint64(fiatScalarUint1(x57)))
  165. var x60 uint64
  166. var x61 uint64
  167. x60, x61 = bits.Add64(x37, x51, uint64(fiatScalarUint1(x59)))
  168. var x62 uint64
  169. var x63 uint64
  170. x62, x63 = bits.Add64(x39, x53, uint64(fiatScalarUint1(x61)))
  171. var x64 uint64
  172. var x65 uint64
  173. x64, x65 = bits.Add64(uint64(fiatScalarUint1(x40)), x55, uint64(fiatScalarUint1(x63)))
  174. var x66 uint64
  175. _, x66 = bits.Mul64(x56, 0xd2b51da312547e1b)
  176. var x68 uint64
  177. var x69 uint64
  178. x69, x68 = bits.Mul64(x66, 0x1000000000000000)
  179. var x70 uint64
  180. var x71 uint64
  181. x71, x70 = bits.Mul64(x66, 0x14def9dea2f79cd6)
  182. var x72 uint64
  183. var x73 uint64
  184. x73, x72 = bits.Mul64(x66, 0x5812631a5cf5d3ed)
  185. var x74 uint64
  186. var x75 uint64
  187. x74, x75 = bits.Add64(x73, x70, uint64(0x0))
  188. x76 := (uint64(fiatScalarUint1(x75)) + x71)
  189. var x78 uint64
  190. _, x78 = bits.Add64(x56, x72, uint64(0x0))
  191. var x79 uint64
  192. var x80 uint64
  193. x79, x80 = bits.Add64(x58, x74, uint64(fiatScalarUint1(x78)))
  194. var x81 uint64
  195. var x82 uint64
  196. x81, x82 = bits.Add64(x60, x76, uint64(fiatScalarUint1(x80)))
  197. var x83 uint64
  198. var x84 uint64
  199. x83, x84 = bits.Add64(x62, x68, uint64(fiatScalarUint1(x82)))
  200. var x85 uint64
  201. var x86 uint64
  202. x85, x86 = bits.Add64(x64, x69, uint64(fiatScalarUint1(x84)))
  203. x87 := (uint64(fiatScalarUint1(x86)) + uint64(fiatScalarUint1(x65)))
  204. var x88 uint64
  205. var x89 uint64
  206. x89, x88 = bits.Mul64(x2, arg2[3])
  207. var x90 uint64
  208. var x91 uint64
  209. x91, x90 = bits.Mul64(x2, arg2[2])
  210. var x92 uint64
  211. var x93 uint64
  212. x93, x92 = bits.Mul64(x2, arg2[1])
  213. var x94 uint64
  214. var x95 uint64
  215. x95, x94 = bits.Mul64(x2, arg2[0])
  216. var x96 uint64
  217. var x97 uint64
  218. x96, x97 = bits.Add64(x95, x92, uint64(0x0))
  219. var x98 uint64
  220. var x99 uint64
  221. x98, x99 = bits.Add64(x93, x90, uint64(fiatScalarUint1(x97)))
  222. var x100 uint64
  223. var x101 uint64
  224. x100, x101 = bits.Add64(x91, x88, uint64(fiatScalarUint1(x99)))
  225. x102 := (uint64(fiatScalarUint1(x101)) + x89)
  226. var x103 uint64
  227. var x104 uint64
  228. x103, x104 = bits.Add64(x79, x94, uint64(0x0))
  229. var x105 uint64
  230. var x106 uint64
  231. x105, x106 = bits.Add64(x81, x96, uint64(fiatScalarUint1(x104)))
  232. var x107 uint64
  233. var x108 uint64
  234. x107, x108 = bits.Add64(x83, x98, uint64(fiatScalarUint1(x106)))
  235. var x109 uint64
  236. var x110 uint64
  237. x109, x110 = bits.Add64(x85, x100, uint64(fiatScalarUint1(x108)))
  238. var x111 uint64
  239. var x112 uint64
  240. x111, x112 = bits.Add64(x87, x102, uint64(fiatScalarUint1(x110)))
  241. var x113 uint64
  242. _, x113 = bits.Mul64(x103, 0xd2b51da312547e1b)
  243. var x115 uint64
  244. var x116 uint64
  245. x116, x115 = bits.Mul64(x113, 0x1000000000000000)
  246. var x117 uint64
  247. var x118 uint64
  248. x118, x117 = bits.Mul64(x113, 0x14def9dea2f79cd6)
  249. var x119 uint64
  250. var x120 uint64
  251. x120, x119 = bits.Mul64(x113, 0x5812631a5cf5d3ed)
  252. var x121 uint64
  253. var x122 uint64
  254. x121, x122 = bits.Add64(x120, x117, uint64(0x0))
  255. x123 := (uint64(fiatScalarUint1(x122)) + x118)
  256. var x125 uint64
  257. _, x125 = bits.Add64(x103, x119, uint64(0x0))
  258. var x126 uint64
  259. var x127 uint64
  260. x126, x127 = bits.Add64(x105, x121, uint64(fiatScalarUint1(x125)))
  261. var x128 uint64
  262. var x129 uint64
  263. x128, x129 = bits.Add64(x107, x123, uint64(fiatScalarUint1(x127)))
  264. var x130 uint64
  265. var x131 uint64
  266. x130, x131 = bits.Add64(x109, x115, uint64(fiatScalarUint1(x129)))
  267. var x132 uint64
  268. var x133 uint64
  269. x132, x133 = bits.Add64(x111, x116, uint64(fiatScalarUint1(x131)))
  270. x134 := (uint64(fiatScalarUint1(x133)) + uint64(fiatScalarUint1(x112)))
  271. var x135 uint64
  272. var x136 uint64
  273. x136, x135 = bits.Mul64(x3, arg2[3])
  274. var x137 uint64
  275. var x138 uint64
  276. x138, x137 = bits.Mul64(x3, arg2[2])
  277. var x139 uint64
  278. var x140 uint64
  279. x140, x139 = bits.Mul64(x3, arg2[1])
  280. var x141 uint64
  281. var x142 uint64
  282. x142, x141 = bits.Mul64(x3, arg2[0])
  283. var x143 uint64
  284. var x144 uint64
  285. x143, x144 = bits.Add64(x142, x139, uint64(0x0))
  286. var x145 uint64
  287. var x146 uint64
  288. x145, x146 = bits.Add64(x140, x137, uint64(fiatScalarUint1(x144)))
  289. var x147 uint64
  290. var x148 uint64
  291. x147, x148 = bits.Add64(x138, x135, uint64(fiatScalarUint1(x146)))
  292. x149 := (uint64(fiatScalarUint1(x148)) + x136)
  293. var x150 uint64
  294. var x151 uint64
  295. x150, x151 = bits.Add64(x126, x141, uint64(0x0))
  296. var x152 uint64
  297. var x153 uint64
  298. x152, x153 = bits.Add64(x128, x143, uint64(fiatScalarUint1(x151)))
  299. var x154 uint64
  300. var x155 uint64
  301. x154, x155 = bits.Add64(x130, x145, uint64(fiatScalarUint1(x153)))
  302. var x156 uint64
  303. var x157 uint64
  304. x156, x157 = bits.Add64(x132, x147, uint64(fiatScalarUint1(x155)))
  305. var x158 uint64
  306. var x159 uint64
  307. x158, x159 = bits.Add64(x134, x149, uint64(fiatScalarUint1(x157)))
  308. var x160 uint64
  309. _, x160 = bits.Mul64(x150, 0xd2b51da312547e1b)
  310. var x162 uint64
  311. var x163 uint64
  312. x163, x162 = bits.Mul64(x160, 0x1000000000000000)
  313. var x164 uint64
  314. var x165 uint64
  315. x165, x164 = bits.Mul64(x160, 0x14def9dea2f79cd6)
  316. var x166 uint64
  317. var x167 uint64
  318. x167, x166 = bits.Mul64(x160, 0x5812631a5cf5d3ed)
  319. var x168 uint64
  320. var x169 uint64
  321. x168, x169 = bits.Add64(x167, x164, uint64(0x0))
  322. x170 := (uint64(fiatScalarUint1(x169)) + x165)
  323. var x172 uint64
  324. _, x172 = bits.Add64(x150, x166, uint64(0x0))
  325. var x173 uint64
  326. var x174 uint64
  327. x173, x174 = bits.Add64(x152, x168, uint64(fiatScalarUint1(x172)))
  328. var x175 uint64
  329. var x176 uint64
  330. x175, x176 = bits.Add64(x154, x170, uint64(fiatScalarUint1(x174)))
  331. var x177 uint64
  332. var x178 uint64
  333. x177, x178 = bits.Add64(x156, x162, uint64(fiatScalarUint1(x176)))
  334. var x179 uint64
  335. var x180 uint64
  336. x179, x180 = bits.Add64(x158, x163, uint64(fiatScalarUint1(x178)))
  337. x181 := (uint64(fiatScalarUint1(x180)) + uint64(fiatScalarUint1(x159)))
  338. var x182 uint64
  339. var x183 uint64
  340. x182, x183 = bits.Sub64(x173, 0x5812631a5cf5d3ed, uint64(0x0))
  341. var x184 uint64
  342. var x185 uint64
  343. x184, x185 = bits.Sub64(x175, 0x14def9dea2f79cd6, uint64(fiatScalarUint1(x183)))
  344. var x186 uint64
  345. var x187 uint64
  346. x186, x187 = bits.Sub64(x177, uint64(0x0), uint64(fiatScalarUint1(x185)))
  347. var x188 uint64
  348. var x189 uint64
  349. x188, x189 = bits.Sub64(x179, 0x1000000000000000, uint64(fiatScalarUint1(x187)))
  350. var x191 uint64
  351. _, x191 = bits.Sub64(x181, uint64(0x0), uint64(fiatScalarUint1(x189)))
  352. var x192 uint64
  353. fiatScalarCmovznzU64(&x192, fiatScalarUint1(x191), x182, x173)
  354. var x193 uint64
  355. fiatScalarCmovznzU64(&x193, fiatScalarUint1(x191), x184, x175)
  356. var x194 uint64
  357. fiatScalarCmovznzU64(&x194, fiatScalarUint1(x191), x186, x177)
  358. var x195 uint64
  359. fiatScalarCmovznzU64(&x195, fiatScalarUint1(x191), x188, x179)
  360. out1[0] = x192
  361. out1[1] = x193
  362. out1[2] = x194
  363. out1[3] = x195
  364. }
  365. // fiatScalarAdd adds two field elements in the Montgomery domain.
  366. //
  367. // Preconditions:
  368. //
  369. // 0 ≤ eval arg1 < m
  370. // 0 ≤ eval arg2 < m
  371. //
  372. // Postconditions:
  373. //
  374. // eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) + eval (from_montgomery arg2)) mod m
  375. // 0 ≤ eval out1 < m
  376. func fiatScalarAdd(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement) {
  377. var x1 uint64
  378. var x2 uint64
  379. x1, x2 = bits.Add64(arg1[0], arg2[0], uint64(0x0))
  380. var x3 uint64
  381. var x4 uint64
  382. x3, x4 = bits.Add64(arg1[1], arg2[1], uint64(fiatScalarUint1(x2)))
  383. var x5 uint64
  384. var x6 uint64
  385. x5, x6 = bits.Add64(arg1[2], arg2[2], uint64(fiatScalarUint1(x4)))
  386. var x7 uint64
  387. var x8 uint64
  388. x7, x8 = bits.Add64(arg1[3], arg2[3], uint64(fiatScalarUint1(x6)))
  389. var x9 uint64
  390. var x10 uint64
  391. x9, x10 = bits.Sub64(x1, 0x5812631a5cf5d3ed, uint64(0x0))
  392. var x11 uint64
  393. var x12 uint64
  394. x11, x12 = bits.Sub64(x3, 0x14def9dea2f79cd6, uint64(fiatScalarUint1(x10)))
  395. var x13 uint64
  396. var x14 uint64
  397. x13, x14 = bits.Sub64(x5, uint64(0x0), uint64(fiatScalarUint1(x12)))
  398. var x15 uint64
  399. var x16 uint64
  400. x15, x16 = bits.Sub64(x7, 0x1000000000000000, uint64(fiatScalarUint1(x14)))
  401. var x18 uint64
  402. _, x18 = bits.Sub64(uint64(fiatScalarUint1(x8)), uint64(0x0), uint64(fiatScalarUint1(x16)))
  403. var x19 uint64
  404. fiatScalarCmovznzU64(&x19, fiatScalarUint1(x18), x9, x1)
  405. var x20 uint64
  406. fiatScalarCmovznzU64(&x20, fiatScalarUint1(x18), x11, x3)
  407. var x21 uint64
  408. fiatScalarCmovznzU64(&x21, fiatScalarUint1(x18), x13, x5)
  409. var x22 uint64
  410. fiatScalarCmovznzU64(&x22, fiatScalarUint1(x18), x15, x7)
  411. out1[0] = x19
  412. out1[1] = x20
  413. out1[2] = x21
  414. out1[3] = x22
  415. }
  416. // fiatScalarSub subtracts two field elements in the Montgomery domain.
  417. //
  418. // Preconditions:
  419. //
  420. // 0 ≤ eval arg1 < m
  421. // 0 ≤ eval arg2 < m
  422. //
  423. // Postconditions:
  424. //
  425. // eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) - eval (from_montgomery arg2)) mod m
  426. // 0 ≤ eval out1 < m
  427. func fiatScalarSub(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement) {
  428. var x1 uint64
  429. var x2 uint64
  430. x1, x2 = bits.Sub64(arg1[0], arg2[0], uint64(0x0))
  431. var x3 uint64
  432. var x4 uint64
  433. x3, x4 = bits.Sub64(arg1[1], arg2[1], uint64(fiatScalarUint1(x2)))
  434. var x5 uint64
  435. var x6 uint64
  436. x5, x6 = bits.Sub64(arg1[2], arg2[2], uint64(fiatScalarUint1(x4)))
  437. var x7 uint64
  438. var x8 uint64
  439. x7, x8 = bits.Sub64(arg1[3], arg2[3], uint64(fiatScalarUint1(x6)))
  440. var x9 uint64
  441. fiatScalarCmovznzU64(&x9, fiatScalarUint1(x8), uint64(0x0), 0xffffffffffffffff)
  442. var x10 uint64
  443. var x11 uint64
  444. x10, x11 = bits.Add64(x1, (x9 & 0x5812631a5cf5d3ed), uint64(0x0))
  445. var x12 uint64
  446. var x13 uint64
  447. x12, x13 = bits.Add64(x3, (x9 & 0x14def9dea2f79cd6), uint64(fiatScalarUint1(x11)))
  448. var x14 uint64
  449. var x15 uint64
  450. x14, x15 = bits.Add64(x5, uint64(0x0), uint64(fiatScalarUint1(x13)))
  451. var x16 uint64
  452. x16, _ = bits.Add64(x7, (x9 & 0x1000000000000000), uint64(fiatScalarUint1(x15)))
  453. out1[0] = x10
  454. out1[1] = x12
  455. out1[2] = x14
  456. out1[3] = x16
  457. }
  458. // fiatScalarOpp negates a field element in the Montgomery domain.
  459. //
  460. // Preconditions:
  461. //
  462. // 0 ≤ eval arg1 < m
  463. //
  464. // Postconditions:
  465. //
  466. // eval (from_montgomery out1) mod m = -eval (from_montgomery arg1) mod m
  467. // 0 ≤ eval out1 < m
  468. func fiatScalarOpp(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement) {
  469. var x1 uint64
  470. var x2 uint64
  471. x1, x2 = bits.Sub64(uint64(0x0), arg1[0], uint64(0x0))
  472. var x3 uint64
  473. var x4 uint64
  474. x3, x4 = bits.Sub64(uint64(0x0), arg1[1], uint64(fiatScalarUint1(x2)))
  475. var x5 uint64
  476. var x6 uint64
  477. x5, x6 = bits.Sub64(uint64(0x0), arg1[2], uint64(fiatScalarUint1(x4)))
  478. var x7 uint64
  479. var x8 uint64
  480. x7, x8 = bits.Sub64(uint64(0x0), arg1[3], uint64(fiatScalarUint1(x6)))
  481. var x9 uint64
  482. fiatScalarCmovznzU64(&x9, fiatScalarUint1(x8), uint64(0x0), 0xffffffffffffffff)
  483. var x10 uint64
  484. var x11 uint64
  485. x10, x11 = bits.Add64(x1, (x9 & 0x5812631a5cf5d3ed), uint64(0x0))
  486. var x12 uint64
  487. var x13 uint64
  488. x12, x13 = bits.Add64(x3, (x9 & 0x14def9dea2f79cd6), uint64(fiatScalarUint1(x11)))
  489. var x14 uint64
  490. var x15 uint64
  491. x14, x15 = bits.Add64(x5, uint64(0x0), uint64(fiatScalarUint1(x13)))
  492. var x16 uint64
  493. x16, _ = bits.Add64(x7, (x9 & 0x1000000000000000), uint64(fiatScalarUint1(x15)))
  494. out1[0] = x10
  495. out1[1] = x12
  496. out1[2] = x14
  497. out1[3] = x16
  498. }
  499. // fiatScalarNonzero outputs a single non-zero word if the input is non-zero and zero otherwise.
  500. //
  501. // Preconditions:
  502. //
  503. // 0 ≤ eval arg1 < m
  504. //
  505. // Postconditions:
  506. //
  507. // out1 = 0 ↔ eval (from_montgomery arg1) mod m = 0
  508. //
  509. // Input Bounds:
  510. //
  511. // arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
  512. //
  513. // Output Bounds:
  514. //
  515. // out1: [0x0 ~> 0xffffffffffffffff]
  516. func fiatScalarNonzero(out1 *uint64, arg1 *[4]uint64) {
  517. x1 := (arg1[0] | (arg1[1] | (arg1[2] | arg1[3])))
  518. *out1 = x1
  519. }
  520. // fiatScalarFromMontgomery translates a field element out of the Montgomery domain.
  521. //
  522. // Preconditions:
  523. //
  524. // 0 ≤ eval arg1 < m
  525. //
  526. // Postconditions:
  527. //
  528. // eval out1 mod m = (eval arg1 * ((2^64)⁻¹ mod m)^4) mod m
  529. // 0 ≤ eval out1 < m
  530. func fiatScalarFromMontgomery(out1 *fiatScalarNonMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement) {
  531. x1 := arg1[0]
  532. var x2 uint64
  533. _, x2 = bits.Mul64(x1, 0xd2b51da312547e1b)
  534. var x4 uint64
  535. var x5 uint64
  536. x5, x4 = bits.Mul64(x2, 0x1000000000000000)
  537. var x6 uint64
  538. var x7 uint64
  539. x7, x6 = bits.Mul64(x2, 0x14def9dea2f79cd6)
  540. var x8 uint64
  541. var x9 uint64
  542. x9, x8 = bits.Mul64(x2, 0x5812631a5cf5d3ed)
  543. var x10 uint64
  544. var x11 uint64
  545. x10, x11 = bits.Add64(x9, x6, uint64(0x0))
  546. var x13 uint64
  547. _, x13 = bits.Add64(x1, x8, uint64(0x0))
  548. var x14 uint64
  549. var x15 uint64
  550. x14, x15 = bits.Add64(uint64(0x0), x10, uint64(fiatScalarUint1(x13)))
  551. var x16 uint64
  552. var x17 uint64
  553. x16, x17 = bits.Add64(x14, arg1[1], uint64(0x0))
  554. var x18 uint64
  555. _, x18 = bits.Mul64(x16, 0xd2b51da312547e1b)
  556. var x20 uint64
  557. var x21 uint64
  558. x21, x20 = bits.Mul64(x18, 0x1000000000000000)
  559. var x22 uint64
  560. var x23 uint64
  561. x23, x22 = bits.Mul64(x18, 0x14def9dea2f79cd6)
  562. var x24 uint64
  563. var x25 uint64
  564. x25, x24 = bits.Mul64(x18, 0x5812631a5cf5d3ed)
  565. var x26 uint64
  566. var x27 uint64
  567. x26, x27 = bits.Add64(x25, x22, uint64(0x0))
  568. var x29 uint64
  569. _, x29 = bits.Add64(x16, x24, uint64(0x0))
  570. var x30 uint64
  571. var x31 uint64
  572. x30, x31 = bits.Add64((uint64(fiatScalarUint1(x17)) + (uint64(fiatScalarUint1(x15)) + (uint64(fiatScalarUint1(x11)) + x7))), x26, uint64(fiatScalarUint1(x29)))
  573. var x32 uint64
  574. var x33 uint64
  575. x32, x33 = bits.Add64(x4, (uint64(fiatScalarUint1(x27)) + x23), uint64(fiatScalarUint1(x31)))
  576. var x34 uint64
  577. var x35 uint64
  578. x34, x35 = bits.Add64(x5, x20, uint64(fiatScalarUint1(x33)))
  579. var x36 uint64
  580. var x37 uint64
  581. x36, x37 = bits.Add64(x30, arg1[2], uint64(0x0))
  582. var x38 uint64
  583. var x39 uint64
  584. x38, x39 = bits.Add64(x32, uint64(0x0), uint64(fiatScalarUint1(x37)))
  585. var x40 uint64
  586. var x41 uint64
  587. x40, x41 = bits.Add64(x34, uint64(0x0), uint64(fiatScalarUint1(x39)))
  588. var x42 uint64
  589. _, x42 = bits.Mul64(x36, 0xd2b51da312547e1b)
  590. var x44 uint64
  591. var x45 uint64
  592. x45, x44 = bits.Mul64(x42, 0x1000000000000000)
  593. var x46 uint64
  594. var x47 uint64
  595. x47, x46 = bits.Mul64(x42, 0x14def9dea2f79cd6)
  596. var x48 uint64
  597. var x49 uint64
  598. x49, x48 = bits.Mul64(x42, 0x5812631a5cf5d3ed)
  599. var x50 uint64
  600. var x51 uint64
  601. x50, x51 = bits.Add64(x49, x46, uint64(0x0))
  602. var x53 uint64
  603. _, x53 = bits.Add64(x36, x48, uint64(0x0))
  604. var x54 uint64
  605. var x55 uint64
  606. x54, x55 = bits.Add64(x38, x50, uint64(fiatScalarUint1(x53)))
  607. var x56 uint64
  608. var x57 uint64
  609. x56, x57 = bits.Add64(x40, (uint64(fiatScalarUint1(x51)) + x47), uint64(fiatScalarUint1(x55)))
  610. var x58 uint64
  611. var x59 uint64
  612. x58, x59 = bits.Add64((uint64(fiatScalarUint1(x41)) + (uint64(fiatScalarUint1(x35)) + x21)), x44, uint64(fiatScalarUint1(x57)))
  613. var x60 uint64
  614. var x61 uint64
  615. x60, x61 = bits.Add64(x54, arg1[3], uint64(0x0))
  616. var x62 uint64
  617. var x63 uint64
  618. x62, x63 = bits.Add64(x56, uint64(0x0), uint64(fiatScalarUint1(x61)))
  619. var x64 uint64
  620. var x65 uint64
  621. x64, x65 = bits.Add64(x58, uint64(0x0), uint64(fiatScalarUint1(x63)))
  622. var x66 uint64
  623. _, x66 = bits.Mul64(x60, 0xd2b51da312547e1b)
  624. var x68 uint64
  625. var x69 uint64
  626. x69, x68 = bits.Mul64(x66, 0x1000000000000000)
  627. var x70 uint64
  628. var x71 uint64
  629. x71, x70 = bits.Mul64(x66, 0x14def9dea2f79cd6)
  630. var x72 uint64
  631. var x73 uint64
  632. x73, x72 = bits.Mul64(x66, 0x5812631a5cf5d3ed)
  633. var x74 uint64
  634. var x75 uint64
  635. x74, x75 = bits.Add64(x73, x70, uint64(0x0))
  636. var x77 uint64
  637. _, x77 = bits.Add64(x60, x72, uint64(0x0))
  638. var x78 uint64
  639. var x79 uint64
  640. x78, x79 = bits.Add64(x62, x74, uint64(fiatScalarUint1(x77)))
  641. var x80 uint64
  642. var x81 uint64
  643. x80, x81 = bits.Add64(x64, (uint64(fiatScalarUint1(x75)) + x71), uint64(fiatScalarUint1(x79)))
  644. var x82 uint64
  645. var x83 uint64
  646. x82, x83 = bits.Add64((uint64(fiatScalarUint1(x65)) + (uint64(fiatScalarUint1(x59)) + x45)), x68, uint64(fiatScalarUint1(x81)))
  647. x84 := (uint64(fiatScalarUint1(x83)) + x69)
  648. var x85 uint64
  649. var x86 uint64
  650. x85, x86 = bits.Sub64(x78, 0x5812631a5cf5d3ed, uint64(0x0))
  651. var x87 uint64
  652. var x88 uint64
  653. x87, x88 = bits.Sub64(x80, 0x14def9dea2f79cd6, uint64(fiatScalarUint1(x86)))
  654. var x89 uint64
  655. var x90 uint64
  656. x89, x90 = bits.Sub64(x82, uint64(0x0), uint64(fiatScalarUint1(x88)))
  657. var x91 uint64
  658. var x92 uint64
  659. x91, x92 = bits.Sub64(x84, 0x1000000000000000, uint64(fiatScalarUint1(x90)))
  660. var x94 uint64
  661. _, x94 = bits.Sub64(uint64(0x0), uint64(0x0), uint64(fiatScalarUint1(x92)))
  662. var x95 uint64
  663. fiatScalarCmovznzU64(&x95, fiatScalarUint1(x94), x85, x78)
  664. var x96 uint64
  665. fiatScalarCmovznzU64(&x96, fiatScalarUint1(x94), x87, x80)
  666. var x97 uint64
  667. fiatScalarCmovznzU64(&x97, fiatScalarUint1(x94), x89, x82)
  668. var x98 uint64
  669. fiatScalarCmovznzU64(&x98, fiatScalarUint1(x94), x91, x84)
  670. out1[0] = x95
  671. out1[1] = x96
  672. out1[2] = x97
  673. out1[3] = x98
  674. }
  675. // fiatScalarToMontgomery translates a field element into the Montgomery domain.
  676. //
  677. // Preconditions:
  678. //
  679. // 0 ≤ eval arg1 < m
  680. //
  681. // Postconditions:
  682. //
  683. // eval (from_montgomery out1) mod m = eval arg1 mod m
  684. // 0 ≤ eval out1 < m
  685. func fiatScalarToMontgomery(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarNonMontgomeryDomainFieldElement) {
  686. x1 := arg1[1]
  687. x2 := arg1[2]
  688. x3 := arg1[3]
  689. x4 := arg1[0]
  690. var x5 uint64
  691. var x6 uint64
  692. x6, x5 = bits.Mul64(x4, 0x399411b7c309a3d)
  693. var x7 uint64
  694. var x8 uint64
  695. x8, x7 = bits.Mul64(x4, 0xceec73d217f5be65)
  696. var x9 uint64
  697. var x10 uint64
  698. x10, x9 = bits.Mul64(x4, 0xd00e1ba768859347)
  699. var x11 uint64
  700. var x12 uint64
  701. x12, x11 = bits.Mul64(x4, 0xa40611e3449c0f01)
  702. var x13 uint64
  703. var x14 uint64
  704. x13, x14 = bits.Add64(x12, x9, uint64(0x0))
  705. var x15 uint64
  706. var x16 uint64
  707. x15, x16 = bits.Add64(x10, x7, uint64(fiatScalarUint1(x14)))
  708. var x17 uint64
  709. var x18 uint64
  710. x17, x18 = bits.Add64(x8, x5, uint64(fiatScalarUint1(x16)))
  711. var x19 uint64
  712. _, x19 = bits.Mul64(x11, 0xd2b51da312547e1b)
  713. var x21 uint64
  714. var x22 uint64
  715. x22, x21 = bits.Mul64(x19, 0x1000000000000000)
  716. var x23 uint64
  717. var x24 uint64
  718. x24, x23 = bits.Mul64(x19, 0x14def9dea2f79cd6)
  719. var x25 uint64
  720. var x26 uint64
  721. x26, x25 = bits.Mul64(x19, 0x5812631a5cf5d3ed)
  722. var x27 uint64
  723. var x28 uint64
  724. x27, x28 = bits.Add64(x26, x23, uint64(0x0))
  725. var x30 uint64
  726. _, x30 = bits.Add64(x11, x25, uint64(0x0))
  727. var x31 uint64
  728. var x32 uint64
  729. x31, x32 = bits.Add64(x13, x27, uint64(fiatScalarUint1(x30)))
  730. var x33 uint64
  731. var x34 uint64
  732. x33, x34 = bits.Add64(x15, (uint64(fiatScalarUint1(x28)) + x24), uint64(fiatScalarUint1(x32)))
  733. var x35 uint64
  734. var x36 uint64
  735. x35, x36 = bits.Add64(x17, x21, uint64(fiatScalarUint1(x34)))
  736. var x37 uint64
  737. var x38 uint64
  738. x38, x37 = bits.Mul64(x1, 0x399411b7c309a3d)
  739. var x39 uint64
  740. var x40 uint64
  741. x40, x39 = bits.Mul64(x1, 0xceec73d217f5be65)
  742. var x41 uint64
  743. var x42 uint64
  744. x42, x41 = bits.Mul64(x1, 0xd00e1ba768859347)
  745. var x43 uint64
  746. var x44 uint64
  747. x44, x43 = bits.Mul64(x1, 0xa40611e3449c0f01)
  748. var x45 uint64
  749. var x46 uint64
  750. x45, x46 = bits.Add64(x44, x41, uint64(0x0))
  751. var x47 uint64
  752. var x48 uint64
  753. x47, x48 = bits.Add64(x42, x39, uint64(fiatScalarUint1(x46)))
  754. var x49 uint64
  755. var x50 uint64
  756. x49, x50 = bits.Add64(x40, x37, uint64(fiatScalarUint1(x48)))
  757. var x51 uint64
  758. var x52 uint64
  759. x51, x52 = bits.Add64(x31, x43, uint64(0x0))
  760. var x53 uint64
  761. var x54 uint64
  762. x53, x54 = bits.Add64(x33, x45, uint64(fiatScalarUint1(x52)))
  763. var x55 uint64
  764. var x56 uint64
  765. x55, x56 = bits.Add64(x35, x47, uint64(fiatScalarUint1(x54)))
  766. var x57 uint64
  767. var x58 uint64
  768. x57, x58 = bits.Add64(((uint64(fiatScalarUint1(x36)) + (uint64(fiatScalarUint1(x18)) + x6)) + x22), x49, uint64(fiatScalarUint1(x56)))
  769. var x59 uint64
  770. _, x59 = bits.Mul64(x51, 0xd2b51da312547e1b)
  771. var x61 uint64
  772. var x62 uint64
  773. x62, x61 = bits.Mul64(x59, 0x1000000000000000)
  774. var x63 uint64
  775. var x64 uint64
  776. x64, x63 = bits.Mul64(x59, 0x14def9dea2f79cd6)
  777. var x65 uint64
  778. var x66 uint64
  779. x66, x65 = bits.Mul64(x59, 0x5812631a5cf5d3ed)
  780. var x67 uint64
  781. var x68 uint64
  782. x67, x68 = bits.Add64(x66, x63, uint64(0x0))
  783. var x70 uint64
  784. _, x70 = bits.Add64(x51, x65, uint64(0x0))
  785. var x71 uint64
  786. var x72 uint64
  787. x71, x72 = bits.Add64(x53, x67, uint64(fiatScalarUint1(x70)))
  788. var x73 uint64
  789. var x74 uint64
  790. x73, x74 = bits.Add64(x55, (uint64(fiatScalarUint1(x68)) + x64), uint64(fiatScalarUint1(x72)))
  791. var x75 uint64
  792. var x76 uint64
  793. x75, x76 = bits.Add64(x57, x61, uint64(fiatScalarUint1(x74)))
  794. var x77 uint64
  795. var x78 uint64
  796. x78, x77 = bits.Mul64(x2, 0x399411b7c309a3d)
  797. var x79 uint64
  798. var x80 uint64
  799. x80, x79 = bits.Mul64(x2, 0xceec73d217f5be65)
  800. var x81 uint64
  801. var x82 uint64
  802. x82, x81 = bits.Mul64(x2, 0xd00e1ba768859347)
  803. var x83 uint64
  804. var x84 uint64
  805. x84, x83 = bits.Mul64(x2, 0xa40611e3449c0f01)
  806. var x85 uint64
  807. var x86 uint64
  808. x85, x86 = bits.Add64(x84, x81, uint64(0x0))
  809. var x87 uint64
  810. var x88 uint64
  811. x87, x88 = bits.Add64(x82, x79, uint64(fiatScalarUint1(x86)))
  812. var x89 uint64
  813. var x90 uint64
  814. x89, x90 = bits.Add64(x80, x77, uint64(fiatScalarUint1(x88)))
  815. var x91 uint64
  816. var x92 uint64
  817. x91, x92 = bits.Add64(x71, x83, uint64(0x0))
  818. var x93 uint64
  819. var x94 uint64
  820. x93, x94 = bits.Add64(x73, x85, uint64(fiatScalarUint1(x92)))
  821. var x95 uint64
  822. var x96 uint64
  823. x95, x96 = bits.Add64(x75, x87, uint64(fiatScalarUint1(x94)))
  824. var x97 uint64
  825. var x98 uint64
  826. x97, x98 = bits.Add64(((uint64(fiatScalarUint1(x76)) + (uint64(fiatScalarUint1(x58)) + (uint64(fiatScalarUint1(x50)) + x38))) + x62), x89, uint64(fiatScalarUint1(x96)))
  827. var x99 uint64
  828. _, x99 = bits.Mul64(x91, 0xd2b51da312547e1b)
  829. var x101 uint64
  830. var x102 uint64
  831. x102, x101 = bits.Mul64(x99, 0x1000000000000000)
  832. var x103 uint64
  833. var x104 uint64
  834. x104, x103 = bits.Mul64(x99, 0x14def9dea2f79cd6)
  835. var x105 uint64
  836. var x106 uint64
  837. x106, x105 = bits.Mul64(x99, 0x5812631a5cf5d3ed)
  838. var x107 uint64
  839. var x108 uint64
  840. x107, x108 = bits.Add64(x106, x103, uint64(0x0))
  841. var x110 uint64
  842. _, x110 = bits.Add64(x91, x105, uint64(0x0))
  843. var x111 uint64
  844. var x112 uint64
  845. x111, x112 = bits.Add64(x93, x107, uint64(fiatScalarUint1(x110)))
  846. var x113 uint64
  847. var x114 uint64
  848. x113, x114 = bits.Add64(x95, (uint64(fiatScalarUint1(x108)) + x104), uint64(fiatScalarUint1(x112)))
  849. var x115 uint64
  850. var x116 uint64
  851. x115, x116 = bits.Add64(x97, x101, uint64(fiatScalarUint1(x114)))
  852. var x117 uint64
  853. var x118 uint64
  854. x118, x117 = bits.Mul64(x3, 0x399411b7c309a3d)
  855. var x119 uint64
  856. var x120 uint64
  857. x120, x119 = bits.Mul64(x3, 0xceec73d217f5be65)
  858. var x121 uint64
  859. var x122 uint64
  860. x122, x121 = bits.Mul64(x3, 0xd00e1ba768859347)
  861. var x123 uint64
  862. var x124 uint64
  863. x124, x123 = bits.Mul64(x3, 0xa40611e3449c0f01)
  864. var x125 uint64
  865. var x126 uint64
  866. x125, x126 = bits.Add64(x124, x121, uint64(0x0))
  867. var x127 uint64
  868. var x128 uint64
  869. x127, x128 = bits.Add64(x122, x119, uint64(fiatScalarUint1(x126)))
  870. var x129 uint64
  871. var x130 uint64
  872. x129, x130 = bits.Add64(x120, x117, uint64(fiatScalarUint1(x128)))
  873. var x131 uint64
  874. var x132 uint64
  875. x131, x132 = bits.Add64(x111, x123, uint64(0x0))
  876. var x133 uint64
  877. var x134 uint64
  878. x133, x134 = bits.Add64(x113, x125, uint64(fiatScalarUint1(x132)))
  879. var x135 uint64
  880. var x136 uint64
  881. x135, x136 = bits.Add64(x115, x127, uint64(fiatScalarUint1(x134)))
  882. var x137 uint64
  883. var x138 uint64
  884. x137, x138 = bits.Add64(((uint64(fiatScalarUint1(x116)) + (uint64(fiatScalarUint1(x98)) + (uint64(fiatScalarUint1(x90)) + x78))) + x102), x129, uint64(fiatScalarUint1(x136)))
  885. var x139 uint64
  886. _, x139 = bits.Mul64(x131, 0xd2b51da312547e1b)
  887. var x141 uint64
  888. var x142 uint64
  889. x142, x141 = bits.Mul64(x139, 0x1000000000000000)
  890. var x143 uint64
  891. var x144 uint64
  892. x144, x143 = bits.Mul64(x139, 0x14def9dea2f79cd6)
  893. var x145 uint64
  894. var x146 uint64
  895. x146, x145 = bits.Mul64(x139, 0x5812631a5cf5d3ed)
  896. var x147 uint64
  897. var x148 uint64
  898. x147, x148 = bits.Add64(x146, x143, uint64(0x0))
  899. var x150 uint64
  900. _, x150 = bits.Add64(x131, x145, uint64(0x0))
  901. var x151 uint64
  902. var x152 uint64
  903. x151, x152 = bits.Add64(x133, x147, uint64(fiatScalarUint1(x150)))
  904. var x153 uint64
  905. var x154 uint64
  906. x153, x154 = bits.Add64(x135, (uint64(fiatScalarUint1(x148)) + x144), uint64(fiatScalarUint1(x152)))
  907. var x155 uint64
  908. var x156 uint64
  909. x155, x156 = bits.Add64(x137, x141, uint64(fiatScalarUint1(x154)))
  910. x157 := ((uint64(fiatScalarUint1(x156)) + (uint64(fiatScalarUint1(x138)) + (uint64(fiatScalarUint1(x130)) + x118))) + x142)
  911. var x158 uint64
  912. var x159 uint64
  913. x158, x159 = bits.Sub64(x151, 0x5812631a5cf5d3ed, uint64(0x0))
  914. var x160 uint64
  915. var x161 uint64
  916. x160, x161 = bits.Sub64(x153, 0x14def9dea2f79cd6, uint64(fiatScalarUint1(x159)))
  917. var x162 uint64
  918. var x163 uint64
  919. x162, x163 = bits.Sub64(x155, uint64(0x0), uint64(fiatScalarUint1(x161)))
  920. var x164 uint64
  921. var x165 uint64
  922. x164, x165 = bits.Sub64(x157, 0x1000000000000000, uint64(fiatScalarUint1(x163)))
  923. var x167 uint64
  924. _, x167 = bits.Sub64(uint64(0x0), uint64(0x0), uint64(fiatScalarUint1(x165)))
  925. var x168 uint64
  926. fiatScalarCmovznzU64(&x168, fiatScalarUint1(x167), x158, x151)
  927. var x169 uint64
  928. fiatScalarCmovznzU64(&x169, fiatScalarUint1(x167), x160, x153)
  929. var x170 uint64
  930. fiatScalarCmovznzU64(&x170, fiatScalarUint1(x167), x162, x155)
  931. var x171 uint64
  932. fiatScalarCmovznzU64(&x171, fiatScalarUint1(x167), x164, x157)
  933. out1[0] = x168
  934. out1[1] = x169
  935. out1[2] = x170
  936. out1[3] = x171
  937. }
  938. // fiatScalarToBytes serializes a field element NOT in the Montgomery domain to bytes in little-endian order.
  939. //
  940. // Preconditions:
  941. //
  942. // 0 ≤ eval arg1 < m
  943. //
  944. // Postconditions:
  945. //
  946. // out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..31]
  947. //
  948. // Input Bounds:
  949. //
  950. // arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0x1fffffffffffffff]]
  951. //
  952. // Output Bounds:
  953. //
  954. // out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1f]]
  955. func fiatScalarToBytes(out1 *[32]uint8, arg1 *[4]uint64) {
  956. x1 := arg1[3]
  957. x2 := arg1[2]
  958. x3 := arg1[1]
  959. x4 := arg1[0]
  960. x5 := (uint8(x4) & 0xff)
  961. x6 := (x4 >> 8)
  962. x7 := (uint8(x6) & 0xff)
  963. x8 := (x6 >> 8)
  964. x9 := (uint8(x8) & 0xff)
  965. x10 := (x8 >> 8)
  966. x11 := (uint8(x10) & 0xff)
  967. x12 := (x10 >> 8)
  968. x13 := (uint8(x12) & 0xff)
  969. x14 := (x12 >> 8)
  970. x15 := (uint8(x14) & 0xff)
  971. x16 := (x14 >> 8)
  972. x17 := (uint8(x16) & 0xff)
  973. x18 := uint8((x16 >> 8))
  974. x19 := (uint8(x3) & 0xff)
  975. x20 := (x3 >> 8)
  976. x21 := (uint8(x20) & 0xff)
  977. x22 := (x20 >> 8)
  978. x23 := (uint8(x22) & 0xff)
  979. x24 := (x22 >> 8)
  980. x25 := (uint8(x24) & 0xff)
  981. x26 := (x24 >> 8)
  982. x27 := (uint8(x26) & 0xff)
  983. x28 := (x26 >> 8)
  984. x29 := (uint8(x28) & 0xff)
  985. x30 := (x28 >> 8)
  986. x31 := (uint8(x30) & 0xff)
  987. x32 := uint8((x30 >> 8))
  988. x33 := (uint8(x2) & 0xff)
  989. x34 := (x2 >> 8)
  990. x35 := (uint8(x34) & 0xff)
  991. x36 := (x34 >> 8)
  992. x37 := (uint8(x36) & 0xff)
  993. x38 := (x36 >> 8)
  994. x39 := (uint8(x38) & 0xff)
  995. x40 := (x38 >> 8)
  996. x41 := (uint8(x40) & 0xff)
  997. x42 := (x40 >> 8)
  998. x43 := (uint8(x42) & 0xff)
  999. x44 := (x42 >> 8)
  1000. x45 := (uint8(x44) & 0xff)
  1001. x46 := uint8((x44 >> 8))
  1002. x47 := (uint8(x1) & 0xff)
  1003. x48 := (x1 >> 8)
  1004. x49 := (uint8(x48) & 0xff)
  1005. x50 := (x48 >> 8)
  1006. x51 := (uint8(x50) & 0xff)
  1007. x52 := (x50 >> 8)
  1008. x53 := (uint8(x52) & 0xff)
  1009. x54 := (x52 >> 8)
  1010. x55 := (uint8(x54) & 0xff)
  1011. x56 := (x54 >> 8)
  1012. x57 := (uint8(x56) & 0xff)
  1013. x58 := (x56 >> 8)
  1014. x59 := (uint8(x58) & 0xff)
  1015. x60 := uint8((x58 >> 8))
  1016. out1[0] = x5
  1017. out1[1] = x7
  1018. out1[2] = x9
  1019. out1[3] = x11
  1020. out1[4] = x13
  1021. out1[5] = x15
  1022. out1[6] = x17
  1023. out1[7] = x18
  1024. out1[8] = x19
  1025. out1[9] = x21
  1026. out1[10] = x23
  1027. out1[11] = x25
  1028. out1[12] = x27
  1029. out1[13] = x29
  1030. out1[14] = x31
  1031. out1[15] = x32
  1032. out1[16] = x33
  1033. out1[17] = x35
  1034. out1[18] = x37
  1035. out1[19] = x39
  1036. out1[20] = x41
  1037. out1[21] = x43
  1038. out1[22] = x45
  1039. out1[23] = x46
  1040. out1[24] = x47
  1041. out1[25] = x49
  1042. out1[26] = x51
  1043. out1[27] = x53
  1044. out1[28] = x55
  1045. out1[29] = x57
  1046. out1[30] = x59
  1047. out1[31] = x60
  1048. }
  1049. // fiatScalarFromBytes deserializes a field element NOT in the Montgomery domain from bytes in little-endian order.
  1050. //
  1051. // Preconditions:
  1052. //
  1053. // 0 ≤ bytes_eval arg1 < m
  1054. //
  1055. // Postconditions:
  1056. //
  1057. // eval out1 mod m = bytes_eval arg1 mod m
  1058. // 0 ≤ eval out1 < m
  1059. //
  1060. // Input Bounds:
  1061. //
  1062. // arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1f]]
  1063. //
  1064. // Output Bounds:
  1065. //
  1066. // out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0x1fffffffffffffff]]
  1067. func fiatScalarFromBytes(out1 *[4]uint64, arg1 *[32]uint8) {
  1068. x1 := (uint64(arg1[31]) << 56)
  1069. x2 := (uint64(arg1[30]) << 48)
  1070. x3 := (uint64(arg1[29]) << 40)
  1071. x4 := (uint64(arg1[28]) << 32)
  1072. x5 := (uint64(arg1[27]) << 24)
  1073. x6 := (uint64(arg1[26]) << 16)
  1074. x7 := (uint64(arg1[25]) << 8)
  1075. x8 := arg1[24]
  1076. x9 := (uint64(arg1[23]) << 56)
  1077. x10 := (uint64(arg1[22]) << 48)
  1078. x11 := (uint64(arg1[21]) << 40)
  1079. x12 := (uint64(arg1[20]) << 32)
  1080. x13 := (uint64(arg1[19]) << 24)
  1081. x14 := (uint64(arg1[18]) << 16)
  1082. x15 := (uint64(arg1[17]) << 8)
  1083. x16 := arg1[16]
  1084. x17 := (uint64(arg1[15]) << 56)
  1085. x18 := (uint64(arg1[14]) << 48)
  1086. x19 := (uint64(arg1[13]) << 40)
  1087. x20 := (uint64(arg1[12]) << 32)
  1088. x21 := (uint64(arg1[11]) << 24)
  1089. x22 := (uint64(arg1[10]) << 16)
  1090. x23 := (uint64(arg1[9]) << 8)
  1091. x24 := arg1[8]
  1092. x25 := (uint64(arg1[7]) << 56)
  1093. x26 := (uint64(arg1[6]) << 48)
  1094. x27 := (uint64(arg1[5]) << 40)
  1095. x28 := (uint64(arg1[4]) << 32)
  1096. x29 := (uint64(arg1[3]) << 24)
  1097. x30 := (uint64(arg1[2]) << 16)
  1098. x31 := (uint64(arg1[1]) << 8)
  1099. x32 := arg1[0]
  1100. x33 := (x31 + uint64(x32))
  1101. x34 := (x30 + x33)
  1102. x35 := (x29 + x34)
  1103. x36 := (x28 + x35)
  1104. x37 := (x27 + x36)
  1105. x38 := (x26 + x37)
  1106. x39 := (x25 + x38)
  1107. x40 := (x23 + uint64(x24))
  1108. x41 := (x22 + x40)
  1109. x42 := (x21 + x41)
  1110. x43 := (x20 + x42)
  1111. x44 := (x19 + x43)
  1112. x45 := (x18 + x44)
  1113. x46 := (x17 + x45)
  1114. x47 := (x15 + uint64(x16))
  1115. x48 := (x14 + x47)
  1116. x49 := (x13 + x48)
  1117. x50 := (x12 + x49)
  1118. x51 := (x11 + x50)
  1119. x52 := (x10 + x51)
  1120. x53 := (x9 + x52)
  1121. x54 := (x7 + uint64(x8))
  1122. x55 := (x6 + x54)
  1123. x56 := (x5 + x55)
  1124. x57 := (x4 + x56)
  1125. x58 := (x3 + x57)
  1126. x59 := (x2 + x58)
  1127. x60 := (x1 + x59)
  1128. out1[0] = x39
  1129. out1[1] = x46
  1130. out1[2] = x53
  1131. out1[3] = x60
  1132. }