Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "argon2.h"
- #include "\Dima\Old Projects and Texts\Argon2\phc\src\core.h"
- #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blake2.h"
- #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blake2-impl.h"
- #include "\Dima\Old Projects and Texts\Argon2\phc\src\blake2\blamka-round-ref.h"
- void fill_block(const block *prev_block, const block *ref_block,
- block *next_block, int with_xor);
- #define R_SIZE 8
- #define X_SIZE 8
- void test_freq()
- {
- FILE* fp = fopen("freq.log", "w+");
- uint64_t tests = 1 << 16;
- uint32_t Y_seed[2];
- Y_seed[0] = Y_seed[1] = 0;
- uint32_t X_seed[2];
- X_seed[0] = X_seed[1] = 0;
- uint32_t freqs[R_SIZE*R_SIZE*X_SIZE];
- memset(freqs, 0, sizeof(uint32_t)*R_SIZE*R_SIZE*X_SIZE);
- block Y_block, X_block, Z_block;
- for (unsigned i = 0; i<tests; ++i)
- {
- //Select random Y
- Y_seed[1] = i & 0xFFFFFFFF;
- Y_seed[0] = i >> 32;
- blake2b_long(&Y_block, ARGON2_BLOCK_SIZE, Y_seed, 8);
- //Select random X
- X_seed[1] = i & 0xFFFFFFFF;
- X_seed[0] = (i >> 32) + (1 << 16);
- blake2b_long(&X_block, ARGON2_BLOCK_SIZE, X_seed, 8);
- //Generate Z
- fill_block(&Y_block, &X_block, &Z_block, 0);
- // Compute (r,r') and put FREQ[r,r',x]++;
- uint64_t r = Y_block.v[0]%R_SIZE;
- uint64_t r2 = Z_block.v[0] % R_SIZE;
- uint64_t x = X_block.v[0] % X_SIZE;
- freqs[r*(X_SIZE*R_SIZE) + r2*X_SIZE + x]++;
- }
- //Print results
- for (unsigned i1 = 0; i1 < R_SIZE; i1++) {
- fprintf(fp,"R1: %d\n", i1);
- for (unsigned i2 = 0; i2 < R_SIZE; i2++) {
- fprintf(fp,"R2: %d\n", i2);
- uint64_t total = 0;
- for (unsigned i4 = 0; i4 < X_SIZE; i4++) {
- total += freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i4];
- }
- for (unsigned i3 = 0; i3 < X_SIZE; i3++) {
- double part = (double)freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i3] / total;
- double dev = ((double)freqs[i1*(X_SIZE*R_SIZE) + i2*X_SIZE + i3] - total/X_SIZE) / pow(total / X_SIZE, 0.5);
- 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);
- }
- }
- }
- fprintf(fp,"STOP");
- }
- int main() {
- test_freq();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement