mbed TLS v2.16.6
hmac_drbg.h
Go to the documentation of this file.
1 
10 /*
11  * Copyright (C) 2006-2019, ARM Limited, All Rights Reserved
12  * SPDX-License-Identifier: GPL-2.0
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  *
28  * This file is part of mbed TLS (https://tls.mbed.org)
29  */
30 #ifndef MBEDTLS_HMAC_DRBG_H
31 #define MBEDTLS_HMAC_DRBG_H
32 
33 #if !defined(MBEDTLS_CONFIG_FILE)
34 #include "config.h"
35 #else
36 #include MBEDTLS_CONFIG_FILE
37 #endif
38 
39 #include "md.h"
40 
41 #if defined(MBEDTLS_THREADING_C)
42 #include "threading.h"
43 #endif
44 
45 /*
46  * Error codes
47  */
48 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
49 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
50 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
51 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
61 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
62 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
63 #endif
64 
65 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
66 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
67 #endif
68 
69 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
70 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
71 #endif
72 
73 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
74 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
75 #endif
76 
77 /* \} name SECTION: Module settings */
78 
79 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
80 #define MBEDTLS_HMAC_DRBG_PR_ON 1
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
90 {
91  /* Working state: the key K is not stored explicitly,
92  * but is implied by the HMAC context */
94  unsigned char V[MBEDTLS_MD_MAX_SIZE];
97  /* Administrative state */
98  size_t entropy_len;
103  /* Callbacks */
104  int (*f_entropy)(void *, unsigned char *, size_t);
105  void *p_entropy;
107 #if defined(MBEDTLS_THREADING_C)
108  mbedtls_threading_mutex_t mutex;
109 #endif
111 
121 
181  const mbedtls_md_info_t * md_info,
182  int (*f_entropy)(void *, unsigned char *, size_t),
183  void *p_entropy,
184  const unsigned char *custom,
185  size_t len );
186 
206  const mbedtls_md_info_t * md_info,
207  const unsigned char *data, size_t data_len );
208 
223  int resistance );
224 
235  size_t len );
236 
250  int interval );
251 
265  const unsigned char *additional, size_t add_len );
266 
287  const unsigned char *additional, size_t len );
288 
315 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
316  unsigned char *output, size_t output_len,
317  const unsigned char *additional,
318  size_t add_len );
319 
338 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
339 
346 
347 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
348 #if defined(MBEDTLS_DEPRECATED_WARNING)
349 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
350 #else
351 #define MBEDTLS_DEPRECATED
352 #endif
353 
367  const unsigned char *additional, size_t add_len );
368 #undef MBEDTLS_DEPRECATED
369 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
370 
371 #if defined(MBEDTLS_FS_IO)
372 
384 
400 #endif /* MBEDTLS_FS_IO */
401 
402 
403 #if defined(MBEDTLS_SELF_TEST)
404 
410 int mbedtls_hmac_drbg_self_test( int verbose );
411 #endif
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 
417 #endif /* hmac_drbg.h */
int mbedtls_hmac_drbg_seed(mbedtls_hmac_drbg_context *ctx, const mbedtls_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 initial seeding.
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:74
int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, const unsigned char *data, size_t data_len)
Initilisation of simpified HMAC_DRBG (never reseeds).
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
Set the reseed interval.
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
This function uses HMAC_DRBG to generate random data.
Configuration options (set of defines)
int mbedtls_hmac_drbg_self_test(int verbose)
The HMAC_DRBG Checkup routine.
unsigned char V[MBEDTLS_MD_MAX_SIZE]
Definition: hmac_drbg.h:94
Threading abstraction layer.
struct mbedtls_hmac_drbg_context mbedtls_hmac_drbg_context
#define MBEDTLS_DEPRECATED
Definition: hmac_drbg.h:351
MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the HMAC_DRBG context.
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: hmac_drbg.h:104
int mbedtls_hmac_drbg_update_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
This function reads and updates a seed file. The seed is added to this instance.
This file contains the generic message-digest wrapper.
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization.
int mbedtls_hmac_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 an HMAC_DRBG instance with additional data and uses it to generate random data...
int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
This function reseeds the HMAC_DRBG context, that is extracts data from the entropy source...
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:82
mbedtls_md_context_t md_ctx
Definition: hmac_drbg.h:93
int mbedtls_hmac_drbg_write_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
This function writes a seed file.
int mbedtls_hmac_drbg_update_ret(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the HMAC_DRBG context.
void mbedtls_hmac_drbg_set_entropy_len(mbedtls_hmac_drbg_context *ctx, size_t len)
This function sets the amount of entropy grabbed on each seed or reseed.
void mbedtls_hmac_drbg_set_prediction_resistance(mbedtls_hmac_drbg_context *ctx, int resistance)
This function turns prediction resistance on or off. The default value is off.