mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge remote-tracking branch 'upstream/development' into make_tests_thread_safe
This commit is contained in:
@ -114,7 +114,7 @@ all: fuzz
|
||||
endif
|
||||
|
||||
fuzz: ${MBEDTLS_TEST_OBJS}
|
||||
$(MAKE) -C fuzz THIRDPARTY_INCLUDES=$(THIRDPARTY_INCLUDES)
|
||||
$(MAKE) -C fuzz
|
||||
|
||||
${MBEDTLS_TEST_OBJS}:
|
||||
$(MAKE) -C ../tests mbedtls_test
|
||||
|
@ -4,7 +4,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -4,7 +4,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
set(libs
|
||||
${mbedtls_target}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
find_library(FUZZINGENGINE_LIB FuzzingEngine)
|
||||
|
@ -1,36 +1,14 @@
|
||||
MBEDTLS_TEST_PATH:=../../tests/src
|
||||
MBEDTLS_TEST_OBJS:=$(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/*.c ${MBEDTLS_TEST_PATH}/drivers/*.c))
|
||||
MBEDTLS_TEST_PATH:=../../tests
|
||||
|
||||
CFLAGS ?= -O2
|
||||
WARNING_CFLAGS ?= -Wall -Wextra
|
||||
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../../tests/include -I../../include -D_FILE_OFFSET_BITS=64
|
||||
LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
|
||||
-L../../library \
|
||||
-lmbedtls$(SHARED_SUFFIX) \
|
||||
-lmbedx509$(SHARED_SUFFIX) \
|
||||
-lmbedcrypto$(SHARED_SUFFIX)
|
||||
MBEDTLS_PATH := ../..
|
||||
include ../../scripts/common.make
|
||||
|
||||
LOCAL_CFLAGS += $(patsubst -I../%,-I../../%,$(THIRDPARTY_INCLUDES))
|
||||
|
||||
ifndef SHARED
|
||||
DEP=../../library/libmbedcrypto.a ../../library/libmbedx509.a ../../library/libmbedtls.a
|
||||
else
|
||||
DEP=../../library/libmbedcrypto.$(DLEXT) ../../library/libmbedx509.$(DLEXT) ../../library/libmbedtls.$(DLEXT)
|
||||
endif
|
||||
|
||||
|
||||
DLEXT ?= so
|
||||
EXEXT=
|
||||
SHARED_SUFFIX=
|
||||
DEP=${MBEDLIBS}
|
||||
|
||||
ifdef FUZZINGENGINE
|
||||
LOCAL_LDFLAGS += -lFuzzingEngine
|
||||
endif
|
||||
|
||||
ifdef WINDOWS_BUILD
|
||||
LOCAL_LDFLAGS += -lbcrypt
|
||||
endif
|
||||
|
||||
# A test application is built for each suites/test_suite_*.data file.
|
||||
# Application name is same as .data file's base name and can be
|
||||
# constructed by stripping path 'suites/' and extension .data.
|
||||
@ -45,9 +23,6 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS))
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
$(DEP):
|
||||
$(MAKE) -C ../../library
|
||||
|
||||
C_FILES := $(addsuffix .c,$(APPS))
|
||||
|
||||
%.o: %.c
|
||||
|
@ -6,7 +6,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -5,7 +5,7 @@ set(executables_mbedtls
|
||||
|
||||
foreach(exe IN LISTS executables_mbedtls)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedtls_target})
|
||||
target_link_libraries(${exe} ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
@ -32,7 +32,7 @@ set(executables_mbedcrypto
|
||||
|
||||
foreach(exe IN LISTS executables_mbedcrypto)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -13,14 +13,13 @@
|
||||
|
||||
#if defined(MBEDTLS_AES_C) && defined(MBEDTLS_DHM_C) && \
|
||||
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_NET_C) && \
|
||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_MD_CAN_SHA256) && \
|
||||
defined(MBEDTLS_FS_IO) && defined(MBEDTLS_CTR_DRBG_C) && \
|
||||
defined(MBEDTLS_MD_CAN_SHA1)
|
||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA256_C) && \
|
||||
defined(MBEDTLS_FS_IO) && defined(MBEDTLS_CTR_DRBG_C)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/dhm.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
|
||||
@ -33,9 +32,8 @@
|
||||
|
||||
#if !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_DHM_C) || \
|
||||
!defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NET_C) || \
|
||||
!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_MD_CAN_SHA256) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_CTR_DRBG_C) || \
|
||||
!defined(MBEDTLS_SHA1_C)
|
||||
!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_SHA256_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_AES_C and/or MBEDTLS_DHM_C and/or MBEDTLS_ENTROPY_C "
|
||||
@ -60,12 +58,14 @@ int main(void)
|
||||
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
unsigned int mdlen;
|
||||
size_t n, buflen;
|
||||
mbedtls_net_context server_fd;
|
||||
|
||||
unsigned char *p, *end;
|
||||
unsigned char buf[2048];
|
||||
unsigned char hash[32];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
mbedtls_mpi N, E;
|
||||
const char *pers = "dh_client";
|
||||
|
||||
mbedtls_entropy_context entropy;
|
||||
@ -78,6 +78,8 @@ int main(void)
|
||||
mbedtls_dhm_init(&dhm);
|
||||
mbedtls_aes_init(&aes);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_mpi_init(&N);
|
||||
mbedtls_mpi_init(&E);
|
||||
|
||||
/*
|
||||
* 1. Setup the RNG
|
||||
@ -106,16 +108,13 @@ int main(void)
|
||||
}
|
||||
|
||||
mbedtls_rsa_init(&rsa);
|
||||
|
||||
if ((ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(N), 16, f)) != 0 ||
|
||||
(ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(E), 16, f)) != 0) {
|
||||
if ((ret = mbedtls_mpi_read_file(&N, 16, f)) != 0 ||
|
||||
(ret = mbedtls_mpi_read_file(&E, 16, f)) != 0 ||
|
||||
(ret = mbedtls_rsa_import(&rsa, &N, NULL, NULL, NULL, &E) != 0)) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret);
|
||||
fclose(f);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rsa.MBEDTLS_PRIVATE(len) = (mbedtls_mpi_bitlen(&rsa.MBEDTLS_PRIVATE(N)) + 7) >> 3;
|
||||
|
||||
fclose(f);
|
||||
|
||||
/*
|
||||
@ -182,18 +181,24 @@ int main(void)
|
||||
|
||||
p += 2;
|
||||
|
||||
if ((n = (size_t) (end - p)) != rsa.MBEDTLS_PRIVATE(len)) {
|
||||
if ((n = (size_t) (end - p)) != mbedtls_rsa_get_len(&rsa)) {
|
||||
mbedtls_printf(" failed\n ! Invalid RSA signature size\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_sha1(buf, (int) (p - 2 - buf), hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_sha1 returned %d\n\n", ret);
|
||||
mdlen = (unsigned int) mbedtls_md_get_size(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256));
|
||||
if (mdlen == 0) {
|
||||
mbedtls_printf(" failed\n ! Invalid digest type\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_sha256(buf, (int) (p - 2 - buf), hash, 0)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_sha256 returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_rsa_pkcs1_verify(&rsa, MBEDTLS_MD_SHA256,
|
||||
32, hash, p)) != 0) {
|
||||
mdlen, hash, p)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_rsa_pkcs1_verify returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
@ -273,6 +278,8 @@ exit:
|
||||
mbedtls_dhm_free(&dhm);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_mpi_free(&N);
|
||||
mbedtls_mpi_free(&E);
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
|
@ -13,14 +13,13 @@
|
||||
|
||||
#if defined(MBEDTLS_AES_C) && defined(MBEDTLS_DHM_C) && \
|
||||
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_NET_C) && \
|
||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_MD_CAN_SHA256) && \
|
||||
defined(MBEDTLS_FS_IO) && defined(MBEDTLS_CTR_DRBG_C) && \
|
||||
defined(MBEDTLS_MD_CAN_SHA1)
|
||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_SHA256_C) && \
|
||||
defined(MBEDTLS_FS_IO) && defined(MBEDTLS_CTR_DRBG_C)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/dhm.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
|
||||
@ -33,9 +32,8 @@
|
||||
|
||||
#if !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_DHM_C) || \
|
||||
!defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NET_C) || \
|
||||
!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_MD_CAN_SHA256) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_CTR_DRBG_C) || \
|
||||
!defined(MBEDTLS_SHA1_C)
|
||||
!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_SHA256_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_AES_C and/or MBEDTLS_DHM_C and/or MBEDTLS_ENTROPY_C "
|
||||
@ -53,11 +51,12 @@ int main(void)
|
||||
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
unsigned int mdlen;
|
||||
size_t n, buflen;
|
||||
mbedtls_net_context listen_fd, client_fd;
|
||||
|
||||
unsigned char buf[2048];
|
||||
unsigned char hash[32];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char buf2[2];
|
||||
const char *pers = "dh_server";
|
||||
|
||||
@ -186,21 +185,30 @@ int main(void)
|
||||
/*
|
||||
* 5. Sign the parameters and send them
|
||||
*/
|
||||
if ((ret = mbedtls_sha1(buf, n, hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_sha1 returned %d\n\n", ret);
|
||||
|
||||
mdlen = (unsigned int) mbedtls_md_get_size(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256));
|
||||
if (mdlen == 0) {
|
||||
mbedtls_printf(" failed\n ! Invalid digest type\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
buf[n] = (unsigned char) (rsa.MBEDTLS_PRIVATE(len) >> 8);
|
||||
buf[n + 1] = (unsigned char) (rsa.MBEDTLS_PRIVATE(len));
|
||||
if ((ret = mbedtls_sha256(buf, n, hash, 0)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_sha256 returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_rsa_pkcs1_sign(&rsa, NULL, NULL, MBEDTLS_MD_SHA256,
|
||||
32, hash, buf + n + 2)) != 0) {
|
||||
const size_t rsa_key_len = mbedtls_rsa_get_len(&rsa);
|
||||
buf[n] = (unsigned char) (rsa_key_len >> 8);
|
||||
buf[n + 1] = (unsigned char) (rsa_key_len);
|
||||
|
||||
if ((ret = mbedtls_rsa_pkcs1_sign(&rsa, mbedtls_ctr_drbg_random, &ctr_drbg,
|
||||
MBEDTLS_MD_SHA256, mdlen,
|
||||
hash, buf + n + 2)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_rsa_pkcs1_sign returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
buflen = n + 2 + rsa.MBEDTLS_PRIVATE(len);
|
||||
buflen = n + 2 + rsa_key_len;
|
||||
buf2[0] = (unsigned char) (buflen >> 8);
|
||||
buf2[1] = (unsigned char) (buflen);
|
||||
|
||||
|
@ -60,8 +60,8 @@ static void dump_pubkey(const char *title, mbedtls_ecdsa_context *key)
|
||||
unsigned char buf[300];
|
||||
size_t len;
|
||||
|
||||
if (mbedtls_ecp_point_write_binary(&key->MBEDTLS_PRIVATE(grp), &key->MBEDTLS_PRIVATE(Q),
|
||||
MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof(buf)) != 0) {
|
||||
if (mbedtls_ecp_write_public_key(key, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&len, buf, sizeof(buf)) != 0) {
|
||||
mbedtls_printf("internal error\n");
|
||||
return;
|
||||
}
|
||||
@ -79,6 +79,8 @@ int main(int argc, char *argv[])
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_ecdsa_context ctx_sign, ctx_verify;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_ecp_point_init(&Q);
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
unsigned char message[100];
|
||||
@ -128,7 +130,10 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf(" ok (key size: %d bits)\n", (int) ctx_sign.MBEDTLS_PRIVATE(grp).pbits);
|
||||
mbedtls_ecp_group_id grp_id = mbedtls_ecp_keypair_get_group_id(&ctx_sign);
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(grp_id);
|
||||
mbedtls_printf(" ok (key size: %d bits)\n", (int) curve_info->bit_size);
|
||||
|
||||
dump_pubkey(" + Public key: ", &ctx_sign);
|
||||
|
||||
@ -174,16 +179,13 @@ int main(int argc, char *argv[])
|
||||
mbedtls_printf(" . Preparing verification context...");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret =
|
||||
mbedtls_ecp_group_copy(&ctx_verify.MBEDTLS_PRIVATE(grp),
|
||||
&ctx_sign.MBEDTLS_PRIVATE(grp))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ecp_group_copy returned %d\n", ret);
|
||||
if ((ret = mbedtls_ecp_export(&ctx_sign, NULL, NULL, &Q)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ecp_export returned %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret =
|
||||
mbedtls_ecp_copy(&ctx_verify.MBEDTLS_PRIVATE(Q), &ctx_sign.MBEDTLS_PRIVATE(Q))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ecp_copy returned %d\n", ret);
|
||||
if ((ret = mbedtls_ecp_set_public_key(grp_id, &ctx_verify, &Q)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ecp_set_public_key returned %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -208,6 +210,7 @@ exit:
|
||||
|
||||
mbedtls_ecdsa_free(&ctx_verify);
|
||||
mbedtls_ecdsa_free(&ctx_sign);
|
||||
mbedtls_ecp_point_free(&Q);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
|
||||
|
@ -9,8 +9,19 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_WRITE_C) && defined(MBEDTLS_FS_IO) && \
|
||||
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C)
|
||||
#if !defined(MBEDTLS_PK_WRITE_C) || !defined(MBEDTLS_PEM_WRITE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_BIGNUM_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_PK_WRITE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
||||
"MBEDTLS_PEM_WRITE_C and/or MBEDTLS_BIGNUM_C "
|
||||
"not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/ecdsa.h"
|
||||
@ -61,7 +72,6 @@ int dev_random_entropy_poll(void *data, unsigned char *output,
|
||||
return 0;
|
||||
}
|
||||
#endif /* !_WIN32 */
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#define DFL_EC_CURVE mbedtls_ecp_curve_list()->grp_id
|
||||
@ -96,19 +106,6 @@ int dev_random_entropy_poll(void *data, unsigned char *output,
|
||||
USAGE_DEV_RANDOM \
|
||||
"\n"
|
||||
|
||||
#if !defined(MBEDTLS_PK_WRITE_C) || !defined(MBEDTLS_PEM_WRITE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_PK_WRITE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
||||
"MBEDTLS_PEM_WRITE_C"
|
||||
"not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
/*
|
||||
* global options
|
||||
@ -160,6 +157,71 @@ static int write_private_key(mbedtls_pk_context *key, const char *output_file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static int show_ecp_key(const mbedtls_ecp_keypair *ecp, int has_private)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(
|
||||
mbedtls_ecp_keypair_get_group_id(ecp));
|
||||
mbedtls_printf("curve: %s\n", curve_info->name);
|
||||
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_group_init(&grp);
|
||||
mbedtls_mpi D;
|
||||
mbedtls_mpi_init(&D);
|
||||
mbedtls_ecp_point pt;
|
||||
mbedtls_ecp_point_init(&pt);
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_export(ecp, &grp,
|
||||
(has_private ? &D : NULL),
|
||||
&pt));
|
||||
|
||||
unsigned char point_bin[MBEDTLS_ECP_MAX_PT_LEN];
|
||||
size_t len = 0;
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_point_write_binary(
|
||||
&grp, &pt, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&len, point_bin, sizeof(point_bin)));
|
||||
switch (mbedtls_ecp_get_type(&grp)) {
|
||||
case MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS:
|
||||
if ((len & 1) == 0 || point_bin[0] != 0x04) {
|
||||
/* Point in an unxepected format. This shouldn't happen. */
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&X, point_bin + 1, len / 2));
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&Y, point_bin + 1 + len / 2, len / 2));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
mbedtls_mpi_write_file("Y_Q: ", &Y, 16, NULL);
|
||||
break;
|
||||
case MBEDTLS_ECP_TYPE_MONTGOMERY:
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&X, point_bin, len));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
break;
|
||||
default:
|
||||
mbedtls_printf(
|
||||
"This program does not yet support listing coordinates for this curve type.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_private) {
|
||||
mbedtls_mpi_write_file("D: ", &D, 16, NULL);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecp_group_free(&grp);
|
||||
mbedtls_mpi_free(&D);
|
||||
mbedtls_ecp_point_free(&pt);
|
||||
mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 1;
|
||||
@ -365,12 +427,10 @@ usage:
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_ECKEY) {
|
||||
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(key);
|
||||
mbedtls_printf("curve: %s\n",
|
||||
mbedtls_ecp_curve_info_from_grp_id(ecp->MBEDTLS_PRIVATE(grp).id)->name);
|
||||
mbedtls_mpi_write_file("X_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL);
|
||||
mbedtls_mpi_write_file("Y_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL);
|
||||
mbedtls_mpi_write_file("D: ", &ecp->MBEDTLS_PRIVATE(d), 16, NULL);
|
||||
if (show_ecp_key(mbedtls_pk_ec(key), 1) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
mbedtls_printf(" ! key type not supported\n");
|
||||
@ -415,5 +475,4 @@ exit:
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_PK_WRITE_C && MBEDTLS_PEM_WRITE_C && MBEDTLS_FS_IO &&
|
||||
* MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
|
||||
#endif /* program viability conditions */
|
||||
|
@ -53,6 +53,71 @@ int main(void)
|
||||
#else
|
||||
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static int show_ecp_key(const mbedtls_ecp_keypair *ecp, int has_private)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(
|
||||
mbedtls_ecp_keypair_get_group_id(ecp));
|
||||
mbedtls_printf("curve: %s\n", curve_info->name);
|
||||
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_group_init(&grp);
|
||||
mbedtls_mpi D;
|
||||
mbedtls_mpi_init(&D);
|
||||
mbedtls_ecp_point pt;
|
||||
mbedtls_ecp_point_init(&pt);
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_export(ecp, &grp,
|
||||
(has_private ? &D : NULL),
|
||||
&pt));
|
||||
|
||||
unsigned char point_bin[MBEDTLS_ECP_MAX_PT_LEN];
|
||||
size_t len = 0;
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_point_write_binary(
|
||||
&grp, &pt, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&len, point_bin, sizeof(point_bin)));
|
||||
switch (mbedtls_ecp_get_type(&grp)) {
|
||||
case MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS:
|
||||
if ((len & 1) == 0 || point_bin[0] != 0x04) {
|
||||
/* Point in an unxepected format. This shouldn't happen. */
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&X, point_bin + 1, len / 2));
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&Y, point_bin + 1 + len / 2, len / 2));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
mbedtls_mpi_write_file("Y_Q: ", &Y, 16, NULL);
|
||||
break;
|
||||
case MBEDTLS_ECP_TYPE_MONTGOMERY:
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&X, point_bin, len));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
break;
|
||||
default:
|
||||
mbedtls_printf(
|
||||
"This program does not yet support listing coordinates for this curve type.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_private) {
|
||||
mbedtls_mpi_write_file("D: ", &D, 16, NULL);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecp_group_free(&grp);
|
||||
mbedtls_mpi_free(&D);
|
||||
mbedtls_ecp_point_free(&pt);
|
||||
mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* global options
|
||||
*/
|
||||
@ -219,17 +284,10 @@ usage:
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY) {
|
||||
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(pk);
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(X): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16,
|
||||
NULL));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(Y): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16,
|
||||
NULL));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(Z): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16,
|
||||
NULL));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("D : ", &ecp->MBEDTLS_PRIVATE(d), 16, NULL));
|
||||
if (show_ecp_key(mbedtls_pk_ec(pk), 1) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto cleanup;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@ -269,16 +327,10 @@ usage:
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_ECKEY) {
|
||||
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(pk);
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(X): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16,
|
||||
NULL));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(Y): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16,
|
||||
NULL));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_write_file("Q(Z): ",
|
||||
&ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16,
|
||||
NULL));
|
||||
if (show_ecp_key(mbedtls_pk_ec(pk), 0) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto cleanup;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
@ -9,9 +9,21 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_PK_WRITE_C) && \
|
||||
defined(MBEDTLS_FS_IO) && \
|
||||
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C)
|
||||
#if !defined(MBEDTLS_PK_PARSE_C) || \
|
||||
!defined(MBEDTLS_PK_WRITE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || \
|
||||
!defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C) || \
|
||||
!defined(MBEDTLS_BIGNUM_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_PK_PARSE_C and/or MBEDTLS_PK_WRITE_C and/or "
|
||||
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
||||
"MBEDTLS_FS_IO and/or MBEDTLS_BIGNUM_C not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/error.h"
|
||||
@ -21,7 +33,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PEM_WRITE_C)
|
||||
#define USAGE_OUT \
|
||||
@ -66,20 +77,6 @@
|
||||
USAGE_OUT \
|
||||
"\n"
|
||||
|
||||
#if !defined(MBEDTLS_PK_PARSE_C) || \
|
||||
!defined(MBEDTLS_PK_WRITE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || \
|
||||
!defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_PK_PARSE_C and/or MBEDTLS_PK_WRITE_C and/or "
|
||||
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
||||
"MBEDTLS_FS_IO not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
/*
|
||||
* global options
|
||||
@ -176,6 +173,71 @@ static int write_private_key(mbedtls_pk_context *key, const char *output_file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static int show_ecp_key(const mbedtls_ecp_keypair *ecp, int has_private)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(
|
||||
mbedtls_ecp_keypair_get_group_id(ecp));
|
||||
mbedtls_printf("curve: %s\n", curve_info->name);
|
||||
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_group_init(&grp);
|
||||
mbedtls_mpi D;
|
||||
mbedtls_mpi_init(&D);
|
||||
mbedtls_ecp_point pt;
|
||||
mbedtls_ecp_point_init(&pt);
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_export(ecp, &grp,
|
||||
(has_private ? &D : NULL),
|
||||
&pt));
|
||||
|
||||
unsigned char point_bin[MBEDTLS_ECP_MAX_PT_LEN];
|
||||
size_t len = 0;
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_point_write_binary(
|
||||
&grp, &pt, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&len, point_bin, sizeof(point_bin)));
|
||||
switch (mbedtls_ecp_get_type(&grp)) {
|
||||
case MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS:
|
||||
if ((len & 1) == 0 || point_bin[0] != 0x04) {
|
||||
/* Point in an unxepected format. This shouldn't happen. */
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&X, point_bin + 1, len / 2));
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&Y, point_bin + 1 + len / 2, len / 2));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
mbedtls_mpi_write_file("Y_Q: ", &Y, 16, NULL);
|
||||
break;
|
||||
case MBEDTLS_ECP_TYPE_MONTGOMERY:
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&X, point_bin, len));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
break;
|
||||
default:
|
||||
mbedtls_printf(
|
||||
"This program does not yet support listing coordinates for this curve type.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_private) {
|
||||
mbedtls_mpi_write_file("D: ", &D, 16, NULL);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecp_group_free(&grp);
|
||||
mbedtls_mpi_free(&D);
|
||||
mbedtls_ecp_point_free(&pt);
|
||||
mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 1;
|
||||
@ -338,11 +400,10 @@ usage:
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_ECKEY) {
|
||||
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(key);
|
||||
mbedtls_mpi_write_file("Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL);
|
||||
mbedtls_mpi_write_file("Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL);
|
||||
mbedtls_mpi_write_file("Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL);
|
||||
mbedtls_mpi_write_file("D : ", &ecp->MBEDTLS_PRIVATE(d), 16, NULL);
|
||||
if (show_ecp_key(mbedtls_pk_ec(key), 1) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
mbedtls_printf("key type not supported yet\n");
|
||||
@ -384,10 +445,10 @@ usage:
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_ECKEY) {
|
||||
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(key);
|
||||
mbedtls_mpi_write_file("Q(X): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL);
|
||||
mbedtls_mpi_write_file("Q(Y): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL);
|
||||
mbedtls_mpi_write_file("Q(Z): ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Z), 16, NULL);
|
||||
if (show_ecp_key(mbedtls_pk_ec(key), 0) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
mbedtls_printf("key type not supported yet\n");
|
||||
@ -431,5 +492,4 @@ exit:
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_PK_PARSE_C && MBEDTLS_PK_WRITE_C && MBEDTLS_FS_IO &&
|
||||
MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
|
||||
#endif /* program viability conditions */
|
||||
|
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (i != rsa.MBEDTLS_PRIVATE(len)) {
|
||||
if (i != mbedtls_rsa_get_len(&rsa)) {
|
||||
mbedtls_printf("\n ! Invalid RSA signature format\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < rsa.MBEDTLS_PRIVATE(len); i++) {
|
||||
for (i = 0; i < mbedtls_rsa_get_len(&rsa); i++) {
|
||||
mbedtls_fprintf(f, "%02X%s", buf[i],
|
||||
(i + 1) % 16 == 0 ? "\r\n" : " ");
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < rsa.MBEDTLS_PRIVATE(len); i++) {
|
||||
for (i = 0; i < mbedtls_rsa_get_len(&rsa); i++) {
|
||||
mbedtls_fprintf(f, "%02X%s", buf[i],
|
||||
(i + 1) % 16 == 0 ? "\r\n" : " ");
|
||||
}
|
||||
|
@ -37,11 +37,14 @@ int main(int argc, char *argv[])
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
size_t i;
|
||||
mbedtls_rsa_context rsa;
|
||||
mbedtls_mpi N, E;
|
||||
unsigned char hash[32];
|
||||
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
|
||||
char filename[512];
|
||||
|
||||
mbedtls_rsa_init(&rsa);
|
||||
mbedtls_mpi_init(&N);
|
||||
mbedtls_mpi_init(&E);
|
||||
|
||||
if (argc != 2) {
|
||||
mbedtls_printf("usage: rsa_verify <filename>\n");
|
||||
@ -62,15 +65,13 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(N), 16, f)) != 0 ||
|
||||
(ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(E), 16, f)) != 0) {
|
||||
if ((ret = mbedtls_mpi_read_file(&N, 16, f)) != 0 ||
|
||||
(ret = mbedtls_mpi_read_file(&E, 16, f)) != 0 ||
|
||||
(ret = mbedtls_rsa_import(&rsa, &N, NULL, NULL, NULL, &E) != 0)) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret);
|
||||
fclose(f);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rsa.MBEDTLS_PRIVATE(len) = (mbedtls_mpi_bitlen(&rsa.MBEDTLS_PRIVATE(N)) + 7) >> 3;
|
||||
|
||||
fclose(f);
|
||||
|
||||
/*
|
||||
@ -91,7 +92,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (i != rsa.MBEDTLS_PRIVATE(len)) {
|
||||
if (i != mbedtls_rsa_get_len(&rsa)) {
|
||||
mbedtls_printf("\n ! Invalid RSA signature format\n\n");
|
||||
goto exit;
|
||||
}
|
||||
@ -124,6 +125,8 @@ int main(int argc, char *argv[])
|
||||
exit:
|
||||
|
||||
mbedtls_rsa_free(&rsa);
|
||||
mbedtls_mpi_free(&N);
|
||||
mbedtls_mpi_free(&E);
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ endif()
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -5,7 +5,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
set(THREADS_USE_PTHREADS_WIN32 true)
|
||||
find_package(Threads)
|
||||
|
||||
set(libs
|
||||
@ -39,7 +38,7 @@ foreach(exe IN LISTS executables)
|
||||
endif()
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>
|
||||
${extra_sources})
|
||||
target_link_libraries(${exe} ${libs})
|
||||
target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2")
|
||||
if(GEN_FILES)
|
||||
|
@ -1612,6 +1612,7 @@ int main(int argc, char *argv[])
|
||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
||||
int tls13_early_data_enabled = MBEDTLS_SSL_EARLY_DATA_DISABLED;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
@ -3450,6 +3451,19 @@ handshake:
|
||||
fflush(stdout);
|
||||
|
||||
while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) {
|
||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
||||
if (ret == MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA) {
|
||||
memset(buf, 0, opt.buffer_size);
|
||||
ret = mbedtls_ssl_read_early_data(&ssl, buf, opt.buffer_size);
|
||||
if (ret > 0) {
|
||||
buf[ret] = '\0';
|
||||
mbedtls_printf(" %d early data bytes read\n\n%s\n",
|
||||
ret, (char *) buf);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
if (ret == MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS &&
|
||||
ssl_async_keys.inject_error == SSL_ASYNC_INJECT_ERROR_CANCEL) {
|
||||
@ -3521,7 +3535,7 @@ handshake:
|
||||
mbedtls_printf(" [ Record expansion is unknown ]\n");
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) || defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
|
||||
mbedtls_printf(" [ Maximum incoming record payload length is %u ]\n",
|
||||
(unsigned int) mbedtls_ssl_get_max_in_record_payload(&ssl));
|
||||
mbedtls_printf(" [ Maximum outgoing record payload length is %u ]\n",
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "ssl_test_lib.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
#include "test/helpers.h"
|
||||
#include "test/threading_helpers.h"
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SSL_TEST_IMPOSSIBLE)
|
||||
@ -515,17 +515,31 @@ static const struct {
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED) && \
|
||||
defined(PSA_WANT_ALG_FFDH)
|
||||
#if defined(PSA_WANT_DH_RFC7919_2048)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048, "ffdhe2048", 1 },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072, "ffdhe3072", 1 },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096, "ffdhe4096", 1 },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144, "ffdhe6144", 1 },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192, "ffdhe8192", 1 },
|
||||
#else
|
||||
#else /* PSA_WANT_DH_RFC7919_2048 */
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048, "ffdhe2048", 0 },
|
||||
#endif /* PSA_WANT_DH_RFC7919_2048 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_3072)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072, "ffdhe3072", 1 },
|
||||
#else /* PSA_WANT_DH_RFC7919_3072 */
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072, "ffdhe3072", 0 },
|
||||
#endif /* PSA_WANT_DH_RFC7919_3072 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_4096)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096, "ffdhe4096", 1 },
|
||||
#else /* PSA_WANT_DH_RFC7919_4096 */
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096, "ffdhe4096", 0 },
|
||||
#endif /* PSA_WANT_DH_RFC7919_4096 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_6144)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144, "ffdhe6144", 1 },
|
||||
#else /* PSA_WANT_DH_RFC7919_6144 */
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144, "ffdhe6144", 0 },
|
||||
#endif /* PSA_WANT_DH_RFC7919_6144 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_8192)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192, "ffdhe8192", 1 },
|
||||
#else /* PSA_WANT_DH_RFC7919_8192 */
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192, "ffdhe8192", 0 },
|
||||
#endif /* PSA_WANT_DH_RFC7919_8192 */
|
||||
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED && PSA_WANT_ALG_FFDH */
|
||||
{ 0, NULL, 0 },
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ if(TEST_CPP)
|
||||
)
|
||||
add_executable(cpp_dummy_build "${cpp_dummy_build_cpp}")
|
||||
target_include_directories(cpp_dummy_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||
target_link_libraries(cpp_dummy_build ${mbedcrypto_target})
|
||||
target_link_libraries(cpp_dummy_build ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if(USE_SHARED_MBEDTLS_LIBRARY AND
|
||||
@ -81,9 +81,9 @@ foreach(exe IN LISTS executables_libs executables_mbedcrypto)
|
||||
# This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
|
||||
list(FIND executables_libs ${exe} exe_index)
|
||||
if (${exe_index} GREATER -1)
|
||||
target_link_libraries(${exe} ${libs})
|
||||
target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
else()
|
||||
target_link_libraries(${exe} ${mbedcrypto_target})
|
||||
target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
@ -507,7 +507,7 @@ typedef struct {
|
||||
char md5, ripemd160, sha1, sha256, sha512,
|
||||
sha3_224, sha3_256, sha3_384, sha3_512,
|
||||
des3, des,
|
||||
aes_cbc, aes_cfb128, aes_cfb8, aes_gcm, aes_ccm, aes_xts, chachapoly,
|
||||
aes_cbc, aes_cfb128, aes_cfb8, aes_ctr, aes_gcm, aes_ccm, aes_xts, chachapoly,
|
||||
aes_cmac, des3_cmac,
|
||||
aria, camellia, chacha20,
|
||||
poly1305,
|
||||
@ -571,6 +571,8 @@ int main(int argc, char *argv[])
|
||||
todo.aes_cfb128 = 1;
|
||||
} else if (strcmp(argv[i], "aes_cfb8") == 0) {
|
||||
todo.aes_cfb8 = 1;
|
||||
} else if (strcmp(argv[i], "aes_ctr") == 0) {
|
||||
todo.aes_ctr = 1;
|
||||
} else if (strcmp(argv[i], "aes_xts") == 0) {
|
||||
todo.aes_xts = 1;
|
||||
} else if (strcmp(argv[i], "aes_gcm") == 0) {
|
||||
@ -774,6 +776,31 @@ int main(int argc, char *argv[])
|
||||
mbedtls_aes_free(&aes);
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
if (todo.aes_ctr) {
|
||||
int keysize;
|
||||
mbedtls_aes_context aes;
|
||||
|
||||
uint8_t stream_block[16];
|
||||
size_t nc_off;
|
||||
|
||||
mbedtls_aes_init(&aes);
|
||||
for (keysize = 128; keysize <= 256; keysize += 64) {
|
||||
mbedtls_snprintf(title, sizeof(title), "AES-CTR-%d", keysize);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
memset(stream_block, 0, sizeof(stream_block));
|
||||
nc_off = 0;
|
||||
|
||||
CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));
|
||||
|
||||
TIME_AND_TSC(title, mbedtls_aes_crypt_ctr(&aes, BUFSIZE, &nc_off, tmp, stream_block,
|
||||
buf, buf));
|
||||
}
|
||||
mbedtls_aes_free(&aes);
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
if (todo.aes_xts) {
|
||||
int keysize;
|
||||
|
@ -20,4 +20,4 @@ set(libs
|
||||
)
|
||||
|
||||
add_executable(cmake_subproject cmake_subproject.c)
|
||||
target_link_libraries(cmake_subproject ${libs})
|
||||
target_link_libraries(cmake_subproject ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <mbedtls/platform.h>
|
||||
#include <mbedtls/platform_util.h>
|
||||
#include "test/helpers.h"
|
||||
#include "test/threading_helpers.h"
|
||||
#include "test/macros.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -9,7 +9,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${libs})
|
||||
target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
@ -13,7 +13,7 @@ set(executables
|
||||
|
||||
foreach(exe IN LISTS executables)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
target_link_libraries(${exe} ${libs})
|
||||
target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
|
||||
endforeach()
|
||||
|
||||
|
Reference in New Issue
Block a user