Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sw/device/lib/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ cc_library(
deps = [
":bitfield",
":hardened",
"//sw/device/lib/crypto/drivers:rv_core_ibex",
],
)

Expand Down
1 change: 1 addition & 0 deletions sw/device/lib/base/random_order.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "sw/device/lib/base/bitfield.h"
#include "sw/device/lib/base/hardened.h"
#include "sw/device/lib/crypto/drivers/rv_core_ibex.h"

void random_order_init(random_order_t *ctx, size_t min_len) {
ctx->ctr = 0;
Expand Down
331 changes: 204 additions & 127 deletions sw/device/lib/crypto/drivers/entropy.c

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions sw/device/lib/crypto/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,14 @@ cc_library(
"//sw/device/lib/crypto/include:datatypes",
],
)

cc_library(
name = "entropy_src",
srcs = ["entropy_src.c"],
hdrs = ["//sw/device/lib/crypto/include:entropy_src.h"],
deps = [
"//sw/device/lib/base:hardened_memory",
"//sw/device/lib/crypto/drivers:entropy",
"//sw/device/lib/crypto/include:datatypes",
],
)
23 changes: 23 additions & 0 deletions sw/device/lib/crypto/impl/entropy_src.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/crypto/include/entropy_src.h"

#include <stdbool.h>

#include "sw/device/lib/crypto/drivers/entropy.h"
#include "sw/device/lib/crypto/impl/status.h"

// Module ID for status codes.
#define MODULE_ID MAKE_MODULE_ID('e', 't', 's')

otcrypto_status_t otcrypto_entropy_init(void) {
HARDENED_TRY(entropy_complex_init());
return OTCRYPTO_OK;
}

otcrypto_status_t otcrypto_entropy_check(void) {
HARDENED_TRY(entropy_complex_check());
return OTCRYPTO_OK;
}
2 changes: 2 additions & 0 deletions sw/device/lib/crypto/include/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cc_library(
"ecc_curve25519.h",
"ecc_p256.h",
"ecc_p384.h",
"entropy_src.h",
"hkdf.h",
"hmac.h",
"integrity.h",
Expand Down Expand Up @@ -79,6 +80,7 @@ cc_library(
"ecc_curve25519.h",
"ecc_p256.h",
"ecc_p384.h",
"entropy_src.h",
"hkdf.h",
"hmac.h",
"integrity.h",
Expand Down
50 changes: 50 additions & 0 deletions sw/device/lib/crypto/include/entropy_src.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ENTROPY_SRC_H_
#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ENTROPY_SRC_H_

#include "datatypes.h"

/**
* @file
* @brief Entropy source functions for the OpenTitan cryptography library.
*
* Instantiate and use the TRNG. Acts as a wrapper to the entropy driver.
*/

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* Configures the entropy source in continuous mode with FIPS thresholds.
*
* @return Operation status in `otcrypto_status_t` format.
*/
OT_WARN_UNUSED_RESULT
otcrypto_status_t otcrypto_entropy_init(void);

/**
* Ensures that the entropy complex is ready for use and verify the health
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Ensures that the entropy complex is ready for use and verify the health
* Ensures that the entropy complex is ready for use and runs the health

* checks of the generated randomness.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* checks of the generated randomness.
* checks for the generated randomness.

*
* Ensures that the entropy complex is running and that `entropy_src` is in
* FIPS mode, and verifies the thresholds for health tests in `entropy_src`.
* This function should be called periodically while the entropy complex is in
* use, because the threshold registers are not shadowed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* use, because the threshold registers are not shadowed.
* use, to prevent FI because the threshold registers are not shadowed.

*
* The test also verifies the health checks of the generated randomness
* providing a status error if a health test jumped.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* providing a status error if a health test jumped.
* providing a status error if a health test failed.

*
* @return Operation status in `otcrypto_status_t` format.
*/
OT_WARN_UNUSED_RESULT
otcrypto_status_t otcrypto_entropy_check(void);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ENTROPY_SRC_H_
Loading
Loading