BN_rand.pod 2.9 KB

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