RAND_DRBG_new.pod 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. =pod
  2. =head1 NAME
  3. RAND_DRBG_new_ex,
  4. RAND_DRBG_new,
  5. RAND_DRBG_set,
  6. RAND_DRBG_set_defaults,
  7. RAND_DRBG_instantiate,
  8. RAND_DRBG_uninstantiate,
  9. RAND_DRBG_free,
  10. RAND_DRBG_verify_zeroization
  11. - initialize and cleanup a RAND_DRBG instance
  12. =head1 SYNOPSIS
  13. #include <openssl/rand_drbg.h>
  14. RAND_DRBG *RAND_DRBG_new_ex(OPENSSL_CTX *ctx,
  15. int type,
  16. unsigned int flags,
  17. RAND_DRBG *parent);
  18. RAND_DRBG *RAND_DRBG_new(int type,
  19. unsigned int flags,
  20. RAND_DRBG *parent);
  21. int RAND_DRBG_set_defaults(int type, unsigned int flags);
  22. int RAND_DRBG_instantiate(RAND_DRBG *drbg,
  23. const unsigned char *pers, size_t perslen);
  24. int RAND_DRBG_uninstantiate(RAND_DRBG *drbg);
  25. void RAND_DRBG_free(RAND_DRBG *drbg);
  26. int RAND_DRBG_verify_zeroization(RAND_DRBG *drbg);
  27. Deprecated since OpenSSL 3.0, can be hidden entirely by defining
  28. B<OPENSSL_API_COMPAT> with a suitable version value, see
  29. L<openssl_user_macros(7)>:
  30. int RAND_DRBG_set(RAND_DRBG *drbg,
  31. int type, unsigned int flags);
  32. =head1 DESCRIPTION
  33. RAND_DRBG_new_ex() creates a new DRBG instance of the given B<type> for the
  34. given OPENSSL_CTX <ctx>.
  35. The <ctx> parameter can be NULL in which case the default OPENSSL_CTX is used.
  36. RAND_DRBG_new() is the same as RAND_DRBG_new_ex() except that the default
  37. OPENSSL_CTX is always used.
  38. RAND_DRBG_set() initializes the B<drbg> with the given B<type> and B<flags>.
  39. This function is deprecated. Applications should instead use
  40. RAND_DRBG_new_ex() to create a new DRBG.
  41. RAND_DRBG_set_defaults() sets the default B<type> and B<flags> for new DRBG
  42. instances.
  43. The DRBG types are AES-CTR, HMAC and HASH so B<type> can be one of the
  44. following values:
  45. NID_aes_128_ctr, NID_aes_192_ctr, NID_aes_256_ctr, NID_sha1, NID_sha224,
  46. NID_sha256, NID_sha384, NID_sha512, NID_sha512_224, NID_sha512_256,
  47. NID_sha3_224, NID_sha3_256, NID_sha3_384 or NID_sha3_512.
  48. If this method is not called then the default type is given by NID_aes_256_ctr
  49. and the default flags are zero.
  50. Before the DRBG can be used to generate random bits, it is necessary to set
  51. its type and to instantiate it.
  52. The optional B<flags> argument specifies a set of bit flags which can be
  53. joined using the | operator. The supported flags are:
  54. =over 4
  55. =item RAND_DRBG_FLAG_CTR_NO_DF
  56. Disables the use of the derivation function ctr_df. For an explanation,
  57. see [NIST SP 800-90A Rev. 1].
  58. =item RAND_DRBG_FLAG_HMAC
  59. Enables use of HMAC instead of the HASH DRBG.
  60. =item RAND_DRBG_FLAG_MASTER
  61. =item RAND_DRBG_FLAG_PUBLIC
  62. =item RAND_DRBG_FLAG_PRIVATE
  63. These 3 flags can be used to set the individual DRBG types created. Multiple
  64. calls are required to set the types to different values. If none of these 3
  65. flags are used, then the same type and flags are used for all 3 DRBGs in the
  66. B<drbg> chain (<master>, <public> and <private>).
  67. =back
  68. If a B<parent> instance is specified then this will be used instead of
  69. the default entropy source for reseeding the B<drbg>. It is said that the
  70. B<drbg> is I<chained> to its B<parent>.
  71. For more information, see the NOTES section.
  72. RAND_DRBG_instantiate()
  73. seeds the B<drbg> instance using random input from trusted entropy sources.
  74. Optionally, a personalization string B<pers> of length B<perslen> can be
  75. specified.
  76. To omit the personalization string, set B<pers>=NULL and B<perslen>=0;
  77. RAND_DRBG_uninstantiate()
  78. clears the internal state of the B<drbg> and puts it back in the
  79. uninstantiated state.
  80. RAND_DRBG_verify_zeroization() confirms if the internal DRBG state is
  81. currently zeroed.
  82. =head1 RETURN VALUES
  83. RAND_DRBG_new_ex() and RAND_DRBG_new() return a pointer to a DRBG instance
  84. allocated on the heap.
  85. RAND_DRBG_set(),
  86. RAND_DRBG_instantiate(), and
  87. RAND_DRBG_uninstantiate()
  88. return 1 on success, and 0 on failure.
  89. RAND_DRBG_verify_zeroization() returns 1 if the DRBG state is current zeroed,
  90. and 0 if not.
  91. RAND_DRBG_free() does not return a value.
  92. =head1 NOTES
  93. The DRBG design supports I<chaining>, which means that a DRBG instance can
  94. use another B<parent> DRBG instance instead of the default entropy source
  95. to obtain fresh random input for reseeding, provided that B<parent> DRBG
  96. instance was properly instantiated, either from a trusted entropy source,
  97. or from yet another parent DRBG instance.
  98. For a detailed description of the reseeding process, see L<RAND_DRBG(7)>.
  99. The default DRBG type and flags are applied only during creation of a DRBG
  100. instance.
  101. To ensure that they are applied to the global and thread-local DRBG instances
  102. (<master>, resp. <public> and <private>), it is necessary to call
  103. RAND_DRBG_set_defaults() before creating any thread and before calling any
  104. cryptographic routines that obtain random data directly or indirectly.
  105. =head1 SEE ALSO
  106. L<RAND_DRBG_generate(3)>,
  107. L<RAND_DRBG(7)>
  108. =head1 HISTORY
  109. The RAND_DRBG_set() function was deprecated in OpenSSL 3.0.
  110. The RAND_DRBG functions were added in OpenSSL 1.1.1.
  111. =head1 COPYRIGHT
  112. Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
  113. Licensed under the Apache License 2.0 (the "License"). You may not use
  114. this file except in compliance with the License. You can obtain a copy
  115. in the file LICENSE in the source distribution or at
  116. L<https://www.openssl.org/source/license.html>.
  117. =cut