aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2015-03-06 02:26:31 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2015-03-09 06:06:18 -0400
commitcde001e4c3c3625c60b68a83eb1f1c2572dee07a (patch)
tree6b0a069f9fdfa36c3741164564ea163f9cb69820
parent4842234f83bfce83c93f84f5972a956ef2c87805 (diff)
crypto: rng - RNGs must return 0 in success case
Change the RNGs to always return 0 in success case. This patch ensures that seqiv.c works with RNGs other than krng. seqiv expects that any return code other than 0 is an error. Without the patch, rfc4106(gcm(aes)) will not work when using a DRBG or an ANSI X9.31 RNG. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/ansi_cprng.c6
-rw-r--r--crypto/drbg.c7
-rw-r--r--include/crypto/rng.h3
3 files changed, 12 insertions, 4 deletions
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 6f5bebc9bf01..765fe7609348 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -210,7 +210,11 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx,
210 byte_count = DEFAULT_BLK_SZ; 210 byte_count = DEFAULT_BLK_SZ;
211 } 211 }
212 212
213 err = byte_count; 213 /*
214 * Return 0 in case of success as mandated by the kernel
215 * crypto API interface definition.
216 */
217 err = 0;
214 218
215 dbgprint(KERN_CRIT "getting %d random bytes for context %p\n", 219 dbgprint(KERN_CRIT "getting %d random bytes for context %p\n",
216 byte_count, ctx); 220 byte_count, ctx);
diff --git a/crypto/drbg.c b/crypto/drbg.c
index 56c1d7ec3d9e..b69409cb7e6a 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1280,7 +1280,7 @@ static void drbg_restore_shadow(struct drbg_state *drbg,
1280 * as defined in SP800-90A. The additional input is mixed into 1280 * as defined in SP800-90A. The additional input is mixed into
1281 * the state in addition to the pulled entropy. 1281 * the state in addition to the pulled entropy.
1282 * 1282 *
1283 * return: generated number of bytes 1283 * return: 0 when all bytes are generated; < 0 in case of an error
1284 */ 1284 */
1285static int drbg_generate(struct drbg_state *drbg, 1285static int drbg_generate(struct drbg_state *drbg,
1286 unsigned char *buf, unsigned int buflen, 1286 unsigned char *buf, unsigned int buflen,
@@ -1419,6 +1419,11 @@ static int drbg_generate(struct drbg_state *drbg,
1419 } 1419 }
1420#endif 1420#endif
1421 1421
1422 /*
1423 * All operations were successful, return 0 as mandated by
1424 * the kernel crypto API interface.
1425 */
1426 len = 0;
1422err: 1427err:
1423 shadow->d_ops->crypto_fini(shadow); 1428 shadow->d_ops->crypto_fini(shadow);
1424 drbg_restore_shadow(drbg, &shadow); 1429 drbg_restore_shadow(drbg, &shadow);
diff --git a/include/crypto/rng.h b/include/crypto/rng.h
index a16fb10142bf..6e28ea5be9f1 100644
--- a/include/crypto/rng.h
+++ b/include/crypto/rng.h
@@ -103,8 +103,7 @@ static inline void crypto_free_rng(struct crypto_rng *tfm)
103 * This function fills the caller-allocated buffer with random numbers using the 103 * This function fills the caller-allocated buffer with random numbers using the
104 * random number generator referenced by the cipher handle. 104 * random number generator referenced by the cipher handle.
105 * 105 *
106 * Return: > 0 function was successful and returns the number of generated 106 * Return: 0 function was successful; < 0 if an error occurred
107 * bytes; < 0 if an error occurred
108 */ 107 */
109static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, 108static inline int crypto_rng_get_bytes(struct crypto_rng *tfm,
110 u8 *rdata, unsigned int dlen) 109 u8 *rdata, unsigned int dlen)