changed readme and test with performance figures

This commit is contained in:
Orson Peters 2013-02-04 13:42:59 +01:00
parent b0de745a0c
commit 08c56cd2dc
2 changed files with 36 additions and 25 deletions

View File

@ -5,35 +5,35 @@ This is a portable implementation of [Ed25519](http://ed25519.cr.yp.to/) based
on the SUPERCOP "ref10" implementation. All code is in the public domain. on the SUPERCOP "ref10" implementation. All code is in the public domain.
All code is pure ANSI C without any dependencies, except for the random seed All code is pure ANSI C without any dependencies, except for the random seed
generation which uses standard OS cryptography APIs. If you wish to be generation which uses standard OS cryptography APIs. If you wish to be entirely
entirely portable define `ED25519_NO_SEED`. This does disable the portable define `ED25519_NO_SEED`. This does disable the `ed25519_create_seed`
`ed25519_create_seed` function however you can use your own seeding function function however you can use your own seeding function if you wish.
if you wish.
Performance Performance
----------- -----------
On a machine with an Intel Q6600 @ 2.4GHz I got the following speeds (running on only one thread): On a machine with an Intel Q6600 @ 2.4GHz I got the following speeds (running
on only one thread):
Key generation: 280us Seed + key generation: 345us
Message signing: 280us Message signing (short message): 256us
Message verifying: 840us Message verifying (short message): 777us
The speeds on other machines may vary. The speeds on other machines may vary. Sign/verify times will be higher with
longer messages.
Usage Usage
----- -----
Simply add all .c and .h files in the `src/` folder to your project and Simply add all .c and .h files in the `src/` folder to your project and include
include `ed25519.h` in any file you want to use the API. If you prefer to use `ed25519.h` in any file you want to use the API. If you prefer to use a shared
a shared library, only copy `ed25519.h` and define `ED25519_DLL` before library, only copy `ed25519.h` and define `ED25519_DLL` before importing. A
importing. A windows DLL is pre-built. windows DLL is pre-built.
There are no defined types for seeds, private keys, public keys or There are no defined types for seeds, private keys, public keys or signatures.
signatures. Instead simple `unsigned char` buffers are used with the following Instead simple `unsigned char` buffers are used with the following sizes:
sizes:
```c ```c
unsigned char seed[32]; unsigned char seed[32];
@ -48,6 +48,7 @@ API
```c ```c
int ed25519_create_seed(unsigned char *seed); int ed25519_create_seed(unsigned char *seed);
``` ```
Creates a 32 byte random seed in `seed` for key generation. `seed` must be a 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.
@ -56,7 +57,8 @@ void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_ke
``` ```
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
byte buffer, `private_key` must be a writable 64 byte buffer and `seed` must be a 32 byte buffer. byte buffer, `private_key` must be a writable 64 byte buffer and `seed` must be
a 32 byte buffer.
```c ```c
void ed25519_sign(unsigned char *signature, void ed25519_sign(unsigned char *signature,
@ -64,9 +66,10 @@ void ed25519_sign(unsigned char *signature,
const unsigned char *public_key, const unsigned char *private_key); const unsigned char *public_key, const unsigned char *private_key);
``` ```
Creates a signature of the given message with the keypair `(public_key, private_key)`. `signature` must be Creates a signature of the given message with the keypair `(public_key,
a writable 64 byte buffer. `message` must have at least `message_len` bytes to private_key)`. `signature` must be a writable 64 byte buffer. `message` must
be read. The given keypair must be a keypair generated by `ed25519_create_keypair`. have at least `message_len` bytes to be read. The given keypair must be a
keypair generated by `ed25519_create_keypair`.
```c ```c
int ed25519_verify(const unsigned char *signature, int ed25519_verify(const unsigned char *signature,
@ -74,9 +77,9 @@ int ed25519_verify(const unsigned char *signature,
const unsigned char *public_key); const unsigned char *public_key);
``` ```
Verifies the signature on the given message using `public_key`. `signature` must be Verifies the signature on the given message using `public_key`. `signature`
a readable 64 byte buffer. `message` must have at least `message_len` bytes to must be a readable 64 byte buffer. `message` must have at least `message_len`
be read. `public_key` must be a 32 byte public key generated by bytes to be read. `public_key` must be a 32 byte public key generated by
`ed25519_create_keypair`. Returns 1 if the signature matches, 0 otherwise. `ed25519_create_keypair`. Returns 1 if the signature matches, 0 otherwise.
Example Example

12
test.c
View File

@ -16,8 +16,6 @@ int main(int argc, char *argv[]) {
clock_t end; clock_t end;
int i; int i;
FILE *f;
/* 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);
@ -41,6 +39,16 @@ int main(int argc, char *argv[]) {
} }
/* test performance */ /* test performance */
printf("testing key generation performance: ");
start = clock();
for (i = 0; i < 10000; ++i) {
ed25519_create_seed(seed);
ed25519_create_keypair(public_key, private_key, seed);
}
end = clock();
printf("%fus per seed and keypair\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
printf("testing sign performance: "); printf("testing sign performance: ");
start = clock(); start = clock();
for (i = 0; i < 10000; ++i) { for (i = 0; i < 10000; ++i) {