Branch data Line data Source code
1 : : #include "compact_ed25519.h"
2 : :
3 : : #ifndef COMPACT_DISABLE_ED25519
4 : : #include "c25519/edsign.h"
5 : : #include "compact_wipe.h"
6 : : #include <string.h>
7 : :
8 : : #define __PUBLIC_KEY_OFFSET (32)
9 : :
10 : 0 : void compact_ed25519_keygen(
11 : : uint8_t private_key[ED25519_PRIVATE_KEY_SIZE],
12 : : uint8_t public_key[ED25519_PUBLIC_KEY_SIZE],
13 : : uint8_t random_seed[ED25519_SEED_SIZE]
14 : : ) {
15 : : // private key is seed + public key, like golang and others
16 : 0 : edsign_sec_to_pub(public_key, random_seed);
17 : 0 : memcpy(private_key, random_seed, ED25519_SEED_SIZE);
18 : 0 : memcpy(private_key + __PUBLIC_KEY_OFFSET, public_key, ED25519_PUBLIC_KEY_SIZE);
19 : 0 : compact_wipe(random_seed, ED25519_SEED_SIZE);
20 : 0 : }
21 : :
22 : 0 : void compact_ed25519_calc_public_key(
23 : : uint8_t public_key[ED25519_PUBLIC_KEY_SIZE],
24 : : const uint8_t private_key[ED25519_PRIVATE_KEY_SIZE]
25 : : ) {
26 : 0 : memcpy(public_key, private_key + __PUBLIC_KEY_OFFSET, ED25519_PUBLIC_KEY_SIZE);
27 : 0 : }
28 : :
29 : 0 : void compact_ed25519_sign(
30 : : uint8_t signature[ED25519_SIGNATURE_SIZE],
31 : : const uint8_t private_key[ED25519_PRIVATE_KEY_SIZE],
32 : : const void *message,
33 : : size_t msg_length
34 : : ) {
35 : 0 : edsign_sign(signature, private_key + __PUBLIC_KEY_OFFSET, private_key, message, msg_length);
36 : 0 : }
37 : :
38 : 0 : bool compact_ed25519_verify(
39 : : const uint8_t signature[ED25519_SIGNATURE_SIZE],
40 : : const uint8_t public_key[ED25519_PUBLIC_KEY_SIZE],
41 : : const void *message,
42 : : size_t msg_length
43 : : ) {
44 : 0 : return edsign_verify(signature, public_key, message, msg_length) != 0;
45 : : }
46 : : #endif
|