1 2 #include <string.h> 3 4 #include "crypto_hash_sha512.h" 5 #include "crypto_sign_ed25519.h" 6 #include "ref10/sign_ed25519_ref10.h" 7 8 size_t 9 crypto_sign_ed25519ph_statebytes(void) 10 { 11 return sizeof(crypto_sign_ed25519ph_state); 12 } 13 14 size_t 15 crypto_sign_ed25519_bytes(void) 16 { 17 return crypto_sign_ed25519_BYTES; 18 } 19 20 size_t 21 crypto_sign_ed25519_seedbytes(void) 22 { 23 return crypto_sign_ed25519_SEEDBYTES; 24 } 25 26 size_t 27 crypto_sign_ed25519_publickeybytes(void) 28 { 29 return crypto_sign_ed25519_PUBLICKEYBYTES; 30 } 31 32 size_t 33 crypto_sign_ed25519_secretkeybytes(void) 34 { 35 return crypto_sign_ed25519_SECRETKEYBYTES; 36 } 37 38 size_t 39 crypto_sign_ed25519_messagebytes_max(void) 40 { 41 return crypto_sign_ed25519_MESSAGEBYTES_MAX; 42 } 43 44 int 45 crypto_sign_ed25519_sk_to_seed(unsigned char *seed, const unsigned char *sk) 46 { 47 memmove(seed, sk, crypto_sign_ed25519_SEEDBYTES); 48 49 return 0; 50 } 51 52 int 53 crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk) 54 { 55 memmove(pk, sk + crypto_sign_ed25519_SEEDBYTES, 56 crypto_sign_ed25519_PUBLICKEYBYTES); 57 return 0; 58 } 59 60 int 61 crypto_sign_ed25519ph_init(crypto_sign_ed25519ph_state *state) 62 { 63 crypto_hash_sha512_init(&state->hs); 64 return 0; 65 } 66 67 int 68 crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state, 69 const unsigned char *m, unsigned long long mlen) 70 { 71 return crypto_hash_sha512_update(&state->hs, m, mlen); 72 } 73 74 int 75 crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state, 76 unsigned char *sig, 77 unsigned long long *siglen_p, 78 const unsigned char *sk) 79 { 80 unsigned char ph[crypto_hash_sha512_BYTES]; 81 82 crypto_hash_sha512_final(&state->hs, ph); 83 84 return _crypto_sign_ed25519_detached(sig, siglen_p, ph, sizeof ph, sk, 1); 85 } 86 87 int 88 crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state, 89 unsigned char *sig, 90 const unsigned char *pk) 91 { 92 unsigned char ph[crypto_hash_sha512_BYTES]; 93 94 crypto_hash_sha512_final(&state->hs, ph); 95 96 return _crypto_sign_ed25519_verify_detached(sig, ph, sizeof ph, pk, 1); 97 } 98