2
0
Fork 0
mirror of https://git.sr.ht/~sircmpwn/mkproof synced 2024-06-09 00:56:07 +02:00

XOR instead of overwrite: fill_block now XORs over the new block. Signatures and generate_addresses() updated accordingly

This commit is contained in:
khovratovich 2016-02-15 14:43:32 +01:00 committed by Daniel
parent 5c840802f2
commit cffb8f1b43
5 changed files with 33 additions and 24 deletions

View File

@ -1,4 +1,4 @@
#include <stdio.h>
git ech#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -22,7 +22,7 @@ static uint64_t rdtsc(void) {
__asm__ __volatile__("rdtsc" : "=A"(rax) : :);
return rax;
#else
#error "Not implemented!"
#error "Not implemented!"git branch
#endif
#endif
}
@ -42,16 +42,16 @@ static void benchmark() {
#undef BENCH_INLEN
#undef BENCH_OUTLEN
uint32_t t_cost = 1;
uint32_t m_cost;
uint32_t thread_test[6] = {1, 2, 4, 6, 8, 16};
uint32_t t_cost = 3;
uint32_t m_cost;git
uint32_t thread_test[4] = {1, 2, 4, 8};
memset(pwd_array, 0, inlen);
memset(salt_array, 1, inlen);
for (m_cost = (uint32_t)1 << 10; m_cost <= (uint32_t)1 << 22; m_cost *= 2) {
unsigned i;
for (i = 0; i < 6; ++i) {
for (i = 0; i < 4; ++i) {
argon2_context context;
uint32_t thread_n = thread_test[i];
uint64_t stop_cycles, stop_cycles_i;

View File

@ -21,7 +21,7 @@
#include "blake2/blake2.h"
#include "blake2/blamka-round-opt.h"
void fill_block(__m128i *state, const uint8_t *ref_block, uint8_t *next_block) {
void fill_block_with_xor(__m128i *state, const uint8_t *ref_block, uint8_t *next_block) {
__m128i block_XY[ARGON2_OWORDS_IN_BLOCK];
uint32_t i;
@ -53,7 +53,7 @@ void fill_block(__m128i *state, const uint8_t *ref_block, uint8_t *next_block) {
void generate_addresses(const argon2_instance_t *instance,
const argon2_position_t *position,
uint64_t *pseudo_rands) {
block address_block, input_block;
block address_block, input_block, tmp_block;
uint32_t i;
init_block_value(&address_block, 0);
@ -69,14 +69,20 @@ void generate_addresses(const argon2_instance_t *instance,
for (i = 0; i < instance->segment_length; ++i) {
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
/*Temporary zero-initialized blocks*/
__m128i zero_block[ARGON2_OWORDS_IN_BLOCK];
__m128i zero2_block[ARGON2_OWORDS_IN_BLOCK];
memset(zero_block, 0, sizeof(zero_block));
memset(zero2_block, 0, sizeof(zero2_block));
init_block_value(&address_block, 0);
init_block_value(&tmp_block, 0);
/*Increasing index counter*/
input_block.v[6]++;
fill_block(zero_block, (uint8_t *)&input_block.v,
(uint8_t *)&address_block.v);
fill_block(zero2_block, (uint8_t *)&address_block.v,
/*First iteration of G*/
fill_block_with_xor(zero_block, (uint8_t *)&input_block.v,
(uint8_t *)&tmp_block.v);
/*Second iteration of G*/
fill_block_with_xor(zero2_block, (uint8_t *)&tmp_block.v,
(uint8_t *)&address_block.v);
}
@ -167,7 +173,7 @@ void fill_segment(const argon2_instance_t *instance,
ref_block =
instance->memory + instance->lane_length * ref_lane + ref_index;
curr_block = instance->memory + curr_offset;
fill_block(state, (uint8_t *)ref_block->v, (uint8_t *)curr_block->v);
fill_block_with_xor(state, (uint8_t *)ref_block->v, (uint8_t *)curr_block->v);
}
free(pseudo_rands);

View File

@ -18,13 +18,14 @@
#include <emmintrin.h>
/*
* Function fills a new memory block. Differs from the
* Function fills a new memory block by XORing the new block over the old one. Memory must be initialized.
* After finishing, @state is identical to @next_block
* @param state Pointer to the just produced block. Content will be updated(!)
* @param ref_block Pointer to the reference block
* @param next_block Pointer to the block to be constructed
* @param next_block Pointer to the block to be XORed over. May coincide with @ref_block
* @pre all block pointers must be valid
*/
void fill_block(__m128i *state, const uint8_t *ref_block, uint8_t *next_block);
void fill_block_with_xor(__m128i *state, const uint8_t *ref_block, uint8_t *next_block);
/*
* Generate pseudo-random values to reference blocks in the segment and puts

View File

@ -22,7 +22,7 @@
#include "blake2/blake2-impl.h"
#include "blake2/blake2.h"
void fill_block(const block *prev_block, const block *ref_block,
void fill_block_with_xor(const block *prev_block, const block *ref_block,
block *next_block) {
block blockR, block_tmp;
unsigned i;
@ -30,7 +30,8 @@ void fill_block(const block *prev_block, const block *ref_block,
copy_block(&blockR, ref_block);
xor_block(&blockR, prev_block);
copy_block(&block_tmp, &blockR);
xor_block(&block_tmp, next_block); /*Saving the next block contents for XOR over*/
/*Now blockR = ref_block + prev_block and bloc_tmp = ref_block + prev_block + next_block*/
/* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then
(16,17,..31)... finally (112,113,...127) */
for (i = 0; i < 8; ++i) {
@ -62,12 +63,11 @@ void fill_block(const block *prev_block, const block *ref_block,
void generate_addresses(const argon2_instance_t *instance,
const argon2_position_t *position,
uint64_t *pseudo_rands) {
block zero_block, input_block, address_block;
block zero_block, input_block, address_block,tmp_block;
uint32_t i;
init_block_value(&zero_block, 0);
init_block_value(&input_block, 0);
init_block_value(&address_block, 0);
if (instance != NULL && position != NULL) {
input_block.v[0] = position->pass;
@ -80,8 +80,10 @@ void generate_addresses(const argon2_instance_t *instance,
for (i = 0; i < instance->segment_length; ++i) {
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
input_block.v[6]++;
fill_block(&zero_block, &input_block, &address_block);
fill_block(&zero_block, &address_block, &address_block);
init_block_value(&tmp_block, 0);
init_block_value(&address_block, 0);
fill_block_with_xor(&zero_block, &input_block, &tmp_block);
fill_block_with_xor(&zero_block, &tmp_block, &address_block);
}
pseudo_rands[i] = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
@ -169,7 +171,7 @@ void fill_segment(const argon2_instance_t *instance,
ref_block =
instance->memory + instance->lane_length * ref_lane + ref_index;
curr_block = instance->memory + curr_offset;
fill_block(instance->memory + prev_offset, ref_block, curr_block);
fill_block_with_xor(instance->memory + prev_offset, ref_block, curr_block);
}
free(pseudo_rands);

View File

@ -17,13 +17,13 @@
#include "core.h"
/*
* Function fills a new memory block
* Function fills a new memory block by XORing over @next_block. @next_block must be initialized
* @param prev_block Pointer to the previous block
* @param ref_block Pointer to the reference block
* @param next_block Pointer to the block to be constructed
* @pre all block pointers must be valid
*/
void fill_block(const block *prev_block, const block *ref_block,
void fill_block_with_xor(const block *prev_block, const block *ref_block,
block *next_block);
/*