]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ec/curve448/ed448.h
Fix header file include guard names
[thirdparty/openssl.git] / crypto / ec / curve448 / ed448.h
CommitLineData
1308e022 1/*
f53c7764 2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
1308e022 3 * Copyright 2015-2016 Cryptography Research, Inc.
7324473f 4 *
a7f182b7 5 * Licensed under the Apache License 2.0 (the "License"). You may not use
1308e022
MC
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
7324473f 9 *
1308e022 10 * Originally written by Mike Hamburg
7324473f
MC
11 */
12
ae4186b0
DMSP
13#ifndef OSSL_CRYPTO_EC_CURVE448_ED448_H
14# define OSSL_CRYPTO_EC_CURVE448_ED448_H
7324473f 15
205fd638 16# include "point_448.h"
7324473f 17
8d55f844 18/* Number of bytes in an EdDSA public key. */
db90b274 19# define EDDSA_448_PUBLIC_BYTES 57
7324473f 20
8d55f844 21/* Number of bytes in an EdDSA private key. */
db90b274 22# define EDDSA_448_PRIVATE_BYTES EDDSA_448_PUBLIC_BYTES
7324473f 23
8d55f844 24/* Number of bytes in an EdDSA private key. */
db90b274
MC
25# define EDDSA_448_SIGNATURE_BYTES (EDDSA_448_PUBLIC_BYTES + \
26 EDDSA_448_PRIVATE_BYTES)
7324473f 27
8d55f844 28/* EdDSA encoding ratio. */
db90b274 29# define C448_EDDSA_ENCODE_RATIO 4
7324473f 30
8d55f844 31/* EdDSA decoding ratio. */
db90b274 32# define C448_EDDSA_DECODE_RATIO (4 / 4)
7324473f 33
8d55f844
MC
34/*
35 * EdDSA key generation. This function uses a different (non-Decaf) encoding.
7324473f 36 *
8d55f844
MC
37 * pubkey (out): The public key.
38 * privkey (in): The private key.
205fd638 39 */
aeeef83c 40c448_error_t c448_ed448_derive_public_key(
a9612d6c 41 OPENSSL_CTX *ctx,
db90b274
MC
42 uint8_t pubkey [EDDSA_448_PUBLIC_BYTES],
43 const uint8_t privkey [EDDSA_448_PRIVATE_BYTES]);
8d55f844
MC
44
45/*
46 * EdDSA signing.
47 *
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
54 * you want to sign.
55 * context (in): A "context" for this signature of up to 255 bytes.
56 * context_len (in): Length of the context.
57 *
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
53ef3252 60 * disambiguation. For Ed448 it is safe.
205fd638 61 */
aeeef83c 62c448_error_t c448_ed448_sign(
a9612d6c 63 OPENSSL_CTX *ctx,
db90b274
MC
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],
8d55f844
MC
67 const uint8_t *message, size_t message_len,
68 uint8_t prehashed, const uint8_t *context,
575d5afc 69 size_t context_len);
8d55f844
MC
70
71/*
72 * EdDSA signing with prehash.
73 *
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
78 * call.
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.
82 *
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
53ef3252 85 * disambiguation. For Ed448 it is safe.
205fd638 86 */
aeeef83c 87c448_error_t c448_ed448_sign_prehash(
a9612d6c 88 OPENSSL_CTX *ctx,
db90b274
MC
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],
8d55f844
MC
92 const uint8_t hash[64],
93 const uint8_t *context,
575d5afc 94 size_t context_len);
8d55f844
MC
95
96/*
97 * EdDSA signature verification.
7324473f
MC
98 *
99 * Uses the standard (i.e. less-strict) verification formula.
100 *
8d55f844
MC
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
106 * want to verify.
107 * context (in): A "context" for this signature of up to 255 bytes.
108 * context_len (in): Length of the context.
109 *
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
68b20c00 112 * disambiguation. For Ed448 it is safe.
7324473f 113 */
a9612d6c
MC
114c448_error_t c448_ed448_verify(OPENSSL_CTX *ctx,
115 const uint8_t
116 signature[EDDSA_448_SIGNATURE_BYTES],
117 const uint8_t
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);
7324473f 122
8d55f844
MC
123/*
124 * EdDSA signature verification.
7324473f
MC
125 *
126 * Uses the standard (i.e. less-strict) verification formula.
127 *
8d55f844
MC
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
131 * call.
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.
135 *
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
53ef3252 138 * disambiguation. For Ed448 it is safe.
7324473f 139 */
aeeef83c 140c448_error_t c448_ed448_verify_prehash(
a9612d6c 141 OPENSSL_CTX *ctx,
db90b274
MC
142 const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
143 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
8d55f844
MC
144 const uint8_t hash[64],
145 const uint8_t *context,
575d5afc 146 uint8_t context_len);
8d55f844
MC
147
148/*
149 * EdDSA point encoding. Used internally, exposed externally.
db90b274 150 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
7324473f
MC
151 *
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.
157 *
db90b274
MC
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
aeeef83c
MC
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.
7324473f
MC
163 *
164 * The upshot is that if you pass the Decaf/Ristretto base point to
db90b274 165 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
7324473f
MC
166 * EdDSA base point.
167 *
8d55f844
MC
168 * enc (out): The encoded point.
169 * p (in): The point.
205fd638 170 */
8d55f844 171void curve448_point_mul_by_ratio_and_encode_like_eddsa(
db90b274 172 uint8_t enc [EDDSA_448_PUBLIC_BYTES],
8d55f844 173 const curve448_point_t p);
7324473f 174
8d55f844 175/*
db90b274 176 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
8d55f844 177 * ignores cofactor information.
7324473f 178 *
e7772577 179 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
7324473f 180 *
8d55f844
MC
181 * enc (out): The encoded point.
182 * p (in): The point.
205fd638 183 */
aeeef83c 184c448_error_t curve448_point_decode_like_eddsa_and_mul_by_ratio(
8d55f844 185 curve448_point_t p,
db90b274 186 const uint8_t enc[EDDSA_448_PUBLIC_BYTES]);
8d55f844 187
8d55f844
MC
188/*
189 * EdDSA to ECDH private key conversion
7324473f
MC
190 * Using the appropriate hash function, hash the EdDSA private key
191 * and keep only the lower bytes to get the ECDH private key
192 *
8d55f844
MC
193 * x (out): The ECDH private key as in RFC7748
194 * ed (in): The EdDSA private key
7324473f 195 */
aeeef83c 196c448_error_t c448_ed448_convert_private_key_to_x448(
a9612d6c 197 OPENSSL_CTX *ctx,
db90b274
MC
198 uint8_t x[X448_PRIVATE_BYTES],
199 const uint8_t ed[EDDSA_448_PRIVATE_BYTES]);
7324473f 200
ae4186b0 201#endif /* OSSL_CRYPTO_EC_CURVE448_ED448_H */