Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * RBG mechanism
  27. *
  28. * This mechanism is designed to comply with ANS X9.82 Part 4 (April
  29. * 2011 Draft) Section 10. This standard is unfortunately not freely
  30. * available.
  31. *
  32. * The chosen RBG design is that of a DRBG with a live entropy source
  33. * with no conditioning function. Only a single security strength is
  34. * supported. No seedfile is used since there may be no non-volatile
  35. * storage available. The system UUID is used as the personalisation
  36. * string.
  37. */
  38. #include <stdint.h>
  39. #include <string.h>
  40. #include <ipxe/init.h>
  41. #include <ipxe/settings.h>
  42. #include <ipxe/uuid.h>
  43. #include <ipxe/crypto.h>
  44. #include <ipxe/drbg.h>
  45. #include <ipxe/rbg.h>
  46. /** The RBG */
  47. struct random_bit_generator rbg;
  48. /**
  49. * Start up RBG
  50. *
  51. * @ret rc Return status code
  52. *
  53. * This is the RBG_Startup function defined in ANS X9.82 Part 4 (April
  54. * 2011 Draft) Section 9.1.2.2.
  55. */
  56. static int rbg_startup ( void ) {
  57. union uuid uuid;
  58. int len;
  59. int rc;
  60. /* Try to obtain system UUID for use as personalisation
  61. * string, in accordance with ANS X9.82 Part 3-2007 Section
  62. * 8.5.2. If no UUID is available, proceed without a
  63. * personalisation string.
  64. */
  65. if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
  66. rc = len;
  67. DBGC ( &rbg, "RBG could not fetch personalisation string: "
  68. "%s\n", strerror ( rc ) );
  69. len = 0;
  70. }
  71. /* Instantiate DRBG */
  72. if ( ( rc = drbg_instantiate ( &rbg.state, &uuid, len ) ) != 0 ) {
  73. DBGC ( &rbg, "RBG could not instantiate DRBG: %s\n",
  74. strerror ( rc ) );
  75. return rc;
  76. }
  77. return 0;
  78. }
  79. /**
  80. * Shut down RBG
  81. *
  82. */
  83. static void rbg_shutdown ( void ) {
  84. /* Uninstantiate DRBG */
  85. drbg_uninstantiate ( &rbg.state );
  86. }
  87. /** RBG startup function */
  88. static void rbg_startup_fn ( void ) {
  89. /* Start up RBG. There is no way to report an error at this
  90. * stage, but a failed startup will result in an invalid DRBG
  91. * that refuses to generate bits.
  92. */
  93. rbg_startup();
  94. }
  95. /** RBG shutdown function */
  96. static void rbg_shutdown_fn ( int booting __unused ) {
  97. /* Shut down RBG */
  98. rbg_shutdown();
  99. }
  100. /** RBG startup table entry */
  101. struct startup_fn startup_rbg __startup_fn ( STARTUP_NORMAL ) = {
  102. .startup = rbg_startup_fn,
  103. .shutdown = rbg_shutdown_fn,
  104. };