]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ec/curve448/ed448.h
Update Curve448 copyright for 2018
[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 *
1308e022
MC
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
7324473f 9 *
1308e022 10 * Originally written by Mike Hamburg
7324473f
MC
11 */
12
aeeef83c
MC
13#ifndef __C448_ED448_H__
14# define __C448_ED448_H__ 1
7324473f 15
205fd638 16# include "point_448.h"
7324473f
MC
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
8d55f844 22/* Number of bytes in an EdDSA public key. */
db90b274 23# define EDDSA_448_PUBLIC_BYTES 57
7324473f 24
8d55f844 25/* Number of bytes in an EdDSA private key. */
db90b274 26# define EDDSA_448_PRIVATE_BYTES EDDSA_448_PUBLIC_BYTES
7324473f 27
8d55f844 28/* Number of bytes in an EdDSA private key. */
db90b274
MC
29# define EDDSA_448_SIGNATURE_BYTES (EDDSA_448_PUBLIC_BYTES + \
30 EDDSA_448_PRIVATE_BYTES)
7324473f 31
8d55f844 32/* EdDSA encoding ratio. */
db90b274 33# define C448_EDDSA_ENCODE_RATIO 4
7324473f 34
8d55f844 35/* EdDSA decoding ratio. */
db90b274 36# define C448_EDDSA_DECODE_RATIO (4 / 4)
7324473f 37
8d55f844
MC
38/*
39 * EdDSA key generation. This function uses a different (non-Decaf) encoding.
7324473f 40 *
8d55f844
MC
41 * pubkey (out): The public key.
42 * privkey (in): The private key.
205fd638 43 */
aeeef83c 44c448_error_t c448_ed448_derive_public_key(
db90b274
MC
45 uint8_t pubkey [EDDSA_448_PUBLIC_BYTES],
46 const uint8_t privkey [EDDSA_448_PRIVATE_BYTES]);
8d55f844
MC
47
48/*
49 * EdDSA signing.
50 *
51 * signature (out): The signature.
52 * privkey (in): The private key.
53 * pubkey (in): The public key.
54 * message (in): The message to sign.
55 * message_len (in): The length of the message.
56 * prehashed (in): Nonzero if the message is actually the hash of something
57 * you want to sign.
58 * context (in): A "context" for this signature of up to 255 bytes.
59 * context_len (in): Length of the context.
60 *
61 * For Ed25519, it is unsafe to use the same key for both prehashed and
62 * non-prehashed messages, at least without some very careful protocol-level
63 * disambiguation. For Ed448 it is safe. The C++ wrapper is designed to make
64 * it harder to screw this up, but this C code gives you no seat belt.
205fd638 65 */
aeeef83c 66c448_error_t c448_ed448_sign(
db90b274
MC
67 uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
68 const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],
69 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
8d55f844
MC
70 const uint8_t *message, size_t message_len,
71 uint8_t prehashed, const uint8_t *context,
575d5afc 72 size_t context_len);
8d55f844
MC
73
74/*
75 * EdDSA signing with prehash.
76 *
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
81 * call.
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.
85 *
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. The C++ wrapper is designed to make
89 * it harder to screw this up, but this C code gives you no seat belt.
205fd638 90 */
aeeef83c 91c448_error_t c448_ed448_sign_prehash(
db90b274
MC
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],
8d55f844
MC
95 const uint8_t hash[64],
96 const uint8_t *context,
575d5afc 97 size_t context_len);
8d55f844
MC
98
99/*
100 * EdDSA signature verification.
7324473f
MC
101 *
102 * Uses the standard (i.e. less-strict) verification formula.
103 *
8d55f844
MC
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
109 * want to verify.
110 * context (in): A "context" for this signature of up to 255 bytes.
111 * context_len (in): Length of the context.
112 *
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. The C++ wrapper is designed to make
116 * it harder to screw this up, but this C code gives you no seat belt.
7324473f 117 */
aeeef83c 118c448_error_t c448_ed448_verify(const uint8_t
db90b274 119 signature[EDDSA_448_SIGNATURE_BYTES],
205fd638 120 const uint8_t
db90b274 121 pubkey[EDDSA_448_PUBLIC_BYTES],
205fd638
MC
122 const uint8_t *message, size_t message_len,
123 uint8_t prehashed, const uint8_t *context,
575d5afc 124 uint8_t context_len);
7324473f 125
8d55f844
MC
126/*
127 * EdDSA signature verification.
7324473f
MC
128 *
129 * Uses the standard (i.e. less-strict) verification formula.
130 *
8d55f844
MC
131 * signature (in): The signature.
132 * pubkey (in): The public key.
133 * hash (in): The hash of the message. This object will not be modified by the
134 * call.
135 * context (in): A "context" for this signature of up to 255 bytes. Must be the
136 * same as what was used for the prehash.
137 * context_len (in): Length of the context.
138 *
139 * For Ed25519, it is unsafe to use the same key for both prehashed and
140 * non-prehashed messages, at least without some very careful protocol-level
141 * disambiguation. For Ed448 it is safe. The C++ wrapper is designed to make
142 * it harder to screw this up, but this C code gives you no seat belt.
7324473f 143 */
aeeef83c 144c448_error_t c448_ed448_verify_prehash(
db90b274
MC
145 const uint8_t signature[EDDSA_448_SIGNATURE_BYTES],
146 const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],
8d55f844
MC
147 const uint8_t hash[64],
148 const uint8_t *context,
575d5afc 149 uint8_t context_len);
8d55f844
MC
150
151/*
152 * EdDSA point encoding. Used internally, exposed externally.
db90b274 153 * Multiplies by C448_EDDSA_ENCODE_RATIO first.
7324473f
MC
154 *
155 * The multiplication is required because the EdDSA encoding represents
156 * the cofactor information, but the Decaf encoding ignores it (which
157 * is the whole point). So if you decode from EdDSA and re-encode to
158 * EdDSA, the cofactor info must get cleared, because the intermediate
159 * representation doesn't track it.
160 *
db90b274
MC
161 * The way we handle this is to multiply by C448_EDDSA_DECODE_RATIO when
162 * decoding, and by C448_EDDSA_ENCODE_RATIO when encoding. The product of
aeeef83c
MC
163 * these ratios is always exactly the cofactor 4, so the cofactor ends up
164 * cleared one way or another. But exactly how that shakes out depends on the
165 * base points specified in RFC 8032.
7324473f
MC
166 *
167 * The upshot is that if you pass the Decaf/Ristretto base point to
db90b274 168 * this function, you will get C448_EDDSA_ENCODE_RATIO times the
7324473f
MC
169 * EdDSA base point.
170 *
8d55f844
MC
171 * enc (out): The encoded point.
172 * p (in): The point.
205fd638 173 */
8d55f844 174void curve448_point_mul_by_ratio_and_encode_like_eddsa(
db90b274 175 uint8_t enc [EDDSA_448_PUBLIC_BYTES],
8d55f844 176 const curve448_point_t p);
7324473f 177
8d55f844 178/*
db90b274 179 * EdDSA point decoding. Multiplies by C448_EDDSA_DECODE_RATIO, and
8d55f844 180 * ignores cofactor information.
7324473f 181 *
e7772577 182 * See notes on curve448_point_mul_by_ratio_and_encode_like_eddsa
7324473f 183 *
8d55f844
MC
184 * enc (out): The encoded point.
185 * p (in): The point.
205fd638 186 */
aeeef83c 187c448_error_t curve448_point_decode_like_eddsa_and_mul_by_ratio(
8d55f844 188 curve448_point_t p,
db90b274 189 const uint8_t enc[EDDSA_448_PUBLIC_BYTES]);
8d55f844 190
8d55f844
MC
191/*
192 * EdDSA to ECDH private key conversion
7324473f
MC
193 * Using the appropriate hash function, hash the EdDSA private key
194 * and keep only the lower bytes to get the ECDH private key
195 *
8d55f844
MC
196 * x (out): The ECDH private key as in RFC7748
197 * ed (in): The EdDSA private key
7324473f 198 */
aeeef83c 199c448_error_t c448_ed448_convert_private_key_to_x448(
db90b274
MC
200 uint8_t x[X448_PRIVATE_BYTES],
201 const uint8_t ed[EDDSA_448_PRIVATE_BYTES]);
7324473f
MC
202
203#ifdef __cplusplus
204} /* extern "C" */
205#endif
206
aeeef83c 207#endif /* __C448_ED448_H__ */