fips_rand.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* fips_rand.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* fips_rand.h for openSSL compatibility */
  22. #ifndef WOLFSSL_OPENSSL_FIPS_RAND_H_
  23. #define WOLFSSL_OPENSSL_FIPS_RAND_H_
  24. #include <wolfssl/openssl/ssl.h>
  25. #include <wolfssl/wolfcrypt/random.h>
  26. #if !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  27. struct WOLFSSL_DRBG_CTX;
  28. typedef size_t (*drbg_entropy_get)(struct WOLFSSL_DRBG_CTX* ctx, unsigned char** pout,
  29. int entropy, size_t min_len, size_t max_len);
  30. typedef void (*drbg_entropy_clean)(struct WOLFSSL_DRBG_CTX* ctx, unsigned char* out,
  31. size_t olen);
  32. typedef size_t (*drbg_nonce_get)(struct WOLFSSL_DRBG_CTX* ctx, unsigned char** pout,
  33. int entropy, size_t min_len, size_t max_len);
  34. typedef void (*drbg_nonce_clean)(struct WOLFSSL_DRBG_CTX* ctx, unsigned char* out,
  35. size_t olen);
  36. typedef struct WOLFSSL_DRBG_CTX {
  37. WC_RNG* rng;
  38. drbg_entropy_get entropy_get;
  39. drbg_entropy_clean entropy_clean;
  40. size_t entropy_blocklen;
  41. drbg_nonce_get none_get;
  42. drbg_nonce_clean nonce_clean;
  43. int type;
  44. int status;
  45. int xflags;
  46. void* app_data;
  47. } WOLFSSL_DRBG_CTX;
  48. #define DRBG_FLAG_CTR_USE_DF 0x1
  49. #define DRBG_FLAG_TEST 0x2
  50. #define DRBG_FLAG_NOERR 0x1
  51. #define DRBG_CUSTOM_RESEED 0x2
  52. #define DRBG_STATUS_UNINITIALISED 0
  53. #define DRBG_STATUS_READY 1
  54. #define DRBG_STATUS_RESEED 2
  55. #define DRBG_STATUS_ERROR 3
  56. WOLFSSL_API WOLFSSL_DRBG_CTX* wolfSSL_FIPS_drbg_new(int type,
  57. unsigned int flags);
  58. WOLFSSL_API int wolfSSL_FIPS_drbg_init(WOLFSSL_DRBG_CTX *ctx,
  59. int type, unsigned int flags);
  60. WOLFSSL_API int wolfSSL_FIPS_drbg_instantiate(WOLFSSL_DRBG_CTX* ctx,
  61. const unsigned char* pers, size_t perslen);
  62. WOLFSSL_API int wolfSSL_FIPS_drbg_set_callbacks(WOLFSSL_DRBG_CTX* ctx,
  63. drbg_entropy_get entropy_get, drbg_entropy_clean entropy_clean,
  64. size_t entropy_blocklen,
  65. drbg_nonce_get none_get, drbg_nonce_clean nonce_clean);
  66. WOLFSSL_API void wolfSSL_FIPS_rand_add(const void* buf, int num,
  67. double entropy);
  68. WOLFSSL_API int wolfSSL_FIPS_drbg_reseed(WOLFSSL_DRBG_CTX* ctx,
  69. const unsigned char* adin, size_t adinlen);
  70. WOLFSSL_API int wolfSSL_FIPS_drbg_generate(WOLFSSL_DRBG_CTX* ctx,
  71. unsigned char* out, size_t outlen, int prediction_resistance,
  72. const unsigned char* adin, size_t adinlen);
  73. WOLFSSL_API int wolfSSL_FIPS_drbg_uninstantiate(WOLFSSL_DRBG_CTX *ctx);
  74. WOLFSSL_API void wolfSSL_FIPS_drbg_free(WOLFSSL_DRBG_CTX *ctx);
  75. WOLFSSL_API WOLFSSL_DRBG_CTX* wolfSSL_FIPS_get_default_drbg(void);
  76. WOLFSSL_API void wolfSSL_FIPS_get_timevec(unsigned char* buf,
  77. unsigned long* pctr);
  78. WOLFSSL_API void* wolfSSL_FIPS_drbg_get_app_data(WOLFSSL_DRBG_CTX *ctx);
  79. WOLFSSL_API void wolfSSL_FIPS_drbg_set_app_data(WOLFSSL_DRBG_CTX *ctx,
  80. void *app_data);
  81. /* compatibility mapping */
  82. typedef WOLFSSL_DRBG_CTX DRBG_CTX;
  83. #define FIPS_drbg_init wolfSSL_FIPS_drbg_init
  84. #define FIPS_drbg_new wolfSSL_FIPS_drbg_new
  85. #define FIPS_drbg_instantiate wolfSSL_FIPS_drbg_instantiate
  86. #define FIPS_drbg_set_callbacks wolfSSL_FIPS_drbg_set_callbacks
  87. #define FIPS_rand_add wolfSSL_FIPS_rand_add
  88. #define FIPS_drbg_reseed wolfSSL_FIPS_drbg_reseed
  89. #define FIPS_drbg_generate wolfSSL_FIPS_drbg_generate
  90. #define FIPS_drbg_uninstantiate wolfSSL_FIPS_drbg_uninstantiate
  91. #define FIPS_drbg_free wolfSSL_FIPS_drbg_free
  92. #define FIPS_get_default_drbg wolfSSL_FIPS_get_default_drbg
  93. #define FIPS_get_timevec wolfSSL_FIPS_get_timevec
  94. #define FIPS_drbg_get_app_data wolfSSL_FIPS_drbg_get_app_data
  95. #define FIPS_drbg_set_app_data wolfSSL_FIPS_drbg_set_app_data
  96. #endif /* !WC_NO_RNG && HAVE_HASHDRBG */
  97. #endif /* WOLFSSL_OPENSSL_FIPS_RAND_H_ */