mbed TLS v2.16.8
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 OR GPL-2.0-or-later
13  *
14  * This file is provided under the Apache License 2.0, or the
15  * GNU General Public License v2.0 or later.
16  *
17  * **********
18  * Apache License 2.0:
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License"); you may
21  * not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  * http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  *
32  * **********
33  *
34  * **********
35  * GNU General Public License v2.0 or later:
36  *
37  * This program is free software; you can redistribute it and/or modify
38  * it under the terms of the GNU General Public License as published by
39  * the Free Software Foundation; either version 2 of the License, or
40  * (at your option) any later version.
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU General Public License for more details.
46  *
47  * You should have received a copy of the GNU General Public License along
48  * with this program; if not, write to the Free Software Foundation, Inc.,
49  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50  *
51  * **********
52  */
53 #ifndef MBEDTLS_HMAC_DRBG_H
54 #define MBEDTLS_HMAC_DRBG_H
55 
56 #if !defined(MBEDTLS_CONFIG_FILE)
57 #include "config.h"
58 #else
59 #include MBEDTLS_CONFIG_FILE
60 #endif
61 
62 #include "md.h"
63 
64 #if defined(MBEDTLS_THREADING_C)
65 #include "threading.h"
66 #endif
67 
68 /*
69  * Error codes
70  */
71 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
72 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
73 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
74 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
84 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
85 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
86 #endif
87 
88 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
89 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
90 #endif
91 
92 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
93 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
94 #endif
95 
96 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
97 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
98 #endif
99 
100 /* \} name SECTION: Module settings */
101 
102 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
103 #define MBEDTLS_HMAC_DRBG_PR_ON 1
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 
113 {
114  /* Working state: the key K is not stored explicitly,
115  * but is implied by the HMAC context */
117  unsigned char V[MBEDTLS_MD_MAX_SIZE];
120  /* Administrative state */
121  size_t entropy_len;
126  /* Callbacks */
127  int (*f_entropy)(void *, unsigned char *, size_t);
128  void *p_entropy;
130 #if defined(MBEDTLS_THREADING_C)
132 #endif
134 
144 
204  const mbedtls_md_info_t * md_info,
205  int (*f_entropy)(void *, unsigned char *, size_t),
206  void *p_entropy,
207  const unsigned char *custom,
208  size_t len );
209 
229  const mbedtls_md_info_t * md_info,
230  const unsigned char *data, size_t data_len );
231 
246  int resistance );
247 
258  size_t len );
259 
273  int interval );
274 
288  const unsigned char *additional, size_t add_len );
289 
310  const unsigned char *additional, size_t len );
311 
339  unsigned char *output, size_t output_len,
340  const unsigned char *additional,
341  size_t add_len );
342 
361 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
362 
369 
370 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
371 #if defined(MBEDTLS_DEPRECATED_WARNING)
372 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
373 #else
374 #define MBEDTLS_DEPRECATED
375 #endif
376 
390  const unsigned char *additional, size_t add_len );
391 #undef MBEDTLS_DEPRECATED
392 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
393 
394 #if defined(MBEDTLS_FS_IO)
395 
407 
423 #endif /* MBEDTLS_FS_IO */
424 
425 
426 #if defined(MBEDTLS_SELF_TEST)
427 
433 int mbedtls_hmac_drbg_self_test( int verbose );
434 #endif
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 
440 #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:113
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:74
MBEDTLS_MD_MAX_SIZE
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:97
mbedtls_hmac_drbg_context::reseed_counter
int reseed_counter
Definition: hmac_drbg.h:118
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: hmac_drbg.h:374
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:117
mbedtls_hmac_drbg_context::entropy_len
size_t entropy_len
Definition: hmac_drbg.h:121
mbedtls_hmac_drbg_context::p_entropy
void * p_entropy
Definition: hmac_drbg.h:128
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:131
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:124
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:105
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:122
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:116
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:111
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:127
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.