mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
remove duplicite curve25519 scalarmult implementations
This commit is contained in:
parent
1d232a6f86
commit
fdf1b6dc6d
4
bip32.c
4
bip32.c
@ -406,7 +406,7 @@ void hdnode_fill_public_key(HDNode *node)
|
||||
ed25519_publickey(node->private_key, node->public_key + 1);
|
||||
} else if (node->curve == &curve25519_info) {
|
||||
node->public_key[0] = 1;
|
||||
curve25519_donna_basepoint(node->public_key + 1, node->private_key);
|
||||
curve25519_scalarmult_basepoint(node->public_key + 1, node->private_key);
|
||||
} else {
|
||||
ecdsa_get_public_key33(node->curve->params, node->private_key, node->public_key);
|
||||
}
|
||||
@ -472,7 +472,7 @@ int hdnode_get_shared_key(const HDNode *node, const uint8_t *peer_public_key, ui
|
||||
if (peer_public_key[0] != 0x40) {
|
||||
return 1; // Curve25519 public key should start with 0x40 byte.
|
||||
}
|
||||
curve25519_donna(session_key + 1, node->private_key, peer_public_key + 1);
|
||||
curve25519_scalarmult(session_key + 1, node->private_key, peer_public_key + 1);
|
||||
*result_size = 33;
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -108,8 +108,8 @@ ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key
|
||||
Fast Curve25519 basepoint scalar multiplication
|
||||
*/
|
||||
void
|
||||
curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e) {
|
||||
curved25519_key ec;
|
||||
curve25519_scalarmult_basepoint(curve25519_key pk, const curve25519_key e) {
|
||||
curve25519_key ec;
|
||||
bignum256modm s;
|
||||
bignum25519 ALIGN(16) yplusz, zminusy;
|
||||
ge25519 ALIGN(16) p;
|
||||
@ -135,7 +135,7 @@ curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e) {
|
||||
}
|
||||
|
||||
void
|
||||
curve25519_donna(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint) {
|
||||
curve25519_scalarmult(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint) {
|
||||
curve25519_key e;
|
||||
size_t i;
|
||||
|
||||
@ -145,9 +145,3 @@ curve25519_donna(curve25519_key mypublic, const curve25519_key secret, const cur
|
||||
e[31] |= 0x40;
|
||||
curve25519_scalarmult_donna(mypublic, e, basepoint);
|
||||
}
|
||||
|
||||
void
|
||||
curve25519_donna_basepoint(curve25519_key mypublic, const curve25519_key secret) {
|
||||
static const curve25519_key basepoint = {9};
|
||||
curve25519_donna(mypublic, secret, basepoint);
|
||||
}
|
||||
|
@ -11,18 +11,12 @@ typedef unsigned char ed25519_secret_key[32];
|
||||
|
||||
typedef unsigned char curve25519_key[32];
|
||||
|
||||
typedef unsigned char curved25519_key[32];
|
||||
|
||||
void ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk);
|
||||
int ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS);
|
||||
void ed25519_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS);
|
||||
|
||||
int ed25519_sign_open_batch(const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid);
|
||||
|
||||
void curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e);
|
||||
|
||||
void curve25519_donna(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint);
|
||||
void curve25519_donna_basepoint(curve25519_key mypublic, const curve25519_key secret);
|
||||
void curve25519_scalarmult(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint);
|
||||
void curve25519_scalarmult_basepoint(curve25519_key mypublic, const curve25519_key secret);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ void bench_curve25519(void)
|
||||
|
||||
clock_t t = clock();
|
||||
for (int i = 0 ; i < 500; i++) {
|
||||
curve25519_donna(result, secret, basepoint);
|
||||
curve25519_scalarmult(result, secret, basepoint);
|
||||
}
|
||||
printf("Curve25519 multiplying speed: %0.2f mul/s\n", 500.0f / ((float)(clock() - t) / CLOCKS_PER_SEC));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user