ring-native 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,18 @@
|
|
|
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
|
+
/* This header is provided in order to make compiling against code that expects
|
|
16
|
+
OpenSSL easier. */
|
|
17
|
+
|
|
18
|
+
#include "buf.h"
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/* Copyright (c) 2014, 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
|
+
#ifndef OPENSSL_HEADER_BYTESTRING_H
|
|
16
|
+
#define OPENSSL_HEADER_BYTESTRING_H
|
|
17
|
+
|
|
18
|
+
#include <openssl/base.h>
|
|
19
|
+
|
|
20
|
+
#if defined(__cplusplus)
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/* Bytestrings are used for parsing and building TLS and ASN.1 messages.
|
|
26
|
+
*
|
|
27
|
+
* A "CBS" (CRYPTO ByteString) represents a string of bytes in memory and
|
|
28
|
+
* provides utility functions for safely parsing length-prefixed structures
|
|
29
|
+
* like TLS and ASN.1 from it.
|
|
30
|
+
*
|
|
31
|
+
* A "CBB" (CRYPTO ByteBuilder) is a memory buffer that grows as needed and
|
|
32
|
+
* provides utility functions for building length-prefixed messages. */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/* CRYPTO ByteString */
|
|
36
|
+
|
|
37
|
+
struct cbs_st {
|
|
38
|
+
const uint8_t *data;
|
|
39
|
+
size_t len;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/* CBS_init sets |cbs| to point to |data|. It does not take ownership of
|
|
43
|
+
* |data|. */
|
|
44
|
+
OPENSSL_EXPORT void CBS_init(CBS *cbs, const uint8_t *data, size_t len);
|
|
45
|
+
|
|
46
|
+
/* CBS_data returns a pointer to the contents of |cbs|. */
|
|
47
|
+
OPENSSL_EXPORT const uint8_t *CBS_data(const CBS *cbs);
|
|
48
|
+
|
|
49
|
+
/* CBS_len returns the number of bytes remaining in |cbs|. */
|
|
50
|
+
OPENSSL_EXPORT size_t CBS_len(const CBS *cbs);
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/* Parsing ASN.1 */
|
|
54
|
+
|
|
55
|
+
#define CBS_ASN1_BOOLEAN 0x1
|
|
56
|
+
#define CBS_ASN1_INTEGER 0x2
|
|
57
|
+
#define CBS_ASN1_BITSTRING 0x3
|
|
58
|
+
#define CBS_ASN1_OCTETSTRING 0x4
|
|
59
|
+
#define CBS_ASN1_NULL 0x5
|
|
60
|
+
#define CBS_ASN1_OBJECT 0x6
|
|
61
|
+
#define CBS_ASN1_ENUMERATED 0xa
|
|
62
|
+
#define CBS_ASN1_SEQUENCE (0x10 | CBS_ASN1_CONSTRUCTED)
|
|
63
|
+
#define CBS_ASN1_SET (0x11 | CBS_ASN1_CONSTRUCTED)
|
|
64
|
+
#define CBS_ASN1_GENERALIZEDTIME 0x18
|
|
65
|
+
|
|
66
|
+
#define CBS_ASN1_CONSTRUCTED 0x20
|
|
67
|
+
#define CBS_ASN1_CONTEXT_SPECIFIC 0x80
|
|
68
|
+
|
|
69
|
+
/* CBS_get_asn1 sets |*out| to the contents of DER-encoded, ASN.1 element (not
|
|
70
|
+
* including tag and length bytes) and advances |cbs| over it. The ASN.1
|
|
71
|
+
* element must match |tag_value|. It returns one on success and zero
|
|
72
|
+
* on error.
|
|
73
|
+
*
|
|
74
|
+
* Tag numbers greater than 30 are not supported (i.e. short form only). */
|
|
75
|
+
OPENSSL_EXPORT int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value);
|
|
76
|
+
|
|
77
|
+
/* CBS_get_asn1_element acts like |CBS_get_asn1| but |out| will include the
|
|
78
|
+
* ASN.1 header bytes too. */
|
|
79
|
+
OPENSSL_EXPORT int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value);
|
|
80
|
+
|
|
81
|
+
/* CBS_peek_asn1_tag looks ahead at the next ASN.1 tag and returns one
|
|
82
|
+
* if the next ASN.1 element on |cbs| would have tag |tag_value|. If
|
|
83
|
+
* |cbs| is empty or the tag does not match, it returns zero. Note: if
|
|
84
|
+
* it returns one, CBS_get_asn1 may still fail if the rest of the
|
|
85
|
+
* element is malformed. */
|
|
86
|
+
OPENSSL_EXPORT int CBS_peek_asn1_tag(const CBS *cbs, unsigned tag_value);
|
|
87
|
+
|
|
88
|
+
/* CBS_get_asn1_uint64 gets an ASN.1 INTEGER from |cbs| using |CBS_get_asn1|
|
|
89
|
+
* and sets |*out| to its value. It returns one on success and zero on error,
|
|
90
|
+
* where error includes the integer being negative, or too large to represent
|
|
91
|
+
* in 64 bits. */
|
|
92
|
+
OPENSSL_EXPORT int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out);
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/* CRYPTO ByteBuilder.
|
|
96
|
+
*
|
|
97
|
+
* |CBB| objects allow one to build length-prefixed serialisations. A |CBB|
|
|
98
|
+
* object is associated with a buffer and new buffers are created with
|
|
99
|
+
* |CBB_init|. Several |CBB| objects can point at the same buffer when a
|
|
100
|
+
* length-prefix is pending, however only a single |CBB| can be 'current' at
|
|
101
|
+
* any one time. For example, if one calls |CBB_add_u8_length_prefixed| then
|
|
102
|
+
* the new |CBB| points at the same buffer as the original. But if the original
|
|
103
|
+
* |CBB| is used then the length prefix is written out and the new |CBB| must
|
|
104
|
+
* not be used again.
|
|
105
|
+
*
|
|
106
|
+
* If one needs to force a length prefix to be written out because a |CBB| is
|
|
107
|
+
* going out of scope, use |CBB_flush|. */
|
|
108
|
+
|
|
109
|
+
struct cbb_buffer_st {
|
|
110
|
+
uint8_t *buf;
|
|
111
|
+
size_t len; /* The number of valid bytes. */
|
|
112
|
+
size_t cap; /* The size of buf. */
|
|
113
|
+
char can_resize; /* One iff |buf| is owned by this object. If not then |buf|
|
|
114
|
+
cannot be resized. */
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
struct cbb_st {
|
|
118
|
+
struct cbb_buffer_st *base;
|
|
119
|
+
/* offset is the offset from the start of |base->buf| to the position of any
|
|
120
|
+
* pending length-prefix. */
|
|
121
|
+
size_t offset;
|
|
122
|
+
/* child points to a child CBB if a length-prefix is pending. */
|
|
123
|
+
CBB *child;
|
|
124
|
+
/* pending_len_len contains the number of bytes in a pending length-prefix,
|
|
125
|
+
* or zero if no length-prefix is pending. */
|
|
126
|
+
uint8_t pending_len_len;
|
|
127
|
+
char pending_is_asn1;
|
|
128
|
+
/* is_top_level is true iff this is a top-level |CBB| (as opposed to a child
|
|
129
|
+
* |CBB|). Top-level objects are valid arguments for |CBB_finish|. */
|
|
130
|
+
char is_top_level;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/* CBB_zero sets an uninitialised |cbb| to the zero state. It must be
|
|
134
|
+
* initialised with |CBB_init| or |CBB_init_fixed| before use, but it is safe to
|
|
135
|
+
* call |CBB_cleanup| without a successful |CBB_init|. This may be used for more
|
|
136
|
+
* uniform cleanup of a |CBB|. */
|
|
137
|
+
OPENSSL_EXPORT void CBB_zero(CBB *cbb);
|
|
138
|
+
|
|
139
|
+
/* CBB_init initialises |cbb| with |initial_capacity|. Since a |CBB| grows as
|
|
140
|
+
* needed, the |initial_capacity| is just a hint. It returns one on success or
|
|
141
|
+
* zero on error. */
|
|
142
|
+
OPENSSL_EXPORT int CBB_init(CBB *cbb, size_t initial_capacity);
|
|
143
|
+
|
|
144
|
+
/* CBB_init_fixed initialises |cbb| to write to |len| bytes at |buf|. Since
|
|
145
|
+
* |buf| cannot grow, trying to write more than |len| bytes will cause CBB
|
|
146
|
+
* functions to fail. It returns one on success or zero on error. */
|
|
147
|
+
OPENSSL_EXPORT int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len);
|
|
148
|
+
|
|
149
|
+
/* CBB_cleanup frees all resources owned by |cbb| and other |CBB| objects
|
|
150
|
+
* writing to the same buffer. This should be used in an error case where a
|
|
151
|
+
* serialisation is abandoned.
|
|
152
|
+
*
|
|
153
|
+
* This function can only be called on a "top level" |CBB|, i.e. one initialised
|
|
154
|
+
* with |CBB_init| or |CBB_init_fixed|, or a |CBB| set to the zero state with
|
|
155
|
+
* |CBB_zero|. */
|
|
156
|
+
OPENSSL_EXPORT void CBB_cleanup(CBB *cbb);
|
|
157
|
+
|
|
158
|
+
/* CBB_finish completes any pending length prefix and sets |*out_data| to a
|
|
159
|
+
* malloced buffer and |*out_len| to the length of that buffer. The caller
|
|
160
|
+
* takes ownership of the buffer and, unless the buffer was fixed with
|
|
161
|
+
* |CBB_init_fixed|, must call |OPENSSL_free| when done.
|
|
162
|
+
*
|
|
163
|
+
* It can only be called on a "top level" |CBB|, i.e. one initialised with
|
|
164
|
+
* |CBB_init| or |CBB_init_fixed|. It returns one on success and zero on
|
|
165
|
+
* error. */
|
|
166
|
+
OPENSSL_EXPORT int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len);
|
|
167
|
+
|
|
168
|
+
/* CBB_flush causes any pending length prefixes to be written out and any child
|
|
169
|
+
* |CBB| objects of |cbb| to be invalidated. It returns one on success or zero
|
|
170
|
+
* on error. */
|
|
171
|
+
OPENSSL_EXPORT int CBB_flush(CBB *cbb);
|
|
172
|
+
|
|
173
|
+
/* CBB_len returns the number of bytes written to |cbb|'s top-level |CBB|. It
|
|
174
|
+
* may be compared before and after an operation to determine how many bytes
|
|
175
|
+
* were written.
|
|
176
|
+
*
|
|
177
|
+
* It is a fatal error to call this on a CBB with any active children. This does
|
|
178
|
+
* not flush |cbb|. */
|
|
179
|
+
OPENSSL_EXPORT size_t CBB_len(const CBB *cbb);
|
|
180
|
+
|
|
181
|
+
/* CBB_add_u8_length_prefixed sets |*out_contents| to a new child of |cbb|. The
|
|
182
|
+
* data written to |*out_contents| will be prefixed in |cbb| with an 8-bit
|
|
183
|
+
* length. It returns one on success or zero on error. */
|
|
184
|
+
OPENSSL_EXPORT int CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents);
|
|
185
|
+
|
|
186
|
+
/* CBB_add_u16_length_prefixed sets |*out_contents| to a new child of |cbb|.
|
|
187
|
+
* The data written to |*out_contents| will be prefixed in |cbb| with a 16-bit,
|
|
188
|
+
* big-endian length. It returns one on success or zero on error. */
|
|
189
|
+
OPENSSL_EXPORT int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents);
|
|
190
|
+
|
|
191
|
+
/* CBB_add_u24_length_prefixed sets |*out_contents| to a new child of |cbb|.
|
|
192
|
+
* The data written to |*out_contents| will be prefixed in |cbb| with a 24-bit,
|
|
193
|
+
* big-endian length. It returns one on success or zero on error. */
|
|
194
|
+
OPENSSL_EXPORT int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
|
|
195
|
+
|
|
196
|
+
/* CBB_add_asn1 sets |*out_contents| to a |CBB| into which the contents of an
|
|
197
|
+
* ASN.1 object can be written. The |tag| argument will be used as the tag for
|
|
198
|
+
* the object. Passing in |tag| number 31 will return in an error since only
|
|
199
|
+
* single octet identifiers are supported. It returns one on success or zero
|
|
200
|
+
* on error. */
|
|
201
|
+
OPENSSL_EXPORT int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag);
|
|
202
|
+
|
|
203
|
+
/* CBB_add_bytes appends |len| bytes from |data| to |cbb|. It returns one on
|
|
204
|
+
* success and zero otherwise. */
|
|
205
|
+
OPENSSL_EXPORT int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len);
|
|
206
|
+
|
|
207
|
+
/* CBB_add_space appends |len| bytes to |cbb| and sets |*out_data| to point to
|
|
208
|
+
* the beginning of that space. The caller must then write |len| bytes of
|
|
209
|
+
* actual contents to |*out_data|. It returns one on success and zero
|
|
210
|
+
* otherwise. */
|
|
211
|
+
OPENSSL_EXPORT int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len);
|
|
212
|
+
|
|
213
|
+
/* CBB_add_u8 appends an 8-bit number from |value| to |cbb|. It returns one on
|
|
214
|
+
* success and zero otherwise. */
|
|
215
|
+
OPENSSL_EXPORT int CBB_add_u8(CBB *cbb, uint8_t value);
|
|
216
|
+
|
|
217
|
+
/* CBB_add_u16 appends a 16-bit, big-endian number from |value| to |cbb|. It
|
|
218
|
+
* returns one on success and zero otherwise. */
|
|
219
|
+
OPENSSL_EXPORT int CBB_add_u16(CBB *cbb, uint16_t value);
|
|
220
|
+
|
|
221
|
+
/* CBB_add_u24 appends a 24-bit, big-endian number from |value| to |cbb|. It
|
|
222
|
+
* returns one on success and zero otherwise. */
|
|
223
|
+
OPENSSL_EXPORT int CBB_add_u24(CBB *cbb, uint32_t value);
|
|
224
|
+
|
|
225
|
+
/* CBB_add_asn1_uint64 writes an ASN.1 INTEGER into |cbb| using |CBB_add_asn1|
|
|
226
|
+
* and writes |value| in its contents. It returns one on success and zero on
|
|
227
|
+
* error. */
|
|
228
|
+
OPENSSL_EXPORT int CBB_add_asn1_uint64(CBB *cbb, uint64_t value);
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
#if defined(__cplusplus)
|
|
232
|
+
} /* extern C */
|
|
233
|
+
#endif
|
|
234
|
+
|
|
235
|
+
#endif /* OPENSSL_HEADER_BYTESTRING_H */
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* Copyright (c) 2014, 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
|
+
#ifndef OPENSSL_HEADER_CHACHA_H
|
|
16
|
+
#define OPENSSL_HEADER_CHACHA_H
|
|
17
|
+
|
|
18
|
+
#include <openssl/base.h>
|
|
19
|
+
|
|
20
|
+
#ifdef __cplusplus
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/* CRYPTO_chacha_20 encrypts |in_len| bytes from |in| with the given key and
|
|
26
|
+
* nonce and writes the result to |out|, which may be equal to |in|. The
|
|
27
|
+
* initial block counter is specified by |counter|. */
|
|
28
|
+
OPENSSL_EXPORT void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in,
|
|
29
|
+
size_t in_len, const uint8_t key[32],
|
|
30
|
+
const uint8_t nonce[12], uint32_t counter);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#if defined(__cplusplus)
|
|
34
|
+
} /* extern C */
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#endif /* OPENSSL_HEADER_CHACHA_H */
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
#ifndef OPENSSL_HEADER_CMAC_H
|
|
16
|
+
#define OPENSSL_HEADER_CMAC_H
|
|
17
|
+
|
|
18
|
+
#include <openssl/base.h>
|
|
19
|
+
|
|
20
|
+
#if defined(__cplusplus)
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/* CMAC.
|
|
26
|
+
*
|
|
27
|
+
* CMAC is a MAC based on AES-CBC and defined in
|
|
28
|
+
* https://tools.ietf.org/html/rfc4493#section-2.3. */
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/* One-shot functions. */
|
|
32
|
+
|
|
33
|
+
/* AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of
|
|
34
|
+
* |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select
|
|
35
|
+
* between AES-128 and AES-256. It returns one on success or zero on error. */
|
|
36
|
+
OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len,
|
|
37
|
+
const uint8_t *in, size_t in_len);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/* Incremental interface. */
|
|
41
|
+
|
|
42
|
+
/* CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
|
|
43
|
+
* error. */
|
|
44
|
+
OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void);
|
|
45
|
+
|
|
46
|
+
/* CMAC_CTX_free frees a |CMAC_CTX|. */
|
|
47
|
+
OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx);
|
|
48
|
+
|
|
49
|
+
/* CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC
|
|
50
|
+
* only specifies the use of AES-128 thus |key_len| should be 16 and |cipher|
|
|
51
|
+
* should be |EVP_aes_128_cbc()|. However, this implementation also supports
|
|
52
|
+
* AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The
|
|
53
|
+
* |engine| argument is ignored.
|
|
54
|
+
*
|
|
55
|
+
* It returns one on success or zero on error. */
|
|
56
|
+
OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
|
|
57
|
+
const EVP_CIPHER *cipher, ENGINE *engine);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/* CMAC_Reset resets |ctx| so that a fresh message can be authenticated. */
|
|
61
|
+
OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx);
|
|
62
|
+
|
|
63
|
+
/* CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
|
|
64
|
+
* success or zero on error. */
|
|
65
|
+
OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
|
|
66
|
+
|
|
67
|
+
/* CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes
|
|
68
|
+
* of authenticator to it. It returns one on success or zero on error. */
|
|
69
|
+
OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
#if defined(__cplusplus)
|
|
73
|
+
} /* extern C */
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
#endif /* OPENSSL_HEADER_CMAC_H */
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
* This product includes cryptographic software written by Eric Young
|
|
58
|
+
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
59
|
+
* Hudson (tjh@cryptsoft.com). */
|
|
60
|
+
|
|
61
|
+
#ifndef OPENSSL_HEADER_CPU_H
|
|
62
|
+
#define OPENSSL_HEADER_CPU_H
|
|
63
|
+
|
|
64
|
+
#include <openssl/base.h>
|
|
65
|
+
|
|
66
|
+
#if defined(__cplusplus)
|
|
67
|
+
extern "C" {
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/* Runtime CPU feature support */
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
|
75
|
+
/* OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or
|
|
76
|
+
* x86-64 system.
|
|
77
|
+
*
|
|
78
|
+
* Index 0:
|
|
79
|
+
* EDX for CPUID where EAX = 1
|
|
80
|
+
* Bit 20 is always zero
|
|
81
|
+
* Bit 28 is adjusted to reflect whether the data cache is shared between
|
|
82
|
+
* multiple logical cores
|
|
83
|
+
* Bit 30 is used to indicate an Intel CPU
|
|
84
|
+
* Index 1:
|
|
85
|
+
* ECX for CPUID where EAX = 1
|
|
86
|
+
* Bit 11 is used to indicate AMD XOP support, not SDBG
|
|
87
|
+
* Index 2:
|
|
88
|
+
* EBX for CPUID where EAX = 7
|
|
89
|
+
* Index 3 is set to zero.
|
|
90
|
+
*
|
|
91
|
+
* Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM
|
|
92
|
+
* bits in XCR0, so it is not necessary to check those. */
|
|
93
|
+
extern uint32_t OPENSSL_ia32cap_P[4];
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
|
97
|
+
|
|
98
|
+
#if defined(OPENSSL_APPLE)
|
|
99
|
+
/* iOS builds use the static ARM configuration. */
|
|
100
|
+
#define OPENSSL_STATIC_ARMCAP
|
|
101
|
+
#endif
|
|
102
|
+
|
|
103
|
+
#if !defined(OPENSSL_STATIC_ARMCAP)
|
|
104
|
+
|
|
105
|
+
/* CRYPTO_is_NEON_capable_at_runtime returns true if the current CPU has a NEON
|
|
106
|
+
* unit. Note that |OPENSSL_armcap_P| also exists and contains the same
|
|
107
|
+
* information in a form that's easier for assembly to use. */
|
|
108
|
+
OPENSSL_EXPORT char CRYPTO_is_NEON_capable_at_runtime(void);
|
|
109
|
+
|
|
110
|
+
/* CRYPTO_is_NEON_capable returns true if the current CPU has a NEON unit. If
|
|
111
|
+
* this is known statically then it returns one immediately. */
|
|
112
|
+
static inline int CRYPTO_is_NEON_capable(void) {
|
|
113
|
+
#if defined(__ARM_NEON__)
|
|
114
|
+
return 1;
|
|
115
|
+
#else
|
|
116
|
+
return CRYPTO_is_NEON_capable_at_runtime();
|
|
117
|
+
#endif
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* CRYPTO_set_NEON_capable sets the return value of |CRYPTO_is_NEON_capable|.
|
|
121
|
+
* By default, unless the code was compiled with |-mfpu=neon|, NEON is assumed
|
|
122
|
+
* not to be present. It is not autodetected. Calling this with a zero
|
|
123
|
+
* argument also causes |CRYPTO_is_NEON_functional| to return false. */
|
|
124
|
+
OPENSSL_EXPORT void CRYPTO_set_NEON_capable(char neon_capable);
|
|
125
|
+
|
|
126
|
+
/* CRYPTO_is_NEON_functional returns true if the current CPU has a /working/
|
|
127
|
+
* NEON unit. Some phones have a NEON unit, but the Poly1305 NEON code causes
|
|
128
|
+
* it to fail. See https://code.google.com/p/chromium/issues/detail?id=341598 */
|
|
129
|
+
OPENSSL_EXPORT char CRYPTO_is_NEON_functional(void);
|
|
130
|
+
|
|
131
|
+
/* CRYPTO_set_NEON_functional sets the "NEON functional" flag. For
|
|
132
|
+
* |CRYPTO_is_NEON_functional| to return true, both this flag and the NEON flag
|
|
133
|
+
* must be true. By default NEON is assumed to be functional if the code was
|
|
134
|
+
* compiled with |-mfpu=neon| or if |CRYPTO_set_NEON_capable| has been called
|
|
135
|
+
* with a non-zero argument. */
|
|
136
|
+
OPENSSL_EXPORT void CRYPTO_set_NEON_functional(char neon_functional);
|
|
137
|
+
|
|
138
|
+
/* CRYPTO_is_ARMv8_AES_capable returns true if the current CPU supports the
|
|
139
|
+
* ARMv8 AES instruction. */
|
|
140
|
+
int CRYPTO_is_ARMv8_AES_capable(void);
|
|
141
|
+
|
|
142
|
+
/* CRYPTO_is_ARMv8_PMULL_capable returns true if the current CPU supports the
|
|
143
|
+
* ARMv8 PMULL instruction. */
|
|
144
|
+
int CRYPTO_is_ARMv8_PMULL_capable(void);
|
|
145
|
+
|
|
146
|
+
#else
|
|
147
|
+
|
|
148
|
+
static inline int CRYPTO_is_NEON_capable(void) {
|
|
149
|
+
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON__)
|
|
150
|
+
return 1;
|
|
151
|
+
#else
|
|
152
|
+
return 0;
|
|
153
|
+
#endif
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static inline int CRYPTO_is_NEON_functional(void) {
|
|
157
|
+
return CRYPTO_is_NEON_capable();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static inline int CRYPTO_is_ARMv8_AES_capable(void) {
|
|
161
|
+
#if defined(OPENSSL_STATIC_ARMCAP_AES)
|
|
162
|
+
return 1;
|
|
163
|
+
#else
|
|
164
|
+
return 0;
|
|
165
|
+
#endif
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static inline int CRYPTO_is_ARMv8_PMULL_capable(void) {
|
|
169
|
+
#if defined(OPENSSL_STATIC_ARMCAP_PMULL)
|
|
170
|
+
return 1;
|
|
171
|
+
#else
|
|
172
|
+
return 0;
|
|
173
|
+
#endif
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#endif /* OPENSSL_STATIC_ARMCAP */
|
|
177
|
+
#endif /* OPENSSL_ARM */
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
#if defined(__cplusplus)
|
|
181
|
+
} /* extern C */
|
|
182
|
+
#endif
|
|
183
|
+
|
|
184
|
+
#endif /* OPENSSL_HEADER_CPU_H */
|