Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/include/openssl/ctrdrbg.h

raw
1 // Copyright (c) 2022, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #ifndef OPENSSL_HEADER_CTRDRBG_H
5 #define OPENSSL_HEADER_CTRDRBG_H
6
7 #include <openssl/base.h>
8
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12
13
14 // FIPS pseudo-random number generator.
15
16
17 // CTR-DRBG state objects.
18 //
19 // CTR_DRBG_STATE contains the state of a FIPS AES-CTR-based pseudo-random
20 // number generator. If BoringSSL was built in FIPS mode then this is a FIPS
21 // Approved algorithm.
22
23 // CTR_DRBG_ENTROPY_LEN is the number of bytes of input entropy. See SP
24 // 800-90Ar1, table 3.
25 #define CTR_DRBG_ENTROPY_LEN 48
26
27 // CTR_DRBG_MAX_GENERATE_LENGTH is the maximum number of bytes that can be
28 // generated in a single call to |CTR_DRBG_generate|.
29 #define CTR_DRBG_MAX_GENERATE_LENGTH 65536
30
31 // CTR_DRBG_new returns an initialized |CTR_DRBG_STATE|, or NULL if either
32 // allocation failed or if |personalization_len| is invalid.
33 OPENSSL_EXPORT CTR_DRBG_STATE *CTR_DRBG_new(
34 const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], const uint8_t *personalization,
35 size_t personalization_len);
36
37 // CTR_DRBG_free frees |state| if non-NULL, or else does nothing.
38 OPENSSL_EXPORT void CTR_DRBG_free(CTR_DRBG_STATE* state);
39
40 // CTR_DRBG_reseed reseeds |drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of entropy
41 // in |entropy| and, optionally, up to |CTR_DRBG_ENTROPY_LEN| bytes of
42 // additional data. It returns one on success or zero on error. |entropy| and
43 // |additional_data| must not alias.
44 OPENSSL_EXPORT int CTR_DRBG_reseed(CTR_DRBG_STATE *drbg,
45 const uint8_t entropy[CTR_DRBG_ENTROPY_LEN],
46 const uint8_t *additional_data,
47 size_t additional_data_len);
48
49 // CTR_DRBG_generate processes to up |CTR_DRBG_ENTROPY_LEN| bytes of additional
50 // data (if any) and then writes |out_len| random bytes to |out|, where
51 // |out_len| <= |CTR_DRBG_MAX_GENERATE_LENGTH|. It returns one on success or
52 // zero on error.
53 OPENSSL_EXPORT int CTR_DRBG_generate(CTR_DRBG_STATE *drbg, uint8_t *out,
54 size_t out_len,
55 const uint8_t *additional_data,
56 size_t additional_data_len);
57
58 // CTR_DRBG_clear zeroises the state of |drbg|.
59 OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg);
60
61
62 #if defined(__cplusplus)
63 } // extern C
64
65 extern "C++" {
66 BSSL_NAMESPACE_BEGIN
67 BORINGSSL_MAKE_DELETER(CTR_DRBG_STATE, CTR_DRBG_free)
68 BSSL_NAMESPACE_END
69 } // extern C++
70 #endif
71
72 #endif // OPENSSL_HEADER_CTRDRBG_H