BN_rand.pod 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. BN_priv_rand() and BN_priv_rand_range() were added in OpenSSL 1.1.1.
  53. =back
  54. =head1 SEE ALSO
  55. L<ERR_get_error(3)>,
  56. L<RAND_add(3)>,
  57. L<RAND_bytes(3)>,
  58. L<RAND_priv_bytes(3)>,
  59. L<RAND(7)>,
  60. L<RAND_DRBG(7)>
  61. =head1 COPYRIGHT
  62. Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
  63. Licensed under the OpenSSL license (the "License"). You may not use
  64. this file except in compliance with the License. You can obtain a copy
  65. in the file LICENSE in the source distribution or at
  66. L<https://www.openssl.org/source/license.html>.
  67. =cut