Skip to content

Commit 4b4332a

Browse files
sylvioalvesjhedberg
authored andcommitted
drivers: crypto: return -ENOTSUP when needed
Make sure all crypto driver returns proper error when feature is not supported. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 8ed51c0 commit 4b4332a

12 files changed

+36
-36
lines changed

drivers/crypto/crypto_ataes132a.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ static int do_ccm_encrypt_mac(struct cipher_ctx *ctx,
713713

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

719719
ataes132a_aes_ccm_encrypt(dev, key_id, &mac_mode,
@@ -758,7 +758,7 @@ static int do_ccm_decrypt_auth(struct cipher_ctx *ctx,
758758

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

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

836836
if (algo != CRYPTO_CIPHER_ALGO_AES) {
837837
LOG_ERR("ATAES132A unsupported algorithm");
838-
return -EINVAL;
838+
return -ENOTSUP;
839839
}
840840

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

847847
if (ctx->keylen != ATAES132A_AES_KEY_SIZE) {
848848
LOG_ERR("ATAES132A unsupported key size");
849-
return -EINVAL;
849+
return -ENOTSUP;
850850
}
851851

852852
if (op_type == CRYPTO_CIPHER_OP_ENCRYPT) {
@@ -859,7 +859,7 @@ static int ataes132a_session_setup(const struct device *dev,
859859
break;
860860
default:
861861
LOG_ERR("ATAES132A unsupported mode");
862-
return -EINVAL;
862+
return -ENOTSUP;
863863
}
864864
} else {
865865
switch (mode) {
@@ -871,7 +871,7 @@ static int ataes132a_session_setup(const struct device *dev,
871871
break;
872872
default:
873873
LOG_ERR("ATAES132A unsupported mode");
874-
return -EINVAL;
874+
return -ENOTSUP;
875875
}
876876
}
877877

drivers/crypto/crypto_cc23x0.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -985,24 +985,24 @@ static int crypto_cc23x0_session_setup(const struct device *dev,
985985
{
986986
if (ctx->flags & ~(CRYPTO_CC23_CAP)) {
987987
LOG_ERR("Unsupported feature");
988-
return -EINVAL;
988+
return -ENOTSUP;
989989
}
990990

991991
if (algo != CRYPTO_CIPHER_ALGO_AES) {
992992
LOG_ERR("Unsupported algo");
993-
return -EINVAL;
993+
return -ENOTSUP;
994994
}
995995

996996
if (mode != CRYPTO_CIPHER_MODE_ECB &&
997997
mode != CRYPTO_CIPHER_MODE_CTR &&
998998
mode != CRYPTO_CIPHER_MODE_CCM) {
999999
LOG_ERR("Unsupported mode");
1000-
return -EINVAL;
1000+
return -ENOTSUP;
10011001
}
10021002

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

10081008
if (!ctx->key.bit_stream) {
@@ -1022,21 +1022,21 @@ static int crypto_cc23x0_session_setup(const struct device *dev,
10221022
ctx->ops.ccm_crypt_hndlr = crypto_cc23x0_ccm_encrypt;
10231023
break;
10241024
default:
1025-
return -EINVAL;
1025+
return -ENOTSUP;
10261026
}
10271027
} else {
10281028
switch (mode) {
10291029
case CRYPTO_CIPHER_MODE_ECB:
10301030
LOG_ERR("ECB decryption not supported by the hardware");
1031-
return -EINVAL;
1031+
return -ENOTSUP;
10321032
case CRYPTO_CIPHER_MODE_CTR:
10331033
ctx->ops.ctr_crypt_hndlr = crypto_cc23x0_ctr;
10341034
break;
10351035
case CRYPTO_CIPHER_MODE_CCM:
10361036
ctx->ops.ccm_crypt_hndlr = crypto_cc23x0_ccm_decrypt;
10371037
break;
10381038
default:
1039-
return -EINVAL;
1039+
return -ENOTSUP;
10401040
}
10411041
}
10421042

drivers/crypto/crypto_it51xxx_sha.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ static int it51xxx_hash_begin_session(const struct device *dev, struct hash_ctx
238238
{
239239
if (algo != CRYPTO_HASH_ALGO_SHA256) {
240240
LOG_ERR("Unsupported algorithm");
241-
return -EINVAL;
241+
return -ENOTSUP;
242242
}
243243

244244
if (ctx->flags & ~(it51xxx_query_hw_caps(dev))) {
245245
LOG_ERR("Unsupported flag");
246-
return -EINVAL;
246+
return -ENOTSUP;
247247
}
248248

249249
it51xxx_sha256_init(true);

drivers/crypto/crypto_it8xxx2_sha.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ static int it8xxx2_hash_begin_session(const struct device *dev,
188188
{
189189
if (algo != CRYPTO_HASH_ALGO_SHA256) {
190190
LOG_ERR("Unsupported algo");
191-
return -EINVAL;
191+
return -ENOTSUP;
192192
}
193193

194194
if (ctx->flags & ~(it8xxx2_query_hw_caps(dev))) {
195195
LOG_ERR("Unsupported flag");
196-
return -EINVAL;
196+
return -ENOTSUP;
197197
}
198198

199199
it8xxx2_sha256_init(false);

drivers/crypto/crypto_it8xxx2_sha_v2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ static int it8xxx2_hash_begin_session(const struct device *dev,
308308
{
309309
if (algo != CRYPTO_HASH_ALGO_SHA256) {
310310
LOG_ERR("Unsupported algorithm");
311-
return -EINVAL;
311+
return -ENOTSUP;
312312
}
313313

314314
if (ctx->flags & ~(it8xxx2_query_hw_caps(dev))) {
315315
LOG_ERR("Unsupported flag");
316-
return -EINVAL;
316+
return -ENOTSUP;
317317
}
318318

319319
it8xxx2_sha256_init(true);

drivers/crypto/crypto_mchp_xec_symcr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ static int xec_symcr_hash_session_begin(const struct device *dev, struct hash_ct
405405

406406
if (ctx->flags & ~(MCHP_XEC_SYMCR_CAPS_SUPPORT)) {
407407
LOG_ERR("Unsupported flag");
408-
return -EINVAL;
408+
return -ENOTSUP;
409409
}
410410

411411
rom_algo = lookup_hash_alg(algo);
412412
if (rom_algo == MCHP_ROM_HASH_ALG_NONE) {
413413
LOG_ERR("Unsupported algo %d", algo);
414-
return -EINVAL;
414+
return -ENOTSUP;
415415
}
416416

417417
session_idx = mchp_xec_get_unused_session_index(data);

drivers/crypto/crypto_mtls_shim.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static int mtls_session_setup(const struct device *dev,
341341
#endif
342342
mode != CRYPTO_CIPHER_MODE_ECB) {
343343
LOG_ERR("Unsupported mode");
344-
return -EINVAL;
344+
return -ENOTSUP;
345345
}
346346

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

542542
if (ctx->flags & ~(MTLS_SUPPORT)) {
543543
LOG_ERR("Unsupported flag");
544-
return -EINVAL;
544+
return -ENOTSUP;
545545
}
546546

547547
if ((algo != CRYPTO_HASH_ALGO_SHA224) &&
548548
(algo != CRYPTO_HASH_ALGO_SHA256) &&
549549
(algo != CRYPTO_HASH_ALGO_SHA384) &&
550550
(algo != CRYPTO_HASH_ALGO_SHA512)) {
551551
LOG_ERR("Unsupported algo: %d", algo);
552-
return -EINVAL;
552+
return -ENOTSUP;
553553
}
554554

555555
ctx_idx = mtls_get_unused_session_index();

drivers/crypto/crypto_npcx_sha.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static int npcx_sha_compute(struct hash_ctx *ctx, struct hash_pkt *pkt, bool fin
9999
break;
100100
default:
101101
LOG_ERR("Unexpected algo: %d", npcx_session->algo);
102-
return -EINVAL;
102+
return -ENOTSUP;
103103
}
104104

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

141141
if (ctx->flags & ~(NPCX_HASH_CAPS_SUPPORT)) {
142142
LOG_ERR("Unsupported flag");
143-
return -EINVAL;
143+
return -ENOTSUP;
144144
}
145145

146146
if ((algo != CRYPTO_HASH_ALGO_SHA256) && (algo != CRYPTO_HASH_ALGO_SHA384) &&
147147
(algo != CRYPTO_HASH_ALGO_SHA512)) {
148148
LOG_ERR("Unsupported algo: %d", algo);
149-
return -EINVAL;
149+
return -ENOTSUP;
150150
}
151151

152152
ctx_idx = npcx_get_unused_session_index();

drivers/crypto/crypto_rts5912_sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int rts5912_hash_begin_session(const struct device *dev, struct hash_ctx
268268
rts5912_sha256_start(dev);
269269
break;
270270
default:
271-
return -EINVAL;
271+
return -ENOTSUP;
272272
}
273273

274274
return 0;

drivers/crypto/crypto_smartbond.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int crypto_smartbond_hash_set_algo(enum hash_algo algo)
384384
(0x1 << AES_HASH_CRYPTO_CTRL_REG_CRYPTO_ALG_Pos));
385385
break;
386386
default:
387-
return -EINVAL;
387+
return -ENOTSUP;
388388
}
389389

390390
return 0;

0 commit comments

Comments
 (0)