Import OpenSSL-1.0.0a.
[dragonfly.git] / crypto / openssl / doc / crypto / EVP_PKEY_sign.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_sign_init, EVP_PKEY_sign - sign using a public key algorithm
6
7 =head1 SYNOPSIS
8
9  #include <openssl/evp.h>
10
11  int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
12  int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
13                         unsigned char *sig, size_t *siglen,
14                         const unsigned char *tbs, size_t tbslen);
15
16 =head1 DESCRIPTION
17
18 The EVP_PKEY_sign_init() function initializes a public key algorithm
19 context using key B<pkey> for a signing operation.
20
21 The EVP_PKEY_sign() function performs a public key signing operation
22 using B<ctx>. The data to be signed is specified using the B<tbs> and
23 B<tbslen> parameters. If B<sig> is B<NULL> then the maximum size of the output
24 buffer is written to the B<siglen> parameter. If B<sig> is not B<NULL> then
25 before the call the B<siglen> parameter should contain the length of the
26 B<sig> buffer, if the call is successful the signature is written to
27 B<sig> and the amount of data written to B<siglen>.
28
29 =head1 NOTES
30
31 After the call to EVP_PKEY_sign_init() algorithm specific control
32 operations can be performed to set any appropriate parameters for the
33 operation.
34
35 The function EVP_PKEY_sign() can be called more than once on the same
36 context if several operations are performed using the same parameters.
37
38 =head1 RETURN VALUES
39
40 EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0
41 or a negative value for failure. In particular a return value of -2
42 indicates the operation is not supported by the public key algorithm.
43
44 =head1 EXAMPLE
45
46 Sign data using RSA with PKCS#1 padding and SHA256 digest:
47
48  #include <openssl/evp.h>
49  #include <openssl/rsa.h>
50
51  EVP_PKEY_CTX *ctx;
52  unsigned char *md, *sig;
53  size_t mdlen, siglen; 
54  EVP_PKEY *signing_key;
55  /* NB: assumes signing_key, md and mdlen are already set up
56   * and that signing_key is an RSA private key
57   */
58  ctx = EVP_PKEY_CTX_new(signing_key);
59  if (!ctx)
60         /* Error occurred */
61  if (EVP_PKEY_sign_init(ctx) <= 0)
62         /* Error */
63  if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
64         /* Error */
65  if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
66         /* Error */
67
68  /* Determine buffer length */
69  if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
70         /* Error */
71
72  sig = OPENSSL_malloc(siglen);
73
74  if (!sig)
75         /* malloc failure */
76  
77  if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
78         /* Error */
79
80  /* Signature is siglen bytes written to buffer sig */
81
82
83 =head1 SEE ALSO
84
85 L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>,
86 L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>,
87 L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>,
88 L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
89 L<EVP_PKEY_verifyrecover(3)|EVP_PKEY_verifyrecover(3)>,
90 L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 
91
92 =head1 HISTORY
93
94 These functions were first added to OpenSSL 1.0.0.
95
96 =cut