gnunet-android

GNUnet for Android
Log | Files | Refs | README

ctrdrbg.h (3048B)


      1 // Copyright 2022 The BoringSSL Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     https://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #ifndef OPENSSL_HEADER_CTRDRBG_H
     16 #define OPENSSL_HEADER_CTRDRBG_H
     17 
     18 #include <openssl/base.h>   // IWYU pragma: export
     19 
     20 #if defined(__cplusplus)
     21 extern "C" {
     22 #endif
     23 
     24 
     25 // FIPS pseudo-random number generator.
     26 
     27 
     28 // CTR-DRBG state objects.
     29 //
     30 // CTR_DRBG_STATE contains the state of a FIPS AES-CTR-based pseudo-random
     31 // number generator. If BoringSSL was built in FIPS mode then this is a FIPS
     32 // Approved algorithm.
     33 
     34 // CTR_DRBG_ENTROPY_LEN is the number of bytes of input entropy. See SP
     35 // 800-90Ar1, table 3.
     36 #define CTR_DRBG_ENTROPY_LEN 48
     37 
     38 // CTR_DRBG_MAX_GENERATE_LENGTH is the maximum number of bytes that can be
     39 // generated in a single call to |CTR_DRBG_generate|.
     40 #define CTR_DRBG_MAX_GENERATE_LENGTH 65536
     41 
     42 // CTR_DRBG_new returns an initialized |CTR_DRBG_STATE|, or NULL if either
     43 // allocation failed or if |personalization_len| is invalid.
     44 OPENSSL_EXPORT CTR_DRBG_STATE *CTR_DRBG_new(
     45     const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], const uint8_t *personalization,
     46     size_t personalization_len);
     47 
     48 // CTR_DRBG_free frees |state| if non-NULL, or else does nothing.
     49 OPENSSL_EXPORT void CTR_DRBG_free(CTR_DRBG_STATE* state);
     50 
     51 // CTR_DRBG_reseed reseeds |drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of entropy
     52 // in |entropy| and, optionally, up to |CTR_DRBG_ENTROPY_LEN| bytes of
     53 // additional data. It returns one on success or zero on error.
     54 OPENSSL_EXPORT int CTR_DRBG_reseed(CTR_DRBG_STATE *drbg,
     55                                    const uint8_t entropy[CTR_DRBG_ENTROPY_LEN],
     56                                    const uint8_t *additional_data,
     57                                    size_t additional_data_len);
     58 
     59 // CTR_DRBG_generate processes to up |CTR_DRBG_ENTROPY_LEN| bytes of additional
     60 // data (if any) and then writes |out_len| random bytes to |out|, where
     61 // |out_len| <= |CTR_DRBG_MAX_GENERATE_LENGTH|. It returns one on success or
     62 // zero on error.
     63 OPENSSL_EXPORT int CTR_DRBG_generate(CTR_DRBG_STATE *drbg, uint8_t *out,
     64                                      size_t out_len,
     65                                      const uint8_t *additional_data,
     66                                      size_t additional_data_len);
     67 
     68 // CTR_DRBG_clear zeroises the state of |drbg|.
     69 OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg);
     70 
     71 
     72 #if defined(__cplusplus)
     73 }  // extern C
     74 
     75 extern "C++" {
     76 BSSL_NAMESPACE_BEGIN
     77 BORINGSSL_MAKE_DELETER(CTR_DRBG_STATE, CTR_DRBG_free)
     78 BSSL_NAMESPACE_END
     79 }  // extern C++
     80 #endif
     81 
     82 #endif  // OPENSSL_HEADER_CTRDRBG_H