2 * Copyright 2017-2021 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.
41 ossl_c448_ed448_derive_public_key(
43 uint8_t pubkey
[EDDSA_448_PUBLIC_BYTES
],
44 const uint8_t privkey
[EDDSA_448_PRIVATE_BYTES
],
50 * signature (out): The signature.
51 * privkey (in): The private key.
52 * pubkey (in): The public key.
53 * message (in): The message to sign.
54 * message_len (in): The length of the message.
55 * prehashed (in): Nonzero if the message is actually the hash of something
57 * context (in): A "context" for this signature of up to 255 bytes.
58 * context_len (in): Length of the context.
60 * For Ed25519, it is unsafe to use the same key for both prehashed and
61 * non-prehashed messages, at least without some very careful protocol-level
62 * disambiguation. For Ed448 it is safe.
65 ossl_c448_ed448_sign(OSSL_LIB_CTX
*ctx
,
66 uint8_t signature
[EDDSA_448_SIGNATURE_BYTES
],
67 const uint8_t privkey
[EDDSA_448_PRIVATE_BYTES
],
68 const uint8_t pubkey
[EDDSA_448_PUBLIC_BYTES
],
69 const uint8_t *message
, size_t message_len
,
70 uint8_t prehashed
, const uint8_t *context
,
75 * EdDSA signing with prehash.
77 * signature (out): The signature.
78 * privkey (in): The private key.
79 * pubkey (in): The public key.
80 * hash (in): The hash of the message. This object will not be modified by the
82 * context (in): A "context" for this signature of up to 255 bytes. Must be the
83 * same as what was used for the prehash.
84 * context_len (in): Length of the context.
86 * For Ed25519, it is unsafe to use the same key for both prehashed and
87 * non-prehashed messages, at least without some very careful protocol-level
88 * disambiguation. For Ed448 it is safe.
91 ossl_c448_ed448_sign_prehash(OSSL_LIB_CTX
*ctx
,
92 uint8_t signature
[EDDSA_448_SIGNATURE_BYTES
],
93 const uint8_t privkey
[EDDSA_448_PRIVATE_BYTES
],
94 const uint8_t pubkey
[EDDSA_448_PUBLIC_BYTES
],
95 const uint8_t hash
[64],
96 const uint8_t *context
,
101 * EdDSA signature verification.
103 * Uses the standard (i.e. less-strict) verification formula.
105 * signature (in): The signature.
106 * pubkey (in): The public key.
107 * message (in): The message to verify.
108 * message_len (in): The length of the message.
109 * prehashed (in): Nonzero if the message is actually the hash of something you
111 * context (in): A "context" for this signature of up to 255 bytes.
112 * context_len (in): Length of the context.
114 * For Ed25519, it is unsafe to use the same key for both prehashed and
115 * non-prehashed messages, at least without some very careful protocol-level
116 * disambiguation. For Ed448 it is safe.
119 ossl_c448_ed448_verify(OSSL_LIB_CTX
*ctx
,
121 signature
[EDDSA_448_SIGNATURE_BYTES
],
123 pubkey
[EDDSA_448_PUBLIC_BYTES
],
124 const uint8_t *message
, size_t message_len
,
125 uint8_t prehashed
, const uint8_t *context
,
130 * EdDSA signature verification.
132 * Uses the standard (i.e. less-strict) verification formula.
134 * signature (in): The signature.
135 * pubkey (in): The public key.
136 * hash (in): The hash of the message. This object will not be modified by the
138 * context (in): A "context" for this signature of up to 255 bytes. Must be the
139 * same as what was used for the prehash.
140 * context_len (in): Length of the context.
142 * For Ed25519, it is unsafe to use the same key for both prehashed and
143 * non-prehashed messages, at least without some very careful protocol-level
144 * disambiguation. For Ed448 it is safe.
147 ossl_c448_ed448_verify_prehash(
149 const uint8_t signature
[EDDSA_448_SIGNATURE_BYTES
],
150 const uint8_t pubkey
[EDDSA_448_PUBLIC_BYTES
],
151 const uint8_t hash
[64],
152 const uint8_t *context
,
157 * EdDSA point encoding. Used internally, exposed externally.
158 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
160 * The multiplication is required because the EdDSA encoding represents
161 * the cofactor information, but the Decaf encoding ignores it (which
162 * is the whole point). So if you decode from EdDSA and re-encode to
163 * EdDSA, the cofactor info must get cleared, because the intermediate
164 * representation doesn't track it.
166 * The way we handle this is to multiply by C448_EDDSA_DECODE_RATIO when
167 * decoding, and by C448_EDDSA_ENCODE_RATIO when encoding. The product of
168 * these ratios is always exactly the cofactor 4, so the cofactor ends up
169 * cleared one way or another. But exactly how that shakes out depends on the
170 * base points specified in RFC 8032.
172 * The upshot is that if you pass the Decaf/Ristretto base point to
173 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
176 * enc (out): The encoded point.
180 ossl_curve448_point_mul_by_ratio_and_encode_like_eddsa(
181 uint8_t enc
[EDDSA_448_PUBLIC_BYTES
],
182 const curve448_point_t p
);
185 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
186 * ignores cofactor information.
188 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
190 * enc (out): The encoded point.
194 ossl_curve448_point_decode_like_eddsa_and_mul_by_ratio(
196 const uint8_t enc
[EDDSA_448_PUBLIC_BYTES
]);
199 * EdDSA to ECDH private key conversion
200 * Using the appropriate hash function, hash the EdDSA private key
201 * and keep only the lower bytes to get the ECDH private key
203 * x (out): The ECDH private key as in RFC7748
204 * ed (in): The EdDSA private key
207 ossl_c448_ed448_convert_private_key_to_x448(
209 uint8_t x
[X448_PRIVATE_BYTES
],
210 const uint8_t ed
[EDDSA_448_PRIVATE_BYTES
],
213 #endif /* OSSL_CRYPTO_EC_CURVE448_ED448_H */