Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <inttypes.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7.  
  8. #include "argon2.h"
  9. #include "\Dima\Old Projects and Texts\Argon2\phc\src\core.h"
  10. #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blake2.h"
  11. #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blake2-impl.h"
  12. #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blamka-round-ref.h"
  13.  
  14. void fill_block(const block *prev_block, const block *ref_block,
  15. block *next_block, int with_xor);
  16.  
  17. #define R_SIZE 8
  18. #define X_SIZE 8
  19.  
  20. void test_freq()
  21. {
  22. FILE* fp = fopen("freq.log", "w+");
  23. uint64_t tests = 1 << 16;
  24. uint32_t Y_seed[2];
  25. Y_seed[0] = Y_seed[1] = 0;
  26. uint32_t X_seed[2];
  27. X_seed[0] = X_seed[1] = 0;
  28.  
  29. uint32_t freqs[R_SIZE*R_SIZE*X_SIZE];
  30. memset(freqs, 0, sizeof(uint32_t)*R_SIZE*R_SIZE*X_SIZE);
  31. block Y_block, X_block, Z_block;
  32.  
  33. for (unsigned i = 0; i<tests; ++i)
  34. {
  35. //Select random Y
  36. Y_seed[1] = i & 0xFFFFFFFF;
  37. Y_seed[0] = i >> 32;
  38. blake2b_long(&Y_block, ARGON2_BLOCK_SIZE, Y_seed, 8);
  39.  
  40. //Select random X
  41. X_seed[1] = i & 0xFFFFFFFF;
  42. X_seed[0] = (i >> 32) + (1 << 16);
  43. blake2b_long(&X_block, ARGON2_BLOCK_SIZE, X_seed, 8);
  44.  
  45. //Generate Z
  46. fill_block(&Y_block, &X_block, &Z_block, 0);
  47.  
  48. // Compute (r,r') and put FREQ[r,r',x]++;
  49. uint64_t r = Y_block.v[0]%R_SIZE;
  50. uint64_t r2 = Z_block.v[0] % R_SIZE;
  51. uint64_t x = X_block.v[0] % X_SIZE;
  52. freqs[r*(X_SIZE*R_SIZE) + r2*X_SIZE + x]++;
  53. }
  54.  
  55. //Print results
  56. for (unsigned i1 = 0; i1 < R_SIZE; i1++) {
  57. fprintf(fp,"R1: %d\n", i1);
  58. for (unsigned i2 = 0; i2 < R_SIZE; i2++) {
  59. fprintf(fp,"R2: %d\n", i2);
  60. uint64_t total = 0;
  61. for (unsigned i4 = 0; i4 < X_SIZE; i4++) {
  62. total += freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i4];
  63. }
  64. for (unsigned i3 = 0; i3 < X_SIZE; i3++) {
  65.  
  66. double part = (double)freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i3] / total;
  67. double dev = ((double)freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i3] - total/X_SIZE) / pow(total / X_SIZE, 0.5);
  68. fprintf(fp,"X %d, FREQ: %d PART: %2.2f DEV: %3.2f\n", i3, freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i3],part,dev);
  69. }
  70. }
  71. }
  72. fprintf(fp,"STOP");
  73.  
  74. }
  75.  
  76. int main() {
  77. test_freq();
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement