ReactOS  0.4.15-dev-3165-gdf6fff7
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
108 
113 #else
114 #define MBEDTLS_CTR_DRBG_KEYSIZE 32
115 
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)
140 
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)
152 
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
162 
163 #endif
164 
165 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
166 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
167 
168 #endif
169 
170 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
171 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
172 
173 #endif
174 
175 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
176 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
177 
178 #endif
179 
180 /* \} name SECTION: Module settings */
181 
182 #define MBEDTLS_CTR_DRBG_PR_OFF 0
183 
184 #define MBEDTLS_CTR_DRBG_PR_ON 1
185 
187 #ifdef __cplusplus
188 extern "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
278 
286 #endif
287 #if defined(MBEDTLS_THREADING_C)
288 
295 #endif /* MBEDTLS_THREADING_C */
296 
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 
472 int mbedtls_ctr_drbg_random_with_add( void *p_rng,
473  unsigned char *output, size_t output_len,
474  const unsigned char *additional, size_t add_len );
475 
482 #if defined(MBEDTLS_THREADING_C)
483 
489 #endif /* MBEDTLS_THREADING_C */
490 
500 int 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
510 
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)
533 
544 int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
545 
560 int 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 
571 int 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 */
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: ctr_drbg.h:211
The CTR_DRBG context structure.
Definition: ctr_drbg.h:194
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
This function resets CTR_DRBG context to the state immediately after initial call of mbedtls_ctr_drbg...
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)
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx)
This function initializes the CTR_DRBG context, and prepares it for mbedtls_ctr_drbg_seed() or mbedtl...
#define MBEDTLS_DEPRECATED
Definition: ctr_drbg.h:508
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
This function uses CTR_DRBG to generate random data.
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
This function sets the reseed interval.
HANDLE mutex
Definition: loader.c:2140
#define verbose
Definition: rosglue.h:36
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.
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.
Threading abstraction layer.
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.
__kernel_size_t size_t
Definition: linux.h:237
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.
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.
This file contains AES definitions and functions.
struct mbedtls_ctr_drbg_context mbedtls_ctr_drbg_context
The CTR_DRBG context structure.
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
This function seeds and sets up the CTR_DRBG entropy source for future reseeds.
GLenum GLsizei len
Definition: glext.h:6722
mbedtls_aes_context aes_ctx
Definition: ctr_drbg.h:206
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.
The AES context-type definition.
Definition: aes.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31