| 1 |
// Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_EVP_H |
| 5 |
#define OPENSSL_HEADER_EVP_H |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
|
| 9 |
#include <openssl/evp_errors.h> // IWYU pragma: export |
| 10 |
#include <openssl/thread.h> |
| 11 |
|
| 12 |
// OpenSSL included digest, cipher, and object functions in this header so we |
| 13 |
// include them for users that still expect that. |
| 14 |
#include <openssl/aead.h> |
| 15 |
#include <openssl/base64.h> |
| 16 |
#include <openssl/cipher.h> |
| 17 |
#include <openssl/digest.h> |
| 18 |
#include <openssl/nid.h> |
| 19 |
#include <openssl/objects.h> |
| 20 |
#include <openssl/hmac.h> // Needed by Apache mod_ssl |
| 21 |
|
| 22 |
#if defined(__cplusplus) |
| 23 |
extern "C" { |
| 24 |
#endif |
| 25 |
|
| 26 |
|
| 27 |
// EVP abstracts over public/private key algorithms. |
| 28 |
|
| 29 |
|
| 30 |
// Public/private key objects. |
| 31 |
// |
| 32 |
// An |EVP_PKEY| object represents a public or private key. A given object may |
| 33 |
// be used concurrently on multiple threads by non-mutating functions, provided |
| 34 |
// no other thread is concurrently calling a mutating function. Unless otherwise |
| 35 |
// documented, functions which take a |const| pointer are non-mutating and |
| 36 |
// functions which take a non-|const| pointer are mutating. |
| 37 |
|
| 38 |
// EVP_PKEY_new creates a new, empty public-key object and returns it or NULL |
| 39 |
// on allocation failure. |
| 40 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new(void); |
| 41 |
|
| 42 |
// EVP_PKEY_free frees all data referenced by |pkey| and then frees |pkey| |
| 43 |
// itself. |
| 44 |
OPENSSL_EXPORT void EVP_PKEY_free(EVP_PKEY *pkey); |
| 45 |
|
| 46 |
// EVP_PKEY_up_ref increments the reference count of |pkey| and returns one. It |
| 47 |
// does not mutate |pkey| for thread-safety purposes and may be used |
| 48 |
// concurrently. |
| 49 |
OPENSSL_EXPORT int EVP_PKEY_up_ref(EVP_PKEY *pkey); |
| 50 |
|
| 51 |
// EVP_PKEY_is_opaque returns one if |pkey| is opaque. Opaque keys are backed by |
| 52 |
// custom implementations which do not expose key material and parameters. It is |
| 53 |
// an error to attempt to duplicate, export, or compare an opaque key. |
| 54 |
OPENSSL_EXPORT int EVP_PKEY_is_opaque(const EVP_PKEY *pkey); |
| 55 |
|
| 56 |
// EVP_PKEY_cmp compares |a| and |b| and returns one if they are equal, zero if |
| 57 |
// not and a negative number on error. |
| 58 |
// |
| 59 |
// WARNING: this differs from the traditional return value of a "cmp" |
| 60 |
// function. |
| 61 |
OPENSSL_EXPORT int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); |
| 62 |
|
| 63 |
// EVP_PKEY_copy_parameters sets the parameters of |to| to equal the parameters |
| 64 |
// of |from|. It returns one on success and zero on error. |
| 65 |
OPENSSL_EXPORT int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); |
| 66 |
|
| 67 |
// EVP_PKEY_missing_parameters returns one if |pkey| is missing needed |
| 68 |
// parameters or zero if not, or if the algorithm doesn't take parameters. |
| 69 |
OPENSSL_EXPORT int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); |
| 70 |
|
| 71 |
// EVP_PKEY_size returns the maximum size, in bytes, of a signature signed by |
| 72 |
// |pkey|. For an RSA key, this returns the number of bytes needed to represent |
| 73 |
// the modulus. For an EC key, this returns the maximum size of a DER-encoded |
| 74 |
// ECDSA signature. For an ML-DSA key, this returns the signature byte size. |
| 75 |
OPENSSL_EXPORT int EVP_PKEY_size(const EVP_PKEY *pkey); |
| 76 |
|
| 77 |
// EVP_PKEY_bits returns the "size", in bits, of |pkey|. For an RSA key, this |
| 78 |
// returns the bit length of the modulus. For an EC key, this returns the bit |
| 79 |
// length of the group order. For an ML-DSA key, this returns the bit length |
| 80 |
// of the public key. |
| 81 |
OPENSSL_EXPORT int EVP_PKEY_bits(const EVP_PKEY *pkey); |
| 82 |
|
| 83 |
// EVP_PKEY_id returns the type of |pkey|, which is one of the |EVP_PKEY_*| |
| 84 |
// values. |
| 85 |
OPENSSL_EXPORT int EVP_PKEY_id(const EVP_PKEY *pkey); |
| 86 |
|
| 87 |
// EVP_PKEY_pqdsa_get_type returns the |nid| of the configured PQDSA key. |pkey| |
| 88 |
// must not be NULL. |
| 89 |
OPENSSL_EXPORT int EVP_PKEY_pqdsa_get_type(const EVP_PKEY *pkey); |
| 90 |
|
| 91 |
// EVP_MD_get0_name returns the short name of |md| |
| 92 |
OPENSSL_EXPORT const char *EVP_MD_get0_name(const EVP_MD *md); |
| 93 |
|
| 94 |
// EVP_MD_name calls |EVP_MD_get0_name| |
| 95 |
OPENSSL_EXPORT const char *EVP_MD_name(const EVP_MD *md); |
| 96 |
|
| 97 |
// EVP Password Utility Functions |
| 98 |
|
| 99 |
// EVP_get_pw_prompt returns an internal pointer to static memory containing |
| 100 |
// the default prompt. In AWS-LC, this default is hardcoded. In OpenSSL, |
| 101 |
// the default prompt must be configured by a user and is otherwise NULL. |
| 102 |
OPENSSL_EXPORT char *EVP_get_pw_prompt(void); |
| 103 |
|
| 104 |
// EVP_read_pw_string writes the prompt to /dev/tty, or, if that could not be opened, |
| 105 |
// to standard output, turns echo off, and reads an input string from /dev/tty, or, |
| 106 |
// if that could not be opened, from standard input. If |prompt| is NULL, the default |
| 107 |
// prompt is used. The user input is returned in |buf|, which must have space for at |
| 108 |
// least length bytes. If verify is set, the user is asked for the password twice and |
| 109 |
// unless the two copies match, an error is returned. |
| 110 |
// Returns 0 on success, -1 on error, or -2 on out-of-band events (Interrupt, Cancel, ...). |
| 111 |
OPENSSL_EXPORT int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); |
| 112 |
|
| 113 |
// EVP_read_pw_string_min implements the functionality for |EVP_read_pw_string|. It |
| 114 |
// additionally checks that the password is at least |min_length| bytes long. |
| 115 |
// Returns 0 on success, -1 on error, or -2 on out-of-band events (Interrupt, Cancel, ...). |
| 116 |
OPENSSL_EXPORT int EVP_read_pw_string_min(char *buf, int min_length, int length, |
| 117 |
const char *prompt, int verify); |
| 118 |
|
| 119 |
|
| 120 |
// Getting and setting concrete key types. |
| 121 |
// |
| 122 |
// The following functions get and set the underlying key representation in an |
| 123 |
// |EVP_PKEY| object. The |set1| functions take an additional reference to the |
| 124 |
// underlying key and return one on success or zero if |key| is NULL. The |
| 125 |
// |assign| functions adopt the caller's reference and return one on success or |
| 126 |
// zero if |key| is NULL. The |get1| functions return a fresh reference to the |
| 127 |
// underlying object or NULL if |pkey| is not of the correct type. The |get0| |
| 128 |
// functions behave the same but return a non-owning pointer. |
| 129 |
// |
| 130 |
// The |get0| and |get1| functions take |const| pointers and are thus |
| 131 |
// non-mutating for thread-safety purposes, but mutating functions on the |
| 132 |
// returned lower-level objects are considered to also mutate the |EVP_PKEY| and |
| 133 |
// may not be called concurrently with other operations on the |EVP_PKEY|. |
| 134 |
|
| 135 |
OPENSSL_EXPORT int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key); |
| 136 |
OPENSSL_EXPORT int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key); |
| 137 |
OPENSSL_EXPORT RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey); |
| 138 |
OPENSSL_EXPORT RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey); |
| 139 |
|
| 140 |
OPENSSL_EXPORT int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key); |
| 141 |
OPENSSL_EXPORT int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key); |
| 142 |
OPENSSL_EXPORT DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey); |
| 143 |
OPENSSL_EXPORT DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey); |
| 144 |
|
| 145 |
OPENSSL_EXPORT int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); |
| 146 |
OPENSSL_EXPORT int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key); |
| 147 |
OPENSSL_EXPORT EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey); |
| 148 |
OPENSSL_EXPORT EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey); |
| 149 |
|
| 150 |
OPENSSL_EXPORT int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key); |
| 151 |
OPENSSL_EXPORT int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key); |
| 152 |
OPENSSL_EXPORT DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey); |
| 153 |
OPENSSL_EXPORT DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey); |
| 154 |
|
| 155 |
// EVP_PKEY_CTX_set_dh_paramgen_prime_len sets the length of the DH prime |
| 156 |
// parameter p for DH parameter generation. If this function is not called, |
| 157 |
// the default length of 2048 is used. |pbits| must be greater than or equal |
| 158 |
// to 256. Returns 1 on success, otherwise returns a non-positive value. |
| 159 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int pbits); |
| 160 |
|
| 161 |
// EVP_PKEY_CTX_set_dh_paramgen_generator sets the DH generator for DH parameter |
| 162 |
// generation. If this function is not called, the default value of 2 is used. |
| 163 |
// |gen| must be greater than 1. Returns 1 on success, otherwise returns a |
| 164 |
// non-positive value. |
| 165 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen); |
| 166 |
|
| 167 |
#define EVP_PKEY_NONE NID_undef |
| 168 |
#define EVP_PKEY_RSA NID_rsaEncryption |
| 169 |
#define EVP_PKEY_RSA_PSS NID_rsassaPss |
| 170 |
#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey |
| 171 |
#define EVP_PKEY_ED25519 NID_ED25519 |
| 172 |
#define EVP_PKEY_ED25519PH NID_ED25519ph |
| 173 |
#define EVP_PKEY_X25519 NID_X25519 |
| 174 |
#define EVP_PKEY_HKDF NID_hkdf |
| 175 |
#define EVP_PKEY_HMAC NID_hmac |
| 176 |
#define EVP_PKEY_DH NID_dhKeyAgreement |
| 177 |
#define EVP_PKEY_PQDSA NID_PQDSA |
| 178 |
#define EVP_PKEY_KEM NID_kem |
| 179 |
|
| 180 |
// EVP_PKEY_set_type sets the type of |pkey| to |type|. It returns one if |
| 181 |
// successful or zero if the |type| argument is not one of the |EVP_PKEY_*| |
| 182 |
// values. If |pkey| is NULL, it simply reports whether the type is known. |
| 183 |
OPENSSL_EXPORT int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); |
| 184 |
|
| 185 |
// EVP_PKEY_set_type_str sets the type of |pkey| to the PEM type string given |
| 186 |
// by the first |len| bytes of |str|. It returns one if successful or zero if it |
| 187 |
// cannot find the PEM type among the |EVP_PKEY_*| values. If |pkey| is NULL, |
| 188 |
// it simply reports whether the type is known. |
| 189 |
OPENSSL_EXPORT int EVP_PKEY_set_type_str(EVP_PKEY *pkey, |
| 190 |
const char *str, |
| 191 |
int len); |
| 192 |
|
| 193 |
// EVP_PKEY_cmp_parameters compares the parameters of |a| and |b|. It returns |
| 194 |
// one if they match, zero if not, or a negative number of on error. |
| 195 |
// |
| 196 |
// WARNING: the return value differs from the usual return value convention. |
| 197 |
OPENSSL_EXPORT int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, |
| 198 |
const EVP_PKEY *b); |
| 199 |
|
| 200 |
|
| 201 |
// ASN.1 functions |
| 202 |
|
| 203 |
// EVP_parse_public_key decodes a DER-encoded SubjectPublicKeyInfo structure |
| 204 |
// (RFC 5280) from |cbs| and advances |cbs|. It returns a newly-allocated |
| 205 |
// |EVP_PKEY| or NULL on error. If the key is an EC key, the curve is guaranteed |
| 206 |
// to be set. |
| 207 |
// |
| 208 |
// The caller must check the type of the parsed public key to ensure it is |
| 209 |
// suitable and validate other desired key properties such as RSA modulus size |
| 210 |
// or EC curve. |
| 211 |
OPENSSL_EXPORT EVP_PKEY *EVP_parse_public_key(CBS *cbs); |
| 212 |
|
| 213 |
// EVP_marshal_public_key marshals |key| as a DER-encoded SubjectPublicKeyInfo |
| 214 |
// structure (RFC 5280) and appends the result to |cbb|. It returns one on |
| 215 |
// success and zero on error. |
| 216 |
OPENSSL_EXPORT int EVP_marshal_public_key(CBB *cbb, const EVP_PKEY *key); |
| 217 |
|
| 218 |
// EVP_parse_private_key decodes a DER-encoded PrivateKeyInfo structure (RFC |
| 219 |
// 5208) from |cbs| and advances |cbs|. It returns a newly-allocated |EVP_PKEY| |
| 220 |
// or NULL on error. |
| 221 |
// |
| 222 |
// The caller must check the type of the parsed private key to ensure it is |
| 223 |
// suitable and validate other desired key properties such as RSA modulus size |
| 224 |
// or EC curve. In particular, RSA private key operations scale cubicly, so |
| 225 |
// applications accepting RSA private keys from external sources may need to |
| 226 |
// bound key sizes (use |EVP_PKEY_bits| or |RSA_bits|) to avoid a DoS vector. |
| 227 |
// |
| 228 |
// A PrivateKeyInfo ends with an optional set of attributes. These are not |
| 229 |
// processed and so this function will silently ignore any trailing data in the |
| 230 |
// structure. |
| 231 |
OPENSSL_EXPORT EVP_PKEY *EVP_parse_private_key(CBS *cbs); |
| 232 |
|
| 233 |
// EVP_marshal_private_key marshals |key| as a DER-encoded PrivateKeyInfo |
| 234 |
// structure (RFC 5208) and appends the result to |cbb|. It returns one on |
| 235 |
// success and zero on error. For ML-DSA, the private seed is encoded. |
| 236 |
OPENSSL_EXPORT int EVP_marshal_private_key(CBB *cbb, const EVP_PKEY *key); |
| 237 |
|
| 238 |
// EVP_marshal_private_key_v2 marshals |key| as a DER-encoded |
| 239 |
// OneAsymmetricKey (RFC 5958) and appends the result to |cbb|. It returns one |
| 240 |
// on success and zero on error. |
| 241 |
// |
| 242 |
// Ed25519 and x25119 are the only private key that supports marshaling as a v2 |
| 243 |
// PKCS8 structure. All other private key types will return |
| 244 |
// UNSUPPORTED_ALGORITHM error. |
| 245 |
OPENSSL_EXPORT int EVP_marshal_private_key_v2(CBB *cbb, const EVP_PKEY *key); |
| 246 |
|
| 247 |
// Raw keys |
| 248 |
// |
| 249 |
// Some keys types support a "raw" serialization. Currently the only supported |
| 250 |
// raw formats are X25519 and Ed25519, where the formats are those specified in |
| 251 |
// RFC 7748 and RFC 8032, respectively. Note the RFC 8032 private key format |
| 252 |
// is the 32-byte prefix of |ED25519_sign|'s 64-byte private key. |
| 253 |
// For ML-DSA use EVP_PKEY_pqdsa_new_raw_private_key. |
| 254 |
|
| 255 |
// EVP_PKEY_new_raw_private_key returns a newly allocated |EVP_PKEY| wrapping a |
| 256 |
// private key of the specified type. It returns NULL on error. |
| 257 |
// For ML-DSA use EVP_PKEY_pqdsa_new_raw_public_key. |
| 258 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused, |
| 259 |
const uint8_t *in, |
| 260 |
size_t len); |
| 261 |
|
| 262 |
// EVP_PKEY_new_raw_public_key returns a newly allocated |EVP_PKEY| wrapping a |
| 263 |
// public key of the specified type. It returns NULL on error. |
| 264 |
// For ML-DSA use EVP_PKEY_pqdsa_new_raw_private_key. |
| 265 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *unused, |
| 266 |
const uint8_t *in, |
| 267 |
size_t len); |
| 268 |
|
| 269 |
// EVP_PKEY_get_raw_private_key outputs the private key for |pkey| in raw form. |
| 270 |
// If |out| is NULL, it sets |*out_len| to the size of the raw private key. |
| 271 |
// Otherwise, it writes at most |*out_len| bytes to |out| and sets |*out_len| to |
| 272 |
// the number of bytes written. |
| 273 |
// |
| 274 |
// It returns one on success and zero if |pkey| has no private key, the key |
| 275 |
// type does not support a raw format, or the buffer is too small. |
| 276 |
OPENSSL_EXPORT int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, |
| 277 |
uint8_t *out, size_t *out_len); |
| 278 |
|
| 279 |
// EVP_PKEY_get_raw_public_key outputs the public key for |pkey| in raw form. |
| 280 |
// If |out| is NULL, it sets |*out_len| to the size of the raw public key. |
| 281 |
// Otherwise, it writes at most |*out_len| bytes to |out| and sets |*out_len| to |
| 282 |
// the number of bytes written. |
| 283 |
// |
| 284 |
// It returns one on success and zero if |pkey| has no public key, the key |
| 285 |
// type does not support a raw format, or the buffer is too small. |
| 286 |
OPENSSL_EXPORT int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, |
| 287 |
uint8_t *out, size_t *out_len); |
| 288 |
|
| 289 |
|
| 290 |
// Signing |
| 291 |
|
| 292 |
// EVP_DigestSignInit sets up |ctx| for a signing operation with |type| and |
| 293 |
// |pkey|. The |ctx| argument must have been initialised with |
| 294 |
// |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing |
| 295 |
// operation will be written to |*pctx|; this can be used to set alternative |
| 296 |
// signing options. |
| 297 |
// |
| 298 |
// For single-shot signing algorithms which do not use a pre-hash, such as |
| 299 |
// Ed25519, or when using ML-DSA in non pre-hash mode, |type| should be NULL. |
| 300 |
// The |EVP_MD_CTX| itself is unused but is present so the API is uniform. |
| 301 |
// See |EVP_DigestSign|. |
| 302 |
// |
| 303 |
// This function does not mutate |pkey| for thread-safety purposes and may be |
| 304 |
// used concurrently with other non-mutating functions on |pkey|. |
| 305 |
// |
| 306 |
// It returns one on success, or zero on error. |
| 307 |
OPENSSL_EXPORT int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, |
| 308 |
const EVP_MD *type, ENGINE *e, |
| 309 |
EVP_PKEY *pkey); |
| 310 |
|
| 311 |
// EVP_DigestSignUpdate appends |len| bytes from |data| to the data which will |
| 312 |
// be signed in |EVP_DigestSignFinal|. It returns one. |
| 313 |
// |
| 314 |
// This function performs a streaming signing operation and will fail for |
| 315 |
// signature algorithms which do not support this. Use |EVP_DigestSign| for a |
| 316 |
// single-shot operation. |
| 317 |
OPENSSL_EXPORT int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, |
| 318 |
size_t len); |
| 319 |
|
| 320 |
// EVP_DigestSignFinal signs the data that has been included by one or more |
| 321 |
// calls to |EVP_DigestSignUpdate|. If |out_sig| is NULL then |*out_sig_len| is |
| 322 |
// set to the maximum number of output bytes. Otherwise, on entry, |
| 323 |
// |*out_sig_len| must contain the length of the |out_sig| buffer. If the call |
| 324 |
// is successful, the signature is written to |out_sig| and |*out_sig_len| is |
| 325 |
// set to its length. |
| 326 |
// |
| 327 |
// This function performs a streaming signing operation and will fail for |
| 328 |
// signature algorithms which do not support this. Use |EVP_DigestSign| for a |
| 329 |
// single-shot operation. |
| 330 |
// |
| 331 |
// It returns one on success, or zero on error. |
| 332 |
OPENSSL_EXPORT int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, |
| 333 |
size_t *out_sig_len); |
| 334 |
|
| 335 |
// EVP_DigestSign signs |data_len| bytes from |data| using |ctx|. If |out_sig| |
| 336 |
// is NULL then |*out_sig_len| is set to the maximum number of output |
| 337 |
// bytes. Otherwise, on entry, |*out_sig_len| must contain the length of the |
| 338 |
// |out_sig| buffer. If the call is successful, the signature is written to |
| 339 |
// |out_sig| and |*out_sig_len| is set to its length. |
| 340 |
// |
| 341 |
// It returns one on success and zero on error. |
| 342 |
OPENSSL_EXPORT int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, |
| 343 |
size_t *out_sig_len, const uint8_t *data, |
| 344 |
size_t data_len); |
| 345 |
|
| 346 |
|
| 347 |
// Verifying |
| 348 |
|
| 349 |
// EVP_DigestVerifyInit sets up |ctx| for a signature verification operation |
| 350 |
// with |type| and |pkey|. The |ctx| argument must have been initialised with |
| 351 |
// |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing |
| 352 |
// operation will be written to |*pctx|; this can be used to set alternative |
| 353 |
// signing options. |
| 354 |
// |
| 355 |
// For single-shot signing algorithms which do not use a pre-hash, such as |
| 356 |
// Ed25519, or when using ML-DSA in non pre-hash mode, |type| should be NULL. |
| 357 |
// The |EVP_MD_CTX| itself is unused but is present so the API is uniform. |
| 358 |
// See |EVP_DigestVerify|. |
| 359 |
// |
| 360 |
// This function does not mutate |pkey| for thread-safety purposes and may be |
| 361 |
// used concurrently with other non-mutating functions on |pkey|. |
| 362 |
// |
| 363 |
// It returns one on success, or zero on error. |
| 364 |
OPENSSL_EXPORT int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, |
| 365 |
const EVP_MD *type, ENGINE *e, |
| 366 |
EVP_PKEY *pkey); |
| 367 |
|
| 368 |
// EVP_DigestVerifyUpdate appends |len| bytes from |data| to the data which |
| 369 |
// will be verified by |EVP_DigestVerifyFinal|. It returns one. |
| 370 |
// |
| 371 |
// This function performs streaming signature verification and will fail for |
| 372 |
// signature algorithms which do not support this. Use |EVP_PKEY_verify_message| |
| 373 |
// for a single-shot verification. |
| 374 |
OPENSSL_EXPORT int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, |
| 375 |
size_t len); |
| 376 |
|
| 377 |
// EVP_DigestVerifyFinal verifies that |sig_len| bytes of |sig| are a valid |
| 378 |
// signature for the data that has been included by one or more calls to |
| 379 |
// |EVP_DigestVerifyUpdate|. It returns one on success and zero otherwise. |
| 380 |
// |
| 381 |
// This function performs streaming signature verification and will fail for |
| 382 |
// signature algorithms which do not support this. Use |EVP_PKEY_verify_message| |
| 383 |
// for a single-shot verification. |
| 384 |
OPENSSL_EXPORT int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 385 |
size_t sig_len); |
| 386 |
|
| 387 |
// EVP_DigestVerify verifies that |sig_len| bytes from |sig| are a valid |
| 388 |
// signature for |data|. It returns one on success or zero on error. |
| 389 |
OPENSSL_EXPORT int EVP_DigestVerify(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 390 |
size_t sig_len, const uint8_t *data, |
| 391 |
size_t len); |
| 392 |
|
| 393 |
|
| 394 |
// Signing (old functions) |
| 395 |
|
| 396 |
// EVP_SignInit_ex configures |ctx|, which must already have been initialised, |
| 397 |
// for a fresh signing operation using the hash function |type|. It returns one |
| 398 |
// on success and zero otherwise. |
| 399 |
// |
| 400 |
// (In order to initialise |ctx|, either obtain it initialised with |
| 401 |
// |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) |
| 402 |
OPENSSL_EXPORT int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, |
| 403 |
ENGINE *impl); |
| 404 |
|
| 405 |
// EVP_SignInit is a deprecated version of |EVP_SignInit_ex|. |
| 406 |
// |
| 407 |
// TODO(fork): remove. |
| 408 |
OPENSSL_EXPORT int EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
| 409 |
|
| 410 |
// EVP_SignUpdate appends |len| bytes from |data| to the data which will be |
| 411 |
// signed in |EVP_SignFinal|. |
| 412 |
OPENSSL_EXPORT int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *data, |
| 413 |
size_t len); |
| 414 |
|
| 415 |
// EVP_SignFinal signs the data that has been included by one or more calls to |
| 416 |
// |EVP_SignUpdate|, using the key |pkey|, and writes it to |sig|. On entry, |
| 417 |
// |sig| must point to at least |EVP_PKEY_size(pkey)| bytes of space. The |
| 418 |
// actual size of the signature is written to |*out_sig_len|. |
| 419 |
// |
| 420 |
// It returns one on success and zero otherwise. |
| 421 |
// |
| 422 |
// It does not modify |ctx|, thus it's possible to continue to use |ctx| in |
| 423 |
// order to sign a longer message. It also does not mutate |pkey| for |
| 424 |
// thread-safety purposes and may be used concurrently with other non-mutating |
| 425 |
// functions on |pkey|. |
| 426 |
OPENSSL_EXPORT int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig, |
| 427 |
unsigned int *out_sig_len, EVP_PKEY *pkey); |
| 428 |
|
| 429 |
|
| 430 |
// Verifying (old functions) |
| 431 |
|
| 432 |
// EVP_VerifyInit_ex configures |ctx|, which must already have been |
| 433 |
// initialised, for a fresh signature verification operation using the hash |
| 434 |
// function |type|. It returns one on success and zero otherwise. |
| 435 |
// |
| 436 |
// (In order to initialise |ctx|, either obtain it initialised with |
| 437 |
// |EVP_MD_CTX_create|, or use |EVP_MD_CTX_init|.) |
| 438 |
OPENSSL_EXPORT int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, |
| 439 |
ENGINE *impl); |
| 440 |
|
| 441 |
// EVP_VerifyInit is a deprecated version of |EVP_VerifyInit_ex|. |
| 442 |
// |
| 443 |
// TODO(fork): remove. |
| 444 |
OPENSSL_EXPORT int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
| 445 |
|
| 446 |
// EVP_VerifyUpdate appends |len| bytes from |data| to the data which will be |
| 447 |
// signed in |EVP_VerifyFinal|. |
| 448 |
OPENSSL_EXPORT int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *data, |
| 449 |
size_t len); |
| 450 |
|
| 451 |
// EVP_VerifyFinal verifies that |sig_len| bytes of |sig| are a valid |
| 452 |
// signature, by |pkey|, for the data that has been included by one or more |
| 453 |
// calls to |EVP_VerifyUpdate|. |
| 454 |
// |
| 455 |
// It returns one on success and zero otherwise. |
| 456 |
// |
| 457 |
// It does not modify |ctx|, thus it's possible to continue to use |ctx| in |
| 458 |
// order to verify a longer message. It also does not mutate |pkey| for |
| 459 |
// thread-safety purposes and may be used concurrently with other non-mutating |
| 460 |
// functions on |pkey|. |
| 461 |
OPENSSL_EXPORT int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, |
| 462 |
size_t sig_len, EVP_PKEY *pkey); |
| 463 |
|
| 464 |
|
| 465 |
// Printing |
| 466 |
|
| 467 |
// EVP_PKEY_print_public prints a textual representation of the public key in |
| 468 |
// |pkey| to |out|. Returns one on success or zero otherwise. |
| 469 |
OPENSSL_EXPORT int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, |
| 470 |
int indent, ASN1_PCTX *pctx); |
| 471 |
|
| 472 |
// EVP_PKEY_print_private prints a textual representation of the private key in |
| 473 |
// |pkey| to |out|. Returns one on success or zero otherwise. |
| 474 |
OPENSSL_EXPORT int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, |
| 475 |
int indent, ASN1_PCTX *pctx); |
| 476 |
|
| 477 |
// EVP_PKEY_print_params prints a textual representation of the parameters in |
| 478 |
// |pkey| to |out|. Returns one on success or zero otherwise. |
| 479 |
OPENSSL_EXPORT int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, |
| 480 |
int indent, ASN1_PCTX *pctx); |
| 481 |
|
| 482 |
|
| 483 |
// Password stretching. |
| 484 |
// |
| 485 |
// Password stretching functions take a low-entropy password and apply a slow |
| 486 |
// function that results in a key suitable for use in symmetric |
| 487 |
// cryptography. |
| 488 |
|
| 489 |
// PKCS5_SALT_LEN is a deprecated constant as used by deprecated |
| 490 |
// EVP_BytesToKey() which cannot change. |
| 491 |
#define PKCS5_SALT_LEN 8 |
| 492 |
|
| 493 |
// PKCS5_PBKDF2_HMAC computes |iterations| iterations of PBKDF2 of |password| |
| 494 |
// and |salt|, using |digest|, and outputs |key_len| bytes to |out_key|. It |
| 495 |
// returns one on success and zero on allocation failure or if |iterations| is |
| 496 |
// 0. It's recommended that |iterations| be set to a much higher number (at |
| 497 |
// least hundreds of thousands). |
| 498 |
OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len, |
| 499 |
const uint8_t *salt, size_t salt_len, |
| 500 |
uint32_t iterations, const EVP_MD *digest, |
| 501 |
size_t key_len, uint8_t *out_key); |
| 502 |
|
| 503 |
// PKCS5_PBKDF2_HMAC_SHA1 is the same as PKCS5_PBKDF2_HMAC, but with |digest| |
| 504 |
// fixed to |EVP_sha1|. |
| 505 |
OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC_SHA1(const char *password, |
| 506 |
size_t password_len, |
| 507 |
const uint8_t *salt, size_t salt_len, |
| 508 |
uint32_t iterations, size_t key_len, |
| 509 |
uint8_t *out_key); |
| 510 |
|
| 511 |
// EVP_PBE_scrypt expands |password| into a secret key of length |key_len| using |
| 512 |
// scrypt, as described in RFC 7914, and writes the result to |out_key|. It |
| 513 |
// returns one on success and zero on allocation failure, if the memory required |
| 514 |
// for the operation exceeds |max_mem|, or if any of the parameters are invalid |
| 515 |
// as described below. |
| 516 |
// |
| 517 |
// |N|, |r|, and |p| are as described in RFC 7914 section 6. They determine the |
| 518 |
// cost of the operation. If |max_mem| is zero, a defult limit of 32MiB will be |
| 519 |
// used. |
| 520 |
// |
| 521 |
// The parameters are considered invalid under any of the following conditions: |
| 522 |
// - |r| or |p| are zero |
| 523 |
// - |p| > (2^30 - 1) / |r| |
| 524 |
// - |N| is not a power of two |
| 525 |
// - |N| > 2^32 |
| 526 |
// - |N| > 2^(128 * |r| / 8) |
| 527 |
OPENSSL_EXPORT int EVP_PBE_scrypt(const char *password, size_t password_len, |
| 528 |
const uint8_t *salt, size_t salt_len, |
| 529 |
uint64_t N, uint64_t r, uint64_t p, |
| 530 |
size_t max_mem, uint8_t *out_key, |
| 531 |
size_t key_len); |
| 532 |
|
| 533 |
|
| 534 |
// Public key contexts. |
| 535 |
// |
| 536 |
// |EVP_PKEY_CTX| objects hold the context of an operation (e.g. signing or |
| 537 |
// encrypting) that uses a public key. |
| 538 |
|
| 539 |
// EVP_PKEY_CTX_new allocates a fresh |EVP_PKEY_CTX| for use with |pkey|. It |
| 540 |
// returns the context or NULL on error. |
| 541 |
OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); |
| 542 |
|
| 543 |
// EVP_PKEY_CTX_new_id allocates a fresh |EVP_PKEY_CTX| for a key of type |id| |
| 544 |
// (e.g. |EVP_PKEY_HMAC|). This can be used for key generation where |
| 545 |
// |EVP_PKEY_CTX_new| can't be used because there isn't an |EVP_PKEY| to pass |
| 546 |
// it. It returns the context or NULL on error. |
| 547 |
OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); |
| 548 |
|
| 549 |
// EVP_PKEY_CTX_free frees |ctx| and the data it owns. |
| 550 |
OPENSSL_EXPORT void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); |
| 551 |
|
| 552 |
// EVP_PKEY_CTX_dup allocates a fresh |EVP_PKEY_CTX| and sets it equal to the |
| 553 |
// state of |ctx|. It returns the fresh |EVP_PKEY_CTX| or NULL on error. |
| 554 |
OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); |
| 555 |
|
| 556 |
// EVP_PKEY_CTX_get0_pkey returns the |EVP_PKEY| associated with |ctx|. |
| 557 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); |
| 558 |
|
| 559 |
// EVP_PKEY_sign_init initialises an |EVP_PKEY_CTX| for a signing operation. It |
| 560 |
// should be called before |EVP_PKEY_sign|. |
| 561 |
// |
| 562 |
// It returns one on success or zero on error. |
| 563 |
OPENSSL_EXPORT int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); |
| 564 |
|
| 565 |
// EVP_PKEY_sign signs |digest_len| bytes from |digest| using |ctx|. If |sig| is |
| 566 |
// NULL, the maximum size of the signature is written to |out_sig_len|. |
| 567 |
// Otherwise, |*sig_len| must contain the number of bytes of space available at |
| 568 |
// |sig|. If sufficient, the signature will be written to |sig| and |*sig_len| |
| 569 |
// updated with the true length. This function will fail for signature |
| 570 |
// Ed25519 as it does not support signing pre-hashed inputs. For ML-DSA this |
| 571 |
// function expects the format of |digest| to conform with "ExternalMu", i.e., |
| 572 |
// the digest mu is the SHAKE256 hash of the associated public key concatenated |
| 573 |
// with a zero byte to indicate pure-mode, the context string length, the |
| 574 |
// contents of the context string, and the input message in this order e.g. |
| 575 |
// mu = SHAKE256(SHAKE256(pk) || 0 || |ctx| || ctx || M). |
| 576 |
// |
| 577 |
// |
| 578 |
// WARNING: |digest| must be the output of some hash function on the data to be |
| 579 |
// signed. Passing unhashed inputs will not result in a secure signature scheme. |
| 580 |
// Use |EVP_DigestSignInit| to sign an unhashed input. |
| 581 |
// |
| 582 |
// WARNING: Setting |sig| to NULL only gives the maximum size of the |
| 583 |
// signature. The actual signature may be smaller. |
| 584 |
// |
| 585 |
// It returns one on success or zero on error. (Note: this differs from |
| 586 |
// OpenSSL, which can also return negative values to indicate an error. ) |
| 587 |
OPENSSL_EXPORT int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, |
| 588 |
size_t *sig_len, const uint8_t *digest, |
| 589 |
size_t digest_len); |
| 590 |
|
| 591 |
// EVP_PKEY_verify_init initialises an |EVP_PKEY_CTX| for a signature |
| 592 |
// verification operation. It should be called before |EVP_PKEY_verify|. |
| 593 |
// |
| 594 |
// It returns one on success or zero on error. |
| 595 |
OPENSSL_EXPORT int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); |
| 596 |
|
| 597 |
// EVP_PKEY_verify verifies that |sig_len| bytes from |sig| are a valid |
| 598 |
// signature for |digest|. This function will fail for signature |
| 599 |
// Ed25519 as it does not support signing pre-hashed inputs. For ML-DSA this |
| 600 |
// function expects the format of |digest| to conform with "ExternalMu", i.e., |
| 601 |
// the digest mu is the SHAKE256 hash of the associated public key concatenated |
| 602 |
// with a zero byte to indicate pure-mode, the context string length, the |
| 603 |
// contents of the context string, and the input message in this order e.g. |
| 604 |
// mu = SHAKE256(SHAKE256(pk) || 0 || |ctx| || ctx || M). |
| 605 |
// |
| 606 |
// WARNING: |digest| must be the output of some hash function on the data to be |
| 607 |
// verified. Passing unhashed inputs will not result in a secure signature |
| 608 |
// scheme. Use |EVP_DigestVerifyInit| to verify a signature given the unhashed |
| 609 |
// input. |
| 610 |
// |
| 611 |
// It returns one on success or zero on error. |
| 612 |
OPENSSL_EXPORT int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig, |
| 613 |
size_t sig_len, const uint8_t *digest, |
| 614 |
size_t digest_len); |
| 615 |
|
| 616 |
// EVP_PKEY_encrypt_init initialises an |EVP_PKEY_CTX| for an encryption |
| 617 |
// operation. It should be called before |EVP_PKEY_encrypt|. |
| 618 |
// |
| 619 |
// It returns one on success or zero on error. |
| 620 |
OPENSSL_EXPORT int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); |
| 621 |
|
| 622 |
// EVP_PKEY_encrypt encrypts |in_len| bytes from |in|. If |out| is NULL, the |
| 623 |
// maximum size of the ciphertext is written to |out_len|. Otherwise, |*out_len| |
| 624 |
// must contain the number of bytes of space available at |out|. If sufficient, |
| 625 |
// the ciphertext will be written to |out| and |*out_len| updated with the true |
| 626 |
// length. |
| 627 |
// |
| 628 |
// WARNING: Setting |out| to NULL only gives the maximum size of the |
| 629 |
// ciphertext. The actual ciphertext may be smaller. |
| 630 |
// |
| 631 |
// It returns one on success or zero on error. |
| 632 |
OPENSSL_EXPORT int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 633 |
size_t *out_len, const uint8_t *in, |
| 634 |
size_t in_len); |
| 635 |
|
| 636 |
// EVP_PKEY_decrypt_init initialises an |EVP_PKEY_CTX| for a decryption |
| 637 |
// operation. It should be called before |EVP_PKEY_decrypt|. |
| 638 |
// |
| 639 |
// It returns one on success or zero on error. |
| 640 |
OPENSSL_EXPORT int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); |
| 641 |
|
| 642 |
// EVP_PKEY_decrypt decrypts |in_len| bytes from |in|. If |out| is NULL, the |
| 643 |
// maximum size of the plaintext is written to |out_len|. Otherwise, |*out_len| |
| 644 |
// must contain the number of bytes of space available at |out|. If sufficient, |
| 645 |
// the ciphertext will be written to |out| and |*out_len| updated with the true |
| 646 |
// length. |
| 647 |
// |
| 648 |
// WARNING: Setting |out| to NULL only gives the maximum size of the |
| 649 |
// plaintext. The actual plaintext may be smaller. |
| 650 |
// |
| 651 |
// It returns one on success or zero on error. |
| 652 |
OPENSSL_EXPORT int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 653 |
size_t *out_len, const uint8_t *in, |
| 654 |
size_t in_len); |
| 655 |
|
| 656 |
// EVP_PKEY_verify_recover_init initialises an |EVP_PKEY_CTX| for a public-key |
| 657 |
// decryption operation. It should be called before |EVP_PKEY_verify_recover|. |
| 658 |
// |
| 659 |
// Public-key decryption is a very obscure operation that is only implemented |
| 660 |
// by RSA keys. It is effectively a signature verification operation that |
| 661 |
// returns the signed message directly. It is almost certainly not what you |
| 662 |
// want. |
| 663 |
// |
| 664 |
// It returns one on success or zero on error. |
| 665 |
OPENSSL_EXPORT int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); |
| 666 |
|
| 667 |
// EVP_PKEY_verify_recover decrypts |sig_len| bytes from |sig|. If |out| is |
| 668 |
// NULL, the maximum size of the plaintext is written to |out_len|. Otherwise, |
| 669 |
// |*out_len| must contain the number of bytes of space available at |out|. If |
| 670 |
// sufficient, the ciphertext will be written to |out| and |*out_len| updated |
| 671 |
// with the true length. |
| 672 |
// |
| 673 |
// WARNING: Setting |out| to NULL only gives the maximum size of the |
| 674 |
// plaintext. The actual plaintext may be smaller. |
| 675 |
// |
| 676 |
// See the warning about this operation in |EVP_PKEY_verify_recover_init|. It |
| 677 |
// is probably not what you want. |
| 678 |
// |
| 679 |
// It returns one on success or zero on error. |
| 680 |
OPENSSL_EXPORT int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, uint8_t *out, |
| 681 |
size_t *out_len, const uint8_t *sig, |
| 682 |
size_t siglen); |
| 683 |
|
| 684 |
// EVP_PKEY_derive_init initialises an |EVP_PKEY_CTX| for a key derivation |
| 685 |
// operation. It should be called before |EVP_PKEY_derive_set_peer| and |
| 686 |
// |EVP_PKEY_derive|. |
| 687 |
// |
| 688 |
// It returns one on success or zero on error. |
| 689 |
OPENSSL_EXPORT int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); |
| 690 |
|
| 691 |
// EVP_PKEY_derive_set_peer sets the peer's key to be used for key derivation |
| 692 |
// by |ctx| to |peer|. It should be called after |EVP_PKEY_derive_init|. (For |
| 693 |
// example, this is used to set the peer's key in (EC)DH.) It returns one on |
| 694 |
// success and zero on error. |
| 695 |
OPENSSL_EXPORT int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); |
| 696 |
|
| 697 |
// EVP_PKEY_derive derives a shared key from |ctx|. If |key| is non-NULL then, |
| 698 |
// on entry, |out_key_len| must contain the amount of space at |key|. If |
| 699 |
// sufficient then the shared key will be written to |key| and |*out_key_len| |
| 700 |
// will be set to the length. If |key| is NULL then |out_key_len| will be set to |
| 701 |
// the maximum length. |
| 702 |
// |
| 703 |
// WARNING: Setting |out| to NULL only gives the maximum size of the key. The |
| 704 |
// actual key may be smaller. |
| 705 |
// |
| 706 |
// It returns one on success and zero on error. |
| 707 |
OPENSSL_EXPORT int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, uint8_t *key, |
| 708 |
size_t *out_key_len); |
| 709 |
|
| 710 |
// EVP_PKEY_check supports EC and RSA keys and validates both the public and |
| 711 |
// private components of a key pair. For EC keys, it verifies that the private |
| 712 |
// key component exists and calls EC_KEY_check_key. For RSA keys, it calls |
| 713 |
// RSA_check_key which validates both public and private key relationships. |
| 714 |
// |
| 715 |
// It returns one on success and zero on error. |
| 716 |
OPENSSL_EXPORT int EVP_PKEY_check(EVP_PKEY_CTX *ctx); |
| 717 |
|
| 718 |
// EVP_PKEY_public_check validates at least the public component of a key. |
| 719 |
// For EC keys, this calls |EC_KEY_check_key| which validates the public component, |
| 720 |
// and if available, the private key as well. |
| 721 |
// For RSA keys, this calls |RSA_check_key| which requires the public and private |
| 722 |
// components of the key pair. This is different from OpenSSL which does not |
| 723 |
// support RSA keys via this API. |
| 724 |
// |
| 725 |
// It returns one on success and zero on error. |
| 726 |
OPENSSL_EXPORT int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx); |
| 727 |
|
| 728 |
// EVP_PKEY_param_check validates the parameters component of the key given by |
| 729 |
// |ctx|. OpenSSL only supports by DH and EC keys via this API. |
| 730 |
// For DH keys, this calls |DH_check| to validate the parameters. EC key |
| 731 |
// parameter validations are not supported as of now. |
| 732 |
// TODO: Support EC group validations. |
| 733 |
// |
| 734 |
// It returns one on success and zero on error. |
| 735 |
OPENSSL_EXPORT int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx); |
| 736 |
|
| 737 |
// EVP_PKEY_keygen_init initialises an |EVP_PKEY_CTX| for a key generation |
| 738 |
// operation. It should be called before |EVP_PKEY_keygen|. |
| 739 |
// |
| 740 |
// It returns one on success or zero on error. |
| 741 |
OPENSSL_EXPORT int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); |
| 742 |
|
| 743 |
// EVP_PKEY_keygen performs a key generation operation using the values from |
| 744 |
// |ctx|. If |*out_pkey| is non-NULL, it overwrites |*out_pkey| with the |
| 745 |
// resulting key. Otherwise, it sets |*out_pkey| to a newly-allocated |EVP_PKEY| |
| 746 |
// containing the result. It returns one on success or zero on error. |
| 747 |
OPENSSL_EXPORT int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **out_pkey); |
| 748 |
|
| 749 |
// EVP_PKEY_encapsulate is an operation defined for a KEM (Key Encapsulation |
| 750 |
// Mechanism). For the KEM specified in |ctx|, the function: |
| 751 |
// 1. generates a random value and writes it to |shared_secret|, |
| 752 |
// 2. encapsulates the shared secret, producing the ciphertext, by using |
| 753 |
// the public key in |ctx|, and writes the ciphertext to |ciphertext|, |
| 754 |
// 3. writes the length of |ciphertext| and |shared_secret| to |
| 755 |
// |ciphertext_len| and |shared_secret_len|. |
| 756 |
// |
| 757 |
// The function requires that output buffers, |ciphertext| and |shared_secret|, |
| 758 |
// be either both NULL or both non-NULL. Otherwise, a failure is returned. |
| 759 |
// |
| 760 |
// If both |ciphertext| and |shared_secret| are NULL it is assumed that |
| 761 |
// the caller is doing a size check: the function will write the size of |
| 762 |
// the ciphertext and the shared secret in |ciphertext_len| and |
| 763 |
// |shared_secret_len| and return successfully. |
| 764 |
// |
| 765 |
// If both |ciphertext| and |shared_secret| are not NULL it is assumed that |
| 766 |
// the caller is performing the actual operation. The function will check |
| 767 |
// additionally if the lengths of the output buffers, |ciphertext_len| and |
| 768 |
// |shared_secret_len|, are large enough for the KEM. |
| 769 |
// |
| 770 |
// NOTE: no allocation is done in the function, the caller is expected to |
| 771 |
// provide large enough |ciphertext| and |shared_secret| buffers. |
| 772 |
// |
| 773 |
// It returns one on success or zero on error. |
| 774 |
OPENSSL_EXPORT int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx /* IN */, |
| 775 |
uint8_t *ciphertext /* OUT */, |
| 776 |
size_t *ciphertext_len /* OUT */, |
| 777 |
uint8_t *shared_secret /* OUT */, |
| 778 |
size_t *shared_secret_len /* OUT */); |
| 779 |
|
| 780 |
// EVP_PKEY_decapsulate is an operation defined for a KEM (Key Encapsulation |
| 781 |
// Mechanism). For the KEM specified in |ctx|, the function: |
| 782 |
// 1. decapsulates the shared secret from the given |ciphertext| using the |
| 783 |
// secret key configured in |ctx| and writes it to |shared_secret|, |
| 784 |
// 2. writes the length of |shared_secret| to |shared_secret_len|. |
| 785 |
// |
| 786 |
// If the given |shared_secret| is NULL it is assumed that the caller is doing |
| 787 |
// a size check: the function will write the size of the shared secret in |
| 788 |
// |shared_secret_len| and return successfully. |
| 789 |
// |
| 790 |
// If |shared_secret| is non-NULL it is assumed that the caller is performing |
| 791 |
// the actual operation. The functions will check additionally if the length of |
| 792 |
// the output buffer |shared_secret_len| is large enough for the KEM. |
| 793 |
// |
| 794 |
// NOTE: no allocation is done in the function, the caller is expected to |
| 795 |
// provide large enough |shared_secret| buffer. |
| 796 |
// |
| 797 |
// It returns one on success or zero on error. |
| 798 |
OPENSSL_EXPORT int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx /* IN */, |
| 799 |
uint8_t *shared_secret /* OUT */, |
| 800 |
size_t *shared_secret_len /* OUT */, |
| 801 |
const uint8_t *ciphertext /* IN */, |
| 802 |
size_t ciphertext_len /* IN */); |
| 803 |
|
| 804 |
// EVP_PKEY_paramgen_init initialises an |EVP_PKEY_CTX| for a parameter |
| 805 |
// generation operation. It should be called before |EVP_PKEY_paramgen|. |
| 806 |
// |
| 807 |
// It returns one on success or zero on error. |
| 808 |
OPENSSL_EXPORT int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); |
| 809 |
|
| 810 |
// EVP_PKEY_paramgen performs a parameter generation using the values from |
| 811 |
// |ctx|. If |*out_pkey| is non-NULL, it overwrites |*out_pkey| with the |
| 812 |
// resulting parameters, but no key. Otherwise, it sets |*out_pkey| to a |
| 813 |
// newly-allocated |EVP_PKEY| containing the result. It returns one on success |
| 814 |
// or zero on error. |
| 815 |
OPENSSL_EXPORT int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **out_pkey); |
| 816 |
|
| 817 |
|
| 818 |
// Generic control functions. |
| 819 |
|
| 820 |
// EVP_PKEY_CTX_set_signature_md sets |md| as the digest to be used in a |
| 821 |
// signature operation. It returns one on success or zero on error. |
| 822 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, |
| 823 |
const EVP_MD *md); |
| 824 |
|
| 825 |
// EVP_PKEY_CTX_get_signature_md sets |*out_md| to the digest to be used in a |
| 826 |
// signature operation. It returns one on success or zero on error. |
| 827 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, |
| 828 |
const EVP_MD **out_md); |
| 829 |
|
| 830 |
|
| 831 |
// EVP_PKEY_CTX_set1_signature_context_string sets |context| of length |context_len| to |
| 832 |
// be used as the context octet string for the signing operation. |context| will |
| 833 |
// be copied to an internal buffer allowing for the caller to free it |
| 834 |
// afterwards. |
| 835 |
// |
| 836 |
// EVP_PKEY_ED25519PH and EVP_PKEY_PQDSA are the key types that currently |
| 837 |
// support setting a signature context. For Ed25519ph, the context is used in |
| 838 |
// computing the HashEdDSA signature. For ML-DSA (PQDSA), the context string is |
| 839 |
// used per FIPS 204 sections 5.2-5.3. The maximum context length is 255 bytes. |
| 840 |
// Note: for ML-DSA, the context string is only used with |
| 841 |
// |EVP_DigestSign|/|EVP_DigestVerify| (message signing). It is not permitted |
| 842 |
// and will return an error when using |EVP_PKEY_sign|/|EVP_PKEY_verify| |
| 843 |
// (digest signing), because the pre-hashed |mu| input already encodes the |
| 844 |
// context per FIPS 204 section 5.3. |
| 845 |
// |
| 846 |
// It returns one on success or zero on error. |
| 847 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set1_signature_context_string(EVP_PKEY_CTX *ctx, |
| 848 |
const uint8_t *context, |
| 849 |
size_t context_len); |
| 850 |
|
| 851 |
// EVP_PKEY_CTX_set_signature_context is the previous name for |
| 852 |
// |EVP_PKEY_CTX_set1_signature_context_string|. It is retained for backward |
| 853 |
// compatibility. |
| 854 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_signature_context(EVP_PKEY_CTX *ctx, |
| 855 |
const uint8_t *context, |
| 856 |
size_t context_len); |
| 857 |
|
| 858 |
// EVP_PKEY_CTX_get0_signature_context sets |*context| to point to the internal |
| 859 |
// buffer containing the signing context octet string (which may be NULL) and |
| 860 |
// writes the length to |*context_len|. |
| 861 |
// |
| 862 |
// EVP_PKEY_ED25519PH and EVP_PKEY_PQDSA are the key types that currently |
| 863 |
// support retrieving a signature context. |
| 864 |
// |
| 865 |
// It returns one on success or zero on error. |
| 866 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get0_signature_context(EVP_PKEY_CTX *ctx, |
| 867 |
const uint8_t **context, |
| 868 |
size_t *context_len); |
| 869 |
|
| 870 |
// RSA specific control functions. |
| 871 |
|
| 872 |
// EVP_PKEY_CTX_set_rsa_padding sets the padding type to use. It should be one |
| 873 |
// of the |RSA_*_PADDING| values. Returns one on success or zero on error. By |
| 874 |
// default, the padding is |RSA_PKCS1_PADDING|. |
| 875 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int padding); |
| 876 |
|
| 877 |
// EVP_PKEY_CTX_get_rsa_padding sets |*out_padding| to the current padding |
| 878 |
// value, which is one of the |RSA_*_PADDING| values. Returns one on success or |
| 879 |
// zero on error. |
| 880 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, |
| 881 |
int *out_padding); |
| 882 |
|
| 883 |
// EVP_PKEY_CTX_set_rsa_pss_saltlen sets the length of the salt in a PSS-padded |
| 884 |
// signature. A value of -1 cause the salt to be the same length as the digest |
| 885 |
// in the signature. A value of -2 causes the salt to be the maximum length |
| 886 |
// that will fit when signing and recovered from the signature when verifying. |
| 887 |
// Otherwise the value gives the size of the salt in bytes. |
| 888 |
// |
| 889 |
// If unsure, use -1. |
| 890 |
// |
| 891 |
// Returns one on success or zero on error. |
| 892 |
// |
| 893 |
// TODO(davidben): The default is currently -2. Switch it to -1. |
| 894 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, |
| 895 |
int salt_len); |
| 896 |
|
| 897 |
// EVP_PKEY_CTX_get_rsa_pss_saltlen sets |*out_salt_len| to the salt length of |
| 898 |
// a PSS-padded signature. See the documentation for |
| 899 |
// |EVP_PKEY_CTX_set_rsa_pss_saltlen| for details of the special values that it |
| 900 |
// can take. |
| 901 |
// |
| 902 |
// Returns one on success or zero on error. |
| 903 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, |
| 904 |
int *out_salt_len); |
| 905 |
|
| 906 |
// EVP_PKEY_CTX_set_rsa_keygen_bits sets the size of the desired RSA modulus, |
| 907 |
// in bits, for key generation. Returns one on success or zero on |
| 908 |
// error. |
| 909 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, |
| 910 |
int bits); |
| 911 |
|
| 912 |
// EVP_PKEY_CTX_set_rsa_keygen_pubexp sets |e| as the public exponent for key |
| 913 |
// generation. Returns one on success or zero on error. On success, |ctx| takes |
| 914 |
// ownership of |e|. The library will then call |BN_free| on |e| when |ctx| is |
| 915 |
// destroyed. |
| 916 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, |
| 917 |
BIGNUM *e); |
| 918 |
|
| 919 |
// EVP_PKEY_CTX_set_rsa_oaep_md sets |md| as the digest used in OAEP padding. |
| 920 |
// Returns one on success or zero on error. If unset, the default is SHA-1. |
| 921 |
// Callers are recommended to overwrite this default. |
| 922 |
// |
| 923 |
// TODO(davidben): Remove the default and require callers specify this. |
| 924 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, |
| 925 |
const EVP_MD *md); |
| 926 |
|
| 927 |
// EVP_PKEY_CTX_get_rsa_oaep_md sets |*out_md| to the digest function used in |
| 928 |
// OAEP padding. Returns one on success or zero on error. |
| 929 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, |
| 930 |
const EVP_MD **out_md); |
| 931 |
|
| 932 |
// EVP_PKEY_CTX_set_rsa_mgf1_md sets |md| as the digest used in MGF1. Returns |
| 933 |
// one on success or zero on error. |
| 934 |
// |
| 935 |
// If unset, the default is the signing hash for |RSA_PKCS1_PSS_PADDING| and the |
| 936 |
// OAEP hash for |RSA_PKCS1_OAEP_PADDING|. Callers are recommended to use this |
| 937 |
// default and not call this function. |
| 938 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, |
| 939 |
const EVP_MD *md); |
| 940 |
|
| 941 |
// EVP_PKEY_CTX_get_rsa_mgf1_md sets |*out_md| to the digest function used in |
| 942 |
// MGF1. Returns one on success or zero on error. |
| 943 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, |
| 944 |
const EVP_MD **out_md); |
| 945 |
|
| 946 |
// EVP_PKEY_CTX_set0_rsa_oaep_label sets |label_len| bytes from |label| as the |
| 947 |
// label used in OAEP. DANGER: On success, this call takes ownership of |label| |
| 948 |
// and will call |OPENSSL_free| on it when |ctx| is destroyed. |
| 949 |
// |
| 950 |
// Returns one on success or zero on error. |
| 951 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, |
| 952 |
uint8_t *label, |
| 953 |
size_t label_len); |
| 954 |
|
| 955 |
// EVP_PKEY_CTX_get0_rsa_oaep_label sets |*out_label| to point to the internal |
| 956 |
// buffer containing the OAEP label (which may be NULL) and returns the length |
| 957 |
// of the label or a negative value on error. |
| 958 |
// |
| 959 |
// WARNING: the return value differs from the usual return value convention. |
| 960 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, |
| 961 |
const uint8_t **out_label); |
| 962 |
|
| 963 |
|
| 964 |
// EC specific control functions. |
| 965 |
|
| 966 |
// EVP_PKEY_CTX_set_ec_paramgen_curve_nid sets the curve used for |
| 967 |
// |EVP_PKEY_keygen| or |EVP_PKEY_paramgen| operations to |nid|. It returns one |
| 968 |
// on success and zero on error. |
| 969 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, |
| 970 |
int nid); |
| 971 |
|
| 972 |
// KEM specific functions. |
| 973 |
|
| 974 |
// EVP_PKEY_CTX_kem_set_params sets in |ctx| the parameters associated with the |
| 975 |
// KEM defined by the given |nid|. It returns one on success and zero on error. |
| 976 |
OPENSSL_EXPORT int EVP_PKEY_CTX_kem_set_params(EVP_PKEY_CTX *ctx, int nid); |
| 977 |
|
| 978 |
// EVP_PKEY_kem_new_raw_public_key generates a new EVP_PKEY object of type |
| 979 |
// EVP_PKEY_KEM, initializes the KEM key based on |nid| and populates the |
| 980 |
// public key part of the KEM key with the contents of |in|. It returns the |
| 981 |
// pointer to the allocated PKEY on sucess and NULL on error. |
| 982 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_kem_new_raw_public_key( |
| 983 |
int nid, const uint8_t *in, size_t len); |
| 984 |
|
| 985 |
// EVP_PKEY_kem_new_raw_secret_key generates a new EVP_PKEY object of type |
| 986 |
// EVP_PKEY_KEM, initializes the KEM key based on |nid| and populates the |
| 987 |
// secret key part of the KEM key with the contents of |in|. It returns the |
| 988 |
// pointer to the allocated PKEY on sucess and NULL on error. |
| 989 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_kem_new_raw_secret_key( |
| 990 |
int nid, const uint8_t *in, size_t len); |
| 991 |
|
| 992 |
// EVP_PKEY_kem_new_raw_key generates a new EVP_PKEY object of type |
| 993 |
// EVP_PKEY_KEM, initializes the KEM key based on |nid| and populates the |
| 994 |
// public and secret key parts of the KEM key with the contents of |in_public| |
| 995 |
// and |in_secret|. It returns the pointer to the allocated PKEY on sucess and |
| 996 |
// NULL on error. |
| 997 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_kem_new_raw_key(int nid, |
| 998 |
const uint8_t *in_public, |
| 999 |
size_t len_public, |
| 1000 |
const uint8_t *in_secret, |
| 1001 |
size_t len_secret); |
| 1002 |
|
| 1003 |
// EVP_PKEY_kem_check_key validates that the public key in |key| corresponds |
| 1004 |
// to the secret key in |key|. |
| 1005 |
OPENSSL_EXPORT int EVP_PKEY_kem_check_key(EVP_PKEY *key); |
| 1006 |
|
| 1007 |
// EVP_PKEY_kem_get_type returns the |nid| of the configured KEM key in |pkey|. |
| 1008 |
// If |pkey| is not of type |EVP_PKEY_KEM|, it returns 0 and pushes |
| 1009 |
// |EVP_R_EXPECTING_A_KEM_KEY| onto the error queue. If |pkey| is of type |
| 1010 |
// |EVP_PKEY_KEM| but has no underlying KEM key attached, it returns 0 and |
| 1011 |
// pushes |EVP_R_NO_PARAMETERS_SET| onto the error queue. |pkey| must not be |
| 1012 |
// NULL. |
| 1013 |
OPENSSL_EXPORT int EVP_PKEY_kem_get_type(const EVP_PKEY *pkey); |
| 1014 |
|
| 1015 |
// PQDSA specific functions. |
| 1016 |
|
| 1017 |
// EVP_PKEY_CTX_pqdsa_set_params sets in |ctx| the parameters associated with |
| 1018 |
// the signature scheme defined by the given |nid|. It returns one on success |
| 1019 |
// and zero on error. |
| 1020 |
OPENSSL_EXPORT int EVP_PKEY_CTX_pqdsa_set_params(EVP_PKEY_CTX *ctx, int nid); |
| 1021 |
|
| 1022 |
// EVP_PKEY_pqdsa_new_raw_public_key generates a new EVP_PKEY object of type |
| 1023 |
// EVP_PKEY_PQDSA, initializes the PQDSA key based on |nid| and populates the |
| 1024 |
// public key part of the PQDSA key with the contents of |in|. It returns the |
| 1025 |
// pointer to the allocated PKEY on sucess and NULL on error. |
| 1026 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_pqdsa_new_raw_public_key(int nid, const uint8_t *in, size_t len); |
| 1027 |
|
| 1028 |
// EVP_PKEY_pqdsa_new_raw_private_key generates a new EVP_PKEY object of type |
| 1029 |
// EVP_PKEY_PQDSA, initializes the PQDSA key based on |nid| and populates the |
| 1030 |
// secret key part of the PQDSA key with the contents of |in|. If the contents |
| 1031 |
// of |in| is the private key seed, then this function will generate the |
| 1032 |
// corresponding key pair and populate both public and private parts of the PKEY. |
| 1033 |
// It returns the pointer to the allocated PKEY on sucess and NULL on error. |
| 1034 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_pqdsa_new_raw_private_key(int nid, const uint8_t *in, size_t len); |
| 1035 |
|
| 1036 |
// Diffie-Hellman-specific control functions. |
| 1037 |
|
| 1038 |
// EVP_PKEY_CTX_set_dh_pad configures configures whether |ctx|, which must be an |
| 1039 |
// |EVP_PKEY_derive| operation, configures the handling of leading zeros in the |
| 1040 |
// Diffie-Hellman shared secret. If |pad| is zero, leading zeros are removed |
| 1041 |
// from the secret. If |pad| is non-zero, the fixed-width shared secret is used |
| 1042 |
// unmodified, as in PKCS #3. If this function is not called, the default is to |
| 1043 |
// remove leading zeros. |
| 1044 |
// |
| 1045 |
// WARNING: The behavior when |pad| is zero leaks information about the shared |
| 1046 |
// secret. This may result in side channel attacks such as |
| 1047 |
// https://raccoon-attack.com/, particularly when the same private key is used |
| 1048 |
// for multiple operations. |
| 1049 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad); |
| 1050 |
|
| 1051 |
|
| 1052 |
// ASN1 functions |
| 1053 |
|
| 1054 |
// EVP_PKEY_asn1_get_count returns the number of available |
| 1055 |
// |EVP_PKEY_ASN1_METHOD| structures. |
| 1056 |
OPENSSL_EXPORT int EVP_PKEY_asn1_get_count(void); |
| 1057 |
|
| 1058 |
// EVP_PKEY_asn1_get0 returns a pointer to an EVP_PKEY_ASN1_METHOD structure. |
| 1059 |
// |idx| is the index value, which must be a non-negative value smaller than |
| 1060 |
// the return value of |EVP_PKEY_asn1_get_count|. |
| 1061 |
OPENSSL_EXPORT const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); |
| 1062 |
|
| 1063 |
// EVP_PKEY_asn1_find finds an |EVP_PKEY_ASN1_METHOD| structure for the given |
| 1064 |
// key |type|, e.g. |EVP_PKEY_EC| or |EVP_PKEY_RSA|. |pe| is ignored. |
| 1065 |
OPENSSL_EXPORT const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **_pe, |
| 1066 |
int type); |
| 1067 |
|
| 1068 |
// EVP_PKEY_asn1_find_str finds an |EVP_PKEY_ASN1_METHOD| structure by name. |
| 1069 |
// |pe| is ignored. |
| 1070 |
// |name| is the name of the key type to find, e.g, "RSA" or "EC". |
| 1071 |
// |len| is the length of the name. |
| 1072 |
OPENSSL_EXPORT const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str( |
| 1073 |
ENGINE **_pe, const char *name, int len); |
| 1074 |
|
| 1075 |
// EVP_PKEY_asn1_get0_info retrieves information about an |EVP_PKEY_ASN1_METHOD| |
| 1076 |
// structure. |
| 1077 |
// |ppkey_id| is a pointer to get the key type identifier. |
| 1078 |
// |pkey_base_id| is a pointer to get the base key type. Value will be the same |
| 1079 |
// as |ppkey_id|. |
| 1080 |
// |ppkey_flags| is not supported. Value is set to 0 if pointer is not |NULL|. |
| 1081 |
// |pinfo| is a pointer to get a text description. |
| 1082 |
// |ppem_str| is a pointer to get the PEM string name. |
| 1083 |
// |ameth| is a pointer to the EVP_PKEY_ASN1_METHOD structure. |
| 1084 |
OPENSSL_EXPORT int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, |
| 1085 |
int *ppkey_flags, const char **pinfo, |
| 1086 |
const char **ppem_str, |
| 1087 |
const EVP_PKEY_ASN1_METHOD *ameth); |
| 1088 |
|
| 1089 |
// EVP_PKEY_get_private_seed returns the seed representation of the private key |
| 1090 |
// for the key type configured in |key|. If |out| is NULL, it sets |*out_len| to |
| 1091 |
// the size of the seed. Otherwise, it writes at most |*out_len| bytes to |out| |
| 1092 |
// and sets |*out_len| to the number of bytes written. |
| 1093 |
// |
| 1094 |
// Return 1 on success and 0 otherwise. |
| 1095 |
// |
| 1096 |
// Note, the private key might not have a seed representation configured. In |
| 1097 |
// this case, the operation is unsupported and 0 is returned. |
| 1098 |
OPENSSL_EXPORT int EVP_PKEY_get_private_seed(const EVP_PKEY *key, uint8_t *out, |
| 1099 |
size_t *out_len); |
| 1100 |
|
| 1101 |
|
| 1102 |
// EVP_PKEY_CTX keygen/paramgen functions. |
| 1103 |
|
| 1104 |
typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); |
| 1105 |
|
| 1106 |
// EVP_PKEY_CTX_set_cb sets |cb| as the key or parameter generation callback |
| 1107 |
// function for |ctx|. The callback function is then translated and used as the |
| 1108 |
// underlying |BN_GENCB| for |ctx|. Once |cb| is set for |ctx|, any information |
| 1109 |
// regarding key or parameter generation can be retrieved via |
| 1110 |
// |EVP_PKEY_CTX_get_keygen_info|. |
| 1111 |
// This behavior only applies to |EVP_PKEY|s that have calls to |BN_GENCB| |
| 1112 |
// available, which is only |EVP_PKEY_RSA|. |
| 1113 |
// |
| 1114 |
// TODO: Add support for |EVP_PKEY_DH| once we have param_gen support. |
| 1115 |
OPENSSL_EXPORT void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); |
| 1116 |
|
| 1117 |
// EVP_PKEY_CTX_get_keygen_info returns the values associated with the |
| 1118 |
// |EVP_PKEY_gen_cb|/|BN_GENCB| assigned to |ctx|. This should only be used if |
| 1119 |
// |EVP_PKEY_CTX_set_cb| has been called. If |idx| is -1, the total number of |
| 1120 |
// available parameters is returned. Any non-negative value less than the total |
| 1121 |
// number of available parameters, returns the indexed value in the parameter |
| 1122 |
// array. We return 0 for any invalid |idx| or key type. |
| 1123 |
// |
| 1124 |
// The |idx|s in |ctx->keygen_info| correspond to the following values for |
| 1125 |
// |BN_GENCB|: |
| 1126 |
// 1. |ctx->keygen_info[0]| -> |event| |
| 1127 |
// 2. |ctx->keygen_info[1]| -> |n| |
| 1128 |
// See documentation for |BN_GENCB| for more details regarding the definition |
| 1129 |
// of each parameter. |
| 1130 |
// |
| 1131 |
// TODO: Add support for |EVP_PKEY_DH| once we have param_gen support. |
| 1132 |
OPENSSL_EXPORT int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); |
| 1133 |
|
| 1134 |
// EVP_PKEY_CTX_set_app_data sets |app_data| for |ctx|. |
| 1135 |
OPENSSL_EXPORT void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); |
| 1136 |
|
| 1137 |
// EVP_PKEY_CTX_get_app_data returns |ctx|'s |app_data|. |
| 1138 |
OPENSSL_EXPORT void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); |
| 1139 |
|
| 1140 |
|
| 1141 |
// Deprecated functions. |
| 1142 |
|
| 1143 |
// EVP_PKEY_RSA2 was historically an alternate form for RSA public keys (OID |
| 1144 |
// 2.5.8.1.1), but is no longer accepted. |
| 1145 |
#define EVP_PKEY_RSA2 NID_rsa |
| 1146 |
|
| 1147 |
// EVP_PKEY_X448 is defined for OpenSSL compatibility, but we do not support |
| 1148 |
// X448 and attempts to create keys will fail. |
| 1149 |
#define EVP_PKEY_X448 NID_X448 |
| 1150 |
|
| 1151 |
// EVP_PKEY_ED448 is defined for OpenSSL compatibility, but we do not support |
| 1152 |
// Ed448 and attempts to create keys will fail. |
| 1153 |
#define EVP_PKEY_ED448 NID_ED448 |
| 1154 |
|
| 1155 |
// EVP_MD_get_pkey_type returns the NID of the public key signing algorithm |
| 1156 |
// associated with |md| and RSA. This does not return all potential signing |
| 1157 |
// algorithms that could work with |md| and should not be used. |
| 1158 |
OPENSSL_EXPORT int EVP_MD_get_pkey_type(const EVP_MD *md); |
| 1159 |
|
| 1160 |
// EVP_MD_pkey_type calls |EVP_MD_get_pkey_type|. |
| 1161 |
OPENSSL_EXPORT int EVP_MD_pkey_type(const EVP_MD *md); |
| 1162 |
|
| 1163 |
OPENSSL_EXPORT void EVP_CIPHER_do_all_sorted( |
| 1164 |
void (*callback)(const EVP_CIPHER *cipher, const char *name, |
| 1165 |
const char *unused, void *arg), |
| 1166 |
void *arg); |
| 1167 |
|
| 1168 |
OPENSSL_EXPORT void EVP_MD_do_all_sorted(void (*callback)(const EVP_MD *cipher, |
| 1169 |
const char *name, |
| 1170 |
const char *unused, |
| 1171 |
void *arg), |
| 1172 |
void *arg); |
| 1173 |
|
| 1174 |
// EVP_MD_do_all is the same as |EVP_MD_do_all_sorted|. We include both for |
| 1175 |
// compatibility reasons. |
| 1176 |
OPENSSL_EXPORT void EVP_MD_do_all(void (*callback)(const EVP_MD *cipher, |
| 1177 |
const char *name, |
| 1178 |
const char *unused, |
| 1179 |
void *arg), |
| 1180 |
void *arg); |
| 1181 |
|
| 1182 |
|
| 1183 |
// i2d_PrivateKey marshals a private key from |key| to type-specific format, as |
| 1184 |
// described in |i2d_SAMPLE|. |
| 1185 |
// |
| 1186 |
// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 8017) structure. |
| 1187 |
// EC keys are serialized as a DER-encoded ECPrivateKey (RFC 5915) structure. |
| 1188 |
// |
| 1189 |
// Use |RSA_marshal_private_key| or |EC_KEY_marshal_private_key| instead. |
| 1190 |
OPENSSL_EXPORT int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp); |
| 1191 |
|
| 1192 |
// i2d_PublicKey marshals a public key from |key| to a type-specific format, as |
| 1193 |
// described in |i2d_SAMPLE|. |
| 1194 |
// |
| 1195 |
// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 8017) structure. |
| 1196 |
// EC keys are serialized as an EC point per SEC 1. |
| 1197 |
// |
| 1198 |
// Use |RSA_marshal_public_key| or |EC_POINT_point2cbb| instead. |
| 1199 |
OPENSSL_EXPORT int i2d_PublicKey(const EVP_PKEY *key, uint8_t **outp); |
| 1200 |
|
| 1201 |
// d2i_PrivateKey parses a DER-encoded private key from |len| bytes at |*inp|, |
| 1202 |
// as described in |d2i_SAMPLE|. The private key must have type |type|, |
| 1203 |
// otherwise it will be rejected. |
| 1204 |
// |
| 1205 |
// This function tries to detect one of several formats. Instead, use |
| 1206 |
// |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an |
| 1207 |
// RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. |
| 1208 |
OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, |
| 1209 |
const uint8_t **inp, long len); |
| 1210 |
|
| 1211 |
// d2i_AutoPrivateKey acts the same as |d2i_PrivateKey|, but detects the type |
| 1212 |
// of the private key. |
| 1213 |
// |
| 1214 |
// This function tries to detect one of several formats. Instead, use |
| 1215 |
// |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an |
| 1216 |
// RSAPrivateKey, and |EC_parse_private_key| for an ECPrivateKey. |
| 1217 |
OPENSSL_EXPORT EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **out, const uint8_t **inp, |
| 1218 |
long len); |
| 1219 |
|
| 1220 |
// d2i_PublicKey parses a public key from |len| bytes at |*inp| in a type- |
| 1221 |
// specific format specified by |type|, as described in |d2i_SAMPLE|. |
| 1222 |
// |
| 1223 |
// The only supported value for |type| is |EVP_PKEY_RSA|, which parses a |
| 1224 |
// DER-encoded RSAPublicKey (RFC 8017) structure. Parsing EC keys is not |
| 1225 |
// supported by this function. |
| 1226 |
// |
| 1227 |
// Use |RSA_parse_public_key| instead. |
| 1228 |
OPENSSL_EXPORT EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **out, |
| 1229 |
const uint8_t **inp, long len); |
| 1230 |
|
| 1231 |
// EVP_PKEY_CTX_set_ec_param_enc returns one if |encoding| is |
| 1232 |
// |OPENSSL_EC_NAMED_CURVE| or zero with an error otherwise. |
| 1233 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, |
| 1234 |
int encoding); |
| 1235 |
|
| 1236 |
// EVP_PKEY_set1_tls_encodedpoint replaces |pkey| with a public key encoded by |
| 1237 |
// |in|. It returns one on success and zero on error. |len| is the size of |in|. |
| 1238 |
// Any value of |len| below 1 is interpreted as an invalid input and will result |
| 1239 |
// in an error. |
| 1240 |
// |
| 1241 |
// This function only works on X25519 |EVP_PKEY_X25519| and EC |EVP_PKEY_EC| key |
| 1242 |
// types. The supported curve for |EVP_PKEY_X25519| is Curve25519. The supported |
| 1243 |
// curves for |EVP_PKEY_EC| are: NID_secp224r1, NID_X9_62_prime256v1, |
| 1244 |
// NID_secp384r1, NID_secp521r1 |
| 1245 |
// |
| 1246 |
// For the EC key type, the EC point representation must be in |
| 1247 |
// uncompressed form. |
| 1248 |
OPENSSL_EXPORT int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, |
| 1249 |
const uint8_t *in, |
| 1250 |
size_t len); |
| 1251 |
|
| 1252 |
// EVP_PKEY_get1_tls_encodedpoint sets |*out_ptr| to a newly-allocated buffer |
| 1253 |
// containing the raw encoded public key for |pkey|. The caller must call |
| 1254 |
// |OPENSSL_free| to release this buffer on success. The function returns the |
| 1255 |
// length of the buffer on success and zero on error. |
| 1256 |
// |
| 1257 |
// This function only works on X25519 |EVP_PKEY_X25519| and EC |EVP_PKEY_EC| key |
| 1258 |
// types. The supported curve for |EVP_PKEY_X25519| is Curve25519. The supported |
| 1259 |
// curves for |EVP_PKEY_EC| are: NID_secp224r1, NID_X9_62_prime256v1, |
| 1260 |
// NID_secp384r1, NID_secp521r1 |
| 1261 |
// |
| 1262 |
// For the EC key type, the EC point representation must be in |
| 1263 |
// uncompressed form. |
| 1264 |
OPENSSL_EXPORT size_t EVP_PKEY_get1_tls_encodedpoint(const EVP_PKEY *pkey, |
| 1265 |
uint8_t **out_ptr); |
| 1266 |
|
| 1267 |
// EVP_PKEY_base_id calls |EVP_PKEY_id|. |
| 1268 |
OPENSSL_EXPORT int EVP_PKEY_base_id(const EVP_PKEY *pkey); |
| 1269 |
|
| 1270 |
// EVP_PKEY_CTX_set_rsa_pss_keygen_md returns 0. |
| 1271 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX *ctx, |
| 1272 |
const EVP_MD *md); |
| 1273 |
|
| 1274 |
// EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen returns 0. |
| 1275 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, |
| 1276 |
int salt_len); |
| 1277 |
|
| 1278 |
// EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md returns 0. |
| 1279 |
OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, |
| 1280 |
const EVP_MD *md); |
| 1281 |
|
| 1282 |
// i2d_PUBKEY marshals |pkey| as a DER-encoded SubjectPublicKeyInfo, as |
| 1283 |
// described in |i2d_SAMPLE|. |
| 1284 |
// |
| 1285 |
// Use |EVP_marshal_public_key| instead. |
| 1286 |
OPENSSL_EXPORT int i2d_PUBKEY(const EVP_PKEY *pkey, uint8_t **outp); |
| 1287 |
|
| 1288 |
// d2i_PUBKEY parses a DER-encoded SubjectPublicKeyInfo from |len| bytes at |
| 1289 |
// |*inp|, as described in |d2i_SAMPLE|. |
| 1290 |
// |
| 1291 |
// Use |EVP_parse_public_key| instead. |
| 1292 |
OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY(EVP_PKEY **out, const uint8_t **inp, |
| 1293 |
long len); |
| 1294 |
|
| 1295 |
// i2d_RSA_PUBKEY marshals |rsa| as a DER-encoded SubjectPublicKeyInfo |
| 1296 |
// structure, as described in |i2d_SAMPLE|. |
| 1297 |
// |
| 1298 |
// Use |EVP_marshal_public_key| instead. |
| 1299 |
OPENSSL_EXPORT int i2d_RSA_PUBKEY(const RSA *rsa, uint8_t **outp); |
| 1300 |
|
| 1301 |
// d2i_RSA_PUBKEY parses an RSA public key as a DER-encoded SubjectPublicKeyInfo |
| 1302 |
// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. |
| 1303 |
// SubjectPublicKeyInfo structures containing other key types are rejected. |
| 1304 |
// |
| 1305 |
// Use |EVP_parse_public_key| instead. |
| 1306 |
OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY(RSA **out, const uint8_t **inp, long len); |
| 1307 |
|
| 1308 |
// i2d_DSA_PUBKEY marshals |dsa| as a DER-encoded SubjectPublicKeyInfo, as |
| 1309 |
// described in |i2d_SAMPLE|. |
| 1310 |
// |
| 1311 |
// Use |EVP_marshal_public_key| instead. |
| 1312 |
OPENSSL_EXPORT int i2d_DSA_PUBKEY(const DSA *dsa, uint8_t **outp); |
| 1313 |
|
| 1314 |
// d2i_DSA_PUBKEY parses a DSA public key as a DER-encoded SubjectPublicKeyInfo |
| 1315 |
// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. |
| 1316 |
// SubjectPublicKeyInfo structures containing other key types are rejected. |
| 1317 |
// |
| 1318 |
// Use |EVP_parse_public_key| instead. |
| 1319 |
OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY(DSA **out, const uint8_t **inp, long len); |
| 1320 |
|
| 1321 |
// i2d_EC_PUBKEY marshals |ec_key| as a DER-encoded SubjectPublicKeyInfo, as |
| 1322 |
// described in |i2d_SAMPLE|. |
| 1323 |
// |
| 1324 |
// Use |EVP_marshal_public_key| instead. |
| 1325 |
OPENSSL_EXPORT int i2d_EC_PUBKEY(const EC_KEY *ec_key, uint8_t **outp); |
| 1326 |
|
| 1327 |
// d2i_EC_PUBKEY parses an EC public key as a DER-encoded SubjectPublicKeyInfo |
| 1328 |
// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. |
| 1329 |
// SubjectPublicKeyInfo structures containing other key types are rejected. |
| 1330 |
// |
| 1331 |
// Use |EVP_parse_public_key| instead. |
| 1332 |
OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY(EC_KEY **out, const uint8_t **inp, |
| 1333 |
long len); |
| 1334 |
|
| 1335 |
// EVP_PKEY_assign sets the underlying key of |pkey| to |key|, which must be of |
| 1336 |
// the given type. If successful, it returns one. If the |type| argument |
| 1337 |
// is one of |EVP_PKEY_RSA|, |EVP_PKEY_DSA|, or |EVP_PKEY_EC| values it calls |
| 1338 |
// the corresponding |EVP_PKEY_assign_*| functions (which should be used instead). |
| 1339 |
// Otherwise, if |type| cannot be set via |EVP_PKEY_set_type| or if the key |
| 1340 |
// is NULL, it returns zero. |
| 1341 |
OPENSSL_EXPORT int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); |
| 1342 |
|
| 1343 |
// EVP_PKEY_type returns |nid|. |
| 1344 |
OPENSSL_EXPORT int EVP_PKEY_type(int nid); |
| 1345 |
|
| 1346 |
// EVP_PKEY_new_mac_key is deprecated. It allocates a fresh |EVP_PKEY| of |
| 1347 |
// |type|. Only |EVP_PKEY_HMAC| is supported. |mac_key| is used as the HMAC key, |
| 1348 |
// NULL |mac_key| will result in a complete zero-key being used, but in that |
| 1349 |
// case, the length must be zero. This returns the fresh |EVP_PKEY|, or NULL on |
| 1350 |
// error. |
| 1351 |
// |
| 1352 |
// NOTE: Use |HMAC_CTX| directly instead. |
| 1353 |
OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *engine, |
| 1354 |
const uint8_t *mac_key, |
| 1355 |
size_t mac_key_len); |
| 1356 |
|
| 1357 |
// EVP_PKEY_get0 returns the consumed key. The type of value returned will be |
| 1358 |
// one of the following, depending on the type of the |EVP_PKEY|: |
| 1359 |
// |DH|, |DSA|, |EC_KEY|, or |RSA|. |
| 1360 |
// |
| 1361 |
// This function is provided only for compatibility with OpenSSL. |
| 1362 |
// Prefer the use the typed |EVP_PKEY_get0_*| functions instead. |
| 1363 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void *EVP_PKEY_get0(const EVP_PKEY *pkey); |
| 1364 |
|
| 1365 |
// General No-op Functions [Deprecated]. |
| 1366 |
|
| 1367 |
// OpenSSL_add_all_algorithms does nothing. This has been deprecated since |
| 1368 |
// OpenSSL 1.1.0. |
| 1369 |
// |
| 1370 |
// TODO (CryptoAlg-2398): Add |OPENSSL_DEPRECATED|. nginx defines -Werror and |
| 1371 |
// depends on this. |
| 1372 |
OPENSSL_EXPORT void OpenSSL_add_all_algorithms(void); |
| 1373 |
|
| 1374 |
// OPENSSL_add_all_algorithms_conf does nothing. This has been deprecated since |
| 1375 |
// OpenSSL 1.1.0. |
| 1376 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void OPENSSL_add_all_algorithms_conf(void); |
| 1377 |
|
| 1378 |
// OpenSSL_add_all_ciphers does nothing. This has been deprecated since OpenSSL |
| 1379 |
// 1.1.0. |
| 1380 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void OpenSSL_add_all_ciphers(void); |
| 1381 |
|
| 1382 |
// OpenSSL_add_all_digests does nothing. This has been deprecated since OpenSSL |
| 1383 |
// 1.1.0. |
| 1384 |
// |
| 1385 |
// TODO (CryptoAlg-2398): Add |OPENSSL_DEPRECATED|. tpm2-tss defines -Werror and |
| 1386 |
// depends on this. |
| 1387 |
OPENSSL_EXPORT void OpenSSL_add_all_digests(void); |
| 1388 |
|
| 1389 |
// EVP_cleanup does nothing. This has been deprecated since OpenSSL 1.1.0. |
| 1390 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void EVP_cleanup(void); |
| 1391 |
|
| 1392 |
|
| 1393 |
// EVP_PKEY_DSA |
| 1394 |
// |
| 1395 |
// |EVP_PKEY_DSA| is deprecated, but signing or verifying are still supported, |
| 1396 |
// as is parsing DER into a DSA |EVP_PKEY|. |
| 1397 |
|
| 1398 |
#define EVP_PKEY_DSA NID_dsa |
| 1399 |
|
| 1400 |
// EVP_PKEY_CTX_set_dsa_paramgen_bits sets the number of bits for DSA paramgen. |
| 1401 |
// |nbits| must be at least 512. Returns 1 on success, 0 otherwise. |
| 1402 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int EVP_PKEY_CTX_set_dsa_paramgen_bits( |
| 1403 |
EVP_PKEY_CTX *ctx, int nbits); |
| 1404 |
|
| 1405 |
// EVP_PKEY_CTX_set_dsa_paramgen_md sets the digest function used for DSA |
| 1406 |
// parameter generation. If not specified, one of SHA-1 (160), SHA-224 (224), |
| 1407 |
// or SHA-256 (256) is selected based on the number of bits in |q|. |
| 1408 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int EVP_PKEY_CTX_set_dsa_paramgen_md(EVP_PKEY_CTX *ctx, const EVP_MD* md); |
| 1409 |
|
| 1410 |
// EVP_PKEY_CTX_set_dsa_paramgen_q_bits sets the number of bits in q to use for |
| 1411 |
// DSA parameter generation. If not specified, the default is 256. If a digest |
| 1412 |
// function is specified with |EVP_PKEY_CTX_set_dsa_paramgen_md| then this |
| 1413 |
// parameter is ignored and the number of bits in q matches the size of the |
| 1414 |
// digest. This function only accepts the values 160, 224 or 256 for |qbits|. |
| 1415 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int EVP_PKEY_CTX_set_dsa_paramgen_q_bits( |
| 1416 |
EVP_PKEY_CTX *ctx, int qbits); |
| 1417 |
|
| 1418 |
|
| 1419 |
// EVP_PKEY_CTX_ctrl_str |
| 1420 |
|
| 1421 |
// EVP_PKEY_CTX_ctrl_str sets a parameter on |ctx| of type |type| to |value|. |
| 1422 |
// This function is deprecated and should not be used in new code. |
| 1423 |
// |
| 1424 |
// WARNING: This function is difficult to use correctly. New code should use |
| 1425 |
// the EVP_PKEY_CTX_set1_* or EVP_PKEY_CTX_set_* functions instead. |
| 1426 |
// |
| 1427 |
// |ctx| is the context to operate on. |
| 1428 |
// |type| is the parameter type as a string. |
| 1429 |
// |value| is the value to set. |
| 1430 |
// |
| 1431 |
// It returns 1 for success and 0 or a negative value for failure. |
| 1432 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, |
| 1433 |
const char *value); |
| 1434 |
|
| 1435 |
|
| 1436 |
// Preprocessor compatibility section (hidden). |
| 1437 |
// |
| 1438 |
// Historically, a number of APIs were implemented in OpenSSL as macros and |
| 1439 |
// constants to 'ctrl' functions. To avoid breaking #ifdefs in consumers, this |
| 1440 |
// section defines a number of legacy macros. |
| 1441 |
|
| 1442 |
// |BORINGSSL_PREFIX| already makes each of these symbols into macros, so there |
| 1443 |
// is no need to define conflicting macros. |
| 1444 |
#if !defined(BORINGSSL_PREFIX) |
| 1445 |
#define EVP_PKEY_CTX_set_rsa_oaep_md EVP_PKEY_CTX_set_rsa_oaep_md |
| 1446 |
#define EVP_PKEY_CTX_set0_rsa_oaep_label EVP_PKEY_CTX_set0_rsa_oaep_label |
| 1447 |
#define EVP_MD_name EVP_MD_name |
| 1448 |
#define EVP_MD_pkey_type EVP_MD_pkey_type |
| 1449 |
#endif |
| 1450 |
|
| 1451 |
|
| 1452 |
// Nodejs compatibility section (hidden). |
| 1453 |
// |
| 1454 |
// These defines exist for node.js, with the hope that we can eliminate the |
| 1455 |
// need for them over time. |
| 1456 |
|
| 1457 |
#define EVPerr(function, reason) \ |
| 1458 |
ERR_put_error(ERR_LIB_EVP, 0, reason, __FILE__, __LINE__) |
| 1459 |
|
| 1460 |
|
| 1461 |
#if defined(__cplusplus) |
| 1462 |
} // extern C |
| 1463 |
|
| 1464 |
extern "C++" { |
| 1465 |
BSSL_NAMESPACE_BEGIN |
| 1466 |
|
| 1467 |
BORINGSSL_MAKE_DELETER(EVP_PKEY, EVP_PKEY_free) |
| 1468 |
BORINGSSL_MAKE_UP_REF(EVP_PKEY, EVP_PKEY_up_ref) |
| 1469 |
BORINGSSL_MAKE_DELETER(EVP_PKEY_CTX, EVP_PKEY_CTX_free) |
| 1470 |
|
| 1471 |
BSSL_NAMESPACE_END |
| 1472 |
|
| 1473 |
} // extern C++ |
| 1474 |
|
| 1475 |
#endif |
| 1476 |
|
| 1477 |
#endif // OPENSSL_HEADER_EVP_H |