Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: akcipher - assume key is already set in maxsize

As of now, crypto_akcipher_maxsize() can not be reached without
successfully setting the key for the transformation. akcipher
algorithm implementations check if the key was set and then return
the output buffer size required for the given key.

Change the return type to unsigned int and always assume that this
function is called after a successful setkey of the transformation.
akcipher algorithm implementations will remove the check if key is not NULL
and directly return the max size.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tudor-Dan Ambarus and committed by
Herbert Xu
561f8e2d 85ac98cb

+6 -5
+6 -5
include/crypto/akcipher.h
··· 98 98 unsigned int keylen); 99 99 int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key, 100 100 unsigned int keylen); 101 - int (*max_size)(struct crypto_akcipher *tfm); 101 + unsigned int (*max_size)(struct crypto_akcipher *tfm); 102 102 int (*init)(struct crypto_akcipher *tfm); 103 103 void (*exit)(struct crypto_akcipher *tfm); 104 104 ··· 257 257 /** 258 258 * crypto_akcipher_maxsize() - Get len for output buffer 259 259 * 260 - * Function returns the dest buffer size required for a given key 260 + * Function returns the dest buffer size required for a given key. 261 + * Function assumes that the key is already set in the transformation. If this 262 + * function is called without a setkey or with a failed setkey, you will end up 263 + * in a NULL dereference. 261 264 * 262 265 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() 263 - * 264 - * Return: minimum len for output buffer or error code in key hasn't been set 265 266 */ 266 - static inline int crypto_akcipher_maxsize(struct crypto_akcipher *tfm) 267 + static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm) 267 268 { 268 269 struct akcipher_alg *alg = crypto_akcipher_alg(tfm); 269 270