Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch crypto implementations to libsodium #1372

Draft
wants to merge 46 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9a62a64
Remove epee::to_hex::formatted
jagerman Nov 23, 2020
656d4f4
Remove idiotic unwrap() functions, scrubbed_arr
jagerman Dec 11, 2020
8def9d5
crypto::hash replacement; null_whatever -> whatever::null
jagerman Dec 11, 2020
ec35a28
Remove unused types
jagerman Dec 11, 2020
3937d7d
Make crypto object bool operators explicit
jagerman Dec 11, 2020
d7eda71
Replace all C++ typedefs with 'using'
jagerman Dec 11, 2020
cc6974b
Remove unused crap
jagerman Dec 11, 2020
ff01538
Remove unused structs/functions
jagerman Dec 11, 2020
eb13fd0
Replace "generic-ops" macros with templates
jagerman Dec 12, 2020
107458c
API simplifications: eliminate tree_hash, cn_fast_hash wrappers
jagerman Dec 12, 2020
8dece01
Remove retarded use of wipeable_string
jagerman Dec 12, 2020
a1e1404
Don't use shitty hash function for wipeable_string
jagerman Dec 13, 2020
c5b8ab9
Remove last of epee hex conversion code
jagerman Dec 13, 2020
c1a6dbc
Use std::byte for byte sequences, reorganize rct::key constants
jagerman Dec 17, 2020
c104c45
Don't misalign tx_output data
jagerman Dec 17, 2020
5c1a600
Fix: unwrap
jagerman Dec 17, 2020
f376c68
Replace crypto:: randomness with libsodium
jagerman Dec 17, 2020
bb6542b
Add WTF comment about messed up distribution
jagerman Dec 17, 2020
cf66367
Fix: key constants
jagerman Jan 4, 2021
20eda20
Trezor code fixes
jagerman Jan 4, 2021
e22cba5
Remove epee garbage
jagerman Jan 4, 2021
f7011c1
Remove crypto::random_range,random_index; add constexpr crypto::rng
jagerman Jan 4, 2021
b4d4955
squash+reword random element addition
jagerman Jan 4, 2021
2f52a13
Add fill_random overload that fills a byte buffer
jagerman Jan 4, 2021
7369716
Compilation fixes
jagerman Jan 4, 2021
aa73bcf
Test suite fixes for recent commits
jagerman Jan 4, 2021
9883449
Massively slim down tests/crypto/tests.txt
jagerman Jan 4, 2021
4fa765e
Fix vestigal lokimq namespace calls
jagerman Mar 24, 2021
93fe3f3
Fix bool conversions on crypto primitives
jagerman Mar 24, 2021
4158049
Merge fixes
jagerman Mar 24, 2021
6794601
fix (lokimq->oxenmq)
jagerman Apr 29, 2021
b095f21
fix: std::byte conversion
jagerman Apr 29, 2021
8f9e742
inline header constants
jagerman Apr 29, 2021
2c25375
Fix SN info upgrade in debug build
jagerman Apr 29, 2021
af79eb7
Fix assertions
jagerman Apr 29, 2021
d3d0ce2
Uncurse tree_hash data types
jagerman Apr 29, 2021
1c8fd02
Fix ONS as_byte_view implementation
jagerman Apr 29, 2021
64aedc2
Fix ringct random scalar gen
jagerman Apr 29, 2021
8672968
Replace sc_reduce(32) with sodium, add `% L` operators
jagerman Apr 29, 2021
28ec96f
DRY some wet code
jagerman Apr 29, 2021
f37b690
Add not-quite-implicit conversion to unsigned char*
jagerman Apr 30, 2021
8eccd4d
Remove sc_0
jagerman May 1, 2021
a911d28
Optimizations and cleanups
jagerman May 1, 2021
c7e8c81
Replace sc_add/sc_sub/sc_mul with sodium
jagerman May 1, 2021
a91f70a
Do sc_muladd/sc_mulsub via sodium
jagerman May 1, 2021
debf373
wtf
jagerman May 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions contrib/epee/include/epee/fnv1.h

This file was deleted.

76 changes: 0 additions & 76 deletions contrib/epee/include/epee/hex.h

This file was deleted.

23 changes: 2 additions & 21 deletions contrib/epee/include/epee/memwipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,10 @@ namespace tools {
template <class T>
struct scrubbed : public T {
using type = T;

~scrubbed() {
scrub();
}

/// Destroy the contents of the contained type.
void scrub() {
static_assert(std::is_trivially_copyable<T>::value,
"T cannot be auto-scrubbed. T must be POD.");
static_assert(std::is_trivially_destructible<T>::value,
"T cannot be auto-scrubbed. T must be trivially destructable.");
memwipe(this, sizeof(T));
}
static_assert(std::is_trivially_copyable_v<type>);
~scrubbed() { memwipe(this, sizeof(type)); }
};

template<typename T>
T& unwrap(scrubbed<T>& src) { return src; }

template<typename T>
const T& unwrap(scrubbed<T> const& src) { return src; }

template <class T, size_t N>
using scrubbed_arr = scrubbed<std::array<T, N>>;
} // namespace tools

namespace epee {
Expand Down
42 changes: 0 additions & 42 deletions contrib/epee/include/epee/misc_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,6 @@ namespace epee

namespace misc_utils
{
template<typename t_type>
t_type get_max_t_val(t_type t)
{
return (std::numeric_limits<t_type>::max)();
}


template<typename t_iterator>
t_iterator move_it_forward(t_iterator it, size_t count)
{
while(count--)
it++;
return it;
}

template<typename t_iterator>
t_iterator move_it_backward(t_iterator it, size_t count)
{
while(count--)
it--;
return it;
}


// TEMPLATE STRUCT less
template<class _Ty>
struct less_as_pod
: public std::binary_function<_Ty, _Ty, bool>
{ // functor for operator<
bool operator()(const _Ty& _Left, const _Ty& _Right) const
{ // apply operator< to operands
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
}
};

template<class _Ty>
bool is_less_as_pod(const _Ty& _Left, const _Ty& _Right)
{ // apply operator< to operands
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
}


inline
void sleep_no_w(long ms)
{
Expand Down
11 changes: 1 addition & 10 deletions contrib/epee/include/epee/mlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,5 @@ namespace epee
~mlocked() { try { mlocker::unlock(this, sizeof(T)); } catch (...) { /* do not propagate */ } }
};

template<typename T>
T& unwrap(mlocked<T>& src) { return src; }

template<typename T>
const T& unwrap(mlocked<T> const& src) { return src; }

template <class T, size_t N>
using mlocked_arr = mlocked<std::array<T, N>>;

template <typename T> constexpr bool is_byte_spannable<mlocked<T>> = is_byte_spannable<T>;
template <typename T> inline constexpr bool is_byte_spannable<mlocked<T>> = is_byte_spannable<T>;
}
20 changes: 10 additions & 10 deletions contrib/epee/include/epee/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace epee
Inspired by `gsl::span` and/or `boost::iterator_range`. This class is
intended to be used as a parameter type for functions that need to take a
writable or read-only sequence of data. Most common cases are `span<char>`
and `span<std::uint8_t>`. Using as a class member is only recommended if
and `span<std::byte>`. Using as a class member is only recommended if
clearly documented as not doing a deep-copy. C-arrays are easily convertible
to this type.

Expand Down Expand Up @@ -137,30 +137,30 @@ namespace epee
template<typename T>
constexpr bool is_byte_spannable = std::has_unique_object_representations_v<T>;

//! \return Cast data from `src` as `span<const std::uint8_t>`.
//! \return Cast data from `src` as `span<const std::byte>`.
template<typename T>
span<const std::uint8_t> to_byte_span(const span<const T> src) noexcept
span<const std::byte> to_byte_span(const span<const T> src) noexcept
{
static_assert(is_byte_spannable<T>, "source type may have padding");
return {reinterpret_cast<const std::uint8_t*>(src.data()), src.size_bytes()};
return {reinterpret_cast<const std::byte*>(src.data()), src.size_bytes()};
}

//! \return `span<const std::uint8_t>` which represents the bytes at `&src`.
//! \return `span<const std::byte>` which represents the bytes at `&src`.
template<typename T>
span<const std::uint8_t> as_byte_span(const T& src) noexcept
span<const std::byte> as_byte_span(const T& src) noexcept
{
static_assert(!std::is_empty<T>(), "empty types cannot be converted to a byte span");
static_assert(is_byte_spannable<T>, "source type may have padding");
return {reinterpret_cast<const std::uint8_t*>(std::addressof(src)), sizeof(T)};
return {reinterpret_cast<const std::byte*>(std::addressof(src)), sizeof(T)};
}

//! \return `span<std::uint8_t>` which represents the bytes at `&src`.
//! \return `span<std::byte>` which represents the bytes at `&src`.
template<typename T>
span<std::uint8_t> as_mut_byte_span(T& src) noexcept
span<std::byte> as_mut_byte_span(T& src) noexcept
{
static_assert(!std::is_empty<T>(), "empty types cannot be converted to a byte span");
static_assert(is_byte_spannable<T>, "source type may have padding");
return {reinterpret_cast<std::uint8_t*>(std::addressof(src)), sizeof(T)};
return {reinterpret_cast<std::byte*>(std::addressof(src)), sizeof(T)};
}

//! make a span from a std::string_view (and thus, implicitly, also std::string or string literal)
Expand Down
31 changes: 0 additions & 31 deletions contrib/epee/include/epee/string_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "storages/parserse_base_utils.h"
#include "hex.h"
#include "mlocker.h"
#include "span.h"
#include "warnings.h"
Expand All @@ -61,36 +60,6 @@ using namespace std::literals;
namespace string_tools
{
//----------------------------------------------------------------------------
inline bool parse_hexstr_to_binbuff(const epee::span<const char> s, epee::span<char>& res)
{
if (s.size() != res.size() * 2)
return false;

unsigned char *dst = (unsigned char *)&res[0];
const unsigned char *src = (const unsigned char *)s.data();
for(size_t i = 0; i < s.size(); i += 2)
{
int tmp = *src++;
tmp = epee::misc_utils::parse::isx[tmp];
if (tmp == 0xff) return false;
int t2 = *src++;
t2 = epee::misc_utils::parse::isx[t2];
if (t2 == 0xff) return false;
*dst++ = (tmp << 4) | t2;
}

return true;
}
//----------------------------------------------------------------------------
inline bool parse_hexstr_to_binbuff(const std::string& s, std::string& res)
{
if (s.size() & 1)
return false;
res.resize(s.size() / 2);
epee::span<char> rspan((char*)&res[0], res.size());
return parse_hexstr_to_binbuff(epee::to_span(s), rspan);
}
//----------------------------------------------------------------------------
PUSH_WARNINGS
DISABLE_GCC_WARNING(maybe-uninitialized)
template<class XType>
Expand Down
21 changes: 10 additions & 11 deletions contrib/epee/include/epee/wipeable_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <cstddef>
#include <vector>
#include <string>
#include <string_view>
#include "memwipe.h"
#include "fnv1.h"

namespace epee
{
Expand All @@ -60,15 +60,17 @@ namespace epee
char pop_back();
const char *data() const noexcept { return buffer.data(); }
char *data() noexcept { return buffer.data(); }
const std::byte* bytes() const noexcept { return reinterpret_cast<const std::byte*>(data()); }
std::byte* bytes() noexcept { return reinterpret_cast<std::byte*>(data()); }
size_t size() const noexcept { return buffer.size(); }
size_t length() const noexcept { return buffer.size(); }
bool empty() const noexcept { return buffer.empty(); }
void trim();
std::string_view view() const noexcept { return std::string_view{data(), size()}; }
void split(std::vector<wipeable_string> &fields) const;
std::optional<wipeable_string> parse_hexstr() const;
template<typename T> inline bool hex_to_pod(T &pod) const;
template<typename T> inline bool hex_to_pod(tools::scrubbed<T> &pod) const { return hex_to_pod(unwrap(pod)); }
template<typename T> bool hex_to_pod(T &pod) const;
template<typename T> bool hex_to_pod(tools::scrubbed<T> &pod) const { return hex_to_pod(pod); }
void resize(size_t sz);
void reserve(size_t sz);
void clear();
Expand All @@ -84,7 +86,7 @@ namespace epee
std::vector<char> buffer;
};

template<typename T> inline bool wipeable_string::hex_to_pod(T &pod) const
template<typename T> bool wipeable_string::hex_to_pod(T &pod) const
{
static_assert(std::is_pod<T>::value, "expected pod type");
if (size() != sizeof(T) * 2)
Expand All @@ -99,13 +101,10 @@ namespace epee
}
}

namespace std
{
template<> struct hash<epee::wipeable_string>
{
size_t operator()(const epee::wipeable_string &s) const
{
return epee::fnv::FNV1a(s.data(), s.size());
namespace std {
template<> struct hash<epee::wipeable_string> {
size_t operator()(const epee::wipeable_string &s) const {
return hash<std::string_view>{}(s.view());
}
};
}
1 change: 0 additions & 1 deletion contrib/epee/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
add_library(epee
buffer.cpp
connection_basic.cpp
hex.cpp
levin_base.cpp
memwipe.c
mlocker.cpp
Expand Down
Loading