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> 61 62 #include <openssl/thread.h> 63 64 // OpenSSL included digest and cipher functions in this header so we include 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> 69 #include <openssl/base64.h> 70 #include <openssl/cipher.h> 71 #include <openssl/digest.h> 72 #include <openssl/nid.h> 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 // An |EVP_PKEY| object represents a public or private key. A given object may 85 // be used concurrently on multiple threads by non-mutating functions, provided 86 // no other thread is concurrently calling a mutating function. Unless otherwise 87 // documented, functions which take a |const| pointer are non-mutating and 88 // functions which take a non-|const| pointer are mutating. 89 90 // EVP_PKEY_new creates a new, empty public-key object and returns it or NULL 91 // on allocation failure. 92 OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new(void); 93 94 // EVP_PKEY_free frees all data referenced by |pkey| and then frees |pkey| 95 // itself. 96 OPENSSL_EXPORT void EVP_PKEY_free(EVP_PKEY *pkey); 97 98 // EVP_PKEY_up_ref increments the reference count of |pkey| and returns one. It 99 // does not mutate |pkey| for thread-safety purposes and may be used 100 // concurrently. 101 OPENSSL_EXPORT int EVP_PKEY_up_ref(EVP_PKEY *pkey); 102 103 // EVP_PKEY_is_opaque returns one if |pkey| is opaque. Opaque keys are backed by 104 // custom implementations which do not expose key material and parameters. It is 105 // an error to attempt to duplicate, export, or compare an opaque key. 106 OPENSSL_EXPORT int EVP_PKEY_is_opaque(const EVP_PKEY *pkey); 107 108 // EVP_PKEY_cmp compares |a| and |b| and returns one if they are equal, zero if 109 // not and a negative number on error. 110 // 111 // WARNING: this differs from the traditional return value of a "cmp" 112 // function. 113 OPENSSL_EXPORT int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); 114 115 // EVP_PKEY_copy_parameters sets the parameters of |to| to equal the parameters 116 // of |from|. It returns one on success and zero on error. 117 OPENSSL_EXPORT int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); 118 119 // EVP_PKEY_missing_parameters returns one if |pkey| is missing needed 120 // parameters or zero if not, or if the algorithm doesn't take parameters. 121 OPENSSL_EXPORT int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); 122 123 // EVP_PKEY_size returns the maximum size, in bytes, of a signature signed by 124 // |pkey|. For an RSA key, this returns the number of bytes needed to represent 125 // the modulus. For an EC key, this returns the maximum size of a DER-encoded 126 // ECDSA signature. 127 OPENSSL_EXPORT int EVP_PKEY_size(const EVP_PKEY *pkey); 128 129 // EVP_PKEY_bits returns the "size", in bits, of |pkey|. For an RSA key, this 130 // returns the bit length of the modulus. For an EC key, this returns the bit 131 // length of the group order. 132 OPENSSL_EXPORT int EVP_PKEY_bits(const EVP_PKEY *pkey); 133 134 // EVP_PKEY_id returns the type of |pkey|, which is one of the |EVP_PKEY_*| 135 // values. 136 OPENSSL_EXPORT int EVP_PKEY_id(const EVP_PKEY *pkey); 137 138 // EVP_PKEY_type returns |nid| if |nid| is a known key type and |NID_undef| 139 // otherwise. 140 OPENSSL_EXPORT int EVP_PKEY_type(int nid); 141 142 143 // Getting and setting concrete public key types. 144 // 145 // The following functions get and set the underlying public key in an 146 // |EVP_PKEY| object. The |set1| functions take an additional reference to the 147 // underlying key and return one on success or zero if |key| is NULL. The 148 // |assign| functions adopt the caller's reference and return one on success or 149 // zero if |key| is NULL. The |get1| functions return a fresh reference to the 150 // underlying object or NULL if |pkey| is not of the correct type. The |get0| 151 // functions behave the same but return a non-owning pointer. 152 // 153 // The |get0| and |get1| functions take |const| pointers and are thus 154 // non-mutating for thread-safety purposes, but mutating functions on the 155 // returned lower-level objects are considered to also mutate the |EVP_PKEY| and 156 // may not be called concurrently with other operations on the |EVP_PKEY|. 157 158 OPENSSL_EXPORT int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key); 159 OPENSSL_EXPORT int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key); 160 OPENSSL_EXPORT RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey); 161 OPENSSL_EXPORT RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey); 162 163 OPENSSL_EXPORT int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key); 164 OPENSSL_EXPORT int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key); 165 OPENSSL_EXPORT DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey); 166 OPENSSL_EXPORT DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey); 167 168 OPENSSL_EXPORT int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); 169 OPENSSL_EXPORT int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); 170 OPENSSL_EXPORT EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey); 171 OPENSSL_EXPORT EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey); 172 173 #define EVP_PKEY_NONE NID_undef 174 #define EVP_PKEY_RSA NID_rsaEncryption 175 #define EVP_PKEY_RSA_PSS NID_rsassaPss 176 #define EVP_PKEY_DSA NID_dsa 177 #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey 178 #define EVP_PKEY_ED25519 NID_ED25519 179 #define EVP_PKEY_X25519 NID_X25519 180 181 // EVP_PKEY_assign sets the underlying key of |pkey| to |key|, which must be of 182 // the given type. It returns one if successful or zero if the |type| argument 183 // is not one of the |EVP_PKEY_*| values or if |key| is NULL. 184 OPENSSL_EXPORT int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); 185 186 // EVP_PKEY_set_type sets the type of |pkey| to |type|. It returns one if 187 // successful or zero if the |type| argument is not one of the |EVP_PKEY_*| 188 // values. If |pkey| is NULL, it simply reports whether the type is known. 189 OPENSSL_EXPORT int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); 190 191 // EVP_PKEY_cmp_parameters compares the parameters of |a| and |b|. It returns 192 // one if they match, zero if not, or a negative number of on error. 193 // 194 // WARNING: the return value differs from the usual return value convention. 195 OPENSSL_EXPORT int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, 196 const EVP_PKEY *b); 197 198 199 // ASN.1 functions 200 201 // EVP_parse_public_key decodes a DER-encoded SubjectPublicKeyInfo structure 202 // (RFC 5280) from |cbs| and advances |cbs|. It returns a newly-allocated 203 // |EVP_PKEY| or NULL on error. If the key is an EC key, the curve is guaranteed 204 // to be set. 205 // 206 // The caller must check the type of the parsed public key to ensure it is 207 // suitable and validate other desired key properties such as RSA modulus size 208 // or EC curve. 209 OPENSSL_EXPORT EVP_PKEY *EVP_parse_public_key(CBS *cbs); 210 211 // EVP_marshal_public_key marshals |key| as a DER-encoded SubjectPublicKeyInfo 212 // structure (RFC 5280) and appends the result to |cbb|. It returns one on 213 // success and zero on error. 214 OPENSSL_EXPORT int EVP_marshal_public_key(CBB *cbb, const EVP_PKEY *key); 215 216 // EVP_parse_private_key decodes a DER-encoded PrivateKeyInfo structure (RFC 217 // 5208) from |cbs| and advances |cbs|. It returns a newly-allocated |EVP_PKEY| 218 // or NULL on error. 219 // 220 // The caller must check the type of the parsed private key to ensure it is 221 // suitable and validate other desired key properties such as RSA modulus size 222 // or EC curve. 223 // 224 // A PrivateKeyInfo ends with an optional set of attributes. These are not 225 // processed and so this function will silently ignore any trailing data in the 226 // structure. 227 OPENSSL_EXPORT EVP_PKEY *EVP_parse_private_key(CBS *cbs); 228 229 // EVP_marshal_private_key marshals |key| as a DER-encoded PrivateKeyInfo 230 // structure (RFC 5208) and appends the result to |cbb|. It returns one on 231 // success and zero on error. 232 OPENSSL_EXPORT int EVP_marshal_private_key(CBB *cbb, const EVP_PKEY *key); 233 234 235 // Raw keys 236 // 237 // Some keys types support a "raw" serialization. Currently the only supported 238 // raw format is Ed25519, where the public key and private key formats are those 239 // specified in RFC 8032. Note the RFC 8032 private key format is the 32-byte 240 // prefix of |ED25519_sign|'s 64-byte private key. 241 242 // EVP_PKEY_new_raw_private_key returns a newly allocated |EVP_PKEY| wrapping a 243 // private key of the specified type. It returns one on success and zero on 244 // error. 245 OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused, 246 const uint8_t *in, 247 size_t len); 248 249 // EVP_PKEY_new_raw_public_key returns a newly allocated |EVP_PKEY| wrapping a 250 // public key of the specified type. It returns one on success and zero on 251 // error. 252 OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *unused, 253 const uint8_t *in, 254 size_t len); 255 256 // EVP_PKEY_get_raw_private_key outputs the private key for |pkey| in raw form. 257 // If |out| is NULL, it sets |*out_len| to the size of the raw private key. 258 // Otherwise, it writes at most |*out_len| bytes to |out| and sets |*out_len| to 259 // the number of bytes written. 260 // 261 // It returns one on success and zero if |pkey| has no private key, the key 262 // type does not support a raw format, or the buffer is too small. 263 OPENSSL_EXPORT int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, 264 uint8_t *out, size_t *out_len); 265 266 // EVP_PKEY_get_raw_public_key outputs the public key for |pkey| in raw form. 267 // If |out| is NULL, it sets |*out_len| to the size of the raw public key. 268 // Otherwise, it writes at most |*out_len| bytes to |out| and sets |*out_len| to 269 // the number of bytes written. 270 // 271 // It returns one on success and zero if |pkey| has no public key, the key 272 // type does not support a raw format, or the buffer is too small. 273 OPENSSL_EXPORT int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, 274 uint8_t *out, size_t *out_len); 275 276 277 // Signing 278 279 // EVP_DigestSignInit sets up |ctx| for a signing operation with |type| and 280 // |pkey|. The |ctx| argument must have been initialised with 281 // |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing 282 // operation will be written to |*pctx|; this can be used to set alternative 283 // signing options. 284 // 285 // For single-shot signing algorithms which do not use a pre-hash, such as 286 // Ed25519, |type| should be NULL. The |EVP_MD_CTX| itself is unused but is 287 // present so the API is uniform. See |EVP_DigestSign|. 288 // 289 // This function does not mutate |pkey| for thread-safety purposes and may be 290 // used concurrently with other non-mutating functions on |pkey|. 291 // 292 // It returns one on success, or zero on error. 293 OPENSSL_EXPORT int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 294 const EVP_MD *type, ENGINE *e, 295 EVP_PKEY *pkey); 296 297 // EVP_DigestSignUpdate appends |len| bytes from |data| to the data which will 298 // be signed in |EVP_DigestSignFinal|. It returns one. 299 // 300 // This function performs a streaming signing operation and will fail for 301 // signature algorithms which do not support this. Use |EVP_DigestSign| for a 302 // single-shot operation. 303 OPENSSL_EXPORT int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, 304 size_t len); 305 306 // EVP_DigestSignFinal signs the data that has been included by one or more 307 // calls to |EVP_DigestSignUpdate|. If |out_sig| is NULL then |*out_sig_len| is 308 // set to the maximum number of output bytes. Otherwise, on entry, 309 // |*out_sig_len| must contain the length of the |out_sig| buffer. If the call 310 // is successful, the signature is written to |out_sig| and |*out_sig_len| is 311 // set to its length. 312 // 313 // This function performs a streaming signing operation and will fail for 314 // signature algorithms which do not support this. Use |EVP_DigestSign| for a 315 // single-shot operation. 316 // 317 // It returns one on success, or zero on error. 318 OPENSSL_EXPORT int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, 319 size_t *out_sig_len); 320 321 // EVP_DigestSign signs |data_len| bytes from |data| using |ctx|. If |out_sig| 322 // is NULL then |*out_sig_len| is set to the maximum number of output 323 // bytes. Otherwise, on entry, |*out_sig_len| must contain the length of the 324 // |out_sig| buffer. If the call is successful, the signature is written to 325 // |out_sig| and |*out_sig_len| is set to its length. 326 // 327 // It returns one on success and zero on error. 328 OPENSSL_EXPORT int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, 329 size_t *out_sig_len, const uint8_t *data, 330 size_t data_len); 331 332 333 // Verifying 334 335 // EVP_DigestVerifyInit sets up |ctx| for a signature verification operation 336 // with |type| and |pkey|. The |ctx| argument must have been initialised with 337 // |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing 338 // operation will be written to |*pctx|; this can be used to set alternative 339 // signing options. 340 // 341 // For single-shot signing algorithms which do not use a pre-hash, such as 342 // Ed25519, |type| should be NULL. The |EVP_MD_CTX| itself is unused but is 343 // present so the API is uniform. See |EVP_DigestVerify|. 344 // 345 // This function does not mutate |pkey| for thread-safety purposes and may be 346 // used concurrently with other non-mutating functions on |pkey|. 347 // 348 // It returns one on success, or zero on error. 349 OPENSSL_EXPORT int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 350 const EVP_MD *type, ENGINE *e, 351 EVP_PKEY *pkey); 352 353 // EVP_DigestVerifyUpdate appends |len| bytes from |data| to the data which 354 // will be verified by |EVP_DigestVerifyFinal|. It returns one. 355 // 356 // This function performs streaming signature verification and will fail for 357 // signature algorithms which do not support this. Use |EVP_PKEY_verify_message| 358 // for a single-shot verification. 359 OPENSSL_EXPORT int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, 360 size_t len); 361 362 // EVP_DigestVerifyFinal verifies that |sig_len| bytes of |sig| are a valid 363 // signature for the data that has been included by one or more calls to 364 // |EVP_DigestVerifyUpdate|. It returns one on success and zero otherwise. 365 // 366 // This function performs streaming signature verification and will fail for 367 // signature algorithms which do not support this. Use |EVP_PKEY_verify_message| 368 // for a single-shot verification. 369 OPENSSL_EXPORT int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, 370 size_t sig_len); 371 372 // EVP_DigestVerify verifies that |sig_len| bytes from |sig| are a valid 373 // signature for |data|. It returns one on success or zero on error. 374 OPENSSL_EXPORT int EVP_DigestVerify(EVP_MD_CTX *ctx, const uint8_t *sig, 375 size_t sig_len, const uint8_t *data, 376 size_t len); 377 378 379 // Signing (old functions) 380 381 // EVP_SignInit_ex configures |ctx|, which must already have been initialised, 382 // for a fresh signing operation using the hash function |type|. It returns one 383 // on success and zero otherwise. 384 // 385 // (In order to initialise |ctx|, either obtain it initialised with 386 // |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) 387 OPENSSL_EXPORT int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, 388 ENGINE *impl); 389 390 // EVP_SignInit is a deprecated version of |EVP_SignInit_ex|. 391 // 392 // TODO(fork): remove. 393 OPENSSL_EXPORT int EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type); 394 395 // EVP_SignUpdate appends |len| bytes from |data| to the data which will be 396 // signed in |EVP_SignFinal|. 397 OPENSSL_EXPORT int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *data, 398 size_t len); 399 400 // EVP_SignFinal signs the data that has been included by one or more calls to 401 // |EVP_SignUpdate|, using the key |pkey|, and writes it to |sig|. On entry, 402 // |sig| must point to at least |EVP_PKEY_size(pkey)| bytes of space. The 403 // actual size of the signature is written to |*out_sig_len|. 404 // 405 // It returns one on success and zero otherwise. 406 // 407 // It does not modify |ctx|, thus it's possible to continue to use |ctx| in 408 // order to sign a longer message. It also does not mutate |pkey| for 409 // thread-safety purposes and may be used concurrently with other non-mutating 410 // functions on |pkey|. 411 OPENSSL_EXPORT int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig, 412 unsigned int *out_sig_len, EVP_PKEY *pkey); 413 414 415 // Verifying (old functions) 416 417 // EVP_VerifyInit_ex configures |ctx|, which must already have been 418 // initialised, for a fresh signature verification operation using the hash 419 // function |type|. It returns one on success and zero otherwise. 420 // 421 // (In order to initialise |ctx|, either obtain it initialised with 422 // |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) 423 OPENSSL_EXPORT int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, 424 ENGINE *impl); 425 426 // EVP_VerifyInit is a deprecated version of |EVP_VerifyInit_ex|. 427 // 428 // TODO(fork): remove. 429 OPENSSL_EXPORT int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type); 430 431 // EVP_VerifyUpdate appends |len| bytes from |data| to the data which will be 432 // signed in |EVP_VerifyFinal|. 433 OPENSSL_EXPORT int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *data, 434 size_t len); 435 436 // EVP_VerifyFinal verifies that |sig_len| bytes of |sig| are a valid 437 // signature, by |pkey|, for the data that has been included by one or more 438 // calls to |EVP_VerifyUpdate|. 439 // 440 // It returns one on success and zero otherwise. 441 // 442 // It does not modify |ctx|, thus it's possible to continue to use |ctx| in 443 // order to verify a longer message. It also does not mutate |pkey| for 444 // thread-safety purposes and may be used concurrently with other non-mutating 445 // functions on |pkey|. 446 OPENSSL_EXPORT int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, 447 size_t sig_len, EVP_PKEY *pkey); 448 449 450 // Printing 451 452 // EVP_PKEY_print_public prints a textual representation of the public key in 453 // |pkey| to |out|. Returns one on success or zero otherwise. 454 OPENSSL_EXPORT int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, 455 int indent, ASN1_PCTX *pctx); 456 457 // EVP_PKEY_print_private prints a textual representation of the private key in 458 // |pkey| to |out|. Returns one on success or zero otherwise. 459 OPENSSL_EXPORT int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, 460 int indent, ASN1_PCTX *pctx); 461 462 // EVP_PKEY_print_params prints a textual representation of the parameters in 463 // |pkey| to |out|. Returns one on success or zero otherwise. 464 OPENSSL_EXPORT int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, 465 int indent, ASN1_PCTX *pctx); 466 467 468 // Password stretching. 469 // 470 // Password stretching functions take a low-entropy password and apply a slow 471 // function that results in a key suitable for use in symmetric 472 // cryptography. 473 474 // PKCS5_PBKDF2_HMAC computes |iterations| iterations of PBKDF2 of |password| 475 // and |salt|, using |digest|, and outputs |key_len| bytes to |out_key|. It 476 // returns one on success and zero on allocation failure or if iterations is 0. 477 OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len, 478 const uint8_t *salt, size_t salt_len, 479 unsigned iterations, const EVP_MD *digest, 480 size_t key_len, uint8_t *out_key); 481 482 // PKCS5_PBKDF2_HMAC_SHA1 is the same as PKCS5_PBKDF2_HMAC, but with |digest| 483 // fixed to |EVP_sha1|. 484 OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC_SHA1(const char *password, 485 size_t password_len, 486 const uint8_t *salt, size_t salt_len, 487 unsigned iterations, size_t key_len, 488 uint8_t *out_key); 489 490 // EVP_PBE_scrypt expands |password| into a secret key of length |key_len| using 491 // scrypt, as described in RFC 7914, and writes the result to |out_key|. It 492 // returns one on success and zero on allocation failure, if the memory required 493 // for the operation exceeds |max_mem|, or if any of the parameters are invalid 494 // as described below. 495 // 496 // |N|, |r|, and |p| are as described in RFC 7914 section 6. They determine the 497 // cost of the operation. If |max_mem| is zero, a defult limit of 32MiB will be 498 // used. 499 // 500 // The parameters are considered invalid under any of the following conditions: 501 // - |r| or |p| are zero 502 // - |p| > (2^30 - 1) / |r| 503 // - |N| is not a power of two 504 // - |N| > 2^32 505 // - |N| > 2^(128 * |r| / 8) 506 OPENSSL_EXPORT int EVP_PBE_scrypt(const char *password, size_t password_len, 507 const uint8_t *salt, size_t salt_len, 508 uint64_t N, uint64_t r, uint64_t p, 509 size_t max_mem, uint8_t *out_key, 510 size_t key_len); 511 512 513 // Public key contexts. 514 // 515 // |EVP_PKEY_CTX| objects hold the context of an operation (e.g. signing or 516 // encrypting) that uses a public key. 517 518 // EVP_PKEY_CTX_new allocates a fresh |EVP_PKEY_CTX| for use with |pkey|. It 519 // returns the context or NULL on error. 520 OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); 521 522 // EVP_PKEY_CTX_new_id allocates a fresh |EVP_PKEY_CTX| for a key of type |id| 523 // (e.g. |EVP_PKEY_HMAC|). This can be used for key generation where 524 // |EVP_PKEY_CTX_new| can't be used because there isn't an |EVP_PKEY| to pass 525 // it. It returns the context or NULL on error. 526 OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); 527 528 // EVP_PKEY_CTX_free frees |ctx| and the data it owns. 529 OPENSSL_EXPORT void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); 530 531 // EVP_PKEY_CTX_dup allocates a fresh |EVP_PKEY_CTX| and sets it equal to the 532 // state of |ctx|. It returns the fresh |EVP_PKEY_CTX| or NULL on error. 533 OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); 534 535 // EVP_PKEY_CTX_get0_pkey returns the |EVP_PKEY| associated with |ctx|. 536 OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); 537 538 // EVP_PKEY_sign_init initialises an |EVP_PKEY_CTX| for a signing operation. It 539 // should be called before |EVP_PKEY_sign|. 540 // 541 // It returns one on success or zero on error. 542 OPENSSL_EXPORT int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); 543 544 // EVP_PKEY_sign signs |digest_len| bytes from |digest| using |ctx|. If |sig| is 545 // NULL, the maximum size of the signature is written to 546 // |out_sig_len|. Otherwise, |*sig_len| must contain the number of bytes of 547 // space available at |sig|. If sufficient, the signature will be written to 548 // |sig| and |*sig_len| updated with the true length. 549 // 550 // This function expects a pre-hashed input and will fail for signature 551 // algorithms which do not support this. Use |EVP_DigestSignInit| to sign an 552 // unhashed input. 553 // 554 // WARNING: Setting |sig| to NULL only gives the maximum size of the 555 // signature. The actual signature may be smaller. 556 // 557 // It returns one on success or zero on error. (Note: this differs from 558 // OpenSSL, which can also return negative values to indicate an error. ) 559 OPENSSL_EXPORT int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, 560 size_t *sig_len, const uint8_t *digest, 561 size_t digest_len); 562 563 // EVP_PKEY_verify_init initialises an |EVP_PKEY_CTX| for a signature 564 // verification operation. It should be called before |EVP_PKEY_verify|. 565 // 566 // It returns one on success or zero on error. 567 OPENSSL_EXPORT int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); 568 569 // EVP_PKEY_verify verifies that |sig_len| bytes from |sig| are a valid 570 // signature for |digest|. 571 // 572 // This function expects a pre-hashed input and will fail for signature 573 // algorithms which do not support this. Use |EVP_DigestVerifyInit| to verify a 574 // signature given the unhashed input. 575 // 576 // It returns one on success or zero on error. 577 OPENSSL_EXPORT int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig, 578 size_t sig_len, const uint8_t *digest, 579 size_t digest_len); 580 581 // EVP_PKEY_encrypt_init initialises an |EVP_PKEY_CTX| for an encryption 582 // operation. It should be called before |EVP_PKEY_encrypt|. 583 // 584 // It returns one on success or zero on error. 585 OPENSSL_EXPORT int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); 586 587 // EVP_PKEY_encrypt encrypts |in_len| bytes from |in|. If |out| is NULL, the 588 // maximum size of the ciphertext is written to |out_len|. Otherwise, |*out_len| 589 // must contain the number of bytes of space available at |out|. If sufficient, 590 // the ciphertext will be written to |out| and |*out_len| updated with the true 591 // length. 592 // 593 // WARNING: Setting |out| to NULL only gives the maximum size of the 594 // ciphertext. The actual ciphertext may be smaller. 595 // 596 // It returns one on success or zero on error. 597 OPENSSL_EXPORT int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, uint8_t *out, 598 size_t *out_len, const uint8_t *in, 599 size_t in_len); 600 601 // EVP_PKEY_decrypt_init initialises an |EVP_PKEY_CTX| for a decryption 602 // operation. It should be called before |EVP_PKEY_decrypt|. 603 // 604 // It returns one on success or zero on error. 605 OPENSSL_EXPORT int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); 606 607 // EVP_PKEY_decrypt decrypts |in_len| bytes from |in|. If |out| is NULL, the 608 // maximum size of the plaintext is written to |out_len|. Otherwise, |*out_len| 609 // must contain the number of bytes of space available at |out|. If sufficient, 610 // the ciphertext will be written to |out| and |*out_len| updated with the true 611 // length. 612 // 613 // WARNING: Setting |out| to NULL only gives the maximum size of the 614 // plaintext. The actual plaintext may be smaller. 615 // 616 // It returns one on success or zero on error. 617 OPENSSL_EXPORT int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out, 618 size_t *out_len, const uint8_t *in, 619 size_t in_len); 620 621 // EVP_PKEY_verify_recover_init initialises an |EVP_PKEY_CTX| for a public-key 622 // decryption operation. It should be called before |EVP_PKEY_verify_recover|. 623 // 624 // Public-key decryption is a very obscure operation that is only implemented 625 // by RSA keys. It is effectively a signature verification operation that 626 // returns the signed message directly. It is almost certainly not what you 627 // want. 628 // 629 // It returns one on success or zero on error. 630 OPENSSL_EXPORT int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); 631 632 // EVP_PKEY_verify_recover decrypts |sig_len| bytes from |sig|. If |out| is 633 // NULL, the maximum size of the plaintext is written to |out_len|. Otherwise, 634 // |*out_len| must contain the number of bytes of space available at |out|. If 635 // sufficient, the ciphertext will be written to |out| and |*out_len| updated 636 // with the true length. 637 // 638 // WARNING: Setting |out| to NULL only gives the maximum size of the 639 // plaintext. The actual plaintext may be smaller. 640 // 641 // See the warning about this operation in |EVP_PKEY_verify_recover_init|. It 642 // is probably not what you want. 643 // 644 // It returns one on success or zero on error. 645 OPENSSL_EXPORT int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, uint8_t *out, 646 size_t *out_len, const uint8_t *sig, 647 size_t siglen); 648 649 // EVP_PKEY_derive_init initialises an |EVP_PKEY_CTX| for a key derivation 650 // operation. It should be called before |EVP_PKEY_derive_set_peer| and 651 // |EVP_PKEY_derive|. 652 // 653 // It returns one on success or zero on error. 654 OPENSSL_EXPORT int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); 655 656 // EVP_PKEY_derive_set_peer sets the peer's key to be used for key derivation 657 // by |ctx| to |peer|. It should be called after |EVP_PKEY_derive_init|. (For 658 // example, this is used to set the peer's key in (EC)DH.) It returns one on 659 // success and zero on error. 660 OPENSSL_EXPORT int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); 661 662 // EVP_PKEY_derive derives a shared key between the two keys configured in 663 // |ctx|. If |key| is non-NULL then, on entry, |out_key_len| must contain the 664 // amount of space at |key|. If sufficient then the shared key will be written 665 // to |key| and |*out_key_len| will be set to the length. If |key| is NULL then 666 // |out_key_len| will be set to the maximum length. 667 // 668 // WARNING: Setting |out| to NULL only gives the maximum size of the key. The 669 // actual key may be smaller. 670 // 671 // It returns one on success and zero on error. 672 OPENSSL_EXPORT int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, uint8_t *key, 673 size_t *out_key_len); 674 675 // EVP_PKEY_keygen_init initialises an |EVP_PKEY_CTX| for a key generation 676 // operation. It should be called before |EVP_PKEY_keygen|. 677 // 678 // It returns one on success or zero on error. 679 OPENSSL_EXPORT int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); 680 681 // EVP_PKEY_keygen performs a key generation operation using the values from 682 // |ctx|. If |*out_pkey| is non-NULL, it overwrites |*out_pkey| with the 683 // resulting key. Otherwise, it sets |*out_pkey| to a newly-allocated |EVP_PKEY| 684 // containing the result. It returns one on success or zero on error. 685 OPENSSL_EXPORT int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **out_pkey); 686 687 // EVP_PKEY_paramgen_init initialises an |EVP_PKEY_CTX| for a parameter 688 // generation operation. It should be called before |EVP_PKEY_paramgen|. 689 // 690 // It returns one on success or zero on error. 691 OPENSSL_EXPORT int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); 692 693 // EVP_PKEY_paramgen performs a parameter generation using the values from 694 // |ctx|. If |*out_pkey| is non-NULL, it overwrites |*out_pkey| with the 695 // resulting parameters, but no key. Otherwise, it sets |*out_pkey| to a 696 // newly-allocated |EVP_PKEY| containing the result. It returns one on success 697 // or zero on error. 698 OPENSSL_EXPORT int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **out_pkey); 699 700 701 // Generic control functions. 702 703 // EVP_PKEY_CTX_set_signature_md sets |md| as the digest to be used in a 704 // signature operation. It returns one on success or zero on error. 705 OPENSSL_EXPORT int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, 706 const EVP_MD *md); 707 708 // EVP_PKEY_CTX_get_signature_md sets |*out_md| to the digest to be used in a 709 // signature operation. It returns one on success or zero on error. 710 OPENSSL_EXPORT int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, 711 const EVP_MD **out_md); 712 713 714 // RSA specific control functions. 715 716 // EVP_PKEY_CTX_set_rsa_padding sets the padding type to use. It should be one 717 // of the |RSA_*_PADDING| values. Returns one on success or zero on error. 718 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int padding); 719 720 // EVP_PKEY_CTX_get_rsa_padding sets |*out_padding| to the current padding 721 // value, which is one of the |RSA_*_PADDING| values. Returns one on success or 722 // zero on error. 723 OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, 724 int *out_padding); 725 726 // EVP_PKEY_CTX_set_rsa_pss_saltlen sets the length of the salt in a PSS-padded 727 // signature. A value of -1 cause the salt to be the same length as the digest 728 // in the signature. A value of -2 causes the salt to be the maximum length 729 // that will fit when signing and recovered from the signature when verifying. 730 // Otherwise the value gives the size of the salt in bytes. 731 // 732 // If unsure, use -1. 733 // 734 // Returns one on success or zero on error. 735 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, 736 int salt_len); 737 738 // EVP_PKEY_CTX_get_rsa_pss_saltlen sets |*out_salt_len| to the salt length of 739 // a PSS-padded signature. See the documentation for 740 // |EVP_PKEY_CTX_set_rsa_pss_saltlen| for details of the special values that it 741 // can take. 742 // 743 // Returns one on success or zero on error. 744 OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, 745 int *out_salt_len); 746 747 // EVP_PKEY_CTX_set_rsa_keygen_bits sets the size of the desired RSA modulus, 748 // in bits, for key generation. Returns one on success or zero on 749 // error. 750 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, 751 int bits); 752 753 // EVP_PKEY_CTX_set_rsa_keygen_pubexp sets |e| as the public exponent for key 754 // generation. Returns one on success or zero on error. 755 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, 756 BIGNUM *e); 757 758 // EVP_PKEY_CTX_set_rsa_oaep_md sets |md| as the digest used in OAEP padding. 759 // Returns one on success or zero on error. 760 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, 761 const EVP_MD *md); 762 763 // EVP_PKEY_CTX_get_rsa_oaep_md sets |*out_md| to the digest function used in 764 // OAEP padding. Returns one on success or zero on error. 765 OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, 766 const EVP_MD **out_md); 767 768 // EVP_PKEY_CTX_set_rsa_mgf1_md sets |md| as the digest used in MGF1. Returns 769 // one on success or zero on error. 770 OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, 771 const EVP_MD *md); 772 773 // EVP_PKEY_CTX_get_rsa_mgf1_md sets |*out_md| to the digest function used in 774 // MGF1. Returns one on success or zero on error. 775 OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, 776 const EVP_MD **out_md); 777 778 // EVP_PKEY_CTX_set0_rsa_oaep_label sets |label_len| bytes from |label| as the 779 // label used in OAEP. DANGER: On success, this call takes ownership of |label| 780 // and will call |OPENSSL_free| on it when |ctx| is destroyed. 781 // 782 // Returns one on success or zero on error. 783 OPENSSL_EXPORT int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, 784 uint8_t *label, 785 size_t label_len); 786 787 // EVP_PKEY_CTX_get0_rsa_oaep_label sets |*out_label| to point to the internal 788 // buffer containing the OAEP label (which may be NULL) and returns the length 789 // of the label or a negative value on error. 790 // 791 // WARNING: the return value differs from the usual return value convention. 792 OPENSSL_EXPORT int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, 793 const uint8_t **out_label); 794 795 796 // EC specific control functions. 797 798 // EVP_PKEY_CTX_set_ec_paramgen_curve_nid sets the curve used for 799 // |EVP_PKEY_keygen| or |EVP_PKEY_paramgen| operations to |nid|. It returns one 800 // on success and zero on error. 801 OPENSSL_EXPORT int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, 802 int nid); 803 804 805 // Deprecated functions. 806 807 // EVP_PKEY_DH is defined for compatibility, but it is impossible to create an 808 // |EVP_PKEY| of that type. 809 #define EVP_PKEY_DH NID_dhKeyAgreement 810 811 // EVP_PKEY_RSA2 was historically an alternate form for RSA public keys (OID 812 // 2.5.8.1.1), but is no longer accepted. 813 #define EVP_PKEY_RSA2 NID_rsa 814 815 // OpenSSL_add_all_algorithms does nothing. 816 OPENSSL_EXPORT void OpenSSL_add_all_algorithms(void); 817 818 // OPENSSL_add_all_algorithms_conf does nothing. 819 OPENSSL_EXPORT void OPENSSL_add_all_algorithms_conf(void); 820 821 // OpenSSL_add_all_ciphers does nothing. 822 OPENSSL_EXPORT void OpenSSL_add_all_ciphers(void); 823 824 // OpenSSL_add_all_digests does nothing. 825 OPENSSL_EXPORT void OpenSSL_add_all_digests(void); 826 827 // EVP_cleanup does nothing. 828 OPENSSL_EXPORT void EVP_cleanup(void); 829 830 OPENSSL_EXPORT void EVP_CIPHER_do_all_sorted( 831 void (*callback)(const EVP_CIPHER *cipher, const char *name, 832 const char *unused, void *arg), 833 void *arg); 834 835 OPENSSL_EXPORT void EVP_MD_do_all_sorted(void (*callback)(const EVP_MD *cipher, 836 const char *name, 837 const char *unused, 838 void *arg), 839 void *arg); 840 841 // i2d_PrivateKey marshals a private key from |key| to an ASN.1, DER 842 // structure. If |outp| is not NULL then the result is written to |*outp| and 843 // |*outp| is advanced just past the output. It returns the number of bytes in 844 // the result, whether written or not, or a negative value on error. 845 // 846 // RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. 847 // EC keys are serialized as a DER-encoded ECPrivateKey (RFC 5915) structure. 848 // 849 // Use |RSA_marshal_private_key| or |EC_KEY_marshal_private_key| instead. 850 OPENSSL_EXPORT int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp); 851 852 // i2d_PublicKey marshals a public key from |key| to a type-specific format. 853 // If |outp| is not NULL then the result is written to |*outp| and 854 // |*outp| is advanced just past the output. It returns the number of bytes in 855 // the result, whether written or not, or a negative value on error. 856 // 857 // RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. 858 // EC keys are serialized as an EC point per SEC 1. 859 // 860 // Use |RSA_marshal_public_key| or |EC_POINT_point2cbb| instead. 861 OPENSSL_EXPORT int i2d_PublicKey(const EVP_PKEY *key, uint8_t **outp); 862 863 // d2i_PrivateKey parses an ASN.1, DER-encoded, private key from |len| bytes at 864 // |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in 865 // |*out|. Note that, even if |*out| is already non-NULL on entry, it will not 866 // be written to. Rather, a fresh |EVP_PKEY| is allocated and the previous one 867 // is freed. On successful exit, |*inp| is advanced past the DER structure. It 868 // returns the result or NULL on error. 869 // 870 // This function tries to detect one of several formats. Instead, use 871 // |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an 872 // RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. 873 OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, 874 const uint8_t **inp, long len); 875 876 // d2i_AutoPrivateKey acts the same as |d2i_PrivateKey|, but detects the type 877 // of the private key. 878 // 879 // This function tries to detect one of several formats. Instead, use 880 // |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an 881 // RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. 882 OPENSSL_EXPORT EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **out, const uint8_t **inp, 883 long len); 884 885 // d2i_PublicKey parse a public key from |len| bytes at |*inp| in a type- 886 // specific format specified by |type|. If |out| is not NULL then, on exit, a 887 // pointer to the result is in |*out|. Note that, even if |*out| is already non- 888 // NULL on entry, it will not be written to. Rather, a fresh |EVP_PKEY| is 889 // allocated and the previous one is freed. On successful exit, |*inp| is 890 // advanced past the decoded key. It returns the result or NULL on error. 891 // 892 // RSA keys are parsed as a DER-encoded RSAPublicKey (RFC 3447) structure. 893 // Parsing EC keys is not supported by this function. 894 // 895 // Use |RSA_parse_public_key| instead. 896 OPENSSL_EXPORT EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **out, 897 const uint8_t **inp, long len); 898 899 // EVP_PKEY_get0_DH returns NULL. 900 OPENSSL_EXPORT DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey); 901 902 // EVP_PKEY_get1_DH returns NULL. 903 OPENSSL_EXPORT DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey); 904 905 // EVP_PKEY_CTX_set_ec_param_enc returns one if |encoding| is 906 // |OPENSSL_EC_NAMED_CURVE| or zero with an error otherwise. 907 OPENSSL_EXPORT int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, 908 int encoding); 909 910 // EVP_PKEY_set1_tls_encodedpoint replaces |pkey| with a public key encoded by 911 // |in|. It returns one on success and zero on error. 912 // 913 // This function only works on X25519 keys. 914 OPENSSL_EXPORT int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, 915 const uint8_t *in, 916 size_t len); 917 918 // EVP_PKEY_get1_tls_encodedpoint sets |*out_ptr| to a newly-allocated buffer 919 // containing the raw encoded public key for |pkey|. The caller must call 920 // |OPENSSL_free| to release this buffer. The function returns the length of the 921 // buffer on success and zero on error. 922 // 923 // This function only works on X25519 keys. 924 OPENSSL_EXPORT size_t EVP_PKEY_get1_tls_encodedpoint(const EVP_PKEY *pkey, 925 uint8_t **out_ptr); 926 927 // EVP_PKEY_base_id calls |EVP_PKEY_id|. 928 OPENSSL_EXPORT int EVP_PKEY_base_id(const EVP_PKEY *pkey); 929 930 931 // Preprocessor compatibility section (hidden). 932 // 933 // Historically, a number of APIs were implemented in OpenSSL as macros and 934 // constants to 'ctrl' functions. To avoid breaking #ifdefs in consumers, this 935 // section defines a number of legacy macros. 936 937 // |BORINGSSL_PREFIX| already makes each of these symbols into macros, so there 938 // is no need to define conflicting macros. 939 #if !defined(BORINGSSL_PREFIX) 940 #define EVP_PKEY_CTX_set_rsa_oaep_md EVP_PKEY_CTX_set_rsa_oaep_md 941 #define EVP_PKEY_CTX_set0_rsa_oaep_label EVP_PKEY_CTX_set0_rsa_oaep_label 942 #endif 943 944 945 // Nodejs compatibility section (hidden). 946 // 947 // These defines exist for node.js, with the hope that we can eliminate the 948 // need for them over time. 949 950 #define EVPerr(function, reason) \ 951 ERR_put_error(ERR_LIB_EVP, 0, reason, __FILE__, __LINE__) 952 953 954 // Private structures. 955 956 struct evp_pkey_st { 957 CRYPTO_refcount_t references; 958 959 // type contains one of the EVP_PKEY_* values or NID_undef and determines 960 // which element (if any) of the |pkey| union is valid. 961 int type; 962 963 union { 964 void *ptr; 965 RSA *rsa; 966 DSA *dsa; 967 DH *dh; 968 EC_KEY *ec; 969 } pkey; 970 971 // ameth contains a pointer to a method table that contains many ASN.1 972 // methods for the key type. 973 const EVP_PKEY_ASN1_METHOD *ameth; 974 } /* EVP_PKEY */; 975 976 977 #if defined(__cplusplus) 978 } // extern C 979 980 extern "C++" { 981 BSSL_NAMESPACE_BEGIN 982 983 BORINGSSL_MAKE_DELETER(EVP_PKEY, EVP_PKEY_free) 984 BORINGSSL_MAKE_UP_REF(EVP_PKEY, EVP_PKEY_up_ref) 985 BORINGSSL_MAKE_DELETER(EVP_PKEY_CTX, EVP_PKEY_CTX_free) 986 987 BSSL_NAMESPACE_END 988 989 } // extern C++ 990 991 #endif 992 993 #define EVP_R_BUFFER_TOO_SMALL 100 994 #define EVP_R_COMMAND_NOT_SUPPORTED 101 995 #define EVP_R_DECODE_ERROR 102 996 #define EVP_R_DIFFERENT_KEY_TYPES 103 997 #define EVP_R_DIFFERENT_PARAMETERS 104 998 #define EVP_R_ENCODE_ERROR 105 999 #define EVP_R_EXPECTING_AN_EC_KEY_KEY 106 1000 #define EVP_R_EXPECTING_AN_RSA_KEY 107 1001 #define EVP_R_EXPECTING_A_DSA_KEY 108 1002 #define EVP_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 109 1003 #define EVP_R_INVALID_DIGEST_LENGTH 110 1004 #define EVP_R_INVALID_DIGEST_TYPE 111 1005 #define EVP_R_INVALID_KEYBITS 112 1006 #define EVP_R_INVALID_MGF1_MD 113 1007 #define EVP_R_INVALID_OPERATION 114 1008 #define EVP_R_INVALID_PADDING_MODE 115 1009 #define EVP_R_INVALID_PSS_SALTLEN 116 1010 #define EVP_R_KEYS_NOT_SET 117 1011 #define EVP_R_MISSING_PARAMETERS 118 1012 #define EVP_R_NO_DEFAULT_DIGEST 119 1013 #define EVP_R_NO_KEY_SET 120 1014 #define EVP_R_NO_MDC2_SUPPORT 121 1015 #define EVP_R_NO_NID_FOR_CURVE 122 1016 #define EVP_R_NO_OPERATION_SET 123 1017 #define EVP_R_NO_PARAMETERS_SET 124 1018 #define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 125 1019 #define EVP_R_OPERATON_NOT_INITIALIZED 126 1020 #define EVP_R_UNKNOWN_PUBLIC_KEY_TYPE 127 1021 #define EVP_R_UNSUPPORTED_ALGORITHM 128 1022 #define EVP_R_UNSUPPORTED_PUBLIC_KEY_TYPE 129 1023 #define EVP_R_NOT_A_PRIVATE_KEY 130 1024 #define EVP_R_INVALID_SIGNATURE 131 1025 #define EVP_R_MEMORY_LIMIT_EXCEEDED 132 1026 #define EVP_R_INVALID_PARAMETERS 133 1027 #define EVP_R_INVALID_PEER_KEY 134 1028 #define EVP_R_NOT_XOF_OR_INVALID_LENGTH 135 1029 1030 #endif // OPENSSL_HEADER_EVP_H 1031