aboutsummaryrefslogtreecommitdiff
path: root/src/ringct
diff options
context:
space:
mode:
authorJethro Grassie <jtg@xtrabass.com>2019-11-08 01:26:17 -0500
committerJethro Grassie <jtg@xtrabass.com>2019-11-19 04:21:02 -0500
commitd8fc8d8868568c3694b24e0a413a896569e41a79 (patch)
tree90136654a58cb3177957787378116cfb6ec78f5a /src/ringct
parentMerge pull request #6148 (diff)
downloadmonero-d8fc8d8868568c3694b24e0a413a896569e41a79.tar.xz
make d2h et al. constant-time
Diffstat (limited to 'src/ringct')
-rw-r--r--src/ringct/rctTypes.cpp38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/ringct/rctTypes.cpp b/src/ringct/rctTypes.cpp
index 2c4e5fc3b..1763542db 100644
--- a/src/ringct/rctTypes.cpp
+++ b/src/ringct/rctTypes.cpp
@@ -31,6 +31,7 @@
#include "misc_log_ex.h"
#include "cryptonote_config.h"
#include "rctTypes.h"
+#include "int-util.h"
using namespace crypto;
using namespace std;
@@ -118,40 +119,22 @@ namespace rct {
//uint long long to 32 byte key
void d2h(key & amounth, const xmr_amount in) {
sc_0(amounth.bytes);
- xmr_amount val = in;
- int i = 0;
- while (val != 0) {
- amounth[i] = (unsigned char)(val & 0xFF);
- i++;
- val /= (xmr_amount)256;
- }
+ memcpy_swap64le(amounth.bytes, &in, 1);
}
//uint long long to 32 byte key
key d2h(const xmr_amount in) {
key amounth;
- sc_0(amounth.bytes);
- xmr_amount val = in;
- int i = 0;
- while (val != 0) {
- amounth[i] = (unsigned char)(val & 0xFF);
- i++;
- val /= (xmr_amount)256;
- }
+ d2h(amounth, in);
return amounth;
}
//uint long long to int[64]
void d2b(bits amountb, xmr_amount val) {
int i = 0;
- while (val != 0) {
- amountb[i] = val & 1;
- i++;
- val >>= 1;
- }
while (i < 64) {
- amountb[i] = 0;
- i++;
+ amountb[i++] = val & 1;
+ val >>= 1;
}
}
@@ -172,16 +155,11 @@ namespace rct {
int val = 0, i = 0, j = 0;
for (j = 0; j < 8; j++) {
val = (unsigned char)test.bytes[j];
- i = 8 * j;
- while (val != 0) {
- amountb2[i] = val & 1;
- i++;
+ i = 0;
+ while (i < 8) {
+ amountb2[j*8+i++] = val & 1;
val >>= 1;
}
- while (i < 8 * (j + 1)) {
- amountb2[i] = 0;
- i++;
- }
}
}