summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/caam/sg_sw_sec4.h
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-08 16:38:24 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-09 22:25:58 +0800
commit70c3c8a96a85d333b3ff1f24df84c0e179261a8a (patch)
tree60dfee06ecc515fa9113c1fd98b46ece0b6a7845 /drivers/crypto/caam/sg_sw_sec4.h
parentecb479d07a4e2db980965193511dbf2563d50db5 (diff)
downloadlinux-70c3c8a96a85d333b3ff1f24df84c0e179261a8a.tar.bz2
crypto: caam - Clamp AEAD SG list by input length
Currently caam assumes that the SG list contains exactly the number of bytes required. This assumption is incorrect. Up until now this has been harmless. However with the new AEAD interface this now breaks as the AD SG list contains more bytes than just the AD. This patch fixes this by always clamping the AD SG list by the specified AD length. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/caam/sg_sw_sec4.h')
-rw-r--r--drivers/crypto/caam/sg_sw_sec4.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/crypto/caam/sg_sw_sec4.h b/drivers/crypto/caam/sg_sw_sec4.h
index 3b918218aa4c..efbc1db8da53 100644
--- a/drivers/crypto/caam/sg_sw_sec4.h
+++ b/drivers/crypto/caam/sg_sw_sec4.h
@@ -55,6 +55,21 @@ static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
sec4_sg_ptr->len |= SEC4_SG_LEN_FIN;
}
+static inline struct sec4_sg_entry *sg_to_sec4_sg_len(
+ struct scatterlist *sg, unsigned int total,
+ struct sec4_sg_entry *sec4_sg_ptr)
+{
+ do {
+ unsigned int len = min(sg_dma_len(sg), total);
+
+ dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), len, 0);
+ sec4_sg_ptr++;
+ sg = sg_next(sg);
+ total -= len;
+ } while (total);
+ return sec4_sg_ptr - 1;
+}
+
/* count number of elements in scatterlist */
static inline int __sg_count(struct scatterlist *sg_list, int nbytes,
bool *chained)