Skip to content

Commit 8ac1b9c

Browse files
Sivaprakash Murugesanherbertx
authored andcommitted
crypto: qce - support zero length test vectors
crypto test module passes zero length vectors as test input to sha-1 and sha-256. To provide correct output for these vectors, hash zero support has been added as in other crypto drivers. Signed-off-by: Sivaprakash Murugesan <sivaprak@codeaurora.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5c3a8a6 commit 8ac1b9c

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎drivers/crypto/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ config CRYPTO_DEV_QCE_SKCIPHER
624624
config CRYPTO_DEV_QCE_SHA
625625
bool
626626
depends on CRYPTO_DEV_QCE
627+
select CRYPTO_SHA1
628+
select CRYPTO_SHA256
627629

628630
choice
629631
prompt "Algorithms enabled for QCE acceleration"

‎drivers/crypto/qce/common.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct qce_alg_template {
8787
struct ahash_alg ahash;
8888
} alg;
8989
struct qce_device *qce;
90+
const u8 *hash_zero;
91+
const u32 digest_size;
9092
};
9193

9294
void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);

‎drivers/crypto/qce/sha.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,12 @@ static int qce_ahash_final(struct ahash_request *req)
305305
struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
306306
struct qce_device *qce = tmpl->qce;
307307

308-
if (!rctx->buflen)
308+
if (!rctx->buflen) {
309+
if (tmpl->hash_zero)
310+
memcpy(req->result, tmpl->hash_zero,
311+
tmpl->alg.ahash.halg.digestsize);
309312
return 0;
313+
}
310314

311315
rctx->last_blk = true;
312316

@@ -338,6 +342,13 @@ static int qce_ahash_digest(struct ahash_request *req)
338342
rctx->first_blk = true;
339343
rctx->last_blk = true;
340344

345+
if (!rctx->nbytes_orig) {
346+
if (tmpl->hash_zero)
347+
memcpy(req->result, tmpl->hash_zero,
348+
tmpl->alg.ahash.halg.digestsize);
349+
return 0;
350+
}
351+
341352
return qce->async_req_enqueue(tmpl->qce, &req->base);
342353
}
343354

@@ -490,6 +501,11 @@ static int qce_ahash_register_one(const struct qce_ahash_def *def,
490501
alg->halg.digestsize = def->digestsize;
491502
alg->halg.statesize = def->statesize;
492503

504+
if (IS_SHA1(def->flags))
505+
tmpl->hash_zero = sha1_zero_message_hash;
506+
else if (IS_SHA256(def->flags))
507+
tmpl->hash_zero = sha256_zero_message_hash;
508+
493509
base = &alg->halg.base;
494510
base->cra_blocksize = def->blocksize;
495511
base->cra_priority = 300;

0 commit comments

Comments
 (0)