ring-native 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +22 -0
  5. data/Rakefile +1 -0
  6. data/ext/ring/extconf.rb +29 -0
  7. data/lib/ring/native.rb +8 -0
  8. data/lib/ring/native/version.rb +5 -0
  9. data/ring-native.gemspec +25 -0
  10. data/vendor/ring/BUILDING.md +40 -0
  11. data/vendor/ring/Cargo.toml +43 -0
  12. data/vendor/ring/LICENSE +185 -0
  13. data/vendor/ring/Makefile +35 -0
  14. data/vendor/ring/PORTING.md +163 -0
  15. data/vendor/ring/README.md +113 -0
  16. data/vendor/ring/STYLE.md +197 -0
  17. data/vendor/ring/appveyor.yml +27 -0
  18. data/vendor/ring/build.rs +108 -0
  19. data/vendor/ring/crypto/aes/aes.c +1142 -0
  20. data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +25 -0
  21. data/vendor/ring/crypto/aes/aes_test.cc +93 -0
  22. data/vendor/ring/crypto/aes/asm/aes-586.pl +2368 -0
  23. data/vendor/ring/crypto/aes/asm/aes-armv4.pl +1249 -0
  24. data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +2246 -0
  25. data/vendor/ring/crypto/aes/asm/aesni-x86.pl +1318 -0
  26. data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +2084 -0
  27. data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +675 -0
  28. data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +1364 -0
  29. data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +1565 -0
  30. data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +841 -0
  31. data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +1116 -0
  32. data/vendor/ring/crypto/aes/internal.h +87 -0
  33. data/vendor/ring/crypto/aes/mode_wrappers.c +61 -0
  34. data/vendor/ring/crypto/bn/add.c +394 -0
  35. data/vendor/ring/crypto/bn/asm/armv4-mont.pl +694 -0
  36. data/vendor/ring/crypto/bn/asm/armv8-mont.pl +1503 -0
  37. data/vendor/ring/crypto/bn/asm/bn-586.pl +774 -0
  38. data/vendor/ring/crypto/bn/asm/co-586.pl +287 -0
  39. data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +1882 -0
  40. data/vendor/ring/crypto/bn/asm/x86-mont.pl +592 -0
  41. data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +599 -0
  42. data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +1393 -0
  43. data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +3507 -0
  44. data/vendor/ring/crypto/bn/bn.c +352 -0
  45. data/vendor/ring/crypto/bn/bn_asn1.c +74 -0
  46. data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +25 -0
  47. data/vendor/ring/crypto/bn/bn_test.cc +1696 -0
  48. data/vendor/ring/crypto/bn/cmp.c +200 -0
  49. data/vendor/ring/crypto/bn/convert.c +433 -0
  50. data/vendor/ring/crypto/bn/ctx.c +311 -0
  51. data/vendor/ring/crypto/bn/div.c +594 -0
  52. data/vendor/ring/crypto/bn/exponentiation.c +1335 -0
  53. data/vendor/ring/crypto/bn/gcd.c +711 -0
  54. data/vendor/ring/crypto/bn/generic.c +1019 -0
  55. data/vendor/ring/crypto/bn/internal.h +316 -0
  56. data/vendor/ring/crypto/bn/montgomery.c +516 -0
  57. data/vendor/ring/crypto/bn/mul.c +888 -0
  58. data/vendor/ring/crypto/bn/prime.c +829 -0
  59. data/vendor/ring/crypto/bn/random.c +334 -0
  60. data/vendor/ring/crypto/bn/rsaz_exp.c +262 -0
  61. data/vendor/ring/crypto/bn/rsaz_exp.h +53 -0
  62. data/vendor/ring/crypto/bn/shift.c +276 -0
  63. data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +25 -0
  64. data/vendor/ring/crypto/bytestring/bytestring_test.cc +421 -0
  65. data/vendor/ring/crypto/bytestring/cbb.c +399 -0
  66. data/vendor/ring/crypto/bytestring/cbs.c +227 -0
  67. data/vendor/ring/crypto/bytestring/internal.h +46 -0
  68. data/vendor/ring/crypto/chacha/chacha_generic.c +140 -0
  69. data/vendor/ring/crypto/chacha/chacha_vec.c +323 -0
  70. data/vendor/ring/crypto/chacha/chacha_vec_arm.S +1447 -0
  71. data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +153 -0
  72. data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +25 -0
  73. data/vendor/ring/crypto/cipher/e_aes.c +390 -0
  74. data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +208 -0
  75. data/vendor/ring/crypto/cipher/internal.h +173 -0
  76. data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +543 -0
  77. data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +9 -0
  78. data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +475 -0
  79. data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +23 -0
  80. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +422 -0
  81. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +484 -0
  82. data/vendor/ring/crypto/cipher/test/cipher_test.txt +100 -0
  83. data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +25 -0
  84. data/vendor/ring/crypto/constant_time_test.c +304 -0
  85. data/vendor/ring/crypto/cpu-arm-asm.S +32 -0
  86. data/vendor/ring/crypto/cpu-arm.c +199 -0
  87. data/vendor/ring/crypto/cpu-intel.c +261 -0
  88. data/vendor/ring/crypto/crypto.c +151 -0
  89. data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +2118 -0
  90. data/vendor/ring/crypto/curve25519/curve25519.c +4888 -0
  91. data/vendor/ring/crypto/curve25519/x25519_test.cc +128 -0
  92. data/vendor/ring/crypto/digest/md32_common.h +181 -0
  93. data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +2725 -0
  94. data/vendor/ring/crypto/ec/ec.c +193 -0
  95. data/vendor/ring/crypto/ec/ec_curves.c +61 -0
  96. data/vendor/ring/crypto/ec/ec_key.c +228 -0
  97. data/vendor/ring/crypto/ec/ec_montgomery.c +114 -0
  98. data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +25 -0
  99. data/vendor/ring/crypto/ec/internal.h +243 -0
  100. data/vendor/ring/crypto/ec/oct.c +253 -0
  101. data/vendor/ring/crypto/ec/p256-64.c +1794 -0
  102. data/vendor/ring/crypto/ec/p256-x86_64-table.h +9548 -0
  103. data/vendor/ring/crypto/ec/p256-x86_64.c +509 -0
  104. data/vendor/ring/crypto/ec/simple.c +1007 -0
  105. data/vendor/ring/crypto/ec/util-64.c +183 -0
  106. data/vendor/ring/crypto/ec/wnaf.c +508 -0
  107. data/vendor/ring/crypto/ecdh/ecdh.c +155 -0
  108. data/vendor/ring/crypto/ecdsa/ecdsa.c +304 -0
  109. data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +193 -0
  110. data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +25 -0
  111. data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +327 -0
  112. data/vendor/ring/crypto/header_removed.h +17 -0
  113. data/vendor/ring/crypto/internal.h +495 -0
  114. data/vendor/ring/crypto/libring.Windows.vcxproj +101 -0
  115. data/vendor/ring/crypto/mem.c +98 -0
  116. data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +1045 -0
  117. data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +517 -0
  118. data/vendor/ring/crypto/modes/asm/ghash-x86.pl +1393 -0
  119. data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +1741 -0
  120. data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +422 -0
  121. data/vendor/ring/crypto/modes/ctr.c +226 -0
  122. data/vendor/ring/crypto/modes/gcm.c +1206 -0
  123. data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +25 -0
  124. data/vendor/ring/crypto/modes/gcm_test.c +348 -0
  125. data/vendor/ring/crypto/modes/internal.h +299 -0
  126. data/vendor/ring/crypto/perlasm/arm-xlate.pl +170 -0
  127. data/vendor/ring/crypto/perlasm/readme +100 -0
  128. data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +1164 -0
  129. data/vendor/ring/crypto/perlasm/x86asm.pl +292 -0
  130. data/vendor/ring/crypto/perlasm/x86gas.pl +263 -0
  131. data/vendor/ring/crypto/perlasm/x86masm.pl +200 -0
  132. data/vendor/ring/crypto/perlasm/x86nasm.pl +187 -0
  133. data/vendor/ring/crypto/poly1305/poly1305.c +331 -0
  134. data/vendor/ring/crypto/poly1305/poly1305_arm.c +301 -0
  135. data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +2015 -0
  136. data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +25 -0
  137. data/vendor/ring/crypto/poly1305/poly1305_test.cc +80 -0
  138. data/vendor/ring/crypto/poly1305/poly1305_test.txt +52 -0
  139. data/vendor/ring/crypto/poly1305/poly1305_vec.c +892 -0
  140. data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +75 -0
  141. data/vendor/ring/crypto/rand/internal.h +32 -0
  142. data/vendor/ring/crypto/rand/rand.c +189 -0
  143. data/vendor/ring/crypto/rand/urandom.c +219 -0
  144. data/vendor/ring/crypto/rand/windows.c +56 -0
  145. data/vendor/ring/crypto/refcount_c11.c +66 -0
  146. data/vendor/ring/crypto/refcount_lock.c +53 -0
  147. data/vendor/ring/crypto/refcount_test.Windows.vcxproj +25 -0
  148. data/vendor/ring/crypto/refcount_test.c +58 -0
  149. data/vendor/ring/crypto/rsa/blinding.c +462 -0
  150. data/vendor/ring/crypto/rsa/internal.h +108 -0
  151. data/vendor/ring/crypto/rsa/padding.c +300 -0
  152. data/vendor/ring/crypto/rsa/rsa.c +450 -0
  153. data/vendor/ring/crypto/rsa/rsa_asn1.c +261 -0
  154. data/vendor/ring/crypto/rsa/rsa_impl.c +944 -0
  155. data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +25 -0
  156. data/vendor/ring/crypto/rsa/rsa_test.cc +437 -0
  157. data/vendor/ring/crypto/sha/asm/sha-armv8.pl +436 -0
  158. data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +2390 -0
  159. data/vendor/ring/crypto/sha/asm/sha256-586.pl +1275 -0
  160. data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +735 -0
  161. data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +14 -0
  162. data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +14 -0
  163. data/vendor/ring/crypto/sha/asm/sha512-586.pl +911 -0
  164. data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +666 -0
  165. data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +14 -0
  166. data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +14 -0
  167. data/vendor/ring/crypto/sha/sha1.c +271 -0
  168. data/vendor/ring/crypto/sha/sha256.c +204 -0
  169. data/vendor/ring/crypto/sha/sha512.c +355 -0
  170. data/vendor/ring/crypto/test/file_test.cc +326 -0
  171. data/vendor/ring/crypto/test/file_test.h +181 -0
  172. data/vendor/ring/crypto/test/malloc.cc +150 -0
  173. data/vendor/ring/crypto/test/scoped_types.h +95 -0
  174. data/vendor/ring/crypto/test/test.Windows.vcxproj +35 -0
  175. data/vendor/ring/crypto/test/test_util.cc +46 -0
  176. data/vendor/ring/crypto/test/test_util.h +41 -0
  177. data/vendor/ring/crypto/thread_none.c +55 -0
  178. data/vendor/ring/crypto/thread_pthread.c +165 -0
  179. data/vendor/ring/crypto/thread_test.Windows.vcxproj +25 -0
  180. data/vendor/ring/crypto/thread_test.c +200 -0
  181. data/vendor/ring/crypto/thread_win.c +282 -0
  182. data/vendor/ring/examples/checkdigest.rs +103 -0
  183. data/vendor/ring/include/openssl/aes.h +121 -0
  184. data/vendor/ring/include/openssl/arm_arch.h +129 -0
  185. data/vendor/ring/include/openssl/base.h +156 -0
  186. data/vendor/ring/include/openssl/bn.h +794 -0
  187. data/vendor/ring/include/openssl/buffer.h +18 -0
  188. data/vendor/ring/include/openssl/bytestring.h +235 -0
  189. data/vendor/ring/include/openssl/chacha.h +37 -0
  190. data/vendor/ring/include/openssl/cmac.h +76 -0
  191. data/vendor/ring/include/openssl/cpu.h +184 -0
  192. data/vendor/ring/include/openssl/crypto.h +43 -0
  193. data/vendor/ring/include/openssl/curve25519.h +88 -0
  194. data/vendor/ring/include/openssl/ec.h +225 -0
  195. data/vendor/ring/include/openssl/ec_key.h +129 -0
  196. data/vendor/ring/include/openssl/ecdh.h +110 -0
  197. data/vendor/ring/include/openssl/ecdsa.h +156 -0
  198. data/vendor/ring/include/openssl/err.h +201 -0
  199. data/vendor/ring/include/openssl/mem.h +101 -0
  200. data/vendor/ring/include/openssl/obj_mac.h +71 -0
  201. data/vendor/ring/include/openssl/opensslfeatures.h +68 -0
  202. data/vendor/ring/include/openssl/opensslv.h +18 -0
  203. data/vendor/ring/include/openssl/ossl_typ.h +18 -0
  204. data/vendor/ring/include/openssl/poly1305.h +51 -0
  205. data/vendor/ring/include/openssl/rand.h +70 -0
  206. data/vendor/ring/include/openssl/rsa.h +399 -0
  207. data/vendor/ring/include/openssl/thread.h +133 -0
  208. data/vendor/ring/include/openssl/type_check.h +71 -0
  209. data/vendor/ring/mk/Common.props +63 -0
  210. data/vendor/ring/mk/Windows.props +42 -0
  211. data/vendor/ring/mk/WindowsTest.props +18 -0
  212. data/vendor/ring/mk/appveyor.bat +62 -0
  213. data/vendor/ring/mk/bottom_of_makefile.mk +54 -0
  214. data/vendor/ring/mk/ring.mk +266 -0
  215. data/vendor/ring/mk/top_of_makefile.mk +214 -0
  216. data/vendor/ring/mk/travis.sh +40 -0
  217. data/vendor/ring/mk/update-travis-yml.py +229 -0
  218. data/vendor/ring/ring.sln +153 -0
  219. data/vendor/ring/src/aead.rs +682 -0
  220. data/vendor/ring/src/agreement.rs +248 -0
  221. data/vendor/ring/src/c.rs +129 -0
  222. data/vendor/ring/src/constant_time.rs +37 -0
  223. data/vendor/ring/src/der.rs +96 -0
  224. data/vendor/ring/src/digest.rs +690 -0
  225. data/vendor/ring/src/digest_tests.txt +57 -0
  226. data/vendor/ring/src/ecc.rs +28 -0
  227. data/vendor/ring/src/ecc_build.rs +279 -0
  228. data/vendor/ring/src/ecc_curves.rs +117 -0
  229. data/vendor/ring/src/ed25519_tests.txt +2579 -0
  230. data/vendor/ring/src/exe_tests.rs +46 -0
  231. data/vendor/ring/src/ffi.rs +29 -0
  232. data/vendor/ring/src/file_test.rs +187 -0
  233. data/vendor/ring/src/hkdf.rs +153 -0
  234. data/vendor/ring/src/hkdf_tests.txt +59 -0
  235. data/vendor/ring/src/hmac.rs +414 -0
  236. data/vendor/ring/src/hmac_tests.txt +97 -0
  237. data/vendor/ring/src/input.rs +312 -0
  238. data/vendor/ring/src/lib.rs +41 -0
  239. data/vendor/ring/src/pbkdf2.rs +265 -0
  240. data/vendor/ring/src/pbkdf2_tests.txt +113 -0
  241. data/vendor/ring/src/polyfill.rs +57 -0
  242. data/vendor/ring/src/rand.rs +28 -0
  243. data/vendor/ring/src/signature.rs +314 -0
  244. data/vendor/ring/third-party/NIST/README.md +9 -0
  245. data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +263 -0
  246. data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +309 -0
  247. data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +267 -0
  248. data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +263 -0
  249. data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +309 -0
  250. data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +267 -0
  251. data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +263 -0
  252. data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +309 -0
  253. data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +267 -0
  254. data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +519 -0
  255. data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +309 -0
  256. data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +523 -0
  257. data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +519 -0
  258. data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +309 -0
  259. data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +523 -0
  260. data/vendor/ring/third-party/NIST/sha256sums.txt +1 -0
  261. metadata +333 -0
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env perl
2
+
3
+ package x86masm;
4
+
5
+ *out=\@::out;
6
+
7
+ $::lbdecor="\$L"; # local label decoration
8
+ $nmdecor="_"; # external name decoration
9
+
10
+ $initseg="";
11
+ $segment="";
12
+
13
+ sub ::generic
14
+ { my ($opcode,@arg)=@_;
15
+
16
+ # fix hexadecimal constants
17
+ for (@arg) { s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/oi; }
18
+
19
+ if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no []
20
+ { $opcode="mov"; }
21
+ elsif ($opcode !~ /mov[dq]$/)
22
+ { # fix xmm references
23
+ $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[-1]=~/\bxmm[0-7]\b/i);
24
+ $arg[-1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
25
+ }
26
+
27
+ &::emit($opcode,@arg);
28
+ 1;
29
+ }
30
+ #
31
+ # opcodes not covered by ::generic above, mostly inconsistent namings...
32
+ #
33
+ sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
34
+ sub ::call_ptr { &::emit("call",@_); }
35
+ sub ::jmp_ptr { &::emit("jmp",@_); }
36
+ sub ::lock { &::data_byte(0xf0); }
37
+
38
+ sub get_mem
39
+ { my($size,$addr,$reg1,$reg2,$idx)=@_;
40
+ my($post,$ret);
41
+
42
+ if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
43
+
44
+ $ret .= "$size PTR " if ($size ne "");
45
+
46
+ $addr =~ s/^\s+//;
47
+ # prepend global references with optional underscore
48
+ $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
49
+ # put address arithmetic expression in parenthesis
50
+ $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
51
+
52
+ if (($addr ne "") && ($addr ne 0))
53
+ { if ($addr !~ /^-/) { $ret .= "$addr"; }
54
+ else { $post=$addr; }
55
+ }
56
+ $ret .= "[";
57
+
58
+ if ($reg2 ne "")
59
+ { $idx!=0 or $idx=1;
60
+ $ret .= "$reg2*$idx";
61
+ $ret .= "+$reg1" if ($reg1 ne "");
62
+ }
63
+ else
64
+ { $ret .= "$reg1"; }
65
+
66
+ $ret .= "$post]";
67
+ $ret =~ s/\+\]/]/; # in case $addr was the only argument
68
+ $ret =~ s/\[\s*\]//;
69
+
70
+ $ret;
71
+ }
72
+ sub ::BP { &get_mem("BYTE",@_); }
73
+ sub ::WP { &get_mem("WORD",@_); }
74
+ sub ::DWP { &get_mem("DWORD",@_); }
75
+ sub ::QWP { &get_mem("QWORD",@_); }
76
+ sub ::BC { "@_"; }
77
+ sub ::DWC { "@_"; }
78
+
79
+ sub ::file
80
+ { my $tmp=<<___;
81
+ TITLE $_[0].asm
82
+ IF \@Version LT 800
83
+ ECHO MASM version 8.00 or later is strongly recommended.
84
+ ENDIF
85
+ .686
86
+ .MODEL FLAT
87
+ OPTION DOTNAME
88
+ IF \@Version LT 800
89
+ .text\$ SEGMENT PAGE 'CODE'
90
+ ELSE
91
+ .text\$ SEGMENT ALIGN(64) 'CODE'
92
+ ENDIF
93
+ ___
94
+ push(@out,$tmp);
95
+ $segment = ".text\$";
96
+ }
97
+
98
+ sub ::function_begin_B
99
+ { my $func=shift;
100
+ my $global=($func !~ /^_/);
101
+ my $begin="${::lbdecor}_${func}_begin";
102
+
103
+ &::LABEL($func,$global?"$begin":"$nmdecor$func");
104
+ $func="ALIGN\t16\n".$nmdecor.$func."\tPROC";
105
+
106
+ if ($global) { $func.=" PUBLIC\n${begin}::\n"; }
107
+ else { $func.=" PRIVATE\n"; }
108
+ push(@out,$func);
109
+ $::stack=4;
110
+ }
111
+ sub ::function_end_B
112
+ { my $func=shift;
113
+
114
+ push(@out,"$nmdecor$func ENDP\n");
115
+ $::stack=0;
116
+ &::wipe_labels();
117
+ }
118
+
119
+ sub ::file_end
120
+ { my $xmmheader=<<___;
121
+ .686
122
+ .XMM
123
+ IF \@Version LT 800
124
+ XMMWORD STRUCT 16
125
+ DQ 2 dup (?)
126
+ XMMWORD ENDS
127
+ ENDIF
128
+ ___
129
+ if (grep {/\b[x]?mm[0-7]\b/i} @out) {
130
+ grep {s/\.[3-7]86/$xmmheader/} @out;
131
+ }
132
+
133
+ push(@out,"$segment ENDS\n");
134
+
135
+ if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
136
+ { my $comm=<<___;
137
+ .bss SEGMENT 'BSS'
138
+ COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD:4
139
+ .bss ENDS
140
+ ___
141
+ # comment out OPENSSL_ia32cap_P declarations
142
+ grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
143
+ push (@out,$comm);
144
+ }
145
+ push (@out,$initseg) if ($initseg);
146
+ push (@out,"END\n");
147
+ }
148
+
149
+ sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
150
+
151
+ *::set_label_B = sub
152
+ { my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); };
153
+
154
+ sub ::external_label
155
+ { foreach(@_)
156
+ { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); }
157
+ }
158
+
159
+ sub ::public_label
160
+ { push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
161
+
162
+ sub ::data_byte
163
+ { push(@out,("DB\t").join(',',splice(@_,0,16))."\n") while(@_); }
164
+
165
+ sub ::data_short
166
+ { push(@out,("DW\t").join(',',splice(@_,0,8))."\n") while(@_); }
167
+
168
+ sub ::data_word
169
+ { push(@out,("DD\t").join(',',splice(@_,0,4))."\n") while(@_); }
170
+
171
+ sub ::align
172
+ { push(@out,"ALIGN\t$_[0]\n"); }
173
+
174
+ sub ::picmeup
175
+ { my($dst,$sym)=@_;
176
+ &::lea($dst,&::DWP($sym));
177
+ }
178
+
179
+ sub ::initseg
180
+ { my $f=$nmdecor.shift;
181
+
182
+ $initseg.=<<___;
183
+ .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'
184
+ EXTERN $f:NEAR
185
+ DD $f
186
+ .CRT\$XCU ENDS
187
+ ___
188
+ }
189
+
190
+ sub ::dataseg
191
+ { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; }
192
+
193
+ sub ::safeseh
194
+ { my $nm=shift;
195
+ push(@out,"IF \@Version GE 710\n");
196
+ push(@out,".SAFESEH ".&::LABEL($nm,$nmdecor.$nm)."\n");
197
+ push(@out,"ENDIF\n");
198
+ }
199
+
200
+ 1;
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env perl
2
+
3
+ package x86nasm;
4
+
5
+ *out=\@::out;
6
+
7
+ $::lbdecor="L\$"; # local label decoration
8
+ $nmdecor=$::netware?"":"_"; # external name decoration
9
+ $drdecor=$::mwerks?".":""; # directive decoration
10
+
11
+ $initseg="";
12
+
13
+ sub ::generic
14
+ { my $opcode=shift;
15
+ my $tmp;
16
+
17
+ if (!$::mwerks)
18
+ { if ($opcode =~ m/^j/o && $#_==0) # optimize jumps
19
+ { $_[0] = "NEAR $_[0]"; }
20
+ elsif ($opcode eq "lea" && $#_==1) # wipe storage qualifier from lea
21
+ { $_[1] =~ s/^[^\[]*\[/\[/o; }
22
+ elsif ($opcode eq "clflush" && $#_==0)
23
+ { $_[0] =~ s/^[^\[]*\[/\[/o; }
24
+ }
25
+ &::emit($opcode,@_);
26
+ 1;
27
+ }
28
+ #
29
+ # opcodes not covered by ::generic above, mostly inconsistent namings...
30
+ #
31
+ sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
32
+ sub ::call_ptr { &::emit("call",@_); }
33
+ sub ::jmp_ptr { &::emit("jmp",@_); }
34
+
35
+ sub get_mem
36
+ { my($size,$addr,$reg1,$reg2,$idx)=@_;
37
+ my($post,$ret);
38
+
39
+ if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
40
+
41
+ if ($size ne "")
42
+ { $ret .= "$size";
43
+ $ret .= " PTR" if ($::mwerks);
44
+ $ret .= " ";
45
+ }
46
+ $ret .= "[";
47
+
48
+ $addr =~ s/^\s+//;
49
+ # prepend global references with optional underscore
50
+ $addr =~ s/^([^\+\-0-9][^\+\-]*)/::islabel($1) or "$nmdecor$1"/ige;
51
+ # put address arithmetic expression in parenthesis
52
+ $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
53
+
54
+ if (($addr ne "") && ($addr ne 0))
55
+ { if ($addr !~ /^-/) { $ret .= "$addr+"; }
56
+ else { $post=$addr; }
57
+ }
58
+
59
+ if ($reg2 ne "")
60
+ { $idx!=0 or $idx=1;
61
+ $ret .= "$reg2*$idx";
62
+ $ret .= "+$reg1" if ($reg1 ne "");
63
+ }
64
+ else
65
+ { $ret .= "$reg1"; }
66
+
67
+ $ret .= "$post]";
68
+ $ret =~ s/\+\]/]/; # in case $addr was the only argument
69
+
70
+ $ret;
71
+ }
72
+ sub ::BP { &get_mem("BYTE",@_); }
73
+ sub ::DWP { &get_mem("DWORD",@_); }
74
+ sub ::WP { &get_mem("WORD",@_); }
75
+ sub ::QWP { &get_mem("",@_); }
76
+ sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; }
77
+ sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; }
78
+
79
+ sub ::file
80
+ { if ($::mwerks) { push(@out,".section\t.text,64\n"); }
81
+ else
82
+ { my $tmp=<<___;
83
+ %ifidn __OUTPUT_FORMAT__,obj
84
+ section code use32 class=code align=64
85
+ %elifidn __OUTPUT_FORMAT__,win32
86
+ %ifdef __YASM_VERSION_ID__
87
+ %if __YASM_VERSION_ID__ < 01010000h
88
+ %error yasm version 1.1.0 or later needed.
89
+ %endif
90
+ ; Yasm automatically includes @feat.00 and complains about redefining it.
91
+ ; https://www.tortall.net/projects/yasm/manual/html/objfmt-win32-safeseh.html
92
+ %else
93
+ \$\@feat.00 equ 1
94
+ %endif
95
+ section .text code align=64
96
+ %else
97
+ section .text code
98
+ %endif
99
+ ___
100
+ push(@out,$tmp);
101
+ }
102
+ }
103
+
104
+ sub ::function_begin_B
105
+ { my $func=shift;
106
+ my $global=($func !~ /^_/);
107
+ my $begin="${::lbdecor}_${func}_begin";
108
+
109
+ $begin =~ s/^\@/./ if ($::mwerks); # the torture never stops
110
+
111
+ &::LABEL($func,$global?"$begin":"$nmdecor$func");
112
+ $func=$nmdecor.$func;
113
+
114
+ push(@out,"${drdecor}global $func\n") if ($global);
115
+ push(@out,"${drdecor}align 16\n");
116
+ push(@out,"$func:\n");
117
+ push(@out,"$begin:\n") if ($global);
118
+ $::stack=4;
119
+ }
120
+
121
+ sub ::function_end_B
122
+ { $::stack=0;
123
+ &::wipe_labels();
124
+ }
125
+
126
+ sub ::file_end
127
+ { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
128
+ { my $comm=<<___;
129
+ ${drdecor}segment .bss
130
+ ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 16
131
+ ___
132
+ # comment out OPENSSL_ia32cap_P declarations
133
+ grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
134
+ push (@out,$comm)
135
+ }
136
+ push (@out,$initseg) if ($initseg);
137
+ }
138
+
139
+ sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
140
+
141
+ sub ::external_label
142
+ { foreach(@_)
143
+ { push(@out,"${drdecor}extern\t".&::LABEL($_,$nmdecor.$_)."\n"); }
144
+ }
145
+
146
+ sub ::public_label
147
+ { push(@out,"${drdecor}global\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
148
+
149
+ sub ::data_byte
150
+ { push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); }
151
+ sub ::data_short
152
+ { push(@out,(($::mwerks)?".word\t":"dw\t").join(',',@_)."\n"); }
153
+ sub ::data_word
154
+ { push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); }
155
+
156
+ sub ::align
157
+ { push(@out,"${drdecor}align\t$_[0]\n"); }
158
+
159
+ sub ::picmeup
160
+ { my($dst,$sym)=@_;
161
+ &::lea($dst,&::DWP($sym));
162
+ }
163
+
164
+ sub ::initseg
165
+ { my $f=$nmdecor.shift;
166
+ if ($::win32)
167
+ { $initseg=<<___;
168
+ segment .CRT\$XCU data align=4
169
+ extern $f
170
+ dd $f
171
+ ___
172
+ }
173
+ }
174
+
175
+ sub ::dataseg
176
+ { if ($mwerks) { push(@out,".section\t.data,4\n"); }
177
+ else { push(@out,"section\t.data align=4\n"); }
178
+ }
179
+
180
+ sub ::safeseh
181
+ { my $nm=shift;
182
+ push(@out,"%if __NASM_VERSION_ID__ >= 0x02030000\n");
183
+ push(@out,"safeseh ".&::LABEL($nm,$nmdecor.$nm)."\n");
184
+ push(@out,"%endif\n");
185
+ }
186
+
187
+ 1;
@@ -0,0 +1,331 @@
1
+ /* Copyright (c) 2014, Google Inc.
2
+ *
3
+ * Permission to use, copy, modify, and/or distribute this software for any
4
+ * purpose with or without fee is hereby granted, provided that the above
5
+ * copyright notice and this permission notice appear in all copies.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
+
15
+ /* This implementation of poly1305 is by Andrew Moon
16
+ * (https://github.com/floodyberry/poly1305-donna) and released as public
17
+ * domain. */
18
+
19
+ #include <openssl/poly1305.h>
20
+
21
+ #include <string.h>
22
+
23
+ #include <openssl/cpu.h>
24
+
25
+
26
+ #if defined(OPENSSL_WINDOWS) || !defined(OPENSSL_X86_64)
27
+
28
+ #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || defined(OPENSSL_ARM)
29
+ /* We can assume little-endian. */
30
+ static uint32_t U8TO32_LE(const uint8_t *m) {
31
+ uint32_t r;
32
+ memcpy(&r, m, sizeof(r));
33
+ return r;
34
+ }
35
+
36
+ static void U32TO8_LE(uint8_t *m, uint32_t v) { memcpy(m, &v, sizeof(v)); }
37
+ #else
38
+ static uint32_t U8TO32_LE(const uint8_t *m) {
39
+ return (uint32_t)m[0] | (uint32_t)m[1] << 8 | (uint32_t)m[2] << 16 |
40
+ (uint32_t)m[3] << 24;
41
+ }
42
+
43
+ static void U32TO8_LE(uint8_t *m, uint32_t v) {
44
+ m[0] = v;
45
+ m[1] = v >> 8;
46
+ m[2] = v >> 16;
47
+ m[3] = v >> 24;
48
+ }
49
+ #endif
50
+
51
+ #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
52
+ void CRYPTO_poly1305_init_neon(poly1305_state *state, const uint8_t key[32]);
53
+
54
+ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
55
+ size_t in_len);
56
+
57
+ void CRYPTO_poly1305_finish_neon(poly1305_state *state, uint8_t mac[16]);
58
+ #endif
59
+
60
+ static uint64_t mul32x32_64(uint32_t a, uint32_t b) { return (uint64_t)a * b; }
61
+
62
+ struct poly1305_state_st {
63
+ uint32_t r0, r1, r2, r3, r4;
64
+ uint32_t s1, s2, s3, s4;
65
+ uint32_t h0, h1, h2, h3, h4;
66
+ uint8_t buf[16];
67
+ unsigned int buf_used;
68
+ uint8_t key[16];
69
+ };
70
+
71
+ /* poly1305_blocks updates |state| given some amount of input data. This
72
+ * function may only be called with a |len| that is not a multiple of 16 at the
73
+ * end of the data. Otherwise the input must be buffered into 16 byte blocks. */
74
+ static void poly1305_update(struct poly1305_state_st *state, const uint8_t *in,
75
+ size_t len) {
76
+ uint32_t t0, t1, t2, t3;
77
+ uint64_t t[5];
78
+ uint32_t b;
79
+ uint64_t c;
80
+ size_t j;
81
+ uint8_t mp[16];
82
+
83
+ if (len < 16) {
84
+ goto poly1305_donna_atmost15bytes;
85
+ }
86
+
87
+ poly1305_donna_16bytes:
88
+ t0 = U8TO32_LE(in);
89
+ t1 = U8TO32_LE(in + 4);
90
+ t2 = U8TO32_LE(in + 8);
91
+ t3 = U8TO32_LE(in + 12);
92
+
93
+ in += 16;
94
+ len -= 16;
95
+
96
+ state->h0 += t0 & 0x3ffffff;
97
+ state->h1 += ((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff;
98
+ state->h2 += ((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff;
99
+ state->h3 += ((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff;
100
+ state->h4 += (t3 >> 8) | (1 << 24);
101
+
102
+ poly1305_donna_mul:
103
+ t[0] = mul32x32_64(state->h0, state->r0) + mul32x32_64(state->h1, state->s4) +
104
+ mul32x32_64(state->h2, state->s3) + mul32x32_64(state->h3, state->s2) +
105
+ mul32x32_64(state->h4, state->s1);
106
+ t[1] = mul32x32_64(state->h0, state->r1) + mul32x32_64(state->h1, state->r0) +
107
+ mul32x32_64(state->h2, state->s4) + mul32x32_64(state->h3, state->s3) +
108
+ mul32x32_64(state->h4, state->s2);
109
+ t[2] = mul32x32_64(state->h0, state->r2) + mul32x32_64(state->h1, state->r1) +
110
+ mul32x32_64(state->h2, state->r0) + mul32x32_64(state->h3, state->s4) +
111
+ mul32x32_64(state->h4, state->s3);
112
+ t[3] = mul32x32_64(state->h0, state->r3) + mul32x32_64(state->h1, state->r2) +
113
+ mul32x32_64(state->h2, state->r1) + mul32x32_64(state->h3, state->r0) +
114
+ mul32x32_64(state->h4, state->s4);
115
+ t[4] = mul32x32_64(state->h0, state->r4) + mul32x32_64(state->h1, state->r3) +
116
+ mul32x32_64(state->h2, state->r2) + mul32x32_64(state->h3, state->r1) +
117
+ mul32x32_64(state->h4, state->r0);
118
+
119
+ state->h0 = (uint32_t)t[0] & 0x3ffffff;
120
+ c = (t[0] >> 26);
121
+ t[1] += c;
122
+ state->h1 = (uint32_t)t[1] & 0x3ffffff;
123
+ b = (uint32_t)(t[1] >> 26);
124
+ t[2] += b;
125
+ state->h2 = (uint32_t)t[2] & 0x3ffffff;
126
+ b = (uint32_t)(t[2] >> 26);
127
+ t[3] += b;
128
+ state->h3 = (uint32_t)t[3] & 0x3ffffff;
129
+ b = (uint32_t)(t[3] >> 26);
130
+ t[4] += b;
131
+ state->h4 = (uint32_t)t[4] & 0x3ffffff;
132
+ b = (uint32_t)(t[4] >> 26);
133
+ state->h0 += b * 5;
134
+
135
+ if (len >= 16) {
136
+ goto poly1305_donna_16bytes;
137
+ }
138
+
139
+ /* final bytes */
140
+ poly1305_donna_atmost15bytes:
141
+ if (!len) {
142
+ return;
143
+ }
144
+
145
+ for (j = 0; j < len; j++) {
146
+ mp[j] = in[j];
147
+ }
148
+ mp[j++] = 1;
149
+ for (; j < 16; j++) {
150
+ mp[j] = 0;
151
+ }
152
+ len = 0;
153
+
154
+ t0 = U8TO32_LE(mp + 0);
155
+ t1 = U8TO32_LE(mp + 4);
156
+ t2 = U8TO32_LE(mp + 8);
157
+ t3 = U8TO32_LE(mp + 12);
158
+
159
+ state->h0 += t0 & 0x3ffffff;
160
+ state->h1 += ((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff;
161
+ state->h2 += ((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff;
162
+ state->h3 += ((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff;
163
+ state->h4 += (t3 >> 8);
164
+
165
+ goto poly1305_donna_mul;
166
+ }
167
+
168
+ void CRYPTO_poly1305_init(poly1305_state *statep, const uint8_t key[32]) {
169
+ struct poly1305_state_st *state = (struct poly1305_state_st *)statep;
170
+ uint32_t t0, t1, t2, t3;
171
+
172
+ #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
173
+ if (CRYPTO_is_NEON_functional()) {
174
+ CRYPTO_poly1305_init_neon(statep, key);
175
+ return;
176
+ }
177
+ #endif
178
+
179
+ t0 = U8TO32_LE(key + 0);
180
+ t1 = U8TO32_LE(key + 4);
181
+ t2 = U8TO32_LE(key + 8);
182
+ t3 = U8TO32_LE(key + 12);
183
+
184
+ /* precompute multipliers */
185
+ state->r0 = t0 & 0x3ffffff;
186
+ t0 >>= 26;
187
+ t0 |= t1 << 6;
188
+ state->r1 = t0 & 0x3ffff03;
189
+ t1 >>= 20;
190
+ t1 |= t2 << 12;
191
+ state->r2 = t1 & 0x3ffc0ff;
192
+ t2 >>= 14;
193
+ t2 |= t3 << 18;
194
+ state->r3 = t2 & 0x3f03fff;
195
+ t3 >>= 8;
196
+ state->r4 = t3 & 0x00fffff;
197
+
198
+ state->s1 = state->r1 * 5;
199
+ state->s2 = state->r2 * 5;
200
+ state->s3 = state->r3 * 5;
201
+ state->s4 = state->r4 * 5;
202
+
203
+ /* init state */
204
+ state->h0 = 0;
205
+ state->h1 = 0;
206
+ state->h2 = 0;
207
+ state->h3 = 0;
208
+ state->h4 = 0;
209
+
210
+ state->buf_used = 0;
211
+ memcpy(state->key, key + 16, sizeof(state->key));
212
+ }
213
+
214
+ void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
215
+ size_t in_len) {
216
+ unsigned int i;
217
+ struct poly1305_state_st *state = (struct poly1305_state_st *)statep;
218
+
219
+ #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
220
+ if (CRYPTO_is_NEON_functional()) {
221
+ CRYPTO_poly1305_update_neon(statep, in, in_len);
222
+ return;
223
+ }
224
+ #endif
225
+
226
+ if (state->buf_used) {
227
+ unsigned int todo = 16 - state->buf_used;
228
+ if (todo > in_len) {
229
+ todo = in_len;
230
+ }
231
+ for (i = 0; i < todo; i++) {
232
+ state->buf[state->buf_used + i] = in[i];
233
+ }
234
+ state->buf_used += todo;
235
+ in_len -= todo;
236
+ in += todo;
237
+
238
+ if (state->buf_used == 16) {
239
+ poly1305_update(state, state->buf, 16);
240
+ state->buf_used = 0;
241
+ }
242
+ }
243
+
244
+ if (in_len >= 16) {
245
+ size_t todo = in_len & ~0xf;
246
+ poly1305_update(state, in, todo);
247
+ in += todo;
248
+ in_len &= 0xf;
249
+ }
250
+
251
+ if (in_len) {
252
+ for (i = 0; i < in_len; i++) {
253
+ state->buf[i] = in[i];
254
+ }
255
+ state->buf_used = in_len;
256
+ }
257
+ }
258
+
259
+ void CRYPTO_poly1305_finish(poly1305_state *statep, uint8_t mac[16]) {
260
+ struct poly1305_state_st *state = (struct poly1305_state_st *)statep;
261
+ uint64_t f0, f1, f2, f3;
262
+ uint32_t g0, g1, g2, g3, g4;
263
+ uint32_t b, nb;
264
+
265
+ #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
266
+ if (CRYPTO_is_NEON_functional()) {
267
+ CRYPTO_poly1305_finish_neon(statep, mac);
268
+ return;
269
+ }
270
+ #endif
271
+
272
+ if (state->buf_used) {
273
+ poly1305_update(state, state->buf, state->buf_used);
274
+ }
275
+
276
+ b = state->h0 >> 26;
277
+ state->h0 = state->h0 & 0x3ffffff;
278
+ state->h1 += b;
279
+ b = state->h1 >> 26;
280
+ state->h1 = state->h1 & 0x3ffffff;
281
+ state->h2 += b;
282
+ b = state->h2 >> 26;
283
+ state->h2 = state->h2 & 0x3ffffff;
284
+ state->h3 += b;
285
+ b = state->h3 >> 26;
286
+ state->h3 = state->h3 & 0x3ffffff;
287
+ state->h4 += b;
288
+ b = state->h4 >> 26;
289
+ state->h4 = state->h4 & 0x3ffffff;
290
+ state->h0 += b * 5;
291
+
292
+ g0 = state->h0 + 5;
293
+ b = g0 >> 26;
294
+ g0 &= 0x3ffffff;
295
+ g1 = state->h1 + b;
296
+ b = g1 >> 26;
297
+ g1 &= 0x3ffffff;
298
+ g2 = state->h2 + b;
299
+ b = g2 >> 26;
300
+ g2 &= 0x3ffffff;
301
+ g3 = state->h3 + b;
302
+ b = g3 >> 26;
303
+ g3 &= 0x3ffffff;
304
+ g4 = state->h4 + b - (1 << 26);
305
+
306
+ b = (g4 >> 31) - 1;
307
+ nb = ~b;
308
+ state->h0 = (state->h0 & nb) | (g0 & b);
309
+ state->h1 = (state->h1 & nb) | (g1 & b);
310
+ state->h2 = (state->h2 & nb) | (g2 & b);
311
+ state->h3 = (state->h3 & nb) | (g3 & b);
312
+ state->h4 = (state->h4 & nb) | (g4 & b);
313
+
314
+ f0 = ((state->h0) | (state->h1 << 26)) + (uint64_t)U8TO32_LE(&state->key[0]);
315
+ f1 = ((state->h1 >> 6) | (state->h2 << 20)) +
316
+ (uint64_t)U8TO32_LE(&state->key[4]);
317
+ f2 = ((state->h2 >> 12) | (state->h3 << 14)) +
318
+ (uint64_t)U8TO32_LE(&state->key[8]);
319
+ f3 = ((state->h3 >> 18) | (state->h4 << 8)) +
320
+ (uint64_t)U8TO32_LE(&state->key[12]);
321
+
322
+ U32TO8_LE(&mac[0], f0);
323
+ f1 += (f0 >> 32);
324
+ U32TO8_LE(&mac[4], f1);
325
+ f2 += (f1 >> 32);
326
+ U32TO8_LE(&mac[8], f2);
327
+ f3 += (f2 >> 32);
328
+ U32TO8_LE(&mac[12], f3);
329
+ }
330
+
331
+ #endif /* OPENSSL_WINDOWS || !OPENSSL_X86_64 */