2008-08-14 12:15:52 +00:00
|
|
|
/*
|
|
|
|
* RNG implementation using standard kernel RNG.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <crypto/internal/rng.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
|
2015-04-21 02:46:45 +00:00
|
|
|
static int krng_generate(struct crypto_rng *tfm,
|
|
|
|
const u8 *src, unsigned int slen,
|
|
|
|
u8 *rdata, unsigned int dlen)
|
2008-08-14 12:15:52 +00:00
|
|
|
{
|
|
|
|
get_random_bytes(rdata, dlen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:46:45 +00:00
|
|
|
static int krng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
|
2008-08-14 12:15:52 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:46:45 +00:00
|
|
|
static struct rng_alg krng_alg = {
|
|
|
|
.generate = krng_generate,
|
|
|
|
.seed = krng_seed,
|
|
|
|
.base = {
|
|
|
|
.cra_name = "stdrng",
|
|
|
|
.cra_driver_name = "krng",
|
|
|
|
.cra_priority = 200,
|
|
|
|
.cra_module = THIS_MODULE,
|
2008-08-14 12:15:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Module initalization */
|
|
|
|
static int __init krng_mod_init(void)
|
|
|
|
{
|
2015-04-21 02:46:45 +00:00
|
|
|
return crypto_register_rng(&krng_alg);
|
2008-08-14 12:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit krng_mod_fini(void)
|
|
|
|
{
|
2015-04-21 02:46:45 +00:00
|
|
|
crypto_unregister_rng(&krng_alg);
|
2008-08-14 12:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(krng_mod_init);
|
|
|
|
module_exit(krng_mod_fini);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Kernel Random Number Generator");
|
2014-11-21 01:05:53 +00:00
|
|
|
MODULE_ALIAS_CRYPTO("stdrng");
|
2015-01-11 17:17:42 +00:00
|
|
|
MODULE_ALIAS_CRYPTO("krng");
|