You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.4 KiB

  1. /*
  2. * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef HEADER_DRBG_RAND_H
  10. # define HEADER_DRBG_RAND_H
  11. # include <time.h>
  12. # include <openssl/ossl_typ.h>
  13. /* In CTR mode, disable derivation function ctr_df */
  14. # define RAND_DRBG_FLAG_CTR_NO_DF 0x1
  15. /* A logical OR of all used flag bits (currently there is only one) */
  16. # define RAND_DRBG_USED_FLAGS ( \
  17. RAND_DRBG_FLAG_CTR_NO_DF \
  18. )
  19. /*
  20. * Default security strength (in the sense of [NIST SP 800-90Ar1])
  21. *
  22. * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
  23. * of the cipher by collecting less entropy. The current DRBG implemantion does
  24. * not take RAND_DRBG_STRENGTH into account and sets the strength of the DRBG
  25. * to that of the cipher.
  26. *
  27. * RAND_DRBG_STRENGTH is currently only used for the legacy RAND
  28. * implementation.
  29. *
  30. * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and
  31. * NID_aes_256_ctr
  32. */
  33. # define RAND_DRBG_STRENGTH 256
  34. # define RAND_DRBG_TYPE NID_aes_256_ctr
  35. # define RAND_DRBG_FLAGS 0
  36. # ifdef __cplusplus
  37. extern "C" {
  38. # endif
  39. /*
  40. * Object lifetime functions.
  41. */
  42. RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent);
  43. RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent);
  44. int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags);
  45. int RAND_DRBG_set_defaults(int type, unsigned int flags);
  46. int RAND_DRBG_instantiate(RAND_DRBG *drbg,
  47. const unsigned char *pers, size_t perslen);
  48. int RAND_DRBG_uninstantiate(RAND_DRBG *drbg);
  49. void RAND_DRBG_free(RAND_DRBG *drbg);
  50. /*
  51. * Object "use" functions.
  52. */
  53. int RAND_DRBG_reseed(RAND_DRBG *drbg,
  54. const unsigned char *adin, size_t adinlen,
  55. int prediction_resistance);
  56. int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
  57. int prediction_resistance,
  58. const unsigned char *adin, size_t adinlen);
  59. int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen);
  60. int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval);
  61. int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval);
  62. int RAND_DRBG_set_reseed_defaults(
  63. unsigned int master_reseed_interval,
  64. unsigned int slave_reseed_interval,
  65. time_t master_reseed_time_interval,
  66. time_t slave_reseed_time_interval
  67. );
  68. RAND_DRBG *RAND_DRBG_get0_master(void);
  69. RAND_DRBG *RAND_DRBG_get0_public(void);
  70. RAND_DRBG *RAND_DRBG_get0_private(void);
  71. /*
  72. * EXDATA
  73. */
  74. # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \
  75. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef)
  76. int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg);
  77. void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx);
  78. /*
  79. * Callback function typedefs
  80. */
  81. typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg,
  82. unsigned char **pout,
  83. int entropy, size_t min_len,
  84. size_t max_len,
  85. int prediction_resistance);
  86. typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx,
  87. unsigned char *out, size_t outlen);
  88. typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout,
  89. int entropy, size_t min_len,
  90. size_t max_len);
  91. typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg,
  92. unsigned char *out, size_t outlen);
  93. int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
  94. RAND_DRBG_get_entropy_fn get_entropy,
  95. RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
  96. RAND_DRBG_get_nonce_fn get_nonce,
  97. RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
  98. # ifdef __cplusplus
  99. }
  100. # endif
  101. #endif