Commit e7c2422a authored by Herbert Xu's avatar Herbert Xu

crypto: ansi_cprng - Convert to new rng interface

This patch ocnverts the ANSI CPRNG implementation to the new
low-level rng interface.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
parent 6f7e3caa
...@@ -279,11 +279,11 @@ static void free_prng_context(struct prng_context *ctx) ...@@ -279,11 +279,11 @@ static void free_prng_context(struct prng_context *ctx)
} }
static int reset_prng_context(struct prng_context *ctx, static int reset_prng_context(struct prng_context *ctx,
unsigned char *key, size_t klen, const unsigned char *key, size_t klen,
unsigned char *V, unsigned char *DT) const unsigned char *V, const unsigned char *DT)
{ {
int ret; int ret;
unsigned char *prng_key; const unsigned char *prng_key;
spin_lock_bh(&ctx->prng_lock); spin_lock_bh(&ctx->prng_lock);
ctx->flags |= PRNG_NEED_RESET; ctx->flags |= PRNG_NEED_RESET;
...@@ -351,8 +351,9 @@ static void cprng_exit(struct crypto_tfm *tfm) ...@@ -351,8 +351,9 @@ static void cprng_exit(struct crypto_tfm *tfm)
free_prng_context(crypto_tfm_ctx(tfm)); free_prng_context(crypto_tfm_ctx(tfm));
} }
static int cprng_get_random(struct crypto_rng *tfm, u8 *rdata, static int cprng_get_random(struct crypto_rng *tfm,
unsigned int dlen) const u8 *src, unsigned int slen,
u8 *rdata, unsigned int dlen)
{ {
struct prng_context *prng = crypto_rng_ctx(tfm); struct prng_context *prng = crypto_rng_ctx(tfm);
...@@ -365,11 +366,12 @@ static int cprng_get_random(struct crypto_rng *tfm, u8 *rdata, ...@@ -365,11 +366,12 @@ static int cprng_get_random(struct crypto_rng *tfm, u8 *rdata,
* V and KEY are required during reset, and DT is optional, detected * V and KEY are required during reset, and DT is optional, detected
* as being present by testing the length of the seed * as being present by testing the length of the seed
*/ */
static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) static int cprng_reset(struct crypto_rng *tfm,
const u8 *seed, unsigned int slen)
{ {
struct prng_context *prng = crypto_rng_ctx(tfm); struct prng_context *prng = crypto_rng_ctx(tfm);
u8 *key = seed + DEFAULT_BLK_SZ; const u8 *key = seed + DEFAULT_BLK_SZ;
u8 *dt = NULL; const u8 *dt = NULL;
if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ) if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ)
return -EINVAL; return -EINVAL;
...@@ -385,18 +387,20 @@ static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) ...@@ -385,18 +387,20 @@ static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
} }
#ifdef CONFIG_CRYPTO_FIPS #ifdef CONFIG_CRYPTO_FIPS
static int fips_cprng_get_random(struct crypto_rng *tfm, u8 *rdata, static int fips_cprng_get_random(struct crypto_rng *tfm,
unsigned int dlen) const u8 *src, unsigned int slen,
u8 *rdata, unsigned int dlen)
{ {
struct prng_context *prng = crypto_rng_ctx(tfm); struct prng_context *prng = crypto_rng_ctx(tfm);
return get_prng_bytes(rdata, dlen, prng, 1); return get_prng_bytes(rdata, dlen, prng, 1);
} }
static int fips_cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) static int fips_cprng_reset(struct crypto_rng *tfm,
const u8 *seed, unsigned int slen)
{ {
u8 rdata[DEFAULT_BLK_SZ]; u8 rdata[DEFAULT_BLK_SZ];
u8 *key = seed + DEFAULT_BLK_SZ; const u8 *key = seed + DEFAULT_BLK_SZ;
int rc; int rc;
struct prng_context *prng = crypto_rng_ctx(tfm); struct prng_context *prng = crypto_rng_ctx(tfm);
...@@ -422,40 +426,32 @@ static int fips_cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) ...@@ -422,40 +426,32 @@ static int fips_cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
} }
#endif #endif
static struct crypto_alg rng_algs[] = { { static struct rng_alg rng_algs[] = { {
.generate = cprng_get_random,
.seed = cprng_reset,
.seedsize = DEFAULT_PRNG_KSZ + 2 * DEFAULT_BLK_SZ,
.base = {
.cra_name = "stdrng", .cra_name = "stdrng",
.cra_driver_name = "ansi_cprng", .cra_driver_name = "ansi_cprng",
.cra_priority = 100, .cra_priority = 100,
.cra_flags = CRYPTO_ALG_TYPE_RNG,
.cra_ctxsize = sizeof(struct prng_context), .cra_ctxsize = sizeof(struct prng_context),
.cra_type = &crypto_rng_type,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_init = cprng_init, .cra_init = cprng_init,
.cra_exit = cprng_exit, .cra_exit = cprng_exit,
.cra_u = {
.rng = {
.rng_make_random = cprng_get_random,
.rng_reset = cprng_reset,
.seedsize = DEFAULT_PRNG_KSZ + 2*DEFAULT_BLK_SZ,
}
} }
#ifdef CONFIG_CRYPTO_FIPS #ifdef CONFIG_CRYPTO_FIPS
}, { }, {
.generate = fips_cprng_get_random,
.seed = fips_cprng_reset,
.seedsize = DEFAULT_PRNG_KSZ + 2 * DEFAULT_BLK_SZ,
.base = {
.cra_name = "fips(ansi_cprng)", .cra_name = "fips(ansi_cprng)",
.cra_driver_name = "fips_ansi_cprng", .cra_driver_name = "fips_ansi_cprng",
.cra_priority = 300, .cra_priority = 300,
.cra_flags = CRYPTO_ALG_TYPE_RNG,
.cra_ctxsize = sizeof(struct prng_context), .cra_ctxsize = sizeof(struct prng_context),
.cra_type = &crypto_rng_type,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_init = cprng_init, .cra_init = cprng_init,
.cra_exit = cprng_exit, .cra_exit = cprng_exit,
.cra_u = {
.rng = {
.rng_make_random = fips_cprng_get_random,
.rng_reset = fips_cprng_reset,
.seedsize = DEFAULT_PRNG_KSZ + 2*DEFAULT_BLK_SZ,
}
} }
#endif #endif
} }; } };
...@@ -463,12 +459,12 @@ static struct crypto_alg rng_algs[] = { { ...@@ -463,12 +459,12 @@ static struct crypto_alg rng_algs[] = { {
/* Module initalization */ /* Module initalization */
static int __init prng_mod_init(void) static int __init prng_mod_init(void)
{ {
return crypto_register_algs(rng_algs, ARRAY_SIZE(rng_algs)); return crypto_register_rngs(rng_algs, ARRAY_SIZE(rng_algs));
} }
static void __exit prng_mod_fini(void) static void __exit prng_mod_fini(void)
{ {
crypto_unregister_algs(rng_algs, ARRAY_SIZE(rng_algs)); crypto_unregister_rngs(rng_algs, ARRAY_SIZE(rng_algs));
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment