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
3 changes: 3 additions & 0 deletions drivers/crypto/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ config CRYPTO_MBEDTLS_SHIM
bool "MbedTLS shim driver [EXPERIMENTAL]"
select MBEDTLS
select MBEDTLS_ENABLE_HEAP
select MBEDTLS_SHA224
select MBEDTLS_SHA256
select MBEDTLS_SHA384
select MBEDTLS_SHA512
select MBEDTLS_CIPHER_AES_ENABLED
select EXPERIMENTAL
Expand Down
14 changes: 7 additions & 7 deletions drivers/crypto/crypto_ataes132a.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static int do_ccm_encrypt_mac(struct cipher_ctx *ctx,

if (aead_op->ad != NULL || aead_op->ad_len != 0U) {
LOG_ERR("Associated data is not supported.");
return -EINVAL;
return -ENOTSUP;
}

ataes132a_aes_ccm_encrypt(dev, key_id, &mac_mode,
Expand Down Expand Up @@ -758,7 +758,7 @@ static int do_ccm_decrypt_auth(struct cipher_ctx *ctx,

if (aead_op->ad != NULL || aead_op->ad_len != 0U) {
LOG_ERR("Associated data is not supported.");
return -EINVAL;
return -ENOTSUP;
}

/* Normal Decryption Mode will only decrypt host generated packets */
Expand Down Expand Up @@ -835,18 +835,18 @@ static int ataes132a_session_setup(const struct device *dev,

if (algo != CRYPTO_CIPHER_ALGO_AES) {
LOG_ERR("ATAES132A unsupported algorithm");
return -EINVAL;
return -ENOTSUP;
}

/*ATAES132A support I2C polling only*/
if (!(ctx->flags & CAP_SYNC_OPS)) {
LOG_ERR("Async not supported by this driver");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->keylen != ATAES132A_AES_KEY_SIZE) {
LOG_ERR("ATAES132A unsupported key size");
return -EINVAL;
return -ENOTSUP;
}

if (op_type == CRYPTO_CIPHER_OP_ENCRYPT) {
Expand All @@ -859,7 +859,7 @@ static int ataes132a_session_setup(const struct device *dev,
break;
default:
LOG_ERR("ATAES132A unsupported mode");
return -EINVAL;
return -ENOTSUP;
}
} else {
switch (mode) {
Expand All @@ -871,7 +871,7 @@ static int ataes132a_session_setup(const struct device *dev,
break;
default:
LOG_ERR("ATAES132A unsupported mode");
return -EINVAL;
return -ENOTSUP;
}
}

Expand Down
14 changes: 7 additions & 7 deletions drivers/crypto/crypto_cc23x0.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,24 +985,24 @@ static int crypto_cc23x0_session_setup(const struct device *dev,
{
if (ctx->flags & ~(CRYPTO_CC23_CAP)) {
LOG_ERR("Unsupported feature");
return -EINVAL;
return -ENOTSUP;
}

if (algo != CRYPTO_CIPHER_ALGO_AES) {
LOG_ERR("Unsupported algo");
return -EINVAL;
return -ENOTSUP;
}

if (mode != CRYPTO_CIPHER_MODE_ECB &&
mode != CRYPTO_CIPHER_MODE_CTR &&
mode != CRYPTO_CIPHER_MODE_CCM) {
LOG_ERR("Unsupported mode");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->keylen != 16U) {
LOG_ERR("%u key size is not supported", ctx->keylen);
return -EINVAL;
return -ENOTSUP;
}

if (!ctx->key.bit_stream) {
Expand All @@ -1022,21 +1022,21 @@ static int crypto_cc23x0_session_setup(const struct device *dev,
ctx->ops.ccm_crypt_hndlr = crypto_cc23x0_ccm_encrypt;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
} else {
switch (mode) {
case CRYPTO_CIPHER_MODE_ECB:
LOG_ERR("ECB decryption not supported by the hardware");
return -EINVAL;
return -ENOTSUP;
case CRYPTO_CIPHER_MODE_CTR:
ctx->ops.ctr_crypt_hndlr = crypto_cc23x0_ctr;
break;
case CRYPTO_CIPHER_MODE_CCM:
ctx->ops.ccm_crypt_hndlr = crypto_cc23x0_ccm_decrypt;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/crypto/crypto_it51xxx_sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ static int it51xxx_hash_begin_session(const struct device *dev, struct hash_ctx
{
if (algo != CRYPTO_HASH_ALGO_SHA256) {
LOG_ERR("Unsupported algorithm");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->flags & ~(it51xxx_query_hw_caps(dev))) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

it51xxx_sha256_init(true);
Expand Down
4 changes: 2 additions & 2 deletions drivers/crypto/crypto_it8xxx2_sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ static int it8xxx2_hash_begin_session(const struct device *dev,
{
if (algo != CRYPTO_HASH_ALGO_SHA256) {
LOG_ERR("Unsupported algo");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->flags & ~(it8xxx2_query_hw_caps(dev))) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

it8xxx2_sha256_init(false);
Expand Down
4 changes: 2 additions & 2 deletions drivers/crypto/crypto_it8xxx2_sha_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ static int it8xxx2_hash_begin_session(const struct device *dev,
{
if (algo != CRYPTO_HASH_ALGO_SHA256) {
LOG_ERR("Unsupported algorithm");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->flags & ~(it8xxx2_query_hw_caps(dev))) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

it8xxx2_sha256_init(true);
Expand Down
4 changes: 2 additions & 2 deletions drivers/crypto/crypto_mchp_xec_symcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ static int xec_symcr_hash_session_begin(const struct device *dev, struct hash_ct

if (ctx->flags & ~(MCHP_XEC_SYMCR_CAPS_SUPPORT)) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

rom_algo = lookup_hash_alg(algo);
if (rom_algo == MCHP_ROM_HASH_ALG_NONE) {
LOG_ERR("Unsupported algo %d", algo);
return -EINVAL;
return -ENOTSUP;
}

session_idx = mchp_xec_get_unused_session_index(data);
Expand Down
6 changes: 3 additions & 3 deletions drivers/crypto/crypto_mtls_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static int mtls_session_setup(const struct device *dev,
#endif
mode != CRYPTO_CIPHER_MODE_ECB) {
LOG_ERR("Unsupported mode");
return -EINVAL;
return -ENOTSUP;
}

if (ctx->keylen != 16U) {
Expand Down Expand Up @@ -541,15 +541,15 @@ static int mtls_hash_session_setup(const struct device *dev,

if (ctx->flags & ~(MTLS_SUPPORT)) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

if ((algo != CRYPTO_HASH_ALGO_SHA224) &&
(algo != CRYPTO_HASH_ALGO_SHA256) &&
(algo != CRYPTO_HASH_ALGO_SHA384) &&
(algo != CRYPTO_HASH_ALGO_SHA512)) {
LOG_ERR("Unsupported algo: %d", algo);
return -EINVAL;
return -ENOTSUP;
}

ctx_idx = mtls_get_unused_session_index();
Expand Down
6 changes: 3 additions & 3 deletions drivers/crypto/crypto_npcx_sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static int npcx_sha_compute(struct hash_ctx *ctx, struct hash_pkt *pkt, bool fin
break;
default:
LOG_ERR("Unexpected algo: %d", npcx_session->algo);
return -EINVAL;
return -ENOTSUP;
}

if (!ctx->started) {
Expand Down Expand Up @@ -140,13 +140,13 @@ static int npcx_hash_session_setup(const struct device *dev, struct hash_ctx *ct

if (ctx->flags & ~(NPCX_HASH_CAPS_SUPPORT)) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

if ((algo != CRYPTO_HASH_ALGO_SHA256) && (algo != CRYPTO_HASH_ALGO_SHA384) &&
(algo != CRYPTO_HASH_ALGO_SHA512)) {
LOG_ERR("Unsupported algo: %d", algo);
return -EINVAL;
return -ENOTSUP;
}

ctx_idx = npcx_get_unused_session_index();
Expand Down
2 changes: 1 addition & 1 deletion drivers/crypto/crypto_rts5912_sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static int rts5912_hash_begin_session(const struct device *dev, struct hash_ctx
rts5912_sha256_start(dev);
break;
default:
return -EINVAL;
return -ENOTSUP;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/crypto/crypto_smartbond.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static int crypto_smartbond_hash_set_algo(enum hash_algo algo)
(0x1 << AES_HASH_CRYPTO_CTRL_REG_CRYPTO_ALG_Pos));
break;
default:
return -EINVAL;
return -ENOTSUP;
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions drivers/crypto/crypto_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ static int crypto_stm32_session_setup(const struct device *dev,

if (ctx->flags & ~(CRYP_SUPPORT)) {
LOG_ERR("Unsupported flag");
return -EINVAL;
return -ENOTSUP;
}

if (algo != CRYPTO_CIPHER_ALGO_AES) {
LOG_ERR("Unsupported algo");
return -EINVAL;
return -ENOTSUP;
}

/* The CRYP peripheral supports the AES ECB, CBC, CTR, CCM and GCM
Expand All @@ -356,7 +356,7 @@ static int crypto_stm32_session_setup(const struct device *dev,
(mode != CRYPTO_CIPHER_MODE_CBC) &&
(mode != CRYPTO_CIPHER_MODE_CTR)) {
LOG_ERR("Unsupported mode");
return -EINVAL;
return -ENOTSUP;
}

/* The STM32F4 CRYP peripheral supports key sizes of 128, 192 and 256
Expand All @@ -368,7 +368,7 @@ static int crypto_stm32_session_setup(const struct device *dev,
#endif
(ctx->keylen != 32U)) {
LOG_ERR("%u key size is not supported", ctx->keylen);
return -EINVAL;
return -ENOTSUP;
}

ctx_idx = crypto_stm32_get_unused_session_index(dev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/crypto/crypto_stm32_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int stm32_hash_handler(struct hash_ctx *ctx, struct hash_pkt *pkt, bool f
default:
k_sem_give(&data->device_sem);
LOG_ERR("Unsupported algorithm in handler: %d", session->algo);
return -EINVAL;
return -ENOTSUP;
}

k_sem_give(&data->device_sem);
Expand All @@ -98,7 +98,7 @@ static int stm32_hash_begin_session(const struct device *dev, struct hash_ctx *c
break;
default:
LOG_ERR("Unsupported hash algorithm: %d", algo);
return -EINVAL;
return -ENOTSUP;
}

ctx_idx = crypto_stm32_hash_get_unused_session_index(dev);
Expand Down
8 changes: 8 additions & 0 deletions tests/crypto/crypto_aes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(crypto_hash)

target_sources(app PRIVATE src/main.c)
9 changes: 9 additions & 0 deletions tests/crypto/crypto_aes/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_ZTEST_STACK_SIZE=4096
CONFIG_ZTEST=y
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y

CONFIG_MAIN_STACK_SIZE=4096

CONFIG_CRYPTO=y
CONFIG_CRYPTO_LOG_LEVEL_DBG=y
8 changes: 8 additions & 0 deletions tests/crypto/crypto_aes/prj_mtls_shim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_HEAP_SIZE=512
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
CONFIG_MBEDTLS_CIPHER_GCM_ENABLED=y

CONFIG_CRYPTO_MBEDTLS_SHIM=y
Loading