addtl changes to slow-hash and mlocker - these may be unnecessary

pull/2/head
Paul Shapiro 6 years ago
parent 387d4315aa
commit 0ad95ab88d

@ -244,8 +244,54 @@ and replace get_page_size with
=========== ===========
important for 13-word support:
mnemonics/electrum-words.cpp mnemonics/electrum-words.cpp
- return result.checksum() % crypto::ElectrumWords::seed_length; - return result.checksum() % crypto::ElectrumWords::seed_length;
+ return result.checksum() % word_list.size(); + return result.checksum() % word_list.size();
=========
for emscripten: (Note this might not actually make a difference - remove if confirmed not to)
crypto/slow-hash.c
-extern int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
-extern int aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
+extern void aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
+extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
-extern int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
-extern int aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
+extern void aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
+extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
=========
Note: this may not be necessary but might simplify emscripten compilation (remove this entry if confirmed not to)
epee/src/mlocker.cpp
-#define HAVE_MLOCK 1
+// #define HAVE_MLOCK 1
- CRITICAL_REGION_LOCAL(mutex());
- if (page_size == 0)
- page_size = query_page_size();
- return page_size;
+ return 4096;
+ // CRITICAL_REGION_LOCAL(mutex());
+ // if (page_size == 0)
+ // page_size = query_page_size();
+ // return page_size;
and comment out body of other function implementations

@ -47,8 +47,8 @@
#define INIT_SIZE_BLK 8 #define INIT_SIZE_BLK 8
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) #define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE)
extern int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey); extern void aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern int aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey); extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
#define VARIANT1_1(p) \ #define VARIANT1_1(p) \
do if (variant == 1) \ do if (variant == 1) \
@ -1408,8 +1408,8 @@ static void (*const extra_hashes[4])(const void *, size_t, char *) = {
hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein
}; };
extern int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey); extern void aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern int aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey); extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
static size_t e2i(const uint8_t* a, size_t count) { return (*((uint64_t*)a) / AES_BLOCK_SIZE) & (count - 1); } static size_t e2i(const uint8_t* a, size_t count) { return (*((uint64_t*)a) / AES_BLOCK_SIZE) & (count - 1); }

@ -27,7 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined __GNUC__ && !defined _WIN32 #if defined __GNUC__ && !defined _WIN32
#define HAVE_MLOCK 1 // #define HAVE_MLOCK 1
#endif #endif
#include <unistd.h> #include <unistd.h>
@ -95,20 +95,21 @@ namespace epee
size_t mlocker::get_page_size() size_t mlocker::get_page_size()
{ {
CRITICAL_REGION_LOCAL(mutex()); return 4096;
if (page_size == 0) // CRITICAL_REGION_LOCAL(mutex());
page_size = query_page_size(); // if (page_size == 0)
return page_size; // page_size = query_page_size();
// return page_size;
} }
mlocker::mlocker(void *ptr, size_t len): ptr(ptr), len(len) mlocker::mlocker(void *ptr, size_t len): ptr(ptr), len(len)
{ {
lock(ptr, len); // lock(ptr, len);
} }
mlocker::~mlocker() mlocker::~mlocker()
{ {
unlock(ptr, len); // unlock(ptr, len);
} }
void mlocker::lock(void *ptr, size_t len) void mlocker::lock(void *ptr, size_t len)
@ -117,12 +118,12 @@ namespace epee
if (page_size == 0) if (page_size == 0)
return; return;
CRITICAL_REGION_LOCAL(mutex()); // CRITICAL_REGION_LOCAL(mutex());
const size_t first = ((uintptr_t)ptr) / page_size; // const size_t first = ((uintptr_t)ptr) / page_size;
const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; // const size_t last = (((uintptr_t)ptr) + len - 1) / page_size;
for (size_t page = first; page <= last; ++page) // for (size_t page = first; page <= last; ++page)
lock_page(page); // lock_page(page);
++num_locked_objects; // ++num_locked_objects;
} }
void mlocker::unlock(void *ptr, size_t len) void mlocker::unlock(void *ptr, size_t len)
@ -130,53 +131,55 @@ namespace epee
size_t page_size = get_page_size(); size_t page_size = get_page_size();
if (page_size == 0) if (page_size == 0)
return; return;
CRITICAL_REGION_LOCAL(mutex()); // CRITICAL_REGION_LOCAL(mutex());
const size_t first = ((uintptr_t)ptr) / page_size; // const size_t first = ((uintptr_t)ptr) / page_size;
const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; // const size_t last = (((uintptr_t)ptr) + len - 1) / page_size;
for (size_t page = first; page <= last; ++page) // for (size_t page = first; page <= last; ++page)
unlock_page(page); // unlock_page(page);
--num_locked_objects; // --num_locked_objects;
} }
size_t mlocker::get_num_locked_pages() size_t mlocker::get_num_locked_pages()
{ {
CRITICAL_REGION_LOCAL(mutex()); return 0;
return map().size(); // CRITICAL_REGION_LOCAL(mutex());
// return map().size();
} }
size_t mlocker::get_num_locked_objects() size_t mlocker::get_num_locked_objects()
{ {
CRITICAL_REGION_LOCAL(mutex()); return 0;
return num_locked_objects; // CRITICAL_REGION_LOCAL(mutex());
// return num_locked_objects;
} }
void mlocker::lock_page(size_t page) void mlocker::lock_page(size_t page)
{ {
std::pair<std::map<size_t, unsigned int>::iterator, bool> p = map().insert(std::make_pair(page, 1)); // std::pair<std::map<size_t, unsigned int>::iterator, bool> p = map().insert(std::make_pair(page, 1));
if (p.second) // if (p.second)
{ // {
do_lock((void*)(page * page_size), page_size); // do_lock((void*)(page * page_size), page_size);
} // }
else // else
{ // {
++p.first->second; // ++p.first->second;
} // }
} }
void mlocker::unlock_page(size_t page) void mlocker::unlock_page(size_t page)
{ {
std::map<size_t, unsigned int>::iterator i = map().find(page); // std::map<size_t, unsigned int>::iterator i = map().find(page);
if (i == map().end()) // if (i == map().end())
{ // {
MERROR("Attempt to unlock unlocked page at " << (void*)(page * page_size)); // MERROR("Attempt to unlock unlocked page at " << (void*)(page * page_size));
} // }
else // else
{ // {
if (!--i->second) // if (!--i->second)
{ // {
map().erase(i); // map().erase(i);
do_unlock((void*)(page * page_size), page_size); // do_unlock((void*)(page * page_size), page_size);
} // }
} // }
} }
} }

Loading…
Cancel
Save