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,355 +0,0 @@
|
|
1
|
-
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
2
|
-
* All rights reserved.
|
3
|
-
*
|
4
|
-
* This package is an SSL implementation written
|
5
|
-
* by Eric Young (eay@cryptsoft.com).
|
6
|
-
* The implementation was written so as to conform with Netscapes SSL.
|
7
|
-
*
|
8
|
-
* This library is free for commercial and non-commercial use as long as
|
9
|
-
* the following conditions are aheared to. The following conditions
|
10
|
-
* apply to all code found in this distribution, be it the RC4, RSA,
|
11
|
-
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
12
|
-
* included with this distribution is covered by the same copyright terms
|
13
|
-
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
14
|
-
*
|
15
|
-
* Copyright remains Eric Young's, and as such any Copyright notices in
|
16
|
-
* the code are not to be removed.
|
17
|
-
* If this package is used in a product, Eric Young should be given attribution
|
18
|
-
* as the author of the parts of the library used.
|
19
|
-
* This can be in the form of a textual message at program startup or
|
20
|
-
* in documentation (online or textual) provided with the package.
|
21
|
-
*
|
22
|
-
* Redistribution and use in source and binary forms, with or without
|
23
|
-
* modification, are permitted provided that the following conditions
|
24
|
-
* are met:
|
25
|
-
* 1. Redistributions of source code must retain the copyright
|
26
|
-
* notice, this list of conditions and the following disclaimer.
|
27
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
28
|
-
* notice, this list of conditions and the following disclaimer in the
|
29
|
-
* documentation and/or other materials provided with the distribution.
|
30
|
-
* 3. All advertising materials mentioning features or use of this software
|
31
|
-
* must display the following acknowledgement:
|
32
|
-
* "This product includes cryptographic software written by
|
33
|
-
* Eric Young (eay@cryptsoft.com)"
|
34
|
-
* The word 'cryptographic' can be left out if the rouines from the library
|
35
|
-
* being used are not cryptographic related :-).
|
36
|
-
* 4. If you include any Windows specific code (or a derivative thereof) from
|
37
|
-
* the apps directory (application code) you must include an acknowledgement:
|
38
|
-
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
39
|
-
*
|
40
|
-
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
41
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
44
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50
|
-
* SUCH DAMAGE.
|
51
|
-
*
|
52
|
-
* The licence and distribution terms for any publically available version or
|
53
|
-
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
54
|
-
* copied and put under another distribution licence
|
55
|
-
* [including the GNU Public Licence.] */
|
56
|
-
|
57
|
-
#include "openssl/base.h"
|
58
|
-
|
59
|
-
|
60
|
-
/* The 32-bit hash algorithms' |*_block_data_order| functions operate on
|
61
|
-
* unaligned data. |sha512_block_data_order| does not. */
|
62
|
-
|
63
|
-
#include "../internal.h"
|
64
|
-
|
65
|
-
|
66
|
-
#if !defined(OPENSSL_NO_ASM) && \
|
67
|
-
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
|
68
|
-
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
69
|
-
#define SHA512_ASM
|
70
|
-
#endif
|
71
|
-
|
72
|
-
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
|
73
|
-
defined(__ARM_FEATURE_UNALIGNED)
|
74
|
-
#define SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
|
75
|
-
#else
|
76
|
-
#error "ring::digest does pre-align data for sha512_block_data_order"
|
77
|
-
#endif
|
78
|
-
|
79
|
-
#ifndef SHA512_ASM
|
80
|
-
static const uint64_t K512[80] = {
|
81
|
-
0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f,
|
82
|
-
0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019,
|
83
|
-
0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242,
|
84
|
-
0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
|
85
|
-
0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235,
|
86
|
-
0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3,
|
87
|
-
0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275,
|
88
|
-
0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5,
|
89
|
-
0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f,
|
90
|
-
0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
|
91
|
-
0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc,
|
92
|
-
0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df,
|
93
|
-
0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6,
|
94
|
-
0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001,
|
95
|
-
0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218,
|
96
|
-
0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8,
|
97
|
-
0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99,
|
98
|
-
0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb,
|
99
|
-
0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc,
|
100
|
-
0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
|
101
|
-
0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915,
|
102
|
-
0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207,
|
103
|
-
0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba,
|
104
|
-
0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,
|
105
|
-
0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,
|
106
|
-
0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a,
|
107
|
-
0x5fcb6fab3ad6faec, 0x6c44198c4a475817};
|
108
|
-
|
109
|
-
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM)
|
110
|
-
#if defined(__x86_64) || defined(__x86_64__)
|
111
|
-
#define ROTR(a, n) \
|
112
|
-
({ \
|
113
|
-
uint64_t ret; \
|
114
|
-
asm("rorq %1,%0" : "=r"(ret) : "J"(n), "0"(a) : "cc"); \
|
115
|
-
ret; \
|
116
|
-
})
|
117
|
-
#define PULL64(x) \
|
118
|
-
({ \
|
119
|
-
uint64_t ret = *((const uint64_t *)(&(x))); \
|
120
|
-
asm("bswapq %0" : "=r"(ret) : "0"(ret)); \
|
121
|
-
ret; \
|
122
|
-
})
|
123
|
-
#elif(defined(__i386) || defined(__i386__))
|
124
|
-
#define PULL64(x) \
|
125
|
-
({ \
|
126
|
-
const unsigned int *p = (const unsigned int *)(&(x)); \
|
127
|
-
unsigned int hi = p[0], lo = p[1]; \
|
128
|
-
asm("bswapl %0; bswapl %1;" : "=r"(lo), "=r"(hi) : "0"(lo), "1"(hi)); \
|
129
|
-
((uint64_t)hi) << 32 | lo; \
|
130
|
-
})
|
131
|
-
#elif(defined(_ARCH_PPC) && defined(__64BIT__)) || defined(_ARCH_PPC64)
|
132
|
-
#define ROTR(a, n) \
|
133
|
-
({ \
|
134
|
-
uint64_t ret; \
|
135
|
-
asm("rotrdi %0,%1,%2" : "=r"(ret) : "r"(a), "K"(n)); \
|
136
|
-
ret; \
|
137
|
-
})
|
138
|
-
#elif defined(__aarch64__)
|
139
|
-
#define ROTR(a, n) \
|
140
|
-
({ \
|
141
|
-
uint64_t ret; \
|
142
|
-
asm("ror %0,%1,%2" : "=r"(ret) : "r"(a), "I"(n)); \
|
143
|
-
ret; \
|
144
|
-
})
|
145
|
-
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
|
146
|
-
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
147
|
-
#define PULL64(x) \
|
148
|
-
({ \
|
149
|
-
uint64_t ret; \
|
150
|
-
asm("rev %0,%1" : "=r"(ret) : "r"(*((const uint64_t *)(&(x))))); \
|
151
|
-
ret; \
|
152
|
-
})
|
153
|
-
#endif
|
154
|
-
#endif
|
155
|
-
#elif defined(_MSC_VER)
|
156
|
-
#if defined(_WIN64) /* applies to both IA-64 and AMD64 */
|
157
|
-
#pragma intrinsic(_rotr64)
|
158
|
-
#define ROTR(a, n) _rotr64((a), n)
|
159
|
-
#endif
|
160
|
-
#if defined(_M_IX86) && !defined(OPENSSL_NO_ASM)
|
161
|
-
static uint64_t __fastcall __pull64be(const void *x) {
|
162
|
-
_asm mov edx, [ecx + 0]
|
163
|
-
_asm mov eax, [ecx + 4]
|
164
|
-
_asm bswap edx
|
165
|
-
_asm bswap eax
|
166
|
-
}
|
167
|
-
#define PULL64(x) __pull64be(&(x))
|
168
|
-
#if _MSC_VER <= 1200
|
169
|
-
#pragma inline_depth(0)
|
170
|
-
#endif
|
171
|
-
#endif
|
172
|
-
#endif
|
173
|
-
|
174
|
-
#ifndef PULL64
|
175
|
-
#define B(x, j) \
|
176
|
-
(((uint64_t)(*(((const uint8_t *)(&x)) + j))) << ((7 - j) * 8))
|
177
|
-
#define PULL64(x) \
|
178
|
-
(B(x, 0) | B(x, 1) | B(x, 2) | B(x, 3) | B(x, 4) | B(x, 5) | B(x, 6) | \
|
179
|
-
B(x, 7))
|
180
|
-
#endif
|
181
|
-
|
182
|
-
#ifndef ROTR
|
183
|
-
#define ROTR(x, s) (((x) >> s) | (x) << (64 - s))
|
184
|
-
#endif
|
185
|
-
|
186
|
-
#define Sigma0(x) (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39))
|
187
|
-
#define Sigma1(x) (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41))
|
188
|
-
#define sigma0(x) (ROTR((x), 1) ^ ROTR((x), 8) ^ ((x) >> 7))
|
189
|
-
#define sigma1(x) (ROTR((x), 19) ^ ROTR((x), 61) ^ ((x) >> 6))
|
190
|
-
|
191
|
-
#define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
192
|
-
#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
193
|
-
|
194
|
-
|
195
|
-
#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
196
|
-
/*
|
197
|
-
* This code should give better results on 32-bit CPU with less than
|
198
|
-
* ~24 registers, both size and performance wise...
|
199
|
-
*/
|
200
|
-
void sha512_block_data_order(uint64_t *state, const uint64_t *W, size_t num) {
|
201
|
-
uint64_t A, E, T;
|
202
|
-
uint64_t X[9 + 80], *F;
|
203
|
-
int i;
|
204
|
-
|
205
|
-
while (num--) {
|
206
|
-
F = X + 80;
|
207
|
-
A = state[0];
|
208
|
-
F[1] = state[1];
|
209
|
-
F[2] = state[2];
|
210
|
-
F[3] = state[3];
|
211
|
-
E = state[4];
|
212
|
-
F[5] = state[5];
|
213
|
-
F[6] = state[6];
|
214
|
-
F[7] = state[7];
|
215
|
-
|
216
|
-
for (i = 0; i < 16; i++, F--) {
|
217
|
-
T = PULL64(W[i]);
|
218
|
-
F[0] = A;
|
219
|
-
F[4] = E;
|
220
|
-
F[8] = T;
|
221
|
-
T += F[7] + Sigma1(E) + Ch(E, F[5], F[6]) + K512[i];
|
222
|
-
E = F[3] + T;
|
223
|
-
A = T + Sigma0(A) + Maj(A, F[1], F[2]);
|
224
|
-
}
|
225
|
-
|
226
|
-
for (; i < 80; i++, F--) {
|
227
|
-
T = sigma0(F[8 + 16 - 1]);
|
228
|
-
T += sigma1(F[8 + 16 - 14]);
|
229
|
-
T += F[8 + 16] + F[8 + 16 - 9];
|
230
|
-
|
231
|
-
F[0] = A;
|
232
|
-
F[4] = E;
|
233
|
-
F[8] = T;
|
234
|
-
T += F[7] + Sigma1(E) + Ch(E, F[5], F[6]) + K512[i];
|
235
|
-
E = F[3] + T;
|
236
|
-
A = T + Sigma0(A) + Maj(A, F[1], F[2]);
|
237
|
-
}
|
238
|
-
|
239
|
-
state[0] += A;
|
240
|
-
state[1] += F[1];
|
241
|
-
state[2] += F[2];
|
242
|
-
state[3] += F[3];
|
243
|
-
state[4] += E;
|
244
|
-
state[5] += F[5];
|
245
|
-
state[6] += F[6];
|
246
|
-
state[7] += F[7];
|
247
|
-
|
248
|
-
W += 16;
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
#else
|
253
|
-
|
254
|
-
#define ROUND_00_15(i, a, b, c, d, e, f, g, h) \
|
255
|
-
do { \
|
256
|
-
T1 += h + Sigma1(e) + Ch(e, f, g) + K512[i]; \
|
257
|
-
h = Sigma0(a) + Maj(a, b, c); \
|
258
|
-
d += T1; \
|
259
|
-
h += T1; \
|
260
|
-
} while (0)
|
261
|
-
|
262
|
-
#define ROUND_16_80(i, j, a, b, c, d, e, f, g, h, X) \
|
263
|
-
do { \
|
264
|
-
s0 = X[(j + 1) & 0x0f]; \
|
265
|
-
s0 = sigma0(s0); \
|
266
|
-
s1 = X[(j + 14) & 0x0f]; \
|
267
|
-
s1 = sigma1(s1); \
|
268
|
-
T1 = X[(j) & 0x0f] += s0 + s1 + X[(j + 9) & 0x0f]; \
|
269
|
-
ROUND_00_15(i + j, a, b, c, d, e, f, g, h); \
|
270
|
-
} while (0)
|
271
|
-
|
272
|
-
void sha512_block_data_order(uint64_t *state, const uint64_t *W, size_t num) {
|
273
|
-
uint64_t a, b, c, d, e, f, g, h, s0, s1, T1;
|
274
|
-
uint64_t X[16];
|
275
|
-
int i;
|
276
|
-
|
277
|
-
while (num--) {
|
278
|
-
|
279
|
-
a = state[0];
|
280
|
-
b = state[1];
|
281
|
-
c = state[2];
|
282
|
-
d = state[3];
|
283
|
-
e = state[4];
|
284
|
-
f = state[5];
|
285
|
-
g = state[6];
|
286
|
-
h = state[7];
|
287
|
-
|
288
|
-
T1 = X[0] = PULL64(W[0]);
|
289
|
-
ROUND_00_15(0, a, b, c, d, e, f, g, h);
|
290
|
-
T1 = X[1] = PULL64(W[1]);
|
291
|
-
ROUND_00_15(1, h, a, b, c, d, e, f, g);
|
292
|
-
T1 = X[2] = PULL64(W[2]);
|
293
|
-
ROUND_00_15(2, g, h, a, b, c, d, e, f);
|
294
|
-
T1 = X[3] = PULL64(W[3]);
|
295
|
-
ROUND_00_15(3, f, g, h, a, b, c, d, e);
|
296
|
-
T1 = X[4] = PULL64(W[4]);
|
297
|
-
ROUND_00_15(4, e, f, g, h, a, b, c, d);
|
298
|
-
T1 = X[5] = PULL64(W[5]);
|
299
|
-
ROUND_00_15(5, d, e, f, g, h, a, b, c);
|
300
|
-
T1 = X[6] = PULL64(W[6]);
|
301
|
-
ROUND_00_15(6, c, d, e, f, g, h, a, b);
|
302
|
-
T1 = X[7] = PULL64(W[7]);
|
303
|
-
ROUND_00_15(7, b, c, d, e, f, g, h, a);
|
304
|
-
T1 = X[8] = PULL64(W[8]);
|
305
|
-
ROUND_00_15(8, a, b, c, d, e, f, g, h);
|
306
|
-
T1 = X[9] = PULL64(W[9]);
|
307
|
-
ROUND_00_15(9, h, a, b, c, d, e, f, g);
|
308
|
-
T1 = X[10] = PULL64(W[10]);
|
309
|
-
ROUND_00_15(10, g, h, a, b, c, d, e, f);
|
310
|
-
T1 = X[11] = PULL64(W[11]);
|
311
|
-
ROUND_00_15(11, f, g, h, a, b, c, d, e);
|
312
|
-
T1 = X[12] = PULL64(W[12]);
|
313
|
-
ROUND_00_15(12, e, f, g, h, a, b, c, d);
|
314
|
-
T1 = X[13] = PULL64(W[13]);
|
315
|
-
ROUND_00_15(13, d, e, f, g, h, a, b, c);
|
316
|
-
T1 = X[14] = PULL64(W[14]);
|
317
|
-
ROUND_00_15(14, c, d, e, f, g, h, a, b);
|
318
|
-
T1 = X[15] = PULL64(W[15]);
|
319
|
-
ROUND_00_15(15, b, c, d, e, f, g, h, a);
|
320
|
-
|
321
|
-
for (i = 16; i < 80; i += 16) {
|
322
|
-
ROUND_16_80(i, 0, a, b, c, d, e, f, g, h, X);
|
323
|
-
ROUND_16_80(i, 1, h, a, b, c, d, e, f, g, X);
|
324
|
-
ROUND_16_80(i, 2, g, h, a, b, c, d, e, f, X);
|
325
|
-
ROUND_16_80(i, 3, f, g, h, a, b, c, d, e, X);
|
326
|
-
ROUND_16_80(i, 4, e, f, g, h, a, b, c, d, X);
|
327
|
-
ROUND_16_80(i, 5, d, e, f, g, h, a, b, c, X);
|
328
|
-
ROUND_16_80(i, 6, c, d, e, f, g, h, a, b, X);
|
329
|
-
ROUND_16_80(i, 7, b, c, d, e, f, g, h, a, X);
|
330
|
-
ROUND_16_80(i, 8, a, b, c, d, e, f, g, h, X);
|
331
|
-
ROUND_16_80(i, 9, h, a, b, c, d, e, f, g, X);
|
332
|
-
ROUND_16_80(i, 10, g, h, a, b, c, d, e, f, X);
|
333
|
-
ROUND_16_80(i, 11, f, g, h, a, b, c, d, e, X);
|
334
|
-
ROUND_16_80(i, 12, e, f, g, h, a, b, c, d, X);
|
335
|
-
ROUND_16_80(i, 13, d, e, f, g, h, a, b, c, X);
|
336
|
-
ROUND_16_80(i, 14, c, d, e, f, g, h, a, b, X);
|
337
|
-
ROUND_16_80(i, 15, b, c, d, e, f, g, h, a, X);
|
338
|
-
}
|
339
|
-
|
340
|
-
state[0] += a;
|
341
|
-
state[1] += b;
|
342
|
-
state[2] += c;
|
343
|
-
state[3] += d;
|
344
|
-
state[4] += e;
|
345
|
-
state[5] += f;
|
346
|
-
state[6] += g;
|
347
|
-
state[7] += h;
|
348
|
-
|
349
|
-
W += 16;
|
350
|
-
}
|
351
|
-
}
|
352
|
-
|
353
|
-
#endif
|
354
|
-
|
355
|
-
#endif /* SHA512_ASM */
|
@@ -1,326 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2015, Google Inc.
|
2
|
-
*
|
3
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
* purpose with or without fee is hereby granted, provided that the above
|
5
|
-
* copyright notice and this permission notice appear in all copies.
|
6
|
-
*
|
7
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
10
|
-
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
12
|
-
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
13
|
-
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
14
|
-
|
15
|
-
#include "file_test.h"
|
16
|
-
|
17
|
-
#include <ctype.h>
|
18
|
-
#include <errno.h>
|
19
|
-
#include <stdarg.h>
|
20
|
-
#include <stdlib.h>
|
21
|
-
#include <string.h>
|
22
|
-
|
23
|
-
#include <openssl/err.h>
|
24
|
-
|
25
|
-
|
26
|
-
FileTest::FileTest(const char *path) {
|
27
|
-
file_ = fopen(path, "r");
|
28
|
-
if (file_ == nullptr) {
|
29
|
-
fprintf(stderr, "Could not open file %s: %s.\n", path, strerror(errno));
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
FileTest::~FileTest() {
|
34
|
-
if (file_ != nullptr) {
|
35
|
-
fclose(file_);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
// FindDelimiter returns a pointer to the first '=' or ':' in |str| or nullptr
|
40
|
-
// if there is none.
|
41
|
-
static const char *FindDelimiter(const char *str) {
|
42
|
-
while (*str) {
|
43
|
-
if (*str == ':' || *str == '=') {
|
44
|
-
return str;
|
45
|
-
}
|
46
|
-
str++;
|
47
|
-
}
|
48
|
-
return nullptr;
|
49
|
-
}
|
50
|
-
|
51
|
-
// StripSpace returns a string containing up to |len| characters from |str| with
|
52
|
-
// leading and trailing whitespace removed.
|
53
|
-
static std::string StripSpace(const char *str, size_t len) {
|
54
|
-
// Remove leading space.
|
55
|
-
while (len > 0 && isspace(*str)) {
|
56
|
-
str++;
|
57
|
-
len--;
|
58
|
-
}
|
59
|
-
while (len > 0 && isspace(str[len-1])) {
|
60
|
-
len--;
|
61
|
-
}
|
62
|
-
return std::string(str, len);
|
63
|
-
}
|
64
|
-
|
65
|
-
FileTest::ReadResult FileTest::ReadNext() {
|
66
|
-
// If the previous test had unused attributes or block, it is an error.
|
67
|
-
if (!unused_attributes_.empty()) {
|
68
|
-
for (const std::string &key : unused_attributes_) {
|
69
|
-
PrintLine("Unused attribute: %s", key.c_str());
|
70
|
-
}
|
71
|
-
return kReadError;
|
72
|
-
}
|
73
|
-
if (!block_.empty() && !used_block_) {
|
74
|
-
PrintLine("Unused block");
|
75
|
-
return kReadError;
|
76
|
-
}
|
77
|
-
|
78
|
-
ClearTest();
|
79
|
-
|
80
|
-
bool in_block = false;
|
81
|
-
while (true) {
|
82
|
-
// Read the next line.
|
83
|
-
char buf[4096];
|
84
|
-
if (fgets(buf, sizeof(buf), file_) == nullptr) {
|
85
|
-
if (feof(file_)) {
|
86
|
-
if (in_block) {
|
87
|
-
fprintf(stderr, "Unterminated block.\n");
|
88
|
-
return kReadError;
|
89
|
-
}
|
90
|
-
// EOF is a valid terminator for a test.
|
91
|
-
return start_line_ > 0 ? kReadSuccess : kReadEOF;
|
92
|
-
}
|
93
|
-
fprintf(stderr, "Error reading from input.\n");
|
94
|
-
return kReadError;
|
95
|
-
}
|
96
|
-
|
97
|
-
line_++;
|
98
|
-
size_t len = strlen(buf);
|
99
|
-
// Check for truncation.
|
100
|
-
if (len > 0 && buf[len - 1] != '\n' && !feof(file_)) {
|
101
|
-
fprintf(stderr, "Line %u too long.\n", line_);
|
102
|
-
return kReadError;
|
103
|
-
}
|
104
|
-
|
105
|
-
bool is_delimiter = strncmp(buf, "---", 3) == 0;
|
106
|
-
if (in_block) {
|
107
|
-
block_ += buf;
|
108
|
-
if (is_delimiter) {
|
109
|
-
// Ending the block completes the test.
|
110
|
-
return kReadSuccess;
|
111
|
-
}
|
112
|
-
} else if (is_delimiter) {
|
113
|
-
if (start_line_ == 0) {
|
114
|
-
fprintf(stderr, "Line %u: Unexpected block.\n", line_);
|
115
|
-
return kReadError;
|
116
|
-
}
|
117
|
-
in_block = true;
|
118
|
-
block_ += buf;
|
119
|
-
} else if (buf[0] == '\n' || buf[0] == '\0') {
|
120
|
-
// Empty lines delimit tests.
|
121
|
-
if (start_line_ > 0) {
|
122
|
-
return kReadSuccess;
|
123
|
-
}
|
124
|
-
} else if (buf[0] != '#') { // Comment lines are ignored.
|
125
|
-
// Parse the line as an attribute.
|
126
|
-
const char *delimiter = FindDelimiter(buf);
|
127
|
-
if (delimiter == nullptr) {
|
128
|
-
fprintf(stderr, "Line %u: Could not parse attribute.\n", line_);
|
129
|
-
return kReadError;
|
130
|
-
}
|
131
|
-
std::string key = StripSpace(buf, delimiter - buf);
|
132
|
-
std::string value = StripSpace(delimiter + 1,
|
133
|
-
buf + len - delimiter - 1);
|
134
|
-
|
135
|
-
unused_attributes_.insert(key);
|
136
|
-
attributes_[key] = value;
|
137
|
-
if (start_line_ == 0) {
|
138
|
-
// This is the start of a test.
|
139
|
-
type_ = key;
|
140
|
-
parameter_ = value;
|
141
|
-
start_line_ = line_;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
void FileTest::PrintLine(const char *format, ...) {
|
148
|
-
va_list args;
|
149
|
-
va_start(args, format);
|
150
|
-
|
151
|
-
fprintf(stderr, "Line %u: ", start_line_);
|
152
|
-
vfprintf(stderr, format, args);
|
153
|
-
fprintf(stderr, "\n");
|
154
|
-
|
155
|
-
va_end(args);
|
156
|
-
}
|
157
|
-
|
158
|
-
const std::string &FileTest::GetType() {
|
159
|
-
OnKeyUsed(type_);
|
160
|
-
return type_;
|
161
|
-
}
|
162
|
-
|
163
|
-
const std::string &FileTest::GetParameter() {
|
164
|
-
OnKeyUsed(type_);
|
165
|
-
return parameter_;
|
166
|
-
}
|
167
|
-
|
168
|
-
const std::string &FileTest::GetBlock() {
|
169
|
-
used_block_ = true;
|
170
|
-
return block_;
|
171
|
-
}
|
172
|
-
|
173
|
-
bool FileTest::HasAttribute(const std::string &key) {
|
174
|
-
OnKeyUsed(key);
|
175
|
-
return attributes_.count(key) > 0;
|
176
|
-
}
|
177
|
-
|
178
|
-
bool FileTest::GetAttribute(std::string *out_value, const std::string &key) {
|
179
|
-
OnKeyUsed(key);
|
180
|
-
auto iter = attributes_.find(key);
|
181
|
-
if (iter == attributes_.end()) {
|
182
|
-
PrintLine("Missing attribute '%s'.", key.c_str());
|
183
|
-
return false;
|
184
|
-
}
|
185
|
-
*out_value = iter->second;
|
186
|
-
return true;
|
187
|
-
}
|
188
|
-
|
189
|
-
const std::string &FileTest::GetAttributeOrDie(const std::string &key) {
|
190
|
-
if (!HasAttribute(key)) {
|
191
|
-
abort();
|
192
|
-
}
|
193
|
-
return attributes_[key];
|
194
|
-
}
|
195
|
-
|
196
|
-
static bool FromHexDigit(uint8_t *out, char c) {
|
197
|
-
if ('0' <= c && c <= '9') {
|
198
|
-
*out = c - '0';
|
199
|
-
return true;
|
200
|
-
}
|
201
|
-
if ('a' <= c && c <= 'f') {
|
202
|
-
*out = c - 'a' + 10;
|
203
|
-
return true;
|
204
|
-
}
|
205
|
-
if ('A' <= c && c <= 'F') {
|
206
|
-
*out = c - 'A' + 10;
|
207
|
-
return true;
|
208
|
-
}
|
209
|
-
return false;
|
210
|
-
}
|
211
|
-
|
212
|
-
bool FileTest::GetBytesOrDefault(std::vector<uint8_t> *out, bool *is_default,
|
213
|
-
const std::string &key) {
|
214
|
-
std::string value;
|
215
|
-
if (!GetAttribute(&value, key)) {
|
216
|
-
return false;
|
217
|
-
}
|
218
|
-
|
219
|
-
*is_default = value == "DEFAULT";
|
220
|
-
if (*is_default) {
|
221
|
-
return true;
|
222
|
-
}
|
223
|
-
|
224
|
-
if (value.size() >= 2 && value[0] == '"' && value[value.size() - 1] == '"') {
|
225
|
-
out->assign(value.begin() + 1, value.end() - 1);
|
226
|
-
return true;
|
227
|
-
}
|
228
|
-
|
229
|
-
if (value.size() % 2 != 0) {
|
230
|
-
PrintLine("Error decoding value: %s", value.c_str());
|
231
|
-
return false;
|
232
|
-
}
|
233
|
-
out->reserve(value.size() / 2);
|
234
|
-
for (size_t i = 0; i < value.size(); i += 2) {
|
235
|
-
uint8_t hi, lo;
|
236
|
-
if (!FromHexDigit(&hi, value[i]) || !FromHexDigit(&lo, value[i+1])) {
|
237
|
-
PrintLine("Error decoding value: %s", value.c_str());
|
238
|
-
return false;
|
239
|
-
}
|
240
|
-
out->push_back((hi << 4) | lo);
|
241
|
-
}
|
242
|
-
return true;
|
243
|
-
}
|
244
|
-
|
245
|
-
bool FileTest::GetBytes(std::vector<uint8_t> *out, const std::string &key) {
|
246
|
-
bool is_default;
|
247
|
-
if (!GetBytesOrDefault(out, &is_default, key)) {
|
248
|
-
return false;
|
249
|
-
}
|
250
|
-
if (is_default) {
|
251
|
-
return false;
|
252
|
-
}
|
253
|
-
return true;
|
254
|
-
}
|
255
|
-
|
256
|
-
static std::string EncodeHex(const uint8_t *in, size_t in_len) {
|
257
|
-
static const char kHexDigits[] = "0123456789abcdef";
|
258
|
-
std::string ret;
|
259
|
-
ret.reserve(in_len * 2);
|
260
|
-
for (size_t i = 0; i < in_len; i++) {
|
261
|
-
ret += kHexDigits[in[i] >> 4];
|
262
|
-
ret += kHexDigits[in[i] & 0xf];
|
263
|
-
}
|
264
|
-
return ret;
|
265
|
-
}
|
266
|
-
|
267
|
-
bool FileTest::ExpectBytesEqual(const uint8_t *expected, size_t expected_len,
|
268
|
-
const uint8_t *actual, size_t actual_len) {
|
269
|
-
if (expected_len == actual_len &&
|
270
|
-
memcmp(expected, actual, expected_len) == 0) {
|
271
|
-
return true;
|
272
|
-
}
|
273
|
-
|
274
|
-
std::string expected_hex = EncodeHex(expected, expected_len);
|
275
|
-
std::string actual_hex = EncodeHex(actual, actual_len);
|
276
|
-
PrintLine("Expected: %s", expected_hex.c_str());
|
277
|
-
PrintLine("Actual: %s", actual_hex.c_str());
|
278
|
-
return false;
|
279
|
-
}
|
280
|
-
|
281
|
-
void FileTest::ClearTest() {
|
282
|
-
start_line_ = 0;
|
283
|
-
type_.clear();
|
284
|
-
parameter_.clear();
|
285
|
-
attributes_.clear();
|
286
|
-
block_.clear();
|
287
|
-
unused_attributes_.clear();
|
288
|
-
used_block_ = false;
|
289
|
-
}
|
290
|
-
|
291
|
-
void FileTest::OnKeyUsed(const std::string &key) {
|
292
|
-
unused_attributes_.erase(key);
|
293
|
-
}
|
294
|
-
|
295
|
-
int FileTestMain(bool (*run_test)(FileTest *t, void *arg), void *arg,
|
296
|
-
const char *path) {
|
297
|
-
FileTest t(path);
|
298
|
-
if (!t.is_open()) {
|
299
|
-
return 1;
|
300
|
-
}
|
301
|
-
|
302
|
-
bool failed = false;
|
303
|
-
while (true) {
|
304
|
-
FileTest::ReadResult ret = t.ReadNext();
|
305
|
-
if (ret == FileTest::kReadError) {
|
306
|
-
return 1;
|
307
|
-
} else if (ret == FileTest::kReadEOF) {
|
308
|
-
break;
|
309
|
-
}
|
310
|
-
|
311
|
-
bool result = run_test(&t, arg);
|
312
|
-
if (!result) {
|
313
|
-
// In case the test itself doesn't print output, print something so the
|
314
|
-
// line number is reported.
|
315
|
-
t.PrintLine("Test failed");
|
316
|
-
failed = true;
|
317
|
-
continue;
|
318
|
-
}
|
319
|
-
}
|
320
|
-
|
321
|
-
if (failed) {
|
322
|
-
return 1;
|
323
|
-
}
|
324
|
-
|
325
|
-
return 0;
|
326
|
-
}
|