BachelorWork/appendixes/BC_ZK/README.md

200 lines
6.6 KiB
Markdown
Raw Normal View History

2021-05-24 20:44:55 +00:00
# INFORMATIONS
Organization: Technical University of Kosice (TUKE),
Department: Department of Electronics and Multimedia Telecommunications (DEMT/KEMT),
Faculties: Faculty of Electrical Engineering and Informatics (FEI),
Feld of study: Informatics,
Study program: Computer Networks,
School year: 3., Bachelor study, 2020/2021,
Author: Marek Rohac -- MR,
Compiler: Winlibs GCC -- MinGW-W64 x86_64-posix-seh, built by Brecht Sanders, v. 10.2.0,
-- works also with v.11.1.0
Version: 1.3, 20.05.2021.
# COMPILING
## VIA MAKEFILE
For compiling all source codes i prepare makefile, so just use command:
```bash
make all
```
That will create .exe files. For more details see makefile.
## SELECTIVE COMPILING
winAPIprng:
```bash
gcc winAPIprng.c -o winAPIprng -Wall -Wextra -Werror -g -std=c11 -lbcrypt
```
amdSPRNG:
```bash
gcc ./amdINC/secrng.c amdSPRNG.c -Wall -Wextra -Werror -g -I./amdINC -mrdrnd -mrdseed -o amdSPRNG -std=c11
```
opessl_rng:
```bash
gcc -o openssl_rng openssl_rng.c -Wall -Wextra -g -I./openssl/include -L./openssl/lib -llibcrypto
```
## REMOVAL
For removing all executables and files which was generated by executions these programs use command:
```bash
make clean
```
That remove all file with .exe , .bin and .txt suffixes
# USAGE
NO INPUT PARAMATERS IN EACH CASE
## WINDOWS API PRNG - winAPIprng.c
```c
39 #define RNG_PER_CYKLE_BITS 268435456 //per API call output size
41 #define RNG_CYCLES 1024 //total count of calls
```
In macro RNG_PER_CYKLE_BITS define how much output in bits you want from one call of API and in RNG_CYCLES number of api calls.
Program generate output according APIs and save values to .bin files with name by current API.
If you want to generate with specific API, just comment all other functions im main().
### MEASURMENT
For measurment of API i use function cpucyclesS() and cpucyclesE(). They returns numbers of cycles of current API.
Speed or time of execution we then can calculate via formula:
Total_cpycycles_of_API * (1/Processor_ghz_during_execution_API) * 10^-9 = Time_of_executions s
On modern processors its hard to determine how much GHz was used during executions(power plans,turbo modes,...).
Therefore i also implemented timer of execution, but keep in mind, it counts also with storing of random data.
Results are store in Results.txt file.
### NOTE FOR MEASURMENT
If you want better precision of Total execution time, don't save random data (comment function store_Data()).
Also for absolutely same conditions for every api, you should wait certain time before calling next api.
Reason is to give system time to retrieve respectively gain more data
into entropy pool from system entropy sources. (1 hours to full regen).
Also random data have much better quality after giving a time to regen entropy.
### TIME OF EXECUTIONS
Time of executions of program strongly depend on your procesor and output size.
If you don't want spend to much time lover RNG_OUTPUT_BITS (do it correctly).
WIN API for measurment is used via macros.
Experimental time results on my computer (see SPEC),if you run all api
in program with storing random data:
1,875GB output size --> CryptGenRandom --> EXECUTED in 1.752000 s
BCryptGenRandom --> EXECUTED in 21.232000 s
RtlGenRandom --> EXECUTED in 23.052000 s
SPEED OF EXECUTION IS ALSO INFLUENCED BY WRITING SPEED OF YOUR STORAGE DEVICE
(In case store_Data() is enable)
### NOTE FOR OUTPUT SIZE
To count output size in GB use formula:
--> RNG_OUTPUT_BITS/RNG_PER_CYKLE_BITS/8/1000/1000 = output_size_in_GB
For faster execution downsize macros
## AMD SECURE PRNG - amdSPRNG.c
Program use 4 AMD APIs (defined in secrng.h, realized in secrng.c)
to generate random bytes:
```c
is_RDRAND_supported();
is_RDSEED_supported();
get_rdseed_bytes_arr(unsigned char *rng_arr, unsigned int N, unsigned int retry_count)
get_rdrand_bytes_arr(unsigned char *rng_arr, unsigned int N, unsigned int retry_count)
```
Version of AMD libraries: 3.0 -- March, 2021
### DESCRIPTION
In source code, amdSPRNG.c, macros
```c
29 #define CYCLES 1000 // calls count
31 #define N 625000 //per API call output size
36 #define NT 10 //retry times
```
N define how much random bytes you want per one generating of certain API.
CYCLES defined how much times you want to repeat generating process of that API.
Program then generate output according APIs and save values
to .bin files with name by current RD name.
IN CASE OF PRINTING FAILURE TO STDOUT, RAISE NT macro.
Maximum of retry attempts is set in secrng.c,
under MAX_RETRY_COUNT on 51 line. (equal 20, default 10).
For informations about file output size check NOTE FOR OUTPUT SIZE
### MEASURMENT
Look on MEASURMENT in WINDOWS API PRNG.
Results are store in RDResults.txt file.
For better precision comment checking confition and storing data.
NOTICE: NO REGEN TIME NEEDED FOR REGAINING ENTROPY CAUSE OF USING TRNG.
### TIME OF EXECUTIONS
Look on TIME OF EXECUTION in WINDOWS API PRNG. Same principle.
Note that these will take longer time to execute program.
It depend on NT times, your processor and writing speed of storage device.
Experimental time results (same hardware & software like above):
0,625GB output size --> RDSEED --> EXECUTED in 319.976000 s
RDRAND --> EXECUTED in 71.733000 s
### NOTE FOR OUTPUT SIZE
To count output size in GB use formula:
--> N*CYCLES/1024/1024/1024 = output_size_in_GB
## OPENSSL RNG APIs 64-bit libraries used
We implement 2 API --> RAND_bytes and RAND_priv_bytes. To right function don't remove libcrypto dll.
Metods implemented in winAPIprng are use there also.
Time of executions is litle bit longer than win api.
Results are available in Ossl_rng.txt
## !!ALWAYS CHECK OUTPUT IN TERMINAL!!
## REFERENCIES
AMD RNG API Libraries + examples
--> https://developer.amd.com/amd-aocl/rng-library/
WIN API Documentations:
Deprecated
CryptGenRandom() --> https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom
RtlGenRandom() --> https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom
Currently supported:
BCryptGenRandom() --> https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
rand_s() --> https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rand-s?view=msvc-160
MEASURMENT FUNCTIONS:
--> https://github.com/newhopecrypto/newhope/tree/master/ref
WINLIBS GCC
--> http://winlibs.com/
OPENSSL LIBRARIES
--> https://curl.se/windows/
(See specification--> OpenSSL )