summaryrefslogtreecommitdiff
path: root/lib/mbedtls
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mbedtls')
-rw-r--r--lib/mbedtls/Kconfig54
-rw-r--r--lib/mbedtls/Makefile2
-rw-r--r--lib/mbedtls/mbedtls_def_config.h4
-rw-r--r--lib/mbedtls/sha256.c59
4 files changed, 95 insertions, 24 deletions
diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig
index 78167ffa252..35d8c507a89 100644
--- a/lib/mbedtls/Kconfig
+++ b/lib/mbedtls/Kconfig
@@ -112,6 +112,46 @@ config SPL_MD5_LEGACY
endif # SPL
+if VPL
+
+config VPL_SHA1_LEGACY
+ bool "Enable SHA1 support in VPL with legacy crypto library"
+ depends on LEGACY_CRYPTO_BASIC && VPL_SHA1
+ help
+ This option enables support of hashing using SHA1 algorithm
+ with legacy crypto library.
+
+config VPL_SHA256_LEGACY
+ bool "Enable SHA256 support in VPL with legacy crypto library"
+ depends on LEGACY_CRYPTO_BASIC && VPL_SHA256
+ help
+ This option enables support of hashing using SHA256 algorithm
+ with legacy crypto library.
+
+config VPL_SHA512_LEGACY
+ bool "Enable SHA512 support in VPL with legacy crypto library"
+ depends on LEGACY_CRYPTO_BASIC && VPL_SHA512
+ help
+ This option enables support of hashing using SHA512 algorithm
+ with legacy crypto library.
+
+config VPL_SHA384_LEGACY
+ bool "Enable SHA384 support in VPL with legacy crypto library"
+ depends on LEGACY_CRYPTO_BASIC && VPL_SHA384
+ select VPL_SHA512_LEGACY
+ help
+ This option enables support of hashing using SHA384 algorithm
+ with legacy crypto library.
+
+config VPL_MD5_LEGACY
+ bool "Enable MD5 support in VPL with legacy crypto library"
+ depends on LEGACY_CRYPTO_BASIC && VPL_MD5
+ help
+ This option enables support of hashing using MD5 algorithm
+ with legacy crypto library.
+
+endif # VPL
+
endif # LEGACY_CRYPTO_BASIC
config LEGACY_CRYPTO_CERT
@@ -297,6 +337,13 @@ config MD5_MBEDTLS
This option enables support of hashing using MD5 algorithm
with MbedTLS crypto library.
+config HKDF_MBEDTLS
+ bool "Enable HKDF support with MbedTLS crypto library"
+ depends on MBEDTLS_LIB_CRYPTO
+ help
+ This option enables support of key derivation using HKDF algorithm
+ with MbedTLS crypto library.
+
if SPL
config SPL_SHA1_MBEDTLS
@@ -335,6 +382,13 @@ config SPL_MD5_MBEDTLS
This option enables support of hashing using MD5 algorithm
with MbedTLS crypto library.
+config SPL_HKDF_MBEDTLS
+ bool "Enable HKDF support in SPL with MbedTLS crypto library"
+ depends on MBEDTLS_LIB_CRYPTO
+ help
+ This option enables support of key derivation using HKDF algorithm
+ with MbedTLS crypto library.
+
endif # SPL
endif # MBEDTLS_LIB_CRYPTO
diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile
index ce0a61e4054..e66c2018d97 100644
--- a/lib/mbedtls/Makefile
+++ b/lib/mbedtls/Makefile
@@ -33,6 +33,8 @@ mbedtls_lib_crypto-$(CONFIG_$(SPL_)SHA256_MBEDTLS) += \
$(MBEDTLS_LIB_DIR)/sha256.o
mbedtls_lib_crypto-$(CONFIG_$(SPL_)SHA512_MBEDTLS) += \
$(MBEDTLS_LIB_DIR)/sha512.o
+mbedtls_lib_crypto-$(CONFIG_$(SPL_)HKDF_MBEDTLS) += \
+ $(MBEDTLS_LIB_DIR)/hkdf.o
# MbedTLS X509 library
obj-$(CONFIG_MBEDTLS_LIB_X509) += mbedtls_lib_x509.o
diff --git a/lib/mbedtls/mbedtls_def_config.h b/lib/mbedtls/mbedtls_def_config.h
index 1d2314e90e4..fd440c392f9 100644
--- a/lib/mbedtls/mbedtls_def_config.h
+++ b/lib/mbedtls/mbedtls_def_config.h
@@ -56,6 +56,10 @@
#endif
#endif
+#if CONFIG_IS_ENABLED(HKDF_MBEDTLS)
+#define MBEDTLS_HKDF_C
+#endif
+
#if defined CONFIG_MBEDTLS_LIB_X509
#if CONFIG_IS_ENABLED(X509_CERTIFICATE_PARSER)
diff --git a/lib/mbedtls/sha256.c b/lib/mbedtls/sha256.c
index 24aa58fa674..59edcb517df 100644
--- a/lib/mbedtls/sha256.c
+++ b/lib/mbedtls/sha256.c
@@ -10,6 +10,12 @@
#endif /* USE_HOSTCC */
#include <u-boot/sha256.h>
+#include <mbedtls/md.h>
+
+#if CONFIG_IS_ENABLED(HKDF_MBEDTLS)
+#include <mbedtls/hkdf.h>
+#endif
+
const u8 sha256_der_prefix[SHA256_DER_LEN] = {
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
@@ -34,29 +40,34 @@ void sha256_finish(sha256_context *ctx, uint8_t digest[SHA256_SUM_LEN])
mbedtls_sha256_free(ctx);
}
-void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
- unsigned char *output, unsigned int chunk_sz)
+int sha256_hmac(const unsigned char *key, int keylen,
+ const unsigned char *input, unsigned int ilen,
+ unsigned char *output)
{
- sha256_context ctx;
-
- sha256_starts(&ctx);
-
- if (IS_ENABLED(CONFIG_HW_WATCHDOG) || IS_ENABLED(CONFIG_WATCHDOG)) {
- const unsigned char *curr = input;
- const unsigned char *end = input + ilen;
- int chunk;
-
- while (curr < end) {
- chunk = end - curr;
- if (chunk > chunk_sz)
- chunk = chunk_sz;
- sha256_update(&ctx, curr, chunk);
- curr += chunk;
- schedule();
- }
- } else {
- sha256_update(&ctx, input, ilen);
- }
-
- sha256_finish(&ctx, output);
+ const mbedtls_md_info_t *md;
+
+ md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
+ if (!md)
+ return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE;
+
+ return mbedtls_md_hmac(md, key, keylen, input, ilen, output);
+}
+
+#if CONFIG_IS_ENABLED(HKDF_MBEDTLS)
+int sha256_hkdf(const unsigned char *salt, int saltlen,
+ const unsigned char *ikm, int ikmlen,
+ const unsigned char *info, int infolen,
+ unsigned char *output, int outputlen)
+{
+ const mbedtls_md_info_t *md;
+
+ md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
+ if (!md)
+ return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE;
+
+ return mbedtls_hkdf(md, salt, saltlen,
+ ikm, ikmlen,
+ info, infolen,
+ output, outputlen);
}
+#endif