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,155 @@
|
|
|
1
|
+
/* ====================================================================
|
|
2
|
+
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
|
3
|
+
*
|
|
4
|
+
* The Elliptic Curve Public-Key Crypto Library (ECC Code) included
|
|
5
|
+
* herein is developed by SUN MICROSYSTEMS, INC., and is contributed
|
|
6
|
+
* to the OpenSSL project.
|
|
7
|
+
*
|
|
8
|
+
* The ECC Code is licensed pursuant to the OpenSSL open source
|
|
9
|
+
* license provided below.
|
|
10
|
+
*
|
|
11
|
+
* The ECDH software is originally written by Douglas Stebila of
|
|
12
|
+
* Sun Microsystems Laboratories.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/* ====================================================================
|
|
16
|
+
* Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved.
|
|
17
|
+
*
|
|
18
|
+
* Redistribution and use in source and binary forms, with or without
|
|
19
|
+
* modification, are permitted provided that the following conditions
|
|
20
|
+
* are met:
|
|
21
|
+
*
|
|
22
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
23
|
+
* notice, this list of conditions and the following disclaimer.
|
|
24
|
+
*
|
|
25
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
26
|
+
* notice, this list of conditions and the following disclaimer in
|
|
27
|
+
* the documentation and/or other materials provided with the
|
|
28
|
+
* distribution.
|
|
29
|
+
*
|
|
30
|
+
* 3. All advertising materials mentioning features or use of this
|
|
31
|
+
* software must display the following acknowledgment:
|
|
32
|
+
* "This product includes software developed by the OpenSSL Project
|
|
33
|
+
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
|
34
|
+
*
|
|
35
|
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
|
36
|
+
* endorse or promote products derived from this software without
|
|
37
|
+
* prior written permission. For written permission, please contact
|
|
38
|
+
* licensing@OpenSSL.org.
|
|
39
|
+
*
|
|
40
|
+
* 5. Products derived from this software may not be called "OpenSSL"
|
|
41
|
+
* nor may "OpenSSL" appear in their names without prior written
|
|
42
|
+
* permission of the OpenSSL Project.
|
|
43
|
+
*
|
|
44
|
+
* 6. Redistributions of any form whatsoever must retain the following
|
|
45
|
+
* acknowledgment:
|
|
46
|
+
* "This product includes software developed by the OpenSSL Project
|
|
47
|
+
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
|
48
|
+
*
|
|
49
|
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
|
50
|
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
51
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
52
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
|
53
|
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
54
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
55
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
56
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
57
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
58
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
59
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
60
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
61
|
+
* ====================================================================
|
|
62
|
+
*
|
|
63
|
+
* This product includes cryptographic software written by Eric Young
|
|
64
|
+
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
65
|
+
* Hudson (tjh@cryptsoft.com). */
|
|
66
|
+
|
|
67
|
+
#include <openssl/ecdh.h>
|
|
68
|
+
|
|
69
|
+
#include <string.h>
|
|
70
|
+
|
|
71
|
+
#include <openssl/bn.h>
|
|
72
|
+
#include <openssl/err.h>
|
|
73
|
+
#include <openssl/mem.h>
|
|
74
|
+
#include <openssl/type_check.h>
|
|
75
|
+
|
|
76
|
+
#include "../ec/internal.h"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
int ECDH_compute_key_ex(uint8_t *out, size_t *out_len, size_t max_out_len,
|
|
80
|
+
const EC_KEY *priv_key, int peer_curve_nid,
|
|
81
|
+
const uint8_t *peer_pub_point_bytes,
|
|
82
|
+
size_t peer_pub_point_bytes_len) {
|
|
83
|
+
const EC_GROUP *group = EC_KEY_get0_group(priv_key);
|
|
84
|
+
if (peer_curve_nid != EC_GROUP_get_curve_name(group)) {
|
|
85
|
+
OPENSSL_PUT_ERROR(EC, EC_R_INCOMPATIBLE_OBJECTS);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
OPENSSL_COMPILE_ASSERT(sizeof(*out_len) >= sizeof(unsigned),
|
|
90
|
+
SIZE_T_IS_SMALLER_THAN_UNSIGNED);
|
|
91
|
+
*out_len = (EC_GROUP_get_degree(group) + 7) / 8;
|
|
92
|
+
if (*out_len > max_out_len) {
|
|
93
|
+
OPENSSL_PUT_ERROR(EC, EC_R_BUFFER_TOO_SMALL);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const BIGNUM *priv = EC_KEY_get0_private_key(priv_key);
|
|
98
|
+
if (priv == NULL) {
|
|
99
|
+
OPENSSL_PUT_ERROR(ECDH, ECDH_R_NO_PRIVATE_VALUE);
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
BN_CTX *ctx = BN_CTX_new();
|
|
104
|
+
if (ctx == NULL) {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
BN_CTX_start(ctx);
|
|
109
|
+
|
|
110
|
+
int ret = 0;
|
|
111
|
+
EC_POINT *tmp = NULL;
|
|
112
|
+
|
|
113
|
+
EC_POINT *pub_key = EC_POINT_new(group);
|
|
114
|
+
if (!pub_key ||
|
|
115
|
+
!EC_POINT_oct2point(group, pub_key, peer_pub_point_bytes,
|
|
116
|
+
peer_pub_point_bytes_len, ctx)) {
|
|
117
|
+
goto err;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
tmp = EC_POINT_new(group);
|
|
121
|
+
if (tmp == NULL) {
|
|
122
|
+
OPENSSL_PUT_ERROR(ECDH, ERR_R_MALLOC_FAILURE);
|
|
123
|
+
goto err;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!group->meth->mul_private(group, tmp, NULL, pub_key, priv, ctx)) {
|
|
127
|
+
OPENSSL_PUT_ERROR(ECDH, ECDH_R_POINT_ARITHMETIC_FAILURE);
|
|
128
|
+
goto err;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
BIGNUM *x = BN_CTX_get(ctx);
|
|
132
|
+
if (!x) {
|
|
133
|
+
OPENSSL_PUT_ERROR(ECDH, ERR_R_MALLOC_FAILURE);
|
|
134
|
+
goto err;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, NULL, ctx)) {
|
|
138
|
+
OPENSSL_PUT_ERROR(ECDH, ECDH_R_POINT_ARITHMETIC_FAILURE);
|
|
139
|
+
goto err;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!BN_bn2bin_padded(out, *out_len, x)) {
|
|
143
|
+
OPENSSL_PUT_ERROR(ECDH, ERR_R_INTERNAL_ERROR);
|
|
144
|
+
goto err;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
ret = 1;
|
|
148
|
+
|
|
149
|
+
err:
|
|
150
|
+
EC_POINT_free(tmp);
|
|
151
|
+
BN_CTX_end(ctx);
|
|
152
|
+
BN_CTX_free(ctx);
|
|
153
|
+
EC_POINT_free(pub_key);
|
|
154
|
+
return ret;
|
|
155
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/* ====================================================================
|
|
2
|
+
* Copyright (c) 1998-2005 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
|
+
* This product includes cryptographic software written by Eric Young
|
|
50
|
+
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
51
|
+
* Hudson (tjh@cryptsoft.com). */
|
|
52
|
+
|
|
53
|
+
#include <openssl/ecdsa.h>
|
|
54
|
+
|
|
55
|
+
#include <assert.h>
|
|
56
|
+
#include <string.h>
|
|
57
|
+
|
|
58
|
+
#include <openssl/bn.h>
|
|
59
|
+
#include <openssl/bytestring.h>
|
|
60
|
+
#include <openssl/err.h>
|
|
61
|
+
#include <openssl/mem.h>
|
|
62
|
+
|
|
63
|
+
#include "../ec/internal.h"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
static int digest_to_bn(BIGNUM *out, const uint8_t *digest, size_t digest_len,
|
|
67
|
+
const BIGNUM *order);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, uint8_t *sig,
|
|
71
|
+
unsigned int *sig_len, EC_KEY *eckey) {
|
|
72
|
+
const EC_GROUP *group = EC_KEY_get0_group(eckey);
|
|
73
|
+
const BIGNUM *priv_key = EC_KEY_get0_private_key(eckey);
|
|
74
|
+
if (group == NULL || priv_key == NULL) {
|
|
75
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_PASSED_NULL_PARAMETER);
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
BN_CTX *ctx = BN_CTX_new();
|
|
80
|
+
if (ctx == NULL) {
|
|
81
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_MALLOC_FAILURE);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
BN_CTX_start(ctx);
|
|
85
|
+
|
|
86
|
+
int ret = 0;
|
|
87
|
+
EC_POINT *tmp_point = tmp_point = EC_POINT_new(group);
|
|
88
|
+
if (tmp_point == NULL) {
|
|
89
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_EC_LIB);
|
|
90
|
+
goto err;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
BIGNUM *m = BN_CTX_get(ctx);
|
|
94
|
+
BIGNUM *k = BN_CTX_get(ctx);
|
|
95
|
+
BIGNUM *r = BN_CTX_get(ctx);
|
|
96
|
+
BIGNUM *X = BN_CTX_get(ctx);
|
|
97
|
+
BIGNUM *s = BN_CTX_get(ctx);
|
|
98
|
+
BIGNUM *tmp = BN_CTX_get(ctx);
|
|
99
|
+
if (m == NULL ||
|
|
100
|
+
k == NULL ||
|
|
101
|
+
r == NULL ||
|
|
102
|
+
X == NULL ||
|
|
103
|
+
s == NULL ||
|
|
104
|
+
tmp == NULL) {
|
|
105
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_MALLOC_FAILURE);
|
|
106
|
+
goto err;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!digest_to_bn(m, digest, digest_len, &group->order)) {
|
|
110
|
+
goto err;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
do {
|
|
114
|
+
do {
|
|
115
|
+
do {
|
|
116
|
+
if (!BN_generate_dsa_nonce(k, &group->order,
|
|
117
|
+
EC_KEY_get0_private_key(eckey), digest,
|
|
118
|
+
digest_len, ctx)) {
|
|
119
|
+
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);
|
|
120
|
+
goto err;
|
|
121
|
+
}
|
|
122
|
+
} while (BN_is_zero(k));
|
|
123
|
+
|
|
124
|
+
/* Compute |r|, the X coordinate of |generator * k|. */
|
|
125
|
+
if (!group->meth->mul_private(group, tmp_point, k, NULL, NULL, ctx) ||
|
|
126
|
+
!EC_POINT_get_affine_coordinates_GFp(group, tmp_point, X, NULL, ctx)) {
|
|
127
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_EC_LIB);
|
|
128
|
+
goto err;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!BN_nnmod(r, X, &group->order, ctx)) {
|
|
132
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
133
|
+
goto err;
|
|
134
|
+
}
|
|
135
|
+
} while (BN_is_zero(r));
|
|
136
|
+
|
|
137
|
+
/* Compute the inverse of k. We want inverse in constant time, therefore we
|
|
138
|
+
* use Fermat's Little Theorem, which works because the subgroup order is
|
|
139
|
+
* prime.
|
|
140
|
+
*
|
|
141
|
+
* XXX: This isn't perfectly constant-time because the implementation of
|
|
142
|
+
* BN_mod_exp_mont_consttime isn't perfectly constant time. */
|
|
143
|
+
if (!BN_mod_exp_mont_consttime(k, k, &group->order_minus_2, &group->order,
|
|
144
|
+
ctx, &group->order_mont)) {
|
|
145
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
146
|
+
goto err;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (!BN_mod_mul(tmp, priv_key, r, &group->order, ctx) ||
|
|
150
|
+
!BN_mod_add_quick(s, tmp, m, &group->order) ||
|
|
151
|
+
!BN_mod_mul(s, s, k, &group->order, ctx)) {
|
|
152
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
153
|
+
goto err;
|
|
154
|
+
}
|
|
155
|
+
} while (BN_is_zero(s));
|
|
156
|
+
|
|
157
|
+
/* s != 0 => we have a valid signature */
|
|
158
|
+
|
|
159
|
+
ECDSA_SIG ecdsa_sig;
|
|
160
|
+
ecdsa_sig.r = r;
|
|
161
|
+
ecdsa_sig.s = s;
|
|
162
|
+
|
|
163
|
+
CBB cbb;
|
|
164
|
+
CBB_zero(&cbb);
|
|
165
|
+
size_t len;
|
|
166
|
+
if (!CBB_init_fixed(&cbb, sig, ECDSA_size(eckey)) ||
|
|
167
|
+
!ECDSA_SIG_marshal(&cbb, &ecdsa_sig) ||
|
|
168
|
+
!CBB_finish(&cbb, NULL, &len)) {
|
|
169
|
+
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_ENCODE_ERROR);
|
|
170
|
+
CBB_cleanup(&cbb);
|
|
171
|
+
goto err;
|
|
172
|
+
}
|
|
173
|
+
*sig_len = (unsigned)len;
|
|
174
|
+
ret = 1;
|
|
175
|
+
|
|
176
|
+
err:
|
|
177
|
+
if (!ret) {
|
|
178
|
+
*sig_len = 0;
|
|
179
|
+
}
|
|
180
|
+
EC_POINT_free(tmp_point);
|
|
181
|
+
BN_CTX_end(ctx);
|
|
182
|
+
BN_CTX_free(ctx);
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
int ECDSA_verify_signed_digest(const EC_GROUP *group, int hash_nid,
|
|
187
|
+
const uint8_t *digest, size_t digest_len,
|
|
188
|
+
const uint8_t *sig_, size_t sig_len,
|
|
189
|
+
const uint8_t *ec_key, const size_t ec_key_len) {
|
|
190
|
+
BN_CTX *ctx = BN_CTX_new();
|
|
191
|
+
if (ctx == NULL) {
|
|
192
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_MALLOC_FAILURE);
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
BN_CTX_start(ctx);
|
|
197
|
+
|
|
198
|
+
int ret = 0;
|
|
199
|
+
ECDSA_SIG *sig = NULL;
|
|
200
|
+
EC_POINT *point = NULL;
|
|
201
|
+
|
|
202
|
+
EC_POINT *pub_key = EC_POINT_new(group);
|
|
203
|
+
if (!pub_key ||
|
|
204
|
+
!EC_POINT_oct2point(group, pub_key, ec_key, ec_key_len, NULL)) {
|
|
205
|
+
goto err;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
sig = ECDSA_SIG_from_bytes(sig_, sig_len);
|
|
209
|
+
if (sig == NULL) {
|
|
210
|
+
goto err;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* check input values */
|
|
214
|
+
BIGNUM *u1 = BN_CTX_get(ctx);
|
|
215
|
+
BIGNUM *u2 = BN_CTX_get(ctx);
|
|
216
|
+
BIGNUM *m = BN_CTX_get(ctx);
|
|
217
|
+
BIGNUM *X = BN_CTX_get(ctx);
|
|
218
|
+
if (u1 == NULL || u2 == NULL || m == NULL || X == NULL) {
|
|
219
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
220
|
+
goto err;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
|
|
224
|
+
BN_ucmp(sig->r, &group->order) >= 0 || BN_is_zero(sig->s) ||
|
|
225
|
+
BN_is_negative(sig->s) || BN_ucmp(sig->s, &group->order) >= 0) {
|
|
226
|
+
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_BAD_SIGNATURE);
|
|
227
|
+
ret = 0; /* signature is invalid */
|
|
228
|
+
goto err;
|
|
229
|
+
}
|
|
230
|
+
/* calculate tmp1 = inv(S) mod order */
|
|
231
|
+
if (!BN_mod_inverse(u2, sig->s, &group->order, ctx)) {
|
|
232
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
233
|
+
goto err;
|
|
234
|
+
}
|
|
235
|
+
if (!digest_to_bn(m, digest, digest_len, &group->order)) {
|
|
236
|
+
goto err;
|
|
237
|
+
}
|
|
238
|
+
/* u1 = m * tmp mod order */
|
|
239
|
+
if (!BN_mod_mul(u1, m, u2, &group->order, ctx)) {
|
|
240
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
241
|
+
goto err;
|
|
242
|
+
}
|
|
243
|
+
/* u2 = r * w mod q */
|
|
244
|
+
if (!BN_mod_mul(u2, sig->r, u2, &group->order, ctx)) {
|
|
245
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
246
|
+
goto err;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
point = EC_POINT_new(group);
|
|
250
|
+
if (point == NULL) {
|
|
251
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_MALLOC_FAILURE);
|
|
252
|
+
goto err;
|
|
253
|
+
}
|
|
254
|
+
if (!group->meth->mul_public(group, point, u1, pub_key, u2, ctx)) {
|
|
255
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_EC_LIB);
|
|
256
|
+
goto err;
|
|
257
|
+
}
|
|
258
|
+
if (!EC_POINT_get_affine_coordinates_GFp(group, point, X, NULL, ctx)) {
|
|
259
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_EC_LIB);
|
|
260
|
+
goto err;
|
|
261
|
+
}
|
|
262
|
+
if (!BN_nnmod(u1, X, &group->order, ctx)) {
|
|
263
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
264
|
+
goto err;
|
|
265
|
+
}
|
|
266
|
+
/* if the signature is correct u1 is equal to sig->r */
|
|
267
|
+
ret = (BN_ucmp(u1, sig->r) == 0);
|
|
268
|
+
|
|
269
|
+
err:
|
|
270
|
+
BN_CTX_end(ctx);
|
|
271
|
+
BN_CTX_free(ctx);
|
|
272
|
+
EC_POINT_free(pub_key);
|
|
273
|
+
ECDSA_SIG_free(sig);
|
|
274
|
+
EC_POINT_free(point);
|
|
275
|
+
return ret;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* digest_to_bn interprets |digest_len| bytes from |digest| as a big-endian
|
|
279
|
+
* number and sets |out| to that value. It then truncates |out| so that it's,
|
|
280
|
+
* at most, as long as |order|. It returns one on success and zero otherwise. */
|
|
281
|
+
static int digest_to_bn(BIGNUM *out, const uint8_t *digest, size_t digest_len,
|
|
282
|
+
const BIGNUM *order) {
|
|
283
|
+
size_t num_bits;
|
|
284
|
+
|
|
285
|
+
num_bits = BN_num_bits(order);
|
|
286
|
+
/* Need to truncate digest if it is too long: first truncate whole
|
|
287
|
+
* bytes. */
|
|
288
|
+
if (8 * digest_len > num_bits) {
|
|
289
|
+
digest_len = (num_bits + 7) / 8;
|
|
290
|
+
}
|
|
291
|
+
if (!BN_bin2bn(digest, digest_len, out)) {
|
|
292
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* If still too long truncate remaining bits with a shift */
|
|
297
|
+
if ((8 * digest_len > num_bits) &&
|
|
298
|
+
!BN_rshift(out, out, 8 - (num_bits & 0x7))) {
|
|
299
|
+
OPENSSL_PUT_ERROR(ECDSA, ERR_R_BN_LIB);
|
|
300
|
+
return 0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return 1;
|
|
304
|
+
}
|