mbed TLS v2.28.2
hmac_drbg.h
Go to the documentation of this file.
1 
10 /*
11  * Copyright The Mbed TLS Contributors
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 #ifndef MBEDTLS_HMAC_DRBG_H
27 #define MBEDTLS_HMAC_DRBG_H
28 
29 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include "mbedtls/config.h"
31 #else
32 #include MBEDTLS_CONFIG_FILE
33 #endif
34 
35 #include "mbedtls/md.h"
36 
37 #if defined(MBEDTLS_THREADING_C)
38 #include "mbedtls/threading.h"
39 #endif
40 
41 /*
42  * Error codes
43  */
45 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
47 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
49 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
51 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
52 
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 
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  /* Invariant: the mutex is initialized if and only if
109  * md_ctx->md_info != NULL. This means that the mutex is initialized
110  * during the initial seeding in mbedtls_hmac_drbg_seed() or
111  * mbedtls_hmac_drbg_seed_buf() and freed in mbedtls_ctr_drbg_free().
112  *
113  * Note that this invariant may change without notice. Do not rely on it
114  * and do not access the mutex directly in application code.
115  */
117 #endif
119 
133 
166 #if defined(MBEDTLS_THREADING_C)
174 #endif /* MBEDTLS_THREADING_C */
203  const mbedtls_md_info_t * md_info,
204  int (*f_entropy)(void *, unsigned char *, size_t),
205  void *p_entropy,
206  const unsigned char *custom,
207  size_t len );
208 
215 #if defined(MBEDTLS_THREADING_C)
223 #endif /* MBEDTLS_THREADING_C */
238  const mbedtls_md_info_t * md_info,
239  const unsigned char *data, size_t data_len );
240 
255  int resistance );
256 
267  size_t len );
268 
282  int interval );
283 
302  const unsigned char *additional, size_t add_len );
303 
329  const unsigned char *additional, size_t len );
330 
363  unsigned char *output, size_t output_len,
364  const unsigned char *additional,
365  size_t add_len );
366 
373 #if defined(MBEDTLS_THREADING_C)
380 #endif /* MBEDTLS_THREADING_C */
394 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
395 
403 
404 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
405 #if defined(MBEDTLS_DEPRECATED_WARNING)
406 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
407 #else
408 #define MBEDTLS_DEPRECATED
409 #endif
424  const unsigned char *additional, size_t add_len );
425 #undef MBEDTLS_DEPRECATED
426 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
427 
428 #if defined(MBEDTLS_FS_IO)
441 
457 #endif /* MBEDTLS_FS_IO */
458 
459 
460 #if defined(MBEDTLS_SELF_TEST)
467 int mbedtls_hmac_drbg_self_test( int verbose );
468 #endif
469 
470 #ifdef __cplusplus
471 }
472 #endif
473 
474 #endif /* hmac_drbg.h */
Configuration options (set of defines)
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.
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.
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.
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.
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization.
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
Set the reseed interval.
int mbedtls_hmac_drbg_self_test(int verbose)
The HMAC_DRBG Checkup routine.
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
This function resets HMAC_DRBG context to the state immediately after initial call of mbedtls_hmac_dr...
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)
Initialisation of simplified HMAC_DRBG (never reseeds).
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.
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_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_random(void *p_rng, unsigned char *output, size_t out_len)
This function uses HMAC_DRBG to generate random data.
#define MBEDTLS_DEPRECATED
Definition: hmac_drbg.h:406
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 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.
struct mbedtls_hmac_drbg_context mbedtls_hmac_drbg_context
This file contains the generic message-digest wrapper.
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:90
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:76
unsigned char V[MBEDTLS_MD_MAX_SIZE]
Definition: hmac_drbg.h:94
mbedtls_threading_mutex_t mutex
Definition: hmac_drbg.h:116
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: hmac_drbg.h:104
mbedtls_md_context_t md_ctx
Definition: hmac_drbg.h:93
Threading abstraction layer.