provider-rand

title: provider-rand(7ossl)

summary: The random number generation library <\-> provider

text:
# provider-rand(7ossl)

## NAME
provider-rand - The random number generation library <-> provider functions

## SYNOPSIS

```
 #include <openssl/core_dispatch.h>
 #include <openssl/core_names.h>
 /*
  * None of these are actual functions, but are displayed like this for
  * the function signatures for functions that are offered as function
  * pointers in OSSL_DISPATCH arrays.
  */
 /* Context management */
 void *OSSL_FUNC_rand_newctx(void *provctx, void *parent,
                             const OSSL_DISPATCH *parent_calls);
 void OSSL_FUNC_rand_freectx(void *ctx);
 /* Random number generator functions: NIST */
 int OSSL_FUNC_rand_instantiate(void *ctx, unsigned int strength,
                                int prediction_resistance,
                                const unsigned char *pstr, size_t pstr_len,
                                const OSSL_PARAM params[]);
 int OSSL_FUNC_rand_uninstantiate(void *ctx);
 int OSSL_FUNC_rand_generate(void *ctx, unsigned char *out, size_t outlen,
                             unsigned int strength, int prediction_resistance,
                             const unsigned char *addin, size_t addin_len);
 int OSSL_FUNC_rand_reseed(void *ctx, int prediction_resistance,
                           const unsigned char *ent, size_t ent_len,
                           const unsigned char *addin, size_t addin_len);
 /* Random number generator functions: additional */
 size_t OSSL_FUNC_rand_nonce(void *ctx, unsigned char *out, size_t outlen,
                             int strength, size_t min_noncelen,
                             size_t max_noncelen);
 size_t OSSL_FUNC_rand_get_seed(void *ctx, unsigned char **buffer,
                                int entropy, size_t min_len, size_t max_len,
                                int prediction_resistance,
                                const unsigned char *adin, size_t adin_len);
 void OSSL_FUNC_rand_clear_seed(void *ctx, unsigned char *buffer, size_t b_len);
 int OSSL_FUNC_rand_verify_zeroization(void *ctx);
 /* Context Locking */
 int OSSL_FUNC_rand_enable_locking(void *ctx);
 int OSSL_FUNC_rand_lock(void *ctx);
 void OSSL_FUNC_rand_unlock(void *ctx);
 /* RAND parameter descriptors */
 const OSSL_PARAM *OSSL_FUNC_rand_gettable_params(void *provctx);
 const OSSL_PARAM *OSSL_FUNC_rand_gettable_ctx_params(void *ctx, void *provctx);
 const OSSL_PARAM *OSSL_FUNC_rand_settable_ctx_params(void *ctx, void *provctx);
 /* RAND parameters */
 int OSSL_FUNC_rand_get_params(OSSL_PARAM params[]);
 int OSSL_FUNC_rand_get_ctx_params(void *ctx, OSSL_PARAM params[]);
 int OSSL_FUNC_rand_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
```

## DESCRIPTION
This documentation is primarily aimed at provider authors. See provider(7) for further information.

The RAND operation enables providers to implement random number generation algorithms and random number sources and make them available to applications via the API function EVP_RAND(3).

### Context Management Functions
OSSL_FUNC_rand_newctx() should create and return a pointer to a provider side structure for holding context information during a rand operation. A pointer to this context will be passed back in a number of the other rand operation function calls. The parameter provctx is the provider context generated during provider initialisation (see provider(7)). The parameter parent specifies another rand instance to be used for seeding purposes. If NULL and the specific instance supports it, the operating system will be used for seeding. The parameter parent_calls points to the dispatch table for parent. Thus, the parent need not be from the same provider as the new instance.

OSSL_FUNC_rand_freectx() is passed a pointer to the provider side rand context in the mctx parameter. If it receives NULL as ctx value, it should not do anything other than return. This function should free any resources associated with that context.

### Random Number Generator Functions: NIST
These functions correspond to those defined in NIST SP 800-90A and SP 800-90C.

OSSL_FUNC_rand_instantiate() is used to instantiate the DRBG ctx at a requested security strength. In addition, prediction_resistance can be requested. Additional input addin of length addin_len bytes can optionally be provided. The parameters specified in params configure the DRBG and these should be processed before instantiation.

OSSL_FUNC_rand_uninstantiate() is used to uninstantiate the DRBG ctx. After being uninstantiated, a DRBG is unable to produce output until it is instantiated anew.

OSSL_FUNC_rand_generate() is used to generate random bytes from the DRBG ctx. It will generate outlen bytes placing them into the buffer pointed to by out. The generated bytes will meet the specified security strength and, if prediction_resistance is true, the bytes will be produced after reseeding from a live entropy source. Additional input addin of length addin_len bytes can optionally be provided.

### Random Number Generator Functions: Additional
OSSL_FUNC_rand_nonce() is used to generate a nonce of the given strength with a length from min_noncelen to max_noncelen. If the output buffer out is NULL, the length of the nonce should be returned.

OSSL_FUNC_rand_get_seed() is used by deterministic generators to obtain their seeding material from their parent. The seed bytes will meet the specified security level of entropy bits and there will be between min_len and max_len inclusive bytes in total. If prediction_resistance is true, the bytes will be produced from a live entropy source. Additional input addin of length addin_len bytes can optionally be provided. A pointer to the seed material is returned in *buffer and this must be freed by a later call to OSSL_FUNC_rand_clear_seed().

OSSL_FUNC_rand_clear_seed() frees a seed buffer of length b_len bytes which was previously allocated by OSSL_FUNC_rand_get_seed().

OSSL_FUNC_rand_verify_zeroization() is used to determine if the internal state of the DRBG is zero. This capability is mandated by NIST as part of the self tests, it is unlikely to be useful in other circumstances.

### Context Locking
When DRBGs are used by multiple threads, there must be locking employed to ensure their proper operation. Because locking introduces an overhead, it is disabled by default.

OSSL_FUNC_rand_enable_locking() allows locking to be turned on for a DRBG and all of its parent DRBGs. From this call onwards, the DRBG can be used in a thread safe manner.

OSSL_FUNC_rand_lock() is used to lock a DRBG. Once locked, exclusive access is guaranteed.

OSSL_FUNC_rand_unlock() is used to unlock a DRBG.

### Rand Parameters
See OSSL_PARAM(3) for further details on the parameters structure used by these functions.

OSSL_FUNC_rand_get_params() gets details of parameter values associated with the provider algorithm and stores them in params.

OSSL_FUNC_rand_set_ctx_params() sets rand parameters associated with the given provider side rand context ctx to params. Any parameter settings are additional to any that were previously set. Passing NULL for params should return true.

OSSL_FUNC_rand_get_ctx_params() gets details of currently set parameter values associated with the given provider side rand context ctx and stores them in params. Passing NULL for params should return true.

OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params(), and OSSL_FUNC_rand_settable_ctx_params() all return constant OSSL_PARAM(3) arrays as descriptors of the parameters that OSSL_FUNC_rand_get_params(), OSSL_FUNC_rand_get_ctx_params(), and OSSL_FUNC_rand_set_ctx_params() can handle, respectively. OSSL_FUNC_rand_gettable_ctx_params() and OSSL_FUNC_rand_settable_ctx_params() will return the parameters associated with the provider side context ctx in its current state if it is not NULL. Otherwise, they return the parameters associated with the provider side algorithm provctx.

Parameters currently recognised by built-in rands are as follows. Not all parameters are relevant to, or are understood by all rands:

"state" (OSSL_RAND_PARAM_STATE) <integer>

Returns the state of the random number generator.

"strength" (OSSL_RAND_PARAM_STRENGTH) <unsigned integer>

Returns the bit strength of the random number generator.

"fips-indicator" (OSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR) <integer>

A getter that returns 1 if the operation is FIPS approved, or 0 otherwise. This option is used by the OpenSSL FIPS provider and is not supported by all EVP_RAND sources.

For rands that are also deterministic random bit generators (DRBGs), these additional parameters are recognised. Not all parameters are relevant to, or are understood by all DRBG rands:

"reseed_requests" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>

Reads or set the number of generate requests before reseeding the associated RAND ctx.

"reseed_time_interval" (OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL) <integer>

Reads or set the number of elapsed seconds before reseeding the associated RAND ctx.

"max_request" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>

Specifies the maximum number of bytes that can be generated in a single call to OSSL_FUNC_rand_generate.

"min_entropylen" (OSSL_DRBG_PARAM_MIN_ENTROPYLEN) <unsigned integer>

"max_entropylen" (OSSL_DRBG_PARAM_MAX_ENTROPYLEN) <unsigned integer>

Specify the minimum and maximum number of bytes of random material that can be used to seed the DRBG.

"min_noncelen" (OSSL_DRBG_PARAM_MIN_NONCELEN) <unsigned integer>

"max_noncelen" (OSSL_DRBG_PARAM_MAX_NONCELEN) <unsigned integer>

Specify the minimum and maximum number of bytes of nonce that can be used to instantiate the DRBG.

"max_perslen" (OSSL_DRBG_PARAM_MAX_PERSLEN) <unsigned integer>

"max_adinlen" (OSSL_DRBG_PARAM_MAX_ADINLEN) <unsigned integer>

Specify the minimum and maximum number of bytes of personalisation string that can be used with the DRBG.

"reseed_counter" (OSSL_DRBG_PARAM_RESEED_COUNTER) <unsigned integer>

Specifies the number of times the DRBG has been seeded or reseeded.

"digest" (OSSL_DRBG_PARAM_DIGEST) <UTF8 string>

"cipher" (OSSL_DRBG_PARAM_CIPHER) <UTF8 string>

"mac" (OSSL_DRBG_PARAM_MAC) <UTF8 string>

Sets the name of the underlying cipher, digest or MAC to be used. It must name a suitable algorithm for the DRBG that's being used.

"properties" (OSSL_DRBG_PARAM_PROPERTIES) <UTF8 string>

Sets the properties to be queried when trying to fetch an underlying algorithm. This must be given together with the algorithm naming parameter to be considered valid.

The OpenSSL FIPS provider also supports the following parameters:

"fips-indicator" (OSSL_DRBG_PARAM_FIPS_APPROVED_INDICATOR) <integer>

A getter that returns 1 if the operation is FIPS approved, or 0 otherwise. This may be used after calling OSSL_FUNC_rand_generate(). It may return 0 if the "digest-check" is set to 0.

"digest-check" (OSSL_DRBG_PARAM_FIPS_DIGEST_CHECK) <integer>

If required this parameter should be set before the digest is set. The default value of 1 causes an error when the digest is set if the digest is not FIPS approved (e.g. truncated digests). Setting this to 0 will ignore the error and set the approved "fips-indicator" to 0. This option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0.

## RETURN VALUES
OSSL_FUNC_rand_newctx() should return the newly created provider side rand context, or NULL on failure.

OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params() and OSSL_FUNC_rand_settable_ctx_params() should return a constant OSSL_PARAM(3) array, or NULL if none is offered.

OSSL_FUNC_rand_nonce() returns the size of the generated nonce, or 0 on error.

OSSL_FUNC_rand_get_seed() returns the size of the generated seed, or 0 on error.

All of the remaining functions should return 1 for success or 0 on error.

## NOTES
The RAND life-cycle is described in life_cycle-rand(7). Providers should ensure that the various transitions listed there are supported. At some point the EVP layer will begin enforcing the listed transitions.

## SEE ALSO
provider(7), RAND(7), EVP_RAND(7), life_cycle-rand(7), EVP_RAND(3)

## HISTORY
The provider RAND interface was introduced in OpenSSL 3.0. The Rand Parameters "fips-indicator" and "digest-check" were added in OpenSSL 3.4.

## COPYRIGHT
Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


provider-signature

package: openssl

title: provider-signature(7ossl)

summary: The signature library <\-> provider functions

text:
# provider-signature(7ossl)

## NAME
provider-signature - The signature library <-> provider functions

## SYNOPSIS

```
 #include <openssl/core_dispatch.h>
 #include <openssl/core_names.h>
 /*
  * None of these are actual functions, but are displayed like this for
  * the function signatures for functions that are offered as function
  * pointers in OSSL_DISPATCH arrays.
  */
 /* Context management */
 void *OSSL_FUNC_signature_newctx(void *provctx, const char *propq);
 void OSSL_FUNC_signature_freectx(void *ctx);
 void *OSSL_FUNC_signature_dupctx(void *ctx);
 /* Get the key types that a signature algorithm supports */
 const char **OSSL_FUNC_signature_query_key_types(void);
 /* Signing */
 int OSSL_FUNC_signature_sign_init(void *ctx, void *provkey,
                                   const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
                              size_t sigsize, const unsigned char *tbs, size_t tbslen);
 int OSSL_FUNC_signature_sign_message_init(void *ctx, void *provkey,
                                           const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_sign_message_update(void *ctx, const unsigned char *in,
                                             size_t inlen);
 int OSSL_FUNC_signature_sign_message_final(void *ctx, unsigned char *sig,
                                            size_t *siglen, size_t sigsize);
 /* Verifying */
 int OSSL_FUNC_signature_verify_init(void *ctx, void *provkey,
                                     const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
                                const unsigned char *tbs, size_t tbslen);
 int OSSL_FUNC_signature_verify_message_init(void *ctx, void *provkey,
                                             const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_verify_message_update(void *ctx, const unsigned char *in,
                                               size_t inlen);
 /*
  * OSSL_FUNC_signature_verify_message_final requires that the signature to be
  * verified is specified via a "signature" OSSL_PARAM, which is given with a
  * previous call of OSSL_FUNC_signature_set_ctx_params().
  */
 int OSSL_FUNC_signature_verify_message_final(void *ctx);
 /* Verify Recover */
 int OSSL_FUNC_signature_verify_recover_init(void *ctx, void *provkey,
                                             const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_verify_recover(void *ctx, unsigned char *rout,
                                        size_t *routlen, size_t routsize,
                                        const unsigned char *sig, size_t siglen);
 /* Digest Sign */
 int OSSL_FUNC_signature_digest_sign_init(void *ctx, const char *mdname,
                                          void *provkey,
                                          const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_digest_sign_update(void *ctx, const unsigned char *data,
                                     size_t datalen);
 int OSSL_FUNC_signature_digest_sign_final(void *ctx, unsigned char *sig,
                                           size_t *siglen, size_t sigsize);
 int OSSL_FUNC_signature_digest_sign(void *ctx,
                              unsigned char *sig, size_t *siglen,
                              size_t sigsize, const unsigned char *tbs,
                              size_t tbslen);
 /* Digest Verify */
 int OSSL_FUNC_signature_digest_verify_init(void *ctx, const char *mdname,
                                            void *provkey,
                                            const OSSL_PARAM params[]);
 int OSSL_FUNC_signature_digest_verify_update(void *ctx,
                                              const unsigned char *data,
                                              size_t datalen);
 int OSSL_FUNC_signature_digest_verify_final(void *ctx, const unsigned char *sig,
                                      size_t siglen);
 int OSSL_FUNC_signature_digest_verify(void *ctx, const unsigned char *sig,
                                size_t siglen, const unsigned char *tbs,
                                size_t tbslen);
 /* Signature parameters */
 int OSSL_FUNC_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
 const OSSL_PARAM *OSSL_FUNC_signature_gettable_ctx_params(void *ctx,
                                                           void *provctx);
 int OSSL_FUNC_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
 const OSSL_PARAM *OSSL_FUNC_signature_settable_ctx_params(void *ctx,
                                                           void *provctx);
 /* MD parameters */
 int OSSL_FUNC_signature_get_ctx_md_params(void *ctx, OSSL_PARAM params[]);
 const OSSL_PARAM * OSSL_FUNC_signature_gettable_ctx_md_params(void *ctx);
 int OSSL_FUNC_signature_set_ctx_md_params(void *ctx, const OSSL_PARAM params[]);
 const OSSL_PARAM * OSSL_FUNC_signature_settable_ctx_md_params(void *ctx);
```

## DESCRIPTION
This documentation is primarily aimed at provider authors. See provider(7) for further information.

The signature (OSSL_OP_SIGNATURE) operation enables providers to implement signature algorithms and make them available to applications via the API functions EVP_PKEY_sign(3), EVP_PKEY_verify(3), and EVP_PKEY_verify_recover(3) (as well as other related functions).

All "functions" mentioned here are passed as function pointers between libcrypto and the provider in OSSL_DISPATCH(3) arrays via OSSL_ALGORITHM(3) arrays that are returned by the provider's provider_query_operation() function (see "Provider Functions" in provider-base(7)).

All these "functions" have a corresponding function type definition named OSSL_FUNC_{name}_fn, and a helper function to retrieve the function pointer from an OSSL_DISPATCH(3) element named OSSL_FUNC_{name}. For example, the "function" OSSL_FUNC_signature_newctx() has these:

```
 typedef void *(OSSL_FUNC_signature_newctx_fn)(void *provctx, const char *propq);
 static ossl_inline OSSL_FUNC_signature_newctx_fn
     OSSL_FUNC_signature_newctx(const OSSL_DISPATCH *opf);
```

OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h(7), as follows:

```
 OSSL_FUNC_signature_newctx                 OSSL_FUNC_SIGNATURE_NEWCTX
 OSSL_FUNC_signature_freectx                OSSL_FUNC_SIGNATURE_FREECTX
 OSSL_FUNC_signature_dupctx                 OSSL_FUNC_SIGNATURE_DUPCTX
 OSSL_FUNC_signature_query_key_types        OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES
 OSSL_FUNC_signature_sign_init              OSSL_FUNC_SIGNATURE_SIGN_INIT
 OSSL_FUNC_signature_sign                   OSSL_FUNC_SIGNATURE_SIGN
 OSSL_FUNC_signature_sign_message_init      OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT
 OSSL_FUNC_signature_sign_message_update    OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE
 OSSL_FUNC_signature_sign_message_final     OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL
 OSSL_FUNC_signature_verify_init            OSSL_FUNC_SIGNATURE_VERIFY_INIT
 OSSL_FUNC_signature_verify                 OSSL_FUNC_SIGNATURE_VERIFY
 OSSL_FUNC_signature_verify_message_init    OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT
 OSSL_FUNC_signature_verify_message_update  OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE
 OSSL_FUNC_signature_verify_message_final   OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL
 OSSL_FUNC_signature_verify_recover_init    OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
 OSSL_FUNC_signature_verify_recover         OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
 OSSL_FUNC_signature_digest_sign_init       OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT
 OSSL_FUNC_signature_digest_sign_update     OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE
 OSSL_FUNC_signature_digest_sign_final      OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL
 OSSL_FUNC_signature_digest_sign            OSSL_FUNC_SIGNATURE_DIGEST_SIGN
 OSSL_FUNC_signature_digest_verify_init     OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT
 OSSL_FUNC_signature_digest_verify_update   OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE
 OSSL_FUNC_signature_digest_verify_final    OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL
 OSSL_FUNC_signature_digest_verify          OSSL_FUNC_SIGNATURE_DIGEST_VERIFY
 OSSL_FUNC_signature_get_ctx_params         OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
 OSSL_FUNC_signature_gettable_ctx_params    OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
 OSSL_FUNC_signature_set_ctx_params         OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
 OSSL_FUNC_signature_settable_ctx_params    OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
 OSSL_FUNC_signature_get_ctx_md_params      OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS
 OSSL_FUNC_signature_gettable_ctx_md_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS
 OSSL_FUNC_signature_set_ctx_md_params      OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS
 OSSL_FUNC_signature_settable_ctx_md_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS
```

A signature algorithm implementation may not implement all of these functions. In order to be a consistent set of functions we must have at least a set of context functions (OSSL_FUNC_signature_newctx and OSSL_FUNC_signature_freectx) as well as a set of "signature" functions, i.e. at least one of:

OSSL_FUNC_signature_sign_init and OSSL_FUNC_signature_sign

OSSL_FUNC_signature_sign_message_init and OSSL_FUNC_signature_sign

OSSL_FUNC_signature_sign_message_init, OSSL_FUNC_signature_sign_message_update and OSSL_FUNC_signature_sign_message_final

OSSL_FUNC_signature_verify_init and OSSL_FUNC_signature_verify

OSSL_FUNC_signature_verify_message_init and OSSL_FUNC_signature_verify

OSSL_FUNC_signature_verify_message_init, OSSL_FUNC_signature_verify_message_update and OSSL_FUNC_signature_verify_message_final

OSSL_FUNC_signature_verify_recover_init and OSSL_FUNC_signature_verify_recover

OSSL_FUNC_signature_digest_sign_init, OSSL_FUNC_signature_digest_sign_update and OSSL_FUNC_signature_digest_sign_final

OSSL_FUNC_signature_digest_verify_init, OSSL_FUNC_signature_digest_verify_update and OSSL_FUNC_signature_digest_verify_final

OSSL_FUNC_signature_digest_sign_init and OSSL_FUNC_signature_digest_sign

OSSL_FUNC_signature_digest_verify_init and OSSL_FUNC_signature_digest_verify

The OSSL_FUNC_signature_set_ctx_params() and OSSL_FUNC_signature_settable_ctx_params() functions are optional, but if one of them is provided then the other one must also be provided. The same applies to the OSSL_FUNC_signature_get_ctx_params() and OSSL_FUNC_signature_gettable_ctx_params() functions, as well as the "md_params" functions.

The OSSL_FUNC_signature_dupctx() function is optional. It is not yet used by OpenSSL.

The OSSL_FUNC_signature_query_key_types() function is optional. When present, it should return a NULL-terminated array of strings indicating the key types supported by the provider for signature operations. Otherwise the signature algorithm name must match the given key or match the default signature algorithm name of the key, both checked using EVP_SIGNATURE_is_a(3).

A signature algorithm must also implement some mechanism for generating, loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. See provider-keymgmt(7) for further details.

### Context Management Functions
OSSL_FUNC_signature_newctx() should create and return a pointer to a provider side structure for holding context information during a signature operation. A pointer to this context will be passed back in a number of the other signature operation function calls. The parameter provctx is the provider context generated during provider initialisation (see provider(7)). The propq parameter is a property query string that may be (optionally) used by the provider during any "fetches" that it may perform (if it performs any).

OSSL_FUNC_signature_freectx() is passed a pointer to the provider side signature context in the ctx parameter. This function should free any resources associated with that context.

OSSL_FUNC_signature_dupctx() should duplicate the provider side signature context in the ctx parameter and return the duplicate copy.

### Signing Functions
OSSL_FUNC_signature_sign_init() initialises a context for signing given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_signature_sign() performs the actual signing itself. A previously initialised signature context is passed in the ctx parameter. The data to be signed is pointed to be the tbs parameter which is tbslen bytes long. Unless sig is NULL, the signature should be written to the location pointed to by the sig parameter and it should not exceed sigsize bytes in length. The length of the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written to *siglen.

### Message Signing Functions
These functions are suitable for providers that implement algorithms that accumulate a full message and sign the result of that accumulation, such as RSA-SHA256.

OSSL_FUNC_signature_sign_message_init() initialises a context for signing a message given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_signature_sign_message_update() gathers the data pointed at by in, which is inlen bytes long.

OSSL_FUNC_signature_sign_message_final() performs the actual signing on the data that was gathered with OSSL_FUNC_signature_sign_message_update().

OSSL_FUNC_signature_sign() can be used for one-shot signature calls. In that case, tbs is expected to be the whole message to be signed, tbslen bytes long.

For both OSSL_FUNC_signature_sign_message_final() and OSSL_FUNC_signature_sign(), if sig is not NULL, the signature should be written to the location pointed to by sig, and it should not exceed sigsize bytes in length. The length of the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written to *siglen.

### Verify Functions
OSSL_FUNC_signature_verify_init() initialises a context for verifying a signature given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_signature_verify() performs the actual verification itself. A previously initialised signature context is passed in the ctx parameter. The data that the signature covers is pointed to be the tbs parameter which is tbslen bytes long. The signature is pointed to by the sig parameter which is siglen bytes long.

### Message Verify Functions
These functions are suitable for providers that implement algorithms that accumulate a full message and verify a signature on the result of that accumulation, such as RSA-SHA256.

OSSL_FUNC_signature_verify_message_init() initialises a context for verifying a signature on a message given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_signature_verify_message_update() gathers the data pointed at by in, which is inlen bytes long.

OSSL_FUNC_signature_verify_message_final() performs the actual verification on the data that was gathered with OSSL_FUNC_signature_verify_message_update(). The signature itself must have been passed through the "signature" (OSSL_SIGNATURE_PARAM_SIGNATURE) Signature parameter before this function is called.

OSSL_FUNC_signature_verify() can be used for one-shot verification calls. In that case, tbs is expected to be the whole message to be verified on, tbslen bytes long.

### Verify Recover Functions
OSSL_FUNC_signature_verify_recover_init() initialises a context for recovering the signed data given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_signature_verify_recover() performs the actual verify recover itself. A previously initialised signature context is passed in the ctx parameter. The signature is pointed to by the sig parameter which is siglen bytes long. Unless rout is NULL, the recovered data should be written to the location pointed to by rout which should not exceed routsize bytes in length. The length of the recovered data should be written to *routlen. If rout is NULL then the maximum size of the output buffer is written to the routlen parameter.

### Digest Sign Functions
OSSL_FUNC_signature_digest_sign_init() initialises a context for signing given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_signature_set_ctx_params() and OSSL_FUNC_signature_set_ctx_md_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)). The name of the digest to be used will be in the mdname parameter.

OSSL_FUNC_signature_digest_sign_update() provides data to be signed in the data parameter which should be of length datalen. A previously initialised signature context is passed in the ctx parameter. This function may be called multiple times to cumulatively add data to be signed.

OSSL_FUNC_signature_digest_sign_final() finalises a signature operation previously started through OSSL_FUNC_signature_digest_sign_init() and OSSL_FUNC_signature_digest_sign_update() calls. Once finalised no more data will be added through OSSL_FUNC_signature_digest_sign_update(). A previously initialised signature context is passed in the ctx parameter. Unless sig is NULL, the signature should be written to the location pointed to by the sig parameter and it should not exceed sigsize bytes in length. The length of the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written to *siglen.

OSSL_FUNC_signature_digest_sign() implements a "one shot" digest sign operation previously started through OSSL_FUNC_signature_digest_sign_init(). A previously initialised signature context is passed in the ctx parameter. The data to be signed is in tbs which should be tbslen bytes long. Unless sig is NULL, the signature should be written to the location pointed to by the sig parameter and it should not exceed sigsize bytes in length. The length of the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written to *siglen.

### Digest Verify Functions
OSSL_FUNC_signature_digest_verify_init() initialises a context for verifying given a provider side verification context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The params, if not NULL, should be set on the context in a manner similar to OSSL_FUNC_signature_set_ctx_params() and OSSL_FUNC_signature_set_ctx_md_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)). The name of the digest to be used will be in the mdname parameter.

OSSL_FUNC_signature_digest_verify_update() provides data to be verified in the data parameter which should be of length datalen. A previously initialised verification context is passed in the ctx parameter. This function may be called multiple times to cumulatively add data to be verified.

OSSL_FUNC_signature_digest_verify_final() finalises a verification operation previously started through OSSL_FUNC_signature_digest_verify_init() and OSSL_FUNC_signature_digest_verify_update() calls. Once finalised no more data will be added through OSSL_FUNC_signature_digest_verify_update(). A previously initialised verification context is passed in the ctx parameter. The signature to be verified is in sig which is siglen bytes long.

OSSL_FUNC_signature_digest_verify() implements a "one shot" digest verify operation previously started through OSSL_FUNC_signature_digest_verify_init(). A previously initialised verification context is passed in the ctx parameter. The data to be verified is in tbs which should be tbslen bytes long. The signature to be verified is in sig which is siglen bytes long.

### Signature parameters
See OSSL_PARAM(3) for further details on the parameters structure used by the OSSL_FUNC_signature_get_ctx_params() and OSSL_FUNC_signature_set_ctx_params() functions.

OSSL_FUNC_signature_get_ctx_params() gets signature parameters associated with the given provider side signature context ctx and stored them in params. Passing NULL for params should return true.

OSSL_FUNC_signature_set_ctx_params() sets the signature parameters associated with the given provider side signature context ctx to params. Any parameter settings are additional to any that were previously set. Passing NULL for params should return true.

Common parameters currently recognised by built-in signature algorithms are as follows.

"digest" (OSSL_SIGNATURE_PARAM_DIGEST) <UTF8 string>

Get or sets the name of the digest algorithm used for the input to the signature functions. It is required in order to calculate the "algorithm-id".

"properties" (OSSL_SIGNATURE_PARAM_PROPERTIES) <UTF8 string>

Sets the name of the property query associated with the "digest" algorithm. NULL is used if this optional value is not set.

Note that when implementing a signature algorithm that gathers a full message, like RSA-SHA256, the "digest" and "properties" parameters should not be used. For such implementations, it's acceptable to simply ignore them if they happen to be passed in a call to OSSL_FUNC_signature_set_ctx_params(). For such implementations, however, it is not acceptable to have them in the OSSL_PARAM array that's returned by OSSL_FUNC_signature_settable_ctx_params().

"signature" (OSSL_SIGNATURE_PARAM_SIGNATURE) <octet string>

Sets the signature to verify, specifically when OSSL_FUNC_signature_verify_message_final() is used.

"digest-size" (OSSL_SIGNATURE_PARAM_DIGEST_SIZE) <unsigned integer>

Gets or sets the output size of the digest algorithm used for the input to the signature functions. The length of the "digest-size" parameter should not exceed that of a size_t.

"algorithm-id" (OSSL_SIGNATURE_PARAM_ALGORITHM_ID) <octet string>

Gets the DER-encoded AlgorithmIdentifier for the signature operation. This typically corresponds to the combination of a digest algorithm with a purely asymmetric signature algorithm, such as SHA256WithECDSA. The ASN1_item_sign_ctx(3) function relies on this operation and is used by many other functions that sign ASN.1 structures such as X.509 certificates, certificate requests, and CRLs, as well as OCSP, CMP, and CMS messages.

"nonce-type" (OSSL_SIGNATURE_PARAM_NONCE_TYPE) <unsigned integer>

Set this to 1 to use deterministic digital signature generation with ECDSA or DSA, as defined in RFC 6979 (see Section 3.2 "Generation of k"). In this case, the "digest" parameter must be explicitly set (otherwise, deterministic nonce generation will fail). Before using deterministic digital signature generation, please read RFC 6979 Section 4 "Security Considerations". The default value for "nonce-type" is 0 and results in a random value being used for the nonce k as defined in FIPS 186-4 Section 6.3 "Secret Number Generation". The FIPS provider does not support deterministic digital signature generation.

"kat" (OSSL_SIGNATURE_PARAM_KAT) <unsigned integer>

Sets a flag to modify the sign operation to return an error if the initial calculated signature is invalid. In the normal mode of operation - new random values are chosen until the signature operation succeeds. By default it retries until a signature is calculated. Setting the value to 0 causes the sign operation to retry, otherwise the sign operation is only tried once and returns whether or not it was successful. Known answer tests can be performed if the random generator is overridden to supply known values that either pass or fail.

The following parameters are used by the OpenSSL FIPS provider:

"fips-indicator" (OSSL_SIGNATURE_PARAM_FIPS_APPROVED_INDICATOR) <integer>

A getter that returns 1 if the operation is FIPS approved, or 0 otherwise. This may be used after calling either the sign or verify final functions. It may return 0 if either the "digest-check", "key-check", or "sign-check" are set to 0.

"verify-message" (OSSL_SIGNATURE_PARAM_FIPS_VERIFY_MESSAGE <integer>

A getter that returns 1 if a signature verification operation acted on a raw message, or 0 if it verified a predigested message. A value of 0 indicates likely non-approved usage of the FIPS provider. This flag is set when any signature verification initialisation function is called. It is also set to 1 when any signing operation is performed to signify compliance. See FIPS 140-3 IG 2.4.B for further information.

"key-check" (OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK) <integer>

If required this parameter should be set early via an init function (e.g. OSSL_FUNC_signature_sign_init() or OSSL_FUNC_signature_verify_init()). The default value of 1 causes an error during the init if the key is not FIPS approved (e.g. The key has a security strength of less than 112 bits). Setting this to 0 will ignore the error and set the approved "indicator" to 0. This option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0.

"digest-check" (OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK) <integer>

If required this parameter should be set before the signature digest is set. The default value of 1 causes an error when the digest is set if the digest is not FIPS approved (e.g. SHA1 is used for signing). Setting this to 0 will ignore the error and set the approved "fips-indicator" to 0. This option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0.

"sign-check" (OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK) <integer>

If required this parameter should be set early via an init function. The default value of 1 causes an error when a signing algorithm is used. (This is triggered by deprecated signing algorithms). Setting this to 0 will ignore the error and set the approved "fips-indicator" to 0. This option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0.

"sign-x931-pad-check" (OSSL_SIGNATURE_PARAM_FIPS_SIGN_X931_PAD_CHECK) <integer>

If required this parameter should be set before the padding mode is set. The default value of 1 causes an error if the padding mode is set to X9.31 padding for a RSA signing operation. Setting this to 0 will ignore the error and set the approved "fips-indicator" to 0. This option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0.

OSSL_FUNC_signature_gettable_ctx_params() and OSSL_FUNC_signature_settable_ctx_params() get a constant OSSL_PARAM(3) array that describes the gettable and settable parameters, i.e. parameters that can be used with OSSL_FUNC_signature_get_ctx_params() and OSSL_FUNC_signature_set_ctx_params() respectively.

### MD parameters
See OSSL_PARAM(3) for further details on the parameters structure used by the OSSL_FUNC_signature_get_md_ctx_params() and OSSL_FUNC_signature_set_md_ctx_params() functions.

OSSL_FUNC_signature_get_md_ctx_params() gets digest parameters associated with the given provider side digest signature context ctx and stores them in params. Passing NULL for params should return true.

OSSL_FUNC_signature_set_ms_ctx_params() sets the digest parameters associated with the given provider side digest signature context ctx to params. Any parameter settings are additional to any that were previously set. Passing NULL for params should return true.

Parameters currently recognised by built-in signature algorithms are the same as those for built-in digest algorithms. See "Digest Parameters" in provider-digest(7) for further information.

OSSL_FUNC_signature_gettable_md_ctx_params() and OSSL_FUNC_signature_settable_md_ctx_params() get a constant OSSL_PARAM(3) array that describes the gettable and settable digest parameters, i.e. parameters that can be used with OSSL_FUNC_signature_get_md_ctx_params() and OSSL_FUNC_signature_set_md_ctx_params() respectively.

## RETURN VALUES
OSSL_FUNC_signature_newctx() and OSSL_FUNC_signature_dupctx() should return the newly created provider side signature context, or NULL on failure.

OSSL_FUNC_signature_gettable_ctx_params(), OSSL_FUNC_signature_settable_ctx_params(), OSSL_FUNC_signature_gettable_md_ctx_params() and OSSL_FUNC_signature_settable_md_ctx_params(), return the gettable or settable parameters in a constant OSSL_PARAM(3) array.

OSSL_FUNC_signature_query_key_types() should return a NULL-terminated array of strings.

All verification functions should return 1 for success, 0 for a non-matching signature, and a negative value for operation failure.

All other functions should return 1 for success and 0 or a negative value for failure.

## SEE ALSO
provider(7), "Provider Functions" in provider-base(7), OSSL_PARAM(3), OSSL_DISPATCH(3), OSSL_ALGORITHM(3), EVP_PKEY_sign(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_SIGNATURE_is_a(3), ASN1_item_sign_ctx(3)

## HISTORY
The provider SIGNATURE interface was introduced in OpenSSL 3.0. The Signature Parameters "fips-indicator", "key-check" and "digest-check" were added in OpenSSL 3.4.

## COPYRIGHT
Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.

branch: sisyphus


provider-skeymgmt

title: provider-skeymgmt(7ossl)

summary: The SKEYMGMT library <\-> provider functions

text:
# provider-skeymgmt(7ossl)

## NAME
provider-skeymgmt - The SKEYMGMT library <-> provider functions

## SYNOPSIS

```
 #include <openssl/core_dispatch.h>
 /*
  * None of these are actual functions, but are displayed like this for
  * the function signatures for functions that are offered as function
  * pointers in OSSL_DISPATCH arrays.
  */
 /* Key object destruction */
 void OSSL_FUNC_skeymgmt_free(void *keydata);
 /* Key object import and export functions */
 void *OSSL_FUNC_skeymgmt_import(void *provctx, int selection,
                                 const OSSL_PARAM params[]);
 int OSSL_FUNC_skeymgmt_export(void *keydata, int selection,
                               OSSL_CALLBACK *param_cb, void *cbarg);
 void *OSSL_FUNC_skeymgmt_generate(void *provctx,
                                   const OSSL_PARAM params[]);
 const OSSL_PARAM *OSSL_FUNC_skeymgmt_gen_settable_params(void *provctx);
 const OSSL_PARAM *OSSL_FUNC_skeymgmt_imp_settable_params(void *provctx);
 const char *OSSL_FUNC_skeymgmt_get_key_id(void *keydata);
```

## DESCRIPTION
The SKEYMGMT operation doesn't have much public visibility in the OpenSSL libraries, rather it is an internal operation that is designed to work with operations that use opaque symmetric keys objects.

The SKEYMGMT operation shares knowledge with the operations it works with, therefore the SKEYMGMT and the algorithms which use it must belong to the same provider. The OpenSSL libraries will ensure that they do.

The primary responsibility of the SKEYMGMT operation is to hold the provider side key data for the OpenSSL library EVP_SKEY structure.

All "functions" mentioned here are passed as function pointers between libcrypto and the provider in OSSL_DISPATCH(3) arrays via OSSL_ALGORITHM(3) arrays that are returned by the provider's provider_query_operation() function (see "Provider Functions" in provider-base(7)).

All these "functions" have a corresponding function type definition named OSSL_FUNC_{name}_fn, and a helper function to retrieve the function pointer from a OSSL_DISPATCH(3) element named OSSL_FUNC_{name}.

OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h(7), as follows:

```
 OSSL_FUNC_skeymgmt_free                 OSSL_FUNC_SKEYMGMT_FREE
 OSSL_FUNC_skeymgmt_import               OSSL_FUNC_SKEYMGMT_IMPORT
 OSSL_FUNC_skeymgmt_export               OSSL_FUNC_SKEYMGMT_EXPORT
 OSSL_FUNC_skeymgmt_generate             OSSL_FUNC_SKEYMGMT_GENERATE
 OSSL_FUNC_skeymgmt_get_key_id           OSSL_FUNC_SKEYMGMT_GET_KEY_ID
 OSSL_FUNC_skeymgmt_imp_settable_params  OSSL_FUNC_SKEYMGMT_IMP_SETTABLE_PARAMS
 OSSL_FUNC_skeymgmt_gen_settable_params  OSSL_FUNC_SKEYMGMT_GEN_SETTABLE_PARAMS
```

The SKEYMGMT management is inspired by KEYMGMT but is simpler.

### Key Objects
A key object is a collection of data for an symmetric key, and is represented as keydata in this manual.

The exact contents of a key object are defined by the provider, and it is assumed that different operations in one and the same provider use the exact same structure to represent this collection of data, so that for example, a key object that has been created using the SKEYMGMT interface can be passed as is to other algorithms from the same provider operations, such as OSSL_FUNC_mac_init_opaque() (see provider-mac(7)).

With the export SKEYMGMT function, it's possible to select a specific subset of data to handle, governed by the bits in a selection indicator. The bits are:

OSSL_SKEYMGMT_SELECT_SECRET_KEY

Indicating that the secret key raw bytes in a key object should be included.

OSSL_SKEYMGMT_SELECT_PARAMETERS

Indicating that the parameters in a key object should be included.

Combined selector bits are also defined for easier use:

OSSL_SKEYMGMT_SELECT_ALL

Indicating that everything in a key object should be included.

The exact interpretation of those bits or how they combine is left to each function where you can specify a selector.

### Destructing Function
OSSL_FUNC_skeymgmt_free() should free the passed keydata.

### Key Object Import and Export Functions
OSSL_FUNC_skeymgmt_import() should import data into keydata with values taken from the OSSL_PARAM(3) array params. It allocates the keydata object (there is no separate allocation function).

OSSL_FUNC_skeymgmt_imp_settable_params() returns a list of parameters that can be provided to the OSSL_FUNC_skeymgmt_import() function.

OSSL_FUNC_skeymgmt_export() should extract values indicated by selection from keydata, create an OSSL_PARAM(3) array with them and call param_cb with that array as well as the given cbarg. The passed OSSL_PARAM(3) array is transient and is freed upon the return from param_cb.

### Key Object Generation Functions
OSSL_FUNC_skeymgmt_generate() creates a new key according to the values taken from the OSSL_PARAM(3) array params. It allocates the keydata object.

OSSL_FUNC_skeymgmt_gen_settable_params() returns a list of parameters that can be provided to the OSSL_FUNC_skeymgmt_generate() function.

### Key Object Information functions
OSSL_FUNC_skeymgmt_get_key_id() returns a NUL-terminated string identifying the particular key. The returned string will be freed by a call to EVP_SKEY_free() so callers need to copy it themselves if they want to preserve the value past the key lifetime. The purpose of this function is providing a printable string that can help users to access the specific key. The content of this string is provider-specific.

### Common Import and Export Parameters
See OSSL_PARAM(3) for further details on the parameters structure.

Common information parameters currently recognised by built-in skeymgmt algorithms are as follows:

"raw-bytes" (SKEY_PARAM_RAW_BYTES) <octet string>

The value represents symmetric key as a byte array.

"key-length" (SKEY_PARAM_KEY_LENGTH) <integer>

The value is the byte length of the given key.

## RETURN VALUES
OSSL_FUNC_skeymgmt_import() and OSSL_FUNC_skeymgmt_generate() return a pointer to an allocated object on success and NULL on error.

OSSL_FUNC_skeymgmt_export() returns 1 for success or 0 on error.

OSSL_FUNC_skeymgmt_get_key_id() returns a pointer to a 0-terminated string or NULL.

OSSL_FUNC_skeymgmt_gen_settable_params() and OSSL_FUNC_skeymgmt_imp_settable_params() return references to an array of OSSL_PARAM which can be NULL if there are no settable parameters.

## SEE ALSO
provider(7), EVP_SKEY(3), EVP_KEYMGMT(3)

## HISTORY
The SKEYMGMT interface was introduced in OpenSSL 3.5.

## COPYRIGHT
Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


provider-storemgmt

title: provider-storemgmt(7ossl)

summary: The OSSL_STORE library <\-> provider functions

text:
# provider-storemgmt(7ossl)

## NAME
provider-storemgmt - The OSSL_STORE library <-> provider functions

## SYNOPSIS

```
 #include <openssl/core_dispatch.h>
 /*
  * None of these are actual functions, but are displayed like this for
  * the function signatures for functions that are offered as function
  * pointers in OSSL_DISPATCH arrays.
  */
 void *OSSL_FUNC_store_open(void *provctx, const char *uri);
 void *OSSL_FUNC_store_attach(void *provctx, OSSL_CORE_BIO *bio);
 const OSSL_PARAM *store_settable_ctx_params(void *provctx);
 int OSSL_FUNC_store_set_ctx_params(void *loaderctx, const OSSL_PARAM[]);
 int OSSL_FUNC_store_load(void *loaderctx,
                          OSSL_CALLBACK *object_cb, void *object_cbarg,
                          OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg);
 int OSSL_FUNC_store_eof(void *loaderctx);
 int OSSL_FUNC_store_close(void *loaderctx);
 int OSSL_FUNC_store_export_object
     (void *loaderctx, const void *objref, size_t objref_sz,
      OSSL_CALLBACK *export_cb, void *export_cbarg);
 void *OSSL_FUNC_store_open_ex(void *provctx, const char *uri,
                               const OSSL_PARAM params[],
                               OSSL_PASSPHRASE_CALLBACK *pw_cb,
                               void *pw_cbarg);
 int OSSL_FUNC_store_delete(void *provctx, const char *uri,
                    const OSSL_PARAM params[],
                    OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg);
```

## DESCRIPTION
The STORE operation is the provider side of the ossl_store(7) API.

The primary responsibility of the STORE operation is to load all sorts of objects from a container indicated by URI. These objects are given to the OpenSSL library in provider-native object abstraction form (see provider-object(7)). The OpenSSL library is then responsible for passing on that abstraction to suitable provided functions.

Examples of functions that the OpenSSL library can pass the abstraction to include OSSL_FUNC_keymgmt_load() (provider-keymgmt(7)), OSSL_FUNC_store_export_object() (which exports the object in parameterized form).

All "functions" mentioned here are passed as function pointers between libcrypto and the provider in OSSL_DISPATCH(3) arrays via OSSL_ALGORITHM(3) arrays that are returned by the provider's provider_query_operation() function (see "Provider Functions" in provider-base(7)).

All these "functions" have a corresponding function type definition named OSSL_FUNC_{name}_fn, and a helper function to retrieve the function pointer from a OSSL_DISPATCH(3) element named OSSL_get_{name}. For example, the "function" OSSL_FUNC_store_attach() has these:

```
 typedef void *(OSSL_FUNC_store_attach_fn)(void *provctx,
                                           OSSL_CORE_BIO * bio);
 static ossl_inline OSSL_FUNC_store_attach_fn
     OSSL_FUNC_store_attach(const OSSL_DISPATCH *opf);
```

OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h(7), as follows:

```
 OSSL_FUNC_store_open                 OSSL_FUNC_STORE_OPEN
 OSSL_FUNC_store_attach               OSSL_FUNC_STORE_ATTACH
 OSSL_FUNC_store_settable_ctx_params  OSSL_FUNC_STORE_SETTABLE_CTX_PARAMS
 OSSL_FUNC_store_set_ctx_params       OSSL_FUNC_STORE_SET_CTX_PARAMS
 OSSL_FUNC_store_load                 OSSL_FUNC_STORE_LOAD
 OSSL_FUNC_store_eof                  OSSL_FUNC_STORE_EOF
 OSSL_FUNC_store_close                OSSL_FUNC_STORE_CLOSE
 OSSL_FUNC_store_export_object        OSSL_FUNC_STORE_EXPORT_OBJECT
 OSSL_FUNC_store_delete               OSSL_FUNC_STORE_DELETE
 OSSL_FUNC_store_open_ex              OSSL_FUNC_STORE_OPEN_EX
```

### Functions
OSSL_FUNC_store_open() should create a provider side context with data based on the input uri. The implementation is entirely responsible for the interpretation of the URI.

OSSL_FUNC_store_attach() should create a provider side context with the core BIO bio attached. This is an alternative to using a URI to find storage, supporting OSSL_STORE_attach(3).

OSSL_FUNC_store_settable_ctx_params() should return a constant array of descriptor OSSL_PARAM(3), for parameters that OSSL_FUNC_store_set_ctx_params() can handle.

OSSL_FUNC_store_set_ctx_params() should set additional parameters, such as what kind of data to expect, search criteria, and so on. More on those below, in "Load Parameters". Whether unrecognised parameters are an error or simply ignored is at the implementation's discretion. Passing NULL for params should return true.

OSSL_FUNC_store_load() loads the next object from the URI opened by OSSL_FUNC_store_open(), creates an object abstraction for it (see provider-object(7)), and calls object_cb with it as well as object_cbarg. object_cb will then interpret the object abstraction and do what it can to wrap it or decode it into an OpenSSL structure. In case a passphrase needs to be prompted to unlock an object, pw_cb should be called.

OSSL_FUNC_store_eof() indicates if the end of the set of objects from the URI has been reached. When that happens, there's no point trying to do any further loading.

OSSL_FUNC_store_close() frees the provider side context ctx.

When a provider-native object is created by a store manager it would be unsuitable for direct use with a foreign provider. The export function allows for exporting the object to that foreign provider if the foreign provider supports the type of the object and provides an import function.

OSSL_FUNC_store_export_object() should export the object of size objref_sz referenced by objref as an OSSL_PARAM(3) array and pass that to the export_cb as well as the given export_cbarg.

OSSL_FUNC_store_delete() deletes the object identified by the uri. The implementation is entirely responsible for the interpretation of the URI. In case a passphrase needs to be prompted to remove an object, pw_cb should be called.

OSSL_FUNC_store_open_ex() is an extended variant of OSSL_FUNC_store_open(). If the provider does not implement this function the code internally falls back to use the original OSSL_FUNC_store_open(). This variant additionally accepts an OSSL_PARAM(3) object and a pw_cb callback that can be used to request a passphrase in cases where the whole store needs to be unlocked before performing any load operation.

### Load Parameters
"expect" (OSSL_STORE_PARAM_EXPECT) <integer>

Is a hint of what type of data the OpenSSL library expects to get. This is only useful for optimization, as the library will check that the object types match the expectation too. The number that can be given through this parameter is found in <openssl/store.h>, with the macros having names starting with "OSSL_STORE_INFO_". These are further described in "SUPPORTED OBJECTS" in OSSL_STORE_INFO(3).

"subject" (OSSL_STORE_PARAM_SUBJECT) <octet string>

Indicates that the caller wants to search for an object with the given subject associated. This can be used to select specific certificates by subject. The contents of the octet string is expected to be in DER form.

"issuer" (OSSL_STORE_PARAM_ISSUER) <octet string>

Indicates that the caller wants to search for an object with the given issuer associated. This can be used to select specific certificates by issuer. The contents of the octet string is expected to be in DER form.

"serial" (OSSL_STORE_PARAM_SERIAL) <integer>

Indicates that the caller wants to search for an object with the given serial number associated.

"digest" (OSSL_STORE_PARAM_DIGEST) <UTF8 string>

"fingerprint" (OSSL_STORE_PARAM_FINGERPRINT) <octet string>

Indicates that the caller wants to search for an object with the given fingerprint, computed with the given digest.

"alias" (OSSL_STORE_PARAM_ALIAS) <UTF8 string>

Indicates that the caller wants to search for an object with the given alias (some call it a "friendly name").

"properties" (OSSL_STORE_PARAM_PROPERTIES) <utf8 string>

Property string to use when querying for algorithms such as the OSSL_DECODER decoder implementations.

"input-type" (OSSL_STORE_PARAM_INPUT_TYPE) <utf8 string>

Type of the input format as a hint to use when decoding the objects in the store.

Several of these search criteria may be combined. For example, to search for a certificate by issuer+serial, both the "issuer" and the "serial" parameters will be given.

## SEE ALSO
provider(7)

## HISTORY
The STORE interface was introduced in OpenSSL 3.0.

OSSL_FUNC_store_delete() callback was added in OpenSSL 3.2

## COPYRIGHT
Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


proxy-certificates

title: proxy-certificates(7ossl)

summary: Proxy certificates in OpenSSL

text:
# proxy-certificates(7ossl)

## NAME
proxy-certificates - Proxy certificates in OpenSSL

## DESCRIPTION
Proxy certificates are defined in RFC 3820. They are used to extend rights to some other entity (a computer process, typically, or sometimes to the user itself). This allows the entity to perform operations on behalf of the owner of the EE (End Entity) certificate.

The requirements for a valid proxy certificate are:

- They are issued by an End Entity, either a normal EE certificate, or another proxy certificate.

- They must not have the subjectAltName or issuerAltName extensions.

- They must have the proxyCertInfo extension.

- They must have the subject of their issuer, with one commonName added.

### Enabling proxy certificate verification
OpenSSL expects applications that want to use proxy certificates to be specially aware of them, and make that explicit. This is done by setting an X509 verification flag:

```
    X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
```

or

```
    X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_ALLOW_PROXY_CERTS);
```

See "NOTES" for a discussion on this requirement.

### Creating proxy certificates
Creating proxy certificates can be done using the openssl-x509(1) command, with some extra extensions:

```
    [ proxy ]
    # A proxy certificate MUST NEVER be a CA certificate.
    basicConstraints = CA:FALSE
    # Usual authority key ID
    authorityKeyIdentifier = keyid,issuer:always
    # The extension which marks this certificate as a proxy
    proxyCertInfo = critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
```

It's also possible to specify the proxy extension in a separate section:

```
    proxyCertInfo = critical,@proxy_ext
    [ proxy_ext ]
    language = id-ppl-anyLanguage
    pathlen = 0
    policy = text:BC
```

The policy value has a specific syntax, syntag:string, where the syntag determines what will be done with the string. The following syntags are recognised:

text

indicates that the string is a byte sequence, without any encoding:

```
    policy=text:räksmörgås

```

hex

indicates the string is encoded hexadecimal encoded binary data, with colons between each byte (every second hex digit):

```
    policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73

```

file

indicates that the text of the policy should be taken from a file. The string is then a filename. This is useful for policies that are more than a few lines, such as XML or other markup.

Note that the proxy policy value is what determines the rights granted to the process during the proxy certificate, and it is up to the application to interpret and combine these policies.>

With a proxy extension, creating a proxy certificate is a matter of two commands:

```
    openssl req -new -config proxy.cnf \
        -out proxy.req -keyout proxy.key \
        -subj "/DC=org/DC=openssl/DC=users/CN=proxy"
    openssl x509 -req -CAcreateserial -in proxy.req -out proxy.crt \
        -CA user.crt -CAkey user.key -days 7 \
        -extfile proxy.cnf -extensions proxy
```

You can also create a proxy certificate using another proxy certificate as issuer. Note that this example uses a different configuration section for the proxy extensions:

```
    openssl req -new -config proxy.cnf \
        -out proxy2.req -keyout proxy2.key \
        -subj "/DC=org/DC=openssl/DC=users/CN=proxy/CN=proxy 2"
    openssl x509 -req -CAcreateserial -in proxy2.req -out proxy2.crt \
        -CA proxy.crt -CAkey proxy.key -days 7 \
        -extfile proxy.cnf -extensions proxy_2
```

### Using proxy certs in applications
To interpret proxy policies, the application would normally start with some default rights (perhaps none at all), then compute the resulting rights by checking the rights against the chain of proxy certificates, user certificate and CA certificates.

The complicated part is figuring out how to pass data between your application and the certificate validation procedure.

The following ingredients are needed for such processing:

- a callback function that will be called for every certificate being validated. The callback is called several times for each certificate, so you must be careful to do the proxy policy interpretation at the right time. You also need to fill in the defaults when the EE certificate is checked.

- a data structure that is shared between your application code and the callback.

- a wrapper function that sets it all up.

- an ex_data index function that creates an index into the generic ex_data store that is attached to an X509 validation context.

The following skeleton code can be used as a starting point:

```
    #include <string.h>
    #include <netdb.h>
    #include <openssl/x509.h>
    #include <openssl/x509v3.h>
    #define total_rights 25
    /*
     * In this example, I will use a view of granted rights as a bit
     * array, one bit for each possible right.
     */
    typedef struct your_rights {
        unsigned char rights[(total_rights + 7) / 8];
    } YOUR_RIGHTS;
    /*
     * The following procedure will create an index for the ex_data
     * store in the X509 validation context the first time it's
     * called.  Subsequent calls will return the same index.
     */
    static int get_proxy_auth_ex_data_idx(X509_STORE_CTX *ctx)
    {
        static volatile int idx = -1;
        if (idx < 0) {
            X509_STORE_lock(X509_STORE_CTX_get0_store(ctx));
            if (idx < 0) {
                idx = X509_STORE_CTX_get_ex_new_index(0,
                                                      "for verify callback",
                                                      NULL,NULL,NULL);
            }
            X509_STORE_unlock(X509_STORE_CTX_get0_store(ctx));
        }
        return idx;
    }
    /* Callback to be given to the X509 validation procedure.  */
    static int verify_callback(int ok, X509_STORE_CTX *ctx)
    {
        if (ok == 1) {
            /*
             * It's REALLY important you keep the proxy policy check
             * within this section.  It's important to know that when
             * ok is 1, the certificates are checked from top to
             * bottom.  You get the CA root first, followed by the
             * possible chain of intermediate CAs, followed by the EE
             * certificate, followed by the possible proxy
             * certificates.
             */
            X509 *xs = X509_STORE_CTX_get_current_cert(ctx);
            if (X509_get_extension_flags(xs) & EXFLAG_PROXY) {
                YOUR_RIGHTS *rights =
                    (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
                        get_proxy_auth_ex_data_idx(ctx));
                PROXY_CERT_INFO_EXTENSION *pci =
                    X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
                switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage)) {
                case NID_Independent:
                    /*
                     * Do whatever you need to grant explicit rights
                     * to this particular proxy certificate, usually
                     * by pulling them from some database.  If there
                     * are none to be found, clear all rights (making
                     * this and any subsequent proxy certificate void
                     * of any rights).
                     */
                    memset(rights->rights, 0, sizeof(rights->rights));
                    break;
                case NID_id_ppl_inheritAll:
                    /*
                     * This is basically a NOP, we simply let the
                     * current rights stand as they are.
                     */
                    break;
                default:
                    /*
                     * This is usually the most complex section of
                     * code.  You really do whatever you want as long
                     * as you follow RFC 3820.  In the example we use
                     * here, the simplest thing to do is to build
                     * another, temporary bit array and fill it with
                     * the rights granted by the current proxy
                     * certificate, then use it as a mask on the
                     * accumulated rights bit array, and voilà, you
                     * now have a new accumulated rights bit array.
                     */
                    {
                        int i;
                        YOUR_RIGHTS tmp_rights;
                        memset(tmp_rights.rights, 0,
                               sizeof(tmp_rights.rights));
                        /*
                         * process_rights() is supposed to be a
                         * procedure that takes a string and its
                         * length, interprets it and sets the bits
                         * in the YOUR_RIGHTS pointed at by the
                         * third argument.
                         */
                        process_rights((char *) pci->proxyPolicy->policy->data,
                                       pci->proxyPolicy->policy->length,
                                       &tmp_rights);
                        for(i = 0; i < total_rights / 8; i++)
                            rights->rights[i] &= tmp_rights.rights[i];
                    }
                    break;
                }
                PROXY_CERT_INFO_EXTENSION_free(pci);
            } else if (!(X509_get_extension_flags(xs) & EXFLAG_CA)) {
                /* We have an EE certificate, let's use it to set default! */
                YOUR_RIGHTS *rights =
                    (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
                        get_proxy_auth_ex_data_idx(ctx));
                /*
                 * The following procedure finds out what rights the
                 * owner of the current certificate has, and sets them
                 * in the YOUR_RIGHTS structure pointed at by the
                 * second argument.
                 */
                set_default_rights(xs, rights);
            }
        }
        return ok;
    }
    static int my_X509_verify_cert(X509_STORE_CTX *ctx,
                                   YOUR_RIGHTS *needed_rights)
    {
        int ok;
        int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) =
            X509_STORE_CTX_get_verify_cb(ctx);
        YOUR_RIGHTS rights;
        X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
        X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(ctx),
                                   &rights);
        X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
        ok = X509_verify_cert(ctx);
        if (ok == 1) {
            ok = check_needed_rights(rights, needed_rights);
        }
        X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
        return ok;
    }
```

If you use SSL or TLS, you can easily set up a callback to have the certificates checked properly, using the code above:

```
    SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert,
                                     &needed_rights);
```

## NOTES
To this date, it seems that proxy certificates have only been used in environments that are aware of them, and no one seems to have investigated how they can be used or misused outside of such an environment.

For that reason, OpenSSL requires that applications aware of proxy certificates must also make that explicit.

subjectAltName and issuerAltName are forbidden in proxy certificates, and this is enforced in OpenSSL. The subject must be the same as the issuer, with one commonName added on.

## SEE ALSO
X509_STORE_CTX_set_flags(3), X509_STORE_CTX_set_verify_cb(3), X509_VERIFY_PARAM_set_flags(3), SSL_CTX_set_cert_verify_callback(3), openssl-req(1), openssl-x509(1), RFC 3820 <https://tools.ietf.org/html/rfc3820>

## COPYRIGHT
Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


title: x509(7ossl)

summary: X.509 certificate handling

text:
# x509(7ossl)

## NAME
x509 - X.509 certificate handling

## SYNOPSIS

```
 #include <openssl/x509.h>
```

## DESCRIPTION
An X.509 certificate is a structured grouping of information about an individual, a device, or anything one can imagine. An X.509 CRL (certificate revocation list) is a tool to help determine if a certificate is still valid. The exact definition of those can be found in the X.509 document from ITU-T, or in RFC3280 from PKIX. In OpenSSL, the type X509 is used to express such a certificate, and the type X509_CRL is used to express a CRL.

A related structure is a certificate request, defined in PKCS#10 from RSA Security, Inc, also reflected in RFC2896. In OpenSSL, the type X509_REQ is used to express such a certificate request.

To handle some complex parts of a certificate, there are the types X509_NAME (to express a certificate name), X509_ATTRIBUTE (to express a certificate attribute), X509_EXTENSION (to express a certificate extension) and a few more.

Finally, there's the supertype X509_INFO, which can contain a CRL, a certificate and a corresponding private key.

X509_XXX, d2i_X509_XXX, and i2d_X509_XXX functions handle X.509 certificates, with some exceptions, shown below.

X509_CRL_XXX, d2i_X509_CRL_XXX, and i2d_X509_CRL_XXX functions handle X.509 CRLs.

X509_REQ_XXX, d2i_X509_REQ_XXX, and i2d_X509_REQ_XXX functions handle PKCS#10 certificate requests.

X509_NAME_XXX functions handle certificate names.

X509_ATTRIBUTE_XXX functions handle certificate attributes.

X509_EXTENSION_XXX functions handle certificate extensions.

## SEE ALSO
X509_NAME_ENTRY_get_object(3), X509_NAME_add_entry_by_txt(3), X509_NAME_add_entry_by_NID(3), X509_NAME_print_ex(3), X509_NAME_new(3), PEM_X509_INFO_read(3), d2i_X509(3), d2i_X509_ALGOR(3), d2i_X509_CRL(3), d2i_X509_NAME(3), d2i_X509_REQ(3), d2i_X509_SIG(3), crypto(7)

## COPYRIGHT
Copyright 2003-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.