EVP_RAND-SEED-SRC.pod 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. =pod
  2. =head1 NAME
  3. EVP_RAND-SEED-SRC - The randomness seed source EVP_RAND implementation
  4. =head1 DESCRIPTION
  5. Support for deterministic random number generator seeding through the
  6. B<EVP_RAND> API.
  7. The seed sources used are specified at the time OpenSSL is configured for
  8. building using the B<--with-rand-seed=> option. By default, operating system
  9. randomness sources are used.
  10. =head2 Identity
  11. "SEED-SRC" is the name for this implementation; it can be used with the
  12. EVP_RAND_fetch() function.
  13. =head2 Supported parameters
  14. The supported parameters are:
  15. =over 4
  16. =item "state" (B<OSSL_RAND_PARAM_STATE>) <integer>
  17. =item "strength" (B<OSSL_RAND_PARAM_STRENGTH>) <unsigned integer>
  18. =item "max_request" (B<OSSL_RAND_PARAM_MAX_REQUEST>) <unsigned integer>
  19. These parameters work as described in L<EVP_RAND(3)/PARAMETERS>.
  20. =back
  21. =head1 NOTES
  22. A context for the seed source can be obtained by calling:
  23. EVP_RAND *rand = EVP_RAND_fetch(NULL, "SEED-SRC", NULL);
  24. EVP_RAND_CTX *rctx = EVP_RAND_CTX_new(rand);
  25. =head1 EXAMPLES
  26. EVP_RAND *rand;
  27. EVP_RAND_CTX *seed, *rctx;
  28. unsigned char bytes[100];
  29. OSSL_PARAM params[2], *p = params;
  30. unsigned int strength = 128;
  31. /* Create a seed source */
  32. rand = EVP_RAND_fetch(NULL, "SEED-SRC", NULL);
  33. seed = EVP_RAND_CTX_new(rand, NULL);
  34. EVP_RAND_free(rand);
  35. /* Feed this into a DRBG */
  36. rand = EVP_RAND_fetch(NULL, "CTR-DRBG", NULL);
  37. rctx = EVP_RAND_CTX_new(rand, seed);
  38. EVP_RAND_free(rand);
  39. /* Configure the DRBG */
  40. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_DRBG_PARAM_CIPHER,
  41. SN_aes_256_ctr, 0);
  42. *p = OSSL_PARAM_construct_end();
  43. EVP_RAND_instantiate(rctx, strength, 0, NULL, 0, params);
  44. EVP_RAND_generate(rctx, bytes, sizeof(bytes), strength, 0, NULL, 0);
  45. EVP_RAND_CTX_free(rctx);
  46. EVP_RAND_CTX_free(seed);
  47. =head1 SEE ALSO
  48. L<EVP_RAND(3)>,
  49. L<EVP_RAND(3)/PARAMETERS>
  50. =head1 COPYRIGHT
  51. Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  52. Licensed under the Apache License 2.0 (the "License"). You may not use
  53. this file except in compliance with the License. You can obtain a copy
  54. in the file LICENSE in the source distribution or at
  55. L<https://www.openssl.org/source/license.html>.
  56. =cut