ctrdrbg.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (c) 2022, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_CTRDRBG_H
  15. #define OPENSSL_HEADER_CTRDRBG_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. // FIPS pseudo-random number generator.
  21. // CTR-DRBG state objects.
  22. //
  23. // CTR_DRBG_STATE contains the state of a FIPS AES-CTR-based pseudo-random
  24. // number generator. If BoringSSL was built in FIPS mode then this is a FIPS
  25. // Approved algorithm.
  26. // CTR_DRBG_ENTROPY_LEN is the number of bytes of input entropy. See SP
  27. // 800-90Ar1, table 3.
  28. #define CTR_DRBG_ENTROPY_LEN 48
  29. // CTR_DRBG_MAX_GENERATE_LENGTH is the maximum number of bytes that can be
  30. // generated in a single call to |CTR_DRBG_generate|.
  31. #define CTR_DRBG_MAX_GENERATE_LENGTH 65536
  32. // CTR_DRBG_new returns an initialized |CTR_DRBG_STATE|, or NULL if either
  33. // allocation failed or if |personalization_len| is invalid.
  34. OPENSSL_EXPORT CTR_DRBG_STATE *CTR_DRBG_new(
  35. const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], const uint8_t *personalization,
  36. size_t personalization_len);
  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. // CTR_DRBG_reseed reseeds |drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of entropy
  40. // in |entropy| and, optionally, up to |CTR_DRBG_ENTROPY_LEN| bytes of
  41. // additional data. It returns one on success or zero on error.
  42. OPENSSL_EXPORT int CTR_DRBG_reseed(CTR_DRBG_STATE *drbg,
  43. const uint8_t entropy[CTR_DRBG_ENTROPY_LEN],
  44. const uint8_t *additional_data,
  45. size_t additional_data_len);
  46. // CTR_DRBG_generate processes to up |CTR_DRBG_ENTROPY_LEN| bytes of additional
  47. // data (if any) and then writes |out_len| random bytes to |out|, where
  48. // |out_len| <= |CTR_DRBG_MAX_GENERATE_LENGTH|. It returns one on success or
  49. // zero on error.
  50. OPENSSL_EXPORT int CTR_DRBG_generate(CTR_DRBG_STATE *drbg, uint8_t *out,
  51. size_t out_len,
  52. const uint8_t *additional_data,
  53. size_t additional_data_len);
  54. // CTR_DRBG_clear zeroises the state of |drbg|.
  55. OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg);
  56. #if defined(__cplusplus)
  57. } // extern C
  58. #endif
  59. #endif // OPENSSL_HEADER_CTRDRBG_H