Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] */ |
| 56 | |
| 57 | #ifndef OPENSSL_HEADER_EVP_H |
| 58 | #define OPENSSL_HEADER_EVP_H |
| 59 | |
| 60 | #include <openssl/base.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 61 | |
Adam Langley | 0da323a | 2015-05-15 12:49:30 -0700 | [diff] [blame] | 62 | #include <openssl/thread.h> |
| 63 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 64 | /* OpenSSL included digest and cipher functions in this header so we include |
Adam Langley | fd772a5 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 65 | * them for users that still expect that. |
| 66 | * |
| 67 | * TODO(fork): clean up callers so that they include what they use. */ |
| 68 | #include <openssl/aead.h> |
Matt Braithwaite | 5acf6b5 | 2015-08-03 11:18:11 -0700 | [diff] [blame] | 69 | #include <openssl/base64.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 70 | #include <openssl/cipher.h> |
| 71 | #include <openssl/digest.h> |
David Benjamin | 9819367 | 2016-03-25 18:07:11 -0400 | [diff] [blame] | 72 | #include <openssl/nid.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 73 | |
| 74 | #if defined(__cplusplus) |
| 75 | extern "C" { |
| 76 | #endif |
| 77 | |
| 78 | |
| 79 | /* EVP abstracts over public/private key algorithms. */ |
| 80 | |
| 81 | |
| 82 | /* Public key objects. */ |
| 83 | |
| 84 | /* EVP_PKEY_new creates a new, empty public-key object and returns it or NULL |
| 85 | * on allocation failure. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 86 | OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 87 | |
| 88 | /* EVP_PKEY_free frees all data referenced by |pkey| and then frees |pkey| |
| 89 | * itself. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 90 | OPENSSL_EXPORT void EVP_PKEY_free(EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 91 | |
Adam Langley | 310d3f6 | 2016-07-12 10:39:20 -0700 | [diff] [blame] | 92 | /* EVP_PKEY_up_ref increments the reference count of |pkey| and returns one. */ |
| 93 | OPENSSL_EXPORT int EVP_PKEY_up_ref(EVP_PKEY *pkey); |
Adam Langley | 517da2f | 2015-05-05 10:27:54 -0700 | [diff] [blame] | 94 | |
David Benjamin | ecc0ce7 | 2014-07-18 18:39:42 -0400 | [diff] [blame] | 95 | /* EVP_PKEY_is_opaque returns one if |pkey| is opaque. Opaque keys are backed by |
| 96 | * custom implementations which do not expose key material and parameters. It is |
| 97 | * an error to attempt to duplicate, export, or compare an opaque key. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 98 | OPENSSL_EXPORT int EVP_PKEY_is_opaque(const EVP_PKEY *pkey); |
David Benjamin | ecc0ce7 | 2014-07-18 18:39:42 -0400 | [diff] [blame] | 99 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 100 | /* EVP_PKEY_cmp compares |a| and |b| and returns one if they are equal, zero if |
| 101 | * not and a negative number on error. |
| 102 | * |
| 103 | * WARNING: this differs from the traditional return value of a "cmp" |
| 104 | * function. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 105 | OPENSSL_EXPORT int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 106 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 107 | /* EVP_PKEY_copy_parameters sets the parameters of |to| to equal the parameters |
| 108 | * of |from|. It returns one on success and zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 109 | OPENSSL_EXPORT int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 110 | |
| 111 | /* EVP_PKEY_missing_parameters returns one if |pkey| is missing needed |
| 112 | * parameters or zero if not, or if the algorithm doesn't take parameters. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 113 | OPENSSL_EXPORT int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 114 | |
David Benjamin | 0673215 | 2015-03-18 16:30:04 -0400 | [diff] [blame] | 115 | /* EVP_PKEY_size returns the maximum size, in bytes, of a signature signed by |
| 116 | * |pkey|. For an RSA key, this returns the number of bytes needed to represent |
| 117 | * the modulus. For an EC key, this returns the maximum size of a DER-encoded |
| 118 | * ECDSA signature. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 119 | OPENSSL_EXPORT int EVP_PKEY_size(const EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 120 | |
David Benjamin | 0673215 | 2015-03-18 16:30:04 -0400 | [diff] [blame] | 121 | /* EVP_PKEY_bits returns the "size", in bits, of |pkey|. For an RSA key, this |
| 122 | * returns the bit length of the modulus. For an EC key, this returns the bit |
| 123 | * length of the group order. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 124 | OPENSSL_EXPORT int EVP_PKEY_bits(EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 125 | |
| 126 | /* EVP_PKEY_id returns the type of |pkey|, which is one of the |EVP_PKEY_*| |
| 127 | * values. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 128 | OPENSSL_EXPORT int EVP_PKEY_id(const EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 129 | |
David Benjamin | f6094e0 | 2015-12-29 17:14:33 -0500 | [diff] [blame] | 130 | /* EVP_PKEY_type returns |nid| if |nid| is a known key type and |NID_undef| |
| 131 | * otherwise. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 132 | OPENSSL_EXPORT int EVP_PKEY_type(int nid); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 133 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | |
| 135 | /* Getting and setting concrete public key types. |
| 136 | * |
| 137 | * The following functions get and set the underlying public key in an |
Adam Langley | 389e3f0 | 2014-08-19 11:24:27 -0700 | [diff] [blame] | 138 | * |EVP_PKEY| object. The |set1| functions take an additional reference to the |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 139 | * underlying key and return one on success or zero on error. The |assign| |
David Benjamin | 758d127 | 2015-11-20 17:47:25 -0500 | [diff] [blame] | 140 | * functions adopt the caller's reference. The |get1| functions return a fresh |
| 141 | * reference to the underlying object or NULL if |pkey| is not of the correct |
| 142 | * type. The |get0| functions behave the same but return a non-owning |
| 143 | * pointer. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 144 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 145 | OPENSSL_EXPORT int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key); |
| 146 | OPENSSL_EXPORT int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key); |
David Benjamin | 758d127 | 2015-11-20 17:47:25 -0500 | [diff] [blame] | 147 | OPENSSL_EXPORT RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey); |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 148 | OPENSSL_EXPORT RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 149 | |
David Benjamin | e6d1e5a | 2015-11-06 16:13:40 -0500 | [diff] [blame] | 150 | OPENSSL_EXPORT int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key); |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 151 | OPENSSL_EXPORT int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key); |
David Benjamin | 758d127 | 2015-11-20 17:47:25 -0500 | [diff] [blame] | 152 | OPENSSL_EXPORT DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey); |
David Benjamin | e6d1e5a | 2015-11-06 16:13:40 -0500 | [diff] [blame] | 153 | OPENSSL_EXPORT DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 154 | |
David Benjamin | e6d1e5a | 2015-11-06 16:13:40 -0500 | [diff] [blame] | 155 | OPENSSL_EXPORT int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 156 | OPENSSL_EXPORT int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); |
David Benjamin | 758d127 | 2015-11-20 17:47:25 -0500 | [diff] [blame] | 157 | OPENSSL_EXPORT EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); |
David Benjamin | e6d1e5a | 2015-11-06 16:13:40 -0500 | [diff] [blame] | 158 | OPENSSL_EXPORT EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 159 | |
David Benjamin | 05bb1c5 | 2017-03-27 21:55:52 -0500 | [diff] [blame] | 160 | /* EVP_PKEY_new_ed25519_public returns a newly allocated |EVP_PKEY| wrapping an |
| 161 | * Ed25519 public key, or NULL on allocation error. */ |
| 162 | OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_ed25519_public( |
| 163 | const uint8_t public_key[32]); |
| 164 | |
| 165 | /* EVP_PKEY_new_ed25519_private returns a newly allocated |EVP_PKEY| wrapping an |
| 166 | * Ed25519 private key, or NULL on allocation error. */ |
| 167 | OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_ed25519_private( |
| 168 | const uint8_t private_key[64]); |
| 169 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 170 | #define EVP_PKEY_NONE NID_undef |
| 171 | #define EVP_PKEY_RSA NID_rsaEncryption |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 172 | #define EVP_PKEY_DSA NID_dsa |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 173 | #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 174 | #define EVP_PKEY_ED25519 NID_ED25519 |
David Benjamin | e9e3837 | 2014-12-23 12:26:22 -0500 | [diff] [blame] | 175 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 176 | /* EVP_PKEY_assign sets the underlying key of |pkey| to |key|, which must be of |
| 177 | * the given type. The |type| argument should be one of the |EVP_PKEY_*| |
| 178 | * values. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 179 | OPENSSL_EXPORT int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 180 | |
| 181 | /* EVP_PKEY_set_type sets the type of |pkey| to |type|, which should be one of |
David Benjamin | 1d6eeb3 | 2017-01-08 05:15:58 -0500 | [diff] [blame] | 182 | * the |EVP_PKEY_*| values. It returns one if successful or zero otherwise. If |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 183 | * |pkey| is NULL, it simply reports whether the type is known. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 184 | OPENSSL_EXPORT int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 185 | |
| 186 | /* EVP_PKEY_cmp_parameters compares the parameters of |a| and |b|. It returns |
| 187 | * one if they match, zero if not, or a negative number of on error. |
| 188 | * |
| 189 | * WARNING: the return value differs from the usual return value convention. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 190 | OPENSSL_EXPORT int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, |
| 191 | const EVP_PKEY *b); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 192 | |
| 193 | |
| 194 | /* ASN.1 functions */ |
| 195 | |
David Benjamin | 68772b3 | 2015-12-30 21:40:40 -0500 | [diff] [blame] | 196 | /* EVP_parse_public_key decodes a DER-encoded SubjectPublicKeyInfo structure |
| 197 | * (RFC 5280) from |cbs| and advances |cbs|. It returns a newly-allocated |
| 198 | * |EVP_PKEY| or NULL on error. |
| 199 | * |
| 200 | * The caller must check the type of the parsed public key to ensure it is |
| 201 | * suitable and validate other desired key properties such as RSA modulus size |
| 202 | * or EC curve. */ |
| 203 | OPENSSL_EXPORT EVP_PKEY *EVP_parse_public_key(CBS *cbs); |
| 204 | |
| 205 | /* EVP_marshal_public_key marshals |key| as a DER-encoded SubjectPublicKeyInfo |
| 206 | * structure (RFC 5280) and appends the result to |cbb|. It returns one on |
| 207 | * success and zero on error. */ |
| 208 | OPENSSL_EXPORT int EVP_marshal_public_key(CBB *cbb, const EVP_PKEY *key); |
| 209 | |
David Benjamin | e30a09e | 2016-01-01 01:17:30 -0500 | [diff] [blame] | 210 | /* EVP_parse_private_key decodes a DER-encoded PrivateKeyInfo structure (RFC |
| 211 | * 5208) from |cbs| and advances |cbs|. It returns a newly-allocated |EVP_PKEY| |
| 212 | * or NULL on error. |
| 213 | * |
| 214 | * The caller must check the type of the parsed private key to ensure it is |
| 215 | * suitable and validate other desired key properties such as RSA modulus size |
| 216 | * or EC curve. |
| 217 | * |
| 218 | * A PrivateKeyInfo ends with an optional set of attributes. These are not |
| 219 | * processed and so this function will silently ignore any trailing data in the |
| 220 | * structure. */ |
| 221 | OPENSSL_EXPORT EVP_PKEY *EVP_parse_private_key(CBS *cbs); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 222 | |
David Benjamin | e30a09e | 2016-01-01 01:17:30 -0500 | [diff] [blame] | 223 | /* EVP_marshal_private_key marshals |key| as a DER-encoded PrivateKeyInfo |
| 224 | * structure (RFC 5208) and appends the result to |cbb|. It returns one on |
| 225 | * success and zero on error. */ |
| 226 | OPENSSL_EXPORT int EVP_marshal_private_key(CBB *cbb, const EVP_PKEY *key); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 227 | |
David Benjamin | 1d59f6e | 2017-05-09 19:04:11 -0400 | [diff] [blame] | 228 | /* EVP_set_buggy_rsa_parser configures whether |RSA_parse_public_key_buggy| is |
| 229 | * used by |EVP_parse_public_key|. By default, it is used. */ |
| 230 | OPENSSL_EXPORT void EVP_set_buggy_rsa_parser(int buggy); |
| 231 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 232 | |
| 233 | /* Signing */ |
| 234 | |
| 235 | /* EVP_DigestSignInit sets up |ctx| for a signing operation with |type| and |
| 236 | * |pkey|. The |ctx| argument must have been initialised with |
| 237 | * |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing |
| 238 | * operation will be written to |*pctx|; this can be used to set alternative |
| 239 | * signing options. |
| 240 | * |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 241 | * For single-shot signing algorithms which do not use a pre-hash, such as |
| 242 | * Ed25519, |type| should be NULL. The |EVP_MD_CTX| itself is unused but is |
| 243 | * present so the API is uniform. See |EVP_DigestSign|. |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 244 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 245 | * It returns one on success, or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 246 | OPENSSL_EXPORT int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, |
| 247 | const EVP_MD *type, ENGINE *e, |
| 248 | EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 249 | |
| 250 | /* EVP_DigestSignUpdate appends |len| bytes from |data| to the data which will |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 251 | * be signed in |EVP_DigestSignFinal|. It returns one. |
| 252 | * |
| 253 | * This function performs a streaming signing operation and will fail for |
| 254 | * signature algorithms which do not support this. Use |EVP_DigestSign| for a |
| 255 | * single-shot operation. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 256 | OPENSSL_EXPORT int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, |
| 257 | size_t len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 258 | |
| 259 | /* EVP_DigestSignFinal signs the data that has been included by one or more |
| 260 | * calls to |EVP_DigestSignUpdate|. If |out_sig| is NULL then |*out_sig_len| is |
| 261 | * set to the maximum number of output bytes. Otherwise, on entry, |
| 262 | * |*out_sig_len| must contain the length of the |out_sig| buffer. If the call |
| 263 | * is successful, the signature is written to |out_sig| and |*out_sig_len| is |
| 264 | * set to its length. |
| 265 | * |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 266 | * This function performs a streaming signing operation and will fail for |
| 267 | * signature algorithms which do not support this. Use |EVP_DigestSign| for a |
| 268 | * single-shot operation. |
| 269 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 270 | * It returns one on success, or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 271 | OPENSSL_EXPORT int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, |
| 272 | size_t *out_sig_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 273 | |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 274 | /* EVP_DigestSign signs |data_len| bytes from |data| using |ctx|. If |out_sig| |
| 275 | * is NULL then |*out_sig_len| is set to the maximum number of output |
| 276 | * bytes. Otherwise, on entry, |*out_sig_len| must contain the length of the |
| 277 | * |out_sig| buffer. If the call is successful, the signature is written to |
| 278 | * |out_sig| and |*out_sig_len| is set to its length. |
| 279 | * |
| 280 | * It returns one on success and zero on error. */ |
| 281 | OPENSSL_EXPORT int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, |
| 282 | size_t *out_sig_len, const uint8_t *data, |
| 283 | size_t data_len); |
| 284 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 285 | |
| 286 | /* Verifying */ |
| 287 | |
| 288 | /* EVP_DigestVerifyInit sets up |ctx| for a signature verification operation |
| 289 | * with |type| and |pkey|. The |ctx| argument must have been initialised with |
| 290 | * |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing |
| 291 | * operation will be written to |*pctx|; this can be used to set alternative |
| 292 | * signing options. |
| 293 | * |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 294 | * For single-shot signing algorithms which do not use a pre-hash, such as |
| 295 | * Ed25519, |type| should be NULL. The |EVP_MD_CTX| itself is unused but is |
| 296 | * present so the API is uniform. See |EVP_DigestVerify|. |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 297 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 298 | * It returns one on success, or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 299 | OPENSSL_EXPORT int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, |
| 300 | const EVP_MD *type, ENGINE *e, |
| 301 | EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 302 | |
| 303 | /* EVP_DigestVerifyUpdate appends |len| bytes from |data| to the data which |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 304 | * will be verified by |EVP_DigestVerifyFinal|. It returns one. |
| 305 | * |
| 306 | * This function performs streaming signature verification and will fail for |
| 307 | * signature algorithms which do not support this. Use |EVP_PKEY_verify_message| |
| 308 | * for a single-shot verification. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 309 | OPENSSL_EXPORT int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, |
| 310 | size_t len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 311 | |
| 312 | /* EVP_DigestVerifyFinal verifies that |sig_len| bytes of |sig| are a valid |
| 313 | * signature for the data that has been included by one or more calls to |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 314 | * |EVP_DigestVerifyUpdate|. It returns one on success and zero otherwise. |
| 315 | * |
| 316 | * This function performs streaming signature verification and will fail for |
| 317 | * signature algorithms which do not support this. Use |EVP_PKEY_verify_message| |
| 318 | * for a single-shot verification. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 319 | OPENSSL_EXPORT int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 320 | size_t sig_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 321 | |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 322 | /* EVP_DigestVerify verifies that |sig_len| bytes from |sig| are a valid |
| 323 | * signature for |data|. It returns one on success or zero on error. */ |
| 324 | OPENSSL_EXPORT int EVP_DigestVerify(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 325 | size_t sig_len, const uint8_t *data, |
| 326 | size_t len); |
| 327 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 328 | |
| 329 | /* Signing (old functions) */ |
| 330 | |
| 331 | /* EVP_SignInit_ex configures |ctx|, which must already have been initialised, |
| 332 | * for a fresh signing operation using the hash function |type|. It returns one |
| 333 | * on success and zero otherwise. |
| 334 | * |
| 335 | * (In order to initialise |ctx|, either obtain it initialised with |
| 336 | * |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 337 | OPENSSL_EXPORT int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, |
| 338 | ENGINE *impl); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 339 | |
| 340 | /* EVP_SignInit is a deprecated version of |EVP_SignInit_ex|. |
| 341 | * |
| 342 | * TODO(fork): remove. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 343 | OPENSSL_EXPORT int EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 344 | |
| 345 | /* EVP_SignUpdate appends |len| bytes from |data| to the data which will be |
| 346 | * signed in |EVP_SignFinal|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 347 | OPENSSL_EXPORT int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *data, |
| 348 | size_t len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 349 | |
| 350 | /* EVP_SignFinal signs the data that has been included by one or more calls to |
| 351 | * |EVP_SignUpdate|, using the key |pkey|, and writes it to |sig|. On entry, |
| 352 | * |sig| must point to at least |EVP_PKEY_size(pkey)| bytes of space. The |
| 353 | * actual size of the signature is written to |*out_sig_len|. |
| 354 | * |
| 355 | * It returns one on success and zero otherwise. |
| 356 | * |
| 357 | * It does not modify |ctx|, thus it's possible to continue to use |ctx| in |
| 358 | * order to sign a longer message. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 359 | OPENSSL_EXPORT int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig, |
| 360 | unsigned int *out_sig_len, EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 361 | |
| 362 | |
| 363 | /* Verifying (old functions) */ |
| 364 | |
| 365 | /* EVP_VerifyInit_ex configures |ctx|, which must already have been |
| 366 | * initialised, for a fresh signature verification operation using the hash |
| 367 | * function |type|. It returns one on success and zero otherwise. |
| 368 | * |
| 369 | * (In order to initialise |ctx|, either obtain it initialised with |
| 370 | * |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 371 | OPENSSL_EXPORT int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, |
| 372 | ENGINE *impl); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 373 | |
| 374 | /* EVP_VerifyInit is a deprecated version of |EVP_VerifyInit_ex|. |
| 375 | * |
| 376 | * TODO(fork): remove. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 377 | OPENSSL_EXPORT int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 378 | |
| 379 | /* EVP_VerifyUpdate appends |len| bytes from |data| to the data which will be |
| 380 | * signed in |EVP_VerifyFinal|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 381 | OPENSSL_EXPORT int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *data, |
| 382 | size_t len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 383 | |
| 384 | /* EVP_VerifyFinal verifies that |sig_len| bytes of |sig| are a valid |
| 385 | * signature, by |pkey|, for the data that has been included by one or more |
| 386 | * calls to |EVP_VerifyUpdate|. |
| 387 | * |
| 388 | * It returns one on success and zero otherwise. |
| 389 | * |
| 390 | * It does not modify |ctx|, thus it's possible to continue to use |ctx| in |
| 391 | * order to sign a longer message. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 392 | OPENSSL_EXPORT int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 393 | size_t sig_len, EVP_PKEY *pkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 394 | |
| 395 | |
| 396 | /* Printing */ |
| 397 | |
| 398 | /* EVP_PKEY_print_public prints a textual representation of the public key in |
| 399 | * |pkey| to |out|. Returns one on success or zero otherwise. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 400 | OPENSSL_EXPORT int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, |
| 401 | int indent, ASN1_PCTX *pctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 402 | |
Kenny Root | 3a9e1fb | 2015-06-10 14:52:40 -0700 | [diff] [blame] | 403 | /* EVP_PKEY_print_private prints a textual representation of the private key in |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 404 | * |pkey| to |out|. Returns one on success or zero otherwise. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 405 | OPENSSL_EXPORT int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, |
| 406 | int indent, ASN1_PCTX *pctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 407 | |
Kenny Root | 3a9e1fb | 2015-06-10 14:52:40 -0700 | [diff] [blame] | 408 | /* EVP_PKEY_print_params prints a textual representation of the parameters in |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 409 | * |pkey| to |out|. Returns one on success or zero otherwise. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 410 | OPENSSL_EXPORT int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, |
| 411 | int indent, ASN1_PCTX *pctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 412 | |
| 413 | |
| 414 | /* Password stretching. |
| 415 | * |
| 416 | * Password stretching functions take a low-entropy password and apply a slow |
| 417 | * function that results in a key suitable for use in symmetric |
| 418 | * cryptography. */ |
| 419 | |
| 420 | /* PKCS5_PBKDF2_HMAC computes |iterations| iterations of PBKDF2 of |password| |
| 421 | * and |salt|, using |digest|, and outputs |key_len| bytes to |out_key|. It |
| 422 | * returns one on success and zero on error. */ |
Eric Roman | 4dcb057 | 2015-01-20 12:19:13 -0800 | [diff] [blame] | 423 | OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len, |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 424 | const uint8_t *salt, size_t salt_len, |
| 425 | unsigned iterations, const EVP_MD *digest, |
| 426 | size_t key_len, uint8_t *out_key); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 427 | |
| 428 | /* PKCS5_PBKDF2_HMAC_SHA1 is the same as PKCS5_PBKDF2_HMAC, but with |digest| |
| 429 | * fixed to |EVP_sha1|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 430 | OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC_SHA1(const char *password, |
David Benjamin | 1d6eeb3 | 2017-01-08 05:15:58 -0500 | [diff] [blame] | 431 | size_t password_len, |
| 432 | const uint8_t *salt, size_t salt_len, |
| 433 | unsigned iterations, size_t key_len, |
| 434 | uint8_t *out_key); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 435 | |
David Benjamin | b529253 | 2017-06-09 19:27:37 -0400 | [diff] [blame] | 436 | /* EVP_PBE_scrypt expands |password| into a secret key of length |key_len| using |
| 437 | * scrypt, as described in RFC 7914, and writes the result to |out_key|. It |
| 438 | * returns one on success and zero on error. |
| 439 | * |
| 440 | * |N|, |r|, and |p| are as described in RFC 7914 section 6. They determine the |
| 441 | * cost of the operation. If the memory required exceeds |max_mem|, the |
| 442 | * operation will fail instead. If |max_mem| is zero, a defult limit of 32MiB |
| 443 | * will be used. */ |
| 444 | OPENSSL_EXPORT int EVP_PBE_scrypt(const char *password, size_t password_len, |
| 445 | const uint8_t *salt, size_t salt_len, |
| 446 | uint64_t N, uint64_t r, uint64_t p, |
| 447 | size_t max_mem, uint8_t *out_key, |
| 448 | size_t key_len); |
| 449 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 450 | |
| 451 | /* Public key contexts. |
| 452 | * |
| 453 | * |EVP_PKEY_CTX| objects hold the context of an operation (e.g. signing or |
| 454 | * encrypting) that uses a public key. */ |
| 455 | |
| 456 | /* EVP_PKEY_CTX_new allocates a fresh |EVP_PKEY_CTX| for use with |pkey|. It |
| 457 | * returns the context or NULL on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 458 | OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 459 | |
Kenny Root | 3a9e1fb | 2015-06-10 14:52:40 -0700 | [diff] [blame] | 460 | /* EVP_PKEY_CTX_new_id allocates a fresh |EVP_PKEY_CTX| for a key of type |id| |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 461 | * (e.g. |EVP_PKEY_HMAC|). This can be used for key generation where |
| 462 | * |EVP_PKEY_CTX_new| can't be used because there isn't an |EVP_PKEY| to pass |
| 463 | * it. It returns the context or NULL on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 464 | OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 465 | |
Kenny Root | 3a9e1fb | 2015-06-10 14:52:40 -0700 | [diff] [blame] | 466 | /* EVP_PKEY_CTX_free frees |ctx| and the data it owns. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 467 | OPENSSL_EXPORT void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 468 | |
| 469 | /* EVP_PKEY_CTX_dup allocates a fresh |EVP_PKEY_CTX| and sets it equal to the |
| 470 | * state of |ctx|. It returns the fresh |EVP_PKEY_CTX| or NULL on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 471 | OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 472 | |
| 473 | /* EVP_PKEY_CTX_get0_pkey returns the |EVP_PKEY| associated with |ctx|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 474 | OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 475 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 476 | /* EVP_PKEY_sign_init initialises an |EVP_PKEY_CTX| for a signing operation. It |
| 477 | * should be called before |EVP_PKEY_sign|. |
| 478 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 479 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 480 | OPENSSL_EXPORT int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 481 | |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 482 | /* EVP_PKEY_sign signs |digest_len| bytes from |digest| using |ctx|. If |sig| is |
David Benjamin | 9b561e6 | 2014-07-09 11:47:42 -0400 | [diff] [blame] | 483 | * NULL, the maximum size of the signature is written to |
| 484 | * |out_sig_len|. Otherwise, |*sig_len| must contain the number of bytes of |
| 485 | * space available at |sig|. If sufficient, the signature will be written to |
| 486 | * |sig| and |*sig_len| updated with the true length. |
| 487 | * |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 488 | * This function expects a pre-hashed input and will fail for signature |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 489 | * algorithms which do not support this. Use |EVP_DigestSignInit| to sign an |
| 490 | * unhashed input. |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 491 | * |
David Benjamin | e167976 | 2014-10-28 16:06:56 -0400 | [diff] [blame] | 492 | * WARNING: Setting |sig| to NULL only gives the maximum size of the |
| 493 | * signature. The actual signature may be smaller. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 494 | * |
| 495 | * It returns one on success or zero on error. (Note: this differs from |
| 496 | * OpenSSL, which can also return negative values to indicate an error. ) */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 497 | OPENSSL_EXPORT int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 498 | size_t *sig_len, const uint8_t *digest, |
| 499 | size_t digest_len); |
| 500 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 501 | /* EVP_PKEY_verify_init initialises an |EVP_PKEY_CTX| for a signature |
| 502 | * verification operation. It should be called before |EVP_PKEY_verify|. |
| 503 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 504 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 505 | OPENSSL_EXPORT int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 506 | |
David Benjamin | 1d6eeb3 | 2017-01-08 05:15:58 -0500 | [diff] [blame] | 507 | /* EVP_PKEY_verify verifies that |sig_len| bytes from |sig| are a valid |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 508 | * signature for |digest|. |
| 509 | * |
| 510 | * This function expects a pre-hashed input and will fail for signature |
David Benjamin | 1967094 | 2017-05-31 19:07:31 -0400 | [diff] [blame] | 511 | * algorithms which do not support this. Use |EVP_DigestVerifyInit| to verify a |
| 512 | * signature given the unhashed input. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 513 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 514 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 515 | OPENSSL_EXPORT int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig, |
David Benjamin | 7c83fda | 2017-03-28 13:54:06 -0500 | [diff] [blame] | 516 | size_t sig_len, const uint8_t *digest, |
| 517 | size_t digest_len); |
| 518 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 519 | /* EVP_PKEY_encrypt_init initialises an |EVP_PKEY_CTX| for an encryption |
| 520 | * operation. It should be called before |EVP_PKEY_encrypt|. |
| 521 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 522 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 523 | OPENSSL_EXPORT int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 524 | |
David Benjamin | 9b561e6 | 2014-07-09 11:47:42 -0400 | [diff] [blame] | 525 | /* EVP_PKEY_encrypt encrypts |in_len| bytes from |in|. If |out| is NULL, the |
| 526 | * maximum size of the ciphertext is written to |out_len|. Otherwise, |*out_len| |
| 527 | * must contain the number of bytes of space available at |out|. If sufficient, |
| 528 | * the ciphertext will be written to |out| and |*out_len| updated with the true |
| 529 | * length. |
| 530 | * |
| 531 | * WARNING: Setting |out| to NULL only gives the maximum size of the |
| 532 | * ciphertext. The actual ciphertext may be smaller. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 533 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 534 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 535 | OPENSSL_EXPORT int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 536 | size_t *out_len, const uint8_t *in, |
| 537 | size_t in_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 538 | |
| 539 | /* EVP_PKEY_decrypt_init initialises an |EVP_PKEY_CTX| for a decryption |
| 540 | * operation. It should be called before |EVP_PKEY_decrypt|. |
| 541 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 542 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 543 | OPENSSL_EXPORT int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 544 | |
David Benjamin | 9b561e6 | 2014-07-09 11:47:42 -0400 | [diff] [blame] | 545 | /* EVP_PKEY_decrypt decrypts |in_len| bytes from |in|. If |out| is NULL, the |
| 546 | * maximum size of the plaintext is written to |out_len|. Otherwise, |*out_len| |
| 547 | * must contain the number of bytes of space available at |out|. If sufficient, |
| 548 | * the ciphertext will be written to |out| and |*out_len| updated with the true |
| 549 | * length. |
| 550 | * |
| 551 | * WARNING: Setting |out| to NULL only gives the maximum size of the |
| 552 | * plaintext. The actual plaintext may be smaller. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 553 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 554 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 555 | OPENSSL_EXPORT int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 556 | size_t *out_len, const uint8_t *in, |
| 557 | size_t in_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 558 | |
Adam Langley | ce9d85e | 2016-01-24 15:58:39 -0800 | [diff] [blame] | 559 | /* EVP_PKEY_verify_recover_init initialises an |EVP_PKEY_CTX| for a public-key |
| 560 | * decryption operation. It should be called before |EVP_PKEY_verify_recover|. |
| 561 | * |
| 562 | * Public-key decryption is a very obscure operation that is only implemented |
| 563 | * by RSA keys. It is effectively a signature verification operation that |
| 564 | * returns the signed message directly. It is almost certainly not what you |
| 565 | * want. |
| 566 | * |
| 567 | * It returns one on success or zero on error. */ |
| 568 | OPENSSL_EXPORT int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); |
| 569 | |
| 570 | /* EVP_PKEY_verify_recover decrypts |sig_len| bytes from |sig|. If |out| is |
| 571 | * NULL, the maximum size of the plaintext is written to |out_len|. Otherwise, |
| 572 | * |*out_len| must contain the number of bytes of space available at |out|. If |
| 573 | * sufficient, the ciphertext will be written to |out| and |*out_len| updated |
| 574 | * with the true length. |
| 575 | * |
| 576 | * WARNING: Setting |out| to NULL only gives the maximum size of the |
| 577 | * plaintext. The actual plaintext may be smaller. |
| 578 | * |
| 579 | * See the warning about this operation in |EVP_PKEY_verify_recover_init|. It |
| 580 | * is probably not what you want. |
| 581 | * |
| 582 | * It returns one on success or zero on error. */ |
| 583 | OPENSSL_EXPORT int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 584 | size_t *out_len, const uint8_t *sig, |
| 585 | size_t siglen); |
| 586 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 587 | /* EVP_PKEY_derive_init initialises an |EVP_PKEY_CTX| for a key derivation |
| 588 | * operation. It should be called before |EVP_PKEY_derive_set_peer| and |
| 589 | * |EVP_PKEY_derive|. |
| 590 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 591 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 592 | OPENSSL_EXPORT int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 593 | |
| 594 | /* EVP_PKEY_derive_set_peer sets the peer's key to be used for key derivation |
| 595 | * by |ctx| to |peer|. It should be called after |EVP_PKEY_derive_init|. (For |
| 596 | * example, this is used to set the peer's key in (EC)DH.) It returns one on |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 597 | * success and zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 598 | OPENSSL_EXPORT int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 599 | |
| 600 | /* EVP_PKEY_derive derives a shared key between the two keys configured in |
| 601 | * |ctx|. If |key| is non-NULL then, on entry, |out_key_len| must contain the |
| 602 | * amount of space at |key|. If sufficient then the shared key will be written |
| 603 | * to |key| and |*out_key_len| will be set to the length. If |key| is NULL then |
David Benjamin | 9b561e6 | 2014-07-09 11:47:42 -0400 | [diff] [blame] | 604 | * |out_key_len| will be set to the maximum length. |
| 605 | * |
| 606 | * WARNING: Setting |out| to NULL only gives the maximum size of the key. The |
| 607 | * actual key may be smaller. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 608 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 609 | * It returns one on success and zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 610 | OPENSSL_EXPORT int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, uint8_t *key, |
| 611 | size_t *out_key_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 612 | |
| 613 | /* EVP_PKEY_keygen_init initialises an |EVP_PKEY_CTX| for a key generation |
| 614 | * operation. It should be called before |EVP_PKEY_keygen|. |
| 615 | * |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 616 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 617 | OPENSSL_EXPORT int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 618 | |
| 619 | /* EVP_PKEY_keygen performs a key generation operation using the values from |
| 620 | * |ctx| and sets |*ppkey| to a fresh |EVP_PKEY| containing the resulting key. |
Adam Langley | 5129e2d | 2014-07-25 10:06:44 -0700 | [diff] [blame] | 621 | * It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 622 | OPENSSL_EXPORT int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 623 | |
| 624 | |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 625 | /* Generic control functions. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 626 | |
| 627 | /* EVP_PKEY_CTX_set_signature_md sets |md| as the digest to be used in a |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 628 | * signature operation. It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 629 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, |
| 630 | const EVP_MD *md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 631 | |
| 632 | /* EVP_PKEY_CTX_get_signature_md sets |*out_md| to the digest to be used in a |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 633 | * signature operation. It returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 634 | OPENSSL_EXPORT int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, |
| 635 | const EVP_MD **out_md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 636 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 637 | |
| 638 | /* RSA specific control functions. */ |
| 639 | |
| 640 | /* EVP_PKEY_CTX_set_rsa_padding sets the padding type to use. It should be one |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 641 | * of the |RSA_*_PADDING| values. Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 642 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int padding); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 643 | |
| 644 | /* EVP_PKEY_CTX_get_rsa_padding sets |*out_padding| to the current padding |
| 645 | * value, which is one of the |RSA_*_PADDING| values. Returns one on success or |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 646 | * zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 647 | OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, |
| 648 | int *out_padding); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 649 | |
| 650 | /* EVP_PKEY_CTX_set_rsa_pss_saltlen sets the length of the salt in a PSS-padded |
| 651 | * signature. A value of -1 cause the salt to be the same length as the digest |
| 652 | * in the signature. A value of -2 causes the salt to be the maximum length |
David Benjamin | a36255c | 2016-12-14 12:41:02 -0500 | [diff] [blame] | 653 | * that will fit when signing and recovered from the signature when verifying. |
| 654 | * Otherwise the value gives the size of the salt in bytes. |
| 655 | * |
| 656 | * If unsure, use -1. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 657 | * |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 658 | * Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 659 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, |
| 660 | int salt_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 661 | |
| 662 | /* EVP_PKEY_CTX_get_rsa_pss_saltlen sets |*out_salt_len| to the salt length of |
| 663 | * a PSS-padded signature. See the documentation for |
| 664 | * |EVP_PKEY_CTX_set_rsa_pss_saltlen| for details of the special values that it |
| 665 | * can take. |
| 666 | * |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 667 | * Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 668 | OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, |
| 669 | int *out_salt_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 670 | |
| 671 | /* EVP_PKEY_CTX_set_rsa_keygen_bits sets the size of the desired RSA modulus, |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 672 | * in bits, for key generation. Returns one on success or zero on |
| 673 | * error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 674 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, |
| 675 | int bits); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 676 | |
| 677 | /* EVP_PKEY_CTX_set_rsa_keygen_pubexp sets |e| as the public exponent for key |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 678 | * generation. Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 679 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, |
| 680 | BIGNUM *e); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 681 | |
| 682 | /* EVP_PKEY_CTX_set_rsa_oaep_md sets |md| as the digest used in OAEP padding. |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 683 | * Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 684 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, |
| 685 | const EVP_MD *md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 686 | |
| 687 | /* EVP_PKEY_CTX_get_rsa_oaep_md sets |*out_md| to the digest function used in |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 688 | * OAEP padding. Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 689 | OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, |
| 690 | const EVP_MD **out_md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 691 | |
| 692 | /* EVP_PKEY_CTX_set_rsa_mgf1_md sets |md| as the digest used in MGF1. Returns |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 693 | * one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 694 | OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, |
| 695 | const EVP_MD *md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 696 | |
| 697 | /* EVP_PKEY_CTX_get_rsa_mgf1_md sets |*out_md| to the digest function used in |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 698 | * MGF1. Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 699 | OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, |
| 700 | const EVP_MD **out_md); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 701 | |
| 702 | /* EVP_PKEY_CTX_set0_rsa_oaep_label sets |label_len| bytes from |label| as the |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 703 | * label used in OAEP. DANGER: On success, this call takes ownership of |label| |
| 704 | * and will call |OPENSSL_free| on it when |ctx| is destroyed. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 705 | * |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 706 | * Returns one on success or zero on error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 707 | OPENSSL_EXPORT int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, |
David Benjamin | 719594e | 2015-12-25 01:02:37 -0500 | [diff] [blame] | 708 | uint8_t *label, |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 709 | size_t label_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 710 | |
| 711 | /* EVP_PKEY_CTX_get0_rsa_oaep_label sets |*out_label| to point to the internal |
| 712 | * buffer containing the OAEP label (which may be NULL) and returns the length |
David Benjamin | e0ba4dd | 2015-03-10 17:10:22 -0400 | [diff] [blame] | 713 | * of the label or a negative value on error. |
| 714 | * |
| 715 | * WARNING: the return value differs from the usual return value convention. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 716 | OPENSSL_EXPORT int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, |
| 717 | const uint8_t **out_label); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 718 | |
| 719 | |
Adam Langley | 517da2f | 2015-05-05 10:27:54 -0700 | [diff] [blame] | 720 | /* Deprecated functions. */ |
| 721 | |
David Benjamin | c3ae38b | 2015-11-20 17:50:41 -0500 | [diff] [blame] | 722 | /* EVP_PKEY_DH is defined for compatibility, but it is impossible to create an |
| 723 | * |EVP_PKEY| of that type. */ |
| 724 | #define EVP_PKEY_DH NID_dhKeyAgreement |
| 725 | |
David Benjamin | f6094e0 | 2015-12-29 17:14:33 -0500 | [diff] [blame] | 726 | /* EVP_PKEY_RSA2 was historically an alternate form for RSA public keys (OID |
| 727 | * 2.5.8.1.1), but is no longer accepted. */ |
| 728 | #define EVP_PKEY_RSA2 NID_rsa |
| 729 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 730 | /* OpenSSL_add_all_algorithms does nothing. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 731 | OPENSSL_EXPORT void OpenSSL_add_all_algorithms(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 732 | |
David Benjamin | 65dac9c | 2016-06-15 17:24:20 -0400 | [diff] [blame] | 733 | /* OPENSSL_add_all_algorithms_conf does nothing. */ |
| 734 | OPENSSL_EXPORT void OPENSSL_add_all_algorithms_conf(void); |
David Benjamin | 83042a8 | 2016-06-06 11:29:58 -0400 | [diff] [blame] | 735 | |
Matt Braithwaite | 444dce4 | 2015-05-06 16:10:57 -0700 | [diff] [blame] | 736 | /* OpenSSL_add_all_ciphers does nothing. */ |
| 737 | OPENSSL_EXPORT void OpenSSL_add_all_ciphers(void); |
| 738 | |
| 739 | /* OpenSSL_add_all_digests does nothing. */ |
| 740 | OPENSSL_EXPORT void OpenSSL_add_all_digests(void); |
| 741 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 742 | /* EVP_cleanup does nothing. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 743 | OPENSSL_EXPORT void EVP_cleanup(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 744 | |
Adam Langley | ce9d85e | 2016-01-24 15:58:39 -0800 | [diff] [blame] | 745 | OPENSSL_EXPORT void EVP_CIPHER_do_all_sorted( |
| 746 | void (*callback)(const EVP_CIPHER *cipher, const char *name, |
| 747 | const char *unused, void *arg), |
| 748 | void *arg); |
| 749 | |
| 750 | OPENSSL_EXPORT void EVP_MD_do_all_sorted(void (*callback)(const EVP_MD *cipher, |
| 751 | const char *name, |
| 752 | const char *unused, |
| 753 | void *arg), |
| 754 | void *arg); |
David Benjamin | cce5a98 | 2015-06-30 00:20:29 -0400 | [diff] [blame] | 755 | |
David Benjamin | 239a0ab | 2016-01-01 01:02:49 -0500 | [diff] [blame] | 756 | /* i2d_PrivateKey marshals a private key from |key| to an ASN.1, DER |
| 757 | * structure. If |outp| is not NULL then the result is written to |*outp| and |
| 758 | * |*outp| is advanced just past the output. It returns the number of bytes in |
| 759 | * the result, whether written or not, or a negative value on error. |
| 760 | * |
| 761 | * RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. |
| 762 | * EC keys are serialized as a DER-encoded ECPrivateKey (RFC 5915) structure. |
| 763 | * |
| 764 | * Use |RSA_marshal_private_key| or |EC_marshal_private_key| instead. */ |
| 765 | OPENSSL_EXPORT int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp); |
| 766 | |
| 767 | /* i2d_PublicKey marshals a public key from |key| to a type-specific format. |
| 768 | * If |outp| is not NULL then the result is written to |*outp| and |
| 769 | * |*outp| is advanced just past the output. It returns the number of bytes in |
| 770 | * the result, whether written or not, or a negative value on error. |
| 771 | * |
| 772 | * RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. |
| 773 | * EC keys are serialized as an EC point per SEC 1. |
| 774 | * |
| 775 | * Use |RSA_marshal_public_key| or |EC_POINT_point2cbb| instead. */ |
| 776 | OPENSSL_EXPORT int i2d_PublicKey(EVP_PKEY *key, uint8_t **outp); |
| 777 | |
David Benjamin | e30a09e | 2016-01-01 01:17:30 -0500 | [diff] [blame] | 778 | /* d2i_PrivateKey parses an ASN.1, DER-encoded, private key from |len| bytes at |
| 779 | * |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in |
David Benjamin | 921d906 | 2016-01-30 19:33:52 -0500 | [diff] [blame] | 780 | * |*out|. Note that, even if |*out| is already non-NULL on entry, it will not |
| 781 | * be written to. Rather, a fresh |EVP_PKEY| is allocated and the previous one |
| 782 | * is freed. On successful exit, |*inp| is advanced past the DER structure. It |
| 783 | * returns the result or NULL on error. |
David Benjamin | e30a09e | 2016-01-01 01:17:30 -0500 | [diff] [blame] | 784 | * |
| 785 | * This function tries to detect one of several formats. Instead, use |
| 786 | * |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an |
| 787 | * RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. */ |
| 788 | OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, |
| 789 | const uint8_t **inp, long len); |
| 790 | |
| 791 | /* d2i_AutoPrivateKey acts the same as |d2i_PrivateKey|, but detects the type |
| 792 | * of the private key. |
| 793 | * |
| 794 | * This function tries to detect one of several formats. Instead, use |
| 795 | * |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an |
| 796 | * RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. */ |
| 797 | OPENSSL_EXPORT EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **out, const uint8_t **inp, |
| 798 | long len); |
| 799 | |
David Benjamin | 5a91503 | 2016-08-09 11:04:24 -0400 | [diff] [blame] | 800 | /* EVP_PKEY_get0_DH returns NULL. */ |
| 801 | OPENSSL_EXPORT DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey); |
| 802 | |
David Benjamin | 239a0ab | 2016-01-01 01:02:49 -0500 | [diff] [blame] | 803 | |
David Benjamin | 8ebc0f5 | 2016-01-03 03:02:50 -0800 | [diff] [blame] | 804 | /* Private structures. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 805 | |
| 806 | struct evp_pkey_st { |
Adam Langley | 0da323a | 2015-05-15 12:49:30 -0700 | [diff] [blame] | 807 | CRYPTO_refcount_t references; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 808 | |
| 809 | /* type contains one of the EVP_PKEY_* values or NID_undef and determines |
| 810 | * which element (if any) of the |pkey| union is valid. */ |
| 811 | int type; |
| 812 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 813 | union { |
David Benjamin | 05bb1c5 | 2017-03-27 21:55:52 -0500 | [diff] [blame] | 814 | void *ptr; |
David Benjamin | 507b819 | 2015-06-12 01:28:22 -0400 | [diff] [blame] | 815 | RSA *rsa; |
| 816 | DSA *dsa; |
| 817 | DH *dh; |
| 818 | EC_KEY *ec; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 819 | } pkey; |
| 820 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 821 | /* ameth contains a pointer to a method table that contains many ASN.1 |
| 822 | * methods for the key type. */ |
| 823 | const EVP_PKEY_ASN1_METHOD *ameth; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 824 | } /* EVP_PKEY */; |
| 825 | |
| 826 | |
| 827 | #if defined(__cplusplus) |
| 828 | } /* extern C */ |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 829 | |
| 830 | extern "C++" { |
| 831 | namespace bssl { |
| 832 | |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 833 | BORINGSSL_MAKE_DELETER(EVP_PKEY, EVP_PKEY_free) |
| 834 | BORINGSSL_MAKE_DELETER(EVP_PKEY_CTX, EVP_PKEY_CTX_free) |
| 835 | |
Matt Braithwaite | d17d74d | 2016-08-17 20:10:28 -0700 | [diff] [blame] | 836 | } // namespace bssl |
| 837 | |
| 838 | } /* extern C++ */ |
| 839 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 840 | #endif |
| 841 | |
David Benjamin | 689be0f | 2015-02-11 15:55:26 -0500 | [diff] [blame] | 842 | #define EVP_R_BUFFER_TOO_SMALL 100 |
| 843 | #define EVP_R_COMMAND_NOT_SUPPORTED 101 |
David Benjamin | 63d9246 | 2016-02-01 15:48:51 -0500 | [diff] [blame] | 844 | #define EVP_R_DECODE_ERROR 102 |
| 845 | #define EVP_R_DIFFERENT_KEY_TYPES 103 |
| 846 | #define EVP_R_DIFFERENT_PARAMETERS 104 |
| 847 | #define EVP_R_ENCODE_ERROR 105 |
| 848 | #define EVP_R_EXPECTING_AN_EC_KEY_KEY 106 |
| 849 | #define EVP_R_EXPECTING_AN_RSA_KEY 107 |
| 850 | #define EVP_R_EXPECTING_A_DSA_KEY 108 |
| 851 | #define EVP_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 109 |
| 852 | #define EVP_R_INVALID_DIGEST_LENGTH 110 |
| 853 | #define EVP_R_INVALID_DIGEST_TYPE 111 |
| 854 | #define EVP_R_INVALID_KEYBITS 112 |
| 855 | #define EVP_R_INVALID_MGF1_MD 113 |
| 856 | #define EVP_R_INVALID_OPERATION 114 |
| 857 | #define EVP_R_INVALID_PADDING_MODE 115 |
| 858 | #define EVP_R_INVALID_PSS_SALTLEN 116 |
| 859 | #define EVP_R_KEYS_NOT_SET 117 |
| 860 | #define EVP_R_MISSING_PARAMETERS 118 |
| 861 | #define EVP_R_NO_DEFAULT_DIGEST 119 |
| 862 | #define EVP_R_NO_KEY_SET 120 |
| 863 | #define EVP_R_NO_MDC2_SUPPORT 121 |
| 864 | #define EVP_R_NO_NID_FOR_CURVE 122 |
| 865 | #define EVP_R_NO_OPERATION_SET 123 |
| 866 | #define EVP_R_NO_PARAMETERS_SET 124 |
| 867 | #define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 125 |
| 868 | #define EVP_R_OPERATON_NOT_INITIALIZED 126 |
| 869 | #define EVP_R_UNKNOWN_PUBLIC_KEY_TYPE 127 |
| 870 | #define EVP_R_UNSUPPORTED_ALGORITHM 128 |
| 871 | #define EVP_R_UNSUPPORTED_PUBLIC_KEY_TYPE 129 |
David Benjamin | 05bb1c5 | 2017-03-27 21:55:52 -0500 | [diff] [blame] | 872 | #define EVP_R_NOT_A_PRIVATE_KEY 130 |
David Benjamin | 417830d | 2017-03-28 15:24:11 -0500 | [diff] [blame] | 873 | #define EVP_R_INVALID_SIGNATURE 131 |
David Benjamin | b529253 | 2017-06-09 19:27:37 -0400 | [diff] [blame] | 874 | #define EVP_R_MEMORY_LIMIT_EXCEEDED 132 |
| 875 | #define EVP_R_INVALID_PARAMETERS 133 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 876 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 877 | #endif /* OPENSSL_HEADER_EVP_H */ |