Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Juniper_rand_bytes(void *output, int size)
- {
- unsigned int remaining; // esi@6
- unsigned int index; // edi@6
- signed int size_to_copy; // ebx@7
- char *output_ptr; // ST00_4@9
- char *str; // [sp+0h] [bp-18h]@2
- if ( size <= 0 || output == 0 )
- {
- str = "FIPS ERROR: bad parameter to PRNG\n";
- LABEL_3:
- error_handler(str, 11);
- return 0;
- }
- if ( !memcmp(zeros_, prng_seed, 8) || !memcmp(zeros_, prng_key, 8) )
- {
- str = "FIPS ERROR: PRNG not initialized\n";
- goto LABEL_3;
- }
- remaining = size;
- index = 0;
- if ( size )
- {
- do
- {
- prng_generate();
- size_to_copy = 32;
- if ( remaining < 0x21 )
- size_to_copy = remaining;
- remaining -= size_to_copy;
- output_ptr = (char *)output + index;
- index += size_to_copy;
- memcpy(output_ptr, prng_output_buffer, size_to_copy);
- }
- while ( size > index );
- }
- return 1;
- }
- void prng_generate()
- {
- int index; // eax@4
- unsigned int bytes_generated; // ebx@4
- int v2; // eax@9
- int v3; // eax@12
- char v4; // ST04_1@12
- int time[2]; // [sp+10h] [bp-10h]@1
- time[0] = 0;
- time[1] = get_cycles();
- prng_output_index = 0;
- ++blocks_generated_since_reseed;
- if ( !do_not_need_to_reseed() )
- prng_reseed();
- for ( ; (unsigned int)prng_output_index <= 0x1F; prng_output_index += 8 )
- {
- memcpy(prev_prng_seed, prng_seed, 8);
- memcpy(prev_prng_block, prng_block, 8);
- ANSI_X9_31_generate_block(time, prng_seed, prng_key, prng_block);
- if ( sub_561A30(0) && (!memcmp(prng_seed, prev_prng_seed, 8) || !memcmp(prng_block, prev_prng_block, 8)) )
- {
- v3 = sub_92D6F0();
- sub_39E2C0(0, 6, v3, "FIPS ERROR: PRNG failure, duplicate random output\n", SLOBYTE(time[0]));
- sub_65EDD0(67375118, v4);
- error_handler("FIPS ERROR: PRNG failure, duplicate random output\n", 11);
- }
- index = prng_output_index;
- bytes_generated = 0;
- if ( prng_output_index )
- {
- do
- {
- if ( !memcmp(&prng_output_buffer[bytes_generated], prng_block, 8) )
- {
- v2 = sub_92D6F0();
- sub_39E2C0(0, 6, v2, "FIPS ERROR: PRNG failure, duplicate random output\n", SLOBYTE(time[0]));
- error_handler("FIPS ERROR: PRNG failure, duplicate random output\n", 11);
- }
- index = prng_output_index;
- bytes_generated += 8;
- }
- while ( prng_output_index > bytes_generated );
- }
- memcpy(&prng_output_buffer[index], prng_block, 8);
- }
- }
- void prng_reseed(void)
- {
- blocks_generated_since_reseed = 0;
- if ( dualec_generate(prng_output_buffer, 32) != 32 )
- error_handler("FIPS ERROR: PRNG failure, unable to reseed\n", 11);
- memcpy(prng_seed, prng_output_buffer, 8);
- prng_output_index = 8;
- memcpy(prng_key, &prng_output_buffer[8], 24);
- prng_output_index = 32;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement