]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/EVP_PKEY_sign.pod
Fix typos and repeated words
[thirdparty/openssl.git] / doc / man3 / EVP_PKEY_sign.pod
CommitLineData
ba544377
DSH
1=pod
2
3=head1 NAME
4
0e521004 5EVP_PKEY_sign_init, EVP_PKEY_sign
11031468 6- sign using a public key algorithm
ba544377
DSH
7
8=head1 SYNOPSIS
9
10 #include <openssl/evp.h>
11
12 int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
13 int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
e9b77246
BB
14 unsigned char *sig, size_t *siglen,
15 const unsigned char *tbs, size_t tbslen);
ba544377
DSH
16
17=head1 DESCRIPTION
18
0e521004
RL
19EVP_PKEY_sign_init() initializes a public key algorithm context I<ctx> for
20signing using the algorithm given when the context was created
21using L<EVP_PKEY_CTX_new(3)> or variants thereof. The algorithm is used to
22fetch a B<EVP_SIGNATURE> method implicitly, see L<provider(7)/Implicit fetch>
8c1cbc72 23for more information about implicit fetches.
ba544377
DSH
24
25The EVP_PKEY_sign() function performs a public key signing operation
0e521004
RL
26using I<ctx>. The data to be signed is specified using the I<tbs> and
27I<tbslen> parameters. If I<sig> is NULL then the maximum size of the output
28buffer is written to the I<siglen> parameter. If I<sig> is not NULL then
29before the call the I<siglen> parameter should contain the length of the
30I<sig> buffer, if the call is successful the signature is written to
31I<sig> and the amount of data written to I<siglen>.
ba544377
DSH
32
33=head1 NOTES
34
d64c533a
EK
35EVP_PKEY_sign() does not hash the data to be signed, and therefore is
36normally used to sign digests. For signing arbitrary messages, see the
9b86974e
RS
37L<EVP_DigestSignInit(3)> and
38L<EVP_SignInit(3)> signing interfaces instead.
d64c533a 39
ba544377
DSH
40After the call to EVP_PKEY_sign_init() algorithm specific control
41operations can be performed to set any appropriate parameters for the
9b86974e 42operation (see L<EVP_PKEY_CTX_ctrl(3)>).
ba544377
DSH
43
44The function EVP_PKEY_sign() can be called more than once on the same
45context if several operations are performed using the same parameters.
46
47=head1 RETURN VALUES
48
49EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0
50or a negative value for failure. In particular a return value of -2
51indicates the operation is not supported by the public key algorithm.
52
cda77422 53=head1 EXAMPLES
ba544377 54
43636910
DSH
55Sign 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;
d64c533a 61 /* md is a SHA-256 digest in this example. */
43636910 62 unsigned char *md, *sig;
d64c533a 63 size_t mdlen = 32, siglen;
43636910 64 EVP_PKEY *signing_key;
d64c533a
EK
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.
43636910 70 */
d64c533a 71 ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */);
43636910 72 if (!ctx)
2947af32 73 /* Error occurred */
43636910 74 if (EVP_PKEY_sign_init(ctx) <= 0)
2947af32 75 /* Error */
43636910 76 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
2947af32 77 /* Error */
43636910 78 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
2947af32 79 /* Error */
43636910
DSH
80
81 /* Determine buffer length */
82 if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
2947af32 83 /* Error */
43636910
DSH
84
85 sig = OPENSSL_malloc(siglen);
86
87 if (!sig)
2947af32 88 /* malloc failure */
1bc74519 89
43636910 90 if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
2947af32 91 /* Error */
43636910
DSH
92
93 /* Signature is siglen bytes written to buffer sig */
ba544377 94
ba544377
DSH
95
96=head1 SEE ALSO
97
9b86974e
RS
98L<EVP_PKEY_CTX_new(3)>,
99L<EVP_PKEY_CTX_ctrl(3)>,
100L<EVP_PKEY_encrypt(3)>,
101L<EVP_PKEY_decrypt(3)>,
102L<EVP_PKEY_verify(3)>,
103L<EVP_PKEY_verify_recover(3)>,
1bc74519 104L<EVP_PKEY_derive(3)>
ba544377
DSH
105
106=head1 HISTORY
107
fc5ecadd 108These functions were added in OpenSSL 1.0.0.
ba544377 109
e2f92610
RS
110=head1 COPYRIGHT
111
33388b44 112Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 113
4746f25a 114Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
115this file except in compliance with the License. You can obtain a copy
116in the file LICENSE in the source distribution or at
117L<https://www.openssl.org/source/license.html>.
118
119=cut