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

rand.h 3.9 kB

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