/* Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes. */
EFI_STATUS EFIAPI RngGetBytes(IN UINTN Length, OUT UINT8 *RandBuffer)
/* Runs CPU RNG instruction to fill a buffer of arbitrary size with random bytes. */
EFI_STATUS EFIAPI RngGetBytes(IN UINTN Length, OUT UINT8 *RandBuffer)
{
  BOOLEAN  IsRandom;
  UINT64   TempRand[2];
  while (Length > 0) {
    IsRandom = GetRandomNumber128 (TempRand);
    if (!IsRandom) {
      return EFI_NOT_READY;
    }
    if (Length >= sizeof (TempRand)) {
      WriteUnaligned64 ((UINT64 *)RandBuffer, TempRand[0]);
      RandBuffer += sizeof (UINT64);
      WriteUnaligned64 ((UINT64 *)RandBuffer, TempRand[1]);
      RandBuffer += sizeof (UINT64);
      Length     -= sizeof (TempRand);
    } else {
      CopyMem (RandBuffer, TempRand, Length);
      Length = 0;
    }
  }
  return EFI_SUCCESS;
}