]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Rand/CryptRandItc.c
2 Pseudorandom Number Generator Wrapper Implementation over OpenSSL.
4 Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalCryptLib.h"
16 #include <openssl/rand.h>
17 #include <openssl/evp.h>
18 #include <Library/PrintLib.h>
21 Sets up the seed value for the pseudorandom number generator.
23 This function sets up the seed value for the pseudorandom number generator.
24 If Seed is not NULL, then the seed passed in is used.
25 If Seed is NULL, then default seed is used.
27 @param[in] Seed Pointer to seed value.
28 If NULL, default seed is used.
29 @param[in] SeedSize Size of seed value.
30 If Seed is NULL, this parameter is ignored.
32 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
33 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
39 IN CONST UINT8
*Seed OPTIONAL
,
43 CHAR8 DefaultSeed
[128];
45 if (SeedSize
> INT_MAX
) {
50 // The software PRNG implementation built in OpenSSL depends on message digest algorithm.
51 // Make sure SHA-1 digest algorithm is available here.
53 if (EVP_add_digest (EVP_sha1 ()) == 0) {
58 // Seed the pseudorandom number generator with user-supplied value.
59 // NOTE: A cryptographic PRNG must be seeded with unpredictable data.
62 RAND_seed (Seed
, (UINT32
) SeedSize
);
65 // Retrieve current time.
70 "UEFI Crypto Library default seed (%ld)",
74 RAND_seed (DefaultSeed
, sizeof (DefaultSeed
));
77 if (RAND_status () == 1) {
85 Generates a pseudorandom byte stream of the specified size.
87 If Output is NULL, then return FALSE.
89 @param[out] Output Pointer to buffer to receive random value.
90 @param[in] Size Size of randome bytes to generate.
92 @retval TRUE Pseudorandom byte stream generated successfully.
93 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
104 // Check input parameters.
106 if (Output
== NULL
|| Size
> INT_MAX
) {
111 // Generate random data.
113 if (RAND_bytes (Output
, (UINT32
) Size
) != 1) {