mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 20:36:31 +02:00
Merge pull request #1251
59f0d4b
ringct: some more small optimizations (moneromooo-monero)
This commit is contained in:
commit
971f3ae031
@ -37,50 +37,12 @@ namespace rct {
|
|||||||
|
|
||||||
//Various key initialization functions
|
//Various key initialization functions
|
||||||
|
|
||||||
//Creates a zero scalar
|
|
||||||
void zero(key &zero) {
|
|
||||||
memset(&zero, 0, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Creates a zero scalar
|
|
||||||
key zero() {
|
|
||||||
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) {
|
|
||||||
Id[0] = (unsigned char)(0x01);
|
|
||||||
memset(Id.bytes+1, 0, 31);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Creates a zero elliptic curve point
|
|
||||||
key identity() {
|
|
||||||
key Id;
|
|
||||||
Id[0] = (unsigned char)(0x01);
|
|
||||||
memset(Id.bytes+1, 0, 31);
|
|
||||||
return Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
//copies a scalar or point
|
|
||||||
void copy(key &AA, const key &A) {
|
|
||||||
memcpy(&AA, &A, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
//copies a scalar or point
|
|
||||||
key copy(const key &A) {
|
|
||||||
key AA;
|
|
||||||
memcpy(&AA, &A, 32);
|
|
||||||
return AA;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//initializes a key matrix;
|
//initializes a key matrix;
|
||||||
//first parameter is rows,
|
//first parameter is rows,
|
||||||
//second is columns
|
//second is columns
|
||||||
keyM keyMInit(int rows, int cols) {
|
keyM keyMInit(size_t rows, size_t cols) {
|
||||||
keyM rv(cols);
|
keyM rv(cols);
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
for (i = 0 ; i < cols ; i++) {
|
for (i = 0 ; i < cols ; i++) {
|
||||||
rv[i] = keyV(rows);
|
rv[i] = keyV(rows);
|
||||||
}
|
}
|
||||||
@ -107,11 +69,12 @@ namespace rct {
|
|||||||
|
|
||||||
//Generates a vector of secret key
|
//Generates a vector of secret key
|
||||||
//Mainly used in testing
|
//Mainly used in testing
|
||||||
keyV skvGen(int rows ) {
|
keyV skvGen(size_t rows ) {
|
||||||
keyV rv(rows);
|
keyV rv(rows);
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
|
crypto::rand(rows * sizeof(key), (uint8_t*)&rv[0]);
|
||||||
for (i = 0 ; i < rows ; i++) {
|
for (i = 0 ; i < rows ; i++) {
|
||||||
skGen(rv[i]);
|
sc_reduce32(rv[i].bytes);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -155,7 +118,7 @@ namespace rct {
|
|||||||
|
|
||||||
|
|
||||||
//generates a <secret , public> / Pedersen commitment but takes bH as input
|
//generates a <secret , public> / Pedersen commitment but takes bH as input
|
||||||
tuple<ctkey, ctkey> ctskpkGen(key bH) {
|
tuple<ctkey, ctkey> ctskpkGen(const key &bH) {
|
||||||
ctkey sk, pk;
|
ctkey sk, pk;
|
||||||
skpkGen(sk.dest, pk.dest);
|
skpkGen(sk.dest, pk.dest);
|
||||||
skpkGen(sk.mask, pk.mask);
|
skpkGen(sk.mask, pk.mask);
|
||||||
@ -172,12 +135,12 @@ namespace rct {
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
key commit(xmr_amount amount, key mask) {
|
key commit(xmr_amount amount, const key &mask) {
|
||||||
mask = scalarmultBase(mask);
|
key c = scalarmultBase(mask);
|
||||||
key am = d2h(amount);
|
key am = d2h(amount);
|
||||||
key bH = scalarmultH(am);
|
key bH = scalarmultH(am);
|
||||||
addKeys(mask, mask, bH);
|
addKeys(c, c, bH);
|
||||||
return mask;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
//generates a random uint long long (for testing)
|
//generates a random uint long long (for testing)
|
||||||
|
@ -64,19 +64,23 @@ namespace rct {
|
|||||||
|
|
||||||
//Various key initialization functions
|
//Various key initialization functions
|
||||||
|
|
||||||
|
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 } };
|
||||||
|
static const key I = { {0x01, 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 } };
|
||||||
|
|
||||||
//Creates a zero scalar
|
//Creates a zero scalar
|
||||||
key zero();
|
inline key zero() { return Z; }
|
||||||
void zero(key &z);
|
inline void zero(key &z) { memset(&z, 0, 32); }
|
||||||
//Creates a zero elliptic curve point
|
//Creates a zero elliptic curve point
|
||||||
key identity();
|
inline key identity() { return I; }
|
||||||
void identity(key &Id);
|
inline void identity(key &Id) { memcpy(&Id, &I, 32); }
|
||||||
//copies a scalar or point
|
//copies a scalar or point
|
||||||
void copy(key &AA, const key &A);
|
inline void copy(key &AA, const key &A) { memcpy(&AA, &A, 32); }
|
||||||
key copy(const key & AA);
|
inline key copy(const key & A) { key AA; memcpy(&AA, &A, 32); return AA; }
|
||||||
|
|
||||||
//initializes a key matrix;
|
//initializes a key matrix;
|
||||||
//first parameter is rows,
|
//first parameter is rows,
|
||||||
//second is columns
|
//second is columns
|
||||||
keyM keyMInit(int, int);
|
keyM keyMInit(size_t rows, size_t cols);
|
||||||
|
|
||||||
//Various key generation functions
|
//Various key generation functions
|
||||||
|
|
||||||
@ -85,7 +89,7 @@ namespace rct {
|
|||||||
void skGen(key &);
|
void skGen(key &);
|
||||||
|
|
||||||
//generates a vector of secret keys of size "int"
|
//generates a vector of secret keys of size "int"
|
||||||
keyV skvGen(int );
|
keyV skvGen(size_t rows );
|
||||||
|
|
||||||
//generates a random curve point (for testing)
|
//generates a random curve point (for testing)
|
||||||
key pkGen();
|
key pkGen();
|
||||||
@ -97,9 +101,9 @@ namespace rct {
|
|||||||
//generates C =aG + bH from b, a is random
|
//generates C =aG + bH from b, a is random
|
||||||
void genC(key & C, const key & a, xmr_amount amount);
|
void genC(key & C, const key & a, xmr_amount amount);
|
||||||
//this one is mainly for testing, can take arbitrary amounts..
|
//this one is mainly for testing, can take arbitrary amounts..
|
||||||
tuple<ctkey, ctkey> ctskpkGen(key bH);
|
tuple<ctkey, ctkey> ctskpkGen(const key &bH);
|
||||||
// make a pedersen commitment with given key
|
// make a pedersen commitment with given key
|
||||||
key commit(xmr_amount amount, key mask);
|
key commit(xmr_amount amount, const key &mask);
|
||||||
// make a pedersen commitment with zero key
|
// make a pedersen commitment with zero key
|
||||||
key zeroCommit(xmr_amount amount);
|
key zeroCommit(xmr_amount amount);
|
||||||
//generates a random uint long long
|
//generates a random uint long long
|
||||||
|
Loading…
Reference in New Issue
Block a user