EVP_RAND-SEED-SRC.pod 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, NULL);
  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 and instantiate a seed source */
  32. rand = EVP_RAND_fetch(NULL, "SEED-SRC", NULL);
  33. seed = EVP_RAND_CTX_new(rand, NULL);
  34. EVP_RAND_instantiate(seed, strength, 0, NULL, 0, NULL);
  35. EVP_RAND_free(rand);
  36. /* Feed this into a DRBG */
  37. rand = EVP_RAND_fetch(NULL, "CTR-DRBG", NULL);
  38. rctx = EVP_RAND_CTX_new(rand, seed);
  39. EVP_RAND_free(rand);
  40. /* Configure the DRBG */
  41. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_DRBG_PARAM_CIPHER,
  42. SN_aes_256_ctr, 0);
  43. *p = OSSL_PARAM_construct_end();
  44. EVP_RAND_instantiate(rctx, strength, 0, NULL, 0, params);
  45. EVP_RAND_generate(rctx, bytes, sizeof(bytes), strength, 0, NULL, 0);
  46. EVP_RAND_CTX_free(rctx);
  47. EVP_RAND_CTX_free(seed);
  48. =head1 SEE ALSO
  49. L<EVP_RAND(3)>,
  50. L<EVP_RAND(3)/PARAMETERS>
  51. =head1 COPYRIGHT
  52. Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  53. Licensed under the Apache License 2.0 (the "License"). You may not use
  54. this file except in compliance with the License. You can obtain a copy
  55. in the file LICENSE in the source distribution or at
  56. L<https://www.openssl.org/source/license.html>.
  57. =cut