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

crypto: kpp - assume key is already set in maxsize

As of now, crypto_kpp_maxsize() can not be reached without successfully
setting the key for the transformation. kpp 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.
kpp 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
c444b8da ee34e264

+6 -5
+6 -5
include/crypto/kpp.h
··· 79 79 int (*generate_public_key)(struct kpp_request *req); 80 80 int (*compute_shared_secret)(struct kpp_request *req); 81 81 82 - int (*max_size)(struct crypto_kpp *tfm); 82 + unsigned int (*max_size)(struct crypto_kpp *tfm); 83 83 84 84 int (*init)(struct crypto_kpp *tfm); 85 85 void (*exit)(struct crypto_kpp *tfm); ··· 323 323 /** 324 324 * crypto_kpp_maxsize() - Get len for output buffer 325 325 * 326 - * Function returns the output buffer size required 326 + * Function returns the output buffer size required for a given key. 327 + * Function assumes that the key is already set in the transformation. If this 328 + * function is called without a setkey or with a failed setkey, you will end up 329 + * in a NULL dereference. 327 330 * 328 331 * @tfm: KPP tfm handle allocated with crypto_alloc_kpp() 329 - * 330 - * Return: minimum len for output buffer or error code if key hasn't been set 331 332 */ 332 - static inline int crypto_kpp_maxsize(struct crypto_kpp *tfm) 333 + static inline unsigned int crypto_kpp_maxsize(struct crypto_kpp *tfm) 333 334 { 334 335 struct kpp_alg *alg = crypto_kpp_alg(tfm); 335 336