mbed TLS v2.16.0: hmac_drbg.h Source File

mbed TLS v2.16.0

hmac_drbg.h
Go to the documentation of this file.
1
6 /*
7 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * This file is part of mbed TLS (https://tls.mbed.org)
23 */
24 #ifndef MBEDTLS_HMAC_DRBG_H
25 #define MBEDTLS_HMAC_DRBG_H
26
27 #include "md.h"
28
29 #if defined(MBEDTLS_THREADING_C)
30 #include "threading.h"
31 #endif
32
33 /*
34 * Error codes
35 */
36 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
37 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
38 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
39 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
49 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
50 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
51 #endif
52
53 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
54 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
55 #endif
56
57 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
58 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
59 #endif
60
61 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
62 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
63 #endif
64
65 /* \} name SECTION: Module settings */
66
67 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
68 #define MBEDTLS_HMAC_DRBG_PR_ON 1
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
77 typedef struct mbedtls_hmac_drbg_context
78 {
79 /* Working state: the key K is not stored explicitely,
80 * but is implied by the HMAC context */
81 mbedtls_md_context_t md_ctx;
82 unsigned char V[MBEDTLS_MD_MAX_SIZE];
83 int reseed_counter;
85 /* Administrative state */
86 size_t entropy_len;
87 int prediction_resistance;
89 int reseed_interval;
91 /* Callbacks */
92 int (*f_entropy)(void *, unsigned char *, size_t);
93 void *p_entropy;
95 #if defined(MBEDTLS_THREADING_C)
96 mbedtls_threading_mutex_t mutex;
97 #endif
98 } mbedtls_hmac_drbg_context;
99
108 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
109
134 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
135 const mbedtls_md_info_t * md_info,
136 int (*f_entropy)(void *, unsigned char *, size_t),
137 void *p_entropy,
138 const unsigned char *custom,
139 size_t len );
140
154 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
155 const mbedtls_md_info_t * md_info,
156 const unsigned char *data, size_t data_len );
157
167 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
168 int resistance );
169
178 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
179 size_t len );
180
188 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
189 int interval );
190
204 int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
205 const unsigned char *additional, size_t add_len );
206
217 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
218 const unsigned char *additional, size_t len );
219
236 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
237 unsigned char *output, size_t output_len,
238 const unsigned char *additional,
239 size_t add_len );
240
254 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
255
261 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
262
263 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
264 #if defined(MBEDTLS_DEPRECATED_WARNING)
265 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
266 #else
267 #define MBEDTLS_DEPRECATED
268 #endif
269
282 MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(
283 mbedtls_hmac_drbg_context *ctx,
284 const unsigned char *additional, size_t add_len );
285 #undef MBEDTLS_DEPRECATED
286 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
287
288 #if defined(MBEDTLS_FS_IO)
289
298 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
299
311 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
312 #endif /* MBEDTLS_FS_IO */
313
314
315 #if defined(MBEDTLS_SELF_TEST)
316
321 int mbedtls_hmac_drbg_self_test( int verbose );
322 #endif
323
324 #ifdef __cplusplus
325 }
326 #endif
327
328 #endif /* hmac_drbg.h */
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 Seed and setup entropy source for future reseeds.
MBEDTLS_MD_MAX_SIZE
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:72
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). (For use with deterministic ECDSA....
mbedtls_hmac_drbg_set_reseed_interval
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
Set the reseed interval (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
mbedtls_hmac_drbg_context
Definition: hmac_drbg.h:77
mbedtls_hmac_drbg_free
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
mbedtls_hmac_drbg_random
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
HMAC_DRBG generate random.
mbedtls_hmac_drbg_self_test
int mbedtls_hmac_drbg_self_test(int verbose)
Checkup routine.
mbedtls_hmac_drbg_context::p_entropy
void * p_entropy
Definition: hmac_drbg.h:93
mbedtls_md_context_t
Definition: md.h:85
mbedtls_hmac_drbg_context::f_entropy
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: hmac_drbg.h:92
mbedtls_hmac_drbg_context::reseed_interval
int reseed_interval
Definition: hmac_drbg.h:89
mbedtls_hmac_drbg_context::V
unsigned char V[MBEDTLS_MD_MAX_SIZE]
Definition: hmac_drbg.h:82
mbedtls_hmac_drbg_context::entropy_len
size_t entropy_len
Definition: hmac_drbg.h:86
threading.h
Threading abstraction layer.
mbedtls_hmac_drbg_context
struct mbedtls_hmac_drbg_context mbedtls_hmac_drbg_context
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: hmac_drbg.h:267
mbedtls_hmac_drbg_update
MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
HMAC_DRBG update state.
mbedtls_hmac_drbg_update_seed_file
int mbedtls_hmac_drbg_update_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
Read and update a seed file. Seed is added to this instance.
md.h
This file contains the generic message-digest wrapper.
mbedtls_hmac_drbg_init
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization Makes the context ready for mbedtls_hmac_drbg_seed(),...
mbedtls_hmac_drbg_context::prediction_resistance
int prediction_resistance
Definition: hmac_drbg.h:87
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)
HMAC_DRBG generate random with additional update input.
mbedtls_hmac_drbg_reseed
int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
HMAC_DRBG reseeding (extracts data from entropy source)
mbedtls_md_info_t
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:80
mbedtls_hmac_drbg_context::md_ctx
mbedtls_md_context_t md_ctx
Definition: hmac_drbg.h:81
mbedtls_hmac_drbg_write_seed_file
int mbedtls_hmac_drbg_write_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path)
Write a seed file.
mbedtls_hmac_drbg_update_ret
int mbedtls_hmac_drbg_update_ret(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
HMAC_DRBG update state.
mbedtls_hmac_drbg_set_entropy_len
void mbedtls_hmac_drbg_set_entropy_len(mbedtls_hmac_drbg_context *ctx, size_t len)
Set the amount of entropy grabbed on each reseed (Default: given by the security strength,...
mbedtls_hmac_drbg_context::reseed_counter
int reseed_counter
Definition: hmac_drbg.h:83
mbedtls_hmac_drbg_set_prediction_resistance
void mbedtls_hmac_drbg_set_prediction_resistance(mbedtls_hmac_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)