mbed TLS v2.16.3
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: Apache-2.0
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License"); you may
15  * not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  *
26  * This file is part of mbed TLS (https://tls.mbed.org)
27  */
28 #ifndef MBEDTLS_HMAC_DRBG_H
29 #define MBEDTLS_HMAC_DRBG_H
30 
31 #if !defined(MBEDTLS_CONFIG_FILE)
32 #include "config.h"
33 #else
34 #include MBEDTLS_CONFIG_FILE
35 #endif
36 
37 #include "md.h"
38 
39 #if defined(MBEDTLS_THREADING_C)
40 #include "threading.h"
41 #endif
42 
43 /*
44  * Error codes
45  */
46 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
47 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
48 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
49 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
59 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
60 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
61 #endif
62 
63 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
64 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
65 #endif
66 
67 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
68 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
69 #endif
70 
71 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
72 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
73 #endif
74 
75 /* \} name SECTION: Module settings */
76 
77 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
78 #define MBEDTLS_HMAC_DRBG_PR_ON 1
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
88 {
89  /* Working state: the key K is not stored explicitly,
90  * but is implied by the HMAC context */
92  unsigned char V[MBEDTLS_MD_MAX_SIZE];
95  /* Administrative state */
96  size_t entropy_len;
101  /* Callbacks */
102  int (*f_entropy)(void *, unsigned char *, size_t);
103  void *p_entropy;
105 #if defined(MBEDTLS_THREADING_C)
107 #endif
109 
119 
179  const mbedtls_md_info_t * md_info,
180  int (*f_entropy)(void *, unsigned char *, size_t),
181  void *p_entropy,
182  const unsigned char *custom,
183  size_t len );
184 
204  const mbedtls_md_info_t * md_info,
205  const unsigned char *data, size_t data_len );
206 
221  int resistance );
222 
233  size_t len );
234 
248  int interval );
249 
263  const unsigned char *additional, size_t add_len );
264 
285  const unsigned char *additional, size_t len );
286 
313 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
314  unsigned char *output, size_t output_len,
315  const unsigned char *additional,
316  size_t add_len );
317 
336 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
337 
344 
345 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
346 #if defined(MBEDTLS_DEPRECATED_WARNING)
347 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
348 #else
349 #define MBEDTLS_DEPRECATED
350 #endif
351 
365  const unsigned char *additional, size_t add_len );
366 #undef MBEDTLS_DEPRECATED
367 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
368 
369 #if defined(MBEDTLS_FS_IO)
370 
382 
398 #endif /* MBEDTLS_FS_IO */
399 
400 
401 #if defined(MBEDTLS_SELF_TEST)
402 
408 int mbedtls_hmac_drbg_self_test( int verbose );
409 #endif
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 
415 #endif /* hmac_drbg.h */
mbedtls_hmac_drbg_seed_buf
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).
mbedtls_hmac_drbg_free
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
mbedtls_hmac_drbg_self_test
int mbedtls_hmac_drbg_self_test(int verbose)
The HMAC_DRBG Checkup routine.
mbedtls_hmac_drbg_context
struct mbedtls_hmac_drbg_context mbedtls_hmac_drbg_context
md.h
This file contains the generic message-digest wrapper.
mbedtls_hmac_drbg_context
Definition: hmac_drbg.h:87
mbedtls_hmac_drbg_set_reseed_interval
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
Set the reseed interval.
mbedtls_threading_mutex_t
Definition: threading.h:48
MBEDTLS_MD_MAX_SIZE
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:72
mbedtls_hmac_drbg_context::reseed_counter
int reseed_counter
Definition: hmac_drbg.h:93
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: hmac_drbg.h:347
mbedtls_hmac_drbg_update
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.
mbedtls_hmac_drbg_random
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
This function uses HMAC_DRBG to generate random data.
mbedtls_hmac_drbg_context::V
unsigned char V[MBEDTLS_MD_MAX_SIZE]
Definition: hmac_drbg.h:92
mbedtls_hmac_drbg_context::entropy_len
size_t entropy_len
Definition: hmac_drbg.h:96
mbedtls_hmac_drbg_context::p_entropy
void * p_entropy
Definition: hmac_drbg.h:103
mbedtls_hmac_drbg_update_seed_file
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.
mbedtls_hmac_drbg_context::mutex
mbedtls_threading_mutex_t mutex
Definition: hmac_drbg.h:106
mbedtls_hmac_drbg_update_ret
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.
mbedtls_hmac_drbg_context::reseed_interval
int reseed_interval
Definition: hmac_drbg.h:99
mbedtls_hmac_drbg_set_prediction_resistance
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.
mbedtls_md_info_t
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:80
mbedtls_hmac_drbg_random_with_add
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.
mbedtls_hmac_drbg_context::prediction_resistance
int prediction_resistance
Definition: hmac_drbg.h:97
threading.h
Threading abstraction layer.
mbedtls_hmac_drbg_init
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization.
mbedtls_hmac_drbg_context::md_ctx
mbedtls_md_context_t md_ctx
Definition: hmac_drbg.h:91
config.h
Configuration options (set of defines)
mbedtls_hmac_drbg_reseed
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.
mbedtls_md_context_t
Definition: md.h:85
mbedtls_hmac_drbg_seed
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.
mbedtls_hmac_drbg_set_entropy_len
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.
mbedtls_hmac_drbg_context::f_entropy
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: hmac_drbg.h:102
mbedtls_hmac_drbg_write_seed_file
int mbedtls_hmac_drbg_write_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
This function writes a seed file.