testutils.c: Fix high bits of the mpz_urandomb used with mini-gmp.
[gd/nettle] / eddsa.h
1 /* eddsa.h
2
3    Copyright (C) 2014 Niels Möller
4
5    This file is part of GNU Nettle.
6
7    GNU Nettle is free software: you can redistribute it and/or
8    modify it under the terms of either:
9
10      * the GNU Lesser General Public License as published by the Free
11        Software Foundation; either version 3 of the License, or (at your
12        option) any later version.
13
14    or
15
16      * the GNU General Public License as published by the Free
17        Software Foundation; either version 2 of the License, or (at your
18        option) any later version.
19
20    or both in parallel, as here.
21
22    GNU Nettle is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25    General Public License for more details.
26
27    You should have received copies of the GNU General Public License and
28    the GNU Lesser General Public License along with this program.  If
29    not, see http://www.gnu.org/licenses/.
30 */
31
32 #ifndef NETTLE_EDDSA_H
33 #define NETTLE_EDDSA_H
34
35 #include "nettle-types.h"
36
37 #include "bignum.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /* Name mangling */
44 #define ed25519_sha512_set_private_key nettle_ed25519_sha512_set_private_key
45 #define ed25519_sha512_public_key nettle_ed25519_sha512_public_key
46 #define ed25519_sha512_sign nettle_ed25519_sha512_sign
47 #define ed25519_sha512_verify nettle_ed25519_sha512_verify
48
49 #define _eddsa_compress _nettle_eddsa_compress
50 #define _eddsa_compress_itch _nettle_eddsa_compress_itch
51 #define _eddsa_decompress _nettle_eddsa_decompress
52 #define _eddsa_decompress_itch _nettle_eddsa_decompress_itch
53 #define _eddsa_hash _nettle_eddsa_hash
54 #define _eddsa_expand_key _nettle_eddsa_expand_key
55 #define _eddsa_sign _nettle_eddsa_sign
56 #define _eddsa_sign_itch _nettle_eddsa_sign_itch
57 #define _eddsa_verify _nettle_eddsa_verify
58 #define _eddsa_verify_itch _nettle_eddsa_verify_itch
59 #define _eddsa_public_key_itch _nettle_eddsa_public_key_itch
60 #define _eddsa_public_key _nettle_eddsa_public_key
61
62 #define ED25519_KEY_SIZE 32
63 #define ED25519_SIGNATURE_SIZE 64
64
65 void
66 ed25519_sha512_public_key (uint8_t *pub, const uint8_t *priv);
67
68 void
69 ed25519_sha512_sign (const uint8_t *pub,
70                      const uint8_t *priv,                    
71                      size_t length, const uint8_t *msg,
72                      uint8_t *signature);
73
74 int
75 ed25519_sha512_verify (const uint8_t *pub,
76                        size_t length, const uint8_t *msg,
77                        const uint8_t *signature);
78
79 /* Low-level internal functions */
80
81 struct ecc_curve;
82 struct ecc_modulo;
83
84 mp_size_t
85 _eddsa_compress_itch (const struct ecc_curve *ecc);
86 void
87 _eddsa_compress (const struct ecc_curve *ecc, uint8_t *r, mp_limb_t *p,
88                  mp_limb_t *scratch);
89
90 mp_size_t
91 _eddsa_decompress_itch (const struct ecc_curve *ecc);
92 int
93 _eddsa_decompress (const struct ecc_curve *ecc, mp_limb_t *p,
94                    const uint8_t *cp,
95                    mp_limb_t *scratch);
96
97 void
98 _eddsa_hash (const struct ecc_modulo *m,
99              mp_limb_t *rp, const uint8_t *digest);
100
101 mp_size_t
102 _eddsa_sign_itch (const struct ecc_curve *ecc);
103
104 void
105 _eddsa_sign (const struct ecc_curve *ecc,
106              const struct nettle_hash *H,
107              const uint8_t *pub,
108              void *ctx,
109              const mp_limb_t *k2,
110              size_t length,
111              const uint8_t *msg,
112              uint8_t *signature,
113              mp_limb_t *scratch);
114
115 mp_size_t
116 _eddsa_verify_itch (const struct ecc_curve *ecc);
117
118 int
119 _eddsa_verify (const struct ecc_curve *ecc,
120                const struct nettle_hash *H,
121                const uint8_t *pub,
122                const mp_limb_t *A,
123                void *ctx,
124                size_t length,
125                const uint8_t *msg,
126                const uint8_t *signature,
127                mp_limb_t *scratch);
128
129 void
130 _eddsa_expand_key (const struct ecc_curve *ecc,
131                    const struct nettle_hash *H,
132                    void *ctx,
133                    const uint8_t *key,
134                    uint8_t *digest,
135                    mp_limb_t *k2);
136
137 mp_size_t
138 _eddsa_public_key_itch (const struct ecc_curve *ecc);
139
140 void
141 _eddsa_public_key (const struct ecc_curve *ecc,
142                    const mp_limb_t *k, uint8_t *pub, mp_limb_t *scratch);
143
144                            
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* NETTLE_EDDSA_H */