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