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,675 @@
|
|
1
|
+
#!/usr/bin/env perl
|
2
|
+
#
|
3
|
+
# ====================================================================
|
4
|
+
# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
|
5
|
+
# project. The module is, however, dual licensed under OpenSSL and
|
6
|
+
# CRYPTOGAMS licenses depending on where you obtain it. For further
|
7
|
+
# details see http://www.openssl.org/~appro/cryptogams/.
|
8
|
+
# ====================================================================
|
9
|
+
#
|
10
|
+
# This module implements support for ARMv8 AES instructions. The
|
11
|
+
# module is endian-agnostic in sense that it supports both big- and
|
12
|
+
# little-endian cases. As does it support both 32- and 64-bit modes
|
13
|
+
# of operation. Latter is achieved by limiting amount of utilized
|
14
|
+
# registers to 16, which implies additional NEON load and integer
|
15
|
+
# instructions. This has no effect on mighty Apple A7, where results
|
16
|
+
# are literally equal to the theoretical estimates based on AES
|
17
|
+
# instruction latencies and issue rates. On Cortex-A53, an in-order
|
18
|
+
# execution core, this costs up to 10-15%, which is partially
|
19
|
+
# compensated by implementing dedicated code path for 128-bit
|
20
|
+
# CBC encrypt case. On Cortex-A57 parallelizable mode performance
|
21
|
+
# seems to be limited by sheer amount of NEON instructions...
|
22
|
+
#
|
23
|
+
# Performance in cycles per byte processed with 128-bit key:
|
24
|
+
#
|
25
|
+
# CBC enc CBC dec CTR
|
26
|
+
# Apple A7 2.39 1.20 1.20
|
27
|
+
# Cortex-A53 1.32 1.29 1.46
|
28
|
+
# Cortex-A57(*) 1.95 0.85 0.93
|
29
|
+
# Denver 1.96 0.86 0.80
|
30
|
+
#
|
31
|
+
# (*) original 3.64/1.34/1.32 results were for r0p0 revision
|
32
|
+
# and are still same even for updated module;
|
33
|
+
|
34
|
+
$flavour = shift;
|
35
|
+
$output = shift;
|
36
|
+
|
37
|
+
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
38
|
+
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
|
39
|
+
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
|
40
|
+
die "can't locate arm-xlate.pl";
|
41
|
+
|
42
|
+
open OUT,"| \"$^X\" $xlate $flavour $output";
|
43
|
+
*STDOUT=*OUT;
|
44
|
+
|
45
|
+
$prefix="aes_v8";
|
46
|
+
|
47
|
+
$code=<<___;
|
48
|
+
#include <openssl/arm_arch.h>
|
49
|
+
|
50
|
+
#if __ARM_MAX_ARCH__>=7
|
51
|
+
.text
|
52
|
+
___
|
53
|
+
$code.=<<___ if ($flavour =~ /64/);
|
54
|
+
#if !defined(__clang__)
|
55
|
+
.arch armv8-a+crypto
|
56
|
+
#endif
|
57
|
+
___
|
58
|
+
$code.=".arch armv7-a\n.fpu neon\n.code 32\n" if ($flavour !~ /64/);
|
59
|
+
#^^^^^^ this is done to simplify adoption by not depending
|
60
|
+
# on latest binutils.
|
61
|
+
|
62
|
+
# Assembler mnemonics are an eclectic mix of 32- and 64-bit syntax,
|
63
|
+
# NEON is mostly 32-bit mnemonics, integer - mostly 64. Goal is to
|
64
|
+
# maintain both 32- and 64-bit codes within single module and
|
65
|
+
# transliterate common code to either flavour with regex vodoo.
|
66
|
+
#
|
67
|
+
{{{
|
68
|
+
my ($inp,$bits,$out,$ptr,$rounds)=("x0","w1","x2","x3","w12");
|
69
|
+
my ($zero,$rcon,$mask,$in0,$in1,$tmp,$key)=
|
70
|
+
$flavour=~/64/? map("q$_",(0..6)) : map("q$_",(0..3,8..10));
|
71
|
+
|
72
|
+
|
73
|
+
$code.=<<___;
|
74
|
+
.align 5
|
75
|
+
.Lrcon:
|
76
|
+
.long 0x01,0x01,0x01,0x01
|
77
|
+
.long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d // rotate-n-splat
|
78
|
+
.long 0x1b,0x1b,0x1b,0x1b
|
79
|
+
|
80
|
+
.globl ${prefix}_set_encrypt_key
|
81
|
+
.type ${prefix}_set_encrypt_key,%function
|
82
|
+
.align 5
|
83
|
+
${prefix}_set_encrypt_key:
|
84
|
+
.Lenc_key:
|
85
|
+
___
|
86
|
+
$code.=<<___ if ($flavour =~ /64/);
|
87
|
+
stp x29,x30,[sp,#-16]!
|
88
|
+
add x29,sp,#0
|
89
|
+
___
|
90
|
+
$code.=<<___;
|
91
|
+
mov $ptr,#-1
|
92
|
+
cmp $inp,#0
|
93
|
+
b.eq .Lenc_key_abort
|
94
|
+
cmp $out,#0
|
95
|
+
b.eq .Lenc_key_abort
|
96
|
+
mov $ptr,#-2
|
97
|
+
cmp $bits,#128
|
98
|
+
b.lt .Lenc_key_abort
|
99
|
+
cmp $bits,#256
|
100
|
+
b.gt .Lenc_key_abort
|
101
|
+
tst $bits,#0x3f
|
102
|
+
b.ne .Lenc_key_abort
|
103
|
+
|
104
|
+
adr $ptr,.Lrcon
|
105
|
+
cmp $bits,#192
|
106
|
+
|
107
|
+
veor $zero,$zero,$zero
|
108
|
+
vld1.8 {$in0},[$inp],#16
|
109
|
+
mov $bits,#8 // reuse $bits
|
110
|
+
vld1.32 {$rcon,$mask},[$ptr],#32
|
111
|
+
|
112
|
+
b.lt .Loop128
|
113
|
+
b.eq .L192
|
114
|
+
b .L256
|
115
|
+
|
116
|
+
.align 4
|
117
|
+
.Loop128:
|
118
|
+
vtbl.8 $key,{$in0},$mask
|
119
|
+
vext.8 $tmp,$zero,$in0,#12
|
120
|
+
vst1.32 {$in0},[$out],#16
|
121
|
+
aese $key,$zero
|
122
|
+
subs $bits,$bits,#1
|
123
|
+
|
124
|
+
veor $in0,$in0,$tmp
|
125
|
+
vext.8 $tmp,$zero,$tmp,#12
|
126
|
+
veor $in0,$in0,$tmp
|
127
|
+
vext.8 $tmp,$zero,$tmp,#12
|
128
|
+
veor $key,$key,$rcon
|
129
|
+
veor $in0,$in0,$tmp
|
130
|
+
vshl.u8 $rcon,$rcon,#1
|
131
|
+
veor $in0,$in0,$key
|
132
|
+
b.ne .Loop128
|
133
|
+
|
134
|
+
vld1.32 {$rcon},[$ptr]
|
135
|
+
|
136
|
+
vtbl.8 $key,{$in0},$mask
|
137
|
+
vext.8 $tmp,$zero,$in0,#12
|
138
|
+
vst1.32 {$in0},[$out],#16
|
139
|
+
aese $key,$zero
|
140
|
+
|
141
|
+
veor $in0,$in0,$tmp
|
142
|
+
vext.8 $tmp,$zero,$tmp,#12
|
143
|
+
veor $in0,$in0,$tmp
|
144
|
+
vext.8 $tmp,$zero,$tmp,#12
|
145
|
+
veor $key,$key,$rcon
|
146
|
+
veor $in0,$in0,$tmp
|
147
|
+
vshl.u8 $rcon,$rcon,#1
|
148
|
+
veor $in0,$in0,$key
|
149
|
+
|
150
|
+
vtbl.8 $key,{$in0},$mask
|
151
|
+
vext.8 $tmp,$zero,$in0,#12
|
152
|
+
vst1.32 {$in0},[$out],#16
|
153
|
+
aese $key,$zero
|
154
|
+
|
155
|
+
veor $in0,$in0,$tmp
|
156
|
+
vext.8 $tmp,$zero,$tmp,#12
|
157
|
+
veor $in0,$in0,$tmp
|
158
|
+
vext.8 $tmp,$zero,$tmp,#12
|
159
|
+
veor $key,$key,$rcon
|
160
|
+
veor $in0,$in0,$tmp
|
161
|
+
veor $in0,$in0,$key
|
162
|
+
vst1.32 {$in0},[$out]
|
163
|
+
add $out,$out,#0x50
|
164
|
+
|
165
|
+
mov $rounds,#10
|
166
|
+
b .Ldone
|
167
|
+
|
168
|
+
.align 4
|
169
|
+
.L192:
|
170
|
+
vld1.8 {$in1},[$inp],#8
|
171
|
+
vmov.i8 $key,#8 // borrow $key
|
172
|
+
vst1.32 {$in0},[$out],#16
|
173
|
+
vsub.i8 $mask,$mask,$key // adjust the mask
|
174
|
+
|
175
|
+
.Loop192:
|
176
|
+
vtbl.8 $key,{$in1},$mask
|
177
|
+
vext.8 $tmp,$zero,$in0,#12
|
178
|
+
vst1.32 {$in1},[$out],#8
|
179
|
+
aese $key,$zero
|
180
|
+
subs $bits,$bits,#1
|
181
|
+
|
182
|
+
veor $in0,$in0,$tmp
|
183
|
+
vext.8 $tmp,$zero,$tmp,#12
|
184
|
+
veor $in0,$in0,$tmp
|
185
|
+
vext.8 $tmp,$zero,$tmp,#12
|
186
|
+
veor $in0,$in0,$tmp
|
187
|
+
|
188
|
+
vdup.32 $tmp,${in0}[3]
|
189
|
+
veor $tmp,$tmp,$in1
|
190
|
+
veor $key,$key,$rcon
|
191
|
+
vext.8 $in1,$zero,$in1,#12
|
192
|
+
vshl.u8 $rcon,$rcon,#1
|
193
|
+
veor $in1,$in1,$tmp
|
194
|
+
veor $in0,$in0,$key
|
195
|
+
veor $in1,$in1,$key
|
196
|
+
vst1.32 {$in0},[$out],#16
|
197
|
+
b.ne .Loop192
|
198
|
+
|
199
|
+
mov $rounds,#12
|
200
|
+
add $out,$out,#0x20
|
201
|
+
b .Ldone
|
202
|
+
|
203
|
+
.align 4
|
204
|
+
.L256:
|
205
|
+
vld1.8 {$in1},[$inp]
|
206
|
+
mov $bits,#7
|
207
|
+
mov $rounds,#14
|
208
|
+
vst1.32 {$in0},[$out],#16
|
209
|
+
|
210
|
+
.Loop256:
|
211
|
+
vtbl.8 $key,{$in1},$mask
|
212
|
+
vext.8 $tmp,$zero,$in0,#12
|
213
|
+
vst1.32 {$in1},[$out],#16
|
214
|
+
aese $key,$zero
|
215
|
+
subs $bits,$bits,#1
|
216
|
+
|
217
|
+
veor $in0,$in0,$tmp
|
218
|
+
vext.8 $tmp,$zero,$tmp,#12
|
219
|
+
veor $in0,$in0,$tmp
|
220
|
+
vext.8 $tmp,$zero,$tmp,#12
|
221
|
+
veor $key,$key,$rcon
|
222
|
+
veor $in0,$in0,$tmp
|
223
|
+
vshl.u8 $rcon,$rcon,#1
|
224
|
+
veor $in0,$in0,$key
|
225
|
+
vst1.32 {$in0},[$out],#16
|
226
|
+
b.eq .Ldone
|
227
|
+
|
228
|
+
vdup.32 $key,${in0}[3] // just splat
|
229
|
+
vext.8 $tmp,$zero,$in1,#12
|
230
|
+
aese $key,$zero
|
231
|
+
|
232
|
+
veor $in1,$in1,$tmp
|
233
|
+
vext.8 $tmp,$zero,$tmp,#12
|
234
|
+
veor $in1,$in1,$tmp
|
235
|
+
vext.8 $tmp,$zero,$tmp,#12
|
236
|
+
veor $in1,$in1,$tmp
|
237
|
+
|
238
|
+
veor $in1,$in1,$key
|
239
|
+
b .Loop256
|
240
|
+
|
241
|
+
.Ldone:
|
242
|
+
str $rounds,[$out]
|
243
|
+
mov $ptr,#0
|
244
|
+
|
245
|
+
.Lenc_key_abort:
|
246
|
+
mov x0,$ptr // return value
|
247
|
+
`"ldr x29,[sp],#16" if ($flavour =~ /64/)`
|
248
|
+
ret
|
249
|
+
.size ${prefix}_set_encrypt_key,.-${prefix}_set_encrypt_key
|
250
|
+
|
251
|
+
.globl ${prefix}_set_decrypt_key
|
252
|
+
.type ${prefix}_set_decrypt_key,%function
|
253
|
+
.align 5
|
254
|
+
${prefix}_set_decrypt_key:
|
255
|
+
___
|
256
|
+
$code.=<<___ if ($flavour =~ /64/);
|
257
|
+
stp x29,x30,[sp,#-16]!
|
258
|
+
add x29,sp,#0
|
259
|
+
___
|
260
|
+
$code.=<<___ if ($flavour !~ /64/);
|
261
|
+
stmdb sp!,{r4,lr}
|
262
|
+
___
|
263
|
+
$code.=<<___;
|
264
|
+
bl .Lenc_key
|
265
|
+
|
266
|
+
cmp x0,#0
|
267
|
+
b.ne .Ldec_key_abort
|
268
|
+
|
269
|
+
sub $out,$out,#240 // restore original $out
|
270
|
+
mov x4,#-16
|
271
|
+
add $inp,$out,x12,lsl#4 // end of key schedule
|
272
|
+
|
273
|
+
vld1.32 {v0.16b},[$out]
|
274
|
+
vld1.32 {v1.16b},[$inp]
|
275
|
+
vst1.32 {v0.16b},[$inp],x4
|
276
|
+
vst1.32 {v1.16b},[$out],#16
|
277
|
+
|
278
|
+
.Loop_imc:
|
279
|
+
vld1.32 {v0.16b},[$out]
|
280
|
+
vld1.32 {v1.16b},[$inp]
|
281
|
+
aesimc v0.16b,v0.16b
|
282
|
+
aesimc v1.16b,v1.16b
|
283
|
+
vst1.32 {v0.16b},[$inp],x4
|
284
|
+
vst1.32 {v1.16b},[$out],#16
|
285
|
+
cmp $inp,$out
|
286
|
+
b.hi .Loop_imc
|
287
|
+
|
288
|
+
vld1.32 {v0.16b},[$out]
|
289
|
+
aesimc v0.16b,v0.16b
|
290
|
+
vst1.32 {v0.16b},[$inp]
|
291
|
+
|
292
|
+
eor x0,x0,x0 // return value
|
293
|
+
.Ldec_key_abort:
|
294
|
+
___
|
295
|
+
$code.=<<___ if ($flavour !~ /64/);
|
296
|
+
ldmia sp!,{r4,pc}
|
297
|
+
___
|
298
|
+
$code.=<<___ if ($flavour =~ /64/);
|
299
|
+
ldp x29,x30,[sp],#16
|
300
|
+
ret
|
301
|
+
___
|
302
|
+
$code.=<<___;
|
303
|
+
.size ${prefix}_set_decrypt_key,.-${prefix}_set_decrypt_key
|
304
|
+
___
|
305
|
+
}}}
|
306
|
+
{{{
|
307
|
+
sub gen_block () {
|
308
|
+
my $dir = shift;
|
309
|
+
my ($e,$mc) = $dir eq "en" ? ("e","mc") : ("d","imc");
|
310
|
+
my ($inp,$out,$key)=map("x$_",(0..2));
|
311
|
+
my $rounds="w3";
|
312
|
+
my ($rndkey0,$rndkey1,$inout)=map("q$_",(0..3));
|
313
|
+
|
314
|
+
$code.=<<___;
|
315
|
+
.globl ${prefix}_${dir}crypt
|
316
|
+
.type ${prefix}_${dir}crypt,%function
|
317
|
+
.align 5
|
318
|
+
${prefix}_${dir}crypt:
|
319
|
+
ldr $rounds,[$key,#240]
|
320
|
+
vld1.32 {$rndkey0},[$key],#16
|
321
|
+
vld1.8 {$inout},[$inp]
|
322
|
+
sub $rounds,$rounds,#2
|
323
|
+
vld1.32 {$rndkey1},[$key],#16
|
324
|
+
|
325
|
+
.Loop_${dir}c:
|
326
|
+
aes$e $inout,$rndkey0
|
327
|
+
aes$mc $inout,$inout
|
328
|
+
vld1.32 {$rndkey0},[$key],#16
|
329
|
+
subs $rounds,$rounds,#2
|
330
|
+
aes$e $inout,$rndkey1
|
331
|
+
aes$mc $inout,$inout
|
332
|
+
vld1.32 {$rndkey1},[$key],#16
|
333
|
+
b.gt .Loop_${dir}c
|
334
|
+
|
335
|
+
aes$e $inout,$rndkey0
|
336
|
+
aes$mc $inout,$inout
|
337
|
+
vld1.32 {$rndkey0},[$key]
|
338
|
+
aes$e $inout,$rndkey1
|
339
|
+
veor $inout,$inout,$rndkey0
|
340
|
+
|
341
|
+
vst1.8 {$inout},[$out]
|
342
|
+
ret
|
343
|
+
.size ${prefix}_${dir}crypt,.-${prefix}_${dir}crypt
|
344
|
+
___
|
345
|
+
}
|
346
|
+
&gen_block("en");
|
347
|
+
&gen_block("de");
|
348
|
+
}}}
|
349
|
+
{{{
|
350
|
+
my ($inp,$out,$len,$key,$ivp)=map("x$_",(0..4));
|
351
|
+
my ($rounds,$cnt,$key_)=("w5","w6","x7");
|
352
|
+
my ($ctr,$tctr0,$tctr1,$tctr2)=map("w$_",(8..10,12));
|
353
|
+
my $step="x12"; # aliases with $tctr2
|
354
|
+
|
355
|
+
my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$ivec,$rndlast)=map("q$_",(0..7));
|
356
|
+
my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9));
|
357
|
+
|
358
|
+
my ($dat,$tmp)=($dat0,$tmp0);
|
359
|
+
|
360
|
+
### q8-q15 preloaded key schedule
|
361
|
+
|
362
|
+
$code.=<<___;
|
363
|
+
.globl ${prefix}_ctr32_encrypt_blocks
|
364
|
+
.type ${prefix}_ctr32_encrypt_blocks,%function
|
365
|
+
.align 5
|
366
|
+
${prefix}_ctr32_encrypt_blocks:
|
367
|
+
___
|
368
|
+
$code.=<<___ if ($flavour =~ /64/);
|
369
|
+
stp x29,x30,[sp,#-16]!
|
370
|
+
add x29,sp,#0
|
371
|
+
___
|
372
|
+
$code.=<<___ if ($flavour !~ /64/);
|
373
|
+
mov ip,sp
|
374
|
+
stmdb sp!,{r4-r10,lr}
|
375
|
+
vstmdb sp!,{d8-d15} @ ABI specification says so
|
376
|
+
ldr r4, [ip] @ load remaining arg
|
377
|
+
___
|
378
|
+
$code.=<<___;
|
379
|
+
ldr $rounds,[$key,#240]
|
380
|
+
|
381
|
+
ldr $ctr, [$ivp, #12]
|
382
|
+
vld1.32 {$dat0},[$ivp]
|
383
|
+
|
384
|
+
vld1.32 {q8-q9},[$key] // load key schedule...
|
385
|
+
sub $rounds,$rounds,#4
|
386
|
+
mov $step,#16
|
387
|
+
cmp $len,#2
|
388
|
+
add $key_,$key,x5,lsl#4 // pointer to last 5 round keys
|
389
|
+
sub $rounds,$rounds,#2
|
390
|
+
vld1.32 {q12-q13},[$key_],#32
|
391
|
+
vld1.32 {q14-q15},[$key_],#32
|
392
|
+
vld1.32 {$rndlast},[$key_]
|
393
|
+
add $key_,$key,#32
|
394
|
+
mov $cnt,$rounds
|
395
|
+
cclr $step,lo
|
396
|
+
#ifndef __ARMEB__
|
397
|
+
rev $ctr, $ctr
|
398
|
+
#endif
|
399
|
+
vorr $dat1,$dat0,$dat0
|
400
|
+
add $tctr1, $ctr, #1
|
401
|
+
vorr $dat2,$dat0,$dat0
|
402
|
+
add $ctr, $ctr, #2
|
403
|
+
vorr $ivec,$dat0,$dat0
|
404
|
+
rev $tctr1, $tctr1
|
405
|
+
vmov.32 ${dat1}[3],$tctr1
|
406
|
+
b.ls .Lctr32_tail
|
407
|
+
rev $tctr2, $ctr
|
408
|
+
sub $len,$len,#3 // bias
|
409
|
+
vmov.32 ${dat2}[3],$tctr2
|
410
|
+
b .Loop3x_ctr32
|
411
|
+
|
412
|
+
.align 4
|
413
|
+
.Loop3x_ctr32:
|
414
|
+
aese $dat0,q8
|
415
|
+
aesmc $dat0,$dat0
|
416
|
+
aese $dat1,q8
|
417
|
+
aesmc $dat1,$dat1
|
418
|
+
aese $dat2,q8
|
419
|
+
aesmc $dat2,$dat2
|
420
|
+
vld1.32 {q8},[$key_],#16
|
421
|
+
subs $cnt,$cnt,#2
|
422
|
+
aese $dat0,q9
|
423
|
+
aesmc $dat0,$dat0
|
424
|
+
aese $dat1,q9
|
425
|
+
aesmc $dat1,$dat1
|
426
|
+
aese $dat2,q9
|
427
|
+
aesmc $dat2,$dat2
|
428
|
+
vld1.32 {q9},[$key_],#16
|
429
|
+
b.gt .Loop3x_ctr32
|
430
|
+
|
431
|
+
aese $dat0,q8
|
432
|
+
aesmc $tmp0,$dat0
|
433
|
+
aese $dat1,q8
|
434
|
+
aesmc $tmp1,$dat1
|
435
|
+
vld1.8 {$in0},[$inp],#16
|
436
|
+
vorr $dat0,$ivec,$ivec
|
437
|
+
aese $dat2,q8
|
438
|
+
aesmc $dat2,$dat2
|
439
|
+
vld1.8 {$in1},[$inp],#16
|
440
|
+
vorr $dat1,$ivec,$ivec
|
441
|
+
aese $tmp0,q9
|
442
|
+
aesmc $tmp0,$tmp0
|
443
|
+
aese $tmp1,q9
|
444
|
+
aesmc $tmp1,$tmp1
|
445
|
+
vld1.8 {$in2},[$inp],#16
|
446
|
+
mov $key_,$key
|
447
|
+
aese $dat2,q9
|
448
|
+
aesmc $tmp2,$dat2
|
449
|
+
vorr $dat2,$ivec,$ivec
|
450
|
+
add $tctr0,$ctr,#1
|
451
|
+
aese $tmp0,q12
|
452
|
+
aesmc $tmp0,$tmp0
|
453
|
+
aese $tmp1,q12
|
454
|
+
aesmc $tmp1,$tmp1
|
455
|
+
veor $in0,$in0,$rndlast
|
456
|
+
add $tctr1,$ctr,#2
|
457
|
+
aese $tmp2,q12
|
458
|
+
aesmc $tmp2,$tmp2
|
459
|
+
veor $in1,$in1,$rndlast
|
460
|
+
add $ctr,$ctr,#3
|
461
|
+
aese $tmp0,q13
|
462
|
+
aesmc $tmp0,$tmp0
|
463
|
+
aese $tmp1,q13
|
464
|
+
aesmc $tmp1,$tmp1
|
465
|
+
veor $in2,$in2,$rndlast
|
466
|
+
rev $tctr0,$tctr0
|
467
|
+
aese $tmp2,q13
|
468
|
+
aesmc $tmp2,$tmp2
|
469
|
+
vmov.32 ${dat0}[3], $tctr0
|
470
|
+
rev $tctr1,$tctr1
|
471
|
+
aese $tmp0,q14
|
472
|
+
aesmc $tmp0,$tmp0
|
473
|
+
aese $tmp1,q14
|
474
|
+
aesmc $tmp1,$tmp1
|
475
|
+
vmov.32 ${dat1}[3], $tctr1
|
476
|
+
rev $tctr2,$ctr
|
477
|
+
aese $tmp2,q14
|
478
|
+
aesmc $tmp2,$tmp2
|
479
|
+
vmov.32 ${dat2}[3], $tctr2
|
480
|
+
subs $len,$len,#3
|
481
|
+
aese $tmp0,q15
|
482
|
+
aese $tmp1,q15
|
483
|
+
aese $tmp2,q15
|
484
|
+
|
485
|
+
veor $in0,$in0,$tmp0
|
486
|
+
vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0]
|
487
|
+
vst1.8 {$in0},[$out],#16
|
488
|
+
veor $in1,$in1,$tmp1
|
489
|
+
mov $cnt,$rounds
|
490
|
+
vst1.8 {$in1},[$out],#16
|
491
|
+
veor $in2,$in2,$tmp2
|
492
|
+
vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1]
|
493
|
+
vst1.8 {$in2},[$out],#16
|
494
|
+
b.hs .Loop3x_ctr32
|
495
|
+
|
496
|
+
adds $len,$len,#3
|
497
|
+
b.eq .Lctr32_done
|
498
|
+
cmp $len,#1
|
499
|
+
mov $step,#16
|
500
|
+
cclr $step,eq
|
501
|
+
|
502
|
+
.Lctr32_tail:
|
503
|
+
aese $dat0,q8
|
504
|
+
aesmc $dat0,$dat0
|
505
|
+
aese $dat1,q8
|
506
|
+
aesmc $dat1,$dat1
|
507
|
+
vld1.32 {q8},[$key_],#16
|
508
|
+
subs $cnt,$cnt,#2
|
509
|
+
aese $dat0,q9
|
510
|
+
aesmc $dat0,$dat0
|
511
|
+
aese $dat1,q9
|
512
|
+
aesmc $dat1,$dat1
|
513
|
+
vld1.32 {q9},[$key_],#16
|
514
|
+
b.gt .Lctr32_tail
|
515
|
+
|
516
|
+
aese $dat0,q8
|
517
|
+
aesmc $dat0,$dat0
|
518
|
+
aese $dat1,q8
|
519
|
+
aesmc $dat1,$dat1
|
520
|
+
aese $dat0,q9
|
521
|
+
aesmc $dat0,$dat0
|
522
|
+
aese $dat1,q9
|
523
|
+
aesmc $dat1,$dat1
|
524
|
+
vld1.8 {$in0},[$inp],$step
|
525
|
+
aese $dat0,q12
|
526
|
+
aesmc $dat0,$dat0
|
527
|
+
aese $dat1,q12
|
528
|
+
aesmc $dat1,$dat1
|
529
|
+
vld1.8 {$in1},[$inp]
|
530
|
+
aese $dat0,q13
|
531
|
+
aesmc $dat0,$dat0
|
532
|
+
aese $dat1,q13
|
533
|
+
aesmc $dat1,$dat1
|
534
|
+
veor $in0,$in0,$rndlast
|
535
|
+
aese $dat0,q14
|
536
|
+
aesmc $dat0,$dat0
|
537
|
+
aese $dat1,q14
|
538
|
+
aesmc $dat1,$dat1
|
539
|
+
veor $in1,$in1,$rndlast
|
540
|
+
aese $dat0,q15
|
541
|
+
aese $dat1,q15
|
542
|
+
|
543
|
+
cmp $len,#1
|
544
|
+
veor $in0,$in0,$dat0
|
545
|
+
veor $in1,$in1,$dat1
|
546
|
+
vst1.8 {$in0},[$out],#16
|
547
|
+
b.eq .Lctr32_done
|
548
|
+
vst1.8 {$in1},[$out]
|
549
|
+
|
550
|
+
.Lctr32_done:
|
551
|
+
___
|
552
|
+
$code.=<<___ if ($flavour !~ /64/);
|
553
|
+
vldmia sp!,{d8-d15}
|
554
|
+
ldmia sp!,{r4-r10,pc}
|
555
|
+
___
|
556
|
+
$code.=<<___ if ($flavour =~ /64/);
|
557
|
+
ldr x29,[sp],#16
|
558
|
+
ret
|
559
|
+
___
|
560
|
+
$code.=<<___;
|
561
|
+
.size ${prefix}_ctr32_encrypt_blocks,.-${prefix}_ctr32_encrypt_blocks
|
562
|
+
___
|
563
|
+
}}}
|
564
|
+
$code.=<<___;
|
565
|
+
#endif
|
566
|
+
___
|
567
|
+
########################################
|
568
|
+
if ($flavour =~ /64/) { ######## 64-bit code
|
569
|
+
my %opcode = (
|
570
|
+
"aesd" => 0x4e285800, "aese" => 0x4e284800,
|
571
|
+
"aesimc"=> 0x4e287800, "aesmc" => 0x4e286800 );
|
572
|
+
|
573
|
+
local *unaes = sub {
|
574
|
+
my ($mnemonic,$arg)=@_;
|
575
|
+
|
576
|
+
$arg =~ m/[qv]([0-9]+)[^,]*,\s*[qv]([0-9]+)/o &&
|
577
|
+
sprintf ".inst\t0x%08x\t//%s %s",
|
578
|
+
$opcode{$mnemonic}|$1|($2<<5),
|
579
|
+
$mnemonic,$arg;
|
580
|
+
};
|
581
|
+
|
582
|
+
foreach(split("\n",$code)) {
|
583
|
+
s/\`([^\`]*)\`/eval($1)/geo;
|
584
|
+
|
585
|
+
s/\bq([0-9]+)\b/"v".($1<8?$1:$1+8).".16b"/geo; # old->new registers
|
586
|
+
s/@\s/\/\//o; # old->new style commentary
|
587
|
+
|
588
|
+
#s/[v]?(aes\w+)\s+([qv].*)/unaes($1,$2)/geo or
|
589
|
+
s/cclr\s+([wx])([^,]+),\s*([a-z]+)/csel $1$2,$1zr,$1$2,$3/o or
|
590
|
+
s/mov\.([a-z]+)\s+([wx][0-9]+),\s*([wx][0-9]+)/csel $2,$3,$2,$1/o or
|
591
|
+
s/vmov\.i8/movi/o or # fix up legacy mnemonics
|
592
|
+
s/vext\.8/ext/o or
|
593
|
+
s/vrev32\.8/rev32/o or
|
594
|
+
s/vtst\.8/cmtst/o or
|
595
|
+
s/vshr/ushr/o or
|
596
|
+
s/^(\s+)v/$1/o or # strip off v prefix
|
597
|
+
s/\bbx\s+lr\b/ret/o;
|
598
|
+
|
599
|
+
# fix up remainig legacy suffixes
|
600
|
+
s/\.[ui]?8//o;
|
601
|
+
m/\],#8/o and s/\.16b/\.8b/go;
|
602
|
+
s/\.[ui]?32//o and s/\.16b/\.4s/go;
|
603
|
+
s/\.[ui]?64//o and s/\.16b/\.2d/go;
|
604
|
+
s/\.[42]([sd])\[([0-3])\]/\.$1\[$2\]/o;
|
605
|
+
|
606
|
+
print $_,"\n";
|
607
|
+
}
|
608
|
+
} else { ######## 32-bit code
|
609
|
+
my %opcode = (
|
610
|
+
"aesd" => 0xf3b00340, "aese" => 0xf3b00300,
|
611
|
+
"aesimc"=> 0xf3b003c0, "aesmc" => 0xf3b00380 );
|
612
|
+
|
613
|
+
local *unaes = sub {
|
614
|
+
my ($mnemonic,$arg)=@_;
|
615
|
+
|
616
|
+
if ($arg =~ m/[qv]([0-9]+)[^,]*,\s*[qv]([0-9]+)/o) {
|
617
|
+
my $word = $opcode{$mnemonic}|(($1&7)<<13)|(($1&8)<<19)
|
618
|
+
|(($2&7)<<1) |(($2&8)<<2);
|
619
|
+
# since ARMv7 instructions are always encoded little-endian.
|
620
|
+
# correct solution is to use .inst directive, but older
|
621
|
+
# assemblers don't implement it:-(
|
622
|
+
sprintf ".byte\t0x%02x,0x%02x,0x%02x,0x%02x\t@ %s %s",
|
623
|
+
$word&0xff,($word>>8)&0xff,
|
624
|
+
($word>>16)&0xff,($word>>24)&0xff,
|
625
|
+
$mnemonic,$arg;
|
626
|
+
}
|
627
|
+
};
|
628
|
+
|
629
|
+
sub unvtbl {
|
630
|
+
my $arg=shift;
|
631
|
+
|
632
|
+
$arg =~ m/q([0-9]+),\s*\{q([0-9]+)\},\s*q([0-9]+)/o &&
|
633
|
+
sprintf "vtbl.8 d%d,{q%d},d%d\n\t".
|
634
|
+
"vtbl.8 d%d,{q%d},d%d", 2*$1,$2,2*$3, 2*$1+1,$2,2*$3+1;
|
635
|
+
}
|
636
|
+
|
637
|
+
sub unvdup32 {
|
638
|
+
my $arg=shift;
|
639
|
+
|
640
|
+
$arg =~ m/q([0-9]+),\s*q([0-9]+)\[([0-3])\]/o &&
|
641
|
+
sprintf "vdup.32 q%d,d%d[%d]",$1,2*$2+($3>>1),$3&1;
|
642
|
+
}
|
643
|
+
|
644
|
+
sub unvmov32 {
|
645
|
+
my $arg=shift;
|
646
|
+
|
647
|
+
$arg =~ m/q([0-9]+)\[([0-3])\],(.*)/o &&
|
648
|
+
sprintf "vmov.32 d%d[%d],%s",2*$1+($2>>1),$2&1,$3;
|
649
|
+
}
|
650
|
+
|
651
|
+
foreach(split("\n",$code)) {
|
652
|
+
s/\`([^\`]*)\`/eval($1)/geo;
|
653
|
+
|
654
|
+
s/\b[wx]([0-9]+)\b/r$1/go; # new->old registers
|
655
|
+
s/\bv([0-9])\.[12468]+[bsd]\b/q$1/go; # new->old registers
|
656
|
+
s/\/\/\s?/@ /o; # new->old style commentary
|
657
|
+
|
658
|
+
# fix up remainig new-style suffixes
|
659
|
+
s/\{q([0-9]+)\},\s*\[(.+)\],#8/sprintf "{d%d},[$2]!",2*$1/eo or
|
660
|
+
s/\],#[0-9]+/]!/o;
|
661
|
+
|
662
|
+
s/[v]?(aes\w+)\s+([qv].*)/unaes($1,$2)/geo or
|
663
|
+
s/cclr\s+([^,]+),\s*([a-z]+)/mov$2 $1,#0/o or
|
664
|
+
s/vtbl\.8\s+(.*)/unvtbl($1)/geo or
|
665
|
+
s/vdup\.32\s+(.*)/unvdup32($1)/geo or
|
666
|
+
s/vmov\.32\s+(.*)/unvmov32($1)/geo or
|
667
|
+
s/^(\s+)b\./$1b/o or
|
668
|
+
s/^(\s+)mov\./$1mov/o or
|
669
|
+
s/^(\s+)ret/$1bx\tlr/o;
|
670
|
+
|
671
|
+
print $_,"\n";
|
672
|
+
}
|
673
|
+
}
|
674
|
+
|
675
|
+
close STDOUT;
|