ring-native 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,292 @@
1
+ #!/usr/bin/env perl
2
+
3
+ # require 'x86asm.pl';
4
+ # &asm_init(<flavor>,"des-586.pl"[,$i386only]);
5
+ # &function_begin("foo");
6
+ # ...
7
+ # &function_end("foo");
8
+ # &asm_finish
9
+
10
+ $out=();
11
+ $i386=0;
12
+
13
+ # AUTOLOAD is this context has quite unpleasant side effect, namely
14
+ # that typos in function calls effectively go to assembler output,
15
+ # but on the pros side we don't have to implement one subroutine per
16
+ # each opcode...
17
+ sub ::AUTOLOAD
18
+ { my $opcode = $AUTOLOAD;
19
+
20
+ die "more than 4 arguments passed to $opcode" if ($#_>3);
21
+
22
+ $opcode =~ s/.*:://;
23
+ if ($opcode =~ /^push/) { $stack+=4; }
24
+ elsif ($opcode =~ /^pop/) { $stack-=4; }
25
+
26
+ &generic($opcode,@_) or die "undefined subroutine \&$AUTOLOAD";
27
+ }
28
+
29
+ sub ::emit
30
+ { my $opcode=shift;
31
+
32
+ if ($#_==-1) { push(@out,"\t$opcode\n"); }
33
+ else { push(@out,"\t$opcode\t".join(',',@_)."\n"); }
34
+ }
35
+
36
+ sub ::LB
37
+ { $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'";
38
+ $1."l";
39
+ }
40
+ sub ::HB
41
+ { $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'high byte'";
42
+ $1."h";
43
+ }
44
+ sub ::stack_push{ my $num=$_[0]*4; $stack+=$num; &sub("esp",$num); }
45
+ sub ::stack_pop { my $num=$_[0]*4; $stack-=$num; &add("esp",$num); }
46
+ sub ::blindpop { &pop($_[0]); $stack+=4; }
47
+ sub ::wparam { &DWP($stack+4*$_[0],"esp"); }
48
+ sub ::swtmp { &DWP(4*$_[0],"esp"); }
49
+
50
+ sub ::bswap
51
+ { if ($i386) # emulate bswap for i386
52
+ { &comment("bswap @_");
53
+ &xchg(&HB(@_),&LB(@_));
54
+ &ror (@_,16);
55
+ &xchg(&HB(@_),&LB(@_));
56
+ }
57
+ else
58
+ { &generic("bswap",@_); }
59
+ }
60
+ # These are made-up opcodes introduced over the years essentially
61
+ # by ignorance, just alias them to real ones...
62
+ sub ::movb { &mov(@_); }
63
+ sub ::xorb { &xor(@_); }
64
+ sub ::rotl { &rol(@_); }
65
+ sub ::rotr { &ror(@_); }
66
+ sub ::exch { &xchg(@_); }
67
+ sub ::halt { &hlt; }
68
+ sub ::movz { &movzx(@_); }
69
+ sub ::pushf { &pushfd; }
70
+ sub ::popf { &popfd; }
71
+
72
+ # 3 argument instructions
73
+ sub ::movq
74
+ { my($p1,$p2,$optimize)=@_;
75
+
76
+ if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
77
+ # movq between mmx registers can sink Intel CPUs
78
+ { &::pshufw($p1,$p2,0xe4); }
79
+ else
80
+ { &::generic("movq",@_); }
81
+ }
82
+
83
+ # SSE>2 instructions
84
+ my %regrm = ( "eax"=>0, "ecx"=>1, "edx"=>2, "ebx"=>3,
85
+ "esp"=>4, "ebp"=>5, "esi"=>6, "edi"=>7 );
86
+ sub ::pextrd
87
+ { my($dst,$src,$imm)=@_;
88
+ if ("$dst:$src" =~ /(e[a-dsd][ixp]):xmm([0-7])/)
89
+ { &::data_byte(0x66,0x0f,0x3a,0x16,0xc0|($2<<3)|$regrm{$1},$imm); }
90
+ else
91
+ { &::generic("pextrd",@_); }
92
+ }
93
+
94
+ sub ::pinsrd
95
+ { my($dst,$src,$imm)=@_;
96
+ if ("$dst:$src" =~ /xmm([0-7]):(e[a-dsd][ixp])/)
97
+ { &::data_byte(0x66,0x0f,0x3a,0x22,0xc0|($1<<3)|$regrm{$2},$imm); }
98
+ else
99
+ { &::generic("pinsrd",@_); }
100
+ }
101
+
102
+ sub ::pshufb
103
+ { my($dst,$src)=@_;
104
+ if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
105
+ { &data_byte(0x66,0x0f,0x38,0x00,0xc0|($1<<3)|$2); }
106
+ else
107
+ { &::generic("pshufb",@_); }
108
+ }
109
+
110
+ sub ::palignr
111
+ { my($dst,$src,$imm)=@_;
112
+ if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
113
+ { &::data_byte(0x66,0x0f,0x3a,0x0f,0xc0|($1<<3)|$2,$imm); }
114
+ else
115
+ { &::generic("palignr",@_); }
116
+ }
117
+
118
+ sub ::pclmulqdq
119
+ { my($dst,$src,$imm)=@_;
120
+ if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
121
+ { &::data_byte(0x66,0x0f,0x3a,0x44,0xc0|($1<<3)|$2,$imm); }
122
+ else
123
+ { &::generic("pclmulqdq",@_); }
124
+ }
125
+
126
+ sub ::rdrand
127
+ { my ($dst)=@_;
128
+ if ($dst =~ /(e[a-dsd][ixp])/)
129
+ { &::data_byte(0x0f,0xc7,0xf0|$regrm{$dst}); }
130
+ else
131
+ { &::generic("rdrand",@_); }
132
+ }
133
+
134
+ sub rxb {
135
+ local *opcode=shift;
136
+ my ($dst,$src1,$src2,$rxb)=@_;
137
+
138
+ $rxb|=0x7<<5;
139
+ $rxb&=~(0x04<<5) if($dst>=8);
140
+ $rxb&=~(0x01<<5) if($src1>=8);
141
+ $rxb&=~(0x02<<5) if($src2>=8);
142
+ push @opcode,$rxb;
143
+ }
144
+
145
+ sub ::vprotd
146
+ { my $args=join(',',@_);
147
+ if ($args =~ /xmm([0-7]),xmm([0-7]),([x0-9a-f]+)/)
148
+ { my @opcode=(0x8f);
149
+ rxb(\@opcode,$1,$2,-1,0x08);
150
+ push @opcode,0x78,0xc2;
151
+ push @opcode,0xc0|($2&7)|(($1&7)<<3); # ModR/M
152
+ my $c=$3;
153
+ push @opcode,$c=~/^0/?oct($c):$c;
154
+ &::data_byte(@opcode);
155
+ }
156
+ else
157
+ { &::generic("vprotd",@_); }
158
+ }
159
+
160
+ # label management
161
+ $lbdecor="L"; # local label decoration, set by package
162
+ $label="000";
163
+
164
+ sub ::islabel # see is argument is a known label
165
+ { my $i;
166
+ foreach $i (values %label) { return $i if ($i eq $_[0]); }
167
+ $label{$_[0]}; # can be undef
168
+ }
169
+
170
+ sub ::label # instantiate a function-scope label
171
+ { if (!defined($label{$_[0]}))
172
+ { $label{$_[0]}="${lbdecor}${label}${_[0]}"; $label++; }
173
+ $label{$_[0]};
174
+ }
175
+
176
+ sub ::LABEL # instantiate a file-scope label
177
+ { $label{$_[0]}=$_[1] if (!defined($label{$_[0]}));
178
+ $label{$_[0]};
179
+ }
180
+
181
+ sub ::static_label { &::LABEL($_[0],$lbdecor.$_[0]); }
182
+
183
+ sub ::set_label_B { push(@out,"@_:\n"); }
184
+ sub ::set_label
185
+ { my $label=&::label($_[0]);
186
+ &::align($_[1]) if ($_[1]>1);
187
+ &::set_label_B($label);
188
+ $label;
189
+ }
190
+
191
+ sub ::wipe_labels # wipes function-scope labels
192
+ { foreach $i (keys %label)
193
+ { delete $label{$i} if ($label{$i} =~ /^\Q${lbdecor}\E[0-9]{3}/); }
194
+ }
195
+
196
+ # subroutine management
197
+ sub ::function_begin
198
+ { &function_begin_B(@_);
199
+ $stack=4;
200
+ &push("ebp");
201
+ &push("ebx");
202
+ &push("esi");
203
+ &push("edi");
204
+ }
205
+
206
+ sub ::function_end
207
+ { &pop("edi");
208
+ &pop("esi");
209
+ &pop("ebx");
210
+ &pop("ebp");
211
+ &ret();
212
+ &function_end_B(@_);
213
+ $stack=0;
214
+ &wipe_labels();
215
+ }
216
+
217
+ sub ::function_end_A
218
+ { &pop("edi");
219
+ &pop("esi");
220
+ &pop("ebx");
221
+ &pop("ebp");
222
+ &ret();
223
+ $stack+=16; # readjust esp as if we didn't pop anything
224
+ }
225
+
226
+ sub ::asciz
227
+ { my @str=unpack("C*",shift);
228
+ push @str,0;
229
+ while ($#str>15) {
230
+ &data_byte(@str[0..15]);
231
+ foreach (0..15) { shift @str; }
232
+ }
233
+ &data_byte(@str) if (@str);
234
+ }
235
+
236
+ sub ::asm_finish
237
+ { &file_end();
238
+ print "#if defined(__i386__)\n" unless $win32;
239
+ print @out;
240
+ print "#endif\n" unless $win32;
241
+ }
242
+
243
+ sub ::asm_init
244
+ { my ($type,$fn,$cpu)=@_;
245
+
246
+ $filename=$fn;
247
+ $i386=$cpu;
248
+
249
+ $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=$android=0;
250
+ if (($type eq "elf"))
251
+ { $elf=1; require "x86gas.pl"; }
252
+ elsif (($type eq "elf-1"))
253
+ { $elf=-1; require "x86gas.pl"; }
254
+ elsif (($type eq "a\.out"))
255
+ { $aout=1; require "x86gas.pl"; }
256
+ elsif (($type eq "coff" or $type eq "gaswin"))
257
+ { $coff=1; require "x86gas.pl"; }
258
+ elsif (($type eq "win32n"))
259
+ { $win32=1; require "x86nasm.pl"; }
260
+ elsif (($type eq "nw-nasm"))
261
+ { $netware=1; require "x86nasm.pl"; }
262
+ #elsif (($type eq "nw-mwasm"))
263
+ #{ $netware=1; $mwerks=1; require "x86nasm.pl"; }
264
+ elsif (($type eq "win32"))
265
+ { $win32=1; require "x86masm.pl"; }
266
+ elsif (($type eq "macosx"))
267
+ { $aout=1; $macosx=1; require "x86gas.pl"; }
268
+ elsif (($type eq "android"))
269
+ { $elf=1; $android=1; require "x86gas.pl"; }
270
+ else
271
+ { print STDERR <<"EOF";
272
+ Pick one target type from
273
+ elf - Linux, FreeBSD, Solaris x86, etc.
274
+ a.out - DJGPP, elder OpenBSD, etc.
275
+ coff - GAS/COFF such as Win32 targets
276
+ win32n - Windows 95/Windows NT NASM format
277
+ nw-nasm - NetWare NASM format
278
+ macosx - Mac OS X
279
+ EOF
280
+ exit(1);
281
+ }
282
+
283
+ $pic=0;
284
+ for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
285
+
286
+ $filename =~ s/\.pl$//;
287
+ &file($filename);
288
+ }
289
+
290
+ sub ::hidden {}
291
+
292
+ 1;
@@ -0,0 +1,263 @@
1
+ #!/usr/bin/env perl
2
+
3
+ package x86gas;
4
+
5
+ *out=\@::out;
6
+
7
+ $::lbdecor=$::aout?"L":".L"; # local label decoration
8
+ $nmdecor=($::aout or $::coff)?"_":""; # external name decoration
9
+
10
+ $initseg="";
11
+
12
+ $align=16;
13
+ $align=log($align)/log(2) if ($::aout);
14
+ $com_start="#" if ($::aout or $::coff);
15
+
16
+ sub opsize()
17
+ { my $reg=shift;
18
+ if ($reg =~ m/^%e/o) { "l"; }
19
+ elsif ($reg =~ m/^%[a-d][hl]$/o) { "b"; }
20
+ elsif ($reg =~ m/^%[xm]/o) { undef; }
21
+ else { "w"; }
22
+ }
23
+
24
+ # swap arguments;
25
+ # expand opcode with size suffix;
26
+ # prefix numeric constants with $;
27
+ sub ::generic
28
+ { my($opcode,@arg)=@_;
29
+ my($suffix,$dst,$src);
30
+
31
+ @arg=reverse(@arg);
32
+
33
+ for (@arg)
34
+ { s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o; # gp registers
35
+ s/^([xy]?mm[0-7])$/%$1/o; # xmm/mmx registers
36
+ s/^(\-?[0-9]+)$/\$$1/o; # constants
37
+ s/^(\-?0x[0-9a-f]+)$/\$$1/o; # constants
38
+ }
39
+
40
+ $dst = $arg[$#arg] if ($#arg>=0);
41
+ $src = $arg[$#arg-1] if ($#arg>=1);
42
+ if ($dst =~ m/^%/o) { $suffix=&opsize($dst); }
43
+ elsif ($src =~ m/^%/o) { $suffix=&opsize($src); }
44
+ else { $suffix="l"; }
45
+ undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
46
+
47
+ if ($#_==0) { &::emit($opcode); }
48
+ elsif ($#_==1 && $opcode =~ m/^(call|clflush|j|loop|set)/o)
49
+ { &::emit($opcode,@arg); }
50
+ else { &::emit($opcode.$suffix,@arg);}
51
+
52
+ 1;
53
+ }
54
+ #
55
+ # opcodes not covered by ::generic above, mostly inconsistent namings...
56
+ #
57
+ sub ::movzx { &::movzb(@_); }
58
+ sub ::pushfd { &::pushfl; }
59
+ sub ::popfd { &::popfl; }
60
+ sub ::cpuid { &::emit(".byte\t0x0f,0xa2"); }
61
+ sub ::rdtsc { &::emit(".byte\t0x0f,0x31"); }
62
+
63
+ sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
64
+ sub ::call_ptr { &::generic("call","*$_[0]"); }
65
+ sub ::jmp_ptr { &::generic("jmp","*$_[0]"); }
66
+
67
+ *::bswap = sub { &::emit("bswap","%$_[0]"); } if (!$::i386);
68
+
69
+ sub ::DWP
70
+ { my($addr,$reg1,$reg2,$idx)=@_;
71
+ my $ret="";
72
+
73
+ if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
74
+
75
+ $addr =~ s/^\s+//;
76
+ # prepend global references with optional underscore
77
+ $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
78
+
79
+ $reg1 = "%$reg1" if ($reg1);
80
+ $reg2 = "%$reg2" if ($reg2);
81
+
82
+ $ret .= $addr if (($addr ne "") && ($addr ne 0));
83
+
84
+ if ($reg2)
85
+ { $idx!= 0 or $idx=1;
86
+ $ret .= "($reg1,$reg2,$idx)";
87
+ }
88
+ elsif ($reg1)
89
+ { $ret .= "($reg1)"; }
90
+
91
+ $ret;
92
+ }
93
+ sub ::QWP { &::DWP(@_); }
94
+ sub ::BP { &::DWP(@_); }
95
+ sub ::WP { &::DWP(@_); }
96
+ sub ::BC { @_; }
97
+ sub ::DWC { @_; }
98
+
99
+ sub ::file
100
+ { push(@out,".file\t\"$_[0].S\"\n.text\n"); }
101
+
102
+ sub ::function_begin_B
103
+ { my $func=shift;
104
+ my $global=($func !~ /^_/);
105
+ my $begin="${::lbdecor}_${func}_begin";
106
+
107
+ &::LABEL($func,$global?"$begin":"$nmdecor$func");
108
+ $func=$nmdecor.$func;
109
+
110
+ push(@out,".globl\t$func\n") if ($global);
111
+ if ($::macosx) {
112
+ push(@out,".private_extern\t$func\n");
113
+ } else {
114
+ push(@out,".hidden\t$func\n");
115
+ }
116
+ if ($::coff)
117
+ { push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
118
+ elsif (($::aout and !$::pic) or $::macosx)
119
+ { }
120
+ else
121
+ { push(@out,".type $func,\@function\n"); }
122
+ push(@out,".align\t$align\n");
123
+ push(@out,"$func:\n");
124
+ push(@out,"$begin:\n") if ($global);
125
+ $::stack=4;
126
+ }
127
+
128
+ sub ::function_end_B
129
+ { my $func=shift;
130
+ push(@out,".size\t$nmdecor$func,.-".&::LABEL($func)."\n") if ($::elf);
131
+ $::stack=0;
132
+ &::wipe_labels();
133
+ }
134
+
135
+ sub ::comment
136
+ {
137
+ if (!defined($com_start) or $::elf)
138
+ { # Regarding $::elf above...
139
+ # GNU and SVR4 as'es use different comment delimiters,
140
+ push(@out,"\n"); # so we just skip ELF comments...
141
+ return;
142
+ }
143
+ foreach (@_)
144
+ {
145
+ if (/^\s*$/)
146
+ { push(@out,"\n"); }
147
+ else
148
+ { push(@out,"\t$com_start $_ $com_end\n"); }
149
+ }
150
+ }
151
+
152
+ sub ::external_label
153
+ { foreach(@_) { &::LABEL($_,$nmdecor.$_); } }
154
+
155
+ sub ::public_label
156
+ { push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
157
+
158
+ sub ::file_end
159
+ { if ($::macosx)
160
+ { if (%non_lazy_ptr)
161
+ { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
162
+ foreach $i (keys %non_lazy_ptr)
163
+ { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); }
164
+ }
165
+ }
166
+ if (0 && grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
167
+ my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,16";
168
+ if ($::macosx) { push (@out,"$tmp,2\n"); }
169
+ elsif ($::elf) { push (@out,"$tmp,4\n"); }
170
+ else { push (@out,"$tmp\n"); }
171
+ }
172
+ push(@out,$initseg) if ($initseg);
173
+ }
174
+
175
+ sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); }
176
+ sub ::data_short{ push(@out,".value\t".join(',',@_)."\n"); }
177
+ sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); }
178
+
179
+ sub ::align
180
+ { my $val=$_[0];
181
+ if ($::aout)
182
+ { $val=int(log($val)/log(2));
183
+ $val.=",0x90";
184
+ }
185
+ push(@out,".align\t$val\n");
186
+ }
187
+
188
+ sub ::picmeup
189
+ { my($dst,$sym,$base,$reflabel)=@_;
190
+
191
+ if (($::pic && ($::elf || $::aout)) || $::macosx)
192
+ { if (!defined($base))
193
+ { &::call(&::label("PIC_me_up"));
194
+ &::set_label("PIC_me_up");
195
+ &::blindpop($dst);
196
+ $base=$dst;
197
+ $reflabel=&::label("PIC_me_up");
198
+ }
199
+ if ($::macosx)
200
+ { my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr");
201
+ &::mov($dst,&::DWP("$indirect-$reflabel",$base));
202
+ $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
203
+ }
204
+ elsif ($sym eq "OPENSSL_ia32cap_P" && $::elf>0)
205
+ { &::lea($dst,&::DWP("$sym-$reflabel",$base)); }
206
+ else
207
+ { &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
208
+ $base));
209
+ &::mov($dst,&::DWP("$sym\@GOT",$dst));
210
+ }
211
+ }
212
+ else
213
+ { &::lea($dst,&::DWP($sym)); }
214
+ }
215
+
216
+ sub ::initseg
217
+ { my $f=$nmdecor.shift;
218
+
219
+ if ($::android)
220
+ { $initseg.=<<___;
221
+ .section .init_array
222
+ .align 4
223
+ .long $f
224
+ ___
225
+ }
226
+ elsif ($::elf)
227
+ { $initseg.=<<___;
228
+ .section .init
229
+ call $f
230
+ ___
231
+ }
232
+ elsif ($::coff)
233
+ { $initseg.=<<___; # applies to both Cygwin and Mingw
234
+ .section .ctors
235
+ .long $f
236
+ ___
237
+ }
238
+ elsif ($::macosx)
239
+ { $initseg.=<<___;
240
+ .mod_init_func
241
+ .align 2
242
+ .long $f
243
+ ___
244
+ }
245
+ elsif ($::aout)
246
+ { my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
247
+ $initseg.=".text\n";
248
+ $initseg.=".type $ctor,\@function\n" if ($::pic);
249
+ $initseg.=<<___; # OpenBSD way...
250
+ .globl $ctor
251
+ .align 2
252
+ $ctor:
253
+ jmp $f
254
+ ___
255
+ }
256
+ }
257
+
258
+ sub ::dataseg
259
+ { push(@out,".data\n"); }
260
+
261
+ *::hidden = sub { push(@out,".hidden\t$nmdecor$_[0]\n"); } if ($::elf);
262
+
263
+ 1;