provider-mac

title: provider-mac(7ossl)

summary: The mac library <\-> provider functions

text:
# provider-mac(7ossl)

## NAME
provider-mac - The mac 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_mac_newctx(void *provctx);
 void OSSL_FUNC_mac_freectx(void *mctx);
 void *OSSL_FUNC_mac_dupctx(void *src);
 /* Encryption/decryption */
 int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
                        const OSSL_PARAM params[]);
 int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
 int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
 /* MAC parameter descriptors */
 const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
 const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
 const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
 /* MAC parameters */
 int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
 int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
 int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
```

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

The MAC operation enables providers to implement mac algorithms and make them available to applications via the API functions EVP_MAC_init(3), EVP_MAC_update(3) and EVP_MAC_final(3).

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_mac_newctx() has these:

```
 typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx);
 static ossl_inline OSSL_FUNC_mac_newctx_fn
     OSSL_FUNC_mac_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_mac_newctx               OSSL_FUNC_MAC_NEWCTX
 OSSL_FUNC_mac_freectx              OSSL_FUNC_MAC_FREECTX
 OSSL_FUNC_mac_dupctx               OSSL_FUNC_MAC_DUPCTX
 OSSL_FUNC_mac_init                 OSSL_FUNC_MAC_INIT
 OSSL_FUNC_mac_update               OSSL_FUNC_MAC_UPDATE
 OSSL_FUNC_mac_final                OSSL_FUNC_MAC_FINAL
 OSSL_FUNC_mac_get_params           OSSL_FUNC_MAC_GET_PARAMS
 OSSL_FUNC_mac_get_ctx_params       OSSL_FUNC_MAC_GET_CTX_PARAMS
 OSSL_FUNC_mac_set_ctx_params       OSSL_FUNC_MAC_SET_CTX_PARAMS
 OSSL_FUNC_mac_gettable_params      OSSL_FUNC_MAC_GETTABLE_PARAMS
 OSSL_FUNC_mac_gettable_ctx_params  OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
 OSSL_FUNC_mac_settable_ctx_params  OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
```

A mac algorithm implementation may not implement all of these functions. In order to be a consistent set of functions, at least the following functions must be implemented: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(). All other functions are optional.

### Context Management Functions
OSSL_FUNC_mac_newctx() should create and return a pointer to a provider side structure for holding context information during a mac operation. A pointer to this context will be passed back in a number of the other mac operation function calls. The parameter provctx is the provider context generated during provider initialisation (see provider(7)).

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

OSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the mctx parameter and return the duplicate copy.

### Encryption/Decryption Functions
OSSL_FUNC_mac_init() initialises a mac operation given a newly created provider side mac context in the mctx parameter. The params are set before setting the MAC key of keylen bytes.

OSSL_FUNC_mac_update() is called to supply data for MAC computation of a previously initialised mac operation. The mctx parameter contains a pointer to a previously initialised provider side context. OSSL_FUNC_mac_update() may be called multiple times for a single mac operation.

OSSL_FUNC_mac_final() completes the MAC computation started through previous OSSL_FUNC_mac_init() and OSSL_FUNC_mac_update() calls. The mctx parameter contains a pointer to the provider side context. The resulting MAC should be written to out and the amount of data written to *outl, which should not exceed outsize bytes. The same expectations apply to outsize as documented for EVP_MAC_final(3).

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

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

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

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

OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(), and OSSL_FUNC_mac_settable_ctx_params() all return constant OSSL_PARAM(3) arrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(), OSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params() can handle, respectively. OSSL_FUNC_mac_gettable_ctx_params() and OSSL_FUNC_mac_settable_ctx_params() will return the parameters associated with the provider side context mctx in its current state if it is not NULL. Otherwise, they return the parameters associated with the provider side algorithm provctx.

All MAC implementations are expected to handle the following parameters:

with OSSL_FUNC_set_ctx_params():

"key" (OSSL_MAC_PARAM_KEY) <octet string>

Sets the key in the associated MAC ctx. This is identical to passing a key argument to the OSSL_FUNC_mac_init() function.

with OSSL_FUNC_get_params():

"size" (OSSL_MAC_PARAM_SIZE) <integer>

Can be used to get the default MAC size (which might be the only allowable MAC size for the implementation). Note that some implementations allow setting the size that the resulting MAC should have as well, see the documentation of the implementation.

"size" (OSSL_MAC_PARAM_BLOCK_SIZE) <integer>

Can be used to get the MAC block size (if supported by the algorithm).

## NOTES
The MAC 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.

## RETURN VALUES
OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created provider side mac context, or NULL on failure.

OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(), OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for success or 0 on error.

OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and OSSL_FUNC_mac_settable_ctx_params() should return a constant OSSL_PARAM(3) array, or NULL if none is offered.

## SEE ALSO
provider(7), EVP_MAC-BLAKE2(7), EVP_MAC-CMAC(7), EVP_MAC-GMAC(7), EVP_MAC-HMAC(7), EVP_MAC-KMAC(7), EVP_MAC-Poly1305(7), EVP_MAC-Siphash(7), life_cycle-mac(7), EVP_MAC(3)

## HISTORY
The provider MAC interface was introduced in OpenSSL 3.0.

## COPYRIGHT
Copyright 2019-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>.


provider-object

package: openssl

title: provider-object(7ossl)

summary: A specification for a provider\-native object abstraction

text:
# provider-object(7ossl)

## NAME
provider-object - A specification for a provider-native object abstraction

## SYNOPSIS

```
 #include <openssl/core_object.h>
 #include <openssl/core_names.h>
```

## DESCRIPTION
The provider-native object abstraction is a set of OSSL_PARAM(3) keys and values that can be used to pass provider-native objects to OpenSSL library code or between different provider operation implementations with the help of OpenSSL library code.

The intention is that certain provider-native operations can pass any sort of object that belong with other operations, or with OpenSSL library code.

An object may be passed in the following manners:

1.

By value This means that the object data is passed as an octet string or an UTF8 string, which can be handled in diverse ways by other provided implementations. The encoding of the object depends on the context it's used in; for example, OSSL_DECODER(3) allows multiple encodings, depending on existing decoders. If central OpenSSL library functionality is to handle the data directly, it must be encoded in DER for all object types except for OSSL_OBJECT_NAME (see "Parameter reference" below), where it's assumed to a plain UTF8 string.

2.

By reference This means that the object data isn't passed directly, an object reference is passed instead. It's an octet string that only the correct provider understands correctly.

Objects by value can be used by anything that handles DER encoded objects.

Objects by reference need a higher level of cooperation from the implementation where the object originated (let's call it X) and its target implementation (let's call it Y):

1.

An object loading function in the target implementation The target implementation (Y) may have a function that can take an object reference. This can only be used if the target implementation is from the same provider as the one originating the object abstraction in question (X).

The exact target implementation to use is determined from the object type and possibly the object data type. For example, when the OpenSSL library receives an object abstraction with the object type OSSL_OBJECT_PKEY, it will fetch a provider-keymgmt(7) using the object data type as its key type (the second argument in EVP_KEYMGMT_fetch(3)).

2.

An object exporter in the originating implementation The originating implementation (X) may have an exporter function. This exporter function can be used to export the object in OSSL_PARAM(3) form, that can then be imported by the target implementation's imported function.

This can be used when it's not possible to fetch the target implementation (Y) from the same provider.

### Parameter reference
A provider-native object abstraction is an OSSL_PARAM(3) with a selection of the following parameters:

"data" (OSSL_OBJECT_PARAM_DATA) <octet string> or <UTF8 string>

The object data passed by value.

"reference" (OSSL_OBJECT_PARAM_REFERENCE) <octet string>

The object data passed by reference.

"type" (OSSL_OBJECT_PARAM_TYPE) <integer>

The object type, a number that may have any of the following values (all defined in <openssl/core_object.h>):

OSSL_OBJECT_NAME

The object data may only be passed by value, and should be a UTF8 string. This is useful for provider-storemgmt(7) when a URI load results in new URIs.

OSSL_OBJECT_PKEY

The object data is suitable as provider-native EVP_PKEY key data. The object data may be passed by value or passed by reference.

OSSL_OBJECT_CERT

The object data is suitable as X509 data. The object data for this object type can only be passed by value, and should be an octet string. Since there's no provider-native X.509 object, OpenSSL libraries that receive this object abstraction are expected to convert the data to a X509 object with d2i_X509().

OSSL_OBJECT_CRL

The object data is suitable as X509_CRL data. The object data can only be passed by value, and should be an octet string. Since there's no provider-native X.509 CRL object, OpenSSL libraries that receive this object abstraction are expected to convert the data to a X509_CRL object with d2i_X509_CRL().

"data-type" (OSSL_OBJECT_PARAM_DATA_TYPE) <UTF8 string>

The specific type of the object content. Legitimate values depend on the object type; if it is OSSL_OBJECT_PKEY, the data type is expected to be a key type suitable for fetching a provider-keymgmt(7) that can handle the data.

"data-structure" (OSSL_OBJECT_PARAM_DATA_STRUCTURE) <UTF8 string>

The outermost structure of the object content. Legitimate values depend on the object type.

"desc" (OSSL_OBJECT_PARAM_DESC) <UTF8 string>

A human readable text that describes extra details on the object.

When a provider-native object abstraction is used, it must contain object data in at least one form (object data passed by value, i.e. the "data" item, or object data passed by reference, i.e. the "reference" item). Both may be present at once, in which case the OpenSSL library code that receives this will use the most optimal variant.

For objects with the object type OSSL_OBJECT_NAME, that object type must be given.

## SEE ALSO
provider(7), OSSL_DECODER(3)

## HISTORY
The concept of providers and everything surrounding them was introduced in OpenSSL 3.0.

## COPYRIGHT
Copyright 2020-2022 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-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.

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.

## 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.

## COPYRIGHT
Copyright 2020-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>.


provider-signature

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);
 /* 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);
 /* 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);
 /* 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_sign_init              OSSL_FUNC_SIGNATURE_SIGN_INIT
 OSSL_FUNC_signature_sign                   OSSL_FUNC_SIGNATURE_SIGN
 OSSL_FUNC_signature_verify_init            OSSL_FUNC_SIGNATURE_VERIFY_INIT
 OSSL_FUNC_signature_verify                 OSSL_FUNC_SIGNATURE_VERIFY
 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_verify_init and OSSL_FUNC_signature_verify

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

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

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.

### 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.

### 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_digeset_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_digeset_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_digeset_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_digeset_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.

"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 that corresponds to the combination of signature algorithm and digest algorithm for the signature operation.

"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".

"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.

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.

All other functions should return 1 for success or 0 on error.

## SEE ALSO
provider(7)

## HISTORY
The provider SIGNATURE interface was introduced in OpenSSL 3.0.

## COPYRIGHT
Copyright 2019-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-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>.