]>
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.
48 // Use RngLib to get random number
49 Ret
= GetRandomNumber64 (&TempRand
);
55 if (Length
>= sizeof (TempRand
)) {
56 *((UINT64
*)RandBuffer
) = TempRand
;
57 RandBuffer
+= sizeof (UINT64
);
58 Length
-= sizeof (TempRand
);
60 CopyMem (RandBuffer
, &TempRand
, Length
);
69 * Add random bytes to the pool to acquire requested amount of entropy
71 * This function is platform specific and tries to acquire the requested
72 * amount of entropy by polling platform specific entropy sources.
74 * This is OpenSSL required interface.
77 rand_pool_acquire_entropy (
83 unsigned char *Buffer
;
85 Bytes_needed
= rand_pool_bytes_needed (pool
, 1 /*entropy_factor*/);
86 if (Bytes_needed
> 0) {
87 Buffer
= rand_pool_add_begin (pool
, Bytes_needed
);
90 Ret
= RandGetBytes (Bytes_needed
, Buffer
);
92 rand_pool_add_end (pool
, 0, 0);
94 rand_pool_add_end (pool
, Bytes_needed
, 8 * Bytes_needed
);
99 return rand_pool_entropy_available (pool
);
103 * Implementation for UEFI
105 * This is OpenSSL required interface.
108 rand_pool_add_nonce_data (
114 RandGetBytes (sizeof (data
), data
);
116 return rand_pool_add (pool
, (unsigned char *)&data
, sizeof (data
), 0);
120 * Implementation for UEFI
122 * This is OpenSSL required interface.
125 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 (