Add docs for the provider interface for signature operations
authorMatt Caswell <matt@openssl.org>
Tue, 3 Sep 2019 16:05:52 +0000 (17:05 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 9 Sep 2019 13:00:00 +0000 (14:00 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9753)

doc/man7/provider-signature.pod [new file with mode: 0644]

diff --git a/doc/man7/provider-signature.pod b/doc/man7/provider-signature.pod
new file mode 100644 (file)
index 0000000..3894afd
--- /dev/null
@@ -0,0 +1,229 @@
+=pod
+
+=head1 NAME
+
+provider-signature - The signature library E<lt>-E<gt> provider functions
+
+=head1 SYNOPSIS
+
+=for comment multiple includes
+
+ #include <openssl/core_numbers.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 *OP_signature_newctx(void *provctx);
+ void OP_signature_freectx(void *ctx);
+ void *OP_signature_dupctx(void *ctx);
+
+ /* Signing */
+ int OP_signature_sign_init(void *ctx, void *provkey);
+ int OP_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
+                       size_t sigsize, const unsigned char *tbs, size_t tbslen);
+
+ /* Verifying */
+ int OP_signature_verify_init(void *ctx, void *provkey);
+ int OP_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
+                         const unsigned char *tbs, size_t tbslen);
+
+ /* Verify Recover */
+ int OP_signature_verify_recover_init(void *ctx, void *provkey);
+ int OP_signature_verify_recover(void *ctx, unsigned char *rout,
+                                 size_t *routlen, size_t routsize,
+                                 const unsigned char *sig, size_t siglen);
+
+ /* Signature parameters */
+ int OP_signature_set_params(void *ctx, const OSSL_PARAM params[]);
+
+
+=head1 DESCRIPTION
+
+This documentation is primarily aimed at provider authors. See L<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 L<EVP_PKEY_sign_init_ex(3)>, L<EVP_PKEY_sign(3)>,
+L<EVP_PKEY_verify_init_ex(3)>, L<EVP_PKEY_verify(3)>,
+L<EVP_PKEY_verify_recover_init_ex(3)> and L<EVP_PKEY_verify_recover(3)> (as well
+as other related functions).
+
+All "functions" mentioned here are passed as function pointers between
+F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
+B<OSSL_ALGORITHM> arrays that are returned by the provider's
+provider_query_operation() function
+(see L<provider-base(7)/Provider Functions>).
+
+All these "functions" have a corresponding function type definition
+named B<OSSL_{name}_fn>, and a helper function to retrieve the
+function pointer from an B<OSSL_DISPATCH> element named
+B<OSSL_get_{name}>.
+For example, the "function" OP_signature_newctx() has these:
+
+ typedef void *(OSSL_OP_signature_newctx_fn)(void *provctx);
+ static ossl_inline OSSL_OP_signature_newctx_fn
+     OSSL_get_OP_signature_newctx(const OSSL_DISPATCH *opf);
+
+B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
+macros in L<openssl-core_numbers.h(7)>, as follows:
+
+ OP_signature_newctx                 OSSL_FUNC_SIGNATURE_NEWCTX
+ OP_signature_freectx                OSSL_FUNC_SIGNATURE_FREECTX
+ OP_signature_dupctx                 OSSL_FUNC_SIGNATURE_DUPCTX
+
+ OP_signature_sign_init              OSSL_FUNC_SIGNATURE_SIGN_INIT
+ OP_signature_sign                   OSSL_FUNC_SIGNATURE_SIGN
+
+ OP_signature_verify_init            OSSL_FUNC_SIGNATURE_VERIFY_INIT
+ OP_signature_verify                 OSSL_FUNC_SIGNATURE_VERIFY
+
+ OP_signature_verify_recover_init    OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
+ OP_signature_verify_recover         OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
+
+ OP_signature_set_params             OSSL_FUNC_SIGNATURE_SET_PARAMS
+
+A signature algorithm implementation may not implement all of these functions.
+In order to be a consistent set of functions a provider must implement
+OP_signature_newctx and OP_signature_freectx.
+It must also implement both of OP_signature_sign_init and OP_signature_sign,
+or both of OP_signature_verify_init and OP_signature_verify, or both of
+OP_signature_verify_recover_init and OP_signature_verify_recover.
+All other functions are optional.
+
+A signature algorithm must also implement some mechanism for generating,
+loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
+See L<provider-keymgmt(7)> for further details.
+
+=head2 Context Management Functions
+
+OP_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 B<provctx> is the provider context generated during provider
+initialisation (see L<provider(3)>).
+
+OP_signature_freectx() is passed a pointer to the provider side signature
+context in the B<ctx> parameter.
+This function should free any resources associated with that context.
+
+OP_signature_dupctx() should duplicate the provider side signature context in
+the B<ctx> parameter and return the duplicate copy.
+
+=head2 Signing Functions
+
+OP_signature_sign_init() initialises a context for signing given a provider side
+signature context in the B<ctx> parameter, and a pointer to a provider key object
+in the B<provkey> parameter.
+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)>.
+
+OP_signature_sign() performs the actual signing itself.
+A previously initialised signature context is passed in the B<ctx>
+parameter.
+The data to be signed is pointed to be the B<tbs> parameter which is B<tbslen>
+bytes long.
+Unless B<sig> is NULL, the signature should be written to the location pointed
+to by the B<sig> parameter and it should not exceed B<sigsize> bytes in length.
+The length of the signature should be written to B<*siglen>.
+If B<sig> is NULL then the maximum length of the signature should be written to
+B<*siglen>.
+
+=head2 Verify Functions
+
+OP_signature_verify_init() initialises a context for verifying a signature given
+a provider side signature context in the B<ctx> parameter, and a pointer to a
+provider key object in the B<provkey> parameter.
+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)>.
+
+OP_signature_verify() performs the actual verification itself.
+A previously initialised signature context is passed in the B<ctx> parameter.
+The data that the signature covers is pointed to be the B<tbs> parameter which
+is B<tbslen> bytes long.
+The signature is pointed to by the B<sig> parameter which is B<siglen> bytes
+long.
+
+=head2 Verify Recover Functions
+
+OP_signature_verify_recover_init() initialises a context for recovering the
+signed data given a provider side signature context in the B<ctx> parameter, and
+a pointer to a provider key object in the B<provkey> parameter.
+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)>.
+
+OP_signature_verify_recover() performs the actual verify recover itself.
+A previously initialised signature context is passed in the B<ctx> parameter.
+The signature is pointed to by the B<sig> parameter which is B<siglen> bytes
+long.
+Unless B<rout> is NULL, the recovered data should be written to the location
+pointed to by B<rout> which should not exceed B<routsize> bytes in length.
+The length of the recovered data should be written to B<*routlen>.
+If B<rout> is B<NULL> then the maximum size of the output buffer is written to
+the B<routlen> parameter.
+
+=head2 Signature Parameters
+
+See L<OSSL_PARAM(3)> for further details on the parameters structure used by
+the OP_signature_set_params() function.
+
+OP_signature_set_params() sets signature parameters associated with the given
+provider side key exchange context B<ctx> to B<params>.
+Any parameter settings are additional to any that were previously set.
+
+Parameters currently recognised by built-in signature algorithms are as
+follows.
+Not all parameters are relevant to, or are understood by all signature
+algorithms:
+
+=over 4
+
+=item B<OSSL_SIGNATURE_PARAM_DIGEST> (UTF8 string)
+
+Sets the name of the digest algorithm used for the input to the signature
+functions.
+
+=item B<OSSL_SIGNATURE_PARAM_DIGEST_SIZE> (size_t)
+
+Sets the output size of the digest algorithm used for the input to the signature
+functions.
+
+=back
+
+=head1 RETURN VALUES
+
+OP_signature_newctx() and OP_signature_dupctx() should return the newly created
+provider side signature, or NULL on failure.
+
+OP_signature_sign_init(), OP_signature_sign(), OP_signature_verify_init(),
+OP_signature_verify(), OP_signature_verify_recover_init(),
+OP_signature_verify_recover() and OP_signature_set_params() should return 1 for
+success or 0 on error.
+
+=head1 SEE ALSO
+
+L<provider(7)>
+
+=head1 HISTORY
+
+The provider SIGNATURE interface was introduced in OpenSSL 3.0.
+
+=head1 COPYRIGHT
+
+Copyright 2019 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
+L<https://www.openssl.org/source/license.html>.
+
+=cut