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,87 @@
|
|
1
|
+
/* ====================================================================
|
2
|
+
* Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions
|
6
|
+
* are met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. All advertising materials mentioning features or use of this
|
17
|
+
* software must display the following acknowledgment:
|
18
|
+
* "This product includes software developed by the OpenSSL Project
|
19
|
+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
20
|
+
*
|
21
|
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
22
|
+
* endorse or promote products derived from this software without
|
23
|
+
* prior written permission. For written permission, please contact
|
24
|
+
* openssl-core@openssl.org.
|
25
|
+
*
|
26
|
+
* 5. Products derived from this software may not be called "OpenSSL"
|
27
|
+
* nor may "OpenSSL" appear in their names without prior written
|
28
|
+
* permission of the OpenSSL Project.
|
29
|
+
*
|
30
|
+
* 6. Redistributions of any form whatsoever must retain the following
|
31
|
+
* acknowledgment:
|
32
|
+
* "This product includes software developed by the OpenSSL Project
|
33
|
+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
34
|
+
*
|
35
|
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
36
|
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
37
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
38
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
39
|
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
41
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
42
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
43
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
44
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
45
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
46
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
|
+
* ==================================================================== */
|
48
|
+
|
49
|
+
#ifndef OPENSSL_HEADER_AES_INTERNAL_H
|
50
|
+
#define OPENSSL_HEADER_AES_INTERNAL_H
|
51
|
+
|
52
|
+
#include <openssl/base.h>
|
53
|
+
|
54
|
+
#if defined(__cplusplus)
|
55
|
+
extern "C" {
|
56
|
+
#endif
|
57
|
+
|
58
|
+
|
59
|
+
#if defined(_MSC_VER) && \
|
60
|
+
(defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
|
61
|
+
#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
62
|
+
#define GETU32(p) SWAP(*((uint32_t *)(p)))
|
63
|
+
#define PUTU32(ct, st) \
|
64
|
+
{ *((uint32_t *)(ct)) = SWAP((st)); }
|
65
|
+
#else
|
66
|
+
#define GETU32(pt) \
|
67
|
+
(((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ \
|
68
|
+
((uint32_t)(pt)[2] << 8) ^ ((uint32_t)(pt)[3]))
|
69
|
+
#define PUTU32(ct, st) \
|
70
|
+
{ \
|
71
|
+
(ct)[0] = (uint8_t)((st) >> 24); \
|
72
|
+
(ct)[1] = (uint8_t)((st) >> 16); \
|
73
|
+
(ct)[2] = (uint8_t)((st) >> 8); \
|
74
|
+
(ct)[3] = (uint8_t)(st); \
|
75
|
+
}
|
76
|
+
#endif
|
77
|
+
|
78
|
+
#define MAXKC (256 / 32)
|
79
|
+
#define MAXKB (256 / 8)
|
80
|
+
#define MAXNR 14
|
81
|
+
|
82
|
+
|
83
|
+
#if defined(__cplusplus)
|
84
|
+
} /* extern C */
|
85
|
+
#endif
|
86
|
+
|
87
|
+
#endif /* OPENSSL_HEADER_AES_INTERNAL_H */
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/* ====================================================================
|
2
|
+
* Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions
|
6
|
+
* are met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. All advertising materials mentioning features or use of this
|
17
|
+
* software must display the following acknowledgment:
|
18
|
+
* "This product includes software developed by the OpenSSL Project
|
19
|
+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
20
|
+
*
|
21
|
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
22
|
+
* endorse or promote products derived from this software without
|
23
|
+
* prior written permission. For written permission, please contact
|
24
|
+
* openssl-core@openssl.org.
|
25
|
+
*
|
26
|
+
* 5. Products derived from this software may not be called "OpenSSL"
|
27
|
+
* nor may "OpenSSL" appear in their names without prior written
|
28
|
+
* permission of the OpenSSL Project.
|
29
|
+
*
|
30
|
+
* 6. Redistributions of any form whatsoever must retain the following
|
31
|
+
* acknowledgment:
|
32
|
+
* "This product includes software developed by the OpenSSL Project
|
33
|
+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
34
|
+
*
|
35
|
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
36
|
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
37
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
38
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
39
|
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
41
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
42
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
43
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
44
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
45
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
46
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
|
+
* ==================================================================== */
|
48
|
+
|
49
|
+
#include <openssl/aes.h>
|
50
|
+
|
51
|
+
#include <assert.h>
|
52
|
+
|
53
|
+
#include "../modes/internal.h"
|
54
|
+
|
55
|
+
|
56
|
+
void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
57
|
+
const AES_KEY *key, uint8_t ivec[AES_BLOCK_SIZE],
|
58
|
+
uint8_t ecount_buf[AES_BLOCK_SIZE], unsigned int *num) {
|
59
|
+
CRYPTO_ctr128_encrypt(in, out, len, key, ivec, ecount_buf, num,
|
60
|
+
(block128_f)AES_encrypt);
|
61
|
+
}
|
@@ -0,0 +1,394 @@
|
|
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/bn.h>
|
58
|
+
|
59
|
+
#include <openssl/err.h>
|
60
|
+
#include <openssl/mem.h>
|
61
|
+
|
62
|
+
#include "internal.h"
|
63
|
+
|
64
|
+
|
65
|
+
int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
66
|
+
const BIGNUM *tmp;
|
67
|
+
int a_neg = a->neg, ret;
|
68
|
+
|
69
|
+
/* a + b a+b
|
70
|
+
* a + -b a-b
|
71
|
+
* -a + b b-a
|
72
|
+
* -a + -b -(a+b)
|
73
|
+
*/
|
74
|
+
if (a_neg ^ b->neg) {
|
75
|
+
/* only one is negative */
|
76
|
+
if (a_neg) {
|
77
|
+
tmp = a;
|
78
|
+
a = b;
|
79
|
+
b = tmp;
|
80
|
+
}
|
81
|
+
|
82
|
+
/* we are now a - b */
|
83
|
+
if (BN_ucmp(a, b) < 0) {
|
84
|
+
if (!BN_usub(r, b, a)) {
|
85
|
+
return 0;
|
86
|
+
}
|
87
|
+
r->neg = 1;
|
88
|
+
} else {
|
89
|
+
if (!BN_usub(r, a, b)) {
|
90
|
+
return 0;
|
91
|
+
}
|
92
|
+
r->neg = 0;
|
93
|
+
}
|
94
|
+
return 1;
|
95
|
+
}
|
96
|
+
|
97
|
+
ret = BN_uadd(r, a, b);
|
98
|
+
r->neg = a_neg;
|
99
|
+
return ret;
|
100
|
+
}
|
101
|
+
|
102
|
+
int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
103
|
+
int max, min, dif;
|
104
|
+
BN_ULONG *ap, *bp, *rp, carry, t1, t2;
|
105
|
+
const BIGNUM *tmp;
|
106
|
+
|
107
|
+
if (a->top < b->top) {
|
108
|
+
tmp = a;
|
109
|
+
a = b;
|
110
|
+
b = tmp;
|
111
|
+
}
|
112
|
+
max = a->top;
|
113
|
+
min = b->top;
|
114
|
+
dif = max - min;
|
115
|
+
|
116
|
+
if (bn_wexpand(r, max + 1) == NULL) {
|
117
|
+
return 0;
|
118
|
+
}
|
119
|
+
|
120
|
+
r->top = max;
|
121
|
+
|
122
|
+
ap = a->d;
|
123
|
+
bp = b->d;
|
124
|
+
rp = r->d;
|
125
|
+
|
126
|
+
carry = bn_add_words(rp, ap, bp, min);
|
127
|
+
rp += min;
|
128
|
+
ap += min;
|
129
|
+
bp += min;
|
130
|
+
|
131
|
+
if (carry) {
|
132
|
+
while (dif) {
|
133
|
+
dif--;
|
134
|
+
t1 = *(ap++);
|
135
|
+
t2 = (t1 + 1) & BN_MASK2;
|
136
|
+
*(rp++) = t2;
|
137
|
+
if (t2) {
|
138
|
+
carry = 0;
|
139
|
+
break;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
if (carry) {
|
143
|
+
/* carry != 0 => dif == 0 */
|
144
|
+
*rp = 1;
|
145
|
+
r->top++;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
if (dif && rp != ap) {
|
150
|
+
while (dif--) {
|
151
|
+
/* copy remaining words if ap != rp */
|
152
|
+
*(rp++) = *(ap++);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
r->neg = 0;
|
157
|
+
return 1;
|
158
|
+
}
|
159
|
+
|
160
|
+
int BN_add_word(BIGNUM *a, BN_ULONG w) {
|
161
|
+
BN_ULONG l;
|
162
|
+
int i;
|
163
|
+
|
164
|
+
w &= BN_MASK2;
|
165
|
+
|
166
|
+
/* degenerate case: w is zero */
|
167
|
+
if (!w) {
|
168
|
+
return 1;
|
169
|
+
}
|
170
|
+
|
171
|
+
/* degenerate case: a is zero */
|
172
|
+
if (BN_is_zero(a)) {
|
173
|
+
return BN_set_word(a, w);
|
174
|
+
}
|
175
|
+
|
176
|
+
/* handle 'a' when negative */
|
177
|
+
if (a->neg) {
|
178
|
+
a->neg = 0;
|
179
|
+
i = BN_sub_word(a, w);
|
180
|
+
if (!BN_is_zero(a)) {
|
181
|
+
a->neg = !(a->neg);
|
182
|
+
}
|
183
|
+
return i;
|
184
|
+
}
|
185
|
+
|
186
|
+
for (i = 0; w != 0 && i < a->top; i++) {
|
187
|
+
a->d[i] = l = (a->d[i] + w) & BN_MASK2;
|
188
|
+
w = (w > l) ? 1 : 0;
|
189
|
+
}
|
190
|
+
|
191
|
+
if (w && i == a->top) {
|
192
|
+
if (bn_wexpand(a, a->top + 1) == NULL) {
|
193
|
+
return 0;
|
194
|
+
}
|
195
|
+
a->top++;
|
196
|
+
a->d[i] = w;
|
197
|
+
}
|
198
|
+
|
199
|
+
return 1;
|
200
|
+
}
|
201
|
+
|
202
|
+
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
203
|
+
int max;
|
204
|
+
int add = 0, neg = 0;
|
205
|
+
const BIGNUM *tmp;
|
206
|
+
|
207
|
+
/* a - b a-b
|
208
|
+
* a - -b a+b
|
209
|
+
* -a - b -(a+b)
|
210
|
+
* -a - -b b-a
|
211
|
+
*/
|
212
|
+
if (a->neg) {
|
213
|
+
if (b->neg) {
|
214
|
+
tmp = a;
|
215
|
+
a = b;
|
216
|
+
b = tmp;
|
217
|
+
} else {
|
218
|
+
add = 1;
|
219
|
+
neg = 1;
|
220
|
+
}
|
221
|
+
} else {
|
222
|
+
if (b->neg) {
|
223
|
+
add = 1;
|
224
|
+
neg = 0;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
if (add) {
|
229
|
+
if (!BN_uadd(r, a, b)) {
|
230
|
+
return 0;
|
231
|
+
}
|
232
|
+
|
233
|
+
r->neg = neg;
|
234
|
+
return 1;
|
235
|
+
}
|
236
|
+
|
237
|
+
/* We are actually doing a - b :-) */
|
238
|
+
|
239
|
+
max = (a->top > b->top) ? a->top : b->top;
|
240
|
+
if (bn_wexpand(r, max) == NULL) {
|
241
|
+
return 0;
|
242
|
+
}
|
243
|
+
|
244
|
+
if (BN_ucmp(a, b) < 0) {
|
245
|
+
if (!BN_usub(r, b, a)) {
|
246
|
+
return 0;
|
247
|
+
}
|
248
|
+
r->neg = 1;
|
249
|
+
} else {
|
250
|
+
if (!BN_usub(r, a, b)) {
|
251
|
+
return 0;
|
252
|
+
}
|
253
|
+
r->neg = 0;
|
254
|
+
}
|
255
|
+
|
256
|
+
return 1;
|
257
|
+
}
|
258
|
+
|
259
|
+
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
260
|
+
int max, min, dif;
|
261
|
+
register BN_ULONG t1, t2, *ap, *bp, *rp;
|
262
|
+
int i, carry;
|
263
|
+
|
264
|
+
max = a->top;
|
265
|
+
min = b->top;
|
266
|
+
dif = max - min;
|
267
|
+
|
268
|
+
if (dif < 0) /* hmm... should not be happening */
|
269
|
+
{
|
270
|
+
OPENSSL_PUT_ERROR(BN, BN_R_ARG2_LT_ARG3);
|
271
|
+
return 0;
|
272
|
+
}
|
273
|
+
|
274
|
+
if (bn_wexpand(r, max) == NULL) {
|
275
|
+
return 0;
|
276
|
+
}
|
277
|
+
|
278
|
+
ap = a->d;
|
279
|
+
bp = b->d;
|
280
|
+
rp = r->d;
|
281
|
+
|
282
|
+
carry = 0;
|
283
|
+
for (i = min; i != 0; i--) {
|
284
|
+
t1 = *(ap++);
|
285
|
+
t2 = *(bp++);
|
286
|
+
if (carry) {
|
287
|
+
carry = (t1 <= t2);
|
288
|
+
t1 = (t1 - t2 - 1) & BN_MASK2;
|
289
|
+
} else {
|
290
|
+
carry = (t1 < t2);
|
291
|
+
t1 = (t1 - t2) & BN_MASK2;
|
292
|
+
}
|
293
|
+
*(rp++) = t1 & BN_MASK2;
|
294
|
+
}
|
295
|
+
|
296
|
+
if (carry) /* subtracted */
|
297
|
+
{
|
298
|
+
if (!dif) {
|
299
|
+
/* error: a < b */
|
300
|
+
return 0;
|
301
|
+
}
|
302
|
+
|
303
|
+
while (dif) {
|
304
|
+
dif--;
|
305
|
+
t1 = *(ap++);
|
306
|
+
t2 = (t1 - 1) & BN_MASK2;
|
307
|
+
*(rp++) = t2;
|
308
|
+
if (t1) {
|
309
|
+
break;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
if (rp != ap) {
|
315
|
+
for (;;) {
|
316
|
+
if (!dif--) {
|
317
|
+
break;
|
318
|
+
}
|
319
|
+
rp[0] = ap[0];
|
320
|
+
if (!dif--) {
|
321
|
+
break;
|
322
|
+
}
|
323
|
+
rp[1] = ap[1];
|
324
|
+
if (!dif--) {
|
325
|
+
break;
|
326
|
+
}
|
327
|
+
rp[2] = ap[2];
|
328
|
+
if (!dif--) {
|
329
|
+
break;
|
330
|
+
}
|
331
|
+
rp[3] = ap[3];
|
332
|
+
rp += 4;
|
333
|
+
ap += 4;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
r->top = max;
|
338
|
+
r->neg = 0;
|
339
|
+
bn_correct_top(r);
|
340
|
+
|
341
|
+
return 1;
|
342
|
+
}
|
343
|
+
|
344
|
+
int BN_sub_word(BIGNUM *a, BN_ULONG w) {
|
345
|
+
int i;
|
346
|
+
|
347
|
+
w &= BN_MASK2;
|
348
|
+
|
349
|
+
/* degenerate case: w is zero */
|
350
|
+
if (!w) {
|
351
|
+
return 1;
|
352
|
+
}
|
353
|
+
|
354
|
+
/* degenerate case: a is zero */
|
355
|
+
if (BN_is_zero(a)) {
|
356
|
+
i = BN_set_word(a, w);
|
357
|
+
if (i != 0) {
|
358
|
+
BN_set_negative(a, 1);
|
359
|
+
}
|
360
|
+
return i;
|
361
|
+
}
|
362
|
+
|
363
|
+
/* handle 'a' when negative */
|
364
|
+
if (a->neg) {
|
365
|
+
a->neg = 0;
|
366
|
+
i = BN_add_word(a, w);
|
367
|
+
a->neg = 1;
|
368
|
+
return i;
|
369
|
+
}
|
370
|
+
|
371
|
+
if ((a->top == 1) && (a->d[0] < w)) {
|
372
|
+
a->d[0] = w - a->d[0];
|
373
|
+
a->neg = 1;
|
374
|
+
return 1;
|
375
|
+
}
|
376
|
+
|
377
|
+
i = 0;
|
378
|
+
for (;;) {
|
379
|
+
if (a->d[i] >= w) {
|
380
|
+
a->d[i] -= w;
|
381
|
+
break;
|
382
|
+
} else {
|
383
|
+
a->d[i] = (a->d[i] - w) & BN_MASK2;
|
384
|
+
i++;
|
385
|
+
w = 1;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
if ((a->d[i] == 0) && (i == (a->top - 1))) {
|
390
|
+
a->top--;
|
391
|
+
}
|
392
|
+
|
393
|
+
return 1;
|
394
|
+
}
|