BN_rand.pod 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. =pod
  2. =head1 NAME
  3. BN_rand_ex, BN_rand, BN_priv_rand_ex, BN_priv_rand, BN_pseudo_rand,
  4. BN_rand_range_ex, BN_rand_range, BN_priv_rand_range_ex, BN_priv_rand_range,
  5. BN_pseudo_rand_range
  6. - generate pseudo-random number
  7. =head1 SYNOPSIS
  8. #include <openssl/bn.h>
  9. int BN_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx);
  10. int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
  11. int BN_priv_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx);
  12. int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom);
  13. int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
  14. int BN_rand_range_ex(BIGNUM *rnd, BIGNUM *range, BN_CTX *ctx);
  15. int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
  16. int BN_priv_rand_range_ex(BIGNUM *rnd, BIGNUM *range, BN_CTX *ctx);
  17. int BN_priv_rand_range(BIGNUM *rnd, BIGNUM *range);
  18. int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
  19. =head1 DESCRIPTION
  20. BN_rand_ex() generate a cryptographically strong pseudo-random
  21. number of B<bits> in length and stores it in B<rnd> using the random number
  22. generator for the library context associated with B<ctx>. The parameter B<ctx>
  23. may be NULL in which case the default library context is used.
  24. If B<bits> is less than zero, or too small to
  25. accommodate the requirements specified by the B<top> and B<bottom>
  26. parameters, an error is returned.
  27. The B<top> parameters specifies
  28. requirements on the most significant bit of the generated number.
  29. If it is B<BN_RAND_TOP_ANY>, there is no constraint.
  30. If it is B<BN_RAND_TOP_ONE>, the top bit must be one.
  31. If it is B<BN_RAND_TOP_TWO>, the two most significant bits of
  32. the number will be set to 1, so that the product of two such random
  33. numbers will always have 2*B<bits> length.
  34. If B<bottom> is B<BN_RAND_BOTTOM_ODD>, the number will be odd; if it
  35. is B<BN_RAND_BOTTOM_ANY> it can be odd or even.
  36. If B<bits> is 1 then B<top> cannot also be B<BN_RAND_FLG_TOPTWO>.
  37. BN_rand() is the same as BN_rand_ex() except that the default library context
  38. is always used.
  39. BN_rand_range_ex() generates a cryptographically strong pseudo-random
  40. number B<rnd> in the range 0 E<lt>= B<rnd> E<lt> B<range> using the random number
  41. generator for the library context associated with B<ctx>. The parameter B<ctx>
  42. may be NULL in which case the default library context is used.
  43. BN_rand_range() is the same as BN_rand_range_ex() except that the default
  44. library context is always used.
  45. BN_priv_rand_ex(), BN_priv_rand(), BN_priv_rand_rand_ex() and
  46. BN_priv_rand_range() have the same semantics as BN_rand_ex(), BN_rand(),
  47. BN_rand_range_ex() and BN_rand_range() respectively. They are intended to be
  48. used for generating values that should remain private, and mirror the
  49. same difference between L<RAND_bytes(3)> and L<RAND_priv_bytes(3)>.
  50. =head1 NOTES
  51. Always check the error return value of these functions and do not take
  52. randomness for granted: an error occurs if the CSPRNG has not been
  53. seeded with enough randomness to ensure an unpredictable byte sequence.
  54. =head1 RETURN VALUES
  55. The functions return 1 on success, 0 on error.
  56. The error codes can be obtained by L<ERR_get_error(3)>.
  57. =head1 SEE ALSO
  58. L<ERR_get_error(3)>,
  59. L<RAND_add(3)>,
  60. L<RAND_bytes(3)>,
  61. L<RAND_priv_bytes(3)>,
  62. L<RAND(7)>,
  63. L<EVP_RAND(7)>
  64. =head1 HISTORY
  65. =over 2
  66. =item *
  67. Starting with OpenSSL release 1.1.0, BN_pseudo_rand() has been identical
  68. to BN_rand() and BN_pseudo_rand_range() has been identical to
  69. BN_rand_range().
  70. The "pseudo" functions should not be used and may be deprecated in
  71. a future release.
  72. =item *
  73. The
  74. BN_priv_rand() and BN_priv_rand_range() functions were added in OpenSSL 1.1.1.
  75. =item *
  76. The BN_rand_ex(), BN_priv_rand_ex(), BN_rand_range_ex() and
  77. BN_priv_rand_range_ex() functions were added in OpenSSL 3.0.
  78. =back
  79. =head1 COPYRIGHT
  80. Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
  81. Licensed under the Apache License 2.0 (the "License"). You may not use
  82. this file except in compliance with the License. You can obtain a copy
  83. in the file LICENSE in the source distribution or at
  84. L<https://www.openssl.org/source/license.html>.
  85. =cut