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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. /** @file
  20. *
  21. * Cryptographically strong random number generator
  22. *
  23. * Currently the cryptographic part is not implemented, and this just
  24. * uses random().
  25. */
  26. #include <gpxe/crypto.h>
  27. #include <stdlib.h>
  28. /**
  29. * Get cryptographically strong random bytes
  30. *
  31. * @v buf Buffer in which to store random bytes
  32. * @v len Number of random bytes to generate
  33. *
  34. * @b WARNING: This function is currently underimplemented, and does
  35. * not give numbers any stronger than random()!
  36. */
  37. void get_random_bytes ( void *buf, size_t len )
  38. {
  39. u8 *bufp = buf;
  40. /*
  41. * Somewhat arbitrarily, choose the 0x00FF0000-masked byte
  42. * returned by random() as having good entropy. PRNGs often
  43. * don't provide good entropy in lower bits, and the top byte
  44. * might show a pattern because of sign issues.
  45. */
  46. while ( len-- ) {
  47. *bufp++ = ( random() >> 16 ) & 0xFF;
  48. }
  49. }