aboutsummaryrefslogtreecommitdiff
path: root/riscv/entropy_source.h
diff options
context:
space:
mode:
Diffstat (limited to 'riscv/entropy_source.h')
-rw-r--r--riscv/entropy_source.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/riscv/entropy_source.h b/riscv/entropy_source.h
index 47823ff..3a3c8e6 100644
--- a/riscv/entropy_source.h
+++ b/riscv/entropy_source.h
@@ -3,6 +3,7 @@
#include <iostream>
#include "internals.h"
+#include "common.h"
//
// Used to model the cryptography extension entropy source.
@@ -30,13 +31,12 @@ public:
// seed register
// ------------------------------------------------------------
- void set_seed(reg_t val) {
+ void set_seed(reg_t UNUSED val) {
// Always ignore writes to seed.
// This CSR is strictly read only. It occupies a RW CSR address
// to handle the side-effect of the changing seed value on a read.
}
-
//
// The format of seed is described in Section 4.1 of
// the scalar cryptography specification.
@@ -50,27 +50,27 @@ public:
// the bare minimum.
uint32_t return_status = OPST_ES16;
- if(return_status == OPST_ES16) {
+ if (return_status == OPST_ES16) {
- // Add some sampled entropy into the low 16 bits
- uint16_t entropy = this -> get_two_random_bytes();
- result |= entropy;
+ // Add some sampled entropy into the low 16 bits
+ uint16_t entropy = this -> get_two_random_bytes();
+ result |= entropy;
- } else if(return_status == OPST_BIST) {
+ } else if (return_status == OPST_BIST) {
- // Do nothing.
+ // Do nothing.
- } else if(return_status == OPST_WAIT) {
+ } else if (return_status == OPST_WAIT) {
- // Do nothing.
+ // Do nothing.
- } else if(return_status == OPST_DEAD) {
+ } else if (return_status == OPST_DEAD) {
- // Do nothing. Stay dead.
+ // Do nothing. Stay dead.
} else {
- // Unreachable.
+ // Unreachable.
}
@@ -93,25 +93,25 @@ public:
// Read two random bytes from the entropy source file.
uint16_t get_two_random_bytes() {
- std::ifstream fh(this -> randomness_source, std::ios::binary);
+ std::ifstream fh(this -> randomness_source, std::ios::binary);
- if(fh.is_open()) {
+ if (fh.is_open()) {
- uint16_t random_bytes;
+ uint16_t random_bytes;
- fh.read((char*)(&random_bytes), 2);
+ fh.read((char*)(&random_bytes), 2);
- fh.close();
+ fh.close();
- return random_bytes;
+ return random_bytes;
- } else {
+ } else {
- fprintf(stderr, "Could not open randomness source file:\n\t");
- fprintf(stderr, "%s", randomness_source.c_str());
- abort();
+ fprintf(stderr, "Could not open randomness source file:\n\t");
+ fprintf(stderr, "%s", randomness_source.c_str());
+ abort();
- }
+ }
}