Skip to content

Commit 809778e

Browse files
atenartherbertx
authored andcommitted
crypto: inside-secure - fix hash when length is a multiple of a block
This patch fixes the hash support in the SafeXcel driver when the update size is a multiple of a block size, and when a final call is made just after with a size of 0. In such cases the driver should cache the last block from the update to avoid handling 0 length data on the final call (that's a hardware limitation). Cc: stable@vger.kernel.org Fixes: 1b44c5a ("crypto: inside-secure - add SafeXcel EIP197 crypto engine driver") Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent c957f8b commit 809778e

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

‎drivers/crypto/inside-secure/safexcel_hash.c‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,31 @@ static int safexcel_ahash_send_req(struct crypto_async_request *async, int ring,
189189
else
190190
cache_len = queued - areq->nbytes;
191191

192-
/*
193-
* If this is not the last request and the queued data does not fit
194-
* into full blocks, cache it for the next send() call.
195-
*/
196-
extra = queued & (crypto_ahash_blocksize(ahash) - 1);
197-
if (!req->last_req && extra) {
198-
sg_pcopy_to_buffer(areq->src, sg_nents(areq->src),
199-
req->cache_next, extra, areq->nbytes - extra);
192+
if (!req->last_req) {
193+
/* If this is not the last request and the queued data does not
194+
* fit into full blocks, cache it for the next send() call.
195+
*/
196+
extra = queued & (crypto_ahash_blocksize(ahash) - 1);
197+
if (!extra)
198+
/* If this is not the last request and the queued data
199+
* is a multiple of a block, cache the last one for now.
200+
*/
201+
extra = queued - crypto_ahash_blocksize(ahash);
200202

201-
queued -= extra;
202-
len -= extra;
203+
if (extra) {
204+
sg_pcopy_to_buffer(areq->src, sg_nents(areq->src),
205+
req->cache_next, extra,
206+
areq->nbytes - extra);
207+
208+
queued -= extra;
209+
len -= extra;
210+
211+
if (!queued) {
212+
*commands = 0;
213+
*results = 0;
214+
return 0;
215+
}
216+
}
203217
}
204218

205219
spin_lock_bh(&priv->ring[ring].egress_lock);

0 commit comments

Comments
 (0)