krng.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * RNG implementation using standard kernel RNG.
  3. *
  4. * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * any later version.
  10. *
  11. */
  12. #include <crypto/internal/rng.h>
  13. #include <linux/err.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/random.h>
  17. static int krng_get_random(struct crypto_rng *tfm, u8 *rdata, unsigned int dlen)
  18. {
  19. get_random_bytes(rdata, dlen);
  20. return 0;
  21. }
  22. static int krng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
  23. {
  24. return 0;
  25. }
  26. static struct crypto_alg krng_alg = {
  27. .cra_name = "stdrng",
  28. .cra_driver_name = "krng",
  29. .cra_priority = 200,
  30. .cra_flags = CRYPTO_ALG_TYPE_RNG,
  31. .cra_ctxsize = 0,
  32. .cra_type = &crypto_rng_type,
  33. .cra_module = THIS_MODULE,
  34. .cra_list = LIST_HEAD_INIT(krng_alg.cra_list),
  35. .cra_u = {
  36. .rng = {
  37. .rng_make_random = krng_get_random,
  38. .rng_reset = krng_reset,
  39. .seedsize = 0,
  40. }
  41. }
  42. };
  43. /* Module initalization */
  44. static int __init krng_mod_init(void)
  45. {
  46. return crypto_register_alg(&krng_alg);
  47. }
  48. static void __exit krng_mod_fini(void)
  49. {
  50. crypto_unregister_alg(&krng_alg);
  51. return;
  52. }
  53. module_init(krng_mod_init);
  54. module_exit(krng_mod_fini);
  55. MODULE_LICENSE("GPL");
  56. MODULE_DESCRIPTION("Kernel Random Number Generator");
  57. MODULE_ALIAS("stdrng");