ReactOS 0.4.16-dev-297-gc569aee
ctr_drbg.h
Go to the documentation of this file.
1
40/*
41 * Copyright The Mbed TLS Contributors
42 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
43 *
44 * This file is provided under the Apache License 2.0, or the
45 * GNU General Public License v2.0 or later.
46 *
47 * **********
48 * Apache License 2.0:
49 *
50 * Licensed under the Apache License, Version 2.0 (the "License"); you may
51 * not use this file except in compliance with the License.
52 * You may obtain a copy of the License at
53 *
54 * http://www.apache.org/licenses/LICENSE-2.0
55 *
56 * Unless required by applicable law or agreed to in writing, software
57 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
58 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59 * See the License for the specific language governing permissions and
60 * limitations under the License.
61 *
62 * **********
63 *
64 * **********
65 * GNU General Public License v2.0 or later:
66 *
67 * This program is free software; you can redistribute it and/or modify
68 * it under the terms of the GNU General Public License as published by
69 * the Free Software Foundation; either version 2 of the License, or
70 * (at your option) any later version.
71 *
72 * This program is distributed in the hope that it will be useful,
73 * but WITHOUT ANY WARRANTY; without even the implied warranty of
74 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 * GNU General Public License for more details.
76 *
77 * You should have received a copy of the GNU General Public License along
78 * with this program; if not, write to the Free Software Foundation, Inc.,
79 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
80 *
81 * **********
82 */
83
84#ifndef MBEDTLS_CTR_DRBG_H
85#define MBEDTLS_CTR_DRBG_H
86
87#if !defined(MBEDTLS_CONFIG_FILE)
88#include "config.h"
89#else
90#include MBEDTLS_CONFIG_FILE
91#endif
92
93#include "aes.h"
94
95#if defined(MBEDTLS_THREADING_C)
96#include "threading.h"
97#endif
98
99#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
100#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
101#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
102#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
104#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
106#if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
107#define MBEDTLS_CTR_DRBG_KEYSIZE 16
113#else
114#define MBEDTLS_CTR_DRBG_KEYSIZE 32
120#endif
121
122#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
123#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
138#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
139#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
143#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
144
145#else /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
146
151#if !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
155#endif /* !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) */
156#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
157#endif /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
158#endif /* !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) */
159
160#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
161#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
163#endif
164
165#if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
166#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
168#endif
169
170#if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
171#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
173#endif
174
175#if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
176#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
178#endif
179
180/* \} name SECTION: Module settings */
181
182#define MBEDTLS_CTR_DRBG_PR_OFF 0
184#define MBEDTLS_CTR_DRBG_PR_ON 1
187#ifdef __cplusplus
188extern "C" {
189#endif
190
195{
196 unsigned char counter[16];
202 size_t entropy_len;
208 /*
209 * Callbacks (Entropy)
210 */
211 int (*f_entropy)(void *, unsigned char *, size_t);
214 void *p_entropy;
216#if defined(MBEDTLS_THREADING_C)
217 /* Invariant: the mutex is initialized if and only if f_entropy != NULL.
218 * This means that the mutex is initialized during the initial seeding
219 * in mbedtls_ctr_drbg_seed() and freed in mbedtls_ctr_drbg_free().
220 *
221 * Note that this invariant may change without notice. Do not rely on it
222 * and do not access the mutex directly in application code.
223 */
224 mbedtls_threading_mutex_t mutex;
225#endif
226}
228
242
277#if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
286#endif
287#if defined(MBEDTLS_THREADING_C)
295#endif /* MBEDTLS_THREADING_C */
325 int (*f_entropy)(void *, unsigned char *, size_t),
326 void *p_entropy,
327 const unsigned char *custom,
328 size_t len );
329
337
352 int resistance );
353
377 size_t len );
378
392 int interval );
393
415 const unsigned char *additional, size_t len );
416
438 const unsigned char *additional,
439 size_t add_len );
440
473 unsigned char *output, size_t output_len,
474 const unsigned char *additional, size_t add_len );
475
482#if defined(MBEDTLS_THREADING_C)
489#endif /* MBEDTLS_THREADING_C */
500int mbedtls_ctr_drbg_random( void *p_rng,
501 unsigned char *output, size_t output_len );
502
503
504#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
505#if defined(MBEDTLS_DEPRECATED_WARNING)
506#define MBEDTLS_DEPRECATED __attribute__((deprecated))
507#else
508#define MBEDTLS_DEPRECATED
509#endif
527 const unsigned char *additional,
528 size_t add_len );
529#undef MBEDTLS_DEPRECATED
530#endif /* !MBEDTLS_DEPRECATED_REMOVED */
531
532#if defined(MBEDTLS_FS_IO)
544int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
545
560int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
561#endif /* MBEDTLS_FS_IO */
562
563#if defined(MBEDTLS_SELF_TEST)
564
571int mbedtls_ctr_drbg_self_test( int verbose );
572
573#endif /* MBEDTLS_SELF_TEST */
574
575/* Internal functions (do not call directly) */
577 int (*)(void *, unsigned char *, size_t), void *,
578 const unsigned char *, size_t, size_t );
579
580#ifdef __cplusplus
581}
582#endif
583
584#endif /* ctr_drbg.h */
This file contains AES definitions and functions.
int mbedtls_ctr_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 a CTR_DRBG instance with additional data and uses it to generate random data.
int mbedtls_ctr_drbg_reseed(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
This function reseeds the CTR_DRBG context, that is extracts data from the entropy source.
MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
int mbedtls_ctr_drbg_seed_entropy_len(mbedtls_ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
#define MBEDTLS_DEPRECATED
Definition: ctr_drbg.h:508
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
This function turns prediction resistance on or off. The default value is off.
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
This function sets the reseed interval.
void mbedtls_ctr_drbg_set_entropy_len(mbedtls_ctr_drbg_context *ctx, size_t len)
This function sets the amount of entropy grabbed on each seed or reseed.
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
__kernel_size_t size_t
Definition: linux.h:237
GLenum GLsizei len
Definition: glext.h:6722
#define verbose
Definition: rosglue.h:36
#define mbedtls_ctr_drbg_seed
#define mbedtls_ctr_drbg_random
#define mbedtls_ctr_drbg_init
#define mbedtls_ctr_drbg_free
The AES context-type definition.
Definition: aes.h:113
The CTR_DRBG context structure.
Definition: ctr_drbg.h:195
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: ctr_drbg.h:211
mbedtls_aes_context aes_ctx
Definition: ctr_drbg.h:206
Definition: module.h:456
Threading abstraction layer.