You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

entropy_sample.c 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. /** @file
  20. *
  21. * Entropy sampling
  22. *
  23. */
  24. #include <stdio.h>
  25. #include <ipxe/entropy.h>
  26. #include <ipxe/test.h>
  27. /** Total number of test samples */
  28. #define SAMPLE_COUNT 65536
  29. /** Number of samples per block */
  30. #define SAMPLE_BLOCKSIZE 256
  31. /**
  32. * Generate entropy samples for external testing
  33. *
  34. */
  35. static void entropy_sample_test_exec ( void ) {
  36. static noise_sample_t samples[SAMPLE_BLOCKSIZE];
  37. unsigned int i;
  38. unsigned int j;
  39. int rc;
  40. /* Collect and print blocks of samples */
  41. for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) {
  42. /* Collect one block of samples */
  43. rc = entropy_enable();
  44. ok ( rc == 0 );
  45. for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
  46. rc = get_noise ( &samples[j] );
  47. ok ( rc == 0 );
  48. }
  49. entropy_disable();
  50. /* Print out sample values */
  51. for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
  52. printf ( "SAMPLE %d %d\n", ( i * SAMPLE_BLOCKSIZE + j ),
  53. samples[j] );
  54. }
  55. }
  56. }
  57. /** Entropy sampling self-test */
  58. struct self_test entropy_sample_test __self_test = {
  59. .name = "entropy_sample",
  60. .exec = entropy_sample_test_exec,
  61. };