mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-14 14:05:38 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
162
Living_SDK/security/alicrypto/mbedtls/library/CMakeLists.txt
Normal file
162
Living_SDK/security/alicrypto/mbedtls/library/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
|
||||
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
|
||||
option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
|
||||
|
||||
set(src_crypto
|
||||
aes.c
|
||||
aesni.c
|
||||
arc4.c
|
||||
asn1parse.c
|
||||
asn1write.c
|
||||
base64.c
|
||||
bignum.c
|
||||
blowfish.c
|
||||
camellia.c
|
||||
ccm.c
|
||||
cipher.c
|
||||
cipher_wrap.c
|
||||
cmac.c
|
||||
ctr_drbg.c
|
||||
des.c
|
||||
dhm.c
|
||||
ecdh.c
|
||||
ecdsa.c
|
||||
ecjpake.c
|
||||
ecp.c
|
||||
ecp_curves.c
|
||||
entropy.c
|
||||
entropy_poll.c
|
||||
error.c
|
||||
gcm.c
|
||||
havege.c
|
||||
hmac_drbg.c
|
||||
md.c
|
||||
md2.c
|
||||
md4.c
|
||||
md5.c
|
||||
md_wrap.c
|
||||
memory_buffer_alloc.c
|
||||
oid.c
|
||||
padlock.c
|
||||
pem.c
|
||||
pk.c
|
||||
pk_wrap.c
|
||||
pkcs12.c
|
||||
pkcs5.c
|
||||
pkparse.c
|
||||
pkwrite.c
|
||||
platform.c
|
||||
ripemd160.c
|
||||
rsa.c
|
||||
sha1.c
|
||||
sha256.c
|
||||
sha512.c
|
||||
threading.c
|
||||
timing.c
|
||||
version.c
|
||||
version_features.c
|
||||
xtea.c
|
||||
)
|
||||
|
||||
set(src_x509
|
||||
certs.c
|
||||
pkcs11.c
|
||||
x509.c
|
||||
x509_create.c
|
||||
x509_crl.c
|
||||
x509_crt.c
|
||||
x509_csr.c
|
||||
x509write_crt.c
|
||||
x509write_csr.c
|
||||
)
|
||||
|
||||
set(src_tls
|
||||
debug.c
|
||||
net_sockets.c
|
||||
ssl_cache.c
|
||||
ssl_ciphersuites.c
|
||||
ssl_cli.c
|
||||
ssl_cookie.c
|
||||
ssl_srv.c
|
||||
ssl_ticket.c
|
||||
ssl_tls.c
|
||||
)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
|
||||
endif(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
if(CMAKE_COMPILER_IS_CLANG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
|
||||
endif(CMAKE_COMPILER_IS_CLANG)
|
||||
|
||||
if(WIN32)
|
||||
set(libs ${libs} ws2_32)
|
||||
endif(WIN32)
|
||||
|
||||
if(USE_PKCS11_HELPER_LIBRARY)
|
||||
set(libs ${libs} pkcs11-helper)
|
||||
endif(USE_PKCS11_HELPER_LIBRARY)
|
||||
|
||||
if(ENABLE_ZLIB_SUPPORT)
|
||||
set(libs ${libs} ${ZLIB_LIBRARIES})
|
||||
endif(ENABLE_ZLIB_SUPPORT)
|
||||
|
||||
if(LINK_WITH_PTHREAD)
|
||||
set(libs ${libs} pthread)
|
||||
endif()
|
||||
|
||||
if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
||||
message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
|
||||
endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
||||
|
||||
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
||||
set(mbedtls_static_target "mbedtls_static")
|
||||
set(mbedx509_static_target "mbedx509_static")
|
||||
set(mbedcrypto_static_target "mbedcrypto_static")
|
||||
elseif(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
set(mbedtls_static_target "mbedtls")
|
||||
set(mbedx509_static_target "mbedx509")
|
||||
set(mbedcrypto_static_target "mbedcrypto")
|
||||
endif()
|
||||
|
||||
if(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
|
||||
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
|
||||
target_link_libraries(${mbedcrypto_static_target} ${libs})
|
||||
|
||||
add_library(${mbedx509_static_target} STATIC ${src_x509})
|
||||
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
|
||||
target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
|
||||
|
||||
add_library(${mbedtls_static_target} STATIC ${src_tls})
|
||||
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
|
||||
target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
|
||||
|
||||
install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
|
||||
DESTINATION ${LIB_INSTALL_DIR}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
endif(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
|
||||
if(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
add_library(mbedcrypto SHARED ${src_crypto})
|
||||
set_target_properties(mbedcrypto PROPERTIES VERSION 2.4.1 SOVERSION 0)
|
||||
target_link_libraries(mbedcrypto ${libs})
|
||||
|
||||
add_library(mbedx509 SHARED ${src_x509})
|
||||
set_target_properties(mbedx509 PROPERTIES VERSION 2.4.1 SOVERSION 0)
|
||||
target_link_libraries(mbedx509 ${libs} mbedcrypto)
|
||||
|
||||
add_library(mbedtls SHARED ${src_tls})
|
||||
set_target_properties(mbedtls PROPERTIES VERSION 2.4.1 SOVERSION 10)
|
||||
target_link_libraries(mbedtls ${libs} mbedx509)
|
||||
|
||||
install(TARGETS mbedtls mbedx509 mbedcrypto
|
||||
DESTINATION ${LIB_INSTALL_DIR}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
|
||||
add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
|
||||
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
||||
add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
|
||||
endif()
|
||||
194
Living_SDK/security/alicrypto/mbedtls/library/Makefile
Normal file
194
Living_SDK/security/alicrypto/mbedtls/library/Makefile
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
|
||||
# Also see "include/mbedtls/config.h"
|
||||
|
||||
#TOOLCHAIN_PRE := arm-none-eabi-
|
||||
#TOOLCHAIN_PRE := arm-linux-gnueabihf-
|
||||
TOOLCHAIN_PRE :=
|
||||
CC = $(TOOLCHAIN_PRE)gcc
|
||||
LD = $(TOOLCHAIN_PRE)ld
|
||||
AR = $(TOOLCHAIN_PRE)ar
|
||||
|
||||
CFLAGS ?= -O2
|
||||
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
|
||||
LDFLAGS ?=
|
||||
|
||||
ifeq ($(m32),1)
|
||||
CFLAGS += -m32
|
||||
endif
|
||||
|
||||
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -I../../libalicrypto/inc -D_FILE_OFFSET_BITS=64
|
||||
#-DCONFIG_NO_ALIOS=1
|
||||
LOCAL_LDFLAGS =
|
||||
|
||||
ifdef DEBUG
|
||||
LOCAL_CFLAGS += -g3
|
||||
endif
|
||||
|
||||
# MicroBlaze specific options:
|
||||
# CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
|
||||
|
||||
# To compile on Plan9:
|
||||
# CFLAGS += -D_BSD_EXTENSION
|
||||
|
||||
# if were running on Windows build for Windows
|
||||
ifdef WINDOWS
|
||||
WINDOWS_BUILD=1
|
||||
endif
|
||||
|
||||
# To compile as a shared library:
|
||||
ifdef SHARED
|
||||
# all code is position-indep with mingw, avoid warning about useless flag
|
||||
ifndef WINDOWS_BUILD
|
||||
LOCAL_CFLAGS += -fPIC -fpic
|
||||
endif
|
||||
endif
|
||||
|
||||
SOEXT_TLS=so.10
|
||||
SOEXT_X509=so.0
|
||||
SOEXT_CRYPTO=so.0
|
||||
|
||||
DLEXT=so
|
||||
# OSX shared library extension:
|
||||
# DLEXT=dylib
|
||||
|
||||
# Windows shared library extension:
|
||||
ifdef WINDOWS_BUILD
|
||||
DLEXT=dll
|
||||
endif
|
||||
|
||||
OBJS_CRYPTO= aes.o \
|
||||
bignum.o asn1parse.o \
|
||||
oid.o \
|
||||
md5.o hash_wrap.o \
|
||||
rsa.o sha1.o \
|
||||
sha256.o \
|
||||
threading.o \
|
||||
hmac.o \
|
||||
|
||||
LOCAL_CFLAGS += -I../../../yunos_iot/aos/include
|
||||
OBJS_CRYPTO += \
|
||||
mbedtls_alt.o
|
||||
|
||||
#OBJS_CRYPTO= aes.o aesni.o arc4.o \
|
||||
asn1parse.o asn1write.o base64.o \
|
||||
bignum.o blowfish.o camellia.o \
|
||||
ccm.o cipher.o cipher_wrap.o \
|
||||
cmac.o ctr_drbg.o des.o \
|
||||
dhm.o ecdh.o ecdsa.o \
|
||||
ecjpake.o ecp.o \
|
||||
ecp_curves.o entropy.o entropy_poll.o \
|
||||
error.o gcm.o havege.o \
|
||||
hmac_drbg.o md.o md2.o \
|
||||
md4.o md5.o md_wrap.o \
|
||||
memory_buffer_alloc.o oid.o \
|
||||
padlock.o pem.o pk.o \
|
||||
pk_wrap.o pkcs12.o pkcs5.o \
|
||||
pkparse.o pkwrite.o platform.o \
|
||||
ripemd160.o rsa.o sha1.o \
|
||||
sha256.o sha512.o threading.o \
|
||||
timing.o version.o \
|
||||
version_features.o xtea.o
|
||||
|
||||
OBJS_X509= certs.o pkcs11.o x509.o \
|
||||
x509_create.o x509_crl.o x509_crt.o \
|
||||
x509_csr.o x509write_crt.o x509write_csr.o
|
||||
|
||||
OBJS_TLS= debug.o net_sockets.o \
|
||||
ssl_cache.o ssl_ciphersuites.o \
|
||||
ssl_cli.o ssl_cookie.o \
|
||||
ssl_srv.o ssl_ticket.o \
|
||||
ssl_tls.o
|
||||
|
||||
.SILENT:
|
||||
|
||||
.PHONY: all static shared clean
|
||||
|
||||
ifndef SHARED
|
||||
all: static
|
||||
else
|
||||
all: shared static
|
||||
endif
|
||||
|
||||
static: libmbedcrypto.a #libmbedx509.a libmbedtls.a
|
||||
|
||||
shared: libmbedcrypto.$(DLEXT) #libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
|
||||
|
||||
# tls
|
||||
libmbedtls.a: $(OBJS_TLS)
|
||||
echo " AR $@"
|
||||
$(AR) -rc $@ $(OBJS_TLS)
|
||||
echo " RL $@"
|
||||
$(AR) -s $@
|
||||
|
||||
libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
|
||||
|
||||
libmbedtls.so: libmbedtls.$(SOEXT_TLS)
|
||||
echo " LN $@ -> $<"
|
||||
ln -sf $< $@
|
||||
|
||||
libmbedtls.dylib: $(OBJS_TLS)
|
||||
echo " LD $@"
|
||||
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
|
||||
|
||||
libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -lmbedx509 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
|
||||
|
||||
# x509
|
||||
libmbedx509.a: $(OBJS_X509)
|
||||
echo " AR $@"
|
||||
$(AR) -rc $@ $(OBJS_X509)
|
||||
echo " RL $@"
|
||||
$(AR) -s $@
|
||||
|
||||
libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
|
||||
|
||||
libmbedx509.so: libmbedx509.$(SOEXT_X509)
|
||||
echo " LN $@ -> $<"
|
||||
ln -sf $< $@
|
||||
|
||||
libmbedx509.dylib: $(OBJS_X509)
|
||||
echo " LD $@"
|
||||
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
|
||||
|
||||
libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
|
||||
|
||||
# crypto
|
||||
libmbedcrypto.a: $(OBJS_CRYPTO)
|
||||
echo " AR $@"
|
||||
$(AR) -rc $@ $(OBJS_CRYPTO)
|
||||
echo " RL $@"
|
||||
$(AR) -s $@
|
||||
|
||||
libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
|
||||
|
||||
libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
|
||||
echo " LN $@ -> $<"
|
||||
ln -sf $< $@
|
||||
|
||||
libmbedcrypto.dylib: $(OBJS_CRYPTO)
|
||||
echo " LD $@"
|
||||
$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
|
||||
|
||||
libmbedcrypto.dll: $(OBJS_CRYPTO)
|
||||
echo " LD $@"
|
||||
$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
|
||||
|
||||
.c.o:
|
||||
echo " CC $< CFLAGS $(CFLAGS)"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
ifndef WINDOWS
|
||||
rm -f *.o libmbed*
|
||||
else
|
||||
del /Q /F *.o libmbed*
|
||||
endif
|
||||
1492
Living_SDK/security/alicrypto/mbedtls/library/aes.c
Normal file
1492
Living_SDK/security/alicrypto/mbedtls/library/aes.c
Normal file
File diff suppressed because it is too large
Load diff
397
Living_SDK/security/alicrypto/mbedtls/library/asn1parse.c
Normal file
397
Living_SDK/security/alicrypto/mbedtls/library/asn1parse.c
Normal file
|
|
@ -0,0 +1,397 @@
|
|||
/*
|
||||
* Generic ASN.1 parsing
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
|
||||
#include "mbedtls/asn1.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
#include "mbedtls/bignum.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#ifdef MBEDTLS_IOT_PLAT_AOS
|
||||
#include <aos/kernel.h>
|
||||
#define mbedtls_malloc aos_malloc
|
||||
#define mbedtls_free aos_free
|
||||
#else
|
||||
#define mbedtls_malloc malloc
|
||||
#define mbedtls_free free
|
||||
#endif /* MBEDTLS_IOT_PLAT_AOS */
|
||||
#endif
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* ASN.1 DER decoding routines
|
||||
*/
|
||||
int mbedtls_asn1_get_len( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len )
|
||||
{
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
if( ( **p & 0x80 ) == 0 )
|
||||
*len = *(*p)++;
|
||||
else
|
||||
{
|
||||
switch( **p & 0x7F )
|
||||
{
|
||||
case 1:
|
||||
if( ( end - *p ) < 2 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
*len = (*p)[1];
|
||||
(*p) += 2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if( ( end - *p ) < 3 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
*len = ( (size_t)(*p)[1] << 8 ) | (*p)[2];
|
||||
(*p) += 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if( ( end - *p ) < 4 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
*len = ( (size_t)(*p)[1] << 16 ) |
|
||||
( (size_t)(*p)[2] << 8 ) | (*p)[3];
|
||||
(*p) += 4;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if( ( end - *p ) < 5 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
*len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) |
|
||||
( (size_t)(*p)[3] << 8 ) | (*p)[4];
|
||||
(*p) += 5;
|
||||
break;
|
||||
|
||||
default:
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
}
|
||||
}
|
||||
|
||||
if( *len > (size_t) ( end - *p ) )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_get_tag( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len, int tag )
|
||||
{
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
if( **p != tag )
|
||||
return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
|
||||
(*p)++;
|
||||
|
||||
return( mbedtls_asn1_get_len( p, end, len ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_get_bool( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val )
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_BOOLEAN ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( len != 1 )
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
|
||||
*val = ( **p != 0 ) ? 1 : 0;
|
||||
(*p)++;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_get_int( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val )
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( len == 0 || len > sizeof( int ) || ( **p & 0x80 ) != 0 )
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
|
||||
*val = 0;
|
||||
|
||||
while( len-- > 0 )
|
||||
{
|
||||
*val = ( *val << 8 ) | **p;
|
||||
(*p)++;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
int mbedtls_asn1_get_mpi( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_mpi *X )
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
ret = mbedtls_mpi_read_binary( X, *p, len );
|
||||
|
||||
*p += len;
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
|
||||
mbedtls_asn1_bitstring *bs)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Certificate type is a single byte bitstring */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
/* Check length, subtract one for actual bit string length */
|
||||
if( bs->len < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
bs->len -= 1;
|
||||
|
||||
/* Get number of unused bits, ensure unused bits <= 7 */
|
||||
bs->unused_bits = **p;
|
||||
if( bs->unused_bits > 7 )
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
(*p)++;
|
||||
|
||||
/* Get actual bitstring */
|
||||
bs->p = *p;
|
||||
*p += bs->len;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a bit string without unused bits
|
||||
*/
|
||||
int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
|
||||
size_t *len )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( (*len)-- < 2 || *(*p)++ != 0 )
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_DATA );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Parses and splits an ASN.1 "SEQUENCE OF <tag>"
|
||||
*/
|
||||
int mbedtls_asn1_get_sequence_of( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_sequence *cur,
|
||||
int tag)
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
mbedtls_asn1_buf *buf;
|
||||
|
||||
/* Get main sequence tag */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
while( *p < end )
|
||||
{
|
||||
buf = &(cur->buf);
|
||||
buf->tag = **p;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &buf->len, tag ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
buf->p = *p;
|
||||
*p += buf->len;
|
||||
|
||||
/* Allocate and assign next pointer */
|
||||
if( *p < end )
|
||||
{
|
||||
cur->next = (mbedtls_asn1_sequence*)mbedtls_malloc( sizeof( mbedtls_asn1_sequence ) );
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
|
||||
memset(cur->next, 0, sizeof(mbedtls_asn1_sequence));
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set final sequence entry's next pointer to NULL */
|
||||
cur->next = NULL;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_get_alg( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params )
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
alg->tag = **p;
|
||||
end = *p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
alg->p = *p;
|
||||
*p += alg->len;
|
||||
|
||||
if( *p == end )
|
||||
{
|
||||
mbedtls_zeroize( params, sizeof(mbedtls_asn1_buf) );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
params->tag = **p;
|
||||
(*p)++;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_len( p, end, ¶ms->len ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
params->p = *p;
|
||||
*p += params->len;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_get_alg_null( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg )
|
||||
{
|
||||
int ret;
|
||||
mbedtls_asn1_buf params;
|
||||
|
||||
memset( ¶ms, 0, sizeof(mbedtls_asn1_buf) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg( p, end, alg, ¶ms ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( ( params.tag != MBEDTLS_ASN1_NULL && params.tag != 0 ) || params.len != 0 )
|
||||
return( MBEDTLS_ERR_ASN1_INVALID_DATA );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur )
|
||||
{
|
||||
if( cur == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_free( cur->oid.p );
|
||||
mbedtls_free( cur->val.p );
|
||||
|
||||
mbedtls_zeroize( cur, sizeof( mbedtls_asn1_named_data ) );
|
||||
}
|
||||
|
||||
void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
|
||||
{
|
||||
mbedtls_asn1_named_data *cur;
|
||||
|
||||
while( ( cur = *head ) != NULL )
|
||||
{
|
||||
*head = cur->next;
|
||||
mbedtls_asn1_free_named_data( cur );
|
||||
mbedtls_free( cur );
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len )
|
||||
{
|
||||
while( list != NULL )
|
||||
{
|
||||
if( list->oid.len == len &&
|
||||
memcmp( list->oid.p, oid, len ) == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return( list );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_ASN1_PARSE_C */
|
||||
2590
Living_SDK/security/alicrypto/mbedtls/library/bignum.c
Normal file
2590
Living_SDK/security/alicrypto/mbedtls/library/bignum.c
Normal file
File diff suppressed because it is too large
Load diff
366
Living_SDK/security/alicrypto/mbedtls/library/debug.c
Normal file
366
Living_SDK/security/alicrypto/mbedtls/library/debug.c
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
* Debugging routines
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_time_t time_t
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#include "mbedtls/debug.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#define DEBUG_BUF_SIZE 512
|
||||
|
||||
static int debug_threshold = 0;
|
||||
|
||||
void mbedtls_debug_set_threshold( int threshold )
|
||||
{
|
||||
debug_threshold = threshold;
|
||||
}
|
||||
|
||||
/*
|
||||
* All calls to f_dbg must be made via this function
|
||||
*/
|
||||
static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *str )
|
||||
{
|
||||
/*
|
||||
* If in a threaded environment, we need a thread identifier.
|
||||
* Since there is no portable way to get one, use the address of the ssl
|
||||
* context instead, as it shouldn't be shared between threads.
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
|
||||
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
|
||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
|
||||
#else
|
||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
||||
#endif
|
||||
}
|
||||
|
||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *format, ... )
|
||||
{
|
||||
va_list argp;
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
int ret;
|
||||
|
||||
if( NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold )
|
||||
return;
|
||||
|
||||
va_start( argp, format );
|
||||
#if defined(_WIN32)
|
||||
#if defined(_TRUNCATE)
|
||||
ret = _vsnprintf_s( str, DEBUG_BUF_SIZE, _TRUNCATE, format, argp );
|
||||
#else
|
||||
ret = _vsnprintf( str, DEBUG_BUF_SIZE, format, argp );
|
||||
if( ret < 0 || (size_t) ret == DEBUG_BUF_SIZE )
|
||||
{
|
||||
str[DEBUG_BUF_SIZE-1] = '\0';
|
||||
ret = -1;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
ret = vsnprintf( str, DEBUG_BUF_SIZE, format, argp );
|
||||
#endif
|
||||
va_end( argp );
|
||||
|
||||
if( ret >= 0 && ret < DEBUG_BUF_SIZE - 1 )
|
||||
{
|
||||
str[ret] = '\n';
|
||||
str[ret + 1] = '\0';
|
||||
}
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
|
||||
void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, int ret )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
/*
|
||||
* With non-blocking I/O and examples that just retry immediately,
|
||||
* the logs would be quickly flooded with WANT_READ, so ignore that.
|
||||
* Don't ignore WANT_WRITE however, since is is usually rare.
|
||||
*/
|
||||
if( ret == MBEDTLS_ERR_SSL_WANT_READ )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
|
||||
text, ret, -ret );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
|
||||
void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line, const char *text,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
char txt[17];
|
||||
size_t i, idx = 0;
|
||||
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
|
||||
text, (unsigned int) len );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
idx = 0;
|
||||
memset( txt, 0, sizeof( txt ) );
|
||||
for( i = 0; i < len; i++ )
|
||||
{
|
||||
if( i >= 4096 )
|
||||
break;
|
||||
|
||||
if( i % 16 == 0 )
|
||||
{
|
||||
if( i > 0 )
|
||||
{
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
idx = 0;
|
||||
memset( txt, 0, sizeof( txt ) );
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
|
||||
(unsigned int) i );
|
||||
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x",
|
||||
(unsigned int) buf[i] );
|
||||
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
|
||||
}
|
||||
|
||||
if( len > 0 )
|
||||
{
|
||||
for( /* i = i */; i % 16 != 0; i++ )
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_ecp_point *X )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
|
||||
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s(Y)", text );
|
||||
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->Y );
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_mpi *X )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
int j, k, zeros = 1;
|
||||
size_t i, n, idx = 0;
|
||||
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || X == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
for( n = X->n - 1; n > 0; n-- )
|
||||
if( X->p[n] != 0 )
|
||||
break;
|
||||
|
||||
for( j = ( sizeof(mbedtls_mpi_uint) << 3 ) - 1; j >= 0; j-- )
|
||||
if( ( ( X->p[n] >> j ) & 1 ) != 0 )
|
||||
break;
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
|
||||
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
idx = 0;
|
||||
for( i = n + 1, j = 0; i > 0; i-- )
|
||||
{
|
||||
if( zeros && X->p[i - 1] == 0 )
|
||||
continue;
|
||||
|
||||
for( k = sizeof( mbedtls_mpi_uint ) - 1; k >= 0; k-- )
|
||||
{
|
||||
if( zeros && ( ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF ) == 0 )
|
||||
continue;
|
||||
else
|
||||
zeros = 0;
|
||||
|
||||
if( j % 16 == 0 )
|
||||
{
|
||||
if( j > 0 )
|
||||
{
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
|
||||
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
|
||||
|
||||
j++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( zeros == 1 )
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_pk_context *pk )
|
||||
{
|
||||
size_t i;
|
||||
mbedtls_pk_debug_item items[MBEDTLS_PK_DEBUG_MAX_ITEMS];
|
||||
char name[16];
|
||||
|
||||
memset( items, 0, sizeof( items ) );
|
||||
|
||||
if( mbedtls_pk_debug( pk, items ) != 0 )
|
||||
{
|
||||
debug_send_line( ssl, level, file, line,
|
||||
"invalid PK context\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
for( i = 0; i < MBEDTLS_PK_DEBUG_MAX_ITEMS; i++ )
|
||||
{
|
||||
if( items[i].type == MBEDTLS_PK_DEBUG_NONE )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
|
||||
name[sizeof( name ) - 1] = '\0';
|
||||
|
||||
if( items[i].type == MBEDTLS_PK_DEBUG_MPI )
|
||||
mbedtls_debug_print_mpi( ssl, level, file, line, name, items[i].value );
|
||||
else
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if( items[i].type == MBEDTLS_PK_DEBUG_ECP )
|
||||
mbedtls_debug_print_ecp( ssl, level, file, line, name, items[i].value );
|
||||
else
|
||||
#endif
|
||||
debug_send_line( ssl, level, file, line,
|
||||
"should not happen\n" );
|
||||
}
|
||||
}
|
||||
|
||||
static void debug_print_line_by_line( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line, const char *text )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
const char *start, *cur;
|
||||
|
||||
start = text;
|
||||
for( cur = text; *cur != '\0'; cur++ )
|
||||
{
|
||||
if( *cur == '\n' )
|
||||
{
|
||||
size_t len = cur - start + 1;
|
||||
if( len > DEBUG_BUF_SIZE - 1 )
|
||||
len = DEBUG_BUF_SIZE - 1;
|
||||
|
||||
memcpy( str, start, len );
|
||||
str[len] = '\0';
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
start = cur + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_x509_crt *crt )
|
||||
{
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
int i = 0;
|
||||
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || crt == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
while( crt != NULL )
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
||||
debug_print_line_by_line( ssl, level, file, line, buf );
|
||||
|
||||
debug_print_pk( ssl, level, file, line, "crt->", &crt->pk );
|
||||
|
||||
crt = crt->next;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
590
Living_SDK/security/alicrypto/mbedtls/library/hash_wrap.c
Normal file
590
Living_SDK/security/alicrypto/mbedtls/library/hash_wrap.c
Normal file
|
|
@ -0,0 +1,590 @@
|
|||
/**
|
||||
* \file hash_wrap.c
|
||||
*
|
||||
* \brief Generic message digest wrapper for mbed TLS
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
|
||||
#include "ali_crypto.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/hash.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
#include "mbedtls/md5.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
#include "mbedtls/sha1.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
#include "mbedtls/sha256.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
#include "mbedtls/sha512.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#ifdef MBEDTLS_IOT_PLAT_AOS
|
||||
#include <aos/kernel.h>
|
||||
#define mbedtls_malloc aos_malloc
|
||||
#define mbedtls_free aos_free
|
||||
#else
|
||||
#define mbedtls_malloc malloc
|
||||
#define mbedtls_free free
|
||||
#endif /* MBEDTLS_IOT_PLAT_AOS */
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
extern ali_crypto_result ali_hash_init(hash_type_t type, void *context);
|
||||
extern ali_crypto_result ali_hash_update(const uint8_t *src, size_t size,
|
||||
void *context);
|
||||
extern ali_crypto_result ali_hash_final(uint8_t *dgst, void *context);
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
static void _md5_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(MD5, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
static void _sha1_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(SHA1, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
static void _sha224_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(SHA224, ctx);
|
||||
}
|
||||
|
||||
static void _sha256_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(SHA256, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
static void _sha384_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(SHA384, ctx);
|
||||
}
|
||||
|
||||
static void _sha512_starts_wrap(void *ctx)
|
||||
{
|
||||
ali_hash_init(SHA512, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _hash_update_wrap(void *ctx, const unsigned char *input,
|
||||
size_t ilen)
|
||||
{
|
||||
int ret;
|
||||
ret = ali_hash_update(input, ilen, ctx);
|
||||
if (ret != ALI_CRYPTO_SUCCESS) {
|
||||
mbedtls_printf("failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void _hash_finish_wrap(void *ctx, unsigned char *output)
|
||||
{
|
||||
ali_hash_final(output, ctx);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
void _mbedtls_md5(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(MD5, input, ilen, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
void _mbedtls_sha1(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(SHA1, input, ilen, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
void _mbedtls_sha224(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(SHA224, input, ilen, output);
|
||||
}
|
||||
|
||||
void _mbedtls_sha256(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(SHA256, input, ilen, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
void _mbedtls_sha384(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(SHA384, input, ilen, output);
|
||||
}
|
||||
|
||||
void _mbedtls_sha512(const unsigned char *input, size_t ilen,
|
||||
unsigned char *output)
|
||||
{
|
||||
ali_hash_digest(SHA512, input, ilen, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
static void *_md5_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(MD5, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void _md5_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
static void *sha1_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(SHA1, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void sha1_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
static void *_sha224_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(SHA224, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void _sha224_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
|
||||
static void *_sha256_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(SHA256, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void _sha256_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
static void *_sha384_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(SHA384, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void _sha384_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
|
||||
static void *_sha512_ctx_alloc(void)
|
||||
{
|
||||
size_t len;
|
||||
int32_t ret;
|
||||
void * ctx;
|
||||
|
||||
ret = ali_hash_get_ctx_size(SHA512, &len);
|
||||
if (0 != ret) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = mbedtls_malloc(len);
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ctx, 0, len);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
static void _sha512_ctx_free(void *ctx)
|
||||
{
|
||||
mbedtls_free(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
static const mbedtls_md_info_t _mbedtls_md5_info = {
|
||||
MBEDTLS_MD_MD5,
|
||||
"MD5",
|
||||
16,
|
||||
64,
|
||||
_md5_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_md5,
|
||||
_md5_ctx_alloc,
|
||||
_md5_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
static const mbedtls_md_info_t _mbedtls_sha1_info = {
|
||||
MBEDTLS_MD_SHA1,
|
||||
"SHA1",
|
||||
20,
|
||||
64,
|
||||
_sha1_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_sha1,
|
||||
sha1_ctx_alloc,
|
||||
sha1_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
static const mbedtls_md_info_t _mbedtls_sha224_info = {
|
||||
MBEDTLS_MD_SHA224,
|
||||
"SHA224",
|
||||
28,
|
||||
64,
|
||||
_sha224_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_sha224,
|
||||
_sha224_ctx_alloc,
|
||||
_sha224_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const mbedtls_md_info_t _mbedtls_sha256_info = {
|
||||
MBEDTLS_MD_SHA256,
|
||||
"SHA256",
|
||||
32,
|
||||
64,
|
||||
_sha256_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_sha256,
|
||||
_sha256_ctx_alloc,
|
||||
_sha256_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
static const mbedtls_md_info_t _mbedtls_sha384_info = {
|
||||
MBEDTLS_MD_SHA384,
|
||||
"SHA384",
|
||||
48,
|
||||
128,
|
||||
_sha384_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_sha384,
|
||||
_sha384_ctx_alloc,
|
||||
_sha384_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const mbedtls_md_info_t _mbedtls_sha512_info = {
|
||||
MBEDTLS_MD_SHA512,
|
||||
"SHA512",
|
||||
64,
|
||||
128,
|
||||
_sha512_starts_wrap,
|
||||
_hash_update_wrap,
|
||||
_hash_finish_wrap,
|
||||
_mbedtls_sha512,
|
||||
_sha512_ctx_alloc,
|
||||
_sha512_ctx_free,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize(void *v, size_t n)
|
||||
{
|
||||
volatile unsigned char *p = v;
|
||||
while (n--) {
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const mbedtls_hash_info_t *mbedtls_hash_info_from_type(
|
||||
mbedtls_md_type_t md_type)
|
||||
{
|
||||
switch (md_type) {
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
case MBEDTLS_MD_MD5:
|
||||
return (&_mbedtls_md5_info);
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
case MBEDTLS_MD_SHA1:
|
||||
return (&_mbedtls_sha1_info);
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
case MBEDTLS_MD_SHA224:
|
||||
return (&_mbedtls_sha224_info);
|
||||
case MBEDTLS_MD_SHA256:
|
||||
return (&_mbedtls_sha256_info);
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
case MBEDTLS_MD_SHA384:
|
||||
return (&_mbedtls_sha384_info);
|
||||
case MBEDTLS_MD_SHA512:
|
||||
return (&_mbedtls_sha512_info);
|
||||
#endif
|
||||
default:
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_hash_init(mbedtls_hash_context_t *ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(mbedtls_hash_context_t));
|
||||
}
|
||||
|
||||
void mbedtls_hash_free(mbedtls_hash_context_t *ctx)
|
||||
{
|
||||
if (ctx == NULL || ctx->md_info == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->md_ctx != NULL) {
|
||||
ctx->md_info->ctx_free_func(ctx->md_ctx);
|
||||
ctx->md_ctx = NULL;
|
||||
}
|
||||
|
||||
if (ctx->hmac_ctx != NULL) {
|
||||
mbedtls_zeroize(ctx->hmac_ctx, 2 * ctx->md_info->block_size);
|
||||
mbedtls_free(ctx->hmac_ctx);
|
||||
ctx->hmac_ctx = NULL;
|
||||
}
|
||||
|
||||
mbedtls_zeroize(ctx, sizeof(mbedtls_hash_context_t));
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
int mbedtls_hash_init_ctx(mbedtls_hash_context_t * ctx,
|
||||
const mbedtls_md_info_t *md_info)
|
||||
{
|
||||
return mbedtls_hash_setup(ctx, md_info, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
int mbedtls_hash_setup(mbedtls_hash_context_t * ctx,
|
||||
const mbedtls_md_info_t *md_info, int hmac)
|
||||
{
|
||||
if (md_info == NULL || ctx == NULL) {
|
||||
return (MBEDTLS_ERR_MD_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
if ((ctx->md_ctx = md_info->ctx_alloc_func()) == NULL) {
|
||||
return (MBEDTLS_ERR_MD_ALLOC_FAILED);
|
||||
}
|
||||
|
||||
if (hmac != 0) {
|
||||
ctx->hmac_ctx = mbedtls_malloc(2 * md_info->block_size);
|
||||
if (ctx->hmac_ctx == NULL) {
|
||||
md_info->ctx_free_func(ctx->md_ctx);
|
||||
ctx->md_ctx = NULL;
|
||||
return (MBEDTLS_ERR_MD_ALLOC_FAILED);
|
||||
}
|
||||
memset(ctx->hmac_ctx, 0, 2 * md_info->block_size);
|
||||
}
|
||||
|
||||
ctx->md_info = md_info;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mbedtls_hash_starts(mbedtls_hash_context_t *ctx)
|
||||
{
|
||||
if (ctx == NULL || ctx->md_info == NULL) {
|
||||
return (MBEDTLS_ERR_MD_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
ctx->md_info->starts_func(ctx->md_ctx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mbedtls_hash_update(mbedtls_hash_context_t *ctx, const unsigned char *input,
|
||||
size_t ilen)
|
||||
{
|
||||
if (ctx == NULL || ctx->md_info == NULL) {
|
||||
return (MBEDTLS_ERR_MD_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
ctx->md_info->update_func(ctx->md_ctx, input, ilen);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mbedtls_hash_finish(mbedtls_hash_context_t *ctx, unsigned char *output)
|
||||
{
|
||||
if (ctx == NULL || ctx->md_info == NULL) {
|
||||
return (MBEDTLS_ERR_MD_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
ctx->md_info->finish_func(ctx->md_ctx, output);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mbedtls_hash(const mbedtls_hash_info_t *md_info, const unsigned char *input,
|
||||
size_t ilen, unsigned char *output)
|
||||
{
|
||||
if (md_info == NULL) {
|
||||
return (MBEDTLS_ERR_MD_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
md_info->digest_func(input, ilen, output);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
unsigned char mbedtls_hash_get_size(const mbedtls_md_info_t *md_info)
|
||||
{
|
||||
if (md_info == NULL) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
return md_info->size;
|
||||
}
|
||||
|
||||
mbedtls_md_type_t mbedtls_hash_get_type(const mbedtls_md_info_t *md_info)
|
||||
{
|
||||
if (md_info == NULL) {
|
||||
return (MBEDTLS_MD_NONE);
|
||||
}
|
||||
|
||||
return md_info->type;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
139
Living_SDK/security/alicrypto/mbedtls/library/hmac.c
Normal file
139
Living_SDK/security/alicrypto/mbedtls/library/hmac.c
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/hash.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "mbedtls/hmac.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
int mbedtls_hmac_starts( mbedtls_hash_context_t *ctx, const unsigned char *key, size_t keylen )
|
||||
{
|
||||
unsigned char sum[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char *ipad, *opad;
|
||||
size_t i;
|
||||
|
||||
if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL )
|
||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||
|
||||
if( keylen > (size_t) ctx->md_info->block_size )
|
||||
{
|
||||
ctx->md_info->starts_func( ctx->md_ctx );
|
||||
ctx->md_info->update_func( ctx->md_ctx, key, keylen );
|
||||
ctx->md_info->finish_func( ctx->md_ctx, sum );
|
||||
|
||||
keylen = ctx->md_info->size;
|
||||
key = sum;
|
||||
}
|
||||
|
||||
ipad = (unsigned char *) ctx->hmac_ctx;
|
||||
opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
|
||||
|
||||
memset( ipad, 0x36, ctx->md_info->block_size );
|
||||
memset( opad, 0x5C, ctx->md_info->block_size );
|
||||
|
||||
for( i = 0; i < keylen; i++ )
|
||||
{
|
||||
ipad[i] = (unsigned char)( ipad[i] ^ key[i] );
|
||||
opad[i] = (unsigned char)( opad[i] ^ key[i] );
|
||||
}
|
||||
|
||||
mbedtls_zeroize( sum, sizeof( sum ) );
|
||||
|
||||
ctx->md_info->starts_func( ctx->md_ctx );
|
||||
ctx->md_info->update_func( ctx->md_ctx, ipad, ctx->md_info->block_size );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_hmac_update( mbedtls_hash_context_t *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL )
|
||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||
|
||||
ctx->md_info->update_func( ctx->md_ctx, input, ilen );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_hmac_finish( mbedtls_hash_context_t *ctx, unsigned char *output )
|
||||
{
|
||||
unsigned char tmp[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char *opad;
|
||||
|
||||
if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL )
|
||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||
|
||||
opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
|
||||
|
||||
ctx->md_info->finish_func( ctx->md_ctx, tmp );
|
||||
ctx->md_info->starts_func( ctx->md_ctx );
|
||||
ctx->md_info->update_func( ctx->md_ctx, opad, ctx->md_info->block_size );
|
||||
ctx->md_info->update_func( ctx->md_ctx, tmp, ctx->md_info->size );
|
||||
ctx->md_info->finish_func( ctx->md_ctx, output );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_hash_hmac( const mbedtls_hash_info_t *md_info, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output )
|
||||
{
|
||||
mbedtls_hash_context_t ctx;
|
||||
int ret;
|
||||
|
||||
if( md_info == NULL )
|
||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||
|
||||
mbedtls_hash_init( &ctx );
|
||||
|
||||
if( ( ret = mbedtls_hash_setup( &ctx, md_info, 1 ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
mbedtls_hmac_starts( &ctx, key, keylen );
|
||||
mbedtls_hmac_update( &ctx, input, ilen );
|
||||
mbedtls_hmac_finish( &ctx, output );
|
||||
|
||||
mbedtls_hash_free( &ctx );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_hmac_reset( mbedtls_hash_context_t *ctx )
|
||||
{
|
||||
unsigned char *ipad;
|
||||
|
||||
if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL )
|
||||
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
|
||||
|
||||
ipad = (unsigned char *) ctx->hmac_ctx;
|
||||
|
||||
ctx->md_info->starts_func( ctx->md_ctx );
|
||||
ctx->md_info->update_func( ctx->md_ctx, ipad, ctx->md_info->block_size );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* defined(MBEDTLS_MD_C) */
|
||||
|
||||
85
Living_SDK/security/alicrypto/mbedtls/library/mbedtls_alt.c
Normal file
85
Living_SDK/security/alicrypto/mbedtls/library/mbedtls_alt.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Copyright (C) 2017 The YunOS IoT Project. All rights reserved.
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
#include "mbedtls/debug.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_THREADING_ALT)
|
||||
#include "mbedtls/threading.h"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define FORCE_COMPILE
|
||||
#else
|
||||
#define FORCE_COMPILE __attribute__((__used__))
|
||||
#endif
|
||||
|
||||
|
||||
#define MBEDTLS_ALT_PRINT(_f, ...) \
|
||||
printf("%s %d: "_f, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#if defined(MBEDTLS_THREADING_ALT)
|
||||
|
||||
extern int aos_mutex_new(aos_mutex_t *mutex);
|
||||
extern void aos_mutex_free(aos_mutex_t *mutex);
|
||||
extern int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout);
|
||||
extern int aos_mutex_unlock(aos_mutex_t *mutex);
|
||||
|
||||
FORCE_COMPILE void OSA_mutex_init(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || mutex->is_valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
mutex->is_valid = (aos_mutex_new(&mutex->mutex) == 0);
|
||||
}
|
||||
|
||||
FORCE_COMPILE void OSA_mutex_free(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
aos_mutex_free(&mutex->mutex);
|
||||
mutex->is_valid = 0;
|
||||
}
|
||||
|
||||
FORCE_COMPILE int OSA_mutex_lock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
return (MBEDTLS_ERR_THREADING_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
if (aos_mutex_lock(&mutex->mutex, AOS_WAIT_FOREVER) != 0) {
|
||||
return (MBEDTLS_ERR_THREADING_MUTEX_ERROR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCE_COMPILE int OSA_mutex_unlock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
return (MBEDTLS_ERR_THREADING_BAD_INPUT_DATA);
|
||||
}
|
||||
|
||||
if (aos_mutex_unlock(&mutex->mutex) != 0) {
|
||||
return (MBEDTLS_ERR_THREADING_MUTEX_ERROR);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_THREADING_ALT */
|
||||
404
Living_SDK/security/alicrypto/mbedtls/library/md5.c
Normal file
404
Living_SDK/security/alicrypto/mbedtls/library/md5.c
Normal file
|
|
@ -0,0 +1,404 @@
|
|||
/*
|
||||
* RFC 1321 compliant MD5 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
/*
|
||||
* The MD5 algorithm was designed by Ron Rivest in 1991.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc1321.txt
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_MD5_ALT)
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_UINT32_LE
|
||||
#define GET_UINT32_LE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32_t) (b)[(i) ] ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 8 ) \
|
||||
| ( (uint32_t) (b)[(i) + 2] << 16 ) \
|
||||
| ( (uint32_t) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT32_LE
|
||||
#define PUT_UINT32_LE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
void mbedtls_md5_init( mbedtls_md5_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( mbedtls_md5_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_md5_free( mbedtls_md5_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
||||
const mbedtls_md5_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 context setup
|
||||
*/
|
||||
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_MD5_PROCESS_ALT)
|
||||
void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
uint32_t X[16], A, B, C, D;
|
||||
|
||||
GET_UINT32_LE( X[ 0], data, 0 );
|
||||
GET_UINT32_LE( X[ 1], data, 4 );
|
||||
GET_UINT32_LE( X[ 2], data, 8 );
|
||||
GET_UINT32_LE( X[ 3], data, 12 );
|
||||
GET_UINT32_LE( X[ 4], data, 16 );
|
||||
GET_UINT32_LE( X[ 5], data, 20 );
|
||||
GET_UINT32_LE( X[ 6], data, 24 );
|
||||
GET_UINT32_LE( X[ 7], data, 28 );
|
||||
GET_UINT32_LE( X[ 8], data, 32 );
|
||||
GET_UINT32_LE( X[ 9], data, 36 );
|
||||
GET_UINT32_LE( X[10], data, 40 );
|
||||
GET_UINT32_LE( X[11], data, 44 );
|
||||
GET_UINT32_LE( X[12], data, 48 );
|
||||
GET_UINT32_LE( X[13], data, 52 );
|
||||
GET_UINT32_LE( X[14], data, 56 );
|
||||
GET_UINT32_LE( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define P(a,b,c,d,k,s,t) \
|
||||
{ \
|
||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
||||
|
||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
|
||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (x | ~z))
|
||||
|
||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
||||
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
#endif /* !MBEDTLS_MD5_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
* MD5 process buffer
|
||||
*/
|
||||
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
size_t fill;
|
||||
uint32_t left;
|
||||
|
||||
if( ilen == 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += (uint32_t) ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (uint32_t) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left), input, fill );
|
||||
mbedtls_md5_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
mbedtls_md5_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left), input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char md5_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* MD5 final digest
|
||||
*/
|
||||
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
|
||||
{
|
||||
uint32_t last, padn;
|
||||
uint32_t high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_UINT32_LE( low, msglen, 0 );
|
||||
PUT_UINT32_LE( high, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
mbedtls_md5_update( ctx, md5_padding, padn );
|
||||
mbedtls_md5_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_UINT32_LE( ctx->state[0], output, 0 );
|
||||
PUT_UINT32_LE( ctx->state[1], output, 4 );
|
||||
PUT_UINT32_LE( ctx->state[2], output, 8 );
|
||||
PUT_UINT32_LE( ctx->state[3], output, 12 );
|
||||
}
|
||||
|
||||
#endif /* !MBEDTLS_MD5_ALT */
|
||||
|
||||
/*
|
||||
* output = MD5( input buffer )
|
||||
*/
|
||||
void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md5_context ctx;
|
||||
|
||||
mbedtls_md5_init( &ctx );
|
||||
mbedtls_md5_starts( &ctx );
|
||||
mbedtls_md5_update( &ctx, input, ilen );
|
||||
mbedtls_md5_finish( &ctx, output );
|
||||
mbedtls_md5_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* RFC 1321 test vectors
|
||||
*/
|
||||
static const unsigned char md5_test_buf[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const int md5_test_buflen[7] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 62, 80
|
||||
};
|
||||
|
||||
static const unsigned char md5_test_sum[7][16] =
|
||||
{
|
||||
{ 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
|
||||
0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
|
||||
{ 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
|
||||
0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
|
||||
{ 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
|
||||
0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
|
||||
{ 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
|
||||
0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
|
||||
{ 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
|
||||
0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
|
||||
{ 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
|
||||
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
|
||||
{ 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
|
||||
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_md5_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
unsigned char md5sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD5 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_md5( md5_test_buf[i], md5_test_buflen[i], md5sum );
|
||||
|
||||
if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
782
Living_SDK/security/alicrypto/mbedtls/library/oid.c
Normal file
782
Living_SDK/security/alicrypto/mbedtls/library/oid.c
Normal file
|
|
@ -0,0 +1,782 @@
|
|||
/**
|
||||
* \file oid.c
|
||||
*
|
||||
* \brief Object Identifier (OID) database
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_OID_C)
|
||||
|
||||
#include "mbedtls/oid.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define mbedtls_snprintf snprintf
|
||||
|
||||
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
|
||||
#include "mbedtls/x509.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macro to automatically add the size of #define'd OIDs
|
||||
*/
|
||||
#define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
|
||||
|
||||
/*
|
||||
* Macro to generate an internal function for oid_XXX_from_asn1() (used by
|
||||
* the other functions)
|
||||
*/
|
||||
#define FN_OID_TYPED_FROM_ASN1(TYPE_T, NAME, LIST) \
|
||||
static const TYPE_T *oid_##NAME##_from_asn1(const mbedtls_asn1_buf *oid) \
|
||||
{ \
|
||||
const TYPE_T * p = LIST; \
|
||||
const mbedtls_oid_descriptor_t *cur = \
|
||||
(const mbedtls_oid_descriptor_t *)p; \
|
||||
if (p == NULL || oid == NULL) \
|
||||
return (NULL); \
|
||||
while (cur->asn1 != NULL) { \
|
||||
if (cur->asn1_len == oid->len && \
|
||||
memcmp(cur->asn1, oid->p, oid->len) == 0) { \
|
||||
return (p); \
|
||||
} \
|
||||
p++; \
|
||||
cur = (const mbedtls_oid_descriptor_t *)p; \
|
||||
} \
|
||||
return (NULL); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving a single attribute from the
|
||||
* descriptor of an mbedtls_oid_descriptor_t wrapper.
|
||||
*/
|
||||
#define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, \
|
||||
ATTR1) \
|
||||
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE *ATTR1) \
|
||||
{ \
|
||||
const TYPE_T *data = oid_##TYPE_NAME##_from_asn1(oid); \
|
||||
if (data == NULL) \
|
||||
return (MBEDTLS_ERR_OID_NOT_FOUND); \
|
||||
*ATTR1 = data->descriptor.ATTR1; \
|
||||
return (0); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving a single attribute from an
|
||||
* mbedtls_oid_descriptor_t wrapper.
|
||||
*/
|
||||
#define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
|
||||
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE *ATTR1) \
|
||||
{ \
|
||||
const TYPE_T *data = oid_##TYPE_NAME##_from_asn1(oid); \
|
||||
if (data == NULL) \
|
||||
return (MBEDTLS_ERR_OID_NOT_FOUND); \
|
||||
*ATTR1 = data->ATTR1; \
|
||||
return (0); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving two attributes from an
|
||||
* mbedtls_oid_descriptor_t wrapper.
|
||||
*/
|
||||
#define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
|
||||
ATTR2_TYPE, ATTR2) \
|
||||
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE *ATTR1, \
|
||||
ATTR2_TYPE *ATTR2) \
|
||||
{ \
|
||||
const TYPE_T *data = oid_##TYPE_NAME##_from_asn1(oid); \
|
||||
if (data == NULL) \
|
||||
return (MBEDTLS_ERR_OID_NOT_FOUND); \
|
||||
*ATTR1 = data->ATTR1; \
|
||||
*ATTR2 = data->ATTR2; \
|
||||
return (0); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving the OID based on a single
|
||||
* attribute from a mbedtls_oid_descriptor_t wrapper.
|
||||
*/
|
||||
#define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
|
||||
int FN_NAME(ATTR1_TYPE ATTR1, const char **oid, size_t *olen) \
|
||||
{ \
|
||||
const TYPE_T *cur = LIST; \
|
||||
while (cur->descriptor.asn1 != NULL) { \
|
||||
if (cur->ATTR1 == ATTR1) { \
|
||||
*oid = cur->descriptor.asn1; \
|
||||
*olen = cur->descriptor.asn1_len; \
|
||||
return (0); \
|
||||
} \
|
||||
cur++; \
|
||||
} \
|
||||
return (MBEDTLS_ERR_OID_NOT_FOUND); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving the OID based on two
|
||||
* attributes from a mbedtls_oid_descriptor_t wrapper.
|
||||
*/
|
||||
#define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
|
||||
ATTR2_TYPE, ATTR2) \
|
||||
int FN_NAME(ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid, \
|
||||
size_t *olen) \
|
||||
{ \
|
||||
const TYPE_T *cur = LIST; \
|
||||
while (cur->descriptor.asn1 != NULL) { \
|
||||
if (cur->ATTR1 == ATTR1 && cur->ATTR2 == ATTR2) { \
|
||||
*oid = cur->descriptor.asn1; \
|
||||
*olen = cur->descriptor.asn1_len; \
|
||||
return (0); \
|
||||
} \
|
||||
cur++; \
|
||||
} \
|
||||
return (MBEDTLS_ERR_OID_NOT_FOUND); \
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
|
||||
/*
|
||||
* For X520 attribute types
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
const char * short_name;
|
||||
} oid_x520_attr_t;
|
||||
|
||||
static const oid_x520_attr_t oid_x520_attr_type[] = {
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_CN), "id-at-commonName", "Common Name" },
|
||||
"CN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_COUNTRY), "id-at-countryName", "Country" },
|
||||
"C",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_LOCALITY), "id-at-locality", "Locality" },
|
||||
"L",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_STATE), "id-at-state", "State" },
|
||||
"ST",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_ORGANIZATION), "id-at-organizationName",
|
||||
"Organization" },
|
||||
"O",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_ORG_UNIT), "id-at-organizationalUnitName",
|
||||
"Org Unit" },
|
||||
"OU",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS9_EMAIL), "emailAddress", "E-mail address" },
|
||||
"emailAddress",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_SERIAL_NUMBER), "id-at-serialNumber",
|
||||
"Serial number" },
|
||||
"serialNumber",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_POSTAL_ADDRESS), "id-at-postalAddress",
|
||||
"Postal address" },
|
||||
"postalAddress",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_POSTAL_CODE), "id-at-postalCode",
|
||||
"Postal code" },
|
||||
"postalCode",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_SUR_NAME), "id-at-surName", "Surname" },
|
||||
"SN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_GIVEN_NAME), "id-at-givenName", "Given name" },
|
||||
"GN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_INITIALS), "id-at-initials", "Initials" },
|
||||
"initials",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_GENERATION_QUALIFIER),
|
||||
"id-at-generationQualifier", "Generation qualifier" },
|
||||
"generationQualifier",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_TITLE), "id-at-title", "Title" },
|
||||
"title",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_DN_QUALIFIER), "id-at-dnQualifier",
|
||||
"Distinguished Name qualifier" },
|
||||
"dnQualifier",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_PSEUDONYM), "id-at-pseudonym", "Pseudonym" },
|
||||
"pseudonym",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DOMAIN_COMPONENT), "id-domainComponent",
|
||||
"Domain component" },
|
||||
"DC",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_AT_UNIQUE_IDENTIFIER), "id-at-uniqueIdentifier",
|
||||
"Unique Identifier" },
|
||||
"uniqueIdentifier",
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL,
|
||||
}
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name, oid_x520_attr_t, x520_attr,
|
||||
const char *, short_name)
|
||||
|
||||
/*
|
||||
* For X509 extensions
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
int ext_type;
|
||||
} oid_x509_ext_t;
|
||||
|
||||
static const oid_x509_ext_t oid_x509_ext[] = {
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_BASIC_CONSTRAINTS), "id-ce-basicConstraints",
|
||||
"Basic Constraints" },
|
||||
MBEDTLS_X509_EXT_BASIC_CONSTRAINTS,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_KEY_USAGE), "id-ce-keyUsage", "Key Usage" },
|
||||
MBEDTLS_X509_EXT_KEY_USAGE,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EXTENDED_KEY_USAGE), "id-ce-extKeyUsage",
|
||||
"Extended Key Usage" },
|
||||
MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_SUBJECT_ALT_NAME), "id-ce-subjectAltName",
|
||||
"Subject Alt Name" },
|
||||
MBEDTLS_X509_EXT_SUBJECT_ALT_NAME,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_NS_CERT_TYPE), "id-netscape-certtype",
|
||||
"Netscape Certificate Type" },
|
||||
MBEDTLS_X509_EXT_NS_CERT_TYPE,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
0,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int,
|
||||
ext_type)
|
||||
|
||||
static const mbedtls_oid_descriptor_t oid_ext_key_usage[] = {
|
||||
{ ADD_LEN(MBEDTLS_OID_SERVER_AUTH), "id-kp-serverAuth",
|
||||
"TLS Web Server Authentication" },
|
||||
{ ADD_LEN(MBEDTLS_OID_CLIENT_AUTH), "id-kp-clientAuth",
|
||||
"TLS Web Client Authentication" },
|
||||
{ ADD_LEN(MBEDTLS_OID_CODE_SIGNING), "id-kp-codeSigning", "Code Signing" },
|
||||
{ ADD_LEN(MBEDTLS_OID_EMAIL_PROTECTION), "id-kp-emailProtection",
|
||||
"E-mail Protection" },
|
||||
{ ADD_LEN(MBEDTLS_OID_TIME_STAMPING), "id-kp-timeStamping",
|
||||
"Time Stamping" },
|
||||
{ ADD_LEN(MBEDTLS_OID_OCSP_SIGNING), "id-kp-OCSPSigning", "OCSP Signing" },
|
||||
{ NULL, 0, NULL, NULL },
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage,
|
||||
oid_ext_key_usage)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t,
|
||||
ext_key_usage, const char *, description)
|
||||
#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
/*
|
||||
* For SignatureAlgorithmIdentifier
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_md_type_t md_alg;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
} oid_sig_alg_t;
|
||||
|
||||
static const oid_sig_alg_t oid_sig_alg[] = {
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_MD2), "md2WithRSAEncryption",
|
||||
"RSA with MD2" },
|
||||
MBEDTLS_MD_MD2,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_MD4), "md4WithRSAEncryption",
|
||||
"RSA with MD4" },
|
||||
MBEDTLS_MD_MD4,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_MD5), "md5WithRSAEncryption",
|
||||
"RSA with MD5" },
|
||||
MBEDTLS_MD_MD5,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_SHA1), "sha-1WithRSAEncryption",
|
||||
"RSA with SHA1" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_SHA224), "sha224WithRSAEncryption",
|
||||
"RSA with SHA-224" },
|
||||
MBEDTLS_MD_SHA224,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_SHA256), "sha256WithRSAEncryption",
|
||||
"RSA with SHA-256" },
|
||||
MBEDTLS_MD_SHA256,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_SHA384), "sha384WithRSAEncryption",
|
||||
"RSA with SHA-384" },
|
||||
MBEDTLS_MD_SHA384,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_SHA512), "sha512WithRSAEncryption",
|
||||
"RSA with SHA-512" },
|
||||
MBEDTLS_MD_SHA512,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_RSA_SHA_OBS), "sha-1WithRSAEncryption",
|
||||
"RSA with SHA1" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_ECDSA_SHA1), "ecdsa-with-SHA1", "ECDSA with SHA1" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_ECDSA_SHA224), "ecdsa-with-SHA224",
|
||||
"ECDSA with SHA224" },
|
||||
MBEDTLS_MD_SHA224,
|
||||
MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_ECDSA_SHA256), "ecdsa-with-SHA256",
|
||||
"ECDSA with SHA256" },
|
||||
MBEDTLS_MD_SHA256,
|
||||
MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_ECDSA_SHA384), "ecdsa-with-SHA384",
|
||||
"ECDSA with SHA384" },
|
||||
MBEDTLS_MD_SHA384,
|
||||
MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_ECDSA_SHA512), "ecdsa-with-SHA512",
|
||||
"ECDSA with SHA512" },
|
||||
MBEDTLS_MD_SHA512,
|
||||
MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#endif /* MBEDTLS_ECDSA_C */
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_RSASSA_PSS), "RSASSA-PSS", "RSASSA-PSS" },
|
||||
MBEDTLS_MD_NONE,
|
||||
MBEDTLS_PK_RSASSA_PSS,
|
||||
},
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_MD_NONE,
|
||||
MBEDTLS_PK_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
|
||||
FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t,
|
||||
sig_alg, const char *, description)
|
||||
FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg, oid_sig_alg_t, sig_alg,
|
||||
mbedtls_md_type_t, md_alg, mbedtls_pk_type_t, pk_alg)
|
||||
FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg, oid_sig_alg_t,
|
||||
oid_sig_alg, mbedtls_pk_type_t, pk_alg,
|
||||
mbedtls_md_type_t, md_alg)
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
/*
|
||||
* For PublicKeyInfo (PKCS1, RFC 5480)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
} oid_pk_alg_t;
|
||||
|
||||
static const oid_pk_alg_t oid_pk_alg[] = {
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS1_RSA), "rsaEncryption", "RSA" },
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_ALG_UNRESTRICTED), "id-ecPublicKey",
|
||||
"Generic EC key" },
|
||||
MBEDTLS_PK_ECKEY,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_ALG_ECDH), "id-ecDH", "EC key for ECDH" },
|
||||
MBEDTLS_PK_ECKEY_DH,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_PK_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg,
|
||||
mbedtls_pk_type_t, pk_alg)
|
||||
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg, oid_pk_alg_t, oid_pk_alg,
|
||||
mbedtls_pk_type_t, pk_alg)
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
/*
|
||||
* For namedCurve (RFC 5480)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_ecp_group_id grp_id;
|
||||
} oid_ecp_grp_t;
|
||||
|
||||
static const oid_ecp_grp_t oid_ecp_grp[] = {
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP192R1), "secp192r1", "secp192r1" },
|
||||
MBEDTLS_ECP_DP_SECP192R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP224R1), "secp224r1", "secp224r1" },
|
||||
MBEDTLS_ECP_DP_SECP224R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP256R1), "secp256r1", "secp256r1" },
|
||||
MBEDTLS_ECP_DP_SECP256R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP384R1), "secp384r1", "secp384r1" },
|
||||
MBEDTLS_ECP_DP_SECP384R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP521R1), "secp521r1", "secp521r1" },
|
||||
MBEDTLS_ECP_DP_SECP521R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP192K1), "secp192k1", "secp192k1" },
|
||||
MBEDTLS_ECP_DP_SECP192K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP224K1), "secp224k1", "secp224k1" },
|
||||
MBEDTLS_ECP_DP_SECP224K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_SECP256K1), "secp256k1", "secp256k1" },
|
||||
MBEDTLS_ECP_DP_SECP256K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_BP256R1), "brainpoolP256r1",
|
||||
"brainpool256r1" },
|
||||
MBEDTLS_ECP_DP_BP256R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_BP384R1), "brainpoolP384r1",
|
||||
"brainpool384r1" },
|
||||
MBEDTLS_ECP_DP_BP384R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_EC_GRP_BP512R1), "brainpoolP512r1",
|
||||
"brainpool512r1" },
|
||||
MBEDTLS_ECP_DP_BP512R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_ECP_DP_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id,
|
||||
mbedtls_ecp_group_id, grp_id)
|
||||
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp, oid_ecp_grp_t,
|
||||
oid_ecp_grp, mbedtls_ecp_group_id, grp_id)
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
/*
|
||||
* For PKCS#5 PBES2 encryption algorithm
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_cipher_type_t cipher_alg;
|
||||
} oid_cipher_alg_t;
|
||||
|
||||
static const oid_cipher_alg_t oid_cipher_alg[] = {
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DES_CBC), "desCBC", "DES-CBC" },
|
||||
MBEDTLS_CIPHER_DES_CBC,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DES_EDE3_CBC), "des-ede3-cbc", "DES-EDE3-CBC" },
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_CIPHER_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg, oid_cipher_alg_t, cipher_alg,
|
||||
mbedtls_cipher_type_t, cipher_alg)
|
||||
#endif /* MBEDTLS_CIPHER_C */
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
/*
|
||||
* For digestAlgorithm
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_md_type_t md_alg;
|
||||
} oid_md_alg_t;
|
||||
|
||||
static const oid_md_alg_t oid_md_alg[] = {
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD2), "id-md2", "MD2" },
|
||||
MBEDTLS_MD_MD2,
|
||||
},
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD4), "id-md4", "MD4" },
|
||||
MBEDTLS_MD_MD4,
|
||||
},
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_MD5), "id-md5", "MD5" },
|
||||
MBEDTLS_MD_MD5,
|
||||
},
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA1), "id-sha1", "SHA-1" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA224), "id-sha224", "SHA-224" },
|
||||
MBEDTLS_MD_SHA224,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA256), "id-sha256", "SHA-256" },
|
||||
MBEDTLS_MD_SHA256,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA384), "id-sha384", "SHA-384" },
|
||||
MBEDTLS_MD_SHA384,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_DIGEST_ALG_SHA512), "id-sha512", "SHA-512" },
|
||||
MBEDTLS_MD_SHA512,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_MD_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg,
|
||||
mbedtls_md_type_t, md_alg)
|
||||
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md, oid_md_alg_t, oid_md_alg,
|
||||
mbedtls_md_type_t, md_alg)
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
#if defined(MBEDTLS_PKCS12_C)
|
||||
/*
|
||||
* For PKCS#12 PBEs
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_oid_descriptor_t descriptor;
|
||||
mbedtls_md_type_t md_alg;
|
||||
mbedtls_cipher_type_t cipher_alg;
|
||||
} oid_pkcs12_pbe_alg_t;
|
||||
|
||||
static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] = {
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC),
|
||||
"pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC),
|
||||
"pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
|
||||
MBEDTLS_MD_SHA1,
|
||||
MBEDTLS_CIPHER_DES_EDE_CBC,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
MBEDTLS_MD_NONE,
|
||||
MBEDTLS_CIPHER_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg)
|
||||
FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t,
|
||||
pkcs12_pbe_alg, mbedtls_md_type_t, md_alg,
|
||||
mbedtls_cipher_type_t, cipher_alg)
|
||||
#endif /* MBEDTLS_PKCS12_C */
|
||||
|
||||
#define OID_SAFE_SNPRINTF \
|
||||
do { \
|
||||
if (ret < 0 || (size_t)ret >= n) \
|
||||
return (MBEDTLS_ERR_OID_BUF_TOO_SMALL); \
|
||||
\
|
||||
n -= (size_t)ret; \
|
||||
p += (size_t)ret; \
|
||||
} while (0)
|
||||
|
||||
/* Return the x.y.z.... style numeric string for the given OID */
|
||||
int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
||||
const mbedtls_asn1_buf *oid)
|
||||
{
|
||||
int ret;
|
||||
size_t i, n;
|
||||
unsigned int value;
|
||||
char * p;
|
||||
|
||||
p = buf;
|
||||
n = size;
|
||||
|
||||
/* First byte contains first two dots */
|
||||
if (oid->len > 0) {
|
||||
ret = mbedtls_snprintf(p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40);
|
||||
OID_SAFE_SNPRINTF;
|
||||
}
|
||||
|
||||
value = 0;
|
||||
for (i = 1; i < oid->len; i++) {
|
||||
/* Prevent overflow in value. */
|
||||
if (((value << 7) >> 7) != value) {
|
||||
return (MBEDTLS_ERR_OID_BUF_TOO_SMALL);
|
||||
}
|
||||
|
||||
value <<= 7;
|
||||
value += oid->p[i] & 0x7F;
|
||||
|
||||
if (!(oid->p[i] & 0x80)) {
|
||||
/* Last byte */
|
||||
ret = mbedtls_snprintf(p, n, ".%d", value);
|
||||
OID_SAFE_SNPRINTF;
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ((int)(size - n));
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_OID_C */
|
||||
1753
Living_SDK/security/alicrypto/mbedtls/library/rsa.c
Normal file
1753
Living_SDK/security/alicrypto/mbedtls/library/rsa.c
Normal file
File diff suppressed because it is too large
Load diff
448
Living_SDK/security/alicrypto/mbedtls/library/sha1.c
Normal file
448
Living_SDK/security/alicrypto/mbedtls/library/sha1.c
Normal file
|
|
@ -0,0 +1,448 @@
|
|||
/*
|
||||
* FIPS-180-1 compliant SHA-1 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
/*
|
||||
* The SHA-1 standard was published by NIST in 1993.
|
||||
*
|
||||
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
|
||||
#include "mbedtls/sha1.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_ALT)
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_UINT32_BE
|
||||
#define GET_UINT32_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT32_BE
|
||||
#define PUT_UINT32_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_sha1_free( mbedtls_sha1_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_sha1_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
|
||||
const mbedtls_sha1_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 context setup
|
||||
*/
|
||||
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_PROCESS_ALT)
|
||||
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
uint32_t temp, W[16], A, B, C, D, E;
|
||||
|
||||
GET_UINT32_BE( W[ 0], data, 0 );
|
||||
GET_UINT32_BE( W[ 1], data, 4 );
|
||||
GET_UINT32_BE( W[ 2], data, 8 );
|
||||
GET_UINT32_BE( W[ 3], data, 12 );
|
||||
GET_UINT32_BE( W[ 4], data, 16 );
|
||||
GET_UINT32_BE( W[ 5], data, 20 );
|
||||
GET_UINT32_BE( W[ 6], data, 24 );
|
||||
GET_UINT32_BE( W[ 7], data, 28 );
|
||||
GET_UINT32_BE( W[ 8], data, 32 );
|
||||
GET_UINT32_BE( W[ 9], data, 36 );
|
||||
GET_UINT32_BE( W[10], data, 40 );
|
||||
GET_UINT32_BE( W[11], data, 44 );
|
||||
GET_UINT32_BE( W[12], data, 48 );
|
||||
GET_UINT32_BE( W[13], data, 52 );
|
||||
GET_UINT32_BE( W[14], data, 56 );
|
||||
GET_UINT32_BE( W[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
temp = W[( t - 3 ) & 0x0F] ^ W[( t - 8 ) & 0x0F] ^ \
|
||||
W[( t - 14 ) & 0x0F] ^ W[ t & 0x0F], \
|
||||
( W[t & 0x0F] = S(temp,1) ) \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,x) \
|
||||
{ \
|
||||
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define K 0x5A827999
|
||||
|
||||
P( A, B, C, D, E, W[0] );
|
||||
P( E, A, B, C, D, W[1] );
|
||||
P( D, E, A, B, C, W[2] );
|
||||
P( C, D, E, A, B, W[3] );
|
||||
P( B, C, D, E, A, W[4] );
|
||||
P( A, B, C, D, E, W[5] );
|
||||
P( E, A, B, C, D, W[6] );
|
||||
P( D, E, A, B, C, W[7] );
|
||||
P( C, D, E, A, B, W[8] );
|
||||
P( B, C, D, E, A, W[9] );
|
||||
P( A, B, C, D, E, W[10] );
|
||||
P( E, A, B, C, D, W[11] );
|
||||
P( D, E, A, B, C, W[12] );
|
||||
P( C, D, E, A, B, W[13] );
|
||||
P( B, C, D, E, A, W[14] );
|
||||
P( A, B, C, D, E, W[15] );
|
||||
P( E, A, B, C, D, R(16) );
|
||||
P( D, E, A, B, C, R(17) );
|
||||
P( C, D, E, A, B, R(18) );
|
||||
P( B, C, D, E, A, R(19) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0x6ED9EBA1
|
||||
|
||||
P( A, B, C, D, E, R(20) );
|
||||
P( E, A, B, C, D, R(21) );
|
||||
P( D, E, A, B, C, R(22) );
|
||||
P( C, D, E, A, B, R(23) );
|
||||
P( B, C, D, E, A, R(24) );
|
||||
P( A, B, C, D, E, R(25) );
|
||||
P( E, A, B, C, D, R(26) );
|
||||
P( D, E, A, B, C, R(27) );
|
||||
P( C, D, E, A, B, R(28) );
|
||||
P( B, C, D, E, A, R(29) );
|
||||
P( A, B, C, D, E, R(30) );
|
||||
P( E, A, B, C, D, R(31) );
|
||||
P( D, E, A, B, C, R(32) );
|
||||
P( C, D, E, A, B, R(33) );
|
||||
P( B, C, D, E, A, R(34) );
|
||||
P( A, B, C, D, E, R(35) );
|
||||
P( E, A, B, C, D, R(36) );
|
||||
P( D, E, A, B, C, R(37) );
|
||||
P( C, D, E, A, B, R(38) );
|
||||
P( B, C, D, E, A, R(39) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define K 0x8F1BBCDC
|
||||
|
||||
P( A, B, C, D, E, R(40) );
|
||||
P( E, A, B, C, D, R(41) );
|
||||
P( D, E, A, B, C, R(42) );
|
||||
P( C, D, E, A, B, R(43) );
|
||||
P( B, C, D, E, A, R(44) );
|
||||
P( A, B, C, D, E, R(45) );
|
||||
P( E, A, B, C, D, R(46) );
|
||||
P( D, E, A, B, C, R(47) );
|
||||
P( C, D, E, A, B, R(48) );
|
||||
P( B, C, D, E, A, R(49) );
|
||||
P( A, B, C, D, E, R(50) );
|
||||
P( E, A, B, C, D, R(51) );
|
||||
P( D, E, A, B, C, R(52) );
|
||||
P( C, D, E, A, B, R(53) );
|
||||
P( B, C, D, E, A, R(54) );
|
||||
P( A, B, C, D, E, R(55) );
|
||||
P( E, A, B, C, D, R(56) );
|
||||
P( D, E, A, B, C, R(57) );
|
||||
P( C, D, E, A, B, R(58) );
|
||||
P( B, C, D, E, A, R(59) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0xCA62C1D6
|
||||
|
||||
P( A, B, C, D, E, R(60) );
|
||||
P( E, A, B, C, D, R(61) );
|
||||
P( D, E, A, B, C, R(62) );
|
||||
P( C, D, E, A, B, R(63) );
|
||||
P( B, C, D, E, A, R(64) );
|
||||
P( A, B, C, D, E, R(65) );
|
||||
P( E, A, B, C, D, R(66) );
|
||||
P( D, E, A, B, C, R(67) );
|
||||
P( C, D, E, A, B, R(68) );
|
||||
P( B, C, D, E, A, R(69) );
|
||||
P( A, B, C, D, E, R(70) );
|
||||
P( E, A, B, C, D, R(71) );
|
||||
P( D, E, A, B, C, R(72) );
|
||||
P( C, D, E, A, B, R(73) );
|
||||
P( B, C, D, E, A, R(74) );
|
||||
P( A, B, C, D, E, R(75) );
|
||||
P( E, A, B, C, D, R(76) );
|
||||
P( D, E, A, B, C, R(77) );
|
||||
P( C, D, E, A, B, R(78) );
|
||||
P( B, C, D, E, A, R(79) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
}
|
||||
#endif /* !MBEDTLS_SHA1_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
* SHA-1 process buffer
|
||||
*/
|
||||
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
size_t fill;
|
||||
uint32_t left;
|
||||
|
||||
if( ilen == 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += (uint32_t) ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (uint32_t) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left), input, fill );
|
||||
mbedtls_sha1_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
mbedtls_sha1_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
memcpy( (void *) (ctx->buffer + left), input, ilen );
|
||||
}
|
||||
|
||||
static const unsigned char sha1_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA-1 final digest
|
||||
*/
|
||||
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
|
||||
{
|
||||
uint32_t last, padn;
|
||||
uint32_t high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_UINT32_BE( high, msglen, 0 );
|
||||
PUT_UINT32_BE( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
mbedtls_sha1_update( ctx, sha1_padding, padn );
|
||||
mbedtls_sha1_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_UINT32_BE( ctx->state[0], output, 0 );
|
||||
PUT_UINT32_BE( ctx->state[1], output, 4 );
|
||||
PUT_UINT32_BE( ctx->state[2], output, 8 );
|
||||
PUT_UINT32_BE( ctx->state[3], output, 12 );
|
||||
PUT_UINT32_BE( ctx->state[4], output, 16 );
|
||||
}
|
||||
|
||||
#endif /* !MBEDTLS_SHA1_ALT */
|
||||
|
||||
/*
|
||||
* output = SHA-1( input buffer )
|
||||
*/
|
||||
void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] )
|
||||
{
|
||||
mbedtls_sha1_context ctx;
|
||||
|
||||
mbedtls_sha1_init( &ctx );
|
||||
mbedtls_sha1_starts( &ctx );
|
||||
mbedtls_sha1_update( &ctx, input, ilen );
|
||||
mbedtls_sha1_finish( &ctx, output );
|
||||
mbedtls_sha1_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-1 test vectors
|
||||
*/
|
||||
static const unsigned char sha1_test_buf[3][57] =
|
||||
{
|
||||
{ "abc" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha1_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
||||
static const unsigned char sha1_test_sum[3][20] =
|
||||
{
|
||||
{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
|
||||
0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
|
||||
{ 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
|
||||
0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
|
||||
{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
|
||||
0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_sha1_self_test( int verbose )
|
||||
{
|
||||
int i, j, buflen, ret = 0;
|
||||
unsigned char buf[1024];
|
||||
unsigned char sha1sum[20];
|
||||
mbedtls_sha1_context ctx;
|
||||
|
||||
mbedtls_sha1_init( &ctx );
|
||||
|
||||
/*
|
||||
* SHA-1
|
||||
*/
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " SHA-1 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_sha1_starts( &ctx );
|
||||
|
||||
if( i == 2 )
|
||||
{
|
||||
memset( buf, 'a', buflen = 1000 );
|
||||
|
||||
for( j = 0; j < 1000; j++ )
|
||||
mbedtls_sha1_update( &ctx, buf, buflen );
|
||||
}
|
||||
else
|
||||
mbedtls_sha1_update( &ctx, sha1_test_buf[i],
|
||||
sha1_test_buflen[i] );
|
||||
|
||||
mbedtls_sha1_finish( &ctx, sha1sum );
|
||||
|
||||
if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_sha1_free( &ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
465
Living_SDK/security/alicrypto/mbedtls/library/sha256.c
Normal file
465
Living_SDK/security/alicrypto/mbedtls/library/sha256.c
Normal file
|
|
@ -0,0 +1,465 @@
|
|||
/*
|
||||
* FIPS-180-2 compliant SHA-256 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
/*
|
||||
* The SHA-256 Secure Hash Standard was published by NIST in 2002.
|
||||
*
|
||||
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
|
||||
#include "mbedtls/sha256.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#ifdef MBEDTLS_IOT_PLAT_AOS
|
||||
#include <aos/kernel.h>
|
||||
#define mbedtls_malloc aos_malloc
|
||||
#define mbedtls_free aos_free
|
||||
#else
|
||||
#define mbedtls_malloc malloc
|
||||
#define mbedtls_free free
|
||||
#endif /* MBEDTLS_IOT_PLAT_AOS */
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_SHA256_ALT)
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_UINT32_BE
|
||||
#define GET_UINT32_BE(n,b,i) \
|
||||
do { \
|
||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
||||
} while( 0 )
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT32_BE
|
||||
#define PUT_UINT32_BE(n,b,i) \
|
||||
do { \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
} while( 0 )
|
||||
#endif
|
||||
|
||||
void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( mbedtls_sha256_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_sha256_free( mbedtls_sha256_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_sha256_context ) );
|
||||
}
|
||||
|
||||
void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
||||
const mbedtls_sha256_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 context setup
|
||||
*/
|
||||
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
if( is224 == 0 )
|
||||
{
|
||||
/* SHA-256 */
|
||||
ctx->state[0] = 0x6A09E667;
|
||||
ctx->state[1] = 0xBB67AE85;
|
||||
ctx->state[2] = 0x3C6EF372;
|
||||
ctx->state[3] = 0xA54FF53A;
|
||||
ctx->state[4] = 0x510E527F;
|
||||
ctx->state[5] = 0x9B05688C;
|
||||
ctx->state[6] = 0x1F83D9AB;
|
||||
ctx->state[7] = 0x5BE0CD19;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SHA-224 */
|
||||
ctx->state[0] = 0xC1059ED8;
|
||||
ctx->state[1] = 0x367CD507;
|
||||
ctx->state[2] = 0x3070DD17;
|
||||
ctx->state[3] = 0xF70E5939;
|
||||
ctx->state[4] = 0xFFC00B31;
|
||||
ctx->state[5] = 0x68581511;
|
||||
ctx->state[6] = 0x64F98FA7;
|
||||
ctx->state[7] = 0xBEFA4FA4;
|
||||
}
|
||||
|
||||
ctx->is224 = is224;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SHA256_PROCESS_ALT)
|
||||
static const uint32_t K[] =
|
||||
{
|
||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
|
||||
};
|
||||
|
||||
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
|
||||
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
|
||||
|
||||
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
|
||||
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
|
||||
|
||||
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
|
||||
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
|
||||
|
||||
#define F0(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define F1(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
W[t] = S1(W[t - 2]) + W[t - 7] + \
|
||||
S0(W[t - 15]) + W[t - 16] \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,f,g,h,x,K) \
|
||||
{ \
|
||||
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
|
||||
temp2 = S2(a) + F0(a,b,c); \
|
||||
d += temp1; h = temp1 + temp2; \
|
||||
}
|
||||
|
||||
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
uint32_t temp1, temp2, W[64];
|
||||
uint32_t A[8];
|
||||
unsigned int i;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
A[i] = ctx->state[i];
|
||||
|
||||
#if defined(MBEDTLS_SHA256_SMALLER)
|
||||
for( i = 0; i < 64; i++ )
|
||||
{
|
||||
if( i < 16 )
|
||||
GET_UINT32_BE( W[i], data, 4 * i );
|
||||
else
|
||||
R( i );
|
||||
|
||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i] );
|
||||
|
||||
temp1 = A[7]; A[7] = A[6]; A[6] = A[5]; A[5] = A[4]; A[4] = A[3];
|
||||
A[3] = A[2]; A[2] = A[1]; A[1] = A[0]; A[0] = temp1;
|
||||
}
|
||||
#else /* MBEDTLS_SHA256_SMALLER */
|
||||
for( i = 0; i < 16; i++ )
|
||||
GET_UINT32_BE( W[i], data, 4 * i );
|
||||
|
||||
for( i = 0; i < 16; i += 8 )
|
||||
{
|
||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i+0], K[i+0] );
|
||||
P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], W[i+1], K[i+1] );
|
||||
P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], W[i+2], K[i+2] );
|
||||
P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], W[i+3], K[i+3] );
|
||||
P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], W[i+4], K[i+4] );
|
||||
P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], W[i+5], K[i+5] );
|
||||
P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], W[i+6], K[i+6] );
|
||||
P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], W[i+7], K[i+7] );
|
||||
}
|
||||
|
||||
for( i = 16; i < 64; i += 8 )
|
||||
{
|
||||
P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], R(i+0), K[i+0] );
|
||||
P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], R(i+1), K[i+1] );
|
||||
P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], R(i+2), K[i+2] );
|
||||
P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], R(i+3), K[i+3] );
|
||||
P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], R(i+4), K[i+4] );
|
||||
P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], R(i+5), K[i+5] );
|
||||
P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], R(i+6), K[i+6] );
|
||||
P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], R(i+7), K[i+7] );
|
||||
}
|
||||
#endif /* MBEDTLS_SHA256_SMALLER */
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
ctx->state[i] += A[i];
|
||||
}
|
||||
#endif /* !MBEDTLS_SHA256_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
* SHA-256 process buffer
|
||||
*/
|
||||
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
size_t fill;
|
||||
uint32_t left;
|
||||
|
||||
if( ilen == 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += (uint32_t) ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (uint32_t) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left), input, fill );
|
||||
mbedtls_sha256_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
mbedtls_sha256_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
memcpy( (void *) (ctx->buffer + left), input, ilen );
|
||||
}
|
||||
|
||||
static const unsigned char sha256_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA-256 final digest
|
||||
*/
|
||||
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] )
|
||||
{
|
||||
uint32_t last, padn;
|
||||
uint32_t high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_UINT32_BE( high, msglen, 0 );
|
||||
PUT_UINT32_BE( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
mbedtls_sha256_update( ctx, sha256_padding, padn );
|
||||
mbedtls_sha256_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_UINT32_BE( ctx->state[0], output, 0 );
|
||||
PUT_UINT32_BE( ctx->state[1], output, 4 );
|
||||
PUT_UINT32_BE( ctx->state[2], output, 8 );
|
||||
PUT_UINT32_BE( ctx->state[3], output, 12 );
|
||||
PUT_UINT32_BE( ctx->state[4], output, 16 );
|
||||
PUT_UINT32_BE( ctx->state[5], output, 20 );
|
||||
PUT_UINT32_BE( ctx->state[6], output, 24 );
|
||||
|
||||
if( ctx->is224 == 0 )
|
||||
PUT_UINT32_BE( ctx->state[7], output, 28 );
|
||||
}
|
||||
|
||||
#endif /* !MBEDTLS_SHA256_ALT */
|
||||
|
||||
/*
|
||||
* output = SHA-256( input buffer )
|
||||
*/
|
||||
void mbedtls_sha256( const unsigned char *input, size_t ilen,
|
||||
unsigned char output[32], int is224 )
|
||||
{
|
||||
mbedtls_sha256_context ctx;
|
||||
|
||||
mbedtls_sha256_init( &ctx );
|
||||
mbedtls_sha256_starts( &ctx, is224 );
|
||||
mbedtls_sha256_update( &ctx, input, ilen );
|
||||
mbedtls_sha256_finish( &ctx, output );
|
||||
mbedtls_sha256_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-2 test vectors
|
||||
*/
|
||||
static const unsigned char sha256_test_buf[3][57] =
|
||||
{
|
||||
{ "abc" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha256_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
||||
static const unsigned char sha256_test_sum[6][32] =
|
||||
{
|
||||
/*
|
||||
* SHA-224 test vectors
|
||||
*/
|
||||
{ 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
|
||||
0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
|
||||
0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
|
||||
0xE3, 0x6C, 0x9D, 0xA7 },
|
||||
{ 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
|
||||
0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
|
||||
0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
|
||||
0x52, 0x52, 0x25, 0x25 },
|
||||
{ 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
|
||||
0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
|
||||
0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
|
||||
0x4E, 0xE7, 0xAD, 0x67 },
|
||||
|
||||
/*
|
||||
* SHA-256 test vectors
|
||||
*/
|
||||
{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
|
||||
0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
|
||||
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
|
||||
0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
|
||||
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
|
||||
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
|
||||
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
|
||||
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
|
||||
{ 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
|
||||
0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
|
||||
0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
|
||||
0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_sha256_self_test( int verbose )
|
||||
{
|
||||
int i, j, k, buflen, ret = 0;
|
||||
unsigned char *buf;
|
||||
unsigned char sha256sum[32];
|
||||
mbedtls_sha256_context ctx;
|
||||
|
||||
buf = mbedtls_malloc( 1024 * sizeof(unsigned char) );
|
||||
if( NULL == buf )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "Buffer allocation failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
memset(buf, 0, 1024 * sizeof(unsigned char));
|
||||
|
||||
mbedtls_sha256_init( &ctx );
|
||||
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
j = i % 3;
|
||||
k = i < 3;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
|
||||
mbedtls_sha256_starts( &ctx, k );
|
||||
|
||||
if( j == 2 )
|
||||
{
|
||||
memset( buf, 'a', buflen = 1000 );
|
||||
|
||||
for( j = 0; j < 1000; j++ )
|
||||
mbedtls_sha256_update( &ctx, buf, buflen );
|
||||
}
|
||||
else
|
||||
mbedtls_sha256_update( &ctx, sha256_test_buf[j],
|
||||
sha256_test_buflen[j] );
|
||||
|
||||
mbedtls_sha256_finish( &ctx, sha256sum );
|
||||
|
||||
if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_sha256_free( &ctx );
|
||||
mbedtls_free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
137
Living_SDK/security/alicrypto/mbedtls/library/threading.c
Normal file
137
Living_SDK/security/alicrypto/mbedtls/library/threading.c
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Threading abstraction layer
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
|
||||
#include "mbedtls/threading.h"
|
||||
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL || mutex->is_valid )
|
||||
return;
|
||||
|
||||
mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0;
|
||||
}
|
||||
|
||||
static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL || !mutex->is_valid )
|
||||
return;
|
||||
|
||||
(void) pthread_mutex_destroy( &mutex->mutex );
|
||||
mutex->is_valid = 0;
|
||||
}
|
||||
|
||||
static int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL || ! mutex->is_valid )
|
||||
return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
|
||||
|
||||
if( pthread_mutex_lock( &mutex->mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int threading_mutex_unlock_pthread( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
if( mutex == NULL || ! mutex->is_valid )
|
||||
return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
|
||||
|
||||
if( pthread_mutex_unlock( &mutex->mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_init_pthread;
|
||||
void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_free_pthread;
|
||||
int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_lock_pthread;
|
||||
int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_unlock_pthread;
|
||||
|
||||
/*
|
||||
* With phtreads we can statically initialize mutexes
|
||||
*/
|
||||
#define MUTEX_INIT = { PTHREAD_MUTEX_INITIALIZER, 1 }
|
||||
|
||||
#endif /* MBEDTLS_THREADING_PTHREAD */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_ALT)
|
||||
static int threading_mutex_fail( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
((void) mutex );
|
||||
return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
|
||||
}
|
||||
static void threading_mutex_dummy( mbedtls_threading_mutex_t *mutex )
|
||||
{
|
||||
((void) mutex );
|
||||
return;
|
||||
}
|
||||
|
||||
void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy;
|
||||
void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t * ) = threading_mutex_dummy;
|
||||
int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail;
|
||||
int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t * ) = threading_mutex_fail;
|
||||
|
||||
/*
|
||||
* Set functions pointers and initialize global mutexes
|
||||
*/
|
||||
void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
|
||||
void (*mutex_free)( mbedtls_threading_mutex_t * ),
|
||||
int (*mutex_lock)( mbedtls_threading_mutex_t * ),
|
||||
int (*mutex_unlock)( mbedtls_threading_mutex_t * ) )
|
||||
{
|
||||
mbedtls_mutex_init = mutex_init;
|
||||
mbedtls_mutex_free = mutex_free;
|
||||
mbedtls_mutex_lock = mutex_lock;
|
||||
mbedtls_mutex_unlock = mutex_unlock;
|
||||
|
||||
mbedtls_mutex_init( &mbedtls_threading_readdir_mutex );
|
||||
mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex );
|
||||
}
|
||||
|
||||
/*
|
||||
* Free global mutexes
|
||||
*/
|
||||
void mbedtls_threading_free_alt( void )
|
||||
{
|
||||
mbedtls_mutex_free( &mbedtls_threading_readdir_mutex );
|
||||
mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex );
|
||||
}
|
||||
#endif /* MBEDTLS_THREADING_ALT */
|
||||
|
||||
/*
|
||||
* Define global mutexes
|
||||
*/
|
||||
#ifndef MUTEX_INIT
|
||||
#define MUTEX_INIT
|
||||
#endif
|
||||
mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT;
|
||||
mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT;
|
||||
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
50
Living_SDK/security/alicrypto/mbedtls/library/version.c
Normal file
50
Living_SDK/security/alicrypto/mbedtls/library/version.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Version information
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_VERSION_C)
|
||||
|
||||
#include "mbedtls/version.h"
|
||||
#include <string.h>
|
||||
|
||||
unsigned int mbedtls_version_get_number()
|
||||
{
|
||||
return( MBEDTLS_VERSION_NUMBER );
|
||||
}
|
||||
|
||||
void mbedtls_version_get_string( char *string )
|
||||
{
|
||||
memcpy( string, MBEDTLS_VERSION_STRING,
|
||||
sizeof( MBEDTLS_VERSION_STRING ) );
|
||||
}
|
||||
|
||||
void mbedtls_version_get_string_full( char *string )
|
||||
{
|
||||
memcpy( string, MBEDTLS_VERSION_STRING_FULL,
|
||||
sizeof( MBEDTLS_VERSION_STRING_FULL ) );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_VERSION_C */
|
||||
647
Living_SDK/security/alicrypto/mbedtls/library/version_features.c
Normal file
647
Living_SDK/security/alicrypto/mbedtls/library/version_features.c
Normal file
|
|
@ -0,0 +1,647 @@
|
|||
/*
|
||||
* Version feature information
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_VERSION_C)
|
||||
|
||||
#include "mbedtls/version.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static const char *features[] = {
|
||||
#if defined(MBEDTLS_VERSION_FEATURES)
|
||||
#if defined(MBEDTLS_HAVE_ASM)
|
||||
"MBEDTLS_HAVE_ASM",
|
||||
#endif /* MBEDTLS_HAVE_ASM */
|
||||
#if defined(MBEDTLS_HAVE_SSE2)
|
||||
"MBEDTLS_HAVE_SSE2",
|
||||
#endif /* MBEDTLS_HAVE_SSE2 */
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
"MBEDTLS_HAVE_TIME",
|
||||
#endif /* MBEDTLS_HAVE_TIME */
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
"MBEDTLS_HAVE_TIME_DATE",
|
||||
#endif /* MBEDTLS_HAVE_TIME_DATE */
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
"MBEDTLS_PLATFORM_MEMORY",
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY */
|
||||
#if defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
||||
"MBEDTLS_PLATFORM_NO_STD_FUNCTIONS",
|
||||
#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
||||
#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||
"MBEDTLS_PLATFORM_EXIT_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_TIME_ALT)
|
||||
"MBEDTLS_PLATFORM_TIME_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_TIME_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||
"MBEDTLS_PLATFORM_FPRINTF_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||
"MBEDTLS_PLATFORM_PRINTF_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||
"MBEDTLS_PLATFORM_SNPRINTF_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
|
||||
"MBEDTLS_PLATFORM_NV_SEED_ALT",
|
||||
#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
"MBEDTLS_DEPRECATED_WARNING",
|
||||
#endif /* MBEDTLS_DEPRECATED_WARNING */
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
"MBEDTLS_DEPRECATED_REMOVED",
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#if defined(MBEDTLS_TIMING_ALT)
|
||||
"MBEDTLS_TIMING_ALT",
|
||||
#endif /* MBEDTLS_TIMING_ALT */
|
||||
#if defined(MBEDTLS_AES_ALT)
|
||||
"MBEDTLS_AES_ALT",
|
||||
#endif /* MBEDTLS_AES_ALT */
|
||||
#if defined(MBEDTLS_ARC4_ALT)
|
||||
"MBEDTLS_ARC4_ALT",
|
||||
#endif /* MBEDTLS_ARC4_ALT */
|
||||
#if defined(MBEDTLS_BLOWFISH_ALT)
|
||||
"MBEDTLS_BLOWFISH_ALT",
|
||||
#endif /* MBEDTLS_BLOWFISH_ALT */
|
||||
#if defined(MBEDTLS_CAMELLIA_ALT)
|
||||
"MBEDTLS_CAMELLIA_ALT",
|
||||
#endif /* MBEDTLS_CAMELLIA_ALT */
|
||||
#if defined(MBEDTLS_DES_ALT)
|
||||
"MBEDTLS_DES_ALT",
|
||||
#endif /* MBEDTLS_DES_ALT */
|
||||
#if defined(MBEDTLS_XTEA_ALT)
|
||||
"MBEDTLS_XTEA_ALT",
|
||||
#endif /* MBEDTLS_XTEA_ALT */
|
||||
#if defined(MBEDTLS_MD2_ALT)
|
||||
"MBEDTLS_MD2_ALT",
|
||||
#endif /* MBEDTLS_MD2_ALT */
|
||||
#if defined(MBEDTLS_MD4_ALT)
|
||||
"MBEDTLS_MD4_ALT",
|
||||
#endif /* MBEDTLS_MD4_ALT */
|
||||
#if defined(MBEDTLS_MD5_ALT)
|
||||
"MBEDTLS_MD5_ALT",
|
||||
#endif /* MBEDTLS_MD5_ALT */
|
||||
#if defined(MBEDTLS_RIPEMD160_ALT)
|
||||
"MBEDTLS_RIPEMD160_ALT",
|
||||
#endif /* MBEDTLS_RIPEMD160_ALT */
|
||||
#if defined(MBEDTLS_SHA1_ALT)
|
||||
"MBEDTLS_SHA1_ALT",
|
||||
#endif /* MBEDTLS_SHA1_ALT */
|
||||
#if defined(MBEDTLS_SHA256_ALT)
|
||||
"MBEDTLS_SHA256_ALT",
|
||||
#endif /* MBEDTLS_SHA256_ALT */
|
||||
#if defined(MBEDTLS_SHA512_ALT)
|
||||
"MBEDTLS_SHA512_ALT",
|
||||
#endif /* MBEDTLS_SHA512_ALT */
|
||||
#if defined(MBEDTLS_MD2_PROCESS_ALT)
|
||||
"MBEDTLS_MD2_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_MD2_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_MD4_PROCESS_ALT)
|
||||
"MBEDTLS_MD4_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_MD4_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_MD5_PROCESS_ALT)
|
||||
"MBEDTLS_MD5_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_MD5_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
|
||||
"MBEDTLS_RIPEMD160_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_RIPEMD160_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_SHA1_PROCESS_ALT)
|
||||
"MBEDTLS_SHA1_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_SHA1_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_SHA256_PROCESS_ALT)
|
||||
"MBEDTLS_SHA256_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_SHA256_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_SHA512_PROCESS_ALT)
|
||||
"MBEDTLS_SHA512_PROCESS_ALT",
|
||||
#endif /* MBEDTLS_SHA512_PROCESS_ALT */
|
||||
#if defined(MBEDTLS_DES_SETKEY_ALT)
|
||||
"MBEDTLS_DES_SETKEY_ALT",
|
||||
#endif /* MBEDTLS_DES_SETKEY_ALT */
|
||||
#if defined(MBEDTLS_DES_CRYPT_ECB_ALT)
|
||||
"MBEDTLS_DES_CRYPT_ECB_ALT",
|
||||
#endif /* MBEDTLS_DES_CRYPT_ECB_ALT */
|
||||
#if defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
|
||||
"MBEDTLS_DES3_CRYPT_ECB_ALT",
|
||||
#endif /* MBEDTLS_DES3_CRYPT_ECB_ALT */
|
||||
#if defined(MBEDTLS_AES_SETKEY_ENC_ALT)
|
||||
"MBEDTLS_AES_SETKEY_ENC_ALT",
|
||||
#endif /* MBEDTLS_AES_SETKEY_ENC_ALT */
|
||||
#if defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
"MBEDTLS_AES_SETKEY_DEC_ALT",
|
||||
#endif /* MBEDTLS_AES_SETKEY_DEC_ALT */
|
||||
#if defined(MBEDTLS_AES_ENCRYPT_ALT)
|
||||
"MBEDTLS_AES_ENCRYPT_ALT",
|
||||
#endif /* MBEDTLS_AES_ENCRYPT_ALT */
|
||||
#if defined(MBEDTLS_AES_DECRYPT_ALT)
|
||||
"MBEDTLS_AES_DECRYPT_ALT",
|
||||
#endif /* MBEDTLS_AES_DECRYPT_ALT */
|
||||
#if defined(MBEDTLS_TEST_NULL_ENTROPY)
|
||||
"MBEDTLS_TEST_NULL_ENTROPY",
|
||||
#endif /* MBEDTLS_TEST_NULL_ENTROPY */
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
"MBEDTLS_ENTROPY_HARDWARE_ALT",
|
||||
#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
|
||||
#if defined(MBEDTLS_AES_ROM_TABLES)
|
||||
"MBEDTLS_AES_ROM_TABLES",
|
||||
#endif /* MBEDTLS_AES_ROM_TABLES */
|
||||
#if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY)
|
||||
"MBEDTLS_CAMELLIA_SMALL_MEMORY",
|
||||
#endif /* MBEDTLS_CAMELLIA_SMALL_MEMORY */
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
"MBEDTLS_CIPHER_MODE_CBC",
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
"MBEDTLS_CIPHER_MODE_CFB",
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
"MBEDTLS_CIPHER_MODE_CTR",
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
"MBEDTLS_CIPHER_NULL_CIPHER",
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
|
||||
"MBEDTLS_CIPHER_PADDING_PKCS7",
|
||||
#endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */
|
||||
#if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
|
||||
"MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS",
|
||||
#endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */
|
||||
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
|
||||
"MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN",
|
||||
#endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */
|
||||
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
|
||||
"MBEDTLS_CIPHER_PADDING_ZEROS",
|
||||
#endif /* MBEDTLS_CIPHER_PADDING_ZEROS */
|
||||
#if defined(MBEDTLS_ENABLE_WEAK_CIPHERSUITES)
|
||||
"MBEDTLS_ENABLE_WEAK_CIPHERSUITES",
|
||||
#endif /* MBEDTLS_ENABLE_WEAK_CIPHERSUITES */
|
||||
#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
|
||||
"MBEDTLS_REMOVE_ARC4_CIPHERSUITES",
|
||||
#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP192R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP224R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP256R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP384R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP521R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP192K1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP224K1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_SECP256K1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_BP256R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_BP384R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
"MBEDTLS_ECP_DP_BP512R1_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
||||
"MBEDTLS_ECP_DP_CURVE25519_ENABLED",
|
||||
#endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_NIST_OPTIM)
|
||||
"MBEDTLS_ECP_NIST_OPTIM",
|
||||
#endif /* MBEDTLS_ECP_NIST_OPTIM */
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
"MBEDTLS_ECDSA_DETERMINISTIC",
|
||||
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_PSK_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_RSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
"MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED",
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
#if defined(MBEDTLS_PK_PARSE_EC_EXTENDED)
|
||||
"MBEDTLS_PK_PARSE_EC_EXTENDED",
|
||||
#endif /* MBEDTLS_PK_PARSE_EC_EXTENDED */
|
||||
#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
|
||||
"MBEDTLS_ERROR_STRERROR_DUMMY",
|
||||
#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
|
||||
#if defined(MBEDTLS_GENPRIME)
|
||||
"MBEDTLS_GENPRIME",
|
||||
#endif /* MBEDTLS_GENPRIME */
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
"MBEDTLS_FS_IO",
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
#if defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
|
||||
"MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
|
||||
#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
|
||||
#if defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
||||
"MBEDTLS_NO_PLATFORM_ENTROPY",
|
||||
#endif /* MBEDTLS_NO_PLATFORM_ENTROPY */
|
||||
#if defined(MBEDTLS_ENTROPY_FORCE_SHA256)
|
||||
"MBEDTLS_ENTROPY_FORCE_SHA256",
|
||||
#endif /* MBEDTLS_ENTROPY_FORCE_SHA256 */
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
"MBEDTLS_ENTROPY_NV_SEED",
|
||||
#endif /* MBEDTLS_ENTROPY_NV_SEED */
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
"MBEDTLS_MEMORY_DEBUG",
|
||||
#endif /* MBEDTLS_MEMORY_DEBUG */
|
||||
#if defined(MBEDTLS_MEMORY_BACKTRACE)
|
||||
"MBEDTLS_MEMORY_BACKTRACE",
|
||||
#endif /* MBEDTLS_MEMORY_BACKTRACE */
|
||||
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
||||
"MBEDTLS_PK_RSA_ALT_SUPPORT",
|
||||
#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
|
||||
#if defined(MBEDTLS_PKCS1_V15)
|
||||
"MBEDTLS_PKCS1_V15",
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
#if defined(MBEDTLS_PKCS1_V21)
|
||||
"MBEDTLS_PKCS1_V21",
|
||||
#endif /* MBEDTLS_PKCS1_V21 */
|
||||
#if defined(MBEDTLS_RSA_NO_CRT)
|
||||
"MBEDTLS_RSA_NO_CRT",
|
||||
#endif /* MBEDTLS_RSA_NO_CRT */
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
"MBEDTLS_SELF_TEST",
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
#if defined(MBEDTLS_SHA256_SMALLER)
|
||||
"MBEDTLS_SHA256_SMALLER",
|
||||
#endif /* MBEDTLS_SHA256_SMALLER */
|
||||
#if defined(MBEDTLS_SSL_ALL_ALERT_MESSAGES)
|
||||
"MBEDTLS_SSL_ALL_ALERT_MESSAGES",
|
||||
#endif /* MBEDTLS_SSL_ALL_ALERT_MESSAGES */
|
||||
#if defined(MBEDTLS_SSL_DEBUG_ALL)
|
||||
"MBEDTLS_SSL_DEBUG_ALL",
|
||||
#endif /* MBEDTLS_SSL_DEBUG_ALL */
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||
"MBEDTLS_SSL_ENCRYPT_THEN_MAC",
|
||||
#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
|
||||
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
||||
"MBEDTLS_SSL_EXTENDED_MASTER_SECRET",
|
||||
#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
|
||||
#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
|
||||
"MBEDTLS_SSL_FALLBACK_SCSV",
|
||||
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
"MBEDTLS_SSL_HW_RECORD_ACCEL",
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
|
||||
"MBEDTLS_SSL_CBC_RECORD_SPLITTING",
|
||||
#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
"MBEDTLS_SSL_RENEGOTIATION",
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
|
||||
"MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO",
|
||||
#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
|
||||
#if defined(MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
|
||||
"MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE",
|
||||
#endif /* MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE */
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||
"MBEDTLS_SSL_MAX_FRAGMENT_LENGTH",
|
||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
"MBEDTLS_SSL_PROTO_SSL3",
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
"MBEDTLS_SSL_PROTO_TLS1",
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
"MBEDTLS_SSL_PROTO_TLS1_1",
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
"MBEDTLS_SSL_PROTO_TLS1_2",
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
"MBEDTLS_SSL_PROTO_DTLS",
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
#if defined(MBEDTLS_SSL_ALPN)
|
||||
"MBEDTLS_SSL_ALPN",
|
||||
#endif /* MBEDTLS_SSL_ALPN */
|
||||
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
||||
"MBEDTLS_SSL_DTLS_ANTI_REPLAY",
|
||||
#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
|
||||
"MBEDTLS_SSL_DTLS_HELLO_VERIFY",
|
||||
#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY */
|
||||
#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE)
|
||||
"MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE",
|
||||
#endif /* MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE */
|
||||
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
|
||||
"MBEDTLS_SSL_DTLS_BADMAC_LIMIT",
|
||||
#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
"MBEDTLS_SSL_SESSION_TICKETS",
|
||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
|
||||
#if defined(MBEDTLS_SSL_EXPORT_KEYS)
|
||||
"MBEDTLS_SSL_EXPORT_KEYS",
|
||||
#endif /* MBEDTLS_SSL_EXPORT_KEYS */
|
||||
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
||||
"MBEDTLS_SSL_SERVER_NAME_INDICATION",
|
||||
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||
"MBEDTLS_SSL_TRUNCATED_HMAC",
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
#if defined(MBEDTLS_THREADING_ALT)
|
||||
"MBEDTLS_THREADING_ALT",
|
||||
#endif /* MBEDTLS_THREADING_ALT */
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
"MBEDTLS_THREADING_PTHREAD",
|
||||
#endif /* MBEDTLS_THREADING_PTHREAD */
|
||||
#if defined(MBEDTLS_VERSION_FEATURES)
|
||||
"MBEDTLS_VERSION_FEATURES",
|
||||
#endif /* MBEDTLS_VERSION_FEATURES */
|
||||
#if defined(MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3)
|
||||
"MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3",
|
||||
#endif /* MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 */
|
||||
#if defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
|
||||
"MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION",
|
||||
#endif /* MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION */
|
||||
#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
|
||||
"MBEDTLS_X509_CHECK_KEY_USAGE",
|
||||
#endif /* MBEDTLS_X509_CHECK_KEY_USAGE */
|
||||
#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
|
||||
"MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE",
|
||||
#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
"MBEDTLS_X509_RSASSA_PSS_SUPPORT",
|
||||
#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
"MBEDTLS_ZLIB_SUPPORT",
|
||||
#endif /* MBEDTLS_ZLIB_SUPPORT */
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
"MBEDTLS_AESNI_C",
|
||||
#endif /* MBEDTLS_AESNI_C */
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
"MBEDTLS_AES_C",
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
"MBEDTLS_ARC4_C",
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
"MBEDTLS_ASN1_PARSE_C",
|
||||
#endif /* MBEDTLS_ASN1_PARSE_C */
|
||||
#if defined(MBEDTLS_ASN1_WRITE_C)
|
||||
"MBEDTLS_ASN1_WRITE_C",
|
||||
#endif /* MBEDTLS_ASN1_WRITE_C */
|
||||
#if defined(MBEDTLS_BASE64_C)
|
||||
"MBEDTLS_BASE64_C",
|
||||
#endif /* MBEDTLS_BASE64_C */
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
"MBEDTLS_BIGNUM_C",
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
#if defined(MBEDTLS_BLOWFISH_C)
|
||||
"MBEDTLS_BLOWFISH_C",
|
||||
#endif /* MBEDTLS_BLOWFISH_C */
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
"MBEDTLS_CAMELLIA_C",
|
||||
#endif /* MBEDTLS_CAMELLIA_C */
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
"MBEDTLS_CCM_C",
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
#if defined(MBEDTLS_CERTS_C)
|
||||
"MBEDTLS_CERTS_C",
|
||||
#endif /* MBEDTLS_CERTS_C */
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
"MBEDTLS_CIPHER_C",
|
||||
#endif /* MBEDTLS_CIPHER_C */
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
"MBEDTLS_CMAC_C",
|
||||
#endif /* MBEDTLS_CMAC_C */
|
||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||
"MBEDTLS_CTR_DRBG_C",
|
||||
#endif /* MBEDTLS_CTR_DRBG_C */
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
"MBEDTLS_DEBUG_C",
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
"MBEDTLS_DES_C",
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
#if defined(MBEDTLS_DHM_C)
|
||||
"MBEDTLS_DHM_C",
|
||||
#endif /* MBEDTLS_DHM_C */
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
"MBEDTLS_ECDH_C",
|
||||
#endif /* MBEDTLS_ECDH_C */
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
"MBEDTLS_ECDSA_C",
|
||||
#endif /* MBEDTLS_ECDSA_C */
|
||||
#if defined(MBEDTLS_ECJPAKE_C)
|
||||
"MBEDTLS_ECJPAKE_C",
|
||||
#endif /* MBEDTLS_ECJPAKE_C */
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
"MBEDTLS_ECP_C",
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
#if defined(MBEDTLS_ENTROPY_C)
|
||||
"MBEDTLS_ENTROPY_C",
|
||||
#endif /* MBEDTLS_ENTROPY_C */
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
"MBEDTLS_ERROR_C",
|
||||
#endif /* MBEDTLS_ERROR_C */
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
"MBEDTLS_GCM_C",
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
"MBEDTLS_HAVEGE_C",
|
||||
#endif /* MBEDTLS_HAVEGE_C */
|
||||
#if defined(MBEDTLS_HMAC_DRBG_C)
|
||||
"MBEDTLS_HMAC_DRBG_C",
|
||||
#endif /* MBEDTLS_HMAC_DRBG_C */
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
"MBEDTLS_MD_C",
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
"MBEDTLS_MD2_C",
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
"MBEDTLS_MD4_C",
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
"MBEDTLS_MD5_C",
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
"MBEDTLS_MEMORY_BUFFER_ALLOC_C",
|
||||
#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
|
||||
#if defined(MBEDTLS_NET_C)
|
||||
"MBEDTLS_NET_C",
|
||||
#endif /* MBEDTLS_NET_C */
|
||||
#if defined(MBEDTLS_OID_C)
|
||||
"MBEDTLS_OID_C",
|
||||
#endif /* MBEDTLS_OID_C */
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
"MBEDTLS_PADLOCK_C",
|
||||
#endif /* MBEDTLS_PADLOCK_C */
|
||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||
"MBEDTLS_PEM_PARSE_C",
|
||||
#endif /* MBEDTLS_PEM_PARSE_C */
|
||||
#if defined(MBEDTLS_PEM_WRITE_C)
|
||||
"MBEDTLS_PEM_WRITE_C",
|
||||
#endif /* MBEDTLS_PEM_WRITE_C */
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
"MBEDTLS_PK_C",
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
#if defined(MBEDTLS_PK_PARSE_C)
|
||||
"MBEDTLS_PK_PARSE_C",
|
||||
#endif /* MBEDTLS_PK_PARSE_C */
|
||||
#if defined(MBEDTLS_PK_WRITE_C)
|
||||
"MBEDTLS_PK_WRITE_C",
|
||||
#endif /* MBEDTLS_PK_WRITE_C */
|
||||
#if defined(MBEDTLS_PKCS5_C)
|
||||
"MBEDTLS_PKCS5_C",
|
||||
#endif /* MBEDTLS_PKCS5_C */
|
||||
#if defined(MBEDTLS_PKCS11_C)
|
||||
"MBEDTLS_PKCS11_C",
|
||||
#endif /* MBEDTLS_PKCS11_C */
|
||||
#if defined(MBEDTLS_PKCS12_C)
|
||||
"MBEDTLS_PKCS12_C",
|
||||
#endif /* MBEDTLS_PKCS12_C */
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
"MBEDTLS_PLATFORM_C",
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
"MBEDTLS_RIPEMD160_C",
|
||||
#endif /* MBEDTLS_RIPEMD160_C */
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
"MBEDTLS_RSA_C",
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
"MBEDTLS_SHA1_C",
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
"MBEDTLS_SHA256_C",
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
"MBEDTLS_SHA512_C",
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#if defined(MBEDTLS_SSL_CACHE_C)
|
||||
"MBEDTLS_SSL_CACHE_C",
|
||||
#endif /* MBEDTLS_SSL_CACHE_C */
|
||||
#if defined(MBEDTLS_SSL_COOKIE_C)
|
||||
"MBEDTLS_SSL_COOKIE_C",
|
||||
#endif /* MBEDTLS_SSL_COOKIE_C */
|
||||
#if defined(MBEDTLS_SSL_TICKET_C)
|
||||
"MBEDTLS_SSL_TICKET_C",
|
||||
#endif /* MBEDTLS_SSL_TICKET_C */
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
"MBEDTLS_SSL_CLI_C",
|
||||
#endif /* MBEDTLS_SSL_CLI_C */
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
"MBEDTLS_SSL_SRV_C",
|
||||
#endif /* MBEDTLS_SSL_SRV_C */
|
||||
#if defined(MBEDTLS_SSL_TLS_C)
|
||||
"MBEDTLS_SSL_TLS_C",
|
||||
#endif /* MBEDTLS_SSL_TLS_C */
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
"MBEDTLS_THREADING_C",
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
"MBEDTLS_TIMING_C",
|
||||
#endif /* MBEDTLS_TIMING_C */
|
||||
#if defined(MBEDTLS_VERSION_C)
|
||||
"MBEDTLS_VERSION_C",
|
||||
#endif /* MBEDTLS_VERSION_C */
|
||||
#if defined(MBEDTLS_X509_USE_C)
|
||||
"MBEDTLS_X509_USE_C",
|
||||
#endif /* MBEDTLS_X509_USE_C */
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
"MBEDTLS_X509_CRT_PARSE_C",
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
"MBEDTLS_X509_CRL_PARSE_C",
|
||||
#endif /* MBEDTLS_X509_CRL_PARSE_C */
|
||||
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
||||
"MBEDTLS_X509_CSR_PARSE_C",
|
||||
#endif /* MBEDTLS_X509_CSR_PARSE_C */
|
||||
#if defined(MBEDTLS_X509_CREATE_C)
|
||||
"MBEDTLS_X509_CREATE_C",
|
||||
#endif /* MBEDTLS_X509_CREATE_C */
|
||||
#if defined(MBEDTLS_X509_CRT_WRITE_C)
|
||||
"MBEDTLS_X509_CRT_WRITE_C",
|
||||
#endif /* MBEDTLS_X509_CRT_WRITE_C */
|
||||
#if defined(MBEDTLS_X509_CSR_WRITE_C)
|
||||
"MBEDTLS_X509_CSR_WRITE_C",
|
||||
#endif /* MBEDTLS_X509_CSR_WRITE_C */
|
||||
#if defined(MBEDTLS_XTEA_C)
|
||||
"MBEDTLS_XTEA_C",
|
||||
#endif /* MBEDTLS_XTEA_C */
|
||||
#endif /* MBEDTLS_VERSION_FEATURES */
|
||||
NULL
|
||||
};
|
||||
|
||||
int mbedtls_version_check_feature( const char *feature )
|
||||
{
|
||||
const char **idx = features;
|
||||
|
||||
if( *idx == NULL )
|
||||
return( -2 );
|
||||
|
||||
if( feature == NULL )
|
||||
return( -1 );
|
||||
|
||||
while( *idx != NULL )
|
||||
{
|
||||
if( !strcmp( *idx, feature ) )
|
||||
return( 0 );
|
||||
idx++;
|
||||
}
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_VERSION_C */
|
||||
Loading…
Add table
Add a link
Reference in a new issue