blob: f86c13665b4ca8e87f5d326965e24183a96e9347 [file] [log] [blame]
Manuel Pégourié-Gonnard490bdf32014-01-27 14:03:10 +01001/**
2 * \file hmac_drbg.h
3 *
4 * \brief HMAC_DRBG (NIST SP 800-90A)
5 *
6 * Copyright (C) 2014, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_HMAC_DRBG_H
28#define POLARSSL_HMAC_DRBG_H
29
30#include "md.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * Simplified HMAC_DRBG context.
38 * No reseed counter, no prediction resistance flag.
39 */
40typedef struct
41{
42 md_context_t md_ctx;
43 unsigned char V[POLARSSL_MD_MAX_SIZE];
44 unsigned char K[POLARSSL_MD_MAX_SIZE];
45} hmac_drbg_context;
46
47/**
48 * \brief HMAC_DRBG initialisation
49 *
50 * \param ctx HMAC_DRBG context to be initialised
51 * \param md_info MD algorithm to use for HMAC_DRBG
52 * \param data Concatenation of entropy string and additional data
53 * \param data_len Length of data in bytes
54 *
55 * \todo Use entropy callback rather than buffer.
56 *
57 * \return 0 if successful, or
58 * POLARSSL_ERR_MD_BAD_INPUT_DATA, or
59 * POLARSSL_ERR_MD_ALLOC_FAILED
60 */
61int hmac_drbg_init( hmac_drbg_context *ctx,
62 const md_info_t * md_info,
63 const unsigned char *data, size_t data_len );
64
65/**
66 * \brief HMAC_DRBG update state
67 *
68 * \param ctx HMAC_DRBG context
69 * \param additional Additional data to update state with, or NULL
70 * \param add_len Length of additional data, or 0
71 *
72 * \note Additional data is optional, pass NULL and 0 as second
73 * third argument if no additional data is being used.
74 */
75void hmac_drbg_update( hmac_drbg_context *ctx,
76 const unsigned char *additional, size_t add_len );
77
78/**
79 * \brief HMAC_DRBG generate random
80 *
81 * Note: Automatically reseeds if reseed_counter is reached. (TODO)
82 *
83 * \param p_rng HMAC_DRBG context
84 * \param output Buffer to fill
85 * \param output_len Length of the buffer
86 *
87 * \return 0 if successful.
88 */
89int hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
90
91/**
92 * \brief Free an HMAC_DRBG context
93 *
94 * \param ctx HMAC_DRBG context to free.
95 */
96void hmac_drbg_free( hmac_drbg_context *ctx );
97
98
99#if defined(POLARSSL_SELF_TEST)
100/**
101 * \brief Checkup routine
102 *
103 * \return 0 if successful, or 1 if the test failed
104 */
105int hmac_drbg_self_test( int verbose );
106#endif
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif /* hmac_drbg.h */