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>{A8616FF5-8273-4C80-8BF0-1785D8E1DF74}</ProjectGuid>
|
5
|
-
<TargetName>gcm_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\modes\</OutDir>
|
12
|
-
</PropertyGroup>
|
13
|
-
<ItemGroup>
|
14
|
-
<ClCompile Include="gcm_test.c" />
|
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,348 +0,0 @@
|
|
1
|
-
/* ====================================================================
|
2
|
-
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
3
|
-
*
|
4
|
-
* Redistribution and use in source and binary forms, with or without
|
5
|
-
* modification, are permitted provided that the following conditions
|
6
|
-
* are met:
|
7
|
-
*
|
8
|
-
* 1. Redistributions of source code must retain the above copyright
|
9
|
-
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in
|
13
|
-
* the documentation and/or other materials provided with the
|
14
|
-
* distribution.
|
15
|
-
*
|
16
|
-
* 3. All advertising materials mentioning features or use of this
|
17
|
-
* software must display the following acknowledgment:
|
18
|
-
* "This product includes software developed by the OpenSSL Project
|
19
|
-
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
20
|
-
*
|
21
|
-
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
22
|
-
* endorse or promote products derived from this software without
|
23
|
-
* prior written permission. For written permission, please contact
|
24
|
-
* openssl-core@openssl.org.
|
25
|
-
*
|
26
|
-
* 5. Products derived from this software may not be called "OpenSSL"
|
27
|
-
* nor may "OpenSSL" appear in their names without prior written
|
28
|
-
* permission of the OpenSSL Project.
|
29
|
-
*
|
30
|
-
* 6. Redistributions of any form whatsoever must retain the following
|
31
|
-
* acknowledgment:
|
32
|
-
* "This product includes software developed by the OpenSSL Project
|
33
|
-
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
34
|
-
*
|
35
|
-
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
36
|
-
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
37
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
38
|
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
39
|
-
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
41
|
-
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
42
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
43
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
44
|
-
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
45
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
46
|
-
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
|
-
* ==================================================================== */
|
48
|
-
|
49
|
-
#include <stdio.h>
|
50
|
-
#include <string.h>
|
51
|
-
|
52
|
-
#include <openssl/aes.h>
|
53
|
-
#include <openssl/crypto.h>
|
54
|
-
#include <openssl/mem.h>
|
55
|
-
|
56
|
-
#include "internal.h"
|
57
|
-
#include "../test/test_util.h"
|
58
|
-
|
59
|
-
|
60
|
-
struct test_case {
|
61
|
-
const char *key;
|
62
|
-
const char *plaintext;
|
63
|
-
const char *additional_data;
|
64
|
-
const char *nonce;
|
65
|
-
const char *ciphertext;
|
66
|
-
const char *tag;
|
67
|
-
};
|
68
|
-
|
69
|
-
static const struct test_case test_cases[] = {
|
70
|
-
{
|
71
|
-
"00000000000000000000000000000000",
|
72
|
-
NULL,
|
73
|
-
NULL,
|
74
|
-
"000000000000000000000000",
|
75
|
-
NULL,
|
76
|
-
"58e2fccefa7e3061367f1d57a4e7455a",
|
77
|
-
},
|
78
|
-
{
|
79
|
-
"00000000000000000000000000000000",
|
80
|
-
"00000000000000000000000000000000",
|
81
|
-
NULL,
|
82
|
-
"000000000000000000000000",
|
83
|
-
"0388dace60b6a392f328c2b971b2fe78",
|
84
|
-
"ab6e47d42cec13bdf53a67b21257bddf",
|
85
|
-
},
|
86
|
-
{
|
87
|
-
"feffe9928665731c6d6a8f9467308308",
|
88
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
89
|
-
NULL,
|
90
|
-
"cafebabefacedbaddecaf888",
|
91
|
-
"42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f5985",
|
92
|
-
"4d5c2af327cd64a62cf35abd2ba6fab4",
|
93
|
-
},
|
94
|
-
{
|
95
|
-
"feffe9928665731c6d6a8f9467308308",
|
96
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
97
|
-
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
98
|
-
"cafebabefacedbaddecaf888",
|
99
|
-
"42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091",
|
100
|
-
"5bc94fbc3221a5db94fae95ae7121a47",
|
101
|
-
},
|
102
|
-
{
|
103
|
-
"000000000000000000000000000000000000000000000000",
|
104
|
-
NULL,
|
105
|
-
NULL,
|
106
|
-
"000000000000000000000000",
|
107
|
-
NULL,
|
108
|
-
"cd33b28ac773f74ba00ed1f312572435",
|
109
|
-
},
|
110
|
-
{
|
111
|
-
"000000000000000000000000000000000000000000000000",
|
112
|
-
"00000000000000000000000000000000",
|
113
|
-
NULL,
|
114
|
-
"000000000000000000000000",
|
115
|
-
"98e7247c07f0fe411c267e4384b0f600",
|
116
|
-
"2ff58d80033927ab8ef4d4587514f0fb",
|
117
|
-
},
|
118
|
-
{
|
119
|
-
"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
120
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
121
|
-
NULL,
|
122
|
-
"cafebabefacedbaddecaf888",
|
123
|
-
"3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710acade256",
|
124
|
-
"9924a7c8587336bfb118024db8674a14",
|
125
|
-
},
|
126
|
-
{
|
127
|
-
"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
128
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
129
|
-
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
130
|
-
"cafebabefacedbaddecaf888",
|
131
|
-
"3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710",
|
132
|
-
"2519498e80f1478f37ba55bd6d27618c",
|
133
|
-
},
|
134
|
-
{
|
135
|
-
"0000000000000000000000000000000000000000000000000000000000000000",
|
136
|
-
NULL,
|
137
|
-
NULL,
|
138
|
-
"000000000000000000000000",
|
139
|
-
NULL,
|
140
|
-
"530f8afbc74536b9a963b4f1c4cb738b",
|
141
|
-
},
|
142
|
-
{
|
143
|
-
"0000000000000000000000000000000000000000000000000000000000000000",
|
144
|
-
"00000000000000000000000000000000",
|
145
|
-
NULL,
|
146
|
-
"000000000000000000000000",
|
147
|
-
"cea7403d4d606b6e074ec5d3baf39d18",
|
148
|
-
"d0d1c8a799996bf0265b98b5d48ab919",
|
149
|
-
},
|
150
|
-
{
|
151
|
-
"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
152
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
153
|
-
NULL,
|
154
|
-
"cafebabefacedbaddecaf888",
|
155
|
-
"522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662898015ad",
|
156
|
-
"b094dac5d93471bdec1a502270e3cc6c",
|
157
|
-
},
|
158
|
-
{
|
159
|
-
"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
160
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
161
|
-
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
162
|
-
"cafebabefacedbaddecaf888",
|
163
|
-
"522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662",
|
164
|
-
"76fc6ece0f4e1768cddf8853bb2d551b",
|
165
|
-
},
|
166
|
-
{
|
167
|
-
"00000000000000000000000000000000",
|
168
|
-
NULL,
|
169
|
-
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662898015ad",
|
170
|
-
"000000000000000000000000",
|
171
|
-
NULL,
|
172
|
-
"5fea793a2d6f974d37e68e0cb8ff9492",
|
173
|
-
},
|
174
|
-
};
|
175
|
-
|
176
|
-
static int from_hex(uint8_t *out, char in) {
|
177
|
-
if (in >= '0' && in <= '9') {
|
178
|
-
*out = in - '0';
|
179
|
-
return 1;
|
180
|
-
}
|
181
|
-
if (in >= 'a' && in <= 'f') {
|
182
|
-
*out = in - 'a' + 10;
|
183
|
-
return 1;
|
184
|
-
}
|
185
|
-
if (in >= 'A' && in <= 'F') {
|
186
|
-
*out = in - 'A' + 10;
|
187
|
-
return 1;
|
188
|
-
}
|
189
|
-
|
190
|
-
return 0;
|
191
|
-
}
|
192
|
-
|
193
|
-
static int decode_hex(uint8_t **out, size_t *out_len, const char *in,
|
194
|
-
unsigned test_num, const char *description) {
|
195
|
-
uint8_t *buf = NULL;
|
196
|
-
size_t i;
|
197
|
-
|
198
|
-
if (in == NULL) {
|
199
|
-
*out = NULL;
|
200
|
-
*out_len = 0;
|
201
|
-
return 1;
|
202
|
-
}
|
203
|
-
|
204
|
-
size_t len = strlen(in);
|
205
|
-
if (len & 1) {
|
206
|
-
fprintf(stderr, "%u: Odd-length %s input.\n", test_num, description);
|
207
|
-
goto err;
|
208
|
-
}
|
209
|
-
|
210
|
-
buf = OPENSSL_malloc(len / 2);
|
211
|
-
if (buf == NULL) {
|
212
|
-
fprintf(stderr, "%u: malloc failure.\n", test_num);
|
213
|
-
goto err;
|
214
|
-
}
|
215
|
-
|
216
|
-
for (i = 0; i < len; i += 2) {
|
217
|
-
uint8_t v, v2;
|
218
|
-
if (!from_hex(&v, in[i]) ||
|
219
|
-
!from_hex(&v2, in[i+1])) {
|
220
|
-
fprintf(stderr,
|
221
|
-
"%u: invalid hex digit in %s around offset "
|
222
|
-
"%" OPENSSL_PR_SIZE_T ".\n", test_num, description, i);
|
223
|
-
goto err;
|
224
|
-
}
|
225
|
-
buf[i/2] = (v << 4) | v2;
|
226
|
-
}
|
227
|
-
|
228
|
-
*out = buf;
|
229
|
-
*out_len = len/2;
|
230
|
-
return 1;
|
231
|
-
|
232
|
-
err:
|
233
|
-
OPENSSL_free(buf);
|
234
|
-
return 0;
|
235
|
-
}
|
236
|
-
|
237
|
-
static int run_test_case(unsigned test_num, const struct test_case *test) {
|
238
|
-
size_t key_len, plaintext_len, additional_data_len, nonce_len, ciphertext_len,
|
239
|
-
tag_len;
|
240
|
-
uint8_t *key = NULL, *plaintext = NULL, *additional_data = NULL,
|
241
|
-
*nonce = NULL, *ciphertext = NULL, *tag = NULL, *out = NULL;
|
242
|
-
int ret = 0;
|
243
|
-
AES_KEY aes_key;
|
244
|
-
GCM128_CONTEXT ctx;
|
245
|
-
|
246
|
-
if (!decode_hex(&key, &key_len, test->key, test_num, "key") ||
|
247
|
-
!decode_hex(&plaintext, &plaintext_len, test->plaintext, test_num,
|
248
|
-
"plaintext") ||
|
249
|
-
!decode_hex(&additional_data, &additional_data_len, test->additional_data,
|
250
|
-
test_num, "additional_data") ||
|
251
|
-
!decode_hex(&nonce, &nonce_len, test->nonce, test_num, "nonce") ||
|
252
|
-
!decode_hex(&ciphertext, &ciphertext_len, test->ciphertext, test_num,
|
253
|
-
"ciphertext") ||
|
254
|
-
!decode_hex(&tag, &tag_len, test->tag, test_num, "tag")) {
|
255
|
-
goto out;
|
256
|
-
}
|
257
|
-
|
258
|
-
if (plaintext_len != ciphertext_len) {
|
259
|
-
fprintf(stderr, "%u: plaintext and ciphertext have differing lengths.\n",
|
260
|
-
test_num);
|
261
|
-
goto out;
|
262
|
-
}
|
263
|
-
|
264
|
-
if (nonce_len != 12) {
|
265
|
-
fprintf(stderr, "%u: bad nonce length.\n", test_num);
|
266
|
-
goto out;
|
267
|
-
}
|
268
|
-
|
269
|
-
if (key_len != 16 && key_len != 24 && key_len != 32) {
|
270
|
-
fprintf(stderr, "%u: bad key length.\n", test_num);
|
271
|
-
goto out;
|
272
|
-
}
|
273
|
-
|
274
|
-
if (tag_len != 16) {
|
275
|
-
fprintf(stderr, "%u: bad tag length.\n", test_num);
|
276
|
-
goto out;
|
277
|
-
}
|
278
|
-
|
279
|
-
out = OPENSSL_malloc(plaintext_len);
|
280
|
-
if (out == NULL) {
|
281
|
-
goto out;
|
282
|
-
}
|
283
|
-
if (AES_set_encrypt_key(key, key_len*8, &aes_key)) {
|
284
|
-
fprintf(stderr, "%u: AES_set_encrypt_key failed.\n", test_num);
|
285
|
-
goto out;
|
286
|
-
}
|
287
|
-
|
288
|
-
CRYPTO_gcm128_init(&ctx, &aes_key, (block128_f) AES_encrypt);
|
289
|
-
CRYPTO_gcm128_set_96_bit_iv(&ctx, &aes_key, nonce);
|
290
|
-
memset(out, 0, plaintext_len);
|
291
|
-
if (additional_data) {
|
292
|
-
CRYPTO_gcm128_aad(&ctx, additional_data, additional_data_len);
|
293
|
-
}
|
294
|
-
if (plaintext) {
|
295
|
-
CRYPTO_gcm128_encrypt(&ctx, &aes_key, plaintext, out, plaintext_len);
|
296
|
-
}
|
297
|
-
if (!CRYPTO_gcm128_finish(&ctx, tag, tag_len) ||
|
298
|
-
(ciphertext && memcmp(out, ciphertext, plaintext_len) != 0)) {
|
299
|
-
fprintf(stderr, "%u: encrypt failed.\n", test_num);
|
300
|
-
hexdump(stderr, "got :", out, plaintext_len);
|
301
|
-
hexdump(stderr, "want:", ciphertext, plaintext_len);
|
302
|
-
goto out;
|
303
|
-
}
|
304
|
-
|
305
|
-
CRYPTO_gcm128_set_96_bit_iv(&ctx, &aes_key, nonce);
|
306
|
-
memset(out, 0, plaintext_len);
|
307
|
-
if (additional_data) {
|
308
|
-
CRYPTO_gcm128_aad(&ctx, additional_data, additional_data_len);
|
309
|
-
}
|
310
|
-
if (ciphertext) {
|
311
|
-
CRYPTO_gcm128_decrypt(&ctx, &aes_key, ciphertext, out, plaintext_len);
|
312
|
-
}
|
313
|
-
if (!CRYPTO_gcm128_finish(&ctx, tag, tag_len)) {
|
314
|
-
fprintf(stderr, "%u: decrypt failed.\n", test_num);
|
315
|
-
goto out;
|
316
|
-
}
|
317
|
-
if (plaintext && memcmp(out, plaintext, plaintext_len)) {
|
318
|
-
fprintf(stderr, "%u: plaintext doesn't match.\n", test_num);
|
319
|
-
goto out;
|
320
|
-
}
|
321
|
-
|
322
|
-
ret = 1;
|
323
|
-
|
324
|
-
out:
|
325
|
-
OPENSSL_free(key);
|
326
|
-
OPENSSL_free(plaintext);
|
327
|
-
OPENSSL_free(additional_data);
|
328
|
-
OPENSSL_free(nonce);
|
329
|
-
OPENSSL_free(ciphertext);
|
330
|
-
OPENSSL_free(tag);
|
331
|
-
OPENSSL_free(out);
|
332
|
-
return ret;
|
333
|
-
}
|
334
|
-
|
335
|
-
int main(void) {
|
336
|
-
int ret = 0;
|
337
|
-
unsigned i;
|
338
|
-
|
339
|
-
CRYPTO_library_init();
|
340
|
-
|
341
|
-
for (i = 0; i < sizeof(test_cases) / sizeof(struct test_case); i++) {
|
342
|
-
if (!run_test_case(i, &test_cases[i])) {
|
343
|
-
ret = 1;
|
344
|
-
}
|
345
|
-
}
|
346
|
-
|
347
|
-
return ret;
|
348
|
-
}
|
@@ -1,299 +0,0 @@
|
|
1
|
-
/* ====================================================================
|
2
|
-
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
3
|
-
*
|
4
|
-
* Redistribution and use in source and binary forms, with or without
|
5
|
-
* modification, are permitted provided that the following conditions
|
6
|
-
* are met:
|
7
|
-
*
|
8
|
-
* 1. Redistributions of source code must retain the above copyright
|
9
|
-
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in
|
13
|
-
* the documentation and/or other materials provided with the
|
14
|
-
* distribution.
|
15
|
-
*
|
16
|
-
* 3. All advertising materials mentioning features or use of this
|
17
|
-
* software must display the following acknowledgment:
|
18
|
-
* "This product includes software developed by the OpenSSL Project
|
19
|
-
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
20
|
-
*
|
21
|
-
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
22
|
-
* endorse or promote products derived from this software without
|
23
|
-
* prior written permission. For written permission, please contact
|
24
|
-
* openssl-core@openssl.org.
|
25
|
-
*
|
26
|
-
* 5. Products derived from this software may not be called "OpenSSL"
|
27
|
-
* nor may "OpenSSL" appear in their names without prior written
|
28
|
-
* permission of the OpenSSL Project.
|
29
|
-
*
|
30
|
-
* 6. Redistributions of any form whatsoever must retain the following
|
31
|
-
* acknowledgment:
|
32
|
-
* "This product includes software developed by the OpenSSL Project
|
33
|
-
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
34
|
-
*
|
35
|
-
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
36
|
-
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
37
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
38
|
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
39
|
-
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
41
|
-
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
42
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
43
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
44
|
-
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
45
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
46
|
-
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
|
-
* ==================================================================== */
|
48
|
-
|
49
|
-
#ifndef OPENSSL_HEADER_MODES_INTERNAL_H
|
50
|
-
#define OPENSSL_HEADER_MODES_INTERNAL_H
|
51
|
-
|
52
|
-
#include <openssl/base.h>
|
53
|
-
|
54
|
-
#if defined(__cplusplus)
|
55
|
-
extern "C" {
|
56
|
-
#endif
|
57
|
-
|
58
|
-
|
59
|
-
#define asm __asm__
|
60
|
-
|
61
|
-
#define STRICT_ALIGNMENT 1
|
62
|
-
#if defined(OPENSSL_X86_64) || defined(OPENSSL_X86) || defined(OPENSSL_AARCH64)
|
63
|
-
#undef STRICT_ALIGNMENT
|
64
|
-
#define STRICT_ALIGNMENT 0
|
65
|
-
#endif
|
66
|
-
|
67
|
-
#if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM)
|
68
|
-
#if defined(__GNUC__) && __GNUC__ >= 2
|
69
|
-
#if defined(OPENSSL_X86_64)
|
70
|
-
#define BSWAP8(x) \
|
71
|
-
({ \
|
72
|
-
uint64_t ret = (x); \
|
73
|
-
asm("bswapq %0" : "+r"(ret)); \
|
74
|
-
ret; \
|
75
|
-
})
|
76
|
-
#define BSWAP4(x) \
|
77
|
-
({ \
|
78
|
-
uint32_t ret = (x); \
|
79
|
-
asm("bswapl %0" : "+r"(ret)); \
|
80
|
-
ret; \
|
81
|
-
})
|
82
|
-
#elif defined(OPENSSL_X86)
|
83
|
-
#define BSWAP8(x) \
|
84
|
-
({ \
|
85
|
-
uint32_t lo = (uint64_t)(x) >> 32, hi = (x); \
|
86
|
-
asm("bswapl %0; bswapl %1" : "+r"(hi), "+r"(lo)); \
|
87
|
-
(uint64_t) hi << 32 | lo; \
|
88
|
-
})
|
89
|
-
#define BSWAP4(x) \
|
90
|
-
({ \
|
91
|
-
uint32_t ret = (x); \
|
92
|
-
asm("bswapl %0" : "+r"(ret)); \
|
93
|
-
ret; \
|
94
|
-
})
|
95
|
-
#elif defined(OPENSSL_AARCH64)
|
96
|
-
#define BSWAP8(x) \
|
97
|
-
({ \
|
98
|
-
uint64_t ret; \
|
99
|
-
asm("rev %0,%1" : "=r"(ret) : "r"(x)); \
|
100
|
-
ret; \
|
101
|
-
})
|
102
|
-
#define BSWAP4(x) \
|
103
|
-
({ \
|
104
|
-
uint32_t ret; \
|
105
|
-
asm("rev %w0,%w1" : "=r"(ret) : "r"(x)); \
|
106
|
-
ret; \
|
107
|
-
})
|
108
|
-
#elif defined(OPENSSL_ARM) && !defined(STRICT_ALIGNMENT)
|
109
|
-
#define BSWAP8(x) \
|
110
|
-
({ \
|
111
|
-
uint32_t lo = (uint64_t)(x) >> 32, hi = (x); \
|
112
|
-
asm("rev %0,%0; rev %1,%1" : "+r"(hi), "+r"(lo)); \
|
113
|
-
(uint64_t) hi << 32 | lo; \
|
114
|
-
})
|
115
|
-
#define BSWAP4(x) \
|
116
|
-
({ \
|
117
|
-
uint32_t ret; \
|
118
|
-
asm("rev %0,%1" : "=r"(ret) : "r"((uint32_t)(x))); \
|
119
|
-
ret; \
|
120
|
-
})
|
121
|
-
#endif
|
122
|
-
#elif defined(_MSC_VER)
|
123
|
-
#if _MSC_VER >= 1300
|
124
|
-
#pragma warning(push, 3)
|
125
|
-
#include <intrin.h>
|
126
|
-
#pragma warning(pop)
|
127
|
-
#pragma intrinsic(_byteswap_uint64, _byteswap_ulong)
|
128
|
-
#define BSWAP8(x) _byteswap_uint64((uint64_t)(x))
|
129
|
-
#define BSWAP4(x) _byteswap_ulong((uint32_t)(x))
|
130
|
-
#elif defined(OPENSSL_X86)
|
131
|
-
__inline uint32_t _bswap4(uint32_t val) {
|
132
|
-
_asm mov eax, val
|
133
|
-
_asm bswap eax
|
134
|
-
}
|
135
|
-
#define BSWAP4(x) _bswap4(x)
|
136
|
-
#endif
|
137
|
-
#endif
|
138
|
-
#endif
|
139
|
-
|
140
|
-
#if defined(BSWAP4) && !defined(STRICT_ALIGNMENT)
|
141
|
-
#define GETU32(p) BSWAP4(*(const uint32_t *)(p))
|
142
|
-
#define PUTU32(p, v) *(uint32_t *)(p) = BSWAP4(v)
|
143
|
-
#else
|
144
|
-
#define GETU32(p) \
|
145
|
-
((uint32_t)(p)[0] << 24 | (uint32_t)(p)[1] << 16 | (uint32_t)(p)[2] << 8 | (uint32_t)(p)[3])
|
146
|
-
#define PUTU32(p, v) \
|
147
|
-
((p)[0] = (uint8_t)((v) >> 24), (p)[1] = (uint8_t)((v) >> 16), \
|
148
|
-
(p)[2] = (uint8_t)((v) >> 8), (p)[3] = (uint8_t)(v))
|
149
|
-
#endif
|
150
|
-
|
151
|
-
|
152
|
-
/* block128_f is the type of a 128-bit, block cipher. */
|
153
|
-
typedef void (*block128_f)(const uint8_t in[16], uint8_t out[16],
|
154
|
-
const void *key);
|
155
|
-
|
156
|
-
/* GCM definitions */
|
157
|
-
typedef struct { uint64_t hi,lo; } u128;
|
158
|
-
|
159
|
-
/* This differs from OpenSSL's |gcm128_context| in that it does not have the
|
160
|
-
* |key| pointer, in order to make it |memcpy|-friendly. See openssl/modes.h
|
161
|
-
* for more info. */
|
162
|
-
struct gcm128_context {
|
163
|
-
/* Following 6 names follow names in GCM specification */
|
164
|
-
union {
|
165
|
-
uint64_t u[2];
|
166
|
-
uint32_t d[4];
|
167
|
-
uint8_t c[16];
|
168
|
-
size_t t[16 / sizeof(size_t)];
|
169
|
-
} Yi, EKi, EK0, len, Xi, H;
|
170
|
-
|
171
|
-
/* Relative position of Xi, H and pre-computed Htable is used in some
|
172
|
-
* assembler modules, i.e. don't change the order! */
|
173
|
-
u128 Htable[16];
|
174
|
-
void (*gmult)(uint64_t Xi[2], const u128 Htable[16]);
|
175
|
-
void (*ghash)(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
|
176
|
-
size_t len);
|
177
|
-
|
178
|
-
unsigned int mres, ares;
|
179
|
-
block128_f block;
|
180
|
-
};
|
181
|
-
|
182
|
-
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
183
|
-
/* crypto_gcm_clmul_enabled returns one if the CLMUL implementation of GCM is
|
184
|
-
* used. */
|
185
|
-
int crypto_gcm_clmul_enabled(void);
|
186
|
-
#endif
|
187
|
-
|
188
|
-
|
189
|
-
/* CTR. */
|
190
|
-
|
191
|
-
/* ctr128_f is the type of a function that performs CTR-mode encryption. */
|
192
|
-
typedef void (*ctr128_f)(const uint8_t *in, uint8_t *out, size_t blocks,
|
193
|
-
const void *key, const uint8_t ivec[16]);
|
194
|
-
|
195
|
-
/* CRYPTO_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode)
|
196
|
-
* |len| bytes from |in| to |out| using |block| in counter mode. There's no
|
197
|
-
* requirement that |len| be a multiple of any value and any partial blocks are
|
198
|
-
* stored in |ecount_buf| and |*num|, which must be zeroed before the initial
|
199
|
-
* call. The counter is a 128-bit, big-endian value in |ivec| and is
|
200
|
-
* incremented by this function. */
|
201
|
-
void CRYPTO_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
202
|
-
const void *key, uint8_t ivec[16],
|
203
|
-
uint8_t ecount_buf[16], unsigned int *num,
|
204
|
-
block128_f block);
|
205
|
-
|
206
|
-
/* CRYPTO_ctr128_encrypt_ctr32 acts like |CRYPTO_ctr128_encrypt| but takes
|
207
|
-
* |ctr|, a function that performs CTR mode but only deals with the lower 32
|
208
|
-
* bits of the counter. This is useful when |ctr| can be an optimised
|
209
|
-
* function. */
|
210
|
-
void CRYPTO_ctr128_encrypt_ctr32(const uint8_t *in, uint8_t *out, size_t len,
|
211
|
-
const void *key, uint8_t ivec[16],
|
212
|
-
uint8_t ecount_buf[16], unsigned int *num,
|
213
|
-
ctr128_f ctr);
|
214
|
-
|
215
|
-
|
216
|
-
/* GCM.
|
217
|
-
*
|
218
|
-
* This API differs from the OpenSSL API slightly. The |GCM128_CONTEXT| does
|
219
|
-
* not have a |key| pointer that points to the key as OpenSSL's version does.
|
220
|
-
* Instead, every function takes a |key| parameter. This way |GCM128_CONTEXT|
|
221
|
-
* can be safely copied. */
|
222
|
-
|
223
|
-
typedef struct gcm128_context GCM128_CONTEXT;
|
224
|
-
|
225
|
-
/* CRYPTO_gcm128_new allocates a fresh |GCM128_CONTEXT| and calls
|
226
|
-
* |CRYPTO_gcm128_init|. It returns the new context, or NULL on error. */
|
227
|
-
OPENSSL_EXPORT GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key,
|
228
|
-
block128_f block);
|
229
|
-
|
230
|
-
/* CRYPTO_gcm128_init initialises |ctx| to use |block| (typically AES) with
|
231
|
-
* the given key. */
|
232
|
-
OPENSSL_EXPORT void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, const void *key,
|
233
|
-
block128_f block);
|
234
|
-
|
235
|
-
/* CRYPTO_gcm128_set_96_bit_iv sets the IV (nonce) for |ctx|. The |key| must be
|
236
|
-
* the same key that was passed to |CRYPTO_gcm128_init|. */
|
237
|
-
OPENSSL_EXPORT void CRYPTO_gcm128_set_96_bit_iv(GCM128_CONTEXT *ctx,
|
238
|
-
const void *key,
|
239
|
-
const uint8_t *iv);
|
240
|
-
|
241
|
-
/* CRYPTO_gcm128_aad sets the authenticated data for an instance of GCM.
|
242
|
-
* This must be called before and data is encrypted. It returns one on success
|
243
|
-
* and zero otherwise. */
|
244
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const uint8_t *aad,
|
245
|
-
size_t len);
|
246
|
-
|
247
|
-
/* CRYPTO_gcm128_encrypt encrypts |len| bytes from |in| to |out|. The |key|
|
248
|
-
* must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one
|
249
|
-
* on success and zero otherwise. */
|
250
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const void *key,
|
251
|
-
const uint8_t *in, uint8_t *out,
|
252
|
-
size_t len);
|
253
|
-
|
254
|
-
/* CRYPTO_gcm128_decrypt decrypts |len| bytes from |in| to |out|. The |key|
|
255
|
-
* must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one
|
256
|
-
* on success and zero otherwise. */
|
257
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const void *key,
|
258
|
-
const uint8_t *in, uint8_t *out,
|
259
|
-
size_t len);
|
260
|
-
|
261
|
-
/* CRYPTO_gcm128_encrypt_ctr32 encrypts |len| bytes from |in| to |out| using
|
262
|
-
* a CTR function that only handles the bottom 32 bits of the nonce, like
|
263
|
-
* |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was
|
264
|
-
* passed to |CRYPTO_gcm128_init|. It returns one on success and zero
|
265
|
-
* otherwise. */
|
266
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
|
267
|
-
const void *key,
|
268
|
-
const uint8_t *in, uint8_t *out,
|
269
|
-
size_t len, ctr128_f stream);
|
270
|
-
|
271
|
-
/* CRYPTO_gcm128_decrypt_ctr32 decrypts |len| bytes from |in| to |out| using
|
272
|
-
* a CTR function that only handles the bottom 32 bits of the nonce, like
|
273
|
-
* |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was
|
274
|
-
* passed to |CRYPTO_gcm128_init|. It returns one on success and zero
|
275
|
-
* otherwise. */
|
276
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
|
277
|
-
const void *key,
|
278
|
-
const uint8_t *in, uint8_t *out,
|
279
|
-
size_t len, ctr128_f stream);
|
280
|
-
|
281
|
-
/* CRYPTO_gcm128_finish calculates the authenticator and compares it against
|
282
|
-
* |len| bytes of |tag|. It returns one on success and zero otherwise. */
|
283
|
-
OPENSSL_EXPORT int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const uint8_t *tag,
|
284
|
-
size_t len);
|
285
|
-
|
286
|
-
/* CRYPTO_gcm128_tag calculates the authenticator and copies it into |tag|.
|
287
|
-
* The minimum of |len| and 16 bytes are copied into |tag|. */
|
288
|
-
OPENSSL_EXPORT void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, uint8_t *tag,
|
289
|
-
size_t len);
|
290
|
-
|
291
|
-
/* CRYPTO_gcm128_release clears and frees |ctx|. */
|
292
|
-
OPENSSL_EXPORT void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
|
293
|
-
|
294
|
-
|
295
|
-
#if defined(__cplusplus)
|
296
|
-
} /* extern C */
|
297
|
-
#endif
|
298
|
-
|
299
|
-
#endif /* OPENSSL_HEADER_MODES_INTERNAL_H */
|