2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2015-2016 Cryptography Research, Inc.
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
10 * Originally written by Mike Hamburg
13 #ifndef HEADER_ED448_H
14 # define HEADER_ED448_H
16 # include "point_448.h"
18 /* Number of bytes in an EdDSA public key. */
19 # define EDDSA_448_PUBLIC_BYTES 57
21 /* Number of bytes in an EdDSA private key. */
22 # define EDDSA_448_PRIVATE_BYTES EDDSA_448_PUBLIC_BYTES
24 /* Number of bytes in an EdDSA private key. */
25 # define EDDSA_448_SIGNATURE_BYTES (EDDSA_448_PUBLIC_BYTES + \
26 EDDSA_448_PRIVATE_BYTES)
28 /* EdDSA encoding ratio. */
29 # define C448_EDDSA_ENCODE_RATIO 4
31 /* EdDSA decoding ratio. */
32 # define C448_EDDSA_DECODE_RATIO (4 / 4)
35 * EdDSA key generation. This function uses a different (non-Decaf) encoding.
37 * pubkey (out): The public key.
38 * privkey (in): The private key.
40 c448_error_t c448_ed448_derive_public_key(
41 uint8_t pubkey [EDDSA_448_PUBLIC_BYTES],
42 const uint8_t privkey [EDDSA_448_PRIVATE_BYTES]);
47 * signature (out): The signature.
48 * privkey (in): The private key.
49 * pubkey (in): The public key.
50 * message (in): The message to sign.
51 * message_len (in): The length of the message.
52 * prehashed (in): Nonzero if the message is actually the hash of something
54 * context (in): A "context" for this signature of up to 255 bytes.
55 * context_len (in): Length of the context.
57 * For Ed25519, it is unsafe to use the same key for both prehashed and
58 * non-prehashed messages, at least without some very careful protocol-level
59 * disambiguation. For Ed448 it is safe. The C++ wrapper is designed to make
60 * it harder to screw this up, but this C code gives you no seat belt.
62 c448_error_t c448_ed448_sign(
63 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
64 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
65 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
66 const uint8_t *message, size_t message_len,
67 uint8_t prehashed, const uint8_t *context,
71 * EdDSA signing with prehash.
73 * signature (out): The signature.
74 * privkey (in): The private key.
75 * pubkey (in): The public key.
76 * hash (in): The hash of the message. This object will not be modified by the
78 * context (in): A "context" for this signature of up to 255 bytes. Must be the
79 * same as what was used for the prehash.
80 * context_len (in): Length of the context.
82 * For Ed25519, it is unsafe to use the same key for both prehashed and
83 * non-prehashed messages, at least without some very careful protocol-level
84 * disambiguation. For Ed448 it is safe. The C++ wrapper is designed to make
85 * it harder to screw this up, but this C code gives you no seat belt.
87 c448_error_t c448_ed448_sign_prehash(
88 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
89 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
90 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
91 const uint8_t hash[64],
92 const uint8_t *context,
96 * EdDSA signature verification.
98 * Uses the standard (i.e. less-strict) verification formula.
100 * signature (in): The signature.
101 * pubkey (in): The public key.
102 * message (in): The message to verify.
103 * message_len (in): The length of the message.
104 * prehashed (in): Nonzero if the message is actually the hash of something you
106 * context (in): A "context" for this signature of up to 255 bytes.
107 * context_len (in): Length of the context.
109 * For Ed25519, it is unsafe to use the same key for both prehashed and
110 * non-prehashed messages, at least without some very careful protocol-level
111 * disambiguation. For Ed448 it is safe.
113 c448_error_t c448_ed448_verify(const uint8_t
114 signature[EDDSA_448_SIGNATURE_BYTES],
116 pubkey[EDDSA_448_PUBLIC_BYTES],
117 const uint8_t *message, size_t message_len,
118 uint8_t prehashed, const uint8_t *context,
119 uint8_t context_len);
122 * EdDSA signature verification.
124 * Uses the standard (i.e. less-strict) verification formula.
126 * signature (in): The signature.
127 * pubkey (in): The public key.
128 * hash (in): The hash of the message. This object will not be modified by the
130 * context (in): A "context" for this signature of up to 255 bytes. Must be the
131 * same as what was used for the prehash.
132 * context_len (in): Length of the context.
134 * For Ed25519, it is unsafe to use the same key for both prehashed and
135 * non-prehashed messages, at least without some very careful protocol-level
136 * disambiguation. For Ed448 it is safe. The C++ wrapper is designed to make
137 * it harder to screw this up, but this C code gives you no seat belt.
139 c448_error_t c448_ed448_verify_prehash(
140 const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
141 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
142 const uint8_t hash[64],
143 const uint8_t *context,
144 uint8_t context_len);
147 * EdDSA point encoding. Used internally, exposed externally.
148 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
150 * The multiplication is required because the EdDSA encoding represents
151 * the cofactor information, but the Decaf encoding ignores it (which
152 * is the whole point). So if you decode from EdDSA and re-encode to
153 * EdDSA, the cofactor info must get cleared, because the intermediate
154 * representation doesn't track it.
156 * The way we handle this is to multiply by C448_EDDSA_DECODE_RATIO when
157 * decoding, and by C448_EDDSA_ENCODE_RATIO when encoding. The product of
158 * these ratios is always exactly the cofactor 4, so the cofactor ends up
159 * cleared one way or another. But exactly how that shakes out depends on the
160 * base points specified in RFC 8032.
162 * The upshot is that if you pass the Decaf/Ristretto base point to
163 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
166 * enc (out): The encoded point.
169 void curve448_point_mul_by_ratio_and_encode_like_eddsa(
170 uint8_t enc [EDDSA_448_PUBLIC_BYTES],
171 const curve448_point_t p);
174 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
175 * ignores cofactor information.
177 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
179 * enc (out): The encoded point.
182 c448_error_t curve448_point_decode_like_eddsa_and_mul_by_ratio(
184 const uint8_t enc[EDDSA_448_PUBLIC_BYTES]);
187 * EdDSA to ECDH private key conversion
188 * Using the appropriate hash function, hash the EdDSA private key
189 * and keep only the lower bytes to get the ECDH private key
191 * x (out): The ECDH private key as in RFC7748
192 * ed (in): The EdDSA private key
194 c448_error_t c448_ed448_convert_private_key_to_x448(
195 uint8_t x[X448_PRIVATE_BYTES],
196 const uint8_t ed[EDDSA_448_PRIVATE_BYTES]);
198 #endif /* HEADER_ED448_H */