/*
 * Copyright (C) 2005-2022 Advanced Micro Devices, Inc. All rights reserved.
 */

AOCL-SecureRNG Library
------------------------------------------

The AOCL-SecureRNG Library exposes APIs to access hardware generated
random numbers using x86 instructions RDRAND and RDSEED.

System Requirements
-------------------

Hardware - Processor should support RDRAND and RDSEED instructions. AMD Family
17h processors and other products of 2016 and beyond support these instructions


Usage of the library
--------------------

Following are the source files included by installer package,
  1. include/secrng.h  : Header file that has declaration of all the library APIs.
  2. src/secrng.c      : Has the implementation of the APIs
  3. src/secrng_test.c : Test application to test all the library APIs
  4. Makefile          : To compile test application and library

Application developers can use the included makefile to compile the source files
and generate dynamic and static libraries. They can then link it to their application and
invoke the required APIs.

Below code snippet shows sample usage of the library API.
In this example,
  get_rdrand64u is invoked to return a single 64-bit random value and
  get_rdrand64u_arr is used to return an array of 1000 64-bit random values.


```
//Check for RDRAND instruction support
int ret = is_RDRAND_supported();
int N = 1000;

//If RDRAND supported
if (ret == SECRNG_SUPPORTED)
{
   uint64_t rng64;

   //Get 64-bit random number
   ret = get_rdrand64u(&rng64, 0);

   if (ret == SECRNG_SUCCESS)
     printf("RDRAND rng 64-bit value %lu\n\n", rng64);
   else
     printf("Failure in retrieving random value using RDRAND!\n");

   //Get a range of 64-bit random values
   uint64_t* rng64_arr = (uint64_t*) malloc(sizeof(uint64_t) * N);

   ret = get_rdrand64u_arr(rng64_arr, N, 0);

   if (ret == SECRNG_SUCCESS)
   {
     printf("RDRAND for %u 64-bit random values succeeded!\n", N);
     printf("First 10 values in the range : \n");
     for (int i = 0; i < (N > 10? 10 : N); i++)
            printf("%lu\n", rng64_arr[i]);
   }
   else
     printf("Failure in retrieving array of random values using RDRAND!\n");
}
else
{
     printf("No support for RDRAND!\n");
}

```
