mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
(mbedtls) Get rid of MBEDTLS_SELF_TEST
This commit is contained in:
parent
be289a4292
commit
8fe5ad8fd4
461
deps/mbedtls/aes.c
vendored
461
deps/mbedtls/aes.c
vendored
@ -43,15 +43,6 @@
|
||||
#include "mbedtls/aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_AES_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -1050,456 +1041,4 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
|
||||
#endif /* !MBEDTLS_AES_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* AES test vectors from:
|
||||
*
|
||||
* http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
|
||||
*/
|
||||
static const unsigned char aes_test_ecb_dec[3][16] =
|
||||
{
|
||||
{ 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
|
||||
0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
|
||||
{ 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
|
||||
0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
|
||||
{ 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
|
||||
0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_ecb_enc[3][16] =
|
||||
{
|
||||
{ 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
|
||||
0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
|
||||
{ 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
|
||||
0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
|
||||
{ 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
|
||||
0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
static const unsigned char aes_test_cbc_dec[3][16] =
|
||||
{
|
||||
{ 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
|
||||
0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 },
|
||||
{ 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75,
|
||||
0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B },
|
||||
{ 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75,
|
||||
0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_cbc_enc[3][16] =
|
||||
{
|
||||
{ 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84,
|
||||
0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D },
|
||||
{ 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB,
|
||||
0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 },
|
||||
{ 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
|
||||
0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
|
||||
};
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
/*
|
||||
* AES-CFB128 test vectors from:
|
||||
*
|
||||
* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
|
||||
*/
|
||||
static const unsigned char aes_test_cfb128_key[3][32] =
|
||||
{
|
||||
{ 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
|
||||
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
|
||||
{ 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
|
||||
0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
|
||||
0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
|
||||
{ 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
|
||||
0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
|
||||
0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
|
||||
0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_cfb128_iv[16] =
|
||||
{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_cfb128_pt[64] =
|
||||
{
|
||||
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
|
||||
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
|
||||
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
|
||||
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
|
||||
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
|
||||
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
|
||||
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
|
||||
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_cfb128_ct[3][64] =
|
||||
{
|
||||
{ 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
|
||||
0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
|
||||
0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F,
|
||||
0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B,
|
||||
0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40,
|
||||
0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF,
|
||||
0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E,
|
||||
0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 },
|
||||
{ 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
|
||||
0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
|
||||
0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21,
|
||||
0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A,
|
||||
0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1,
|
||||
0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9,
|
||||
0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0,
|
||||
0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF },
|
||||
{ 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
|
||||
0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
|
||||
0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8,
|
||||
0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B,
|
||||
0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92,
|
||||
0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9,
|
||||
0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
|
||||
0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
|
||||
};
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/*
|
||||
* AES-CTR test vectors from:
|
||||
*
|
||||
* http://www.faqs.org/rfcs/rfc3686.html
|
||||
*/
|
||||
|
||||
static const unsigned char aes_test_ctr_key[3][16] =
|
||||
{
|
||||
{ 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
|
||||
0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
|
||||
{ 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
|
||||
0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
|
||||
{ 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
|
||||
0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_ctr_nonce_counter[3][16] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
|
||||
0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
|
||||
0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_ctr_pt[3][48] =
|
||||
{
|
||||
{ 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
|
||||
0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
|
||||
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
|
||||
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23 }
|
||||
};
|
||||
|
||||
static const unsigned char aes_test_ctr_ct[3][48] =
|
||||
{
|
||||
{ 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79,
|
||||
0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 },
|
||||
{ 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9,
|
||||
0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88,
|
||||
0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8,
|
||||
0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 },
|
||||
{ 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
|
||||
0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
|
||||
0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
|
||||
0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
|
||||
0x25, 0xB2, 0x07, 0x2F }
|
||||
};
|
||||
|
||||
static const int aes_test_ctr_len[3] =
|
||||
{ 16, 32, 36 };
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_aes_self_test( int verbose )
|
||||
{
|
||||
int ret = 0, i, j, u, v;
|
||||
unsigned char key[32];
|
||||
unsigned char buf[64];
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
unsigned char iv[16];
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
unsigned char prv[16];
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
size_t offset;
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
int len;
|
||||
unsigned char nonce_counter[16];
|
||||
unsigned char stream_block[16];
|
||||
#endif
|
||||
mbedtls_aes_context ctx;
|
||||
|
||||
memset( key, 0, 32 );
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
/*
|
||||
* ECB mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-ECB-%3d (%s): ", 128 + u * 64,
|
||||
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memset( buf, 0, 16 );
|
||||
|
||||
if( v == MBEDTLS_AES_DECRYPT )
|
||||
{
|
||||
mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/*
|
||||
* CBC mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memset( iv , 0, 16 );
|
||||
memset( prv, 0, 16 );
|
||||
memset( buf, 0, 16 );
|
||||
|
||||
if( v == MBEDTLS_AES_DECRYPT )
|
||||
{
|
||||
mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
unsigned char tmp[16];
|
||||
|
||||
mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
|
||||
|
||||
memcpy( tmp, prv, 16 );
|
||||
memcpy( prv, buf, 16 );
|
||||
memcpy( buf, tmp, 16 );
|
||||
}
|
||||
|
||||
if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
/*
|
||||
* CFB128 mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-CFB128-%3d (%s): ", 128 + u * 64,
|
||||
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( iv, aes_test_cfb128_iv, 16 );
|
||||
memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 );
|
||||
|
||||
offset = 0;
|
||||
mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
|
||||
|
||||
if( v == MBEDTLS_AES_DECRYPT )
|
||||
{
|
||||
memcpy( buf, aes_test_cfb128_ct[u], 64 );
|
||||
mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( buf, aes_test_cfb128_pt, 64 );
|
||||
mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/*
|
||||
* CTR mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-CTR-128 (%s): ",
|
||||
( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 );
|
||||
memcpy( key, aes_test_ctr_key[u], 16 );
|
||||
|
||||
offset = 0;
|
||||
mbedtls_aes_setkey_enc( &ctx, key, 128 );
|
||||
|
||||
if( v == MBEDTLS_AES_DECRYPT )
|
||||
{
|
||||
len = aes_test_ctr_len[u];
|
||||
memcpy( buf, aes_test_ctr_ct[u], len );
|
||||
|
||||
mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
|
||||
buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
len = aes_test_ctr_len[u];
|
||||
memcpy( buf, aes_test_ctr_pt[u], len );
|
||||
|
||||
mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
|
||||
buf, buf );
|
||||
|
||||
if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
mbedtls_aes_free( &ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
82
deps/mbedtls/arc4.c
vendored
82
deps/mbedtls/arc4.c
vendored
@ -36,15 +36,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_ARC4_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -126,77 +117,4 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
|
||||
|
||||
#endif /* !MBEDTLS_ARC4_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* ARC4 tests vectors as posted by Eric Rescorla in sep. 1994:
|
||||
*
|
||||
* http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0
|
||||
*/
|
||||
static const unsigned char arc4_test_key[3][8] =
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
};
|
||||
|
||||
static const unsigned char arc4_test_pt[3][8] =
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
};
|
||||
|
||||
static const unsigned char arc4_test_ct[3][8] =
|
||||
{
|
||||
{ 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 },
|
||||
{ 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 },
|
||||
{ 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_arc4_self_test( int verbose )
|
||||
{
|
||||
int i, ret = 0;
|
||||
unsigned char ibuf[8];
|
||||
unsigned char obuf[8];
|
||||
mbedtls_arc4_context ctx;
|
||||
|
||||
mbedtls_arc4_init( &ctx );
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ARC4 test #%d: ", i + 1 );
|
||||
|
||||
memcpy( ibuf, arc4_test_pt[i], 8 );
|
||||
|
||||
mbedtls_arc4_setup( &ctx, arc4_test_key[i], 8 );
|
||||
mbedtls_arc4_crypt( &ctx, 8, ibuf, obuf );
|
||||
|
||||
if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_arc4_free( &ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
14
deps/mbedtls/asn1parse.c
vendored
14
deps/mbedtls/asn1parse.c
vendored
@ -35,13 +35,7 @@
|
||||
#include "mbedtls/bignum.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
@ -266,7 +260,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
|
||||
/* Allocate and assign next pointer */
|
||||
if( *p < end )
|
||||
{
|
||||
cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
|
||||
cur->next = (mbedtls_asn1_sequence*)calloc( 1,
|
||||
sizeof( mbedtls_asn1_sequence ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
@ -352,8 +346,8 @@ void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur )
|
||||
if( cur == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_free( cur->oid.p );
|
||||
mbedtls_free( cur->val.p );
|
||||
free( cur->oid.p );
|
||||
free( cur->val.p );
|
||||
|
||||
mbedtls_zeroize( cur, sizeof( mbedtls_asn1_named_data ) );
|
||||
}
|
||||
@ -366,7 +360,7 @@ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
|
||||
{
|
||||
*head = cur->next;
|
||||
mbedtls_asn1_free_named_data( cur );
|
||||
mbedtls_free( cur );
|
||||
free( cur );
|
||||
}
|
||||
}
|
||||
|
||||
|
73
deps/mbedtls/base64.c
vendored
73
deps/mbedtls/base64.c
vendored
@ -31,16 +31,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#include <string.h>
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
static const unsigned char base64_enc_map[64] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
@ -227,67 +217,4 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
static const unsigned char base64_test_dec[64] =
|
||||
{
|
||||
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
|
||||
0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
|
||||
0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
|
||||
0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
|
||||
0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
|
||||
0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
|
||||
0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
|
||||
0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
|
||||
};
|
||||
|
||||
static const unsigned char base64_test_enc[] =
|
||||
"JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
|
||||
"swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_base64_self_test( int verbose )
|
||||
{
|
||||
size_t len;
|
||||
const unsigned char *src;
|
||||
unsigned char buffer[128];
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " Base64 encoding test: " );
|
||||
|
||||
src = base64_test_dec;
|
||||
|
||||
if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
|
||||
memcmp( base64_test_enc, buffer, 88 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n Base64 decoding test: " );
|
||||
|
||||
src = base64_test_enc;
|
||||
|
||||
if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
|
||||
memcmp( base64_test_dec, buffer, 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_BASE64_C */
|
||||
|
174
deps/mbedtls/bignum.c
vendored
174
deps/mbedtls/bignum.c
vendored
@ -2270,178 +2270,4 @@ cleanup:
|
||||
|
||||
#endif /* MBEDTLS_GENPRIME */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#define GCD_PAIR_COUNT 3
|
||||
|
||||
static const int gcd_pairs[GCD_PAIR_COUNT][3] =
|
||||
{
|
||||
{ 693, 609, 21 },
|
||||
{ 1764, 868, 28 },
|
||||
{ 768454923, 542167814, 1 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_mpi_self_test( int verbose )
|
||||
{
|
||||
int ret, i;
|
||||
mbedtls_mpi A, E, N, X, Y, U, V;
|
||||
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &X );
|
||||
mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &U ); mbedtls_mpi_init( &V );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &A, 16,
|
||||
"EFE021C2645FD1DC586E69184AF4A31E" \
|
||||
"D5F53E93B5F123FA41680867BA110131" \
|
||||
"944FE7952E2517337780CB0DB80E61AA" \
|
||||
"E7C8DDC6C5C6AADEB34EB38A2F40D5E6" ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &E, 16,
|
||||
"B2E7EFD37075B9F03FF989C7C5051C20" \
|
||||
"34D2A323810251127E7BF8625A4F49A5" \
|
||||
"F3E27F4DA8BD59C47D6DAABA4C8127BD" \
|
||||
"5B5C25763222FEFCCFC38B832366C29E" ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &N, 16,
|
||||
"0066A198186C18C10B2F5ED9B522752A" \
|
||||
"9830B69916E535C8F047518A889A43A5" \
|
||||
"94B6BED27A168D31D4A52F88925AA8F5" ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &X, &A, &N ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
|
||||
"602AB7ECA597A3D6B56FF9829A5E8B85" \
|
||||
"9E857EA95A03512E2BAE7391688D264A" \
|
||||
"A5663B0341DB9CCFD2C4C5F421FEC814" \
|
||||
"8001B72E848A38CAE1C65F78E56ABDEF" \
|
||||
"E12D3C039B8A02D6BE593F0BBBDA56F1" \
|
||||
"ECF677152EF804370C1A305CAF3B5BF1" \
|
||||
"30879B56C61DE584A0F53A2447A51E" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MPI test #1 (mul_mpi): " );
|
||||
|
||||
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &X, &Y, &A, &N ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
|
||||
"256567336059E52CAE22925474705F39A94" ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &V, 16,
|
||||
"6613F26162223DF488E9CD48CC132C7A" \
|
||||
"0AC93C701B001B092E4E5B9F73BCD27B" \
|
||||
"9EE50D0657C77F374E903CDFA4C642" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MPI test #2 (div_mpi): " );
|
||||
|
||||
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ||
|
||||
mbedtls_mpi_cmp_mpi( &Y, &V ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
|
||||
"36E139AEA55215609D2816998ED020BB" \
|
||||
"BD96C37890F65171D948E9BC7CBAA4D9" \
|
||||
"325D24D6A3C12710F10A09FA08AB87" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MPI test #3 (exp_mod): " );
|
||||
|
||||
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &X, &A, &N ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
|
||||
"003A0AAEDD7E784FC07D8F9EC6E3BFD5" \
|
||||
"C3DBA76456363A10869622EAC2DD84EC" \
|
||||
"C5B8A74DAC4D09E03B5E0BE779F2DF61" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MPI test #4 (inv_mod): " );
|
||||
|
||||
if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MPI test #5 (simple gcd): " );
|
||||
|
||||
for( i = 0; i < GCD_PAIR_COUNT; i++ )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &X, gcd_pairs[i][0] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Y, gcd_pairs[i][1] ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &A, &X, &Y ) );
|
||||
|
||||
if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed at %d\n", i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
|
||||
if( ret != 0 && verbose != 0 )
|
||||
mbedtls_printf( "Unexpected error, return code = %08X\n", ret );
|
||||
|
||||
mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X );
|
||||
mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &U ); mbedtls_mpi_free( &V );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
387
deps/mbedtls/camellia.c
vendored
387
deps/mbedtls/camellia.c
vendored
@ -37,15 +37,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_CAMELLIA_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -688,382 +679,4 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
#endif /* !MBEDTLS_CAMELLIA_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* Camellia test vectors from:
|
||||
*
|
||||
* http://info.isl.ntt.co.jp/crypt/eng/camellia/technology.html:
|
||||
* http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/intermediate.txt
|
||||
* http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt
|
||||
* (For each bitlength: Key 0, Nr 39)
|
||||
*/
|
||||
#define CAMELLIA_TESTS_ECB 2
|
||||
|
||||
static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] =
|
||||
{
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
},
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
},
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
},
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] =
|
||||
{
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] =
|
||||
{
|
||||
{
|
||||
{ 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
|
||||
0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
|
||||
{ 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE,
|
||||
0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 }
|
||||
},
|
||||
{
|
||||
{ 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
|
||||
0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
|
||||
{ 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9,
|
||||
0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 }
|
||||
},
|
||||
{
|
||||
{ 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
|
||||
0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
|
||||
{ 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C,
|
||||
0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 }
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
#define CAMELLIA_TESTS_CBC 3
|
||||
|
||||
static const unsigned char camellia_test_cbc_key[3][32] =
|
||||
{
|
||||
{ 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
|
||||
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
|
||||
,
|
||||
{ 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
|
||||
0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
|
||||
0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }
|
||||
,
|
||||
{ 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
|
||||
0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
|
||||
0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
|
||||
0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_cbc_iv[16] =
|
||||
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
|
||||
;
|
||||
|
||||
static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] =
|
||||
{
|
||||
{ 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
|
||||
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A },
|
||||
{ 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
|
||||
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 },
|
||||
{ 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
|
||||
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF }
|
||||
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] =
|
||||
{
|
||||
{
|
||||
{ 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
|
||||
0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB },
|
||||
{ 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78,
|
||||
0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 },
|
||||
{ 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B,
|
||||
0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 }
|
||||
},
|
||||
{
|
||||
{ 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
|
||||
0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 },
|
||||
{ 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42,
|
||||
0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 },
|
||||
{ 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8,
|
||||
0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 }
|
||||
},
|
||||
{
|
||||
{ 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
|
||||
0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA },
|
||||
{ 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40,
|
||||
0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 },
|
||||
{ 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA,
|
||||
0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 }
|
||||
}
|
||||
};
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/*
|
||||
* Camellia-CTR test vectors from:
|
||||
*
|
||||
* http://www.faqs.org/rfcs/rfc5528.html
|
||||
*/
|
||||
|
||||
static const unsigned char camellia_test_ctr_key[3][16] =
|
||||
{
|
||||
{ 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
|
||||
0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
|
||||
{ 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
|
||||
0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
|
||||
{ 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
|
||||
0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_ctr_nonce_counter[3][16] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
|
||||
0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
|
||||
0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_ctr_pt[3][48] =
|
||||
{
|
||||
{ 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
|
||||
0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
|
||||
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
|
||||
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23 }
|
||||
};
|
||||
|
||||
static const unsigned char camellia_test_ctr_ct[3][48] =
|
||||
{
|
||||
{ 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A,
|
||||
0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F },
|
||||
{ 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4,
|
||||
0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44,
|
||||
0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7,
|
||||
0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 },
|
||||
{ 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88,
|
||||
0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73,
|
||||
0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1,
|
||||
0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD,
|
||||
0xDF, 0x50, 0x86, 0x96 }
|
||||
};
|
||||
|
||||
static const int camellia_test_ctr_len[3] =
|
||||
{ 16, 32, 36 };
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_camellia_self_test( int verbose )
|
||||
{
|
||||
int i, j, u, v;
|
||||
unsigned char key[32];
|
||||
unsigned char buf[64];
|
||||
unsigned char src[16];
|
||||
unsigned char dst[16];
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
unsigned char iv[16];
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
size_t offset, len;
|
||||
unsigned char nonce_counter[16];
|
||||
unsigned char stream_block[16];
|
||||
#endif
|
||||
|
||||
mbedtls_camellia_context ctx;
|
||||
|
||||
memset( key, 0, 32 );
|
||||
|
||||
for( j = 0; j < 6; j++ ) {
|
||||
u = j >> 1;
|
||||
v = j & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
|
||||
(v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
|
||||
|
||||
for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
|
||||
memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u );
|
||||
|
||||
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
|
||||
mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
|
||||
memcpy( src, camellia_test_ecb_cipher[u][i], 16 );
|
||||
memcpy( dst, camellia_test_ecb_plain[i], 16 );
|
||||
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
|
||||
mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
|
||||
memcpy( src, camellia_test_ecb_plain[i], 16 );
|
||||
memcpy( dst, camellia_test_ecb_cipher[u][i], 16 );
|
||||
}
|
||||
|
||||
mbedtls_camellia_crypt_ecb( &ctx, v, src, buf );
|
||||
|
||||
if( memcmp( buf, dst, 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/*
|
||||
* CBC mode
|
||||
*/
|
||||
for( j = 0; j < 6; j++ )
|
||||
{
|
||||
u = j >> 1;
|
||||
v = j & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( src, camellia_test_cbc_iv, 16 );
|
||||
memcpy( dst, camellia_test_cbc_iv, 16 );
|
||||
memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u );
|
||||
|
||||
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
|
||||
mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
|
||||
} else {
|
||||
mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
|
||||
}
|
||||
|
||||
for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) {
|
||||
|
||||
if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
|
||||
memcpy( iv , src, 16 );
|
||||
memcpy( src, camellia_test_cbc_cipher[u][i], 16 );
|
||||
memcpy( dst, camellia_test_cbc_plain[i], 16 );
|
||||
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
|
||||
memcpy( iv , dst, 16 );
|
||||
memcpy( src, camellia_test_cbc_plain[i], 16 );
|
||||
memcpy( dst, camellia_test_cbc_cipher[u][i], 16 );
|
||||
}
|
||||
|
||||
mbedtls_camellia_crypt_cbc( &ctx, v, 16, iv, src, buf );
|
||||
|
||||
if( memcmp( buf, dst, 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/*
|
||||
* CTR mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CAMELLIA-CTR-128 (%s): ",
|
||||
( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 );
|
||||
memcpy( key, camellia_test_ctr_key[u], 16 );
|
||||
|
||||
offset = 0;
|
||||
mbedtls_camellia_setkey_enc( &ctx, key, 128 );
|
||||
|
||||
if( v == MBEDTLS_CAMELLIA_DECRYPT )
|
||||
{
|
||||
len = camellia_test_ctr_len[u];
|
||||
memcpy( buf, camellia_test_ctr_ct[u], len );
|
||||
|
||||
mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
|
||||
buf, buf );
|
||||
|
||||
if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
len = camellia_test_ctr_len[u];
|
||||
memcpy( buf, camellia_test_ctr_pt[u], len );
|
||||
|
||||
mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
|
||||
buf, buf );
|
||||
|
||||
if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_CAMELLIA_C */
|
||||
|
122
deps/mbedtls/ccm.c
vendored
122
deps/mbedtls/ccm.c
vendored
@ -40,15 +40,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
#define CCM_ENCRYPT 0
|
||||
@ -345,117 +336,4 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
/*
|
||||
* Examples 1 to 3 from SP800-38C Appendix C
|
||||
*/
|
||||
|
||||
#define NB_TESTS 3
|
||||
|
||||
/*
|
||||
* The data is the same for all tests, only the used length changes
|
||||
*/
|
||||
static const unsigned char ccm_key[] = {
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
|
||||
};
|
||||
|
||||
static const unsigned char iv[] = {
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b
|
||||
};
|
||||
|
||||
static const unsigned char ad[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13
|
||||
};
|
||||
|
||||
static const unsigned char msg[] = {
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
};
|
||||
|
||||
static const size_t iv_len [NB_TESTS] = { 7, 8, 12 };
|
||||
static const size_t add_len[NB_TESTS] = { 8, 16, 20 };
|
||||
static const size_t msg_len[NB_TESTS] = { 4, 16, 24 };
|
||||
static const size_t tag_len[NB_TESTS] = { 4, 6, 8 };
|
||||
|
||||
static const unsigned char res[NB_TESTS][32] = {
|
||||
{ 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d },
|
||||
{ 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62,
|
||||
0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d,
|
||||
0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd },
|
||||
{ 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a,
|
||||
0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b,
|
||||
0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5,
|
||||
0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 }
|
||||
};
|
||||
|
||||
int mbedtls_ccm_self_test( int verbose )
|
||||
{
|
||||
mbedtls_ccm_context ctx;
|
||||
unsigned char out[32];
|
||||
size_t i;
|
||||
int ret;
|
||||
|
||||
mbedtls_ccm_init( &ctx );
|
||||
|
||||
if( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, ccm_key, 8 * sizeof ccm_key ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CCM: setup failed" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
for( i = 0; i < NB_TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CCM-AES #%u: ", (unsigned int) i + 1 );
|
||||
|
||||
ret = mbedtls_ccm_encrypt_and_tag( &ctx, msg_len[i],
|
||||
iv, iv_len[i], ad, add_len[i],
|
||||
msg, out,
|
||||
out + msg_len[i], tag_len[i] );
|
||||
|
||||
if( ret != 0 ||
|
||||
memcmp( out, res[i], msg_len[i] + tag_len[i] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
ret = mbedtls_ccm_auth_decrypt( &ctx, msg_len[i],
|
||||
iv, iv_len[i], ad, add_len[i],
|
||||
res[i], out,
|
||||
res[i] + msg_len[i], tag_len[i] );
|
||||
|
||||
if( ret != 0 ||
|
||||
memcmp( out, msg, msg_len[i] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
mbedtls_ccm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
615
deps/mbedtls/cmac.c
vendored
615
deps/mbedtls/cmac.c
vendored
@ -53,17 +53,7 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
@ -225,7 +215,7 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
|
||||
/* Allocated and initialise in the cipher context memory for the CMAC
|
||||
* context */
|
||||
cmac_ctx = mbedtls_calloc( 1, sizeof( mbedtls_cmac_context_t ) );
|
||||
cmac_ctx = calloc( 1, sizeof( mbedtls_cmac_context_t ) );
|
||||
if( cmac_ctx == NULL )
|
||||
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
|
||||
|
||||
@ -465,607 +455,4 @@ exit:
|
||||
}
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* CMAC test data for SP800-38B
|
||||
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CMAC.pdf
|
||||
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/TDES_CMAC.pdf
|
||||
*
|
||||
* AES-CMAC-PRF-128 test data from RFC 4615
|
||||
* https://tools.ietf.org/html/rfc4615#page-4
|
||||
*/
|
||||
|
||||
#define NB_CMAC_TESTS_PER_KEY 4
|
||||
#define NB_PRF_TESTS 3
|
||||
|
||||
#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C)
|
||||
/* All CMAC test inputs are truncated from the same 64 byte buffer. */
|
||||
static const unsigned char test_message[] = {
|
||||
/* PT */
|
||||
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
||||
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
||||
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
||||
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
|
||||
};
|
||||
#endif /* MBEDTLS_AES_C || MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
/* Truncation point of message for AES CMAC tests */
|
||||
static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
||||
/* Mlen */
|
||||
0,
|
||||
16,
|
||||
20,
|
||||
64
|
||||
};
|
||||
|
||||
/* CMAC-AES128 Test Data */
|
||||
static const unsigned char aes_128_key[16] = {
|
||||
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
|
||||
};
|
||||
static const unsigned char aes_128_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* K1 */
|
||||
0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66,
|
||||
0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde
|
||||
},
|
||||
{
|
||||
/* K2 */
|
||||
0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc,
|
||||
0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b
|
||||
}
|
||||
};
|
||||
static const unsigned char aes_128_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* Example #1 */
|
||||
0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
||||
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
|
||||
},
|
||||
{
|
||||
/* Example #2 */
|
||||
0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
||||
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
|
||||
},
|
||||
{
|
||||
/* Example #3 */
|
||||
0x7d, 0x85, 0x44, 0x9e, 0xa6, 0xea, 0x19, 0xc8,
|
||||
0x23, 0xa7, 0xbf, 0x78, 0x83, 0x7d, 0xfa, 0xde
|
||||
},
|
||||
{
|
||||
/* Example #4 */
|
||||
0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
||||
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
|
||||
}
|
||||
};
|
||||
|
||||
/* CMAC-AES192 Test Data */
|
||||
static const unsigned char aes_192_key[24] = {
|
||||
0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
|
||||
0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
|
||||
0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
|
||||
};
|
||||
static const unsigned char aes_192_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* K1 */
|
||||
0x44, 0x8a, 0x5b, 0x1c, 0x93, 0x51, 0x4b, 0x27,
|
||||
0x3e, 0xe6, 0x43, 0x9d, 0xd4, 0xda, 0xa2, 0x96
|
||||
},
|
||||
{
|
||||
/* K2 */
|
||||
0x89, 0x14, 0xb6, 0x39, 0x26, 0xa2, 0x96, 0x4e,
|
||||
0x7d, 0xcc, 0x87, 0x3b, 0xa9, 0xb5, 0x45, 0x2c
|
||||
}
|
||||
};
|
||||
static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* Example #1 */
|
||||
0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
|
||||
0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
|
||||
},
|
||||
{
|
||||
/* Example #2 */
|
||||
0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
|
||||
0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
|
||||
},
|
||||
{
|
||||
/* Example #3 */
|
||||
0x3d, 0x75, 0xc1, 0x94, 0xed, 0x96, 0x07, 0x04,
|
||||
0x44, 0xa9, 0xfa, 0x7e, 0xc7, 0x40, 0xec, 0xf8
|
||||
},
|
||||
{
|
||||
/* Example #4 */
|
||||
0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
|
||||
0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
|
||||
}
|
||||
};
|
||||
|
||||
/* CMAC-AES256 Test Data */
|
||||
static const unsigned char aes_256_key[32] = {
|
||||
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
|
||||
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
|
||||
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
|
||||
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
|
||||
};
|
||||
static const unsigned char aes_256_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* K1 */
|
||||
0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac,
|
||||
0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f
|
||||
},
|
||||
{
|
||||
/* K2 */
|
||||
0x95, 0xa3, 0xda, 0x06, 0x53, 0x3d, 0xdb, 0x58,
|
||||
0x5d, 0x35, 0x33, 0x01, 0x0c, 0x42, 0xa0, 0xd9
|
||||
}
|
||||
};
|
||||
static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||
{
|
||||
/* Example #1 */
|
||||
0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
|
||||
0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
|
||||
},
|
||||
{
|
||||
/* Example #2 */
|
||||
0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
|
||||
0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
|
||||
},
|
||||
{
|
||||
/* Example #3 */
|
||||
0x15, 0x67, 0x27, 0xdc, 0x08, 0x78, 0x94, 0x4a,
|
||||
0x02, 0x3c, 0x1f, 0xe0, 0x3b, 0xad, 0x6d, 0x93
|
||||
},
|
||||
{
|
||||
/* Example #4 */
|
||||
0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
|
||||
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
|
||||
}
|
||||
};
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
/* Truncation point of message for 3DES CMAC tests */
|
||||
static const unsigned int des3_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
||||
0,
|
||||
16,
|
||||
20,
|
||||
32
|
||||
};
|
||||
|
||||
/* CMAC-TDES (Generation) - 2 Key Test Data */
|
||||
static const unsigned char des3_2key_key[24] = {
|
||||
/* Key1 */
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
/* Key2 */
|
||||
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xEF, 0x01,
|
||||
/* Key3 */
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
|
||||
};
|
||||
static const unsigned char des3_2key_subkeys[2][8] = {
|
||||
{
|
||||
/* K1 */
|
||||
0x0d, 0xd2, 0xcb, 0x7a, 0x3d, 0x88, 0x88, 0xd9
|
||||
},
|
||||
{
|
||||
/* K2 */
|
||||
0x1b, 0xa5, 0x96, 0xf4, 0x7b, 0x11, 0x11, 0xb2
|
||||
}
|
||||
};
|
||||
static const unsigned char des3_2key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
||||
{
|
||||
/* Sample #1 */
|
||||
0x79, 0xce, 0x52, 0xa7, 0xf7, 0x86, 0xa9, 0x60
|
||||
},
|
||||
{
|
||||
/* Sample #2 */
|
||||
0xcc, 0x18, 0xa0, 0xb7, 0x9a, 0xf2, 0x41, 0x3b
|
||||
},
|
||||
{
|
||||
/* Sample #3 */
|
||||
0xc0, 0x6d, 0x37, 0x7e, 0xcd, 0x10, 0x19, 0x69
|
||||
},
|
||||
{
|
||||
/* Sample #4 */
|
||||
0x9c, 0xd3, 0x35, 0x80, 0xf9, 0xb6, 0x4d, 0xfb
|
||||
}
|
||||
};
|
||||
|
||||
/* CMAC-TDES (Generation) - 3 Key Test Data */
|
||||
static const unsigned char des3_3key_key[24] = {
|
||||
/* Key1 */
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xaa, 0xcd, 0xef,
|
||||
/* Key2 */
|
||||
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
|
||||
/* Key3 */
|
||||
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
|
||||
};
|
||||
static const unsigned char des3_3key_subkeys[2][8] = {
|
||||
{
|
||||
/* K1 */
|
||||
0x9d, 0x74, 0xe7, 0x39, 0x33, 0x17, 0x96, 0xc0
|
||||
},
|
||||
{
|
||||
/* K2 */
|
||||
0x3a, 0xe9, 0xce, 0x72, 0x66, 0x2f, 0x2d, 0x9b
|
||||
}
|
||||
};
|
||||
static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
||||
{
|
||||
/* Sample #1 */
|
||||
0x7d, 0xb0, 0xd3, 0x7d, 0xf9, 0x36, 0xc5, 0x50
|
||||
},
|
||||
{
|
||||
/* Sample #2 */
|
||||
0x30, 0x23, 0x9c, 0xf1, 0xf5, 0x2e, 0x66, 0x09
|
||||
},
|
||||
{
|
||||
/* Sample #3 */
|
||||
0x6c, 0x9f, 0x3e, 0xe4, 0x92, 0x3f, 0x6b, 0xe2
|
||||
},
|
||||
{
|
||||
/* Sample #4 */
|
||||
0x99, 0x42, 0x9b, 0xd0, 0xbF, 0x79, 0x04, 0xe5
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
/* AES AES-CMAC-PRF-128 Test Data */
|
||||
static const unsigned char PRFK[] = {
|
||||
/* Key */
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0xed, 0xcb
|
||||
};
|
||||
|
||||
/* Sizes in bytes */
|
||||
static const size_t PRFKlen[NB_PRF_TESTS] = {
|
||||
18,
|
||||
16,
|
||||
10
|
||||
};
|
||||
|
||||
/* Message */
|
||||
static const unsigned char PRFM[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13
|
||||
};
|
||||
|
||||
static const unsigned char PRFT[NB_PRF_TESTS][16] = {
|
||||
{
|
||||
0x84, 0xa3, 0x48, 0xa4, 0xa4, 0x5d, 0x23, 0x5b,
|
||||
0xab, 0xff, 0xfc, 0x0d, 0x2b, 0x4d, 0xa0, 0x9a
|
||||
},
|
||||
{
|
||||
0x98, 0x0a, 0xe8, 0x7b, 0x5f, 0x4c, 0x9c, 0x52,
|
||||
0x14, 0xf5, 0xb6, 0xa8, 0x45, 0x5e, 0x4c, 0x2d
|
||||
},
|
||||
{
|
||||
0x29, 0x0d, 0x9e, 0x11, 0x2e, 0xdb, 0x09, 0xee,
|
||||
0x14, 0x1f, 0xcf, 0x64, 0xc0, 0xb7, 0x2f, 0x3d
|
||||
}
|
||||
};
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
static int cmac_test_subkeys( int verbose,
|
||||
const char* testname,
|
||||
const unsigned char* key,
|
||||
int keybits,
|
||||
const unsigned char* subkeys,
|
||||
mbedtls_cipher_type_t cipher_type,
|
||||
int block_size,
|
||||
int num_tests )
|
||||
{
|
||||
int i, ret;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
unsigned char K1[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
unsigned char K2[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type( cipher_type );
|
||||
if( cipher_info == NULL )
|
||||
{
|
||||
/* Failing at this point must be due to a build issue */
|
||||
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
}
|
||||
|
||||
for( i = 0; i < num_tests; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " %s CMAC subkey #%u: ", testname, i + 1 );
|
||||
|
||||
mbedtls_cipher_init( &ctx );
|
||||
|
||||
if( ( ret = mbedtls_cipher_setup( &ctx, cipher_info ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "test execution failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_cipher_setkey( &ctx, key, keybits,
|
||||
MBEDTLS_ENCRYPT ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "test execution failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = cmac_generate_subkeys( &ctx, K1, K2 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( ( ret = memcmp( K1, subkeys, block_size ) ) != 0 ||
|
||||
( ret = memcmp( K2, &subkeys[block_size], block_size ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
mbedtls_cipher_free( &ctx );
|
||||
}
|
||||
|
||||
goto exit;
|
||||
|
||||
cleanup:
|
||||
mbedtls_cipher_free( &ctx );
|
||||
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
static int cmac_test_wth_cipher( int verbose,
|
||||
const char* testname,
|
||||
const unsigned char* key,
|
||||
int keybits,
|
||||
const unsigned char* messages,
|
||||
const unsigned int message_lengths[4],
|
||||
const unsigned char* expected_result,
|
||||
mbedtls_cipher_type_t cipher_type,
|
||||
int block_size,
|
||||
int num_tests )
|
||||
{
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
int i, ret;
|
||||
unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type( cipher_type );
|
||||
if( cipher_info == NULL )
|
||||
{
|
||||
/* Failing at this point must be due to a build issue */
|
||||
ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( i = 0; i < num_tests; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " %s CMAC #%u: ", testname, i + 1 );
|
||||
|
||||
if( ( ret = mbedtls_cipher_cmac( cipher_info, key, keybits, messages,
|
||||
message_lengths[i], output ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = memcmp( output, &expected_result[i * block_size], block_size ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
static int test_aes128_cmac_prf( int verbose )
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
unsigned char output[MBEDTLS_AES_BLOCK_SIZE];
|
||||
|
||||
for( i = 0; i < NB_PRF_TESTS; i++ )
|
||||
{
|
||||
mbedtls_printf( " AES CMAC 128 PRF #%u: ", i );
|
||||
ret = mbedtls_aes_cmac_prf_128( PRFK, PRFKlen[i], PRFM, 20, output );
|
||||
if( ret != 0 ||
|
||||
memcmp( output, PRFT[i], MBEDTLS_AES_BLOCK_SIZE ) != 0 )
|
||||
{
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
else if( verbose != 0 )
|
||||
{
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
}
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
int mbedtls_cmac_self_test( int verbose )
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
/* AES-128 */
|
||||
if( ( ret = cmac_test_subkeys( verbose,
|
||||
"AES 128",
|
||||
aes_128_key,
|
||||
128,
|
||||
(const unsigned char*)aes_128_subkeys,
|
||||
MBEDTLS_CIPHER_AES_128_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = cmac_test_wth_cipher( verbose,
|
||||
"AES 128",
|
||||
aes_128_key,
|
||||
128,
|
||||
test_message,
|
||||
aes_message_lengths,
|
||||
(const unsigned char*)aes_128_expected_result,
|
||||
MBEDTLS_CIPHER_AES_128_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* AES-192 */
|
||||
if( ( ret = cmac_test_subkeys( verbose,
|
||||
"AES 192",
|
||||
aes_192_key,
|
||||
192,
|
||||
(const unsigned char*)aes_192_subkeys,
|
||||
MBEDTLS_CIPHER_AES_192_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = cmac_test_wth_cipher( verbose,
|
||||
"AES 192",
|
||||
aes_192_key,
|
||||
192,
|
||||
test_message,
|
||||
aes_message_lengths,
|
||||
(const unsigned char*)aes_192_expected_result,
|
||||
MBEDTLS_CIPHER_AES_192_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* AES-256 */
|
||||
if( ( ret = cmac_test_subkeys( verbose,
|
||||
"AES 256",
|
||||
aes_256_key,
|
||||
256,
|
||||
(const unsigned char*)aes_256_subkeys,
|
||||
MBEDTLS_CIPHER_AES_256_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = cmac_test_wth_cipher ( verbose,
|
||||
"AES 256",
|
||||
aes_256_key,
|
||||
256,
|
||||
test_message,
|
||||
aes_message_lengths,
|
||||
(const unsigned char*)aes_256_expected_result,
|
||||
MBEDTLS_CIPHER_AES_256_ECB,
|
||||
MBEDTLS_AES_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
/* 3DES 2 key */
|
||||
if( ( ret = cmac_test_subkeys( verbose,
|
||||
"3DES 2 key",
|
||||
des3_2key_key,
|
||||
192,
|
||||
(const unsigned char*)des3_2key_subkeys,
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB,
|
||||
MBEDTLS_DES3_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = cmac_test_wth_cipher( verbose,
|
||||
"3DES 2 key",
|
||||
des3_2key_key,
|
||||
192,
|
||||
test_message,
|
||||
des3_message_lengths,
|
||||
(const unsigned char*)des3_2key_expected_result,
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB,
|
||||
MBEDTLS_DES3_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* 3DES 3 key */
|
||||
if( ( ret = cmac_test_subkeys( verbose,
|
||||
"3DES 3 key",
|
||||
des3_3key_key,
|
||||
192,
|
||||
(const unsigned char*)des3_3key_subkeys,
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB,
|
||||
MBEDTLS_DES3_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = cmac_test_wth_cipher( verbose,
|
||||
"3DES 3 key",
|
||||
des3_3key_key,
|
||||
192,
|
||||
test_message,
|
||||
des3_message_lengths,
|
||||
(const unsigned char*)des3_3key_expected_result,
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB,
|
||||
MBEDTLS_DES3_BLOCK_SIZE,
|
||||
NB_CMAC_TESTS_PER_KEY ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
if( ( ret = test_aes128_cmac_prf( verbose ) ) != 0 )
|
||||
return( ret );
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_CMAC_C */
|
||||
|
125
deps/mbedtls/ctr_drbg.c
vendored
125
deps/mbedtls/ctr_drbg.c
vendored
@ -40,15 +40,6 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
/*
|
||||
@ -472,120 +463,4 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
|
||||
}
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
static const unsigned char entropy_source_pr[96] =
|
||||
{ 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
|
||||
0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
|
||||
0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
|
||||
0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb,
|
||||
0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9,
|
||||
0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95,
|
||||
0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63,
|
||||
0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3,
|
||||
0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31,
|
||||
0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4,
|
||||
0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
|
||||
0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 };
|
||||
|
||||
static const unsigned char entropy_source_nopr[64] =
|
||||
{ 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
|
||||
0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
|
||||
0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
|
||||
0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20,
|
||||
0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9,
|
||||
0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46,
|
||||
0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e,
|
||||
0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e };
|
||||
|
||||
static const unsigned char nonce_pers_pr[16] =
|
||||
{ 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2,
|
||||
0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c };
|
||||
|
||||
static const unsigned char nonce_pers_nopr[16] =
|
||||
{ 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5,
|
||||
0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f };
|
||||
|
||||
static const unsigned char ctr_result_pr[16] =
|
||||
{ 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f,
|
||||
0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 };
|
||||
|
||||
static const unsigned char ctr_result_nopr[16] =
|
||||
{ 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88,
|
||||
0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
|
||||
|
||||
static size_t test_offset;
|
||||
static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
const unsigned char *p = data;
|
||||
memcpy( buf, p + test_offset, len );
|
||||
test_offset += len;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
mbedtls_printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_ctr_drbg_self_test( int verbose )
|
||||
{
|
||||
mbedtls_ctr_drbg_context ctx;
|
||||
unsigned char buf[16];
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
|
||||
/*
|
||||
* Based on a NIST CTR_DRBG test vector (PR = True)
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CTR_DRBG (PR = TRUE) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) );
|
||||
mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
|
||||
CHK( memcmp( buf, ctr_result_pr, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
|
||||
|
||||
mbedtls_ctr_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
/*
|
||||
* Based on a NIST CTR_DRBG test vector (PR = FALSE)
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " CTR_DRBG (PR = FALSE): " );
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
|
||||
CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
|
||||
CHK( memcmp( buf, ctr_result_nopr, 16 ) );
|
||||
|
||||
mbedtls_ctr_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_CTR_DRBG_C */
|
||||
|
42
deps/mbedtls/debug.c
vendored
42
deps/mbedtls/debug.c
vendored
@ -27,15 +27,7 @@
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_time_t time_t
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#include "mbedtls/debug.h"
|
||||
|
||||
@ -66,7 +58,7 @@ static void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
|
||||
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
|
||||
snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
|
||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
|
||||
#else
|
||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
||||
@ -133,7 +125,7 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
||||
if( ret == MBEDTLS_ERR_SSL_WANT_READ )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
|
||||
snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
|
||||
text, ret, -ret );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
@ -150,7 +142,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
|
||||
snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
|
||||
text, (unsigned int) len );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
@ -166,19 +158,19 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
{
|
||||
if( i > 0 )
|
||||
{
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
idx = 0;
|
||||
memset( txt, 0, sizeof( txt ) );
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
|
||||
idx += snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
|
||||
(unsigned int) i );
|
||||
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x",
|
||||
idx += snprintf( str + idx, sizeof( str ) - idx, " %02x",
|
||||
(unsigned int) buf[i] );
|
||||
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
|
||||
}
|
||||
@ -186,9 +178,9 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
if( len > 0 )
|
||||
{
|
||||
for( /* i = i */; i % 16 != 0; i++ )
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
|
||||
idx += snprintf( str + idx, sizeof( str ) - idx, " " );
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
}
|
||||
@ -203,10 +195,10 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
|
||||
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
|
||||
snprintf( str, sizeof( str ), "%s(X)", text );
|
||||
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s(Y)", text );
|
||||
snprintf( str, sizeof( str ), "%s(Y)", text );
|
||||
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->Y );
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
@ -231,7 +223,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
if( ( ( X->p[n] >> j ) & 1 ) != 0 )
|
||||
break;
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
|
||||
snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
|
||||
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
|
||||
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
@ -253,13 +245,13 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
{
|
||||
if( j > 0 )
|
||||
{
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
|
||||
idx += snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
|
||||
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
|
||||
|
||||
j++;
|
||||
@ -268,9 +260,9 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
}
|
||||
|
||||
if( zeros == 1 )
|
||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
|
||||
idx += snprintf( str + idx, sizeof( str ) - idx, " 00" );
|
||||
|
||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
@ -298,7 +290,7 @@ static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
|
||||
if( items[i].type == MBEDTLS_PK_DEBUG_NONE )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
|
||||
snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
|
||||
name[sizeof( name ) - 1] = '\0';
|
||||
|
||||
if( items[i].type == MBEDTLS_PK_DEBUG_MPI )
|
||||
@ -353,7 +345,7 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
|
||||
snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
|
||||
debug_send_line( ssl, level, file, line, str );
|
||||
|
||||
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
||||
|
256
deps/mbedtls/des.c
vendored
256
deps/mbedtls/des.c
vendored
@ -37,15 +37,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_DES_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -808,251 +799,4 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
|
||||
#endif /* !MBEDTLS_DES_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* DES and 3DES test vectors from:
|
||||
*
|
||||
* http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip
|
||||
*/
|
||||
static const unsigned char des3_test_keys[24] =
|
||||
{
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
|
||||
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
|
||||
};
|
||||
|
||||
static const unsigned char des3_test_buf[8] =
|
||||
{
|
||||
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
|
||||
};
|
||||
|
||||
static const unsigned char des3_test_ecb_dec[3][8] =
|
||||
{
|
||||
{ 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D },
|
||||
{ 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB },
|
||||
{ 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A }
|
||||
};
|
||||
|
||||
static const unsigned char des3_test_ecb_enc[3][8] =
|
||||
{
|
||||
{ 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B },
|
||||
{ 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 },
|
||||
{ 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 }
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
static const unsigned char des3_test_iv[8] =
|
||||
{
|
||||
0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
|
||||
};
|
||||
|
||||
static const unsigned char des3_test_cbc_dec[3][8] =
|
||||
{
|
||||
{ 0x12, 0x9F, 0x40, 0xB9, 0xD2, 0x00, 0x56, 0xB3 },
|
||||
{ 0x47, 0x0E, 0xFC, 0x9A, 0x6B, 0x8E, 0xE3, 0x93 },
|
||||
{ 0xC5, 0xCE, 0xCF, 0x63, 0xEC, 0xEC, 0x51, 0x4C }
|
||||
};
|
||||
|
||||
static const unsigned char des3_test_cbc_enc[3][8] =
|
||||
{
|
||||
{ 0x54, 0xF1, 0x5A, 0xF6, 0xEB, 0xE3, 0xA4, 0xB4 },
|
||||
{ 0x35, 0x76, 0x11, 0x56, 0x5F, 0xA1, 0x8E, 0x4D },
|
||||
{ 0xCB, 0x19, 0x1F, 0x85, 0xD1, 0xED, 0x84, 0x39 }
|
||||
};
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_des_self_test( int verbose )
|
||||
{
|
||||
int i, j, u, v, ret = 0;
|
||||
mbedtls_des_context ctx;
|
||||
mbedtls_des3_context ctx3;
|
||||
unsigned char buf[8];
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
unsigned char prv[8];
|
||||
unsigned char iv[8];
|
||||
#endif
|
||||
|
||||
mbedtls_des_init( &ctx );
|
||||
mbedtls_des3_init( &ctx3 );
|
||||
/*
|
||||
* ECB mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " DES%c-ECB-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( buf, des3_test_buf, 8 );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
case 0:
|
||||
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 5:
|
||||
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
default:
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_ecb( &ctx, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
|
||||
}
|
||||
|
||||
if( ( v == MBEDTLS_DES_DECRYPT &&
|
||||
memcmp( buf, des3_test_ecb_dec[u], 8 ) != 0 ) ||
|
||||
( v != MBEDTLS_DES_DECRYPT &&
|
||||
memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/*
|
||||
* CBC mode
|
||||
*/
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
u = i >> 1;
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " DES%c-CBC-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( iv, des3_test_iv, 8 );
|
||||
memcpy( prv, des3_test_iv, 8 );
|
||||
memcpy( buf, des3_test_buf, 8 );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
case 0:
|
||||
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 5:
|
||||
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
default:
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( v == MBEDTLS_DES_DECRYPT )
|
||||
{
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
unsigned char tmp[8];
|
||||
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
|
||||
memcpy( tmp, prv, 8 );
|
||||
memcpy( prv, buf, 8 );
|
||||
memcpy( buf, tmp, 8 );
|
||||
}
|
||||
|
||||
memcpy( buf, prv, 8 );
|
||||
}
|
||||
|
||||
if( ( v == MBEDTLS_DES_DECRYPT &&
|
||||
memcmp( buf, des3_test_cbc_dec[u], 8 ) != 0 ) ||
|
||||
( v != MBEDTLS_DES_DECRYPT &&
|
||||
memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_des_free( &ctx );
|
||||
mbedtls_des3_free( &ctx3 );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
46
deps/mbedtls/dhm.c
vendored
46
deps/mbedtls/dhm.c
vendored
@ -575,50 +575,4 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path )
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
#endif /* MBEDTLS_ASN1_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
static const char mbedtls_test_dhm_params[] =
|
||||
"-----BEGIN DH PARAMETERS-----\r\n"
|
||||
"MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
|
||||
"1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
|
||||
"9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
|
||||
"-----END DH PARAMETERS-----\r\n";
|
||||
|
||||
static const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params );
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_dhm_self_test( int verbose )
|
||||
{
|
||||
int ret;
|
||||
mbedtls_dhm_context dhm;
|
||||
|
||||
mbedtls_dhm_init( &dhm );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " DHM parameter load: " );
|
||||
|
||||
if( ( ret = mbedtls_dhm_parse_dhm( &dhm,
|
||||
(const unsigned char *) mbedtls_test_dhm_params,
|
||||
mbedtls_test_dhm_params_len ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_dhm_free( &dhm );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_DHM_C */
|
||||
|
336
deps/mbedtls/ecjpake.c
vendored
336
deps/mbedtls/ecjpake.c
vendored
@ -764,340 +764,4 @@ cleanup:
|
||||
#undef ID_MINE
|
||||
#undef ID_PEER
|
||||
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
|
||||
!defined(MBEDTLS_SHA256_C)
|
||||
int mbedtls_ecjpake_self_test( int verbose )
|
||||
{
|
||||
(void) verbose;
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
||||
static const unsigned char ecjpake_test_password[] = {
|
||||
0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, 0x61, 0x6b, 0x65, 0x74,
|
||||
0x65, 0x73, 0x74
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_x1[] = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
|
||||
0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x21
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_x2[] = {
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
|
||||
0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||
0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_x3[] = {
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
|
||||
0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||
0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_x4[] = {
|
||||
0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc,
|
||||
0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
|
||||
0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe1
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_cli_one[] = {
|
||||
0x41, 0x04, 0xac, 0xcf, 0x01, 0x06, 0xef, 0x85, 0x8f, 0xa2, 0xd9, 0x19,
|
||||
0x33, 0x13, 0x46, 0x80, 0x5a, 0x78, 0xb5, 0x8b, 0xba, 0xd0, 0xb8, 0x44,
|
||||
0xe5, 0xc7, 0x89, 0x28, 0x79, 0x14, 0x61, 0x87, 0xdd, 0x26, 0x66, 0xad,
|
||||
0xa7, 0x81, 0xbb, 0x7f, 0x11, 0x13, 0x72, 0x25, 0x1a, 0x89, 0x10, 0x62,
|
||||
0x1f, 0x63, 0x4d, 0xf1, 0x28, 0xac, 0x48, 0xe3, 0x81, 0xfd, 0x6e, 0xf9,
|
||||
0x06, 0x07, 0x31, 0xf6, 0x94, 0xa4, 0x41, 0x04, 0x1d, 0xd0, 0xbd, 0x5d,
|
||||
0x45, 0x66, 0xc9, 0xbe, 0xd9, 0xce, 0x7d, 0xe7, 0x01, 0xb5, 0xe8, 0x2e,
|
||||
0x08, 0xe8, 0x4b, 0x73, 0x04, 0x66, 0x01, 0x8a, 0xb9, 0x03, 0xc7, 0x9e,
|
||||
0xb9, 0x82, 0x17, 0x22, 0x36, 0xc0, 0xc1, 0x72, 0x8a, 0xe4, 0xbf, 0x73,
|
||||
0x61, 0x0d, 0x34, 0xde, 0x44, 0x24, 0x6e, 0xf3, 0xd9, 0xc0, 0x5a, 0x22,
|
||||
0x36, 0xfb, 0x66, 0xa6, 0x58, 0x3d, 0x74, 0x49, 0x30, 0x8b, 0xab, 0xce,
|
||||
0x20, 0x72, 0xfe, 0x16, 0x66, 0x29, 0x92, 0xe9, 0x23, 0x5c, 0x25, 0x00,
|
||||
0x2f, 0x11, 0xb1, 0x50, 0x87, 0xb8, 0x27, 0x38, 0xe0, 0x3c, 0x94, 0x5b,
|
||||
0xf7, 0xa2, 0x99, 0x5d, 0xda, 0x1e, 0x98, 0x34, 0x58, 0x41, 0x04, 0x7e,
|
||||
0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62,
|
||||
0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, 0x9a, 0xc5,
|
||||
0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, 0xeb,
|
||||
0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, 0xc3, 0x35,
|
||||
0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0,
|
||||
0x13, 0xbb, 0x2b, 0x41, 0x04, 0xa4, 0x95, 0x58, 0xd3, 0x2e, 0xd1, 0xeb,
|
||||
0xfc, 0x18, 0x16, 0xaf, 0x4f, 0xf0, 0x9b, 0x55, 0xfc, 0xb4, 0xca, 0x47,
|
||||
0xb2, 0xa0, 0x2d, 0x1e, 0x7c, 0xaf, 0x11, 0x79, 0xea, 0x3f, 0xe1, 0x39,
|
||||
0x5b, 0x22, 0xb8, 0x61, 0x96, 0x40, 0x16, 0xfa, 0xba, 0xf7, 0x2c, 0x97,
|
||||
0x56, 0x95, 0xd9, 0x3d, 0x4d, 0xf0, 0xe5, 0x19, 0x7f, 0xe9, 0xf0, 0x40,
|
||||
0x63, 0x4e, 0xd5, 0x97, 0x64, 0x93, 0x77, 0x87, 0xbe, 0x20, 0xbc, 0x4d,
|
||||
0xee, 0xbb, 0xf9, 0xb8, 0xd6, 0x0a, 0x33, 0x5f, 0x04, 0x6c, 0xa3, 0xaa,
|
||||
0x94, 0x1e, 0x45, 0x86, 0x4c, 0x7c, 0xad, 0xef, 0x9c, 0xf7, 0x5b, 0x3d,
|
||||
0x8b, 0x01, 0x0e, 0x44, 0x3e, 0xf0
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_srv_one[] = {
|
||||
0x41, 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb,
|
||||
0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18,
|
||||
0x40, 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47,
|
||||
0x79, 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f,
|
||||
0xd1, 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7,
|
||||
0xe3, 0x2b, 0xb0, 0x13, 0xbb, 0x2b, 0x41, 0x04, 0x09, 0xf8, 0x5b, 0x3d,
|
||||
0x20, 0xeb, 0xd7, 0x88, 0x5c, 0xe4, 0x64, 0xc0, 0x8d, 0x05, 0x6d, 0x64,
|
||||
0x28, 0xfe, 0x4d, 0xd9, 0x28, 0x7a, 0xa3, 0x65, 0xf1, 0x31, 0xf4, 0x36,
|
||||
0x0f, 0xf3, 0x86, 0xd8, 0x46, 0x89, 0x8b, 0xc4, 0xb4, 0x15, 0x83, 0xc2,
|
||||
0xa5, 0x19, 0x7f, 0x65, 0xd7, 0x87, 0x42, 0x74, 0x6c, 0x12, 0xa5, 0xec,
|
||||
0x0a, 0x4f, 0xfe, 0x2f, 0x27, 0x0a, 0x75, 0x0a, 0x1d, 0x8f, 0xb5, 0x16,
|
||||
0x20, 0x93, 0x4d, 0x74, 0xeb, 0x43, 0xe5, 0x4d, 0xf4, 0x24, 0xfd, 0x96,
|
||||
0x30, 0x6c, 0x01, 0x17, 0xbf, 0x13, 0x1a, 0xfa, 0xbf, 0x90, 0xa9, 0xd3,
|
||||
0x3d, 0x11, 0x98, 0xd9, 0x05, 0x19, 0x37, 0x35, 0x14, 0x41, 0x04, 0x19,
|
||||
0x0a, 0x07, 0x70, 0x0f, 0xfa, 0x4b, 0xe6, 0xae, 0x1d, 0x79, 0xee, 0x0f,
|
||||
0x06, 0xae, 0xb5, 0x44, 0xcd, 0x5a, 0xdd, 0xaa, 0xbe, 0xdf, 0x70, 0xf8,
|
||||
0x62, 0x33, 0x21, 0x33, 0x2c, 0x54, 0xf3, 0x55, 0xf0, 0xfb, 0xfe, 0xc7,
|
||||
0x83, 0xed, 0x35, 0x9e, 0x5d, 0x0b, 0xf7, 0x37, 0x7a, 0x0f, 0xc4, 0xea,
|
||||
0x7a, 0xce, 0x47, 0x3c, 0x9c, 0x11, 0x2b, 0x41, 0xcc, 0xd4, 0x1a, 0xc5,
|
||||
0x6a, 0x56, 0x12, 0x41, 0x04, 0x36, 0x0a, 0x1c, 0xea, 0x33, 0xfc, 0xe6,
|
||||
0x41, 0x15, 0x64, 0x58, 0xe0, 0xa4, 0xea, 0xc2, 0x19, 0xe9, 0x68, 0x31,
|
||||
0xe6, 0xae, 0xbc, 0x88, 0xb3, 0xf3, 0x75, 0x2f, 0x93, 0xa0, 0x28, 0x1d,
|
||||
0x1b, 0xf1, 0xfb, 0x10, 0x60, 0x51, 0xdb, 0x96, 0x94, 0xa8, 0xd6, 0xe8,
|
||||
0x62, 0xa5, 0xef, 0x13, 0x24, 0xa3, 0xd9, 0xe2, 0x78, 0x94, 0xf1, 0xee,
|
||||
0x4f, 0x7c, 0x59, 0x19, 0x99, 0x65, 0xa8, 0xdd, 0x4a, 0x20, 0x91, 0x84,
|
||||
0x7d, 0x2d, 0x22, 0xdf, 0x3e, 0xe5, 0x5f, 0xaa, 0x2a, 0x3f, 0xb3, 0x3f,
|
||||
0xd2, 0xd1, 0xe0, 0x55, 0xa0, 0x7a, 0x7c, 0x61, 0xec, 0xfb, 0x8d, 0x80,
|
||||
0xec, 0x00, 0xc2, 0xc9, 0xeb, 0x12
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_srv_two[] = {
|
||||
0x03, 0x00, 0x17, 0x41, 0x04, 0x0f, 0xb2, 0x2b, 0x1d, 0x5d, 0x11, 0x23,
|
||||
0xe0, 0xef, 0x9f, 0xeb, 0x9d, 0x8a, 0x2e, 0x59, 0x0a, 0x1f, 0x4d, 0x7c,
|
||||
0xed, 0x2c, 0x2b, 0x06, 0x58, 0x6e, 0x8f, 0x2a, 0x16, 0xd4, 0xeb, 0x2f,
|
||||
0xda, 0x43, 0x28, 0xa2, 0x0b, 0x07, 0xd8, 0xfd, 0x66, 0x76, 0x54, 0xca,
|
||||
0x18, 0xc5, 0x4e, 0x32, 0xa3, 0x33, 0xa0, 0x84, 0x54, 0x51, 0xe9, 0x26,
|
||||
0xee, 0x88, 0x04, 0xfd, 0x7a, 0xf0, 0xaa, 0xa7, 0xa6, 0x41, 0x04, 0x55,
|
||||
0x16, 0xea, 0x3e, 0x54, 0xa0, 0xd5, 0xd8, 0xb2, 0xce, 0x78, 0x6b, 0x38,
|
||||
0xd3, 0x83, 0x37, 0x00, 0x29, 0xa5, 0xdb, 0xe4, 0x45, 0x9c, 0x9d, 0xd6,
|
||||
0x01, 0xb4, 0x08, 0xa2, 0x4a, 0xe6, 0x46, 0x5c, 0x8a, 0xc9, 0x05, 0xb9,
|
||||
0xeb, 0x03, 0xb5, 0xd3, 0x69, 0x1c, 0x13, 0x9e, 0xf8, 0x3f, 0x1c, 0xd4,
|
||||
0x20, 0x0f, 0x6c, 0x9c, 0xd4, 0xec, 0x39, 0x22, 0x18, 0xa5, 0x9e, 0xd2,
|
||||
0x43, 0xd3, 0xc8, 0x20, 0xff, 0x72, 0x4a, 0x9a, 0x70, 0xb8, 0x8c, 0xb8,
|
||||
0x6f, 0x20, 0xb4, 0x34, 0xc6, 0x86, 0x5a, 0xa1, 0xcd, 0x79, 0x06, 0xdd,
|
||||
0x7c, 0x9b, 0xce, 0x35, 0x25, 0xf5, 0x08, 0x27, 0x6f, 0x26, 0x83, 0x6c
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_cli_two[] = {
|
||||
0x41, 0x04, 0x69, 0xd5, 0x4e, 0xe8, 0x5e, 0x90, 0xce, 0x3f, 0x12, 0x46,
|
||||
0x74, 0x2d, 0xe5, 0x07, 0xe9, 0x39, 0xe8, 0x1d, 0x1d, 0xc1, 0xc5, 0xcb,
|
||||
0x98, 0x8b, 0x58, 0xc3, 0x10, 0xc9, 0xfd, 0xd9, 0x52, 0x4d, 0x93, 0x72,
|
||||
0x0b, 0x45, 0x54, 0x1c, 0x83, 0xee, 0x88, 0x41, 0x19, 0x1d, 0xa7, 0xce,
|
||||
0xd8, 0x6e, 0x33, 0x12, 0xd4, 0x36, 0x23, 0xc1, 0xd6, 0x3e, 0x74, 0x98,
|
||||
0x9a, 0xba, 0x4a, 0xff, 0xd1, 0xee, 0x41, 0x04, 0x07, 0x7e, 0x8c, 0x31,
|
||||
0xe2, 0x0e, 0x6b, 0xed, 0xb7, 0x60, 0xc1, 0x35, 0x93, 0xe6, 0x9f, 0x15,
|
||||
0xbe, 0x85, 0xc2, 0x7d, 0x68, 0xcd, 0x09, 0xcc, 0xb8, 0xc4, 0x18, 0x36,
|
||||
0x08, 0x91, 0x7c, 0x5c, 0x3d, 0x40, 0x9f, 0xac, 0x39, 0xfe, 0xfe, 0xe8,
|
||||
0x2f, 0x72, 0x92, 0xd3, 0x6f, 0x0d, 0x23, 0xe0, 0x55, 0x91, 0x3f, 0x45,
|
||||
0xa5, 0x2b, 0x85, 0xdd, 0x8a, 0x20, 0x52, 0xe9, 0xe1, 0x29, 0xbb, 0x4d,
|
||||
0x20, 0x0f, 0x01, 0x1f, 0x19, 0x48, 0x35, 0x35, 0xa6, 0xe8, 0x9a, 0x58,
|
||||
0x0c, 0x9b, 0x00, 0x03, 0xba, 0xf2, 0x14, 0x62, 0xec, 0xe9, 0x1a, 0x82,
|
||||
0xcc, 0x38, 0xdb, 0xdc, 0xae, 0x60, 0xd9, 0xc5, 0x4c
|
||||
};
|
||||
|
||||
static const unsigned char ecjpake_test_pms[] = {
|
||||
0xf3, 0xd4, 0x7f, 0x59, 0x98, 0x44, 0xdb, 0x92, 0xa5, 0x69, 0xbb, 0xe7,
|
||||
0x98, 0x1e, 0x39, 0xd9, 0x31, 0xfd, 0x74, 0x3b, 0xf2, 0x2e, 0x98, 0xf9,
|
||||
0xb4, 0x38, 0xf7, 0x19, 0xd3, 0xc4, 0xf3, 0x51
|
||||
};
|
||||
|
||||
/* Load my private keys and generate the correponding public keys */
|
||||
static int ecjpake_test_load( mbedtls_ecjpake_context *ctx,
|
||||
const unsigned char *xm1, size_t len1,
|
||||
const unsigned char *xm2, size_t len2 )
|
||||
{
|
||||
int ret;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm1, xm1, len1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm2, xm2, len2 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &ctx->Xm1, &ctx->xm1,
|
||||
&ctx->grp.G, NULL, NULL ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &ctx->Xm2, &ctx->xm2,
|
||||
&ctx->grp.G, NULL, NULL ) );
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* For tests we don't need a secure RNG;
|
||||
* use the LGC from Numerical Recipes for simplicity */
|
||||
static int ecjpake_lgc( void *p, unsigned char *out, size_t len )
|
||||
{
|
||||
static uint32_t x = 42;
|
||||
(void) p;
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
size_t use_len = len > 4 ? 4 : len;
|
||||
x = 1664525 * x + 1013904223;
|
||||
memcpy( out, &x, use_len );
|
||||
out += use_len;
|
||||
len -= use_len;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define TEST_ASSERT( x ) \
|
||||
do { \
|
||||
if( x ) \
|
||||
ret = 0; \
|
||||
else \
|
||||
{ \
|
||||
ret = 1; \
|
||||
goto cleanup; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_ecjpake_self_test( int verbose )
|
||||
{
|
||||
int ret;
|
||||
mbedtls_ecjpake_context cli;
|
||||
mbedtls_ecjpake_context srv;
|
||||
unsigned char buf[512], pms[32];
|
||||
size_t len, pmslen;
|
||||
|
||||
mbedtls_ecjpake_init( &cli );
|
||||
mbedtls_ecjpake_init( &srv );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ECJPAKE test #0 (setup): " );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_setup( &cli, MBEDTLS_ECJPAKE_CLIENT,
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1,
|
||||
ecjpake_test_password,
|
||||
sizeof( ecjpake_test_password ) ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_setup( &srv, MBEDTLS_ECJPAKE_SERVER,
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1,
|
||||
ecjpake_test_password,
|
||||
sizeof( ecjpake_test_password ) ) == 0 );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ECJPAKE test #1 (random handshake): " );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_write_round_one( &cli,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_one( &srv, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_write_round_one( &srv,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_one( &cli, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_write_round_two( &srv,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_two( &cli, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_derive_secret( &cli,
|
||||
pms, sizeof( pms ), &pmslen, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_write_round_two( &cli,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_two( &srv, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_derive_secret( &srv,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( len == pmslen );
|
||||
TEST_ASSERT( memcmp( buf, pms, len ) == 0 );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ECJPAKE test #2 (reference handshake): " );
|
||||
|
||||
/* Simulate generation of round one */
|
||||
MBEDTLS_MPI_CHK( ecjpake_test_load( &cli,
|
||||
ecjpake_test_x1, sizeof( ecjpake_test_x1 ),
|
||||
ecjpake_test_x2, sizeof( ecjpake_test_x2 ) ) );
|
||||
|
||||
MBEDTLS_MPI_CHK( ecjpake_test_load( &srv,
|
||||
ecjpake_test_x3, sizeof( ecjpake_test_x3 ),
|
||||
ecjpake_test_x4, sizeof( ecjpake_test_x4 ) ) );
|
||||
|
||||
/* Read round one */
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_one( &srv,
|
||||
ecjpake_test_cli_one,
|
||||
sizeof( ecjpake_test_cli_one ) ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_one( &cli,
|
||||
ecjpake_test_srv_one,
|
||||
sizeof( ecjpake_test_srv_one ) ) == 0 );
|
||||
|
||||
/* Skip generation of round two, read round two */
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_two( &cli,
|
||||
ecjpake_test_srv_two,
|
||||
sizeof( ecjpake_test_srv_two ) ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecjpake_read_round_two( &srv,
|
||||
ecjpake_test_cli_two,
|
||||
sizeof( ecjpake_test_cli_two ) ) == 0 );
|
||||
|
||||
/* Server derives PMS */
|
||||
TEST_ASSERT( mbedtls_ecjpake_derive_secret( &srv,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( len == sizeof( ecjpake_test_pms ) );
|
||||
TEST_ASSERT( memcmp( buf, ecjpake_test_pms, len ) == 0 );
|
||||
|
||||
memset( buf, 0, len ); /* Avoid interferences with next step */
|
||||
|
||||
/* Client derives PMS */
|
||||
TEST_ASSERT( mbedtls_ecjpake_derive_secret( &cli,
|
||||
buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( len == sizeof( ecjpake_test_pms ) );
|
||||
TEST_ASSERT( memcmp( buf, ecjpake_test_pms, len ) == 0 );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecjpake_free( &cli );
|
||||
mbedtls_ecjpake_free( &srv );
|
||||
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#undef TEST_ASSERT
|
||||
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED && MBEDTLS_SHA256_C */
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_ECJPAKE_C */
|
||||
|
151
deps/mbedtls/ecp.c
vendored
151
deps/mbedtls/ecp.c
vendored
@ -74,14 +74,6 @@
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* Counts of point addition and doubling, and field multiplications.
|
||||
* Used to test resistance of point multiplication to simple timing attacks.
|
||||
*/
|
||||
static unsigned long add_count, dbl_count, mul_count;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
|
||||
defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
|
||||
defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
|
||||
@ -702,11 +694,7 @@ cleanup:
|
||||
/*
|
||||
* Reduce a mbedtls_mpi mod p in-place, general case, to use after mbedtls_mpi_mul_mpi
|
||||
*/
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#define INC_MUL_COUNT mul_count++;
|
||||
#else
|
||||
#define INC_MUL_COUNT
|
||||
#endif
|
||||
|
||||
#define MOD_MUL( N ) do { MBEDTLS_MPI_CHK( ecp_modp( &N, grp ) ); INC_MUL_COUNT } \
|
||||
while( 0 )
|
||||
@ -922,10 +910,6 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
int ret;
|
||||
mbedtls_mpi M, S, T, U;
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
dbl_count++;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
|
||||
if ( mbedtls_internal_ecp_grp_capable( grp ) )
|
||||
{
|
||||
@ -1020,10 +1004,6 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
int ret;
|
||||
mbedtls_mpi T1, T2, T3, T4, X, Y, Z;
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
add_count++;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
|
||||
if ( mbedtls_internal_ecp_grp_capable( grp ) )
|
||||
{
|
||||
@ -2057,137 +2037,6 @@ cleanup:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_ecp_self_test( int verbose )
|
||||
{
|
||||
int ret;
|
||||
size_t i;
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R, P;
|
||||
mbedtls_mpi m;
|
||||
unsigned long add_c_prev, dbl_c_prev, mul_c_prev;
|
||||
/* exponents especially adapted for secp192r1 */
|
||||
const char *exponents[] =
|
||||
{
|
||||
"000000000000000000000000000000000000000000000001", /* one */
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22830", /* N - 1 */
|
||||
"5EA6F389A38B8BC81E767753B15AA5569E1782E30ABE7D25", /* random */
|
||||
"400000000000000000000000000000000000000000000000", /* one and zeros */
|
||||
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", /* all ones */
|
||||
"555555555555555555555555555555555555555555555555", /* 101010... */
|
||||
};
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &R );
|
||||
mbedtls_ecp_point_init( &P );
|
||||
mbedtls_mpi_init( &m );
|
||||
|
||||
/* Use secp192r1 if available, or any available curve */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &grp, MBEDTLS_ECP_DP_SECP192R1 ) );
|
||||
#else
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &grp, mbedtls_ecp_curve_list()->grp_id ) );
|
||||
#endif
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ECP test #1 (constant op_count, base point G): " );
|
||||
|
||||
/* Do a dummy multiplication first to trigger precomputation */
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &m, 2 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &P, &m, &grp.G, NULL, NULL ) );
|
||||
|
||||
add_count = 0;
|
||||
dbl_count = 0;
|
||||
mul_count = 0;
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[0] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL ) );
|
||||
|
||||
for( i = 1; i < sizeof( exponents ) / sizeof( exponents[0] ); i++ )
|
||||
{
|
||||
add_c_prev = add_count;
|
||||
dbl_c_prev = dbl_count;
|
||||
mul_c_prev = mul_count;
|
||||
add_count = 0;
|
||||
dbl_count = 0;
|
||||
mul_count = 0;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[i] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL ) );
|
||||
|
||||
if( add_count != add_c_prev ||
|
||||
dbl_count != dbl_c_prev ||
|
||||
mul_count != mul_c_prev )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed (%u)\n", (unsigned int) i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ECP test #2 (constant op_count, other point): " );
|
||||
/* We computed P = 2G last time, use it */
|
||||
|
||||
add_count = 0;
|
||||
dbl_count = 0;
|
||||
mul_count = 0;
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[0] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &P, NULL, NULL ) );
|
||||
|
||||
for( i = 1; i < sizeof( exponents ) / sizeof( exponents[0] ); i++ )
|
||||
{
|
||||
add_c_prev = add_count;
|
||||
dbl_c_prev = dbl_count;
|
||||
mul_c_prev = mul_count;
|
||||
add_count = 0;
|
||||
dbl_count = 0;
|
||||
mul_count = 0;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[i] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &P, NULL, NULL ) );
|
||||
|
||||
if( add_count != add_c_prev ||
|
||||
dbl_count != dbl_c_prev ||
|
||||
mul_count != mul_c_prev )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed (%u)\n", (unsigned int) i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
|
||||
if( ret < 0 && verbose != 0 )
|
||||
mbedtls_printf( "Unexpected error, return code = %08X\n", ret );
|
||||
|
||||
mbedtls_ecp_group_free( &grp );
|
||||
mbedtls_ecp_point_free( &R );
|
||||
mbedtls_ecp_point_free( &P );
|
||||
mbedtls_mpi_free( &m );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* !MBEDTLS_ECP_ALT */
|
||||
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
206
deps/mbedtls/entropy.c
vendored
206
deps/mbedtls/entropy.c
vendored
@ -46,15 +46,6 @@
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
@ -452,201 +443,4 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *
|
||||
}
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
|
||||
/*
|
||||
* Dummy source function
|
||||
*/
|
||||
static int entropy_dummy_source( void *data, unsigned char *output,
|
||||
size_t len, size_t *olen )
|
||||
{
|
||||
((void) data);
|
||||
|
||||
memset( output, 0x2a, len );
|
||||
*olen = len;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
|
||||
static int mbedtls_entropy_source_self_test_gather( unsigned char *buf, size_t buf_len )
|
||||
{
|
||||
int ret = 0;
|
||||
size_t entropy_len = 0;
|
||||
size_t olen = 0;
|
||||
size_t attempts = buf_len;
|
||||
|
||||
while( attempts > 0 && entropy_len < buf_len )
|
||||
{
|
||||
if( ( ret = mbedtls_hardware_poll( NULL, buf + entropy_len,
|
||||
buf_len - entropy_len, &olen ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
entropy_len += olen;
|
||||
attempts--;
|
||||
}
|
||||
|
||||
if( entropy_len < buf_len )
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
|
||||
static int mbedtls_entropy_source_self_test_check_bits( const unsigned char *buf,
|
||||
size_t buf_len )
|
||||
{
|
||||
unsigned char set= 0xFF;
|
||||
unsigned char unset = 0x00;
|
||||
size_t i;
|
||||
|
||||
for( i = 0; i < buf_len; i++ )
|
||||
{
|
||||
set &= buf[i];
|
||||
unset |= buf[i];
|
||||
}
|
||||
|
||||
return( set == 0xFF || unset == 0x00 );
|
||||
}
|
||||
|
||||
/*
|
||||
* A test to ensure hat the entropy sources are functioning correctly
|
||||
* and there is no obvious failure. The test performs the following checks:
|
||||
* - The entropy source is not providing only 0s (all bits unset) or 1s (all
|
||||
* bits set).
|
||||
* - The entropy source is not providing values in a pattern. Because the
|
||||
* hardware could be providing data in an arbitrary length, this check polls
|
||||
* the hardware entropy source twice and compares the result to ensure they
|
||||
* are not equal.
|
||||
* - The error code returned by the entropy source is not an error.
|
||||
*/
|
||||
int mbedtls_entropy_source_self_test( int verbose )
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char buf0[2 * sizeof( unsigned long long int )];
|
||||
unsigned char buf1[2 * sizeof( unsigned long long int )];
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ENTROPY_BIAS test: " );
|
||||
|
||||
memset( buf0, 0x00, sizeof( buf0 ) );
|
||||
memset( buf1, 0x00, sizeof( buf1 ) );
|
||||
|
||||
if( ( ret = mbedtls_entropy_source_self_test_gather( buf0, sizeof( buf0 ) ) ) != 0 )
|
||||
goto cleanup;
|
||||
if( ( ret = mbedtls_entropy_source_self_test_gather( buf1, sizeof( buf1 ) ) ) != 0 )
|
||||
goto cleanup;
|
||||
|
||||
/* Make sure that the returned values are not all 0 or 1 */
|
||||
if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf0, sizeof( buf0 ) ) ) != 0 )
|
||||
goto cleanup;
|
||||
if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf1, sizeof( buf1 ) ) ) != 0 )
|
||||
goto cleanup;
|
||||
|
||||
/* Make sure that the entropy source is not returning values in a
|
||||
* pattern */
|
||||
ret = memcmp( buf0, buf1, sizeof( buf0 ) ) == 0;
|
||||
|
||||
cleanup:
|
||||
if( verbose != 0 )
|
||||
{
|
||||
if( ret != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
else
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
mbedtls_printf( "\n" );
|
||||
}
|
||||
|
||||
return( ret != 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
|
||||
|
||||
/*
|
||||
* The actual entropy quality is hard to test, but we can at least
|
||||
* test that the functions don't cause errors and write the correct
|
||||
* amount of data to buffers.
|
||||
*/
|
||||
int mbedtls_entropy_self_test( int verbose )
|
||||
{
|
||||
int ret = 1;
|
||||
#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
|
||||
mbedtls_entropy_context ctx;
|
||||
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
|
||||
unsigned char acc[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
|
||||
size_t i, j;
|
||||
#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " ENTROPY test: " );
|
||||
|
||||
#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
|
||||
mbedtls_entropy_init( &ctx );
|
||||
|
||||
/* First do a gather to make sure we have default sources */
|
||||
if( ( ret = mbedtls_entropy_gather( &ctx ) ) != 0 )
|
||||
goto cleanup;
|
||||
|
||||
ret = mbedtls_entropy_add_source( &ctx, entropy_dummy_source, NULL, 16,
|
||||
MBEDTLS_ENTROPY_SOURCE_WEAK );
|
||||
if( ret != 0 )
|
||||
goto cleanup;
|
||||
|
||||
if( ( ret = mbedtls_entropy_update_manual( &ctx, buf, sizeof buf ) ) != 0 )
|
||||
goto cleanup;
|
||||
|
||||
/*
|
||||
* To test that mbedtls_entropy_func writes correct number of bytes:
|
||||
* - use the whole buffer and rely on ASan to detect overruns
|
||||
* - collect entropy 8 times and OR the result in an accumulator:
|
||||
* any byte should then be 0 with probably 2^(-64), so requiring
|
||||
* each of the 32 or 64 bytes to be non-zero has a false failure rate
|
||||
* of at most 2^(-58) which is acceptable.
|
||||
*/
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
if( ( ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ) ) != 0 )
|
||||
goto cleanup;
|
||||
|
||||
for( j = 0; j < sizeof( buf ); j++ )
|
||||
acc[j] |= buf[j];
|
||||
}
|
||||
|
||||
for( j = 0; j < sizeof( buf ); j++ )
|
||||
{
|
||||
if( acc[j] == 0 )
|
||||
{
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
if( ( ret = mbedtls_entropy_source_self_test( 0 ) ) != 0 )
|
||||
goto cleanup;
|
||||
#endif
|
||||
|
||||
cleanup:
|
||||
mbedtls_entropy_free( &ctx );
|
||||
#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
|
||||
|
||||
if( verbose != 0 )
|
||||
{
|
||||
if( ret != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
else
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
mbedtls_printf( "\n" );
|
||||
}
|
||||
|
||||
return( ret != 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_ENTROPY_C */
|
||||
|
407
deps/mbedtls/error.c
vendored
407
deps/mbedtls/error.c
vendored
@ -30,13 +30,6 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#define mbedtls_snprintf snprintf
|
||||
#define mbedtls_time_t time_t
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
|
||||
#include <stdio.h>
|
||||
@ -172,319 +165,319 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
||||
* BEGIN generated code */
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
|
||||
snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
|
||||
snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
|
||||
snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
|
||||
snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
|
||||
snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
|
||||
mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" );
|
||||
snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" );
|
||||
#endif /* MBEDTLS_CIPHER_C */
|
||||
|
||||
#if defined(MBEDTLS_DHM_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "DHM - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
|
||||
snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
|
||||
snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
|
||||
snprintf( buf, buflen, "DHM - Reading of the public values failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
|
||||
snprintf( buf, buflen, "DHM - Making of the public value failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
|
||||
snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
|
||||
snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
|
||||
snprintf( buf, buflen, "DHM - Allocation of memory failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
|
||||
snprintf( buf, buflen, "DHM - Read/write of file failed" );
|
||||
#endif /* MBEDTLS_DHM_C */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "ECP - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
|
||||
snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
|
||||
snprintf( buf, buflen, "ECP - Requested curve not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
|
||||
snprintf( buf, buflen, "ECP - The signature is not valid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
|
||||
snprintf( buf, buflen, "ECP - Memory allocation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
|
||||
snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
|
||||
snprintf( buf, buflen, "ECP - Invalid private or public key" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
|
||||
snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
|
||||
snprintf( buf, buflen, "MD - The selected feature is not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "MD - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
|
||||
snprintf( buf, buflen, "MD - Failed to allocate memory" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
|
||||
snprintf( buf, buflen, "MD - Opening or reading of file failed" );
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
|
||||
snprintf( buf, buflen, "PEM - No PEM header or footer found" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
|
||||
snprintf( buf, buflen, "PEM - PEM string is not as expected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
|
||||
snprintf( buf, buflen, "PEM - Failed to allocate memory" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
|
||||
snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
|
||||
snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
|
||||
snprintf( buf, buflen, "PEM - Private key password can't be empty" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
|
||||
snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
|
||||
snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "PEM - Bad input parameters to function" );
|
||||
#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
|
||||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
|
||||
snprintf( buf, buflen, "PK - Memory allocation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
|
||||
snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "PK - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
|
||||
snprintf( buf, buflen, "PK - Read/write of file failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
|
||||
snprintf( buf, buflen, "PK - Unsupported key version" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
|
||||
snprintf( buf, buflen, "PK - Invalid key tag or value" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
|
||||
snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
|
||||
snprintf( buf, buflen, "PK - Private key password can't be empty" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
|
||||
snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
|
||||
snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
|
||||
snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
|
||||
snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
|
||||
snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
|
||||
snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
|
||||
#if defined(MBEDTLS_PKCS12_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
|
||||
snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
|
||||
snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
|
||||
snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
|
||||
#endif /* MBEDTLS_PKCS12_C */
|
||||
|
||||
#if defined(MBEDTLS_PKCS5_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
|
||||
snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
|
||||
snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
|
||||
snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
|
||||
#endif /* MBEDTLS_PKCS5_C */
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "RSA - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
|
||||
snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
|
||||
snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
|
||||
snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
|
||||
snprintf( buf, buflen, "RSA - The public key operation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
|
||||
snprintf( buf, buflen, "RSA - The private key operation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
|
||||
snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
|
||||
snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
|
||||
if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
|
||||
snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
|
||||
snprintf( buf, buflen, "SSL - The requested feature is not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "SSL - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
|
||||
snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
|
||||
snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
|
||||
snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
|
||||
snprintf( buf, buflen, "SSL - An unknown cipher was received" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
|
||||
snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
|
||||
snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
|
||||
snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
|
||||
snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
|
||||
snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
|
||||
snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
|
||||
snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
|
||||
snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
|
||||
{
|
||||
mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
|
||||
snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
|
||||
return;
|
||||
}
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
|
||||
snprintf( buf, buflen, "SSL - Verification of our peer failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
|
||||
snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
|
||||
snprintf( buf, buflen, "SSL - Memory allocation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
|
||||
snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
|
||||
snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
|
||||
snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
|
||||
snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
|
||||
snprintf( buf, buflen, "SSL - Session ticket has expired" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
|
||||
snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
|
||||
snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
|
||||
snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
|
||||
snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
|
||||
snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
|
||||
snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
|
||||
snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
|
||||
snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
|
||||
snprintf( buf, buflen, "SSL - Connection requires a read call" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
|
||||
snprintf( buf, buflen, "SSL - Connection requires a write call" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
|
||||
snprintf( buf, buflen, "SSL - The operation timed out" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
|
||||
snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
|
||||
snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
|
||||
snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
|
||||
if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
|
||||
mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
|
||||
snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
|
||||
#endif /* MBEDTLS_SSL_TLS_C */
|
||||
|
||||
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
|
||||
snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
|
||||
snprintf( buf, buflen, "X509 - Requested OID is unknown" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
|
||||
snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
|
||||
snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
|
||||
snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
|
||||
snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
|
||||
snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
|
||||
snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
|
||||
snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
|
||||
snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
|
||||
snprintf( buf, buflen, "X509 - Input invalid" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
|
||||
snprintf( buf, buflen, "X509 - Allocation of memory failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
|
||||
snprintf( buf, buflen, "X509 - Read/write of file failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
|
||||
snprintf( buf, buflen, "X509 - Destination buffer is too small" );
|
||||
#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
|
||||
/* END generated code */
|
||||
|
||||
if( strlen( buf ) == 0 )
|
||||
mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
|
||||
snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
|
||||
}
|
||||
|
||||
use_ret = ret & ~0xFF80;
|
||||
@ -501,7 +494,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
||||
if( buflen - len < 5 )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( buf + len, buflen - len, " : " );
|
||||
snprintf( buf + len, buflen - len, " : " );
|
||||
|
||||
buf += len + 3;
|
||||
buflen -= len + 3;
|
||||
@ -513,178 +506,178 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
||||
*/
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
|
||||
snprintf( buf, buflen, "AES - Invalid key length" );
|
||||
if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
|
||||
snprintf( buf, buflen, "AES - Invalid data input length" );
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
|
||||
snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
|
||||
snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
|
||||
snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
|
||||
snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
|
||||
snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
|
||||
snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
|
||||
snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
|
||||
#endif /* MBEDTLS_ASN1_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_BASE64_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
|
||||
snprintf( buf, buflen, "BASE64 - Output buffer too small" );
|
||||
if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
|
||||
mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
|
||||
snprintf( buf, buflen, "BASE64 - Invalid character in input" );
|
||||
#endif /* MBEDTLS_BASE64_C */
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
|
||||
snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
|
||||
snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
|
||||
snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
|
||||
snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
|
||||
snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
|
||||
snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
|
||||
if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
|
||||
snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
#if defined(MBEDTLS_BLOWFISH_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
|
||||
snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
|
||||
if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
|
||||
snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
|
||||
#endif /* MBEDTLS_BLOWFISH_C */
|
||||
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
|
||||
snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
|
||||
snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
|
||||
#endif /* MBEDTLS_CAMELLIA_C */
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
|
||||
mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "CCM - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
|
||||
snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
|
||||
snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
|
||||
mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
|
||||
snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
|
||||
mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
|
||||
snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
|
||||
snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
|
||||
#endif /* MBEDTLS_CTR_DRBG_C */
|
||||
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
|
||||
snprintf( buf, buflen, "DES - The data input has an invalid length" );
|
||||
#endif /* MBEDTLS_DES_C */
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
|
||||
snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
|
||||
mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
|
||||
snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
|
||||
mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
|
||||
snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
|
||||
mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
|
||||
snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
|
||||
if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
|
||||
snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
|
||||
#endif /* MBEDTLS_ENTROPY_C */
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
|
||||
snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
|
||||
mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "GCM - Bad input parameters to function" );
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
|
||||
#if defined(MBEDTLS_HMAC_DRBG_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
|
||||
mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
|
||||
snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
|
||||
if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
|
||||
mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
|
||||
snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
|
||||
if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
|
||||
snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
|
||||
if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
|
||||
snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
|
||||
#endif /* MBEDTLS_HMAC_DRBG_C */
|
||||
|
||||
#if defined(MBEDTLS_NET_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
|
||||
snprintf( buf, buflen, "NET - Failed to open a socket" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
|
||||
snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
|
||||
snprintf( buf, buflen, "NET - Binding of the socket failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
|
||||
snprintf( buf, buflen, "NET - Could not listen on the socket" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
|
||||
snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
|
||||
snprintf( buf, buflen, "NET - Reading information from the socket failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
|
||||
snprintf( buf, buflen, "NET - Sending information through the socket failed" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
|
||||
snprintf( buf, buflen, "NET - Connection was reset by peer" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
|
||||
snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
|
||||
snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
|
||||
if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
|
||||
mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
|
||||
snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
|
||||
#endif /* MBEDTLS_NET_C */
|
||||
|
||||
#if defined(MBEDTLS_OID_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
|
||||
mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
|
||||
snprintf( buf, buflen, "OID - OID is not found" );
|
||||
if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
|
||||
mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
|
||||
snprintf( buf, buflen, "OID - output buffer is too small" );
|
||||
#endif /* MBEDTLS_OID_C */
|
||||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
|
||||
mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
|
||||
snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
|
||||
#endif /* MBEDTLS_PADLOCK_C */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
|
||||
mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
|
||||
snprintf( buf, buflen, "THREADING - The selected feature is not available" );
|
||||
if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
|
||||
mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
|
||||
snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
|
||||
if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
|
||||
mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
|
||||
snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
#if defined(MBEDTLS_XTEA_C)
|
||||
if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
|
||||
mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
|
||||
snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
|
||||
#endif /* MBEDTLS_XTEA_C */
|
||||
/* END generated code */
|
||||
|
||||
if( strlen( buf ) != 0 )
|
||||
return;
|
||||
|
||||
mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
|
||||
snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
|
||||
}
|
||||
|
||||
#else /* MBEDTLS_ERROR_C */
|
||||
|
452
deps/mbedtls/gcm.c
vendored
452
deps/mbedtls/gcm.c
vendored
@ -45,15 +45,6 @@
|
||||
#include "mbedtls/aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
@ -505,447 +496,4 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx )
|
||||
mbedtls_zeroize( ctx, sizeof( mbedtls_gcm_context ) );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
/*
|
||||
* AES-GCM test vectors from:
|
||||
*
|
||||
* http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip
|
||||
*/
|
||||
#define MAX_TESTS 6
|
||||
|
||||
static const int key_index[MAX_TESTS] =
|
||||
{ 0, 0, 1, 1, 1, 1 };
|
||||
|
||||
static const unsigned char gcm_key[MAX_TESTS][32] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
|
||||
};
|
||||
|
||||
static const size_t gcm_iv_len[MAX_TESTS] =
|
||||
{ 12, 12, 12, 12, 8, 60 };
|
||||
|
||||
static const int iv_index[MAX_TESTS] =
|
||||
{ 0, 0, 1, 1, 1, 2 };
|
||||
|
||||
static const unsigned char gcm_iv[MAX_TESTS][64] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
|
||||
0xde, 0xca, 0xf8, 0x88 },
|
||||
{ 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
|
||||
0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
|
||||
0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
|
||||
0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
|
||||
0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
|
||||
0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
|
||||
0xa6, 0x37, 0xb3, 0x9b },
|
||||
};
|
||||
|
||||
static const size_t gcm_add_len[MAX_TESTS] =
|
||||
{ 0, 0, 0, 20, 20, 20 };
|
||||
|
||||
static const int add_index[MAX_TESTS] =
|
||||
{ 0, 0, 0, 1, 1, 1 };
|
||||
|
||||
static const unsigned char additional[MAX_TESTS][64] =
|
||||
{
|
||||
{ 0x00 },
|
||||
{ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xab, 0xad, 0xda, 0xd2 },
|
||||
};
|
||||
|
||||
static const size_t pt_len[MAX_TESTS] =
|
||||
{ 0, 16, 64, 60, 60, 60 };
|
||||
|
||||
static const int pt_index[MAX_TESTS] =
|
||||
{ 0, 0, 1, 1, 1, 1 };
|
||||
|
||||
static const unsigned char pt[MAX_TESTS][64] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
|
||||
0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
|
||||
0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
|
||||
0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
|
||||
0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
|
||||
};
|
||||
|
||||
static const unsigned char ct[MAX_TESTS * 3][64] =
|
||||
{
|
||||
{ 0x00 },
|
||||
{ 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
|
||||
0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 },
|
||||
{ 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
|
||||
0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
|
||||
0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
|
||||
0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
|
||||
0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
|
||||
0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
|
||||
0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
|
||||
0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85 },
|
||||
{ 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
|
||||
0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
|
||||
0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
|
||||
0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
|
||||
0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
|
||||
0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
|
||||
0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
|
||||
0x3d, 0x58, 0xe0, 0x91 },
|
||||
{ 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a,
|
||||
0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55,
|
||||
0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8,
|
||||
0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23,
|
||||
0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2,
|
||||
0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42,
|
||||
0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07,
|
||||
0xc2, 0x3f, 0x45, 0x98 },
|
||||
{ 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
|
||||
0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
|
||||
0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
|
||||
0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
|
||||
0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
|
||||
0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
|
||||
0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
|
||||
0x4c, 0x34, 0xae, 0xe5 },
|
||||
{ 0x00 },
|
||||
{ 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
|
||||
0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 },
|
||||
{ 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
|
||||
0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
|
||||
0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
|
||||
0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
|
||||
0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
|
||||
0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
|
||||
0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
|
||||
0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56 },
|
||||
{ 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
|
||||
0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
|
||||
0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
|
||||
0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
|
||||
0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
|
||||
0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
|
||||
0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
|
||||
0xcc, 0xda, 0x27, 0x10 },
|
||||
{ 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54,
|
||||
0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8,
|
||||
0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f,
|
||||
0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57,
|
||||
0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75,
|
||||
0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9,
|
||||
0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f,
|
||||
0xa0, 0xf0, 0x62, 0xf7 },
|
||||
{ 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
|
||||
0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
|
||||
0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
|
||||
0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
|
||||
0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
|
||||
0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
|
||||
0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
|
||||
0xe9, 0xb7, 0x37, 0x3b },
|
||||
{ 0x00 },
|
||||
{ 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
|
||||
0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18 },
|
||||
{ 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
|
||||
0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
|
||||
0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
|
||||
0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
|
||||
0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
|
||||
0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
|
||||
0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
|
||||
0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad },
|
||||
{ 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
|
||||
0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
|
||||
0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
|
||||
0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
|
||||
0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
|
||||
0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
|
||||
0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
|
||||
0xbc, 0xc9, 0xf6, 0x62 },
|
||||
{ 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32,
|
||||
0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb,
|
||||
0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
|
||||
0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0,
|
||||
0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0,
|
||||
0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
|
||||
0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99,
|
||||
0xf4, 0x7c, 0x9b, 0x1f },
|
||||
{ 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1,
|
||||
0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20,
|
||||
0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19,
|
||||
0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4,
|
||||
0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45,
|
||||
0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde,
|
||||
0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e,
|
||||
0x44, 0xae, 0x7e, 0x3f },
|
||||
};
|
||||
|
||||
static const unsigned char tag[MAX_TESTS * 3][16] =
|
||||
{
|
||||
{ 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
|
||||
0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a },
|
||||
{ 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
|
||||
0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf },
|
||||
{ 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
|
||||
0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 },
|
||||
{ 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
|
||||
0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 },
|
||||
{ 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85,
|
||||
0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb },
|
||||
{ 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
|
||||
0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 },
|
||||
{ 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
|
||||
0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 },
|
||||
{ 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
|
||||
0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb },
|
||||
{ 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
|
||||
0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 },
|
||||
{ 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
|
||||
0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c },
|
||||
{ 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24,
|
||||
0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8 },
|
||||
{ 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
|
||||
0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9 },
|
||||
{ 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
|
||||
0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b },
|
||||
{ 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
|
||||
0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 },
|
||||
{ 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
|
||||
0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c },
|
||||
{ 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
|
||||
0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b },
|
||||
{ 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4,
|
||||
0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 },
|
||||
{ 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0,
|
||||
0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a },
|
||||
};
|
||||
|
||||
int mbedtls_gcm_self_test( int verbose )
|
||||
{
|
||||
mbedtls_gcm_context ctx;
|
||||
unsigned char buf[64];
|
||||
unsigned char tag_buf[16];
|
||||
int i, j, ret;
|
||||
mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
|
||||
|
||||
mbedtls_gcm_init( &ctx );
|
||||
|
||||
for( j = 0; j < 3; j++ )
|
||||
{
|
||||
int key_len = 128 + 64 * j;
|
||||
|
||||
for( i = 0; i < MAX_TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-GCM-%3d #%d (%s): ",
|
||||
key_len, i, "enc" );
|
||||
|
||||
mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
|
||||
|
||||
ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT,
|
||||
pt_len[i],
|
||||
gcm_iv[iv_index[i]], gcm_iv_len[i],
|
||||
additional[add_index[i]], gcm_add_len[i],
|
||||
pt[pt_index[i]], buf, 16, tag_buf );
|
||||
|
||||
if( ret != 0 ||
|
||||
memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 ||
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-GCM-%3d #%d (%s): ",
|
||||
key_len, i, "dec" );
|
||||
|
||||
mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
|
||||
|
||||
ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_DECRYPT,
|
||||
pt_len[i],
|
||||
gcm_iv[iv_index[i]], gcm_iv_len[i],
|
||||
additional[add_index[i]], gcm_add_len[i],
|
||||
ct[j * 6 + i], buf, 16, tag_buf );
|
||||
|
||||
if( ret != 0 ||
|
||||
memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 ||
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-GCM-%3d #%d split (%s): ",
|
||||
key_len, i, "enc" );
|
||||
|
||||
mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
|
||||
|
||||
ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_ENCRYPT,
|
||||
gcm_iv[iv_index[i]], gcm_iv_len[i],
|
||||
additional[add_index[i]], gcm_add_len[i] );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( pt_len[i] > 32 )
|
||||
{
|
||||
size_t rest_len = pt_len[i] - 32;
|
||||
ret = mbedtls_gcm_update( &ctx, 32, pt[pt_index[i]], buf );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_update( &ctx, rest_len, pt[pt_index[i]] + 32,
|
||||
buf + 32 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = mbedtls_gcm_update( &ctx, pt_len[i], pt[pt_index[i]], buf );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
|
||||
if( ret != 0 ||
|
||||
memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 ||
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " AES-GCM-%3d #%d split (%s): ",
|
||||
key_len, i, "dec" );
|
||||
|
||||
mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
|
||||
|
||||
ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_DECRYPT,
|
||||
gcm_iv[iv_index[i]], gcm_iv_len[i],
|
||||
additional[add_index[i]], gcm_add_len[i] );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( pt_len[i] > 32 )
|
||||
{
|
||||
size_t rest_len = pt_len[i] - 32;
|
||||
ret = mbedtls_gcm_update( &ctx, 32, ct[j * 6 + i], buf );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_update( &ctx, rest_len, ct[j * 6 + i] + 32,
|
||||
buf + 32 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = mbedtls_gcm_update( &ctx, pt_len[i], ct[j * 6 + i], buf );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
|
||||
if( ret != 0 ||
|
||||
memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 ||
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
|
135
deps/mbedtls/hmac_drbg.c
vendored
135
deps/mbedtls/hmac_drbg.c
vendored
@ -41,15 +41,6 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#include "arc4_alt.h"
|
||||
|
||||
/*
|
||||
@ -397,130 +388,4 @@ int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const ch
|
||||
}
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_C)
|
||||
/* Dummy checkup routine */
|
||||
int mbedtls_hmac_drbg_self_test( int verbose )
|
||||
{
|
||||
(void) verbose;
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
||||
#define OUTPUT_LEN 80
|
||||
|
||||
/* From a NIST PR=true test vector */
|
||||
static const unsigned char entropy_pr[] = {
|
||||
0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f,
|
||||
0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11,
|
||||
0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42,
|
||||
0x17, 0x60, 0x99, 0xd4, 0x5e, 0x13, 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3,
|
||||
0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4 };
|
||||
static const unsigned char hmac_result_pr[OUTPUT_LEN] = {
|
||||
0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39,
|
||||
0x9b, 0x60, 0x81, 0x48, 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94,
|
||||
0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, 0xfc, 0xcc, 0x2d, 0x54,
|
||||
0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e,
|
||||
0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab,
|
||||
0x46, 0x05, 0x5c, 0x09, 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3,
|
||||
0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44 };
|
||||
|
||||
/* From a NIST PR=false test vector */
|
||||
static const unsigned char entropy_nopr[] = {
|
||||
0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66,
|
||||
0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8,
|
||||
0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3,
|
||||
0xe9, 0x9d, 0xfe, 0xdf };
|
||||
static const unsigned char hmac_result_nopr[OUTPUT_LEN] = {
|
||||
0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f,
|
||||
0xec, 0x5a, 0xdc, 0xa9, 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6,
|
||||
0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, 0x4a, 0x4c, 0x0a, 0x0a,
|
||||
0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec,
|
||||
0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd,
|
||||
0xb5, 0xb3, 0xe9, 0x1b, 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49,
|
||||
0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7 };
|
||||
|
||||
/* "Entropy" from buffer */
|
||||
static size_t test_offset;
|
||||
static int hmac_drbg_self_test_entropy( void *data,
|
||||
unsigned char *buf, size_t len )
|
||||
{
|
||||
const unsigned char *p = (const unsigned char*)data;
|
||||
memcpy( buf, p + test_offset, len );
|
||||
test_offset += len;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
mbedtls_printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Checkup routine for HMAC_DRBG with SHA-1
|
||||
*/
|
||||
int mbedtls_hmac_drbg_self_test( int verbose )
|
||||
{
|
||||
mbedtls_hmac_drbg_context ctx;
|
||||
unsigned char buf[OUTPUT_LEN];
|
||||
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 );
|
||||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
|
||||
/*
|
||||
* PR = True
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " HMAC_DRBG (PR = True) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_hmac_drbg_seed( &ctx, md_info,
|
||||
hmac_drbg_self_test_entropy, (void *) entropy_pr,
|
||||
NULL, 0 ) );
|
||||
mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
|
||||
CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
|
||||
CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
|
||||
CHK( memcmp( buf, hmac_result_pr, OUTPUT_LEN ) );
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
/*
|
||||
* PR = False
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " HMAC_DRBG (PR = False) : " );
|
||||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_hmac_drbg_seed( &ctx, md_info,
|
||||
hmac_drbg_self_test_entropy, (void *) entropy_nopr,
|
||||
NULL, 0 ) );
|
||||
CHK( mbedtls_hmac_drbg_reseed( &ctx, NULL, 0 ) );
|
||||
CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
|
||||
CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
|
||||
CHK( memcmp( buf, hmac_result_nopr, OUTPUT_LEN ) );
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_HMAC_DRBG_C */
|
||||
|
9
deps/mbedtls/mbedtls/ccm.h
vendored
9
deps/mbedtls/mbedtls/ccm.h
vendored
@ -125,15 +125,6 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_ccm_self_test( int verbose );
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
9
deps/mbedtls/mbedtls/cmac.h
vendored
9
deps/mbedtls/mbedtls/cmac.h
vendored
@ -154,15 +154,6 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
||||
unsigned char output[16] );
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_cmac_self_test( int verbose );
|
||||
#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
3
deps/mbedtls/mbedtls/compat-1.3.h
vendored
3
deps/mbedtls/mbedtls/compat-1.3.h
vendored
@ -450,9 +450,6 @@
|
||||
#if defined MBEDTLS_RSA_NO_CRT
|
||||
#define POLARSSL_RSA_NO_CRT MBEDTLS_RSA_NO_CRT
|
||||
#endif
|
||||
#if defined MBEDTLS_SELF_TEST
|
||||
#define POLARSSL_SELF_TEST MBEDTLS_SELF_TEST
|
||||
#endif
|
||||
#if defined MBEDTLS_SHA1_ALT
|
||||
#define POLARSSL_SHA1_ALT MBEDTLS_SHA1_ALT
|
||||
#endif
|
||||
|
74
deps/mbedtls/mbedtls/config.h
vendored
74
deps/mbedtls/mbedtls/config.h
vendored
@ -124,32 +124,6 @@
|
||||
*/
|
||||
#define MBEDTLS_HAVE_TIME_DATE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PLATFORM_MEMORY
|
||||
*
|
||||
* Enable the memory allocation layer.
|
||||
*
|
||||
* By default mbed TLS uses the system-provided calloc() and free().
|
||||
* This allows different allocators (self-implemented or provided) to be
|
||||
* provided to the platform abstraction layer.
|
||||
*
|
||||
* Enabling MBEDTLS_PLATFORM_MEMORY without the
|
||||
* MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
|
||||
* "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
|
||||
* free() function pointer at runtime.
|
||||
*
|
||||
* Enabling MBEDTLS_PLATFORM_MEMORY and specifying
|
||||
* MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
|
||||
* alternate function at compile time.
|
||||
*
|
||||
* Requires: MBEDTLS_PLATFORM_C
|
||||
*
|
||||
* Enable this layer to allow use of alternative memory allocators.
|
||||
*/
|
||||
#if 0
|
||||
#define MBEDTLS_PLATFORM_MEMORY
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
||||
*
|
||||
@ -171,39 +145,6 @@
|
||||
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PLATFORM_EXIT_ALT
|
||||
*
|
||||
* MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
|
||||
* function in the platform abstraction layer.
|
||||
*
|
||||
* Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
|
||||
* provide a function "mbedtls_platform_set_printf()" that allows you to set an
|
||||
* alternative printf function pointer.
|
||||
*
|
||||
* All these define require MBEDTLS_PLATFORM_C to be defined!
|
||||
*
|
||||
* \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
|
||||
* it will be enabled automatically by check_config.h
|
||||
*
|
||||
* \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
|
||||
* MBEDTLS_PLATFORM_XXX_MACRO!
|
||||
*
|
||||
* Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
|
||||
*
|
||||
* Uncomment a macro to enable alternate implementation of specific base
|
||||
* platform function
|
||||
*/
|
||||
#if 0
|
||||
#define MBEDTLS_PLATFORM_EXIT_ALT
|
||||
#define MBEDTLS_PLATFORM_TIME_ALT
|
||||
#define MBEDTLS_PLATFORM_FPRINTF_ALT
|
||||
#define MBEDTLS_PLATFORM_PRINTF_ALT
|
||||
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
|
||||
#define MBEDTLS_PLATFORM_NV_SEED_ALT
|
||||
#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_DEPRECATED_WARNING
|
||||
*
|
||||
@ -1074,15 +1015,6 @@
|
||||
#define MBEDTLS_RSA_NO_CRT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SELF_TEST
|
||||
*
|
||||
* Enable the checkup functions (*_self_test).
|
||||
*/
|
||||
#if 0
|
||||
#define MBEDTLS_SELF_TEST
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SHA256_SMALLER
|
||||
*
|
||||
@ -2730,14 +2662,10 @@
|
||||
/* Platform options */
|
||||
#if 0
|
||||
#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
|
||||
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
|
||||
/* Note: your snprintf must correclty zero-terminate the buffer! */
|
||||
#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
|
||||
@ -2755,8 +2683,6 @@
|
||||
#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
|
||||
#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
|
||||
/* Note: your snprintf must correclty zero-terminate the buffer! */
|
||||
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
|
||||
#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
|
||||
#endif
|
||||
|
9
deps/mbedtls/mbedtls/ecjpake.h
vendored
9
deps/mbedtls/mbedtls/ecjpake.h
vendored
@ -222,15 +222,6 @@ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
|
||||
*/
|
||||
void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_ecjpake_self_test( int verbose );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
11
deps/mbedtls/mbedtls/ecp.h
vendored
11
deps/mbedtls/mbedtls/ecp.h
vendored
@ -662,17 +662,6 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
*/
|
||||
int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_ecp_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
29
deps/mbedtls/mbedtls/entropy.h
vendored
29
deps/mbedtls/mbedtls/entropy.h
vendored
@ -251,35 +251,6 @@ int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *p
|
||||
int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* This module self-test also calls the entropy self-test,
|
||||
* mbedtls_entropy_source_self_test();
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_entropy_self_test( int verbose );
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* Verifies the integrity of the hardware entropy source
|
||||
* provided by the function 'mbedtls_hardware_poll()'.
|
||||
*
|
||||
* Note this is the only hardware entropy source that is known
|
||||
* at link time, and other entropy sources configured
|
||||
* dynamically at runtime by the function
|
||||
* mbedtls_entropy_add_source() will not be tested.
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_entropy_source_self_test( int verbose );
|
||||
#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
10
deps/mbedtls/mbedtls/hmac_drbg.h
vendored
10
deps/mbedtls/mbedtls/hmac_drbg.h
vendored
@ -282,16 +282,6 @@ int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const cha
|
||||
int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_hmac_drbg_self_test( int verbose );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
9
deps/mbedtls/mbedtls/memory_buffer_alloc.h
vendored
9
deps/mbedtls/mbedtls/memory_buffer_alloc.h
vendored
@ -134,15 +134,6 @@ void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks )
|
||||
*/
|
||||
int mbedtls_memory_buffer_alloc_verify( void );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_memory_buffer_alloc_self_test( int verbose );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
47
deps/mbedtls/mbedtls/platform.h
vendored
47
deps/mbedtls/mbedtls/platform.h
vendored
@ -49,25 +49,12 @@ extern "C" {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
|
||||
#if defined(_WIN32)
|
||||
#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< Default snprintf to use */
|
||||
#else
|
||||
#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
|
||||
#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
|
||||
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use */
|
||||
#endif
|
||||
@ -177,40 +164,6 @@ int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
|
||||
/*
|
||||
* The function pointers for snprintf
|
||||
*
|
||||
* The snprintf implementation should conform to C99:
|
||||
* - it *must* always correctly zero-terminate the buffer
|
||||
* (except when n == 0, then it must leave the buffer untouched)
|
||||
* - however it is acceptable to return -1 instead of the required length when
|
||||
* the destination buffer is too short.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
/* For Windows (inc. MSYS2), we provide our own fixed implementation */
|
||||
int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||
extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
|
||||
|
||||
/**
|
||||
* \brief Set your own snprintf function pointer
|
||||
*
|
||||
* \param snprintf_func the snprintf function implementation
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
|
||||
const char * format, ... ) );
|
||||
#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
|
||||
#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
|
||||
#else
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
|
||||
#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
|
||||
/*
|
||||
* The function pointers for exit
|
||||
*/
|
||||
|
9
deps/mbedtls/mbedtls/timing.h
vendored
9
deps/mbedtls/mbedtls/timing.h
vendored
@ -124,15 +124,6 @@ int mbedtls_timing_get_delay( void *data );
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_timing_self_test( int verbose );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
80
deps/mbedtls/md2.c
vendored
80
deps/mbedtls/md2.c
vendored
@ -37,15 +37,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_MD2_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -211,75 +202,4 @@ void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[
|
||||
mbedtls_md2_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* RFC 1319 test vectors
|
||||
*/
|
||||
static const char md2_test_str[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const unsigned char md2_test_sum[7][16] =
|
||||
{
|
||||
{ 0x83, 0x50, 0xE5, 0xA3, 0xE2, 0x4C, 0x15, 0x3D,
|
||||
0xF2, 0x27, 0x5C, 0x9F, 0x80, 0x69, 0x27, 0x73 },
|
||||
{ 0x32, 0xEC, 0x01, 0xEC, 0x4A, 0x6D, 0xAC, 0x72,
|
||||
0xC0, 0xAB, 0x96, 0xFB, 0x34, 0xC0, 0xB5, 0xD1 },
|
||||
{ 0xDA, 0x85, 0x3B, 0x0D, 0x3F, 0x88, 0xD9, 0x9B,
|
||||
0x30, 0x28, 0x3A, 0x69, 0xE6, 0xDE, 0xD6, 0xBB },
|
||||
{ 0xAB, 0x4F, 0x49, 0x6B, 0xFB, 0x2A, 0x53, 0x0B,
|
||||
0x21, 0x9F, 0xF3, 0x30, 0x31, 0xFE, 0x06, 0xB0 },
|
||||
{ 0x4E, 0x8D, 0xDF, 0xF3, 0x65, 0x02, 0x92, 0xAB,
|
||||
0x5A, 0x41, 0x08, 0xC3, 0xAA, 0x47, 0x94, 0x0B },
|
||||
{ 0xDA, 0x33, 0xDE, 0xF2, 0xA4, 0x2D, 0xF1, 0x39,
|
||||
0x75, 0x35, 0x28, 0x46, 0xC3, 0x03, 0x38, 0xCD },
|
||||
{ 0xD5, 0x97, 0x6F, 0x79, 0xD8, 0x3D, 0x3A, 0x0D,
|
||||
0xC9, 0x80, 0x6C, 0x3C, 0x66, 0xF3, 0xEF, 0xD8 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_md2_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
unsigned char md2sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD2 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_md2( (unsigned char *) md2_test_str[i],
|
||||
strlen( md2_test_str[i] ), md2sum );
|
||||
|
||||
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
|
80
deps/mbedtls/md4.c
vendored
80
deps/mbedtls/md4.c
vendored
@ -37,15 +37,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_MD4_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -307,75 +298,4 @@ void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[
|
||||
mbedtls_md4_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* RFC 1320 test vectors
|
||||
*/
|
||||
static const char md4_test_str[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const unsigned char md4_test_sum[7][16] =
|
||||
{
|
||||
{ 0x31, 0xD6, 0xCF, 0xE0, 0xD1, 0x6A, 0xE9, 0x31,
|
||||
0xB7, 0x3C, 0x59, 0xD7, 0xE0, 0xC0, 0x89, 0xC0 },
|
||||
{ 0xBD, 0xE5, 0x2C, 0xB3, 0x1D, 0xE3, 0x3E, 0x46,
|
||||
0x24, 0x5E, 0x05, 0xFB, 0xDB, 0xD6, 0xFB, 0x24 },
|
||||
{ 0xA4, 0x48, 0x01, 0x7A, 0xAF, 0x21, 0xD8, 0x52,
|
||||
0x5F, 0xC1, 0x0A, 0xE8, 0x7A, 0xA6, 0x72, 0x9D },
|
||||
{ 0xD9, 0x13, 0x0A, 0x81, 0x64, 0x54, 0x9F, 0xE8,
|
||||
0x18, 0x87, 0x48, 0x06, 0xE1, 0xC7, 0x01, 0x4B },
|
||||
{ 0xD7, 0x9E, 0x1C, 0x30, 0x8A, 0xA5, 0xBB, 0xCD,
|
||||
0xEE, 0xA8, 0xED, 0x63, 0xDF, 0x41, 0x2D, 0xA9 },
|
||||
{ 0x04, 0x3F, 0x85, 0x82, 0xF2, 0x41, 0xDB, 0x35,
|
||||
0x1C, 0xE6, 0x27, 0xE1, 0x53, 0xE7, 0xF0, 0xE4 },
|
||||
{ 0xE3, 0x3B, 0x4D, 0xDC, 0x9C, 0x38, 0xF2, 0x19,
|
||||
0x9C, 0x3E, 0x7B, 0x16, 0x4F, 0xCC, 0x05, 0x36 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_md4_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
unsigned char md4sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD4 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_md4( (unsigned char *) md4_test_str[i],
|
||||
strlen( md4_test_str[i] ), md4sum );
|
||||
|
||||
if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
|
83
deps/mbedtls/md5.c
vendored
83
deps/mbedtls/md5.c
vendored
@ -36,15 +36,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_MD5_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -324,78 +315,4 @@ void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[
|
||||
mbedtls_md5_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* RFC 1321 test vectors
|
||||
*/
|
||||
static const unsigned char md5_test_buf[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const int md5_test_buflen[7] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 62, 80
|
||||
};
|
||||
|
||||
static const unsigned char md5_test_sum[7][16] =
|
||||
{
|
||||
{ 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
|
||||
0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
|
||||
{ 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
|
||||
0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
|
||||
{ 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
|
||||
0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
|
||||
{ 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
|
||||
0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
|
||||
{ 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
|
||||
0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
|
||||
{ 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
|
||||
0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
|
||||
{ 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
|
||||
0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_md5_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
unsigned char md5sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD5 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_md5( md5_test_buf[i], md5_test_buflen[i], md5sum );
|
||||
|
||||
if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
|
134
deps/mbedtls/memory_buffer_alloc.c
vendored
134
deps/mbedtls/memory_buffer_alloc.c
vendored
@ -605,138 +605,4 @@ void mbedtls_memory_buffer_alloc_free()
|
||||
mbedtls_zeroize( &heap, sizeof(buffer_alloc_ctx) );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
static int check_pointer( void *p )
|
||||
{
|
||||
if( p == NULL )
|
||||
return( -1 );
|
||||
|
||||
if( (size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0 )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int check_all_free( )
|
||||
{
|
||||
if(
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
heap.total_used != 0 ||
|
||||
#endif
|
||||
heap.first != heap.first_free ||
|
||||
(void *) heap.first != (void *) heap.buf )
|
||||
{
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define TEST_ASSERT( condition ) \
|
||||
if( ! (condition) ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
mbedtls_printf( "failed\n" ); \
|
||||
\
|
||||
ret = 1; \
|
||||
goto cleanup; \
|
||||
}
|
||||
|
||||
int mbedtls_memory_buffer_alloc_self_test( int verbose )
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char *p, *q, *r, *end;
|
||||
int ret = 0;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MBA test #1 (basic alloc-free cycle): " );
|
||||
|
||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||
|
||||
p = mbedtls_calloc( 1, 1 );
|
||||
q = mbedtls_calloc( 1, 128 );
|
||||
r = mbedtls_calloc( 1, 16 );
|
||||
|
||||
TEST_ASSERT( check_pointer( p ) == 0 &&
|
||||
check_pointer( q ) == 0 &&
|
||||
check_pointer( r ) == 0 );
|
||||
|
||||
mbedtls_free( r );
|
||||
mbedtls_free( q );
|
||||
mbedtls_free( p );
|
||||
|
||||
TEST_ASSERT( check_all_free( ) == 0 );
|
||||
|
||||
/* Memorize end to compare with the next test */
|
||||
end = heap.buf + heap.len;
|
||||
|
||||
mbedtls_memory_buffer_alloc_free( );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MBA test #2 (buf not aligned): " );
|
||||
|
||||
mbedtls_memory_buffer_alloc_init( buf + 1, sizeof( buf ) - 1 );
|
||||
|
||||
TEST_ASSERT( heap.buf + heap.len == end );
|
||||
|
||||
p = mbedtls_calloc( 1, 1 );
|
||||
q = mbedtls_calloc( 1, 128 );
|
||||
r = mbedtls_calloc( 1, 16 );
|
||||
|
||||
TEST_ASSERT( check_pointer( p ) == 0 &&
|
||||
check_pointer( q ) == 0 &&
|
||||
check_pointer( r ) == 0 );
|
||||
|
||||
mbedtls_free( r );
|
||||
mbedtls_free( q );
|
||||
mbedtls_free( p );
|
||||
|
||||
TEST_ASSERT( check_all_free( ) == 0 );
|
||||
|
||||
mbedtls_memory_buffer_alloc_free( );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MBA test #3 (full): " );
|
||||
|
||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||
|
||||
p = mbedtls_calloc( 1, sizeof( buf ) - sizeof( memory_header ) );
|
||||
|
||||
TEST_ASSERT( check_pointer( p ) == 0 );
|
||||
TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
|
||||
|
||||
mbedtls_free( p );
|
||||
|
||||
p = mbedtls_calloc( 1, sizeof( buf ) - 2 * sizeof( memory_header ) - 16 );
|
||||
q = mbedtls_calloc( 1, 16 );
|
||||
|
||||
TEST_ASSERT( check_pointer( p ) == 0 && check_pointer( q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
|
||||
|
||||
mbedtls_free( q );
|
||||
|
||||
TEST_ASSERT( mbedtls_calloc( 1, 17 ) == NULL );
|
||||
|
||||
mbedtls_free( p );
|
||||
|
||||
TEST_ASSERT( check_all_free( ) == 0 );
|
||||
|
||||
mbedtls_memory_buffer_alloc_free( );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
mbedtls_memory_buffer_alloc_free( );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
|
||||
|
10
deps/mbedtls/oid.c
vendored
10
deps/mbedtls/oid.c
vendored
@ -35,12 +35,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
|
||||
#include "mbedtls/x509.h"
|
||||
#endif
|
||||
@ -681,7 +675,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size,
|
||||
/* First byte contains first two dots */
|
||||
if( oid->len > 0 )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
|
||||
ret = snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
|
||||
OID_SAFE_SNPRINTF;
|
||||
}
|
||||
|
||||
@ -698,7 +692,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size,
|
||||
if( !( oid->p[i] & 0x80 ) )
|
||||
{
|
||||
/* Last byte */
|
||||
ret = mbedtls_snprintf( p, n, ".%d", value );
|
||||
ret = snprintf( p, n, ".%d", value );
|
||||
OID_SAFE_SNPRINTF;
|
||||
value = 0;
|
||||
}
|
||||
|
118
deps/mbedtls/pkcs5.c
vendored
118
deps/mbedtls/pkcs5.c
vendored
@ -281,122 +281,4 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_C)
|
||||
int mbedtls_pkcs5_self_test( int verbose )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " PBKDF2 (SHA1): skipped\n\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
||||
#define MAX_TESTS 6
|
||||
|
||||
static const size_t plen[MAX_TESTS] =
|
||||
{ 8, 8, 8, 24, 9 };
|
||||
|
||||
static const unsigned char password[MAX_TESTS][32] =
|
||||
{
|
||||
"password",
|
||||
"password",
|
||||
"password",
|
||||
"passwordPASSWORDpassword",
|
||||
"pass\0word",
|
||||
};
|
||||
|
||||
static const size_t slen[MAX_TESTS] =
|
||||
{ 4, 4, 4, 36, 5 };
|
||||
|
||||
static const unsigned char salt[MAX_TESTS][40] =
|
||||
{
|
||||
"salt",
|
||||
"salt",
|
||||
"salt",
|
||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt",
|
||||
"sa\0lt",
|
||||
};
|
||||
|
||||
static const uint32_t it_cnt[MAX_TESTS] =
|
||||
{ 1, 2, 4096, 4096, 4096 };
|
||||
|
||||
static const uint32_t key_len[MAX_TESTS] =
|
||||
{ 20, 20, 20, 25, 16 };
|
||||
|
||||
static const unsigned char result_key[MAX_TESTS][32] =
|
||||
{
|
||||
{ 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
|
||||
0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
|
||||
0x2f, 0xe0, 0x37, 0xa6 },
|
||||
{ 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
|
||||
0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
|
||||
0xd8, 0xde, 0x89, 0x57 },
|
||||
{ 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
|
||||
0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
|
||||
0x65, 0xa4, 0x29, 0xc1 },
|
||||
{ 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
|
||||
0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
|
||||
0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
|
||||
0x38 },
|
||||
{ 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
|
||||
0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 },
|
||||
};
|
||||
|
||||
int mbedtls_pkcs5_self_test( int verbose )
|
||||
{
|
||||
mbedtls_md_context_t sha1_ctx;
|
||||
const mbedtls_md_info_t *info_sha1;
|
||||
int ret, i;
|
||||
unsigned char key[64];
|
||||
|
||||
mbedtls_md_init( &sha1_ctx );
|
||||
|
||||
info_sha1 = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 );
|
||||
if( info_sha1 == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_md_setup( &sha1_ctx, info_sha1, 1 ) ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( i = 0; i < MAX_TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " PBKDF2 (SHA1) #%d: ", i );
|
||||
|
||||
ret = mbedtls_pkcs5_pbkdf2_hmac( &sha1_ctx, password[i], plen[i], salt[i],
|
||||
slen[i], it_cnt[i], key_len[i], key );
|
||||
if( ret != 0 ||
|
||||
memcmp( result_key[i], key, key_len[i] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_md_free( &sha1_ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_PKCS5_C */
|
||||
|
91
deps/mbedtls/platform.c
vendored
91
deps/mbedtls/platform.c
vendored
@ -29,97 +29,6 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
static void *platform_calloc_uninit( size_t n, size_t size )
|
||||
{
|
||||
((void) n);
|
||||
((void) size);
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
|
||||
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
static void platform_free_uninit( void *ptr )
|
||||
{
|
||||
((void) ptr);
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_FREE */
|
||||
|
||||
void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
|
||||
void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
|
||||
|
||||
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
mbedtls_calloc = calloc_func;
|
||||
mbedtls_free = free_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <stdarg.h>
|
||||
int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
|
||||
{
|
||||
int ret;
|
||||
va_list argp;
|
||||
|
||||
/* Avoid calling the invalid parameter handler by checking ourselves */
|
||||
if( s == NULL || n == 0 || fmt == NULL )
|
||||
return( -1 );
|
||||
|
||||
va_start( argp, fmt );
|
||||
#if defined(_TRUNCATE)
|
||||
ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
|
||||
#else
|
||||
ret = _vsnprintf( s, n, fmt, argp );
|
||||
if( ret < 0 || (size_t) ret == n )
|
||||
{
|
||||
s[n-1] = '\0';
|
||||
ret = -1;
|
||||
}
|
||||
#endif
|
||||
va_end( argp );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_snprintf_uninit( char * s, size_t n,
|
||||
const char * format, ... )
|
||||
{
|
||||
((void) s);
|
||||
((void) n);
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
|
||||
|
||||
int (*mbedtls_snprintf)( char * s, size_t n,
|
||||
const char * format,
|
||||
... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
|
||||
|
||||
int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
|
||||
const char * format,
|
||||
... ) )
|
||||
{
|
||||
mbedtls_snprintf = snprintf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
|
||||
/*
|
||||
|
88
deps/mbedtls/ripemd160.c
vendored
88
deps/mbedtls/ripemd160.c
vendored
@ -37,15 +37,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
@ -392,83 +383,4 @@ void mbedtls_ripemd160( const unsigned char *input, size_t ilen,
|
||||
mbedtls_ripemd160_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* Test vectors from the RIPEMD-160 paper and
|
||||
* http://homes.esat.kuleuven.be/~bosselae/mbedtls_ripemd160.html#HMAC
|
||||
*/
|
||||
#define TESTS 8
|
||||
#define KEYS 2
|
||||
static const char *ripemd160_test_input[TESTS] =
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"1234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890",
|
||||
};
|
||||
|
||||
static const unsigned char ripemd160_test_md[TESTS][20] =
|
||||
{
|
||||
{ 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28,
|
||||
0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31 },
|
||||
{ 0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae,
|
||||
0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe },
|
||||
{ 0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04,
|
||||
0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc },
|
||||
{ 0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8,
|
||||
0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36 },
|
||||
{ 0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb,
|
||||
0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc },
|
||||
{ 0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05,
|
||||
0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b },
|
||||
{ 0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed,
|
||||
0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89 },
|
||||
{ 0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb,
|
||||
0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb },
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_ripemd160_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
unsigned char output[20];
|
||||
|
||||
memset( output, 0, sizeof output );
|
||||
|
||||
for( i = 0; i < TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " RIPEMD-160 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_ripemd160( (const unsigned char *) ripemd160_test_input[i],
|
||||
strlen( ripemd160_test_input[i] ),
|
||||
output );
|
||||
|
||||
if( memcmp( output, ripemd160_test_md[i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_RIPEMD160_C */
|
||||
|
202
deps/mbedtls/rsa.c
vendored
202
deps/mbedtls/rsa.c
vendored
@ -1664,206 +1664,4 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx )
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#include "mbedtls/sha1.h"
|
||||
|
||||
/*
|
||||
* Example RSA-1024 keypair, for test purposes
|
||||
*/
|
||||
#define KEY_LEN 128
|
||||
|
||||
#define RSA_N "9292758453063D803DD603D5E777D788" \
|
||||
"8ED1D5BF35786190FA2F23EBC0848AEA" \
|
||||
"DDA92CA6C3D80B32C4D109BE0F36D6AE" \
|
||||
"7130B9CED7ACDF54CFC7555AC14EEBAB" \
|
||||
"93A89813FBF3C4F8066D2D800F7C38A8" \
|
||||
"1AE31942917403FF4946B0A83D3D3E05" \
|
||||
"EE57C6F5F5606FB5D4BC6CD34EE0801A" \
|
||||
"5E94BB77B07507233A0BC7BAC8F90F79"
|
||||
|
||||
#define RSA_E "10001"
|
||||
|
||||
#define RSA_D "24BF6185468786FDD303083D25E64EFC" \
|
||||
"66CA472BC44D253102F8B4A9D3BFA750" \
|
||||
"91386C0077937FE33FA3252D28855837" \
|
||||
"AE1B484A8A9A45F7EE8C0C634F99E8CD" \
|
||||
"DF79C5CE07EE72C7F123142198164234" \
|
||||
"CABB724CF78B8173B9F880FC86322407" \
|
||||
"AF1FEDFDDE2BEB674CA15F3E81A1521E" \
|
||||
"071513A1E85B5DFA031F21ECAE91A34D"
|
||||
|
||||
#define RSA_P "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
|
||||
"2C01CAD19EA484A87EA4377637E75500" \
|
||||
"FCB2005C5C7DD6EC4AC023CDA285D796" \
|
||||
"C3D9E75E1EFC42488BB4F1D13AC30A57"
|
||||
|
||||
#define RSA_Q "C000DF51A7C77AE8D7C7370C1FF55B69" \
|
||||
"E211C2B9E5DB1ED0BF61D0D9899620F4" \
|
||||
"910E4168387E3C30AA1E00C339A79508" \
|
||||
"8452DD96A9A5EA5D9DCA68DA636032AF"
|
||||
|
||||
#define RSA_DP "C1ACF567564274FB07A0BBAD5D26E298" \
|
||||
"3C94D22288ACD763FD8E5600ED4A702D" \
|
||||
"F84198A5F06C2E72236AE490C93F07F8" \
|
||||
"3CC559CD27BC2D1CA488811730BB5725"
|
||||
|
||||
#define RSA_DQ "4959CBF6F8FEF750AEE6977C155579C7" \
|
||||
"D8AAEA56749EA28623272E4F7D0592AF" \
|
||||
"7C1F1313CAC9471B5C523BFE592F517B" \
|
||||
"407A1BD76C164B93DA2D32A383E58357"
|
||||
|
||||
#define RSA_QP "9AE7FBC99546432DF71896FC239EADAE" \
|
||||
"F38D18D2B2F0E2DD275AA977E2BF4411" \
|
||||
"F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \
|
||||
"A74206CEC169D74BF5A8C50D6F48EA08"
|
||||
|
||||
#define PT_LEN 24
|
||||
#define RSA_PT "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
|
||||
"\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
|
||||
|
||||
#if defined(MBEDTLS_PKCS1_V15)
|
||||
static int myrand( void *rng_state, unsigned char *output, size_t len )
|
||||
{
|
||||
#if !defined(__OpenBSD__)
|
||||
size_t i;
|
||||
|
||||
if( rng_state != NULL )
|
||||
rng_state = NULL;
|
||||
|
||||
for( i = 0; i < len; ++i )
|
||||
output[i] = rand();
|
||||
#else
|
||||
if( rng_state != NULL )
|
||||
rng_state = NULL;
|
||||
|
||||
arc4random_buf( output, len );
|
||||
#endif /* !OpenBSD */
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_rsa_self_test( int verbose )
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_PKCS1_V15)
|
||||
size_t len;
|
||||
mbedtls_rsa_context rsa;
|
||||
unsigned char rsa_plaintext[PT_LEN];
|
||||
unsigned char rsa_decrypted[PT_LEN];
|
||||
unsigned char rsa_ciphertext[KEY_LEN];
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
unsigned char sha1sum[20];
|
||||
#endif
|
||||
|
||||
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
rsa.len = KEY_LEN;
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.N , 16, RSA_N ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.E , 16, RSA_E ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.D , 16, RSA_D ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.P , 16, RSA_P ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.Q , 16, RSA_Q ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DP, 16, RSA_DP ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DQ, 16, RSA_DQ ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.QP, 16, RSA_QP ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " RSA key validation: " );
|
||||
|
||||
if( mbedtls_rsa_check_pubkey( &rsa ) != 0 ||
|
||||
mbedtls_rsa_check_privkey( &rsa ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n PKCS#1 encryption : " );
|
||||
|
||||
memcpy( rsa_plaintext, RSA_PT, PT_LEN );
|
||||
|
||||
if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PUBLIC, PT_LEN,
|
||||
rsa_plaintext, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n PKCS#1 decryption : " );
|
||||
|
||||
if( mbedtls_rsa_pkcs1_decrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, &len,
|
||||
rsa_ciphertext, rsa_decrypted,
|
||||
sizeof(rsa_decrypted) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " PKCS#1 data sign : " );
|
||||
|
||||
mbedtls_sha1( rsa_plaintext, PT_LEN, sha1sum );
|
||||
|
||||
if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0,
|
||||
sha1sum, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n PKCS#1 sig. verify: " );
|
||||
|
||||
if( mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0,
|
||||
sha1sum, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
cleanup:
|
||||
mbedtls_rsa_free( &rsa );
|
||||
#else /* MBEDTLS_PKCS1_V15 */
|
||||
((void) verbose);
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
94
deps/mbedtls/sha1.c
vendored
94
deps/mbedtls/sha1.c
vendored
@ -36,15 +36,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_SHA1_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -357,89 +348,4 @@ void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output
|
||||
mbedtls_sha1_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-1 test vectors
|
||||
*/
|
||||
static const unsigned char sha1_test_buf[3][57] =
|
||||
{
|
||||
{ "abc" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha1_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
||||
static const unsigned char sha1_test_sum[3][20] =
|
||||
{
|
||||
{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
|
||||
0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
|
||||
{ 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
|
||||
0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
|
||||
{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
|
||||
0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_sha1_self_test( int verbose )
|
||||
{
|
||||
int i, j, buflen, ret = 0;
|
||||
unsigned char buf[1024];
|
||||
unsigned char sha1sum[20];
|
||||
mbedtls_sha1_context ctx;
|
||||
|
||||
mbedtls_sha1_init( &ctx );
|
||||
|
||||
/*
|
||||
* SHA-1
|
||||
*/
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " SHA-1 test #%d: ", i + 1 );
|
||||
|
||||
mbedtls_sha1_starts( &ctx );
|
||||
|
||||
if( i == 2 )
|
||||
{
|
||||
memset( buf, 'a', buflen = 1000 );
|
||||
|
||||
for( j = 0; j < 1000; j++ )
|
||||
mbedtls_sha1_update( &ctx, buf, buflen );
|
||||
}
|
||||
else
|
||||
mbedtls_sha1_update( &ctx, sha1_test_buf[i],
|
||||
sha1_test_buflen[i] );
|
||||
|
||||
mbedtls_sha1_finish( &ctx, sha1sum );
|
||||
|
||||
if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_sha1_free( &ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
|
132
deps/mbedtls/sha256.c
vendored
132
deps/mbedtls/sha256.c
vendored
@ -36,18 +36,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_SHA256_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -336,124 +324,4 @@ void mbedtls_sha256( const unsigned char *input, size_t ilen,
|
||||
mbedtls_sha256_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* FIPS-180-2 test vectors
|
||||
*/
|
||||
static const unsigned char sha256_test_buf[3][57] =
|
||||
{
|
||||
{ "abc" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha256_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
||||
static const unsigned char sha256_test_sum[6][32] =
|
||||
{
|
||||
/*
|
||||
* SHA-224 test vectors
|
||||
*/
|
||||
{ 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
|
||||
0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
|
||||
0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
|
||||
0xE3, 0x6C, 0x9D, 0xA7 },
|
||||
{ 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
|
||||
0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
|
||||
0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
|
||||
0x52, 0x52, 0x25, 0x25 },
|
||||
{ 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
|
||||
0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
|
||||
0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
|
||||
0x4E, 0xE7, 0xAD, 0x67 },
|
||||
|
||||
/*
|
||||
* SHA-256 test vectors
|
||||
*/
|
||||
{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
|
||||
0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
|
||||
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
|
||||
0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
|
||||
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
|
||||
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
|
||||
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
|
||||
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
|
||||
{ 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
|
||||
0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
|
||||
0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
|
||||
0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_sha256_self_test( int verbose )
|
||||
{
|
||||
int i, j, k, buflen, ret = 0;
|
||||
unsigned char *buf;
|
||||
unsigned char sha256sum[32];
|
||||
mbedtls_sha256_context ctx;
|
||||
|
||||
buf = mbedtls_calloc( 1024, sizeof(unsigned char) );
|
||||
if( NULL == buf )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "Buffer allocation failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_sha256_init( &ctx );
|
||||
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
j = i % 3;
|
||||
k = i < 3;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
|
||||
mbedtls_sha256_starts( &ctx, k );
|
||||
|
||||
if( j == 2 )
|
||||
{
|
||||
memset( buf, 'a', buflen = 1000 );
|
||||
|
||||
for( j = 0; j < 1000; j++ )
|
||||
mbedtls_sha256_update( &ctx, buf, buflen );
|
||||
}
|
||||
else
|
||||
mbedtls_sha256_update( &ctx, sha256_test_buf[j],
|
||||
sha256_test_buflen[j] );
|
||||
|
||||
mbedtls_sha256_finish( &ctx, sha256sum );
|
||||
|
||||
if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_sha256_free( &ctx );
|
||||
mbedtls_free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
|
152
deps/mbedtls/sha512.c
vendored
152
deps/mbedtls/sha512.c
vendored
@ -42,18 +42,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_SHA512_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -371,144 +359,4 @@ void mbedtls_sha512( const unsigned char *input, size_t ilen,
|
||||
mbedtls_sha512_free( &ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* FIPS-180-2 test vectors
|
||||
*/
|
||||
static const unsigned char sha512_test_buf[3][113] =
|
||||
{
|
||||
{ "abc" },
|
||||
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
|
||||
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" },
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha512_test_buflen[3] =
|
||||
{
|
||||
3, 112, 1000
|
||||
};
|
||||
|
||||
static const unsigned char sha512_test_sum[6][64] =
|
||||
{
|
||||
/*
|
||||
* SHA-384 test vectors
|
||||
*/
|
||||
{ 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
|
||||
0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
|
||||
0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
|
||||
0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
|
||||
0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
|
||||
0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 },
|
||||
{ 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8,
|
||||
0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47,
|
||||
0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2,
|
||||
0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12,
|
||||
0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9,
|
||||
0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39 },
|
||||
{ 0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB,
|
||||
0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C,
|
||||
0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52,
|
||||
0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B,
|
||||
0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB,
|
||||
0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85 },
|
||||
|
||||
/*
|
||||
* SHA-512 test vectors
|
||||
*/
|
||||
{ 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
|
||||
0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
|
||||
0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
|
||||
0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
|
||||
0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
|
||||
0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
|
||||
0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
|
||||
0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F },
|
||||
{ 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA,
|
||||
0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F,
|
||||
0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1,
|
||||
0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18,
|
||||
0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4,
|
||||
0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A,
|
||||
0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54,
|
||||
0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09 },
|
||||
{ 0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64,
|
||||
0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63,
|
||||
0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, 0x44, 0x28,
|
||||
0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB,
|
||||
0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A,
|
||||
0x4C, 0xB0, 0x43, 0x2C, 0xE5, 0x77, 0xC3, 0x1B,
|
||||
0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E,
|
||||
0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_sha512_self_test( int verbose )
|
||||
{
|
||||
int i, j, k, buflen, ret = 0;
|
||||
unsigned char *buf;
|
||||
unsigned char sha512sum[64];
|
||||
mbedtls_sha512_context ctx;
|
||||
|
||||
buf = mbedtls_calloc( 1024, sizeof(unsigned char) );
|
||||
if( NULL == buf )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "Buffer allocation failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
mbedtls_sha512_init( &ctx );
|
||||
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
j = i % 3;
|
||||
k = i < 3;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 );
|
||||
|
||||
mbedtls_sha512_starts( &ctx, k );
|
||||
|
||||
if( j == 2 )
|
||||
{
|
||||
memset( buf, 'a', buflen = 1000 );
|
||||
|
||||
for( j = 0; j < 1000; j++ )
|
||||
mbedtls_sha512_update( &ctx, buf, buflen );
|
||||
}
|
||||
else
|
||||
mbedtls_sha512_update( &ctx, sha512_test_buf[j],
|
||||
sha512_test_buflen[j] );
|
||||
|
||||
mbedtls_sha512_finish( &ctx, sha512sum );
|
||||
|
||||
if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_sha512_free( &ctx );
|
||||
mbedtls_free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
|
10
deps/mbedtls/ssl_ticket.c
vendored
10
deps/mbedtls/ssl_ticket.c
vendored
@ -27,13 +27,7 @@
|
||||
|
||||
#if defined(MBEDTLS_SSL_TICKET_C)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ssl_ticket.h"
|
||||
|
||||
@ -240,7 +234,7 @@ static int ssl_load_session( mbedtls_ssl_session *session,
|
||||
if( p + cert_len > end )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
session->peer_cert = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
session->peer_cert = calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
|
||||
if( session->peer_cert == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
@ -251,7 +245,7 @@ static int ssl_load_session( mbedtls_ssl_session *session,
|
||||
p, cert_len ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( session->peer_cert );
|
||||
mbedtls_free( session->peer_cert );
|
||||
free( session->peer_cert );
|
||||
session->peer_cert = NULL;
|
||||
return( ret );
|
||||
}
|
||||
|
124
deps/mbedtls/ssl_tls.c
vendored
124
deps/mbedtls/ssl_tls.c
vendored
@ -35,13 +35,7 @@
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
@ -163,7 +157,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
|
||||
{
|
||||
int ret;
|
||||
|
||||
dst->peer_cert = (mbedtls_x509_crt*)mbedtls_calloc( 1, sizeof(mbedtls_x509_crt) );
|
||||
dst->peer_cert = (mbedtls_x509_crt*)calloc( 1, sizeof(mbedtls_x509_crt) );
|
||||
if( dst->peer_cert == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
|
||||
@ -172,7 +166,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
|
||||
if( ( ret = mbedtls_x509_crt_parse_der( dst->peer_cert, src->peer_cert->raw.p,
|
||||
src->peer_cert->raw.len ) ) != 0 )
|
||||
{
|
||||
mbedtls_free( dst->peer_cert );
|
||||
free( dst->peer_cert );
|
||||
dst->peer_cert = NULL;
|
||||
return( ret );
|
||||
}
|
||||
@ -182,7 +176,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
||||
if( src->ticket != NULL )
|
||||
{
|
||||
dst->ticket = (unsigned char*)mbedtls_calloc( 1, src->ticket_len );
|
||||
dst->ticket = (unsigned char*)calloc( 1, src->ticket_len );
|
||||
if( dst->ticket == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
|
||||
@ -927,7 +921,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
||||
if( ssl->compress_buf == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "Allocating compression buffer" ) );
|
||||
ssl->compress_buf = mbedtls_calloc( 1, MBEDTLS_SSL_BUFFER_LEN );
|
||||
ssl->compress_buf = calloc( 1, MBEDTLS_SSL_BUFFER_LEN );
|
||||
if( ssl->compress_buf == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed",
|
||||
@ -2472,17 +2466,17 @@ static int ssl_flight_append( mbedtls_ssl_context *ssl )
|
||||
|
||||
/* Allocate space for current message */
|
||||
if( ( msg = (mbedtls_ssl_flight_item*)
|
||||
mbedtls_calloc( 1, sizeof( mbedtls_ssl_flight_item ) ) ) == NULL )
|
||||
calloc( 1, sizeof( mbedtls_ssl_flight_item ) ) ) == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %d bytes failed",
|
||||
sizeof( mbedtls_ssl_flight_item ) ) );
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
}
|
||||
|
||||
if( ( msg->p = (unsigned char*)mbedtls_calloc( 1, ssl->out_msglen ) ) == NULL )
|
||||
if( ( msg->p = (unsigned char*)calloc( 1, ssl->out_msglen ) ) == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %d bytes failed", ssl->out_msglen ) );
|
||||
mbedtls_free( msg );
|
||||
free( msg );
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
}
|
||||
|
||||
@ -2518,8 +2512,8 @@ static void ssl_flight_free( mbedtls_ssl_flight_item *flight )
|
||||
{
|
||||
next = cur->next;
|
||||
|
||||
mbedtls_free( cur->p );
|
||||
mbedtls_free( cur );
|
||||
free( cur->p );
|
||||
free( cur );
|
||||
|
||||
cur = next;
|
||||
}
|
||||
@ -2951,7 +2945,7 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl )
|
||||
/* The bitmask needs one bit per byte of message excluding header */
|
||||
alloc_len = 12 + msg_len + msg_len / 8 + ( msg_len % 8 != 0 );
|
||||
|
||||
ssl->handshake->hs_msg = (unsigned char*)mbedtls_calloc( 1, alloc_len );
|
||||
ssl->handshake->hs_msg = (unsigned char*)calloc( 1, alloc_len );
|
||||
if( ssl->handshake->hs_msg == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc failed (%d bytes)", alloc_len ) );
|
||||
@ -3058,7 +3052,7 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl )
|
||||
|
||||
memcpy( ssl->in_msg, ssl->handshake->hs_msg, ssl->in_hslen );
|
||||
|
||||
mbedtls_free( ssl->handshake->hs_msg );
|
||||
free( ssl->handshake->hs_msg );
|
||||
ssl->handshake->hs_msg = NULL;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "reassembled handshake message",
|
||||
@ -4451,10 +4445,10 @@ int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl )
|
||||
if( ssl->session_negotiate->peer_cert != NULL )
|
||||
{
|
||||
mbedtls_x509_crt_free( ssl->session_negotiate->peer_cert );
|
||||
mbedtls_free( ssl->session_negotiate->peer_cert );
|
||||
free( ssl->session_negotiate->peer_cert );
|
||||
}
|
||||
|
||||
if( ( ssl->session_negotiate->peer_cert = (mbedtls_x509_crt*)mbedtls_calloc( 1,
|
||||
if( ( ssl->session_negotiate->peer_cert = (mbedtls_x509_crt*)calloc( 1,
|
||||
sizeof( mbedtls_x509_crt ) ) ) == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed",
|
||||
@ -5145,7 +5139,7 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl )
|
||||
* Free our handshake params
|
||||
*/
|
||||
mbedtls_ssl_handshake_free( ssl->handshake );
|
||||
mbedtls_free( ssl->handshake );
|
||||
free( ssl->handshake );
|
||||
ssl->handshake = NULL;
|
||||
|
||||
/*
|
||||
@ -5154,7 +5148,7 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl )
|
||||
if( ssl->transform )
|
||||
{
|
||||
mbedtls_ssl_transform_free( ssl->transform );
|
||||
mbedtls_free( ssl->transform );
|
||||
free( ssl->transform );
|
||||
}
|
||||
ssl->transform = ssl->transform_negotiate;
|
||||
ssl->transform_negotiate = NULL;
|
||||
@ -5188,7 +5182,7 @@ void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl )
|
||||
#endif
|
||||
|
||||
mbedtls_ssl_session_free( ssl->session );
|
||||
mbedtls_free( ssl->session );
|
||||
free( ssl->session );
|
||||
}
|
||||
ssl->session = ssl->session_negotiate;
|
||||
ssl->session_negotiate = NULL;
|
||||
@ -5507,17 +5501,17 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl )
|
||||
*/
|
||||
if( ssl->transform_negotiate == NULL )
|
||||
{
|
||||
ssl->transform_negotiate = (mbedtls_ssl_transform*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_transform) );
|
||||
ssl->transform_negotiate = (mbedtls_ssl_transform*)calloc( 1, sizeof(mbedtls_ssl_transform) );
|
||||
}
|
||||
|
||||
if( ssl->session_negotiate == NULL )
|
||||
{
|
||||
ssl->session_negotiate = (mbedtls_ssl_session*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_session) );
|
||||
ssl->session_negotiate = (mbedtls_ssl_session*)calloc( 1, sizeof(mbedtls_ssl_session) );
|
||||
}
|
||||
|
||||
if( ssl->handshake == NULL )
|
||||
{
|
||||
ssl->handshake = (mbedtls_ssl_handshake_params*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_handshake_params) );
|
||||
ssl->handshake = (mbedtls_ssl_handshake_params*)calloc( 1, sizeof(mbedtls_ssl_handshake_params) );
|
||||
}
|
||||
|
||||
/* All pointers should exist and can be directly freed without issue */
|
||||
@ -5527,9 +5521,9 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc() of ssl sub-contexts failed" ) );
|
||||
|
||||
mbedtls_free( ssl->handshake );
|
||||
mbedtls_free( ssl->transform_negotiate );
|
||||
mbedtls_free( ssl->session_negotiate );
|
||||
free( ssl->handshake );
|
||||
free( ssl->transform_negotiate );
|
||||
free( ssl->session_negotiate );
|
||||
|
||||
ssl->handshake = NULL;
|
||||
ssl->transform_negotiate = NULL;
|
||||
@ -5611,11 +5605,11 @@ int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
|
||||
/*
|
||||
* Prepare base structures
|
||||
*/
|
||||
if( ( ssl-> in_buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL ||
|
||||
( ssl->out_buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL )
|
||||
if( ( ssl-> in_buf = (unsigned char*)calloc( 1, len ) ) == NULL ||
|
||||
( ssl->out_buf = (unsigned char*)calloc( 1, len ) ) == NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed", len ) );
|
||||
mbedtls_free( ssl->in_buf );
|
||||
free( ssl->in_buf );
|
||||
ssl->in_buf = NULL;
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
}
|
||||
@ -5734,14 +5728,14 @@ static int ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial )
|
||||
if( ssl->transform )
|
||||
{
|
||||
mbedtls_ssl_transform_free( ssl->transform );
|
||||
mbedtls_free( ssl->transform );
|
||||
free( ssl->transform );
|
||||
ssl->transform = NULL;
|
||||
}
|
||||
|
||||
if( ssl->session )
|
||||
{
|
||||
mbedtls_ssl_session_free( ssl->session );
|
||||
mbedtls_free( ssl->session );
|
||||
free( ssl->session );
|
||||
ssl->session = NULL;
|
||||
}
|
||||
|
||||
@ -5752,7 +5746,7 @@ static int ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial )
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
|
||||
if( partial == 0 )
|
||||
{
|
||||
mbedtls_free( ssl->cli_id );
|
||||
free( ssl->cli_id );
|
||||
ssl->cli_id = NULL;
|
||||
ssl->cli_id_len = 0;
|
||||
}
|
||||
@ -5938,7 +5932,7 @@ static int ssl_append_key_cert( mbedtls_ssl_key_cert **head,
|
||||
mbedtls_pk_context *key )
|
||||
{
|
||||
mbedtls_ssl_key_cert *keycert = (mbedtls_ssl_key_cert*)
|
||||
mbedtls_calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
|
||||
calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
|
||||
if( keycert == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
|
||||
@ -6048,17 +6042,17 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
|
||||
|
||||
if( conf->psk != NULL || conf->psk_identity != NULL )
|
||||
{
|
||||
mbedtls_free( conf->psk );
|
||||
mbedtls_free( conf->psk_identity );
|
||||
free( conf->psk );
|
||||
free( conf->psk_identity );
|
||||
conf->psk = NULL;
|
||||
conf->psk_identity = NULL;
|
||||
}
|
||||
|
||||
if( ( conf->psk = (unsigned char*)mbedtls_calloc( 1, psk_len ) ) == NULL ||
|
||||
( conf->psk_identity = (unsigned char*)mbedtls_calloc( 1, psk_identity_len ) ) == NULL )
|
||||
if( ( conf->psk = (unsigned char*)calloc( 1, psk_len ) ) == NULL ||
|
||||
( conf->psk_identity = (unsigned char*)calloc( 1, psk_identity_len ) ) == NULL )
|
||||
{
|
||||
mbedtls_free( conf->psk );
|
||||
mbedtls_free( conf->psk_identity );
|
||||
free( conf->psk );
|
||||
free( conf->psk_identity );
|
||||
conf->psk = NULL;
|
||||
conf->psk_identity = NULL;
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
@ -6083,10 +6077,10 @@ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
if( ssl->handshake->psk != NULL )
|
||||
mbedtls_free( ssl->handshake->psk );
|
||||
free( ssl->handshake->psk );
|
||||
|
||||
if( ( ssl->handshake->psk = (unsigned char*)
|
||||
mbedtls_calloc( 1, psk_len ) ) == NULL )
|
||||
calloc( 1, psk_len ) ) == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
|
||||
ssl->handshake->psk_len = psk_len;
|
||||
@ -6186,7 +6180,7 @@ int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname )
|
||||
if( hostname_len > MBEDTLS_SSL_MAX_HOST_NAME_LEN )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
ssl->hostname = (char*)mbedtls_calloc( 1, hostname_len + 1 );
|
||||
ssl->hostname = (char*)calloc( 1, hostname_len + 1 );
|
||||
|
||||
if( ssl->hostname == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
@ -7229,7 +7223,7 @@ static void ssl_key_cert_free( mbedtls_ssl_key_cert *key_cert )
|
||||
while( cur != NULL )
|
||||
{
|
||||
next = cur->next;
|
||||
mbedtls_free( cur );
|
||||
free( cur );
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
@ -7263,7 +7257,7 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake )
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
mbedtls_ecjpake_free( &handshake->ecjpake_ctx );
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
mbedtls_free( handshake->ecjpake_cache );
|
||||
free( handshake->ecjpake_cache );
|
||||
handshake->ecjpake_cache = NULL;
|
||||
handshake->ecjpake_cache_len = 0;
|
||||
#endif
|
||||
@ -7272,14 +7266,14 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake )
|
||||
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
/* explicit void pointer cast for buggy MS compiler */
|
||||
mbedtls_free( (void *) handshake->curves );
|
||||
free( (void *) handshake->curves );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
if( handshake->psk != NULL )
|
||||
{
|
||||
mbedtls_zeroize( handshake->psk, handshake->psk_len );
|
||||
mbedtls_free( handshake->psk );
|
||||
free( handshake->psk );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -7296,15 +7290,15 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake )
|
||||
while( cur != NULL )
|
||||
{
|
||||
next = cur->next;
|
||||
mbedtls_free( cur );
|
||||
free( cur );
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
mbedtls_free( handshake->verify_cookie );
|
||||
mbedtls_free( handshake->hs_msg );
|
||||
free( handshake->verify_cookie );
|
||||
free( handshake->hs_msg );
|
||||
ssl_flight_free( handshake->flight );
|
||||
#endif
|
||||
|
||||
@ -7320,12 +7314,12 @@ void mbedtls_ssl_session_free( mbedtls_ssl_session *session )
|
||||
if( session->peer_cert != NULL )
|
||||
{
|
||||
mbedtls_x509_crt_free( session->peer_cert );
|
||||
mbedtls_free( session->peer_cert );
|
||||
free( session->peer_cert );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
||||
mbedtls_free( session->ticket );
|
||||
free( session->ticket );
|
||||
#endif
|
||||
|
||||
mbedtls_zeroize( session, sizeof( mbedtls_ssl_session ) );
|
||||
@ -7344,27 +7338,27 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
|
||||
if( ssl->out_buf != NULL )
|
||||
{
|
||||
mbedtls_zeroize( ssl->out_buf, MBEDTLS_SSL_BUFFER_LEN );
|
||||
mbedtls_free( ssl->out_buf );
|
||||
free( ssl->out_buf );
|
||||
}
|
||||
|
||||
if( ssl->in_buf != NULL )
|
||||
{
|
||||
mbedtls_zeroize( ssl->in_buf, MBEDTLS_SSL_BUFFER_LEN );
|
||||
mbedtls_free( ssl->in_buf );
|
||||
free( ssl->in_buf );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
if( ssl->compress_buf != NULL )
|
||||
{
|
||||
mbedtls_zeroize( ssl->compress_buf, MBEDTLS_SSL_BUFFER_LEN );
|
||||
mbedtls_free( ssl->compress_buf );
|
||||
free( ssl->compress_buf );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( ssl->transform )
|
||||
{
|
||||
mbedtls_ssl_transform_free( ssl->transform );
|
||||
mbedtls_free( ssl->transform );
|
||||
free( ssl->transform );
|
||||
}
|
||||
|
||||
if( ssl->handshake )
|
||||
@ -7373,22 +7367,22 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
|
||||
mbedtls_ssl_transform_free( ssl->transform_negotiate );
|
||||
mbedtls_ssl_session_free( ssl->session_negotiate );
|
||||
|
||||
mbedtls_free( ssl->handshake );
|
||||
mbedtls_free( ssl->transform_negotiate );
|
||||
mbedtls_free( ssl->session_negotiate );
|
||||
free( ssl->handshake );
|
||||
free( ssl->transform_negotiate );
|
||||
free( ssl->session_negotiate );
|
||||
}
|
||||
|
||||
if( ssl->session )
|
||||
{
|
||||
mbedtls_ssl_session_free( ssl->session );
|
||||
mbedtls_free( ssl->session );
|
||||
free( ssl->session );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
if( ssl->hostname != NULL )
|
||||
{
|
||||
mbedtls_zeroize( ssl->hostname, strlen( ssl->hostname ) );
|
||||
mbedtls_free( ssl->hostname );
|
||||
free( ssl->hostname );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -7401,7 +7395,7 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
|
||||
mbedtls_free( ssl->cli_id );
|
||||
free( ssl->cli_id );
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= free" ) );
|
||||
@ -7625,8 +7619,8 @@ void mbedtls_ssl_config_free( mbedtls_ssl_config *conf )
|
||||
{
|
||||
mbedtls_zeroize( conf->psk, conf->psk_len );
|
||||
mbedtls_zeroize( conf->psk_identity, conf->psk_identity_len );
|
||||
mbedtls_free( conf->psk );
|
||||
mbedtls_free( conf->psk_identity );
|
||||
free( conf->psk );
|
||||
free( conf->psk_identity );
|
||||
conf->psk_len = 0;
|
||||
conf->psk_identity_len = 0;
|
||||
}
|
||||
|
172
deps/mbedtls/timing.c
vendored
172
deps/mbedtls/timing.c
vendored
@ -25,13 +25,6 @@
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
|
||||
#include "mbedtls/timing.h"
|
||||
@ -357,169 +350,4 @@ int mbedtls_timing_get_delay( void *data )
|
||||
|
||||
#endif /* !MBEDTLS_TIMING_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* Busy-waits for the given number of milliseconds.
|
||||
* Used for testing mbedtls_timing_hardclock.
|
||||
*/
|
||||
static void busy_msleep( unsigned long msec )
|
||||
{
|
||||
struct mbedtls_timing_hr_time hires;
|
||||
unsigned long i = 0; /* for busy-waiting */
|
||||
volatile unsigned long j; /* to prevent optimisation */
|
||||
|
||||
(void) mbedtls_timing_get_timer( &hires, 1 );
|
||||
|
||||
while( mbedtls_timing_get_timer( &hires, 0 ) < msec )
|
||||
i++;
|
||||
|
||||
j = i;
|
||||
(void) j;
|
||||
}
|
||||
|
||||
#define FAIL do \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
mbedtls_printf( "failed\n" ); \
|
||||
\
|
||||
return( 1 ); \
|
||||
} while( 0 )
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*
|
||||
* Warning: this is work in progress, some tests may not be reliable enough
|
||||
* yet! False positives may happen.
|
||||
*/
|
||||
int mbedtls_timing_self_test( int verbose )
|
||||
{
|
||||
unsigned long cycles, ratio;
|
||||
unsigned long millisecs, secs;
|
||||
int hardfail;
|
||||
struct mbedtls_timing_hr_time hires;
|
||||
uint32_t a, b;
|
||||
mbedtls_timing_delay_context ctx;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " TIMING tests note: will take some time!\n" );
|
||||
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " TIMING test #1 (set_alarm / get_timer): " );
|
||||
|
||||
for( secs = 1; secs <= 3; secs++ )
|
||||
{
|
||||
(void) mbedtls_timing_get_timer( &hires, 1 );
|
||||
|
||||
mbedtls_set_alarm( (int) secs );
|
||||
while( !mbedtls_timing_alarmed )
|
||||
;
|
||||
|
||||
millisecs = mbedtls_timing_get_timer( &hires, 0 );
|
||||
|
||||
/* For some reason on Windows it looks like alarm has an extra delay
|
||||
* (maybe related to creating a new thread). Allow some room here. */
|
||||
if( millisecs < 800 * secs || millisecs > 1200 * secs + 300 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " TIMING test #2 (set/get_delay ): " );
|
||||
|
||||
for( a = 200; a <= 400; a += 200 )
|
||||
{
|
||||
for( b = 200; b <= 400; b += 200 )
|
||||
{
|
||||
mbedtls_timing_set_delay( &ctx, a, a + b );
|
||||
|
||||
busy_msleep( a - a / 8 );
|
||||
if( mbedtls_timing_get_delay( &ctx ) != 0 )
|
||||
FAIL;
|
||||
|
||||
busy_msleep( a / 4 );
|
||||
if( mbedtls_timing_get_delay( &ctx ) != 1 )
|
||||
FAIL;
|
||||
|
||||
busy_msleep( b - a / 8 - b / 8 );
|
||||
if( mbedtls_timing_get_delay( &ctx ) != 1 )
|
||||
FAIL;
|
||||
|
||||
busy_msleep( b / 4 );
|
||||
if( mbedtls_timing_get_delay( &ctx ) != 2 )
|
||||
FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_timing_set_delay( &ctx, 0, 0 );
|
||||
busy_msleep( 200 );
|
||||
if( mbedtls_timing_get_delay( &ctx ) != -1 )
|
||||
FAIL;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " TIMING test #3 (hardclock / get_timer): " );
|
||||
|
||||
/*
|
||||
* Allow one failure for possible counter wrapping.
|
||||
* On a 4Ghz 32-bit machine the cycle counter wraps about once per second;
|
||||
* since the whole test is about 10ms, it shouldn't happen twice in a row.
|
||||
*/
|
||||
hardfail = 0;
|
||||
|
||||
hard_test:
|
||||
if( hardfail > 1 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed (ignored)\n" );
|
||||
|
||||
goto hard_test_done;
|
||||
}
|
||||
|
||||
/* Get a reference ratio cycles/ms */
|
||||
millisecs = 1;
|
||||
cycles = mbedtls_timing_hardclock();
|
||||
busy_msleep( millisecs );
|
||||
cycles = mbedtls_timing_hardclock() - cycles;
|
||||
ratio = cycles / millisecs;
|
||||
|
||||
/* Check that the ratio is mostly constant */
|
||||
for( millisecs = 2; millisecs <= 4; millisecs++ )
|
||||
{
|
||||
cycles = mbedtls_timing_hardclock();
|
||||
busy_msleep( millisecs );
|
||||
cycles = mbedtls_timing_hardclock() - cycles;
|
||||
|
||||
/* Allow variation up to 20% */
|
||||
if( cycles / millisecs < ratio - ratio / 5 ||
|
||||
cycles / millisecs > ratio + ratio / 5 )
|
||||
{
|
||||
hardfail++;
|
||||
goto hard_test;
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
|
||||
hard_test_done:
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_TIMING_C */
|
||||
|
110
deps/mbedtls/x509.c
vendored
110
deps/mbedtls/x509.c
vendored
@ -48,16 +48,8 @@
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
@ -457,7 +449,7 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
/* Mark this item as being no the only one in a set */
|
||||
cur->next_merged = 1;
|
||||
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
cur->next = calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
@ -471,7 +463,7 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
if( *p == end )
|
||||
return( 0 );
|
||||
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
cur->next = calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
@ -666,7 +658,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
|
||||
{
|
||||
mbedtls_pk_rsassa_pss_options *pss_opts;
|
||||
|
||||
pss_opts = mbedtls_calloc( 1, sizeof( mbedtls_pk_rsassa_pss_options ) );
|
||||
pss_opts = calloc( 1, sizeof( mbedtls_pk_rsassa_pss_options ) );
|
||||
if( pss_opts == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
|
||||
@ -676,7 +668,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
|
||||
&pss_opts->expected_salt_len );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_free( pss_opts );
|
||||
free( pss_opts );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
@ -764,16 +756,16 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
|
||||
|
||||
if( name != dn )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, merge ? " + " : ", " );
|
||||
ret = snprintf( p, n, merge ? " + " : ", " );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
}
|
||||
|
||||
ret = mbedtls_oid_get_attr_short_name( &name->oid, &short_name );
|
||||
|
||||
if( ret == 0 )
|
||||
ret = mbedtls_snprintf( p, n, "%s=", short_name );
|
||||
ret = snprintf( p, n, "%s=", short_name );
|
||||
else
|
||||
ret = mbedtls_snprintf( p, n, "\?\?=" );
|
||||
ret = snprintf( p, n, "\?\?=" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
for( i = 0; i < name->val.len; i++ )
|
||||
@ -787,7 +779,7 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
|
||||
else s[i] = c;
|
||||
}
|
||||
s[i] = '\0';
|
||||
ret = mbedtls_snprintf( p, n, "%s", s );
|
||||
ret = snprintf( p, n, "%s", s );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
merge = name->next_merged;
|
||||
@ -818,14 +810,14 @@ int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *se
|
||||
if( i == 0 && nr > 1 && serial->p[i] == 0x0 )
|
||||
continue;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%02X%s",
|
||||
ret = snprintf( p, n, "%02X%s",
|
||||
serial->p[i], ( i < nr - 1 ) ? ":" : "" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
}
|
||||
|
||||
if( nr != serial->len )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "...." );
|
||||
ret = snprintf( p, n, "...." );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
}
|
||||
|
||||
@ -846,9 +838,9 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
|
||||
|
||||
ret = mbedtls_oid_get_sig_alg_desc( sig_oid, &desc );
|
||||
if( ret != 0 )
|
||||
ret = mbedtls_snprintf( p, n, "???" );
|
||||
ret = snprintf( p, n, "???" );
|
||||
else
|
||||
ret = mbedtls_snprintf( p, n, "%s", desc );
|
||||
ret = snprintf( p, n, "%s", desc );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
@ -862,7 +854,7 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
mgf_md_info = mbedtls_md_info_from_type( pss_opts->mgf1_hash_id );
|
||||
|
||||
ret = mbedtls_snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
|
||||
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
|
||||
md_info ? mbedtls_md_get_name( md_info ) : "???",
|
||||
mgf_md_info ? mbedtls_md_get_name( mgf_md_info ) : "???",
|
||||
pss_opts->expected_salt_len );
|
||||
@ -882,11 +874,9 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
|
||||
*/
|
||||
int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name )
|
||||
{
|
||||
char *p = buf;
|
||||
char *p = buf;
|
||||
size_t n = buf_size;
|
||||
int ret;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%s key size", name );
|
||||
int ret = snprintf( p, n, "%s key size", name );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
return( 0 );
|
||||
@ -1025,74 +1015,4 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
|
||||
}
|
||||
#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 )
|
||||
{
|
||||
#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_SHA256_C)
|
||||
int ret;
|
||||
uint32_t flags;
|
||||
mbedtls_x509_crt cacert;
|
||||
mbedtls_x509_crt clicert;
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " X.509 certificate load: " );
|
||||
|
||||
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" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
mbedtls_x509_crt_init( &cacert );
|
||||
|
||||
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" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
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" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n\n");
|
||||
|
||||
mbedtls_x509_crt_free( &cacert );
|
||||
mbedtls_x509_crt_free( &clicert );
|
||||
|
||||
return( 0 );
|
||||
#else
|
||||
((void) verbose);
|
||||
return( 0 );
|
||||
#endif /* MBEDTLS_CERTS_C && MBEDTLS_SHA1_C */
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_X509_USE_C */
|
||||
|
43
deps/mbedtls/x509_crl.c
vendored
43
deps/mbedtls/x509_crl.c
vendored
@ -46,15 +46,8 @@
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
|
||||
#include <windows.h>
|
||||
@ -234,7 +227,7 @@ static int x509_get_entries( unsigned char **p,
|
||||
|
||||
if( *p < end )
|
||||
{
|
||||
cur_entry->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl_entry ) );
|
||||
cur_entry->next = calloc( 1, sizeof( mbedtls_x509_crl_entry ) );
|
||||
|
||||
if( cur_entry->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
@ -276,7 +269,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
|
||||
if( crl->version != 0 && crl->next == NULL )
|
||||
{
|
||||
crl->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl ) );
|
||||
crl->next = calloc( 1, sizeof( mbedtls_x509_crl ) );
|
||||
|
||||
if( crl->next == NULL )
|
||||
{
|
||||
@ -291,7 +284,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
/*
|
||||
* Copy raw DER-encoded CRL
|
||||
*/
|
||||
if( ( p = mbedtls_calloc( 1, buflen ) ) == NULL )
|
||||
if( ( p = calloc( 1, buflen ) ) == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
|
||||
memcpy( p, buf, buflen );
|
||||
@ -561,7 +554,7 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
|
||||
ret = mbedtls_x509_crl_parse( chain, buf, n );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -588,23 +581,23 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
|
||||
p = buf;
|
||||
n = size;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%sCRL version : %d",
|
||||
ret = snprintf( p, n, "%sCRL version : %d",
|
||||
prefix, crl->version );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
|
||||
ret = snprintf( p, n, "\n%sissuer name : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_x509_dn_gets( p, n, &crl->issuer );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sthis update : " \
|
||||
ret = snprintf( p, n, "\n%sthis update : " \
|
||||
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
|
||||
crl->this_update.year, crl->this_update.mon,
|
||||
crl->this_update.day, crl->this_update.hour,
|
||||
crl->this_update.min, crl->this_update.sec );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%snext update : " \
|
||||
ret = snprintf( p, n, "\n%snext update : " \
|
||||
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
|
||||
crl->next_update.year, crl->next_update.mon,
|
||||
crl->next_update.day, crl->next_update.hour,
|
||||
@ -613,20 +606,20 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
entry = &crl->entry;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sRevoked certificates:",
|
||||
ret = snprintf( p, n, "\n%sRevoked certificates:",
|
||||
prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
while( entry != NULL && entry->raw.len != 0 )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%sserial number: ",
|
||||
ret = snprintf( p, n, "\n%sserial number: ",
|
||||
prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_x509_serial_gets( p, n, &entry->serial );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, " revocation date: " \
|
||||
ret = snprintf( p, n, " revocation date: " \
|
||||
"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
entry->revocation_date.year, entry->revocation_date.mon,
|
||||
entry->revocation_date.day, entry->revocation_date.hour,
|
||||
@ -636,14 +629,14 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_x509_sig_alg_gets( p, n, &crl->sig_oid, crl->sig_pk, crl->sig_md,
|
||||
crl->sig_opts );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n" );
|
||||
ret = snprintf( p, n, "\n" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
@ -675,7 +668,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
|
||||
do
|
||||
{
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
mbedtls_free( crl_cur->sig_opts );
|
||||
free( crl_cur->sig_opts );
|
||||
#endif
|
||||
|
||||
name_cur = crl_cur->issuer.next;
|
||||
@ -684,7 +677,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
|
||||
mbedtls_free( name_prv );
|
||||
free( name_prv );
|
||||
}
|
||||
|
||||
entry_cur = crl_cur->entry.next;
|
||||
@ -693,13 +686,13 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
|
||||
entry_prv = entry_cur;
|
||||
entry_cur = entry_cur->next;
|
||||
mbedtls_zeroize( entry_prv, sizeof( mbedtls_x509_crl_entry ) );
|
||||
mbedtls_free( entry_prv );
|
||||
free( entry_prv );
|
||||
}
|
||||
|
||||
if( crl_cur->raw.p != NULL )
|
||||
{
|
||||
mbedtls_zeroize( crl_cur->raw.p, crl_cur->raw.len );
|
||||
mbedtls_free( crl_cur->raw.p );
|
||||
free( crl_cur->raw.p );
|
||||
}
|
||||
|
||||
crl_cur = crl_cur->next;
|
||||
@ -714,7 +707,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
|
||||
|
||||
mbedtls_zeroize( crl_prv, sizeof( mbedtls_x509_crl ) );
|
||||
if( crl_prv != crl )
|
||||
mbedtls_free( crl_prv );
|
||||
free( crl_prv );
|
||||
}
|
||||
while( crl_cur != NULL );
|
||||
}
|
||||
|
78
deps/mbedtls/x509_crt.c
vendored
78
deps/mbedtls/x509_crt.c
vendored
@ -42,19 +42,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <compat/strl.h>
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
#include "mbedtls/threading.h"
|
||||
@ -486,7 +480,7 @@ static int x509_get_subject_alt_name( unsigned char **p,
|
||||
if( cur->next != NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS );
|
||||
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
|
||||
cur->next = calloc( 1, sizeof( mbedtls_asn1_sequence ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
@ -704,7 +698,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
|
||||
|
||||
/* Create and populate a new buffer for the raw field */
|
||||
crt->raw.len = crt_end - buf;
|
||||
crt->raw.p = p = mbedtls_calloc( 1, crt->raw.len );
|
||||
crt->raw.p = p = calloc( 1, crt->raw.len );
|
||||
if( p == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
|
||||
@ -936,9 +930,9 @@ int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *bu
|
||||
/*
|
||||
* Add new certificate on the end of the chain if needed.
|
||||
*/
|
||||
if( crt->version != 0 && crt->next == NULL )
|
||||
if( crt->version != 0 && !crt->next)
|
||||
{
|
||||
crt->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
crt->next = calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
|
||||
if( crt->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
@ -954,7 +948,7 @@ int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *bu
|
||||
prev->next = NULL;
|
||||
|
||||
if( crt != chain )
|
||||
mbedtls_free( crt );
|
||||
free( crt );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -1093,7 +1087,7 @@ int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path )
|
||||
ret = mbedtls_x509_crt_parse( chain, buf, n );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -1182,7 +1176,7 @@ cleanup:
|
||||
|
||||
while( ( entry = readdir( dir ) ) != NULL )
|
||||
{
|
||||
snp_ret = mbedtls_snprintf( entry_name, sizeof entry_name,
|
||||
snp_ret = snprintf( entry_name, sizeof entry_name,
|
||||
"%s/%s", path, entry->d_name );
|
||||
|
||||
if( snp_ret < 0 || (size_t)snp_ret >= sizeof entry_name )
|
||||
@ -1261,7 +1255,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size,
|
||||
|
||||
#define PRINT_ITEM(i) \
|
||||
{ \
|
||||
ret = mbedtls_snprintf( p, n, "%s" i, sep ); \
|
||||
ret = snprintf( p, n, "%s" i, sep ); \
|
||||
MBEDTLS_X509_SAFE_SNPRINTF; \
|
||||
sep = ", "; \
|
||||
}
|
||||
@ -1336,7 +1330,7 @@ static int x509_info_ext_key_usage( char **buf, size_t *size,
|
||||
if( mbedtls_oid_get_extended_key_usage( &cur->buf, &desc ) != 0 )
|
||||
desc = "???";
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%s%s", sep, desc );
|
||||
ret = snprintf( p, n, "%s%s", sep, desc );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
sep = ", ";
|
||||
@ -1370,47 +1364,47 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
if( NULL == crt )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\nCertificate is uninitialised!\n" );
|
||||
ret = snprintf( p, n, "\nCertificate is uninitialised!\n" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%scert. version : %d\n",
|
||||
ret = snprintf( p, n, "%scert. version : %d\n",
|
||||
prefix, crt->version );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_snprintf( p, n, "%sserial number : ",
|
||||
ret = snprintf( p, n, "%sserial number : ",
|
||||
prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_x509_serial_gets( p, n, &crt->serial );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
|
||||
ret = snprintf( p, n, "\n%sissuer name : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_x509_dn_gets( p, n, &crt->issuer );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssubject name : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssubject name : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_x509_dn_gets( p, n, &crt->subject );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sissued on : " \
|
||||
ret = snprintf( p, n, "\n%sissued on : " \
|
||||
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
|
||||
crt->valid_from.year, crt->valid_from.mon,
|
||||
crt->valid_from.day, crt->valid_from.hour,
|
||||
crt->valid_from.min, crt->valid_from.sec );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%sexpires on : " \
|
||||
ret = snprintf( p, n, "\n%sexpires on : " \
|
||||
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
|
||||
crt->valid_to.year, crt->valid_to.mon,
|
||||
crt->valid_to.day, crt->valid_to.hour,
|
||||
crt->valid_to.min, crt->valid_to.sec );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_x509_sig_alg_gets( p, n, &crt->sig_oid, crt->sig_pk,
|
||||
@ -1420,11 +1414,9 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
/* Key size */
|
||||
if( ( ret = mbedtls_x509_key_size_helper( key_size_str, BEFORE_COLON,
|
||||
mbedtls_pk_get_name( &crt->pk ) ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
|
||||
ret = snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
|
||||
(int) mbedtls_pk_get_bitlen( &crt->pk ) );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
@ -1434,20 +1426,20 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
if( crt->ext_types & MBEDTLS_X509_EXT_BASIC_CONSTRAINTS )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
|
||||
ret = snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
|
||||
crt->ca_istrue ? "true" : "false" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
if( crt->max_pathlen > 0 )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
|
||||
ret = snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
}
|
||||
}
|
||||
|
||||
if( crt->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssubject alt name : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssubject alt name : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
if( ( ret = x509_info_subject_alt_name( &p, &n,
|
||||
@ -1457,7 +1449,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
if( crt->ext_types & MBEDTLS_X509_EXT_NS_CERT_TYPE )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%scert. type : ", prefix );
|
||||
ret = snprintf( p, n, "\n%scert. type : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
if( ( ret = x509_info_cert_type( &p, &n, crt->ns_cert_type ) ) != 0 )
|
||||
@ -1466,7 +1458,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
if( crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%skey usage : ", prefix );
|
||||
ret = snprintf( p, n, "\n%skey usage : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
if( ( ret = x509_info_key_usage( &p, &n, crt->key_usage ) ) != 0 )
|
||||
@ -1475,7 +1467,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
if( crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "\n%sext key usage : ", prefix );
|
||||
ret = snprintf( p, n, "\n%sext key usage : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
if( ( ret = x509_info_ext_key_usage( &p, &n,
|
||||
@ -1483,7 +1475,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
return( ret );
|
||||
}
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n" );
|
||||
ret = snprintf( p, n, "\n" );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
@ -1531,14 +1523,14 @@ int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
|
||||
if( ( flags & cur->code ) == 0 )
|
||||
continue;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%s%s\n", prefix, cur->string );
|
||||
ret = snprintf( p, n, "%s%s\n", prefix, cur->string );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
flags ^= cur->code;
|
||||
}
|
||||
|
||||
if( flags != 0 )
|
||||
{
|
||||
ret = mbedtls_snprintf( p, n, "%sUnknown reason "
|
||||
ret = snprintf( p, n, "%sUnknown reason "
|
||||
"(this should not happen)\n", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
}
|
||||
@ -2342,7 +2334,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
mbedtls_pk_free( &cert_cur->pk );
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
mbedtls_free( cert_cur->sig_opts );
|
||||
free( cert_cur->sig_opts );
|
||||
#endif
|
||||
|
||||
name_cur = cert_cur->issuer.next;
|
||||
@ -2351,7 +2343,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
|
||||
mbedtls_free( name_prv );
|
||||
free( name_prv );
|
||||
}
|
||||
|
||||
name_cur = cert_cur->subject.next;
|
||||
@ -2360,7 +2352,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
|
||||
mbedtls_free( name_prv );
|
||||
free( name_prv );
|
||||
}
|
||||
|
||||
seq_cur = cert_cur->ext_key_usage.next;
|
||||
@ -2369,7 +2361,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
seq_prv = seq_cur;
|
||||
seq_cur = seq_cur->next;
|
||||
mbedtls_zeroize( seq_prv, sizeof( mbedtls_x509_sequence ) );
|
||||
mbedtls_free( seq_prv );
|
||||
free( seq_prv );
|
||||
}
|
||||
|
||||
seq_cur = cert_cur->subject_alt_names.next;
|
||||
@ -2378,13 +2370,13 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
seq_prv = seq_cur;
|
||||
seq_cur = seq_cur->next;
|
||||
mbedtls_zeroize( seq_prv, sizeof( mbedtls_x509_sequence ) );
|
||||
mbedtls_free( seq_prv );
|
||||
free( seq_prv );
|
||||
}
|
||||
|
||||
if( cert_cur->raw.p != NULL )
|
||||
{
|
||||
mbedtls_zeroize( cert_cur->raw.p, cert_cur->raw.len );
|
||||
mbedtls_free( cert_cur->raw.p );
|
||||
free( cert_cur->raw.p );
|
||||
}
|
||||
|
||||
cert_cur = cert_cur->next;
|
||||
@ -2399,7 +2391,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
|
||||
|
||||
mbedtls_zeroize( cert_prv, sizeof( mbedtls_x509_crt ) );
|
||||
if( cert_prv != crt )
|
||||
mbedtls_free( cert_prv );
|
||||
free( cert_prv );
|
||||
}
|
||||
while( cert_cur != NULL );
|
||||
}
|
||||
|
34
deps/mbedtls/x509_csr.c
vendored
34
deps/mbedtls/x509_csr.c
vendored
@ -46,15 +46,8 @@
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
|
||||
#include <stdio.h>
|
||||
@ -109,7 +102,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
/*
|
||||
* first copy the raw DER data
|
||||
*/
|
||||
p = mbedtls_calloc( 1, len = buflen );
|
||||
p = calloc( 1, len = buflen );
|
||||
|
||||
if( p == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
@ -323,7 +316,7 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path )
|
||||
ret = mbedtls_x509_csr_parse( csr, buf, n );
|
||||
|
||||
mbedtls_zeroize( buf, n );
|
||||
mbedtls_free( buf );
|
||||
free( buf );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -338,24 +331,19 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path )
|
||||
int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
|
||||
const mbedtls_x509_csr *csr )
|
||||
{
|
||||
int ret;
|
||||
size_t n;
|
||||
char *p;
|
||||
char key_size_str[BEFORE_COLON];
|
||||
|
||||
p = buf;
|
||||
n = size;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "%sCSR version : %d",
|
||||
char *p = buf;
|
||||
size_t n = size;
|
||||
int ret = snprintf( p, n, "%sCSR version : %d",
|
||||
prefix, csr->version );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssubject name : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssubject name : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
ret = mbedtls_x509_dn_gets( p, n, &csr->subject );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
ret = mbedtls_x509_sig_alg_gets( p, n, &csr->sig_oid, csr->sig_pk, csr->sig_md,
|
||||
@ -368,7 +356,7 @@ int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
|
||||
return( ret );
|
||||
}
|
||||
|
||||
ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
|
||||
ret = snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
|
||||
(int) mbedtls_pk_get_bitlen( &csr->pk ) );
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
@ -397,7 +385,7 @@ void mbedtls_x509_csr_free( mbedtls_x509_csr *csr )
|
||||
mbedtls_pk_free( &csr->pk );
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
mbedtls_free( csr->sig_opts );
|
||||
free( csr->sig_opts );
|
||||
#endif
|
||||
|
||||
name_cur = csr->subject.next;
|
||||
@ -406,13 +394,13 @@ void mbedtls_x509_csr_free( mbedtls_x509_csr *csr )
|
||||
name_prv = name_cur;
|
||||
name_cur = name_cur->next;
|
||||
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
|
||||
mbedtls_free( name_prv );
|
||||
free( name_prv );
|
||||
}
|
||||
|
||||
if( csr->raw.p != NULL )
|
||||
{
|
||||
mbedtls_zeroize( csr->raw.p, csr->raw.len );
|
||||
mbedtls_free( csr->raw.p );
|
||||
free( csr->raw.p );
|
||||
}
|
||||
|
||||
mbedtls_zeroize( csr, sizeof( mbedtls_x509_csr ) );
|
||||
|
95
deps/mbedtls/xtea.c
vendored
95
deps/mbedtls/xtea.c
vendored
@ -31,15 +31,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if !defined(MBEDTLS_XTEA_ALT)
|
||||
|
||||
#include "arc4_alt.h"
|
||||
@ -189,90 +180,4 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx, int mode, size_t length,
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
#endif /* !MBEDTLS_XTEA_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* XTEA tests vectors (non-official)
|
||||
*/
|
||||
|
||||
static const unsigned char xtea_test_key[6][16] =
|
||||
{
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
||||
0x0c, 0x0d, 0x0e, 0x0f },
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
||||
0x0c, 0x0d, 0x0e, 0x0f },
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
||||
0x0c, 0x0d, 0x0e, 0x0f },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 }
|
||||
};
|
||||
|
||||
static const unsigned char xtea_test_pt[6][8] =
|
||||
{
|
||||
{ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
|
||||
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
|
||||
{ 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
|
||||
{ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
|
||||
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
|
||||
{ 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
|
||||
};
|
||||
|
||||
static const unsigned char xtea_test_ct[6][8] =
|
||||
{
|
||||
{ 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
|
||||
{ 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
|
||||
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
|
||||
{ 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
|
||||
{ 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
|
||||
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_xtea_self_test( int verbose )
|
||||
{
|
||||
int i, ret = 0;
|
||||
unsigned char buf[8];
|
||||
mbedtls_xtea_context ctx;
|
||||
|
||||
mbedtls_xtea_init( &ctx );
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " XTEA test #%d: ", i + 1 );
|
||||
|
||||
memcpy( buf, xtea_test_pt[i], 8 );
|
||||
|
||||
mbedtls_xtea_setup( &ctx, xtea_test_key[i] );
|
||||
mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, buf, buf );
|
||||
|
||||
if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
exit:
|
||||
mbedtls_xtea_free( &ctx );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* MBEDTLS_XTEA_C */
|
||||
|
Loading…
x
Reference in New Issue
Block a user