Skip to content

Commit

Permalink
mmxpos using SHA-512
Browse files Browse the repository at this point in the history
  • Loading branch information
madMAx43v3r committed Nov 13, 2023
1 parent 97e0063 commit c90095e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/mmx/pos/mem_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace pos {

/*
* mem = array of size mem_size
* key = array of size 32
* key = array of size key_size
*/
void gen_mem_array(uint32_t* mem, const uint8_t* key, const int key_size, const uint32_t mem_size);

Expand Down
11 changes: 8 additions & 3 deletions src/pos/mem_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ static const uint32_t MEM_HASH_INIT[16] = {

void gen_mem_array(uint32_t* mem, const uint8_t* key, const int key_size, const uint32_t mem_size)
{
if(key_size > 16) {
throw std::logic_error("key_size > 16");
if(key_size > 64) {
throw std::logic_error("key_size > 64");
}
if(key_size % 4) {
throw std::logic_error("key_size % 4 != 0");
}
if(mem_size % 16) {
throw std::logic_error("mem_size % 16 != 0");
Expand All @@ -34,7 +37,9 @@ void gen_mem_array(uint32_t* mem, const uint8_t* key, const int key_size, const
for(int i = 0; i < 16; ++i) {
state[i] = MEM_HASH_INIT[i];
}
for(int i = 0; i < key_size; ++i) {

for(int i = 0; i < key_size / 4; ++i)
{
uint32_t tmp = 0;
::memcpy(&tmp, key + i * 4, 4);
state[i] ^= tmp;
Expand Down
20 changes: 9 additions & 11 deletions src/pos/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <mmx/pos/verify.h>
#include <mmx/pos/mem_hash.h>
#include <mmx/hash_t.hpp>
#include <mmx/hash_512_t.hpp>

#include <algorithm>
#include <vnx/vnx.h>
Expand Down Expand Up @@ -46,19 +46,18 @@ void compute_f1(std::vector<uint32_t>* X_tmp,
msg[0] = X_i;
::memcpy(msg + 1, id, 32);

const hash_t key(&msg, 36);
gen_mem_array(mem_buf.data(), key.data(), MEM_SIZE);
const hash_512_t key(&msg, 36);
gen_mem_array(mem_buf.data(), key.data(), key.size(), MEM_SIZE);

uint8_t mem_hash[128 + 36] = {};
uint8_t mem_hash[128 + 64] = {};
calc_mem_hash(mem_buf.data(), mem_hash, MEM_HASH_M, MEM_HASH_B);

::memcpy(mem_hash + 128, msg, 36);
::memcpy(mem_hash + 128, key.data(), key.size());

const hash_t mem_hash_hash(mem_hash, sizeof(mem_hash));
const hash_512_t mem_hash_hash(mem_hash, sizeof(mem_hash));

uint32_t hash[16] = {};
::memcpy(hash, hash_t(mem_hash_hash.data(), 32).data(), 32);
::memcpy(hash + 8, hash_t(hash, 32).data(), 32);
::memcpy(hash, mem_hash_hash.data(), mem_hash_hash.size());

std::array<uint32_t, N_META> meta = {};
for(int i = 0; i < N_META; ++i) {
Expand Down Expand Up @@ -171,10 +170,9 @@ compute(const std::vector<uint32_t>& X_values, std::vector<uint32_t>* X_out, con
for(int i = 0; i < N_META; ++i) {
msg[2 + N_META + i] = R_meta[i];
}
const hash_t first(&msg, sizeof(msg));
const hash_512_t tmp(&msg, sizeof(msg));

::memcpy(hash, hash_t(first.data(), 32).data(), 32);
::memcpy(hash + 8, hash_t(hash, 32).data(), 32);
::memcpy(hash, tmp.data(), tmp.size());
}
std::array<uint32_t, N_META> meta = {};
for(int i = 0; i < N_META; ++i) {
Expand Down

0 comments on commit c90095e

Please sign in to comment.