#include "polarssl/config.h"
#include "polarssl/ctr_drbg.h"
#include <stdio.h>
Go to the source code of this file.
Functions | |
int | ctr_drbg_init_entropy_len (ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len, size_t entropy_len) |
int | ctr_drbg_init (ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len) |
CTR_DRBG initialization. | |
void | ctr_drbg_set_prediction_resistance (ctr_drbg_context *ctx, int resistance) |
Enable / disable prediction resistance (Default: Off). | |
void | ctr_drbg_set_entropy_len (ctr_drbg_context *ctx, size_t len) |
Set the amount of entropy grabbed on each (re)seed (Default: CTR_DRBG_ENTROPY_LEN). | |
void | ctr_drbg_set_reseed_interval (ctr_drbg_context *ctx, int interval) |
Set the reseed interval (Default: CTR_DRBG_RESEED_INTERVAL). | |
static int | block_cipher_df (unsigned char *output, const unsigned char *data, size_t data_len) |
static int | ctr_drbg_update_internal (ctr_drbg_context *ctx, const unsigned char data[CTR_DRBG_SEEDLEN]) |
void | ctr_drbg_update (ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len) |
CTR_DRBG update state. | |
int | ctr_drbg_reseed (ctr_drbg_context *ctx, const unsigned char *additional, size_t len) |
CTR_DRBG reseeding (extracts data from entropy source). | |
int | ctr_drbg_random_with_add (void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len) |
CTR_DRBG generate random with additional update input. | |
int | ctr_drbg_random (void *p_rng, unsigned char *output, size_t output_len) |
CTR_DRBG generate random. | |
int | ctr_drbg_write_seed_file (ctr_drbg_context *ctx, const char *path) |
Write a seed file. | |
int | ctr_drbg_update_seed_file (ctr_drbg_context *ctx, const char *path) |
Read and update a seed file. | |
static int | ctr_drbg_self_test_entropy (void *data, unsigned char *buf, size_t len) |
int | ctr_drbg_self_test (int verbose) |
Checkup routine. | |
Variables | |
unsigned char | entropy_source_pr [96] |
unsigned char | entropy_source_nopr [64] |
unsigned char | nonce_pers_pr [16] |
unsigned char | nonce_pers_nopr [16] |
unsigned char | result_pr [16] |
unsigned char | result_nopr [16] |
int | test_offset |
static int block_cipher_df | ( | unsigned char * | output, | |
const unsigned char * | data, | |||
size_t | data_len | |||
) | [static] |
Definition at line 101 of file ctr_drbg.c.
References aes_crypt_ecb(), AES_ENCRYPT, aes_setkey_enc(), CTR_DRBG_BLOCKSIZE, CTR_DRBG_KEYBITS, CTR_DRBG_KEYSIZE, CTR_DRBG_MAX_SEED_INPUT, CTR_DRBG_SEEDLEN, iv, and key.
Referenced by ctr_drbg_random_with_add(), ctr_drbg_reseed(), and ctr_drbg_update().
int ctr_drbg_init | ( | ctr_drbg_context * | ctx, | |
int(*)(void *, unsigned char *, size_t) | f_entropy, | |||
void * | p_entropy, | |||
const unsigned char * | custom, | |||
size_t | len | |||
) |
CTR_DRBG initialization.
Note: Personalization data can be provided in addition to the more generic entropy source to make this instantiation as unique as possible.
ctx | CTR_DRBG context to be initialized | |
f_entropy | Entropy callback (p_entropy, buffer to fill, buffer length) | |
p_entropy | Entropy context | |
custom | Personalization data (Device specific identifiers) (Can be NULL) | |
len | Length of personalization data |
Definition at line 76 of file ctr_drbg.c.
References CTR_DRBG_ENTROPY_LEN, and ctr_drbg_init_entropy_len().
int ctr_drbg_init_entropy_len | ( | ctr_drbg_context * | ctx, | |
int(*)(void *, unsigned char *, size_t) | f_entropy, | |||
void * | p_entropy, | |||
const unsigned char * | custom, | |||
size_t | len, | |||
size_t | entropy_len | |||
) |
Definition at line 45 of file ctr_drbg.c.
References ctr_drbg_context::aes_ctx, aes_setkey_enc(), CTR_DRBG_KEYBITS, CTR_DRBG_KEYSIZE, ctr_drbg_reseed(), CTR_DRBG_RESEED_INTERVAL, ctr_drbg_context::entropy_len, ctr_drbg_context::f_entropy, key, ctr_drbg_context::p_entropy, and ctr_drbg_context::reseed_interval.
Referenced by ctr_drbg_init(), ctr_drbg_self_test(), test_suite_ctr_drbg_validate_nopr(), and test_suite_ctr_drbg_validate_pr().
int ctr_drbg_random | ( | void * | p_rng, | |
unsigned char * | output, | |||
size_t | output_len | |||
) |
CTR_DRBG generate random.
Note: Automatically reseeds if reseed_counter is reached.
p_rng | CTR_DRBG context | |
output | Buffer to fill | |
output_len | Length of the buffer |
Definition at line 345 of file ctr_drbg.c.
References ctr_drbg_random_with_add().
Referenced by ctr_drbg_self_test(), and ctr_drbg_write_seed_file().
int ctr_drbg_random_with_add | ( | void * | p_rng, | |
unsigned char * | output, | |||
size_t | output_len, | |||
const unsigned char * | additional, | |||
size_t | add_len | |||
) |
CTR_DRBG generate random with additional update input.
Note: Automatically reseeds if reseed_counter is reached.
p_rng | CTR_DRBG context | |
output | Buffer to fill | |
output_len | Length of the buffer | |
additional | Additional data to update with (Can be NULL) | |
add_len | Length of additional data |
Definition at line 280 of file ctr_drbg.c.
References aes_crypt_ecb(), ctr_drbg_context::aes_ctx, AES_ENCRYPT, block_cipher_df(), ctr_drbg_context::counter, CTR_DRBG_BLOCKSIZE, CTR_DRBG_MAX_INPUT, CTR_DRBG_MAX_REQUEST, ctr_drbg_reseed(), CTR_DRBG_SEEDLEN, ctr_drbg_update_internal(), POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG, POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG, ctr_drbg_context::prediction_resistance, ctr_drbg_context::reseed_counter, and ctr_drbg_context::reseed_interval.
Referenced by ctr_drbg_random(), test_suite_ctr_drbg_validate_nopr(), and test_suite_ctr_drbg_validate_pr().
int ctr_drbg_reseed | ( | ctr_drbg_context * | ctx, | |
const unsigned char * | additional, | |||
size_t | len | |||
) |
CTR_DRBG reseeding (extracts data from entropy source).
ctx | CTR_DRBG context | |
additional | Additional data to add to state (Can be NULL) | |
len | Length of additional data |
Definition at line 235 of file ctr_drbg.c.
References block_cipher_df(), CTR_DRBG_MAX_SEED_INPUT, ctr_drbg_update_internal(), ctr_drbg_context::entropy_len, ctr_drbg_context::f_entropy, ctr_drbg_context::p_entropy, POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED, POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG, and ctr_drbg_context::reseed_counter.
Referenced by ctr_drbg_init_entropy_len(), ctr_drbg_random_with_add(), ctr_drbg_self_test(), and test_suite_ctr_drbg_validate_nopr().
int ctr_drbg_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 466 of file ctr_drbg.c.
References CTR_DRBG_BLOCKSIZE, ctr_drbg_init_entropy_len(), CTR_DRBG_PR_ON, ctr_drbg_random(), ctr_drbg_reseed(), ctr_drbg_self_test_entropy(), and ctr_drbg_set_prediction_resistance().
static int ctr_drbg_self_test_entropy | ( | void * | data, | |
unsigned char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 454 of file ctr_drbg.c.
Referenced by ctr_drbg_self_test().
void ctr_drbg_set_entropy_len | ( | ctr_drbg_context * | ctx, | |
size_t | len | |||
) |
Set the amount of entropy grabbed on each (re)seed (Default: CTR_DRBG_ENTROPY_LEN).
ctx | CTR_DRBG context | |
len | Amount of entropy to grab |
Definition at line 91 of file ctr_drbg.c.
References ctr_drbg_context::entropy_len.
void ctr_drbg_set_prediction_resistance | ( | ctr_drbg_context * | ctx, | |
int | resistance | |||
) |
Enable / disable prediction resistance (Default: Off).
Note: If enabled, entropy is used for ctx->entropy_len before each call! Only use this if you have ample supply of good entropy!
ctx | CTR_DRBG context | |
resistance | CTR_DRBG_PR_ON or CTR_DRBG_PR_OFF |
Definition at line 86 of file ctr_drbg.c.
References ctr_drbg_context::prediction_resistance.
Referenced by ctr_drbg_self_test(), and test_suite_ctr_drbg_validate_pr().
void ctr_drbg_set_reseed_interval | ( | ctr_drbg_context * | ctx, | |
int | interval | |||
) |
Set the reseed interval (Default: CTR_DRBG_RESEED_INTERVAL).
ctx | CTR_DRBG context | |
interval | Reseed interval |
Definition at line 96 of file ctr_drbg.c.
References ctr_drbg_context::reseed_interval.
void ctr_drbg_update | ( | ctr_drbg_context * | ctx, | |
const unsigned char * | additional, | |||
size_t | add_len | |||
) |
CTR_DRBG update state.
ctx | CTR_DRBG context | |
additional | Additional data to update state with | |
add_len | Length of additional data |
Definition at line 223 of file ctr_drbg.c.
References block_cipher_df(), CTR_DRBG_SEEDLEN, and ctr_drbg_update_internal().
Referenced by ctr_drbg_update_seed_file().
static int ctr_drbg_update_internal | ( | ctr_drbg_context * | ctx, | |
const unsigned char | data[CTR_DRBG_SEEDLEN] | |||
) | [static] |
Definition at line 185 of file ctr_drbg.c.
References aes_crypt_ecb(), ctr_drbg_context::aes_ctx, AES_ENCRYPT, aes_setkey_enc(), ctr_drbg_context::counter, CTR_DRBG_BLOCKSIZE, CTR_DRBG_KEYBITS, and CTR_DRBG_KEYSIZE.
Referenced by ctr_drbg_random_with_add(), ctr_drbg_reseed(), and ctr_drbg_update().
int ctr_drbg_update_seed_file | ( | ctr_drbg_context * | ctx, | |
const char * | path | |||
) |
Read and update a seed file.
Seed is added to this instance
ctx | CTR_DRBG context | |
path | Name of the file |
Definition at line 376 of file ctr_drbg.c.
References CTR_DRBG_MAX_INPUT, ctr_drbg_update(), ctr_drbg_write_seed_file(), POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR, and POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG.
int ctr_drbg_write_seed_file | ( | ctr_drbg_context * | ctx, | |
const char * | path | |||
) |
Write a seed file.
ctx | CTR_DRBG context | |
path | Name of the file |
Definition at line 351 of file ctr_drbg.c.
References CTR_DRBG_MAX_INPUT, ctr_drbg_random(), and POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR.
Referenced by ctr_drbg_update_seed_file().
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 }
Definition at line 427 of file ctr_drbg.c.
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 }
Definition at line 413 of file ctr_drbg.c.
unsigned char nonce_pers_nopr[16] |
{ 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5, 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f }
Definition at line 441 of file ctr_drbg.c.
unsigned char nonce_pers_pr[16] |
{ 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2, 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c }
Definition at line 437 of file ctr_drbg.c.
unsigned char result_nopr[16] |
{ 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88, 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f }
Definition at line 449 of file ctr_drbg.c.
unsigned char result_pr[16] |
{ 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f, 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 }
Definition at line 445 of file ctr_drbg.c.
int test_offset |
Definition at line 453 of file ctr_drbg.c.
Referenced by entropy_func(), test_suite_ctr_drbg_validate_nopr(), and test_suite_ctr_drbg_validate_pr().