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

87 строки
2.1 KiB

  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. */
  9. #include <tomcrypt_test.h>
  10. /* Test store/load macros with offsets */
  11. int store_test(void)
  12. {
  13. unsigned char buf[256];
  14. int y;
  15. ulong32 L, L1;
  16. ulong64 LL, LL1;
  17. #ifdef LTC_FAST
  18. int x, z;
  19. #endif
  20. for (y = 0; y < 4; y++) {
  21. L = 0x12345678UL;
  22. L1 = 0;
  23. STORE32L(L, buf + y);
  24. LOAD32L(L1, buf + y);
  25. if (L1 != L) {
  26. fprintf(stderr, "\n32L failed at offset %d\n", y);
  27. return 1;
  28. }
  29. STORE32H(L, buf + y);
  30. LOAD32H(L1, buf + y);
  31. if (L1 != L) {
  32. fprintf(stderr, "\n32H failed at offset %d\n", y);
  33. return 1;
  34. }
  35. }
  36. for (y = 0; y < 8; y++) {
  37. LL = CONST64 (0x01020304050607);
  38. LL1 = 0;
  39. STORE64L(LL, buf + y);
  40. LOAD64L(LL1, buf + y);
  41. if (LL1 != LL) {
  42. fprintf(stderr, "\n64L failed at offset %d\n", y);
  43. return 1;
  44. }
  45. STORE64H(LL, buf + y);
  46. LOAD64H(LL1, buf + y);
  47. if (LL1 != LL) {
  48. fprintf(stderr, "\n64H failed at offset %d\n", y);
  49. return 1;
  50. }
  51. }
  52. /* test LTC_FAST */
  53. #ifdef LTC_FAST
  54. y = 16;
  55. for (z = 0; z < y; z++) {
  56. /* fill y bytes with random */
  57. yarrow_read(buf+z, y, &yarrow_prng);
  58. yarrow_read(buf+z+y, y, &yarrow_prng);
  59. /* now XOR it byte for byte */
  60. for (x = 0; x < y; x++) {
  61. buf[2*y+z+x] = buf[z+x] ^ buf[z+y+x];
  62. }
  63. /* now XOR it word for word */
  64. for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
  65. *(LTC_FAST_TYPE_PTR_CAST(&buf[3*y+z+x])) = *(LTC_FAST_TYPE_PTR_CAST(&buf[z+x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&buf[z+y+x]));
  66. }
  67. if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
  68. fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
  69. return 1;
  70. }
  71. }
  72. #endif
  73. return 0;
  74. }
  75. /* ref: $Format:%D$ */
  76. /* git commit: $Format:%H$ */
  77. /* commit time: $Format:%ai$ */