1EVP_PKEY_SIGN(3ossl)                OpenSSL               EVP_PKEY_SIGN(3ossl)
2
3
4

NAME

6       EVP_PKEY_sign_init, EVP_PKEY_sign_init_ex, EVP_PKEY_sign - sign using a
7       public key algorithm
8

SYNOPSIS

10        #include <openssl/evp.h>
11
12        int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
13        int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
14        int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
15                          unsigned char *sig, size_t *siglen,
16                          const unsigned char *tbs, size_t tbslen);
17

DESCRIPTION

19       EVP_PKEY_sign_init() initializes a public key algorithm context ctx for
20       signing using the algorithm given when the context was created using
21       EVP_PKEY_CTX_new(3) or variants thereof.  The algorithm is used to
22       fetch a EVP_SIGNATURE method implicitly, see "Implicit fetch" in
23       provider(7) for more information about implicit fetches.
24
25       EVP_PKEY_sign_init_ex() is the same as EVP_PKEY_sign_init() but
26       additionally sets the passed parameters params on the context before
27       returning.
28
29       The EVP_PKEY_sign() function performs a public key signing operation
30       using ctx. The data to be signed is specified using the tbs and tbslen
31       parameters. If sig is NULL then the maximum size of the output buffer
32       is written to the siglen parameter. If sig is not NULL then before the
33       call the siglen parameter should contain the length of the sig buffer,
34       if the call is successful the signature is written to sig and the
35       amount of data written to siglen.
36

NOTES

38       EVP_PKEY_sign() does not hash the data to be signed, and therefore is
39       normally used to sign digests. For signing arbitrary messages, see the
40       EVP_DigestSignInit(3) and EVP_SignInit(3) signing interfaces instead.
41
42       After the call to EVP_PKEY_sign_init() algorithm specific control
43       operations can be performed to set any appropriate parameters for the
44       operation (see EVP_PKEY_CTX_ctrl(3)).
45
46       The function EVP_PKEY_sign() can be called more than once on the same
47       context if several operations are performed using the same parameters.
48

RETURN VALUES

50       EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0 or
51       a negative value for failure. In particular a return value of -2
52       indicates the operation is not supported by the public key algorithm.
53

EXAMPLES

55       Sign data using RSA with PKCS#1 padding and SHA256 digest:
56
57        #include <openssl/evp.h>
58        #include <openssl/rsa.h>
59
60        EVP_PKEY_CTX *ctx;
61        /* md is a SHA-256 digest in this example. */
62        unsigned char *md, *sig;
63        size_t mdlen = 32, siglen;
64        EVP_PKEY *signing_key;
65
66        /*
67         * NB: assumes signing_key and md are set up before the next
68         * step. signing_key must be an RSA private key and md must
69         * point to the SHA-256 digest to be signed.
70         */
71        ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */);
72        if (!ctx)
73            /* Error occurred */
74        if (EVP_PKEY_sign_init(ctx) <= 0)
75            /* Error */
76        if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
77            /* Error */
78        if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
79            /* Error */
80
81        /* Determine buffer length */
82        if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
83            /* Error */
84
85        sig = OPENSSL_malloc(siglen);
86
87        if (!sig)
88            /* malloc failure */
89
90        if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
91            /* Error */
92
93        /* Signature is siglen bytes written to buffer sig */
94

SEE ALSO

96       EVP_PKEY_CTX_new(3), EVP_PKEY_CTX_ctrl(3), EVP_PKEY_encrypt(3),
97       EVP_PKEY_decrypt(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3),
98       EVP_PKEY_derive(3)
99

HISTORY

101       The EVP_PKEY_sign_init() and EVP_PKEY_sign() functions were added in
102       OpenSSL 1.0.0.
103
104       The EVP_PKEY_sign_init_ex() function was added in OpenSSL 3.0.
105
107       Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
108
109       Licensed under the Apache License 2.0 (the "License").  You may not use
110       this file except in compliance with the License.  You can obtain a copy
111       in the file LICENSE in the source distribution or at
112       <https://www.openssl.org/source/license.html>.
113
114
115
1163.0.5                             2022-11-01              EVP_PKEY_SIGN(3ossl)
Impressum