From 0ad95ab88d711e85678e3def10b6635c4fe22ec9 Mon Sep 17 00:00:00 2001 From: Paul Shapiro Date: Thu, 18 Oct 2018 12:28:57 -0500 Subject: [PATCH] addtl changes to slow-hash and mlocker - these may be unnecessary --- changes when upgrading monero src.txt | 48 +++++++++++++- crypto/slow-hash.c | 8 +-- epee/src/mlocker.cpp | 93 ++++++++++++++------------- 3 files changed, 99 insertions(+), 50 deletions(-) diff --git a/changes when upgrading monero src.txt b/changes when upgrading monero src.txt index a933b7c..cebaa49 100644 --- a/changes when upgrading monero src.txt +++ b/changes when upgrading monero src.txt @@ -244,8 +244,54 @@ and replace get_page_size with =========== +important for 13-word support: mnemonics/electrum-words.cpp - return result.checksum() % crypto::ElectrumWords::seed_length; -+ return result.checksum() % word_list.size(); \ No newline at end of file ++ 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 \ No newline at end of file diff --git a/crypto/slow-hash.c b/crypto/slow-hash.c index 40cfb04..bce6087 100644 --- a/crypto/slow-hash.c +++ b/crypto/slow-hash.c @@ -47,8 +47,8 @@ #define INIT_SIZE_BLK 8 #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 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); #define VARIANT1_1(p) \ 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 }; -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); static size_t e2i(const uint8_t* a, size_t count) { return (*((uint64_t*)a) / AES_BLOCK_SIZE) & (count - 1); } diff --git a/epee/src/mlocker.cpp b/epee/src/mlocker.cpp index 5573d59..752f8e8 100644 --- a/epee/src/mlocker.cpp +++ b/epee/src/mlocker.cpp @@ -27,7 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined __GNUC__ && !defined _WIN32 -#define HAVE_MLOCK 1 +// #define HAVE_MLOCK 1 #endif #include @@ -95,20 +95,21 @@ namespace epee size_t mlocker::get_page_size() { - 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; } mlocker::mlocker(void *ptr, size_t len): ptr(ptr), len(len) { - lock(ptr, len); + // lock(ptr, len); } mlocker::~mlocker() { - unlock(ptr, len); + // unlock(ptr, len); } void mlocker::lock(void *ptr, size_t len) @@ -117,12 +118,12 @@ namespace epee if (page_size == 0) return; - CRITICAL_REGION_LOCAL(mutex()); - const size_t first = ((uintptr_t)ptr) / page_size; - const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; - for (size_t page = first; page <= last; ++page) - lock_page(page); - ++num_locked_objects; + // CRITICAL_REGION_LOCAL(mutex()); + // const size_t first = ((uintptr_t)ptr) / page_size; + // const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; + // for (size_t page = first; page <= last; ++page) + // lock_page(page); + // ++num_locked_objects; } void mlocker::unlock(void *ptr, size_t len) @@ -130,53 +131,55 @@ namespace epee size_t page_size = get_page_size(); if (page_size == 0) return; - CRITICAL_REGION_LOCAL(mutex()); - const size_t first = ((uintptr_t)ptr) / page_size; - const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; - for (size_t page = first; page <= last; ++page) - unlock_page(page); - --num_locked_objects; + // CRITICAL_REGION_LOCAL(mutex()); + // const size_t first = ((uintptr_t)ptr) / page_size; + // const size_t last = (((uintptr_t)ptr) + len - 1) / page_size; + // for (size_t page = first; page <= last; ++page) + // unlock_page(page); + // --num_locked_objects; } size_t mlocker::get_num_locked_pages() { - CRITICAL_REGION_LOCAL(mutex()); - return map().size(); + return 0; + // CRITICAL_REGION_LOCAL(mutex()); + // return map().size(); } size_t mlocker::get_num_locked_objects() { - CRITICAL_REGION_LOCAL(mutex()); - return num_locked_objects; + return 0; + // CRITICAL_REGION_LOCAL(mutex()); + // return num_locked_objects; } void mlocker::lock_page(size_t page) { - std::pair::iterator, bool> p = map().insert(std::make_pair(page, 1)); - if (p.second) - { - do_lock((void*)(page * page_size), page_size); - } - else - { - ++p.first->second; - } + // std::pair::iterator, bool> p = map().insert(std::make_pair(page, 1)); + // if (p.second) + // { + // do_lock((void*)(page * page_size), page_size); + // } + // else + // { + // ++p.first->second; + // } } void mlocker::unlock_page(size_t page) { - std::map::iterator i = map().find(page); - if (i == map().end()) - { - MERROR("Attempt to unlock unlocked page at " << (void*)(page * page_size)); - } - else - { - if (!--i->second) - { - map().erase(i); - do_unlock((void*)(page * page_size), page_size); - } - } + // std::map::iterator i = map().find(page); + // if (i == map().end()) + // { + // MERROR("Attempt to unlock unlocked page at " << (void*)(page * page_size)); + // } + // else + // { + // if (!--i->second) + // { + // map().erase(i); + // do_unlock((void*)(page * page_size), page_size); + // } + // } } }