52#if !defined(MBEDTLS_CONFIG_FILE)
55#include MBEDTLS_CONFIG_FILE
58#if defined(MBEDTLS_CTR_DRBG_C)
65#if defined(MBEDTLS_FS_IO)
69#if defined(MBEDTLS_SELF_TEST)
70#if defined(MBEDTLS_PLATFORM_C)
74#define mbedtls_printf printf
97#if defined(MBEDTLS_THREADING_C)
100 mbedtls_mutex_free( &
ctx->mutex );
109 ctx->prediction_resistance = resistance;
122static int block_cipher_df(
unsigned char *output,
123 const unsigned char *
data,
size_t data_len )
129 unsigned char *
p, *iv;
134 size_t buf_len, use_len;
150 *
p++ = ( data_len >> 24 ) & 0xff;
151 *
p++ = ( data_len >> 16 ) & 0xff;
152 *
p++ = ( data_len >> 8 ) & 0xff;
153 *
p++ = ( data_len ) & 0xff;
251 unsigned char *
p = tmp;
263 if( ++
ctx->counter[
i - 1] != 0 )
303 const unsigned char *additional,
312 if( (
ret = block_cipher_df( add_input, additional, add_len ) ) != 0 )
314 if( (
ret = ctr_drbg_update_internal(
ctx, add_input ) ) != 0 )
322#if !defined(MBEDTLS_DEPRECATED_REMOVED)
324 const unsigned char *additional,
348 const unsigned char *additional,
size_t len )
363 if( 0 !=
ctx->f_entropy(
ctx->p_entropy, seed,
369 seedlen +=
ctx->entropy_len;
374 if( additional &&
len )
376 memcpy( seed + seedlen, additional,
len );
383 if( (
ret = block_cipher_df( seed, seed, seedlen ) ) != 0 )
389 if( (
ret = ctr_drbg_update_internal(
ctx, seed ) ) != 0 )
391 ctx->reseed_counter = 1;
410 int (*f_entropy)(
void *,
unsigned char *,
size_t),
412 const unsigned char *custom,
421#if defined(MBEDTLS_THREADING_C)
422 mbedtls_mutex_init( &
ctx->mutex );
427 ctx->f_entropy = f_entropy;
428 ctx->p_entropy = p_entropy;
430 if(
ctx->entropy_len == 0 )
451 int (*f_entropy)(
void *,
unsigned char *,
size_t),
void *p_entropy,
452 const unsigned char *custom,
size_t len,
479 unsigned char *output,
size_t output_len,
480 const unsigned char *additional,
size_t add_len )
485 unsigned char *
p = output;
498 if(
ctx->reseed_counter >
ctx->reseed_interval ||
499 ctx->prediction_resistance )
510 if( (
ret = block_cipher_df( add_input, additional, add_len ) ) != 0 )
512 if( (
ret = ctr_drbg_update_internal(
ctx, add_input ) ) != 0 )
516 while( output_len > 0 )
522 if( ++
ctx->counter[
i - 1] != 0 )
538 output_len -= use_len;
541 if( (
ret = ctr_drbg_update_internal(
ctx, add_input ) ) != 0 )
544 ctx->reseed_counter++;
557#if defined(MBEDTLS_THREADING_C)
558 if( (
ret = mbedtls_mutex_lock( &
ctx->mutex ) ) != 0 )
564#if defined(MBEDTLS_THREADING_C)
565 if( mbedtls_mutex_unlock( &
ctx->mutex ) != 0 )
572#if defined(MBEDTLS_FS_IO)
609 if(
fread( &
c, 1, 1,
f ) != 0 )
630 return( mbedtls_ctr_drbg_write_seed_file(
ctx,
path ) );
634#if defined(MBEDTLS_SELF_TEST)
636static const unsigned char entropy_source_pr[96] =
637 { 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
638 0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
639 0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
640 0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb,
641 0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9,
642 0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95,
643 0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63,
644 0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3,
645 0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31,
646 0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4,
647 0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
648 0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 };
650static const unsigned char entropy_source_nopr[64] =
651 { 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
652 0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
653 0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
654 0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20,
655 0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9,
656 0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46,
657 0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e,
658 0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e };
660static const unsigned char nonce_pers_pr[16] =
661 { 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2,
662 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c };
664static const unsigned char nonce_pers_nopr[16] =
665 { 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5,
666 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f };
668static const unsigned char result_pr[16] =
669 { 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f,
670 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 };
672static const unsigned char result_nopr[16] =
673 { 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88,
674 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
676static size_t test_offset;
677static int ctr_drbg_self_test_entropy(
void *
data,
unsigned char *
buf,
680 const unsigned char *
p =
data;
686#define CHK( c ) if( (c) != 0 ) \
689 mbedtls_printf( "failed\n" ); \
696int mbedtls_ctr_drbg_self_test(
int verbose )
699 unsigned char buf[16];
712 ctr_drbg_self_test_entropy,
713 (
void *) entropy_source_pr,
714 nonce_pers_pr, 16 ) );
736 ctr_drbg_self_test_entropy,
737 (
void *) entropy_source_nopr,
738 nonce_pers_nopr, 16 ) );
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
This function performs an AES single-block encryption or decryption operation.
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
#define MBEDTLS_AES_ENCRYPT
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
void mbedtls_aes_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
This file contains definitions and functions for the CTR_DRBG pseudorandom generator.
#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
int mbedtls_ctr_drbg_random_with_add(void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
This function updates a CTR_DRBG instance with additional data and uses it to generate random data.
#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
int mbedtls_ctr_drbg_reseed(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
This function reseeds the CTR_DRBG context, that is extracts data from the entropy source.
MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
#define MBEDTLS_CTR_DRBG_MAX_REQUEST
#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG
#define MBEDTLS_CTR_DRBG_BLOCKSIZE
#define MBEDTLS_CTR_DRBG_KEYBITS
int mbedtls_ctr_drbg_seed_entropy_len(mbedtls_ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
#define MBEDTLS_CTR_DRBG_SEEDLEN
#define MBEDTLS_CTR_DRBG_MAX_INPUT
int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN
The amount of entropy used per seed by default, in bytes.
#define MBEDTLS_CTR_DRBG_PR_ON
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
This function turns prediction resistance on or off. The default value is off.
#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
This function sets the reseed interval.
void mbedtls_ctr_drbg_set_entropy_len(mbedtls_ctr_drbg_context *ctx, size_t len)
This function sets the amount of entropy grabbed on each seed or reseed.
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL
#define MBEDTLS_CTR_DRBG_KEYSIZE
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define memcpy(s1, s2, n)
#define mbedtls_ctr_drbg_seed
#define mbedtls_ctr_drbg_random
#define mbedtls_ctr_drbg_init
#define mbedtls_ctr_drbg_free
Configuration options (set of defines)
The AES context-type definition.
The CTR_DRBG context structure.
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR