TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmTrng.c
Go to the documentation of this file.
1
13#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
16#include <Library/ArmTrngLib.h>
17#include <Protocol/Rng.h>
18
19#include "RngDxeInternals.h"
20
34EFIAPI
36 IN UINTN Length,
37 OUT UINT8 *Entropy
38 )
39{
40 EFI_STATUS Status;
41 UINTN CollectedEntropyBits;
42 UINTN RequiredEntropyBits;
43 UINTN EntropyBits;
44 UINTN Index;
45 UINTN MaxBits;
46
47 ZeroMem (Entropy, Length);
48
49 RequiredEntropyBits = (Length << 3);
50 Index = 0;
51 CollectedEntropyBits = 0;
53 while (CollectedEntropyBits < RequiredEntropyBits) {
54 EntropyBits = MIN ((RequiredEntropyBits - CollectedEntropyBits), MaxBits);
55 Status = GetArmTrngEntropy (
56 EntropyBits,
57 (Length - Index),
58 &Entropy[Index]
59 );
60 if (EFI_ERROR (Status)) {
61 // Discard the collected bits.
62 ZeroMem (Entropy, Length);
63 return Status;
64 }
65
66 CollectedEntropyBits += EntropyBits;
67 Index += (EntropyBits >> 3);
68 } // while
69
70 return Status;
71}
UINT64 UINTN
EFI_STATUS EFIAPI GenerateEntropy(IN UINTN Length, OUT UINT8 *Entropy)
Definition: ArmTrng.c:35
RETURN_STATUS EFIAPI GetArmTrngEntropy(IN UINTN EntropyBits, IN UINTN BufferSize, OUT UINT8 *Buffer)
Definition: ArmTrngLib.c:247
UINTN EFIAPI GetArmTrngMaxSupportedEntropyBits(VOID)
Definition: ArmTrngLib.c:217
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define MIN(a, b)
Definition: Base.h:1007
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29