ring-native 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +7 -0
- data/Makefile +5 -0
- data/README.md +12 -5
- data/Rakefile +4 -0
- data/ext/ring/extconf.rb +4 -5
- data/lib/ring/native.rb +3 -1
- data/lib/ring/native/version.rb +5 -1
- data/ring-native.gemspec +6 -6
- data/vendor/ring-ffi/Cargo.lock +26 -0
- data/vendor/ring-ffi/Cargo.toml +45 -0
- data/vendor/ring-ffi/LICENSE +16 -0
- data/vendor/ring-ffi/README.md +59 -0
- data/vendor/ring-ffi/src/lib.rs +79 -0
- metadata +10 -255
- data/vendor/ring/BUILDING.md +0 -40
- data/vendor/ring/Cargo.toml +0 -43
- data/vendor/ring/LICENSE +0 -185
- data/vendor/ring/Makefile +0 -35
- data/vendor/ring/PORTING.md +0 -163
- data/vendor/ring/README.md +0 -113
- data/vendor/ring/STYLE.md +0 -197
- data/vendor/ring/appveyor.yml +0 -27
- data/vendor/ring/build.rs +0 -108
- data/vendor/ring/crypto/aes/aes.c +0 -1142
- data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/aes/aes_test.cc +0 -93
- data/vendor/ring/crypto/aes/asm/aes-586.pl +0 -2368
- data/vendor/ring/crypto/aes/asm/aes-armv4.pl +0 -1249
- data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +0 -2246
- data/vendor/ring/crypto/aes/asm/aesni-x86.pl +0 -1318
- data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +0 -2084
- data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +0 -675
- data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +0 -1364
- data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +0 -1565
- data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +0 -841
- data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +0 -1116
- data/vendor/ring/crypto/aes/internal.h +0 -87
- data/vendor/ring/crypto/aes/mode_wrappers.c +0 -61
- data/vendor/ring/crypto/bn/add.c +0 -394
- data/vendor/ring/crypto/bn/asm/armv4-mont.pl +0 -694
- data/vendor/ring/crypto/bn/asm/armv8-mont.pl +0 -1503
- data/vendor/ring/crypto/bn/asm/bn-586.pl +0 -774
- data/vendor/ring/crypto/bn/asm/co-586.pl +0 -287
- data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +0 -1882
- data/vendor/ring/crypto/bn/asm/x86-mont.pl +0 -592
- data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +0 -599
- data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +0 -1393
- data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +0 -3507
- data/vendor/ring/crypto/bn/bn.c +0 -352
- data/vendor/ring/crypto/bn/bn_asn1.c +0 -74
- data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/bn/bn_test.cc +0 -1696
- data/vendor/ring/crypto/bn/cmp.c +0 -200
- data/vendor/ring/crypto/bn/convert.c +0 -433
- data/vendor/ring/crypto/bn/ctx.c +0 -311
- data/vendor/ring/crypto/bn/div.c +0 -594
- data/vendor/ring/crypto/bn/exponentiation.c +0 -1335
- data/vendor/ring/crypto/bn/gcd.c +0 -711
- data/vendor/ring/crypto/bn/generic.c +0 -1019
- data/vendor/ring/crypto/bn/internal.h +0 -316
- data/vendor/ring/crypto/bn/montgomery.c +0 -516
- data/vendor/ring/crypto/bn/mul.c +0 -888
- data/vendor/ring/crypto/bn/prime.c +0 -829
- data/vendor/ring/crypto/bn/random.c +0 -334
- data/vendor/ring/crypto/bn/rsaz_exp.c +0 -262
- data/vendor/ring/crypto/bn/rsaz_exp.h +0 -53
- data/vendor/ring/crypto/bn/shift.c +0 -276
- data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/bytestring/bytestring_test.cc +0 -421
- data/vendor/ring/crypto/bytestring/cbb.c +0 -399
- data/vendor/ring/crypto/bytestring/cbs.c +0 -227
- data/vendor/ring/crypto/bytestring/internal.h +0 -46
- data/vendor/ring/crypto/chacha/chacha_generic.c +0 -140
- data/vendor/ring/crypto/chacha/chacha_vec.c +0 -323
- data/vendor/ring/crypto/chacha/chacha_vec_arm.S +0 -1447
- data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +0 -153
- data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/cipher/e_aes.c +0 -390
- data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +0 -208
- data/vendor/ring/crypto/cipher/internal.h +0 -173
- data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +0 -543
- data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +0 -9
- data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +0 -475
- data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +0 -23
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +0 -422
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +0 -484
- data/vendor/ring/crypto/cipher/test/cipher_test.txt +0 -100
- data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/constant_time_test.c +0 -304
- data/vendor/ring/crypto/cpu-arm-asm.S +0 -32
- data/vendor/ring/crypto/cpu-arm.c +0 -199
- data/vendor/ring/crypto/cpu-intel.c +0 -261
- data/vendor/ring/crypto/crypto.c +0 -151
- data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +0 -2118
- data/vendor/ring/crypto/curve25519/curve25519.c +0 -4888
- data/vendor/ring/crypto/curve25519/x25519_test.cc +0 -128
- data/vendor/ring/crypto/digest/md32_common.h +0 -181
- data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +0 -2725
- data/vendor/ring/crypto/ec/ec.c +0 -193
- data/vendor/ring/crypto/ec/ec_curves.c +0 -61
- data/vendor/ring/crypto/ec/ec_key.c +0 -228
- data/vendor/ring/crypto/ec/ec_montgomery.c +0 -114
- data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/ec/internal.h +0 -243
- data/vendor/ring/crypto/ec/oct.c +0 -253
- data/vendor/ring/crypto/ec/p256-64.c +0 -1794
- data/vendor/ring/crypto/ec/p256-x86_64-table.h +0 -9548
- data/vendor/ring/crypto/ec/p256-x86_64.c +0 -509
- data/vendor/ring/crypto/ec/simple.c +0 -1007
- data/vendor/ring/crypto/ec/util-64.c +0 -183
- data/vendor/ring/crypto/ec/wnaf.c +0 -508
- data/vendor/ring/crypto/ecdh/ecdh.c +0 -155
- data/vendor/ring/crypto/ecdsa/ecdsa.c +0 -304
- data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +0 -193
- data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +0 -327
- data/vendor/ring/crypto/header_removed.h +0 -17
- data/vendor/ring/crypto/internal.h +0 -495
- data/vendor/ring/crypto/libring.Windows.vcxproj +0 -101
- data/vendor/ring/crypto/mem.c +0 -98
- data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +0 -1045
- data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +0 -517
- data/vendor/ring/crypto/modes/asm/ghash-x86.pl +0 -1393
- data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +0 -1741
- data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +0 -422
- data/vendor/ring/crypto/modes/ctr.c +0 -226
- data/vendor/ring/crypto/modes/gcm.c +0 -1206
- data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/modes/gcm_test.c +0 -348
- data/vendor/ring/crypto/modes/internal.h +0 -299
- data/vendor/ring/crypto/perlasm/arm-xlate.pl +0 -170
- data/vendor/ring/crypto/perlasm/readme +0 -100
- data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +0 -1164
- data/vendor/ring/crypto/perlasm/x86asm.pl +0 -292
- data/vendor/ring/crypto/perlasm/x86gas.pl +0 -263
- data/vendor/ring/crypto/perlasm/x86masm.pl +0 -200
- data/vendor/ring/crypto/perlasm/x86nasm.pl +0 -187
- data/vendor/ring/crypto/poly1305/poly1305.c +0 -331
- data/vendor/ring/crypto/poly1305/poly1305_arm.c +0 -301
- data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +0 -2015
- data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/poly1305/poly1305_test.cc +0 -80
- data/vendor/ring/crypto/poly1305/poly1305_test.txt +0 -52
- data/vendor/ring/crypto/poly1305/poly1305_vec.c +0 -892
- data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +0 -75
- data/vendor/ring/crypto/rand/internal.h +0 -32
- data/vendor/ring/crypto/rand/rand.c +0 -189
- data/vendor/ring/crypto/rand/urandom.c +0 -219
- data/vendor/ring/crypto/rand/windows.c +0 -56
- data/vendor/ring/crypto/refcount_c11.c +0 -66
- data/vendor/ring/crypto/refcount_lock.c +0 -53
- data/vendor/ring/crypto/refcount_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/refcount_test.c +0 -58
- data/vendor/ring/crypto/rsa/blinding.c +0 -462
- data/vendor/ring/crypto/rsa/internal.h +0 -108
- data/vendor/ring/crypto/rsa/padding.c +0 -300
- data/vendor/ring/crypto/rsa/rsa.c +0 -450
- data/vendor/ring/crypto/rsa/rsa_asn1.c +0 -261
- data/vendor/ring/crypto/rsa/rsa_impl.c +0 -944
- data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/rsa/rsa_test.cc +0 -437
- data/vendor/ring/crypto/sha/asm/sha-armv8.pl +0 -436
- data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +0 -2390
- data/vendor/ring/crypto/sha/asm/sha256-586.pl +0 -1275
- data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +0 -735
- data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +0 -14
- data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +0 -14
- data/vendor/ring/crypto/sha/asm/sha512-586.pl +0 -911
- data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +0 -666
- data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +0 -14
- data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +0 -14
- data/vendor/ring/crypto/sha/sha1.c +0 -271
- data/vendor/ring/crypto/sha/sha256.c +0 -204
- data/vendor/ring/crypto/sha/sha512.c +0 -355
- data/vendor/ring/crypto/test/file_test.cc +0 -326
- data/vendor/ring/crypto/test/file_test.h +0 -181
- data/vendor/ring/crypto/test/malloc.cc +0 -150
- data/vendor/ring/crypto/test/scoped_types.h +0 -95
- data/vendor/ring/crypto/test/test.Windows.vcxproj +0 -35
- data/vendor/ring/crypto/test/test_util.cc +0 -46
- data/vendor/ring/crypto/test/test_util.h +0 -41
- data/vendor/ring/crypto/thread_none.c +0 -55
- data/vendor/ring/crypto/thread_pthread.c +0 -165
- data/vendor/ring/crypto/thread_test.Windows.vcxproj +0 -25
- data/vendor/ring/crypto/thread_test.c +0 -200
- data/vendor/ring/crypto/thread_win.c +0 -282
- data/vendor/ring/examples/checkdigest.rs +0 -103
- data/vendor/ring/include/openssl/aes.h +0 -121
- data/vendor/ring/include/openssl/arm_arch.h +0 -129
- data/vendor/ring/include/openssl/base.h +0 -156
- data/vendor/ring/include/openssl/bn.h +0 -794
- data/vendor/ring/include/openssl/buffer.h +0 -18
- data/vendor/ring/include/openssl/bytestring.h +0 -235
- data/vendor/ring/include/openssl/chacha.h +0 -37
- data/vendor/ring/include/openssl/cmac.h +0 -76
- data/vendor/ring/include/openssl/cpu.h +0 -184
- data/vendor/ring/include/openssl/crypto.h +0 -43
- data/vendor/ring/include/openssl/curve25519.h +0 -88
- data/vendor/ring/include/openssl/ec.h +0 -225
- data/vendor/ring/include/openssl/ec_key.h +0 -129
- data/vendor/ring/include/openssl/ecdh.h +0 -110
- data/vendor/ring/include/openssl/ecdsa.h +0 -156
- data/vendor/ring/include/openssl/err.h +0 -201
- data/vendor/ring/include/openssl/mem.h +0 -101
- data/vendor/ring/include/openssl/obj_mac.h +0 -71
- data/vendor/ring/include/openssl/opensslfeatures.h +0 -68
- data/vendor/ring/include/openssl/opensslv.h +0 -18
- data/vendor/ring/include/openssl/ossl_typ.h +0 -18
- data/vendor/ring/include/openssl/poly1305.h +0 -51
- data/vendor/ring/include/openssl/rand.h +0 -70
- data/vendor/ring/include/openssl/rsa.h +0 -399
- data/vendor/ring/include/openssl/thread.h +0 -133
- data/vendor/ring/include/openssl/type_check.h +0 -71
- data/vendor/ring/mk/Common.props +0 -63
- data/vendor/ring/mk/Windows.props +0 -42
- data/vendor/ring/mk/WindowsTest.props +0 -18
- data/vendor/ring/mk/appveyor.bat +0 -62
- data/vendor/ring/mk/bottom_of_makefile.mk +0 -54
- data/vendor/ring/mk/ring.mk +0 -266
- data/vendor/ring/mk/top_of_makefile.mk +0 -214
- data/vendor/ring/mk/travis.sh +0 -40
- data/vendor/ring/mk/update-travis-yml.py +0 -229
- data/vendor/ring/ring.sln +0 -153
- data/vendor/ring/src/aead.rs +0 -682
- data/vendor/ring/src/agreement.rs +0 -248
- data/vendor/ring/src/c.rs +0 -129
- data/vendor/ring/src/constant_time.rs +0 -37
- data/vendor/ring/src/der.rs +0 -96
- data/vendor/ring/src/digest.rs +0 -690
- data/vendor/ring/src/digest_tests.txt +0 -57
- data/vendor/ring/src/ecc.rs +0 -28
- data/vendor/ring/src/ecc_build.rs +0 -279
- data/vendor/ring/src/ecc_curves.rs +0 -117
- data/vendor/ring/src/ed25519_tests.txt +0 -2579
- data/vendor/ring/src/exe_tests.rs +0 -46
- data/vendor/ring/src/ffi.rs +0 -29
- data/vendor/ring/src/file_test.rs +0 -187
- data/vendor/ring/src/hkdf.rs +0 -153
- data/vendor/ring/src/hkdf_tests.txt +0 -59
- data/vendor/ring/src/hmac.rs +0 -414
- data/vendor/ring/src/hmac_tests.txt +0 -97
- data/vendor/ring/src/input.rs +0 -312
- data/vendor/ring/src/lib.rs +0 -41
- data/vendor/ring/src/pbkdf2.rs +0 -265
- data/vendor/ring/src/pbkdf2_tests.txt +0 -113
- data/vendor/ring/src/polyfill.rs +0 -57
- data/vendor/ring/src/rand.rs +0 -28
- data/vendor/ring/src/signature.rs +0 -314
- data/vendor/ring/third-party/NIST/README.md +0 -9
- data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +0 -263
- data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +0 -309
- data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +0 -267
- data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +0 -263
- data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +0 -309
- data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +0 -267
- data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +0 -263
- data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +0 -309
- data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +0 -267
- data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +0 -519
- data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +0 -309
- data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +0 -523
- data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +0 -519
- data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +0 -309
- data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +0 -523
- data/vendor/ring/third-party/NIST/sha256sums.txt +0 -1
@@ -1,25 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
-
<PropertyGroup Label="Globals">
|
4
|
-
<ProjectGuid>{F28F10A9-540F-4FC9-AD81-79E79F3FC73D}</ProjectGuid>
|
5
|
-
<TargetName>rsa_test</TargetName>
|
6
|
-
</PropertyGroup>
|
7
|
-
<ImportGroup Label="PropertySheets">
|
8
|
-
<Import Project="..\..\mk\WindowsTest.props" />
|
9
|
-
</ImportGroup>
|
10
|
-
<PropertyGroup Label="Configuration">
|
11
|
-
<OutDir>$(OutRootDir)test\ring\crypto\rsa\</OutDir>
|
12
|
-
</PropertyGroup>
|
13
|
-
<ItemGroup>
|
14
|
-
<ClCompile Include="rsa_test.cc" />
|
15
|
-
</ItemGroup>
|
16
|
-
<ItemGroup>
|
17
|
-
<ProjectReference Include="..\libring.Windows.vcxproj">
|
18
|
-
<Project>{f4c0a1b6-5e09-41c8-8242-3e1f6762fb18}</Project>
|
19
|
-
</ProjectReference>
|
20
|
-
<ProjectReference Include="..\test\test.Windows.vcxproj">
|
21
|
-
<Project>{1dace503-6498-492d-b1ff-f9ee18624443}</Project>
|
22
|
-
</ProjectReference>
|
23
|
-
</ItemGroup>
|
24
|
-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
25
|
-
</Project>
|
@@ -1,437 +0,0 @@
|
|
1
|
-
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
2
|
-
* All rights reserved.
|
3
|
-
*
|
4
|
-
* This package is an SSL implementation written
|
5
|
-
* by Eric Young (eay@cryptsoft.com).
|
6
|
-
* The implementation was written so as to conform with Netscapes SSL.
|
7
|
-
*
|
8
|
-
* This library is free for commercial and non-commercial use as long as
|
9
|
-
* the following conditions are aheared to. The following conditions
|
10
|
-
* apply to all code found in this distribution, be it the RC4, RSA,
|
11
|
-
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
12
|
-
* included with this distribution is covered by the same copyright terms
|
13
|
-
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
14
|
-
*
|
15
|
-
* Copyright remains Eric Young's, and as such any Copyright notices in
|
16
|
-
* the code are not to be removed.
|
17
|
-
* If this package is used in a product, Eric Young should be given attribution
|
18
|
-
* as the author of the parts of the library used.
|
19
|
-
* This can be in the form of a textual message at program startup or
|
20
|
-
* in documentation (online or textual) provided with the package.
|
21
|
-
*
|
22
|
-
* Redistribution and use in source and binary forms, with or without
|
23
|
-
* modification, are permitted provided that the following conditions
|
24
|
-
* are met:
|
25
|
-
* 1. Redistributions of source code must retain the copyright
|
26
|
-
* notice, this list of conditions and the following disclaimer.
|
27
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
28
|
-
* notice, this list of conditions and the following disclaimer in the
|
29
|
-
* documentation and/or other materials provided with the distribution.
|
30
|
-
* 3. All advertising materials mentioning features or use of this software
|
31
|
-
* must display the following acknowledgement:
|
32
|
-
* "This product includes cryptographic software written by
|
33
|
-
* Eric Young (eay@cryptsoft.com)"
|
34
|
-
* The word 'cryptographic' can be left out if the rouines from the library
|
35
|
-
* being used are not cryptographic related :-).
|
36
|
-
* 4. If you include any Windows specific code (or a derivative thereof) from
|
37
|
-
* the apps directory (application code) you must include an acknowledgement:
|
38
|
-
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
39
|
-
*
|
40
|
-
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
41
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
44
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50
|
-
* SUCH DAMAGE.
|
51
|
-
*
|
52
|
-
* The licence and distribution terms for any publically available version or
|
53
|
-
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
54
|
-
* copied and put under another distribution licence
|
55
|
-
* [including the GNU Public Licence.] */
|
56
|
-
|
57
|
-
#include <openssl/rsa.h>
|
58
|
-
|
59
|
-
#include <stdlib.h>
|
60
|
-
#include <string.h>
|
61
|
-
|
62
|
-
#include <openssl/bn.h>
|
63
|
-
#include <openssl/crypto.h>
|
64
|
-
#include <openssl/err.h>
|
65
|
-
#include <openssl/obj_mac.h>
|
66
|
-
|
67
|
-
#include "../test/scoped_types.h"
|
68
|
-
|
69
|
-
|
70
|
-
// kPlaintext is a sample plaintext.
|
71
|
-
static const uint8_t kPlaintext[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
|
72
|
-
static const size_t kPlaintextLen = sizeof(kPlaintext) - 1;
|
73
|
-
|
74
|
-
// kKey1 is a DER-encoded RSAPrivateKey.
|
75
|
-
static const uint8_t kKey1[] =
|
76
|
-
"\x30\x82\x01\x38\x02\x01\x00\x02\x41\x00\xaa\x36\xab\xce\x88\xac\xfd\xff"
|
77
|
-
"\x55\x52\x3c\x7f\xc4\x52\x3f\x90\xef\xa0\x0d\xf3\x77\x4a\x25\x9f\x2e\x62"
|
78
|
-
"\xb4\xc5\xd9\x9c\xb5\xad\xb3\x00\xa0\x28\x5e\x53\x01\x93\x0e\x0c\x70\xfb"
|
79
|
-
"\x68\x76\x93\x9c\xe6\x16\xce\x62\x4a\x11\xe0\x08\x6d\x34\x1e\xbc\xac\xa0"
|
80
|
-
"\xa1\xf5\x02\x01\x11\x02\x40\x0a\x03\x37\x48\x62\x64\x87\x69\x5f\x5f\x30"
|
81
|
-
"\xbc\x38\xb9\x8b\x44\xc2\xcd\x2d\xff\x43\x40\x98\xcd\x20\xd8\xa1\x38\xd0"
|
82
|
-
"\x90\xbf\x64\x79\x7c\x3f\xa7\xa2\xcd\xcb\x3c\xd1\xe0\xbd\xba\x26\x54\xb4"
|
83
|
-
"\xf9\xdf\x8e\x8a\xe5\x9d\x73\x3d\x9f\x33\xb3\x01\x62\x4a\xfd\x1d\x51\x02"
|
84
|
-
"\x21\x00\xd8\x40\xb4\x16\x66\xb4\x2e\x92\xea\x0d\xa3\xb4\x32\x04\xb5\xcf"
|
85
|
-
"\xce\x33\x52\x52\x4d\x04\x16\xa5\xa4\x41\xe7\x00\xaf\x46\x12\x0d\x02\x21"
|
86
|
-
"\x00\xc9\x7f\xb1\xf0\x27\xf4\x53\xf6\x34\x12\x33\xea\xaa\xd1\xd9\x35\x3f"
|
87
|
-
"\x6c\x42\xd0\x88\x66\xb1\xd0\x5a\x0f\x20\x35\x02\x8b\x9d\x89\x02\x20\x59"
|
88
|
-
"\x0b\x95\x72\xa2\xc2\xa9\xc4\x06\x05\x9d\xc2\xab\x2f\x1d\xaf\xeb\x7e\x8b"
|
89
|
-
"\x4f\x10\xa7\x54\x9e\x8e\xed\xf5\xb4\xfc\xe0\x9e\x05\x02\x21\x00\x8e\x3c"
|
90
|
-
"\x05\x21\xfe\x15\xe0\xea\x06\xa3\x6f\xf0\xf1\x0c\x99\x52\xc3\x5b\x7a\x75"
|
91
|
-
"\x14\xfd\x32\x38\xb8\x0a\xad\x52\x98\x62\x8d\x51\x02\x20\x36\x3f\xf7\x18"
|
92
|
-
"\x9d\xa8\xe9\x0b\x1d\x34\x1f\x71\xd0\x9b\x76\xa8\xa9\x43\xe1\x1d\x10\xb2"
|
93
|
-
"\x4d\x24\x9f\x2d\xea\xfe\xf8\x0c\x18\x26";
|
94
|
-
|
95
|
-
// kOAEPCiphertext1 is a sample encryption of |kPlaintext| with |kKey1| using
|
96
|
-
// RSA OAEP.
|
97
|
-
static const uint8_t kOAEPCiphertext1[] =
|
98
|
-
"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89\x2b\xfb"
|
99
|
-
"\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52\x33\x89\x5c\x74"
|
100
|
-
"\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44\xb0\x05\xc3\x9e\xd8\x27"
|
101
|
-
"\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
|
102
|
-
|
103
|
-
// kKey2 is a DER-encoded RSAPrivateKey.
|
104
|
-
static const uint8_t kKey2[] =
|
105
|
-
"\x30\x81\xfb\x02\x01\x00\x02\x33\x00\xa3\x07\x9a\x90\xdf\x0d\xfd\x72\xac"
|
106
|
-
"\x09\x0c\xcc\x2a\x78\xb8\x74\x13\x13\x3e\x40\x75\x9c\x98\xfa\xf8\x20\x4f"
|
107
|
-
"\x35\x8a\x0b\x26\x3c\x67\x70\xe7\x83\xa9\x3b\x69\x71\xb7\x37\x79\xd2\x71"
|
108
|
-
"\x7b\xe8\x34\x77\xcf\x02\x01\x03\x02\x32\x6c\xaf\xbc\x60\x94\xb3\xfe\x4c"
|
109
|
-
"\x72\xb0\xb3\x32\xc6\xfb\x25\xa2\xb7\x62\x29\x80\x4e\x68\x65\xfc\xa4\x5a"
|
110
|
-
"\x74\xdf\x0f\x8f\xb8\x41\x3b\x52\xc0\xd0\xe5\x3d\x9b\x59\x0f\xf1\x9b\xe7"
|
111
|
-
"\x9f\x49\xdd\x21\xe5\xeb\x02\x1a\x00\xcf\x20\x35\x02\x8b\x9d\x86\x98\x40"
|
112
|
-
"\xb4\x16\x66\xb4\x2e\x92\xea\x0d\xa3\xb4\x32\x04\xb5\xcf\xce\x91\x02\x1a"
|
113
|
-
"\x00\xc9\x7f\xb1\xf0\x27\xf4\x53\xf6\x34\x12\x33\xea\xaa\xd1\xd9\x35\x3f"
|
114
|
-
"\x6c\x42\xd0\x88\x66\xb1\xd0\x5f\x02\x1a\x00\x8a\x15\x78\xac\x5d\x13\xaf"
|
115
|
-
"\x10\x2b\x22\xb9\x99\xcd\x74\x61\xf1\x5e\x6d\x22\xcc\x03\x23\xdf\xdf\x0b"
|
116
|
-
"\x02\x1a\x00\x86\x55\x21\x4a\xc5\x4d\x8d\x4e\xcd\x61\x77\xf1\xc7\x36\x90"
|
117
|
-
"\xce\x2a\x48\x2c\x8b\x05\x99\xcb\xe0\x3f\x02\x1a\x00\x83\xef\xef\xb8\xa9"
|
118
|
-
"\xa4\x0d\x1d\xb6\xed\x98\xad\x84\xed\x13\x35\xdc\xc1\x08\xf3\x22\xd0\x57"
|
119
|
-
"\xcf\x8d";
|
120
|
-
|
121
|
-
// kOAEPCiphertext2 is a sample encryption of |kPlaintext| with |kKey2| using
|
122
|
-
// RSA OAEP.
|
123
|
-
static const uint8_t kOAEPCiphertext2[] =
|
124
|
-
"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a\x8b\x40"
|
125
|
-
"\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4\x17\x53\x03\x29"
|
126
|
-
"\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52\x62\x51";
|
127
|
-
|
128
|
-
// kKey3 is a DER-encoded RSAPrivateKey.
|
129
|
-
static const uint8_t kKey3[] =
|
130
|
-
"\x30\x82\x02\x5b\x02\x01\x00\x02\x81\x81\x00\xbb\xf8\x2f\x09\x06\x82\xce"
|
131
|
-
"\x9c\x23\x38\xac\x2b\x9d\xa8\x71\xf7\x36\x8d\x07\xee\xd4\x10\x43\xa4\x40"
|
132
|
-
"\xd6\xb6\xf0\x74\x54\xf5\x1f\xb8\xdf\xba\xaf\x03\x5c\x02\xab\x61\xea\x48"
|
133
|
-
"\xce\xeb\x6f\xcd\x48\x76\xed\x52\x0d\x60\xe1\xec\x46\x19\x71\x9d\x8a\x5b"
|
134
|
-
"\x8b\x80\x7f\xaf\xb8\xe0\xa3\xdf\xc7\x37\x72\x3e\xe6\xb4\xb7\xd9\x3a\x25"
|
135
|
-
"\x84\xee\x6a\x64\x9d\x06\x09\x53\x74\x88\x34\xb2\x45\x45\x98\x39\x4e\xe0"
|
136
|
-
"\xaa\xb1\x2d\x7b\x61\xa5\x1f\x52\x7a\x9a\x41\xf6\xc1\x68\x7f\xe2\x53\x72"
|
137
|
-
"\x98\xca\x2a\x8f\x59\x46\xf8\xe5\xfd\x09\x1d\xbd\xcb\x02\x01\x11\x02\x81"
|
138
|
-
"\x81\x00\xa5\xda\xfc\x53\x41\xfa\xf2\x89\xc4\xb9\x88\xdb\x30\xc1\xcd\xf8"
|
139
|
-
"\x3f\x31\x25\x1e\x06\x68\xb4\x27\x84\x81\x38\x01\x57\x96\x41\xb2\x94\x10"
|
140
|
-
"\xb3\xc7\x99\x8d\x6b\xc4\x65\x74\x5e\x5c\x39\x26\x69\xd6\x87\x0d\xa2\xc0"
|
141
|
-
"\x82\xa9\x39\xe3\x7f\xdc\xb8\x2e\xc9\x3e\xda\xc9\x7f\xf3\xad\x59\x50\xac"
|
142
|
-
"\xcf\xbc\x11\x1c\x76\xf1\xa9\x52\x94\x44\xe5\x6a\xaf\x68\xc5\x6c\x09\x2c"
|
143
|
-
"\xd3\x8d\xc3\xbe\xf5\xd2\x0a\x93\x99\x26\xed\x4f\x74\xa1\x3e\xdd\xfb\xe1"
|
144
|
-
"\xa1\xce\xcc\x48\x94\xaf\x94\x28\xc2\xb7\xb8\x88\x3f\xe4\x46\x3a\x4b\xc8"
|
145
|
-
"\x5b\x1c\xb3\xc1\x02\x41\x00\xee\xcf\xae\x81\xb1\xb9\xb3\xc9\x08\x81\x0b"
|
146
|
-
"\x10\xa1\xb5\x60\x01\x99\xeb\x9f\x44\xae\xf4\xfd\xa4\x93\xb8\x1a\x9e\x3d"
|
147
|
-
"\x84\xf6\x32\x12\x4e\xf0\x23\x6e\x5d\x1e\x3b\x7e\x28\xfa\xe7\xaa\x04\x0a"
|
148
|
-
"\x2d\x5b\x25\x21\x76\x45\x9d\x1f\x39\x75\x41\xba\x2a\x58\xfb\x65\x99\x02"
|
149
|
-
"\x41\x00\xc9\x7f\xb1\xf0\x27\xf4\x53\xf6\x34\x12\x33\xea\xaa\xd1\xd9\x35"
|
150
|
-
"\x3f\x6c\x42\xd0\x88\x66\xb1\xd0\x5a\x0f\x20\x35\x02\x8b\x9d\x86\x98\x40"
|
151
|
-
"\xb4\x16\x66\xb4\x2e\x92\xea\x0d\xa3\xb4\x32\x04\xb5\xcf\xce\x33\x52\x52"
|
152
|
-
"\x4d\x04\x16\xa5\xa4\x41\xe7\x00\xaf\x46\x15\x03\x02\x40\x54\x49\x4c\xa6"
|
153
|
-
"\x3e\xba\x03\x37\xe4\xe2\x40\x23\xfc\xd6\x9a\x5a\xeb\x07\xdd\xdc\x01\x83"
|
154
|
-
"\xa4\xd0\xac\x9b\x54\xb0\x51\xf2\xb1\x3e\xd9\x49\x09\x75\xea\xb7\x74\x14"
|
155
|
-
"\xff\x59\xc1\xf7\x69\x2e\x9a\x2e\x20\x2b\x38\xfc\x91\x0a\x47\x41\x74\xad"
|
156
|
-
"\xc9\x3c\x1f\x67\xc9\x81\x02\x40\x47\x1e\x02\x90\xff\x0a\xf0\x75\x03\x51"
|
157
|
-
"\xb7\xf8\x78\x86\x4c\xa9\x61\xad\xbd\x3a\x8a\x7e\x99\x1c\x5c\x05\x56\xa9"
|
158
|
-
"\x4c\x31\x46\xa7\xf9\x80\x3f\x8f\x6f\x8a\xe3\x42\xe9\x31\xfd\x8a\xe4\x7a"
|
159
|
-
"\x22\x0d\x1b\x99\xa4\x95\x84\x98\x07\xfe\x39\xf9\x24\x5a\x98\x36\xda\x3d"
|
160
|
-
"\x02\x41\x00\xb0\x6c\x4f\xda\xbb\x63\x01\x19\x8d\x26\x5b\xdb\xae\x94\x23"
|
161
|
-
"\xb3\x80\xf2\x71\xf7\x34\x53\x88\x50\x93\x07\x7f\xcd\x39\xe2\x11\x9f\xc9"
|
162
|
-
"\x86\x32\x15\x4f\x58\x83\xb1\x67\xa9\x67\xbf\x40\x2b\x4e\x9e\x2e\x0f\x96"
|
163
|
-
"\x56\xe6\x98\xea\x36\x66\xed\xfb\x25\x79\x80\x39\xf7";
|
164
|
-
|
165
|
-
// kOAEPCiphertext3 is a sample encryption of |kPlaintext| with |kKey3| using
|
166
|
-
// RSA OAEP.
|
167
|
-
static const uint8_t kOAEPCiphertext3[] =
|
168
|
-
"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7\x90\xc4"
|
169
|
-
"\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce\xf0\xc4\x36\x6f"
|
170
|
-
"\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3\xf2\xf1\x92\xdb\xea\xca"
|
171
|
-
"\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06\x69\xac\x22\xe9\xf3\xa7\x85\x2e"
|
172
|
-
"\x3c\x15\xd9\x13\xca\xb0\xb8\x86\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49"
|
173
|
-
"\x54\x61\x03\x46\xf4\xd4\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a"
|
174
|
-
"\x1f\xc4\x02\x6a\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20"
|
175
|
-
"\x2f\xb1";
|
176
|
-
|
177
|
-
|
178
|
-
static bool TestRSA(const uint8_t *der, size_t der_len,
|
179
|
-
const uint8_t *oaep_ciphertext,
|
180
|
-
size_t oaep_ciphertext_len) {
|
181
|
-
ScopedRSA key(RSA_private_key_from_bytes(der, der_len));
|
182
|
-
if (!key) {
|
183
|
-
return false;
|
184
|
-
}
|
185
|
-
|
186
|
-
if (!RSA_check_key(key.get())) {
|
187
|
-
fprintf(stderr, "RSA_check_key failed\n");
|
188
|
-
return false;
|
189
|
-
}
|
190
|
-
|
191
|
-
uint8_t ciphertext[256];
|
192
|
-
|
193
|
-
size_t ciphertext_len = 0;
|
194
|
-
if (!RSA_encrypt(key.get(), &ciphertext_len, ciphertext, sizeof(ciphertext),
|
195
|
-
kPlaintext, kPlaintextLen, RSA_PKCS1_PADDING) ||
|
196
|
-
ciphertext_len != RSA_size(key.get())) {
|
197
|
-
fprintf(stderr, "PKCS#1 v1.5 encryption failed!\n");
|
198
|
-
return false;
|
199
|
-
}
|
200
|
-
|
201
|
-
uint8_t plaintext[256];
|
202
|
-
size_t plaintext_len = 0;
|
203
|
-
if (!RSA_decrypt(key.get(), &plaintext_len, plaintext, sizeof(plaintext),
|
204
|
-
ciphertext, ciphertext_len, RSA_PKCS1_PADDING) ||
|
205
|
-
plaintext_len != kPlaintextLen ||
|
206
|
-
memcmp(plaintext, kPlaintext, plaintext_len) != 0) {
|
207
|
-
fprintf(stderr, "PKCS#1 v1.5 decryption failed!\n");
|
208
|
-
return false;
|
209
|
-
}
|
210
|
-
|
211
|
-
/* ring: OAEP padding is not implemented yet. */
|
212
|
-
#if 0
|
213
|
-
ciphertext_len = 0;
|
214
|
-
if (!RSA_encrypt(key.get(), &ciphertext_len, ciphertext, sizeof(ciphertext),
|
215
|
-
kPlaintext, kPlaintextLen, RSA_PKCS1_OAEP_PADDING) ||
|
216
|
-
ciphertext_len != RSA_size(key.get())) {
|
217
|
-
fprintf(stderr, "OAEP encryption failed!\n");
|
218
|
-
return false;
|
219
|
-
}
|
220
|
-
|
221
|
-
plaintext_len = 0;
|
222
|
-
if (!RSA_decrypt(key.get(), &plaintext_len, plaintext, sizeof(plaintext),
|
223
|
-
ciphertext, ciphertext_len, RSA_PKCS1_OAEP_PADDING) ||
|
224
|
-
plaintext_len != kPlaintextLen ||
|
225
|
-
memcmp(plaintext, kPlaintext, plaintext_len) != 0) {
|
226
|
-
fprintf(stderr, "OAEP decryption (encrypted data) failed!\n");
|
227
|
-
return false;
|
228
|
-
}
|
229
|
-
|
230
|
-
// |oaep_ciphertext| should decrypt to |kPlaintext|.
|
231
|
-
plaintext_len = 0;
|
232
|
-
if (!RSA_decrypt(key.get(), &plaintext_len, plaintext, sizeof(plaintext),
|
233
|
-
oaep_ciphertext, oaep_ciphertext_len,
|
234
|
-
RSA_PKCS1_OAEP_PADDING) ||
|
235
|
-
plaintext_len != kPlaintextLen ||
|
236
|
-
memcmp(plaintext, kPlaintext, plaintext_len) != 0) {
|
237
|
-
fprintf(stderr, "OAEP decryption (test vector data) failed!\n");
|
238
|
-
return false;
|
239
|
-
}
|
240
|
-
|
241
|
-
// Try decrypting corrupted ciphertexts.
|
242
|
-
memcpy(ciphertext, oaep_ciphertext, oaep_ciphertext_len);
|
243
|
-
for (size_t i = 0; i < oaep_ciphertext_len; i++) {
|
244
|
-
ciphertext[i] ^= 1;
|
245
|
-
if (RSA_decrypt(key.get(), &plaintext_len, plaintext, sizeof(plaintext),
|
246
|
-
ciphertext, oaep_ciphertext_len, RSA_PKCS1_OAEP_PADDING)) {
|
247
|
-
fprintf(stderr, "Corrupt data decrypted!\n");
|
248
|
-
return false;
|
249
|
-
}
|
250
|
-
ciphertext[i] ^= 1;
|
251
|
-
}
|
252
|
-
|
253
|
-
// Test truncated ciphertexts.
|
254
|
-
for (size_t len = 0; len < oaep_ciphertext_len; len++) {
|
255
|
-
if (RSA_decrypt(key.get(), &plaintext_len, plaintext, sizeof(plaintext),
|
256
|
-
ciphertext, len, RSA_PKCS1_OAEP_PADDING)) {
|
257
|
-
fprintf(stderr, "Corrupt data decrypted!\n");
|
258
|
-
return false;
|
259
|
-
}
|
260
|
-
}
|
261
|
-
#endif /* if 0 */
|
262
|
-
|
263
|
-
return true;
|
264
|
-
}
|
265
|
-
|
266
|
-
static bool TestBadKey() {
|
267
|
-
ScopedRSA key(RSA_new());
|
268
|
-
ScopedBIGNUM e(BN_new());
|
269
|
-
|
270
|
-
if (!key || !e || !BN_set_word(e.get(), RSA_F4)) {
|
271
|
-
return false;
|
272
|
-
}
|
273
|
-
|
274
|
-
if (!RSA_generate_key_ex(key.get(), 512, e.get(), nullptr)) {
|
275
|
-
fprintf(stderr, "RSA_generate_key_ex failed.\n");
|
276
|
-
return false;
|
277
|
-
}
|
278
|
-
|
279
|
-
if (!BN_add(key->p, key->p, BN_value_one())) {
|
280
|
-
fprintf(stderr, "BN error.\n");
|
281
|
-
return false;
|
282
|
-
}
|
283
|
-
|
284
|
-
if (RSA_check_key(key.get())) {
|
285
|
-
fprintf(stderr, "RSA_check_key passed with invalid key!\n");
|
286
|
-
return false;
|
287
|
-
}
|
288
|
-
|
289
|
-
ERR_clear_error();
|
290
|
-
return true;
|
291
|
-
}
|
292
|
-
|
293
|
-
static bool TestOnlyDGiven() {
|
294
|
-
uint8_t buf[64];
|
295
|
-
unsigned buf_len = sizeof(buf);
|
296
|
-
ScopedRSA key(RSA_new());
|
297
|
-
if (!key ||
|
298
|
-
!BN_hex2bn(&key->n,
|
299
|
-
"00e77bbf3889d4ef36a9a25d4d69f3f632eb4362214c74517da6d6aeaa9bd"
|
300
|
-
"09ac42b26621cd88f3a6eb013772fc3bf9f83914b6467231c630202c35b3e"
|
301
|
-
"5808c659") ||
|
302
|
-
!BN_hex2bn(&key->e, "010001") ||
|
303
|
-
!BN_hex2bn(&key->d,
|
304
|
-
"0365db9eb6d73b53b015c40cd8db4de7dd7035c68b5ac1bf786d7a4ee2cea"
|
305
|
-
"316eaeca21a73ac365e58713195f2ae9849348525ca855386b6d028e437a9"
|
306
|
-
"495a01") ||
|
307
|
-
RSA_size(key.get()) > sizeof(buf)) {
|
308
|
-
return false;
|
309
|
-
}
|
310
|
-
|
311
|
-
if (!RSA_check_key(key.get())) {
|
312
|
-
fprintf(stderr, "RSA_check_key failed with only d given.\n");
|
313
|
-
return false;
|
314
|
-
}
|
315
|
-
|
316
|
-
const uint8_t kDummyHash[16] = {0};
|
317
|
-
|
318
|
-
if (!RSA_sign(NID_sha256, kDummyHash, sizeof(kDummyHash), buf, &buf_len,
|
319
|
-
key.get())) {
|
320
|
-
fprintf(stderr, "RSA_sign failed with only d given.\n");
|
321
|
-
return false;
|
322
|
-
}
|
323
|
-
|
324
|
-
if (!RSA_verify(NID_sha256, kDummyHash, sizeof(kDummyHash), buf, buf_len,
|
325
|
-
key.get())) {
|
326
|
-
fprintf(stderr, "RSA_verify failed with only d given.\n");
|
327
|
-
return false;
|
328
|
-
}
|
329
|
-
|
330
|
-
return true;
|
331
|
-
}
|
332
|
-
|
333
|
-
static bool TestRecoverCRTParams() {
|
334
|
-
ScopedBIGNUM e(BN_new());
|
335
|
-
if (!e || !BN_set_word(e.get(), RSA_F4)) {
|
336
|
-
return false;
|
337
|
-
}
|
338
|
-
|
339
|
-
ERR_clear_error();
|
340
|
-
|
341
|
-
for (unsigned i = 0; i < 1; i++) {
|
342
|
-
ScopedRSA key1(RSA_new());
|
343
|
-
if (!key1 ||
|
344
|
-
!RSA_generate_key_ex(key1.get(), 512, e.get(), nullptr)) {
|
345
|
-
fprintf(stderr, "RSA_generate_key_ex failed.\n");
|
346
|
-
return false;
|
347
|
-
}
|
348
|
-
|
349
|
-
if (!RSA_check_key(key1.get())) {
|
350
|
-
fprintf(stderr, "RSA_check_key failed with original key.\n");
|
351
|
-
return false;
|
352
|
-
}
|
353
|
-
|
354
|
-
ScopedRSA key2(RSA_new());
|
355
|
-
if (!key2) {
|
356
|
-
return false;
|
357
|
-
}
|
358
|
-
key2->n = BN_dup(key1->n);
|
359
|
-
key2->e = BN_dup(key1->e);
|
360
|
-
key2->d = BN_dup(key1->d);
|
361
|
-
if (key2->n == nullptr || key2->e == nullptr || key2->d == nullptr) {
|
362
|
-
return false;
|
363
|
-
}
|
364
|
-
}
|
365
|
-
|
366
|
-
return true;
|
367
|
-
}
|
368
|
-
|
369
|
-
static bool TestASN1() {
|
370
|
-
// Test that private keys may be decoded.
|
371
|
-
ScopedRSA rsa(RSA_private_key_from_bytes(kKey1, sizeof(kKey1) - 1));
|
372
|
-
if (!rsa) {
|
373
|
-
return false;
|
374
|
-
}
|
375
|
-
|
376
|
-
// Test that the serialization round-trips.
|
377
|
-
uint8_t *der;
|
378
|
-
size_t der_len;
|
379
|
-
if (!RSA_private_key_to_bytes(&der, &der_len, rsa.get())) {
|
380
|
-
return false;
|
381
|
-
}
|
382
|
-
ScopedOpenSSLBytes delete_der(der);
|
383
|
-
if (der_len != sizeof(kKey1) - 1 || memcmp(der, kKey1, der_len) != 0) {
|
384
|
-
return false;
|
385
|
-
}
|
386
|
-
|
387
|
-
// Test that serializing public keys works.
|
388
|
-
if (!RSA_public_key_to_bytes(&der, &der_len, rsa.get())) {
|
389
|
-
return false;
|
390
|
-
}
|
391
|
-
delete_der.reset(der);
|
392
|
-
|
393
|
-
// Public keys may be parsed back out.
|
394
|
-
rsa.reset(RSA_public_key_from_bytes(der, der_len));
|
395
|
-
if (!rsa || rsa->p != NULL || rsa->q != NULL) {
|
396
|
-
return false;
|
397
|
-
}
|
398
|
-
|
399
|
-
// Serializing the result round-trips.
|
400
|
-
uint8_t *der2;
|
401
|
-
size_t der2_len;
|
402
|
-
if (!RSA_public_key_to_bytes(&der2, &der2_len, rsa.get())) {
|
403
|
-
return false;
|
404
|
-
}
|
405
|
-
ScopedOpenSSLBytes delete_der2(der2);
|
406
|
-
if (der_len != der2_len || memcmp(der, der2, der_len) != 0) {
|
407
|
-
return false;
|
408
|
-
}
|
409
|
-
|
410
|
-
// Public keys cannot be serialized as private keys.
|
411
|
-
if (RSA_private_key_to_bytes(&der, &der_len, rsa.get())) {
|
412
|
-
OPENSSL_free(der);
|
413
|
-
return false;
|
414
|
-
}
|
415
|
-
ERR_clear_error();
|
416
|
-
|
417
|
-
return true;
|
418
|
-
}
|
419
|
-
|
420
|
-
int main(int argc, char *argv[]) {
|
421
|
-
CRYPTO_library_init();
|
422
|
-
|
423
|
-
if (!TestRSA(kKey1, sizeof(kKey1) - 1, kOAEPCiphertext1,
|
424
|
-
sizeof(kOAEPCiphertext1) - 1) ||
|
425
|
-
!TestRSA(kKey2, sizeof(kKey2) - 1, kOAEPCiphertext2,
|
426
|
-
sizeof(kOAEPCiphertext2) - 1) ||
|
427
|
-
!TestRSA(kKey3, sizeof(kKey3) - 1, kOAEPCiphertext3,
|
428
|
-
sizeof(kOAEPCiphertext3) - 1) ||
|
429
|
-
!TestOnlyDGiven() ||
|
430
|
-
!TestRecoverCRTParams() ||
|
431
|
-
!TestBadKey() ||
|
432
|
-
!TestASN1()) {
|
433
|
-
return 1;
|
434
|
-
}
|
435
|
-
|
436
|
-
return 0;
|
437
|
-
}
|