Merge pull request #4407 from ARMmbed/dev3_signoffs
Merge development_3.0 into development
This commit is contained in:
commit
12f93f4fc2
183 changed files with 834 additions and 12758 deletions
|
@ -39,7 +39,6 @@ set(src_crypto
|
|||
entropy_poll.c
|
||||
error.c
|
||||
gcm.c
|
||||
havege.c
|
||||
hkdf.c
|
||||
hmac_drbg.c
|
||||
md.c
|
||||
|
@ -76,7 +75,7 @@ set(src_crypto
|
|||
psa_its_file.c
|
||||
ripemd160.c
|
||||
rsa.c
|
||||
rsa_internal.c
|
||||
rsa_alt_helpers.c
|
||||
sha1.c
|
||||
sha256.c
|
||||
sha512.c
|
||||
|
@ -90,8 +89,6 @@ set(src_crypto
|
|||
list(APPEND src_crypto ${thirdparty_src})
|
||||
|
||||
set(src_x509
|
||||
certs.c
|
||||
pkcs11.c
|
||||
x509.c
|
||||
x509_create.c
|
||||
x509_crl.c
|
||||
|
@ -138,14 +135,6 @@ if(HAIKU)
|
|||
set(libs ${libs} network)
|
||||
endif(HAIKU)
|
||||
|
||||
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()
|
||||
|
|
|
@ -96,7 +96,6 @@ OBJS_CRYPTO= \
|
|||
entropy_poll.o \
|
||||
error.o \
|
||||
gcm.o \
|
||||
havege.o \
|
||||
hkdf.o \
|
||||
hmac_drbg.o \
|
||||
md.o \
|
||||
|
@ -133,7 +132,7 @@ OBJS_CRYPTO= \
|
|||
psa_its_file.o \
|
||||
ripemd160.o \
|
||||
rsa.o \
|
||||
rsa_internal.o \
|
||||
rsa_alt_helpers.o \
|
||||
sha1.o \
|
||||
sha256.o \
|
||||
sha512.o \
|
||||
|
@ -149,8 +148,6 @@ LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
|
|||
OBJS_CRYPTO+=$(THIRDPARTY_CRYPTO_OBJECTS)
|
||||
|
||||
OBJS_X509= \
|
||||
certs.o \
|
||||
pkcs11.o \
|
||||
x509.o \
|
||||
x509_create.o \
|
||||
x509_crl.o \
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
#include "mbedtls/padlock.h"
|
||||
#include "padlock.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
136
library/aesni.h
Normal file
136
library/aesni.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
* \file aesni.h
|
||||
*
|
||||
* \brief AES-NI for hardware AES acceleration on some Intel processors
|
||||
*
|
||||
* \warning These functions are only for internal use by other library
|
||||
* functions; you must not call them directly.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_AESNI_H
|
||||
#define MBEDTLS_AESNI_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
#define MBEDTLS_AESNI_AES 0x02000000u
|
||||
#define MBEDTLS_AESNI_CLMUL 0x00000002u
|
||||
|
||||
#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
|
||||
( defined(__amd64__) || defined(__x86_64__) ) && \
|
||||
! defined(MBEDTLS_HAVE_X86_64)
|
||||
#define MBEDTLS_HAVE_X86_64
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_X86_64)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Internal function to detect the AES-NI feature in CPUs.
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param what The feature to detect
|
||||
* (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
|
||||
*
|
||||
* \return 1 if CPU has support for the feature, 0 otherwise
|
||||
*/
|
||||
int mbedtls_aesni_has_support( unsigned int what );
|
||||
|
||||
/**
|
||||
* \brief Internal AES-NI AES-ECB block encryption and decryption
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param ctx AES context
|
||||
* \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
|
||||
* \param input 16-byte input block
|
||||
* \param output 16-byte output block
|
||||
*
|
||||
* \return 0 on success (cannot fail)
|
||||
*/
|
||||
int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief Internal GCM multiplication: c = a * b in GF(2^128)
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param c Result
|
||||
* \param a First operand
|
||||
* \param b Second operand
|
||||
*
|
||||
* \note Both operands and result are bit strings interpreted as
|
||||
* elements of GF(2^128) as per the GCM spec.
|
||||
*/
|
||||
void mbedtls_aesni_gcm_mult( unsigned char c[16],
|
||||
const unsigned char a[16],
|
||||
const unsigned char b[16] );
|
||||
|
||||
/**
|
||||
* \brief Internal round key inversion. This function computes
|
||||
* decryption round keys from the encryption round keys.
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param invkey Round keys for the equivalent inverse cipher
|
||||
* \param fwdkey Original round keys (for encryption)
|
||||
* \param nr Number of rounds (that is, number of round keys minus one)
|
||||
*/
|
||||
void mbedtls_aesni_inverse_key( unsigned char *invkey,
|
||||
const unsigned char *fwdkey,
|
||||
int nr );
|
||||
|
||||
/**
|
||||
* \brief Internal key expansion for encryption
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param rk Destination buffer where the round keys are written
|
||||
* \param key Encryption key
|
||||
* \param bits Key size in bits (must be 128, 192 or 256)
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
|
||||
*/
|
||||
int mbedtls_aesni_setkey_enc( unsigned char *rk,
|
||||
const unsigned char *key,
|
||||
size_t bits );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_HAVE_X86_64 */
|
||||
|
||||
#endif /* MBEDTLS_AESNI_H */
|
|
@ -461,7 +461,7 @@ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
|
|||
}
|
||||
}
|
||||
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
|
||||
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len )
|
||||
{
|
||||
while( list != NULL )
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
|
||||
int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start, size_t len )
|
||||
{
|
||||
if( len < 0x80 )
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len
|
|||
#endif
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start, unsigned char tag )
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start, unsigned char tag )
|
||||
{
|
||||
if( *p - start < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
@ -108,7 +108,7 @@ int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start, unsigned ch
|
|||
return( 1 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size )
|
||||
{
|
||||
size_t len = 0;
|
||||
|
@ -124,7 +124,7 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
|||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X )
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start, const mbedtls_mpi *X )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -161,7 +161,7 @@ cleanup:
|
|||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start )
|
||||
int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -174,7 +174,7 @@ int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start )
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -188,7 +188,7 @@ int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len )
|
||||
{
|
||||
|
@ -209,7 +209,7 @@ int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *s
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start, int boolean )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -226,7 +226,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolea
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
static int asn1_write_tagged_int( unsigned char **p, unsigned char *start, int val, int tag )
|
||||
static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, int val, int tag )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -255,17 +255,17 @@ static int asn1_write_tagged_int( unsigned char **p, unsigned char *start, int v
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val )
|
||||
int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val )
|
||||
{
|
||||
return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_INTEGER ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val )
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val )
|
||||
{
|
||||
return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_ENUMERATED ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, int tag,
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start, int tag,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -280,26 +280,26 @@ int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, i
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
||||
unsigned char *start,
|
||||
const unsigned char *start,
|
||||
const unsigned char *buf,
|
||||
size_t bits )
|
||||
{
|
||||
|
@ -341,7 +341,7 @@ int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
|||
return( mbedtls_asn1_write_bitstring( p, start, buf, bits ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t bits )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -374,7 +374,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/bn_mul.h"
|
||||
#include "bn_mul.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
|
938
library/bn_mul.h
Normal file
938
library/bn_mul.h
Normal file
|
@ -0,0 +1,938 @@
|
|||
/**
|
||||
* \file bn_mul.h
|
||||
*
|
||||
* \brief Multi-precision integer library
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* Multiply source vector [s] with b, add result
|
||||
* to destination vector [d] and set carry c.
|
||||
*
|
||||
* Currently supports:
|
||||
*
|
||||
* . IA-32 (386+) . AMD64 / EM64T
|
||||
* . IA-32 (SSE2) . Motorola 68000
|
||||
* . PowerPC, 32-bit . MicroBlaze
|
||||
* . PowerPC, 64-bit . TriCore
|
||||
* . SPARC v8 . ARM v3+
|
||||
* . Alpha . MIPS32
|
||||
* . C, longlong . C, generic
|
||||
*/
|
||||
#ifndef MBEDTLS_BN_MUL_H
|
||||
#define MBEDTLS_BN_MUL_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
#if defined(MBEDTLS_HAVE_ASM)
|
||||
|
||||
#ifndef asm
|
||||
#define asm __asm
|
||||
#endif
|
||||
|
||||
/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
|
||||
#if defined(__GNUC__) && \
|
||||
( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
|
||||
|
||||
/*
|
||||
* Disable use of the i386 assembly code below if option -O0, to disable all
|
||||
* compiler optimisations, is passed, detected with __OPTIMIZE__
|
||||
* This is done as the number of registers used in the assembly code doesn't
|
||||
* work with the -O0 option.
|
||||
*/
|
||||
#if defined(__i386__) && defined(__OPTIMIZE__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"movl %%ebx, %0 \n\t" \
|
||||
"movl %5, %%esi \n\t" \
|
||||
"movl %6, %%edi \n\t" \
|
||||
"movl %7, %%ecx \n\t" \
|
||||
"movl %8, %%ebx \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"lodsl \n\t" \
|
||||
"mull %%ebx \n\t" \
|
||||
"addl %%ecx, %%eax \n\t" \
|
||||
"adcl $0, %%edx \n\t" \
|
||||
"addl (%%edi), %%eax \n\t" \
|
||||
"adcl $0, %%edx \n\t" \
|
||||
"movl %%edx, %%ecx \n\t" \
|
||||
"stosl \n\t"
|
||||
|
||||
#if defined(MBEDTLS_HAVE_SSE2)
|
||||
|
||||
#define MULADDC_HUIT \
|
||||
"movd %%ecx, %%mm1 \n\t" \
|
||||
"movd %%ebx, %%mm0 \n\t" \
|
||||
"movd (%%edi), %%mm3 \n\t" \
|
||||
"paddq %%mm3, %%mm1 \n\t" \
|
||||
"movd (%%esi), %%mm2 \n\t" \
|
||||
"pmuludq %%mm0, %%mm2 \n\t" \
|
||||
"movd 4(%%esi), %%mm4 \n\t" \
|
||||
"pmuludq %%mm0, %%mm4 \n\t" \
|
||||
"movd 8(%%esi), %%mm6 \n\t" \
|
||||
"pmuludq %%mm0, %%mm6 \n\t" \
|
||||
"movd 12(%%esi), %%mm7 \n\t" \
|
||||
"pmuludq %%mm0, %%mm7 \n\t" \
|
||||
"paddq %%mm2, %%mm1 \n\t" \
|
||||
"movd 4(%%edi), %%mm3 \n\t" \
|
||||
"paddq %%mm4, %%mm3 \n\t" \
|
||||
"movd 8(%%edi), %%mm5 \n\t" \
|
||||
"paddq %%mm6, %%mm5 \n\t" \
|
||||
"movd 12(%%edi), %%mm4 \n\t" \
|
||||
"paddq %%mm4, %%mm7 \n\t" \
|
||||
"movd %%mm1, (%%edi) \n\t" \
|
||||
"movd 16(%%esi), %%mm2 \n\t" \
|
||||
"pmuludq %%mm0, %%mm2 \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"movd 20(%%esi), %%mm4 \n\t" \
|
||||
"pmuludq %%mm0, %%mm4 \n\t" \
|
||||
"paddq %%mm3, %%mm1 \n\t" \
|
||||
"movd 24(%%esi), %%mm6 \n\t" \
|
||||
"pmuludq %%mm0, %%mm6 \n\t" \
|
||||
"movd %%mm1, 4(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"movd 28(%%esi), %%mm3 \n\t" \
|
||||
"pmuludq %%mm0, %%mm3 \n\t" \
|
||||
"paddq %%mm5, %%mm1 \n\t" \
|
||||
"movd 16(%%edi), %%mm5 \n\t" \
|
||||
"paddq %%mm5, %%mm2 \n\t" \
|
||||
"movd %%mm1, 8(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"paddq %%mm7, %%mm1 \n\t" \
|
||||
"movd 20(%%edi), %%mm5 \n\t" \
|
||||
"paddq %%mm5, %%mm4 \n\t" \
|
||||
"movd %%mm1, 12(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"paddq %%mm2, %%mm1 \n\t" \
|
||||
"movd 24(%%edi), %%mm5 \n\t" \
|
||||
"paddq %%mm5, %%mm6 \n\t" \
|
||||
"movd %%mm1, 16(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"paddq %%mm4, %%mm1 \n\t" \
|
||||
"movd 28(%%edi), %%mm5 \n\t" \
|
||||
"paddq %%mm5, %%mm3 \n\t" \
|
||||
"movd %%mm1, 20(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"paddq %%mm6, %%mm1 \n\t" \
|
||||
"movd %%mm1, 24(%%edi) \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"paddq %%mm3, %%mm1 \n\t" \
|
||||
"movd %%mm1, 28(%%edi) \n\t" \
|
||||
"addl $32, %%edi \n\t" \
|
||||
"addl $32, %%esi \n\t" \
|
||||
"psrlq $32, %%mm1 \n\t" \
|
||||
"movd %%mm1, %%ecx \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"emms \n\t" \
|
||||
"movl %4, %%ebx \n\t" \
|
||||
"movl %%ecx, %1 \n\t" \
|
||||
"movl %%edi, %2 \n\t" \
|
||||
"movl %%esi, %3 \n\t" \
|
||||
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
|
||||
);
|
||||
|
||||
#else
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"movl %4, %%ebx \n\t" \
|
||||
"movl %%ecx, %1 \n\t" \
|
||||
"movl %%edi, %2 \n\t" \
|
||||
"movl %%esi, %3 \n\t" \
|
||||
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
|
||||
);
|
||||
#endif /* SSE2 */
|
||||
#endif /* i386 */
|
||||
|
||||
#if defined(__amd64__) || defined (__x86_64__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"xorq %%r8, %%r8\n"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"movq (%%rsi), %%rax\n" \
|
||||
"mulq %%rbx\n" \
|
||||
"addq $8, %%rsi\n" \
|
||||
"addq %%rcx, %%rax\n" \
|
||||
"movq %%r8, %%rcx\n" \
|
||||
"adcq $0, %%rdx\n" \
|
||||
"nop \n" \
|
||||
"addq %%rax, (%%rdi)\n" \
|
||||
"adcq %%rdx, %%rcx\n" \
|
||||
"addq $8, %%rdi\n"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
: "+c" (c), "+D" (d), "+S" (s) \
|
||||
: "b" (b) \
|
||||
: "rax", "rdx", "r8" \
|
||||
);
|
||||
|
||||
#endif /* AMD64 */
|
||||
|
||||
#if defined(__aarch64__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm(
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldr x4, [%2], #8 \n\t" \
|
||||
"ldr x5, [%1] \n\t" \
|
||||
"mul x6, x4, %3 \n\t" \
|
||||
"umulh x7, x4, %3 \n\t" \
|
||||
"adds x5, x5, x6 \n\t" \
|
||||
"adc x7, x7, xzr \n\t" \
|
||||
"adds x5, x5, %0 \n\t" \
|
||||
"adc %0, x7, xzr \n\t" \
|
||||
"str x5, [%1], #8 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
: "+r" (c), "+r" (d), "+r" (s) \
|
||||
: "r" (b) \
|
||||
: "x4", "x5", "x6", "x7", "cc" \
|
||||
);
|
||||
|
||||
#endif /* Aarch64 */
|
||||
|
||||
#if defined(__mc68020__) || defined(__mcpu32__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"movl %3, %%a2 \n\t" \
|
||||
"movl %4, %%a3 \n\t" \
|
||||
"movl %5, %%d3 \n\t" \
|
||||
"movl %6, %%d2 \n\t" \
|
||||
"moveq #0, %%d0 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d4:%%d1 \n\t" \
|
||||
"addl %%d3, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d4 \n\t" \
|
||||
"moveq #0, %%d3 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"addxl %%d4, %%d3 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"movl %%d3, %0 \n\t" \
|
||||
"movl %%a3, %1 \n\t" \
|
||||
"movl %%a2, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
|
||||
);
|
||||
|
||||
#define MULADDC_HUIT \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d4:%%d1 \n\t" \
|
||||
"addxl %%d3, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d4 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d3:%%d1 \n\t" \
|
||||
"addxl %%d4, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d3 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d4:%%d1 \n\t" \
|
||||
"addxl %%d3, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d4 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d3:%%d1 \n\t" \
|
||||
"addxl %%d4, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d3 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d4:%%d1 \n\t" \
|
||||
"addxl %%d3, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d4 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d3:%%d1 \n\t" \
|
||||
"addxl %%d4, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d3 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d4:%%d1 \n\t" \
|
||||
"addxl %%d3, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d4 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"movel %%a2@+, %%d1 \n\t" \
|
||||
"mulul %%d2, %%d3:%%d1 \n\t" \
|
||||
"addxl %%d4, %%d1 \n\t" \
|
||||
"addxl %%d0, %%d3 \n\t" \
|
||||
"addl %%d1, %%a3@+ \n\t" \
|
||||
"addxl %%d0, %%d3 \n\t"
|
||||
|
||||
#endif /* MC68000 */
|
||||
|
||||
#if defined(__powerpc64__) || defined(__ppc64__)
|
||||
|
||||
#if defined(__MACH__) && defined(__APPLE__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ld r3, %3 \n\t" \
|
||||
"ld r4, %4 \n\t" \
|
||||
"ld r5, %5 \n\t" \
|
||||
"ld r6, %6 \n\t" \
|
||||
"addi r3, r3, -8 \n\t" \
|
||||
"addi r4, r4, -8 \n\t" \
|
||||
"addic r5, r5, 0 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldu r7, 8(r3) \n\t" \
|
||||
"mulld r8, r7, r6 \n\t" \
|
||||
"mulhdu r9, r7, r6 \n\t" \
|
||||
"adde r8, r8, r5 \n\t" \
|
||||
"ld r7, 8(r4) \n\t" \
|
||||
"addze r5, r9 \n\t" \
|
||||
"addc r8, r8, r7 \n\t" \
|
||||
"stdu r8, 8(r4) \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"addze r5, r5 \n\t" \
|
||||
"addi r4, r4, 8 \n\t" \
|
||||
"addi r3, r3, 8 \n\t" \
|
||||
"std r5, %0 \n\t" \
|
||||
"std r4, %1 \n\t" \
|
||||
"std r3, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
||||
);
|
||||
|
||||
|
||||
#else /* __MACH__ && __APPLE__ */
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ld %%r3, %3 \n\t" \
|
||||
"ld %%r4, %4 \n\t" \
|
||||
"ld %%r5, %5 \n\t" \
|
||||
"ld %%r6, %6 \n\t" \
|
||||
"addi %%r3, %%r3, -8 \n\t" \
|
||||
"addi %%r4, %%r4, -8 \n\t" \
|
||||
"addic %%r5, %%r5, 0 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldu %%r7, 8(%%r3) \n\t" \
|
||||
"mulld %%r8, %%r7, %%r6 \n\t" \
|
||||
"mulhdu %%r9, %%r7, %%r6 \n\t" \
|
||||
"adde %%r8, %%r8, %%r5 \n\t" \
|
||||
"ld %%r7, 8(%%r4) \n\t" \
|
||||
"addze %%r5, %%r9 \n\t" \
|
||||
"addc %%r8, %%r8, %%r7 \n\t" \
|
||||
"stdu %%r8, 8(%%r4) \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"addze %%r5, %%r5 \n\t" \
|
||||
"addi %%r4, %%r4, 8 \n\t" \
|
||||
"addi %%r3, %%r3, 8 \n\t" \
|
||||
"std %%r5, %0 \n\t" \
|
||||
"std %%r4, %1 \n\t" \
|
||||
"std %%r3, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
||||
);
|
||||
|
||||
#endif /* __MACH__ && __APPLE__ */
|
||||
|
||||
#elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
|
||||
|
||||
#if defined(__MACH__) && defined(__APPLE__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"lwz r3, %3 \n\t" \
|
||||
"lwz r4, %4 \n\t" \
|
||||
"lwz r5, %5 \n\t" \
|
||||
"lwz r6, %6 \n\t" \
|
||||
"addi r3, r3, -4 \n\t" \
|
||||
"addi r4, r4, -4 \n\t" \
|
||||
"addic r5, r5, 0 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"lwzu r7, 4(r3) \n\t" \
|
||||
"mullw r8, r7, r6 \n\t" \
|
||||
"mulhwu r9, r7, r6 \n\t" \
|
||||
"adde r8, r8, r5 \n\t" \
|
||||
"lwz r7, 4(r4) \n\t" \
|
||||
"addze r5, r9 \n\t" \
|
||||
"addc r8, r8, r7 \n\t" \
|
||||
"stwu r8, 4(r4) \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"addze r5, r5 \n\t" \
|
||||
"addi r4, r4, 4 \n\t" \
|
||||
"addi r3, r3, 4 \n\t" \
|
||||
"stw r5, %0 \n\t" \
|
||||
"stw r4, %1 \n\t" \
|
||||
"stw r3, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
||||
);
|
||||
|
||||
#else /* __MACH__ && __APPLE__ */
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"lwz %%r3, %3 \n\t" \
|
||||
"lwz %%r4, %4 \n\t" \
|
||||
"lwz %%r5, %5 \n\t" \
|
||||
"lwz %%r6, %6 \n\t" \
|
||||
"addi %%r3, %%r3, -4 \n\t" \
|
||||
"addi %%r4, %%r4, -4 \n\t" \
|
||||
"addic %%r5, %%r5, 0 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"lwzu %%r7, 4(%%r3) \n\t" \
|
||||
"mullw %%r8, %%r7, %%r6 \n\t" \
|
||||
"mulhwu %%r9, %%r7, %%r6 \n\t" \
|
||||
"adde %%r8, %%r8, %%r5 \n\t" \
|
||||
"lwz %%r7, 4(%%r4) \n\t" \
|
||||
"addze %%r5, %%r9 \n\t" \
|
||||
"addc %%r8, %%r8, %%r7 \n\t" \
|
||||
"stwu %%r8, 4(%%r4) \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"addze %%r5, %%r5 \n\t" \
|
||||
"addi %%r4, %%r4, 4 \n\t" \
|
||||
"addi %%r3, %%r3, 4 \n\t" \
|
||||
"stw %%r5, %0 \n\t" \
|
||||
"stw %%r4, %1 \n\t" \
|
||||
"stw %%r3, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
||||
);
|
||||
|
||||
#endif /* __MACH__ && __APPLE__ */
|
||||
|
||||
#endif /* PPC32 */
|
||||
|
||||
/*
|
||||
* The Sparc(64) assembly is reported to be broken.
|
||||
* Disable it for now, until we're able to fix it.
|
||||
*/
|
||||
#if 0 && defined(__sparc__)
|
||||
#if defined(__sparc64__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ldx %3, %%o0 \n\t" \
|
||||
"ldx %4, %%o1 \n\t" \
|
||||
"ld %5, %%o2 \n\t" \
|
||||
"ld %6, %%o3 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ld [%%o0], %%o4 \n\t" \
|
||||
"inc 4, %%o0 \n\t" \
|
||||
"ld [%%o1], %%o5 \n\t" \
|
||||
"umul %%o3, %%o4, %%o4 \n\t" \
|
||||
"addcc %%o4, %%o2, %%o4 \n\t" \
|
||||
"rd %%y, %%g1 \n\t" \
|
||||
"addx %%g1, 0, %%g1 \n\t" \
|
||||
"addcc %%o4, %%o5, %%o4 \n\t" \
|
||||
"st %%o4, [%%o1] \n\t" \
|
||||
"addx %%g1, 0, %%o2 \n\t" \
|
||||
"inc 4, %%o1 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"st %%o2, %0 \n\t" \
|
||||
"stx %%o1, %1 \n\t" \
|
||||
"stx %%o0, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "g1", "o0", "o1", "o2", "o3", "o4", \
|
||||
"o5" \
|
||||
);
|
||||
|
||||
#else /* __sparc64__ */
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ld %3, %%o0 \n\t" \
|
||||
"ld %4, %%o1 \n\t" \
|
||||
"ld %5, %%o2 \n\t" \
|
||||
"ld %6, %%o3 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ld [%%o0], %%o4 \n\t" \
|
||||
"inc 4, %%o0 \n\t" \
|
||||
"ld [%%o1], %%o5 \n\t" \
|
||||
"umul %%o3, %%o4, %%o4 \n\t" \
|
||||
"addcc %%o4, %%o2, %%o4 \n\t" \
|
||||
"rd %%y, %%g1 \n\t" \
|
||||
"addx %%g1, 0, %%g1 \n\t" \
|
||||
"addcc %%o4, %%o5, %%o4 \n\t" \
|
||||
"st %%o4, [%%o1] \n\t" \
|
||||
"addx %%g1, 0, %%o2 \n\t" \
|
||||
"inc 4, %%o1 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"st %%o2, %0 \n\t" \
|
||||
"st %%o1, %1 \n\t" \
|
||||
"st %%o0, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "g1", "o0", "o1", "o2", "o3", "o4", \
|
||||
"o5" \
|
||||
);
|
||||
|
||||
#endif /* __sparc64__ */
|
||||
#endif /* __sparc__ */
|
||||
|
||||
#if defined(__microblaze__) || defined(microblaze)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"lwi r3, %3 \n\t" \
|
||||
"lwi r4, %4 \n\t" \
|
||||
"lwi r5, %5 \n\t" \
|
||||
"lwi r6, %6 \n\t" \
|
||||
"andi r7, r6, 0xffff \n\t" \
|
||||
"bsrli r6, r6, 16 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"lhui r8, r3, 0 \n\t" \
|
||||
"addi r3, r3, 2 \n\t" \
|
||||
"lhui r9, r3, 0 \n\t" \
|
||||
"addi r3, r3, 2 \n\t" \
|
||||
"mul r10, r9, r6 \n\t" \
|
||||
"mul r11, r8, r7 \n\t" \
|
||||
"mul r12, r9, r7 \n\t" \
|
||||
"mul r13, r8, r6 \n\t" \
|
||||
"bsrli r8, r10, 16 \n\t" \
|
||||
"bsrli r9, r11, 16 \n\t" \
|
||||
"add r13, r13, r8 \n\t" \
|
||||
"add r13, r13, r9 \n\t" \
|
||||
"bslli r10, r10, 16 \n\t" \
|
||||
"bslli r11, r11, 16 \n\t" \
|
||||
"add r12, r12, r10 \n\t" \
|
||||
"addc r13, r13, r0 \n\t" \
|
||||
"add r12, r12, r11 \n\t" \
|
||||
"addc r13, r13, r0 \n\t" \
|
||||
"lwi r10, r4, 0 \n\t" \
|
||||
"add r12, r12, r10 \n\t" \
|
||||
"addc r13, r13, r0 \n\t" \
|
||||
"add r12, r12, r5 \n\t" \
|
||||
"addc r5, r13, r0 \n\t" \
|
||||
"swi r12, r4, 0 \n\t" \
|
||||
"addi r4, r4, 4 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"swi r5, %0 \n\t" \
|
||||
"swi r4, %1 \n\t" \
|
||||
"swi r3, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r3", "r4", "r5", "r6", "r7", "r8", \
|
||||
"r9", "r10", "r11", "r12", "r13" \
|
||||
);
|
||||
|
||||
#endif /* MicroBlaze */
|
||||
|
||||
#if defined(__tricore__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ld.a %%a2, %3 \n\t" \
|
||||
"ld.a %%a3, %4 \n\t" \
|
||||
"ld.w %%d4, %5 \n\t" \
|
||||
"ld.w %%d1, %6 \n\t" \
|
||||
"xor %%d5, %%d5 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ld.w %%d0, [%%a2+] \n\t" \
|
||||
"madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
|
||||
"ld.w %%d0, [%%a3] \n\t" \
|
||||
"addx %%d2, %%d2, %%d0 \n\t" \
|
||||
"addc %%d3, %%d3, 0 \n\t" \
|
||||
"mov %%d4, %%d3 \n\t" \
|
||||
"st.w [%%a3+], %%d2 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"st.w %0, %%d4 \n\t" \
|
||||
"st.a %1, %%a3 \n\t" \
|
||||
"st.a %2, %%a2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "d0", "d1", "e2", "d4", "a2", "a3" \
|
||||
);
|
||||
|
||||
#endif /* TriCore */
|
||||
|
||||
/*
|
||||
* Note, gcc -O0 by default uses r7 for the frame pointer, so it complains about
|
||||
* our use of r7 below, unless -fomit-frame-pointer is passed.
|
||||
*
|
||||
* On the other hand, -fomit-frame-pointer is implied by any -Ox options with
|
||||
* x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
|
||||
* clang and armcc5 under the same conditions).
|
||||
*
|
||||
* So, only use the optimized assembly below for optimized build, which avoids
|
||||
* the build error and is pretty reasonable anyway.
|
||||
*/
|
||||
#if defined(__GNUC__) && !defined(__OPTIMIZE__)
|
||||
#define MULADDC_CANNOT_USE_R7
|
||||
#endif
|
||||
|
||||
#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
|
||||
|
||||
#if defined(__thumb__) && !defined(__thumb2__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ldr r0, %3 \n\t" \
|
||||
"ldr r1, %4 \n\t" \
|
||||
"ldr r2, %5 \n\t" \
|
||||
"ldr r3, %6 \n\t" \
|
||||
"lsr r7, r3, #16 \n\t" \
|
||||
"mov r9, r7 \n\t" \
|
||||
"lsl r7, r3, #16 \n\t" \
|
||||
"lsr r7, r7, #16 \n\t" \
|
||||
"mov r8, r7 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldmia r0!, {r6} \n\t" \
|
||||
"lsr r7, r6, #16 \n\t" \
|
||||
"lsl r6, r6, #16 \n\t" \
|
||||
"lsr r6, r6, #16 \n\t" \
|
||||
"mov r4, r8 \n\t" \
|
||||
"mul r4, r6 \n\t" \
|
||||
"mov r3, r9 \n\t" \
|
||||
"mul r6, r3 \n\t" \
|
||||
"mov r5, r9 \n\t" \
|
||||
"mul r5, r7 \n\t" \
|
||||
"mov r3, r8 \n\t" \
|
||||
"mul r7, r3 \n\t" \
|
||||
"lsr r3, r6, #16 \n\t" \
|
||||
"add r5, r5, r3 \n\t" \
|
||||
"lsr r3, r7, #16 \n\t" \
|
||||
"add r5, r5, r3 \n\t" \
|
||||
"add r4, r4, r2 \n\t" \
|
||||
"mov r2, #0 \n\t" \
|
||||
"adc r5, r2 \n\t" \
|
||||
"lsl r3, r6, #16 \n\t" \
|
||||
"add r4, r4, r3 \n\t" \
|
||||
"adc r5, r2 \n\t" \
|
||||
"lsl r3, r7, #16 \n\t" \
|
||||
"add r4, r4, r3 \n\t" \
|
||||
"adc r5, r2 \n\t" \
|
||||
"ldr r3, [r1] \n\t" \
|
||||
"add r4, r4, r3 \n\t" \
|
||||
"adc r2, r5 \n\t" \
|
||||
"stmia r1!, {r4} \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"str r2, %0 \n\t" \
|
||||
"str r1, %1 \n\t" \
|
||||
"str r0, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r0", "r1", "r2", "r3", "r4", "r5", \
|
||||
"r6", "r7", "r8", "r9", "cc" \
|
||||
);
|
||||
|
||||
#elif (__ARM_ARCH >= 6) && \
|
||||
defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm(
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldr r0, [%0], #4 \n\t" \
|
||||
"ldr r1, [%1] \n\t" \
|
||||
"umaal r1, %2, %3, r0 \n\t" \
|
||||
"str r1, [%1], #4 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
: "=r" (s), "=r" (d), "=r" (c) \
|
||||
: "r" (b), "0" (s), "1" (d), "2" (c) \
|
||||
: "r0", "r1", "memory" \
|
||||
);
|
||||
|
||||
#else
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ldr r0, %3 \n\t" \
|
||||
"ldr r1, %4 \n\t" \
|
||||
"ldr r2, %5 \n\t" \
|
||||
"ldr r3, %6 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldr r4, [r0], #4 \n\t" \
|
||||
"mov r5, #0 \n\t" \
|
||||
"ldr r6, [r1] \n\t" \
|
||||
"umlal r2, r5, r3, r4 \n\t" \
|
||||
"adds r7, r6, r2 \n\t" \
|
||||
"adc r2, r5, #0 \n\t" \
|
||||
"str r7, [r1], #4 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"str r2, %0 \n\t" \
|
||||
"str r1, %1 \n\t" \
|
||||
"str r0, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "r0", "r1", "r2", "r3", "r4", "r5", \
|
||||
"r6", "r7", "cc" \
|
||||
);
|
||||
|
||||
#endif /* Thumb */
|
||||
|
||||
#endif /* ARMv3 */
|
||||
|
||||
#if defined(__alpha__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"ldq $1, %3 \n\t" \
|
||||
"ldq $2, %4 \n\t" \
|
||||
"ldq $3, %5 \n\t" \
|
||||
"ldq $4, %6 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"ldq $6, 0($1) \n\t" \
|
||||
"addq $1, 8, $1 \n\t" \
|
||||
"mulq $6, $4, $7 \n\t" \
|
||||
"umulh $6, $4, $6 \n\t" \
|
||||
"addq $7, $3, $7 \n\t" \
|
||||
"cmpult $7, $3, $3 \n\t" \
|
||||
"ldq $5, 0($2) \n\t" \
|
||||
"addq $7, $5, $7 \n\t" \
|
||||
"cmpult $7, $5, $5 \n\t" \
|
||||
"stq $7, 0($2) \n\t" \
|
||||
"addq $2, 8, $2 \n\t" \
|
||||
"addq $6, $3, $3 \n\t" \
|
||||
"addq $5, $3, $3 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"stq $3, %0 \n\t" \
|
||||
"stq $2, %1 \n\t" \
|
||||
"stq $1, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
|
||||
);
|
||||
#endif /* Alpha */
|
||||
|
||||
#if defined(__mips__) && !defined(__mips64)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
"lw $10, %3 \n\t" \
|
||||
"lw $11, %4 \n\t" \
|
||||
"lw $12, %5 \n\t" \
|
||||
"lw $13, %6 \n\t"
|
||||
|
||||
#define MULADDC_CORE \
|
||||
"lw $14, 0($10) \n\t" \
|
||||
"multu $13, $14 \n\t" \
|
||||
"addi $10, $10, 4 \n\t" \
|
||||
"mflo $14 \n\t" \
|
||||
"mfhi $9 \n\t" \
|
||||
"addu $14, $12, $14 \n\t" \
|
||||
"lw $15, 0($11) \n\t" \
|
||||
"sltu $12, $14, $12 \n\t" \
|
||||
"addu $15, $14, $15 \n\t" \
|
||||
"sltu $14, $15, $14 \n\t" \
|
||||
"addu $12, $12, $9 \n\t" \
|
||||
"sw $15, 0($11) \n\t" \
|
||||
"addu $12, $12, $14 \n\t" \
|
||||
"addi $11, $11, 4 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
"sw $12, %0 \n\t" \
|
||||
"sw $11, %1 \n\t" \
|
||||
"sw $10, %2 \n\t" \
|
||||
: "=m" (c), "=m" (d), "=m" (s) \
|
||||
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
||||
: "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \
|
||||
);
|
||||
|
||||
#endif /* MIPS */
|
||||
#endif /* GNUC */
|
||||
|
||||
#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
__asm mov esi, s \
|
||||
__asm mov edi, d \
|
||||
__asm mov ecx, c \
|
||||
__asm mov ebx, b
|
||||
|
||||
#define MULADDC_CORE \
|
||||
__asm lodsd \
|
||||
__asm mul ebx \
|
||||
__asm add eax, ecx \
|
||||
__asm adc edx, 0 \
|
||||
__asm add eax, [edi] \
|
||||
__asm adc edx, 0 \
|
||||
__asm mov ecx, edx \
|
||||
__asm stosd
|
||||
|
||||
#if defined(MBEDTLS_HAVE_SSE2)
|
||||
|
||||
#define EMIT __asm _emit
|
||||
|
||||
#define MULADDC_HUIT \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x1F \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x16 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x0F \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
|
||||
EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
|
||||
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
|
||||
EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
|
||||
EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
||||
EMIT 0x0F EMIT 0x7E EMIT 0xC9
|
||||
|
||||
#define MULADDC_STOP \
|
||||
EMIT 0x0F EMIT 0x77 \
|
||||
__asm mov c, ecx \
|
||||
__asm mov d, edi \
|
||||
__asm mov s, esi \
|
||||
|
||||
#else
|
||||
|
||||
#define MULADDC_STOP \
|
||||
__asm mov c, ecx \
|
||||
__asm mov d, edi \
|
||||
__asm mov s, esi \
|
||||
|
||||
#endif /* SSE2 */
|
||||
#endif /* MSVC */
|
||||
|
||||
#endif /* MBEDTLS_HAVE_ASM */
|
||||
|
||||
#if !defined(MULADDC_CORE)
|
||||
#if defined(MBEDTLS_HAVE_UDBL)
|
||||
|
||||
#define MULADDC_INIT \
|
||||
{ \
|
||||
mbedtls_t_udbl r; \
|
||||
mbedtls_mpi_uint r0, r1;
|
||||
|
||||
#define MULADDC_CORE \
|
||||
r = *(s++) * (mbedtls_t_udbl) b; \
|
||||
r0 = (mbedtls_mpi_uint) r; \
|
||||
r1 = (mbedtls_mpi_uint)( r >> biL ); \
|
||||
r0 += c; r1 += (r0 < c); \
|
||||
r0 += *d; r1 += (r0 < *d); \
|
||||
c = r1; *(d++) = r0;
|
||||
|
||||
#define MULADDC_STOP \
|
||||
}
|
||||
|
||||
#else
|
||||
#define MULADDC_INIT \
|
||||
{ \
|
||||
mbedtls_mpi_uint s0, s1, b0, b1; \
|
||||
mbedtls_mpi_uint r0, r1, rx, ry; \
|
||||
b0 = ( b << biH ) >> biH; \
|
||||
b1 = ( b >> biH );
|
||||
|
||||
#define MULADDC_CORE \
|
||||
s0 = ( *s << biH ) >> biH; \
|
||||
s1 = ( *s >> biH ); s++; \
|
||||
rx = s0 * b1; r0 = s0 * b0; \
|
||||
ry = s1 * b0; r1 = s1 * b1; \
|
||||
r1 += ( rx >> biH ); \
|
||||
r1 += ( ry >> biH ); \
|
||||
rx <<= biH; ry <<= biH; \
|
||||
r0 += rx; r1 += (r0 < rx); \
|
||||
r0 += ry; r1 += (r0 < ry); \
|
||||
r0 += c; r1 += (r0 < c); \
|
||||
r0 += *d; r1 += (r0 < *d); \
|
||||
c = r1; *(d++) = r0;
|
||||
|
||||
#define MULADDC_STOP \
|
||||
}
|
||||
|
||||
#endif /* C (generic) */
|
||||
#endif /* C (longlong) */
|
||||
|
||||
#endif /* bn_mul.h */
|
1746
library/certs.c
1746
library/certs.c
File diff suppressed because it is too large
Load diff
|
@ -26,7 +26,7 @@
|
|||
#if defined(MBEDTLS_CIPHER_C)
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/cipher_internal.h"
|
||||
#include "cipher_wrap.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -328,7 +328,7 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
|
|||
case PSA_ERROR_NOT_SUPPORTED:
|
||||
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
default:
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
}
|
||||
/* Indicate that we own the key slot and need to
|
||||
* destroy it in mbedtls_cipher_free(). */
|
||||
|
@ -1244,23 +1244,23 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
|||
* are terminated by unsuccessful calls to psa_cipher_update(),
|
||||
* and by any call to psa_cipher_finish(). */
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
status = psa_cipher_set_iv( &cipher_op, iv, iv_len );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
status = psa_cipher_update( &cipher_op,
|
||||
input, ilen,
|
||||
output, ilen, olen );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
status = psa_cipher_finish( &cipher_op,
|
||||
output + *olen, ilen - *olen,
|
||||
&part_len );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
*olen += part_len;
|
||||
return( 0 );
|
||||
|
@ -1323,7 +1323,7 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx,
|
|||
input, ilen,
|
||||
output, ilen + tag_len, olen );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
*olen -= tag_len;
|
||||
return( 0 );
|
||||
|
@ -1405,7 +1405,7 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx,
|
|||
if( status == PSA_ERROR_INVALID_SIGNATURE )
|
||||
return( MBEDTLS_ERR_CIPHER_AUTH_FAILED );
|
||||
else if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
|
||||
#include "mbedtls/cipher_internal.h"
|
||||
#include "cipher_wrap.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C)
|
||||
|
|
150
library/cipher_wrap.h
Normal file
150
library/cipher_wrap.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
/**
|
||||
* \file cipher_wrap.h
|
||||
*
|
||||
* \brief Cipher wrappers.
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_CIPHER_WRAP_H
|
||||
#define MBEDTLS_CIPHER_WRAP_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Base cipher information. The non-mode specific functions and values.
|
||||
*/
|
||||
struct mbedtls_cipher_base_t
|
||||
{
|
||||
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
|
||||
mbedtls_cipher_id_t cipher;
|
||||
|
||||
/** Encrypt using ECB */
|
||||
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
|
||||
const unsigned char *input, unsigned char *output );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/** Encrypt using CBC */
|
||||
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
||||
unsigned char *iv, const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
/** Encrypt using CFB (Full length) */
|
||||
int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
|
||||
unsigned char *iv, const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
||||
/** Encrypt using OFB (Full length) */
|
||||
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
|
||||
unsigned char *iv,
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/** Encrypt using CTR */
|
||||
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
|
||||
unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
const unsigned char *input, unsigned char *output );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
/** Encrypt or decrypt using XTS. */
|
||||
int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
||||
const unsigned char data_unit[16],
|
||||
const unsigned char *input, unsigned char *output );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
||||
/** Encrypt using STREAM */
|
||||
int (*stream_func)( void *ctx, size_t length,
|
||||
const unsigned char *input, unsigned char *output );
|
||||
#endif
|
||||
|
||||
/** Set key for encryption purposes */
|
||||
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen );
|
||||
|
||||
/** Set key for decryption purposes */
|
||||
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen);
|
||||
|
||||
/** Allocate a new context */
|
||||
void * (*ctx_alloc_func)( void );
|
||||
|
||||
/** Free the given context */
|
||||
void (*ctx_free_func)( void *ctx );
|
||||
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_cipher_type_t type;
|
||||
const mbedtls_cipher_info_t *info;
|
||||
} mbedtls_cipher_definition_t;
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
|
||||
MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
|
||||
/* use raw key material internally imported */
|
||||
/* as a volatile key, and which hence need */
|
||||
/* to destroy that key when the context is */
|
||||
/* freed. */
|
||||
MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
|
||||
/* which use a key provided by the */
|
||||
/* user, and which hence will not be */
|
||||
/* destroyed when the context is freed. */
|
||||
} mbedtls_cipher_psa_key_ownership;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
psa_algorithm_t alg;
|
||||
psa_key_id_t slot;
|
||||
mbedtls_cipher_psa_key_ownership slot_state;
|
||||
} mbedtls_cipher_context_psa;
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
|
||||
|
||||
extern int mbedtls_cipher_supported[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_CIPHER_WRAP_H */
|
|
@ -99,7 +99,7 @@
|
|||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ecp_internal.h"
|
||||
#include "ecp_alt.h"
|
||||
|
||||
#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
|
||||
#if defined(MBEDTLS_HMAC_DRBG_C)
|
||||
|
|
297
library/ecp_alt.h
Normal file
297
library/ecp_alt.h
Normal file
|
@ -0,0 +1,297 @@
|
|||
/**
|
||||
* \file ecp_alt.h
|
||||
*
|
||||
* \brief Function declarations for alternative implementation of elliptic curve
|
||||
* point arithmetic.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* References:
|
||||
*
|
||||
* [1] BERNSTEIN, Daniel J. Curve25519: new Diffie-Hellman speed records.
|
||||
* <http://cr.yp.to/ecdh/curve25519-20060209.pdf>
|
||||
*
|
||||
* [2] CORON, Jean-S'ebastien. Resistance against differential power analysis
|
||||
* for elliptic curve cryptosystems. In : Cryptographic Hardware and
|
||||
* Embedded Systems. Springer Berlin Heidelberg, 1999. p. 292-302.
|
||||
* <http://link.springer.com/chapter/10.1007/3-540-48059-5_25>
|
||||
*
|
||||
* [3] HEDABOU, Mustapha, PINEL, Pierre, et B'EN'ETEAU, Lucien. A comb method to
|
||||
* render ECC resistant against Side Channel Attacks. IACR Cryptology
|
||||
* ePrint Archive, 2004, vol. 2004, p. 342.
|
||||
* <http://eprint.iacr.org/2004/342.pdf>
|
||||
*
|
||||
* [4] Certicom Research. SEC 2: Recommended Elliptic Curve Domain Parameters.
|
||||
* <http://www.secg.org/sec2-v2.pdf>
|
||||
*
|
||||
* [5] HANKERSON, Darrel, MENEZES, Alfred J., VANSTONE, Scott. Guide to Elliptic
|
||||
* Curve Cryptography.
|
||||
*
|
||||
* [6] Digital Signature Standard (DSS), FIPS 186-4.
|
||||
* <http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf>
|
||||
*
|
||||
* [7] Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer
|
||||
* Security (TLS), RFC 4492.
|
||||
* <https://tools.ietf.org/search/rfc4492>
|
||||
*
|
||||
* [8] <http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html>
|
||||
*
|
||||
* [9] COHEN, Henri. A Course in Computational Algebraic Number Theory.
|
||||
* Springer Science & Business Media, 1 Aug 2000
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_ECP_INTERNAL_H
|
||||
#define MBEDTLS_ECP_INTERNAL_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
|
||||
/**
|
||||
* \brief Indicate if the Elliptic Curve Point module extension can
|
||||
* handle the group.
|
||||
*
|
||||
* \param grp The pointer to the elliptic curve group that will be the
|
||||
* basis of the cryptographic computations.
|
||||
*
|
||||
* \return Non-zero if successful.
|
||||
*/
|
||||
unsigned char mbedtls_internal_ecp_grp_capable( const mbedtls_ecp_group *grp );
|
||||
|
||||
/**
|
||||
* \brief Initialise the Elliptic Curve Point module extension.
|
||||
*
|
||||
* If mbedtls_internal_ecp_grp_capable returns true for a
|
||||
* group, this function has to be able to initialise the
|
||||
* module for it.
|
||||
*
|
||||
* This module can be a driver to a crypto hardware
|
||||
* accelerator, for which this could be an initialise function.
|
||||
*
|
||||
* \param grp The pointer to the group the module needs to be
|
||||
* initialised for.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
*/
|
||||
int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp );
|
||||
|
||||
/**
|
||||
* \brief Frees and deallocates the Elliptic Curve Point module
|
||||
* extension.
|
||||
*
|
||||
* \param grp The pointer to the group the module was initialised for.
|
||||
*/
|
||||
void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp );
|
||||
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
|
||||
/**
|
||||
* \brief Randomize jacobian coordinates:
|
||||
* (X, Y, Z) -> (l^2 X, l^3 Y, l Z) for random l.
|
||||
*
|
||||
* \param grp Pointer to the group representing the curve.
|
||||
*
|
||||
* \param pt The point on the curve to be randomised, given with Jacobian
|
||||
* coordinates.
|
||||
*
|
||||
* \param f_rng A function pointer to the random number generator.
|
||||
*
|
||||
* \param p_rng A pointer to the random number generator state.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
*/
|
||||
int mbedtls_internal_ecp_randomize_jac( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *pt, int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
|
||||
/**
|
||||
* \brief Addition: R = P + Q, mixed affine-Jacobian coordinates.
|
||||
*
|
||||
* The coordinates of Q must be normalized (= affine),
|
||||
* but those of P don't need to. R is not normalized.
|
||||
*
|
||||
* This function is used only as a subrutine of
|
||||
* ecp_mul_comb().
|
||||
*
|
||||
* Special cases: (1) P or Q is zero, (2) R is zero,
|
||||
* (3) P == Q.
|
||||
* None of these cases can happen as intermediate step in
|
||||
* ecp_mul_comb():
|
||||
* - at each step, P, Q and R are multiples of the base
|
||||
* point, the factor being less than its order, so none of
|
||||
* them is zero;
|
||||
* - Q is an odd multiple of the base point, P an even
|
||||
* multiple, due to the choice of precomputed points in the
|
||||
* modified comb method.
|
||||
* So branches for these cases do not leak secret information.
|
||||
*
|
||||
* We accept Q->Z being unset (saving memory in tables) as
|
||||
* meaning 1.
|
||||
*
|
||||
* Cost in field operations if done by [5] 3.22:
|
||||
* 1A := 8M + 3S
|
||||
*
|
||||
* \param grp Pointer to the group representing the curve.
|
||||
*
|
||||
* \param R Pointer to a point structure to hold the result.
|
||||
*
|
||||
* \param P Pointer to the first summand, given with Jacobian
|
||||
* coordinates
|
||||
*
|
||||
* \param Q Pointer to the second summand, given with affine
|
||||
* coordinates.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
*/
|
||||
int mbedtls_internal_ecp_add_mixed( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *R, const mbedtls_ecp_point *P,
|
||||
const mbedtls_ecp_point *Q );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Point doubling R = 2 P, Jacobian coordinates.
|
||||
*
|
||||
* Cost: 1D := 3M + 4S (A == 0)
|
||||
* 4M + 4S (A == -3)
|
||||
* 3M + 6S + 1a otherwise
|
||||
* when the implementation is based on the "dbl-1998-cmo-2"
|
||||
* doubling formulas in [8] and standard optimizations are
|
||||
* applied when curve parameter A is one of { 0, -3 }.
|
||||
*
|
||||
* \param grp Pointer to the group representing the curve.
|
||||
*
|
||||
* \param R Pointer to a point structure to hold the result.
|
||||
*
|
||||
* \param P Pointer to the point that has to be doubled, given with
|
||||
* Jacobian coordinates.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
|
||||
int mbedtls_internal_ecp_double_jac( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *R, const mbedtls_ecp_point *P );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Normalize jacobian coordinates of an array of (pointers to)
|
||||
* points.
|
||||
*
|
||||
* Using Montgomery's trick to perform only one inversion mod P
|
||||
* the cost is:
|
||||
* 1N(t) := 1I + (6t - 3)M + 1S
|
||||
* (See for example Algorithm 10.3.4. in [9])
|
||||
*
|
||||
* This function is used only as a subrutine of
|
||||
* ecp_mul_comb().
|
||||
*
|
||||
* Warning: fails (returning an error) if one of the points is
|
||||
* zero!
|
||||
* This should never happen, see choice of w in ecp_mul_comb().
|
||||
*
|
||||
* \param grp Pointer to the group representing the curve.
|
||||
*
|
||||
* \param T Array of pointers to the points to normalise.
|
||||
*
|
||||
* \param t_len Number of elements in the array.
|
||||
*
|
||||
* \return 0 if successful,
|
||||
* an error if one of the points is zero.
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
|
||||
int mbedtls_internal_ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *T[], size_t t_len );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Normalize jacobian coordinates so that Z == 0 || Z == 1.
|
||||
*
|
||||
* Cost in field operations if done by [5] 3.2.1:
|
||||
* 1N := 1I + 3M + 1S
|
||||
*
|
||||
* \param grp Pointer to the group representing the curve.
|
||||
*
|
||||
* \param pt pointer to the point to be normalised. This is an
|
||||
* input/output parameter.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
|
||||
int mbedtls_internal_ecp_normalize_jac( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *pt );
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
|
||||
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
|
||||
int mbedtls_internal_ecp_double_add_mxz( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *R, mbedtls_ecp_point *S, const mbedtls_ecp_point *P,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *d );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Randomize projective x/z coordinates:
|
||||
* (X, Z) -> (l X, l Z) for random l
|
||||
*
|
||||
* \param grp pointer to the group representing the curve
|
||||
*
|
||||
* \param P the point on the curve to be randomised given with
|
||||
* projective coordinates. This is an input/output parameter.
|
||||
*
|
||||
* \param f_rng a function pointer to the random number generator
|
||||
*
|
||||
* \param p_rng a pointer to the random number generator state
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
int mbedtls_internal_ecp_randomize_mxz( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Normalize Montgomery x/z coordinates: X = X/Z, Z = 1.
|
||||
*
|
||||
* \param grp pointer to the group representing the curve
|
||||
*
|
||||
* \param P pointer to the point to be normalised. This is an
|
||||
* input/output parameter.
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
|
||||
int mbedtls_internal_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *P );
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
|
||||
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
#endif /* ecp_alt.h */
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "entropy_poll.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -51,9 +51,6 @@
|
|||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
|
||||
#define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */
|
||||
|
||||
|
@ -72,9 +69,6 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
|
|||
#else
|
||||
mbedtls_sha256_init( &ctx->accumulator );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_havege_init( &ctx->havege_data );
|
||||
#endif
|
||||
|
||||
/* Reminder: Update ENTROPY_HAVE_STRONG in the test files
|
||||
* when adding more strong entropy sources here. */
|
||||
|
@ -95,11 +89,6 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
|
|||
MBEDTLS_ENTROPY_MIN_HARDCLOCK,
|
||||
MBEDTLS_ENTROPY_SOURCE_WEAK );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_entropy_add_source( ctx, mbedtls_havege_poll, &ctx->havege_data,
|
||||
MBEDTLS_ENTROPY_MIN_HAVEGE,
|
||||
MBEDTLS_ENTROPY_SOURCE_STRONG );
|
||||
#endif
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
mbedtls_entropy_add_source( ctx, mbedtls_hardware_poll, NULL,
|
||||
MBEDTLS_ENTROPY_MIN_HARDWARE,
|
||||
|
@ -121,9 +110,6 @@ void mbedtls_entropy_free( mbedtls_entropy_context *ctx )
|
|||
if( ctx->accumulator_started == -1 )
|
||||
return;
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_havege_free( &ctx->havege_data );
|
||||
#endif
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
mbedtls_mutex_free( &ctx->mutex );
|
||||
#endif
|
||||
|
|
|
@ -29,15 +29,12 @@
|
|||
#if defined(MBEDTLS_ENTROPY_C)
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "entropy_poll.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
#include "mbedtls/timing.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
@ -249,22 +246,6 @@ int mbedtls_hardclock_poll( void *data,
|
|||
}
|
||||
#endif /* MBEDTLS_TIMING_C */
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
int mbedtls_havege_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
{
|
||||
mbedtls_havege_state *hs = (mbedtls_havege_state *) data;
|
||||
*olen = 0;
|
||||
|
||||
if( mbedtls_havege_random( hs, output, len ) != 0 )
|
||||
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
|
||||
|
||||
*olen = len;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_HAVEGE_C */
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
int mbedtls_nv_seed_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
|
|
97
library/entropy_poll.h
Normal file
97
library/entropy_poll.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* \file entropy_poll.h
|
||||
*
|
||||
* \brief Platform-specific and custom entropy polling functions
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_ENTROPY_POLL_H
|
||||
#define MBEDTLS_ENTROPY_POLL_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Default thresholds for built-in sources, in bytes
|
||||
*/
|
||||
#define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */
|
||||
#define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */
|
||||
#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
|
||||
#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Entropy poll callback that provides 0 entropy.
|
||||
*/
|
||||
#if defined(MBEDTLS_TEST_NULL_ENTROPY)
|
||||
int mbedtls_null_entropy_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
||||
/**
|
||||
* \brief Platform-specific entropy poll callback
|
||||
*/
|
||||
int mbedtls_platform_entropy_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
/**
|
||||
* \brief mbedtls_timing_hardclock-based entropy poll callback
|
||||
*/
|
||||
int mbedtls_hardclock_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
/**
|
||||
* \brief Entropy poll callback for a hardware source
|
||||
*
|
||||
* \warning This is not provided by mbed TLS!
|
||||
* See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
|
||||
*
|
||||
* \note This must accept NULL as its first argument.
|
||||
*/
|
||||
int mbedtls_hardware_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
/**
|
||||
* \brief Entropy poll callback for a non-volatile seed file
|
||||
*
|
||||
* \note This must accept NULL as its first argument.
|
||||
*/
|
||||
int mbedtls_nv_seed_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* entropy_poll.h */
|
137
library/error.c
137
library/error.c
|
@ -38,10 +38,6 @@
|
|||
#include "mbedtls/aes.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#include "mbedtls/arc4.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
#include "mbedtls/aria.h"
|
||||
#endif
|
||||
|
@ -82,10 +78,6 @@
|
|||
#include "mbedtls/cipher.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
#include "mbedtls/cmac.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#endif
|
||||
|
@ -110,6 +102,10 @@
|
|||
#include "mbedtls/error.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
#include "mbedtls/gcm.h"
|
||||
#endif
|
||||
|
@ -126,18 +122,6 @@
|
|||
#include "mbedtls/md.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
#include "mbedtls/md2.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
#include "mbedtls/md4.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
#include "mbedtls/md5.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_NET_C)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#endif
|
||||
|
@ -146,10 +130,6 @@
|
|||
#include "mbedtls/oid.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
#include "mbedtls/padlock.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
@ -166,18 +146,10 @@
|
|||
#include "mbedtls/pkcs5.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_POLY1305_C)
|
||||
#include "mbedtls/poly1305.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
#include "mbedtls/rsa.h"
|
||||
#endif
|
||||
|
@ -239,8 +211,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "CIPHER - Authentication failed (for AEAD modes)" );
|
||||
case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
|
||||
return( "CIPHER - The context is invalid. For example, because it was freed" );
|
||||
case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED):
|
||||
return( "CIPHER - Cipher hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_CIPHER_C */
|
||||
|
||||
#if defined(MBEDTLS_DHM_C)
|
||||
|
@ -262,8 +232,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "DHM - Allocation of memory failed" );
|
||||
case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
|
||||
return( "DHM - Read or write of file failed" );
|
||||
case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED):
|
||||
return( "DHM - DHM hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
|
||||
return( "DHM - Setting the modulus and generator failed" );
|
||||
#endif /* MBEDTLS_DHM_C */
|
||||
|
@ -285,8 +253,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "ECP - Invalid private or public key" );
|
||||
case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
|
||||
return( "ECP - The buffer contains a valid signature followed by more data" );
|
||||
case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED):
|
||||
return( "ECP - The ECP hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
|
||||
return( "ECP - Operation in progress, call again with the same parameters to continue" );
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
@ -300,8 +266,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "MD - Failed to allocate memory" );
|
||||
case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
|
||||
return( "MD - Opening or reading of file failed" );
|
||||
case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED):
|
||||
return( "MD - MD hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
|
||||
|
@ -354,8 +318,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
|
||||
case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
|
||||
return( "PK - The buffer contains a valid signature followed by more data" );
|
||||
case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED):
|
||||
return( "PK - PK hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
|
||||
#if defined(MBEDTLS_PKCS12_C)
|
||||
|
@ -399,10 +361,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "RSA - The output buffer for decryption is not large enough" );
|
||||
case -(MBEDTLS_ERR_RSA_RNG_FAILED):
|
||||
return( "RSA - The random generator failed to generate non-zeros" );
|
||||
case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION):
|
||||
return( "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
|
||||
case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED):
|
||||
return( "RSA - RSA hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C)
|
||||
|
@ -470,8 +428,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "SSL - Hardware acceleration function returned with error" );
|
||||
case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
|
||||
return( "SSL - Hardware acceleration function skipped / left alone data" );
|
||||
case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
|
||||
return( "SSL - Processing of the compression / decompression failed" );
|
||||
case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
|
||||
return( "SSL - Handshake protocol not within min/max boundaries" );
|
||||
case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
|
||||
|
@ -595,26 +551,13 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "AES - Invalid data input length" );
|
||||
case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
|
||||
return( "AES - Invalid input data" );
|
||||
case -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE):
|
||||
return( "AES - Feature not available. For example, an unsupported AES key size" );
|
||||
case -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED):
|
||||
return( "AES - AES hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
case -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED):
|
||||
return( "ARC4 - ARC4 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
|
||||
return( "ARIA - Bad input data" );
|
||||
case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
|
||||
return( "ARIA - Invalid data input length" );
|
||||
case -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE):
|
||||
return( "ARIA - Feature not available. For example, an unsupported ARIA key size" );
|
||||
case -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED):
|
||||
return( "ARIA - ARIA hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_ARIA_C */
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
|
@ -665,8 +608,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "BLOWFISH - Bad input data" );
|
||||
case -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH):
|
||||
return( "BLOWFISH - Invalid data input length" );
|
||||
case -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED):
|
||||
return( "BLOWFISH - Blowfish hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_BLOWFISH_C */
|
||||
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
|
@ -674,8 +615,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "CAMELLIA - Bad input data" );
|
||||
case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
|
||||
return( "CAMELLIA - Invalid data input length" );
|
||||
case -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED):
|
||||
return( "CAMELLIA - Camellia hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_CAMELLIA_C */
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
|
@ -683,17 +622,11 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "CCM - Bad input parameters to the function" );
|
||||
case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
|
||||
return( "CCM - Authenticated decryption failed" );
|
||||
case -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED):
|
||||
return( "CCM - CCM hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
||||
#if defined(MBEDTLS_CHACHA20_C)
|
||||
case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
|
||||
return( "CHACHA20 - Invalid input parameter(s)" );
|
||||
case -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE):
|
||||
return( "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
|
||||
case -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED):
|
||||
return( "CHACHA20 - Chacha20 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_CHACHA20_C */
|
||||
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C)
|
||||
|
@ -703,11 +636,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
|
||||
#endif /* MBEDTLS_CHACHAPOLY_C */
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
case -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED):
|
||||
return( "CMAC - CMAC hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_CMAC_C */
|
||||
|
||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||
case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
|
||||
return( "CTR_DRBG - The entropy source failed" );
|
||||
|
@ -722,8 +650,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
#if defined(MBEDTLS_DES_C)
|
||||
case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
|
||||
return( "DES - The data input has an invalid length" );
|
||||
case -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED):
|
||||
return( "DES - DES hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_C)
|
||||
|
@ -746,11 +672,16 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "ERROR - This is a bug in the library" );
|
||||
#endif /* MBEDTLS_ERROR_C */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
|
||||
return( "PLATFORM - Hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
|
||||
return( "PLATFORM - The requested feature is not supported by the platform" );
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
|
||||
return( "GCM - Authenticated decryption failed" );
|
||||
case -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED):
|
||||
return( "GCM - GCM hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_GCM_BAD_INPUT):
|
||||
return( "GCM - Bad input parameters to function" );
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
|
@ -771,21 +702,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "HMAC_DRBG - The entropy source failed" );
|
||||
#endif /* MBEDTLS_HMAC_DRBG_C */
|
||||
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
case -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED):
|
||||
return( "MD2 - MD2 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
case -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED):
|
||||
return( "MD4 - MD4 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
case -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED):
|
||||
return( "MD5 - MD5 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
|
||||
#if defined(MBEDTLS_NET_C)
|
||||
case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
|
||||
return( "NET - Failed to open a socket" );
|
||||
|
@ -822,56 +738,27 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
return( "OID - output buffer is too small" );
|
||||
#endif /* MBEDTLS_OID_C */
|
||||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
case -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED):
|
||||
return( "PADLOCK - Input data should be aligned" );
|
||||
#endif /* MBEDTLS_PADLOCK_C */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
|
||||
return( "PLATFORM - Hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
|
||||
return( "PLATFORM - The requested feature is not supported by the platform" );
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#if defined(MBEDTLS_POLY1305_C)
|
||||
case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
|
||||
return( "POLY1305 - Invalid input parameter(s)" );
|
||||
case -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE):
|
||||
return( "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
|
||||
case -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED):
|
||||
return( "POLY1305 - Poly1305 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_POLY1305_C */
|
||||
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
case -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED):
|
||||
return( "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_RIPEMD160_C */
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
case -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED):
|
||||
return( "SHA1 - SHA-1 hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
|
||||
return( "SHA1 - SHA-1 input data was malformed" );
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
case -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED):
|
||||
return( "SHA256 - SHA-256 hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
|
||||
return( "SHA256 - SHA-256 input data was malformed" );
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
case -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED):
|
||||
return( "SHA512 - SHA-512 hardware accelerator failed" );
|
||||
case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
|
||||
return( "SHA512 - SHA-512 input data was malformed" );
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
case -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE):
|
||||
return( "THREADING - The selected feature is not available" );
|
||||
case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
|
||||
return( "THREADING - Bad input parameters to function" );
|
||||
case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
|
||||
|
@ -881,8 +768,6 @@ const char * mbedtls_low_level_strerr( int error_code )
|
|||
#if defined(MBEDTLS_XTEA_C)
|
||||
case -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH):
|
||||
return( "XTEA - The data input has an invalid length" );
|
||||
case -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED):
|
||||
return( "XTEA - XTEA hardware accelerator failed" );
|
||||
#endif /* MBEDTLS_XTEA_C */
|
||||
/* End Auto-Generated Code. */
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
|
|
237
library/havege.c
237
library/havege.c
|
@ -1,237 +0,0 @@
|
|||
/**
|
||||
* \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* The HAVEGE RNG was designed by Andre Seznec in 2002.
|
||||
*
|
||||
* http://www.irisa.fr/caps/projects/hipsor/publi.php
|
||||
*
|
||||
* Contact: seznec(at)irisa_dot_fr - orocheco(at)irisa_dot_fr
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
|
||||
#include "mbedtls/havege.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* On average, one iteration accesses two 8-word blocks in the havege WALK
|
||||
* table, and generates 16 words in the RES array.
|
||||
*
|
||||
* The data read in the WALK table is updated and permuted after each use.
|
||||
* The result of the hardware clock counter read is used for this update.
|
||||
*
|
||||
* 25 conditional tests are present. The conditional tests are grouped in
|
||||
* two nested groups of 12 conditional tests and 1 test that controls the
|
||||
* permutation; on average, there should be 6 tests executed and 3 of them
|
||||
* should be mispredicted.
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SWAP(X,Y) { uint32_t *T = (X); (X) = (Y); (Y) = T; }
|
||||
|
||||
#define TST1_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
|
||||
#define TST2_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
|
||||
|
||||
#define TST1_LEAVE U1++; }
|
||||
#define TST2_LEAVE U2++; }
|
||||
|
||||
#define ONE_ITERATION \
|
||||
\
|
||||
PTEST = PT1 >> 20; \
|
||||
\
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
\
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
\
|
||||
PTX = (PT1 >> 18) & 7; \
|
||||
PT1 &= 0x1FFF; \
|
||||
PT2 &= 0x1FFF; \
|
||||
CLK = (uint32_t) mbedtls_timing_hardclock(); \
|
||||
\
|
||||
i = 0; \
|
||||
A = &WALK[PT1 ]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 1]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 4]; RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> (1)) ^ (*A << (31)) ^ CLK; \
|
||||
*A = (*B >> (2)) ^ (*B << (30)) ^ CLK; \
|
||||
*B = IN ^ U1; \
|
||||
*C = (*C >> (3)) ^ (*C << (29)) ^ CLK; \
|
||||
*D = (*D >> (4)) ^ (*D << (28)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 2]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ^ 2]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 3]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 6]; RES[i++] ^= *D; \
|
||||
\
|
||||
if( PTEST & 1 ) SWAP( A, C ); \
|
||||
\
|
||||
IN = (*A >> (5)) ^ (*A << (27)) ^ CLK; \
|
||||
*A = (*B >> (6)) ^ (*B << (26)) ^ CLK; \
|
||||
*B = IN; CLK = (uint32_t) mbedtls_timing_hardclock(); \
|
||||
*C = (*C >> (7)) ^ (*C << (25)) ^ CLK; \
|
||||
*D = (*D >> (8)) ^ (*D << (24)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 4]; \
|
||||
B = &WALK[PT2 ^ 1]; \
|
||||
\
|
||||
PTEST = PT2 >> 1; \
|
||||
\
|
||||
PT2 = (RES[(i - 8) ^ PTY] ^ WALK[PT2 ^ PTY ^ 7]); \
|
||||
PT2 = ((PT2 & 0x1FFF) & (~8)) ^ ((PT1 ^ 8) & 0x8); \
|
||||
PTY = (PT2 >> 10) & 7; \
|
||||
\
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
\
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
\
|
||||
C = &WALK[PT1 ^ 5]; \
|
||||
D = &WALK[PT2 ^ 5]; \
|
||||
\
|
||||
RES[i++] ^= *A; \
|
||||
RES[i++] ^= *B; \
|
||||
RES[i++] ^= *C; \
|
||||
RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> ( 9)) ^ (*A << (23)) ^ CLK; \
|
||||
*A = (*B >> (10)) ^ (*B << (22)) ^ CLK; \
|
||||
*B = IN ^ U2; \
|
||||
*C = (*C >> (11)) ^ (*C << (21)) ^ CLK; \
|
||||
*D = (*D >> (12)) ^ (*D << (20)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 6]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ^ 3]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 7]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 7]; RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> (13)) ^ (*A << (19)) ^ CLK; \
|
||||
*A = (*B >> (14)) ^ (*B << (18)) ^ CLK; \
|
||||
*B = IN; \
|
||||
*C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \
|
||||
*D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \
|
||||
\
|
||||
PT1 = ( RES[( i - 8 ) ^ PTX] ^ \
|
||||
WALK[PT1 ^ PTX ^ 7] ) & (~1); \
|
||||
PT1 ^= (PT2 ^ 0x10) & 0x10; \
|
||||
\
|
||||
for( n++, i = 0; i < 16; i++ ) \
|
||||
hs->pool[n % MBEDTLS_HAVEGE_COLLECT_SIZE] ^= RES[i];
|
||||
|
||||
/*
|
||||
* Entropy gathering function
|
||||
*/
|
||||
static void havege_fill( mbedtls_havege_state *hs )
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t i;
|
||||
uint32_t U1, U2, *A, *B, *C, *D;
|
||||
uint32_t PT1, PT2, *WALK, RES[16];
|
||||
uint32_t PTX, PTY, CLK, PTEST, IN;
|
||||
|
||||
WALK = hs->WALK;
|
||||
PT1 = hs->PT1;
|
||||
PT2 = hs->PT2;
|
||||
|
||||
PTX = U1 = 0;
|
||||
PTY = U2 = 0;
|
||||
|
||||
(void)PTX;
|
||||
|
||||
memset( RES, 0, sizeof( RES ) );
|
||||
|
||||
while( n < MBEDTLS_HAVEGE_COLLECT_SIZE * 4 )
|
||||
{
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
}
|
||||
|
||||
hs->PT1 = PT1;
|
||||
hs->PT2 = PT2;
|
||||
|
||||
hs->offset[0] = 0;
|
||||
hs->offset[1] = MBEDTLS_HAVEGE_COLLECT_SIZE / 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* HAVEGE initialization
|
||||
*/
|
||||
void mbedtls_havege_init( mbedtls_havege_state *hs )
|
||||
{
|
||||
memset( hs, 0, sizeof( mbedtls_havege_state ) );
|
||||
|
||||
havege_fill( hs );
|
||||
}
|
||||
|
||||
void mbedtls_havege_free( mbedtls_havege_state *hs )
|
||||
{
|
||||
if( hs == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_platform_zeroize( hs, sizeof( mbedtls_havege_state ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* HAVEGE rand function
|
||||
*/
|
||||
int mbedtls_havege_random( void *p_rng, unsigned char *buf, size_t len )
|
||||
{
|
||||
uint32_t val;
|
||||
size_t use_len;
|
||||
mbedtls_havege_state *hs = (mbedtls_havege_state *) p_rng;
|
||||
unsigned char *p = buf;
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
use_len = len;
|
||||
if( use_len > sizeof( val ) )
|
||||
use_len = sizeof( val );
|
||||
|
||||
if( hs->offset[1] >= MBEDTLS_HAVEGE_COLLECT_SIZE )
|
||||
havege_fill( hs );
|
||||
|
||||
val = hs->pool[hs->offset[0]++];
|
||||
val ^= hs->pool[hs->offset[1]++];
|
||||
|
||||
memcpy( p, &val, use_len );
|
||||
|
||||
len -= use_len;
|
||||
p += use_len;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_HAVEGE_C */
|
|
@ -26,7 +26,7 @@
|
|||
#if defined(MBEDTLS_MD_C)
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "md_wrap.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -390,13 +390,6 @@ int mbedtls_md_clone( mbedtls_md_context_t *dst,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info )
|
||||
{
|
||||
return mbedtls_md_setup( ctx, md_info, 1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ALLOC( type ) \
|
||||
do { \
|
||||
ctx->md_ctx = mbedtls_calloc( 1, sizeof( mbedtls_##type##_context ) ); \
|
||||
|
|
|
@ -106,13 +106,6 @@ int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md2_starts( mbedtls_md2_context *ctx )
|
||||
{
|
||||
mbedtls_md2_starts_ret( ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD2_PROCESS_ALT)
|
||||
int mbedtls_internal_md2_process( mbedtls_md2_context *ctx )
|
||||
{
|
||||
|
@ -153,12 +146,6 @@ int mbedtls_internal_md2_process( mbedtls_md2_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md2_process( mbedtls_md2_context *ctx )
|
||||
{
|
||||
mbedtls_internal_md2_process( ctx );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_MD2_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -195,15 +182,6 @@ int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md2_update( mbedtls_md2_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_md2_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD2 final digest
|
||||
*/
|
||||
|
@ -231,14 +209,6 @@ int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md2_finish( mbedtls_md2_context *ctx,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md2_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_MD2_ALT */
|
||||
|
||||
/*
|
||||
|
@ -268,15 +238,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md2( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md2_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
|
|
|
@ -102,13 +102,6 @@ int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_starts( mbedtls_md4_context *ctx )
|
||||
{
|
||||
mbedtls_md4_starts_ret( ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD4_PROCESS_ALT)
|
||||
int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
|
@ -238,13 +231,6 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_process( mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
{
|
||||
mbedtls_internal_md4_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_MD4_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -301,15 +287,6 @@ int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_update( mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_md4_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
static const unsigned char md4_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -355,14 +332,6 @@ int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_finish( mbedtls_md4_context *ctx,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md4_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_MD4_ALT */
|
||||
|
||||
/*
|
||||
|
@ -392,15 +361,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md4_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
|
|
|
@ -101,13 +101,6 @@ int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
|
||||
{
|
||||
mbedtls_md5_starts_ret( ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD5_PROCESS_ALT)
|
||||
int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
|
@ -244,13 +237,6 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md5_process( mbedtls_md5_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
{
|
||||
mbedtls_internal_md5_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_MD5_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -304,15 +290,6 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md5_update( mbedtls_md5_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_md5_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD5 final digest
|
||||
*/
|
||||
|
@ -370,14 +347,6 @@ int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md5_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_MD5_ALT */
|
||||
|
||||
/*
|
||||
|
@ -407,15 +376,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md5( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md5_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* RFC 1321 test vectors
|
||||
|
|
90
library/md_wrap.h
Normal file
90
library/md_wrap.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* \file md_wrap.h
|
||||
*
|
||||
* \brief Message digest wrappers.
|
||||
*
|
||||
* \warning This in an internal header. Do not include directly.
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_MD_WRAP_H
|
||||
#define MBEDTLS_MD_WRAP_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Message digest information.
|
||||
* Allows message digest functions to be called in a generic way.
|
||||
*/
|
||||
struct mbedtls_md_info_t
|
||||
{
|
||||
/** Name of the message digest */
|
||||
const char * name;
|
||||
|
||||
/** Digest identifier */
|
||||
mbedtls_md_type_t type;
|
||||
|
||||
/** Output length of the digest function in bytes */
|
||||
unsigned char size;
|
||||
|
||||
/** Block length of the digest function in bytes */
|
||||
unsigned char block_size;
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
extern const mbedtls_md_info_t mbedtls_md2_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
extern const mbedtls_md_info_t mbedtls_md4_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
extern const mbedtls_md_info_t mbedtls_md5_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
extern const mbedtls_md_info_t mbedtls_ripemd160_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
extern const mbedtls_md_info_t mbedtls_sha1_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
extern const mbedtls_md_info_t mbedtls_sha224_info;
|
||||
extern const mbedtls_md_info_t mbedtls_sha256_info;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
#if !defined(MBEDTLS_SHA512_NO_SHA384)
|
||||
extern const mbedtls_md_info_t mbedtls_sha384_info;
|
||||
#endif
|
||||
extern const mbedtls_md_info_t mbedtls_sha512_info;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_MD_WRAP_H */
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
|
||||
#include "mbedtls/padlock.h"
|
||||
#include "padlock.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
124
library/padlock.h
Normal file
124
library/padlock.h
Normal file
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
* \file padlock.h
|
||||
*
|
||||
* \brief VIA PadLock ACE for HW encryption/decryption supported by some
|
||||
* processors
|
||||
*
|
||||
* \warning These functions are only for internal use by other library
|
||||
* functions; you must not call them directly.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_PADLOCK_H
|
||||
#define MBEDTLS_PADLOCK_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(address_sanitizer)
|
||||
#define MBEDTLS_HAVE_ASAN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Some versions of ASan result in errors about not enough registers */
|
||||
#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
|
||||
!defined(MBEDTLS_HAVE_ASAN)
|
||||
|
||||
#ifndef MBEDTLS_HAVE_X86
|
||||
#define MBEDTLS_HAVE_X86
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBEDTLS_PADLOCK_RNG 0x000C
|
||||
#define MBEDTLS_PADLOCK_ACE 0x00C0
|
||||
#define MBEDTLS_PADLOCK_PHE 0x0C00
|
||||
#define MBEDTLS_PADLOCK_PMM 0x3000
|
||||
|
||||
#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Internal PadLock detection routine
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param feature The feature to detect
|
||||
*
|
||||
* \return 1 if CPU has support for the feature, 0 otherwise
|
||||
*/
|
||||
int mbedtls_padlock_has_support( int feature );
|
||||
|
||||
/**
|
||||
* \brief Internal PadLock AES-ECB block en(de)cryption
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param ctx AES context
|
||||
* \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
|
||||
* \param input 16-byte input block
|
||||
* \param output 16-byte output block
|
||||
*
|
||||
* \return 0 if success, 1 if operation failed
|
||||
*/
|
||||
int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief Internal PadLock AES-CBC buffer en(de)cryption
|
||||
*
|
||||
* \note This function is only for internal use by other library
|
||||
* functions; you must not call it directly.
|
||||
*
|
||||
* \param ctx AES context
|
||||
* \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
|
||||
* \param length length of the input data
|
||||
* \param iv initialization vector (updated after use)
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer holding the output data
|
||||
*
|
||||
* \return 0 if success, 1 if operation failed
|
||||
*/
|
||||
int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_X86 */
|
||||
|
||||
#endif /* padlock.h */
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "pk_wrap.h"
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
@ -626,7 +626,7 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
|
|||
|
||||
/* import private key into PSA */
|
||||
if( PSA_SUCCESS != psa_import_key( &attributes, d, d_len, key ) )
|
||||
return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
/* make PK context wrap the key slot */
|
||||
mbedtls_pk_free( pk );
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "pk_wrap.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
/* Even if RSA not activated, for the sake of RSA-alt */
|
||||
|
@ -941,7 +941,7 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start,
|
|||
|
||||
/* this is only reached if the signature was invalid */
|
||||
if( len == 0 )
|
||||
return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
|
||||
/* if the msb is 1, ASN.1 requires that we prepend a 0.
|
||||
* Neither r nor s can be 0, so we can assume len > 0 at all times. */
|
||||
|
|
140
library/pk_wrap.h
Normal file
140
library/pk_wrap.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
* \file pk_wrap.h
|
||||
*
|
||||
* \brief Public Key abstraction layer: wrapper functions
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_PK_WRAP_H
|
||||
#define MBEDTLS_PK_WRAP_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
|
||||
struct mbedtls_pk_info_t
|
||||
{
|
||||
/** Public key type */
|
||||
mbedtls_pk_type_t type;
|
||||
|
||||
/** Type name */
|
||||
const char *name;
|
||||
|
||||
/** Get key size in bits */
|
||||
size_t (*get_bitlen)( const void * );
|
||||
|
||||
/** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
|
||||
int (*can_do)( mbedtls_pk_type_t type );
|
||||
|
||||
/** Verify signature */
|
||||
int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len );
|
||||
|
||||
/** Make signature */
|
||||
int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
unsigned char *sig, size_t *sig_len,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/** Verify signature (restartable) */
|
||||
int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len,
|
||||
void *rs_ctx );
|
||||
|
||||
/** Make signature (restartable) */
|
||||
int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
unsigned char *sig, size_t *sig_len,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng, void *rs_ctx );
|
||||
#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
/** Decrypt message */
|
||||
int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen, size_t osize,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/** Encrypt message */
|
||||
int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen, size_t osize,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/** Check public-private key pair */
|
||||
int (*check_pair_func)( const void *pub, const void *prv );
|
||||
|
||||
/** Allocate a new context */
|
||||
void * (*ctx_alloc_func)( void );
|
||||
|
||||
/** Free the given context */
|
||||
void (*ctx_free_func)( void *ctx );
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/** Allocate the restart context */
|
||||
void * (*rs_alloc_func)( void );
|
||||
|
||||
/** Free the restart context */
|
||||
void (*rs_free_func)( void *rs_ctx );
|
||||
#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
/** Interface with the debug module */
|
||||
void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
|
||||
|
||||
};
|
||||
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
||||
/* Container for RSA-alt */
|
||||
typedef struct
|
||||
{
|
||||
void *key;
|
||||
mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
|
||||
mbedtls_pk_rsa_alt_sign_func sign_func;
|
||||
mbedtls_pk_rsa_alt_key_len_func key_len_func;
|
||||
} mbedtls_rsa_alt_context;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
extern const mbedtls_pk_info_t mbedtls_rsa_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
extern const mbedtls_pk_info_t mbedtls_eckey_info;
|
||||
extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
||||
extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_PK_WRAP_H */
|
238
library/pkcs11.c
238
library/pkcs11.c
|
@ -1,238 +0,0 @@
|
|||
/**
|
||||
* \file pkcs11.c
|
||||
*
|
||||
* \brief Wrapper for PKCS#11 library libpkcs11-helper
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "mbedtls/pkcs11.h"
|
||||
|
||||
#if defined(MBEDTLS_PKCS11_C)
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/oid.h"
|
||||
#include "mbedtls/x509_crt.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( mbedtls_pkcs11_context ) );
|
||||
}
|
||||
|
||||
int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11_cert )
|
||||
{
|
||||
int ret = 1;
|
||||
unsigned char *cert_blob = NULL;
|
||||
size_t cert_blob_size = 0;
|
||||
|
||||
if( cert == NULL )
|
||||
{
|
||||
ret = 2;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( pkcs11h_certificate_getCertificateBlob( pkcs11_cert, NULL,
|
||||
&cert_blob_size ) != CKR_OK )
|
||||
{
|
||||
ret = 3;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cert_blob = mbedtls_calloc( 1, cert_blob_size );
|
||||
if( NULL == cert_blob )
|
||||
{
|
||||
ret = 4;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( pkcs11h_certificate_getCertificateBlob( pkcs11_cert, cert_blob,
|
||||
&cert_blob_size ) != CKR_OK )
|
||||
{
|
||||
ret = 5;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( 0 != mbedtls_x509_crt_parse( cert, cert_blob, cert_blob_size ) )
|
||||
{
|
||||
ret = 6;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
if( NULL != cert_blob )
|
||||
mbedtls_free( cert_blob );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
|
||||
int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
|
||||
pkcs11h_certificate_t pkcs11_cert )
|
||||
{
|
||||
int ret = 1;
|
||||
mbedtls_x509_crt cert;
|
||||
|
||||
mbedtls_x509_crt_init( &cert );
|
||||
|
||||
if( priv_key == NULL )
|
||||
goto cleanup;
|
||||
|
||||
if( 0 != mbedtls_pkcs11_x509_cert_bind( &cert, pkcs11_cert ) )
|
||||
goto cleanup;
|
||||
|
||||
priv_key->len = mbedtls_pk_get_len( &cert.pk );
|
||||
priv_key->pkcs11h_cert = pkcs11_cert;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
mbedtls_x509_crt_free( &cert );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key )
|
||||
{
|
||||
if( NULL != priv_key )
|
||||
pkcs11h_certificate_freeCertificate( priv_key->pkcs11h_cert );
|
||||
}
|
||||
|
||||
int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
|
||||
int mode, size_t *olen,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
size_t output_max_len )
|
||||
{
|
||||
size_t input_len, output_len;
|
||||
|
||||
if( NULL == ctx )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
if( MBEDTLS_RSA_PRIVATE != mode )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
output_len = input_len = ctx->len;
|
||||
|
||||
if( input_len < 16 || input_len > output_max_len )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
/* Determine size of output buffer */
|
||||
if( pkcs11h_certificate_decryptAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, input,
|
||||
input_len, NULL, &output_len ) != CKR_OK )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
if( output_len > output_max_len )
|
||||
return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE );
|
||||
|
||||
if( pkcs11h_certificate_decryptAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, input,
|
||||
input_len, output, &output_len ) != CKR_OK )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
}
|
||||
*olen = output_len;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
|
||||
int mode,
|
||||
mbedtls_md_type_t md_alg,
|
||||
unsigned int hashlen,
|
||||
const unsigned char *hash,
|
||||
unsigned char *sig )
|
||||
{
|
||||
size_t sig_len = 0, asn_len = 0, oid_size = 0;
|
||||
unsigned char *p = sig;
|
||||
const char *oid;
|
||||
|
||||
if( NULL == ctx )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
if( MBEDTLS_RSA_PRIVATE != mode )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
if( md_alg != MBEDTLS_MD_NONE )
|
||||
{
|
||||
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg );
|
||||
if( md_info == NULL )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
if( mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ) != 0 )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
|
||||
hashlen = mbedtls_md_get_size( md_info );
|
||||
asn_len = 10 + oid_size;
|
||||
}
|
||||
|
||||
sig_len = ctx->len;
|
||||
if( hashlen > sig_len || asn_len > sig_len ||
|
||||
hashlen + asn_len > sig_len )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
if( md_alg != MBEDTLS_MD_NONE )
|
||||
{
|
||||
/*
|
||||
* DigestInfo ::= SEQUENCE {
|
||||
* digestAlgorithm DigestAlgorithmIdentifier,
|
||||
* digest Digest }
|
||||
*
|
||||
* DigestAlgorithmIdentifier ::= AlgorithmIdentifier
|
||||
*
|
||||
* Digest ::= OCTET STRING
|
||||
*/
|
||||
*p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
|
||||
*p++ = (unsigned char) ( 0x08 + oid_size + hashlen );
|
||||
*p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
|
||||
*p++ = (unsigned char) ( 0x04 + oid_size );
|
||||
*p++ = MBEDTLS_ASN1_OID;
|
||||
*p++ = oid_size & 0xFF;
|
||||
memcpy( p, oid, oid_size );
|
||||
p += oid_size;
|
||||
*p++ = MBEDTLS_ASN1_NULL;
|
||||
*p++ = 0x00;
|
||||
*p++ = MBEDTLS_ASN1_OCTET_STRING;
|
||||
*p++ = hashlen;
|
||||
}
|
||||
|
||||
memcpy( p, hash, hashlen );
|
||||
|
||||
if( pkcs11h_certificate_signAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, sig,
|
||||
asn_len + hashlen, sig, &sig_len ) != CKR_OK )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* defined(MBEDTLS_PKCS11_C) */
|
|
@ -222,7 +222,7 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *c;
|
||||
|
@ -271,7 +271,7 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, si
|
|||
|
||||
key_id = *((psa_key_id_t*) key->pk_ctx );
|
||||
if( PSA_SUCCESS != psa_get_key_attributes( key_id, &attributes ) )
|
||||
return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
key_type = psa_get_key_type( &attributes );
|
||||
bits = psa_get_key_bits( &attributes );
|
||||
psa_reset_key_attributes( &attributes );
|
||||
|
@ -310,7 +310,7 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, si
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_key_der( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *c;
|
||||
|
@ -553,7 +553,7 @@ int mbedtls_pk_write_key_der( mbedtls_pk_context *key, unsigned char *buf, size_
|
|||
#define PRV_DER_MAX_BYTES ( RSA_PRV_DER_MAX_BYTES > ECP_PRV_DER_MAX_BYTES ? \
|
||||
RSA_PRV_DER_MAX_BYTES : ECP_PRV_DER_MAX_BYTES )
|
||||
|
||||
int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_pubkey_pem( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char output_buf[PUB_DER_MAX_BYTES];
|
||||
|
@ -578,7 +578,7 @@ int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *key, unsigned char *buf, si
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_key_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_key_pem( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char output_buf[PRV_DER_MAX_BYTES];
|
||||
|
|
|
@ -78,9 +78,9 @@
|
|||
#include "mbedtls/md4.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "md_wrap.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "pk_wrap.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/ripemd160.h"
|
||||
|
@ -151,14 +151,7 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
|
||||
case MBEDTLS_ERR_AES_INVALID_KEY_LENGTH:
|
||||
case MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH:
|
||||
case MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_AES_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_ASN1_OUT_OF_DATA:
|
||||
case MBEDTLS_ERR_ASN1_UNEXPECTED_TAG:
|
||||
case MBEDTLS_ERR_ASN1_INVALID_LENGTH:
|
||||
|
@ -172,30 +165,20 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
|
||||
#if defined(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA)
|
||||
case MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA:
|
||||
#elif defined(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH)
|
||||
case MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH:
|
||||
#endif
|
||||
case MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
#if defined(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA)
|
||||
case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA:
|
||||
#elif defined(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH)
|
||||
case MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH:
|
||||
#endif
|
||||
case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_CCM_BAD_INPUT:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
case MBEDTLS_ERR_CCM_AUTH_FAILED:
|
||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
||||
case MBEDTLS_ERR_CCM_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
@ -219,11 +202,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_INVALID_SIGNATURE );
|
||||
case MBEDTLS_ERR_CIPHER_INVALID_CONTEXT:
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
case MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
#if !( defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) || \
|
||||
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE) )
|
||||
|
@ -240,8 +218,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
|
||||
case MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_DES_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED:
|
||||
case MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE:
|
||||
|
@ -252,8 +228,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_INVALID_SIGNATURE );
|
||||
case MBEDTLS_ERR_GCM_BAD_INPUT:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
case MBEDTLS_ERR_GCM_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) && \
|
||||
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE)
|
||||
|
@ -268,11 +242,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_INSUFFICIENT_ENTROPY );
|
||||
#endif
|
||||
|
||||
case MBEDTLS_ERR_MD2_HW_ACCEL_FAILED:
|
||||
case MBEDTLS_ERR_MD4_HW_ACCEL_FAILED:
|
||||
case MBEDTLS_ERR_MD5_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_MD_BAD_INPUT_DATA:
|
||||
|
@ -281,8 +250,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
case MBEDTLS_ERR_MD_FILE_IO_ERROR:
|
||||
return( PSA_ERROR_STORAGE_FAILURE );
|
||||
case MBEDTLS_ERR_MD_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_MPI_FILE_IO_ERROR:
|
||||
return( PSA_ERROR_STORAGE_FAILURE );
|
||||
|
@ -324,17 +291,12 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_PK_SIG_LEN_MISMATCH:
|
||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
||||
case MBEDTLS_ERR_PK_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
case MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
|
||||
case MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_RSA_BAD_INPUT_DATA:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
case MBEDTLS_ERR_RSA_INVALID_PADDING:
|
||||
|
@ -352,20 +314,9 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
case MBEDTLS_ERR_RSA_RNG_FAILED:
|
||||
return( PSA_ERROR_INSUFFICIENT_ENTROPY );
|
||||
case MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION:
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
case MBEDTLS_ERR_RSA_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED:
|
||||
case MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED:
|
||||
case MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
case MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_ECP_BAD_INPUT_DATA:
|
||||
case MBEDTLS_ERR_ECP_INVALID_KEY:
|
||||
|
@ -381,8 +332,6 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
|||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
case MBEDTLS_ERR_ECP_RANDOM_FAILED:
|
||||
return( PSA_ERROR_INSUFFICIENT_ENTROPY );
|
||||
case MBEDTLS_ERR_ECP_HW_ACCEL_FAILED:
|
||||
return( PSA_ERROR_HARDWARE_FAILURE );
|
||||
|
||||
case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED:
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
|
@ -4879,7 +4828,7 @@ int mbedtls_psa_get_random( void *p_rng,
|
|||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "entropy_poll.h"
|
||||
|
||||
psa_status_t mbedtls_psa_inject_entropy( const uint8_t *seed,
|
||||
size_t seed_size )
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <psa/crypto.h>
|
||||
|
||||
#include <mbedtls/md_internal.h>
|
||||
#include "md_wrap.h"
|
||||
|
||||
/** Get Mbed TLS MD information of a hash algorithm given its PSA identifier
|
||||
*
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/error.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include <mbedtls/pk_internal.h>
|
||||
#include "pk_wrap.h"
|
||||
|
||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
||||
|
|
|
@ -103,13 +103,6 @@ int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx )
|
||||
{
|
||||
mbedtls_ripemd160_starts_ret( ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
|
||||
/*
|
||||
* Process one block
|
||||
|
@ -307,13 +300,6 @@ int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ripemd160_process( mbedtls_ripemd160_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
{
|
||||
mbedtls_internal_ripemd160_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_RIPEMD160_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -368,15 +354,6 @@ int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_ripemd160_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
static const unsigned char ripemd160_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -423,14 +400,6 @@ int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx,
|
||||
unsigned char output[20] )
|
||||
{
|
||||
mbedtls_ripemd160_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! MBEDTLS_RIPEMD160_ALT */
|
||||
|
||||
/*
|
||||
|
@ -460,15 +429,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ripemd160( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] )
|
||||
{
|
||||
mbedtls_ripemd160_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* Test vectors from the RIPEMD-160 paper and
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#if defined(MBEDTLS_RSA_C)
|
||||
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/rsa_internal.h"
|
||||
#include "rsa_alt_helpers.h"
|
||||
#include "mbedtls/oid.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/rsa_internal.h"
|
||||
#include "rsa_alt_helpers.h"
|
||||
|
||||
/*
|
||||
* Compute RSA prime factors from public and private exponents
|
||||
|
@ -237,90 +237,36 @@ cleanup:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that RSA CRT parameters are in accordance with core parameters.
|
||||
*/
|
||||
int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, const mbedtls_mpi *DP,
|
||||
const mbedtls_mpi *DQ, const mbedtls_mpi *QP )
|
||||
int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, mbedtls_mpi *DP,
|
||||
mbedtls_mpi *DQ, mbedtls_mpi *QP )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mbedtls_mpi K, L;
|
||||
mbedtls_mpi K;
|
||||
mbedtls_mpi_init( &K );
|
||||
mbedtls_mpi_init( &L );
|
||||
|
||||
/* Check that DP - D == 0 mod P - 1 */
|
||||
/* DP = D mod P-1 */
|
||||
if( DP != NULL )
|
||||
{
|
||||
if( P == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DP, D ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) );
|
||||
|
||||
if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DP, D, &K ) );
|
||||
}
|
||||
|
||||
/* Check that DQ - D == 0 mod Q - 1 */
|
||||
/* DQ = D mod Q-1 */
|
||||
if( DQ != NULL )
|
||||
{
|
||||
if( Q == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DQ, D ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) );
|
||||
|
||||
if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DQ, D, &K ) );
|
||||
}
|
||||
|
||||
/* Check that QP * Q - 1 == 0 mod P */
|
||||
/* QP = Q^{-1} mod P */
|
||||
if( QP != NULL )
|
||||
{
|
||||
if( P == NULL || Q == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, QP, Q ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, P ) );
|
||||
if( mbedtls_mpi_cmp_int( &K, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( QP, Q, P ) );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
/* Wrap MPI error codes by RSA check failure error code */
|
||||
if( ret != 0 &&
|
||||
ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED &&
|
||||
ret != MBEDTLS_ERR_RSA_BAD_INPUT_DATA )
|
||||
{
|
||||
ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
}
|
||||
|
||||
mbedtls_mpi_free( &K );
|
||||
mbedtls_mpi_free( &L );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -449,36 +395,90 @@ cleanup:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, mbedtls_mpi *DP,
|
||||
mbedtls_mpi *DQ, mbedtls_mpi *QP )
|
||||
/*
|
||||
* Check that RSA CRT parameters are in accordance with core parameters.
|
||||
*/
|
||||
int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, const mbedtls_mpi *DP,
|
||||
const mbedtls_mpi *DQ, const mbedtls_mpi *QP )
|
||||
{
|
||||
int ret = 0;
|
||||
mbedtls_mpi K;
|
||||
mbedtls_mpi_init( &K );
|
||||
|
||||
/* DP = D mod P-1 */
|
||||
mbedtls_mpi K, L;
|
||||
mbedtls_mpi_init( &K );
|
||||
mbedtls_mpi_init( &L );
|
||||
|
||||
/* Check that DP - D == 0 mod P - 1 */
|
||||
if( DP != NULL )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DP, D, &K ) );
|
||||
if( P == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DP, D ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) );
|
||||
|
||||
if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* DQ = D mod Q-1 */
|
||||
/* Check that DQ - D == 0 mod Q - 1 */
|
||||
if( DQ != NULL )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DQ, D, &K ) );
|
||||
if( Q == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DQ, D ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) );
|
||||
|
||||
if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* QP = Q^{-1} mod P */
|
||||
/* Check that QP * Q - 1 == 0 mod P */
|
||||
if( QP != NULL )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( QP, Q, P ) );
|
||||
if( P == NULL || Q == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, QP, Q ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, P ) );
|
||||
if( mbedtls_mpi_cmp_int( &K, 0 ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
/* Wrap MPI error codes by RSA check failure error code */
|
||||
if( ret != 0 &&
|
||||
ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED &&
|
||||
ret != MBEDTLS_ERR_RSA_BAD_INPUT_DATA )
|
||||
{
|
||||
ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
|
||||
}
|
||||
|
||||
mbedtls_mpi_free( &K );
|
||||
mbedtls_mpi_free( &L );
|
||||
|
||||
return( ret );
|
||||
}
|
224
library/rsa_alt_helpers.h
Normal file
224
library/rsa_alt_helpers.h
Normal file
|
@ -0,0 +1,224 @@
|
|||
/**
|
||||
* \file rsa_alt_helpers.h
|
||||
*
|
||||
* \brief Context-independent RSA helper functions
|
||||
*
|
||||
* This module declares some RSA-related helper functions useful when
|
||||
* implementing the RSA interface. These functions are provided in a separate
|
||||
* compilation unit in order to make it easy for designers of alternative RSA
|
||||
* implementations to use them in their own code, as it is conceived that the
|
||||
* functionality they provide will be necessary for most complete
|
||||
* implementations.
|
||||
*
|
||||
* End-users of Mbed TLS who are not providing their own alternative RSA
|
||||
* implementations should not use these functions directly, and should instead
|
||||
* use only the functions declared in rsa.h.
|
||||
*
|
||||
* The interface provided by this module will be maintained through LTS (Long
|
||||
* Term Support) branches of Mbed TLS, but may otherwise be subject to change,
|
||||
* and must be considered an internal interface of the library.
|
||||
*
|
||||
* There are two classes of helper functions:
|
||||
*
|
||||
* (1) Parameter-generating helpers. These are:
|
||||
* - mbedtls_rsa_deduce_primes
|
||||
* - mbedtls_rsa_deduce_private_exponent
|
||||
* - mbedtls_rsa_deduce_crt
|
||||
* Each of these functions takes a set of core RSA parameters and
|
||||
* generates some other, or CRT related parameters.
|
||||
*
|
||||
* (2) Parameter-checking helpers. These are:
|
||||
* - mbedtls_rsa_validate_params
|
||||
* - mbedtls_rsa_validate_crt
|
||||
* They take a set of core or CRT related RSA parameters and check their
|
||||
* validity.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_RSA_INTERNAL_H
|
||||
#define MBEDTLS_RSA_INTERNAL_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \brief Compute RSA prime moduli P, Q from public modulus N=PQ
|
||||
* and a pair of private and public key.
|
||||
*
|
||||
* \note This is a 'static' helper function not operating on
|
||||
* an RSA context. Alternative implementations need not
|
||||
* overwrite it.
|
||||
*
|
||||
* \param N RSA modulus N = PQ, with P, Q to be found
|
||||
* \param E RSA public exponent
|
||||
* \param D RSA private exponent
|
||||
* \param P Pointer to MPI holding first prime factor of N on success
|
||||
* \param Q Pointer to MPI holding second prime factor of N on success
|
||||
*
|
||||
* \return
|
||||
* - 0 if successful. In this case, P and Q constitute a
|
||||
* factorization of N.
|
||||
* - A non-zero error code otherwise.
|
||||
*
|
||||
* \note It is neither checked that P, Q are prime nor that
|
||||
* D, E are modular inverses wrt. P-1 and Q-1. For that,
|
||||
* use the helper function \c mbedtls_rsa_validate_params.
|
||||
*
|
||||
*/
|
||||
int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi const *E,
|
||||
mbedtls_mpi const *D,
|
||||
mbedtls_mpi *P, mbedtls_mpi *Q );
|
||||
|
||||
/**
|
||||
* \brief Compute RSA private exponent from
|
||||
* prime moduli and public key.
|
||||
*
|
||||
* \note This is a 'static' helper function not operating on
|
||||
* an RSA context. Alternative implementations need not
|
||||
* overwrite it.
|
||||
*
|
||||
* \param P First prime factor of RSA modulus
|
||||
* \param Q Second prime factor of RSA modulus
|
||||
* \param E RSA public exponent
|
||||
* \param D Pointer to MPI holding the private exponent on success.
|
||||
*
|
||||
* \return
|
||||
* - 0 if successful. In this case, D is set to a simultaneous
|
||||
* modular inverse of E modulo both P-1 and Q-1.
|
||||
* - A non-zero error code otherwise.
|
||||
*
|
||||
* \note This function does not check whether P and Q are primes.
|
||||
*
|
||||
*/
|
||||
int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P,
|
||||
mbedtls_mpi const *Q,
|
||||
mbedtls_mpi const *E,
|
||||
mbedtls_mpi *D );
|
||||
|
||||
|
||||
/**
|
||||
* \brief Generate RSA-CRT parameters
|
||||
*
|
||||
* \note This is a 'static' helper function not operating on
|
||||
* an RSA context. Alternative implementations need not
|
||||
* overwrite it.
|
||||
*
|
||||
* \param P First prime factor of N
|
||||
* \param Q Second prime factor of N
|
||||
* \param D RSA private exponent
|
||||
* \param DP Output variable for D modulo P-1
|
||||
* \param DQ Output variable for D modulo Q-1
|
||||
* \param QP Output variable for the modular inverse of Q modulo P.
|
||||
*
|
||||
* \return 0 on success, non-zero error code otherwise.
|
||||
*
|
||||
* \note This function does not check whether P, Q are
|
||||
* prime and whether D is a valid private exponent.
|
||||
*
|
||||
*/
|
||||
int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, mbedtls_mpi *DP,
|
||||
mbedtls_mpi *DQ, mbedtls_mpi *QP );
|
||||
|
||||
|
||||
/**
|
||||
* \brief Check validity of core RSA parameters
|
||||
*
|
||||
* \note This is a 'static' helper function not operating on
|
||||
* an RSA context. Alternative implementations need not
|
||||
* overwrite it.
|
||||
*
|
||||
* \param N RSA modulus N = PQ
|
||||
* \param P First prime factor of N
|
||||
* \param Q Second prime factor of N
|
||||
* \param D RSA private exponent
|
||||
* \param E RSA public exponent
|
||||
* \param f_rng PRNG to be used for primality check, or NULL
|
||||
* \param p_rng PRNG context for f_rng, or NULL
|
||||
*
|
||||
* \return
|
||||
* - 0 if the following conditions are satisfied
|
||||
* if all relevant parameters are provided:
|
||||
* - P prime if f_rng != NULL (%)
|
||||
* - Q prime if f_rng != NULL (%)
|
||||
* - 1 < N = P * Q
|
||||
* - 1 < D, E < N
|
||||
* - D and E are modular inverses modulo P-1 and Q-1
|
||||
* (%) This is only done if MBEDTLS_GENPRIME is defined.
|
||||
* - A non-zero error code otherwise.
|
||||
*
|
||||
* \note The function can be used with a restricted set of arguments
|
||||
* to perform specific checks only. E.g., calling it with
|
||||
* (-,P,-,-,-) and a PRNG amounts to a primality check for P.
|
||||
*/
|
||||
int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P,
|
||||
const mbedtls_mpi *Q, const mbedtls_mpi *D,
|
||||
const mbedtls_mpi *E,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief Check validity of RSA CRT parameters
|
||||
*
|
||||
* \note This is a 'static' helper function not operating on
|
||||
* an RSA context. Alternative implementations need not
|
||||
* overwrite it.
|
||||
*
|
||||
* \param P First prime factor of RSA modulus
|
||||
* \param Q Second prime factor of RSA modulus
|
||||
* \param D RSA private exponent
|
||||
* \param DP MPI to check for D modulo P-1
|
||||
* \param DQ MPI to check for D modulo P-1
|
||||
* \param QP MPI to check for the modular inverse of Q modulo P.
|
||||
*
|
||||
* \return
|
||||
* - 0 if the following conditions are satisfied:
|
||||
* - D = DP mod P-1 if P, D, DP != NULL
|
||||
* - Q = DQ mod P-1 if P, D, DQ != NULL
|
||||
* - QP = Q^-1 mod P if P, Q, QP != NULL
|
||||
* - \c MBEDTLS_ERR_RSA_KEY_CHECK_FAILED if check failed,
|
||||
* potentially including \c MBEDTLS_ERR_MPI_XXX if some
|
||||
* MPI calculations failed.
|
||||
* - \c MBEDTLS_ERR_RSA_BAD_INPUT_DATA if insufficient
|
||||
* data was provided to check DP, DQ or QP.
|
||||
*
|
||||
* \note The function can be used with a restricted set of arguments
|
||||
* to perform specific checks only. E.g., calling it with the
|
||||
* parameters (P, -, D, DP, -, -) will check DP = D mod P-1.
|
||||
*/
|
||||
int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
|
||||
const mbedtls_mpi *D, const mbedtls_mpi *DP,
|
||||
const mbedtls_mpi *DQ, const mbedtls_mpi *QP );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* rsa_alt_helpers.h */
|
|
@ -114,13 +114,6 @@ int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
|
||||
{
|
||||
mbedtls_sha1_starts_ret( ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_PROCESS_ALT)
|
||||
int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
|
@ -294,13 +287,6 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
{
|
||||
mbedtls_internal_sha1_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_SHA1_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -356,15 +342,6 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_sha1_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-1 final digest
|
||||
*/
|
||||
|
@ -426,14 +403,6 @@ int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
|
||||
unsigned char output[20] )
|
||||
{
|
||||
mbedtls_sha1_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_SHA1_ALT */
|
||||
|
||||
/*
|
||||
|
@ -466,15 +435,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha1( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] )
|
||||
{
|
||||
mbedtls_sha1_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-1 test vectors
|
||||
|
|
|
@ -138,14 +138,6 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
|
||||
int is224 )
|
||||
{
|
||||
mbedtls_sha256_starts_ret( ctx, is224 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SHA256_PROCESS_ALT)
|
||||
static const uint32_t K[] =
|
||||
{
|
||||
|
@ -281,13 +273,6 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
{
|
||||
mbedtls_internal_sha256_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_SHA256_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -343,15 +328,6 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_sha256_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-256 final digest
|
||||
*/
|
||||
|
@ -418,14 +394,6 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
||||
unsigned char output[32] )
|
||||
{
|
||||
mbedtls_sha256_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_SHA256_ALT */
|
||||
|
||||
/*
|
||||
|
@ -460,16 +428,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha256( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[32],
|
||||
int is224 )
|
||||
{
|
||||
mbedtls_sha256_ret( input, ilen, output, is224 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-2 test vectors
|
||||
|
|
|
@ -171,14 +171,6 @@ int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
|
||||
int is384 )
|
||||
{
|
||||
mbedtls_sha512_starts_ret( ctx, is384 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SHA512_PROCESS_ALT)
|
||||
|
||||
/*
|
||||
|
@ -330,13 +322,6 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha512_process( mbedtls_sha512_context *ctx,
|
||||
const unsigned char data[128] )
|
||||
{
|
||||
mbedtls_internal_sha512_process( ctx, data );
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_SHA512_PROCESS_ALT */
|
||||
|
||||
/*
|
||||
|
@ -391,15 +376,6 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
{
|
||||
mbedtls_sha512_update_ret( ctx, input, ilen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-512 final digest
|
||||
*/
|
||||
|
@ -470,14 +446,6 @@ int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
|
||||
unsigned char output[64] )
|
||||
{
|
||||
mbedtls_sha512_finish_ret( ctx, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !MBEDTLS_SHA512_ALT */
|
||||
|
||||
/*
|
||||
|
@ -516,16 +484,6 @@ exit:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_sha512( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[64],
|
||||
int is384 )
|
||||
{
|
||||
mbedtls_sha512_ret( input, ilen, output, is384 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl_cache.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -266,22 +266,6 @@ static const int ciphersuite_preference[] =
|
|||
MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA,
|
||||
MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA,
|
||||
|
||||
/* RC4 suites */
|
||||
MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_RSA_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_RSA_WITH_RC4_128_MD5,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA,
|
||||
MBEDTLS_TLS_PSK_WITH_RC4_128_SHA,
|
||||
|
||||
/* Weak suites */
|
||||
MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA,
|
||||
MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA,
|
||||
|
||||
/* NULL suites */
|
||||
MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA,
|
||||
MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA,
|
||||
|
@ -499,16 +483,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA, "TLS-ECDHE-ECDSA-WITH-NULL-SHA",
|
||||
|
@ -618,16 +592,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS-ECDHE-RSA-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA, "TLS-ECDHE-RSA-WITH-NULL-SHA",
|
||||
|
@ -677,13 +641,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA, "TLS-DHE-RSA-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA, "TLS-DHE-RSA-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -731,13 +695,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -766,7 +730,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -812,13 +776,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
{ MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA, "TLS-RSA-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA, "TLS-RSA-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
@ -866,13 +830,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -902,30 +866,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-RSA-WITH-3DES-EDE-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_RC4_128_MD5, "TLS-RSA-WITH-RC4-128-MD5",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_MD5, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_RC4_128_SHA, "TLS-RSA-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
|
||||
|
@ -1026,16 +973,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA, "TLS-ECDH-RSA-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, "TLS-ECDH-RSA-WITH-NULL-SHA",
|
||||
|
@ -1145,16 +1082,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA, "TLS-ECDH-ECDSA-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, "TLS-ECDH-ECDSA-WITH-NULL-SHA",
|
||||
|
@ -1206,13 +1133,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, "TLS-PSK-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, "TLS-PSK-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -1284,22 +1211,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-PSK-WITH-3DES-EDE-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_PSK_WITH_RC4_128_SHA, "TLS-PSK-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
|
||||
|
@ -1342,13 +1260,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA, "TLS-DHE-PSK-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
|
||||
{ MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA, "TLS-DHE-PSK-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -1420,22 +1338,13 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-PSK-WITH-3DES-EDE-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
0 },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA, "TLS-DHE-PSK-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
|
||||
|
@ -1506,15 +1415,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA, "TLS-ECDHE-PSK-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
|
||||
|
@ -1620,15 +1520,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA, "TLS-RSA-PSK-WITH-RC4-128-SHA",
|
||||
MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_NODTLS },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
|
@ -1649,7 +1540,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_MD5_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_NULL_MD5, "TLS-RSA-WITH-NULL-MD5",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_MD5, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif
|
||||
|
@ -1657,7 +1548,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_NULL_SHA, "TLS-RSA-WITH-NULL-SHA",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif
|
||||
|
@ -1675,7 +1566,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_PSK_WITH_NULL_SHA, "TLS-PSK-WITH-NULL-SHA",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -1701,7 +1592,7 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA, "TLS-DHE-PSK-WITH-NULL-SHA",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
@ -1776,29 +1667,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
|||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA, "TLS-DHE-RSA-WITH-DES-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{ MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA, "TLS-RSA-WITH-DES-CBC-SHA",
|
||||
MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
MBEDTLS_CIPHERSUITE_WEAK },
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
#endif /* MBEDTLS_ENABLE_WEAK_CIPHERSUITES */
|
||||
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
|
@ -2180,11 +2048,6 @@ static int ciphersuite_is_removed( const mbedtls_ssl_ciphersuite_t *cs_info )
|
|||
{
|
||||
(void)cs_info;
|
||||
|
||||
#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
|
||||
if( cs_info->cipher == MBEDTLS_CIPHER_ARC4_128 )
|
||||
return( 1 );
|
||||
#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */
|
||||
|
||||
#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES)
|
||||
if( cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_ECB ||
|
||||
cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_CBC )
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SSLv3/TLSv1 client-side functions
|
||||
* TLS client-side functions
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -599,8 +599,7 @@ static int ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
|
|||
|
||||
*olen = 0;
|
||||
|
||||
if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED ||
|
||||
ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED )
|
||||
return( 0 );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3,
|
||||
|
@ -630,8 +629,7 @@ static int ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl,
|
|||
|
||||
*olen = 0;
|
||||
|
||||
if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED ||
|
||||
ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED )
|
||||
return( 0 );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3,
|
||||
|
@ -949,12 +947,6 @@ static int ssl_validate_ciphersuite(
|
|||
return( 1 );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
if( ssl->conf->arc4_disabled == MBEDTLS_SSL_ARC4_DISABLED &&
|
||||
suite_info->cipher == MBEDTLS_CIPHER_ARC4_128 )
|
||||
return( 1 );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
if( suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE &&
|
||||
mbedtls_ecjpake_check( &ssl->handshake->ecjpake_ctx ) != 0 )
|
||||
|
@ -982,7 +974,6 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||
unsigned char *p, *q;
|
||||
const unsigned char *end;
|
||||
|
||||
unsigned char offer_compress;
|
||||
const int *ciphersuites;
|
||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
|
||||
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
||||
|
@ -1164,7 +1155,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||
/*
|
||||
* Ciphersuite list
|
||||
*/
|
||||
ciphersuites = ssl->conf->ciphersuite_list[ssl->minor_ver];
|
||||
ciphersuites = mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf,
|
||||
ssl->minor_ver );
|
||||
|
||||
/* Skip writing ciphersuite length for now */
|
||||
n = 0;
|
||||
|
@ -1230,45 +1222,13 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||
*q++ = (unsigned char)( n >> 7 );
|
||||
*q++ = (unsigned char)( n << 1 );
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
offer_compress = 1;
|
||||
#else
|
||||
offer_compress = 0;
|
||||
#endif
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 1 ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d",
|
||||
MBEDTLS_SSL_COMPRESS_NULL ) );
|
||||
|
||||
/*
|
||||
* We don't support compression with DTLS right now: if many records come
|
||||
* in the same datagram, uncompressing one could overwrite the next one.
|
||||
* We don't want to add complexity for handling that case unless there is
|
||||
* an actual need for it.
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
offer_compress = 0;
|
||||
#endif
|
||||
|
||||
if( offer_compress )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 2 ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d %d",
|
||||
MBEDTLS_SSL_COMPRESS_DEFLATE,
|
||||
MBEDTLS_SSL_COMPRESS_NULL ) );
|
||||
|
||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 3 );
|
||||
*p++ = 2;
|
||||
*p++ = MBEDTLS_SSL_COMPRESS_DEFLATE;
|
||||
*p++ = MBEDTLS_SSL_COMPRESS_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 1 ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d",
|
||||
MBEDTLS_SSL_COMPRESS_NULL ) );
|
||||
|
||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||
*p++ = 1;
|
||||
*p++ = MBEDTLS_SSL_COMPRESS_NULL;
|
||||
}
|
||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||
*p++ = 1;
|
||||
*p++ = MBEDTLS_SSL_COMPRESS_NULL;
|
||||
|
||||
/* First write extensions, then the total length */
|
||||
|
||||
|
@ -1620,7 +1580,6 @@ static int ssl_parse_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
|
|||
size_t len )
|
||||
{
|
||||
if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED ||
|
||||
ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ||
|
||||
len != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1,
|
||||
|
@ -1646,7 +1605,6 @@ static int ssl_parse_extended_ms_ext( mbedtls_ssl_context *ssl,
|
|||
size_t len )
|
||||
{
|
||||
if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED ||
|
||||
ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ||
|
||||
len != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1,
|
||||
|
@ -2052,9 +2010,6 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
size_t ext_len;
|
||||
unsigned char *buf, *ext;
|
||||
unsigned char comp;
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
int accept_comp;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
int renegotiation_info_seen = 0;
|
||||
#endif
|
||||
|
@ -2223,20 +2178,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
*/
|
||||
comp = buf[37 + n];
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
/* See comments in ssl_write_client_hello() */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
accept_comp = 0;
|
||||
else
|
||||
#endif
|
||||
accept_comp = 1;
|
||||
|
||||
if( comp != MBEDTLS_SSL_COMPRESS_NULL &&
|
||||
( comp != MBEDTLS_SSL_COMPRESS_DEFLATE || accept_comp == 0 ) )
|
||||
#else /* MBEDTLS_ZLIB_SUPPORT */
|
||||
if( comp != MBEDTLS_SSL_COMPRESS_NULL )
|
||||
#endif/* MBEDTLS_ZLIB_SUPPORT */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1,
|
||||
( "server hello, bad compression: %d", comp ) );
|
||||
|
@ -2315,7 +2257,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
i = 0;
|
||||
while( 1 )
|
||||
{
|
||||
if( ssl->conf->ciphersuite_list[ssl->minor_ver][i] == 0 )
|
||||
if( mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver )[i] == 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||
mbedtls_ssl_send_alert_message(
|
||||
|
@ -2325,7 +2267,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||
}
|
||||
|
||||
if( ssl->conf->ciphersuite_list[ssl->minor_ver][i++] ==
|
||||
if( mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver )[i++] ==
|
||||
ssl->session_negotiate->ciphersuite )
|
||||
{
|
||||
break;
|
||||
|
@ -2357,9 +2299,6 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
|||
#endif
|
||||
|
||||
if( comp != MBEDTLS_SSL_COMPRESS_NULL
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
&& comp != MBEDTLS_SSL_COMPRESS_DEFLATE
|
||||
#endif
|
||||
)
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||
|
@ -2842,7 +2781,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
|||
size_t pms_offset )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len_bytes = ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ? 0 : 2;
|
||||
size_t len_bytes = 2;
|
||||
unsigned char *p = ssl->handshake->premaster + pms_offset;
|
||||
mbedtls_pk_context * peer_pk;
|
||||
|
||||
|
@ -3297,8 +3236,7 @@ start_processing:
|
|||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( ssl->minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
pk_alg = mbedtls_ssl_get_ciphersuite_sig_pk_alg( ciphersuite_info );
|
||||
|
@ -3345,8 +3283,7 @@ start_processing:
|
|||
/*
|
||||
* Compute the hash that has been signed
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( md_alg == MBEDTLS_MD_NONE )
|
||||
{
|
||||
hashlen = 36;
|
||||
|
@ -3356,8 +3293,7 @@ start_processing:
|
|||
return( ret );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( md_alg != MBEDTLS_MD_NONE )
|
||||
|
@ -4175,8 +4111,7 @@ sign:
|
|||
|
||||
ssl->handshake->calc_verify( ssl, hash, &hashlen );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
/*
|
||||
|
@ -4204,8 +4139,7 @@ sign:
|
|||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl_cookie.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
|
|
1265
library/ssl_misc.h
Normal file
1265
library/ssl_misc.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -18,10 +18,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* The SSL 3.0 specification was drafted by Netscape in 1996,
|
||||
* and became an IETF standard in 1999.
|
||||
*
|
||||
* http://wp.netscape.com/eng/ssl3/
|
||||
* http://www.ietf.org/rfc/rfc2246.txt
|
||||
* http://www.ietf.org/rfc/rfc4346.txt
|
||||
*/
|
||||
|
@ -39,7 +35,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
@ -106,7 +102,7 @@ int mbedtls_ssl_check_record( mbedtls_ssl_context const *ssl,
|
|||
|
||||
/* We don't support record checking in TLS because
|
||||
* (a) there doesn't seem to be a usecase for it, and
|
||||
* (b) In SSLv3 and TLS 1.0, CBC record decryption has state
|
||||
* (b) In TLS 1.0, CBC record decryption has state
|
||||
* and we'd need to backup the transform here.
|
||||
*/
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_STREAM )
|
||||
|
@ -297,21 +293,6 @@ static void ssl_reset_retransmit_timeout( mbedtls_ssl_context *ssl )
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
int (*mbedtls_ssl_hw_record_init)( mbedtls_ssl_context *ssl,
|
||||
const unsigned char *key_enc, const unsigned char *key_dec,
|
||||
size_t keylen,
|
||||
const unsigned char *iv_enc, const unsigned char *iv_dec,
|
||||
size_t ivlen,
|
||||
const unsigned char *mac_enc, const unsigned char *mac_dec,
|
||||
size_t maclen ) = NULL;
|
||||
int (*mbedtls_ssl_hw_record_activate)( mbedtls_ssl_context *ssl, int direction) = NULL;
|
||||
int (*mbedtls_ssl_hw_record_reset)( mbedtls_ssl_context *ssl ) = NULL;
|
||||
int (*mbedtls_ssl_hw_record_write)( mbedtls_ssl_context *ssl ) = NULL;
|
||||
int (*mbedtls_ssl_hw_record_read)( mbedtls_ssl_context *ssl ) = NULL;
|
||||
int (*mbedtls_ssl_hw_record_finish)( mbedtls_ssl_context *ssl ) = NULL;
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
|
||||
/*
|
||||
* Encryption/decryption functions
|
||||
*/
|
||||
|
@ -469,53 +450,6 @@ static void ssl_extract_add_data_from_record( unsigned char* add_data,
|
|||
*add_data_len = cur - add_data;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
|
||||
#define SSL3_MAC_MAX_BYTES 20 /* MD-5 or SHA-1 */
|
||||
|
||||
/*
|
||||
* SSLv3.0 MAC functions
|
||||
*/
|
||||
static void ssl_mac( mbedtls_md_context_t *md_ctx,
|
||||
const unsigned char *secret,
|
||||
const unsigned char *buf, size_t len,
|
||||
const unsigned char *ctr, int type,
|
||||
unsigned char out[SSL3_MAC_MAX_BYTES] )
|
||||
{
|
||||
unsigned char header[11];
|
||||
unsigned char padding[48];
|
||||
int padlen;
|
||||
int md_size = mbedtls_md_get_size( md_ctx->md_info );
|
||||
int md_type = mbedtls_md_get_type( md_ctx->md_info );
|
||||
|
||||
/* Only MD5 and SHA-1 supported */
|
||||
if( md_type == MBEDTLS_MD_MD5 )
|
||||
padlen = 48;
|
||||
else
|
||||
padlen = 40;
|
||||
|
||||
memcpy( header, ctr, 8 );
|
||||
header[ 8] = (unsigned char) type;
|
||||
header[ 9] = (unsigned char)( len >> 8 );
|
||||
header[10] = (unsigned char)( len );
|
||||
|
||||
memset( padding, 0x36, padlen );
|
||||
mbedtls_md_starts( md_ctx );
|
||||
mbedtls_md_update( md_ctx, secret, md_size );
|
||||
mbedtls_md_update( md_ctx, padding, padlen );
|
||||
mbedtls_md_update( md_ctx, header, 11 );
|
||||
mbedtls_md_update( md_ctx, buf, len );
|
||||
mbedtls_md_finish( md_ctx, out );
|
||||
|
||||
memset( padding, 0x5C, padlen );
|
||||
mbedtls_md_starts( md_ctx );
|
||||
mbedtls_md_update( md_ctx, secret, md_size );
|
||||
mbedtls_md_update( md_ctx, padding, padlen );
|
||||
mbedtls_md_update( md_ctx, out, md_size );
|
||||
mbedtls_md_finish( md_ctx, out );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) || \
|
||||
defined(MBEDTLS_CCM_C) || \
|
||||
defined(MBEDTLS_CHACHAPOLY_C)
|
||||
|
@ -712,17 +646,6 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
|||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "Buffer provided for encrypted record not large enough" ) );
|
||||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
unsigned char mac[SSL3_MAC_MAX_BYTES];
|
||||
ssl_mac( &transform->md_ctx_enc, transform->mac_enc,
|
||||
data, rec->data_len, rec->ctr, rec->type, mac );
|
||||
memcpy( data + rec->data_len, mac, transform->maclen );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( transform->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
|
@ -760,7 +683,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
|||
/*
|
||||
* Encrypt
|
||||
*/
|
||||
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
if( mode == MBEDTLS_MODE_STREAM )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -785,7 +708,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
|||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_ARC4_C || MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) || \
|
||||
defined(MBEDTLS_CCM_C) || \
|
||||
|
@ -968,11 +891,11 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
|||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
if( transform->minor_ver < MBEDTLS_SSL_MINOR_VERSION_2 )
|
||||
{
|
||||
/*
|
||||
* Save IV in SSL3 and TLS1
|
||||
* Save IV in TLS1
|
||||
*/
|
||||
memcpy( transform->iv_enc, transform->cipher_ctx_enc.iv,
|
||||
transform->ivlen );
|
||||
|
@ -1322,7 +1245,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
if( mode == MBEDTLS_MODE_STREAM )
|
||||
{
|
||||
padlen = 0;
|
||||
|
@ -1343,7 +1266,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_ARC4_C || MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#if defined(MBEDTLS_GCM_C) || \
|
||||
defined(MBEDTLS_CCM_C) || \
|
||||
defined(MBEDTLS_CHACHAPOLY_C)
|
||||
|
@ -1598,11 +1521,11 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
if( transform->minor_ver < MBEDTLS_SSL_MINOR_VERSION_2 )
|
||||
{
|
||||
/*
|
||||
* Save IV in SSL3 and TLS1, where CBC decryption of consecutive
|
||||
* Save IV in TLS1, where CBC decryption of consecutive
|
||||
* records is equivalent to CBC decryption of the concatenation
|
||||
* of the records; in other words, IVs are maintained across
|
||||
* record decryptions.
|
||||
|
@ -1652,70 +1575,44 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
/* Regardless of the validity of the padding,
|
||||
* we have data_len >= padlen here. */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
/* This is the SSL 3.0 path, we don't have to worry about Lucky
|
||||
* 13, because there's a strictly worse padding attack built in
|
||||
* the protocol (known as part of POODLE), so we don't care if the
|
||||
* code is not constant-time, in particular branches are OK. */
|
||||
if( padlen > transform->ivlen )
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_DEBUG_ALL)
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad padding length: is %" MBEDTLS_PRINTF_SIZET ", "
|
||||
"should be no more than %" MBEDTLS_PRINTF_SIZET,
|
||||
padlen, transform->ivlen ) );
|
||||
#endif
|
||||
correct = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( transform->minor_ver > MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
/* The padding check involves a series of up to 256
|
||||
* consecutive memory reads at the end of the record
|
||||
* plaintext buffer. In order to hide the length and
|
||||
* validity of the padding, always perform exactly
|
||||
* `min(256,plaintext_len)` reads (but take into account
|
||||
* only the last `padlen` bytes for the padding check). */
|
||||
size_t pad_count = 0;
|
||||
volatile unsigned char* const check = data;
|
||||
|
||||
/* Index of first padding byte; it has been ensured above
|
||||
* that the subtraction is safe. */
|
||||
size_t const padding_idx = rec->data_len - padlen;
|
||||
size_t const num_checks = rec->data_len <= 256 ? rec->data_len : 256;
|
||||
size_t const start_idx = rec->data_len - num_checks;
|
||||
size_t idx;
|
||||
|
||||
for( idx = start_idx; idx < rec->data_len; idx++ )
|
||||
{
|
||||
/* The padding check involves a series of up to 256
|
||||
* consecutive memory reads at the end of the record
|
||||
* plaintext buffer. In order to hide the length and
|
||||
* validity of the padding, always perform exactly
|
||||
* `min(256,plaintext_len)` reads (but take into account
|
||||
* only the last `padlen` bytes for the padding check). */
|
||||
size_t pad_count = 0;
|
||||
volatile unsigned char* const check = data;
|
||||
|
||||
/* Index of first padding byte; it has been ensured above
|
||||
* that the subtraction is safe. */
|
||||
size_t const padding_idx = rec->data_len - padlen;
|
||||
size_t const num_checks = rec->data_len <= 256 ? rec->data_len : 256;
|
||||
size_t const start_idx = rec->data_len - num_checks;
|
||||
size_t idx;
|
||||
|
||||
for( idx = start_idx; idx < rec->data_len; idx++ )
|
||||
{
|
||||
/* pad_count += (idx >= padding_idx) &&
|
||||
* (check[idx] == padlen - 1);
|
||||
*/
|
||||
const size_t mask = mbedtls_ssl_cf_mask_ge( idx, padding_idx );
|
||||
const size_t equal = mbedtls_ssl_cf_bool_eq( check[idx],
|
||||
padlen - 1 );
|
||||
pad_count += mask & equal;
|
||||
}
|
||||
correct &= mbedtls_ssl_cf_bool_eq( pad_count, padlen );
|
||||
/* pad_count += (idx >= padding_idx) &&
|
||||
* (check[idx] == padlen - 1);
|
||||
*/
|
||||
const size_t mask = mbedtls_ssl_cf_mask_ge( idx, padding_idx );
|
||||
const size_t equal = mbedtls_ssl_cf_bool_eq( check[idx],
|
||||
padlen - 1 );
|
||||
pad_count += mask & equal;
|
||||
}
|
||||
correct &= mbedtls_ssl_cf_bool_eq( pad_count, padlen );
|
||||
|
||||
#if defined(MBEDTLS_SSL_DEBUG_ALL)
|
||||
if( padlen > 0 && correct == 0 )
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad padding byte detected" ) );
|
||||
if( padlen > 0 && correct == 0 )
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad padding byte detected" ) );
|
||||
#endif
|
||||
padlen &= mbedtls_ssl_cf_mask_from_bit( correct );
|
||||
}
|
||||
else
|
||||
padlen &= mbedtls_ssl_cf_mask_from_bit( correct );
|
||||
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
/* If the padding was found to be invalid, padlen == 0
|
||||
* and the subtraction is safe. If the padding was found valid,
|
||||
|
@ -1762,57 +1659,37 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
ssl_extract_add_data_from_record( add_data, &add_data_len, rec,
|
||||
transform->minor_ver );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
ssl_mac( &transform->md_ctx_dec,
|
||||
transform->mac_dec,
|
||||
data, rec->data_len,
|
||||
rec->ctr, rec->type,
|
||||
mac_expect );
|
||||
memcpy( mac_peer, data + rec->data_len, transform->maclen );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( transform->minor_ver > MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
/*
|
||||
* The next two sizes are the minimum and maximum values of
|
||||
* data_len over all padlen values.
|
||||
*
|
||||
* They're independent of padlen, since we previously did
|
||||
* data_len -= padlen.
|
||||
*
|
||||
* Note that max_len + maclen is never more than the buffer
|
||||
* length, as we previously did in_msglen -= maclen too.
|
||||
*/
|
||||
const size_t max_len = rec->data_len + padlen;
|
||||
const size_t min_len = ( max_len > 256 ) ? max_len - 256 : 0;
|
||||
|
||||
ret = mbedtls_ssl_cf_hmac( &transform->md_ctx_dec,
|
||||
add_data, add_data_len,
|
||||
data, rec->data_len, min_len, max_len,
|
||||
mac_expect );
|
||||
if( ret != 0 )
|
||||
{
|
||||
/*
|
||||
* The next two sizes are the minimum and maximum values of
|
||||
* data_len over all padlen values.
|
||||
*
|
||||
* They're independent of padlen, since we previously did
|
||||
* data_len -= padlen.
|
||||
*
|
||||
* Note that max_len + maclen is never more than the buffer
|
||||
* length, as we previously did in_msglen -= maclen too.
|
||||
*/
|
||||
const size_t max_len = rec->data_len + padlen;
|
||||
const size_t min_len = ( max_len > 256 ) ? max_len - 256 : 0;
|
||||
|
||||
ret = mbedtls_ssl_cf_hmac( &transform->md_ctx_dec,
|
||||
add_data, add_data_len,
|
||||
data, rec->data_len, min_len, max_len,
|
||||
mac_expect );
|
||||
if( ret != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_cf_hmac", ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
mbedtls_ssl_cf_memcpy_offset( mac_peer, data,
|
||||
rec->data_len,
|
||||
min_len, max_len,
|
||||
transform->maclen );
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_cf_hmac", ret );
|
||||
return( ret );
|
||||
}
|
||||
else
|
||||
|
||||
mbedtls_ssl_cf_memcpy_offset( mac_peer, data,
|
||||
rec->data_len,
|
||||
min_len, max_len,
|
||||
transform->maclen );
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_DEBUG_ALL)
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "expected mac", mac_expect, transform->maclen );
|
||||
|
@ -1875,115 +1752,6 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
|||
#undef MAC_PLAINTEXT
|
||||
#undef MAC_CIPHERTEXT
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
/*
|
||||
* Compression/decompression functions
|
||||
*/
|
||||
static int ssl_compress_buf( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *msg_post = ssl->out_msg;
|
||||
ptrdiff_t bytes_written = ssl->out_msg - ssl->out_buf;
|
||||
size_t len_pre = ssl->out_msglen;
|
||||
unsigned char *msg_pre = ssl->compress_buf;
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
size_t out_buf_len = ssl->out_buf_len;
|
||||
#else
|
||||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN;
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> compress buf" ) );
|
||||
|
||||
if( len_pre == 0 )
|
||||
return( 0 );
|
||||
|
||||
memcpy( msg_pre, ssl->out_msg, len_pre );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "before compression: msglen = %" MBEDTLS_PRINTF_SIZET ", ",
|
||||
ssl->out_msglen ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "before compression: output payload",
|
||||
ssl->out_msg, ssl->out_msglen );
|
||||
|
||||
ssl->transform_out->ctx_deflate.next_in = msg_pre;
|
||||
ssl->transform_out->ctx_deflate.avail_in = len_pre;
|
||||
ssl->transform_out->ctx_deflate.next_out = msg_post;
|
||||
ssl->transform_out->ctx_deflate.avail_out = out_buf_len - bytes_written;
|
||||
|
||||
ret = deflate( &ssl->transform_out->ctx_deflate, Z_SYNC_FLUSH );
|
||||
if( ret != Z_OK )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "failed to perform compression (%d)", ret ) );
|
||||
return( MBEDTLS_ERR_SSL_COMPRESSION_FAILED );
|
||||
}
|
||||
|
||||
ssl->out_msglen = out_buf_len -
|
||||
ssl->transform_out->ctx_deflate.avail_out - bytes_written;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "after compression: msglen = %" MBEDTLS_PRINTF_SIZET ", ",
|
||||
ssl->out_msglen ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "after compression: output payload",
|
||||
ssl->out_msg, ssl->out_msglen );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= compress buf" ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int ssl_decompress_buf( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *msg_post = ssl->in_msg;
|
||||
ptrdiff_t header_bytes = ssl->in_msg - ssl->in_buf;
|
||||
size_t len_pre = ssl->in_msglen;
|
||||
unsigned char *msg_pre = ssl->compress_buf;
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
size_t in_buf_len = ssl->in_buf_len;
|
||||
#else
|
||||
size_t in_buf_len = MBEDTLS_SSL_IN_BUFFER_LEN;
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> decompress buf" ) );
|
||||
|
||||
if( len_pre == 0 )
|
||||
return( 0 );
|
||||
|
||||
memcpy( msg_pre, ssl->in_msg, len_pre );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "before decompression: msglen = %" MBEDTLS_PRINTF_SIZET ", ",
|
||||
ssl->in_msglen ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "before decompression: input payload",
|
||||
ssl->in_msg, ssl->in_msglen );
|
||||
|
||||
ssl->transform_in->ctx_inflate.next_in = msg_pre;
|
||||
ssl->transform_in->ctx_inflate.avail_in = len_pre;
|
||||
ssl->transform_in->ctx_inflate.next_out = msg_post;
|
||||
ssl->transform_in->ctx_inflate.avail_out = in_buf_len - header_bytes;
|
||||
|
||||
ret = inflate( &ssl->transform_in->ctx_inflate, Z_SYNC_FLUSH );
|
||||
if( ret != Z_OK )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "failed to perform decompression (%d)", ret ) );
|
||||
return( MBEDTLS_ERR_SSL_COMPRESSION_FAILED );
|
||||
}
|
||||
|
||||
ssl->in_msglen = in_buf_len -
|
||||
ssl->transform_in->ctx_inflate.avail_out - header_bytes;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "after decompression: msglen = %" MBEDTLS_PRINTF_SIZET ", ",
|
||||
ssl->in_msglen ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "after decompression: input payload",
|
||||
ssl->in_msg, ssl->in_msglen );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= decompress buf" ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_ZLIB_SUPPORT */
|
||||
|
||||
/*
|
||||
* Fill the input message buffer by appending data to it.
|
||||
* The amount of data already fetched is in ssl->in_left.
|
||||
|
@ -2382,18 +2150,6 @@ static int ssl_swap_epochs( mbedtls_ssl_context *ssl )
|
|||
/* Adjust to the newly activated transform */
|
||||
mbedtls_ssl_update_out_pointers( ssl, ssl->transform_out );
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_activate != NULL )
|
||||
{
|
||||
int ret = mbedtls_ssl_hw_record_activate( ssl, MBEDTLS_SSL_CHANNEL_OUTBOUND );
|
||||
if( ret != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_activate", ret );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -2671,16 +2427,8 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl )
|
|||
if( ssl->out_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE &&
|
||||
ssl->out_msgtype != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC )
|
||||
{
|
||||
/* In SSLv3, the client might send a NoCertificate alert. */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) && defined(MBEDTLS_SSL_CLI_C)
|
||||
if( ! ( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 &&
|
||||
ssl->out_msgtype == MBEDTLS_SSL_MSG_ALERT &&
|
||||
ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT ) )
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 && MBEDTLS_SSL_SRV_C */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
/* Whenever we send anything different from a
|
||||
|
@ -2825,36 +2573,6 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush )
|
|||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write record" ) );
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->transform_out != NULL &&
|
||||
ssl->session_out->compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
|
||||
{
|
||||
if( ( ret = ssl_compress_buf( ssl ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_compress_buf", ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
len = ssl->out_msglen;
|
||||
}
|
||||
#endif /*MBEDTLS_ZLIB_SUPPORT */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_write != NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "going for mbedtls_ssl_hw_record_write()" ) );
|
||||
|
||||
ret = mbedtls_ssl_hw_record_write( ssl );
|
||||
if( ret != 0 && ret != MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_write", ret );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
|
||||
if( ret == 0 )
|
||||
done = 1;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
if( !done )
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -3874,22 +3592,6 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl,
|
|||
MBEDTLS_SSL_DEBUG_BUF( 4, "input record from network",
|
||||
rec->buf, rec->buf_len );
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_read != NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "going for mbedtls_ssl_hw_record_read()" ) );
|
||||
|
||||
ret = mbedtls_ssl_hw_record_read( ssl );
|
||||
if( ret != 0 && ret != MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_read", ret );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
|
||||
if( ret == 0 )
|
||||
done = 1;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
if( !done && ssl->transform_in != NULL )
|
||||
{
|
||||
unsigned char const old_msg_type = rec->type;
|
||||
|
@ -4891,26 +4593,6 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl )
|
|||
ssl->in_len[0] = (unsigned char)( rec.data_len >> 8 );
|
||||
ssl->in_len[1] = (unsigned char)( rec.data_len );
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->transform_in != NULL &&
|
||||
ssl->session_in->compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
|
||||
{
|
||||
if( ( ret = ssl_decompress_buf( ssl ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_decompress_buf", ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* Check actual (decompress) record content length against
|
||||
* configured maximum. */
|
||||
if( ssl->in_msglen > MBEDTLS_SSL_IN_CONTENT_LEN )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) );
|
||||
return( MBEDTLS_ERR_SSL_INVALID_RECORD );
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_ZLIB_SUPPORT */
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -4998,24 +4680,11 @@ int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl )
|
|||
if( ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING &&
|
||||
ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "is a SSLv3 no renegotiation alert" ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "is a no renegotiation alert" ) );
|
||||
/* Will be handled when trying to parse ServerHello */
|
||||
return( 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) && defined(MBEDTLS_SSL_SRV_C)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 &&
|
||||
ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER &&
|
||||
ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING &&
|
||||
ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_CERT )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "is a SSLv3 no_cert" ) );
|
||||
/* Will be handled in mbedtls_ssl_parse_certificate() */
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 && MBEDTLS_SSL_SRV_C */
|
||||
|
||||
/* Silently ignore: fetch new message */
|
||||
return MBEDTLS_ERR_SSL_NON_FATAL;
|
||||
}
|
||||
|
@ -5158,19 +4827,6 @@ int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl )
|
|||
|
||||
mbedtls_ssl_update_in_pointers( ssl );
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_activate != NULL )
|
||||
{
|
||||
if( ( ret = mbedtls_ssl_hw_record_activate( ssl, MBEDTLS_SSL_CHANNEL_INBOUND ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_activate", ret );
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ssl->state++;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse change cipher spec" ) );
|
||||
|
@ -5380,11 +5036,6 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl )
|
|||
if( transform == NULL )
|
||||
return( (int) out_hdr_len );
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->session_out->compression != MBEDTLS_SSL_COMPRESS_NULL )
|
||||
return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
|
||||
#endif
|
||||
|
||||
switch( mbedtls_cipher_get_cipher_mode( &transform->cipher_ctx_enc ) )
|
||||
{
|
||||
case MBEDTLS_MODE_GCM:
|
||||
|
@ -5639,17 +5290,6 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
|
|||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "refusing renegotiation, sending alert" ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
/* SSLv3 does not have a "no_renegotiation" warning, so
|
||||
we send a fatal alert and abort the connection. */
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE );
|
||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
|
@ -5960,11 +5600,6 @@ void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform )
|
|||
if( transform == NULL )
|
||||
return;
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
deflateEnd( &transform->ctx_deflate );
|
||||
inflateEnd( &transform->ctx_inflate );
|
||||
#endif
|
||||
|
||||
mbedtls_cipher_free( &transform->cipher_ctx_enc );
|
||||
mbedtls_cipher_free( &transform->cipher_ctx_dec );
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SSLv3/TLSv1 server-side functions
|
||||
* TLS server-side functions
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
@ -579,8 +579,7 @@ static int ssl_parse_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
|
|||
|
||||
((void) buf);
|
||||
|
||||
if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_ENABLED &&
|
||||
ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_ENABLED )
|
||||
{
|
||||
ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_ENABLED;
|
||||
}
|
||||
|
@ -604,8 +603,7 @@ static int ssl_parse_extended_ms_ext( mbedtls_ssl_context *ssl,
|
|||
|
||||
((void) buf);
|
||||
|
||||
if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_ENABLED &&
|
||||
ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_ENABLED )
|
||||
{
|
||||
ssl->handshake->extended_ms = MBEDTLS_SSL_EXTENDED_MS_ENABLED;
|
||||
}
|
||||
|
@ -1063,15 +1061,6 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id,
|
|||
return( 0 );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
if( ssl->conf->arc4_disabled == MBEDTLS_SSL_ARC4_DISABLED &&
|
||||
suite_info->cipher == MBEDTLS_CIPHER_ARC4_128 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: rc4" ) );
|
||||
return( 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
if( suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE &&
|
||||
( ssl->handshake->cli_exts & MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK ) == 0 )
|
||||
|
@ -1144,269 +1133,6 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
|
||||
static int ssl_parse_client_hello_v2( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret, got_common_suite;
|
||||
unsigned int i, j;
|
||||
size_t n;
|
||||
unsigned int ciph_len, sess_len, chal_len;
|
||||
unsigned char *buf, *p;
|
||||
const int *ciphersuites;
|
||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse client hello v2" ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
if( ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "client hello v2 illegal for renegotiation" ) );
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
|
||||
buf = ssl->in_hdr;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "record header", buf, 5 );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v2, message type: %d",
|
||||
buf[2] ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v2, message len.: %d",
|
||||
( ( buf[0] & 0x7F ) << 8 ) | buf[1] ) );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v2, max. version: [%d:%d]",
|
||||
buf[3], buf[4] ) );
|
||||
|
||||
/*
|
||||
* SSLv2 Client Hello
|
||||
*
|
||||
* Record layer:
|
||||
* 0 . 1 message length
|
||||
*
|
||||
* SSL layer:
|
||||
* 2 . 2 message type
|
||||
* 3 . 4 protocol version
|
||||
*/
|
||||
if( buf[2] != MBEDTLS_SSL_HS_CLIENT_HELLO ||
|
||||
buf[3] != MBEDTLS_SSL_MAJOR_VERSION_3 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
n = ( ( buf[0] << 8 ) | buf[1] ) & 0x7FFF;
|
||||
|
||||
if( n < 17 || n > 512 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
ssl->major_ver = MBEDTLS_SSL_MAJOR_VERSION_3;
|
||||
ssl->minor_ver = ( buf[4] <= ssl->conf->max_minor_ver )
|
||||
? buf[4] : ssl->conf->max_minor_ver;
|
||||
|
||||
if( ssl->minor_ver < ssl->conf->min_minor_ver )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "client only supports ssl smaller than minimum"
|
||||
" [%d:%d] < [%d:%d]",
|
||||
ssl->major_ver, ssl->minor_ver,
|
||||
ssl->conf->min_major_ver, ssl->conf->min_minor_ver ) );
|
||||
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION );
|
||||
}
|
||||
|
||||
ssl->handshake->max_major_ver = buf[3];
|
||||
ssl->handshake->max_minor_ver = buf[4];
|
||||
|
||||
if( ( ret = mbedtls_ssl_fetch_input( ssl, 2 + n ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
ssl->handshake->update_checksum( ssl, buf + 2, n );
|
||||
|
||||
buf = ssl->in_msg;
|
||||
n = ssl->in_left - 5;
|
||||
|
||||
/*
|
||||
* 0 . 1 ciphersuitelist length
|
||||
* 2 . 3 session id length
|
||||
* 4 . 5 challenge length
|
||||
* 6 . .. ciphersuitelist
|
||||
* .. . .. session id
|
||||
* .. . .. challenge
|
||||
*/
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "record contents", buf, n );
|
||||
|
||||
ciph_len = ( buf[0] << 8 ) | buf[1];
|
||||
sess_len = ( buf[2] << 8 ) | buf[3];
|
||||
chal_len = ( buf[4] << 8 ) | buf[5];
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciph_len: %u, sess_len: %u, chal_len: %u",
|
||||
ciph_len, sess_len, chal_len ) );
|
||||
|
||||
/*
|
||||
* Make sure each parameter length is valid
|
||||
*/
|
||||
if( ciph_len < 3 || ( ciph_len % 3 ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
if( sess_len > 32 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
if( chal_len < 8 || chal_len > 32 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
if( n != 6 + ciph_len + sess_len + chal_len )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, ciphersuitelist",
|
||||
buf + 6, ciph_len );
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, session id",
|
||||
buf + 6 + ciph_len, sess_len );
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, challenge",
|
||||
buf + 6 + ciph_len + sess_len, chal_len );
|
||||
|
||||
p = buf + 6 + ciph_len;
|
||||
ssl->session_negotiate->id_len = sess_len;
|
||||
memset( ssl->session_negotiate->id, 0,
|
||||
sizeof( ssl->session_negotiate->id ) );
|
||||
memcpy( ssl->session_negotiate->id, p, ssl->session_negotiate->id_len );
|
||||
|
||||
p += sess_len;
|
||||
memset( ssl->handshake->randbytes, 0, 64 );
|
||||
memcpy( ssl->handshake->randbytes + 32 - chal_len, p, chal_len );
|
||||
|
||||
/*
|
||||
* Check for TLS_EMPTY_RENEGOTIATION_INFO_SCSV
|
||||
*/
|
||||
for( i = 0, p = buf + 6; i < ciph_len; i += 3, p += 3 )
|
||||
{
|
||||
if( p[0] == 0 && p[1] == 0 && p[2] == MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "received TLS_EMPTY_RENEGOTIATION_INFO " ) );
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
if( ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "received RENEGOTIATION SCSV "
|
||||
"during renegotiation" ) );
|
||||
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
|
||||
for( i = 0, p = buf + 6; i < ciph_len; i += 3, p += 3 )
|
||||
{
|
||||
if( p[0] == 0 &&
|
||||
p[1] == (unsigned char)( ( MBEDTLS_SSL_FALLBACK_SCSV_VALUE >> 8 ) & 0xff ) &&
|
||||
p[2] == (unsigned char)( ( MBEDTLS_SSL_FALLBACK_SCSV_VALUE ) & 0xff ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "received FALLBACK_SCSV" ) );
|
||||
|
||||
if( ssl->minor_ver < ssl->conf->max_minor_ver )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "inapropriate fallback" ) );
|
||||
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK );
|
||||
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
||||
|
||||
got_common_suite = 0;
|
||||
ciphersuites = ssl->conf->ciphersuite_list[ssl->minor_ver];
|
||||
ciphersuite_info = NULL;
|
||||
#if defined(MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
|
||||
for( j = 0, p = buf + 6; j < ciph_len; j += 3, p += 3 )
|
||||
for( i = 0; ciphersuites[i] != 0; i++ )
|
||||
#else
|
||||
for( i = 0; ciphersuites[i] != 0; i++ )
|
||||
for( j = 0, p = buf + 6; j < ciph_len; j += 3, p += 3 )
|
||||
#endif
|
||||
{
|
||||
if( p[0] != 0 ||
|
||||
p[1] != ( ( ciphersuites[i] >> 8 ) & 0xFF ) ||
|
||||
p[2] != ( ( ciphersuites[i] ) & 0xFF ) )
|
||||
continue;
|
||||
|
||||
got_common_suite = 1;
|
||||
|
||||
if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i],
|
||||
&ciphersuite_info ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( ciphersuite_info != NULL )
|
||||
goto have_ciphersuite_v2;
|
||||
}
|
||||
|
||||
if( got_common_suite )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "got ciphersuites in common, "
|
||||
"but none of them usable" ) );
|
||||
return( MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE );
|
||||
}
|
||||
else
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) );
|
||||
return( MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN );
|
||||
}
|
||||
|
||||
have_ciphersuite_v2:
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "selected ciphersuite: %s", ciphersuite_info->name ) );
|
||||
|
||||
ssl->session_negotiate->ciphersuite = ciphersuites[i];
|
||||
ssl->handshake->ciphersuite_info = ciphersuite_info;
|
||||
|
||||
/*
|
||||
* SSLv2 Client Hello relevant renegotiation security checks
|
||||
*/
|
||||
if( ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION &&
|
||||
ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "legacy renegotiation, breaking off handshake" ) );
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
ssl->in_left = 0;
|
||||
ssl->state++;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse client hello v2" ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
|
||||
|
||||
/* This function doesn't alert on errors that happen early during
|
||||
ClientHello parsing because they might indicate that the client is
|
||||
not talking SSL/TLS at all and would not understand our alert. */
|
||||
|
@ -1461,18 +1187,10 @@ read_record_header:
|
|||
|
||||
buf = ssl->in_hdr;
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_STREAM )
|
||||
#endif
|
||||
if( ( buf[0] & 0x80 ) != 0 )
|
||||
return( ssl_parse_client_hello_v2( ssl ) );
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "record header", buf, mbedtls_ssl_in_hdr_len( ssl ) );
|
||||
|
||||
/*
|
||||
* SSLv3/TLS Client Hello
|
||||
* TLS Client Hello
|
||||
*
|
||||
* Record layer:
|
||||
* 0 . 0 message type
|
||||
|
@ -1480,7 +1198,7 @@ read_record_header:
|
|||
* 3 . 11 DTLS: epoch + record sequence number
|
||||
* 3 . 4 message length
|
||||
*/
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, message type: %d",
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, message type: %d",
|
||||
buf[0] ) );
|
||||
|
||||
if( buf[0] != MBEDTLS_SSL_MSG_HANDSHAKE )
|
||||
|
@ -1489,10 +1207,10 @@ read_record_header:
|
|||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, message len.: %d",
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, message len.: %d",
|
||||
( ssl->in_len[0] << 8 ) | ssl->in_len[1] ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, protocol version: [%d:%d]",
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, protocol version: [%d:%d]",
|
||||
buf[1], buf[2] ) );
|
||||
|
||||
mbedtls_ssl_read_version( &major, &minor, ssl->conf->transport, buf + 1 );
|
||||
|
@ -1848,28 +1566,11 @@ read_record_header:
|
|||
buf + comp_offset + 1, comp_len );
|
||||
|
||||
ssl->session_negotiate->compression = MBEDTLS_SSL_COMPRESS_NULL;
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
for( i = 0; i < comp_len; ++i )
|
||||
{
|
||||
if( buf[comp_offset + 1 + i] == MBEDTLS_SSL_COMPRESS_DEFLATE )
|
||||
{
|
||||
ssl->session_negotiate->compression = MBEDTLS_SSL_COMPRESS_DEFLATE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* See comments in ssl_write_client_hello() */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
ssl->session_negotiate->compression = MBEDTLS_SSL_COMPRESS_NULL;
|
||||
#endif
|
||||
|
||||
/* Do not parse the extensions if the protocol is SSLv3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( ( ssl->major_ver != 3 ) || ( ssl->minor_ver != 0 ) )
|
||||
{
|
||||
#endif
|
||||
/*
|
||||
* Check the extension length
|
||||
*/
|
||||
|
@ -2079,9 +1780,6 @@ read_record_header:
|
|||
ext_len -= 4 + ext_size;
|
||||
ext += 4 + ext_size;
|
||||
}
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
|
||||
for( i = 0, p = buf + ciph_offset + 2; i < ciph_len; i += 2, p += 2 )
|
||||
|
@ -2195,7 +1893,7 @@ read_record_header:
|
|||
* and certificate from the SNI callback triggered by the SNI extension.)
|
||||
*/
|
||||
got_common_suite = 0;
|
||||
ciphersuites = ssl->conf->ciphersuite_list[ssl->minor_ver];
|
||||
ciphersuites = mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver );
|
||||
ciphersuite_info = NULL;
|
||||
#if defined(MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
|
||||
for( j = 0, p = buf + ciph_offset + 2; j < ciph_len; j += 2, p += 2 )
|
||||
|
@ -2357,8 +2055,7 @@ static void ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
|
|||
const mbedtls_ssl_ciphersuite_t *suite = NULL;
|
||||
const mbedtls_cipher_info_t *cipher = NULL;
|
||||
|
||||
if( ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED ||
|
||||
ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED )
|
||||
{
|
||||
*olen = 0;
|
||||
return;
|
||||
|
@ -2398,8 +2095,7 @@ static void ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl,
|
|||
{
|
||||
unsigned char *p = buf;
|
||||
|
||||
if( ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED ||
|
||||
ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if( ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED )
|
||||
{
|
||||
*olen = 0;
|
||||
return;
|
||||
|
@ -2920,12 +2616,6 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
|
|||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, compress alg.: 0x%02X",
|
||||
(unsigned int) ssl->session_negotiate->compression ) );
|
||||
|
||||
/* Do not write the extensions if the protocol is SSLv3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( ( ssl->major_ver != 3 ) || ( ssl->minor_ver != 0 ) )
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
* First write extensions, then the total length
|
||||
*/
|
||||
|
@ -2997,10 +2687,6 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
|
|||
p += ext_len;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
}
|
||||
#endif
|
||||
|
||||
ssl->out_msglen = p - buf;
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO;
|
||||
|
@ -3454,7 +3140,7 @@ curve_matching_done:
|
|||
* 2.1: Choose hash algorithm:
|
||||
* A: For TLS 1.2, obey signature-hash-algorithm extension
|
||||
* to choose appropriate hash.
|
||||
* B: For SSL3, TLS1.0, TLS1.1 and ECDHE_ECDSA, use SHA1
|
||||
* B: For TLS1.0, TLS1.1 and ECDHE_ECDSA, use SHA1
|
||||
* (RFC 4492, Sec. 5.4)
|
||||
* C: Otherwise, use MD5 + SHA1 (RFC 4346, Sec. 7.4.3)
|
||||
*/
|
||||
|
@ -3480,16 +3166,14 @@ curve_matching_done:
|
|||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA )
|
||||
{
|
||||
/* B: Default hash SHA1 */
|
||||
md_alg = MBEDTLS_MD_SHA1;
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
{
|
||||
/* C: MD5 + SHA1 */
|
||||
md_alg = MBEDTLS_MD_NONE;
|
||||
|
@ -3500,8 +3184,7 @@ curve_matching_done:
|
|||
/*
|
||||
* 2.2: Compute the hash to be signed
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( md_alg == MBEDTLS_MD_NONE )
|
||||
{
|
||||
hashlen = 36;
|
||||
|
@ -3512,8 +3195,7 @@ curve_matching_done:
|
|||
return( ret );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( md_alg != MBEDTLS_MD_NONE )
|
||||
|
@ -3843,18 +3525,15 @@ static int ssl_decrypt_encrypted_pms( mbedtls_ssl_context *ssl,
|
|||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
if ( p + 2 > end ) {
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||
}
|
||||
if( *p++ != ( ( len >> 8 ) & 0xFF ) ||
|
||||
*p++ != ( ( len ) & 0xFF ) )
|
||||
{
|
||||
if ( p + 2 > end ) {
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||
}
|
||||
if( *p++ != ( ( len >> 8 ) & 0xFF ) ||
|
||||
*p++ != ( ( len ) & 0xFF ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||
}
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4465,8 +4144,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
|||
* opaque signature<0..2^16-1>;
|
||||
* } DigitallySigned;
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
md_alg = MBEDTLS_MD_NONE;
|
||||
|
@ -4481,8 +4159,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
|||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 ||
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/ssl_ticket.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SSLv3/TLSv1 shared functions
|
||||
* TLS shared functions
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
|
@ -17,10 +17,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* The SSL 3.0 specification was drafted by Netscape in 1996,
|
||||
* and became an IETF standard in 1999.
|
||||
*
|
||||
* http://wp.netscape.com/eng/ssl3/
|
||||
* http://www.ietf.org/rfc/rfc2246.txt
|
||||
* http://www.ietf.org/rfc/rfc4346.txt
|
||||
*/
|
||||
|
@ -38,7 +34,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
@ -328,70 +324,6 @@ static void handle_buffer_resizing( mbedtls_ssl_context *ssl, int downsizing,
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH */
|
||||
|
||||
/*
|
||||
* Key material generation
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
static int ssl3_prf( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
const unsigned char *random, size_t rlen,
|
||||
unsigned char *dstbuf, size_t dlen )
|
||||
{
|
||||
int ret = 0;
|
||||
size_t i;
|
||||
mbedtls_md5_context md5;
|
||||
mbedtls_sha1_context sha1;
|
||||
unsigned char padding[16];
|
||||
unsigned char sha1sum[20];
|
||||
((void)label);
|
||||
|
||||
mbedtls_md5_init( &md5 );
|
||||
mbedtls_sha1_init( &sha1 );
|
||||
|
||||
/*
|
||||
* SSLv3:
|
||||
* block =
|
||||
* MD5( secret + SHA1( 'A' + secret + random ) ) +
|
||||
* MD5( secret + SHA1( 'BB' + secret + random ) ) +
|
||||
* MD5( secret + SHA1( 'CCC' + secret + random ) ) +
|
||||
* ...
|
||||
*/
|
||||
for( i = 0; i < dlen / 16; i++ )
|
||||
{
|
||||
memset( padding, (unsigned char) ('A' + i), 1 + i );
|
||||
|
||||
if( ( ret = mbedtls_sha1_starts_ret( &sha1 ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_sha1_update_ret( &sha1, padding, 1 + i ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_sha1_update_ret( &sha1, secret, slen ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_sha1_update_ret( &sha1, random, rlen ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_sha1_finish_ret( &sha1, sha1sum ) ) != 0 )
|
||||
goto exit;
|
||||
|
||||
if( ( ret = mbedtls_md5_starts_ret( &md5 ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_md5_update_ret( &md5, secret, slen ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_md5_update_ret( &md5, sha1sum, 20 ) ) != 0 )
|
||||
goto exit;
|
||||
if( ( ret = mbedtls_md5_finish_ret( &md5, dstbuf + i * 16 ) ) != 0 )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_md5_free( &md5 );
|
||||
mbedtls_sha1_free( &sha1 );
|
||||
|
||||
mbedtls_platform_zeroize( padding, sizeof( padding ) );
|
||||
mbedtls_platform_zeroize( sha1sum, sizeof( sha1sum ) );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
static int tls1_prf( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
|
@ -735,16 +667,10 @@ static int tls_prf_sha384( const unsigned char *secret, size_t slen,
|
|||
|
||||
static void ssl_update_checksum_start( mbedtls_ssl_context *, const unsigned char *, size_t );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
static void ssl_update_checksum_md5sha1( mbedtls_ssl_context *, const unsigned char *, size_t );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
static void ssl_calc_verify_ssl( const mbedtls_ssl_context *, unsigned char *, size_t * );
|
||||
static void ssl_calc_finished_ssl( mbedtls_ssl_context *, unsigned char *, int );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
static void ssl_calc_verify_tls( const mbedtls_ssl_context *, unsigned char*, size_t * );
|
||||
static void ssl_calc_finished_tls( mbedtls_ssl_context *, unsigned char *, int );
|
||||
|
@ -789,13 +715,6 @@ static int ssl_use_opaque_psk( mbedtls_ssl_context const *ssl )
|
|||
#if defined(MBEDTLS_SSL_EXPORT_KEYS)
|
||||
static mbedtls_tls_prf_types tls_prf_get_type( mbedtls_ssl_tls_prf_cb *tls_prf )
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( tls_prf == ssl3_prf )
|
||||
{
|
||||
return( MBEDTLS_SSL_TLS_PRF_SSL3 );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( tls_prf == tls1_prf )
|
||||
{
|
||||
|
@ -833,11 +752,6 @@ int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf,
|
|||
|
||||
switch( prf )
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
case MBEDTLS_SSL_TLS_PRF_SSL3:
|
||||
tls_prf = ssl3_prf;
|
||||
break;
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
case MBEDTLS_SSL_TLS_PRF_TLS1:
|
||||
tls_prf = tls1_prf;
|
||||
|
@ -886,7 +800,6 @@ typedef int ssl_tls_prf_t(const unsigned char *, size_t, const char *,
|
|||
* - [in] minor_ver: SSL/TLS minor version
|
||||
* - [in] endpoint: client or server
|
||||
* - [in] ssl: optionally used for:
|
||||
* - MBEDTLS_SSL_HW_RECORD_ACCEL: whole context (non-const)
|
||||
* - MBEDTLS_SSL_EXPORT_KEYS: ssl->conf->{f,p}_export_keys
|
||||
* - MBEDTLS_DEBUG_C: ssl->conf->{f,p}_dbg
|
||||
*/
|
||||
|
@ -901,17 +814,11 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
int trunc_hmac,
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
int compression,
|
||||
#endif
|
||||
ssl_tls_prf_t tls_prf,
|
||||
const unsigned char randbytes[64],
|
||||
int minor_ver,
|
||||
unsigned endpoint,
|
||||
#if !defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
const
|
||||
#endif
|
||||
mbedtls_ssl_context *ssl )
|
||||
const mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
|
@ -929,8 +836,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
const mbedtls_cipher_info_t *cipher_info;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
|
||||
#if !defined(MBEDTLS_SSL_HW_RECORD_ACCEL) && \
|
||||
!defined(MBEDTLS_SSL_EXPORT_KEYS) && \
|
||||
#if !defined(MBEDTLS_SSL_EXPORT_KEYS) && \
|
||||
!defined(MBEDTLS_DEBUG_C)
|
||||
ssl = NULL; /* make sure we don't use it except for those cases */
|
||||
(void) ssl;
|
||||
|
@ -1086,13 +992,6 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
if( trunc_hmac == MBEDTLS_SSL_TRUNC_HMAC_ENABLED )
|
||||
{
|
||||
transform->maclen = MBEDTLS_SSL_TRUNCATED_HMAC_LEN;
|
||||
|
||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT)
|
||||
/* Fall back to old, non-compliant version of the truncated
|
||||
* HMAC implementation which also truncates the key
|
||||
* (Mbed TLS versions from 1.3 to 2.6.0) */
|
||||
mac_key_len = transform->maclen;
|
||||
#endif
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
|
||||
|
@ -1108,7 +1007,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
* GenericBlockCipher:
|
||||
* 1. if EtM is in use: one block plus MAC
|
||||
* otherwise: * first multiple of blocklen greater than maclen
|
||||
* 2. IV except for SSL3 and TLS 1.0
|
||||
* 2. IV except for TLS 1.0
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||
if( encrypt_then_mac == MBEDTLS_SSL_ETM_ENABLED )
|
||||
|
@ -1124,9 +1023,8 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
- transform->maclen % cipher_info->block_size;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
if( minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ||
|
||||
minor_ver == MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
if( minor_ver == MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
; /* No need to adjust minlen */
|
||||
else
|
||||
#endif
|
||||
|
@ -1208,21 +1106,6 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
if( mac_key_len > sizeof( transform->mac_enc ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
ret = MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
goto end;
|
||||
}
|
||||
|
||||
memcpy( transform->mac_enc, mac_enc, mac_key_len );
|
||||
memcpy( transform->mac_dec, mac_dec, mac_key_len );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
|
@ -1244,28 +1127,8 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_init != NULL )
|
||||
{
|
||||
ret = 0;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "going for mbedtls_ssl_hw_record_init()" ) );
|
||||
|
||||
if( ( ret = mbedtls_ssl_hw_record_init( ssl, key1, key2, keylen,
|
||||
transform->iv_enc, transform->iv_dec,
|
||||
iv_copy_len,
|
||||
mac_enc, mac_dec,
|
||||
mac_key_len ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_init", ret );
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#else
|
||||
((void) mac_dec);
|
||||
((void) mac_enc);
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
|
||||
#if defined(MBEDTLS_SSL_EXPORT_KEYS)
|
||||
if( ssl->conf->f_export_keys != NULL )
|
||||
|
@ -1411,26 +1274,6 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
|||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
|
||||
/* Initialize Zlib contexts */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "Initializing zlib states" ) );
|
||||
|
||||
memset( &transform->ctx_deflate, 0, sizeof( transform->ctx_deflate ) );
|
||||
memset( &transform->ctx_inflate, 0, sizeof( transform->ctx_inflate ) );
|
||||
|
||||
if( deflateInit( &transform->ctx_deflate,
|
||||
Z_DEFAULT_COMPRESSION ) != Z_OK ||
|
||||
inflateInit( &transform->ctx_inflate ) != Z_OK )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "Failed to initialize compression" ) );
|
||||
ret = MBEDTLS_ERR_SSL_COMPRESSION_FAILED;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_ZLIB_SUPPORT */
|
||||
|
||||
end:
|
||||
mbedtls_platform_zeroize( keyblk, sizeof( keyblk ) );
|
||||
return( ret );
|
||||
|
@ -1454,15 +1297,6 @@ static int ssl_set_handshake_prfs( mbedtls_ssl_handshake_params *handshake,
|
|||
(void) hash;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
handshake->tls_prf = ssl3_prf;
|
||||
handshake->calc_verify = ssl_calc_verify_ssl;
|
||||
handshake->calc_finished = ssl_calc_finished_ssl;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
{
|
||||
|
@ -1511,7 +1345,7 @@ static int ssl_set_handshake_prfs( mbedtls_ssl_handshake_params *handshake,
|
|||
* [out] master
|
||||
* [in] ssl: optionally used for debugging, EMS and PSA-PSK
|
||||
* debug: conf->f_dbg, conf->p_dbg
|
||||
* EMS: passed to calc_verify (debug + (SSL3) session_negotiate)
|
||||
* EMS: passed to calc_verify (debug + session_negotiate)
|
||||
* PSA-PSA: minor_ver, conf
|
||||
*/
|
||||
static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake,
|
||||
|
@ -1692,9 +1526,6 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
|||
ssl->session_negotiate->trunc_hmac,
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
ssl->session_negotiate->compression,
|
||||
#endif
|
||||
ssl->handshake->tls_prf,
|
||||
ssl->handshake->randbytes,
|
||||
ssl->minor_ver,
|
||||
|
@ -1710,80 +1541,11 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
|||
mbedtls_platform_zeroize( ssl->handshake->randbytes,
|
||||
sizeof( ssl->handshake->randbytes ) );
|
||||
|
||||
/* Allocate compression buffer */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->session_negotiate->compression == MBEDTLS_SSL_COMPRESS_DEFLATE &&
|
||||
ssl->compress_buf == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "Allocating compression buffer" ) );
|
||||
ssl->compress_buf = mbedtls_calloc( 1, MBEDTLS_SSL_COMPRESS_BUFFER_LEN );
|
||||
if( ssl->compress_buf == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed",
|
||||
MBEDTLS_SSL_COMPRESS_BUFFER_LEN ) );
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= derive keys" ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
void ssl_calc_verify_ssl( const mbedtls_ssl_context *ssl,
|
||||
unsigned char *hash,
|
||||
size_t *hlen )
|
||||
{
|
||||
mbedtls_md5_context md5;
|
||||
mbedtls_sha1_context sha1;
|
||||
unsigned char pad_1[48];
|
||||
unsigned char pad_2[48];
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> calc verify ssl" ) );
|
||||
|
||||
mbedtls_md5_init( &md5 );
|
||||
mbedtls_sha1_init( &sha1 );
|
||||
|
||||
mbedtls_md5_clone( &md5, &ssl->handshake->fin_md5 );
|
||||
mbedtls_sha1_clone( &sha1, &ssl->handshake->fin_sha1 );
|
||||
|
||||
memset( pad_1, 0x36, 48 );
|
||||
memset( pad_2, 0x5C, 48 );
|
||||
|
||||
mbedtls_md5_update_ret( &md5, ssl->session_negotiate->master, 48 );
|
||||
mbedtls_md5_update_ret( &md5, pad_1, 48 );
|
||||
mbedtls_md5_finish_ret( &md5, hash );
|
||||
|
||||
mbedtls_md5_starts_ret( &md5 );
|
||||
mbedtls_md5_update_ret( &md5, ssl->session_negotiate->master, 48 );
|
||||
mbedtls_md5_update_ret( &md5, pad_2, 48 );
|
||||
mbedtls_md5_update_ret( &md5, hash, 16 );
|
||||
mbedtls_md5_finish_ret( &md5, hash );
|
||||
|
||||
mbedtls_sha1_update_ret( &sha1, ssl->session_negotiate->master, 48 );
|
||||
mbedtls_sha1_update_ret( &sha1, pad_1, 40 );
|
||||
mbedtls_sha1_finish_ret( &sha1, hash + 16 );
|
||||
|
||||
mbedtls_sha1_starts_ret( &sha1 );
|
||||
mbedtls_sha1_update_ret( &sha1, ssl->session_negotiate->master, 48 );
|
||||
mbedtls_sha1_update_ret( &sha1, pad_2, 40 );
|
||||
mbedtls_sha1_update_ret( &sha1, hash + 16, 20 );
|
||||
mbedtls_sha1_finish_ret( &sha1, hash + 16 );
|
||||
|
||||
*hlen = 36;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "calculated verify result", hash, *hlen );
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= calc verify" ) );
|
||||
|
||||
mbedtls_md5_free( &md5 );
|
||||
mbedtls_sha1_free( &sha1 );
|
||||
|
||||
return;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
void ssl_calc_verify_tls( const mbedtls_ssl_context *ssl,
|
||||
unsigned char *hash,
|
||||
|
@ -2167,24 +1929,6 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl )
|
|||
ssl->state++;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
/*
|
||||
* If using SSLv3 and got no cert, send an Alert message
|
||||
* (otherwise an empty Certificate message will be sent).
|
||||
*/
|
||||
if( mbedtls_ssl_own_cert( ssl ) == NULL &&
|
||||
ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
ssl->out_msglen = 2;
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_ALERT;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_ALERT_LEVEL_WARNING;
|
||||
ssl->out_msg[1] = MBEDTLS_SSL_ALERT_MSG_NO_CERT;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "got no certificate to send" ) );
|
||||
goto write_msg;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CLI_C */
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
|
@ -2239,10 +1983,6 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl )
|
|||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE;
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) && defined(MBEDTLS_SSL_CLI_C)
|
||||
write_msg:
|
||||
#endif
|
||||
|
||||
ssl->state++;
|
||||
|
||||
if( ( ret = mbedtls_ssl_write_handshake_msg( ssl ) ) != 0 )
|
||||
|
@ -2462,25 +2202,6 @@ static int ssl_srv_check_client_no_crt_notification( mbedtls_ssl_context *ssl )
|
|||
if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT )
|
||||
return( -1 );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
/*
|
||||
* Check if the client sent an empty certificate
|
||||
*/
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
if( ssl->in_msglen == 2 &&
|
||||
ssl->in_msgtype == MBEDTLS_SSL_MSG_ALERT &&
|
||||
ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING &&
|
||||
ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_CERT )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "SSLv3 client has no certificate" ) );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->in_hslen == 3 + mbedtls_ssl_hs_hdr_len( ssl ) &&
|
||||
|
@ -2929,8 +2650,7 @@ void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
|
|||
{
|
||||
((void) ciphersuite_info);
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
if( ssl->minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
ssl->handshake->update_checksum = ssl_update_checksum_md5sha1;
|
||||
else
|
||||
|
@ -2955,8 +2675,7 @@ void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
|
|||
|
||||
void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
mbedtls_md5_starts_ret( &ssl->handshake->fin_md5 );
|
||||
mbedtls_sha1_starts_ret( &ssl->handshake->fin_sha1 );
|
||||
#endif
|
||||
|
@ -2983,8 +2702,7 @@ void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl )
|
|||
static void ssl_update_checksum_start( mbedtls_ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
mbedtls_md5_update_ret( &ssl->handshake->fin_md5 , buf, len );
|
||||
mbedtls_sha1_update_ret( &ssl->handshake->fin_sha1, buf, len );
|
||||
#endif
|
||||
|
@ -3006,8 +2724,7 @@ static void ssl_update_checksum_start( mbedtls_ssl_context *ssl,
|
|||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
static void ssl_update_checksum_md5sha1( mbedtls_ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
|
@ -3042,91 +2759,6 @@ static void ssl_update_checksum_sha384( mbedtls_ssl_context *ssl,
|
|||
#endif
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
static void ssl_calc_finished_ssl(
|
||||
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
|
||||
{
|
||||
const char *sender;
|
||||
mbedtls_md5_context md5;
|
||||
mbedtls_sha1_context sha1;
|
||||
|
||||
unsigned char padbuf[48];
|
||||
unsigned char md5sum[16];
|
||||
unsigned char sha1sum[20];
|
||||
|
||||
mbedtls_ssl_session *session = ssl->session_negotiate;
|
||||
if( !session )
|
||||
session = ssl->session;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> calc finished ssl" ) );
|
||||
|
||||
mbedtls_md5_init( &md5 );
|
||||
mbedtls_sha1_init( &sha1 );
|
||||
|
||||
mbedtls_md5_clone( &md5, &ssl->handshake->fin_md5 );
|
||||
mbedtls_sha1_clone( &sha1, &ssl->handshake->fin_sha1 );
|
||||
|
||||
/*
|
||||
* SSLv3:
|
||||
* hash =
|
||||
* MD5( master + pad2 +
|
||||
* MD5( handshake + sender + master + pad1 ) )
|
||||
* + SHA1( master + pad2 +
|
||||
* SHA1( handshake + sender + master + pad1 ) )
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_MD5_ALT)
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "finished md5 state", (unsigned char *)
|
||||
md5.state, sizeof( md5.state ) );
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_ALT)
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "finished sha1 state", (unsigned char *)
|
||||
sha1.state, sizeof( sha1.state ) );
|
||||
#endif
|
||||
|
||||
sender = ( from == MBEDTLS_SSL_IS_CLIENT ) ? "CLNT"
|
||||
: "SRVR";
|
||||
|
||||
memset( padbuf, 0x36, 48 );
|
||||
|
||||
mbedtls_md5_update_ret( &md5, (const unsigned char *) sender, 4 );
|
||||
mbedtls_md5_update_ret( &md5, session->master, 48 );
|
||||
mbedtls_md5_update_ret( &md5, padbuf, 48 );
|
||||
mbedtls_md5_finish_ret( &md5, md5sum );
|
||||
|
||||
mbedtls_sha1_update_ret( &sha1, (const unsigned char *) sender, 4 );
|
||||
mbedtls_sha1_update_ret( &sha1, session->master, 48 );
|
||||
mbedtls_sha1_update_ret( &sha1, padbuf, 40 );
|
||||
mbedtls_sha1_finish_ret( &sha1, sha1sum );
|
||||
|
||||
memset( padbuf, 0x5C, 48 );
|
||||
|
||||
mbedtls_md5_starts_ret( &md5 );
|
||||
mbedtls_md5_update_ret( &md5, session->master, 48 );
|
||||
mbedtls_md5_update_ret( &md5, padbuf, 48 );
|
||||
mbedtls_md5_update_ret( &md5, md5sum, 16 );
|
||||
mbedtls_md5_finish_ret( &md5, buf );
|
||||
|
||||
mbedtls_sha1_starts_ret( &sha1 );
|
||||
mbedtls_sha1_update_ret( &sha1, session->master, 48 );
|
||||
mbedtls_sha1_update_ret( &sha1, padbuf , 40 );
|
||||
mbedtls_sha1_update_ret( &sha1, sha1sum, 20 );
|
||||
mbedtls_sha1_finish_ret( &sha1, buf + 16 );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "calc finished result", buf, 36 );
|
||||
|
||||
mbedtls_md5_free( &md5 );
|
||||
mbedtls_sha1_free( &sha1 );
|
||||
|
||||
mbedtls_platform_zeroize( padbuf, sizeof( padbuf ) );
|
||||
mbedtls_platform_zeroize( md5sum, sizeof( md5sum ) );
|
||||
mbedtls_platform_zeroize( sha1sum, sizeof( sha1sum ) );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= calc finished" ) );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
static void ssl_calc_finished_tls(
|
||||
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
|
||||
|
@ -3451,7 +3083,7 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl )
|
|||
* ciphersuite does this (and this is unlikely to change as activity has
|
||||
* moved to TLS 1.3 now) so we can keep the hardcoded 12 here.
|
||||
*/
|
||||
hash_len = ( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ) ? 36 : 12;
|
||||
hash_len = 12;
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
ssl->verify_data_len = hash_len;
|
||||
|
@ -3517,17 +3149,6 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl )
|
|||
ssl->transform_out = ssl->transform_negotiate;
|
||||
ssl->session_out = ssl->session_negotiate;
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_activate != NULL )
|
||||
{
|
||||
if( ( ret = mbedtls_ssl_hw_record_activate( ssl, MBEDTLS_SSL_CHANNEL_OUTBOUND ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_activate", ret );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
mbedtls_ssl_send_flight_completed( ssl );
|
||||
|
@ -3553,11 +3174,7 @@ int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl )
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
#define SSL_MAX_HASH_LEN 36
|
||||
#else
|
||||
#define SSL_MAX_HASH_LEN 12
|
||||
#endif
|
||||
|
||||
int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
|
@ -3583,13 +3200,7 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
|||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
|
||||
/* There is currently no ciphersuite using another length with TLS 1.2 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
hash_len = 36;
|
||||
else
|
||||
#endif
|
||||
hash_len = 12;
|
||||
hash_len = 12;
|
||||
|
||||
if( ssl->in_msg[0] != MBEDTLS_SSL_HS_FINISHED ||
|
||||
ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) + hash_len )
|
||||
|
@ -3642,8 +3253,7 @@ static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake )
|
|||
{
|
||||
memset( handshake, 0, sizeof( mbedtls_ssl_handshake_params ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
mbedtls_md5_init( &handshake->fin_md5 );
|
||||
mbedtls_sha1_init( &handshake->fin_sha1 );
|
||||
mbedtls_md5_starts_ret( &handshake->fin_md5 );
|
||||
|
@ -3998,18 +3608,6 @@ int mbedtls_ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial )
|
|||
memset( ssl->in_buf, 0, in_buf_len );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_reset != NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "going for mbedtls_ssl_hw_record_reset()" ) );
|
||||
if( ( ret = mbedtls_ssl_hw_record_reset( ssl ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_hw_record_reset", ret );
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if( ssl->transform )
|
||||
{
|
||||
mbedtls_ssl_transform_free( ssl->transform );
|
||||
|
@ -4200,13 +3798,60 @@ int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_CLI_C */
|
||||
|
||||
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
|
||||
const int *ciphersuites )
|
||||
static int protocol_version_to_ciphersuites_list_index(int prot_version)
|
||||
{
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] = ciphersuites;
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] = ciphersuites;
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] = ciphersuites;
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] = ciphersuites;
|
||||
switch(prot_version) {
|
||||
case MBEDTLS_SSL_MINOR_VERSION_1:
|
||||
return 0;
|
||||
case MBEDTLS_SSL_MINOR_VERSION_2:
|
||||
return 1;
|
||||
case MBEDTLS_SSL_MINOR_VERSION_3:
|
||||
return 2;
|
||||
default:
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
static void set_protocol_version_ciphersuites( mbedtls_ssl_config *conf,
|
||||
int prot_version,
|
||||
const int* ciphersuites )
|
||||
{
|
||||
int ciphersuite_list_index =
|
||||
protocol_version_to_ciphersuites_list_index(prot_version);
|
||||
if ( ciphersuite_list_index >= 0 &&
|
||||
(unsigned int)ciphersuite_list_index <
|
||||
sizeof(conf->ciphersuite_list)/sizeof(conf->ciphersuite_list[0]) )
|
||||
{
|
||||
conf->ciphersuite_list[ciphersuite_list_index] = ciphersuites;
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
|
||||
const int *ciphersuites )
|
||||
{
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
ciphersuites);
|
||||
}
|
||||
|
||||
const int *mbedtls_ssl_get_protocol_version_ciphersuites(
|
||||
const mbedtls_ssl_config *conf, int prot_version )
|
||||
{
|
||||
int ciphersuite_list_index =
|
||||
protocol_version_to_ciphersuites_list_index(prot_version);
|
||||
if ( ciphersuite_list_index >= 0 &&
|
||||
(unsigned int)ciphersuite_list_index <
|
||||
sizeof(conf->ciphersuite_list)/sizeof(conf->ciphersuite_list[0]) )
|
||||
{
|
||||
return conf->ciphersuite_list[ciphersuite_list_index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
|
||||
|
@ -4216,10 +3861,10 @@ void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
|
|||
if( major != MBEDTLS_SSL_MAJOR_VERSION_3 )
|
||||
return;
|
||||
|
||||
if( minor < MBEDTLS_SSL_MINOR_VERSION_0 || minor > MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
if( minor < MBEDTLS_SSL_MINOR_VERSION_1 || minor > MBEDTLS_SSL_MINOR_VERSION_3 )
|
||||
return;
|
||||
|
||||
conf->ciphersuite_list[minor] = ciphersuites;
|
||||
set_protocol_version_ciphersuites(conf, minor, ciphersuites);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
|
@ -4831,13 +4476,6 @@ void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 )
|
||||
{
|
||||
conf->arc4_disabled = arc4;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||
int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code )
|
||||
{
|
||||
|
@ -5009,9 +4647,6 @@ const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl )
|
|||
|
||||
switch( ssl->minor_ver )
|
||||
{
|
||||
case MBEDTLS_SSL_MINOR_VERSION_0:
|
||||
return( "SSLv3.0" );
|
||||
|
||||
case MBEDTLS_SSL_MINOR_VERSION_1:
|
||||
return( "TLSv1.0" );
|
||||
|
||||
|
@ -5977,8 +5612,7 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_context *ssl )
|
|||
}
|
||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
mbedtls_md5_free( &handshake->fin_md5 );
|
||||
mbedtls_sha1_free( &handshake->fin_sha1 );
|
||||
#endif
|
||||
|
@ -6560,9 +6194,6 @@ static int ssl_context_load( mbedtls_ssl_context *ssl,
|
|||
ssl->session->trunc_hmac,
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
ssl->session->compression,
|
||||
#endif
|
||||
ssl_tls12prf_from_cs( ssl->session->ciphersuite ),
|
||||
p, /* currently pointing to randbytes */
|
||||
MBEDTLS_SSL_MINOR_VERSION_3, /* (D)TLS 1.2 is forced */
|
||||
|
@ -6778,14 +6409,6 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
|
|||
ssl->in_buf = NULL;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->compress_buf != NULL )
|
||||
{
|
||||
mbedtls_platform_zeroize( ssl->compress_buf, MBEDTLS_SSL_COMPRESS_BUFFER_LEN );
|
||||
mbedtls_free( ssl->compress_buf );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( ssl->transform )
|
||||
{
|
||||
mbedtls_ssl_transform_free( ssl->transform );
|
||||
|
@ -6817,14 +6440,6 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_finish != NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "going for mbedtls_ssl_hw_record_finish()" ) );
|
||||
mbedtls_ssl_hw_record_finish( ssl );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
|
||||
mbedtls_free( ssl->cli_id );
|
||||
#endif
|
||||
|
@ -6914,10 +6529,6 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
conf->arc4_disabled = MBEDTLS_SSL_ARC4_DISABLED;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||
conf->encrypt_then_mac = MBEDTLS_SSL_ETM_ENABLED;
|
||||
#endif
|
||||
|
@ -6985,11 +6596,12 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
|
|||
conf->max_major_ver = MBEDTLS_SSL_MAX_MAJOR_VERSION;
|
||||
conf->max_minor_ver = MBEDTLS_SSL_MAX_MINOR_VERSION;
|
||||
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] =
|
||||
ssl_preset_suiteb_ciphersuites;
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
ssl_preset_suiteb_ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
ssl_preset_suiteb_ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
ssl_preset_suiteb_ciphersuites);
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
conf->cert_profile = &mbedtls_x509_crt_profile_suiteb;
|
||||
|
@ -7023,12 +6635,13 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
|
|||
if( transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
conf->min_minor_ver = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||
#endif
|
||||
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] =
|
||||
conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] =
|
||||
mbedtls_ssl_list_ciphersuites();
|
||||
const int* default_ciphersuites = mbedtls_ssl_list_ciphersuites();
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
default_ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
default_ciphersuites);
|
||||
set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
|
||||
default_ciphersuites);
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
conf->cert_profile = &mbedtls_x509_crt_profile_default;
|
||||
|
@ -7423,8 +7036,7 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md )
|
|||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl,
|
||||
unsigned char *output,
|
||||
unsigned char *data, size_t data_len )
|
||||
|
@ -7506,8 +7118,7 @@ exit:
|
|||
return( ret );
|
||||
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
|
||||
MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
|
@ -7567,7 +7178,7 @@ exit:
|
|||
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
||||
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
|
||||
default:
|
||||
return( MBEDTLS_ERR_MD_HW_ACCEL_FAILED );
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
return( 0 );
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
|
||||
|
||||
#include "mbedtls/hkdf.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#include "ssl_misc.h"
|
||||
#include "ssl_tls13_keys.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -303,9 +303,6 @@ static const char * const features[] = {
|
|||
#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_REMOVE_3DES_CIPHERSUITES)
|
||||
"MBEDTLS_REMOVE_3DES_CIPHERSUITES",
|
||||
#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */
|
||||
|
@ -501,27 +498,18 @@ static const char * const features[] = {
|
|||
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
"MBEDTLS_SSL_KEEP_PEER_CERTIFICATE",
|
||||
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
#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 */
|
||||
|
@ -567,9 +555,6 @@ static const char * const features[] = {
|
|||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||
"MBEDTLS_SSL_TRUNCATED_HMAC",
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT)
|
||||
"MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT",
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT */
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
"MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH",
|
||||
#endif /* MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH */
|
||||
|
@ -615,9 +600,6 @@ static const char * const features[] = {
|
|||
#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 */
|
||||
|
@ -651,9 +633,6 @@ static const char * const features[] = {
|
|||
#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_CHACHA20_C)
|
||||
"MBEDTLS_CHACHA20_C",
|
||||
#endif /* MBEDTLS_CHACHA20_C */
|
||||
|
@ -699,9 +678,6 @@ static const char * const features[] = {
|
|||
#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_HKDF_C)
|
||||
"MBEDTLS_HKDF_C",
|
||||
#endif /* MBEDTLS_HKDF_C */
|
||||
|
@ -753,9 +729,6 @@ static const char * const features[] = {
|
|||
#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 */
|
||||
|
|
|
@ -995,73 +995,4 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
|
|||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_HAVE_TIME_DATE */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#include "mbedtls/x509_crt.h"
|
||||
#include "mbedtls/certs.h"
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_x509_self_test( int verbose )
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_SHA256_C)
|
||||
uint32_t flags;
|
||||
mbedtls_x509_crt cacert;
|
||||
mbedtls_x509_crt clicert;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " X.509 certificate load: " );
|
||||
|
||||
mbedtls_x509_crt_init( &cacert );
|
||||
mbedtls_x509_crt_init( &clicert );
|
||||
|
||||
ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt,
|
||||
mbedtls_test_cli_crt_len );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_ca_crt,
|
||||
mbedtls_test_ca_crt_len );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n X.509 signature verify: ");
|
||||
|
||||
ret = mbedtls_x509_crt_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n\n");
|
||||
|
||||
cleanup:
|
||||
mbedtls_x509_crt_free( &cacert );
|
||||
mbedtls_x509_crt_free( &clicert );
|
||||
#else
|
||||
((void) verbose);
|
||||
#endif /* MBEDTLS_CERTS_C && MBEDTLS_SHA256_C */
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_X509_USE_C */
|
||||
|
|
|
@ -96,10 +96,6 @@ typedef struct {
|
|||
*/
|
||||
const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default =
|
||||
{
|
||||
#if defined(MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES)
|
||||
/* Allow SHA-1 (weak, but still safe in controlled environments) */
|
||||
MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ) |
|
||||
#endif
|
||||
/* Only SHA-2 hashes */
|
||||
MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ) |
|
||||
MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue