solve warning issues
This commit is contained in:
parent
cbb7a43eda
commit
27e5b0d86e
|
@ -64,7 +64,8 @@ Creates a 32 byte random seed in `seed` for key generation. `seed` must be a
|
||||||
writable 32 byte buffer. Returns 0 on success, and nonzero on failure.
|
writable 32 byte buffer. Returns 0 on success, and nonzero on failure.
|
||||||
|
|
||||||
```c
|
```c
|
||||||
void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
|
void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key,
|
||||||
|
const unsigned char *seed);
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a new key pair from the given seed. `public_key` must be a writable 32
|
Creates a new key pair from the given seed. `public_key` must be a writable 32
|
||||||
|
|
|
@ -38,8 +38,8 @@ void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, c
|
||||||
} else {
|
} else {
|
||||||
/* unpack public key into T */
|
/* unpack public key into T */
|
||||||
ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
|
ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
|
||||||
fe_neg(public_key_unpacked.X, public_key_unpacked.X); // undo negate
|
fe_neg(public_key_unpacked.X, public_key_unpacked.X); /* undo negate */
|
||||||
fe_neg(public_key_unpacked.T, public_key_unpacked.T); // undo negate
|
fe_neg(public_key_unpacked.T, public_key_unpacked.T); /* undo negate */
|
||||||
ge_p3_to_cached(&T, &public_key_unpacked);
|
ge_p3_to_cached(&T, &public_key_unpacked);
|
||||||
|
|
||||||
/* calculate n*B */
|
/* calculate n*B */
|
||||||
|
|
|
@ -268,8 +268,8 @@ int sha512(const unsigned char *message, size_t message_len, unsigned char *out)
|
||||||
{
|
{
|
||||||
sha512_context ctx;
|
sha512_context ctx;
|
||||||
int ret;
|
int ret;
|
||||||
if (ret = sha512_init(&ctx)) return ret;
|
if ((ret = sha512_init(&ctx))) return ret;
|
||||||
if (ret = sha512_update(&ctx, message, message_len)) return ret;
|
if ((ret = sha512_update(&ctx, message, message_len))) return ret;
|
||||||
if (ret = sha512_final(&ctx, out)) return ret;
|
if ((ret = sha512_final(&ctx, out))) return ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
23
test.c
23
test.c
|
@ -3,16 +3,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
//#define ED25519_DLL
|
/* #define ED25519_DLL */
|
||||||
#include "src/ed25519.h"
|
#include "src/ed25519.h"
|
||||||
|
|
||||||
#include "src/ge.h"
|
#include "src/ge.h"
|
||||||
#include "src/sc.h"
|
#include "src/sc.h"
|
||||||
|
|
||||||
const char message[] = "Hello, world!";
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
unsigned char public_key[32], private_key[64], seed[32], scalar[32];
|
unsigned char public_key[32], private_key[64], seed[32], scalar[32];
|
||||||
unsigned char other_public_key[32], other_private_key[64];
|
unsigned char other_public_key[32], other_private_key[64];
|
||||||
unsigned char shared_secret[32], other_shared_secret[32];
|
unsigned char shared_secret[32], other_shared_secret[32];
|
||||||
|
@ -22,15 +20,18 @@ int main(int argc, char *argv[]) {
|
||||||
clock_t end;
|
clock_t end;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
const unsigned char message[] = "Hello, world!";
|
||||||
|
const int message_len = strlen((char*) message);
|
||||||
|
|
||||||
/* create a random seed, and a keypair out of that seed */
|
/* create a random seed, and a keypair out of that seed */
|
||||||
ed25519_create_seed(seed);
|
ed25519_create_seed(seed);
|
||||||
ed25519_create_keypair(public_key, private_key, seed);
|
ed25519_create_keypair(public_key, private_key, seed);
|
||||||
|
|
||||||
/* create signature on the message with the keypair */
|
/* create signature on the message with the keypair */
|
||||||
ed25519_sign(signature, message, strlen(message), public_key, private_key);
|
ed25519_sign(signature, message, message_len, public_key, private_key);
|
||||||
|
|
||||||
/* verify the signature */
|
/* verify the signature */
|
||||||
if (ed25519_verify(signature, message, strlen(message), public_key)) {
|
if (ed25519_verify(signature, message, message_len, public_key)) {
|
||||||
printf("valid signature\n");
|
printf("valid signature\n");
|
||||||
} else {
|
} else {
|
||||||
printf("invalid signature\n");
|
printf("invalid signature\n");
|
||||||
|
@ -41,10 +42,10 @@ int main(int argc, char *argv[]) {
|
||||||
ed25519_add_scalar(public_key, private_key, scalar);
|
ed25519_add_scalar(public_key, private_key, scalar);
|
||||||
|
|
||||||
/* create signature with the new keypair */
|
/* create signature with the new keypair */
|
||||||
ed25519_sign(signature, message, strlen(message), public_key, private_key);
|
ed25519_sign(signature, message, message_len, public_key, private_key);
|
||||||
|
|
||||||
/* verify the signature with the new keypair */
|
/* verify the signature with the new keypair */
|
||||||
if (ed25519_verify(signature, message, strlen(message), public_key)) {
|
if (ed25519_verify(signature, message, message_len, public_key)) {
|
||||||
printf("valid signature\n");
|
printf("valid signature\n");
|
||||||
} else {
|
} else {
|
||||||
printf("invalid signature\n");
|
printf("invalid signature\n");
|
||||||
|
@ -52,7 +53,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
/* make a slight adjustment and verify again */
|
/* make a slight adjustment and verify again */
|
||||||
signature[44] ^= 0x10;
|
signature[44] ^= 0x10;
|
||||||
if (ed25519_verify(signature, message, strlen(message), public_key)) {
|
if (ed25519_verify(signature, message, message_len, public_key)) {
|
||||||
printf("did not detect signature change\n");
|
printf("did not detect signature change\n");
|
||||||
} else {
|
} else {
|
||||||
printf("correctly detected signature change\n");
|
printf("correctly detected signature change\n");
|
||||||
|
@ -102,7 +103,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("testing sign performance: ");
|
printf("testing sign performance: ");
|
||||||
start = clock();
|
start = clock();
|
||||||
for (i = 0; i < 10000; ++i) {
|
for (i = 0; i < 10000; ++i) {
|
||||||
ed25519_sign(signature, message, strlen(message), public_key, private_key);
|
ed25519_sign(signature, message, message_len, public_key, private_key);
|
||||||
}
|
}
|
||||||
end = clock();
|
end = clock();
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("testing verify performance: ");
|
printf("testing verify performance: ");
|
||||||
start = clock();
|
start = clock();
|
||||||
for (i = 0; i < 10000; ++i) {
|
for (i = 0; i < 10000; ++i) {
|
||||||
ed25519_verify(signature, message, strlen(message), public_key);
|
ed25519_verify(signature, message, message_len, public_key);
|
||||||
}
|
}
|
||||||
end = clock();
|
end = clock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue