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,509 @@
|
|
|
1
|
+
/* Copyright (c) 2014, Intel Corporation.
|
|
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
|
+
/* Developers and authors:
|
|
16
|
+
* Shay Gueron (1, 2), and Vlad Krasnov (1)
|
|
17
|
+
* (1) Intel Corporation, Israel Development Center
|
|
18
|
+
* (2) University of Haifa
|
|
19
|
+
* Reference:
|
|
20
|
+
* Shay Gueron and Vlad Krasnov
|
|
21
|
+
* "Fast Prime Field Elliptic Curve Cryptography with 256 Bit Primes"
|
|
22
|
+
* http://eprint.iacr.org/2013/816 */
|
|
23
|
+
|
|
24
|
+
#include <openssl/ec.h>
|
|
25
|
+
|
|
26
|
+
#include <assert.h>
|
|
27
|
+
#include <stdint.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
#include <openssl/bn.h>
|
|
31
|
+
#include <openssl/crypto.h>
|
|
32
|
+
#include <openssl/err.h>
|
|
33
|
+
|
|
34
|
+
#include "../bn/internal.h"
|
|
35
|
+
#include "../ec/internal.h"
|
|
36
|
+
#include "../internal.h"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \
|
|
40
|
+
!defined(OPENSSL_SMALL)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#if defined(__GNUC__)
|
|
44
|
+
#define ALIGN(x) __attribute((aligned(x)))
|
|
45
|
+
#elif defined(_MSC_VER)
|
|
46
|
+
#define ALIGN(x) __declspec(align(x))
|
|
47
|
+
#else
|
|
48
|
+
#define ALIGN(x)
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
#define ALIGNPTR(p, N) ((uint8_t *)p + N - (size_t)p % N)
|
|
52
|
+
#define P256_LIMBS (256 / BN_BITS2)
|
|
53
|
+
|
|
54
|
+
typedef struct {
|
|
55
|
+
BN_ULONG X[P256_LIMBS];
|
|
56
|
+
BN_ULONG Y[P256_LIMBS];
|
|
57
|
+
BN_ULONG Z[P256_LIMBS];
|
|
58
|
+
} P256_POINT;
|
|
59
|
+
|
|
60
|
+
typedef struct {
|
|
61
|
+
BN_ULONG X[P256_LIMBS];
|
|
62
|
+
BN_ULONG Y[P256_LIMBS];
|
|
63
|
+
} P256_POINT_AFFINE;
|
|
64
|
+
|
|
65
|
+
typedef P256_POINT_AFFINE PRECOMP256_ROW[64];
|
|
66
|
+
|
|
67
|
+
/* Functions implemented in assembly */
|
|
68
|
+
|
|
69
|
+
/* Modular neg: res = -a mod P */
|
|
70
|
+
void ecp_nistz256_neg(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]);
|
|
71
|
+
/* Montgomery mul: res = a*b*2^-256 mod P */
|
|
72
|
+
void ecp_nistz256_mul_mont(BN_ULONG res[P256_LIMBS],
|
|
73
|
+
const BN_ULONG a[P256_LIMBS],
|
|
74
|
+
const BN_ULONG b[P256_LIMBS]);
|
|
75
|
+
/* Montgomery sqr: res = a*a*2^-256 mod P */
|
|
76
|
+
void ecp_nistz256_sqr_mont(BN_ULONG res[P256_LIMBS],
|
|
77
|
+
const BN_ULONG a[P256_LIMBS]);
|
|
78
|
+
/* Convert a number from Montgomery domain, by multiplying with 1 */
|
|
79
|
+
void ecp_nistz256_from_mont(BN_ULONG res[P256_LIMBS],
|
|
80
|
+
const BN_ULONG in[P256_LIMBS]);
|
|
81
|
+
/* Functions that perform constant time access to the precomputed tables */
|
|
82
|
+
void ecp_nistz256_select_w5(P256_POINT *val, const P256_POINT *in_t, int index);
|
|
83
|
+
void ecp_nistz256_select_w7(P256_POINT_AFFINE *val,
|
|
84
|
+
const P256_POINT_AFFINE *in_t, int index);
|
|
85
|
+
|
|
86
|
+
/* One converted into the Montgomery domain */
|
|
87
|
+
static const BN_ULONG ONE[P256_LIMBS] = {
|
|
88
|
+
TOBN(0x00000000, 0x00000001), TOBN(0xffffffff, 0x00000000),
|
|
89
|
+
TOBN(0xffffffff, 0xffffffff), TOBN(0x00000000, 0xfffffffe),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/* Precomputed tables for the default generator */
|
|
93
|
+
#include "p256-x86_64-table.h"
|
|
94
|
+
|
|
95
|
+
/* Recode window to a signed digit, see ecp_nistputil.c for details */
|
|
96
|
+
static unsigned booth_recode_w5(unsigned in) {
|
|
97
|
+
unsigned s, d;
|
|
98
|
+
|
|
99
|
+
s = ~((in >> 5) - 1);
|
|
100
|
+
d = (1 << 6) - in - 1;
|
|
101
|
+
d = (d & s) | (in & ~s);
|
|
102
|
+
d = (d >> 1) + (d & 1);
|
|
103
|
+
|
|
104
|
+
return (d << 1) + (s & 1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static unsigned booth_recode_w7(unsigned in) {
|
|
108
|
+
unsigned s, d;
|
|
109
|
+
|
|
110
|
+
s = ~((in >> 7) - 1);
|
|
111
|
+
d = (1 << 8) - in - 1;
|
|
112
|
+
d = (d & s) | (in & ~s);
|
|
113
|
+
d = (d >> 1) + (d & 1);
|
|
114
|
+
|
|
115
|
+
return (d << 1) + (s & 1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static void copy_conditional(BN_ULONG dst[P256_LIMBS],
|
|
119
|
+
const BN_ULONG src[P256_LIMBS], BN_ULONG move) {
|
|
120
|
+
BN_ULONG mask1 = ((BN_ULONG)0) - move;
|
|
121
|
+
BN_ULONG mask2 = ~mask1;
|
|
122
|
+
|
|
123
|
+
dst[0] = (src[0] & mask1) ^ (dst[0] & mask2);
|
|
124
|
+
dst[1] = (src[1] & mask1) ^ (dst[1] & mask2);
|
|
125
|
+
dst[2] = (src[2] & mask1) ^ (dst[2] & mask2);
|
|
126
|
+
dst[3] = (src[3] & mask1) ^ (dst[3] & mask2);
|
|
127
|
+
if (P256_LIMBS == 8) {
|
|
128
|
+
dst[4] = (src[4] & mask1) ^ (dst[4] & mask2);
|
|
129
|
+
dst[5] = (src[5] & mask1) ^ (dst[5] & mask2);
|
|
130
|
+
dst[6] = (src[6] & mask1) ^ (dst[6] & mask2);
|
|
131
|
+
dst[7] = (src[7] & mask1) ^ (dst[7] & mask2);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void ecp_nistz256_point_double(P256_POINT *r, const P256_POINT *a);
|
|
136
|
+
void ecp_nistz256_point_add(P256_POINT *r, const P256_POINT *a,
|
|
137
|
+
const P256_POINT *b);
|
|
138
|
+
void ecp_nistz256_point_add_affine(P256_POINT *r, const P256_POINT *a,
|
|
139
|
+
const P256_POINT_AFFINE *b);
|
|
140
|
+
|
|
141
|
+
/* r = in^-1 mod p */
|
|
142
|
+
static void ecp_nistz256_mod_inverse(BN_ULONG r[P256_LIMBS],
|
|
143
|
+
const BN_ULONG in[P256_LIMBS]) {
|
|
144
|
+
/* The poly is ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff
|
|
145
|
+
ffffffff
|
|
146
|
+
We use FLT and used poly-2 as exponent */
|
|
147
|
+
BN_ULONG p2[P256_LIMBS];
|
|
148
|
+
BN_ULONG p4[P256_LIMBS];
|
|
149
|
+
BN_ULONG p8[P256_LIMBS];
|
|
150
|
+
BN_ULONG p16[P256_LIMBS];
|
|
151
|
+
BN_ULONG p32[P256_LIMBS];
|
|
152
|
+
BN_ULONG res[P256_LIMBS];
|
|
153
|
+
int i;
|
|
154
|
+
|
|
155
|
+
ecp_nistz256_sqr_mont(res, in);
|
|
156
|
+
ecp_nistz256_mul_mont(p2, res, in); /* 3*p */
|
|
157
|
+
|
|
158
|
+
ecp_nistz256_sqr_mont(res, p2);
|
|
159
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
160
|
+
ecp_nistz256_mul_mont(p4, res, p2); /* f*p */
|
|
161
|
+
|
|
162
|
+
ecp_nistz256_sqr_mont(res, p4);
|
|
163
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
164
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
165
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
166
|
+
ecp_nistz256_mul_mont(p8, res, p4); /* ff*p */
|
|
167
|
+
|
|
168
|
+
ecp_nistz256_sqr_mont(res, p8);
|
|
169
|
+
for (i = 0; i < 7; i++) {
|
|
170
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
171
|
+
}
|
|
172
|
+
ecp_nistz256_mul_mont(p16, res, p8); /* ffff*p */
|
|
173
|
+
|
|
174
|
+
ecp_nistz256_sqr_mont(res, p16);
|
|
175
|
+
for (i = 0; i < 15; i++) {
|
|
176
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
177
|
+
}
|
|
178
|
+
ecp_nistz256_mul_mont(p32, res, p16); /* ffffffff*p */
|
|
179
|
+
|
|
180
|
+
ecp_nistz256_sqr_mont(res, p32);
|
|
181
|
+
for (i = 0; i < 31; i++) {
|
|
182
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
183
|
+
}
|
|
184
|
+
ecp_nistz256_mul_mont(res, res, in);
|
|
185
|
+
|
|
186
|
+
for (i = 0; i < 32 * 4; i++) {
|
|
187
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
188
|
+
}
|
|
189
|
+
ecp_nistz256_mul_mont(res, res, p32);
|
|
190
|
+
|
|
191
|
+
for (i = 0; i < 32; i++) {
|
|
192
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
193
|
+
}
|
|
194
|
+
ecp_nistz256_mul_mont(res, res, p32);
|
|
195
|
+
|
|
196
|
+
for (i = 0; i < 16; i++) {
|
|
197
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
198
|
+
}
|
|
199
|
+
ecp_nistz256_mul_mont(res, res, p16);
|
|
200
|
+
|
|
201
|
+
for (i = 0; i < 8; i++) {
|
|
202
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
203
|
+
}
|
|
204
|
+
ecp_nistz256_mul_mont(res, res, p8);
|
|
205
|
+
|
|
206
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
207
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
208
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
209
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
210
|
+
ecp_nistz256_mul_mont(res, res, p4);
|
|
211
|
+
|
|
212
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
213
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
214
|
+
ecp_nistz256_mul_mont(res, res, p2);
|
|
215
|
+
|
|
216
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
217
|
+
ecp_nistz256_sqr_mont(res, res);
|
|
218
|
+
ecp_nistz256_mul_mont(res, res, in);
|
|
219
|
+
|
|
220
|
+
memcpy(r, res, sizeof(res));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* ecp_nistz256_bignum_to_field_elem copies the contents of |in| to |out| and
|
|
224
|
+
* returns one if it fits. Otherwise it returns zero. */
|
|
225
|
+
static int ecp_nistz256_bignum_to_field_elem(BN_ULONG out[P256_LIMBS],
|
|
226
|
+
const BIGNUM *in) {
|
|
227
|
+
if (in->top > P256_LIMBS) {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
memset(out, 0, sizeof(BN_ULONG) * P256_LIMBS);
|
|
232
|
+
memcpy(out, in->d, sizeof(BN_ULONG) * in->top);
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* r = p * p_scalar */
|
|
237
|
+
static int ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
|
|
238
|
+
const EC_POINT *p, const BIGNUM *p_scalar,
|
|
239
|
+
BN_CTX *ctx) {
|
|
240
|
+
assert(p != NULL);
|
|
241
|
+
assert(p_scalar != NULL);
|
|
242
|
+
assert(BN_cmp(p_scalar, EC_GROUP_get0_order(group)) < 0);
|
|
243
|
+
|
|
244
|
+
static const unsigned kWindowSize = 5;
|
|
245
|
+
static const unsigned kMask = (1 << (5 /* kWindowSize */ + 1)) - 1;
|
|
246
|
+
|
|
247
|
+
/* A |P256_POINT| is (3 * 32) = 96 bytes, and the 64-byte alignment should
|
|
248
|
+
* add no more than 63 bytes of overhead. Thus, |table| should require
|
|
249
|
+
* ~1599 ((96 * 16) + 63) bytes of stack space. */
|
|
250
|
+
ALIGN(64) P256_POINT table[16];
|
|
251
|
+
uint8_t p_str[33];
|
|
252
|
+
|
|
253
|
+
int j;
|
|
254
|
+
for (j = 0; j < p_scalar->top * BN_BYTES; j += BN_BYTES) {
|
|
255
|
+
BN_ULONG d = p_scalar->d[j / BN_BYTES];
|
|
256
|
+
|
|
257
|
+
p_str[j + 0] = d & 0xff;
|
|
258
|
+
p_str[j + 1] = (d >> 8) & 0xff;
|
|
259
|
+
p_str[j + 2] = (d >> 16) & 0xff;
|
|
260
|
+
p_str[j + 3] = (d >>= 24) & 0xff;
|
|
261
|
+
if (BN_BYTES == 8) {
|
|
262
|
+
d >>= 8;
|
|
263
|
+
p_str[j + 4] = d & 0xff;
|
|
264
|
+
p_str[j + 5] = (d >> 8) & 0xff;
|
|
265
|
+
p_str[j + 6] = (d >> 16) & 0xff;
|
|
266
|
+
p_str[j + 7] = (d >> 24) & 0xff;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
for (; j < 33; j++) {
|
|
271
|
+
p_str[j] = 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* table[0] is implicitly (0,0,0) (the point at infinity), therefore it is
|
|
275
|
+
* not stored. All other values are actually stored with an offset of -1 in
|
|
276
|
+
* table. */
|
|
277
|
+
P256_POINT *row = table;
|
|
278
|
+
|
|
279
|
+
if (!ecp_nistz256_bignum_to_field_elem(row[1 - 1].X, &p->X) ||
|
|
280
|
+
!ecp_nistz256_bignum_to_field_elem(row[1 - 1].Y, &p->Y) ||
|
|
281
|
+
!ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z, &p->Z)) {
|
|
282
|
+
OPENSSL_PUT_ERROR(EC, EC_R_COORDINATES_OUT_OF_RANGE);
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
ecp_nistz256_point_double(&row[2 - 1], &row[1 - 1]);
|
|
287
|
+
ecp_nistz256_point_add(&row[3 - 1], &row[2 - 1], &row[1 - 1]);
|
|
288
|
+
ecp_nistz256_point_double(&row[4 - 1], &row[2 - 1]);
|
|
289
|
+
ecp_nistz256_point_double(&row[6 - 1], &row[3 - 1]);
|
|
290
|
+
ecp_nistz256_point_double(&row[8 - 1], &row[4 - 1]);
|
|
291
|
+
ecp_nistz256_point_double(&row[12 - 1], &row[6 - 1]);
|
|
292
|
+
ecp_nistz256_point_add(&row[5 - 1], &row[4 - 1], &row[1 - 1]);
|
|
293
|
+
ecp_nistz256_point_add(&row[7 - 1], &row[6 - 1], &row[1 - 1]);
|
|
294
|
+
ecp_nistz256_point_add(&row[9 - 1], &row[8 - 1], &row[1 - 1]);
|
|
295
|
+
ecp_nistz256_point_add(&row[13 - 1], &row[12 - 1], &row[1 - 1]);
|
|
296
|
+
ecp_nistz256_point_double(&row[14 - 1], &row[7 - 1]);
|
|
297
|
+
ecp_nistz256_point_double(&row[10 - 1], &row[5 - 1]);
|
|
298
|
+
ecp_nistz256_point_add(&row[15 - 1], &row[14 - 1], &row[1 - 1]);
|
|
299
|
+
ecp_nistz256_point_add(&row[11 - 1], &row[10 - 1], &row[1 - 1]);
|
|
300
|
+
ecp_nistz256_point_add(&row[16 - 1], &row[15 - 1], &row[1 - 1]);
|
|
301
|
+
|
|
302
|
+
BN_ULONG tmp[P256_LIMBS];
|
|
303
|
+
ALIGN(32) P256_POINT h;
|
|
304
|
+
unsigned index = 255;
|
|
305
|
+
unsigned wvalue = p_str[(index - 1) / 8];
|
|
306
|
+
wvalue = (wvalue >> ((index - 1) % 8)) & kMask;
|
|
307
|
+
|
|
308
|
+
ecp_nistz256_select_w5(r, table, booth_recode_w5(wvalue) >> 1);
|
|
309
|
+
|
|
310
|
+
while (index >= 5) {
|
|
311
|
+
if (index != 255) {
|
|
312
|
+
unsigned off = (index - 1) / 8;
|
|
313
|
+
|
|
314
|
+
wvalue = p_str[off] | p_str[off + 1] << 8;
|
|
315
|
+
wvalue = (wvalue >> ((index - 1) % 8)) & kMask;
|
|
316
|
+
|
|
317
|
+
wvalue = booth_recode_w5(wvalue);
|
|
318
|
+
|
|
319
|
+
ecp_nistz256_select_w5(&h, table, wvalue >> 1);
|
|
320
|
+
|
|
321
|
+
ecp_nistz256_neg(tmp, h.Y);
|
|
322
|
+
copy_conditional(h.Y, tmp, (wvalue & 1));
|
|
323
|
+
|
|
324
|
+
ecp_nistz256_point_add(r, r, &h);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
index -= kWindowSize;
|
|
328
|
+
|
|
329
|
+
ecp_nistz256_point_double(r, r);
|
|
330
|
+
ecp_nistz256_point_double(r, r);
|
|
331
|
+
ecp_nistz256_point_double(r, r);
|
|
332
|
+
ecp_nistz256_point_double(r, r);
|
|
333
|
+
ecp_nistz256_point_double(r, r);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* Final window */
|
|
337
|
+
wvalue = p_str[0];
|
|
338
|
+
wvalue = (wvalue << 1) & kMask;
|
|
339
|
+
|
|
340
|
+
wvalue = booth_recode_w5(wvalue);
|
|
341
|
+
|
|
342
|
+
ecp_nistz256_select_w5(&h, table, wvalue >> 1);
|
|
343
|
+
|
|
344
|
+
ecp_nistz256_neg(tmp, h.Y);
|
|
345
|
+
copy_conditional(h.Y, tmp, wvalue & 1);
|
|
346
|
+
|
|
347
|
+
ecp_nistz256_point_add(r, r, &h);
|
|
348
|
+
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
static int ecp_nistz256_points_mul(
|
|
353
|
+
const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
|
|
354
|
+
const EC_POINT *p_, const BIGNUM *p_scalar, BN_CTX *ctx) {
|
|
355
|
+
assert((p_ != NULL) == (p_scalar != NULL));
|
|
356
|
+
|
|
357
|
+
static const unsigned kWindowSize = 7;
|
|
358
|
+
static const unsigned kMask = (1 << (7 /* kWindowSize */ + 1)) - 1;
|
|
359
|
+
|
|
360
|
+
ALIGN(32) union {
|
|
361
|
+
P256_POINT p;
|
|
362
|
+
P256_POINT_AFFINE a;
|
|
363
|
+
} t, p;
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
if (g_scalar != NULL) {
|
|
367
|
+
assert(BN_cmp(g_scalar, EC_GROUP_get0_order(group)) < 0);
|
|
368
|
+
uint8_t p_str[33] = {0};
|
|
369
|
+
int i;
|
|
370
|
+
for (i = 0; i < g_scalar->top * BN_BYTES; i += BN_BYTES) {
|
|
371
|
+
BN_ULONG d = g_scalar->d[i / BN_BYTES];
|
|
372
|
+
|
|
373
|
+
p_str[i + 0] = d & 0xff;
|
|
374
|
+
p_str[i + 1] = (d >> 8) & 0xff;
|
|
375
|
+
p_str[i + 2] = (d >> 16) & 0xff;
|
|
376
|
+
p_str[i + 3] = (d >>= 24) & 0xff;
|
|
377
|
+
if (BN_BYTES == 8) {
|
|
378
|
+
d >>= 8;
|
|
379
|
+
p_str[i + 4] = d & 0xff;
|
|
380
|
+
p_str[i + 5] = (d >> 8) & 0xff;
|
|
381
|
+
p_str[i + 6] = (d >> 16) & 0xff;
|
|
382
|
+
p_str[i + 7] = (d >> 24) & 0xff;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
for (; i < (int) sizeof(p_str); i++) {
|
|
387
|
+
p_str[i] = 0;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/* First window */
|
|
391
|
+
unsigned wvalue = (p_str[0] << 1) & kMask;
|
|
392
|
+
unsigned index = kWindowSize;
|
|
393
|
+
|
|
394
|
+
wvalue = booth_recode_w7(wvalue);
|
|
395
|
+
|
|
396
|
+
const PRECOMP256_ROW *const precomputed_table =
|
|
397
|
+
(const PRECOMP256_ROW *)ecp_nistz256_precomputed;
|
|
398
|
+
ecp_nistz256_select_w7(&p.a, precomputed_table[0], wvalue >> 1);
|
|
399
|
+
|
|
400
|
+
ecp_nistz256_neg(p.p.Z, p.p.Y);
|
|
401
|
+
copy_conditional(p.p.Y, p.p.Z, wvalue & 1);
|
|
402
|
+
|
|
403
|
+
memcpy(p.p.Z, ONE, sizeof(ONE));
|
|
404
|
+
|
|
405
|
+
for (i = 1; i < 37; i++) {
|
|
406
|
+
unsigned off = (index - 1) / 8;
|
|
407
|
+
wvalue = p_str[off] | p_str[off + 1] << 8;
|
|
408
|
+
wvalue = (wvalue >> ((index - 1) % 8)) & kMask;
|
|
409
|
+
index += kWindowSize;
|
|
410
|
+
|
|
411
|
+
wvalue = booth_recode_w7(wvalue);
|
|
412
|
+
|
|
413
|
+
ecp_nistz256_select_w7(&t.a, precomputed_table[i], wvalue >> 1);
|
|
414
|
+
|
|
415
|
+
ecp_nistz256_neg(t.p.Z, t.a.Y);
|
|
416
|
+
copy_conditional(t.a.Y, t.p.Z, wvalue & 1);
|
|
417
|
+
|
|
418
|
+
ecp_nistz256_point_add_affine(&p.p, &p.p, &t.a);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const int p_is_infinity = g_scalar == NULL;
|
|
423
|
+
if (p_scalar != NULL) {
|
|
424
|
+
P256_POINT *out = &t.p;
|
|
425
|
+
if (p_is_infinity) {
|
|
426
|
+
out = &p.p;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (!ecp_nistz256_windowed_mul(group, out, p_, p_scalar, ctx)) {
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (!p_is_infinity) {
|
|
434
|
+
ecp_nistz256_point_add(&p.p, &p.p, out);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/* Not constant-time, but we're only operating on the public output. */
|
|
439
|
+
if (!bn_set_words(&r->X, p.p.X, P256_LIMBS) ||
|
|
440
|
+
!bn_set_words(&r->Y, p.p.Y, P256_LIMBS) ||
|
|
441
|
+
!bn_set_words(&r->Z, p.p.Z, P256_LIMBS)) {
|
|
442
|
+
return 0;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return 1;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
static int ecp_nistz256_get_affine(const EC_GROUP *group, const EC_POINT *point,
|
|
449
|
+
BIGNUM *x, BIGNUM *y, BN_CTX *ctx) {
|
|
450
|
+
BN_ULONG z_inv2[P256_LIMBS];
|
|
451
|
+
BN_ULONG z_inv3[P256_LIMBS];
|
|
452
|
+
BN_ULONG x_aff[P256_LIMBS];
|
|
453
|
+
BN_ULONG y_aff[P256_LIMBS];
|
|
454
|
+
BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS];
|
|
455
|
+
|
|
456
|
+
if (EC_POINT_is_at_infinity(group, point)) {
|
|
457
|
+
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) ||
|
|
462
|
+
!ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) ||
|
|
463
|
+
!ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) {
|
|
464
|
+
OPENSSL_PUT_ERROR(EC, EC_R_COORDINATES_OUT_OF_RANGE);
|
|
465
|
+
return 0;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
ecp_nistz256_mod_inverse(z_inv3, point_z);
|
|
469
|
+
ecp_nistz256_sqr_mont(z_inv2, z_inv3);
|
|
470
|
+
ecp_nistz256_mul_mont(x_aff, z_inv2, point_x);
|
|
471
|
+
|
|
472
|
+
if (x != NULL) {
|
|
473
|
+
if (bn_wexpand(x, P256_LIMBS) == NULL) {
|
|
474
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
|
475
|
+
return 0;
|
|
476
|
+
}
|
|
477
|
+
x->top = P256_LIMBS;
|
|
478
|
+
ecp_nistz256_from_mont(x->d, x_aff);
|
|
479
|
+
bn_correct_top(x);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (y != NULL) {
|
|
483
|
+
ecp_nistz256_mul_mont(z_inv3, z_inv3, z_inv2);
|
|
484
|
+
ecp_nistz256_mul_mont(y_aff, z_inv3, point_y);
|
|
485
|
+
if (bn_wexpand(y, P256_LIMBS) == NULL) {
|
|
486
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
|
487
|
+
return 0;
|
|
488
|
+
}
|
|
489
|
+
y->top = P256_LIMBS;
|
|
490
|
+
ecp_nistz256_from_mont(y->d, y_aff);
|
|
491
|
+
bn_correct_top(y);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return 1;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const EC_METHOD EC_GFp_nistz256_method = {
|
|
498
|
+
ecp_nistz256_get_affine,
|
|
499
|
+
ecp_nistz256_points_mul,
|
|
500
|
+
ecp_nistz256_points_mul,
|
|
501
|
+
ec_GFp_mont_field_mul,
|
|
502
|
+
ec_GFp_mont_field_sqr,
|
|
503
|
+
ec_GFp_mont_field_encode,
|
|
504
|
+
ec_GFp_mont_field_decode,
|
|
505
|
+
ec_GFp_mont_field_set_to_one,
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
#endif /* !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \
|
|
509
|
+
!defined(OPENSSL_SMALL) */
|