diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-27 21:36:32 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-28 21:30:49 +0100 |
commit | fd11271eeabd2aa71f0a3701dcb13f2fbb8e0601 (patch) | |
tree | f027cdfecab05ee9bfcfaac03984fab3737bec5e | |
parent | ringct: remove spurious copies (diff) | |
download | monero-fd11271eeabd2aa71f0a3701dcb13f2fbb8e0601.tar.xz |
ringct: use memcpy/memset instead of handwritten loop where appropriate
-rw-r--r-- | src/ringct/rctOps.cpp | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/src/ringct/rctOps.cpp b/src/ringct/rctOps.cpp index 91dedc3e4..4b3f5b9ef 100644 --- a/src/ringct/rctOps.cpp +++ b/src/ringct/rctOps.cpp @@ -39,52 +39,38 @@ namespace rct { //Creates a zero scalar void zero(key &zero) { - int i = 0; - for (i = 0; i < 32; i++) { - zero[i] = (unsigned char)(0x00); - } + memset(&zero, 0, 32); } //Creates a zero scalar key zero() { - return{ {0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 } }; + static const key z = { {0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 , 0x00, 0x00, 0x00,0x00 } }; + return z; } //Creates a zero elliptic curve point void identity(key &Id) { - int i = 0; Id[0] = (unsigned char)(0x01); - for (i = 1; i < 32; i++) { - Id[i] = (unsigned char)(0x00); - } + memset(Id.bytes+1, 0, 31); } //Creates a zero elliptic curve point key identity() { key Id; - int i = 0; Id[0] = (unsigned char)(0x01); - for (i = 1; i < 32; i++) { - Id[i] = (unsigned char)(0x00); - } + memset(Id.bytes+1, 0, 31); return Id; } //copies a scalar or point void copy(key &AA, const key &A) { - int i = 0; - for (i = 0; i < 32; i++) { - AA[i] = A.bytes[i]; - } + memcpy(&AA, &A, 32); } //copies a scalar or point key copy(const key &A) { - int i = 0; key AA; - for (i = 0; i < 32; i++) { - AA[i] = A.bytes[i]; - } + memcpy(&AA, &A, 32); return AA; } @@ -387,10 +373,8 @@ namespace rct { size_t i = 0, j = 0; vector<char> m(l * 64); for (i = 0 ; i < l ; i++) { - for (j = 0 ; j < 32 ; j++) { - m[i * 64 + j] = PC[i].dest[j]; - m[i * 64 + 32 + j] = PC[i].mask[j]; - } + memcpy(&m[i * 64], &PC[i].dest, 32); + memcpy(&m[i * 64 + 32], &PC[i].mask, 32); } cn_fast_hash(rv, &m[0], 64*l); return rv; @@ -409,11 +393,9 @@ namespace rct { key cn_fast_hash(const keyV &keys) { size_t l = keys.size(); vector<unsigned char> m(l * 32); - size_t i, j; + size_t i; for (i = 0 ; i < l ; i++) { - for (j = 0 ; j < 32 ; j++) { - m[i * 32 + j] = keys[i][j]; - } + memcpy(&m[i * 32], keys[i].bytes, 32); } key rv; cn_fast_hash(rv, &m[0], 32 * l); |