]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/rand_pool.c
2 OpenSSL_1_1_1b doesn't implement rand_pool_* functions for UEFI.
3 The file implement these functions.
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "crypto/rand.h"
11 #include <openssl/aes.h>
14 #include <Library/RngLib.h>
17 Calls RandomNumber64 to fill
18 a buffer of arbitrary size with random bytes.
19 This is a shim layer to RngLib.
21 @param[in] Length Size of the buffer, in bytes, to fill with.
22 @param[out] RandBuffer Pointer to the buffer to store the random result.
24 @retval TRUE Random bytes generation succeeded.
25 @retval FALSE Failed to request random bytes.
41 if (RandBuffer
== NULL
) {
42 DEBUG((DEBUG_ERROR
, "[OPENSSL_RAND_POOL] NULL RandBuffer. No random numbers are generated and your system is not secure\n"));
43 ASSERT (RandBuffer
!= NULL
); // Since we can't generate random numbers, we should assert. Otherwise we will just blow up later.
49 // Use RngLib to get random number
50 Ret
= GetRandomNumber64 (&TempRand
);
55 if (Length
>= sizeof (TempRand
)) {
56 *((UINT64
*) RandBuffer
) = TempRand
;
57 RandBuffer
+= sizeof (UINT64
);
58 Length
-= sizeof (TempRand
);
61 CopyMem (RandBuffer
, &TempRand
, Length
);
70 * Add random bytes to the pool to acquire requested amount of entropy
72 * This function is platform specific and tries to acquire the requested
73 * amount of entropy by polling platform specific entropy sources.
75 * This is OpenSSL required interface.
78 rand_pool_acquire_entropy (
84 unsigned char *Buffer
;
86 Bytes_needed
= rand_pool_bytes_needed (pool
, 1 /*entropy_factor*/);
87 if (Bytes_needed
> 0) {
88 Buffer
= rand_pool_add_begin (pool
, Bytes_needed
);
91 Ret
= RandGetBytes (Bytes_needed
, Buffer
);
93 rand_pool_add_end (pool
, 0, 0);
96 rand_pool_add_end (pool
, Bytes_needed
, 8 * Bytes_needed
);
101 return rand_pool_entropy_available (pool
);
105 * Implementation for UEFI
107 * This is OpenSSL required interface.
110 rand_pool_add_nonce_data (
115 RandGetBytes (sizeof(data
), data
);
117 return rand_pool_add (pool
, (unsigned char*)&data
, sizeof(data
), 0);
121 * Implementation for UEFI
123 * This is OpenSSL required interface.
126 rand_pool_add_additional_data (
131 RandGetBytes (sizeof(data
), data
);
133 return rand_pool_add (pool
, (unsigned char*)&data
, sizeof(data
), 0);
137 * Dummy Implementation for UEFI
139 * This is OpenSSL required interface.
150 * Dummy Implementation for UEFI
152 * This is OpenSSL required interface.
162 * Dummy Implementation for UEFI
164 * This is OpenSSL required interface.
167 rand_pool_keep_random_devices_open (