2 * Copyright 2017-2020 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 OSSL_CRYPTO_EC_CURVE448_ED448_H
14 # define OSSL_CRYPTO_EC_CURVE448_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],
49 * signature (out): The signature.
50 * privkey (in): The private key.
51 * pubkey (in): The public key.
52 * message (in): The message to sign.
53 * message_len (in): The length of the message.
54 * prehashed (in): Nonzero if the message is actually the hash of something
56 * context (in): A "context" for this signature of up to 255 bytes.
57 * context_len (in): Length of the context.
59 * For Ed25519, it is unsafe to use the same key for both prehashed and
60 * non-prehashed messages, at least without some very careful protocol-level
61 * disambiguation. For Ed448 it is safe.
63 c448_error_t c448_ed448_sign(
65 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
66 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
67 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
68 const uint8_t *message, size_t message_len,
69 uint8_t prehashed, const uint8_t *context,
74 * EdDSA signing with prehash.
76 * signature (out): The signature.
77 * privkey (in): The private key.
78 * pubkey (in): The public key.
79 * hash (in): The hash of the message. This object will not be modified by the
81 * context (in): A "context" for this signature of up to 255 bytes. Must be the
82 * same as what was used for the prehash.
83 * context_len (in): Length of the context.
85 * For Ed25519, it is unsafe to use the same key for both prehashed and
86 * non-prehashed messages, at least without some very careful protocol-level
87 * disambiguation. For Ed448 it is safe.
89 c448_error_t c448_ed448_sign_prehash(
91 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
92 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
93 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
94 const uint8_t hash[64],
95 const uint8_t *context,
100 * EdDSA signature verification.
102 * Uses the standard (i.e. less-strict) verification formula.
104 * signature (in): The signature.
105 * pubkey (in): The public key.
106 * message (in): The message to verify.
107 * message_len (in): The length of the message.
108 * prehashed (in): Nonzero if the message is actually the hash of something you
110 * context (in): A "context" for this signature of up to 255 bytes.
111 * context_len (in): Length of the context.
113 * For Ed25519, it is unsafe to use the same key for both prehashed and
114 * non-prehashed messages, at least without some very careful protocol-level
115 * disambiguation. For Ed448 it is safe.
117 c448_error_t c448_ed448_verify(OSSL_LIB_CTX *ctx,
119 signature[EDDSA_448_SIGNATURE_BYTES],
121 pubkey[EDDSA_448_PUBLIC_BYTES],
122 const uint8_t *message, size_t message_len,
123 uint8_t prehashed, const uint8_t *context,
128 * EdDSA signature verification.
130 * Uses the standard (i.e. less-strict) verification formula.
132 * signature (in): The signature.
133 * pubkey (in): The public key.
134 * hash (in): The hash of the message. This object will not be modified by the
136 * context (in): A "context" for this signature of up to 255 bytes. Must be the
137 * same as what was used for the prehash.
138 * context_len (in): Length of the context.
140 * For Ed25519, it is unsafe to use the same key for both prehashed and
141 * non-prehashed messages, at least without some very careful protocol-level
142 * disambiguation. For Ed448 it is safe.
144 c448_error_t c448_ed448_verify_prehash(
146 const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
147 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
148 const uint8_t hash[64],
149 const uint8_t *context,
154 * EdDSA point encoding. Used internally, exposed externally.
155 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
157 * The multiplication is required because the EdDSA encoding represents
158 * the cofactor information, but the Decaf encoding ignores it (which
159 * is the whole point). So if you decode from EdDSA and re-encode to
160 * EdDSA, the cofactor info must get cleared, because the intermediate
161 * representation doesn't track it.
163 * The way we handle this is to multiply by C448_EDDSA_DECODE_RATIO when
164 * decoding, and by C448_EDDSA_ENCODE_RATIO when encoding. The product of
165 * these ratios is always exactly the cofactor 4, so the cofactor ends up
166 * cleared one way or another. But exactly how that shakes out depends on the
167 * base points specified in RFC 8032.
169 * The upshot is that if you pass the Decaf/Ristretto base point to
170 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
173 * enc (out): The encoded point.
176 void curve448_point_mul_by_ratio_and_encode_like_eddsa(
177 uint8_t enc [EDDSA_448_PUBLIC_BYTES],
178 const curve448_point_t p);
181 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
182 * ignores cofactor information.
184 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
186 * enc (out): The encoded point.
189 c448_error_t curve448_point_decode_like_eddsa_and_mul_by_ratio(
191 const uint8_t enc[EDDSA_448_PUBLIC_BYTES]);
194 * EdDSA to ECDH private key conversion
195 * Using the appropriate hash function, hash the EdDSA private key
196 * and keep only the lower bytes to get the ECDH private key
198 * x (out): The ECDH private key as in RFC7748
199 * ed (in): The EdDSA private key
201 c448_error_t c448_ed448_convert_private_key_to_x448(
203 uint8_t x[X448_PRIVATE_BYTES],
204 const uint8_t ed[EDDSA_448_PRIVATE_BYTES],
207 #endif /* OSSL_CRYPTO_EC_CURVE448_ED448_H */