diff options
Diffstat (limited to 'src/lib/libcrypto/man/EVP_PKEY_sign.3')
| -rw-r--r-- | src/lib/libcrypto/man/EVP_PKEY_sign.3 | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EVP_PKEY_sign.3 b/src/lib/libcrypto/man/EVP_PKEY_sign.3 new file mode 100644 index 0000000000..f8e4da7a9d --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_sign.3 | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | .Dd $Mdocdate: November 3 2016 $ | ||
| 2 | .Dt EVP_PKEY_SIGN 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm EVP_PKEY_sign_init , | ||
| 6 | .Nm EVP_PKEY_sign | ||
| 7 | .Nd sign using a public key algorithm | ||
| 8 | .Sh SYNOPSIS | ||
| 9 | .In openssl/evp.h | ||
| 10 | .Ft int | ||
| 11 | .Fo EVP_PKEY_sign_init | ||
| 12 | .Fa "EVP_PKEY_CTX *ctx" | ||
| 13 | .Fc | ||
| 14 | .Ft int | ||
| 15 | .Fo EVP_PKEY_sign | ||
| 16 | .Fa "EVP_PKEY_CTX *ctx" | ||
| 17 | .Fa "unsigned char *sig" | ||
| 18 | .Fa "size_t *siglen" | ||
| 19 | .Fa "const unsigned char *tbs" | ||
| 20 | .Fa "size_t tbslen" | ||
| 21 | .Fc | ||
| 22 | .Sh DESCRIPTION | ||
| 23 | The | ||
| 24 | .Fn EVP_PKEY_sign_init | ||
| 25 | function initializes a public key algorithm context using the key | ||
| 26 | .Fa ctx->pkey | ||
| 27 | for a signing operation. | ||
| 28 | .Pp | ||
| 29 | The | ||
| 30 | .Fn EVP_PKEY_sign | ||
| 31 | function performs a public key signing operation using | ||
| 32 | .Fa ctx . | ||
| 33 | The data to be signed is specified using the | ||
| 34 | .Fa tbs | ||
| 35 | and | ||
| 36 | .Fa tbslen | ||
| 37 | parameters. | ||
| 38 | If | ||
| 39 | .Fa sig | ||
| 40 | is | ||
| 41 | .Dv NULL , | ||
| 42 | then the maximum size of the output buffer is written to the | ||
| 43 | .Fa siglen | ||
| 44 | parameter. | ||
| 45 | If | ||
| 46 | .Fa sig | ||
| 47 | is not | ||
| 48 | .Dv NULL , | ||
| 49 | then before the call the | ||
| 50 | .Fa siglen | ||
| 51 | parameter should contain the length of the | ||
| 52 | .Fa sig | ||
| 53 | buffer. | ||
| 54 | If the call is successful the signature is written to | ||
| 55 | .Fa sig | ||
| 56 | and the amount of data written to | ||
| 57 | .Fa siglen . | ||
| 58 | .Pp | ||
| 59 | After the call to | ||
| 60 | .Fn EVP_PKEY_sign_init , | ||
| 61 | algorithm specific control operations can be performed to set any | ||
| 62 | appropriate parameters for the operation. | ||
| 63 | .Pp | ||
| 64 | The function | ||
| 65 | .Fn EVP_PKEY_sign | ||
| 66 | can be called more than once on the same context if several operations | ||
| 67 | are performed using the same parameters. | ||
| 68 | .Sh RETURN VALUES | ||
| 69 | .Fn EVP_PKEY_sign_init | ||
| 70 | and | ||
| 71 | .Fn EVP_PKEY_sign | ||
| 72 | return 1 for success and 0 or a negative value for failure. | ||
| 73 | In particular, a return value of -2 indicates the operation is not | ||
| 74 | supported by the public key algorithm. | ||
| 75 | .Sh EXAMPLES | ||
| 76 | Sign data using RSA with PKCS#1 padding and SHA256 digest: | ||
| 77 | .Bd -literal | ||
| 78 | #include <openssl/evp.h> | ||
| 79 | #include <openssl/rsa.h> | ||
| 80 | |||
| 81 | EVP_PKEY_CTX *ctx; | ||
| 82 | unsigned char *md, *sig; | ||
| 83 | size_t mdlen, siglen; | ||
| 84 | EVP_PKEY *signing_key; | ||
| 85 | /* NB: assumes signing_key, md and mdlen are already set up | ||
| 86 | * and that signing_key is an RSA private key | ||
| 87 | */ | ||
| 88 | ctx = EVP_PKEY_CTX_new(signing_key); | ||
| 89 | if (!ctx) | ||
| 90 | /* Error occurred */ | ||
| 91 | if (EVP_PKEY_sign_init(ctx) <= 0) | ||
| 92 | /* Error */ | ||
| 93 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) | ||
| 94 | /* Error */ | ||
| 95 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) | ||
| 96 | /* Error */ | ||
| 97 | |||
| 98 | /* Determine buffer length */ | ||
| 99 | if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0) | ||
| 100 | /* Error */ | ||
| 101 | |||
| 102 | sig = malloc(siglen); | ||
| 103 | |||
| 104 | if (!sig) | ||
| 105 | /* malloc failure */ | ||
| 106 | |||
| 107 | if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0) | ||
| 108 | /* Error */ | ||
| 109 | |||
| 110 | /* Signature is siglen bytes written to buffer sig */ | ||
| 111 | .Ed | ||
| 112 | .Sh SEE ALSO | ||
| 113 | .Xr EVP_PKEY_CTX_new 3 , | ||
| 114 | .Xr EVP_PKEY_decrypt 3 , | ||
| 115 | .Xr EVP_PKEY_derive 3 , | ||
| 116 | .Xr EVP_PKEY_encrypt 3 , | ||
| 117 | .Xr EVP_PKEY_verify 3 , | ||
| 118 | .Xr EVP_PKEY_verify_recover 3 | ||
| 119 | .Sh HISTORY | ||
| 120 | These functions were first added to OpenSSL 1.0.0. | ||
