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