rand.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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 OPENSSL_RAND_H
  10. # define OPENSSL_RAND_H
  11. # pragma once
  12. # include <openssl/macros.h>
  13. # ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define HEADER_RAND_H
  15. # endif
  16. # include <stdlib.h>
  17. # include <openssl/types.h>
  18. # include <openssl/e_os2.h>
  19. # include <openssl/randerr.h>
  20. # include <openssl/evp.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * Default security strength (in the sense of [NIST SP 800-90Ar1])
  26. *
  27. * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
  28. * of the cipher by collecting less entropy. The current DRBG implementation
  29. * does not take RAND_DRBG_STRENGTH into account and sets the strength of the
  30. * DRBG to that of the cipher.
  31. */
  32. # define RAND_DRBG_STRENGTH 256
  33. # ifndef OPENSSL_NO_DEPRECATED_3_0
  34. struct rand_meth_st {
  35. int (*seed) (const void *buf, int num);
  36. int (*bytes) (unsigned char *buf, int num);
  37. void (*cleanup) (void);
  38. int (*add) (const void *buf, int num, double randomness);
  39. int (*pseudorand) (unsigned char *buf, int num);
  40. int (*status) (void);
  41. };
  42. OSSL_DEPRECATEDIN_3_0 int RAND_set_rand_method(const RAND_METHOD *meth);
  43. OSSL_DEPRECATEDIN_3_0 const RAND_METHOD *RAND_get_rand_method(void);
  44. # ifndef OPENSSL_NO_ENGINE
  45. OSSL_DEPRECATEDIN_3_0 int RAND_set_rand_engine(ENGINE *engine);
  46. # endif
  47. OSSL_DEPRECATEDIN_3_0 RAND_METHOD *RAND_OpenSSL(void);
  48. # endif /* OPENSSL_NO_DEPRECATED_3_0 */
  49. # ifndef OPENSSL_NO_DEPRECATED_1_1_0
  50. # define RAND_cleanup() while(0) continue
  51. # endif
  52. int RAND_bytes(unsigned char *buf, int num);
  53. int RAND_priv_bytes(unsigned char *buf, int num);
  54. /*
  55. * Equivalent of RAND_priv_bytes() but additionally taking an OSSL_LIB_CTX and
  56. * a strength.
  57. */
  58. int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
  59. unsigned int strength);
  60. /*
  61. * Equivalent of RAND_bytes() but additionally taking an OSSL_LIB_CTX and
  62. * a strength.
  63. */
  64. int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
  65. unsigned int strength);
  66. # ifndef OPENSSL_NO_DEPRECATED_1_1_0
  67. OSSL_DEPRECATEDIN_1_1_0 int RAND_pseudo_bytes(unsigned char *buf, int num);
  68. # endif
  69. EVP_RAND_CTX *RAND_get0_primary(OSSL_LIB_CTX *ctx);
  70. EVP_RAND_CTX *RAND_get0_public(OSSL_LIB_CTX *ctx);
  71. EVP_RAND_CTX *RAND_get0_private(OSSL_LIB_CTX *ctx);
  72. int RAND_set0_public(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
  73. int RAND_set0_private(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
  74. int RAND_set_DRBG_type(OSSL_LIB_CTX *ctx, const char *drbg, const char *propq,
  75. const char *cipher, const char *digest);
  76. int RAND_set_seed_source_type(OSSL_LIB_CTX *ctx, const char *seed,
  77. const char *propq);
  78. void RAND_seed(const void *buf, int num);
  79. void RAND_keep_random_devices_open(int keep);
  80. # if defined(__ANDROID__) && defined(__NDK_FPABI__)
  81. __NDK_FPABI__ /* __attribute__((pcs("aapcs"))) on ARM */
  82. # endif
  83. void RAND_add(const void *buf, int num, double randomness);
  84. int RAND_load_file(const char *file, long max_bytes);
  85. int RAND_write_file(const char *file);
  86. const char *RAND_file_name(char *file, size_t num);
  87. int RAND_status(void);
  88. # ifndef OPENSSL_NO_EGD
  89. int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
  90. int RAND_egd(const char *path);
  91. int RAND_egd_bytes(const char *path, int bytes);
  92. # endif
  93. int RAND_poll(void);
  94. # if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H))
  95. /* application has to include <windows.h> in order to use these */
  96. # ifndef OPENSSL_NO_DEPRECATED_1_1_0
  97. OSSL_DEPRECATEDIN_1_1_0 void RAND_screen(void);
  98. OSSL_DEPRECATEDIN_1_1_0 int RAND_event(UINT, WPARAM, LPARAM);
  99. # endif
  100. # endif
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif