Merge pull request #12 from iamsmooth/master

various portability fixes
This commit is contained in:
aeonix
2015-07-27 06:38:23 -07:00
5 changed files with 22 additions and 16 deletions
+4 -2
View File
@@ -8,6 +8,8 @@
*
*/
#include <stddef.h>
#include "groestl.h"
#include "groestl_tables.h"
@@ -204,7 +206,7 @@ static void OutputTransformation(hashState *ctx) {
/* initialise context */
static void Init(hashState* ctx) {
int i = 0;
size_t i = 0;
/* allocate memory for state and data buffer */
for(;i<(SIZE512/sizeof(uint32_t));i++)
@@ -357,4 +359,4 @@ static int crypto_hash(unsigned char *out,
return 0;
}
*/
*/
+9 -9
View File
@@ -565,7 +565,7 @@ union cn_slow_hash_state {
};
#pragma pack(pop)
void cn_slow_hash(const void *data, size_t length, char *hash) {
void cn_slow_hash(const void *data, size_t length, char *hash, int light) {
uint8_t long_state[MEMORY];
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
@@ -583,7 +583,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) {
aes_ctx = (oaes_ctx *) oaes_alloc();
oaes_key_import_data(aes_ctx, aes_key, AES_KEY_SIZE);
for (i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) {
for (i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) {
for (j = 0; j < INIT_SIZE_BLK; j++) {
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
}
@@ -595,35 +595,35 @@ void cn_slow_hash(const void *data, size_t length, char *hash) {
b[i] = state.k[16 + i] ^ state.k[48 + i];
}
for (i = 0; i < ITER / 2; i++) {
for (i = 0; i < ITER / (light?2:1) / 2; i++) {
/* Dependency chain: address -> read value ------+
* written value <-+ hard function (AES or MUL) <+
* next address <-+
*/
/* Iteration 1 */
j = e2i(a, MEMORY / AES_BLOCK_SIZE);
j = e2i(a, MEMORY / (light?2:1) / AES_BLOCK_SIZE);
copy_block(c, &long_state[j * AES_BLOCK_SIZE]);
aesb_single_round(c, c, a);
aesb_single_round(c, c, a);
xor_blocks(b, c);
swap_blocks(b, c);
copy_block(&long_state[j * AES_BLOCK_SIZE], c);
assert(j == e2i(a, MEMORY / AES_BLOCK_SIZE));
assert(j == e2i(a, MEMORY / (light?2:1) / AES_BLOCK_SIZE));
swap_blocks(a, b);
/* Iteration 2 */
j = e2i(a, MEMORY / AES_BLOCK_SIZE);
j = e2i(a, MEMORY / (light?2:1) / AES_BLOCK_SIZE);
copy_block(c, &long_state[j * AES_BLOCK_SIZE]);
mul(a, c, d);
sum_half_blocks(b, d);
swap_blocks(b, c);
xor_blocks(b, c);
copy_block(&long_state[j * AES_BLOCK_SIZE], c);
assert(j == e2i(a, MEMORY / AES_BLOCK_SIZE));
assert(j == e2i(a, MEMORY / (light?2:1) / AES_BLOCK_SIZE));
swap_blocks(a, b);
}
memcpy(text, state.init, INIT_SIZE_BYTE);
oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE);
for (i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) {
for (i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) {
for (j = 0; j < INIT_SIZE_BLK; j++) {
xor_blocks(&text[j * AES_BLOCK_SIZE], &long_state[i * INIT_SIZE_BYTE + j * AES_BLOCK_SIZE]);
aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data);
+6 -2
View File
@@ -586,7 +586,9 @@ namespace nodetool
peerlist_entry pe_local = AUTO_VAL_INIT(pe_local);
pe_local.adr = na;
pe_local.id = pi;
time(&pe_local.last_seen);
time_t last_seen;
time(&last_seen);
pe_local.last_seen = static_cast<int64_t>(last_seen);
m_peerlist.append_with_peer_white(pe_local);
//update last seen and push it to peerlist manager
@@ -1064,7 +1066,9 @@ namespace nodetool
peerlist_entry pe;
pe.adr.ip = context.m_remote_ip;
pe.adr.port = port_l;
time(&pe.last_seen);
time_t last_seen;
time(&last_seen);
pe.last_seen = static_cast<int64_t>(last_seen);
pe.id = peer_id_l;
this->m_peerlist.append_with_peer_white(pe);
LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l);
+2 -2
View File
@@ -128,7 +128,7 @@ namespace nodetool
// access by peerlist_entry::net_adress
boost::multi_index::ordered_unique<boost::multi_index::tag<by_addr>, boost::multi_index::member<peerlist_entry,net_address,&peerlist_entry::adr> >,
// sort by peerlist_entry::last_seen<
boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,time_t,&peerlist_entry::last_seen> >
boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,int64_t,&peerlist_entry::last_seen> >
>
> peers_indexed;
@@ -140,7 +140,7 @@ namespace nodetool
// access by peerlist_entry::net_adress
boost::multi_index::ordered_unique<boost::multi_index::tag<by_addr>, boost::multi_index::member<peerlist_entry,net_address,&peerlist_entry::adr> >,
// sort by peerlist_entry::last_seen<
boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,time_t,&peerlist_entry::last_seen> >
boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,int64_t,&peerlist_entry::last_seen> >
>
> peers_indexed_old;
public:
+1 -1
View File
@@ -53,7 +53,7 @@ namespace nodetool
{
net_address adr;
peerid_type id;
time_t last_seen;
int64_t last_seen;
};
struct connection_entry