ring-native 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/ext/ring/extconf.rb +29 -0
- data/lib/ring/native.rb +8 -0
- data/lib/ring/native/version.rb +5 -0
- data/ring-native.gemspec +25 -0
- data/vendor/ring/BUILDING.md +40 -0
- data/vendor/ring/Cargo.toml +43 -0
- data/vendor/ring/LICENSE +185 -0
- data/vendor/ring/Makefile +35 -0
- data/vendor/ring/PORTING.md +163 -0
- data/vendor/ring/README.md +113 -0
- data/vendor/ring/STYLE.md +197 -0
- data/vendor/ring/appveyor.yml +27 -0
- data/vendor/ring/build.rs +108 -0
- data/vendor/ring/crypto/aes/aes.c +1142 -0
- data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/aes/aes_test.cc +93 -0
- data/vendor/ring/crypto/aes/asm/aes-586.pl +2368 -0
- data/vendor/ring/crypto/aes/asm/aes-armv4.pl +1249 -0
- data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +2246 -0
- data/vendor/ring/crypto/aes/asm/aesni-x86.pl +1318 -0
- data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +2084 -0
- data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +675 -0
- data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +1364 -0
- data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +1565 -0
- data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +841 -0
- data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +1116 -0
- data/vendor/ring/crypto/aes/internal.h +87 -0
- data/vendor/ring/crypto/aes/mode_wrappers.c +61 -0
- data/vendor/ring/crypto/bn/add.c +394 -0
- data/vendor/ring/crypto/bn/asm/armv4-mont.pl +694 -0
- data/vendor/ring/crypto/bn/asm/armv8-mont.pl +1503 -0
- data/vendor/ring/crypto/bn/asm/bn-586.pl +774 -0
- data/vendor/ring/crypto/bn/asm/co-586.pl +287 -0
- data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +1882 -0
- data/vendor/ring/crypto/bn/asm/x86-mont.pl +592 -0
- data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +599 -0
- data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +1393 -0
- data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +3507 -0
- data/vendor/ring/crypto/bn/bn.c +352 -0
- data/vendor/ring/crypto/bn/bn_asn1.c +74 -0
- data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/bn/bn_test.cc +1696 -0
- data/vendor/ring/crypto/bn/cmp.c +200 -0
- data/vendor/ring/crypto/bn/convert.c +433 -0
- data/vendor/ring/crypto/bn/ctx.c +311 -0
- data/vendor/ring/crypto/bn/div.c +594 -0
- data/vendor/ring/crypto/bn/exponentiation.c +1335 -0
- data/vendor/ring/crypto/bn/gcd.c +711 -0
- data/vendor/ring/crypto/bn/generic.c +1019 -0
- data/vendor/ring/crypto/bn/internal.h +316 -0
- data/vendor/ring/crypto/bn/montgomery.c +516 -0
- data/vendor/ring/crypto/bn/mul.c +888 -0
- data/vendor/ring/crypto/bn/prime.c +829 -0
- data/vendor/ring/crypto/bn/random.c +334 -0
- data/vendor/ring/crypto/bn/rsaz_exp.c +262 -0
- data/vendor/ring/crypto/bn/rsaz_exp.h +53 -0
- data/vendor/ring/crypto/bn/shift.c +276 -0
- data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/bytestring/bytestring_test.cc +421 -0
- data/vendor/ring/crypto/bytestring/cbb.c +399 -0
- data/vendor/ring/crypto/bytestring/cbs.c +227 -0
- data/vendor/ring/crypto/bytestring/internal.h +46 -0
- data/vendor/ring/crypto/chacha/chacha_generic.c +140 -0
- data/vendor/ring/crypto/chacha/chacha_vec.c +323 -0
- data/vendor/ring/crypto/chacha/chacha_vec_arm.S +1447 -0
- data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +153 -0
- data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/cipher/e_aes.c +390 -0
- data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +208 -0
- data/vendor/ring/crypto/cipher/internal.h +173 -0
- data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +543 -0
- data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +9 -0
- data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +475 -0
- data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +23 -0
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +422 -0
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +484 -0
- data/vendor/ring/crypto/cipher/test/cipher_test.txt +100 -0
- data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/constant_time_test.c +304 -0
- data/vendor/ring/crypto/cpu-arm-asm.S +32 -0
- data/vendor/ring/crypto/cpu-arm.c +199 -0
- data/vendor/ring/crypto/cpu-intel.c +261 -0
- data/vendor/ring/crypto/crypto.c +151 -0
- data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +2118 -0
- data/vendor/ring/crypto/curve25519/curve25519.c +4888 -0
- data/vendor/ring/crypto/curve25519/x25519_test.cc +128 -0
- data/vendor/ring/crypto/digest/md32_common.h +181 -0
- data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +2725 -0
- data/vendor/ring/crypto/ec/ec.c +193 -0
- data/vendor/ring/crypto/ec/ec_curves.c +61 -0
- data/vendor/ring/crypto/ec/ec_key.c +228 -0
- data/vendor/ring/crypto/ec/ec_montgomery.c +114 -0
- data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/ec/internal.h +243 -0
- data/vendor/ring/crypto/ec/oct.c +253 -0
- data/vendor/ring/crypto/ec/p256-64.c +1794 -0
- data/vendor/ring/crypto/ec/p256-x86_64-table.h +9548 -0
- data/vendor/ring/crypto/ec/p256-x86_64.c +509 -0
- data/vendor/ring/crypto/ec/simple.c +1007 -0
- data/vendor/ring/crypto/ec/util-64.c +183 -0
- data/vendor/ring/crypto/ec/wnaf.c +508 -0
- data/vendor/ring/crypto/ecdh/ecdh.c +155 -0
- data/vendor/ring/crypto/ecdsa/ecdsa.c +304 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +193 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +327 -0
- data/vendor/ring/crypto/header_removed.h +17 -0
- data/vendor/ring/crypto/internal.h +495 -0
- data/vendor/ring/crypto/libring.Windows.vcxproj +101 -0
- data/vendor/ring/crypto/mem.c +98 -0
- data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +1045 -0
- data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +517 -0
- data/vendor/ring/crypto/modes/asm/ghash-x86.pl +1393 -0
- data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +1741 -0
- data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +422 -0
- data/vendor/ring/crypto/modes/ctr.c +226 -0
- data/vendor/ring/crypto/modes/gcm.c +1206 -0
- data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/modes/gcm_test.c +348 -0
- data/vendor/ring/crypto/modes/internal.h +299 -0
- data/vendor/ring/crypto/perlasm/arm-xlate.pl +170 -0
- data/vendor/ring/crypto/perlasm/readme +100 -0
- data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +1164 -0
- data/vendor/ring/crypto/perlasm/x86asm.pl +292 -0
- data/vendor/ring/crypto/perlasm/x86gas.pl +263 -0
- data/vendor/ring/crypto/perlasm/x86masm.pl +200 -0
- data/vendor/ring/crypto/perlasm/x86nasm.pl +187 -0
- data/vendor/ring/crypto/poly1305/poly1305.c +331 -0
- data/vendor/ring/crypto/poly1305/poly1305_arm.c +301 -0
- data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +2015 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.cc +80 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.txt +52 -0
- data/vendor/ring/crypto/poly1305/poly1305_vec.c +892 -0
- data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +75 -0
- data/vendor/ring/crypto/rand/internal.h +32 -0
- data/vendor/ring/crypto/rand/rand.c +189 -0
- data/vendor/ring/crypto/rand/urandom.c +219 -0
- data/vendor/ring/crypto/rand/windows.c +56 -0
- data/vendor/ring/crypto/refcount_c11.c +66 -0
- data/vendor/ring/crypto/refcount_lock.c +53 -0
- data/vendor/ring/crypto/refcount_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/refcount_test.c +58 -0
- data/vendor/ring/crypto/rsa/blinding.c +462 -0
- data/vendor/ring/crypto/rsa/internal.h +108 -0
- data/vendor/ring/crypto/rsa/padding.c +300 -0
- data/vendor/ring/crypto/rsa/rsa.c +450 -0
- data/vendor/ring/crypto/rsa/rsa_asn1.c +261 -0
- data/vendor/ring/crypto/rsa/rsa_impl.c +944 -0
- data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/rsa/rsa_test.cc +437 -0
- data/vendor/ring/crypto/sha/asm/sha-armv8.pl +436 -0
- data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +2390 -0
- data/vendor/ring/crypto/sha/asm/sha256-586.pl +1275 -0
- data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +735 -0
- data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha512-586.pl +911 -0
- data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +666 -0
- data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +14 -0
- data/vendor/ring/crypto/sha/sha1.c +271 -0
- data/vendor/ring/crypto/sha/sha256.c +204 -0
- data/vendor/ring/crypto/sha/sha512.c +355 -0
- data/vendor/ring/crypto/test/file_test.cc +326 -0
- data/vendor/ring/crypto/test/file_test.h +181 -0
- data/vendor/ring/crypto/test/malloc.cc +150 -0
- data/vendor/ring/crypto/test/scoped_types.h +95 -0
- data/vendor/ring/crypto/test/test.Windows.vcxproj +35 -0
- data/vendor/ring/crypto/test/test_util.cc +46 -0
- data/vendor/ring/crypto/test/test_util.h +41 -0
- data/vendor/ring/crypto/thread_none.c +55 -0
- data/vendor/ring/crypto/thread_pthread.c +165 -0
- data/vendor/ring/crypto/thread_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/thread_test.c +200 -0
- data/vendor/ring/crypto/thread_win.c +282 -0
- data/vendor/ring/examples/checkdigest.rs +103 -0
- data/vendor/ring/include/openssl/aes.h +121 -0
- data/vendor/ring/include/openssl/arm_arch.h +129 -0
- data/vendor/ring/include/openssl/base.h +156 -0
- data/vendor/ring/include/openssl/bn.h +794 -0
- data/vendor/ring/include/openssl/buffer.h +18 -0
- data/vendor/ring/include/openssl/bytestring.h +235 -0
- data/vendor/ring/include/openssl/chacha.h +37 -0
- data/vendor/ring/include/openssl/cmac.h +76 -0
- data/vendor/ring/include/openssl/cpu.h +184 -0
- data/vendor/ring/include/openssl/crypto.h +43 -0
- data/vendor/ring/include/openssl/curve25519.h +88 -0
- data/vendor/ring/include/openssl/ec.h +225 -0
- data/vendor/ring/include/openssl/ec_key.h +129 -0
- data/vendor/ring/include/openssl/ecdh.h +110 -0
- data/vendor/ring/include/openssl/ecdsa.h +156 -0
- data/vendor/ring/include/openssl/err.h +201 -0
- data/vendor/ring/include/openssl/mem.h +101 -0
- data/vendor/ring/include/openssl/obj_mac.h +71 -0
- data/vendor/ring/include/openssl/opensslfeatures.h +68 -0
- data/vendor/ring/include/openssl/opensslv.h +18 -0
- data/vendor/ring/include/openssl/ossl_typ.h +18 -0
- data/vendor/ring/include/openssl/poly1305.h +51 -0
- data/vendor/ring/include/openssl/rand.h +70 -0
- data/vendor/ring/include/openssl/rsa.h +399 -0
- data/vendor/ring/include/openssl/thread.h +133 -0
- data/vendor/ring/include/openssl/type_check.h +71 -0
- data/vendor/ring/mk/Common.props +63 -0
- data/vendor/ring/mk/Windows.props +42 -0
- data/vendor/ring/mk/WindowsTest.props +18 -0
- data/vendor/ring/mk/appveyor.bat +62 -0
- data/vendor/ring/mk/bottom_of_makefile.mk +54 -0
- data/vendor/ring/mk/ring.mk +266 -0
- data/vendor/ring/mk/top_of_makefile.mk +214 -0
- data/vendor/ring/mk/travis.sh +40 -0
- data/vendor/ring/mk/update-travis-yml.py +229 -0
- data/vendor/ring/ring.sln +153 -0
- data/vendor/ring/src/aead.rs +682 -0
- data/vendor/ring/src/agreement.rs +248 -0
- data/vendor/ring/src/c.rs +129 -0
- data/vendor/ring/src/constant_time.rs +37 -0
- data/vendor/ring/src/der.rs +96 -0
- data/vendor/ring/src/digest.rs +690 -0
- data/vendor/ring/src/digest_tests.txt +57 -0
- data/vendor/ring/src/ecc.rs +28 -0
- data/vendor/ring/src/ecc_build.rs +279 -0
- data/vendor/ring/src/ecc_curves.rs +117 -0
- data/vendor/ring/src/ed25519_tests.txt +2579 -0
- data/vendor/ring/src/exe_tests.rs +46 -0
- data/vendor/ring/src/ffi.rs +29 -0
- data/vendor/ring/src/file_test.rs +187 -0
- data/vendor/ring/src/hkdf.rs +153 -0
- data/vendor/ring/src/hkdf_tests.txt +59 -0
- data/vendor/ring/src/hmac.rs +414 -0
- data/vendor/ring/src/hmac_tests.txt +97 -0
- data/vendor/ring/src/input.rs +312 -0
- data/vendor/ring/src/lib.rs +41 -0
- data/vendor/ring/src/pbkdf2.rs +265 -0
- data/vendor/ring/src/pbkdf2_tests.txt +113 -0
- data/vendor/ring/src/polyfill.rs +57 -0
- data/vendor/ring/src/rand.rs +28 -0
- data/vendor/ring/src/signature.rs +314 -0
- data/vendor/ring/third-party/NIST/README.md +9 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +519 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +523 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +519 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +523 -0
- data/vendor/ring/third-party/NIST/sha256sums.txt +1 -0
- 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;
|