2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2015-2016 Cryptography Research, Inc.
5 * Licensed under the Apache License 2.0 (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(
42 uint8_t pubkey [EDDSA_448_PUBLIC_BYTES],
43 const uint8_t privkey [EDDSA_448_PRIVATE_BYTES]);
48 * signature (out): The signature.
49 * privkey (in): The private key.
50 * pubkey (in): The public key.
51 * message (in): The message to sign.
52 * message_len (in): The length of the message.
53 * prehashed (in): Nonzero if the message is actually the hash of something
55 * context (in): A "context" for this signature of up to 255 bytes.
56 * context_len (in): Length of the context.
58 * For Ed25519, it is unsafe to use the same key for both prehashed and
59 * non-prehashed messages, at least without some very careful protocol-level
60 * disambiguation. For Ed448 it is safe.
62 c448_error_t c448_ed448_sign(
64 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
65 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
66 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
67 const uint8_t *message, size_t message_len,
68 uint8_t prehashed, const uint8_t *context,
72 * EdDSA signing with prehash.
74 * signature (out): The signature.
75 * privkey (in): The private key.
76 * pubkey (in): The public key.
77 * hash (in): The hash of the message. This object will not be modified by the
79 * context (in): A "context" for this signature of up to 255 bytes. Must be the
80 * same as what was used for the prehash.
81 * context_len (in): Length of the context.
83 * For Ed25519, it is unsafe to use the same key for both prehashed and
84 * non-prehashed messages, at least without some very careful protocol-level
85 * disambiguation. For Ed448 it is safe.
87 c448_error_t c448_ed448_sign_prehash(
89 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
90 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
91 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
92 const uint8_t hash[64],
93 const uint8_t *context,
97 * EdDSA signature verification.
99 * Uses the standard (i.e. less-strict) verification formula.
101 * signature (in): The signature.
102 * pubkey (in): The public key.
103 * message (in): The message to verify.
104 * message_len (in): The length of the message.
105 * prehashed (in): Nonzero if the message is actually the hash of something you
107 * context (in): A "context" for this signature of up to 255 bytes.
108 * context_len (in): Length of the context.
110 * For Ed25519, it is unsafe to use the same key for both prehashed and
111 * non-prehashed messages, at least without some very careful protocol-level
112 * disambiguation. For Ed448 it is safe.
114 c448_error_t c448_ed448_verify(OPENSSL_CTX *ctx,
116 signature[EDDSA_448_SIGNATURE_BYTES],
118 pubkey[EDDSA_448_PUBLIC_BYTES],
119 const uint8_t *message, size_t message_len,
120 uint8_t prehashed, const uint8_t *context,
121 uint8_t context_len);
124 * EdDSA signature verification.
126 * Uses the standard (i.e. less-strict) verification formula.
128 * signature (in): The signature.
129 * pubkey (in): The public key.
130 * hash (in): The hash of the message. This object will not be modified by the
132 * context (in): A "context" for this signature of up to 255 bytes. Must be the
133 * same as what was used for the prehash.
134 * context_len (in): Length of the context.
136 * For Ed25519, it is unsafe to use the same key for both prehashed and
137 * non-prehashed messages, at least without some very careful protocol-level
138 * disambiguation. For Ed448 it is safe.
140 c448_error_t c448_ed448_verify_prehash(
142 const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
143 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
144 const uint8_t hash[64],
145 const uint8_t *context,
146 uint8_t context_len);
149 * EdDSA point encoding. Used internally, exposed externally.
150 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
152 * The multiplication is required because the EdDSA encoding represents
153 * the cofactor information, but the Decaf encoding ignores it (which
154 * is the whole point). So if you decode from EdDSA and re-encode to
155 * EdDSA, the cofactor info must get cleared, because the intermediate
156 * representation doesn't track it.
158 * The way we handle this is to multiply by C448_EDDSA_DECODE_RATIO when
159 * decoding, and by C448_EDDSA_ENCODE_RATIO when encoding. The product of
160 * these ratios is always exactly the cofactor 4, so the cofactor ends up
161 * cleared one way or another. But exactly how that shakes out depends on the
162 * base points specified in RFC 8032.
164 * The upshot is that if you pass the Decaf/Ristretto base point to
165 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
168 * enc (out): The encoded point.
171 void curve448_point_mul_by_ratio_and_encode_like_eddsa(
172 uint8_t enc [EDDSA_448_PUBLIC_BYTES],
173 const curve448_point_t p);
176 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
177 * ignores cofactor information.
179 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
181 * enc (out): The encoded point.
184 c448_error_t curve448_point_decode_like_eddsa_and_mul_by_ratio(
186 const uint8_t enc[EDDSA_448_PUBLIC_BYTES]);
189 * EdDSA to ECDH private key conversion
190 * Using the appropriate hash function, hash the EdDSA private key
191 * and keep only the lower bytes to get the ECDH private key
193 * x (out): The ECDH private key as in RFC7748
194 * ed (in): The EdDSA private key
196 c448_error_t c448_ed448_convert_private_key_to_x448(
198 uint8_t x[X448_PRIVATE_BYTES],
199 const uint8_t ed[EDDSA_448_PRIVATE_BYTES]);
201 #endif /* HEADER_ED448_H */