diff options
author | Jack Lloyd <[email protected]> | 2018-11-17 14:54:21 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-17 22:50:26 -0500 |
commit | 432d31546eb335bb96c6b2a8c58f0168266387ec (patch) | |
tree | 2397468c243906a08eea08b9376a9922346e6856 /src/lib/pubkey/ed25519 | |
parent | 6b3a827fb493ad884c7443092ba8f9967636b3c8 (diff) |
Avoid calling memset, memcpy within library code
Prefer using wrappers in mem_utils for this.
Current exception is where memcpy is being used to convert between
two different types, since copy_mem requires input and output
pointers have the same type. There should be a new function to
handle conversion-via-memcpy operation.
Diffstat (limited to 'src/lib/pubkey/ed25519')
-rw-r--r-- | src/lib/pubkey/ed25519/ed25519.cpp | 4 | ||||
-rw-r--r-- | src/lib/pubkey/ed25519/ed25519_fe.h | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/pubkey/ed25519/ed25519.cpp b/src/lib/pubkey/ed25519/ed25519.cpp index d959df709..b75028041 100644 --- a/src/lib/pubkey/ed25519/ed25519.cpp +++ b/src/lib/pubkey/ed25519/ed25519.cpp @@ -29,8 +29,8 @@ void ed25519_gen_keypair(uint8_t* pk, uint8_t* sk, const uint8_t seed[32]) ge_scalarmult_base(pk, az); // todo copy_mem - memmove(sk, seed, 32); - memmove(sk + 32, pk, 32); + copy_mem(sk, seed, 32); + copy_mem(sk + 32, pk, 32); } void ed25519_sign(uint8_t sig[64], diff --git a/src/lib/pubkey/ed25519/ed25519_fe.h b/src/lib/pubkey/ed25519/ed25519_fe.h index af92af46a..bcdc36a5e 100644 --- a/src/lib/pubkey/ed25519/ed25519_fe.h +++ b/src/lib/pubkey/ed25519/ed25519_fe.h @@ -30,16 +30,16 @@ class FE_25519 FE_25519(int init = 0) { if(init != 0 && init != 1) - { throw Invalid_Argument("Invalid FE_25519 initial value"); } - memset(m_fe, 0, 10 * sizeof(int32_t)); + throw Invalid_Argument("Invalid FE_25519 initial value"); + clear_mem(m_fe, 10); m_fe[0] = init; } FE_25519(std::initializer_list<int32_t> x) { if(x.size() != 10) - { throw Invalid_Argument("Invalid FE_25519 initializer list"); } - memcpy(m_fe, x.begin(), 10 * sizeof(int32_t)); + throw Invalid_Argument("Invalid FE_25519 initializer list"); + copy_mem(m_fe, x.begin(), 10); } FE_25519(int64_t h0, int64_t h1, int64_t h2, int64_t h3, int64_t h4, |