Skip to content

Commit d955e21

Browse files
Eric Biggersgregkh
authored andcommitted
crypto: drbg - Fix drbg_max_addtl() on 64-bit kernels
commit 6f49f00 upstream. On 64-bit kernels, drbg_max_addtl() returns 2**35 bytes. That's too large, for two reasons: 1. SP800-90A says the maximum limit is 2**35 *bits*, not 2**35 bytes. So the implemented limit has confused bits and bytes. 2. When drbg_kcapi_hash() calls crypto_shash_update() on the additional information string, the length is implicitly cast to 'unsigned int'. That truncates the additional information string to U32_MAX bytes. Fix the maximum additional information string length to always be U32_MAX - 1, causing an error to be returned for any longer lengths. Fixes: 541af94 ("crypto: drbg - SP800-90A Deterministic Random Bit Generator") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cc42fb4 commit d955e21

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

include/crypto/drbg.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,15 @@ static inline size_t drbg_max_request_bytes(struct drbg_state *drbg)
171171
return (1 << 16);
172172
}
173173

174+
/*
175+
* SP800-90A allows implementations to support additional info / personalization
176+
* strings of up to 2**35 bits. Implementations can have a smaller maximum. We
177+
* use 2**35 - 16 bits == U32_MAX - 1 bytes so that the max + 1 always fits in a
178+
* size_t, allowing drbg_healthcheck_sanity() to verify its enforcement.
179+
*/
174180
static inline size_t drbg_max_addtl(struct drbg_state *drbg)
175181
{
176-
/* SP800-90A requires 2**35 bytes additional info str / pers str */
177-
#if (__BITS_PER_LONG == 32)
178-
/*
179-
* SP800-90A allows smaller maximum numbers to be returned -- we
180-
* return SIZE_MAX - 1 to allow the verification of the enforcement
181-
* of this value in drbg_healthcheck_sanity.
182-
*/
183-
return (SIZE_MAX - 1);
184-
#else
185-
return (1UL<<35);
186-
#endif
182+
return U32_MAX - 1;
187183
}
188184

189185
static inline size_t drbg_max_requests(struct drbg_state *drbg)

0 commit comments

Comments
 (0)