Compare commits
160 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f78fa1ea33 | |||
| 40acdaeb86 | |||
| 72f5911a16 | |||
| 4d78718cde | |||
| 89baa72ed8 | |||
| 0e434b9470 | |||
| c0f763b080 | |||
| e631d9679e | |||
| be55790652 | |||
| f8c2c9e9f0 | |||
| a1283f75f1 | |||
| 3db1ded2e7 | |||
| e8261a0100 | |||
| a5974bfae7 | |||
| e12c4378e9 | |||
| 5a3162a521 | |||
| f93d737c86 | |||
| 94e597a51c | |||
| c2b45a164a | |||
| 1d77e56b29 | |||
| 45fb1be33e | |||
| d7c5dfb233 | |||
| c11e13a78b | |||
| 20b64fd19d | |||
| 32ab7b0e74 | |||
| 3e719319be | |||
| e2e13265ff | |||
| 4616bb1e6e | |||
| 87ac295d5d | |||
| 05a5beb35c | |||
| 340d5ed295 | |||
| 0570923ed2 | |||
| 0d4db50a54 | |||
| e5a3ac2cac | |||
| 8056343a58 | |||
| b6d0c6db5e | |||
| 90fa69aaae | |||
| ab2479a08a | |||
| 32156b974d | |||
| 72dc7834af | |||
| 67d1fb59ad | |||
| 642f1498d0 | |||
| 7061e28dc2 | |||
| 3c9746a6d7 | |||
| b85a4c2923 | |||
| cdea40c3e2 | |||
| 4b1510c71e | |||
| 7a8e62dbd9 | |||
| 61c0d4e8b2 | |||
| c12d377e24 | |||
| 7e3b5840c2 | |||
| 078abceb29 | |||
| 8b368412d3 | |||
| 9e13e1a31d | |||
| cfdd6b1aef | |||
| 506fa4f770 | |||
| 42574efaff | |||
| cdcecf546b | |||
| a5a3eeb9cc | |||
| ced555394f | |||
| 34860739de | |||
| 859a04b7ff | |||
| a9c6667cab | |||
| e30f3fb080 | |||
| c02f148fa8 | |||
| 87b2a13a86 | |||
| 2ddba8cd48 | |||
| 3305858342 | |||
| f21645f4e3 | |||
| 067321502d | |||
| 1df63e93f9 | |||
| 0e782a9eb3 | |||
| 52f9f62283 | |||
| 5edc4e2a9b | |||
| ca8feeb301 | |||
| 7282738bad | |||
| 3f92d21094 | |||
| 524e717b87 | |||
| ab2a8e03d9 | |||
| d434f28ef2 | |||
| 1b3a95122d | |||
| 1d1562d9b5 | |||
| a42b4163f8 | |||
| d53b2c3c88 | |||
| 4df48dd30f | |||
| 949b26827a | |||
| 28120a18f6 | |||
| dc3da93899 | |||
| 4f7783eaea | |||
| 7cb0f44d9d | |||
| 165de16c2e | |||
| 1a5c50f3a8 | |||
| 7cc29ab833 | |||
| e0ba4dddf6 | |||
| bc5d8ee0d4 | |||
| e60202797d | |||
| 33c8d60a1f | |||
| b18f024816 | |||
| bcd374570c | |||
| bf0df92964 | |||
| 389939422a | |||
| 5a93342fab | |||
| c4482d65dc | |||
| f298019547 | |||
| 2fa83de3f2 | |||
| 4c31123bfc | |||
| f7f0f3a74b | |||
| ee562b987e | |||
| 8cb7a7c0d5 | |||
| 7538122ca6 | |||
| d03b5eddb9 | |||
| 8a4ab4fc1d | |||
| d216b71f90 | |||
| d27eda00a4 | |||
| f46cea8cd8 | |||
| a4e6d48749 | |||
| 7eaab4cd57 | |||
| 9d102ddbc0 | |||
| e023ad2d83 | |||
| 5f5bf6f210 | |||
| 0685b68216 | |||
| 5ca39fb50c | |||
| b34f510b3b | |||
| fb68d6c901 | |||
| 23721e3705 | |||
| cc239d3903 | |||
| 0d5e080ab9 | |||
| b826c0d670 | |||
| b3323704bc | |||
| 4e581b5378 | |||
| 50073e8c5e | |||
| 5ae21bc02b | |||
| 29b50eab6c | |||
| 114ddebbf6 | |||
| 9a7233cda8 | |||
| a3e894921e | |||
| 03741f61d9 | |||
| 09bdb2a2c3 | |||
| bcb2d91e10 | |||
| 6f5c0f4471 | |||
| 7c21925a10 | |||
| 3ce3c369cb | |||
| 87c8a643e1 | |||
| 6204eba91e | |||
| 2b48d6b7dd | |||
| 3f5917f320 | |||
| 86058a256b | |||
| 2bdb35ccbb | |||
| ce9f0177f8 | |||
| 04c36b5062 | |||
| 3f309aef45 | |||
| 44972944fd | |||
| 5f0efe06e1 | |||
| 93531bd70f | |||
| d3a73360fa | |||
| 97999919bb | |||
| bcc4e23041 | |||
| 40f101b78b | |||
| 16e38b2b8f | |||
| d3459fb2f9 |
@@ -3,7 +3,8 @@ Build Prerequisites:
|
||||
* CMake[1] 2.8.8 or later is required.
|
||||
|
||||
* Perl 5.6.1 or later is required. On Windows, Strawberry Perl and MSYS Perl
|
||||
have both been reported to work.
|
||||
have both been reported to work. If not found by CMake, it may be configured
|
||||
explicitly by setting PERL_EXECUTABLE.
|
||||
|
||||
* On Windows you currently must use Ninja[2] to build; on other platforms,
|
||||
it is not required, but recommended, because it makes builds faster.
|
||||
@@ -11,14 +12,15 @@ Build Prerequisites:
|
||||
* If you need to build Ninja from source, then a recent version of
|
||||
Python[3] is required (Python 2.7.5 works).
|
||||
|
||||
* On Windows only, Yasm[4] is required.
|
||||
* On Windows only, Yasm[4] is required. If not found by CMake, it may be
|
||||
configured explicitly by setting CMAKE_ASM_NASM_COMPILER.
|
||||
|
||||
* A C compiler is required. On Windows, MSVC 12 (Visual Studio 2013) or later
|
||||
with Platform SDK 8.1 or later are supported. Recent versions of GCC and
|
||||
Clang should work on non-Windows platforms, and maybe on Windows too.
|
||||
|
||||
* Go[5] is required for running tests, but not for building. Note that the
|
||||
runner.go tests do not work on Windows.
|
||||
* Go[5] is required. If not found by CMake, the go executable may be
|
||||
configured explicitly by setting GO_EXECUTABLE.
|
||||
|
||||
Using Ninja (note the 'N' is capitalized in the cmake invocation):
|
||||
|
||||
@@ -63,8 +65,6 @@ Known Limitations on Windows:
|
||||
don't have steps for assembling the assembly language source files, so they
|
||||
currently cannot be used to build BoringSSL.
|
||||
|
||||
* The tests written in Go do not work.
|
||||
|
||||
[1] http://www.cmake.org/download/
|
||||
|
||||
[2] https://martine.github.io/ninja/
|
||||
@@ -73,7 +73,4 @@ Known Limitations on Windows:
|
||||
|
||||
[4] http://yasm.tortall.net/
|
||||
|
||||
Either ensure yasm.exe is in %PATH% or configure CMAKE_ASM_NASM_COMPILER
|
||||
appropriately.
|
||||
|
||||
[5] https://golang.org/dl/
|
||||
|
||||
+9
-1
@@ -2,6 +2,13 @@ cmake_minimum_required (VERSION 2.8.10)
|
||||
|
||||
project (BoringSSL)
|
||||
|
||||
find_package(Perl REQUIRED)
|
||||
|
||||
find_program(GO_EXECUTABLE go)
|
||||
if (NOT GO_EXECUTABLE)
|
||||
message(FATAL_ERROR "Could not find Go")
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")
|
||||
@@ -56,9 +63,10 @@ elseif(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX)
|
||||
endif()
|
||||
|
||||
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.5.99") OR
|
||||
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
|
||||
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
|
||||
|
||||
+18
-3
@@ -2,7 +2,7 @@ include_directories(. ../include)
|
||||
|
||||
if(APPLE)
|
||||
if (${ARCH} STREQUAL "x86")
|
||||
set(PERLASM_FLAGS "-fPIC")
|
||||
set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
|
||||
endif()
|
||||
set(PERLASM_STYLE macosx)
|
||||
set(ASM_EXT S)
|
||||
@@ -13,7 +13,7 @@ elseif(UNIX)
|
||||
# in order to decide whether to generate 32- or 64-bit asm.
|
||||
set(PERLASM_STYLE linux64)
|
||||
elseif (${ARCH} STREQUAL "x86")
|
||||
set(PERLASM_FLAGS "-fPIC")
|
||||
set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
|
||||
set(PERLASM_STYLE elf)
|
||||
else()
|
||||
set(PERLASM_STYLE elf)
|
||||
@@ -27,6 +27,7 @@ else()
|
||||
else()
|
||||
message("Using win32n")
|
||||
set(PERLASM_STYLE win32n)
|
||||
set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
|
||||
endif()
|
||||
|
||||
# On Windows, we use the NASM output, specifically built with Yasm.
|
||||
@@ -37,7 +38,7 @@ endif()
|
||||
function(perlasm dest src)
|
||||
add_custom_command(
|
||||
OUTPUT ${dest}
|
||||
COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
|
||||
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
|
||||
DEPENDS
|
||||
${src}
|
||||
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
|
||||
@@ -139,6 +140,8 @@ add_library(
|
||||
crypto.c
|
||||
mem.c
|
||||
thread.c
|
||||
thread_pthread.c
|
||||
thread_win.c
|
||||
ex_data.c
|
||||
ex_data_impl.c
|
||||
time_support.c
|
||||
@@ -186,6 +189,10 @@ add_library(
|
||||
$<TARGET_OBJECTS:pkcs8>
|
||||
)
|
||||
|
||||
if(NOT MSVC)
|
||||
target_link_libraries(crypto pthread)
|
||||
endif()
|
||||
|
||||
add_executable(
|
||||
constant_time_test
|
||||
|
||||
@@ -194,5 +201,13 @@ add_executable(
|
||||
|
||||
target_link_libraries(constant_time_test crypto)
|
||||
|
||||
add_executable(
|
||||
thread_test
|
||||
|
||||
thread_test.c
|
||||
)
|
||||
|
||||
target_link_libraries(thread_test crypto)
|
||||
|
||||
perlasm(cpu-x86_64-asm.${ASM_EXT} cpu-x86_64-asm.pl)
|
||||
perlasm(cpu-x86-asm.${ASM_EXT} cpu-x86-asm.pl)
|
||||
|
||||
+16
-8
@@ -1033,17 +1033,25 @@ void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
||||
#endif /* ?FULL_UNROLL */
|
||||
/* apply last round and
|
||||
* map cipher state to byte array block: */
|
||||
s0 = (Td4[(t0 >> 24)] << 24) ^ (Td4[(t3 >> 16) & 0xff] << 16) ^
|
||||
(Td4[(t2 >> 8) & 0xff] << 8) ^ (Td4[(t1) & 0xff]) ^ rk[0];
|
||||
s0 = ((uint32_t)Td4[(t0 >> 24)] << 24) ^
|
||||
((uint32_t)Td4[(t3 >> 16) & 0xff] << 16) ^
|
||||
((uint32_t)Td4[(t2 >> 8) & 0xff] << 8) ^
|
||||
((uint32_t)Td4[(t1) & 0xff]) ^ rk[0];
|
||||
PUTU32(out, s0);
|
||||
s1 = (Td4[(t1 >> 24)] << 24) ^ (Td4[(t0 >> 16) & 0xff] << 16) ^
|
||||
(Td4[(t3 >> 8) & 0xff] << 8) ^ (Td4[(t2) & 0xff]) ^ rk[1];
|
||||
s1 = ((uint32_t)Td4[(t1 >> 24)] << 24) ^
|
||||
((uint32_t)Td4[(t0 >> 16) & 0xff] << 16) ^
|
||||
((uint32_t)Td4[(t3 >> 8) & 0xff] << 8) ^
|
||||
((uint32_t)Td4[(t2) & 0xff]) ^ rk[1];
|
||||
PUTU32(out + 4, s1);
|
||||
s2 = (Td4[(t2 >> 24)] << 24) ^ (Td4[(t1 >> 16) & 0xff] << 16) ^
|
||||
(Td4[(t0 >> 8) & 0xff] << 8) ^ (Td4[(t3) & 0xff]) ^ rk[2];
|
||||
s2 = ((uint32_t)Td4[(t2 >> 24)] << 24) ^
|
||||
((uint32_t)Td4[(t1 >> 16) & 0xff] << 16) ^
|
||||
((uint32_t)Td4[(t0 >> 8) & 0xff] << 8) ^
|
||||
((uint32_t)Td4[(t3) & 0xff]) ^ rk[2];
|
||||
PUTU32(out + 8, s2);
|
||||
s3 = (Td4[(t3 >> 24)] << 24) ^ (Td4[(t2 >> 16) & 0xff] << 16) ^
|
||||
(Td4[(t1 >> 8) & 0xff] << 8) ^ (Td4[(t0) & 0xff]) ^ rk[3];
|
||||
s3 = ((uint32_t)Td4[(t3 >> 24)] << 24) ^
|
||||
((uint32_t)Td4[(t2 >> 16) & 0xff] << 16) ^
|
||||
((uint32_t)Td4[(t1 >> 8) & 0xff] << 8) ^
|
||||
((uint32_t)Td4[(t0) & 0xff]) ^ rk[3];
|
||||
PUTU32(out + 12, s3);
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
|
||||
len-off);
|
||||
if (c.inf & 0x80)
|
||||
{
|
||||
unsigned long e;
|
||||
uint32_t e;
|
||||
|
||||
e=ERR_GET_REASON(ERR_peek_error());
|
||||
if (e != ASN1_R_TOO_LONG)
|
||||
|
||||
@@ -125,6 +125,9 @@ int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
|
||||
case V_ASN1_NULL:
|
||||
result = 0; /* They do not have content. */
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
result = a->value.boolean - b->value.boolean;
|
||||
break;
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_NEG_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
|
||||
@@ -287,7 +287,7 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
|
||||
if (!OPENSSL_gmtime(&t, &ttm))
|
||||
return -2;
|
||||
|
||||
if (!OPENSSL_gmtime_diff(&day, &sec, &stm, &ttm))
|
||||
if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
|
||||
return -2;
|
||||
|
||||
if (day > 0)
|
||||
|
||||
+20
-20
@@ -137,7 +137,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
#endif
|
||||
if (j & 0x80)
|
||||
{
|
||||
if (BIO_write(bp,"Error in encoding\n",18) <= 0)
|
||||
if (BIO_puts(bp, "Error in encoding\n") <= 0)
|
||||
goto end;
|
||||
ret=0;
|
||||
goto end;
|
||||
@@ -165,7 +165,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
if (j & V_ASN1_CONSTRUCTED)
|
||||
{
|
||||
ep=p+len;
|
||||
if (BIO_write(bp,"\n",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, "\n") <= 0) goto end;
|
||||
if (len > length)
|
||||
{
|
||||
BIO_printf(bp,
|
||||
@@ -196,7 +196,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
else if (xclass != 0)
|
||||
{
|
||||
p+=len;
|
||||
if (BIO_write(bp,"\n",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, "\n") <= 0) goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -210,7 +210,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
(tag == V_ASN1_UTCTIME) ||
|
||||
(tag == V_ASN1_GENERALIZEDTIME))
|
||||
{
|
||||
if (BIO_write(bp,":",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, ":") <= 0) goto end;
|
||||
if ((len > 0) &&
|
||||
BIO_write(bp,(const char *)p,(int)len)
|
||||
!= (int)len)
|
||||
@@ -221,12 +221,12 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
opp=op;
|
||||
if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
|
||||
{
|
||||
if (BIO_write(bp,":",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, ":") <= 0) goto end;
|
||||
i2a_ASN1_OBJECT(bp,o);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BIO_write(bp,":BAD OBJECT",11) <= 0)
|
||||
if (BIO_puts(bp, ":BAD OBJECT") <= 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
|
||||
if (ii < 0)
|
||||
{
|
||||
if (BIO_write(bp,"Bad boolean\n",12) <= 0)
|
||||
if (BIO_puts(bp, "Bad boolean\n") <= 0)
|
||||
goto end;
|
||||
}
|
||||
BIO_printf(bp,":%d",ii);
|
||||
@@ -273,7 +273,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
if (printable)
|
||||
/* printable string */
|
||||
{
|
||||
if (BIO_write(bp,":",1) <= 0)
|
||||
if (BIO_puts(bp, ":") <= 0)
|
||||
goto end;
|
||||
if (BIO_write(bp,(const char *)opp,
|
||||
os->length) <= 0)
|
||||
@@ -283,7 +283,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
/* not printable => print octet string
|
||||
* as hex dump */
|
||||
{
|
||||
if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
|
||||
if (BIO_puts(bp, "[HEX DUMP]:") <= 0)
|
||||
goto end;
|
||||
for (i=0; i<os->length; i++)
|
||||
{
|
||||
@@ -297,7 +297,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
{
|
||||
if (!nl)
|
||||
{
|
||||
if (BIO_write(bp,"\n",1) <= 0)
|
||||
if (BIO_puts(bp, "\n") <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (!BIO_hexdump(bp, opp,
|
||||
@@ -323,9 +323,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
|
||||
if (bs != NULL)
|
||||
{
|
||||
if (BIO_write(bp,":",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, ":") <= 0) goto end;
|
||||
if (bs->type == V_ASN1_NEG_INTEGER)
|
||||
if (BIO_write(bp,"-",1) <= 0)
|
||||
if (BIO_puts(bp, "-") <= 0)
|
||||
goto end;
|
||||
for (i=0; i<bs->length; i++)
|
||||
{
|
||||
@@ -335,13 +335,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
}
|
||||
if (bs->length == 0)
|
||||
{
|
||||
if (BIO_write(bp,"00",2) <= 0)
|
||||
if (BIO_puts(bp, "00") <= 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BIO_write(bp,"BAD INTEGER",11) <= 0)
|
||||
if (BIO_puts(bp, "BAD INTEGER") <= 0)
|
||||
goto end;
|
||||
}
|
||||
M_ASN1_INTEGER_free(bs);
|
||||
@@ -355,9 +355,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
|
||||
if (bs != NULL)
|
||||
{
|
||||
if (BIO_write(bp,":",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, ":") <= 0) goto end;
|
||||
if (bs->type == V_ASN1_NEG_ENUMERATED)
|
||||
if (BIO_write(bp,"-",1) <= 0)
|
||||
if (BIO_puts(bp, "-") <= 0)
|
||||
goto end;
|
||||
for (i=0; i<bs->length; i++)
|
||||
{
|
||||
@@ -367,13 +367,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
}
|
||||
if (bs->length == 0)
|
||||
{
|
||||
if (BIO_write(bp,"00",2) <= 0)
|
||||
if (BIO_puts(bp, "00") <= 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
|
||||
if (BIO_puts(bp, "BAD ENUMERATED") <= 0)
|
||||
goto end;
|
||||
}
|
||||
M_ASN1_ENUMERATED_free(bs);
|
||||
@@ -382,7 +382,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
{
|
||||
if (!nl)
|
||||
{
|
||||
if (BIO_write(bp,"\n",1) <= 0)
|
||||
if (BIO_puts(bp, "\n") <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (!BIO_hexdump(bp,p,
|
||||
@@ -394,7 +394,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
|
||||
|
||||
if (!nl)
|
||||
{
|
||||
if (BIO_write(bp,"\n",1) <= 0) goto end;
|
||||
if (BIO_puts(bp, "\n") <= 0) goto end;
|
||||
}
|
||||
p+=len;
|
||||
if ((tag == V_ASN1_EOC) && (xclass == 0))
|
||||
|
||||
@@ -170,6 +170,9 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
|
||||
p = OPENSSL_malloc(derlen);
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
|
||||
ndef_aux->derbuf = p;
|
||||
*pbuf = p;
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
|
||||
@@ -235,6 +238,9 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
|
||||
p = OPENSSL_malloc(derlen);
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
|
||||
ndef_aux->derbuf = p;
|
||||
*pbuf = p;
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
|
||||
|
||||
+27
-3
@@ -304,8 +304,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
/* Allocate structure */
|
||||
if (!*pval && !ASN1_item_ex_new(pval, it))
|
||||
if (*pval)
|
||||
{
|
||||
/* Free up and zero CHOICE value if initialised */
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount))
|
||||
{
|
||||
tt = it->templates + i;
|
||||
pchptr = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchptr, tt);
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
}
|
||||
}
|
||||
else if (!ASN1_item_ex_new(pval, it))
|
||||
{
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_item_ex_d2i, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
@@ -394,6 +405,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
/* Free up and zero any ADB found */
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
|
||||
{
|
||||
if (tt->flags & ASN1_TFLG_ADB_MASK)
|
||||
{
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get each field entry */
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
|
||||
{
|
||||
@@ -1193,7 +1217,7 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
|
||||
len = buf->length;
|
||||
if (!BUF_MEM_grow_clean(buf, len + plen))
|
||||
{
|
||||
OPENSSL_PUT_ERROR(ASN1, asn1_collect, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_PUT_ERROR(ASN1, collect_data, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
memcpy(buf->data + len, *p, plen);
|
||||
|
||||
@@ -329,14 +329,17 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
ASN1_STRING *str;
|
||||
int utype;
|
||||
|
||||
if (it && it->funcs)
|
||||
if (!it)
|
||||
return 0;
|
||||
|
||||
if (it->funcs)
|
||||
{
|
||||
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
|
||||
if (pf->prim_new)
|
||||
return pf->prim_new(pval, it);
|
||||
}
|
||||
|
||||
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
|
||||
if (it->itype == ASN1_ITYPE_MSTRING)
|
||||
utype = -1;
|
||||
else
|
||||
utype = it->utype;
|
||||
|
||||
@@ -229,6 +229,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
if (!asn1_template_print_ctx(out, fld, indent,
|
||||
it->templates, pctx))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
/* fall thru */
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
@@ -309,6 +310,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
{
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
seqtt = asn1_do_adb(fld, tt, 1);
|
||||
if (!seqtt)
|
||||
return 0;
|
||||
tmpfld = asn1_get_field_ptr(fld, seqtt);
|
||||
if (!asn1_template_print_ctx(out, tmpfld,
|
||||
indent + 2, seqtt, pctx))
|
||||
|
||||
+25
-40
@@ -61,53 +61,38 @@
|
||||
|
||||
/* Declarations for string types */
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_INTEGER);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER);
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
|
||||
sname *sname##_new(void) \
|
||||
{ \
|
||||
return ASN1_STRING_type_new(V_##sname); \
|
||||
} \
|
||||
void sname##_free(sname *x) \
|
||||
{ \
|
||||
ASN1_STRING_free(x); \
|
||||
}
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING);
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_NULL);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_T61STRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING);
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING);
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY);
|
||||
|
||||
/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */;
|
||||
|
||||
@@ -11,7 +11,7 @@ add_library(
|
||||
add_executable(
|
||||
base64_test
|
||||
|
||||
base64_test.c
|
||||
base64_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(base64_test crypto)
|
||||
|
||||
@@ -373,6 +373,10 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
|
||||
rv = 0;
|
||||
goto end;
|
||||
}
|
||||
if (eof > v) {
|
||||
rv = -1;
|
||||
goto end;
|
||||
}
|
||||
ret += (v - eof);
|
||||
} else {
|
||||
eof = 1;
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct TestVector {
|
||||
const char *decoded;
|
||||
const char *encoded;
|
||||
} TEST_VECTOR;
|
||||
};
|
||||
|
||||
/* Test vectors from RFC 4648. */
|
||||
static const TEST_VECTOR test_vectors[] = {
|
||||
// Test vectors from RFC 4648.
|
||||
static const TestVector kTestVectors[] = {
|
||||
{ "", "" },
|
||||
{ "f" , "Zg==" },
|
||||
{ "fo", "Zm8=" },
|
||||
@@ -36,95 +36,90 @@ static const TEST_VECTOR test_vectors[] = {
|
||||
{ "foobar", "Zm9vYmFy" },
|
||||
};
|
||||
|
||||
static const size_t kNumTests = sizeof(test_vectors) / sizeof(test_vectors[0]);
|
||||
static const size_t kNumTests = sizeof(kTestVectors) / sizeof(kTestVectors[0]);
|
||||
|
||||
static int test_encode(void) {
|
||||
uint8_t out[9];
|
||||
size_t i, len;
|
||||
|
||||
for (i = 0; i < kNumTests; i++) {
|
||||
const TEST_VECTOR *t = &test_vectors[i];
|
||||
len = EVP_EncodeBlock(out, (const uint8_t*)t->decoded, strlen(t->decoded));
|
||||
static bool TestEncode() {
|
||||
for (size_t i = 0; i < kNumTests; i++) {
|
||||
const TestVector *t = &kTestVectors[i];
|
||||
uint8_t out[9];
|
||||
size_t len = EVP_EncodeBlock(out, (const uint8_t*)t->decoded,
|
||||
strlen(t->decoded));
|
||||
if (len != strlen(t->encoded) ||
|
||||
memcmp(out, t->encoded, len) != 0) {
|
||||
fprintf(stderr, "encode(\"%s\") = \"%.*s\", want \"%s\"\n",
|
||||
t->decoded, (int)len, (const char*)out, t->encoded);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_decode(void) {
|
||||
static bool TestDecode() {
|
||||
uint8_t out[6];
|
||||
size_t i, len;
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
for (i = 0; i < kNumTests; i++) {
|
||||
/* Test the normal API. */
|
||||
const TEST_VECTOR *t = &test_vectors[i];
|
||||
for (size_t i = 0; i < kNumTests; i++) {
|
||||
// Test the normal API.
|
||||
const TestVector *t = &kTestVectors[i];
|
||||
size_t expected_len = strlen(t->decoded);
|
||||
if (!EVP_DecodeBase64(out, &len, sizeof(out),
|
||||
(const uint8_t*)t->encoded, strlen(t->encoded))) {
|
||||
fprintf(stderr, "decode(\"%s\") failed\n", t->encoded);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (len != strlen(t->decoded) ||
|
||||
memcmp(out, t->decoded, len) != 0) {
|
||||
fprintf(stderr, "decode(\"%s\") = \"%.*s\", want \"%s\"\n",
|
||||
t->encoded, (int)len, (const char*)out, t->decoded);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Test that the padding behavior of the deprecated API is
|
||||
* preserved. */
|
||||
ret = EVP_DecodeBlock(out, (const uint8_t*)t->encoded, strlen(t->encoded));
|
||||
// Test that the padding behavior of the deprecated API is preserved.
|
||||
int ret = EVP_DecodeBlock(out, (const uint8_t*)t->encoded,
|
||||
strlen(t->encoded));
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "decode(\"%s\") failed\n", t->encoded);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (ret % 3 != 0) {
|
||||
fprintf(stderr, "EVP_DecodeBlock did not ignore padding\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (expected_len % 3 != 0) {
|
||||
ret -= 3 - (expected_len % 3);
|
||||
}
|
||||
if (ret != strlen(t->decoded) ||
|
||||
if (static_cast<size_t>(ret) != strlen(t->decoded) ||
|
||||
memcmp(out, t->decoded, ret) != 0) {
|
||||
fprintf(stderr, "decode(\"%s\") = \"%.*s\", want \"%s\"\n",
|
||||
t->encoded, ret, (const char*)out, t->decoded);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"a!bc", 4)) {
|
||||
fprintf(stderr, "Failed to reject invalid characters in the middle.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"a=bc", 4)) {
|
||||
fprintf(stderr, "Failed to reject invalid characters in the middle.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"abc", 4)) {
|
||||
fprintf(stderr, "Failed to reject invalid input length.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
CRYPTO_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
if (!test_encode()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_decode()) {
|
||||
if (!TestEncode() ||
|
||||
!TestDecode()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ add_library(
|
||||
add_executable(
|
||||
bio_test
|
||||
|
||||
bio_test.c
|
||||
bio_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(bio_test crypto)
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#else
|
||||
#include <io.h>
|
||||
#pragma warning(push, 3)
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
@@ -37,95 +37,107 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#define MIN(a, b) ((a < b) ? a : b)
|
||||
#include <algorithm>
|
||||
|
||||
#include "../test/scoped_types.h"
|
||||
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) {
|
||||
return close(sock);
|
||||
}
|
||||
|
||||
static void print_socket_error(const char *func) {
|
||||
static void PrintSocketError(const char *func) {
|
||||
perror(func);
|
||||
}
|
||||
#else
|
||||
static void print_socket_error(const char *func) {
|
||||
static void PrintSocketError(const char *func) {
|
||||
fprintf(stderr, "%s: %d\n", func, WSAGetLastError());
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_socket_connect(void) {
|
||||
int listening_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
int sock;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t sockaddr_len = sizeof(sin);
|
||||
static const char kTestMessage[] = "test";
|
||||
char hostname[80], buf[5];
|
||||
BIO *bio;
|
||||
class ScopedSocket {
|
||||
public:
|
||||
ScopedSocket(int sock) : sock_(sock) {}
|
||||
~ScopedSocket() {
|
||||
closesocket(sock_);
|
||||
}
|
||||
|
||||
private:
|
||||
const int sock_;
|
||||
};
|
||||
|
||||
static bool TestSocketConnect() {
|
||||
static const char kTestMessage[] = "test";
|
||||
|
||||
int listening_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (listening_sock == -1) {
|
||||
PrintSocketError("socket");
|
||||
return false;
|
||||
}
|
||||
ScopedSocket listening_sock_closer(listening_sock);
|
||||
|
||||
struct sockaddr_in sin;
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
if (!inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr)) {
|
||||
print_socket_error("inet_pton");
|
||||
return 0;
|
||||
PrintSocketError("inet_pton");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bind(listening_sock, (struct sockaddr *)&sin, sizeof(sin)) != 0) {
|
||||
print_socket_error("bind");
|
||||
return 0;
|
||||
PrintSocketError("bind");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (listen(listening_sock, 1)) {
|
||||
print_socket_error("listen");
|
||||
return 0;
|
||||
PrintSocketError("listen");
|
||||
return false;
|
||||
}
|
||||
|
||||
socklen_t sockaddr_len = sizeof(sin);
|
||||
if (getsockname(listening_sock, (struct sockaddr *)&sin, &sockaddr_len) ||
|
||||
sockaddr_len != sizeof(sin)) {
|
||||
print_socket_error("getsockname");
|
||||
return 0;
|
||||
PrintSocketError("getsockname");
|
||||
return false;
|
||||
}
|
||||
|
||||
char hostname[80];
|
||||
BIO_snprintf(hostname, sizeof(hostname), "%s:%d", "127.0.0.1",
|
||||
ntohs(sin.sin_port));
|
||||
bio = BIO_new_connect(hostname);
|
||||
ScopedBIO bio(BIO_new_connect(hostname));
|
||||
if (!bio) {
|
||||
fprintf(stderr, "BIO_new_connect failed.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BIO_write(bio, kTestMessage, sizeof(kTestMessage)) !=
|
||||
if (BIO_write(bio.get(), kTestMessage, sizeof(kTestMessage)) !=
|
||||
sizeof(kTestMessage)) {
|
||||
fprintf(stderr, "BIO_write failed.\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
sock = accept(listening_sock, (struct sockaddr *) &sin, &sockaddr_len);
|
||||
if (sock < 0) {
|
||||
print_socket_error("accept");
|
||||
return 0;
|
||||
int sock = accept(listening_sock, (struct sockaddr *) &sin, &sockaddr_len);
|
||||
if (sock == -1) {
|
||||
PrintSocketError("accept");
|
||||
return false;
|
||||
}
|
||||
ScopedSocket sock_closer(sock);
|
||||
|
||||
char buf[5];
|
||||
if (recv(sock, buf, sizeof(buf), 0) != sizeof(kTestMessage)) {
|
||||
print_socket_error("read");
|
||||
return 0;
|
||||
PrintSocketError("read");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(buf, kTestMessage, sizeof(kTestMessage))) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
closesocket(sock);
|
||||
closesocket(listening_sock);
|
||||
BIO_free(bio);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* bio_read_zero_copy_wrapper is a wrapper around the zero-copy APIs to make
|
||||
* testing easier. */
|
||||
static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
|
||||
// BioReadZeroCopyWrapper is a wrapper around the zero-copy APIs to make
|
||||
// testing easier.
|
||||
static size_t BioReadZeroCopyWrapper(BIO *bio, uint8_t *data, size_t len) {
|
||||
uint8_t *read_buf;
|
||||
size_t read_buf_offset;
|
||||
size_t available_bytes;
|
||||
@@ -137,7 +149,7 @@ static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
available_bytes = MIN(available_bytes, len - len_read);
|
||||
available_bytes = std::min(available_bytes, len - len_read);
|
||||
memmove(data + len_read, read_buf + read_buf_offset, available_bytes);
|
||||
|
||||
BIO_zero_copy_get_read_buf_done(bio, available_bytes);
|
||||
@@ -148,10 +160,10 @@ static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
|
||||
return len_read;
|
||||
}
|
||||
|
||||
/* bio_write_zero_copy_wrapper is a wrapper around the zero-copy APIs to make
|
||||
* testing easier. */
|
||||
static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
|
||||
size_t len) {
|
||||
// BioWriteZeroCopyWrapper is a wrapper around the zero-copy APIs to make
|
||||
// testing easier.
|
||||
static size_t BioWriteZeroCopyWrapper(BIO *bio, const uint8_t *data,
|
||||
size_t len) {
|
||||
uint8_t *write_buf;
|
||||
size_t write_buf_offset;
|
||||
size_t available_bytes;
|
||||
@@ -163,7 +175,7 @@ static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
available_bytes = MIN(available_bytes, len - len_written);
|
||||
available_bytes = std::min(available_bytes, len - len_written);
|
||||
memmove(write_buf + write_buf_offset, data + len_written, available_bytes);
|
||||
|
||||
BIO_zero_copy_get_write_buf_done(bio, available_bytes);
|
||||
@@ -174,167 +186,157 @@ static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
|
||||
return len_written;
|
||||
}
|
||||
|
||||
static int test_zero_copy_bio_pairs(void) {
|
||||
/* Test read and write, especially triggering the ring buffer wrap-around.*/
|
||||
BIO* bio1;
|
||||
BIO* bio2;
|
||||
size_t i, j;
|
||||
static bool TestZeroCopyBioPairs() {
|
||||
// Test read and write, especially triggering the ring buffer wrap-around.
|
||||
uint8_t bio1_application_send_buffer[1024];
|
||||
uint8_t bio2_application_recv_buffer[1024];
|
||||
size_t total_read = 0;
|
||||
size_t total_write = 0;
|
||||
uint8_t* write_buf;
|
||||
size_t write_buf_offset;
|
||||
size_t available_bytes;
|
||||
size_t bytes_left;
|
||||
|
||||
const size_t kLengths[] = {254, 255, 256, 257, 510, 511, 512, 513};
|
||||
|
||||
/* These trigger ring buffer wrap around. */
|
||||
// These trigger ring buffer wrap around.
|
||||
const size_t kPartialLengths[] = {0, 1, 2, 3, 128, 255, 256, 257, 511, 512};
|
||||
|
||||
static const size_t kBufferSize = 512;
|
||||
|
||||
srand(1);
|
||||
for (i = 0; i < sizeof(bio1_application_send_buffer); i++) {
|
||||
for (size_t i = 0; i < sizeof(bio1_application_send_buffer); i++) {
|
||||
bio1_application_send_buffer[i] = rand() & 255;
|
||||
}
|
||||
|
||||
/* Transfer bytes from bio1_application_send_buffer to
|
||||
* bio2_application_recv_buffer in various ways. */
|
||||
for (i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
|
||||
for (j = 0; j < sizeof(kPartialLengths) / sizeof(kPartialLengths[0]); j++) {
|
||||
total_write = 0;
|
||||
total_read = 0;
|
||||
// Transfer bytes from bio1_application_send_buffer to
|
||||
// bio2_application_recv_buffer in various ways.
|
||||
for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
|
||||
for (size_t j = 0; j < sizeof(kPartialLengths) / sizeof(kPartialLengths[0]);
|
||||
j++) {
|
||||
size_t total_write = 0;
|
||||
size_t total_read = 0;
|
||||
|
||||
BIO_new_bio_pair(&bio1, kBufferSize, &bio2, kBufferSize);
|
||||
BIO *bio1, *bio2;
|
||||
if (!BIO_new_bio_pair(&bio1, kBufferSize, &bio2, kBufferSize)) {
|
||||
return false;
|
||||
}
|
||||
ScopedBIO bio1_scoper(bio1);
|
||||
ScopedBIO bio2_scoper(bio2);
|
||||
|
||||
total_write += bio_write_zero_copy_wrapper(
|
||||
total_write += BioWriteZeroCopyWrapper(
|
||||
bio1, bio1_application_send_buffer, kLengths[i]);
|
||||
|
||||
/* This tests interleaved read/write calls. Do a read between zero copy
|
||||
* write calls. */
|
||||
// This tests interleaved read/write calls. Do a read between zero copy
|
||||
// write calls.
|
||||
uint8_t *write_buf;
|
||||
size_t write_buf_offset;
|
||||
size_t available_bytes;
|
||||
if (!BIO_zero_copy_get_write_buf(bio1, &write_buf, &write_buf_offset,
|
||||
&available_bytes)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Free kPartialLengths[j] bytes in the beginning of bio1 write buffer.
|
||||
* This enables ring buffer wrap around for the next write. */
|
||||
// Free kPartialLengths[j] bytes in the beginning of bio1 write buffer.
|
||||
// This enables ring buffer wrap around for the next write.
|
||||
total_read += BIO_read(bio2, bio2_application_recv_buffer + total_read,
|
||||
kPartialLengths[j]);
|
||||
|
||||
size_t interleaved_write_len = MIN(kPartialLengths[j], available_bytes);
|
||||
size_t interleaved_write_len = std::min(kPartialLengths[j],
|
||||
available_bytes);
|
||||
|
||||
/* Write the data for the interleaved write call. If the buffer becomes
|
||||
* empty after a read, the write offset is normally set to 0. Check that
|
||||
* this does not happen for interleaved read/write and that
|
||||
* |write_buf_offset| is still valid. */
|
||||
// Write the data for the interleaved write call. If the buffer becomes
|
||||
// empty after a read, the write offset is normally set to 0. Check that
|
||||
// this does not happen for interleaved read/write and that
|
||||
// |write_buf_offset| is still valid.
|
||||
memcpy(write_buf + write_buf_offset,
|
||||
bio1_application_send_buffer + total_write, interleaved_write_len);
|
||||
if (BIO_zero_copy_get_write_buf_done(bio1, interleaved_write_len)) {
|
||||
total_write += interleaved_write_len;
|
||||
}
|
||||
|
||||
/* Do another write in case |write_buf_offset| was wrapped */
|
||||
total_write += bio_write_zero_copy_wrapper(
|
||||
// Do another write in case |write_buf_offset| was wrapped.
|
||||
total_write += BioWriteZeroCopyWrapper(
|
||||
bio1, bio1_application_send_buffer + total_write,
|
||||
kPartialLengths[j] - interleaved_write_len);
|
||||
|
||||
/* Drain the rest. */
|
||||
bytes_left = BIO_pending(bio2);
|
||||
total_read += bio_read_zero_copy_wrapper(
|
||||
// Drain the rest.
|
||||
size_t bytes_left = BIO_pending(bio2);
|
||||
total_read += BioReadZeroCopyWrapper(
|
||||
bio2, bio2_application_recv_buffer + total_read, bytes_left);
|
||||
|
||||
BIO_free(bio1);
|
||||
BIO_free(bio2);
|
||||
|
||||
if (total_read != total_write) {
|
||||
fprintf(stderr, "Lengths not equal in round (%u, %u)\n", (unsigned)i,
|
||||
(unsigned)j);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (total_read > kLengths[i] + kPartialLengths[j]) {
|
||||
fprintf(stderr, "Bad lengths in round (%u, %u)\n", (unsigned)i,
|
||||
(unsigned)j);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (memcmp(bio1_application_send_buffer, bio2_application_recv_buffer,
|
||||
total_read) != 0) {
|
||||
fprintf(stderr, "Buffers not equal in round (%u, %u)\n", (unsigned)i,
|
||||
(unsigned)j);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_printf(void) {
|
||||
/* Test a short output, a very long one, and various sizes around
|
||||
* 256 (the size of the buffer) to ensure edge cases are correct. */
|
||||
static bool TestPrintf() {
|
||||
// Test a short output, a very long one, and various sizes around
|
||||
// 256 (the size of the buffer) to ensure edge cases are correct.
|
||||
static const size_t kLengths[] = { 5, 250, 251, 252, 253, 254, 1023 };
|
||||
BIO *bio;
|
||||
char string[1024];
|
||||
int ret;
|
||||
const uint8_t *contents;
|
||||
size_t i, len;
|
||||
|
||||
bio = BIO_new(BIO_s_mem());
|
||||
ScopedBIO bio(BIO_new(BIO_s_mem()));
|
||||
if (!bio) {
|
||||
fprintf(stderr, "BIO_new failed\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
|
||||
for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
|
||||
char string[1024];
|
||||
if (kLengths[i] >= sizeof(string)) {
|
||||
fprintf(stderr, "Bad test string length\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
memset(string, 'a', sizeof(string));
|
||||
string[kLengths[i]] = '\0';
|
||||
|
||||
ret = BIO_printf(bio, "test %s", string);
|
||||
if (ret != 5 + kLengths[i]) {
|
||||
int ret = BIO_printf(bio.get(), "test %s", string);
|
||||
if (ret < 0 || static_cast<size_t>(ret) != 5 + kLengths[i]) {
|
||||
fprintf(stderr, "BIO_printf failed: %d\n", ret);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (!BIO_mem_contents(bio, &contents, &len)) {
|
||||
const uint8_t *contents;
|
||||
size_t len;
|
||||
if (!BIO_mem_contents(bio.get(), &contents, &len)) {
|
||||
fprintf(stderr, "BIO_mem_contents failed\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (len != 5 + kLengths[i] ||
|
||||
strncmp((const char *)contents, "test ", 5) != 0 ||
|
||||
strncmp((const char *)contents + 5, string, kLengths[i]) != 0) {
|
||||
fprintf(stderr, "Contents did not match: %.*s\n", (int)len, contents);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BIO_reset(bio)) {
|
||||
if (!BIO_reset(bio.get())) {
|
||||
fprintf(stderr, "BIO_reset failed\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
WSADATA wsa_data;
|
||||
WORD wsa_version;
|
||||
int wsa_err;
|
||||
#endif
|
||||
|
||||
CRYPTO_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
/* Initialize Winsock. */
|
||||
wsa_version = MAKEWORD(2, 2);
|
||||
wsa_err = WSAStartup(wsa_version, &wsa_data);
|
||||
// Initialize Winsock.
|
||||
WORD wsa_version = MAKEWORD(2, 2);
|
||||
WSADATA wsa_data;
|
||||
int wsa_err = WSAStartup(wsa_version, &wsa_data);
|
||||
if (wsa_err != 0) {
|
||||
fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
|
||||
return 1;
|
||||
@@ -345,15 +347,9 @@ int main(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!test_socket_connect()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_printf()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_zero_copy_bio_pairs()) {
|
||||
if (!TestSocketConnect() ||
|
||||
!TestPrintf() ||
|
||||
!TestZeroCopyBioPairs()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#pragma warning(push, 3)
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@
|
||||
#else
|
||||
#include <io.h>
|
||||
#pragma warning(push, 3)
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
+3
-1
@@ -64,8 +64,10 @@
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#pragma warning(push, 3)
|
||||
#include <WinSock2.h>
|
||||
#include <winsock2.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#pragma warning(push, 3)
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ perlasm(armv4-mont.${ASM_EXT} asm/armv4-mont.pl)
|
||||
add_executable(
|
||||
bn_test
|
||||
|
||||
bn_test.c
|
||||
bn_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(bn_test crypto)
|
||||
|
||||
@@ -661,6 +661,7 @@ $code.=<<___;
|
||||
.align 2
|
||||
#if __ARM_ARCH__>=7
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
___
|
||||
|
||||
|
||||
-1506
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -172,12 +172,13 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
if (r != rr) {
|
||||
BN_copy(r, rr);
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,12 @@
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
/* Some versions of inttypes.h will not define print macros in C++ unless
|
||||
* __STDC_FORMAT_MACROS is set. */
|
||||
#if !defined(__STDC_FORMAT_MACROS)
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(OPENSSL_X86_64) && defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
|
||||
+7
-1
@@ -659,7 +659,13 @@ again:
|
||||
/* If bits is so small that it fits into a single word then we
|
||||
* additionally don't want to exceed that many bits. */
|
||||
if (is_single_word) {
|
||||
BN_ULONG size_limit = (((BN_ULONG)1) << bits) - get_word(rnd) - 1;
|
||||
BN_ULONG size_limit;
|
||||
if (bits == BN_BITS2) {
|
||||
/* Avoid undefined behavior. */
|
||||
size_limit = ~((BN_ULONG)0) - get_word(rnd);
|
||||
} else {
|
||||
size_limit = (((BN_ULONG)1) << bits) - get_word(rnd) - 1;
|
||||
}
|
||||
if (size_limit < maxdelta) {
|
||||
maxdelta = size_limit;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ add_library(
|
||||
add_executable(
|
||||
bytestring_test
|
||||
|
||||
bytestring_test.c
|
||||
bytestring_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(bytestring_test crypto)
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bytestring.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
#include "../test/scoped_types.h"
|
||||
|
||||
|
||||
static int test_skip(void) {
|
||||
static bool TestSkip() {
|
||||
static const uint8_t kData[] = {1, 2, 3};
|
||||
CBS data;
|
||||
|
||||
@@ -36,7 +39,7 @@ static int test_skip(void) {
|
||||
!CBS_skip(&data, 1);
|
||||
}
|
||||
|
||||
static int test_get_u(void) {
|
||||
static bool TestGetUint() {
|
||||
static const uint8_t kData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
uint8_t u8;
|
||||
uint16_t u16;
|
||||
@@ -55,7 +58,7 @@ static int test_get_u(void) {
|
||||
!CBS_get_u8(&data, &u8);
|
||||
}
|
||||
|
||||
static int test_get_prefixed(void) {
|
||||
static bool TestGetPrefixed() {
|
||||
static const uint8_t kData[] = {1, 2, 0, 2, 3, 4, 0, 0, 3, 3, 2, 1};
|
||||
uint8_t u8;
|
||||
uint16_t u16;
|
||||
@@ -77,7 +80,7 @@ static int test_get_prefixed(void) {
|
||||
u32 == 0x30201;
|
||||
}
|
||||
|
||||
static int test_get_prefixed_bad(void) {
|
||||
static bool TestGetPrefixedBad() {
|
||||
static const uint8_t kData1[] = {2, 1};
|
||||
static const uint8_t kData2[] = {0, 2, 1};
|
||||
static const uint8_t kData3[] = {0, 0, 2, 1};
|
||||
@@ -85,23 +88,23 @@ static int test_get_prefixed_bad(void) {
|
||||
|
||||
CBS_init(&data, kData1, sizeof(kData1));
|
||||
if (CBS_get_u8_length_prefixed(&data, &prefixed)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData2, sizeof(kData2));
|
||||
if (CBS_get_u16_length_prefixed(&data, &prefixed)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData3, sizeof(kData3));
|
||||
if (CBS_get_u24_length_prefixed(&data, &prefixed)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_get_asn1(void) {
|
||||
static bool TestGetASN1() {
|
||||
static const uint8_t kData1[] = {0x30, 2, 1, 2};
|
||||
static const uint8_t kData2[] = {0x30, 3, 1, 2};
|
||||
static const uint8_t kData3[] = {0x30, 0x80};
|
||||
@@ -119,52 +122,52 @@ static int test_get_asn1(void) {
|
||||
CBS_init(&data, kData1, sizeof(kData1));
|
||||
if (CBS_peek_asn1_tag(&data, 0x1) ||
|
||||
!CBS_peek_asn1_tag(&data, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (!CBS_get_asn1(&data, &contents, 0x30) ||
|
||||
CBS_len(&contents) != 2 ||
|
||||
memcmp(CBS_data(&contents), "\x01\x02", 2) != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData2, sizeof(kData2));
|
||||
/* data is truncated */
|
||||
// data is truncated
|
||||
if (CBS_get_asn1(&data, &contents, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData3, sizeof(kData3));
|
||||
/* zero byte length of length */
|
||||
// zero byte length of length
|
||||
if (CBS_get_asn1(&data, &contents, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData4, sizeof(kData4));
|
||||
/* long form mistakenly used. */
|
||||
// long form mistakenly used.
|
||||
if (CBS_get_asn1(&data, &contents, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData5, sizeof(kData5));
|
||||
/* length takes too many bytes. */
|
||||
// length takes too many bytes.
|
||||
if (CBS_get_asn1(&data, &contents, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData1, sizeof(kData1));
|
||||
/* wrong tag. */
|
||||
// wrong tag.
|
||||
if (CBS_get_asn1(&data, &contents, 0x31)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, NULL, 0);
|
||||
/* peek at empty data. */
|
||||
// peek at empty data.
|
||||
if (CBS_peek_asn1_tag(&data, 0x30)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, NULL, 0);
|
||||
/* optional elements at empty data. */
|
||||
// optional elements at empty data.
|
||||
if (!CBS_get_optional_asn1(&data, &contents, &present, 0xa0) ||
|
||||
present ||
|
||||
!CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa0) ||
|
||||
@@ -174,22 +177,22 @@ static int test_get_asn1(void) {
|
||||
CBS_len(&contents) != 0 ||
|
||||
!CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42) ||
|
||||
value != 42) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData6, sizeof(kData6));
|
||||
/* optional element. */
|
||||
// optional element.
|
||||
if (!CBS_get_optional_asn1(&data, &contents, &present, 0xa0) ||
|
||||
present ||
|
||||
!CBS_get_optional_asn1(&data, &contents, &present, 0xa1) ||
|
||||
!present ||
|
||||
CBS_len(&contents) != 3 ||
|
||||
memcmp(CBS_data(&contents), "\x04\x01\x01", 3) != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData6, sizeof(kData6));
|
||||
/* optional octet string. */
|
||||
// optional octet string.
|
||||
if (!CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa0) ||
|
||||
present ||
|
||||
CBS_len(&contents) != 0 ||
|
||||
@@ -197,97 +200,96 @@ static int test_get_asn1(void) {
|
||||
!present ||
|
||||
CBS_len(&contents) != 1 ||
|
||||
CBS_data(&contents)[0] != 1) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData7, sizeof(kData7));
|
||||
/* invalid optional octet string. */
|
||||
// invalid optional octet string.
|
||||
if (CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa1)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData8, sizeof(kData8));
|
||||
/* optional octet string. */
|
||||
// optional octet string.
|
||||
if (!CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42) ||
|
||||
value != 42 ||
|
||||
!CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42) ||
|
||||
value != 1) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kData9, sizeof(kData9));
|
||||
/* invalid optional integer. */
|
||||
// invalid optional integer.
|
||||
if (CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_get_optional_asn1_bool(void) {
|
||||
CBS data;
|
||||
int val;
|
||||
|
||||
static bool TestGetOptionalASN1Bool() {
|
||||
static const uint8_t kTrue[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0xff};
|
||||
static const uint8_t kFalse[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x00};
|
||||
static const uint8_t kInvalid[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x01};
|
||||
|
||||
CBS data;
|
||||
CBS_init(&data, NULL, 0);
|
||||
val = 2;
|
||||
int val = 2;
|
||||
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0) ||
|
||||
val != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kTrue, sizeof(kTrue));
|
||||
val = 2;
|
||||
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0) ||
|
||||
val != 1) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kFalse, sizeof(kFalse));
|
||||
val = 2;
|
||||
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1) ||
|
||||
val != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBS_init(&data, kInvalid, sizeof(kInvalid));
|
||||
if (CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_cbb_basic(void) {
|
||||
static bool TestCBBBasic() {
|
||||
static const uint8_t kExpected[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
uint8_t *buf;
|
||||
size_t buf_len;
|
||||
int ok;
|
||||
CBB cbb;
|
||||
|
||||
if (!CBB_init(&cbb, 100)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
CBB_cleanup(&cbb);
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_u8(&cbb, 1) ||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_u8(&cbb, 1) ||
|
||||
!CBB_add_u16(&cbb, 0x203) ||
|
||||
!CBB_add_u24(&cbb, 0x40506) ||
|
||||
!CBB_add_bytes(&cbb, (const uint8_t*) "\x07\x08", 2) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
|
||||
free(buf);
|
||||
return ok;
|
||||
ScopedOpenSSLBytes scoper(buf);
|
||||
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
|
||||
}
|
||||
|
||||
static int test_cbb_fixed(void) {
|
||||
static bool TestCBBFixed() {
|
||||
CBB cbb;
|
||||
uint8_t buf[1];
|
||||
uint8_t *out_buf;
|
||||
@@ -298,7 +300,7 @@ static int test_cbb_fixed(void) {
|
||||
!CBB_finish(&cbb, &out_buf, &out_size) ||
|
||||
out_buf != NULL ||
|
||||
out_size != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CBB_init_fixed(&cbb, buf, 1) ||
|
||||
@@ -308,40 +310,41 @@ static int test_cbb_fixed(void) {
|
||||
out_buf != buf ||
|
||||
out_size != 1 ||
|
||||
buf[0] != 1) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_cbb_finish_child(void) {
|
||||
static bool TestCBBFinishChild() {
|
||||
CBB cbb, child;
|
||||
uint8_t *out_buf;
|
||||
size_t out_size;
|
||||
|
||||
if (!CBB_init(&cbb, 16) ||
|
||||
!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
||||
CBB_finish(&child, &out_buf, &out_size) ||
|
||||
!CBB_finish(&cbb, &out_buf, &out_size) ||
|
||||
out_size != 1 ||
|
||||
out_buf[0] != 0) {
|
||||
return 0;
|
||||
if (!CBB_init(&cbb, 16)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
free(out_buf);
|
||||
return 1;
|
||||
if (!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
||||
CBB_finish(&child, &out_buf, &out_size) ||
|
||||
!CBB_finish(&cbb, &out_buf, &out_size)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
ScopedOpenSSLBytes scoper(out_buf);
|
||||
return out_size == 1 && out_buf[0] == 0;
|
||||
}
|
||||
|
||||
static int test_cbb_prefixed(void) {
|
||||
static bool TestCBBPrefixed() {
|
||||
static const uint8_t kExpected[] = {0, 1, 1, 0, 2, 2, 3, 0, 0, 3,
|
||||
4, 5, 6, 5, 4, 1, 0, 1, 2};
|
||||
uint8_t *buf;
|
||||
size_t buf_len;
|
||||
CBB cbb, contents, inner_contents, inner_inner_contents;
|
||||
int ok;
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_u8_length_prefixed(&cbb, &contents) ||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_u8_length_prefixed(&cbb, &contents) ||
|
||||
!CBB_add_u8_length_prefixed(&cbb, &contents) ||
|
||||
!CBB_add_u8(&contents, 1) ||
|
||||
!CBB_add_u16_length_prefixed(&cbb, &contents) ||
|
||||
@@ -354,28 +357,31 @@ static int test_cbb_prefixed(void) {
|
||||
!CBB_add_u16_length_prefixed(&inner_contents, &inner_inner_contents) ||
|
||||
!CBB_add_u8(&inner_inner_contents, 2) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
|
||||
free(buf);
|
||||
return ok;
|
||||
ScopedOpenSSLBytes scoper(buf);
|
||||
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
|
||||
}
|
||||
|
||||
static int test_cbb_misuse(void) {
|
||||
static bool TestCBBMisuse() {
|
||||
CBB cbb, child, contents;
|
||||
uint8_t *buf;
|
||||
size_t buf_len;
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
||||
!CBB_add_u8(&child, 1) ||
|
||||
!CBB_add_u8(&cbb, 2)) {
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Since we wrote to |cbb|, |child| is now invalid and attempts to write to
|
||||
* it should fail. */
|
||||
// Since we wrote to |cbb|, |child| is now invalid and attempts to write to
|
||||
// it should fail.
|
||||
if (CBB_add_u8(&child, 1) ||
|
||||
CBB_add_u16(&child, 1) ||
|
||||
CBB_add_u24(&child, 1) ||
|
||||
@@ -384,91 +390,104 @@ static int test_cbb_misuse(void) {
|
||||
CBB_add_asn1(&child, &contents, 1) ||
|
||||
CBB_add_bytes(&child, (const uint8_t*) "a", 1)) {
|
||||
fprintf(stderr, "CBB operation on invalid CBB did not fail.\n");
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CBB_finish(&cbb, &buf, &buf_len) ||
|
||||
buf_len != 3 ||
|
||||
if (!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
ScopedOpenSSLBytes scoper(buf);
|
||||
|
||||
if (buf_len != 3 ||
|
||||
memcmp(buf, "\x01\x01\x02", 3) != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_cbb_asn1(void) {
|
||||
static bool TestCBBASN1() {
|
||||
static const uint8_t kExpected[] = {0x30, 3, 1, 2, 3};
|
||||
uint8_t *buf, *test_data;
|
||||
uint8_t *buf;
|
||||
size_t buf_len;
|
||||
CBB cbb, contents, inner_contents;
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_bytes(&contents, (const uint8_t*) "\x01\x02\x03", 3) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
ScopedOpenSSLBytes scoper(buf);
|
||||
|
||||
if (buf_len != sizeof(kExpected) || memcmp(buf, kExpected, buf_len) != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
test_data = malloc(100000);
|
||||
memset(test_data, 0x42, 100000);
|
||||
std::vector<uint8_t> test_data(100000, 0x42);
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_bytes(&contents, test_data, 130) ||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_bytes(&contents, bssl::vector_data(&test_data), 130) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
scoper.reset(buf);
|
||||
|
||||
if (buf_len != 3 + 130 ||
|
||||
memcmp(buf, "\x30\x81\x82", 3) != 0 ||
|
||||
memcmp(buf + 3, test_data, 130) != 0) {
|
||||
return 0;
|
||||
memcmp(buf + 3, bssl::vector_data(&test_data), 130) != 0) {
|
||||
return false;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_bytes(&contents, test_data, 1000) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_bytes(&contents, bssl::vector_data(&test_data), 1000) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
scoper.reset(buf);
|
||||
|
||||
if (buf_len != 4 + 1000 ||
|
||||
memcmp(buf, "\x30\x82\x03\xe8", 4) != 0 ||
|
||||
memcmp(buf + 4, test_data, 1000)) {
|
||||
return 0;
|
||||
memcmp(buf + 4, bssl::vector_data(&test_data), 1000)) {
|
||||
return false;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
if (!CBB_init(&cbb, 0) ||
|
||||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_asn1(&contents, &inner_contents, 0x30) ||
|
||||
!CBB_add_bytes(&inner_contents, test_data, 100000) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
return 0;
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
|
||||
!CBB_add_asn1(&contents, &inner_contents, 0x30) ||
|
||||
!CBB_add_bytes(&inner_contents, bssl::vector_data(&test_data), 100000) ||
|
||||
!CBB_finish(&cbb, &buf, &buf_len)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return false;
|
||||
}
|
||||
scoper.reset(buf);
|
||||
|
||||
if (buf_len != 5 + 5 + 100000 ||
|
||||
memcmp(buf, "\x30\x83\x01\x86\xa5\x30\x83\x01\x86\xa0", 10) != 0 ||
|
||||
memcmp(buf + 10, test_data, 100000)) {
|
||||
return 0;
|
||||
memcmp(buf + 10, bssl::vector_data(&test_data), 100000)) {
|
||||
return false;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
free(test_data);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int do_ber_convert(const char *name,
|
||||
const uint8_t *der_expected, size_t der_len,
|
||||
const uint8_t *ber, size_t ber_len) {
|
||||
static bool DoBerConvert(const char *name,
|
||||
const uint8_t *der_expected, size_t der_len,
|
||||
const uint8_t *ber, size_t ber_len) {
|
||||
CBS in;
|
||||
uint8_t *out;
|
||||
size_t out_len;
|
||||
@@ -476,44 +495,44 @@ static int do_ber_convert(const char *name,
|
||||
CBS_init(&in, ber, ber_len);
|
||||
if (!CBS_asn1_ber_to_der(&in, &out, &out_len)) {
|
||||
fprintf(stderr, "%s: CBS_asn1_ber_to_der failed.\n", name);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
ScopedOpenSSLBytes scoper(out);
|
||||
|
||||
if (out == NULL) {
|
||||
if (ber_len != der_len ||
|
||||
memcmp(der_expected, ber, ber_len) != 0) {
|
||||
fprintf(stderr, "%s: incorrect unconverted result.\n", name);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (out_len != der_len ||
|
||||
memcmp(out, der_expected, der_len) != 0) {
|
||||
fprintf(stderr, "%s: incorrect converted result.\n", name);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
free(out);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_ber_convert(void) {
|
||||
static bool TestBerConvert() {
|
||||
static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00};
|
||||
|
||||
/* kIndefBER contains a SEQUENCE with an indefinite length. */
|
||||
// kIndefBER contains a SEQUENCE with an indefinite length.
|
||||
static const uint8_t kIndefBER[] = {0x30, 0x80, 0x01, 0x01, 0x02, 0x00, 0x00};
|
||||
static const uint8_t kIndefDER[] = {0x30, 0x03, 0x01, 0x01, 0x02};
|
||||
|
||||
/* kOctetStringBER contains an indefinite length OCTETSTRING with two parts.
|
||||
* These parts need to be concatenated in DER form. */
|
||||
// kOctetStringBER contains an indefinite length OCTETSTRING with two parts.
|
||||
// These parts need to be concatenated in DER form.
|
||||
static const uint8_t kOctetStringBER[] = {0x24, 0x80, 0x04, 0x02, 0, 1,
|
||||
0x04, 0x02, 2, 3, 0x00, 0x00};
|
||||
static const uint8_t kOctetStringDER[] = {0x04, 0x04, 0, 1, 2, 3};
|
||||
|
||||
/* kNSSBER is part of a PKCS#12 message generated by NSS that uses indefinite
|
||||
* length elements extensively. */
|
||||
// kNSSBER is part of a PKCS#12 message generated by NSS that uses indefinite
|
||||
// length elements extensively.
|
||||
static const uint8_t kNSSBER[] = {
|
||||
0x30, 0x80, 0x02, 0x01, 0x03, 0x30, 0x80, 0x06, 0x09, 0x2a, 0x86, 0x48,
|
||||
0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x80, 0x24, 0x80, 0x04, 0x04,
|
||||
@@ -536,56 +555,55 @@ static int test_ber_convert(void) {
|
||||
0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0,
|
||||
};
|
||||
|
||||
return do_ber_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
|
||||
kSimpleBER, sizeof(kSimpleBER)) &&
|
||||
do_ber_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
|
||||
sizeof(kIndefBER)) &&
|
||||
do_ber_convert("kOctetStringBER", kOctetStringDER,
|
||||
sizeof(kOctetStringDER), kOctetStringBER,
|
||||
sizeof(kOctetStringBER)) &&
|
||||
do_ber_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
|
||||
sizeof(kNSSBER));
|
||||
return DoBerConvert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
|
||||
kSimpleBER, sizeof(kSimpleBER)) &&
|
||||
DoBerConvert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
|
||||
sizeof(kIndefBER)) &&
|
||||
DoBerConvert("kOctetStringBER", kOctetStringDER,
|
||||
sizeof(kOctetStringDER), kOctetStringBER,
|
||||
sizeof(kOctetStringBER)) &&
|
||||
DoBerConvert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
|
||||
sizeof(kNSSBER));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct ASN1Uint64Test {
|
||||
uint64_t value;
|
||||
const char *encoding;
|
||||
size_t encoding_len;
|
||||
} ASN1_UINT64_TEST;
|
||||
|
||||
static const ASN1_UINT64_TEST kAsn1Uint64Tests[] = {
|
||||
{0, "\x02\x01\x00", 3},
|
||||
{1, "\x02\x01\x01", 3},
|
||||
{127, "\x02\x01\x7f", 3},
|
||||
{128, "\x02\x02\x00\x80", 4},
|
||||
{0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7},
|
||||
{OPENSSL_U64(0x0102030405060708),
|
||||
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
|
||||
{OPENSSL_U64(0xffffffffffffffff),
|
||||
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const ASN1Uint64Test kASN1Uint64Tests[] = {
|
||||
{0, "\x02\x01\x00", 3},
|
||||
{1, "\x02\x01\x01", 3},
|
||||
{127, "\x02\x01\x7f", 3},
|
||||
{128, "\x02\x02\x00\x80", 4},
|
||||
{0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7},
|
||||
{OPENSSL_U64(0x0102030405060708),
|
||||
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
|
||||
{OPENSSL_U64(0xffffffffffffffff),
|
||||
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
|
||||
};
|
||||
|
||||
struct ASN1InvalidUint64Test {
|
||||
const char *encoding;
|
||||
size_t encoding_len;
|
||||
} ASN1_INVALID_UINT64_TEST;
|
||||
|
||||
static const ASN1_INVALID_UINT64_TEST kAsn1InvalidUint64Tests[] = {
|
||||
/* Bad tag. */
|
||||
{"\x03\x01\x00", 3},
|
||||
/* Empty contents. */
|
||||
{"\x02\x00", 2},
|
||||
/* Negative number. */
|
||||
{"\x02\x01\x80", 3},
|
||||
/* Overflow */
|
||||
{"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11},
|
||||
};
|
||||
|
||||
static int test_asn1_uint64(void) {
|
||||
size_t i;
|
||||
static const ASN1InvalidUint64Test kASN1InvalidUint64Tests[] = {
|
||||
// Bad tag.
|
||||
{"\x03\x01\x00", 3},
|
||||
// Empty contents.
|
||||
{"\x02\x00", 2},
|
||||
// Negative number.
|
||||
{"\x02\x01\x80", 3},
|
||||
// Overflow
|
||||
{"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11},
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(kAsn1Uint64Tests) / sizeof(kAsn1Uint64Tests[0]); i++) {
|
||||
const ASN1_UINT64_TEST *test = &kAsn1Uint64Tests[i];
|
||||
static bool TestASN1Uint64() {
|
||||
for (size_t i = 0; i < sizeof(kASN1Uint64Tests) / sizeof(kASN1Uint64Tests[0]);
|
||||
i++) {
|
||||
const ASN1Uint64Test *test = &kASN1Uint64Tests[i];
|
||||
CBS cbs;
|
||||
uint64_t value;
|
||||
CBB cbb;
|
||||
@@ -596,57 +614,56 @@ static int test_asn1_uint64(void) {
|
||||
if (!CBS_get_asn1_uint64(&cbs, &value) ||
|
||||
CBS_len(&cbs) != 0 ||
|
||||
value != test->value) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CBB_init(&cbb, 0)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (!CBB_add_asn1_uint64(&cbb, test->value) ||
|
||||
!CBB_finish(&cbb, &out, &len)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
ScopedOpenSSLBytes scoper(out);
|
||||
if (len != test->encoding_len || memcmp(out, test->encoding, len) != 0) {
|
||||
free(out);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
free(out);
|
||||
}
|
||||
|
||||
for (i = 0;
|
||||
i < sizeof(kAsn1InvalidUint64Tests) / sizeof(kAsn1InvalidUint64Tests[0]);
|
||||
for (size_t i = 0;
|
||||
i < sizeof(kASN1InvalidUint64Tests) / sizeof(kASN1InvalidUint64Tests[0]);
|
||||
i++) {
|
||||
const ASN1_INVALID_UINT64_TEST *test = &kAsn1InvalidUint64Tests[i];
|
||||
const ASN1InvalidUint64Test *test = &kASN1InvalidUint64Tests[i];
|
||||
CBS cbs;
|
||||
uint64_t value;
|
||||
|
||||
CBS_init(&cbs, (const uint8_t *)test->encoding, test->encoding_len);
|
||||
if (CBS_get_asn1_uint64(&cbs, &value)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
CRYPTO_library_init();
|
||||
|
||||
if (!test_skip() ||
|
||||
!test_get_u() ||
|
||||
!test_get_prefixed() ||
|
||||
!test_get_prefixed_bad() ||
|
||||
!test_get_asn1() ||
|
||||
!test_cbb_basic() ||
|
||||
!test_cbb_fixed() ||
|
||||
!test_cbb_finish_child() ||
|
||||
!test_cbb_misuse() ||
|
||||
!test_cbb_prefixed() ||
|
||||
!test_cbb_asn1() ||
|
||||
!test_ber_convert() ||
|
||||
!test_asn1_uint64() ||
|
||||
!test_get_optional_asn1_bool()) {
|
||||
if (!TestSkip() ||
|
||||
!TestGetUint() ||
|
||||
!TestGetPrefixed() ||
|
||||
!TestGetPrefixedBad() ||
|
||||
!TestGetASN1() ||
|
||||
!TestCBBBasic() ||
|
||||
!TestCBBFixed() ||
|
||||
!TestCBBFinishChild() ||
|
||||
!TestCBBMisuse() ||
|
||||
!TestCBBPrefixed() ||
|
||||
!TestCBBASN1() ||
|
||||
!TestBerConvert() ||
|
||||
!TestASN1Uint64() ||
|
||||
!TestGetOptionalASN1Bool()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
+29
-4
@@ -33,12 +33,29 @@ size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead) { return aead->max_tag_len; }
|
||||
int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
|
||||
const uint8_t *key, size_t key_len, size_t tag_len,
|
||||
ENGINE *impl) {
|
||||
ctx->aead = aead;
|
||||
if (key_len != aead->key_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init, CIPHER_R_UNSUPPORTED_KEY_SIZE);
|
||||
if (!aead->init) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init, CIPHER_R_NO_DIRECTION_SET);
|
||||
return 0;
|
||||
}
|
||||
return aead->init(ctx, key, key_len, tag_len);
|
||||
return EVP_AEAD_CTX_init_with_direction(ctx, aead, key, key_len, tag_len,
|
||||
evp_aead_open);
|
||||
}
|
||||
|
||||
int EVP_AEAD_CTX_init_with_direction(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
ctx->aead = aead;
|
||||
if (key_len != aead->key_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init_with_direction,
|
||||
CIPHER_R_UNSUPPORTED_KEY_SIZE);
|
||||
return 0;
|
||||
}
|
||||
if (aead->init) {
|
||||
return aead->init(ctx, key, key_len, tag_len);
|
||||
} else {
|
||||
return aead->init_with_direction(ctx, key, key_len, tag_len, dir);
|
||||
}
|
||||
}
|
||||
|
||||
void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) {
|
||||
@@ -117,3 +134,11 @@ error:
|
||||
*out_len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_AEAD_CTX_get_rc4_state(const EVP_AEAD_CTX *ctx, const RC4_KEY **out_key) {
|
||||
if (ctx->aead->get_rc4_state == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ctx->aead->get_rc4_state(ctx, out_key);
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ static int run_test_case(const EVP_AEAD *aead,
|
||||
* smaller by at least tag length. */
|
||||
uint8_t out2[sizeof(out)];
|
||||
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
|
||||
NULL)) {
|
||||
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
|
||||
lengths[TAG], evp_aead_seal)) {
|
||||
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
|
||||
return 0;
|
||||
}
|
||||
@@ -123,8 +123,8 @@ static int run_test_case(const EVP_AEAD *aead,
|
||||
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
|
||||
* reset after each operation. */
|
||||
EVP_AEAD_CTX_cleanup(&ctx);
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
|
||||
NULL)) {
|
||||
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
|
||||
lengths[TAG], evp_aead_open)) {
|
||||
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
|
||||
return 0;
|
||||
}
|
||||
@@ -153,8 +153,8 @@ static int run_test_case(const EVP_AEAD *aead,
|
||||
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
|
||||
* reset after each operation. */
|
||||
EVP_AEAD_CTX_cleanup(&ctx);
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
|
||||
NULL)) {
|
||||
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
|
||||
lengths[TAG], evp_aead_open)) {
|
||||
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
|
||||
return 0;
|
||||
}
|
||||
@@ -172,8 +172,8 @@ static int run_test_case(const EVP_AEAD *aead,
|
||||
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
|
||||
* reset after each operation. */
|
||||
EVP_AEAD_CTX_cleanup(&ctx);
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
|
||||
NULL)) {
|
||||
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
|
||||
lengths[TAG], evp_aead_open)) {
|
||||
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
|
||||
return 0;
|
||||
}
|
||||
@@ -251,6 +251,10 @@ int main(int argc, char **argv) {
|
||||
aead = EVP_aead_aes_128_key_wrap();
|
||||
} else if (strcmp(argv[1], "aes-256-key-wrap") == 0) {
|
||||
aead = EVP_aead_aes_256_key_wrap();
|
||||
} else if (strcmp(argv[1], "aes-128-ctr-hmac-sha256") == 0) {
|
||||
aead = EVP_aead_aes_128_ctr_hmac_sha256();
|
||||
} else if (strcmp(argv[1], "aes-256-ctr-hmac-sha256") == 0) {
|
||||
aead = EVP_aead_aes_256_ctr_hmac_sha256();
|
||||
} else {
|
||||
fprintf(stderr, "Unknown AEAD: %s\n", argv[1]);
|
||||
return 2;
|
||||
|
||||
@@ -94,8 +94,8 @@ EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) {
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) {
|
||||
if (c->cipher != NULL && c->cipher->cleanup && !c->cipher->cleanup(c)) {
|
||||
return 0;
|
||||
if (c->cipher != NULL && c->cipher->cleanup) {
|
||||
c->cipher->cleanup(c);
|
||||
}
|
||||
|
||||
if (c->cipher_data) {
|
||||
|
||||
+350
-28
@@ -57,8 +57,10 @@
|
||||
#include <openssl/modes.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
#include "../modes/internal.h"
|
||||
|
||||
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
@@ -390,28 +392,62 @@ static int aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ctr128_f aes_gcm_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
|
||||
const uint8_t *key, size_t key_len) {
|
||||
static char aesni_capable(void);
|
||||
|
||||
static ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
|
||||
block128_f *out_block, const uint8_t *key,
|
||||
size_t key_len) {
|
||||
if (aesni_capable()) {
|
||||
aesni_set_encrypt_key(key, key_len * 8, aes_key);
|
||||
if (gcm_ctx != NULL) {
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aesni_encrypt);
|
||||
}
|
||||
if (out_block) {
|
||||
*out_block = (block128_f) aesni_encrypt;
|
||||
}
|
||||
return (ctr128_f)aesni_ctr32_encrypt_blocks;
|
||||
}
|
||||
|
||||
if (hwaes_capable()) {
|
||||
aes_v8_set_encrypt_key(key, key_len * 8, aes_key);
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aes_v8_encrypt);
|
||||
if (gcm_ctx != NULL) {
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aes_v8_encrypt);
|
||||
}
|
||||
if (out_block) {
|
||||
*out_block = (block128_f) aes_v8_encrypt;
|
||||
}
|
||||
return (ctr128_f)aes_v8_ctr32_encrypt_blocks;
|
||||
}
|
||||
|
||||
if (bsaes_capable()) {
|
||||
AES_set_encrypt_key(key, key_len * 8, aes_key);
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
|
||||
if (gcm_ctx != NULL) {
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
|
||||
}
|
||||
if (out_block) {
|
||||
*out_block = (block128_f) AES_encrypt;
|
||||
}
|
||||
return (ctr128_f)bsaes_ctr32_encrypt_blocks;
|
||||
}
|
||||
|
||||
if (vpaes_capable()) {
|
||||
vpaes_set_encrypt_key(key, key_len * 8, aes_key);
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
|
||||
if (out_block) {
|
||||
*out_block = (block128_f) vpaes_encrypt;
|
||||
}
|
||||
if (gcm_ctx != NULL) {
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AES_set_encrypt_key(key, key_len * 8, aes_key);
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
|
||||
if (gcm_ctx != NULL) {
|
||||
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
|
||||
}
|
||||
if (out_block) {
|
||||
*out_block = (block128_f) AES_encrypt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -422,7 +458,8 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
return 1;
|
||||
}
|
||||
if (key) {
|
||||
gctx->ctr = aes_gcm_set_key(&gctx->ks.ks, &gctx->gcm, key, ctx->key_len);
|
||||
gctx->ctr =
|
||||
aes_ctr_set_key(&gctx->ks.ks, &gctx->gcm, NULL, key, ctx->key_len);
|
||||
/* If we have an iv can set it directly, otherwise use saved IV. */
|
||||
if (iv == NULL && gctx->iv_set) {
|
||||
iv = gctx->iv;
|
||||
@@ -445,13 +482,12 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
|
||||
static void aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
|
||||
EVP_AES_GCM_CTX *gctx = c->cipher_data;
|
||||
OPENSSL_cleanse(&gctx->gcm, sizeof(gctx->gcm));
|
||||
if (gctx->iv != c->iv) {
|
||||
OPENSSL_free(gctx->iv);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* increment counter (64-bit int) by 1 */
|
||||
@@ -951,15 +987,8 @@ static int aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (aesni_capable()) {
|
||||
aesni_set_encrypt_key(key, key_len * 8, &gcm_ctx->ks.ks);
|
||||
CRYPTO_gcm128_init(&gcm_ctx->gcm, &gcm_ctx->ks.ks,
|
||||
(block128_f)aesni_encrypt);
|
||||
gcm_ctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
|
||||
} else {
|
||||
gcm_ctx->ctr =
|
||||
aes_gcm_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm, key, key_len);
|
||||
}
|
||||
gcm_ctx->ctr =
|
||||
aes_ctr_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm, NULL, key, key_len);
|
||||
gcm_ctx->tag_len = tag_len;
|
||||
ctx->aead_state = gcm_ctx;
|
||||
|
||||
@@ -1072,8 +1101,12 @@ static const EVP_AEAD aead_aes_128_gcm = {
|
||||
12, /* nonce len */
|
||||
EVP_AEAD_AES_GCM_TAG_LEN, /* overhead */
|
||||
EVP_AEAD_AES_GCM_TAG_LEN, /* max tag length */
|
||||
aead_aes_gcm_init, aead_aes_gcm_cleanup,
|
||||
aead_aes_gcm_seal, aead_aes_gcm_open,
|
||||
aead_aes_gcm_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_aes_gcm_cleanup,
|
||||
aead_aes_gcm_seal,
|
||||
aead_aes_gcm_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_gcm = {
|
||||
@@ -1081,8 +1114,12 @@ static const EVP_AEAD aead_aes_256_gcm = {
|
||||
12, /* nonce len */
|
||||
EVP_AEAD_AES_GCM_TAG_LEN, /* overhead */
|
||||
EVP_AEAD_AES_GCM_TAG_LEN, /* max tag length */
|
||||
aead_aes_gcm_init, aead_aes_gcm_cleanup,
|
||||
aead_aes_gcm_seal, aead_aes_gcm_open,
|
||||
aead_aes_gcm_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_aes_gcm_cleanup,
|
||||
aead_aes_gcm_seal,
|
||||
aead_aes_gcm_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_gcm(void) { return &aead_aes_128_gcm; }
|
||||
@@ -1286,7 +1323,7 @@ static int aead_aes_key_wrap_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
if (in_len < 24) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_gcm_open, CIPHER_R_BAD_DECRYPT);
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_key_wrap_open, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1323,7 +1360,7 @@ static int aead_aes_key_wrap_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
if (CRYPTO_memcmp(A, nonce, 8) != 0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_gcm_open, CIPHER_R_BAD_DECRYPT);
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_key_wrap_open, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1336,8 +1373,12 @@ static const EVP_AEAD aead_aes_128_key_wrap = {
|
||||
8, /* nonce len */
|
||||
8, /* overhead */
|
||||
8, /* max tag length */
|
||||
aead_aes_key_wrap_init, aead_aes_key_wrap_cleanup,
|
||||
aead_aes_key_wrap_seal, aead_aes_key_wrap_open,
|
||||
aead_aes_key_wrap_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_aes_key_wrap_cleanup,
|
||||
aead_aes_key_wrap_seal,
|
||||
aead_aes_key_wrap_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_key_wrap = {
|
||||
@@ -1345,14 +1386,295 @@ static const EVP_AEAD aead_aes_256_key_wrap = {
|
||||
8, /* nonce len */
|
||||
8, /* overhead */
|
||||
8, /* max tag length */
|
||||
aead_aes_key_wrap_init, aead_aes_key_wrap_cleanup,
|
||||
aead_aes_key_wrap_seal, aead_aes_key_wrap_open,
|
||||
aead_aes_key_wrap_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_aes_key_wrap_cleanup,
|
||||
aead_aes_key_wrap_seal,
|
||||
aead_aes_key_wrap_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_key_wrap(void) { return &aead_aes_128_key_wrap; }
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_256_key_wrap(void) { return &aead_aes_256_key_wrap; }
|
||||
|
||||
|
||||
#define EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN SHA256_DIGEST_LENGTH
|
||||
#define EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN 12
|
||||
|
||||
struct aead_aes_ctr_hmac_sha256_ctx {
|
||||
union {
|
||||
double align;
|
||||
AES_KEY ks;
|
||||
} ks;
|
||||
ctr128_f ctr;
|
||||
block128_f block;
|
||||
SHA256_CTX inner_init_state;
|
||||
SHA256_CTX outer_init_state;
|
||||
uint8_t tag_len;
|
||||
};
|
||||
|
||||
static void hmac_init(SHA256_CTX *out_inner, SHA256_CTX *out_outer,
|
||||
const uint8_t hmac_key[32]) {
|
||||
static const size_t hmac_key_len = 32;
|
||||
uint8_t block[SHA256_CBLOCK];
|
||||
memcpy(block, hmac_key, hmac_key_len);
|
||||
memset(block + hmac_key_len, 0x36, sizeof(block) - hmac_key_len);
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < hmac_key_len; i++) {
|
||||
block[i] ^= 0x36;
|
||||
}
|
||||
|
||||
SHA256_Init(out_inner);
|
||||
SHA256_Update(out_inner, block, sizeof(block));
|
||||
|
||||
memset(block + hmac_key_len, 0x5c, sizeof(block) - hmac_key_len);
|
||||
for (i = 0; i < hmac_key_len; i++) {
|
||||
block[i] ^= (0x36 ^ 0x5c);
|
||||
}
|
||||
|
||||
SHA256_Init(out_outer);
|
||||
SHA256_Update(out_outer, block, sizeof(block));
|
||||
}
|
||||
|
||||
static int aead_aes_ctr_hmac_sha256_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx;
|
||||
static const size_t hmac_key_len = 32;
|
||||
|
||||
if (key_len < hmac_key_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
|
||||
CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0; /* EVP_AEAD_CTX_init should catch this. */
|
||||
}
|
||||
|
||||
const size_t aes_key_len = key_len - hmac_key_len;
|
||||
if (aes_key_len != 16 && aes_key_len != 32) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
|
||||
CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0; /* EVP_AEAD_CTX_init should catch this. */
|
||||
}
|
||||
|
||||
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
|
||||
tag_len = EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN;
|
||||
}
|
||||
|
||||
if (tag_len > EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
|
||||
CIPHER_R_TAG_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
aes_ctx = OPENSSL_malloc(sizeof(struct aead_aes_ctr_hmac_sha256_ctx));
|
||||
if (aes_ctx == NULL) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
aes_ctx->ctr =
|
||||
aes_ctr_set_key(&aes_ctx->ks.ks, NULL, &aes_ctx->block, key, aes_key_len);
|
||||
aes_ctx->tag_len = tag_len;
|
||||
hmac_init(&aes_ctx->inner_init_state, &aes_ctx->outer_init_state,
|
||||
key + aes_key_len);
|
||||
|
||||
ctx->aead_state = aes_ctx;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void aead_aes_ctr_hmac_sha256_cleanup(EVP_AEAD_CTX *ctx) {
|
||||
struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
|
||||
OPENSSL_cleanse(aes_ctx, sizeof(struct aead_aes_ctr_hmac_sha256_ctx));
|
||||
OPENSSL_free(aes_ctx);
|
||||
}
|
||||
|
||||
static void hmac_update_uint64(SHA256_CTX *sha256, uint64_t value) {
|
||||
unsigned i;
|
||||
uint8_t bytes[8];
|
||||
|
||||
for (i = 0; i < sizeof(bytes); i++) {
|
||||
bytes[i] = value & 0xff;
|
||||
value >>= 8;
|
||||
}
|
||||
SHA256_Update(sha256, bytes, sizeof(bytes));
|
||||
}
|
||||
|
||||
static void hmac_calculate(uint8_t out[SHA256_DIGEST_LENGTH],
|
||||
const SHA256_CTX *inner_init_state,
|
||||
const SHA256_CTX *outer_init_state,
|
||||
const uint8_t *ad, size_t ad_len,
|
||||
const uint8_t *nonce, const uint8_t *ciphertext,
|
||||
size_t ciphertext_len) {
|
||||
SHA256_CTX sha256;
|
||||
memcpy(&sha256, inner_init_state, sizeof(sha256));
|
||||
hmac_update_uint64(&sha256, ad_len);
|
||||
hmac_update_uint64(&sha256, ciphertext_len);
|
||||
SHA256_Update(&sha256, nonce, EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN);
|
||||
SHA256_Update(&sha256, ad, ad_len);
|
||||
|
||||
/* Pad with zeros to the end of the SHA-256 block. */
|
||||
const unsigned num_padding =
|
||||
(SHA256_CBLOCK - ((sizeof(uint64_t)*2 +
|
||||
EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN + ad_len) %
|
||||
SHA256_CBLOCK)) %
|
||||
SHA256_CBLOCK;
|
||||
uint8_t padding[SHA256_CBLOCK];
|
||||
memset(padding, 0, num_padding);
|
||||
SHA256_Update(&sha256, padding, num_padding);
|
||||
|
||||
SHA256_Update(&sha256, ciphertext, ciphertext_len);
|
||||
|
||||
uint8_t inner_digest[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Final(inner_digest, &sha256);
|
||||
|
||||
memcpy(&sha256, outer_init_state, sizeof(sha256));
|
||||
SHA256_Update(&sha256, inner_digest, sizeof(inner_digest));
|
||||
SHA256_Final(out, &sha256);
|
||||
}
|
||||
|
||||
static void aead_aes_ctr_hmac_sha256_crypt(
|
||||
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t len, const uint8_t *nonce) {
|
||||
/* Since the AEAD operation is one-shot, keeping a buffer of unused keystream
|
||||
* bytes is pointless. However, |CRYPTO_ctr128_encrypt| requires it. */
|
||||
uint8_t partial_block_buffer[AES_BLOCK_SIZE];
|
||||
unsigned partial_block_offset = 0;
|
||||
memset(partial_block_buffer, 0, sizeof(partial_block_buffer));
|
||||
|
||||
uint8_t counter[AES_BLOCK_SIZE];
|
||||
memcpy(counter, nonce, EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN);
|
||||
memset(counter + EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN, 0, 4);
|
||||
|
||||
if (aes_ctx->ctr) {
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &aes_ctx->ks.ks, counter,
|
||||
partial_block_buffer, &partial_block_offset,
|
||||
aes_ctx->ctr);
|
||||
} else {
|
||||
CRYPTO_ctr128_encrypt(in, out, len, &aes_ctx->ks.ks, counter,
|
||||
partial_block_buffer, &partial_block_offset,
|
||||
aes_ctx->block);
|
||||
}
|
||||
}
|
||||
|
||||
static int aead_aes_ctr_hmac_sha256_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
|
||||
const uint64_t in_len_64 = in_len;
|
||||
|
||||
if (in_len + aes_ctx->tag_len < in_len ||
|
||||
/* This input is so large it would overflow the 32-bit block counter. */
|
||||
in_len_64 >= (OPENSSL_U64(1) << 32) * AES_BLOCK_SIZE) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
|
||||
CIPHER_R_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (max_out_len < in_len + aes_ctx->tag_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
|
||||
CIPHER_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nonce_len != EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
|
||||
CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
aead_aes_ctr_hmac_sha256_crypt(aes_ctx, out, in, in_len, nonce);
|
||||
|
||||
uint8_t hmac_result[SHA256_DIGEST_LENGTH];
|
||||
hmac_calculate(hmac_result, &aes_ctx->inner_init_state,
|
||||
&aes_ctx->outer_init_state, ad, ad_len, nonce, out, in_len);
|
||||
memcpy(out + in_len, hmac_result, aes_ctx->tag_len);
|
||||
*out_len = in_len + aes_ctx->tag_len;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_aes_ctr_hmac_sha256_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
|
||||
size_t plaintext_len;
|
||||
|
||||
if (in_len < aes_ctx->tag_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
|
||||
CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
plaintext_len = in_len - aes_ctx->tag_len;
|
||||
|
||||
if (max_out_len < plaintext_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
|
||||
CIPHER_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nonce_len != EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
|
||||
CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t hmac_result[SHA256_DIGEST_LENGTH];
|
||||
hmac_calculate(hmac_result, &aes_ctx->inner_init_state,
|
||||
&aes_ctx->outer_init_state, ad, ad_len, nonce, in,
|
||||
plaintext_len);
|
||||
if (CRYPTO_memcmp(hmac_result, in + plaintext_len, aes_ctx->tag_len) != 0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
|
||||
CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
aead_aes_ctr_hmac_sha256_crypt(aes_ctx, out, in, plaintext_len, nonce);
|
||||
|
||||
*out_len = plaintext_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_aes_128_ctr_hmac_sha256 = {
|
||||
16 /* AES key */ + 32 /* HMAC key */,
|
||||
12, /* nonce length */
|
||||
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* overhead */
|
||||
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* max tag length */
|
||||
|
||||
aead_aes_ctr_hmac_sha256_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_ctr_hmac_sha256_cleanup,
|
||||
aead_aes_ctr_hmac_sha256_seal,
|
||||
aead_aes_ctr_hmac_sha256_open,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_ctr_hmac_sha256 = {
|
||||
32 /* AES key */ + 32 /* HMAC key */,
|
||||
12, /* nonce length */
|
||||
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* overhead */
|
||||
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* max tag length */
|
||||
|
||||
aead_aes_ctr_hmac_sha256_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_ctr_hmac_sha256_cleanup,
|
||||
aead_aes_ctr_hmac_sha256_seal,
|
||||
aead_aes_ctr_hmac_sha256_open,
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void) {
|
||||
return &aead_aes_128_ctr_hmac_sha256;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void) {
|
||||
return &aead_aes_256_ctr_hmac_sha256;
|
||||
}
|
||||
|
||||
int EVP_has_aes_hardware(void) {
|
||||
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
||||
return aesni_capable() && crypto_gcm_clmul_enabled();
|
||||
|
||||
@@ -209,8 +209,12 @@ static const EVP_AEAD aead_chacha20_poly1305 = {
|
||||
CHACHA20_NONCE_LEN, /* nonce len */
|
||||
POLY1305_TAG_LEN, /* overhead */
|
||||
POLY1305_TAG_LEN, /* max tag length */
|
||||
aead_chacha20_poly1305_init, aead_chacha20_poly1305_cleanup,
|
||||
aead_chacha20_poly1305_seal, aead_chacha20_poly1305_open,
|
||||
aead_chacha20_poly1305_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_chacha20_poly1305_cleanup,
|
||||
aead_chacha20_poly1305_seal,
|
||||
aead_chacha20_poly1305_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_chacha20_poly1305(void) {
|
||||
|
||||
+4
-26
@@ -61,8 +61,6 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define EVP_MAXCHUNK (1<<30)
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
double align;
|
||||
@@ -83,18 +81,8 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
|
||||
while (in_len >= EVP_MAXCHUNK) {
|
||||
DES_ncbc_encrypt(in, out, EVP_MAXCHUNK, &dat->ks.ks, (DES_cblock *)ctx->iv,
|
||||
ctx->encrypt);
|
||||
in_len -= EVP_MAXCHUNK;
|
||||
in += EVP_MAXCHUNK;
|
||||
out += EVP_MAXCHUNK;
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
DES_ncbc_encrypt(in, out, (long)in_len, &dat->ks.ks,
|
||||
(DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
}
|
||||
DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv,
|
||||
ctx->encrypt);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -132,18 +120,8 @@ static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY*) ctx->cipher_data;
|
||||
|
||||
while (in_len >= EVP_MAXCHUNK) {
|
||||
DES_ede3_cbc_encrypt(in, out, EVP_MAXCHUNK, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
in_len -= EVP_MAXCHUNK;
|
||||
in += EVP_MAXCHUNK;
|
||||
out += EVP_MAXCHUNK;
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
}
|
||||
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
+13
-2
@@ -372,13 +372,24 @@ static int aead_rc4_md5_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_rc4_md5_tls_get_rc4_state(const EVP_AEAD_CTX *ctx,
|
||||
const RC4_KEY **out_key) {
|
||||
struct aead_rc4_md5_tls_ctx *rc4_ctx = ctx->aead_state;
|
||||
*out_key = &rc4_ctx->rc4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_rc4_md5_tls = {
|
||||
16 + MD5_DIGEST_LENGTH, /* key len (RC4 + MD5) */
|
||||
0, /* nonce len */
|
||||
MD5_DIGEST_LENGTH, /* overhead */
|
||||
MD5_DIGEST_LENGTH, /* max tag length */
|
||||
aead_rc4_md5_tls_init, aead_rc4_md5_tls_cleanup,
|
||||
aead_rc4_md5_tls_seal, aead_rc4_md5_tls_open,
|
||||
aead_rc4_md5_tls_init,
|
||||
NULL, /* init_with_direction */
|
||||
aead_rc4_md5_tls_cleanup,
|
||||
aead_rc4_md5_tls_seal,
|
||||
aead_rc4_md5_tls_open,
|
||||
aead_rc4_md5_tls_get_rc4_state,
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_rc4_md5_tls(void) { return &aead_rc4_md5_tls; }
|
||||
|
||||
+54
-70
@@ -30,17 +30,6 @@
|
||||
typedef struct {
|
||||
EVP_CIPHER_CTX cipher_ctx;
|
||||
EVP_MD_CTX md_ctx;
|
||||
/* enc_key is the portion of the key used for the stream or block cipher. It
|
||||
* is retained separately to allow the EVP_CIPHER_CTX to be initialized once
|
||||
* the direction is known. */
|
||||
uint8_t enc_key[EVP_MAX_KEY_LENGTH];
|
||||
uint8_t enc_key_len;
|
||||
/* iv is the portion of the key used for the fixed IV. It is retained
|
||||
* separately to allow the EVP_CIPHER_CTX to be initialized once the direction
|
||||
* is known. */
|
||||
uint8_t iv[EVP_MAX_IV_LENGTH];
|
||||
uint8_t iv_len;
|
||||
char initialized;
|
||||
} AEAD_SSL3_CTX;
|
||||
|
||||
static int ssl3_mac(AEAD_SSL3_CTX *ssl3_ctx, uint8_t *out, unsigned *out_len,
|
||||
@@ -87,15 +76,13 @@ static void aead_ssl3_cleanup(EVP_AEAD_CTX *ctx) {
|
||||
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
|
||||
EVP_CIPHER_CTX_cleanup(&ssl3_ctx->cipher_ctx);
|
||||
EVP_MD_CTX_cleanup(&ssl3_ctx->md_ctx);
|
||||
OPENSSL_cleanse(&ssl3_ctx->enc_key, sizeof(ssl3_ctx->enc_key));
|
||||
OPENSSL_cleanse(&ssl3_ctx->iv, sizeof(ssl3_ctx->iv));
|
||||
OPENSSL_free(ssl3_ctx);
|
||||
ctx->aead_state = NULL;
|
||||
}
|
||||
|
||||
static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
size_t tag_len, const EVP_CIPHER *cipher,
|
||||
const EVP_MD *md) {
|
||||
size_t tag_len, enum evp_aead_direction_t dir,
|
||||
const EVP_CIPHER *cipher, const EVP_MD *md) {
|
||||
if (tag_len != EVP_AEAD_DEFAULT_TAG_LENGTH &&
|
||||
tag_len != EVP_MD_size(md)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_init, CIPHER_R_UNSUPPORTED_TAG_SIZE);
|
||||
@@ -109,11 +96,7 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
|
||||
size_t mac_key_len = EVP_MD_size(md);
|
||||
size_t enc_key_len = EVP_CIPHER_key_length(cipher);
|
||||
size_t iv_len = EVP_CIPHER_iv_length(cipher);
|
||||
assert(mac_key_len + enc_key_len + iv_len == key_len);
|
||||
assert(mac_key_len < 256);
|
||||
assert(enc_key_len < 256);
|
||||
assert(iv_len < 256);
|
||||
assert(mac_key_len + enc_key_len + EVP_CIPHER_iv_length(cipher) == key_len);
|
||||
/* Although EVP_rc4() is a variable-length cipher, the default key size is
|
||||
* correct for SSL3. */
|
||||
|
||||
@@ -124,14 +107,11 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
}
|
||||
EVP_CIPHER_CTX_init(&ssl3_ctx->cipher_ctx);
|
||||
EVP_MD_CTX_init(&ssl3_ctx->md_ctx);
|
||||
memcpy(ssl3_ctx->enc_key, &key[mac_key_len], enc_key_len);
|
||||
ssl3_ctx->enc_key_len = (uint8_t)enc_key_len;
|
||||
memcpy(ssl3_ctx->iv, &key[mac_key_len + enc_key_len], iv_len);
|
||||
ssl3_ctx->iv_len = (uint8_t)iv_len;
|
||||
ssl3_ctx->initialized = 0;
|
||||
|
||||
ctx->aead_state = ssl3_ctx;
|
||||
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, cipher, NULL, NULL, NULL, 0) ||
|
||||
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, cipher, NULL, &key[mac_key_len],
|
||||
&key[mac_key_len + enc_key_len],
|
||||
dir == evp_aead_seal) ||
|
||||
!EVP_DigestInit_ex(&ssl3_ctx->md_ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(&ssl3_ctx->md_ctx, key, mac_key_len)) {
|
||||
aead_ssl3_cleanup(ctx);
|
||||
@@ -142,31 +122,6 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* aead_ssl3_ensure_cipher_init initializes |ssl3_ctx| for encryption (or
|
||||
* decryption, if |encrypt| is zero). If it has already been initialized, it
|
||||
* ensures the direction matches and fails otherwise. It returns one on success
|
||||
* and zero on failure.
|
||||
*
|
||||
* Note that, unlike normal AEADs, legacy SSL3 AEADs may not be used concurrently
|
||||
* due to this (and bulk-cipher-internal) statefulness. */
|
||||
static int aead_ssl3_ensure_cipher_init(AEAD_SSL3_CTX *ssl3_ctx, int encrypt) {
|
||||
if (!ssl3_ctx->initialized) {
|
||||
/* Finish initializing the EVP_CIPHER_CTX now that the direction is
|
||||
* known. */
|
||||
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, NULL, NULL, ssl3_ctx->enc_key,
|
||||
ssl3_ctx->iv, encrypt)) {
|
||||
return 0;
|
||||
}
|
||||
ssl3_ctx->initialized = 1;
|
||||
} else if (ssl3_ctx->cipher_ctx.encrypt != encrypt) {
|
||||
/* Unlike a normal AEAD, using an SSL3 AEAD once freezes the direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_ensure_cipher_init,
|
||||
CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
@@ -175,6 +130,12 @@ static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
|
||||
size_t total = 0;
|
||||
|
||||
if (!ssl3_ctx->cipher_ctx.encrypt) {
|
||||
/* Unlike a normal AEAD, an SSL3 AEAD may only be used in one direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_seal, CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (in_len + EVP_AEAD_max_overhead(ctx->aead) < in_len ||
|
||||
in_len > INT_MAX) {
|
||||
/* EVP_CIPHER takes int as input. */
|
||||
@@ -197,10 +158,6 @@ static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!aead_ssl3_ensure_cipher_init(ssl3_ctx, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compute the MAC. This must be first in case the operation is being done
|
||||
* in-place. */
|
||||
uint8_t mac[EVP_MAX_MD_SIZE];
|
||||
@@ -257,6 +214,12 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
|
||||
|
||||
if (ssl3_ctx->cipher_ctx.encrypt) {
|
||||
/* Unlike a normal AEAD, an SSL3 AEAD may only be used in one direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_open, CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t mac_len = EVP_MD_CTX_size(&ssl3_ctx->md_ctx);
|
||||
if (in_len < mac_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_open, CIPHER_R_BAD_DECRYPT);
|
||||
@@ -286,10 +249,6 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!aead_ssl3_ensure_cipher_init(ssl3_ctx, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Decrypt to get the plaintext + MAC + padding. */
|
||||
size_t total = 0;
|
||||
int len;
|
||||
@@ -337,31 +296,46 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_ssl3_get_rc4_state(const EVP_AEAD_CTX *ctx, const RC4_KEY **out_key) {
|
||||
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
|
||||
if (EVP_CIPHER_CTX_cipher(&ssl3_ctx->cipher_ctx) != EVP_rc4()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_key = (RC4_KEY*) ssl3_ctx->cipher_ctx.cipher_data;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_rc4_md5_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_md5());
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_md5());
|
||||
}
|
||||
|
||||
static int aead_rc4_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_sha1());
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_sha1());
|
||||
}
|
||||
|
||||
static int aead_aes_128_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
|
||||
EVP_sha1());
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
|
||||
EVP_sha1());
|
||||
}
|
||||
static int aead_des_ede3_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
|
||||
EVP_sha1());
|
||||
}
|
||||
|
||||
@@ -370,10 +344,12 @@ static const EVP_AEAD aead_rc4_md5_ssl3 = {
|
||||
0, /* nonce len */
|
||||
MD5_DIGEST_LENGTH, /* overhead */
|
||||
MD5_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_rc4_md5_ssl3_init,
|
||||
aead_ssl3_cleanup,
|
||||
aead_ssl3_seal,
|
||||
aead_ssl3_open,
|
||||
aead_ssl3_get_rc4_state,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_rc4_sha1_ssl3 = {
|
||||
@@ -381,10 +357,12 @@ static const EVP_AEAD aead_rc4_sha1_ssl3 = {
|
||||
0, /* nonce len */
|
||||
SHA_DIGEST_LENGTH, /* overhead */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_rc4_sha1_ssl3_init,
|
||||
aead_ssl3_cleanup,
|
||||
aead_ssl3_seal,
|
||||
aead_ssl3_open,
|
||||
aead_ssl3_get_rc4_state,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha1_ssl3 = {
|
||||
@@ -392,10 +370,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_ssl3 = {
|
||||
0, /* nonce len */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_128_cbc_sha1_ssl3_init,
|
||||
aead_ssl3_cleanup,
|
||||
aead_ssl3_seal,
|
||||
aead_ssl3_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha1_ssl3 = {
|
||||
@@ -403,10 +383,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_ssl3 = {
|
||||
0, /* nonce len */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_256_cbc_sha1_ssl3_init,
|
||||
aead_ssl3_cleanup,
|
||||
aead_ssl3_seal,
|
||||
aead_ssl3_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_des_ede3_cbc_sha1_ssl3 = {
|
||||
@@ -414,10 +396,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_ssl3 = {
|
||||
0, /* nonce len */
|
||||
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_des_ede3_cbc_sha1_ssl3_init,
|
||||
aead_ssl3_cleanup,
|
||||
aead_ssl3_seal,
|
||||
aead_ssl3_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_rc4_md5_ssl3(void) { return &aead_rc4_md5_ssl3; }
|
||||
|
||||
+90
-89
@@ -22,6 +22,7 @@
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/type_check.h>
|
||||
|
||||
#include "../crypto/internal.h"
|
||||
#include "internal.h"
|
||||
@@ -34,37 +35,26 @@ typedef struct {
|
||||
* separately for the constant-time CBC code. */
|
||||
uint8_t mac_key[EVP_MAX_MD_SIZE];
|
||||
uint8_t mac_key_len;
|
||||
/* enc_key is the portion of the key used for the stream or block
|
||||
* cipher. It is retained separately to allow the EVP_CIPHER_CTX to be
|
||||
* initialized once the direction is known. */
|
||||
uint8_t enc_key[EVP_MAX_KEY_LENGTH];
|
||||
uint8_t enc_key_len;
|
||||
/* iv is the portion of the key used for the fixed IV. It is retained
|
||||
* separately to allow the EVP_CIPHER_CTX to be initialized once the direction
|
||||
* is known. */
|
||||
uint8_t iv[EVP_MAX_IV_LENGTH];
|
||||
uint8_t iv_len;
|
||||
/* implicit_iv is one iff this is a pre-TLS-1.1 CBC cipher without an explicit
|
||||
* IV. */
|
||||
char implicit_iv;
|
||||
char initialized;
|
||||
} AEAD_TLS_CTX;
|
||||
|
||||
OPENSSL_COMPILE_ASSERT(EVP_MAX_MD_SIZE < 256, mac_key_len_fits_in_uint8_t);
|
||||
|
||||
static void aead_tls_cleanup(EVP_AEAD_CTX *ctx) {
|
||||
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
|
||||
EVP_CIPHER_CTX_cleanup(&tls_ctx->cipher_ctx);
|
||||
HMAC_CTX_cleanup(&tls_ctx->hmac_ctx);
|
||||
OPENSSL_cleanse(&tls_ctx->mac_key, sizeof(tls_ctx->mac_key));
|
||||
OPENSSL_cleanse(&tls_ctx->enc_key, sizeof(tls_ctx->enc_key));
|
||||
OPENSSL_cleanse(&tls_ctx->iv, sizeof(tls_ctx->iv));
|
||||
OPENSSL_free(tls_ctx);
|
||||
ctx->aead_state = NULL;
|
||||
}
|
||||
|
||||
static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
size_t tag_len, const EVP_CIPHER *cipher,
|
||||
const EVP_MD *md, char implicit_iv) {
|
||||
size_t tag_len, enum evp_aead_direction_t dir,
|
||||
const EVP_CIPHER *cipher, const EVP_MD *md,
|
||||
char implicit_iv) {
|
||||
if (tag_len != EVP_AEAD_DEFAULT_TAG_LENGTH &&
|
||||
tag_len != EVP_MD_size(md)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_tls_init, CIPHER_R_UNSUPPORTED_TAG_SIZE);
|
||||
@@ -78,11 +68,8 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
|
||||
size_t mac_key_len = EVP_MD_size(md);
|
||||
size_t enc_key_len = EVP_CIPHER_key_length(cipher);
|
||||
size_t iv_len = implicit_iv ? EVP_CIPHER_iv_length(cipher) : 0;
|
||||
assert(mac_key_len + enc_key_len + iv_len == key_len);
|
||||
assert(mac_key_len < 256);
|
||||
assert(enc_key_len < 256);
|
||||
assert(iv_len < 256);
|
||||
assert(mac_key_len + enc_key_len +
|
||||
(implicit_iv ? EVP_CIPHER_iv_length(cipher) : 0) == key_len);
|
||||
/* Although EVP_rc4() is a variable-length cipher, the default key size is
|
||||
* correct for TLS. */
|
||||
|
||||
@@ -93,17 +80,15 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
}
|
||||
EVP_CIPHER_CTX_init(&tls_ctx->cipher_ctx);
|
||||
HMAC_CTX_init(&tls_ctx->hmac_ctx);
|
||||
assert(mac_key_len <= EVP_MAX_MD_SIZE);
|
||||
memcpy(tls_ctx->mac_key, key, mac_key_len);
|
||||
tls_ctx->mac_key_len = (uint8_t)mac_key_len;
|
||||
memcpy(tls_ctx->enc_key, &key[mac_key_len], enc_key_len);
|
||||
tls_ctx->enc_key_len = (uint8_t)enc_key_len;
|
||||
memcpy(tls_ctx->iv, &key[mac_key_len + enc_key_len], iv_len);
|
||||
tls_ctx->iv_len = (uint8_t)iv_len;
|
||||
tls_ctx->implicit_iv = implicit_iv;
|
||||
tls_ctx->initialized = 0;
|
||||
|
||||
ctx->aead_state = tls_ctx;
|
||||
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, cipher, NULL, NULL, NULL, 0) ||
|
||||
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, cipher, NULL, &key[mac_key_len],
|
||||
implicit_iv ? &key[mac_key_len + enc_key_len] : NULL,
|
||||
dir == evp_aead_seal) ||
|
||||
!HMAC_Init_ex(&tls_ctx->hmac_ctx, key, mac_key_len, md, NULL)) {
|
||||
aead_tls_cleanup(ctx);
|
||||
return 0;
|
||||
@@ -113,32 +98,6 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* aead_tls_ensure_cipher_init initializes |tls_ctx| for encryption (or
|
||||
* decryption, if |encrypt| is zero). If it has already been initialized, it
|
||||
* ensures the direction matches and fails otherwise. It returns one on success
|
||||
* and zero on failure.
|
||||
*
|
||||
* Note that, unlike normal AEADs, legacy TLS AEADs may not be used concurrently
|
||||
* due to this (and bulk-cipher-internal) statefulness. */
|
||||
static int aead_tls_ensure_cipher_init(AEAD_TLS_CTX *tls_ctx, int encrypt) {
|
||||
if (!tls_ctx->initialized) {
|
||||
/* Finish initializing the EVP_CIPHER_CTX now that the direction is
|
||||
* known. */
|
||||
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, NULL, NULL, tls_ctx->enc_key,
|
||||
tls_ctx->implicit_iv ? tls_ctx->iv : NULL,
|
||||
encrypt)) {
|
||||
return 0;
|
||||
}
|
||||
tls_ctx->initialized = 1;
|
||||
} else if (tls_ctx->cipher_ctx.encrypt != encrypt) {
|
||||
/* Unlike a normal AEAD, using a TLS AEAD once freezes the direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_tls_ensure_cipher_init,
|
||||
CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
@@ -147,6 +106,13 @@ static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
|
||||
size_t total = 0;
|
||||
|
||||
if (!tls_ctx->cipher_ctx.encrypt) {
|
||||
/* Unlike a normal AEAD, a TLS AEAD may only be used in one direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_tls_seal, CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if (in_len + EVP_AEAD_max_overhead(ctx->aead) < in_len ||
|
||||
in_len > INT_MAX) {
|
||||
/* EVP_CIPHER takes int as input. */
|
||||
@@ -169,10 +135,6 @@ static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!aead_tls_ensure_cipher_init(tls_ctx, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* To allow for CBC mode which changes cipher length, |ad| doesn't include the
|
||||
* length for legacy ciphers. */
|
||||
uint8_t ad_extra[2];
|
||||
@@ -249,6 +211,13 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
|
||||
|
||||
if (tls_ctx->cipher_ctx.encrypt) {
|
||||
/* Unlike a normal AEAD, a TLS AEAD may only be used in one direction. */
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_tls_open, CIPHER_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if (in_len < HMAC_size(&tls_ctx->hmac_ctx)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, aead_tls_open, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
@@ -277,10 +246,6 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!aead_tls_ensure_cipher_init(tls_ctx, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Configure the explicit IV. */
|
||||
if (EVP_CIPHER_CTX_mode(&tls_ctx->cipher_ctx) == EVP_CIPH_CBC_MODE &&
|
||||
!tls_ctx->implicit_iv &&
|
||||
@@ -394,83 +359,101 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
static int aead_rc4_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_sha1(), 0);
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_sha1(),
|
||||
0);
|
||||
}
|
||||
|
||||
static int aead_aes_128_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
|
||||
EVP_sha1(), 0);
|
||||
}
|
||||
|
||||
static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
|
||||
static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(
|
||||
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
|
||||
EVP_sha1(), 1);
|
||||
}
|
||||
|
||||
static int aead_aes_128_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
|
||||
EVP_sha256(), 0);
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
|
||||
EVP_sha1(), 0);
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
|
||||
static int aead_aes_256_cbc_sha1_tls_implicit_iv_init(
|
||||
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
|
||||
EVP_sha1(), 1);
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
|
||||
EVP_sha256(), 0);
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha384_tls_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
|
||||
EVP_sha384(), 0);
|
||||
}
|
||||
|
||||
static int aead_des_ede3_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
|
||||
EVP_sha1(), 0);
|
||||
}
|
||||
|
||||
static int aead_des_ede3_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key,
|
||||
size_t key_len,
|
||||
size_t tag_len) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
|
||||
static int aead_des_ede3_cbc_sha1_tls_implicit_iv_init(
|
||||
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
|
||||
EVP_sha1(), 1);
|
||||
}
|
||||
|
||||
static int aead_rc4_sha1_tls_get_rc4_state(const EVP_AEAD_CTX *ctx,
|
||||
const RC4_KEY **out_key) {
|
||||
const AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX*) ctx->aead_state;
|
||||
if (EVP_CIPHER_CTX_cipher(&tls_ctx->cipher_ctx) != EVP_rc4()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_key = (const RC4_KEY*) tls_ctx->cipher_ctx.cipher_data;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_rc4_sha1_tls = {
|
||||
SHA_DIGEST_LENGTH + 16, /* key len (SHA1 + RC4) */
|
||||
0, /* nonce len */
|
||||
SHA_DIGEST_LENGTH, /* overhead */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_rc4_sha1_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
aead_rc4_sha1_tls_get_rc4_state, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha1_tls = {
|
||||
@@ -478,10 +461,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls = {
|
||||
16, /* nonce len (IV) */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_128_cbc_sha1_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
|
||||
@@ -489,10 +474,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
|
||||
0, /* nonce len */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_128_cbc_sha1_tls_implicit_iv_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
|
||||
@@ -500,10 +487,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
|
||||
16, /* nonce len (IV) */
|
||||
16 + SHA256_DIGEST_LENGTH, /* overhead (padding + SHA256) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_128_cbc_sha256_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
|
||||
@@ -511,10 +500,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
|
||||
16, /* nonce len (IV) */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_256_cbc_sha1_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha1_tls_implicit_iv = {
|
||||
@@ -522,10 +513,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_tls_implicit_iv = {
|
||||
0, /* nonce len */
|
||||
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_256_cbc_sha1_tls_implicit_iv_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha256_tls = {
|
||||
@@ -533,10 +526,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha256_tls = {
|
||||
16, /* nonce len (IV) */
|
||||
16 + SHA256_DIGEST_LENGTH, /* overhead (padding + SHA256) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_256_cbc_sha256_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha384_tls = {
|
||||
@@ -544,10 +539,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha384_tls = {
|
||||
16, /* nonce len (IV) */
|
||||
16 + SHA384_DIGEST_LENGTH, /* overhead (padding + SHA384) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_aes_256_cbc_sha384_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_des_ede3_cbc_sha1_tls = {
|
||||
@@ -555,10 +552,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_tls = {
|
||||
8, /* nonce len (IV) */
|
||||
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_des_ede3_cbc_sha1_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_des_ede3_cbc_sha1_tls_implicit_iv = {
|
||||
@@ -566,10 +565,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_tls_implicit_iv = {
|
||||
0, /* nonce len */
|
||||
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
|
||||
SHA_DIGEST_LENGTH, /* max tag length */
|
||||
NULL, /* init */
|
||||
aead_des_ede3_cbc_sha1_tls_implicit_iv_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_seal,
|
||||
aead_tls_open,
|
||||
NULL, /* get_rc4_state */
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_rc4_sha1_tls(void) { return &aead_rc4_sha1_tls; }
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
#include <openssl/aead.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@@ -97,7 +98,7 @@ struct evp_cipher_st {
|
||||
int (*cipher)(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t inl);
|
||||
|
||||
int (*cleanup)(EVP_CIPHER_CTX *);
|
||||
void (*cleanup)(EVP_CIPHER_CTX *);
|
||||
|
||||
int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr);
|
||||
};
|
||||
@@ -117,6 +118,9 @@ struct evp_aead_st {
|
||||
|
||||
int (*init)(struct evp_aead_ctx_st *, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len);
|
||||
int (*init_with_direction)(struct evp_aead_ctx_st *, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir);
|
||||
void (*cleanup)(struct evp_aead_ctx_st *);
|
||||
|
||||
int (*seal)(const struct evp_aead_ctx_st *ctx, uint8_t *out,
|
||||
@@ -128,6 +132,9 @@ struct evp_aead_st {
|
||||
size_t *out_len, size_t max_out_len, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len);
|
||||
|
||||
int (*get_rc4_state)(const struct evp_aead_ctx_st *ctx,
|
||||
const RC4_KEY **out_key);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
KEY: 067b841a2540cb467b75f2188f5da4b5aeb7e0e44582a2b668b5b1ff39e21c4e65745470fb1be1aa909c62fabcf0e6ac
|
||||
NONCE: 10e0ecb00da5345127407150
|
||||
IN:
|
||||
AD:
|
||||
CT:
|
||||
TAG: a82a891565e466957ad5a499d45b579d31acaf582f54d518f8f9c128936dac4c
|
||||
|
||||
KEY: c9d9ef2c808c3f8b22f659c12147104b08cec2390a84f0c4b887ca4c247c8c9dd45e72f48b30b67a8545750387232344
|
||||
NONCE: 58bddf96158a3a588bf3ec05
|
||||
IN:
|
||||
AD: 5d
|
||||
CT:
|
||||
TAG: 3580c1601d1c9a5b1595d3dee35b0cd9e1b115d8b0abee557b2c207b8d0df5ee
|
||||
|
||||
KEY: f755dc6786e21f39b595389a51d36673e1ffb94ffc066c03873eb31839be6fa319fd31c8bea29f03ff28831861e60b6e
|
||||
NONCE: bd6c80797f1f4c563b06fd3b
|
||||
IN:
|
||||
AD: 78d88005136e312639572343a2d0daf7483d8235291ee3ac002469456b075243dc03380c387030d546c2b1
|
||||
CT:
|
||||
TAG: dede80d810fc449a769c79a5ecd2c0d68e9e0fae567781e623ab2098c88d8a86
|
||||
|
||||
KEY: 43a0a28fef8b89b8fb0f76de01d802935ad561e27ca9c9fa629347be676a6af758501b6a652f369045da5fef751b56bb
|
||||
NONCE: 0f6472f1e589c16ca5ad45b2
|
||||
IN:
|
||||
AD: 78e4eafccfc87631f0314c442ba4c07bca36f996a5b3408f9e445d6009a87ded16b33a4af9537a4619cab70d
|
||||
CT:
|
||||
TAG: 11fa62dd8374aabe728ebf7e9aa1c02cf8f2dbc29f9aaf1940313f0b7c3e0301
|
||||
|
||||
KEY: acf8e5f1bd64e6289370650b5b3fd773320025c8b229fd335d9461768cd0a17b4bcc946919932efdc9fc84a7f50768bf
|
||||
NONCE: 1aecfc90d28bcdcc5a8e3578
|
||||
IN:
|
||||
AD: 6daedbdc69133b56f6a8f098f9f70cdb7e129e51115df385a6d86204a53412cd999cf2e69f45e168efed4742b6
|
||||
CT:
|
||||
TAG: fbe0511ba0ec5709def9966a9b05facf171cddd81ee2cd56e7afc867af465f31
|
||||
|
||||
KEY: 2773c92e6cddc9a5e5dcaf3893080fd2153f009d807df0b175c76615645f2087539e299d8411b27badb749a9845c5e29
|
||||
NONCE: 6d04ed129299651aec0465f8
|
||||
IN:
|
||||
AD: 44219577e361a7a4681172d120a2d653a53ec74bc487ccde4954835943bca413d55c65dc665310148654d8c1e2e6bc2f06ec344473120ad1f95739b993a57f9ec0b3299cc088f385894fff876fc2ce8ce6b77ca253f177ba615101e84e17ad0e60704cff195dcd50eb48c77de409797e0b1c8c4c5b9215a4a0399954a008267b
|
||||
CT:
|
||||
TAG: 6ab61ac4493e58e48d071d994a000f1c1f498d22f83c8d2af56b03c155afc57e
|
||||
|
||||
KEY: 23189bf23bc4b734410d1c7ae321c42e144a25347a8029bb925e3d8ac1b92f4eb97227c1dece86ae9dea7d127eb33f9b
|
||||
NONCE: 30681944cd5d78f46d36ed8a
|
||||
IN: 59
|
||||
AD:
|
||||
CT: 92
|
||||
TAG: 986aa8438da3cf4a98f478f90d24908c6a4e848f299873e649b256f5499d89d9
|
||||
|
||||
KEY: 463d1148325c5f57af670877068a78203571b8b19f40e9f0373156b7448ab315df86c77d7c85ba6e54b9bc329399f687
|
||||
NONCE: cc9d015a4b5a888b36b14d05
|
||||
IN: 28
|
||||
AD: 6a
|
||||
CT: 05
|
||||
TAG: f66e8dc794b142944fa46d5c04a3e3fe00291668374846d763f2beeffd4ca4a0
|
||||
|
||||
KEY: 937eaab44e7c7d2cd5bbb053c12e6255e0aaa42cbe7d83025b7a2887eff8f098d019c80af849b0ed7da54a5ba5b39200
|
||||
NONCE: 2b160d24df579836e1572ea2
|
||||
IN: 9a
|
||||
AD: 35841a33ba3a6ed3d89a1f76d06c61613d09834847e5a41f8616748e30c14335e5baa43d49fceaf85aeb22
|
||||
CT: 80
|
||||
TAG: 5e5799c147be0329dbcabf7ecdba6ac595ebc2d06b9d757426fbb31e8b39f62a
|
||||
|
||||
KEY: 68a746f382fcc11c02af7b352b9d710c137a9f59bc5886dc374ca88cdc01b86fe5678fde16cfa846846539f67a429276
|
||||
NONCE: b94346c033ac1a3d709c4f09
|
||||
IN: ad
|
||||
AD: ad61c9168debf9974e19759088944e888346aff99f3e2e4522549c8ae332a0f41922972fb7c1d5ff24e7ae4b
|
||||
CT: 46
|
||||
TAG: 62ae92ff64710a9f260da2562e246356e9d749c3584fb9f40d9572307ccbbd31
|
||||
|
||||
KEY: 6622579d1d6350fd5dff432b69d172cc51f99bdaff50b0a1c0f4cda8d5904581ba8657ba61c6936407243d7fb64b00da
|
||||
NONCE: a880caa7157a13540d2b724f
|
||||
IN: 2a
|
||||
AD: 95a23eafcff892deecaf093109d30290d819851ad5c91061510e54baa2b039b114c815da20f0e3ba2ba4875bdd
|
||||
CT: ce
|
||||
TAG: 33f09666f9fd1d92f137d9f3f7092b47b2bd71a7e3139dcd19a803a6b17f2a3a
|
||||
|
||||
KEY: 91ce9dd87c7d11d2c4da41863b6851c40fba786a612e0fbf0d1956a71286dfc61fa10bf7d148cecd72b6ceeb82b68d3f
|
||||
NONCE: a50dc3d8fd63d3076cc70ff6
|
||||
IN: da
|
||||
AD: 9ce8e1a777c159ec775abbd67d85e84f3550c3296e848dec18b61bbd713a98a033805bfe6e2f2a011dd7fd754708e524168142aeee579cae19c7eab78fa7c42fa335f0c725baf556160beef9e4afd1050a2c8813be6bd14cc6982116d0229d53e9b4de923abf6ba99bdffe1d5f21748ae74caddb077d9f7488b394436222beca
|
||||
CT: 2b
|
||||
TAG: 1541cd745bc0259dd72a212474f5c7b8c121dd0289d674e5ba8d56a220d1f1d0
|
||||
|
||||
KEY: 1ad577d3b47e3fff8528e336a43a7ffef72f811e05b5c69ccfe777b10f29061e289178e394a1c87ba483c7f98ea5431d
|
||||
NONCE: 1fcaa4757a9e48ed2cb3be62
|
||||
IN: 46d30dac550103006c292a9ac05d31
|
||||
AD:
|
||||
CT: 37616eba30c55595fa0ad5d50f91ca
|
||||
TAG: 5c3ac4010f75adf90f81e775b07ab939e7551a9b8e0486ba33766728ed498245
|
||||
|
||||
KEY: 6df310dc1847b42c68e50b03d154b73d7f3823354b32759c5369bce1a1b4cd63ccdb911c2dc792acf84b8b8f3fdfb89d
|
||||
NONCE: 92e6759a31dd556ff9124d73
|
||||
IN: 6daba76658db642209e276ff7c8d46
|
||||
AD: 32
|
||||
CT: ce1814c03037078b6be3252460af48
|
||||
TAG: 46e61913f2a1ff6e77faade9a7cd37a82eff3ebec4276fbddff9266b9c9bd873
|
||||
|
||||
KEY: f848c2300995f5c98dcd0db24574d7c61459ca64c084421c6ad156e80e398904417ee745245ddae91be20fb07e66bdb6
|
||||
NONCE: 3b177e11063445717f417d14
|
||||
IN: bbf225131c821a6a60817cc65bf699
|
||||
AD: 4c5ab4fdbe0018344629349feed5d8c3ae0c5b64f2b093576a2aaa1225e7a50eca01a9962c9b4f8fc5c12a
|
||||
CT: 1538957e78f3ab0fed77906153d715
|
||||
TAG: 2c7760d47407ad7b0d5b85fa4967eaa7b6c0bb6eb16619adde7a191abfdf3da3
|
||||
|
||||
KEY: d406cac07630ce2c071732a0ec95f55123486d2677465768dc7db13f90902cf172f92e19f57f5cf7c68cd7bde7ee4b4b
|
||||
NONCE: 766aede0120b634a4be6fa12
|
||||
IN: 3804d40090a38d4c97a5fff631068c
|
||||
AD: 7707b7d0f266284e84c2ecdd5a18832650c3e27d66697616c9e9bb2f8a09a3295de0119582ca3614b9608548
|
||||
CT: 91e96462a5dfbe8b7af201158a36dc
|
||||
TAG: 56623e5813070a0e2f5184aed83b9863301ca02e3108f7afc478d48305e397f8
|
||||
|
||||
KEY: 42bb22a317ed9f9df8119746e9a1257217e5b0144051ca56f39587021d969bc0acc02795f3bd201031e8c05af08ad079
|
||||
NONCE: 0a9f6bace71a1ab21f4917df
|
||||
IN: 013f7b8c75307158f4f300450e7a78
|
||||
AD: cd95a649ae215fe73442a6991e157232cbcabecff6042b87d41557e35b97606d606c3ded54f5d3db7aa2773f67
|
||||
CT: e588dbcecbdb7667dccf7fe34f8387
|
||||
TAG: b04461748109ed9068c7e9c0446528ef09b01613c3b3aa1ffeed6685ebb550f5
|
||||
|
||||
KEY: e1cfcbaba3a04b5108ce2a87099a6aae936ee38acd92b7e6b7df0e3bcb9ad18fc579b5d470ef3e04c23459f509852458
|
||||
NONCE: 112dd267174bcd81e6fbd924
|
||||
IN: 288a1e44b406aebec7b418674f81e7
|
||||
AD: 7809d8011c5a963df14fb8981e874119c60b7a9d897d13a05651759db5835deffdd991fbf98b9aa71c79e48bd701b228ba248b6bed874b02da7fcf28a04c38b81c0ff628846015258af30dbf28ea4f3283f664f888fca545f5fc57dccc4ad1dd476c52fba341182ecf783706c5c458bf0ee5ec83454afba78eb8b5ca17af88ec
|
||||
CT: 80f4e1012d76f6180ca00fd32c8fec
|
||||
TAG: 6de00bf2fd3c88ab34ca9390f7e559875e43e0f938303816a3a75a35729bc453
|
||||
|
||||
KEY: 84172547d8608bd9e788a7bb60df2982963716e45f8e63f0c5033327d85c920c5e3776e314246b1694b739c39abfa29f
|
||||
NONCE: a3f1643bb504b7ce9e5b43c2
|
||||
IN: 7e76323eb13e64da9b240a57c95c855b
|
||||
AD:
|
||||
CT: 966487c18f025d67b42a04c30d3ff4c3
|
||||
TAG: 8bb03d893f0ce8ea4a6a47245bc7f20c72acf8caa466edd01365d0f74c929463
|
||||
|
||||
KEY: 02dee8f2e63b37fe3cbae9101fed0946e05e5090510bef3324a82e3f27456a45ab1b6cdeddb1fe515ad07aefeee6ccbc
|
||||
NONCE: 64723d21365d62926d5c2262
|
||||
IN: 4f1f132c50a01ad48882ce88655b33f7
|
||||
AD: d8
|
||||
CT: b102082e14cd9ecc0895f7a6f08ab522
|
||||
TAG: 2c09651c1a51cb8a375746236fe258a36e725936ccedbc4dfafee6c3084a4716
|
||||
|
||||
KEY: 5db57cf6301bab815d38879b35c9db72fd40ac576d259ad5074d0828364050554e9fc08335b5f2bf066b09e50fbe6ba4
|
||||
NONCE: 36e5340d844de213c312177a
|
||||
IN: 41a6e910b14388740ea351eb1df980c9
|
||||
AD: 8316a6b9b155b2de5e724f7593ecdcee442eaef7b9ad204eda4744a5e648c2dd84f48ee81397e485953465
|
||||
CT: ee21d4d47042415ca27d2ecb11b13d79
|
||||
TAG: 5015da5a3339389d39d0fcafb56ef4005b342e69ba47930e84408d33aadf5f2a
|
||||
|
||||
KEY: a493dd6de6fd6584599096442dd9345f6f2d8fc2d426c78eee2b992b4071aba4ce463f3ca293c84b2faf3e8644b6ec25
|
||||
NONCE: 4f9be6f788ee960adc650d86
|
||||
IN: 4de6e244251091cf13762d20685e9085
|
||||
AD: d15da312b7522c18384acdbf6348b5e105557f1790a6a203a65acd73397524681666743f3145048775ad84e3
|
||||
CT: bb1296457daa39d889c8f986938d6a39
|
||||
TAG: b93548cea90c34d03d6f5683ae2cc78814531b803d42cfe57623fd4bdc8f084c
|
||||
|
||||
KEY: 8cc59ebe2c7375a70915c48d2978a1f720bc0aa2775ce9189ae7b3d5dda9a81e56cde0e0a29939599409b71f0b65f346
|
||||
NONCE: b0ab041f37ea1e594f1eddb3
|
||||
IN: cd0aeaf6806cb99e6bc1c8c5d830de8c
|
||||
AD: 8f4b5a9609df757826dbe7e51bb6a2c6f45f601263cf668836193513cf008ab6b36a7d5447039f1268821ec37e
|
||||
CT: 5d5375b9d9cff6d0c1dbd14221509a0d
|
||||
TAG: d8850bbc838e068b817c24d018f8f1e1cb8aac0a68392a700f48099f81b6c37c
|
||||
|
||||
KEY: f3e9c507478d3f99dbf3e2421e45929b096ab3f3d4aa4ef9c338c5a1a2425c9936b7df602502d33cbafcf781350da77e
|
||||
NONCE: d4872a30c9d1fa9001a25afe
|
||||
IN: 25e05ea69a956b12a9be4ef03ae9d30c
|
||||
AD: 8b346c20e7c64b805d9c8d325829201753069c60b3f221f31474f55cb20315373ccd7c2a8f215e9efc407ae91b05d8b6d693a3780fdd65d7715cdded86c3d6204055812f3fce897f829d1df9ffaaf48885291701ac1765090c383162dd13d6bac88baa0cb2d748363bbb79843a1594ec6d8778854a63b7c9ffeb6d1fb17e90f1
|
||||
CT: 61325c7e0d29e9ad50b9c0fec02d7ef4
|
||||
TAG: 4b2d0caece46ce2496445883c03234e900189c22b54390b399d78ee4ebfbb7d4
|
||||
|
||||
KEY: 3d9b651e65e9239c9e33aafb091b348161ab797901fd0468aedd014e4d5683c8f3f54f20ea6bb07bb25dd258df7bcd5e
|
||||
NONCE: 32bcf856a14437114e7814cc
|
||||
IN: 08a667c2923f87a7db6502478d32280bdc
|
||||
AD:
|
||||
CT: 5e8e02cc91c732356bb9f1fc599426a379
|
||||
TAG: 5449e878d558beff4bc7dfbb5f0195444705cfb259773b4faec524fbaca37ea0
|
||||
|
||||
KEY: 2124cedb5f3f2558f8b9a2304a29c0df6102333cb4aa10625aa82cd76ab645c73f3b7cbf7c96cacdcb9e0b738e40c042
|
||||
NONCE: 7ae419446a3a105beb2fbcc5
|
||||
IN: a305dc4a2e50cc8e7a65a4b10b73849636
|
||||
AD: 70
|
||||
CT: fcaea620f7e9ed1337214c4b432d9869d2
|
||||
TAG: bfc739c8504a4d9033ab1915f46c1bf65c5382fe9ed1c134026ba32c63ca131e
|
||||
|
||||
KEY: b027feb1aced8fb3af27a9fd7f531c30991ec1abd9f230a3e5d6ee9fc6a77747013f8e14dcdbd07b0083d0ce23dfa711
|
||||
NONCE: a30a6520f933ff5265e6e305
|
||||
IN: a705f842d542cb6957fbce21854755c6dc
|
||||
AD: 447bdaf34dfab9cc3dd7777ebaf80077f391093bac9817bf02ad98db9d3f271282ecaf0ff19652f92076d1
|
||||
CT: 3ddcb07c121b498f1abb73bedb527d4df4
|
||||
TAG: 55957a0e884dea22d6ace10e5936cdac891f5b54225349ede5c44715f1064b5e
|
||||
|
||||
KEY: ffefb7770a7cf125395703985823f3e926f3722ca0764518fd2b8996577bec03648c8d542af1c6e36b51174b0ba88316
|
||||
NONCE: 4c31394b4b24f6251a839891
|
||||
IN: f026a1d352c37b204c6c1138abee9a9a75
|
||||
AD: 1e7c0f71a3aacd87ea785521ea31f93b1efd0bdf97952e0b84ecd50c706806deffc19caea312b5a9988454d2
|
||||
CT: 23c8bae37db93ed9f55f2903e04b7c6a8e
|
||||
TAG: 89d0a7e7d921dea5bb54c28e79b612688e42506aa69b141de830c8d63bdefcee
|
||||
|
||||
KEY: 453cf5e4f48ce5a961c94af0e1639c156965970f561ac17fe08d5b75975abe3db87412640972e463290800666be80441
|
||||
NONCE: b3e3f9708a86c7cdf139e496
|
||||
IN: 53f1b11de497cc6ecb411a777dc3d60197
|
||||
AD: afe29e074dcce850ac6640230e6b9f66a64587c5fbe8679144e065d3b1700c721833ba8f918e926c9142f5f362
|
||||
CT: 15d5f597be46a19566a72c5e843b77f70c
|
||||
TAG: a561c3375c096a116a721e9404e555a2deaf3f677a8611694281663274708f58
|
||||
|
||||
KEY: 3d497f81d0652d475bcd85cf53bda13f79ef0afeaec09dd679a6e5ea58f87ba6576269f836096d5ac034594b17073331
|
||||
NONCE: 3fb1664830821e2b524890c8
|
||||
IN: bd75c313f5c8f6007a2185bc39d0af01bb
|
||||
AD: 50744ed959e2b8ba5b5f4807e2997ea0b96ebfcdeaa1c6b33853219844592e82ad67abf6ccbb272cfdba6a3e45c07fec4d4a0ebe4235f11d916771a764d9a129d39f6b84f0b5fb4cdf789ca2f5ea306b25d047a9b1a1e2e90905b6fba472e70b2fa25c96602cfa0031f31c68954d7487507081b8e70f8aa1342cb8b4a98ce9c2
|
||||
CT: abe3869ac43fd8b429ee8b8539c970bc86
|
||||
TAG: 33fcd301c2bf624bccb92a986c2dd5f2ecafc32649ff550eb5312fc81cbce46e
|
||||
|
||||
KEY: 353c3e9f87b40fc0281869c68d9d9bee5c95771dd79998c059bc5ceda71f139fe447cfdf340e9eac57f232b9d230e45d
|
||||
NONCE: cc7a4b46b02f4e7f96fd34e3
|
||||
IN: 44bcb61332930f606276268ddbf3287bcaedb5b25704489cbee63ec839d7a69533dbfb6e95fe5b4694eb485beb1437f0777774868ecf45c8a5b3edafa1d62a
|
||||
AD:
|
||||
CT: d038d67b8b690519fafa7467c9fb94135f9bf0bcd8247cd2c30da62ddf37a6d9a3a9bdcf8ec081fb4469c0fc2798e2e30afede7cda384438fd01e5d672dcb8
|
||||
TAG: db2c685a59cdf304c1fb57b66966a5ca1cc3536fe21eb1113c25868428640c7d
|
||||
|
||||
KEY: 3b3786e38e110ec0c8b05fbdb3d9b6d117d1ebcdc0e7d942249fea6baafa31fe5caac227979fc833b104641e8e9ed01e
|
||||
NONCE: 53bf31912a3ededc01c91f84
|
||||
IN: 6de5890028382aafb186042864c5cca1a77ff80ba4f7f0942dcffa1579711093fb652c8d475dfca81a976be8ca77eb9c7a6b49dca1425610c945bf404ba65b
|
||||
AD: a9
|
||||
CT: 886939354fa117139f5e077baa186825ee7e2955c3a74f88af3a86b260ee9f9959a90409e7d602e36cea31e606aeaa8b9229e28f7fa58ace6fd217e5cce1e7
|
||||
TAG: 91a769003ec900dbb40ea9c9b959882d822421b510ba85ca826bc4af3b5c42e0
|
||||
|
||||
KEY: 5a75c97f3583983bbc5eee4a882b766a6708d798a46f71e63b7509af69afd7cf86f9b42df04b626940914007078a8b9b
|
||||
NONCE: 426e8bcbcffb6b425706dae0
|
||||
IN: c24fa29a66197cad518c5a1a76abd9446a8f24c2dd81e953bfc5c00544c119d67986781a1c754224af234b0ec5e44e78610a4420eb78c283e9a56637c35c24
|
||||
AD: 6376835513967e4ccaff9a0c56b4d27a2bd0d013cd54abf95fe9a162d036af285ebc9567a16ed5abfa69aa
|
||||
CT: bc4daeef3ccdf9abdaa75591781685eee3fd7825bfe63132817a7e0f93817f22bfca30ed775a773f5bb290aac3a381a01085e861cab7b9fe4c5143138e17a5
|
||||
TAG: 79c779bfcb974ad9a8ac88dce5027df5691a3a1163a5d5893b4cdb1663b17aa1
|
||||
|
||||
KEY: d1b301c029fe3b81e4b97e08e84dbc03b138f422161c0e74ccbda3172c034b99610f09a9e611f0e9a3ca40af4fcb3c56
|
||||
NONCE: 4032c79eb3ee4b63e44fa932
|
||||
IN: 71bcf5a5198787b85a66221c22e7bdb9d038dd3e10000555ec9271e54bfefc460ef4e71729ff7ae52859015b49f45df89ddf183fe1e19de3acb032dbaa4d57
|
||||
AD: f1cd18ff1e5ad2b65de41e083b5175966625ebebb3031e1027761e407dae4e8e193ffe7dea52ff61147f1b4e
|
||||
CT: 7c521a703b7d1cbd086bdc316d4f2ff0852c462eeaa1d7a586c561354be9ed412d9d9bd1f78cc85468750f1af09b7b17dc1ee84c926760d63504cd3a1dfa3a
|
||||
TAG: 831f3552890d997f0a8f2d832b6e92e26f6e865424699f0364a82d86ab7734d0
|
||||
|
||||
KEY: fdd24bf37b36666a4f641115581ab4bd6b896dd3017006031b3675beed33f21a314363e3a07bbbf4359d9ac02eec847f
|
||||
NONCE: 7767cff1a096a9f7d8a9b32c
|
||||
IN: e62b7695dd41baf49d1b356e64c6d5504784380b75724b86f5f3185d1a530664aea0e5f9aeef347e1ea4754acaa7f3c233638db234c0e93db02e0bf988e7ab
|
||||
AD: 2d650f3daed2564b0df86fa23ed0343634663adfae2c422f80f9d5674bbb63e824f01ad3994834f889133bbc0e
|
||||
CT: a51f50a6ce77a22ec472bc18c37d08fb28e77efe55065b600e3edbd9ac97f0fd0eec93cd312ec7ef886cb04e1849526f0a38b14d862bcd578b99bf9a007c2e
|
||||
TAG: 89d83264364c9c84ba705e5549abcd496abed3900f65e3daa012275fed18a7da
|
||||
|
||||
KEY: 0f88e2d00d2c4bd682f1591ea5f4c1a1090180e1195809cb363b27c863360a85b27814e6a724effa44f298430d6c9628
|
||||
NONCE: 6e2e62ecb2aa47c7e5921d25
|
||||
IN: 91efc710a57adb57017725cfa26d17d3e2993c5ee66942ca42e770a83763e9df8a455bd408dc1e2661cf301f1dd669cd6d5b4d92a886be0f54527779bae8f9
|
||||
AD: d060cbe84271e85f25a3dcb6dbf299551f0dcd5783e3df80468636e491c0100f3ec8316f24240482a88bc430a398b0ecaee5c48a274ffb2d835e200bc39ec0aa86a1c90c9e2dcb4217595d48826a81de90eb949846a33fc26bf8886ca0554e1b8f12cbeee36e65e33cbbf610c2d24264619fa93c44c88e0e3d9d368fdece461b
|
||||
CT: 10d99b98ed67d85a44fa57e706a8b028c61ef17f35f6713613d158cad90e826f90ef036a2190ba123f9b68b352ca94fbebf8ea947e569ad45f00e6a36975f8
|
||||
TAG: e345bebcc4a8ac01528bc5f317e5c378236b292c2baab6ae8654245da35d90d6
|
||||
|
||||
KEY: 1ccec52c77239bdf6ca50e5b702943b23015d08cb1d9bac592b3dec4c96be904110713e52e114a8bc294df26530a758a
|
||||
NONCE: 38554b7c40027afe9721e14a
|
||||
IN: dac91fcdb3768df8d5ae9ddba1fe5917c084a5d9e6b14eee9a609cab2da34ec9f95cf2d10fff77108477e694c76f362e29b9a9287d8b190a748ed0a929967ff8
|
||||
AD:
|
||||
CT: e6bcb38b3bfd0b428a14bb3aca01a4a9e54b0853f10bd7750f5bb58d0e7dd18006f8929d7d862e5d6601ef63be8442334b4d51a99219cfedaa31f7ab19028459
|
||||
TAG: c4f05d9415840c2325dabbcd12dbeda31e47637437514c606dedfb8ce622edd0
|
||||
|
||||
KEY: c82ad4c6f248bc51d3a51b958ecc2460a3c64d669f6c485c2309d26abb3fa84644a0d8c28da8091f90184b53cd556413
|
||||
NONCE: 35a29938fb7a31225b08d0e4
|
||||
IN: bb0045cec5587e50b148b140b6969612425243ed1412e812aa9f4b471ed34ced6dfa9e0acf3e31455893e4ee7e66b4661c6e1f80b7d6f1159c11387ce579b80f
|
||||
AD: 12
|
||||
CT: 5f1854fc2fb11fd721755445a1efa5a28607a725ad71cda9a3464860a6a0efe3f58727c0e0cd315f867611232abd72034dfc2b9deace8cf6cb507b1cd4032b59
|
||||
TAG: e40429ca19a88da73a7654d7ed8e0621ac2e504b0245615e262ac70bd05a3f47
|
||||
|
||||
KEY: b01bec74fe97e5af7db2a0b1432f8b4c069447d2b56dc2668371387f753b03465412213999d2394a4b79873db06c590a
|
||||
NONCE: fec7de97d54dec8d36c9f253
|
||||
IN: 88ab078d03ffacd128edbceea7ace2e6465f4076097445a5db7f0e61ed817b6e24f22874489049bee0c58d0aa2b42b4db0bbef6ec88d032da9c82ebef57c424d
|
||||
AD: cf0ceb3e80a76d1a75f6e070f5d3fee1cd1e2699434f96e7cb3adce12d4a3148dd433b08c68b9d66962f24
|
||||
CT: 8aa3c7478b0cd86fa30870957fb5307345f89346a869d508da9d3a4fe36fb3d6a9b0c3c1bc2d44c8ea31ec028012098d6032085af0b54603dc2fa65ff091fdd6
|
||||
TAG: acb670172ec3754064b366566bdccf5056eae132e2041f1a285c5883e7eff4f3
|
||||
|
||||
KEY: 699a94f6e6eb457b186af58c25118fcea81c8f0ad265e7c16bd6cdca15c9db64bb9a537580ca0474a4b4d54d47412d88
|
||||
NONCE: ac3fb6525f4357d831529407
|
||||
IN: a7300aa94f3d357cdb272f0a739979e08aad9551dd3bfcd0b5aca6a0972a71b502639e79e1b9e0d22db2f3220b982800d9cebbac3d10d9bf86ea25d3d417fc57
|
||||
AD: 19c3d34bb9d57d0f63f14bdd3da06a43a5afe6a8c505f038cb403515876a2765c2d61aa7e4c84e11c999b81d
|
||||
CT: 8b472f1069ace78172611369b03073f751e5206dcd2ce3b45c431095f303e70c59bfad3af8006e66e4a68f8fa2ffa534bd76bdef089d07dd38988cbf723393c6
|
||||
TAG: 8e7c3c2c41b1117928ca1cd0cd48c25c319c18e009804c007d1aab0967c0d0d4
|
||||
|
||||
KEY: f3a7b8c2a39531d5fb3c97bc9224168aa835973f48243d6f046d00937ed428e5d672e22af26e734f0c24f989fe62621a
|
||||
NONCE: 65c61af60769672f0eeda005
|
||||
IN: 59667fceb2594e002c844a47d2b3935d2c99570b1639f0887fb082499e1d36f9699ff9ef53be3b4236136aa9e441abdc63dfe536e6fc9fa8f332baa1dad577ad
|
||||
AD: f79036742501f1ac19dbb2984e09cf5000bc4bc0424082376c307b8f1e5bf74dd29c802139d7ea93d55d336464
|
||||
CT: 9375a81f016c2dc59a8e99dc33fc0db7ef99ab2f9ade4b0ba000a614ff2bd13bfbee2d4a2338109c98c1147edca6023cea43570adc503da98379326ace89d796
|
||||
TAG: f563869420699dfa0aa84751526bd75af1473bd88311001e49230b09b8ef2797
|
||||
|
||||
KEY: 27611a8f11cb57d08648ec816b5f3c45882dae394200cdfc803d1a52bb03f225206574ea63b63423da6972bf5a994332
|
||||
NONCE: a7f617fe7a52dd76ee443dff
|
||||
IN: d6ccb950515a4a2de7c3cf5a73b568f32fe30567bb22b3b46feb7ef07205d3215a3d689b96d4b9dbaac5a5bd6ecac6ba50314b19b37179fff2557c869950e162
|
||||
AD: 777282a98b2f262ed9456fed3610a2028bcc4433eb8f028597d3bfa220bdb0c04882de03a276d0191cd1a125270ce1630c1b94e2ec0021ce5c494d2e0bdb8745e6e94a387cbb31a0898965174bcff8bba105f94dbf080059b49dee71c3194fefe679ef6c00065154ea809293b088c0c3f2ed7824aac72319a4c4ad85ea990844
|
||||
CT: 41eacc31aa3c3a282ae7638d48fc7541d2f129e4cb3455df7e60259be9a814c8e1642ea826ac1ec7ed1fcc216a6624e79845521e7a8b16702566f27f7a7f3317
|
||||
TAG: b959992feb7005410f9ea6963525e3d9244f038731ffab8da8c4ebc72489f17a
|
||||
|
||||
KEY: 0d9322713cd132c339c38ec7a75862860de304c70486b89b0f587095c66bfd1abe56f0b34f9ca0dac577fd4262616600
|
||||
NONCE: 3298d02dd4eb85a98cb935e3
|
||||
IN: 5dfedb1d168fe262d35f78d797560b2634f71d40f438c21cdcb8e73cf9884c11570554f55a6abd23d0e7775a9ab385ae6c9bbd67f08d1aec57347a8fad5a4b8c7b042b03c25facbffc76f0b1ce2e6c07d427eaebe71255d661ac8e8bfe8867e2d947d496ce2318a601d0beed02426311ca678d036deb3b4c65b1f89bd644a410
|
||||
AD:
|
||||
CT: ff09fe27f12a87d5208bf246378ee0740e848262442b8b9c7670c8a73fe6732192cde43c1a1246743ed49e15ec63c87dc06eb3e0c92c1f286108b2c7e0754dcf1b9c3fc87efe3683289daabf2db71d8742061f93098788c3c6f26328b86e358507a03af296d2c29009562cad3763399e0e2b89ed440f756c16214c8ab7ddfb84
|
||||
TAG: 5076c80fc76c67d6e4f9b9d470cc184db62ea7da49cae44cb3ce9e46c2f2ca9e
|
||||
|
||||
KEY: 2695671fe86f1658d8b01ec856fb4c9d09a0c51a1b994fc87a3f72bec12052537b7429f11f7eb4aef0b128302ec8f336
|
||||
NONCE: 9739e577595418c47b9c10b7
|
||||
IN: c723c39be334a0761db795076e81e3dd85e37a57258c7e0e10fe0f48dc31bd5e683430aa70531b7c8e3a904e49bec838e760d07afa9f86b2cf78ae90f612c4560632acb7ea2d89fb1fd5396d0337111c429cdba99c6a52e863e8603aac24a83302ebf86ae69a212cb938e12085cbf73a28f75e4422995a5ec8705b12d4aa8b6d
|
||||
AD: 31
|
||||
CT: 1569b20732ee6395e605217e1cb419ce57496ba6f6e889bdfa3c93575e969eb7a0410c7930b7ea146e88577376d84f0e824b62890eb84bfe768a1513a12c2958ad1835bc1eabe602cf40f7812c7dd7da955567242cd7512090fca685fdd7306bd98a908b09464961114abbdcd610c153637400a1f81825cfdf06505947fe54ee
|
||||
TAG: d07e14a62a32ef1933abc2127cc5bfc1e43bbca663e460409c6faa3a4ccf99f3
|
||||
|
||||
KEY: 1785ef6e7016733dd1952b3268639f231e7afa973c0a3db8780b81084c67a1783200149a1ed849ca8b5c14c7b1798b4b
|
||||
NONCE: cdf48b73c3c8d8625e52fe11
|
||||
IN: 14002f17e056d7f5524537cee6c2061e2741c01a6f9a82e2cb1747887875860d51bebf8d9b63950a051f6b228ad7567227f8a45b9fa7c4ab47eab410125303defa7e3141bd9bc5bf4ed56550801ff3bfc2dfaaf499c192b1e18879b2f59e1230778132818df8f6ad8a3dce9a1d11c98075b8b4e560edd9b5ea180f0424ab3706
|
||||
AD: a35e86e22e9a3df65e4c08e5175b4216fa9895a1be6252de911cf98349841494617eefaa007759dad7f337
|
||||
CT: 99eae989435578cb57715a7457da31b807b8078a59c2332a0a866eee9da5188baed3f517b6808095f0067e9b4b91cc1424a464f0a09fc946adbe4135a17b0e8e545d2046f81cdfdb233aa3520797319c0884ccbade8235c32d195e7b802017f88ddd86fb630de19eb97f4bf91029c001fc8f1cd2189a8ee6c120e9f1682a8703
|
||||
TAG: 1848f0b163e7b0d270e2a0ced288ea6525697170aae15038f3dcbb4ea49ef843
|
||||
|
||||
KEY: ba9aed2bfa90eaed9b27a697bb44c715c0209cae6b2c4ddffc684bcf07ab51b0e096dbcfa26c18fc24b63408317da567
|
||||
NONCE: 4b850d6bfa64520f1aa1e79e
|
||||
IN: 5bcc2ea4d729c84340c5ceb827f239578971c595e915f0bd9d49ed51d723f8d0e8362e69fd11466230bda0dad57ad724307edcc621ebde1e57fa91fee206d81d2bb6ead94b4a804f74b6cae979f66bdfa4ad93d107ccf114c59cd3d261aa6e2fc0dfbd0df5f7c18e80d0699cc1712abbefab5029e35549d2919d0f937d444051
|
||||
AD: f80c759062e9ed0ee597406aedbcda9a14261d66a9546f1c939d20cb1d0d0974fe7a9b33d8c93287a6a8d60a
|
||||
CT: dae4fc873d302c51e55910e67482bb80ac68e9bc6ef77cb3e57a31d85fe75f9071d0b64026ba16d0b68fa9c0b7e958cf7682bcd329c4174ea0e3f3f9d2e65d82aae1350a53ea7cdcf9ab848b85cd731751f0e2917628e5066f5b1ddebc7dbda5d2d37e46a7a7ee62bb49c4431af730f9cd3da4c1d0e5f8593d8c99803f781bee
|
||||
TAG: 58b42e9117fc8cc2ba5cff74b0d92e8b381a444fa837018b15e9514fc4319fb4
|
||||
|
||||
KEY: 37235623acb0d650f905f106dc3bfe6fd83192e53056de8795ed8d20c6e58e5efd84584007ecb17de9e76b392e12fcd7
|
||||
NONCE: dc441f1c743a92c4b975c6b6
|
||||
IN: 960ceb8d80774bd88b7c5f17042ad2e4baac71b4021c548458cffcd9a049291cb0df93076c115b54f9af878745acebc6e8f04666d053b1ed980728043c4fe7f67b2bcb0341d8a4973ed126342f9add14279f8402cbbffcecfc847379dca8a68ba4f2f26141acfca7f3ef558dbaf04629f0f46e43246b19d875be452f14e7bf56
|
||||
AD: 32579218062560f15ff966932838460f99099782e79f1f8c41cd9f6eb59b4c2c3d2dae9cd199fe66d74c7a9940
|
||||
CT: 49ad8e24a31e90ab1f8dc37dc51dff0f93f1420e79eb108f90f800274a5aa573f64e274cd52f1dbfdee363e4f86e1457bfb8f87ce57aefd34c3a5a3a93db4ebde3f73a3b4c202c993903ab378ae71042ad238e94f400c7ac1891a9890b19d445eb1db60773a3ea165f7c4b2bb2071faaf588daebac7ce09ebfc88f4d9232d9ca
|
||||
TAG: 82f908b837a5768598982f860ecea16aee84427371c4de1f1314749b70ffc173
|
||||
|
||||
KEY: e7fc36c9fe87a38f9bb4ca67723267e80e16bf39740eb1090234a473d68aed9c96fe2f96e539795eb042276aec5d7505
|
||||
NONCE: 83d768746d40dcd695e49ff4
|
||||
IN: e61f0e02a70249b62ec9a8fdbaf6622c9c6316599daff421f1b19815707b67587d196b7e1452c7d7609f108ea946675ac5d97ed215b92a451aa6a11717ab7819f84848151007f37e2cdc8aa99969c3d5652aeeb65fc21b621865f47f44eb2c528ee1142d11f513761a6bb2d169126503db5b263a410cadd2773ff931a032a885
|
||||
AD: 59114e9f21b380ae6068609ac36688e6aa7c2533cbfe07013ad1b6663bfa42e39f20e62b45c0faa256c1d33caa9f59b1e30d8502bb7148d051451b3d0265cb9fd0d82e4f4e0489ac606956762d8e7b70abd7eca413ddb708f119c342b3d0d5df673769d8df281656d909b68b6f6438edd60339fd84ff69918b6036ad12a0a588
|
||||
CT: 4f12807736c9ab32a2be2e00c9a0236394a8bcfcec6037e7582af462a73bf10aa73bd90e2bc24b97f7001ccf653574aea294bc7b30b77540f475e0e846ab78ffcfa1fef28058e540fea43d9017d4efa05c837611b2eacf0034f26cb7903eff7874973c6da7843892bfc676170a75f839e297dc7f04c74b40f4bda20a45b2a352
|
||||
TAG: 9b05aab44ba4d1451f14e087be626232ed11c4ed04081f0d4d47ab593fc619b1
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
KEY: a5060fecb0a738d8ff6dd50009a757c6e58db73228534d03f32c26baa1c209f402c3e03a6947c1d9421d63ce43f6df26d30ce783f5ed0d6b88edd389d9f92d8d
|
||||
NONCE: b52227e92203630a79ec7f5c
|
||||
IN:
|
||||
AD:
|
||||
CT:
|
||||
TAG: e61a28f5df7061b4236834d2034d2b62cb63c660b7de696c26b345e66b34d222
|
||||
|
||||
KEY: d676047046bd5be9263ae39caaa0f688abb1bc67c083658894da6aeeff80b6d58ffc7ca1a1c88f49e629bf5544b2cc7669367202b158fce83fc4a4826dd90a7c
|
||||
NONCE: eabef87a00fd99ebb6ed6d25
|
||||
IN:
|
||||
AD: 83
|
||||
CT:
|
||||
TAG: 473cf728899cd5fdd54f18d6f934c3901f7ca118fc5ab2cbb837feefa7852a67
|
||||
|
||||
KEY: 5eaef3b8e068fbb652bd37df4dfad6490095642cd49761a35476dffc2b5b5f75236d0351d96a9028660788893323a777ea8a2ac88bb5e500b334af02b1c2a648
|
||||
NONCE: 34d049342b9db5ffa039eac0
|
||||
IN:
|
||||
AD: 7578949699d44dec9188a7f7e14b0a23637cddb9107dbb1f8e2a968aad0443356d7eeceff4316ba7b2e8fe
|
||||
CT:
|
||||
TAG: 4d2612c21357638bada9290d2a272f10fb5f070337bf87bae396a1e7253633ae
|
||||
|
||||
KEY: eb7b3d7eeb5f26010915a36837dc83da2bad07eba714566584bf1ce62fa9b61210b0ead7182bc28c8f0427699bf04786583fa32f3c3a8a6582cdc254930043bc
|
||||
NONCE: 3bee5ebcdfc72f4ab0023211
|
||||
IN:
|
||||
AD: efecb57e79a326c6b2ce0ae74d7656992a005fbb8da5a55b9595fc5348a5489ee2e69541ec0e8a727a560625
|
||||
CT:
|
||||
TAG: f457db1e274adabe5fc898fb1eb7c4a5a8e9a2b66f964d0958aa058c1f9e15ba
|
||||
|
||||
KEY: 1c1abffa8a2667a8c1ab347860528162d316d58e3966050dc140fd360e6ff7c557520a8982aae97c5db5495d8951eaa485e1cac4cd8f448a13d071d759885474
|
||||
NONCE: 4fdce4e59bfdf5d9b57c78e9
|
||||
IN:
|
||||
AD: 55125cefc919379b3b4b2a24ee1794f44ac66fd99b8b68f98d4abd45ba50a5b76e5375d08abe3b8b8d3c576bc8
|
||||
CT:
|
||||
TAG: c021d2c73737e54ac6e7f61f9bb44818e5bdbf8d81d43842fd25a535790fafba
|
||||
|
||||
KEY: 366cf53bc185473acf62610b74231e53aace84e9c5d6fbf71fc24db4f42956065d3eec01ecc72a6c89266565ff530075f4532c860e3192e866b41aee98c5c42a
|
||||
NONCE: 9ff54bd7b10f4fdfd8db76c7
|
||||
IN:
|
||||
AD: 853ef59ae873bf0bfe1465e9dd8c2cddfcf123d213ba4f599d984e4ea69d3c85a23508ec7941ca740a9157ca2a788e9b519291240b307d6c5a8c6860a96b4be698659d19e31ab0ac7ae6ba31dcd609c1db67ad580fe4422e42d368c3e93a56f2a087b0d587188462310c2ebe58ecfcf7178412223808eeb2eda76446168730fe
|
||||
CT:
|
||||
TAG: 12d869dc4bd4ac4ce9ed643cccda9e11a1ade65c76f7c1535fa4ec2bcc5eb4c3
|
||||
|
||||
KEY: 147b41369bed390f0a9561586fd975474e3b3bbf7f7ebb7a35e5cc43b516c044dce93e154ac790a109709ac5299bb17b709a913d33fd57ebfef2b48ed66393b3
|
||||
NONCE: 85b81732d2863b41d2551763
|
||||
IN: 73
|
||||
AD:
|
||||
CT: bc
|
||||
TAG: 47fd81f6eed8d3c66afe06d788ffe40717847785f4b4c617d75a11171690a60c
|
||||
|
||||
KEY: 9bf35c1194659c1da634eab6707c55b853c8f61d087187162e926adbae02f8bd4d15bae5b05865d0e2236d64715fc39f32e4e3679a0309396c37eab13d1c637b
|
||||
NONCE: 8da14a98ee741a5fce0de732
|
||||
IN: 10
|
||||
AD: 8e
|
||||
CT: 17
|
||||
TAG: b76af41002a946af4947f98f42a873b7da0871f482990a70bda8f005274ca179
|
||||
|
||||
KEY: 0befac10caec674c9f23676d121f065dbcc8c91852dd5eb4e80c41076995a2138077592fec665954d21fd6787234d32d3d54bf9c220cf2bf018b374bde29926e
|
||||
NONCE: a96bfb49f3a136840a0e32ff
|
||||
IN: 59
|
||||
AD: 236adab55e1bb8a8db384c01bb2afd30ff35da71f955fb217b8305a45ee075e7f8d863d4c0e5dbe36e297c
|
||||
CT: ac
|
||||
TAG: 7bb634357e0835b02a0642352a834ff6598c2ded1af8e8ab60b9ef0641fe863d
|
||||
|
||||
KEY: acc672aecf6f10119ee77070abbc2b4fade7e910efd1f93a5716161f88606469a49df05b40332b390d3ac289abfdf6bf7c37c033b1671082922d939139de0d42
|
||||
NONCE: af0f57b55f1a73794b3ce5cc
|
||||
IN: ee
|
||||
AD: f385a50ef027e532635878a4df0deb23369774be47c42f17cbd44925b668f628338ea5f8256c5ad8219c13cf
|
||||
CT: 71
|
||||
TAG: 13a5296075ef23216c2f2e83b940d24e8e1e6a01967af96599360f11499ac0a6
|
||||
|
||||
KEY: 6195ef5ce3ee01188c48b04ce7a28b3ddd04b78711a6d1233121fc8ec3db3a7a0e496d1b6a416675b1e666b9a3df167efb8ade29e4f22fc77111f32ba8bd1ec2
|
||||
NONCE: 092070b2f8b65fcfe646f6bc
|
||||
IN: 26
|
||||
AD: 98526dba4437d88f657c0b7ce2a2be44ef4951711a40747a7d14b195e4c0eae97247256bba7dbd93d6a8f738c1
|
||||
CT: 83
|
||||
TAG: b6aad3f91a26a38245031d6a7eb97be0d386939d4536b2a27c90a2ddb891de73
|
||||
|
||||
KEY: 40335487f9958dfc00b76ff06dfec162ae5c6be4e26918bd12e3f21760cb0bd364521a11f5bfae11dee989627525ab5295ee404bce476c280d13d238dea1bd40
|
||||
NONCE: ecf77c7c827a34efd8cdf79d
|
||||
IN: 34
|
||||
AD: f6e661254bf235c7d5b8ee330cb754087480dec5fe4c31dee65d1ab4479642101404bb563522937fb2e41d3aa8a4d269a222e6e0bcfd07ec4b29c1185f99fff7cb5bd2ca8c5b38742270e586c8db19138b446833f2ee07a11dae5b6a1a4c28657f3380e84bffe1bafeccad57d9cfea3da7f728119ec5bb18b79e002954f4379c
|
||||
CT: 5c
|
||||
TAG: f3420d4cecae2c1ad79d977abbe408045bd87525c0da2b93e0af3e6c53ba7d74
|
||||
|
||||
KEY: bf32ef44c7ca9851f397e70df736d7e0e6243cfd875ebb81d76ad7612dbcfd084cab6b0d67c6a6e8b567c93fd0c3abb78ae121fdb3051a62ccfa045692d3453c
|
||||
NONCE: 46e0cc64d6e431c1efc2bd2d
|
||||
IN: 959348a8ad6912d7d6c8eae52f19b1
|
||||
AD:
|
||||
CT: 55e8cb6fd958f18b3c19451c5c79a7
|
||||
TAG: af09194071cb0ed4488d27e79700f938ce77386e5d772f9853b17b719f2b1ebc
|
||||
|
||||
KEY: a6b5b8b051edf5cea0353ead88ea887fab048ef32f8303275e93d8f926da0d4b0e34b9447cf44fa70c24c9ab964380065398336bbb20be167fc6cd5e591ef50e
|
||||
NONCE: 371363612c4675a2e59ebd39
|
||||
IN: 443d16621b0cf9a12552216f9558ca
|
||||
AD: 32
|
||||
CT: b7f432eeda8e4b8a25f0445f17ca7c
|
||||
TAG: 649934922826febab4d59dfb52a7558e6d30d56e273602b98f3c55fd8e24f4da
|
||||
|
||||
KEY: 075b75434269a3fcc57922ee8cc55b5bbe1b90516a3b71838ade73d41ed1d1f33ae1e0e86f88f6ed7e091cae3ccb05144b3ef239831554d6e79ff97c4d8f150e
|
||||
NONCE: 754d5c4ccbfb291133859de3
|
||||
IN: 62a151add825077c59459fbf82b708
|
||||
AD: c8db27487de71124a95eb6359270a8363908159200333b46ee74e2709b308878779686bd43c24e9ecabfc3
|
||||
CT: 2ffb9a9f65c9fe3daad13768ab56bf
|
||||
TAG: 4430a90fed7d4b5b2adf5a60d6854956be4feef497781ac7d864a04259e99516
|
||||
|
||||
KEY: e787fdeca1095f2f2760a1c5e0f302e07d6b08de39ce31fe6a0db2f76e4626eb0968768ae04d37082c114573c307699707630b8c7ceef60abe3b7831d2adcd6e
|
||||
NONCE: 9dc9bcfe8b4e2ea059e349bb
|
||||
IN: 3ad57105144e544f95b82d485f80bb
|
||||
AD: 96bce5dcaf4a90f6638a7e30cfd840a1e8dbc60cb70ab9592803f8799f909cafe71a83c2d884e1e289cc61e7
|
||||
CT: e504109cdbf57b0e8a87080379e00d
|
||||
TAG: 1798a64b5261761ecd88f36eaf7f86ed3db62100aed20dc6e337bc93c459487e
|
||||
|
||||
KEY: b43ab650bdd201cf05e0436afe89ac54867383f04c5ed2faea5db8e6784c720d905234f1f5443c550ca14edd8d697fa2d9e288aa58c9a337b30e6d41cfa56545
|
||||
NONCE: 4e3dd3efe527902b9de45a5f
|
||||
IN: e386663e249b241fb8249cfec33ac2
|
||||
AD: 3cf7a396e1bd034ea77a54ffca789f206f94263d90d98bf3e69cb42205fc5c95cfbd0481b0ec490ea447299159
|
||||
CT: 94aacf00092723e778d25ba78e9d27
|
||||
TAG: bd5fcf90b9532e7abfa858aed90d5170f08edcdd28ff2c673e0ab45b8c0a0f39
|
||||
|
||||
KEY: b22a7c5bb38715025cd59cc0feed9ad8e51101200000168052b294fb1ead545a517dee636a7acd22b8283afb33d30adbe02c1c8557715eea7147f3d98a97cbb9
|
||||
NONCE: 3b4244c9ad9fedd3f10fdf7a
|
||||
IN: da79e1ed131856cec3250fde7bda4b
|
||||
AD: 4b77472ade3f06500169405b86a793d63cfa58f57bde0dd706f369b391142c2fa8a3e6345ccf0a9c29b2182f578e22f55c576f155a05be5e81997fbe06410034ecddd871e5ed94b5eeffc6dbd90a8e66449da01f8ef47d28a4a4bd253ffc427f868867c73b5c709b01732bd8035b1a23ff0a903def1eb136fc90d8b3c8279769
|
||||
CT: 5d8ad7abc047bfdf9d9cd0b0aaa53e
|
||||
TAG: 41d050d518d0e51ce16bc2920aa6c76eb8eabd4ed76373c59618c6354885f47a
|
||||
|
||||
KEY: 04b3fd8126d65f851f47b3dea22cd6e32506f21effaa3e29820ac7825e01b51c5a2816f0298154f2d8addefa2fdc34c0635d4d6b80ad23eb320c4d4f2aa1de1c
|
||||
NONCE: fae1b1da40471dbdcec64d4e
|
||||
IN: 509f116ef7435b0640cf141d5b958aaf
|
||||
AD:
|
||||
CT: ecf553eba80e6dd1fae2eab24d772a89
|
||||
TAG: 11473566e80cff5d7421f65949c34301f34de378e91ad50928cf2caeadc466d4
|
||||
|
||||
KEY: 413d154dadc7d8869e9e0f24b3320019a04b7a37620dd9e7aa40b5c08d70dea03c12ccf7faad7009e972680e81544b647650c6ff033f56e5bcdac9a35bd7f804
|
||||
NONCE: 6a4404adae3f4a7bd2bef95c
|
||||
IN: 3539fe02b75981fad4f8762772b3c11f
|
||||
AD: eb
|
||||
CT: 3f8a96905609a4ef1a95fdb87337503d
|
||||
TAG: 8ee076fd624d90e1f6336a92165e80408ca6f0e165b201547d351177c95e8d51
|
||||
|
||||
KEY: ddc10df673e720c00f28fdfb69f1b8fba99696f23b6f29704a0114444cc0c8a6c8606e8d37fa95aabfd65b29c655678fcec50966c8758a3fb15332a1854a8eac
|
||||
NONCE: 06331613842b4af86c13f8a2
|
||||
IN: 55d74bcfc3d1cfc716c6e6b7153c6369
|
||||
AD: acc264344ae79959f9dd5130664273ba6f345c3fc7bc33c6c1ce33312bfbd5f181a3c7a24f15e7acf72ccf
|
||||
CT: 20650d9e846eb42854692d438b21d5e8
|
||||
TAG: 973857523e7ff600cf9bcfcc98403b34ab38d939a6d76716beac42678ca5f5bd
|
||||
|
||||
KEY: be0c884db54cf761fc24ff3dd572362910dedacece5e1d93a916df277f923f78e7dcd908e60beb0043503c5b4877a9d962a7de37cacc7387a7553949b52894ec
|
||||
NONCE: 3f027a93e2716668c7634195
|
||||
IN: 1ba8f3a87ac6738167aac1491b602ddd
|
||||
AD: d06dd1b9360a68afa3de5d239b6d91d212c5c555567545a4f133bf5a3b0f26addb9379e1cc1cd690cd427c57
|
||||
CT: 3596cc50ae72db932dd83bbc8661641d
|
||||
TAG: 44a1834b1587d0f88e34137dcebbca059dfb8f65ddab18f338a8a30152167be0
|
||||
|
||||
KEY: 2ee848726730c64332877a4f88ad7fb241a73b71fbee8eeb4d9d6485855ea32b487e03968e1a7b9e8ac8ab7fbd84257efbce0aa207aeefa67302d5847e0d9c05
|
||||
NONCE: 526b0a79b6359d133ad51011
|
||||
IN: a0c0477e8a9ebfd275b674ed33230d42
|
||||
AD: ded2f0f3f28aea28b17aa58d4b906c6a9b3078f97ffe95b7e161b0c3dbf66879bea7603a046da4945c802ac8b3
|
||||
CT: b1691c8275f12f7d9af85e71dde9dd5d
|
||||
TAG: 65a5742dcbc49295c4805387e0a15f986ae47e51add9389dfabb6468a6e83013
|
||||
|
||||
KEY: f4a7c0e29ff510c034778e47bb30a468a92140a707936d381b1554d421af107c578e74c53ea08c7f7d93cf67612061359ae458408a9c79250f776ca4192016c0
|
||||
NONCE: 025bc10dc99346c4d0766a7d
|
||||
IN: d449a2e812429beb5c466d344f5b5eec
|
||||
AD: 304dbf9a59bfd33b777d8dec9dddce4c365e72aed851210eb964c1da18119bd13248266a67408e88ac2eadfc54def0fb57f23743d376b11293377565d253d2bffe0309f2946cb78d4e9536dde4691fe1eef9ce2dc916a773d06b42fe2b014e7974d4aeffce25a0902c9b44265e5d6d26809b5f24875e80cc13f1f8872b04a237
|
||||
CT: f366e7b66683f52586e1c363c15b7fb1
|
||||
TAG: e0e1bb733471f150ddce1b83f3fc2d88589d286ca052574b7f0735bb598362d2
|
||||
|
||||
KEY: eb78ea626b219e12937057155884547cb7578718f569dc8f2b370c0fea80e7f0d0f5cb590f0b7341d20c775bcd6a3c818e23b6cea949cf99eb94a23a81cd2249
|
||||
NONCE: 75a10f16d429b809cf12b9ef
|
||||
IN: 6b0203316e8108ff01b12df91ba6644382
|
||||
AD:
|
||||
CT: 7ee07054f76471115be159259340c24391
|
||||
TAG: ab970669d1603767d588a93cf215673ad307244f9179f46fca56e97f64a5fbac
|
||||
|
||||
KEY: 3221167926be262b7bd0591f56be6bf030365d45ab84a93a94ea41a5e07735b17245ad43787e8791e7ceaa0472b562ed17e3b609c66c868c9b08304c8bb328b1
|
||||
NONCE: a94d8417d2bb0323bcfd354d
|
||||
IN: cec81bac7b85c441b6261163d67921eb49
|
||||
AD: dd
|
||||
CT: ddd8860fa9e2e8087db30c9da1ec9f9487
|
||||
TAG: 26a3b9bc4d4cd802cc22e7647a19fc2a5092293c9f5b1c84bdab7245a6d8f4ab
|
||||
|
||||
KEY: 4b16e2d62294f76cd2a6c8e0928279d9de40f0b169ef9465738cbfa064c520128ee89cf657da27e4e532d8c4709d992970bfc9daab2f31b3a67e53200d3d6710
|
||||
NONCE: e746d498b9031007332447f7
|
||||
IN: 16841e3fc1f53990d33f7ba525dab121a0
|
||||
AD: a785917bc9f3aaadfd170abe83bb30c0c5d595fc8b491d983131aeab1a7b8d8771f1a963c251976152dd63
|
||||
CT: 6bcf5eac15ef74cb8a706856f62eb5e8c7
|
||||
TAG: 9dc84b06e8ec8921be4bc7762e8cebb61a95ac5660022520f9438e8f77b45796
|
||||
|
||||
KEY: ff2f5944111226df1d9a300533d3e871694fe15a418b2090265cd8c0111b249dfb7ee86bd9228f7ea5d89d8afcf10bf69942ee4c29bfa8409b63c00c2213629e
|
||||
NONCE: 477060f0c61555873bbeb225
|
||||
IN: f091891c43e2374c2755a88a11b04beb4a
|
||||
AD: f1323fd1ac4de9719dc5966dae45dd7b8ddbee3f8da4f4f4d5f25d06bdb8ebf57328dde76d0bdb9bdc5f6b12
|
||||
CT: e0d96f6f3ed0493a289d4c3b79238b9ed6
|
||||
TAG: 71276c05b52bab0063108dbf4e8ff57cf3e15079055a309d725f14bb86671ce1
|
||||
|
||||
KEY: 1ce841bcf2ad8accc458a2d94774c3aa53a99e7dbec587376212101303ca2b42272a23fe28514be190b82e503e7772a3713800f4360fdb767e85ea5e1f7b8eca
|
||||
NONCE: a2f8afc5ceb5382882907630
|
||||
IN: 620fece1e843d1d0b5c5a541a6f615a81d
|
||||
AD: ded910647464d0fbb0a5d93ffb9839de3360c675179c5991ad3470285d79071436025111153628c563ad1b595e
|
||||
CT: 34431c3422e009373c50f3ee6c5b3fcc2d
|
||||
TAG: 6e4e8a3967307f47e233a36ce05a4826a698fada2ac19543bab7c9ac4f79451b
|
||||
|
||||
KEY: 6bafd28a32690851fda667eb2d3c5993f13df52b2e97630527f26c498fd5019f26177a78f27c0c41616d2a4a73757fcaf9cd92a7da8498f90315d41e7479d90a
|
||||
NONCE: 75166c506c8e1d10da4da8b9
|
||||
IN: 697bea4d6eed5e6ed243cf01cc79bfd3a5
|
||||
AD: c0fa663961c3f7e09a8c7bc73e252a232977dd6c9483f02067b34fe695f341d05338ea2002952439ce08295ee5c12f38dafffeb5716908d3f1d4bfbf9eb0e4077bf8e534f19568ed04fca3bbff95da9088cb939f7a20cc97cc0994f9308e184219bf12c8af0d66df436c296ad39832d661b88c98cbb168c751719ac1383c9124
|
||||
CT: 8f37885b9602725385fd9a244ab2a156ea
|
||||
TAG: 7fa5cedd330887900f4a44d098e04d5eca16cf94e21f897fa54b0fc116b711b6
|
||||
|
||||
KEY: 815786c7744d15afe1d6ab452cb6696fead8b88269ba3eb35c458f6248bad77b404acc744ebb74612c4f97deaccb99a7bcc6ad41917d61057c05b30c581dc4a0
|
||||
NONCE: 12342e4704f02336ebfc91df
|
||||
IN: 7f15e696b49ae5104ced5bebbf58a9d8ddcfaf46ddce9df88fe0d58a2f8546feeb83b975c66e4dafddb7fd9d17e80127e70af06b3b8b13c3390f1f50a227e7
|
||||
AD:
|
||||
CT: 22e7c5d54a7b622c47a9edb77cfe7c094e500b0ef9595bc346de736e0088e5934dc07160aea34f24d3ab21440878213d28059551cbfdaa418af40d344674f7
|
||||
TAG: 8c271ea5c15aa771c900388267efb2f435f001c2e83f4ec297e77c608de2d579
|
||||
|
||||
KEY: 66d87d2b18e46257476456a1f87123424477decf196b88b09acfd3ca74bdebef4c98f1b93803098a141e0acc3ce8eede065417a0c1eda9b4614558d2383762b6
|
||||
NONCE: 1ec0ca1d3b09ef186ac4bb1a
|
||||
IN: cbb59e14098c2a8ab7e84ace913515c74e056e0fb272c7b88d0dddfb62e395afb695647d97d1071eb09cc1e1776b609fceaf4e30e92640379bb8f0e762ca9c
|
||||
AD: ec
|
||||
CT: 832804b8003b0ca1b4eff1dc4da6f6a9649e5a582854bb72cd74357476bf38d81ea3bc8ac0463f21fe37683bcbe07360d0ec2d7ab90b588adf669099303ac1
|
||||
TAG: 9fecafc768fca71ffe7d640dbb7a052d97d6c8e2fc86001d71feaf284ab609f0
|
||||
|
||||
KEY: fbff97085351f4500e73190ac139dd3ac91e268042b5926b57e0394c750b10348b47641d195d5fb5b0846256ab229f102538b81e209db5d93b4d55f30c453d9c
|
||||
NONCE: d4868c918de2af7d3e3f57d3
|
||||
IN: 4f14aa5a680d66ae15ce0ce4739888f64d827def862572f9a6cd620badbe4ee9d75f4f9bc1f73d409f519a657f53a50d50e68e22f33a8ef5aa08b1212889e5
|
||||
AD: c41253e96696a948ce500030af27086842aacb79c04cc02a42b858a65c630065a5292bb9b2e69ea5fe5a7a
|
||||
CT: 08596ac0550574e352edc13d7e390d8fd0a57406dd61e1543066b4aa0ea06670f356e26ada0d6c61c1e41de1b4fd7a251c961fae44b23523ce227eec99a338
|
||||
TAG: 72f58de3e6697c8419ef518748fe0bb3cb930907c71b6d682c5e61068206d991
|
||||
|
||||
KEY: c78c550aba82b571d39ce21d6ecf5e5f7c2a7bf921c6162c64ec1fdff4d0b8c41bfcea0e2486cc86b9ed9e9ceb73c4ec228a2ecbcfa0379174e76475cc21ae31
|
||||
NONCE: b5adf4de19980a71cb8ae8e6
|
||||
IN: 3d5e43ce95ff9d7f797f27b904c07291a35678fe76a9c57f0c0cba724f38acbb22c6c185db864a2a17b7ef2d67a04810ee5a45fd5a4e28a15a1ae16971451d
|
||||
AD: b5eeb9a18d436ada7bd5601944784f50fb0a989397b5c781a2cdf29337315dc7664f3c1cbf17f37fd0cc8b30
|
||||
CT: f91f1f20d06ad4480ff233480228994cfa052f9bf3038d06d997d31eb68bffa4960341b93eb5ed2260341e6816519c47bf231db2a41ad8a9719f4de6a33de5
|
||||
TAG: 6e5eabda421961e26dc17a7e1f750425235df4eaf9a97934c1e1b4439fc22791
|
||||
|
||||
KEY: 17b90dec44546d9dbc489e55a01f2cc64452a9b0e50506a8ad7c81bc6fb21328285cafed901a7204048866ff3bd543003fdcbeb3e9e2f3d580f9062362879633
|
||||
NONCE: f0c0cb247d210031f9b233bc
|
||||
IN: 75b9b524cbfd1287259da116f536aff56112a406f069aa08f545b5372d45b66d7a5d05e02728c4bc2c779609dfe251386f78c5f48b9dad90b363d324826cd6
|
||||
AD: 8a604a9b06ad595ce0b9ad1644a596c7d3cde81490abc80840c764c40d6df08fc71d1e8196eae0802f8c8dfc24
|
||||
CT: 23ad62a668f942e613c3b5a7828142048f1f6a67f7f0e0cc8bf3fffb2d1dd967da472d080353dc9c23b900a566f20afb850e4a47688ee507faa6178fef2afd
|
||||
TAG: e9e82d3221f964d9e6c09d761afa3f05d1316d39c82618a82dafa23607bb40a3
|
||||
|
||||
KEY: d5c09fe24201fcc3ad4c9a9c4b759345f643e930301c3714f62c8dd4974bb15a026b217ac637b4f0e8d6ef40f36be967c50aaea83b2e72df18eeb9576865f1d8
|
||||
NONCE: 9cfa0df1fe0910b33ee9849d
|
||||
IN: bfeb3d86ce3f4c5ccd0c3945e1da0e75dd057aa5b4e1f070593394f4a0227abedac0b77478e04d498506245b162e909cb711d8b875d33f9c4578e80a0e2113
|
||||
AD: b874a8523799554436a1174ab124677dc2ae2042a436c85065c50d5b5e7519623379ffed9a9c2b84b9626214b13c1806b65a432ba79066ff28ed94d17628f5ff84618593954389181e997ebd245d31f520539e250b31c86b99992983820f79e74aeaacb3a95e690e2841aba5a384d0333ebaa5d1fde06b4b8e3e1cabc6639459
|
||||
CT: afa649ea47db94936f89612ece681bb175664a97aa6faae5745f49ac9fcbfd4287b73cb58e8d8aa12eccf309182f075098f339db697fc60540481dad0cd82e
|
||||
TAG: 9909335130df0326650823de5a4f5b6f45e6941a6a72ceaf80ef32fe67363944
|
||||
|
||||
KEY: a13c4654606f532a8df47c367dab1b214166e4f7188c20560831ac30ba5e58d316d29764e4c716ec0126657c926ba2e4541da062447228ae61340a951101b4a0
|
||||
NONCE: a2df3417ebb86bbb2f954939
|
||||
IN: f1954e59a319547d32e81f846e0c79db41c681166b43eb9c10458948606ced50a44df26fad5654a7c25d3fb52539cf25fcc1c11707c4b5aca7910a76e2374740
|
||||
AD:
|
||||
CT: 374726a4691f178a4c0a6f96108ba30c4ca8a30242c14e84380969473879d4a5de580fab4cf6ef6e465560a15028ba78a1a88f9e62322cb698b15ccce6ba83a8
|
||||
TAG: 683e5a3e61d9d9c8b170f1d4eaa4f74dcbecb1a4cb1551dc364bbb336d4e4109
|
||||
|
||||
KEY: 0c1751677a9b7373e0c2ceab2c8e4dab50af22e2230be3187c21ed46069168d173c28a7474d8f7c3cab39401663405aebdcc474ce136e1fff9cfc520bfe17ca6
|
||||
NONCE: 38bc2efcd97998de1528b064
|
||||
IN: 8a3c6212240bdcb86da98f0e3ab3e9e78f7f61f0627ea088ab283e739a0bed5c360eeed26cea43ec09b4f3556049a1d7f8ef86abfd1118f9c0e34cc6eea4544a
|
||||
AD: 20
|
||||
CT: a1a9f7f4750be3d89fc4f25917f8ffa7dd462ce712ddf61792a01b1840bc8e428000372252f1b41055416a961db3be8fbe774f0a0a71a82e79e74927522703a0
|
||||
TAG: ae24708df0d5893a902765f6c6c2eebae0c11312936cd415bf4a74bb8498a367
|
||||
|
||||
KEY: 154c21eb43d8d556e5f782ddd64d577ac8066fa172c2936fc2b2e875aa437f941819d9ecfaefa2e388fdeea81a0ece8dcb7647f2c68da48884aeb1315b577c09
|
||||
NONCE: e14d1bd8681373d41702a762
|
||||
IN: a2c880fcda87d9d4681a735a6790d93a1c9c68e55b87d5f7b3146665a6b2051398eb9895e1f5d522841668b9915633aa8cb40048c619baf6d63ca2da486cdeb8
|
||||
AD: b0b725cf634349ce1d3ac49d48313a09697efd9996cc5afd06b1d0817181d0374db05825dc2f08207bfb3b
|
||||
CT: 1cc0db5980863df7a40c78e323a78be6c6d556d4e3b5f930d8d0f2c6a10c6477e31c000d3f0563b46e1a4aa566a4ef4b433e17e94c43338b51a7a3f862739b6e
|
||||
TAG: fe005424112de2a5ca6e68ada40984df1ae5ac666cf5fee19e9a0f203dd69f52
|
||||
|
||||
KEY: c34482341724ee431b5272ee2964b245d7657778f7927cad4b5a1bc30a176b1eb88a83ac9faf58215a72855edf94f8e86fade58c5b5907994bb8381c9f21b753
|
||||
NONCE: 4934d9afc32fc7e2d8851594
|
||||
IN: aa3d32adc47b0b84d1b038ddcaeb007a7d5c96cc06a943eba5da6d0d367625330556e67da099c84086b3f46bb4b72986e076eb426913e415cd20bee34e434bd0
|
||||
AD: 076a7bc587b306f3da3ba88e66a55cb8125bbf8aa000dda266e950f381e35ac938ac86f8a15a83022a25f28b
|
||||
CT: cf017d87da8927e42c1f10fd3d73cf483bae43f4e110363159a9fbb7cba363930a0364cd42a5de2c70171edc4caf15bfc7238f7087bf1402b32c7bdb1f493393
|
||||
TAG: 3961efea656aab1b83082522b801fafdae346f7d4be70db1981283f323e5b5dd
|
||||
|
||||
KEY: 363e10d8b3fe349014d6222761bba7af86545dcd1812fe2e5ada564c5008f8ea1850f374208e87362afa135f20f9e79dd0ad32f86448263416086d3afc5d37c0
|
||||
NONCE: cc545928edd3b21c0e8bc0f1
|
||||
IN: b68e3a54d17dab6eb41b03de2df14e792201d78a9c1cbf341da421da82b026ff471d4305ede5c6baae162a098c73da5cab93f30d6d540b4eaa0ee772448dade8
|
||||
AD: e21498edf4e25ada2dd6a382eceaf737623e501db34f5c5bd5c963f45818b146a6e45aa92db2a2069e55d46a4c
|
||||
CT: e4920c1fddb5dfed2268781fbb17e9ad2ea88bf2a0f116fbb7b309b25a5b9f989e1abc334999ab175b65f87e874d8ba80792044b458dc27d2b24c989d24385e1
|
||||
TAG: f0dcfa064cdf042e0b9a0443d634c38695dd09b99dadc647195fc2ad53dde547
|
||||
|
||||
KEY: ae93f58aefa94e4e0622f2e962529fd2efdab840fd0bce62e163ca0fb004ec3b22e246073614203d9b63fe2842ef5903ed08b3e52abf7ea18acbe16fa8f66368
|
||||
NONCE: c9ac237c87270f2d88b91b64
|
||||
IN: a75f49778a6c03b0f8915f5d09efe99c5f4e9cd928713882e6b9b78bab3541812db41792b893c7e2259debc6c660ce708851912a5b9eaf91416d86b5de114ce1
|
||||
AD: a4b198a329e9c5bb6d9f31a6415811eb33c79422b0db130b78d788c38c0b9a5122688cbc50fea811afa20789465f9ee4362336cc3701ece701179af96eb7c86d5a00ed8582f24364393287d5dbc3e83a82b7a585cee5b152b5da40aa45ccd46dc841004778998c7efe9eb43c9762d1c8581eee64e18c5a961bda5aafdd5cfec8
|
||||
CT: 453fad9395106a703ccbfe811bf775f1827ea960c71d79242d2ea0e3e31b14baa76eb6d107dfc6e484f4e5146f8cad5b389e4c0fa18260c96a193edbc8091a36
|
||||
TAG: b67082c21557b31392a9821fbce4b93706f96856d2581c92e7fb65dd2166624f
|
||||
|
||||
KEY: a145adafac46280e1cee8696903c5f3866540f27f17a519637373d95dca4ac5ac0bfd85ca6e1f8df8ae3fcfc9158421581669db52c20a3e19c5d251952f63218
|
||||
NONCE: 90bd43611f235ff225b23208
|
||||
IN: cbe5f3a5b7a94b8665cac1a4d173a225679e1a3926d8596b5adc0ef4fd00f7d93a432ff141cc04f877be60b6a17fff40ac845a91bcee3b483862f67d9a76ef498ce5e49c361bfc018e401aff47b397e96b2982d4fdcd043ca09905be9634e83dc22a667c955bc992ec96ca1b76f73631767f64fc7151284d5aa81c1aa42eb3aa
|
||||
AD:
|
||||
CT: 604f718dbce17dfca1fc5e0f400151cb65bea9d7d8f26d56687a76a23f89201aab01ef928006d15493f5b1501bb99c517cf123acd956ab575e687298488a88d5739c266e67ca6a20a5dbe5f5f27ac778816f04e7b1764cb716477f3aa01482cb6b25fe034ab5d942013164aa124608cacf13d6cc9487446cfba54315fc6bfc42
|
||||
TAG: 8e3e1a01945bfd9e1aa4eff1cdd0a6da6d8fdd5446e6d732a673effe8e44d76a
|
||||
|
||||
KEY: 63ac8e2561341587bc066c87cd23f7f33e6023bdc1521a91d6ce63d3ab213825d95d674928b56da1741aad8e85a8b703239ad74e0304ad555eeadebf4ae30aa6
|
||||
NONCE: 4f3073c3b780ebb146e136c7
|
||||
IN: 7f9a05b1aead29b4d5361c2606e5db8a48122858842679cd46f8386ef9359f998cd2c6c266791429624ff634a160d08faf1523b650c30b2fcd71517da5f377000251ef23cfd2510a0630215ad45fa6d2313f9add040a07df8259b82d3f29cf1ab8477cd114c9ee579d3e2ce60c5da2f3375b68b4d6e0913d39dac9399c00bd32
|
||||
AD: 22
|
||||
CT: d4ed811c8db932348e0c311e9278ef22f22cec8af88b3ac0cef77f13bbd9b8cca037c1ea87590a0ce3f3e7b3ffe1dcc4c7cd9e721baa5f126a3e0afb26dcfa02bf44428846c0f1e07ba0e026c23a39877de1e69e16a2766ff4fa3d4e8d3a97ba28f407f459ae3520dd840e8f9e149ea582048dc6e3d0227bd86a9c26ddd59895
|
||||
TAG: 0abc9111229bcb725953d139a2dcb1aa0cb9d3d6c01ef4733482dc5edcc88958
|
||||
|
||||
KEY: 355454fbe12f125edbc13550a7494f37efbe12b843058d29f892e1524289c2868ef0050a75a232d3083c381289e4950e352d68d64bf05f0608d694763c36641c
|
||||
NONCE: 0a344bb3da1c4260f2daf256
|
||||
IN: 362e97f8ef09f30e5db2f21d40568d347d9bc42d4c94a563484b12eb109886ccfd2c61c40dfe93eb836bb6aa4f828e77c137485da2df494cbeb6a9a0192c3777b4d7a927fba11a8eaf604b85a81ac4719ce8b595a74656286fd0b80d1ad3f3393e6038b258af97af9a77f6760d486d9caf5a451ba26dee51bda0f76d75bfc26e
|
||||
AD: c7c2e8196f37185b44515480d5d9451d79d07df4c1256bff6382f942727ce9b3a4f81ae964d8af2cd9f638
|
||||
CT: 32a67922947fd6b1c1bfaf3e1d41397173b97095e55307cae1c574daca275778d4aa4313fb1fe5b3997ff18800903ce044c7d0976abbb03b6cc1f7498d8b56d00672bd74f7cb152b677c632ef7a6f6fc13e95e82b6e35d663eb47f27c229c81174fd7c62c94c414e47216af2580fe822643e54907af77ae18e903fe856a02173
|
||||
TAG: 72d0fe5baee8090c5f8e79890b77f6d72a4213a7d1a81e0d1f1c9e6731e44d54
|
||||
|
||||
KEY: 664478c9d30d2cbc39351ec3b3494f3edb81e32e48bd4ef05969da07e770e4181a9ada3b2f83b46f40fc2d9ad35fd8ee6864ff3d70436d6cca3f8e0563cc3b06
|
||||
NONCE: 7313df9679181ffad2972a6b
|
||||
IN: 142f073f2ce443c68822f120b5009e39bea3453017dc04c1b091adfddcb2a7e361c2b79eab1bf0818bc86e9d7964834d3775698b56a11ee07a0c9c03cb7bb895bf1a1dde3975c3662d233052824f1539f58cd6ad5cadb58fecaf2b34935ff711c45a639d642fb8fc3a52929b1296683bb13e67f2cc8ed9090126cdf28a4395c6
|
||||
AD: d0d78b94505793af546912f3780699dd72e288c775bfc75da6e306defcd868f6d40c6d6ce34fab9c11574ef5
|
||||
CT: cb913e40ea5dfe76beae612e9732d23ce352789987134822b2324db585179bf90d0ee20bee102e93a49a55fc978d19e99ba316cf8d9a10d2f2bcb75da4b135d1fcb8057edc33a180586015d8829a128f8fdc87b72497016c280f54f4d974c2c7e9d32ae137eaa1bcb670be237269fa73c3a0f273da9e70d89600ae7c231fc9d4
|
||||
TAG: dcc158c254ff7e131ad854a2158d51c643c281dfd7df342d5481384ab236a685
|
||||
|
||||
KEY: 409d1b4e1c187c8b1c053e999f2af648583e1045d56d553cce9270d08c5643ef365eb35e3bdeaedcd164b0122ad185e71c75146a9807104d9b65b56d9bc1dc55
|
||||
NONCE: 1cce3f08a5aa5824d063a6f2
|
||||
IN: a255239e4065f3effe6aa5e88814d516236d016c51cd8eb35af7cee86418966559802f8ff7ac39c6a45acc1f1b18cc28d7cc32ae66dff43289fe44c3a2a72fbadf3a7249d76c1ba9671dfc420ddf513539f2da5f31030f2b6775c57432c2c3486621d841e80dd4894229debc12ef47d74716838f2d807e208f0fdaf733bce76e
|
||||
AD: 8f34f8b676e71844841c6a7b63fef1ad3061f2449c1044e1a281595da2d9e9fd141aea7350bd8cf9774d375e67
|
||||
CT: 969fc2c64261db415e51eee8cc5e0cf5185b8e3325dea516a70e32115a5b72233a44458c40f2daff3594d71e42ca2e3fc1c444ce171d22ef40009d798456613fa4b76beaa6d469e235997a302ac468c8bcfb8ef5de5cda58d7e554a9eab6cb568945dc37f28b0dbd674c083dfbd2e42fda1b42d0c1966e9652a21b32af71e2d5
|
||||
TAG: fa0789a83c255412501944a67bdceaff3f01d9a23b0c749be38abc956e2acae6
|
||||
|
||||
KEY: e6fd8144cdb305bf9e62a2c901764c62902f354409d8c5b9c8cbfc0ba8ac7d0859ff8994e573e46784395d89c355a91a313f601b56e86ed3fd10ba428a5481ce
|
||||
NONCE: bae080718d3e5c5998542f15
|
||||
IN: 2258ffcd6fcf91b1723f8db0047525d61cc8ffc440acf3290690685d16384292493807312b7dfc23ac9d9c3ee1405baab21a3770a05875cfe325268b65fc877463e3208c842ea4a32cf144cc46d57afd91f6b6b5d85fb2dedb0702f0c4e7f742cf4c9b4aec02f07267ec1f7b96a5a3ef25f6c1b4c27bd829e86583e239cd854b
|
||||
AD: 51ae57749b7757718aef9b9c47da5794659516e7f98bc80e6c18c89253f8617963331f54d4f009f087d1d2bd69a083f3a4b98f2a51ce24ffc6079774f7c7b01638b6131bfccebe21fea67bc839c259a50fcc0a16a69ada3c5adee4097d9e053a03266cb9b4b39ee2a465ec1aa058e61a0b9888b93bfcfd103f91ca3a7b274a10
|
||||
CT: 5b2fe8eea3313cc04d5ec75d75d05b3242b6e3b65c6fa1761716780c9529ff8ca523096dd037c5bda27984aa93c702ce9c01c63569a90657cc6373ad5d4473028b7eef69dd79c44c38d0063e8a8b7f1aa2bf6b646711ecd4eea3fa27408e089d9c4c4aceedff29a25baa6a9069eb7eac83a53212c0b387d700547c46cdc525e3
|
||||
TAG: 60319de093aec5c0bb8d5f17e950b0f4df0dfd20ad96490f6f12db461b2a4a84
|
||||
|
||||
@@ -76,6 +76,8 @@ AES-128-GCM:00000000000000000000000000000000:000000000000000000000000:0000000000
|
||||
AES-128-GCM:00000000000000000000000000000000:000000000000000000000000:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:0388dace60b6a392f328c2b971b2fe78f795aaab494b5923f7fd89ff948bc1e0200211214e7394da2089b6acd093abe0c94da219118e297d7b7ebcbcc9c388f28ade7d85a8ee35616f7124a9d527029195b84d1b96c690ff2f2de30bf2ec89e00253786e126504f0dab90c48a30321de3345e6b0461e7c9e6c6b7afedde83f40::cac45f60e31efd3b5a43b98a22ce1aa1
|
||||
# 192 bytes plaintext, iv is chosen so that initial counter LSB is 0xFF
|
||||
AES-128-GCM:00000000000000000000000000000000:ffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:56b3373ca9ef6e4a2b64fe1e9a17b61425f10d47a75a5fce13efc6bc784af24f4141bdd48cf7c770887afd573cca5418a9aeffcd7c5ceddfc6a78397b9a85b499da558257267caab2ad0b23ca476a53cb17fb41c4b8b475cb4f3f7165094c229c9e8c4dc0a2a5ff1903e501511221376a1cdb8364c5061a20cae74bc4acd76ceb0abc9fd3217ef9f8c90be402ddf6d8697f4f880dff15bfb7a6b28241ec8fe183c2d59e3f9dfff653c7126f0acb9e64211f42bae12af462b1070bef1ab5e3606::566f8ef683078bfdeeffa869d751a017
|
||||
# 288 bytes plaintext, iv is chosen so that initial counter LSB is 0xFF
|
||||
AES-128-GCM:00000000000000000000000000000000:ffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:56b3373ca9ef6e4a2b64fe1e9a17b61425f10d47a75a5fce13efc6bc784af24f4141bdd48cf7c770887afd573cca5418a9aeffcd7c5ceddfc6a78397b9a85b499da558257267caab2ad0b23ca476a53cb17fb41c4b8b475cb4f3f7165094c229c9e8c4dc0a2a5ff1903e501511221376a1cdb8364c5061a20cae74bc4acd76ceb0abc9fd3217ef9f8c90be402ddf6d8697f4f880dff15bfb7a6b28241ec8fe183c2d59e3f9dfff653c7126f0acb9e64211f42bae12af462b1070bef1ab5e3606872ca10dee15b3249b1a1b958f23134c4bccb7d03200bce420a2f8eb66dcf3644d1423c1b5699003c13ecef4bf38a3b60eedc34033bac1902783dc6d89e2e774188a439c7ebcc0672dbda4ddcfb2794613b0be41315ef778708a70ee7d75165c::8b307f6b33286d0ab026a9ed3fe1e85f
|
||||
# 80 bytes plaintext, submitted by Intel
|
||||
AES-128-GCM:843ffcf5d2b72694d19ed01d01249412:dbcca32ebf9b804617c3aa9e:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f:6268c6fa2a80b2d137467f092f657ac04d89be2beaa623d61b5a868c8f03ff95d3dcee23ad2f1ab3a6c80eaf4b140eb05de3457f0fbc111a6b43d0763aa422a3013cf1dc37fe417d1fbfc449b75d4cc5:00000000000000000000000000000000101112131415161718191a1b1c1d1e1f:3b629ccfbc1119b7319e1dce2cd6fd6d
|
||||
|
||||
|
||||
+3
-3
@@ -93,10 +93,10 @@ static int probe_for_NEON() {
|
||||
|
||||
sigset_t original_sigmask;
|
||||
sigprocmask(SIG_SETMASK, &sigmask, &original_sigmask);
|
||||
sigaction(SIGILL, &sigill_action, &sigill_original_action);
|
||||
|
||||
|
||||
if (sigsetjmp(sigill_jmp, 1 /* save signals */) == 0) {
|
||||
sigaction(SIGILL, &sigill_action, &sigill_original_action);
|
||||
|
||||
// This function cannot be inline asm because GCC will refuse to compile
|
||||
// inline NEON instructions unless building with -mfpu=neon, which would
|
||||
// defeat the point of probing for support at runtime.
|
||||
@@ -168,7 +168,7 @@ void OPENSSL_cpuid_setup(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
OPENSSL_armcap_P |= ARMV7_NEON | ARMV7_NEON_FUNCTIONAL;
|
||||
OPENSSL_armcap_P |= ARMV7_NEON;
|
||||
|
||||
if (hwcap & kAES) {
|
||||
OPENSSL_armcap_P |= ARMV8_AES;
|
||||
|
||||
@@ -110,10 +110,6 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
|
||||
&cmp ("ebp",0);
|
||||
&jne (&label("notintel"));
|
||||
&or ("edx",1<<30); # set reserved bit#30 on Intel CPUs
|
||||
&and (&HB("eax"),15); # familiy ID
|
||||
&cmp (&HB("eax"),15); # P4?
|
||||
&jne (&label("notintel"));
|
||||
&or ("edx",1<<20); # set reserved bit#20 to engage RC4_CHAR
|
||||
&set_label("notintel");
|
||||
&bt ("edx",28); # test hyper-threading bit
|
||||
&jnc (&label("generic"));
|
||||
|
||||
@@ -122,10 +122,6 @@ OPENSSL_ia32_cpuid:
|
||||
cmp \$0,%r9d
|
||||
jne .Lnotintel
|
||||
or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
|
||||
and \$15,%ah
|
||||
cmp \$15,%ah # examine Family ID
|
||||
jne .Lnotintel
|
||||
or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
|
||||
.Lnotintel:
|
||||
bt \$28,%edx # test hyper-threading bit
|
||||
jnc .Lgeneric
|
||||
|
||||
@@ -349,6 +349,35 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8_t kOddParity[256] = {
|
||||
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14,
|
||||
14, 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28,
|
||||
31, 31, 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44,
|
||||
44, 47, 47, 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59,
|
||||
61, 61, 62, 62, 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74,
|
||||
74, 76, 76, 79, 79, 81, 81, 82, 82, 84, 84, 87, 87, 88, 88,
|
||||
91, 91, 93, 93, 94, 94, 97, 97, 98, 98, 100, 100, 103, 103, 104,
|
||||
104, 107, 107, 109, 109, 110, 110, 112, 112, 115, 115, 117, 117, 118, 118,
|
||||
121, 121, 122, 122, 124, 124, 127, 127, 128, 128, 131, 131, 133, 133, 134,
|
||||
134, 137, 137, 138, 138, 140, 140, 143, 143, 145, 145, 146, 146, 148, 148,
|
||||
151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 161, 161, 162, 162, 164,
|
||||
164, 167, 167, 168, 168, 171, 171, 173, 173, 174, 174, 176, 176, 179, 179,
|
||||
181, 181, 182, 182, 185, 185, 186, 186, 188, 188, 191, 191, 193, 193, 194,
|
||||
194, 196, 196, 199, 199, 200, 200, 203, 203, 205, 205, 206, 206, 208, 208,
|
||||
211, 211, 213, 213, 214, 214, 217, 217, 218, 218, 220, 220, 223, 223, 224,
|
||||
224, 227, 227, 229, 229, 230, 230, 233, 233, 234, 234, 236, 236, 239, 239,
|
||||
241, 241, 242, 242, 244, 244, 247, 247, 248, 248, 251, 251, 253, 253, 254,
|
||||
254
|
||||
};
|
||||
|
||||
void DES_set_odd_parity(DES_cblock *key) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < DES_KEY_SZ; i++) {
|
||||
key->bytes[i] = kOddParity[key->bytes[i]];
|
||||
}
|
||||
}
|
||||
|
||||
static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
uint32_t l, r, t, u;
|
||||
const uint32_t *s;
|
||||
@@ -609,6 +638,29 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin[1] = 0;
|
||||
}
|
||||
|
||||
void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output,
|
||||
const DES_key_schedule *ks1, const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc) {
|
||||
uint32_t l0, l1;
|
||||
uint32_t ll[2];
|
||||
const uint8_t *in = input->bytes;
|
||||
uint8_t *out = output->bytes;
|
||||
|
||||
c2l(in, l0);
|
||||
c2l(in, l1);
|
||||
ll[0] = l0;
|
||||
ll[1] = l1;
|
||||
if (enc) {
|
||||
DES_encrypt3(ll, ks1, ks2, ks3);
|
||||
} else {
|
||||
DES_decrypt3(ll, ks1, ks2, ks3);
|
||||
}
|
||||
l0 = ll[0];
|
||||
l1 = ll[1];
|
||||
l2c(l0, out);
|
||||
l2c(l1, out);
|
||||
}
|
||||
|
||||
void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
|
||||
@@ -12,7 +12,7 @@ add_library(
|
||||
add_executable(
|
||||
digest_test
|
||||
|
||||
digest_test.c
|
||||
digest_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(digest_test crypto)
|
||||
|
||||
@@ -23,24 +23,26 @@
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "../test/scoped_types.h"
|
||||
|
||||
typedef struct {
|
||||
/* md_func is the digest to test. */
|
||||
|
||||
struct TestVector {
|
||||
// md_func is the digest to test.
|
||||
const EVP_MD *(*md_func)(void);
|
||||
/* one_shot_func is the convenience one-shot version of the
|
||||
* digest. */
|
||||
// one_shot_func is the convenience one-shot version of the
|
||||
// digest.
|
||||
uint8_t *(*one_shot_func)(const uint8_t *, size_t, uint8_t *);
|
||||
/* input is a NUL-terminated string to hash. */
|
||||
// input is a NUL-terminated string to hash.
|
||||
const char *input;
|
||||
/* repeat is the number of times to repeat input. */
|
||||
// repeat is the number of times to repeat input.
|
||||
size_t repeat;
|
||||
/* expected_hex is the expected digest in hexadecimal. */
|
||||
// expected_hex is the expected digest in hexadecimal.
|
||||
const char *expected_hex;
|
||||
} TEST_VECTOR;
|
||||
};
|
||||
|
||||
static const TEST_VECTOR kTestVectors[] = {
|
||||
/* MD4 tests, from RFC 1320. (crypto/md4 does not provide a
|
||||
* one-shot MD4 function.) */
|
||||
static const TestVector kTestVectors[] = {
|
||||
// MD4 tests, from RFC 1320. (crypto/md4 does not provide a
|
||||
// one-shot MD4 function.)
|
||||
{ &EVP_md4, NULL, "", 1, "31d6cfe0d16ae931b73c59d7e0c089c0" },
|
||||
{ &EVP_md4, NULL, "a", 1, "bde52cb31de33e46245e05fbdbd6fb24" },
|
||||
{ &EVP_md4, NULL, "abc", 1, "a448017aaf21d8525fc10ae87aa6729d" },
|
||||
@@ -53,7 +55,7 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"043f8582f241db351ce627e153e7f0e4" },
|
||||
{ &EVP_md4, NULL, "1234567890", 8, "e33b4ddc9c38f2199c3e7b164fcc0536" },
|
||||
|
||||
/* MD5 tests, from RFC 1321. */
|
||||
// MD5 tests, from RFC 1321.
|
||||
{ &EVP_md5, &MD5, "", 1, "d41d8cd98f00b204e9800998ecf8427e" },
|
||||
{ &EVP_md5, &MD5, "a", 1, "0cc175b9c0f1b6a831c399e269772661" },
|
||||
{ &EVP_md5, &MD5, "abc", 1, "900150983cd24fb0d6963f7d28e17f72" },
|
||||
@@ -65,7 +67,7 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"d174ab98d277d9f5a5611c2c9f419d9f" },
|
||||
{ &EVP_md5, &MD5, "1234567890", 8, "57edf4a22be3c955ac49da2e2107b67a" },
|
||||
|
||||
/* SHA-1 tests, from RFC 3174. */
|
||||
// SHA-1 tests, from RFC 3174.
|
||||
{ &EVP_sha1, &SHA1, "abc", 1, "a9993e364706816aba3e25717850c26c9cd0d89d" },
|
||||
{ &EVP_sha1, &SHA1,
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
|
||||
@@ -76,7 +78,7 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"0123456701234567012345670123456701234567012345670123456701234567", 10,
|
||||
"dea356a2cddd90c7a7ecedc5ebb563934f460452" },
|
||||
|
||||
/* SHA-224 tests, from RFC 3874. */
|
||||
// SHA-224 tests, from RFC 3874.
|
||||
{ &EVP_sha224, &SHA224, "abc", 1,
|
||||
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" },
|
||||
{ &EVP_sha224, &SHA224,
|
||||
@@ -86,14 +88,14 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"a", 1000000,
|
||||
"20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" },
|
||||
|
||||
/* SHA-256 tests, from NIST. */
|
||||
// SHA-256 tests, from NIST.
|
||||
{ &EVP_sha256, &SHA256, "abc", 1,
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
|
||||
{ &EVP_sha256, &SHA256,
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
|
||||
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" },
|
||||
|
||||
/* SHA-384 tests, from NIST. */
|
||||
// SHA-384 tests, from NIST.
|
||||
{ &EVP_sha384, &SHA384, "abc", 1,
|
||||
"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed"
|
||||
"8086072ba1e7cc2358baeca134c825a7" },
|
||||
@@ -103,7 +105,7 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712"
|
||||
"fcc7c71a557e2db966c3e9fa91746039" },
|
||||
|
||||
/* SHA-512 tests, from NIST. */
|
||||
// SHA-512 tests, from NIST.
|
||||
{ &EVP_sha512, &SHA512, "abc", 1,
|
||||
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
|
||||
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" },
|
||||
@@ -113,12 +115,12 @@ static const TEST_VECTOR kTestVectors[] = {
|
||||
"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018"
|
||||
"501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" },
|
||||
|
||||
/* MD5-SHA1 tests. */
|
||||
// MD5-SHA1 tests.
|
||||
{ &EVP_md5_sha1, NULL, "abc", 1,
|
||||
"900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d" },
|
||||
};
|
||||
|
||||
static int compare_digest(const TEST_VECTOR *test,
|
||||
static bool CompareDigest(const TestVector *test,
|
||||
const uint8_t *digest,
|
||||
size_t digest_len) {
|
||||
static const char kHexTable[] = "0123456789abcdef";
|
||||
@@ -135,105 +137,94 @@ static int compare_digest(const TEST_VECTOR *test,
|
||||
fprintf(stderr, "%s(\"%s\" * %d) = %s; want %s\n",
|
||||
EVP_MD_name(test->md_func()), test->input, (int)test->repeat,
|
||||
digest_hex, test->expected_hex);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_digest(const TEST_VECTOR *test) {
|
||||
int ret = 0;
|
||||
EVP_MD_CTX ctx;
|
||||
size_t i;
|
||||
uint8_t digest[EVP_MAX_MD_SIZE];
|
||||
unsigned digest_len;
|
||||
static int TestDigest(const TestVector *test) {
|
||||
ScopedEVP_MD_CTX ctx;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
/* Test the input provided. */
|
||||
if (!EVP_DigestInit_ex(&ctx, test->md_func(), NULL)) {
|
||||
// Test the input provided.
|
||||
if (!EVP_DigestInit_ex(ctx.get(), test->md_func(), NULL)) {
|
||||
fprintf(stderr, "EVP_DigestInit_ex failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < test->repeat; i++) {
|
||||
if (!EVP_DigestUpdate(&ctx, test->input, strlen(test->input))) {
|
||||
for (size_t i = 0; i < test->repeat; i++) {
|
||||
if (!EVP_DigestUpdate(ctx.get(), test->input, strlen(test->input))) {
|
||||
fprintf(stderr, "EVP_DigestUpdate failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(&ctx, digest, &digest_len)) {
|
||||
uint8_t digest[EVP_MAX_MD_SIZE];
|
||||
unsigned digest_len;
|
||||
if (!EVP_DigestFinal_ex(ctx.get(), digest, &digest_len)) {
|
||||
fprintf(stderr, "EVP_DigestFinal_ex failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
if (!compare_digest(test, digest, digest_len)) {
|
||||
goto done;
|
||||
if (!CompareDigest(test, digest, digest_len)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Test the input one character at a time. */
|
||||
if (!EVP_DigestInit_ex(&ctx, test->md_func(), NULL)) {
|
||||
// Test the input one character at a time.
|
||||
if (!EVP_DigestInit_ex(ctx.get(), test->md_func(), NULL)) {
|
||||
fprintf(stderr, "EVP_DigestInit_ex failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
if (!EVP_DigestUpdate(&ctx, NULL, 0)) {
|
||||
if (!EVP_DigestUpdate(ctx.get(), NULL, 0)) {
|
||||
fprintf(stderr, "EVP_DigestUpdate failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < test->repeat; i++) {
|
||||
const char *p;
|
||||
for (p = test->input; *p; p++) {
|
||||
if (!EVP_DigestUpdate(&ctx, p, 1)) {
|
||||
for (size_t i = 0; i < test->repeat; i++) {
|
||||
for (const char *p = test->input; *p; p++) {
|
||||
if (!EVP_DigestUpdate(ctx.get(), p, 1)) {
|
||||
fprintf(stderr, "EVP_DigestUpdate failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(&ctx, digest, &digest_len)) {
|
||||
if (!EVP_DigestFinal_ex(ctx.get(), digest, &digest_len)) {
|
||||
fprintf(stderr, "EVP_DigestFinal_ex failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
if (digest_len != EVP_MD_size(test->md_func())) {
|
||||
fprintf(stderr, "EVP_MD_size output incorrect\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
if (!compare_digest(test, digest, digest_len)) {
|
||||
goto done;
|
||||
if (!CompareDigest(test, digest, digest_len)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Test the one-shot function. */
|
||||
// Test the one-shot function.
|
||||
if (test->one_shot_func && test->repeat == 1) {
|
||||
uint8_t *out = test->one_shot_func((const uint8_t *)test->input,
|
||||
strlen(test->input), digest);
|
||||
if (out != digest) {
|
||||
fprintf(stderr, "one_shot_func gave incorrect return\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
if (!compare_digest(test, digest, EVP_MD_size(test->md_func()))) {
|
||||
goto done;
|
||||
if (!CompareDigest(test, digest, EVP_MD_size(test->md_func()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Test the deprecated static buffer variant, until it's removed. */
|
||||
// Test the deprecated static buffer variant, until it's removed.
|
||||
out = test->one_shot_func((const uint8_t *)test->input, strlen(test->input),
|
||||
NULL);
|
||||
if (!compare_digest(test, out, EVP_MD_size(test->md_func()))) {
|
||||
goto done;
|
||||
if (!CompareDigest(test, out, EVP_MD_size(test->md_func()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
size_t i;
|
||||
|
||||
CRYPTO_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
for (i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) {
|
||||
if (!test_digest(&kTestVectors[i])) {
|
||||
for (size_t i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) {
|
||||
if (!TestDigest(&kTestVectors[i])) {
|
||||
fprintf(stderr, "Test %d failed\n", (int)i);
|
||||
return 1;
|
||||
}
|
||||
+6
-7
@@ -426,7 +426,7 @@ void EC_GROUP_free(EC_GROUP *group) {
|
||||
OPENSSL_free(group);
|
||||
}
|
||||
|
||||
int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) {
|
||||
int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src) {
|
||||
if (dest->meth->group_copy == 0) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_GROUP_copy, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
@@ -482,7 +482,7 @@ EC_GROUP *EC_GROUP_dup(const EC_GROUP *a) {
|
||||
if (t == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!EC_GROUP_copy(t, a)) {
|
||||
if (!ec_group_copy(t, a)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -499,11 +499,10 @@ err:
|
||||
}
|
||||
}
|
||||
|
||||
int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b) {
|
||||
if (a->curve_name == NID_undef || b->curve_name == NID_undef) {
|
||||
return 0;
|
||||
}
|
||||
return a->curve_name == b->curve_name;
|
||||
int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ignored) {
|
||||
return a->curve_name == NID_undef ||
|
||||
b->curve_name == NID_undef ||
|
||||
a->curve_name != b->curve_name;
|
||||
}
|
||||
|
||||
const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) {
|
||||
|
||||
+11
-18
@@ -290,16 +290,9 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
|
||||
EC_KEY *ret = NULL;
|
||||
EC_PRIVATEKEY *priv_key = NULL;
|
||||
|
||||
priv_key = EC_PRIVATEKEY_new();
|
||||
if (priv_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len);
|
||||
priv_key = d2i_EC_PRIVATEKEY(NULL, in, len);
|
||||
if (priv_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_EC_LIB);
|
||||
EC_PRIVATEKEY_free(priv_key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -309,9 +302,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
|
||||
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (a) {
|
||||
*a = ret;
|
||||
}
|
||||
} else {
|
||||
ret = *a;
|
||||
}
|
||||
@@ -380,17 +370,17 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
|
||||
ret->enc_flag |= EC_PKEY_NO_PUBKEY;
|
||||
}
|
||||
|
||||
if (a) {
|
||||
*a = ret;
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
if (ret) {
|
||||
if (ret && (a == NULL || *a != ret)) {
|
||||
EC_KEY_free(ret);
|
||||
}
|
||||
ret = NULL;
|
||||
if (a) {
|
||||
*a = ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (priv_key) {
|
||||
@@ -519,18 +509,21 @@ EC_KEY *d2i_ECParameters(EC_KEY **key, const uint8_t **inp, long len) {
|
||||
OPENSSL_PUT_ERROR(EC, d2i_ECParameters, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
if (key) {
|
||||
*key = ret;
|
||||
}
|
||||
} else {
|
||||
ret = *key;
|
||||
}
|
||||
|
||||
if (!d2i_ECPKParameters(&ret->group, inp, len)) {
|
||||
OPENSSL_PUT_ERROR(EC, d2i_ECParameters, ERR_R_EC_LIB);
|
||||
if (key == NULL || *key == NULL) {
|
||||
EC_KEY_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
*key = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+4
-12
@@ -170,35 +170,27 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_KEY_copy, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
/* copy the parameters */
|
||||
/* Copy the parameters. */
|
||||
if (src->group) {
|
||||
/* TODO(fork): duplicating the group seems wasteful. */
|
||||
const EC_METHOD *meth = src->group->meth;
|
||||
/* clear the old group */
|
||||
if (dest->group) {
|
||||
EC_GROUP_free(dest->group);
|
||||
}
|
||||
dest->group = ec_group_new(meth);
|
||||
dest->group = EC_GROUP_dup(src->group);
|
||||
if (dest->group == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!EC_GROUP_copy(dest->group, src->group)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy the public key */
|
||||
/* Copy the public key. */
|
||||
if (src->pub_key && src->group) {
|
||||
if (dest->pub_key) {
|
||||
EC_POINT_free(dest->pub_key);
|
||||
}
|
||||
dest->pub_key = EC_POINT_new(src->group);
|
||||
dest->pub_key = EC_POINT_dup(src->pub_key, src->group);
|
||||
if (dest->pub_key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!EC_POINT_copy(dest->pub_key, src->pub_key)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy the private key */
|
||||
|
||||
@@ -250,6 +250,7 @@ struct ec_point_st {
|
||||
} /* EC_POINT */;
|
||||
|
||||
EC_GROUP *ec_group_new(const EC_METHOD *meth);
|
||||
int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src);
|
||||
|
||||
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
|
||||
size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
|
||||
|
||||
@@ -1,18 +1,50 @@
|
||||
include_directories(. .. ../../include)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT err_data.c
|
||||
COMMAND ${GO_EXECUTABLE} run err_data_generate.go > ${CMAKE_CURRENT_BINARY_DIR}/err_data.c
|
||||
DEPENDS
|
||||
err_data_generate.go
|
||||
asn1.errordata
|
||||
bio.errordata
|
||||
bn.errordata
|
||||
buf.errordata
|
||||
cipher.errordata
|
||||
conf.errordata
|
||||
crypto.errordata
|
||||
dh.errordata
|
||||
digest.errordata
|
||||
dsa.errordata
|
||||
ecdh.errordata
|
||||
ecdsa.errordata
|
||||
ec.errordata
|
||||
engine.errordata
|
||||
evp.errordata
|
||||
hkdf.errordata
|
||||
obj.errordata
|
||||
pem.errordata
|
||||
pkcs8.errordata
|
||||
rsa.errordata
|
||||
ssl.errordata
|
||||
x509.errordata
|
||||
x509v3.errordata
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_library(
|
||||
err
|
||||
|
||||
OBJECT
|
||||
|
||||
err.c
|
||||
err_data.c
|
||||
err_impl.c
|
||||
)
|
||||
|
||||
add_executable(
|
||||
err_test
|
||||
|
||||
err_test.c
|
||||
err_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(err_test crypto)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
CIPHER,function,100,EVP_AEAD_CTX_init
|
||||
CIPHER,function,131,EVP_AEAD_CTX_init_with_direction
|
||||
CIPHER,function,101,EVP_AEAD_CTX_open
|
||||
CIPHER,function,102,EVP_AEAD_CTX_seal
|
||||
CIPHER,function,103,EVP_CIPHER_CTX_copy
|
||||
@@ -7,6 +8,9 @@ CIPHER,function,105,EVP_CIPHER_CTX_set_key_length
|
||||
CIPHER,function,106,EVP_CipherInit_ex
|
||||
CIPHER,function,107,EVP_DecryptFinal_ex
|
||||
CIPHER,function,108,EVP_EncryptFinal_ex
|
||||
CIPHER,function,132,aead_aes_ctr_hmac_sha256_init
|
||||
CIPHER,function,133,aead_aes_ctr_hmac_sha256_open
|
||||
CIPHER,function,134,aead_aes_ctr_hmac_sha256_seal
|
||||
CIPHER,function,109,aead_aes_gcm_init
|
||||
CIPHER,function,110,aead_aes_gcm_open
|
||||
CIPHER,function,111,aead_aes_gcm_seal
|
||||
@@ -44,6 +48,7 @@ CIPHER,reason,111,INVALID_NONCE_SIZE
|
||||
CIPHER,reason,112,INVALID_OPERATION
|
||||
CIPHER,reason,113,IV_TOO_LARGE
|
||||
CIPHER,reason,114,NO_CIPHER_SET
|
||||
CIPHER,reason,124,NO_DIRECTION_SET
|
||||
CIPHER,reason,115,OUTPUT_ALIASES_INPUT
|
||||
CIPHER,reason,116,TAG_TOO_LARGE
|
||||
CIPHER,reason,117,TOO_LARGE
|
||||
|
||||
+14
-9
@@ -117,7 +117,7 @@
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#pragma warning(push, 3)
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
@@ -126,6 +126,14 @@
|
||||
#include <openssl/thread.h>
|
||||
|
||||
|
||||
extern const uint32_t kOpenSSLFunctionValues[];
|
||||
extern const size_t kOpenSSLFunctionValuesLen;
|
||||
extern const char kOpenSSLFunctionStringData[];
|
||||
|
||||
extern const uint32_t kOpenSSLReasonValues[];
|
||||
extern const size_t kOpenSSLReasonValuesLen;
|
||||
extern const char kOpenSSLReasonStringData[];
|
||||
|
||||
/* err_fns contains a pointer to the current error implementation. */
|
||||
static const struct ERR_FNS_st *err_fns = NULL;
|
||||
extern const struct ERR_FNS_st openssl_err_default_impl;
|
||||
@@ -423,8 +431,6 @@ void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
#include "err_data.h"
|
||||
|
||||
// err_string_cmp is a compare function for searching error values with
|
||||
// |bsearch| in |err_string_lookup|.
|
||||
static int err_string_cmp(const void *a, const void *b) {
|
||||
@@ -545,9 +551,9 @@ const char *ERR_func_error_string(uint32_t packed_error) {
|
||||
}
|
||||
|
||||
return err_string_lookup(ERR_GET_LIB(packed_error),
|
||||
ERR_GET_FUNC(packed_error), kFunctionValues,
|
||||
sizeof(kFunctionValues) / sizeof(kFunctionValues[0]),
|
||||
kFunctionStringData);
|
||||
ERR_GET_FUNC(packed_error), kOpenSSLFunctionValues,
|
||||
kOpenSSLFunctionValuesLen,
|
||||
kOpenSSLFunctionStringData);
|
||||
}
|
||||
|
||||
const char *ERR_reason_error_string(uint32_t packed_error) {
|
||||
@@ -582,9 +588,8 @@ const char *ERR_reason_error_string(uint32_t packed_error) {
|
||||
}
|
||||
}
|
||||
|
||||
return err_string_lookup(lib, reason, kReasonValues,
|
||||
sizeof(kReasonValues) / sizeof(kReasonValues[0]),
|
||||
kReasonStringData);
|
||||
return err_string_lookup(lib, reason, kOpenSSLReasonValues,
|
||||
kOpenSSLReasonValuesLen, kOpenSSLReasonStringData);
|
||||
}
|
||||
|
||||
void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -140,13 +140,16 @@ func (st *stringList) WriteTo(out stringWriter, name string) {
|
||||
list := st.buildList()
|
||||
fmt.Fprintf(os.Stderr, "%s: %d bytes of list and %d bytes of string data.\n", name, 4*len(list), len(st.stringData))
|
||||
|
||||
out.WriteString("static const uint32_t k" + name + "Values[] = {\n")
|
||||
values := "kOpenSSL" + name + "Values"
|
||||
out.WriteString("const uint32_t " + values + "[] = {\n")
|
||||
for _, v := range list {
|
||||
fmt.Fprintf(out, " 0x%x,\n", v)
|
||||
}
|
||||
out.WriteString("};\n\n")
|
||||
out.WriteString("const size_t " + values + "Len = sizeof(" + values + ") / sizeof(" + values + "[0]);\n\n");
|
||||
|
||||
out.WriteString("static const char k" + name + "StringData[] =\n \"")
|
||||
stringData := "kOpenSSL" + name + "StringData"
|
||||
out.WriteString("const char " + stringData + "[] =\n \"")
|
||||
for i, c := range st.stringData {
|
||||
if c == 0 {
|
||||
out.WriteString("\\0\"\n \"")
|
||||
@@ -267,6 +270,7 @@ func main() {
|
||||
/* This file was generated by err_data_generate.go. */
|
||||
|
||||
#include <openssl/base.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/type_check.h>
|
||||
|
||||
|
||||
|
||||
@@ -20,55 +20,52 @@
|
||||
#include <openssl/mem.h>
|
||||
|
||||
|
||||
static int test_overflow(void) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < ERR_NUM_ERRORS*2; i++) {
|
||||
static bool TestOverflow() {
|
||||
for (unsigned i = 0; i < ERR_NUM_ERRORS*2; i++) {
|
||||
ERR_put_error(1, 2, i+1, "test", 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < ERR_NUM_ERRORS - 1; i++) {
|
||||
for (unsigned i = 0; i < ERR_NUM_ERRORS - 1; i++) {
|
||||
uint32_t err = ERR_get_error();
|
||||
/* Errors are returned in order they were pushed, with the least recent ones
|
||||
* removed, up to |ERR_NUM_ERRORS - 1| errors. So the errors returned are
|
||||
* |ERR_NUM_ERRORS + 2| through |ERR_NUM_ERRORS * 2|, inclusive. */
|
||||
if (err == 0 || ERR_GET_REASON(err) != i + ERR_NUM_ERRORS + 2) {
|
||||
fprintf(stderr, "ERR_get_error failed at %u\n", i);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ERR_get_error() != 0) {
|
||||
fprintf(stderr, "ERR_get_error more than the expected number of values.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_put_error(void) {
|
||||
uint32_t peeked_packed_error, packed_error;
|
||||
int peeked_line, line, peeked_flags, flags;
|
||||
const char *peeked_file, *file, *peeked_data, *data;
|
||||
|
||||
static bool TestPutError() {
|
||||
if (ERR_get_error() != 0) {
|
||||
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
ERR_put_error(1, 2, 3, "test", 4);
|
||||
ERR_add_error_data(1, "testing");
|
||||
|
||||
peeked_packed_error = ERR_peek_error_line_data(&peeked_file, &peeked_line,
|
||||
&peeked_data, &peeked_flags);
|
||||
packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
|
||||
int peeked_line, line, peeked_flags, flags;
|
||||
const char *peeked_file, *file, *peeked_data, *data;
|
||||
uint32_t peeked_packed_error =
|
||||
ERR_peek_error_line_data(&peeked_file, &peeked_line, &peeked_data,
|
||||
&peeked_flags);
|
||||
uint32_t packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
|
||||
|
||||
if (peeked_packed_error != packed_error ||
|
||||
peeked_file != file ||
|
||||
peeked_data != data ||
|
||||
peeked_flags != flags) {
|
||||
fprintf(stderr, "Bad peeked error data returned.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(file, "test") != 0 ||
|
||||
@@ -79,16 +76,16 @@ static int test_put_error(void) {
|
||||
ERR_GET_REASON(packed_error) != 3 ||
|
||||
strcmp(data, "testing") != 0) {
|
||||
fprintf(stderr, "Bad error data returned.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_clear_error(void) {
|
||||
static bool TestClearError() {
|
||||
if (ERR_get_error() != 0) {
|
||||
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
ERR_put_error(1, 2, 3, "test", 4);
|
||||
@@ -96,42 +93,39 @@ static int test_clear_error(void) {
|
||||
|
||||
if (ERR_get_error() != 0) {
|
||||
fprintf(stderr, "Error remained after clearing.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_print(void) {
|
||||
size_t i;
|
||||
char buf[256];
|
||||
uint32_t packed_error;
|
||||
|
||||
static bool TestPrint() {
|
||||
ERR_put_error(1, 2, 3, "test", 4);
|
||||
ERR_add_error_data(1, "testing");
|
||||
packed_error = ERR_get_error();
|
||||
uint32_t packed_error = ERR_get_error();
|
||||
|
||||
for (i = 0; i <= sizeof(buf); i++) {
|
||||
char buf[256];
|
||||
for (size_t i = 0; i <= sizeof(buf); i++) {
|
||||
ERR_error_string_n(packed_error, buf, i);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_release(void) {
|
||||
static bool TestRelease() {
|
||||
ERR_put_error(1, 2, 3, "test", 4);
|
||||
ERR_remove_thread_state(NULL);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main() {
|
||||
CRYPTO_library_init();
|
||||
|
||||
if (!test_overflow() ||
|
||||
!test_put_error() ||
|
||||
!test_clear_error() ||
|
||||
!test_print() ||
|
||||
!test_release()) {
|
||||
if (!TestOverflow() ||
|
||||
!TestPutError() ||
|
||||
!TestClearError() ||
|
||||
!TestPrint() ||
|
||||
!TestRelease()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ EVP,function,100,EVP_DigestSignAlgorithm
|
||||
EVP,function,101,EVP_DigestVerifyInitFromAlgorithm
|
||||
EVP,function,102,EVP_PKEY_CTX_ctrl
|
||||
EVP,function,103,EVP_PKEY_CTX_dup
|
||||
EVP,function,159,EVP_PKEY_CTX_get0_rsa_oaep_label
|
||||
EVP,function,104,EVP_PKEY_copy_parameters
|
||||
EVP,function,105,EVP_PKEY_decrypt
|
||||
EVP,function,106,EVP_PKEY_decrypt_init
|
||||
@@ -45,6 +46,7 @@ EVP,function,143,pkey_ec_derive
|
||||
EVP,function,144,pkey_ec_keygen
|
||||
EVP,function,145,pkey_ec_paramgen
|
||||
EVP,function,146,pkey_ec_sign
|
||||
EVP,function,158,pkey_hmac_ctrl
|
||||
EVP,function,147,pkey_rsa_ctrl
|
||||
EVP,function,148,pkey_rsa_decrypt
|
||||
EVP,function,149,pkey_rsa_encrypt
|
||||
|
||||
@@ -56,10 +56,13 @@ SSL,function,154,dtls1_buffer_record
|
||||
SSL,function,155,dtls1_check_timeout_num
|
||||
SSL,function,156,dtls1_connect
|
||||
SSL,function,157,dtls1_do_write
|
||||
SSL,function,263,dtls1_get_buffered_message
|
||||
SSL,function,158,dtls1_get_hello_verify
|
||||
SSL,function,159,dtls1_get_message
|
||||
SSL,function,160,dtls1_get_message_fragment
|
||||
SSL,function,265,dtls1_hm_fragment_new
|
||||
SSL,function,161,dtls1_preprocess_fragment
|
||||
SSL,function,264,dtls1_process_fragment
|
||||
SSL,function,162,dtls1_process_record
|
||||
SSL,function,163,dtls1_read_bytes
|
||||
SSL,function,164,dtls1_send_hello_verify_request
|
||||
@@ -216,6 +219,7 @@ SSL,reason,151,EVP_DIGESTSIGNFINAL_FAILED
|
||||
SSL,reason,152,EVP_DIGESTSIGNINIT_FAILED
|
||||
SSL,reason,153,EXCESSIVE_MESSAGE_SIZE
|
||||
SSL,reason,154,EXTRA_DATA_IN_MESSAGE
|
||||
SSL,reason,271,FRAGMENT_MISMATCH
|
||||
SSL,reason,155,GOT_A_FIN_BEFORE_A_CCS
|
||||
SSL,reason,156,GOT_CHANNEL_ID_BEFORE_A_CCS
|
||||
SSL,reason,157,GOT_NEXT_PROTO_BEFORE_A_CCS
|
||||
|
||||
@@ -3,6 +3,7 @@ X509,function,101,ASN1_item_sign_ctx
|
||||
X509,function,102,ASN1_item_verify
|
||||
X509,function,103,NETSCAPE_SPKI_b64_decode
|
||||
X509,function,104,NETSCAPE_SPKI_b64_encode
|
||||
X509,function,158,PKCS7_get_CRLs
|
||||
X509,function,105,PKCS7_get_certificates
|
||||
X509,function,106,X509_ATTRIBUTE_create_by_NID
|
||||
X509,function,107,X509_ATTRIBUTE_create_by_OBJ
|
||||
@@ -52,6 +53,7 @@ X509,function,150,get_cert_by_subject
|
||||
X509,function,151,i2d_DSA_PUBKEY
|
||||
X509,function,152,i2d_EC_PUBKEY
|
||||
X509,function,153,i2d_RSA_PUBKEY
|
||||
X509,function,157,pkcs7_parse_header
|
||||
X509,function,154,x509_name_encode
|
||||
X509,function,155,x509_name_ex_d2i
|
||||
X509,function,156,x509_name_ex_new
|
||||
@@ -78,6 +80,7 @@ X509,reason,119,NEWER_CRL_NOT_NEWER
|
||||
X509,reason,120,NOT_PKCS7_SIGNED_DATA
|
||||
X509,reason,121,NO_CERTIFICATES_INCLUDED
|
||||
X509,reason,122,NO_CERT_SET_FOR_US_TO_VERIFY
|
||||
X509,reason,136,NO_CRLS_INCLUDED
|
||||
X509,reason,123,NO_CRL_NUMBER
|
||||
X509,reason,124,PUBLIC_KEY_DECODE_ERROR
|
||||
X509,reason,125,PUBLIC_KEY_ENCODE_ERROR
|
||||
|
||||
@@ -24,13 +24,13 @@ add_library(
|
||||
add_executable(
|
||||
evp_test
|
||||
|
||||
evp_test.c
|
||||
evp_test.cc
|
||||
)
|
||||
|
||||
add_executable(
|
||||
pbkdf_test
|
||||
|
||||
pbkdf_test.c
|
||||
pbkdf_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(evp_test crypto)
|
||||
|
||||
@@ -65,9 +65,8 @@
|
||||
/* md_begin_digset is a callback from the |EVP_MD_CTX| code that is called when
|
||||
* a new digest is begun. */
|
||||
static int md_begin_digest(EVP_MD_CTX *ctx) {
|
||||
int r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
|
||||
return r > 0 || r == -2;
|
||||
return EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
|
||||
}
|
||||
|
||||
static const struct evp_md_pctx_ops md_pctx_ops = {
|
||||
@@ -98,24 +97,24 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
|
||||
if (is_verify) {
|
||||
if (ctx->pctx->pmeth->verifyctx_init) {
|
||||
if (ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx) <= 0) {
|
||||
if (!ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
ctx->pctx->operation = EVP_PKEY_OP_VERIFYCTX;
|
||||
} else if (EVP_PKEY_verify_init(ctx->pctx) <= 0) {
|
||||
} else if (!EVP_PKEY_verify_init(ctx->pctx)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (ctx->pctx->pmeth->signctx_init) {
|
||||
if (ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx) <= 0) {
|
||||
if (!ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
ctx->pctx->operation = EVP_PKEY_OP_SIGNCTX;
|
||||
} else if (EVP_PKEY_sign_init(ctx->pctx) <= 0) {
|
||||
} else if (!EVP_PKEY_sign_init(ctx->pctx)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (EVP_PKEY_CTX_set_signature_md(ctx->pctx, type) <= 0) {
|
||||
if (!EVP_PKEY_CTX_set_signature_md(ctx->pctx, type)) {
|
||||
return 0;
|
||||
}
|
||||
if (pctx) {
|
||||
|
||||
+5
-11
@@ -109,12 +109,6 @@ void EVP_PKEY_free(EVP_PKEY *pkey) {
|
||||
}
|
||||
|
||||
free_it(pkey);
|
||||
if (pkey->attributes) {
|
||||
/* TODO(fork): layering: X509_ATTRIBUTE_free is an X.509 function. In
|
||||
* practice this path isn't called but should be removed in the future. */
|
||||
/*sk_X509_ATTRIBUTE_pop_free(pkey->attributes, X509_ATTRIBUTE_free);*/
|
||||
assert(0);
|
||||
}
|
||||
OPENSSL_free(pkey);
|
||||
}
|
||||
|
||||
@@ -237,11 +231,11 @@ EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const uint8_t *mac_key,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_keygen_init(mac_ctx) <= 0 ||
|
||||
EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
|
||||
EVP_PKEY_CTRL_SET_MAC_KEY, mac_key_len,
|
||||
(uint8_t *)mac_key) <= 0 ||
|
||||
EVP_PKEY_keygen(mac_ctx, &ret) <= 0) {
|
||||
if (!EVP_PKEY_keygen_init(mac_ctx) ||
|
||||
!EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
|
||||
EVP_PKEY_CTRL_SET_MAC_KEY, mac_key_len,
|
||||
(uint8_t *)mac_key) ||
|
||||
!EVP_PKEY_keygen(mac_ctx, &ret)) {
|
||||
ret = NULL;
|
||||
goto merr;
|
||||
}
|
||||
|
||||
+5
-12
@@ -212,32 +212,25 @@ void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) { return ctx->app_data; }
|
||||
|
||||
int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
|
||||
int p1, void *p2) {
|
||||
int ret;
|
||||
if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if (keytype != -1 && ctx->pmeth->pkey_id != keytype) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_NO_OPERATION_SET);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (optype != -1 && !(ctx->operation & optype)) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_INVALID_OPERATION);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
|
||||
|
||||
if (ret == -2) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ctx->pmeth->ctrl(ctx, cmd, p1, p2);
|
||||
}
|
||||
|
||||
int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/crypto.h>
|
||||
@@ -25,9 +27,11 @@
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "../test/scoped_types.h"
|
||||
|
||||
/* kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
|
||||
* should never use this key anywhere but in an example. */
|
||||
|
||||
// kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
|
||||
// should never use this key anywhere but in an example.
|
||||
static const uint8_t kExampleRSAKeyDER[] = {
|
||||
0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf8,
|
||||
0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5, 0xb4, 0x59,
|
||||
@@ -98,8 +102,8 @@ static const uint8_t kSignature[] = {
|
||||
0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42,
|
||||
};
|
||||
|
||||
/* kExamplePSSCert is an example self-signed certificate, signed with
|
||||
* kExampleRSAKeyDER using RSA-PSS with default hash functions. */
|
||||
// kExamplePSSCert is an example self-signed certificate, signed with
|
||||
// kExampleRSAKeyDER using RSA-PSS with default hash functions.
|
||||
static const uint8_t kExamplePSSCert[] = {
|
||||
0x30, 0x82, 0x02, 0x62, 0x30, 0x82, 0x01, 0xc6, 0xa0, 0x03, 0x02, 0x01,
|
||||
0x02, 0x02, 0x09, 0x00, 0x8d, 0xea, 0x53, 0x24, 0xfa, 0x48, 0x87, 0xf3,
|
||||
@@ -155,8 +159,8 @@ static const uint8_t kExamplePSSCert[] = {
|
||||
0x8c, 0x16,
|
||||
};
|
||||
|
||||
/* kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
|
||||
* PrivateKeyInfo. */
|
||||
// kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
|
||||
// PrivateKeyInfo.
|
||||
static const uint8_t kExampleRSAKeyPKCS8[] = {
|
||||
0x30, 0x82, 0x02, 0x76, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
|
||||
@@ -213,8 +217,8 @@ static const uint8_t kExampleRSAKeyPKCS8[] = {
|
||||
0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
|
||||
};
|
||||
|
||||
/* kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure. */
|
||||
// kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
// structure.
|
||||
static const uint8_t kExampleECKeyDER[] = {
|
||||
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x07, 0x0f, 0x08, 0x72, 0x7a,
|
||||
0xd4, 0xa0, 0x4a, 0x9c, 0xdd, 0x59, 0xc9, 0x4d, 0x89, 0x68, 0x77, 0x08,
|
||||
@@ -229,8 +233,8 @@ static const uint8_t kExampleECKeyDER[] = {
|
||||
0xc1,
|
||||
};
|
||||
|
||||
/* kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure. The private key is equal to the order and will fail to import */
|
||||
// kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
// structure. The private key is equal to the order and will fail to import.
|
||||
static const uint8_t kExampleBadECKeyDER[] = {
|
||||
0x30, 0x66, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48,
|
||||
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03,
|
||||
@@ -243,237 +247,143 @@ static const uint8_t kExampleBadECKeyDER[] = {
|
||||
0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
|
||||
};
|
||||
|
||||
static EVP_PKEY *load_example_rsa_key(void) {
|
||||
EVP_PKEY *ret = NULL;
|
||||
static ScopedEVP_PKEY LoadExampleRSAKey() {
|
||||
const uint8_t *derp = kExampleRSAKeyDER;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
RSA *rsa = NULL;
|
||||
|
||||
if (!d2i_RSAPrivateKey(&rsa, &derp, sizeof(kExampleRSAKeyDER))) {
|
||||
return NULL;
|
||||
ScopedRSA rsa(d2i_RSAPrivateKey(nullptr, &derp, sizeof(kExampleRSAKeyDER)));
|
||||
if (!rsa) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL || !EVP_PKEY_set1_RSA(pkey, rsa)) {
|
||||
goto out;
|
||||
ScopedEVP_PKEY pkey(EVP_PKEY_new());
|
||||
if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ret = pkey;
|
||||
pkey = NULL;
|
||||
|
||||
out:
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (rsa) {
|
||||
RSA_free(rsa);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return pkey;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestSignInit(void) {
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
uint8_t *sig = NULL;
|
||||
static bool TestEVP_DigestSignInit(void) {
|
||||
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
|
||||
ScopedEVP_MD_CTX md_ctx;
|
||||
if (!pkey ||
|
||||
!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
|
||||
!EVP_DigestSignUpdate(md_ctx.get(), kMsg, sizeof(kMsg))) {
|
||||
return false;
|
||||
}
|
||||
// Determine the size of the signature.
|
||||
size_t sig_len = 0;
|
||||
EVP_MD_CTX md_ctx, md_ctx_verify;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
EVP_MD_CTX_init(&md_ctx_verify);
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestSignUpdate(&md_ctx, kMsg, sizeof(kMsg))) {
|
||||
goto out;
|
||||
if (!EVP_DigestSignFinal(md_ctx.get(), NULL, &sig_len)) {
|
||||
return false;
|
||||
}
|
||||
/* Determine the size of the signature. */
|
||||
if (!EVP_DigestSignFinal(&md_ctx, NULL, &sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
/* Sanity check for testing. */
|
||||
if (sig_len != EVP_PKEY_size(pkey)) {
|
||||
// Sanity check for testing.
|
||||
if (sig_len != (size_t)EVP_PKEY_size(pkey.get())) {
|
||||
fprintf(stderr, "sig_len mismatch\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
sig = malloc(sig_len);
|
||||
if (sig == NULL || !EVP_DigestSignFinal(&md_ctx, sig, &sig_len)) {
|
||||
goto out;
|
||||
std::vector<uint8_t> sig;
|
||||
sig.resize(sig_len);
|
||||
if (!EVP_DigestSignFinal(md_ctx.get(), bssl::vector_data(&sig), &sig_len)) {
|
||||
return false;
|
||||
}
|
||||
sig.resize(sig_len);
|
||||
|
||||
// Ensure that the signature round-trips.
|
||||
md_ctx.Reset();
|
||||
if (!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
|
||||
!EVP_DigestVerifyUpdate(md_ctx.get(), kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(md_ctx.get(), bssl::vector_data(&sig), sig_len)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ensure that the signature round-trips. */
|
||||
if (!EVP_DigestVerifyInit(&md_ctx_verify, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(&md_ctx_verify, kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(&md_ctx_verify, sig, sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
BIO_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
EVP_MD_CTX_cleanup(&md_ctx_verify);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (sig) {
|
||||
free(sig);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestVerifyInit(void) {
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX md_ctx;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestVerifyInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(&md_ctx, kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(&md_ctx, kSignature, sizeof(kSignature))) {
|
||||
goto out;
|
||||
static bool TestEVP_DigestVerifyInit(void) {
|
||||
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
|
||||
ScopedEVP_MD_CTX md_ctx;
|
||||
if (!pkey ||
|
||||
!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL,
|
||||
pkey.get()) ||
|
||||
!EVP_DigestVerifyUpdate(md_ctx.get(), kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(md_ctx.get(), kSignature, sizeof(kSignature))) {
|
||||
return false;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
BIO_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* test_algorithm_roundtrip signs a message using an already-initialized
|
||||
* |md_ctx|, sampling the AlgorithmIdentifier. It then uses |pkey| and the
|
||||
* AlgorithmIdentifier to verify the signature. */
|
||||
static int test_algorithm_roundtrip(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) {
|
||||
int ret = 0;
|
||||
uint8_t *sig = NULL;
|
||||
size_t sig_len = 0;
|
||||
EVP_MD_CTX md_ctx_verify;
|
||||
X509_ALGOR *algor = NULL;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx_verify);
|
||||
|
||||
// TestAlgorithmRoundtrip signs a message using an already-initialized
|
||||
// |md_ctx|, sampling the AlgorithmIdentifier. It then uses |pkey| and the
|
||||
// AlgorithmIdentifier to verify the signature.
|
||||
static bool TestAlgorithmRoundtrip(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) {
|
||||
if (!EVP_DigestSignUpdate(md_ctx, kMsg, sizeof(kMsg))) {
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Save the algorithm. */
|
||||
algor = X509_ALGOR_new();
|
||||
if (algor == NULL || !EVP_DigestSignAlgorithm(md_ctx, algor)) {
|
||||
goto out;
|
||||
// Save the algorithm.
|
||||
ScopedX509_ALGOR algor(X509_ALGOR_new());
|
||||
if (!algor || !EVP_DigestSignAlgorithm(md_ctx, algor.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Determine the size of the signature. */
|
||||
// Determine the size of the signature.
|
||||
size_t sig_len = 0;
|
||||
if (!EVP_DigestSignFinal(md_ctx, NULL, &sig_len)) {
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
/* Sanity check for testing. */
|
||||
if (sig_len != EVP_PKEY_size(pkey)) {
|
||||
// Sanity check for testing.
|
||||
if (sig_len != (size_t)EVP_PKEY_size(pkey)) {
|
||||
fprintf(stderr, "sig_len mismatch\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
sig = malloc(sig_len);
|
||||
if (sig == NULL || !EVP_DigestSignFinal(md_ctx, sig, &sig_len)) {
|
||||
goto out;
|
||||
std::vector<uint8_t> sig;
|
||||
sig.resize(sig_len);
|
||||
if (!EVP_DigestSignFinal(md_ctx, bssl::vector_data(&sig), &sig_len)) {
|
||||
return false;
|
||||
}
|
||||
sig.resize(sig_len);
|
||||
|
||||
// Ensure that the signature round-trips.
|
||||
ScopedEVP_MD_CTX md_ctx_verify;
|
||||
if (!EVP_DigestVerifyInitFromAlgorithm(md_ctx_verify.get(), algor.get(),
|
||||
pkey) ||
|
||||
!EVP_DigestVerifyUpdate(md_ctx_verify.get(), kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(md_ctx_verify.get(), bssl::vector_data(&sig),
|
||||
sig_len)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ensure that the signature round-trips. */
|
||||
if (!EVP_DigestVerifyInitFromAlgorithm(&md_ctx_verify, algor, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(&md_ctx_verify, kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(&md_ctx_verify, sig, sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
EVP_MD_CTX_cleanup(&md_ctx_verify);
|
||||
if (sig) {
|
||||
free(sig);
|
||||
}
|
||||
if (algor) {
|
||||
X509_ALGOR_free(algor);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestSignAlgorithm(void) {
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX md_ctx;
|
||||
EVP_PKEY_CTX *pkey_ctx;
|
||||
static bool TestEVP_DigestSignAlgorithm(void) {
|
||||
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Test a simple AlgorithmIdentifier. */
|
||||
if (!EVP_DigestSignInit(&md_ctx, &pkey_ctx, EVP_sha256(), NULL, pkey) ||
|
||||
!test_algorithm_roundtrip(&md_ctx, pkey)) {
|
||||
// Test a simple AlgorithmIdentifier.
|
||||
ScopedEVP_MD_CTX md_ctx;
|
||||
if (!pkey ||
|
||||
!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
|
||||
!TestAlgorithmRoundtrip(md_ctx.get(), pkey.get())) {
|
||||
fprintf(stderr, "RSA with SHA-256 failed\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
/* Test RSA-PSS with custom parameters. */
|
||||
if (!EVP_DigestSignInit(&md_ctx, &pkey_ctx, EVP_sha256(), NULL, pkey) ||
|
||||
EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1 ||
|
||||
EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512()) != 1 ||
|
||||
!test_algorithm_roundtrip(&md_ctx, pkey)) {
|
||||
// Test RSA-PSS with custom parameters.
|
||||
md_ctx.Reset();
|
||||
EVP_PKEY_CTX *pkey_ctx;
|
||||
if (!EVP_DigestSignInit(md_ctx.get(), &pkey_ctx, EVP_sha256(), NULL,
|
||||
pkey.get()) ||
|
||||
!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
|
||||
!EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512()) ||
|
||||
!TestAlgorithmRoundtrip(md_ctx.get(), pkey.get())) {
|
||||
fprintf(stderr, "RSA-PSS failed\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
BIO_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestVerifyInitFromAlgorithm(void) {
|
||||
int ret = 0;
|
||||
static bool TestEVP_DigestVerifyInitFromAlgorithm(void) {
|
||||
CBS cert, cert_body, tbs_cert, algorithm, signature;
|
||||
uint8_t padding;
|
||||
X509_ALGOR *algor = NULL;
|
||||
const uint8_t *derp;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX md_ctx;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
CBS_init(&cert, kExamplePSSCert, sizeof(kExamplePSSCert));
|
||||
if (!CBS_get_asn1(&cert, &cert_body, CBS_ASN1_SEQUENCE) ||
|
||||
CBS_len(&cert) != 0 ||
|
||||
@@ -482,158 +392,126 @@ static int test_EVP_DigestVerifyInitFromAlgorithm(void) {
|
||||
!CBS_get_asn1(&cert_body, &signature, CBS_ASN1_BITSTRING) ||
|
||||
CBS_len(&cert_body) != 0) {
|
||||
fprintf(stderr, "Failed to parse certificate\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Signatures are BIT STRINGs, but they have are multiple of 8 bytes, so the
|
||||
leading phase byte is just a zero. */
|
||||
// Signatures are BIT STRINGs, but they have are multiple of 8 bytes, so the
|
||||
// leading phase byte is just a zero.
|
||||
uint8_t padding;
|
||||
if (!CBS_get_u8(&signature, &padding) || padding != 0) {
|
||||
fprintf(stderr, "Invalid signature padding\n");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
derp = CBS_data(&algorithm);
|
||||
if (!d2i_X509_ALGOR(&algor, &derp, CBS_len(&algorithm)) ||
|
||||
derp != CBS_data(&algorithm) + CBS_len(&algorithm)) {
|
||||
const uint8_t *derp = CBS_data(&algorithm);
|
||||
ScopedX509_ALGOR algor(d2i_X509_ALGOR(NULL, &derp, CBS_len(&algorithm)));
|
||||
if (!algor || derp != CBS_data(&algorithm) + CBS_len(&algorithm)) {
|
||||
fprintf(stderr, "Failed to parse algorithm\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestVerifyInitFromAlgorithm(&md_ctx, algor, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(&md_ctx, CBS_data(&tbs_cert),
|
||||
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
|
||||
ScopedEVP_MD_CTX md_ctx;
|
||||
if (!pkey ||
|
||||
!EVP_DigestVerifyInitFromAlgorithm(md_ctx.get(), algor.get(),
|
||||
pkey.get()) ||
|
||||
!EVP_DigestVerifyUpdate(md_ctx.get(), CBS_data(&tbs_cert),
|
||||
CBS_len(&tbs_cert)) ||
|
||||
!EVP_DigestVerifyFinal(&md_ctx, CBS_data(&signature),
|
||||
!EVP_DigestVerifyFinal(md_ctx.get(), CBS_data(&signature),
|
||||
CBS_len(&signature))) {
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
BIO_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (algor != NULL) {
|
||||
X509_ALGOR_free(algor);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_d2i_AutoPrivateKey(const uint8_t *input, size_t input_len,
|
||||
static bool Testd2i_AutoPrivateKey(const uint8_t *input, size_t input_len,
|
||||
int expected_id) {
|
||||
int ret = 0;
|
||||
const uint8_t *p;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p = input;
|
||||
pkey = d2i_AutoPrivateKey(NULL, &p, input_len);
|
||||
if (pkey == NULL || p != input + input_len) {
|
||||
const uint8_t *p = input;
|
||||
ScopedEVP_PKEY pkey(d2i_AutoPrivateKey(NULL, &p, input_len));
|
||||
if (!pkey || p != input + input_len) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey failed\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_id(pkey) != expected_id) {
|
||||
if (EVP_PKEY_id(pkey.get()) != expected_id) {
|
||||
fprintf(stderr, "Did not decode expected type\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
if (!ret) {
|
||||
BIO_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
if (pkey != NULL) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tests loading a bad key in PKCS8 format */
|
||||
static int test_EVP_PKCS82PKEY(void) {
|
||||
int ret = 0;
|
||||
// TestEVP_PKCS82PKEY tests loading a bad key in PKCS8 format.
|
||||
static bool TestEVP_PKCS82PKEY(void) {
|
||||
const uint8_t *derp = kExampleBadECKeyDER;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER));
|
||||
|
||||
ScopedPKCS8_PRIV_KEY_INFO p8inf(
|
||||
d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER)));
|
||||
if (!p8inf || derp != kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER)) {
|
||||
fprintf(stderr, "Failed to parse key\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
|
||||
pkey = EVP_PKCS82PKEY(p8inf);
|
||||
ScopedEVP_PKEY pkey(EVP_PKCS82PKEY(p8inf.get()));
|
||||
if (pkey) {
|
||||
fprintf(stderr, "Imported invalid EC key\n");
|
||||
goto done;
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
if (p8inf != NULL) {
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
}
|
||||
|
||||
if (pkey != NULL) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
CRYPTO_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
if (!test_EVP_DigestSignInit()) {
|
||||
if (!TestEVP_DigestSignInit()) {
|
||||
fprintf(stderr, "EVP_DigestSignInit failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_DigestVerifyInit()) {
|
||||
if (!TestEVP_DigestVerifyInit()) {
|
||||
fprintf(stderr, "EVP_DigestVerifyInit failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_DigestSignAlgorithm()) {
|
||||
if (!TestEVP_DigestSignAlgorithm()) {
|
||||
fprintf(stderr, "EVP_DigestSignInit failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_DigestVerifyInitFromAlgorithm()) {
|
||||
if (!TestEVP_DigestVerifyInitFromAlgorithm()) {
|
||||
fprintf(stderr, "EVP_DigestVerifyInitFromAlgorithm failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
|
||||
EVP_PKEY_RSA)) {
|
||||
if (!Testd2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
|
||||
EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyDER) failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8),
|
||||
EVP_PKEY_RSA)) {
|
||||
if (!Testd2i_AutoPrivateKey(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8),
|
||||
EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyPKCS8) failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
|
||||
EVP_PKEY_EC)) {
|
||||
if (!Testd2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
|
||||
EVP_PKEY_EC)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleECKeyDER) failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_PKCS82PKEY()) {
|
||||
fprintf(stderr, "test_EVP_PKCS82PKEY failed\n");
|
||||
if (!TestEVP_PKCS82PKEY()) {
|
||||
fprintf(stderr, "TestEVP_PKCS82PKEY failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -170,8 +170,49 @@ typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
|
||||
|
||||
#define EVP_PKEY_OP_TYPE_GEN (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN)
|
||||
|
||||
/* EVP_PKEY_CTX_ctrl performs |cmd| on |ctx|. The |keytype| and |optype|
|
||||
* arguments can be -1 to specify that any type and operation are acceptable,
|
||||
* otherwise |keytype| must match the type of |ctx| and the bits of |optype|
|
||||
* must intersect the operation flags set on |ctx|.
|
||||
*
|
||||
* The |p1| and |p2| arguments depend on the value of |cmd|.
|
||||
*
|
||||
* It returns one on success and zero on error. */
|
||||
OPENSSL_EXPORT int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
int cmd, int p1, void *p2);
|
||||
|
||||
/* EVP_PKEY_CTRL_DIGESTINIT is an internal value. It's called by
|
||||
* EVP_DigestInit_ex to signal the |EVP_PKEY| that a digest operation is
|
||||
* starting.
|
||||
*
|
||||
* TODO(davidben): This is only needed to support the deprecated HMAC |EVP_PKEY|
|
||||
* types. */
|
||||
#define EVP_PKEY_CTRL_DIGESTINIT 3
|
||||
|
||||
/* EVP_PKEY_CTRL_PEER_KEY is called with different values of |p1|:
|
||||
* 0: Is called from |EVP_PKEY_derive_set_peer| and |p2| contains a peer key.
|
||||
* If the return value is <= 0, the key is rejected.
|
||||
* 1: Is called at the end of |EVP_PKEY_derive_set_peer| and |p2| contains a
|
||||
* peer key. If the return value is <= 0, the key is rejected.
|
||||
* 2: Is called with |p2| == NULL to test whether the peer's key was used.
|
||||
* (EC)DH always return one in this case.
|
||||
* 3: Is called with |p2| == NULL to set whether the peer's key was used.
|
||||
* (EC)DH always return one in this case. This was only used for GOST. */
|
||||
#define EVP_PKEY_CTRL_PEER_KEY 4
|
||||
|
||||
/* EVP_PKEY_CTRL_SET_MAC_KEY sets a MAC key. For example, this can be done an
|
||||
* |EVP_PKEY_CTX| prior to calling |EVP_PKEY_keygen| in order to generate an
|
||||
* HMAC |EVP_PKEY| with the given key. It returns one on success and zero on
|
||||
* error. */
|
||||
#define EVP_PKEY_CTRL_SET_MAC_KEY 5
|
||||
|
||||
/* EVP_PKEY_ALG_CTRL is the base value from which key-type specific ctrl
|
||||
* commands are numbered. */
|
||||
#define EVP_PKEY_ALG_CTRL 0x1000
|
||||
|
||||
#define EVP_PKEY_CTRL_MD 1
|
||||
#define EVP_PKEY_CTRL_GET_MD 2
|
||||
|
||||
#define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
|
||||
#define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 2)
|
||||
#define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 3)
|
||||
@@ -185,6 +226,8 @@ typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
|
||||
#define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 11)
|
||||
#define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
|
||||
|
||||
#define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
|
||||
|
||||
struct evp_pkey_ctx_st {
|
||||
/* Method associated with this operation */
|
||||
const EVP_PKEY_METHOD *pmeth;
|
||||
|
||||
+2
-1
@@ -241,7 +241,8 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_ec_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-11
@@ -142,23 +142,14 @@ static EC_KEY *eckey_type2param(int ptype, void *pval) {
|
||||
}
|
||||
} else if (ptype == V_ASN1_OBJECT) {
|
||||
ASN1_OBJECT *poid = pval;
|
||||
EC_GROUP *group;
|
||||
|
||||
/* type == V_ASN1_OBJECT => the parameters are given
|
||||
* by an asn1 OID */
|
||||
eckey = EC_KEY_new();
|
||||
eckey = EC_KEY_new_by_curve_name(OBJ_obj2nid(poid));
|
||||
if (eckey == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, eckey_type2param, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));
|
||||
if (group == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (EC_KEY_set_group(eckey, group) == 0) {
|
||||
goto err;
|
||||
}
|
||||
EC_GROUP_free(group);
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(EVP, eckey_type2param, EVP_R_DECODE_ERROR);
|
||||
goto err;
|
||||
@@ -382,7 +373,11 @@ static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
|
||||
static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
|
||||
const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
|
||||
*group_b = EC_KEY_get0_group(b->pkey.ec);
|
||||
return EC_GROUP_cmp(group_a, group_b);
|
||||
if (EC_GROUP_cmp(group_a, group_b, NULL) != 0) {
|
||||
/* mismatch */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void int_ec_free(EVP_PKEY *pkey) { EC_KEY_free(pkey->pkey.ec); }
|
||||
|
||||
+2
-1
@@ -204,7 +204,8 @@ static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
break;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_hmac_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
+27
-15
@@ -55,10 +55,12 @@
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buf.h>
|
||||
#include <openssl/bytestring.h>
|
||||
#include <openssl/digest.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
@@ -369,7 +371,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
0 == (ctx->operation & EVP_PKEY_OP_TYPE_CRYPT))) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl,
|
||||
EVP_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if ((p1 == RSA_PKCS1_PSS_PADDING || p1 == RSA_PKCS1_OAEP_PADDING) &&
|
||||
rctx->md == NULL) {
|
||||
@@ -386,13 +388,13 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
|
||||
if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PSS_SALTLEN);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if (type == EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN) {
|
||||
*(int *)p2 = rctx->saltlen;
|
||||
} else {
|
||||
if (p1 < -2) {
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
rctx->saltlen = p1;
|
||||
}
|
||||
@@ -401,14 +403,14 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
|
||||
if (p1 < 256) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_KEYBITS);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
rctx->nbits = p1;
|
||||
return 1;
|
||||
|
||||
case EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP:
|
||||
if (!p2) {
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
BN_free(rctx->pub_exp);
|
||||
rctx->pub_exp = p2;
|
||||
@@ -418,7 +420,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
case EVP_PKEY_CTRL_GET_RSA_OAEP_MD:
|
||||
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if (type == EVP_PKEY_CTRL_GET_RSA_OAEP_MD) {
|
||||
*(const EVP_MD **)p2 = rctx->md;
|
||||
@@ -443,7 +445,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING &&
|
||||
rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_MGF1_MD);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if (type == EVP_PKEY_CTRL_GET_RSA_MGF1_MD) {
|
||||
if (rctx->mgf1md) {
|
||||
@@ -459,7 +461,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
case EVP_PKEY_CTRL_RSA_OAEP_LABEL:
|
||||
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
if (rctx->oaep_label) {
|
||||
OPENSSL_free(rctx->oaep_label);
|
||||
@@ -478,16 +480,17 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
case EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL:
|
||||
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
*(uint8_t **)p2 = rctx->oaep_label;
|
||||
return rctx->oaep_labellen;
|
||||
CBS_init((CBS *)p2, rctx->oaep_label, rctx->oaep_labellen);
|
||||
return 1;
|
||||
|
||||
case EVP_PKEY_CTRL_DIGESTINIT:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,7 +587,7 @@ int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, const uint8_t *label,
|
||||
size_t label_len) {
|
||||
int label_len_int = label_len;
|
||||
if (((size_t) label_len_int) != label_len) {
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
|
||||
@@ -594,6 +597,15 @@ int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, const uint8_t *label,
|
||||
|
||||
int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx,
|
||||
const uint8_t **out_label) {
|
||||
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
|
||||
EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *) out_label);
|
||||
CBS label;
|
||||
if (!EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
|
||||
EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, &label)) {
|
||||
return -1;
|
||||
}
|
||||
if (CBS_len(&label) > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_get0_rsa_oaep_label, ERR_R_OVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
*out_label = CBS_data(&label);
|
||||
return (int)CBS_len(&label);
|
||||
}
|
||||
|
||||
@@ -521,8 +521,8 @@ static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx) {
|
||||
EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
|
||||
int saltlen, rv = 0;
|
||||
|
||||
if (EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) <= 0 ||
|
||||
EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) <= 0 ||
|
||||
if (!EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) ||
|
||||
!EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) ||
|
||||
!EVP_PKEY_CTX_get_rsa_pss_saltlen(pkctx, &saltlen)) {
|
||||
goto err;
|
||||
}
|
||||
@@ -625,9 +625,9 @@ static int rsa_pss_to_ctx(EVP_MD_CTX *ctx, X509_ALGOR *sigalg, EVP_PKEY *pkey) {
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyInit(ctx, &pkctx, md, NULL, pkey) ||
|
||||
EVP_PKEY_CTX_set_rsa_padding(pkctx, RSA_PKCS1_PSS_PADDING) <= 0 ||
|
||||
EVP_PKEY_CTX_set_rsa_pss_saltlen(pkctx, saltlen) <= 0 ||
|
||||
EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md) <= 0) {
|
||||
!EVP_PKEY_CTX_set_rsa_padding(pkctx, RSA_PKCS1_PSS_PADDING) ||
|
||||
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkctx, saltlen) ||
|
||||
!EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@ static evp_digest_sign_algorithm_result_t rsa_digest_sign_algorithm(
|
||||
EVP_MD_CTX *ctx, X509_ALGOR *sigalg) {
|
||||
int pad_mode;
|
||||
EVP_PKEY_CTX *pkctx = ctx->pctx;
|
||||
if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0) {
|
||||
if (!EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode)) {
|
||||
return EVP_DIGEST_SIGN_ALGORITHM_ERROR;
|
||||
}
|
||||
if (pad_mode == RSA_PKCS1_PSS_PADDING) {
|
||||
|
||||
@@ -22,17 +22,16 @@
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
/* Prints out the data buffer as a sequence of hex bytes */
|
||||
static void print_data_hex(const void *data, size_t len) {
|
||||
size_t i;
|
||||
for (i = 0; i < len; ++i) {
|
||||
// Prints out the data buffer as a sequence of hex bytes.
|
||||
static void PrintDataHex(const void *data, size_t len) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
fprintf(stderr, "%02x", (int)((const uint8_t *)data)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper for testing that PBKDF2 derives the expected key from the given
|
||||
* inputs. Returns 1 on success, 0 otherwise. */
|
||||
static int test_PBKDF2(const void *password, size_t password_len,
|
||||
// Helper for testing that PBKDF2 derives the expected key from the given
|
||||
// inputs. Returns 1 on success, 0 otherwise.
|
||||
static bool TestPBKDF2(const void *password, size_t password_len,
|
||||
const void *salt, size_t salt_len, unsigned iterations,
|
||||
const EVP_MD *digest, size_t key_len,
|
||||
const uint8_t *expected_key) {
|
||||
@@ -40,64 +39,65 @@ static int test_PBKDF2(const void *password, size_t password_len,
|
||||
|
||||
if (key_len > sizeof(key)) {
|
||||
fprintf(stderr, "Output buffer is not large enough.\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PKCS5_PBKDF2_HMAC(password, password_len, salt, salt_len, iterations,
|
||||
digest, key_len, key)) {
|
||||
if (!PKCS5_PBKDF2_HMAC((const char *)password, password_len,
|
||||
(const uint8_t *)salt, salt_len, iterations, digest,
|
||||
key_len, key)) {
|
||||
fprintf(stderr, "Call to PKCS5_PBKDF2_HMAC failed\n");
|
||||
BIO_print_errors_fp(stderr);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(key, expected_key, key_len) != 0) {
|
||||
fprintf(stderr, "Resulting key material does not match expectation\n");
|
||||
fprintf(stderr, "Expected:\n ");
|
||||
print_data_hex(expected_key, key_len);
|
||||
PrintDataHex(expected_key, key_len);
|
||||
fprintf(stderr, "\nActual:\n ");
|
||||
print_data_hex(key, key_len);
|
||||
PrintDataHex(key, key_len);
|
||||
fprintf(stderr, "\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tests deriving a key using an empty password (specified both as NULL and as
|
||||
* non-NULL). Note that NULL has special meaning to HMAC initialization. */
|
||||
static int test_empty_password(void) {
|
||||
// Tests deriving a key using an empty password (specified both as NULL and as
|
||||
// non-NULL). Note that NULL has special meaning to HMAC initialization.
|
||||
static bool TestEmptyPassword() {
|
||||
const uint8_t kKey[] = {0xa3, 0x3d, 0xdd, 0xc3, 0x04, 0x78, 0x18,
|
||||
0x55, 0x15, 0x31, 0x1f, 0x87, 0x52, 0x89,
|
||||
0x5d, 0x36, 0xea, 0x43, 0x63, 0xa2};
|
||||
|
||||
if (!test_PBKDF2(NULL, 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey) ||
|
||||
!test_PBKDF2("", 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey)) {
|
||||
return 0;
|
||||
if (!TestPBKDF2(NULL, 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey) ||
|
||||
!TestPBKDF2("", 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tests deriving a key using an empty salt. Note that the expectation was
|
||||
* generated using OpenSSL itself, and hence is not verified. */
|
||||
static int test_empty_salt(void) {
|
||||
// Tests deriving a key using an empty salt. Note that the expectation was
|
||||
// generated using OpenSSL itself, and hence is not verified.
|
||||
static bool TestEmptySalt() {
|
||||
const uint8_t kKey[] = {0x8b, 0xc2, 0xf9, 0x16, 0x7a, 0x81, 0xcd, 0xcf,
|
||||
0xad, 0x12, 0x35, 0xcd, 0x90, 0x47, 0xf1, 0x13,
|
||||
0x62, 0x71, 0xc1, 0xf9, 0x78, 0xfc, 0xfc, 0xb3,
|
||||
0x5e, 0x22, 0xdb, 0xea, 0xfa, 0x46, 0x34, 0xf6};
|
||||
|
||||
if (!test_PBKDF2("password", 8, NULL, 0, 2, EVP_sha256(), sizeof(kKey),
|
||||
kKey) ||
|
||||
!test_PBKDF2("password", 8, "", 0, 2, EVP_sha256(), sizeof(kKey), kKey)) {
|
||||
return 0;
|
||||
if (!TestPBKDF2("password", 8, NULL, 0, 2, EVP_sha256(), sizeof(kKey),
|
||||
kKey) ||
|
||||
!TestPBKDF2("password", 8, "", 0, 2, EVP_sha256(), sizeof(kKey), kKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Exercises test vectors taken from https://tools.ietf.org/html/rfc6070.
|
||||
* Note that each of these test vectors uses SHA-1 as the digest. */
|
||||
static int test_rfc6070_vectors(void) {
|
||||
// Exercises test vectors taken from https://tools.ietf.org/html/rfc6070.
|
||||
// Note that each of these test vectors uses SHA-1 as the digest.
|
||||
static bool TestRFC6070Vectors() {
|
||||
const uint8_t kKey1[] = {0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e,
|
||||
0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60,
|
||||
0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6};
|
||||
@@ -107,29 +107,29 @@ static int test_rfc6070_vectors(void) {
|
||||
const uint8_t kKey3[] = {0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
|
||||
0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3};
|
||||
|
||||
if (!test_PBKDF2("password", 8, "salt", 4, 1, EVP_sha1(), sizeof(kKey1),
|
||||
kKey1) ||
|
||||
!test_PBKDF2("password", 8, "salt", 4, 2, EVP_sha1(), sizeof(kKey2),
|
||||
kKey2) ||
|
||||
!test_PBKDF2("pass\0word", 9, "sa\0lt", 5, 4096, EVP_sha1(),
|
||||
sizeof(kKey3), kKey3)) {
|
||||
return 0;
|
||||
if (!TestPBKDF2("password", 8, "salt", 4, 1, EVP_sha1(), sizeof(kKey1),
|
||||
kKey1) ||
|
||||
!TestPBKDF2("password", 8, "salt", 4, 2, EVP_sha1(), sizeof(kKey2),
|
||||
kKey2) ||
|
||||
!TestPBKDF2("pass\0word", 9, "sa\0lt", 5, 4096, EVP_sha1(),
|
||||
sizeof(kKey3), kKey3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Tests key derivation using SHA-2 digests */
|
||||
static int test_sha2(void) {
|
||||
/* This test was taken from:
|
||||
* http://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors */
|
||||
// Tests key derivation using SHA-2 digests.
|
||||
static bool TestSHA2() {
|
||||
// This test was taken from:
|
||||
// http://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors.
|
||||
const uint8_t kKey1[] = {0xae, 0x4d, 0x0c, 0x95, 0xaf, 0x6b, 0x46, 0xd3,
|
||||
0x2d, 0x0a, 0xdf, 0xf9, 0x28, 0xf0, 0x6d, 0xd0,
|
||||
0x2a, 0x30, 0x3f, 0x8e, 0xf3, 0xc2, 0x51, 0xdf,
|
||||
0xd6, 0xe2, 0xd8, 0x5a, 0x95, 0x47, 0x4c, 0x43};
|
||||
|
||||
/* This test was taken from:
|
||||
* http://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors */
|
||||
// This test was taken from:
|
||||
// http://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors.
|
||||
const uint8_t kKey2[] = {
|
||||
0x8c, 0x05, 0x11, 0xf4, 0xc6, 0xe5, 0x97, 0xc6, 0xac, 0x63, 0x15,
|
||||
0xd8, 0xf0, 0x36, 0x2e, 0x22, 0x5f, 0x3c, 0x50, 0x14, 0x95, 0xba,
|
||||
@@ -138,38 +138,38 @@ static int test_sha2(void) {
|
||||
0x75, 0xae, 0xfe, 0x30, 0x22, 0x5c, 0x58, 0x3a, 0x18, 0x6c, 0xd8,
|
||||
0x2b, 0xd4, 0xda, 0xea, 0x97, 0x24, 0xa3, 0xd3, 0xb8};
|
||||
|
||||
if (!test_PBKDF2("password", 8, "salt", 4, 2, EVP_sha256(), sizeof(kKey1),
|
||||
kKey1) ||
|
||||
!test_PBKDF2("passwordPASSWORDpassword", 24,
|
||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096,
|
||||
EVP_sha512(), sizeof(kKey2), kKey2)) {
|
||||
return 0;
|
||||
if (!TestPBKDF2("password", 8, "salt", 4, 2, EVP_sha256(), sizeof(kKey1),
|
||||
kKey1) ||
|
||||
!TestPBKDF2("passwordPASSWORDpassword", 24,
|
||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096,
|
||||
EVP_sha512(), sizeof(kKey2), kKey2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
CRYPTO_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
if (!test_empty_password()) {
|
||||
fprintf(stderr, "test_empty_password failed\n");
|
||||
if (!TestEmptyPassword()) {
|
||||
fprintf(stderr, "TestEmptyPassword failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_empty_salt()) {
|
||||
fprintf(stderr, "test_empty_salt failed\n");
|
||||
if (!TestEmptySalt()) {
|
||||
fprintf(stderr, "TestEmptySalt failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_rfc6070_vectors()) {
|
||||
fprintf(stderr, "test_rfc6070_vectors failed\n");
|
||||
if (!TestRFC6070Vectors()) {
|
||||
fprintf(stderr, "TestRFC6070Vectors failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_sha2()) {
|
||||
fprintf(stderr, "test_sha2 failed\n");
|
||||
if (!TestSHA2()) {
|
||||
fprintf(stderr, "TestSHA2 failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
+5
-5
@@ -92,9 +92,9 @@ int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig,
|
||||
EVP_MD_CTX_cleanup(&tmp_ctx);
|
||||
|
||||
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||
if (!pkctx || EVP_PKEY_sign_init(pkctx) <= 0 ||
|
||||
EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0 ||
|
||||
EVP_PKEY_sign(pkctx, sig, &sig_len, m, m_len) <= 0) {
|
||||
if (!pkctx || !EVP_PKEY_sign_init(pkctx) ||
|
||||
!EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) ||
|
||||
!EVP_PKEY_sign(pkctx, sig, &sig_len, m, m_len)) {
|
||||
goto out;
|
||||
}
|
||||
*out_sig_len = sig_len;
|
||||
@@ -138,8 +138,8 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, size_t sig_len,
|
||||
|
||||
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||
if (!pkctx ||
|
||||
EVP_PKEY_verify_init(pkctx) <= 0 ||
|
||||
EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0) {
|
||||
!EVP_PKEY_verify_init(pkctx) ||
|
||||
!EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest)) {
|
||||
goto out;
|
||||
}
|
||||
ret = EVP_PKEY_verify(pkctx, sig, sig_len, m, m_len);
|
||||
|
||||
@@ -12,7 +12,7 @@ add_library(
|
||||
add_executable(
|
||||
hmac_test
|
||||
|
||||
hmac_test.c
|
||||
hmac_test.cc
|
||||
)
|
||||
|
||||
target_link_libraries(hmac_test crypto)
|
||||
|
||||
+28
-33
@@ -76,7 +76,7 @@ uint8_t *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
|
||||
}
|
||||
|
||||
HMAC_CTX_init(&ctx);
|
||||
if (!HMAC_Init(&ctx, key, key_len, evp_md) ||
|
||||
if (!HMAC_Init_ex(&ctx, key, key_len, evp_md, NULL) ||
|
||||
!HMAC_Update(&ctx, data, data_len) ||
|
||||
!HMAC_Final(&ctx, out, out_len)) {
|
||||
out = NULL;
|
||||
@@ -88,7 +88,6 @@ uint8_t *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
|
||||
|
||||
void HMAC_CTX_init(HMAC_CTX *ctx) {
|
||||
ctx->md = NULL;
|
||||
ctx->key_length = 0;
|
||||
EVP_MD_CTX_init(&ctx->i_ctx);
|
||||
EVP_MD_CTX_init(&ctx->o_ctx);
|
||||
EVP_MD_CTX_init(&ctx->md_ctx);
|
||||
@@ -103,48 +102,44 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx) {
|
||||
|
||||
int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,
|
||||
const EVP_MD *md, ENGINE *impl) {
|
||||
unsigned i, reset = 0;
|
||||
uint8_t pad[HMAC_MAX_MD_CBLOCK];
|
||||
|
||||
if (md != NULL) {
|
||||
if (ctx->md == NULL && key == NULL && ctx->key_length == 0) {
|
||||
/* TODO(eroman): Change the API instead of this hack.
|
||||
* If a key hasn't yet been assigned to the context, then default to using
|
||||
* an all-zero key. This is to work around callers of
|
||||
* HMAC_Init_ex(key=NULL, key_len=0) intending to set a zero-length key.
|
||||
* Rather than resulting in uninitialized memory reads, it will
|
||||
* predictably use a zero key. */
|
||||
memset(ctx->key, 0, sizeof(ctx->key));
|
||||
}
|
||||
reset = 1;
|
||||
ctx->md = md;
|
||||
} else {
|
||||
if (md == NULL) {
|
||||
md = ctx->md;
|
||||
}
|
||||
|
||||
if (key != NULL) {
|
||||
/* If either |key| is non-NULL or |md| has changed, initialize with a new key
|
||||
* rather than rewinding the previous one.
|
||||
*
|
||||
* TODO(davidben,eroman): Passing the previous |md| with a NULL |key| is
|
||||
* ambiguous between using the empty key and reusing the previous key. There
|
||||
* exist callers which intend the latter, but the former is an awkward edge
|
||||
* case. Fix to API to avoid this. */
|
||||
if (md != ctx->md || key != NULL) {
|
||||
size_t i;
|
||||
uint8_t pad[HMAC_MAX_MD_CBLOCK];
|
||||
uint8_t key_block[HMAC_MAX_MD_CBLOCK];
|
||||
unsigned key_block_len;
|
||||
|
||||
size_t block_size = EVP_MD_block_size(md);
|
||||
reset = 1;
|
||||
assert(block_size <= sizeof(ctx->key));
|
||||
assert(block_size <= sizeof(key_block));
|
||||
if (block_size < key_len) {
|
||||
/* Long keys are hashed. */
|
||||
if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl) ||
|
||||
!EVP_DigestUpdate(&ctx->md_ctx, key, key_len) ||
|
||||
!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key, &ctx->key_length)) {
|
||||
!EVP_DigestFinal_ex(&ctx->md_ctx, key_block, &key_block_len)) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
assert(key_len >= 0 && key_len <= sizeof(ctx->key));
|
||||
memcpy(ctx->key, key, key_len);
|
||||
ctx->key_length = key_len;
|
||||
assert(key_len >= 0 && key_len <= sizeof(key_block));
|
||||
memcpy(key_block, key, key_len);
|
||||
key_block_len = (unsigned)key_len;
|
||||
}
|
||||
if (ctx->key_length != HMAC_MAX_MD_CBLOCK) {
|
||||
memset(&ctx->key[ctx->key_length], 0, sizeof(ctx->key) - ctx->key_length);
|
||||
/* Keys are then padded with zeros. */
|
||||
if (key_block_len != HMAC_MAX_MD_CBLOCK) {
|
||||
memset(&key_block[key_block_len], 0, sizeof(key_block) - key_block_len);
|
||||
}
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++) {
|
||||
pad[i] = 0x36 ^ ctx->key[i];
|
||||
pad[i] = 0x36 ^ key_block[i];
|
||||
}
|
||||
if (!EVP_DigestInit_ex(&ctx->i_ctx, md, impl) ||
|
||||
!EVP_DigestUpdate(&ctx->i_ctx, pad, EVP_MD_block_size(md))) {
|
||||
@@ -152,12 +147,14 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,
|
||||
}
|
||||
|
||||
for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++) {
|
||||
pad[i] = 0x5c ^ ctx->key[i];
|
||||
pad[i] = 0x5c ^ key_block[i];
|
||||
}
|
||||
if (!EVP_DigestInit_ex(&ctx->o_ctx, md, impl) ||
|
||||
!EVP_DigestUpdate(&ctx->o_ctx, pad, EVP_MD_block_size(md))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx->md = md;
|
||||
}
|
||||
|
||||
if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->i_ctx)) {
|
||||
@@ -200,8 +197,6 @@ int HMAC_CTX_copy_ex(HMAC_CTX *dest, const HMAC_CTX *src) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(dest->key, src->key, HMAC_MAX_MD_CBLOCK);
|
||||
dest->key_length = src->key_length;
|
||||
dest->md = src->md;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -58,12 +58,17 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/digest.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/mem.h>
|
||||
|
||||
#include "../test/scoped_types.h"
|
||||
|
||||
|
||||
struct test_st {
|
||||
struct Test {
|
||||
uint8_t key[16];
|
||||
size_t key_len;
|
||||
uint8_t data[64];
|
||||
@@ -71,9 +76,7 @@ struct test_st {
|
||||
const char *hex_digest;
|
||||
};
|
||||
|
||||
#define NUM_TESTS 4
|
||||
|
||||
static const struct test_st kTests[NUM_TESTS] = {
|
||||
static const Test kTests[] = {
|
||||
{
|
||||
"", 0, "More text test vectors to stuff up EBCDIC machines :-)", 54,
|
||||
"e9139d1e6ee064ef8cf514fc7dc83e86",
|
||||
@@ -110,109 +113,105 @@ static const struct test_st kTests[NUM_TESTS] = {
|
||||
},
|
||||
};
|
||||
|
||||
static char *to_hex(const uint8_t *md, size_t md_len) {
|
||||
size_t i;
|
||||
static char buf[80];
|
||||
|
||||
for (i = 0; i < md_len; i++) {
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
static std::string ToHex(const uint8_t *md, size_t md_len) {
|
||||
std::string ret;
|
||||
for (size_t i = 0; i < md_len; i++) {
|
||||
char buf[2 + 1 /* NUL */];
|
||||
BIO_snprintf(buf, sizeof(buf), "%02x", md[i]);
|
||||
ret.append(buf, 2);
|
||||
}
|
||||
return buf;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
unsigned i;
|
||||
char *p;
|
||||
int err = 0;
|
||||
uint8_t out[EVP_MAX_MD_SIZE];
|
||||
unsigned out_len;
|
||||
|
||||
CRYPTO_library_init();
|
||||
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
const struct test_st *test = &kTests[i];
|
||||
for (unsigned i = 0; i < sizeof(kTests) / sizeof(kTests[0]); i++) {
|
||||
const Test *test = &kTests[i];
|
||||
|
||||
/* Test using the one-shot API. */
|
||||
// Test using the one-shot API.
|
||||
if (NULL == HMAC(EVP_md5(), test->key, test->key_len, test->data,
|
||||
test->data_len, out, &out_len)) {
|
||||
fprintf(stderr, "%u: HMAC failed.\n", i);
|
||||
err++;
|
||||
continue;
|
||||
}
|
||||
p = to_hex(out, out_len);
|
||||
if (strcmp(p, test->hex_digest) != 0) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
|
||||
std::string out_hex = ToHex(out, out_len);
|
||||
if (out_hex != test->hex_digest) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
|
||||
test->hex_digest);
|
||||
err++;
|
||||
}
|
||||
|
||||
/* Test using HMAC_CTX. */
|
||||
HMAC_CTX ctx;
|
||||
HMAC_CTX_init(&ctx);
|
||||
if (!HMAC_Init_ex(&ctx, test->key, test->key_len, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(&ctx, test->data, test->data_len) ||
|
||||
!HMAC_Final(&ctx, out, &out_len)) {
|
||||
// Test using HMAC_CTX.
|
||||
ScopedHMAC_CTX ctx;
|
||||
if (!HMAC_Init_ex(ctx.get(), test->key, test->key_len, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
|
||||
!HMAC_Final(ctx.get(), out, &out_len)) {
|
||||
fprintf(stderr, "%u: HMAC failed.\n", i);
|
||||
err++;
|
||||
HMAC_CTX_cleanup(&ctx);
|
||||
continue;
|
||||
}
|
||||
p = to_hex(out, out_len);
|
||||
if (strcmp(p, test->hex_digest) != 0) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
|
||||
out_hex = ToHex(out, out_len);
|
||||
if (out_hex != test->hex_digest) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
|
||||
test->hex_digest);
|
||||
err++;
|
||||
}
|
||||
|
||||
/* Test that an HMAC_CTX may be reset with the same key. */
|
||||
if (!HMAC_Init_ex(&ctx, NULL, 0, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(&ctx, test->data, test->data_len) ||
|
||||
!HMAC_Final(&ctx, out, &out_len)) {
|
||||
// Test that an HMAC_CTX may be reset with the same key.
|
||||
if (!HMAC_Init_ex(ctx.get(), NULL, 0, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
|
||||
!HMAC_Final(ctx.get(), out, &out_len)) {
|
||||
fprintf(stderr, "%u: HMAC failed.\n", i);
|
||||
err++;
|
||||
HMAC_CTX_cleanup(&ctx);
|
||||
continue;
|
||||
}
|
||||
p = to_hex(out, out_len);
|
||||
if (strcmp(p, test->hex_digest) != 0) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
|
||||
out_hex = ToHex(out, out_len);
|
||||
if (out_hex != test->hex_digest) {
|
||||
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
|
||||
test->hex_digest);
|
||||
err++;
|
||||
}
|
||||
|
||||
HMAC_CTX_cleanup(&ctx);
|
||||
}
|
||||
|
||||
/* Test that HMAC() uses the empty key when called with key = NULL. */
|
||||
const struct test_st *test = &kTests[0];
|
||||
// Test that HMAC() uses the empty key when called with key = NULL.
|
||||
const Test *test = &kTests[0];
|
||||
assert(test->key_len == 0);
|
||||
if (NULL == HMAC(EVP_md5(), NULL, 0, test->data, test->data_len, out,
|
||||
&out_len)) {
|
||||
fprintf(stderr, "HMAC failed.\n");
|
||||
err++;
|
||||
} else {
|
||||
p = to_hex(out, out_len);
|
||||
if (strcmp(p, test->hex_digest) != 0) {
|
||||
fprintf(stderr, "got %s instead of %s\n", p, test->hex_digest);
|
||||
std::string out_hex = ToHex(out, out_len);
|
||||
if (out_hex != test->hex_digest) {
|
||||
fprintf(stderr, "got %s instead of %s\n", out_hex.c_str(),
|
||||
test->hex_digest);
|
||||
err++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Test that HMAC_Init, etc., uses the empty key when called initially with
|
||||
* key = NULL. */
|
||||
// Test that HMAC_Init, etc., uses the empty key when called initially with
|
||||
// key = NULL.
|
||||
assert(test->key_len == 0);
|
||||
HMAC_CTX ctx;
|
||||
HMAC_CTX_init(&ctx);
|
||||
if (!HMAC_Init_ex(&ctx, NULL, 0, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(&ctx, test->data, test->data_len) ||
|
||||
!HMAC_Final(&ctx, out, &out_len)) {
|
||||
ScopedHMAC_CTX ctx;
|
||||
if (!HMAC_Init_ex(ctx.get(), NULL, 0, EVP_md5(), NULL) ||
|
||||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
|
||||
!HMAC_Final(ctx.get(), out, &out_len)) {
|
||||
fprintf(stderr, "HMAC failed.\n");
|
||||
err++;
|
||||
} else {
|
||||
p = to_hex(out, out_len);
|
||||
if (strcmp(p, test->hex_digest) != 0) {
|
||||
fprintf(stderr, "got %s instead of %s\n", p, test->hex_digest);
|
||||
std::string out_hex = ToHex(out, out_len);
|
||||
if (out_hex != test->hex_digest) {
|
||||
fprintf(stderr, "got %s instead of %s\n", out_hex.c_str(),
|
||||
test->hex_digest);
|
||||
err++;
|
||||
}
|
||||
}
|
||||
HMAC_CTX_cleanup(&ctx);
|
||||
|
||||
if (err) {
|
||||
return 1;
|
||||
@@ -111,6 +111,10 @@
|
||||
|
||||
#include <openssl/ex_data.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -295,6 +299,63 @@ static inline int constant_time_select_int(unsigned int mask, int a, int b) {
|
||||
}
|
||||
|
||||
|
||||
/* Thread-safe initialisation. */
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
typedef pthread_once_t CRYPTO_once_t;
|
||||
#define CRYPTO_ONCE_INIT PTHREAD_ONCE_INIT
|
||||
#else
|
||||
typedef int32_t CRYPTO_once_t;
|
||||
#define CRYPTO_ONCE_INIT 0
|
||||
#endif
|
||||
|
||||
/* CRYPTO_once calls |init| exactly once per process. This is thread-safe: if
|
||||
* concurrent threads call |CRYPTO_once| with the same |CRYPTO_once_t| argument
|
||||
* then they will block until |init| completes, but |init| will have only been
|
||||
* called once.
|
||||
*
|
||||
* The |once| argument must be a |CRYPTO_once_t| that has been initialised with
|
||||
* the value |CRYPTO_ONCE_INIT|. */
|
||||
OPENSSL_EXPORT void CRYPTO_once(CRYPTO_once_t *once, void (*init)(void));
|
||||
|
||||
|
||||
/* Thread local storage. */
|
||||
|
||||
/* thread_local_data_t enumerates the types of thread-local data that can be
|
||||
* stored. */
|
||||
typedef enum {
|
||||
OPENSSL_THREAD_LOCAL_ERR = 0,
|
||||
OPENSSL_THREAD_LOCAL_TEST,
|
||||
NUM_OPENSSL_THREAD_LOCALS,
|
||||
} thread_local_data_t;
|
||||
|
||||
/* thread_local_destructor_t is the type of a destructor function that will be
|
||||
* called when a thread exits and its thread-local storage needs to be freed. */
|
||||
typedef void (*thread_local_destructor_t)(void *);
|
||||
|
||||
/* CRYPTO_get_thread_local gets the pointer value that is stored for the
|
||||
* current thread for the given index, or NULL if none has been set. */
|
||||
OPENSSL_EXPORT void *CRYPTO_get_thread_local(thread_local_data_t value);
|
||||
|
||||
/* CRYPTO_set_thread_local sets a pointer value for the current thread at the
|
||||
* given index. This function should only be called once per thread for a given
|
||||
* |index|: rather than update the pointer value itself, update the data that
|
||||
* is pointed to.
|
||||
*
|
||||
* The destructor function will be called when a thread exits to free this
|
||||
* thread-local data. All calls to |CRYPTO_set_thread_local| with the same
|
||||
* |index| should have the same |destructor| argument. The destructor may be
|
||||
* called with a NULL argument if a thread that never set a thread-local
|
||||
* pointer for |index|, exits. The destructor may be called concurrently with
|
||||
* different arguments.
|
||||
*
|
||||
* This function returns one on success or zero on error. If it returns zero
|
||||
* then |destructor| has been called with |value| already. */
|
||||
OPENSSL_EXPORT int CRYPTO_set_thread_local(
|
||||
thread_local_data_t index, void *value,
|
||||
thread_local_destructor_t destructor);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern C */
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#pragma warning(push, 3)
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
#pragma warning(pop)
|
||||
#else
|
||||
#include <strings.h>
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
# below and combine it with reduction algorithm from x86 module.
|
||||
# Performance improvement over previous version varies from 65% on
|
||||
# Snapdragon S4 to 110% on Cortex A9. In absolute terms Cortex A8
|
||||
# processes one byte in 8.45 cycles, A9 - in 10.2, Snapdragon S4 -
|
||||
# in 9.33.
|
||||
# processes one byte in 8.45 cycles, A9 - in 10.2, A15 - in 7.63,
|
||||
# Snapdragon S4 - in 9.33.
|
||||
#
|
||||
# Câmara, D.; Gouvêa, C. P. L.; López, J. & Dahab, R.: Fast Software
|
||||
# Polynomial Multiplication on ARM Processors using the NEON Engine.
|
||||
|
||||
@@ -131,8 +131,8 @@ require "x86asm.pl";
|
||||
|
||||
&asm_init($ARGV[0],"ghash-x86.pl",$x86only = $ARGV[$#ARGV] eq "386");
|
||||
|
||||
$sse2=1;
|
||||
#for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
|
||||
$sse2=0;
|
||||
for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
|
||||
|
||||
($Zhh,$Zhl,$Zlh,$Zll) = ("ebp","edx","ecx","ebx");
|
||||
$inp = "edi";
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# PowerPC assembler distiller by <appro>.
|
||||
|
||||
my $flavour = shift;
|
||||
my $output = shift;
|
||||
open STDOUT,">$output" || die "can't open $output: $!";
|
||||
|
||||
my %GLOBALS;
|
||||
my $dotinlocallabels=($flavour=~/linux/)?1:0;
|
||||
|
||||
################################################################
|
||||
# directives which need special treatment on different platforms
|
||||
################################################################
|
||||
my $globl = sub {
|
||||
my $junk = shift;
|
||||
my $name = shift;
|
||||
my $global = \$GLOBALS{$name};
|
||||
my $ret;
|
||||
|
||||
$name =~ s|^[\.\_]||;
|
||||
|
||||
SWITCH: for ($flavour) {
|
||||
/aix/ && do { $name = ".$name";
|
||||
last;
|
||||
};
|
||||
/osx/ && do { $name = "_$name";
|
||||
last;
|
||||
};
|
||||
/linux.*(32|64le)/
|
||||
&& do { $ret .= ".globl $name\n";
|
||||
$ret .= ".type $name,\@function";
|
||||
last;
|
||||
};
|
||||
/linux.*64/ && do { $ret .= ".globl $name\n";
|
||||
$ret .= ".type $name,\@function\n";
|
||||
$ret .= ".section \".opd\",\"aw\"\n";
|
||||
$ret .= ".align 3\n";
|
||||
$ret .= "$name:\n";
|
||||
$ret .= ".quad .$name,.TOC.\@tocbase,0\n";
|
||||
$ret .= ".previous\n";
|
||||
|
||||
$name = ".$name";
|
||||
last;
|
||||
};
|
||||
}
|
||||
|
||||
$ret = ".globl $name" if (!$ret);
|
||||
$$global = $name;
|
||||
$ret;
|
||||
};
|
||||
my $text = sub {
|
||||
my $ret = ($flavour =~ /aix/) ? ".csect" : ".text";
|
||||
$ret = ".abiversion 2\n".$ret if ($flavour =~ /linux.*64le/);
|
||||
$ret;
|
||||
};
|
||||
my $machine = sub {
|
||||
my $junk = shift;
|
||||
my $arch = shift;
|
||||
if ($flavour =~ /osx/)
|
||||
{ $arch =~ s/\"//g;
|
||||
$arch = ($flavour=~/64/) ? "ppc970-64" : "ppc970" if ($arch eq "any");
|
||||
}
|
||||
".machine $arch";
|
||||
};
|
||||
my $size = sub {
|
||||
if ($flavour =~ /linux/)
|
||||
{ shift;
|
||||
my $name = shift; $name =~ s|^[\.\_]||;
|
||||
my $ret = ".size $name,.-".($flavour=~/64$/?".":"").$name;
|
||||
$ret .= "\n.size .$name,.-.$name" if ($flavour=~/64$/);
|
||||
$ret;
|
||||
}
|
||||
else
|
||||
{ ""; }
|
||||
};
|
||||
my $asciz = sub {
|
||||
shift;
|
||||
my $line = join(",",@_);
|
||||
if ($line =~ /^"(.*)"$/)
|
||||
{ ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
|
||||
else
|
||||
{ ""; }
|
||||
};
|
||||
|
||||
################################################################
|
||||
# simplified mnemonics not handled by at least one assembler
|
||||
################################################################
|
||||
my $cmplw = sub {
|
||||
my $f = shift;
|
||||
my $cr = 0; $cr = shift if ($#_>1);
|
||||
# Some out-of-date 32-bit GNU assembler just can't handle cmplw...
|
||||
($flavour =~ /linux.*32/) ?
|
||||
" .long ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
|
||||
" cmplw ".join(',',$cr,@_);
|
||||
};
|
||||
my $bdnz = sub {
|
||||
my $f = shift;
|
||||
my $bo = $f=~/[\+\-]/ ? 16+9 : 16; # optional "to be taken" hint
|
||||
" bc $bo,0,".shift;
|
||||
} if ($flavour!~/linux/);
|
||||
my $bltlr = sub {
|
||||
my $f = shift;
|
||||
my $bo = $f=~/\-/ ? 12+2 : 12; # optional "not to be taken" hint
|
||||
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
|
||||
" .long ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
|
||||
" bclr $bo,0";
|
||||
};
|
||||
my $bnelr = sub {
|
||||
my $f = shift;
|
||||
my $bo = $f=~/\-/ ? 4+2 : 4; # optional "not to be taken" hint
|
||||
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
|
||||
" .long ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
|
||||
" bclr $bo,2";
|
||||
};
|
||||
my $beqlr = sub {
|
||||
my $f = shift;
|
||||
my $bo = $f=~/-/ ? 12+2 : 12; # optional "not to be taken" hint
|
||||
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
|
||||
" .long ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
|
||||
" bclr $bo,2";
|
||||
};
|
||||
# GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
|
||||
# arguments is 64, with "operand out of range" error.
|
||||
my $extrdi = sub {
|
||||
my ($f,$ra,$rs,$n,$b) = @_;
|
||||
$b = ($b+$n)&63; $n = 64-$n;
|
||||
" rldicl $ra,$rs,$b,$n";
|
||||
};
|
||||
|
||||
while($line=<>) {
|
||||
|
||||
$line =~ s|[#!;].*$||; # get rid of asm-style comments...
|
||||
$line =~ s|/\*.*\*/||; # ... and C-style comments...
|
||||
$line =~ s|^\s+||; # ... and skip white spaces in beginning...
|
||||
$line =~ s|\s+$||; # ... and at the end
|
||||
|
||||
{
|
||||
$line =~ s|\b\.L(\w+)|L$1|g; # common denominator for Locallabel
|
||||
$line =~ s|\bL(\w+)|\.L$1|g if ($dotinlocallabels);
|
||||
}
|
||||
|
||||
{
|
||||
$line =~ s|(^[\.\w]+)\:\s*||;
|
||||
my $label = $1;
|
||||
if ($label) {
|
||||
printf "%s:",($GLOBALS{$label} or $label);
|
||||
printf "\n.localentry\t$GLOBALS{$label},0" if ($GLOBALS{$label} && $flavour =~ /linux.*64le/);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
$line =~ s|^\s*(\.?)(\w+)([\.\+\-]?)\s*||;
|
||||
my $c = $1; $c = "\t" if ($c eq "");
|
||||
my $mnemonic = $2;
|
||||
my $f = $3;
|
||||
my $opcode = eval("\$$mnemonic");
|
||||
$line =~ s|\bc?[rf]([0-9]+)\b|$1|g if ($c ne "." and $flavour !~ /osx/);
|
||||
if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
|
||||
elsif ($mnemonic) { $line = $c.$mnemonic.$f."\t".$line; }
|
||||
}
|
||||
|
||||
print $line if ($line);
|
||||
print "\n";
|
||||
}
|
||||
|
||||
close STDOUT;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -497,7 +497,11 @@ my %globals;
|
||||
$self->{value} = $dir . "\t" . $line;
|
||||
|
||||
if ($dir =~ /\.extern/) {
|
||||
$self->{value} = ""; # swallow extern
|
||||
if ($flavour eq "elf") {
|
||||
$self->{value} .= "\n.hidden $line";
|
||||
} else {
|
||||
$self->{value} = "";
|
||||
}
|
||||
} elsif (!$elf && $dir =~ /\.type/) {
|
||||
$self->{value} = "";
|
||||
$self->{value} = ".def\t" . ($globals{$1} or $1) . ";\t" .
|
||||
|
||||
@@ -18,10 +18,10 @@ sub ::generic
|
||||
|
||||
if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no []
|
||||
{ $opcode="mov"; }
|
||||
elsif ($opcode !~ /movq/)
|
||||
elsif ($opcode !~ /mov[dq]$/)
|
||||
{ # fix xmm references
|
||||
$arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
|
||||
$arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
|
||||
$arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[-1]=~/\bxmm[0-7]\b/i);
|
||||
$arg[-1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
|
||||
}
|
||||
|
||||
&::emit($opcode,@arg);
|
||||
@@ -160,16 +160,13 @@ sub ::public_label
|
||||
{ push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
|
||||
|
||||
sub ::data_byte
|
||||
{ push(@out,("DB\t").join(',',@_)."\n"); }
|
||||
{ push(@out,("DB\t").join(',',splice(@_,0,16))."\n") while(@_); }
|
||||
|
||||
sub ::data_short
|
||||
{ push(@out,("DW\t").join(',',@_)."\n"); }
|
||||
{ push(@out,("DW\t").join(',',splice(@_,0,8))."\n") while(@_); }
|
||||
|
||||
sub ::data_word
|
||||
{ # MASM can't handle long lines, so emit one word at a time.
|
||||
foreach(@_)
|
||||
{ push(@out,"DD\t$_\n"); }
|
||||
}
|
||||
{ push(@out,("DD\t").join(',',splice(@_,0,4))."\n") while(@_); }
|
||||
|
||||
sub ::align
|
||||
{ push(@out,"ALIGN\t$_[0]\n"); }
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#pragma warning(push, 3)
|
||||
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
|
||||
/* #define needed to link in RtlGenRandom(), a.k.a. SystemFunction036. See the
|
||||
* "Community Additions" comment on MSDN here:
|
||||
|
||||
@@ -502,32 +502,6 @@ asm_RC4_set_key:
|
||||
mov %eax,-4($dat)
|
||||
ret
|
||||
.size asm_RC4_set_key,.-asm_RC4_set_key
|
||||
|
||||
.globl RC4_options
|
||||
.type RC4_options,\@abi-omnipotent
|
||||
.align 16
|
||||
RC4_options:
|
||||
lea .Lopts(%rip),%rax
|
||||
mov OPENSSL_ia32cap_P(%rip),%rdx
|
||||
mov (%rdx),%edx
|
||||
bt \$20,%edx
|
||||
jc .L8xchar
|
||||
bt \$30,%edx
|
||||
jnc .Ldone
|
||||
add \$25,%rax
|
||||
ret
|
||||
.L8xchar:
|
||||
add \$12,%rax
|
||||
.Ldone:
|
||||
ret
|
||||
.align 64
|
||||
.Lopts:
|
||||
.asciz "rc4(8x,int)"
|
||||
.asciz "rc4(8x,char)"
|
||||
.asciz "rc4(16x,int)"
|
||||
.asciz "RC4 for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
|
||||
.align 64
|
||||
.size RC4_options,.-RC4_options
|
||||
___
|
||||
|
||||
# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
|
||||
|
||||
+5
-38
@@ -67,8 +67,6 @@
|
||||
#error "Unknown word size"
|
||||
#endif
|
||||
|
||||
#define RC4_INT uint32_t
|
||||
|
||||
|
||||
/* RC4 as implemented from a posting from
|
||||
* Newsgroups: sci.crypt
|
||||
@@ -78,44 +76,14 @@
|
||||
* Date: Wed, 14 Sep 1994 06:35:31 GMT */
|
||||
|
||||
void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
|
||||
register RC4_INT *d;
|
||||
register RC4_INT x, y, tx, ty;
|
||||
uint32_t *d;
|
||||
uint32_t x, y, tx, ty;
|
||||
size_t i;
|
||||
|
||||
x = key->x;
|
||||
y = key->y;
|
||||
d = key->data;
|
||||
|
||||
#if defined(RC4_CHUNK)
|
||||
/* The original reason for implementing this(*) was the fact that
|
||||
* pre-21164a Alpha CPUs don't have byte load/store instructions
|
||||
* and e.g. a byte store has to be done with 64-bit load, shift,
|
||||
* and, or and finally 64-bit store. Peaking data and operating
|
||||
* at natural word size made it possible to reduce amount of
|
||||
* instructions as well as to perform early read-ahead without
|
||||
* suffering from RAW (read-after-write) hazard. This resulted
|
||||
* in ~40%(**) performance improvement on 21064 box with gcc.
|
||||
* But it's not only Alpha users who win here:-) Thanks to the
|
||||
* early-n-wide read-ahead this implementation also exhibits
|
||||
* >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending
|
||||
* on sizeof(RC4_INT)).
|
||||
*
|
||||
* (*) "this" means code which recognizes the case when input
|
||||
* and output pointers appear to be aligned at natural CPU
|
||||
* word boundary
|
||||
* (**) i.e. according to 'apps/openssl speed rc4' benchmark,
|
||||
* crypto/rc4/rc4speed.c exhibits almost 70% speed-up...
|
||||
*
|
||||
* Cavets.
|
||||
*
|
||||
* - RC4_CHUNK="unsigned long long" should be a #1 choice for
|
||||
* UltraSPARC. Unfortunately gcc generates very slow code
|
||||
* (2.5-3 times slower than one generated by Sun's WorkShop
|
||||
* C) and therefore gcc (at least 2.95 and earlier) should
|
||||
* always be told that RC4_CHUNK="unsigned long".
|
||||
*
|
||||
* <appro@fy.chalmers.se> */
|
||||
|
||||
#define RC4_STEP \
|
||||
(x = (x + 1) & 0xff, tx = d[x], y = (tx + y) & 0xff, ty = d[y], d[y] = tx, \
|
||||
d[x] = ty, (RC4_CHUNK)d[(tx + ty) & 0xff])
|
||||
@@ -255,7 +223,6 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#define LOOP(in, out) \
|
||||
x = ((x + 1) & 0xff); \
|
||||
tx = d[x]; \
|
||||
@@ -328,9 +295,9 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
|
||||
}
|
||||
|
||||
void RC4_set_key(RC4_KEY *rc4key, unsigned len, const uint8_t *key) {
|
||||
register RC4_INT tmp;
|
||||
register int id1, id2;
|
||||
register RC4_INT *d;
|
||||
uint32_t tmp;
|
||||
int id1, id2;
|
||||
uint32_t *d;
|
||||
unsigned int i;
|
||||
|
||||
d = &rc4key->data[0];
|
||||
|
||||
@@ -113,15 +113,6 @@ int RSA_padding_add_none(uint8_t *to, unsigned to_len, const uint8_t *from,
|
||||
int RSA_padding_check_none(uint8_t *to, unsigned to_len, const uint8_t *from,
|
||||
unsigned from_len);
|
||||
|
||||
/* RSA_verify_PKCS1_PSS_mgf1 */
|
||||
int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const uint8_t *mHash,
|
||||
const EVP_MD *Hash, const EVP_MD *mgf1Hash,
|
||||
const uint8_t *EM, int sLen);
|
||||
|
||||
int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, uint8_t *EM, const uint8_t *mHash,
|
||||
const EVP_MD *Hash, const EVP_MD *mgf1Hash,
|
||||
int sLen);
|
||||
|
||||
/* RSA_private_transform calls either the method-specific |private_transform|
|
||||
* function (if given) or the generic one. See the comment for
|
||||
* |private_transform| in |rsa_meth_st|. */
|
||||
|
||||
+5
-11
@@ -125,7 +125,7 @@ void RSA_free(RSA *rsa) {
|
||||
}
|
||||
METHOD_unref(rsa->meth);
|
||||
|
||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, rsa, &rsa->ex_data);
|
||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, rsa, &rsa->ex_data);
|
||||
|
||||
if (rsa->n != NULL) {
|
||||
BN_clear_free(rsa->n);
|
||||
@@ -347,12 +347,6 @@ static const struct pkcs1_sig_prefix kPKCS1SigPrefixes[] = {
|
||||
{0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
|
||||
0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40},
|
||||
},
|
||||
{
|
||||
NID_ripemd160,
|
||||
14,
|
||||
{0x30, 0x20, 0x30, 0x08, 0x06, 0x06, 0x28, 0xcf, 0x06, 0x03, 0x00, 0x31,
|
||||
0x04, 0x14},
|
||||
},
|
||||
{
|
||||
NID_undef, 0, {0},
|
||||
},
|
||||
@@ -375,7 +369,7 @@ static int pkcs1_prefixed_msg(uint8_t **out_msg, size_t *out_msg_len,
|
||||
if (hash_nid == NID_md5_sha1) {
|
||||
/* Special case: SSL signature, just check the length. */
|
||||
if (msg_len != SSL_SIG_LENGTH) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_INVALID_MESSAGE_LENGTH);
|
||||
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_INVALID_MESSAGE_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -395,19 +389,19 @@ static int pkcs1_prefixed_msg(uint8_t **out_msg, size_t *out_msg_len,
|
||||
}
|
||||
|
||||
if (prefix == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_UNKNOWN_ALGORITHM_TYPE);
|
||||
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_UNKNOWN_ALGORITHM_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
signed_msg_len = prefix_len + msg_len;
|
||||
if (signed_msg_len < prefix_len) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_TOO_LONG);
|
||||
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
signed_msg = OPENSSL_malloc(signed_msg_len);
|
||||
if (!signed_msg) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,8 +360,7 @@ static int sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
}
|
||||
|
||||
if (!RSA_private_transform(rsa, out, buf, rsa_size)) {
|
||||
OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
goto err;
|
||||
}
|
||||
|
||||
*out_len = rsa_size;
|
||||
@@ -400,7 +399,6 @@ static int decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
}
|
||||
|
||||
if (!RSA_private_transform(rsa, buf, in, rsa_size)) {
|
||||
OPENSSL_PUT_ERROR(RSA, decrypt, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ sub sha1msg2 { sha1op38(0xca,@_); }
|
||||
&sub ("esp",32);
|
||||
|
||||
&movdqu ($ABCD,&QWP(0,$ctx));
|
||||
&movd ($E,&QWP(16,$ctx));
|
||||
&movd ($E,&DWP(16,$ctx));
|
||||
&and ("esp",-32);
|
||||
&movdqa ($BSWAP,&QWP(0x50,$tmp1)); # byte-n-word swap
|
||||
|
||||
|
||||
@@ -60,7 +60,9 @@
|
||||
# is ~2.5x larger and there are some redundant instructions executed
|
||||
# when processing last block, improvement is not as big for smallest
|
||||
# blocks, only ~30%. Snapdragon S4 is a tad faster, 6.4 cycles per
|
||||
# byte, which is also >80% faster than integer-only code.
|
||||
# byte, which is also >80% faster than integer-only code. Cortex-A15
|
||||
# is even faster spending 5.6 cycles per byte outperforming integer-
|
||||
# only code by factor of 2.
|
||||
|
||||
# May 2014.
|
||||
#
|
||||
@@ -642,6 +644,7 @@ ___
|
||||
$code.=<<___;
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
___
|
||||
|
||||
|
||||
@@ -621,6 +621,7 @@ $code.=<<___;
|
||||
.align 2
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
___
|
||||
|
||||
|
||||
@@ -34,16 +34,9 @@
|
||||
# terms it's 22.6 cycles per byte, which is disappointing result.
|
||||
# Technical writers asserted that 3-way S4 pipeline can sustain
|
||||
# multiple NEON instructions per cycle, but dual NEON issue could
|
||||
# not be observed, and for NEON-only sequences IPC(*) was found to
|
||||
# be limited by 1:-( 0.33 and 0.66 were measured for sequences with
|
||||
# ILPs(*) of 1 and 2 respectively. This in turn means that you can
|
||||
# even find yourself striving, as I did here, for achieving IPC
|
||||
# adequate to one delivered by Cortex A8 [for reference, it's
|
||||
# 0.5 for ILP of 1, and 1 for higher ILPs].
|
||||
#
|
||||
# (*) ILP, instruction-level parallelism, how many instructions
|
||||
# *can* execute at the same time. IPC, instructions per cycle,
|
||||
# indicates how many instructions actually execute.
|
||||
# not be observed, see http://www.openssl.org/~appro/Snapdragon-S4.html
|
||||
# for further details. On side note Cortex-A15 processes one byte in
|
||||
# 16 cycles.
|
||||
|
||||
# Byte order [in]dependence. =========================================
|
||||
#
|
||||
@@ -599,6 +592,7 @@ $code.=<<___;
|
||||
.align 2
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
___
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/* Copyright (c) 2015, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
|
||||
#define OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "stl_compat.h"
|
||||
|
||||
|
||||
template<typename T, void (*func)(T*)>
|
||||
struct OpenSSLDeleter {
|
||||
void operator()(T *obj) {
|
||||
func(obj);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct OpenSSLFree {
|
||||
void operator()(T *buf) {
|
||||
OPENSSL_free(buf);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, void (*func)(T*)>
|
||||
using ScopedOpenSSLType = bssl::unique_ptr<T, OpenSSLDeleter<T, func>>;
|
||||
|
||||
template<typename T, typename CleanupRet, void (*init_func)(T*),
|
||||
CleanupRet (*cleanup_func)(T*)>
|
||||
class ScopedOpenSSLContext {
|
||||
public:
|
||||
ScopedOpenSSLContext() {
|
||||
init_func(&ctx_);
|
||||
}
|
||||
~ScopedOpenSSLContext() {
|
||||
cleanup_func(&ctx_);
|
||||
}
|
||||
|
||||
T *get() { return &ctx_; }
|
||||
const T *get() const { return &ctx_; }
|
||||
|
||||
void Reset() {
|
||||
cleanup_func(&ctx_);
|
||||
init_func(&ctx_);
|
||||
}
|
||||
|
||||
private:
|
||||
T ctx_;
|
||||
};
|
||||
|
||||
using ScopedBIO = ScopedOpenSSLType<BIO, BIO_vfree>;
|
||||
using ScopedBIGNUM = ScopedOpenSSLType<BIGNUM, BN_free>;
|
||||
using ScopedBN_CTX = ScopedOpenSSLType<BN_CTX, BN_CTX_free>;
|
||||
using ScopedBN_MONT_CTX = ScopedOpenSSLType<BN_MONT_CTX, BN_MONT_CTX_free>;
|
||||
using ScopedDH = ScopedOpenSSLType<DH, DH_free>;
|
||||
using ScopedEVP_PKEY = ScopedOpenSSLType<EVP_PKEY, EVP_PKEY_free>;
|
||||
using ScopedPKCS8_PRIV_KEY_INFO = ScopedOpenSSLType<PKCS8_PRIV_KEY_INFO,
|
||||
PKCS8_PRIV_KEY_INFO_free>;
|
||||
using ScopedRSA = ScopedOpenSSLType<RSA, RSA_free>;
|
||||
using ScopedX509_ALGOR = ScopedOpenSSLType<X509_ALGOR, X509_ALGOR_free>;
|
||||
|
||||
using ScopedEVP_MD_CTX = ScopedOpenSSLContext<EVP_MD_CTX, int, EVP_MD_CTX_init,
|
||||
EVP_MD_CTX_cleanup>;
|
||||
using ScopedHMAC_CTX = ScopedOpenSSLContext<HMAC_CTX, void, HMAC_CTX_init,
|
||||
HMAC_CTX_cleanup>;
|
||||
|
||||
using ScopedOpenSSLBytes = bssl::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>;
|
||||
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
|
||||
@@ -0,0 +1,139 @@
|
||||
/* Copyright (c) 2015, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
// This header contains re-implementations of library functions from C++11. They
|
||||
// will be replaced with their standard counterparts once Chromium has C++11
|
||||
// library support in its toolchain.
|
||||
|
||||
namespace bssl {
|
||||
|
||||
// vector_data is a reimplementation of |std::vector::data| from C++11.
|
||||
template <class T>
|
||||
static T *vector_data(std::vector<T> *out) {
|
||||
return out->empty() ? nullptr : &(*out)[0];
|
||||
}
|
||||
|
||||
// remove_reference is a reimplementation of |std::remove_reference| from C++11.
|
||||
template <class T>
|
||||
struct remove_reference {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_reference<T&> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_reference<T&&> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
// move is a reimplementation of |std::move| from C++11.
|
||||
template <class T>
|
||||
typename remove_reference<T>::type &&move(T &&t) {
|
||||
return static_cast<typename remove_reference<T>::type&&>(t);
|
||||
}
|
||||
|
||||
// default_delete is a partial reimplementation of |std::default_delete| from
|
||||
// C++11.
|
||||
template <class T>
|
||||
struct default_delete {
|
||||
void operator()(T *t) const {
|
||||
enum { type_must_be_complete = sizeof(T) };
|
||||
delete t;
|
||||
}
|
||||
};
|
||||
|
||||
// nullptr_t is |std::nullptr_t| from C++11.
|
||||
using nullptr_t = decltype(nullptr);
|
||||
|
||||
// unique_ptr is a partial reimplementation of |std::unique_ptr| from C++11. It
|
||||
// intentionally does not support stateful deleters to avoid having to bother
|
||||
// with the empty member optimization.
|
||||
template <class T, class Deleter = default_delete<T>>
|
||||
class unique_ptr {
|
||||
public:
|
||||
unique_ptr() : ptr_(nullptr) {}
|
||||
unique_ptr(nullptr_t) : ptr_(nullptr) {}
|
||||
unique_ptr(T *ptr) : ptr_(ptr) {}
|
||||
unique_ptr(const unique_ptr &u) = delete;
|
||||
|
||||
unique_ptr(unique_ptr &&u) : ptr_(nullptr) {
|
||||
reset(u.release());
|
||||
}
|
||||
|
||||
~unique_ptr() {
|
||||
reset();
|
||||
}
|
||||
|
||||
unique_ptr &operator=(nullptr_t) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr &operator=(unique_ptr &&u) {
|
||||
reset(u.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr& operator=(const unique_ptr &u) = delete;
|
||||
|
||||
explicit operator bool() const {
|
||||
return ptr_ != nullptr;
|
||||
}
|
||||
|
||||
T &operator*() const {
|
||||
assert(ptr_ != nullptr);
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
T *operator->() const {
|
||||
assert(ptr_ != nullptr);
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
T *get() const {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
T *release() {
|
||||
T *ptr = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void reset(T *ptr = nullptr) {
|
||||
if (ptr_ != nullptr) {
|
||||
Deleter()(ptr_);
|
||||
}
|
||||
ptr_ = ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
T *ptr_;
|
||||
};
|
||||
|
||||
} // namespace bssl
|
||||
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
|
||||
+7
-16
@@ -61,32 +61,23 @@
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#pragma warning(push, 3)
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/type_check.h>
|
||||
|
||||
|
||||
#define CRYPTO_LOCK_ITEM(x) #x
|
||||
|
||||
/* lock_names contains the names of all the locks defined in thread.h. */
|
||||
static const char *const lock_names[] = {
|
||||
"<<ERROR>>", "err", "ex_data", "x509",
|
||||
"x509_info", "x509_pkey", "x509_crl", "x509_req",
|
||||
"dsa", "rsa", "evp_pkey", "x509_store",
|
||||
"ssl_ctx", "ssl_cert", "ssl_session", "ssl_sess_cert",
|
||||
"ssl", "ssl_method", "rand", "rand2",
|
||||
"debug_malloc", "BIO", "gethostbyname", "getservbyname",
|
||||
"readdir", "RSA_blinding", "dh", "debug_malloc2",
|
||||
"dso", "dynlock", "engine", "ui",
|
||||
"ecdsa", "ec", "ecdh", "bn",
|
||||
"ec_pre_comp", "store", "comp", "fips",
|
||||
"fips2", "obj",
|
||||
CRYPTO_LOCK_LIST
|
||||
};
|
||||
|
||||
OPENSSL_COMPILE_ASSERT(CRYPTO_NUM_LOCKS ==
|
||||
sizeof(lock_names) / sizeof(lock_names[0]),
|
||||
CRYPTO_NUM_LOCKS_inconsistent);
|
||||
#undef CRYPTO_LOCK_ITEM
|
||||
|
||||
#define CRYPTO_NUM_LOCKS (sizeof(lock_names) / sizeof(lock_names[0]))
|
||||
|
||||
static void (*locking_callback)(int mode, int lock_num, const char *file,
|
||||
int line) = 0;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user