Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

hmac_drbg.h File Reference

hmac_drbg.h File Reference

HMAC_DRBG (NIST SP 800-90A) More...

Go to the source code of this file.

Data Structures

struct  hmac_drbg_context
 HMAC_DRBG context. More...

Functions

int hmac_drbg_init (hmac_drbg_context *ctx, const md_info_t *md_info, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
 HMAC_DRBG initialisation.
int hmac_drbg_init_buf (hmac_drbg_context *ctx, const md_info_t *md_info, const unsigned char *data, size_t data_len)
 Initilisation of simpified HMAC_DRBG (never reseeds).
void hmac_drbg_set_prediction_resistance (hmac_drbg_context *ctx, int resistance)
 Enable / disable prediction resistance (Default: Off)
void hmac_drbg_set_entropy_len (hmac_drbg_context *ctx, size_t len)
 Set the amount of entropy grabbed on each reseed (Default: given by the security strength, which depends on the hash used, see hmac_drbg_init() )
void hmac_drbg_set_reseed_interval (hmac_drbg_context *ctx, int interval)
 Set the reseed interval (Default: POLARSSL_HMAC_DRBG_RESEED_INTERVAL)
void hmac_drbg_update (hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
 HMAC_DRBG update state.
int hmac_drbg_reseed (hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
 HMAC_DRBG reseeding (extracts data from entropy source)
int hmac_drbg_random_with_add (void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
 HMAC_DRBG generate random with additional update input.
int hmac_drbg_random (void *p_rng, unsigned char *output, size_t out_len)
 HMAC_DRBG generate random.
void hmac_drbg_free (hmac_drbg_context *ctx)
 Free an HMAC_DRBG context.
int hmac_drbg_write_seed_file (hmac_drbg_context *ctx, const char *path)
 Write a seed file.
int hmac_drbg_update_seed_file (hmac_drbg_context *ctx, const char *path)
 Read and update a seed file.
int hmac_drbg_self_test (int verbose)
 Checkup routine.

Detailed Description

HMAC_DRBG (NIST SP 800-90A)

Copyright (C) 2014, Brainspark B.V.

This file is part of PolarSSL (http://www.polarssl.org) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file hmac_drbg.h.


Function Documentation

void hmac_drbg_free ( hmac_drbg_context ctx )

Free an HMAC_DRBG context.

Parameters:
ctxHMAC_DRBG context to free.

Definition at line 301 of file hmac_drbg.c.

int hmac_drbg_init ( hmac_drbg_context ctx,
const md_info_t md_info,
int(*)(void *, unsigned char *, size_t)  f_entropy,
void *  p_entropy,
const unsigned char *  custom,
size_t  len 
)

HMAC_DRBG initialisation.

Parameters:
ctxHMAC_DRBG context to be initialised
md_infoMD algorithm to use for HMAC_DRBG
f_entropyEntropy callback (p_entropy, buffer to fill, buffer length)
p_entropyEntropy context
customPersonalization data (Device specific identifiers) (Can be NULL)
lenLength of personalization data
Note:
The "security strength" as defined by NIST is set to: 128 bits if md_alg is SHA-1, 192 bits if md_alg is SHA-224, 256 bits if md_alg is SHA-256 or higher. Note that SHA-256 is just as efficient as SHA-224.
Returns:
0 if successful, or POLARSSL_ERR_MD_BAD_INPUT_DATA, or POLARSSL_ERR_MD_ALLOC_FAILED, or POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED.

Definition at line 151 of file hmac_drbg.c.

int hmac_drbg_init_buf ( hmac_drbg_context ctx,
const md_info_t md_info,
const unsigned char *  data,
size_t  data_len 
)

Initilisation of simpified HMAC_DRBG (never reseeds).

(For use with deterministic ECDSA.)

Parameters:
ctxHMAC_DRBG context to be initialised
md_infoMD algorithm to use for HMAC_DRBG
dataConcatenation of entropy string and additional data
data_lenLength of data in bytes
Returns:
0 if successful, or POLARSSL_ERR_MD_BAD_INPUT_DATA, or POLARSSL_ERR_MD_ALLOC_FAILED.

Definition at line 83 of file hmac_drbg.c.

int hmac_drbg_random ( void *  p_rng,
unsigned char *  output,
size_t  out_len 
)

HMAC_DRBG generate random.

Note: Automatically reseeds if reseed_counter is reached or PR is enabled.

Parameters:
p_rngHMAC_DRBG context
outputBuffer to fill
out_lenLength of the buffer
Returns:
0 if successful, or POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG

Definition at line 293 of file hmac_drbg.c.

int hmac_drbg_random_with_add ( void *  p_rng,
unsigned char *  output,
size_t  output_len,
const unsigned char *  additional,
size_t  add_len 
)

HMAC_DRBG generate random with additional update input.

Note: Automatically reseeds if reseed_counter is reached or PR is enabled.

Parameters:
p_rngHMAC_DRBG context
outputBuffer to fill
output_lenLength of the buffer
additionalAdditional data to update with (can be NULL)
add_lenLength of additional data (can be 0)
Returns:
0 if successful, or POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG.

Definition at line 233 of file hmac_drbg.c.

int hmac_drbg_reseed ( hmac_drbg_context ctx,
const unsigned char *  additional,
size_t  len 
)

HMAC_DRBG reseeding (extracts data from entropy source)

Parameters:
ctxHMAC_DRBG context
additionalAdditional data to add to state (Can be NULL)
lenLength of additional data
Returns:
0 if successful, or POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED

Definition at line 110 of file hmac_drbg.c.

int hmac_drbg_self_test ( int  verbose )

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 441 of file hmac_drbg.c.

void hmac_drbg_set_entropy_len ( hmac_drbg_context ctx,
size_t  len 
)

Set the amount of entropy grabbed on each reseed (Default: given by the security strength, which depends on the hash used, see hmac_drbg_init() )

Parameters:
ctxHMAC_DRBG context
lenAmount of entropy to grab, in bytes

Definition at line 216 of file hmac_drbg.c.

void hmac_drbg_set_prediction_resistance ( hmac_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!

Parameters:
ctxHMAC_DRBG context
resistancePOLARSSL_HMAC_DRBG_PR_ON or POLARSSL_HMAC_DRBG_PR_OFF

Definition at line 207 of file hmac_drbg.c.

void hmac_drbg_set_reseed_interval ( hmac_drbg_context ctx,
int  interval 
)

Set the reseed interval (Default: POLARSSL_HMAC_DRBG_RESEED_INTERVAL)

Parameters:
ctxHMAC_DRBG context
intervalReseed interval

Definition at line 224 of file hmac_drbg.c.

void hmac_drbg_update ( hmac_drbg_context ctx,
const unsigned char *  additional,
size_t  add_len 
)

HMAC_DRBG update state.

Parameters:
ctxHMAC_DRBG context
additionalAdditional data to update state with, or NULL
add_lenLength of additional data, or 0
Note:
Additional data is optional, pass NULL and 0 as second third argument if no additional data is being used.

Definition at line 55 of file hmac_drbg.c.

int hmac_drbg_update_seed_file ( hmac_drbg_context ctx,
const char *  path 
)

Read and update a seed file.

Seed is added to this instance

Parameters:
ctxHMAC_DRBG context
pathName of the file
Returns:
0 if successful, 1 on file error, POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED or POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG

Definition at line 337 of file hmac_drbg.c.

int hmac_drbg_write_seed_file ( hmac_drbg_context ctx,
const char *  path 
)

Write a seed file.

Parameters:
ctxHMAC_DRBG context
pathName of the file
Returns:
0 if successful, 1 on file error, or POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED

Definition at line 312 of file hmac_drbg.c.