Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

entropy_sample.c 1.8KB

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