[crypto] Code reorganization for cryptolib.
Create an inner directory impl/ to store implementations of
cryptographic algorithms in order to clean up the top-level directory.
Signed-off-by: Jade Philipoom <jadep@google.com>
diff --git a/sw/device/lib/crypto/README.md b/sw/device/lib/crypto/README.md
index 0669b53..56a2ec1 100644
--- a/sw/device/lib/crypto/README.md
+++ b/sw/device/lib/crypto/README.md
@@ -1,5 +1,7 @@
# Library of Cryptographic Implementations
-This folder contains implementations of various cryptographic algorithms. Each
-algorithm has its own, self-contained subfolder, and can be used independently
-of the others. See algorithms' individual READMEs for details.
+This folder contains OpenTitan's OS-visible cryptographic library. The public
+API is under include/; everything else should be considered internal.
+
+Tests are separately stored under sw/device/tests/crypto, except for driver
+tests which are under drivers/.
diff --git a/sw/device/lib/crypto/BUILD b/sw/device/lib/crypto/impl/BUILD
similarity index 100%
rename from sw/device/lib/crypto/BUILD
rename to sw/device/lib/crypto/impl/BUILD
diff --git a/sw/device/lib/crypto/aes_gcm/BUILD b/sw/device/lib/crypto/impl/aes_gcm/BUILD
similarity index 100%
rename from sw/device/lib/crypto/aes_gcm/BUILD
rename to sw/device/lib/crypto/impl/aes_gcm/BUILD
diff --git a/sw/device/lib/crypto/aes_gcm/aes_gcm.c b/sw/device/lib/crypto/impl/aes_gcm/aes_gcm.c
similarity index 99%
rename from sw/device/lib/crypto/aes_gcm/aes_gcm.c
rename to sw/device/lib/crypto/impl/aes_gcm/aes_gcm.c
index 6c793c2..21d9f74 100644
--- a/sw/device/lib/crypto/aes_gcm/aes_gcm.c
+++ b/sw/device/lib/crypto/impl/aes_gcm/aes_gcm.c
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#include "sw/device/lib/crypto/aes_gcm/aes_gcm.h"
+#include "sw/device/lib/crypto/impl/aes_gcm/aes_gcm.h"
#include <stddef.h>
#include <stdint.h>
diff --git a/sw/device/lib/crypto/aes_gcm/aes_gcm.h b/sw/device/lib/crypto/impl/aes_gcm/aes_gcm.h
similarity index 92%
rename from sw/device/lib/crypto/aes_gcm/aes_gcm.h
rename to sw/device/lib/crypto/impl/aes_gcm/aes_gcm.h
index fafe542..ac56ebb 100644
--- a/sw/device/lib/crypto/aes_gcm/aes_gcm.h
+++ b/sw/device/lib/crypto/impl/aes_gcm/aes_gcm.h
@@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_AES_GCM_AES_GCM_H_
-#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_AES_GCM_AES_GCM_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_AES_GCM_AES_GCM_H_
+#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_AES_GCM_AES_GCM_H_
#include <stddef.h>
#include <stdint.h>
@@ -68,4 +68,4 @@
} // extern "C"
#endif // __cplusplus
-#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_AES_GCM_AES_GCM_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_AES_GCM_AES_GCM_H_
diff --git a/sw/device/lib/crypto/ecdsa_p256/BUILD b/sw/device/lib/crypto/impl/ecdsa_p256/BUILD
similarity index 91%
rename from sw/device/lib/crypto/ecdsa_p256/BUILD
rename to sw/device/lib/crypto/impl/ecdsa_p256/BUILD
index 4ae9465..14a08b2 100644
--- a/sw/device/lib/crypto/ecdsa_p256/BUILD
+++ b/sw/device/lib/crypto/impl/ecdsa_p256/BUILD
@@ -13,8 +13,8 @@
target_compatible_with = [OPENTITAN_CPU],
deps = [
"//sw/device/lib/base:hardened",
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:otbn",
+ "//sw/device/lib/crypto/impl:otbn_util",
"//sw/otbn/crypto:p256_ecdsa",
],
)
diff --git a/sw/device/lib/crypto/ecdsa_p256/README.md b/sw/device/lib/crypto/impl/ecdsa_p256/README.md
similarity index 100%
rename from sw/device/lib/crypto/ecdsa_p256/README.md
rename to sw/device/lib/crypto/impl/ecdsa_p256/README.md
diff --git a/sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.c b/sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.c
similarity index 98%
rename from sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.c
rename to sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.c
index f6b273c..f4a625b 100644
--- a/sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.c
+++ b/sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.c
@@ -2,11 +2,11 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#include "sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h"
+#include "sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h"
#include "sw/device/lib/base/hardened.h"
#include "sw/device/lib/crypto/drivers/otbn.h"
-#include "sw/device/lib/crypto/otbn_util.h"
+#include "sw/device/lib/crypto/impl/otbn_util.h"
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
diff --git a/sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h b/sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h
similarity index 93%
rename from sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h
rename to sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h
index 939bfe1..a47b628 100644
--- a/sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h
+++ b/sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h
@@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_ECDSA_P256_ECDSA_P256_H_
-#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_ECDSA_P256_ECDSA_P256_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_ECDSA_P256_ECDSA_P256_H_
+#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_ECDSA_P256_ECDSA_P256_H_
#include <stddef.h>
#include <stdint.h>
@@ -104,4 +104,4 @@
} // extern "C"
#endif // __cplusplus
-#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_ECDSA_P256_ECDSA_P256_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_ECDSA_P256_ECDSA_P256_H_
diff --git a/sw/device/lib/crypto/otbn_util.c b/sw/device/lib/crypto/impl/otbn_util.c
similarity index 97%
rename from sw/device/lib/crypto/otbn_util.c
rename to sw/device/lib/crypto/impl/otbn_util.c
index cc1bf5d..125b246 100644
--- a/sw/device/lib/crypto/otbn_util.c
+++ b/sw/device/lib/crypto/impl/otbn_util.c
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#include "sw/device/lib/crypto/otbn_util.h"
+#include "sw/device/lib/crypto/impl/otbn_util.h"
#include <assert.h>
#include <stddef.h>
diff --git a/sw/device/lib/crypto/otbn_util.h b/sw/device/lib/crypto/impl/otbn_util.h
similarity index 97%
rename from sw/device/lib/crypto/otbn_util.h
rename to sw/device/lib/crypto/impl/otbn_util.h
index db60250..8903ab8 100644
--- a/sw/device/lib/crypto/otbn_util.h
+++ b/sw/device/lib/crypto/impl/otbn_util.h
@@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_OTBN_UTIL_H_
-#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_OTBN_UTIL_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_OTBN_UTIL_H_
+#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_OTBN_UTIL_H_
#include <stdbool.h>
#include <stddef.h>
@@ -244,4 +244,4 @@
}
#endif
-#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_OTBN_UTIL_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_OTBN_UTIL_H_
diff --git a/sw/device/lib/crypto/rsa_3072/BUILD b/sw/device/lib/crypto/impl/rsa_3072/BUILD
similarity index 93%
rename from sw/device/lib/crypto/rsa_3072/BUILD
rename to sw/device/lib/crypto/impl/rsa_3072/BUILD
index 522d171..64f73eb 100644
--- a/sw/device/lib/crypto/rsa_3072/BUILD
+++ b/sw/device/lib/crypto/impl/rsa_3072/BUILD
@@ -15,9 +15,9 @@
"//sw/device/lib/base:hardened",
"//sw/device/lib/base:macros",
"//sw/device/lib/base:memory",
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:hmac",
"//sw/device/lib/crypto/drivers:otbn",
+ "//sw/device/lib/crypto/impl:otbn_util",
"//sw/otbn/crypto:run_rsa_verify_3072",
],
)
diff --git a/sw/device/lib/crypto/rsa_3072/rsa_3072_verify.c b/sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.c
similarity index 98%
rename from sw/device/lib/crypto/rsa_3072/rsa_3072_verify.c
rename to sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.c
index 347e827..6636a2e 100644
--- a/sw/device/lib/crypto/rsa_3072/rsa_3072_verify.c
+++ b/sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.c
@@ -2,14 +2,14 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#include "sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h"
+#include "sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h"
#include "sw/device/lib/base/hardened.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/memory.h"
#include "sw/device/lib/crypto/drivers/hmac.h"
#include "sw/device/lib/crypto/drivers/otbn.h"
-#include "sw/device/lib/crypto/otbn_util.h"
+#include "sw/device/lib/crypto/impl/otbn_util.h"
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
diff --git a/sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h b/sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h
similarity index 93%
rename from sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h
rename to sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h
index 27f903c..e2775a0 100644
--- a/sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h
+++ b/sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h
@@ -2,15 +2,15 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_RSA_3072_RSA_3072_VERIFY_H_
-#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_RSA_3072_RSA_3072_VERIFY_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_3072_RSA_3072_VERIFY_H_
+#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_3072_RSA_3072_VERIFY_H_
#include <stddef.h>
#include <stdint.h>
#include "sw/device/lib/base/hardened.h"
#include "sw/device/lib/crypto/drivers/hmac.h"
-#include "sw/device/lib/crypto/otbn_util.h"
+#include "sw/device/lib/crypto/impl/otbn_util.h"
#ifdef __cplusplus
extern "C" {
@@ -129,4 +129,4 @@
} // extern "C"
#endif // __cplusplus
-#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_RSA_3072_RSA_3072_VERIFY_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_IMPL_RSA_3072_RSA_3072_VERIFY_H_
diff --git a/sw/device/lib/crypto/api.h b/sw/device/lib/crypto/include/api.h
similarity index 99%
rename from sw/device/lib/crypto/api.h
rename to sw/device/lib/crypto/include/api.h
index b980bf1..9e196ea 100644
--- a/sw/device/lib/crypto/api.h
+++ b/sw/device/lib/crypto/include/api.h
@@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
-#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_API_H_
-#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_API_H_
+#ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_API_H_
+#define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_API_H_
/**
* @brief OS-facing API for the OpenTitan cryptography library.
@@ -1842,4 +1842,4 @@
} // extern "C"
#endif // __cplusplus
-#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_API_H_
+#endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_API_H_
diff --git a/sw/device/tests/crypto/BUILD b/sw/device/tests/crypto/BUILD
index 15889cf..a05f051 100644
--- a/sw/device/tests/crypto/BUILD
+++ b/sw/device/tests/crypto/BUILD
@@ -18,7 +18,7 @@
timeout = "long",
),
deps = [
- "//sw/device/lib/crypto/aes_gcm",
+ "//sw/device/lib/crypto/impl/aes_gcm",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_main",
@@ -32,10 +32,10 @@
timeout = "long",
),
deps = [
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:hmac",
"//sw/device/lib/crypto/drivers:otbn",
- "//sw/device/lib/crypto/ecdsa_p256",
+ "//sw/device/lib/crypto/impl:otbn_util",
+ "//sw/device/lib/crypto/impl/ecdsa_p256",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:entropy_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
@@ -57,10 +57,10 @@
),
deps = [
":ecdsa_p256_verify_testvectors_hardcoded_header",
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:hmac",
"//sw/device/lib/crypto/drivers:otbn",
- "//sw/device/lib/crypto/ecdsa_p256",
+ "//sw/device/lib/crypto/impl:otbn_util",
+ "//sw/device/lib/crypto/impl/ecdsa_p256",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:ottf_main",
],
@@ -81,10 +81,10 @@
),
deps = [
":rsa_3072_verify_testvectors_wycheproof_header",
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:hmac",
"//sw/device/lib/crypto/drivers:otbn",
- "//sw/device/lib/crypto/rsa_3072:rsa_3072_verify",
+ "//sw/device/lib/crypto/impl:otbn_util",
+ "//sw/device/lib/crypto/impl/rsa_3072:rsa_3072_verify",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:ottf_main",
],
@@ -105,10 +105,10 @@
),
deps = [
":rsa_3072_verify_testvectors_hardcoded_header",
- "//sw/device/lib/crypto:otbn_util",
"//sw/device/lib/crypto/drivers:hmac",
"//sw/device/lib/crypto/drivers:otbn",
- "//sw/device/lib/crypto/rsa_3072:rsa_3072_verify",
+ "//sw/device/lib/crypto/impl:otbn_util",
+ "//sw/device/lib/crypto/impl/rsa_3072:rsa_3072_verify",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:ottf_main",
],
diff --git a/sw/device/tests/crypto/aes_gcm_functest.c b/sw/device/tests/crypto/aes_gcm_functest.c
index 37ce9c0..f04289e 100644
--- a/sw/device/tests/crypto/aes_gcm_functest.c
+++ b/sw/device/tests/crypto/aes_gcm_functest.c
@@ -3,8 +3,8 @@
// SPDX-License-Identifier: Apache-2.0
#include "sw/device/lib/base/macros.h"
-#include "sw/device/lib/crypto/aes_gcm/aes_gcm.h"
#include "sw/device/lib/crypto/drivers/aes.h"
+#include "sw/device/lib/crypto/impl/aes_gcm/aes_gcm.h"
#include "sw/device/lib/runtime/ibex.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/test_framework/check.h"
diff --git a/sw/device/tests/crypto/ecdsa_p256_functest.c b/sw/device/tests/crypto/ecdsa_p256_functest.c
index c5865b4..2a8c34a 100644
--- a/sw/device/tests/crypto/ecdsa_p256_functest.c
+++ b/sw/device/tests/crypto/ecdsa_p256_functest.c
@@ -4,8 +4,8 @@
#include "sw/device/lib/crypto/drivers/hmac.h"
#include "sw/device/lib/crypto/drivers/otbn.h"
-#include "sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h"
-#include "sw/device/lib/crypto/otbn_util.h"
+#include "sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h"
+#include "sw/device/lib/crypto/impl/otbn_util.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/entropy_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
diff --git a/sw/device/tests/crypto/ecdsa_p256_verify_functest.c b/sw/device/tests/crypto/ecdsa_p256_verify_functest.c
index 536dec0..9156937 100644
--- a/sw/device/tests/crypto/ecdsa_p256_verify_functest.c
+++ b/sw/device/tests/crypto/ecdsa_p256_verify_functest.c
@@ -4,7 +4,7 @@
#include "sw/device/lib/crypto/drivers/hmac.h"
#include "sw/device/lib/crypto/drivers/otbn.h"
-#include "sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h"
+#include "sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
diff --git a/sw/device/tests/crypto/ecdsa_p256_verify_testvectors.h.tpl b/sw/device/tests/crypto/ecdsa_p256_verify_testvectors.h.tpl
index fc8e971..c09c128 100644
--- a/sw/device/tests/crypto/ecdsa_p256_verify_testvectors.h.tpl
+++ b/sw/device/tests/crypto/ecdsa_p256_verify_testvectors.h.tpl
@@ -8,7 +8,7 @@
#ifndef OPENTITAN_SW_DEVICE_TESTS_CRYPTO_ECDSA_P256_VERIFY_TESTVECTORS_H_
#define OPENTITAN_SW_DEVICE_TESTS_CRYPTO_ECDSA_P256_VERIFY_TESTVECTORS_H_
-#include "sw/device/lib/crypto/ecdsa_p256/ecdsa_p256.h"
+#include "sw/device/lib/crypto/impl/ecdsa_p256/ecdsa_p256.h"
#ifdef __cplusplus
extern "C" {
diff --git a/sw/device/tests/crypto/rsa_3072_verify_functest.c b/sw/device/tests/crypto/rsa_3072_verify_functest.c
index 59dac8f..010ba35 100644
--- a/sw/device/tests/crypto/rsa_3072_verify_functest.c
+++ b/sw/device/tests/crypto/rsa_3072_verify_functest.c
@@ -4,7 +4,7 @@
#include "sw/device/lib/base/memory.h"
#include "sw/device/lib/crypto/drivers/otbn.h"
-#include "sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h"
+#include "sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
diff --git a/sw/device/tests/crypto/rsa_3072_verify_testvectors.h.tpl b/sw/device/tests/crypto/rsa_3072_verify_testvectors.h.tpl
index 222a02d..0df9ac2 100644
--- a/sw/device/tests/crypto/rsa_3072_verify_testvectors.h.tpl
+++ b/sw/device/tests/crypto/rsa_3072_verify_testvectors.h.tpl
@@ -8,7 +8,7 @@
#ifndef OPENTITAN_SW_DEVICE_TESTS_CRYPTO_RSA_3072_VERIFY_TESTVECTORS_H_
#define OPENTITAN_SW_DEVICE_TESTS_CRYPTO_RSA_3072_VERIFY_TESTVECTORS_H_
-#include "sw/device/lib/crypto/rsa_3072/rsa_3072_verify.h"
+#include "sw/device/lib/crypto/impl/rsa_3072/rsa_3072_verify.h"
#ifdef __cplusplus
extern "C" {