diff options
author | schwarze <> | 2016-11-03 09:35:34 +0000 |
---|---|---|
committer | schwarze <> | 2016-11-03 09:35:34 +0000 |
commit | 4d607f17ea3eb38ed9f7703afd423f6055c686d4 (patch) | |
tree | 58d82d0d7f6aeee380eaadbcfaa231ecbe6b90a0 /src | |
parent | cf67afe5881727d740e9f6c772aa478123f7d698 (diff) | |
download | openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.gz openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.bz2 openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.zip |
convert EVP manuals from pod to mdoc
Diffstat (limited to 'src')
49 files changed, 4229 insertions, 2724 deletions
diff --git a/src/lib/libcrypto/doc/EVP_BytesToKey.pod b/src/lib/libcrypto/doc/EVP_BytesToKey.pod deleted file mode 100644 index 2dffaa1efa..0000000000 --- a/src/lib/libcrypto/doc/EVP_BytesToKey.pod +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_BytesToKey - password based encryption routine | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md, | ||
12 | const unsigned char *salt, | ||
13 | const unsigned char *data, int datal, int count, | ||
14 | unsigned char *key,unsigned char *iv); | ||
15 | |||
16 | =head1 DESCRIPTION | ||
17 | |||
18 | EVP_BytesToKey() derives a key and IV from various parameters. B<type> is | ||
19 | the cipher to derive the key and IV for. B<md> is the message digest to use. | ||
20 | The B<salt> parameter is used as a salt in the derivation: it should point to | ||
21 | an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing | ||
22 | B<datal> bytes which is used to derive the keying data. B<count> is the | ||
23 | iteration count to use. The derived key and IV will be written to B<key> | ||
24 | and B<iv> respectively. | ||
25 | |||
26 | =head1 NOTES | ||
27 | |||
28 | A typical application of this function is to derive keying material for an | ||
29 | encryption algorithm from a password in the B<data> parameter. | ||
30 | |||
31 | Increasing the B<count> parameter slows down the algorithm which makes it | ||
32 | harder for an attacker to perform a brute force attack using a large number | ||
33 | of candidate passwords. | ||
34 | |||
35 | If the total key and IV length is less than the digest length and | ||
36 | B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5 | ||
37 | otherwise a non standard extension is used to derive the extra data. | ||
38 | |||
39 | Newer applications should use more standard algorithms such as PBKDF2 as | ||
40 | defined in PKCS#5v2.1 for key derivation. | ||
41 | |||
42 | =head1 KEY DERIVATION ALGORITHM | ||
43 | |||
44 | The key and IV is derived by concatenating D_1, D_2, etc until | ||
45 | enough data is available for the key and IV. D_i is defined as: | ||
46 | |||
47 | D_i = HASH^count(D_(i-1) || data || salt) | ||
48 | |||
49 | where || denotes concatenation, D_0 is empty, HASH is the digest | ||
50 | algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data) | ||
51 | is HASH(HASH(data)) and so on. | ||
52 | |||
53 | The initial bytes are used for the key and the subsequent bytes for | ||
54 | the IV. | ||
55 | |||
56 | =head1 RETURN VALUES | ||
57 | |||
58 | EVP_BytesToKey() returns the size of the derived key in bytes. | ||
59 | |||
60 | =head1 SEE ALSO | ||
61 | |||
62 | L<evp(3)|evp(3)>, L<rand(3)|rand(3)>, | ||
63 | L<PKCS5_PBKDF2_HMAC(3)|PKCS5_PBKDF2_HMAC(3)>, | ||
64 | L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> | ||
65 | |||
66 | =head1 HISTORY | ||
67 | |||
68 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod deleted file mode 100644 index c83dcc736f..0000000000 --- a/src/lib/libcrypto/doc/EVP_DigestInit.pod +++ /dev/null | |||
@@ -1,277 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate, | ||
6 | EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE, | ||
7 | EVP_MD_CTX_copy_ex, EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, | ||
8 | EVP_MD_size, EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, | ||
9 | EVP_MD_CTX_block_size, EVP_MD_CTX_type, EVP_md_null, EVP_md2, EVP_md5, | ||
10 | EVP_sha1, EVP_sha224, EVP_sha256, EVP_sha384, EVP_sha512, EVP_dss, EVP_dss1, | ||
11 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, | ||
12 | EVP_get_digestbyobj, EVP_DigestInit, EVP_DigestFinal - EVP digest routines | ||
13 | |||
14 | =head1 SYNOPSIS | ||
15 | |||
16 | #include <openssl/evp.h> | ||
17 | |||
18 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx); | ||
19 | EVP_MD_CTX *EVP_MD_CTX_create(void); | ||
20 | |||
21 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); | ||
22 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); | ||
23 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, | ||
24 | unsigned int *s); | ||
25 | |||
26 | int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); | ||
27 | void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); | ||
28 | |||
29 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in); | ||
30 | |||
31 | int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); | ||
32 | int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, | ||
33 | unsigned int *s); | ||
34 | |||
35 | int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); | ||
36 | |||
37 | #define EVP_MAX_MD_SIZE 64 /* SHA512 */ | ||
38 | |||
39 | int EVP_MD_type(const EVP_MD *md); | ||
40 | int EVP_MD_pkey_type(const EVP_MD *md); | ||
41 | int EVP_MD_size(const EVP_MD *md); | ||
42 | int EVP_MD_block_size(const EVP_MD *md); | ||
43 | |||
44 | const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); | ||
45 | #define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) | ||
46 | #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
47 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | ||
48 | |||
49 | const EVP_MD *EVP_md_null(void); | ||
50 | const EVP_MD *EVP_md2(void); | ||
51 | const EVP_MD *EVP_md5(void); | ||
52 | const EVP_MD *EVP_sha1(void); | ||
53 | const EVP_MD *EVP_dss(void); | ||
54 | const EVP_MD *EVP_dss1(void); | ||
55 | const EVP_MD *EVP_ripemd160(void); | ||
56 | |||
57 | const EVP_MD *EVP_sha224(void); | ||
58 | const EVP_MD *EVP_sha256(void); | ||
59 | const EVP_MD *EVP_sha384(void); | ||
60 | const EVP_MD *EVP_sha512(void); | ||
61 | |||
62 | const EVP_MD *EVP_get_digestbyname(const char *name); | ||
63 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
64 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
65 | |||
66 | =head1 DESCRIPTION | ||
67 | |||
68 | The EVP digest routines are a high level interface to message digests. | ||
69 | |||
70 | EVP_MD_CTX_init() initializes digest context B<ctx>. | ||
71 | |||
72 | EVP_MD_CTX_create() allocates, initializes and returns a digest context. | ||
73 | |||
74 | EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest | ||
75 | B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this | ||
76 | function. B<type> will typically be supplied by a function such as EVP_sha1(). | ||
77 | If B<impl> is NULL then the default implementation of digest B<type> is used. | ||
78 | |||
79 | EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the | ||
80 | digest context B<ctx>. This function can be called several times on the | ||
81 | same B<ctx> to hash additional data. | ||
82 | |||
83 | EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places | ||
84 | it in B<md>. If the B<s> parameter is not NULL then the number of | ||
85 | bytes of data written (i.e. the length of the digest) will be written | ||
86 | to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written. | ||
87 | After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate() | ||
88 | can be made, but EVP_DigestInit_ex() can be called to initialize a new | ||
89 | digest operation. | ||
90 | |||
91 | EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called | ||
92 | after a digest context is no longer needed. | ||
93 | |||
94 | EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the | ||
95 | space allocated to it, it should be called only on a context created | ||
96 | using EVP_MD_CTX_create(). | ||
97 | |||
98 | EVP_MD_CTX_copy_ex() can be used to copy the message digest state from | ||
99 | B<in> to B<out>. This is useful if large amounts of data are to be | ||
100 | hashed which only differ in the last few bytes. B<out> must be initialized | ||
101 | before calling this function. | ||
102 | |||
103 | EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except | ||
104 | the passed context B<ctx> does not have to be initialized, and it always | ||
105 | uses the default digest implementation. | ||
106 | |||
107 | EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest | ||
108 | context B<ctx> is automatically cleaned up. | ||
109 | |||
110 | EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination | ||
111 | B<out> does not have to be initialized. | ||
112 | |||
113 | EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest | ||
114 | when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the | ||
115 | hash. | ||
116 | |||
117 | EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the | ||
118 | message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure. | ||
119 | |||
120 | EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER | ||
121 | representing the given message digest when passed an B<EVP_MD> structure. | ||
122 | For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is | ||
123 | normally used when setting ASN1 OIDs. | ||
124 | |||
125 | EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed | ||
126 | B<EVP_MD_CTX>. | ||
127 | |||
128 | EVP_MD_pkey_type() returns the NID of the public key signing algorithm | ||
129 | associated with this digest. For example EVP_sha1() is associated with RSA so | ||
130 | this will return B<NID_sha1WithRSAEncryption>. Since digests and signature | ||
131 | algorithms are no longer linked this function is only retained for | ||
132 | compatibility reasons. | ||
133 | |||
134 | EVP_md2(), EVP_md5(), EVP_sha1(), EVP_sha224(), EVP_sha256(), EVP_sha384(), | ||
135 | EVP_sha512() and EVP_ripemd160() return B<EVP_MD> structures for the MD2, MD5, | ||
136 | SHA1, SHA224, SHA256, SHA384, SHA512 and RIPEMD160 digest algorithms | ||
137 | respectively. | ||
138 | |||
139 | EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA1 digest | ||
140 | algorithms but using DSS (DSA) for the signature algorithm. Note: there is | ||
141 | no need to use these pseudo-digests in OpenSSL 1.0.0 and later, they are | ||
142 | however retained for compatibility. | ||
143 | |||
144 | EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it | ||
145 | returns is of zero length. | ||
146 | |||
147 | EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj() | ||
148 | return an B<EVP_MD> structure when passed a digest name, a digest NID or | ||
149 | an ASN1_OBJECT structure respectively. The digest table must be initialized | ||
150 | using, for example, OpenSSL_add_all_digests() for these functions to work. | ||
151 | |||
152 | =head1 RETURN VALUES | ||
153 | |||
154 | EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for | ||
155 | success and 0 for failure. | ||
156 | |||
157 | EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure. | ||
158 | |||
159 | EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the | ||
160 | corresponding OBJECT IDENTIFIER or NID_undef if none exists. | ||
161 | |||
162 | EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size() and | ||
163 | EVP_MD_CTX_block_size() return the digest or block size in bytes. | ||
164 | |||
165 | EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha1(), EVP_dss(), | ||
166 | EVP_dss1() and EVP_ripemd160() return pointers to the | ||
167 | corresponding EVP_MD structures. | ||
168 | |||
169 | EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj() | ||
170 | return either an B<EVP_MD> structure or NULL if an error occurs. | ||
171 | |||
172 | =head1 NOTES | ||
173 | |||
174 | The B<EVP> interface to message digests should almost always be used in | ||
175 | preference to the low level interfaces. This is because the code then becomes | ||
176 | transparent to the digest used and much more flexible. | ||
177 | |||
178 | New applications should use the SHA2 digest algorithms such as SHA256. | ||
179 | The other digest algorithms are still in common use. | ||
180 | |||
181 | For most applications the B<impl> parameter to EVP_DigestInit_ex() will be | ||
182 | set to NULL to use the default digest implementation. | ||
183 | |||
184 | The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are | ||
185 | obsolete but are retained to maintain compatibility with existing code. New | ||
186 | applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and | ||
187 | EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context | ||
188 | instead of initializing and cleaning it up on each call and allow non default | ||
189 | implementations of digests to be specified. | ||
190 | |||
191 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use | ||
192 | memory leaks will occur. | ||
193 | |||
194 | Stack allocation of EVP_MD_CTX structures is common, for example: | ||
195 | |||
196 | EVP_MD_CTX mctx; | ||
197 | EVP_MD_CTX_init(&mctx); | ||
198 | |||
199 | This will cause binary compatibility issues if the size of EVP_MD_CTX | ||
200 | structure changes (this will only happen with a major release of OpenSSL). | ||
201 | Applications wishing to avoid this should use EVP_MD_CTX_create() instead: | ||
202 | |||
203 | EVP_MD_CTX *mctx; | ||
204 | mctx = EVP_MD_CTX_create(); | ||
205 | |||
206 | |||
207 | =head1 EXAMPLE | ||
208 | |||
209 | This example digests the data "Test Message\n" and "Hello World\n", using the | ||
210 | digest name passed on the command line. | ||
211 | |||
212 | #include <stdio.h> | ||
213 | #include <openssl/evp.h> | ||
214 | |||
215 | int | ||
216 | main(int argc, char *argv[]) | ||
217 | { | ||
218 | EVP_MD_CTX *mdctx; | ||
219 | const EVP_MD *md; | ||
220 | const char mess1[] = "Test Message\n"; | ||
221 | const char mess2[] = "Hello World\n"; | ||
222 | unsigned char md_value[EVP_MAX_MD_SIZE]; | ||
223 | int md_len, i; | ||
224 | |||
225 | OpenSSL_add_all_digests(); | ||
226 | |||
227 | if (argc <= 1) { | ||
228 | printf("Usage: mdtest digestname\n"); | ||
229 | exit(1); | ||
230 | } | ||
231 | |||
232 | md = EVP_get_digestbyname(argv[1]); | ||
233 | if (md == NULL) { | ||
234 | printf("Unknown message digest %s\n", argv[1]); | ||
235 | exit(1); | ||
236 | } | ||
237 | |||
238 | mdctx = EVP_MD_CTX_create(); | ||
239 | EVP_DigestInit_ex(mdctx, md, NULL); | ||
240 | EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); | ||
241 | EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); | ||
242 | EVP_DigestFinal_ex(mdctx, md_value, &md_len); | ||
243 | EVP_MD_CTX_destroy(mdctx); | ||
244 | |||
245 | printf("Digest is: "); | ||
246 | for(i = 0; i < md_len; i++) | ||
247 | printf("%02x", md_value[i]); | ||
248 | printf("\n"); | ||
249 | } | ||
250 | |||
251 | =head1 SEE ALSO | ||
252 | |||
253 | L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, | ||
254 | L<md5(3)|md5(3)>, L<ripemd(3)|ripemd(3)>, | ||
255 | L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> | ||
256 | |||
257 | =head1 HISTORY | ||
258 | |||
259 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are | ||
260 | available in all versions of SSLeay and OpenSSL. | ||
261 | |||
262 | EVP_MD_CTX_init(), EVP_MD_CTX_create(), EVP_MD_CTX_copy_ex(), | ||
263 | EVP_MD_CTX_cleanup(), EVP_MD_CTX_destroy(), EVP_DigestInit_ex() | ||
264 | and EVP_DigestFinal_ex() were added in OpenSSL 0.9.7. | ||
265 | |||
266 | EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha1(), | ||
267 | EVP_dss(), EVP_dss1() and EVP_ripemd160() were | ||
268 | changed to return truely const EVP_MD * in OpenSSL 0.9.7. | ||
269 | |||
270 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 and | ||
271 | later, so now EVP_sha1() can be used with RSA and DSA, there is no need to | ||
272 | use EVP_dss1() any more. | ||
273 | |||
274 | OpenSSL 1.0 and later does not include the MD2 digest algorithm in the | ||
275 | default configuration due to its security weaknesses. | ||
276 | |||
277 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_DigestSignInit.pod b/src/lib/libcrypto/doc/EVP_DigestSignInit.pod deleted file mode 100644 index 00205d2ae9..0000000000 --- a/src/lib/libcrypto/doc/EVP_DigestSignInit.pod +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_DigestSignInit, EVP_DigestSignUpdate, EVP_DigestSignFinal - EVP signing | ||
6 | functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, | ||
13 | const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); | ||
14 | int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); | ||
15 | int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | The EVP signature routines are a high level interface to digital signatures. | ||
20 | |||
21 | EVP_DigestSignInit() sets up signing context B<ctx> to use digest B<type> from | ||
22 | ENGINE B<impl> and private key B<pkey>. B<ctx> must be initialized with | ||
23 | EVP_MD_CTX_init() before calling this function. If B<pctx> is not NULL the | ||
24 | EVP_PKEY_CTX of the signing operation will be written to B<*pctx>: this can | ||
25 | be used to set alternative signing options. | ||
26 | |||
27 | EVP_DigestSignUpdate() hashes B<cnt> bytes of data at B<d> into the | ||
28 | signature context B<ctx>. This function can be called several times on the | ||
29 | same B<ctx> to include additional data. This function is currently implemented | ||
30 | using a macro. | ||
31 | |||
32 | EVP_DigestSignFinal() signs the data in B<ctx> places the signature in B<sig>. | ||
33 | If B<sig> is B<NULL> then the maximum size of the output buffer is written to | ||
34 | the B<siglen> parameter. If B<sig> is not B<NULL> then before the call the | ||
35 | B<siglen> parameter should contain the length of the B<sig> buffer, if the | ||
36 | call is successful the signature is written to B<sig> and the amount of data | ||
37 | written to B<siglen>. | ||
38 | |||
39 | =head1 RETURN VALUES | ||
40 | |||
41 | EVP_DigestSignInit() EVP_DigestSignUpdate() and EVP_DigestSignaFinal() return | ||
42 | 1 for success and 0 or a negative value for failure. In particular a return | ||
43 | value of -2 indicates the operation is not supported by the public key | ||
44 | algorithm. | ||
45 | |||
46 | The error codes can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>. | ||
47 | |||
48 | =head1 NOTES | ||
49 | |||
50 | The B<EVP> interface to digital signatures should almost always be used in | ||
51 | preference to the low level interfaces. This is because the code then becomes | ||
52 | transparent to the algorithm used and much more flexible. | ||
53 | |||
54 | In previous versions of OpenSSL there was a link between message digest types | ||
55 | and public key algorithms. This meant that "clone" digests such as EVP_dss1() | ||
56 | needed to be used to sign using SHA1 and DSA. This is no longer necessary and | ||
57 | the use of clone digest is now discouraged. | ||
58 | |||
59 | The call to EVP_DigestSignFinal() internally finalizes a copy of the digest | ||
60 | context. This means that calls to EVP_DigestSignUpdate() and | ||
61 | EVP_DigestSignFinal() can be called later to digest and sign additional data. | ||
62 | |||
63 | Since only a copy of the digest context is ever finalized the context must | ||
64 | be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak | ||
65 | will occur. | ||
66 | |||
67 | The use of EVP_PKEY_size() with these functions is discouraged because some | ||
68 | signature operations may have a signature length which depends on the | ||
69 | parameters set. As a result EVP_PKEY_size() would have to return a value | ||
70 | which indicates the maximum possible signature for any set of parameters. | ||
71 | |||
72 | =head1 SEE ALSO | ||
73 | |||
74 | L<EVP_DigestVerifyInit(3)|EVP_DigestVerifyInit(3)>, | ||
75 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>, | ||
76 | L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, | ||
77 | L<md5(3)|md5(3)>, L<ripemd(3)|ripemd(3)>, | ||
78 | L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> | ||
79 | |||
80 | =head1 HISTORY | ||
81 | |||
82 | EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal() | ||
83 | were first added to OpenSSL 1.0.0. | ||
84 | |||
85 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_DigestVerifyInit.pod b/src/lib/libcrypto/doc/EVP_DigestVerifyInit.pod deleted file mode 100644 index 5dcfec1837..0000000000 --- a/src/lib/libcrypto/doc/EVP_DigestVerifyInit.pod +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_DigestVerifyInit, EVP_DigestVerifyUpdate, EVP_DigestVerifyFinal - EVP | ||
6 | signature verification functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, | ||
13 | const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); | ||
14 | int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); | ||
15 | int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | The EVP signature routines are a high level interface to digital signatures. | ||
20 | |||
21 | EVP_DigestVerifyInit() sets up verification context B<ctx> to use digest | ||
22 | B<type> from ENGINE B<impl> and public key B<pkey>. B<ctx> must be initialized | ||
23 | with EVP_MD_CTX_init() before calling this function. If B<pctx> is not NULL the | ||
24 | EVP_PKEY_CTX of the verification operation will be written to B<*pctx>: this | ||
25 | can be used to set alternative verification options. | ||
26 | |||
27 | EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the | ||
28 | verification context B<ctx>. This function can be called several times on the | ||
29 | same B<ctx> to include additional data. This function is currently implemented | ||
30 | using a macro. | ||
31 | |||
32 | EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in | ||
33 | B<sig> of length B<siglen>. | ||
34 | |||
35 | =head1 RETURN VALUES | ||
36 | |||
37 | EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0 | ||
38 | or a negative value for failure. In particular a return value of -2 indicates | ||
39 | the operation is not supported by the public key algorithm. | ||
40 | |||
41 | Unlike other functions the return value 0 from EVP_DigestVerifyFinal() only | ||
42 | indicates that the signature did not verify successfully (that is tbs did | ||
43 | not match the original data or the signature was of invalid form) it is not an | ||
44 | indication of a more serious error. | ||
45 | |||
46 | The error codes can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>. | ||
47 | |||
48 | =head1 NOTES | ||
49 | |||
50 | The B<EVP> interface to digital signatures should almost always be used in | ||
51 | preference to the low level interfaces. This is because the code then becomes | ||
52 | transparent to the algorithm used and much more flexible. | ||
53 | |||
54 | In previous versions of OpenSSL there was a link between message digest types | ||
55 | and public key algorithms. This meant that "clone" digests such as EVP_dss1() | ||
56 | needed to be used to sign using SHA1 and DSA. This is no longer necessary and | ||
57 | the use of clone digest is now discouraged. | ||
58 | |||
59 | The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest | ||
60 | context. This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can | ||
61 | be called later to digest and verify additional data. | ||
62 | |||
63 | Since only a copy of the digest context is ever finalized the context must | ||
64 | be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak | ||
65 | will occur. | ||
66 | |||
67 | =head1 SEE ALSO | ||
68 | |||
69 | L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>, | ||
70 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>, | ||
71 | L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, | ||
72 | L<md5(3)|md5(3)>, L<ripemd(3)|ripemd(3)>, | ||
73 | L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> | ||
74 | |||
75 | =head1 HISTORY | ||
76 | |||
77 | EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal() | ||
78 | were first added to OpenSSL 1.0.0. | ||
79 | |||
80 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod deleted file mode 100644 index 7ae3fe31ea..0000000000 --- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod +++ /dev/null | |||
@@ -1,548 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_CIPHER_CTX_init, EVP_EncryptInit_ex, EVP_EncryptUpdate, | ||
6 | EVP_EncryptFinal_ex, EVP_DecryptInit_ex, EVP_DecryptUpdate, | ||
7 | EVP_DecryptFinal_ex, EVP_CipherInit_ex, EVP_CipherUpdate, | ||
8 | EVP_CipherFinal_ex, EVP_CIPHER_CTX_set_key_length, | ||
9 | EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_cleanup, EVP_EncryptInit, | ||
10 | EVP_EncryptFinal, EVP_DecryptInit, EVP_DecryptFinal, | ||
11 | EVP_CipherInit, EVP_CipherFinal, EVP_get_cipherbyname, | ||
12 | EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_nid, | ||
13 | EVP_CIPHER_block_size, EVP_CIPHER_key_length, EVP_CIPHER_iv_length, | ||
14 | EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher, | ||
15 | EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length, | ||
16 | EVP_CIPHER_CTX_iv_length, EVP_CIPHER_CTX_get_app_data, | ||
17 | EVP_CIPHER_CTX_set_app_data, EVP_CIPHER_CTX_type, EVP_CIPHER_CTX_flags, | ||
18 | EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param, | ||
19 | EVP_CIPHER_CTX_set_padding, EVP_enc_null, EVP_des_cbc, EVP_des_ecb, | ||
20 | EVP_des_cfb, EVP_des_ofb, EVP_des_ede_cbc, EVP_des_ede, EVP_des_ede_ofb, | ||
21 | EVP_des_ede_cfb, EVP_des_ede3_cbc, EVP_des_ede3, EVP_des_ede3_ofb, | ||
22 | EVP_des_ede3_cfb, EVP_desx_cbc, EVP_rc4, EVP_rc4_40, EVP_idea_cbc, | ||
23 | EVP_idea_ecb, EVP_idea_cfb, EVP_idea_ofb, EVP_idea_cbc, EVP_rc2_cbc, | ||
24 | EVP_rc2_ecb, EVP_rc2_cfb, EVP_rc2_ofb, EVP_rc2_40_cbc, EVP_rc2_64_cbc, | ||
25 | EVP_bf_cbc, EVP_bf_ecb, EVP_bf_cfb, EVP_bf_ofb, EVP_cast5_cbc, | ||
26 | EVP_cast5_ecb, EVP_cast5_cfb, EVP_cast5_ofb, | ||
27 | EVP_aes_128_gcm, EVP_aes_192_gcm, EVP_aes_256_gcm, EVP_aes_128_ccm, | ||
28 | EVP_aes_192_ccm, EVP_aes_256_ccm, EVP_rc5_32_12_16_cbc, | ||
29 | EVP_rc5_32_12_16_cfb, EVP_rc5_32_12_16_ecb, EVP_rc5_32_12_16_ofb | ||
30 | - EVP cipher routines | ||
31 | |||
32 | =head1 SYNOPSIS | ||
33 | |||
34 | #include <openssl/evp.h> | ||
35 | |||
36 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); | ||
37 | |||
38 | int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
39 | ENGINE *impl, unsigned char *key, unsigned char *iv); | ||
40 | int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
41 | int *outl, unsigned char *in, int inl); | ||
42 | int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
43 | int *outl); | ||
44 | |||
45 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
46 | ENGINE *impl, unsigned char *key, unsigned char *iv); | ||
47 | int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
48 | int *outl, unsigned char *in, int inl); | ||
49 | int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
50 | int *outl); | ||
51 | |||
52 | int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
53 | ENGINE *impl, unsigned char *key, unsigned char *iv, int enc); | ||
54 | int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
55 | int *outl, unsigned char *in, int inl); | ||
56 | int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
57 | int *outl); | ||
58 | |||
59 | int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
60 | unsigned char *key, unsigned char *iv); | ||
61 | int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
62 | int *outl); | ||
63 | |||
64 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
65 | unsigned char *key, unsigned char *iv); | ||
66 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
67 | int *outl); | ||
68 | |||
69 | int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
70 | unsigned char *key, unsigned char *iv, int enc); | ||
71 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, | ||
72 | int *outl); | ||
73 | |||
74 | int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding); | ||
75 | int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); | ||
76 | int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); | ||
77 | int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); | ||
78 | |||
79 | const EVP_CIPHER *EVP_get_cipherbyname(const char *name); | ||
80 | #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
81 | #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
82 | |||
83 | #define EVP_CIPHER_nid(e) ((e)->nid) | ||
84 | #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
85 | #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
86 | #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
87 | #define EVP_CIPHER_flags(e) ((e)->flags) | ||
88 | #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE) | ||
89 | int EVP_CIPHER_type(const EVP_CIPHER *ctx); | ||
90 | |||
91 | #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
92 | #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
93 | #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
94 | #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len) | ||
95 | #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
96 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
97 | #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
98 | #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) | ||
99 | #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags) | ||
100 | #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE) | ||
101 | |||
102 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
103 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
104 | |||
105 | =head1 DESCRIPTION | ||
106 | |||
107 | The EVP cipher routines are a high level interface to certain | ||
108 | symmetric ciphers. | ||
109 | |||
110 | EVP_CIPHER_CTX_init() initializes cipher context B<ctx>. | ||
111 | |||
112 | EVP_EncryptInit_ex() sets up cipher context B<ctx> for encryption | ||
113 | with cipher B<type> from ENGINE B<impl>. B<ctx> must be initialized | ||
114 | before calling this function. B<type> is normally supplied | ||
115 | by a function such as EVP_aes_256_cbc(). If B<impl> is NULL then the | ||
116 | default implementation is used. B<key> is the symmetric key to use | ||
117 | and B<iv> is the IV to use (if necessary), the actual number of bytes | ||
118 | used for the key and IV depends on the cipher. It is possible to set | ||
119 | all parameters to NULL except B<type> in an initial call and supply | ||
120 | the remaining parameters in subsequent calls, all of which have B<type> | ||
121 | set to NULL. This is done when the default cipher parameters are not | ||
122 | appropriate. | ||
123 | |||
124 | EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and | ||
125 | writes the encrypted version to B<out>. This function can be called | ||
126 | multiple times to encrypt successive blocks of data. The amount | ||
127 | of data written depends on the block alignment of the encrypted data: | ||
128 | as a result the amount of data written may be anything from zero bytes | ||
129 | to (inl + cipher_block_size - 1) so B<outl> should contain sufficient | ||
130 | room. The actual number of bytes written is placed in B<outl>. | ||
131 | |||
132 | If padding is enabled (the default) then EVP_EncryptFinal_ex() encrypts | ||
133 | the "final" data, that is any data that remains in a partial block. | ||
134 | It uses L<standard block padding|/NOTES> (aka PKCS padding). The encrypted | ||
135 | final data is written to B<out> which should have sufficient space for | ||
136 | one cipher block. The number of bytes written is placed in B<outl>. After | ||
137 | this function is called the encryption operation is finished and no further | ||
138 | calls to EVP_EncryptUpdate() should be made. | ||
139 | |||
140 | If padding is disabled then EVP_EncryptFinal_ex() will not encrypt any more | ||
141 | data and it will return an error if any data remains in a partial block: | ||
142 | that is if the total data length is not a multiple of the block size. | ||
143 | |||
144 | EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the | ||
145 | corresponding decryption operations. EVP_DecryptFinal() will return an | ||
146 | error code if padding is enabled and the final block is not correctly | ||
147 | formatted. The parameters and restrictions are identical to the encryption | ||
148 | operations except that if padding is enabled the decrypted data buffer B<out> | ||
149 | passed to EVP_DecryptUpdate() should have sufficient room for | ||
150 | (B<inl> + cipher_block_size) bytes unless the cipher block size is 1 in | ||
151 | which case B<inl> bytes is sufficient. | ||
152 | |||
153 | EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex() are | ||
154 | functions that can be used for decryption or encryption. The operation | ||
155 | performed depends on the value of the B<enc> parameter. It should be set | ||
156 | to 1 for encryption, 0 for decryption and -1 to leave the value unchanged | ||
157 | (the actual value of 'enc' being supplied in a previous call). | ||
158 | |||
159 | EVP_CIPHER_CTX_cleanup() clears all information from a cipher context | ||
160 | and free up any allocated memory associate with it. It should be called | ||
161 | after all operations using a cipher are complete so sensitive information | ||
162 | does not remain in memory. | ||
163 | |||
164 | EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit() behave in a | ||
165 | similar way to EVP_EncryptInit_ex(), EVP_DecryptInit_ex and | ||
166 | EVP_CipherInit_ex() except the B<ctx> parameter does not need to be | ||
167 | initialized and they always use the default cipher implementation. | ||
168 | |||
169 | EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal() are | ||
170 | identical to EVP_EncryptFinal_ex(), EVP_DecryptFinal_ex() and | ||
171 | EVP_CipherFinal_ex(). In previous releases of OpenSSL they also used to clean | ||
172 | up the B<ctx>, but this is no longer done and EVP_CIPHER_CTX_clean() | ||
173 | must be called to free any context resources. | ||
174 | |||
175 | EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj() | ||
176 | return an EVP_CIPHER structure when passed a cipher name, a NID or an | ||
177 | ASN1_OBJECT structure. | ||
178 | |||
179 | EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when | ||
180 | passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID | ||
181 | value is an internal value which may not have a corresponding OBJECT | ||
182 | IDENTIFIER. | ||
183 | |||
184 | EVP_CIPHER_CTX_set_padding() enables or disables padding. By default | ||
185 | encryption operations are padded using standard block padding and the | ||
186 | padding is checked and removed when decrypting. If the B<pad> parameter | ||
187 | is zero then no padding is performed, the total amount of data encrypted | ||
188 | or decrypted must then be a multiple of the block size or an error will | ||
189 | occur. | ||
190 | |||
191 | EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key | ||
192 | length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> | ||
193 | structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length | ||
194 | for all ciphers. Note: although EVP_CIPHER_key_length() is fixed for a | ||
195 | given cipher, the value of EVP_CIPHER_CTX_key_length() may be different | ||
196 | for variable key length ciphers. | ||
197 | |||
198 | EVP_CIPHER_CTX_set_key_length() sets the key length of the cipher ctx. | ||
199 | If the cipher is a fixed length cipher then attempting to set the key | ||
200 | length to any value other than the fixed value is an error. | ||
201 | |||
202 | EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV | ||
203 | length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>. | ||
204 | It will return zero if the cipher does not use an IV. The constant | ||
205 | B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers. | ||
206 | |||
207 | EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block | ||
208 | size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> | ||
209 | structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block | ||
210 | length for all ciphers. | ||
211 | |||
212 | EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed | ||
213 | cipher or context. This "type" is the actual NID of the cipher OBJECT | ||
214 | IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and | ||
215 | 128 bit RC2 have the same NID. If the cipher does not have an object | ||
216 | identifier or does not have ASN1 support this function will return | ||
217 | B<NID_undef>. | ||
218 | |||
219 | EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed | ||
220 | an B<EVP_CIPHER_CTX> structure. | ||
221 | |||
222 | EVP_CIPHER_mode() and EVP_CIPHER_CTX_mode() return the block cipher mode: | ||
223 | EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE or | ||
224 | EVP_CIPH_OFB_MODE. If the cipher is a stream cipher then | ||
225 | EVP_CIPH_STREAM_CIPHER is returned. | ||
226 | |||
227 | EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based | ||
228 | on the passed cipher. This will typically include any parameters and an | ||
229 | IV. The cipher IV (if any) must be set when this call is made. This call | ||
230 | should be made before the cipher is actually "used" (before any | ||
231 | EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function | ||
232 | may fail if the cipher does not have any ASN1 support. | ||
233 | |||
234 | EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1 | ||
235 | AlgorithmIdentifier "parameter". The precise effect depends on the cipher | ||
236 | In the case of RC2, for example, it will set the IV and effective key length. | ||
237 | This function should be called after the base cipher type is set but before | ||
238 | the key is set. For example EVP_CipherInit() will be called with the IV and | ||
239 | key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally | ||
240 | EVP_CipherInit() again with all parameters except the key set to NULL. It is | ||
241 | possible for this function to fail if the cipher does not have any ASN1 support | ||
242 | or the parameters cannot be set (for example the RC2 effective key length | ||
243 | is not supported. | ||
244 | |||
245 | EVP_CIPHER_CTX_ctrl() allows various cipher specific parameters to be determined | ||
246 | and set. Currently only the RC2 effective key length and the number of rounds of | ||
247 | RC5 can be set. | ||
248 | |||
249 | =head1 RETURN VALUES | ||
250 | |||
251 | EVP_EncryptInit_ex(), EVP_EncryptUpdate() and EVP_EncryptFinal_ex() | ||
252 | return 1 for success and 0 for failure. | ||
253 | |||
254 | EVP_DecryptInit_ex() and EVP_DecryptUpdate() return 1 for success and 0 for | ||
255 | failure. EVP_DecryptFinal_ex() returns 0 if the decrypt failed or 1 for | ||
256 | success. | ||
257 | |||
258 | EVP_CipherInit_ex() and EVP_CipherUpdate() return 1 for success and 0 for | ||
259 | failure. EVP_CipherFinal_ex() returns 0 for a decryption failure or 1 for | ||
260 | success. | ||
261 | |||
262 | EVP_CIPHER_CTX_cleanup() returns 1 for success and 0 for failure. | ||
263 | |||
264 | EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj() | ||
265 | return an B<EVP_CIPHER> structure or NULL on error. | ||
266 | |||
267 | EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID. | ||
268 | |||
269 | EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block | ||
270 | size. | ||
271 | |||
272 | EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key | ||
273 | length. | ||
274 | |||
275 | EVP_CIPHER_CTX_set_padding() always returns 1. | ||
276 | |||
277 | EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV | ||
278 | length or zero if the cipher does not use an IV. | ||
279 | |||
280 | EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's | ||
281 | OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER. | ||
282 | |||
283 | EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure. | ||
284 | |||
285 | EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for | ||
286 | success or zero for failure. | ||
287 | |||
288 | =head1 CIPHER LISTING | ||
289 | |||
290 | All algorithms have a fixed key length unless otherwise stated. | ||
291 | |||
292 | =over 4 | ||
293 | |||
294 | =item EVP_enc_null(void) | ||
295 | |||
296 | Null cipher: does nothing. | ||
297 | |||
298 | =item EVP_aes_128_cbc(void), EVP_aes_128_ecb(void), EVP_aes_128_cfb(void), EVP_aes_128_ofb(void) | ||
299 | |||
300 | 128-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
301 | |||
302 | =item EVP_aes_192_cbc(void), EVP_aes_192_ecb(void), EVP_aes_192_cfb(void), EVP_aes_192_ofb(void) | ||
303 | |||
304 | 192-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
305 | |||
306 | =item EVP_aes_256_cbc(void), EVP_aes_256_ecb(void), EVP_aes_256_cfb(void), EVP_aes_256_ofb(void) | ||
307 | |||
308 | 256-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
309 | |||
310 | =item EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void) | ||
311 | |||
312 | DES in CBC, ECB, CFB and OFB modes respectively. | ||
313 | |||
314 | =item EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), | ||
315 | EVP_des_ede_cfb(void) | ||
316 | |||
317 | Two key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
318 | |||
319 | =item EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), | ||
320 | EVP_des_ede3_cfb(void) | ||
321 | |||
322 | Three key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
323 | |||
324 | =item EVP_desx_cbc(void) | ||
325 | |||
326 | DESX algorithm in CBC mode. | ||
327 | |||
328 | =item EVP_rc4(void) | ||
329 | |||
330 | RC4 stream cipher. This is a variable key length cipher with default key length | ||
331 | 128 bits. | ||
332 | |||
333 | =item EVP_rc4_40(void) | ||
334 | |||
335 | RC4 stream cipher with 40 bit key length. This is obsolete and new code should | ||
336 | use EVP_rc4() and the EVP_CIPHER_CTX_set_key_length() function. | ||
337 | |||
338 | =item EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), | ||
339 | EVP_idea_ofb(void), EVP_idea_cbc(void) | ||
340 | |||
341 | IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
342 | |||
343 | =item EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void) | ||
344 | |||
345 | RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a | ||
346 | variable key length cipher with an additional parameter called "effective key | ||
347 | bits" or "effective key length". By default both are set to 128 bits. | ||
348 | |||
349 | =item EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void) | ||
350 | |||
351 | RC2 algorithm in CBC mode with a default key length and effective key length of | ||
352 | 40 and 64 bits. These are obsolete and new code should use EVP_rc2_cbc(), | ||
353 | EVP_CIPHER_CTX_set_key_length() and EVP_CIPHER_CTX_ctrl() to set the key length | ||
354 | and effective key length. | ||
355 | |||
356 | =item EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void); | ||
357 | |||
358 | Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This | ||
359 | is a variable key length cipher. | ||
360 | |||
361 | =item EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), | ||
362 | EVP_cast5_ofb(void) | ||
363 | |||
364 | CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is | ||
365 | a variable key length cipher. | ||
366 | |||
367 | =item EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), | ||
368 | EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void) | ||
369 | |||
370 | RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a | ||
371 | variable key length cipher with an additional "number of rounds" parameter. By | ||
372 | default the key length is set to 128 bits and 12 rounds. | ||
373 | |||
374 | =back | ||
375 | |||
376 | =head1 NOTES | ||
377 | |||
378 | Where possible the B<EVP> interface to symmetric ciphers should be used in | ||
379 | preference to the low level interfaces. This is because the code then becomes | ||
380 | transparent to the cipher used and much more flexible. | ||
381 | |||
382 | PKCS padding works by adding B<n> padding bytes of value B<n> to make the total | ||
383 | length of the encrypted data a multiple of the block size. Padding is always | ||
384 | added so if the data is already a multiple of the block size B<n> will equal | ||
385 | the block size. For example if the block size is 8 and 11 bytes are to be | ||
386 | encrypted then 5 padding bytes of value 5 will be added. | ||
387 | |||
388 | When decrypting the final block is checked to see if it has the correct form. | ||
389 | |||
390 | Although the decryption operation can produce an error if padding is enabled, | ||
391 | it is not a strong test that the input data or key is correct. A random block | ||
392 | has better than 1 in 256 chance of being of the correct format and problems with | ||
393 | the input data earlier on will not produce a final decrypt error. | ||
394 | |||
395 | If padding is disabled then the decryption operation will always succeed if | ||
396 | the total amount of data decrypted is a multiple of the block size. | ||
397 | |||
398 | The functions EVP_EncryptInit(), EVP_EncryptFinal(), EVP_DecryptInit(), | ||
399 | EVP_CipherInit() and EVP_CipherFinal() are obsolete but are retained for | ||
400 | compatibility with existing code. New code should use EVP_EncryptInit_ex(), | ||
401 | EVP_EncryptFinal_ex(), EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), | ||
402 | EVP_CipherInit_ex() and EVP_CipherFinal_ex() because they can reuse an | ||
403 | existing context without allocating and freeing it up on each call. | ||
404 | |||
405 | =head1 BUGS | ||
406 | |||
407 | For RC5 the number of rounds can currently only be set to 8, 12 or 16. This is | ||
408 | a limitation of the current RC5 code rather than the EVP interface. | ||
409 | |||
410 | EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with | ||
411 | default key lengths. If custom ciphers exceed these values the results are | ||
412 | unpredictable. This is because it has become standard practice to define a | ||
413 | generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes. | ||
414 | |||
415 | The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested | ||
416 | for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode. | ||
417 | |||
418 | =head1 EXAMPLES | ||
419 | |||
420 | Get the number of rounds used in RC5: | ||
421 | |||
422 | int nrounds; | ||
423 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds); | ||
424 | |||
425 | Get the RC2 effective key length: | ||
426 | |||
427 | int key_bits; | ||
428 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits); | ||
429 | |||
430 | Set the number of rounds used in RC5: | ||
431 | |||
432 | int nrounds; | ||
433 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL); | ||
434 | |||
435 | Set the effective key length used in RC2: | ||
436 | |||
437 | int key_bits; | ||
438 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | ||
439 | |||
440 | Encrypt a string using blowfish: | ||
441 | |||
442 | int | ||
443 | do_crypt(char *outfile) | ||
444 | { | ||
445 | unsigned char outbuf[1024]; | ||
446 | int outlen, tmplen; | ||
447 | /* | ||
448 | * Bogus key and IV: we'd normally set these from | ||
449 | * another source. | ||
450 | */ | ||
451 | unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
452 | unsigned char iv[] = {1,2,3,4,5,6,7,8}; | ||
453 | const char intext[] = "Some Crypto Text"; | ||
454 | EVP_CIPHER_CTX ctx; | ||
455 | FILE *out; | ||
456 | EVP_CIPHER_CTX_init(&ctx); | ||
457 | EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); | ||
458 | |||
459 | if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, | ||
460 | strlen(intext))) { | ||
461 | /* Error */ | ||
462 | return 0; | ||
463 | } | ||
464 | /* | ||
465 | * Buffer passed to EVP_EncryptFinal() must be after data just | ||
466 | * encrypted to avoid overwriting it. | ||
467 | */ | ||
468 | if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) { | ||
469 | /* Error */ | ||
470 | return 0; | ||
471 | } | ||
472 | outlen += tmplen; | ||
473 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
474 | /* | ||
475 | * Need binary mode for fopen because encrypted data is | ||
476 | * binary data. Also cannot use strlen() on it because | ||
477 | * it won't be NUL terminated and may contain embedded | ||
478 | * NULs. | ||
479 | */ | ||
480 | out = fopen(outfile, "wb"); | ||
481 | fwrite(outbuf, 1, outlen, out); | ||
482 | fclose(out); | ||
483 | return 1; | ||
484 | } | ||
485 | |||
486 | The ciphertext from the above example can be decrypted using the B<openssl> | ||
487 | utility with the command line: | ||
488 | |||
489 | S<openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F -iv 0102030405060708 -d> | ||
490 | |||
491 | General encryption, decryption function example using FILE I/O and RC2 with an | ||
492 | 80 bit key: | ||
493 | |||
494 | int | ||
495 | do_crypt(FILE *in, FILE *out, int do_encrypt) | ||
496 | { | ||
497 | /* Allow enough space in output buffer for additional block */ | ||
498 | inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; | ||
499 | int inlen, outlen; | ||
500 | /* | ||
501 | * Bogus key and IV: we'd normally set these from | ||
502 | * another source. | ||
503 | */ | ||
504 | unsigned char key[] = "0123456789"; | ||
505 | unsigned char iv[] = "12345678"; | ||
506 | |||
507 | /* Don't set key or IV because we will modify the parameters */ | ||
508 | EVP_CIPHER_CTX_init(&ctx); | ||
509 | EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); | ||
510 | EVP_CIPHER_CTX_set_key_length(&ctx, 10); | ||
511 | /* We finished modifying parameters so now we can set key and IV */ | ||
512 | EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt); | ||
513 | |||
514 | for(;;) { | ||
515 | inlen = fread(inbuf, 1, 1024, in); | ||
516 | if (inlen <= 0) | ||
517 | break; | ||
518 | if (!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, | ||
519 | inlen)) { | ||
520 | /* Error */ | ||
521 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
522 | return 0; | ||
523 | } | ||
524 | fwrite(outbuf, 1, outlen, out); | ||
525 | } | ||
526 | if (!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) { | ||
527 | /* Error */ | ||
528 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
529 | return 0; | ||
530 | } | ||
531 | fwrite(outbuf, 1, outlen, out); | ||
532 | |||
533 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
534 | return 1; | ||
535 | } | ||
536 | |||
537 | =head1 SEE ALSO | ||
538 | |||
539 | L<evp(3)|evp(3)> | ||
540 | |||
541 | =head1 HISTORY | ||
542 | |||
543 | EVP_CIPHER_CTX_init(), EVP_EncryptInit_ex(), EVP_EncryptFinal_ex(), | ||
544 | EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), EVP_CipherInit_ex(), | ||
545 | EVP_CipherFinal_ex() and EVP_CIPHER_CTX_set_padding() appeared in | ||
546 | OpenSSL 0.9.7. | ||
547 | |||
548 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_OpenInit.pod b/src/lib/libcrypto/doc/EVP_OpenInit.pod deleted file mode 100644 index 0242f66715..0000000000 --- a/src/lib/libcrypto/doc/EVP_OpenInit.pod +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_OpenInit, EVP_OpenUpdate, EVP_OpenFinal - EVP envelope decryption | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, | ||
12 | int ekl,unsigned char *iv,EVP_PKEY *priv); | ||
13 | int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
14 | int *outl, unsigned char *in, int inl); | ||
15 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
16 | int *outl); | ||
17 | |||
18 | =head1 DESCRIPTION | ||
19 | |||
20 | The EVP envelope routines are a high level interface to envelope | ||
21 | decryption. They decrypt a public key encrypted symmetric key and | ||
22 | then decrypt data using it. | ||
23 | |||
24 | EVP_OpenInit() initializes a cipher context B<ctx> for decryption | ||
25 | with cipher B<type>. It decrypts the encrypted symmetric key of length | ||
26 | B<ekl> bytes passed in the B<ek> parameter using the private key B<priv>. | ||
27 | The IV is supplied in the B<iv> parameter. | ||
28 | |||
29 | EVP_OpenUpdate() and EVP_OpenFinal() have exactly the same properties | ||
30 | as the EVP_DecryptUpdate() and EVP_DecryptFinal() routines, as | ||
31 | documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual | ||
32 | page. | ||
33 | |||
34 | =head1 NOTES | ||
35 | |||
36 | It is possible to call EVP_OpenInit() twice in the same way as | ||
37 | EVP_DecryptInit(). The first call should have B<priv> set to NULL | ||
38 | and (after setting any cipher parameters) it should be called again | ||
39 | with B<type> set to NULL. | ||
40 | |||
41 | If the cipher passed in the B<type> parameter is a variable length | ||
42 | cipher then the key length will be set to the value of the recovered | ||
43 | key length. If the cipher is a fixed length cipher then the recovered | ||
44 | key length must match the fixed cipher length. | ||
45 | |||
46 | =head1 RETURN VALUES | ||
47 | |||
48 | EVP_OpenInit() returns 0 on error or a non zero integer (actually the | ||
49 | recovered secret key size) if successful. | ||
50 | |||
51 | EVP_OpenUpdate() returns 1 for success or 0 for failure. | ||
52 | |||
53 | EVP_OpenFinal() returns 0 if the decrypt failed or 1 for success. | ||
54 | |||
55 | =head1 SEE ALSO | ||
56 | |||
57 | L<evp(3)|evp(3)>, L<rand(3)|rand(3)>, | ||
58 | L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>, | ||
59 | L<EVP_SealInit(3)|EVP_SealInit(3)> | ||
60 | |||
61 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_CTX_ctrl.pod b/src/lib/libcrypto/doc/EVP_PKEY_CTX_ctrl.pod deleted file mode 100644 index e8776e1e67..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_CTX_ctrl.pod +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_CTX_ctrl, EVP_PKEY_CTX_ctrl_str, EVP_PKEY_get_default_digest_nid, | ||
6 | EVP_PKEY_CTX_set_signature_md, EVP_PKEY_CTX_set_rsa_padding, | ||
7 | EVP_PKEY_CTX_set_rsa_pss_saltlen, EVP_PKEY_CTX_set_rsa_rsa_keygen_bits, | ||
8 | EVP_PKEY_CTX_set_rsa_keygen_pubexp, EVP_PKEY_CTX_set_dsa_paramgen_bits, | ||
9 | EVP_PKEY_CTX_set_dh_paramgen_prime_len, | ||
10 | EVP_PKEY_CTX_set_dh_paramgen_generator, | ||
11 | EVP_PKEY_CTX_set_ec_paramgen_curve_nid - algorithm specific control operations | ||
12 | |||
13 | =head1 SYNOPSIS | ||
14 | |||
15 | #include <openssl/evp.h> | ||
16 | |||
17 | int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, | ||
18 | int cmd, int p1, void *p2); | ||
19 | int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, | ||
20 | const char *value); | ||
21 | |||
22 | int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); | ||
23 | |||
24 | #include <openssl/rsa.h> | ||
25 | |||
26 | int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); | ||
27 | |||
28 | int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad); | ||
29 | int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int len); | ||
30 | int EVP_PKEY_CTX_set_rsa_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int mbits); | ||
31 | int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp); | ||
32 | |||
33 | #include <openssl/dsa.h> | ||
34 | int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits); | ||
35 | |||
36 | #include <openssl/dh.h> | ||
37 | int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int len); | ||
38 | int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen); | ||
39 | |||
40 | #include <openssl/ec.h> | ||
41 | int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid); | ||
42 | |||
43 | =head1 DESCRIPTION | ||
44 | |||
45 | The function EVP_PKEY_CTX_ctrl() sends a control operation to the context | ||
46 | B<ctx>. The key type used must match B<keytype> if it is not -1. The parameter | ||
47 | B<optype> is a mask indicating which operations the control can be applied to. | ||
48 | The control command is indicated in B<cmd> and any additional arguments in | ||
49 | B<p1> and B<p2>. | ||
50 | |||
51 | Applications will not normally call EVP_PKEY_CTX_ctrl() directly but will | ||
52 | instead call one of the algorithm specific macros below. | ||
53 | |||
54 | The function EVP_PKEY_CTX_ctrl_str() allows an application to send an algorithm | ||
55 | specific control operation to a context B<ctx> in string form. This is | ||
56 | intended to be used for options specified on the command line or in text | ||
57 | files. The commands supported are documented in the openssl utility | ||
58 | command line pages for the option B<-pkeyopt> which is supported by the | ||
59 | B<pkeyutl>, B<genpkey> and B<req> commands. | ||
60 | |||
61 | All the remaining "functions" are implemented as macros. | ||
62 | |||
63 | The EVP_PKEY_CTX_set_signature_md() macro sets the message digest type used | ||
64 | in a signature. It can be used with any public key algorithm supporting | ||
65 | signature operations. | ||
66 | |||
67 | The macro EVP_PKEY_CTX_set_rsa_padding() sets the RSA padding mode for B<ctx>. | ||
68 | The B<pad> parameter can take the value RSA_PKCS1_PADDING for PKCS#1 padding, | ||
69 | RSA_SSLV23_PADDING for SSLv23 padding, RSA_NO_PADDING for no padding, | ||
70 | RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt only), | ||
71 | RSA_X931_PADDING for X9.31 padding (signature operations only) and | ||
72 | RSA_PKCS1_PSS_PADDING (sign and verify only). | ||
73 | |||
74 | Two RSA padding modes behave differently if EVP_PKEY_CTX_set_signature_md() is | ||
75 | used. If this macro is called for PKCS#1 padding the plaintext buffer is an | ||
76 | actual digest value and is encapsulated in a DigestInfo structure according to | ||
77 | PKCS#1 when signing and this structure is expected (and stripped off) when | ||
78 | verifying. If this control is not used with RSA and PKCS#1 padding then the | ||
79 | supplied data is used directly and not encapsulated. In the case of X9.31 | ||
80 | padding for RSA the algorithm identifier byte is added or checked and removed | ||
81 | if this control is called. If it is not called then the first byte of the | ||
82 | plaintext buffer is expected to be the algorithm identifier byte. | ||
83 | |||
84 | The EVP_PKEY_CTX_set_rsa_pss_saltlen() macro sets the RSA PSS salt length to | ||
85 | B<len> as its name implies it is only supported for PSS padding. Two special | ||
86 | values are supported: -1 sets the salt length to the digest length. When | ||
87 | signing -2 sets the salt length to the maximum permissible value. When | ||
88 | verifying -2 causes the salt length to be automatically determined based on the | ||
89 | B<PSS> block structure. If this macro is not called a salt length value of -2 | ||
90 | is used by default. | ||
91 | |||
92 | The EVP_PKEY_CTX_set_rsa_rsa_keygen_bits() macro sets the RSA key length for | ||
93 | RSA key generation to B<bits>. If not specified 1024 bits is used. | ||
94 | |||
95 | The EVP_PKEY_CTX_set_rsa_keygen_pubexp() macro sets the public exponent value | ||
96 | for RSA key generation to B<pubexp> currently it should be an odd integer. The | ||
97 | B<pubexp> pointer is used internally by this function so it should not be | ||
98 | modified or free after the call. If this macro is not called then 65537 is used. | ||
99 | |||
100 | The macro EVP_PKEY_CTX_set_dsa_paramgen_bits() sets the number of bits used | ||
101 | for DSA parameter generation to B<bits>. If not specified 1024 is used. | ||
102 | |||
103 | The macro EVP_PKEY_CTX_set_dh_paramgen_prime_len() sets the length of the DH | ||
104 | prime parameter B<p> for DH parameter generation. If this macro is not called | ||
105 | then 1024 is used. | ||
106 | |||
107 | The EVP_PKEY_CTX_set_dh_paramgen_generator() macro sets DH generator to B<gen> | ||
108 | for DH parameter generation. If not specified 2 is used. | ||
109 | |||
110 | The EVP_PKEY_CTX_set_ec_paramgen_curve_nid() sets the EC curve for EC parameter | ||
111 | generation to B<nid>. For EC parameter generation this macro must be called | ||
112 | or an error occurs because there is no default curve. | ||
113 | |||
114 | =head1 RETURN VALUES | ||
115 | |||
116 | EVP_PKEY_CTX_ctrl() and its macros return a positive value for success and 0 | ||
117 | or a negative value for failure. In particular a return value of -2 | ||
118 | indicates the operation is not supported by the public key algorithm. | ||
119 | |||
120 | =head1 SEE ALSO | ||
121 | |||
122 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
123 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
124 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
125 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
126 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
127 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
128 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
129 | L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> | ||
130 | |||
131 | =head1 HISTORY | ||
132 | |||
133 | These functions were first added to OpenSSL 1.0.0. | ||
134 | |||
135 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_CTX_new.pod b/src/lib/libcrypto/doc/EVP_PKEY_CTX_new.pod deleted file mode 100644 index 60ad61e853..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_CTX_new.pod +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_CTX_new, EVP_PKEY_CTX_new_id, EVP_PKEY_CTX_dup, EVP_PKEY_CTX_free - | ||
6 | public key algorithm context functions. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); | ||
13 | EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); | ||
14 | EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); | ||
15 | void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | The EVP_PKEY_CTX_new() function allocates public key algorithm context using | ||
20 | the algorithm specified in B<pkey> and ENGINE B<e>. | ||
21 | |||
22 | The EVP_PKEY_CTX_new_id() function allocates public key algorithm context | ||
23 | using the algorithm specified by B<id> and ENGINE B<e>. It is normally used | ||
24 | when no B<EVP_PKEY> structure is associated with the operations, for example | ||
25 | during parameter generation of key generation for some algorithms. | ||
26 | |||
27 | EVP_PKEY_CTX_dup() duplicates the context B<ctx>. | ||
28 | |||
29 | EVP_PKEY_CTX_free() frees up the context B<ctx>. | ||
30 | |||
31 | =head1 NOTES | ||
32 | |||
33 | The B<EVP_PKEY_CTX> structure is an opaque public key algorithm context used | ||
34 | by the OpenSSL high level public key API. Contexts B<MUST NOT> be shared between | ||
35 | threads: that is it is not permissible to use the same context simultaneously | ||
36 | in two threads. | ||
37 | |||
38 | =head1 RETURN VALUES | ||
39 | |||
40 | EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), EVP_PKEY_CTX_dup() returns either | ||
41 | the newly allocated B<EVP_PKEY_CTX> structure of B<NULL> if an error occurred. | ||
42 | |||
43 | EVP_PKEY_CTX_free() does not return a value. | ||
44 | |||
45 | =head1 SEE ALSO | ||
46 | |||
47 | L<EVP_PKEY_new(3)|EVP_PKEY_new(3)> | ||
48 | |||
49 | =head1 HISTORY | ||
50 | |||
51 | These functions were first added to OpenSSL 1.0.0. | ||
52 | |||
53 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_cmp.pod b/src/lib/libcrypto/doc/EVP_PKEY_cmp.pod deleted file mode 100644 index 7a690247bf..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_cmp.pod +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_copy_parameters, EVP_PKEY_missing_parameters, EVP_PKEY_cmp_parameters, | ||
6 | EVP_PKEY_cmp - public key parameter and comparison functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); | ||
13 | int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); | ||
14 | |||
15 | int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); | ||
16 | int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); | ||
17 | |||
18 | =head1 DESCRIPTION | ||
19 | |||
20 | The function EVP_PKEY_missing_parameters() returns 1 if the public key | ||
21 | parameters of B<pkey> are missing and 0 if they are present or the algorithm | ||
22 | doesn't use parameters. | ||
23 | |||
24 | The function EVP_PKEY_copy_parameters() copies the parameters from key | ||
25 | B<from> to key B<to>. | ||
26 | |||
27 | The function EVP_PKEY_cmp_parameters() compares the parameters of keys | ||
28 | B<a> and B<b>. | ||
29 | |||
30 | The function EVP_PKEY_cmp() compares the public key components and parameters | ||
31 | (if present) of keys B<a> and B<b>. | ||
32 | |||
33 | =head1 NOTES | ||
34 | |||
35 | The main purpose of the functions EVP_PKEY_missing_parameters() and | ||
36 | EVP_PKEY_copy_parameters() is to handle public keys in certificates where the | ||
37 | parameters are sometimes omitted from a public key if they are inherited from | ||
38 | the CA that signed it. | ||
39 | |||
40 | Since OpenSSL private keys contain public key components too the function | ||
41 | EVP_PKEY_cmp() can also be used to determine if a private key matches | ||
42 | a public key. | ||
43 | |||
44 | =head1 RETURN VALUES | ||
45 | |||
46 | The function EVP_PKEY_missing_parameters() returns 1 if the public key | ||
47 | parameters of B<pkey> are missing and 0 if they are present or the algorithm | ||
48 | doesn't use parameters. | ||
49 | |||
50 | These functions EVP_PKEY_copy_parameters() returns 1 for success and 0 for | ||
51 | failure. | ||
52 | |||
53 | The function EVP_PKEY_cmp_parameters() and EVP_PKEY_cmp() return 1 if the | ||
54 | keys match, 0 if they don't match, -1 if the key types are different and | ||
55 | -2 if the operation is not supported. | ||
56 | |||
57 | =head1 SEE ALSO | ||
58 | |||
59 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
60 | L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> | ||
61 | |||
62 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_decrypt.pod b/src/lib/libcrypto/doc/EVP_PKEY_decrypt.pod deleted file mode 100644 index a64ef12866..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_decrypt.pod +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_decrypt_init, EVP_PKEY_decrypt - decrypt using a public key algorithm | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); | ||
12 | int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, | ||
13 | unsigned char *out, size_t *outlen, | ||
14 | const unsigned char *in, size_t inlen); | ||
15 | |||
16 | =head1 DESCRIPTION | ||
17 | |||
18 | The EVP_PKEY_decrypt_init() function initializes a public key algorithm | ||
19 | context using key B<pkey> for a decryption operation. | ||
20 | |||
21 | The EVP_PKEY_decrypt() function performs a public key decryption operation | ||
22 | using B<ctx>. The data to be decrypted is specified using the B<in> and | ||
23 | B<inlen> parameters. If B<out> is B<NULL> then the maximum size of the output | ||
24 | buffer is written to the B<outlen> parameter. If B<out> is not B<NULL> then | ||
25 | before the call the B<outlen> parameter should contain the length of the | ||
26 | B<out> buffer, if the call is successful the decrypted data is written to | ||
27 | B<out> and the amount of data written to B<outlen>. | ||
28 | |||
29 | =head1 NOTES | ||
30 | |||
31 | After the call to EVP_PKEY_decrypt_init() algorithm specific control | ||
32 | operations can be performed to set any appropriate parameters for the | ||
33 | operation. | ||
34 | |||
35 | The function EVP_PKEY_decrypt() 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_decrypt_init() and EVP_PKEY_decrypt() 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 | Decrypt data using OAEP (for RSA keys): | ||
47 | |||
48 | #include <openssl/evp.h> | ||
49 | #include <openssl/rsa.h> | ||
50 | |||
51 | EVP_PKEY_CTX *ctx; | ||
52 | unsigned char *out, *in; | ||
53 | size_t outlen, inlen; | ||
54 | EVP_PKEY *key; | ||
55 | /* NB: assumes key in, inlen are already set up | ||
56 | * and that key is an RSA private key | ||
57 | */ | ||
58 | ctx = EVP_PKEY_CTX_new(key); | ||
59 | if (!ctx) | ||
60 | /* Error occurred */ | ||
61 | if (EVP_PKEY_decrypt_init(ctx) <= 0) | ||
62 | /* Error */ | ||
63 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) | ||
64 | /* Error */ | ||
65 | |||
66 | /* Determine buffer length */ | ||
67 | if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0) | ||
68 | /* Error */ | ||
69 | |||
70 | out = malloc(outlen); | ||
71 | |||
72 | if (!out) | ||
73 | /* malloc failure */ | ||
74 | |||
75 | if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0) | ||
76 | /* Error */ | ||
77 | |||
78 | /* Decrypted data is outlen bytes written to buffer out */ | ||
79 | |||
80 | =head1 SEE ALSO | ||
81 | |||
82 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
83 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
84 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
85 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
86 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
87 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
88 | |||
89 | =head1 HISTORY | ||
90 | |||
91 | These functions were first added to OpenSSL 1.0.0. | ||
92 | |||
93 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_derive.pod b/src/lib/libcrypto/doc/EVP_PKEY_derive.pod deleted file mode 100644 index 09654e1b81..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_derive.pod +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_derive_init, EVP_PKEY_derive_set_peer, EVP_PKEY_derive - derive public | ||
6 | key algorithm shared secret. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); | ||
13 | int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); | ||
14 | int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); | ||
15 | |||
16 | =head1 DESCRIPTION | ||
17 | |||
18 | The EVP_PKEY_derive_init() function initializes a public key algorithm | ||
19 | context using key B<pkey> for shared secret derivation. | ||
20 | |||
21 | The EVP_PKEY_derive_set_peer() function sets the peer key: this will normally | ||
22 | be a public key. | ||
23 | |||
24 | The EVP_PKEY_derive() derives a shared secret using B<ctx>. | ||
25 | If B<key> is B<NULL> then the maximum size of the output buffer is written to | ||
26 | the B<keylen> parameter. If B<key> is not B<NULL> then before the call the | ||
27 | B<keylen> parameter should contain the length of the B<key> buffer, if the call | ||
28 | is successful the shared secret is written to B<key> and the amount of data | ||
29 | written to B<keylen>. | ||
30 | |||
31 | =head1 NOTES | ||
32 | |||
33 | After the call to EVP_PKEY_derive_init() algorithm specific control | ||
34 | operations can be performed to set any appropriate parameters for the | ||
35 | operation. | ||
36 | |||
37 | The function EVP_PKEY_derive() can be called more than once on the same | ||
38 | context if several operations are performed using the same parameters. | ||
39 | |||
40 | =head1 RETURN VALUES | ||
41 | |||
42 | EVP_PKEY_derive_init() and EVP_PKEY_derive() return 1 for success and 0 | ||
43 | or a negative value for failure. In particular a return value of -2 | ||
44 | indicates the operation is not supported by the public key algorithm. | ||
45 | |||
46 | =head1 EXAMPLE | ||
47 | |||
48 | Derive shared secret (for example DH or EC keys): | ||
49 | |||
50 | #include <openssl/evp.h> | ||
51 | #include <openssl/rsa.h> | ||
52 | |||
53 | EVP_PKEY_CTX *ctx; | ||
54 | unsigned char *skey; | ||
55 | size_t skeylen; | ||
56 | EVP_PKEY *pkey, *peerkey; | ||
57 | /* NB: assumes pkey, peerkey have been already set up */ | ||
58 | |||
59 | ctx = EVP_PKEY_CTX_new(pkey); | ||
60 | if (!ctx) | ||
61 | /* Error occurred */ | ||
62 | if (EVP_PKEY_derive_init(ctx) <= 0) | ||
63 | /* Error */ | ||
64 | if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0) | ||
65 | /* Error */ | ||
66 | |||
67 | /* Determine buffer length */ | ||
68 | if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0) | ||
69 | /* Error */ | ||
70 | |||
71 | skey = malloc(skeylen); | ||
72 | |||
73 | if (!skey) | ||
74 | /* malloc failure */ | ||
75 | |||
76 | if (EVP_PKEY_derive(ctx, skey, &skeylen) <= 0) | ||
77 | /* Error */ | ||
78 | |||
79 | /* Shared secret is skey bytes written to buffer skey */ | ||
80 | |||
81 | =head1 SEE ALSO | ||
82 | |||
83 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
84 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
85 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
86 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
87 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
88 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
89 | |||
90 | =head1 HISTORY | ||
91 | |||
92 | These functions were first added to OpenSSL 1.0.0. | ||
93 | |||
94 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_encrypt.pod b/src/lib/libcrypto/doc/EVP_PKEY_encrypt.pod deleted file mode 100644 index b3ca123df0..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_encrypt.pod +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_encrypt_init, EVP_PKEY_encrypt - encrypt using a public key algorithm | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); | ||
12 | int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, | ||
13 | unsigned char *out, size_t *outlen, | ||
14 | const unsigned char *in, size_t inlen); | ||
15 | |||
16 | =head1 DESCRIPTION | ||
17 | |||
18 | The EVP_PKEY_encrypt_init() function initializes a public key algorithm | ||
19 | context using key B<pkey> for an encryption operation. | ||
20 | |||
21 | The EVP_PKEY_encrypt() function performs a public key encryption operation | ||
22 | using B<ctx>. The data to be encrypted is specified using the B<in> and | ||
23 | B<inlen> parameters. If B<out> is B<NULL> then the maximum size of the output | ||
24 | buffer is written to the B<outlen> parameter. If B<out> is not B<NULL> then | ||
25 | before the call the B<outlen> parameter should contain the length of the | ||
26 | B<out> buffer, if the call is successful the encrypted data is written to | ||
27 | B<out> and the amount of data written to B<outlen>. | ||
28 | |||
29 | =head1 NOTES | ||
30 | |||
31 | After the call to EVP_PKEY_encrypt_init() algorithm specific control | ||
32 | operations can be performed to set any appropriate parameters for the | ||
33 | operation. | ||
34 | |||
35 | The function EVP_PKEY_encrypt() 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_encrypt_init() and EVP_PKEY_encrypt() 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 | Encrypt data using OAEP (for RSA keys): | ||
47 | |||
48 | #include <openssl/evp.h> | ||
49 | #include <openssl/rsa.h> | ||
50 | |||
51 | EVP_PKEY_CTX *ctx; | ||
52 | unsigned char *out, *in; | ||
53 | size_t outlen, inlen; | ||
54 | EVP_PKEY *key; | ||
55 | /* NB: assumes key in, inlen are already set up | ||
56 | * and that key is an RSA public key | ||
57 | */ | ||
58 | ctx = EVP_PKEY_CTX_new(key); | ||
59 | if (!ctx) | ||
60 | /* Error occurred */ | ||
61 | if (EVP_PKEY_encrypt_init(ctx) <= 0) | ||
62 | /* Error */ | ||
63 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) | ||
64 | /* Error */ | ||
65 | |||
66 | /* Determine buffer length */ | ||
67 | if (EVP_PKEY_encrypt(ctx, NULL, &outlen, in, inlen) <= 0) | ||
68 | /* Error */ | ||
69 | |||
70 | out = malloc(outlen); | ||
71 | |||
72 | if (!out) | ||
73 | /* malloc failure */ | ||
74 | |||
75 | if (EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen) <= 0) | ||
76 | /* Error */ | ||
77 | |||
78 | /* Encrypted data is outlen bytes written to buffer out */ | ||
79 | |||
80 | =head1 SEE ALSO | ||
81 | |||
82 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
83 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
84 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
85 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
86 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
87 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
88 | |||
89 | =head1 HISTORY | ||
90 | |||
91 | These functions were first added to OpenSSL 1.0.0. | ||
92 | |||
93 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_get_default_digest.pod b/src/lib/libcrypto/doc/EVP_PKEY_get_default_digest.pod deleted file mode 100644 index 8ff597d44a..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_get_default_digest.pod +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_get_default_digest_nid - get default signature digest | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); | ||
11 | |||
12 | =head1 DESCRIPTION | ||
13 | |||
14 | The EVP_PKEY_get_default_digest_nid() function sets B<pnid> to the default | ||
15 | message digest NID for the public key signature operations associated with key | ||
16 | B<pkey>. | ||
17 | |||
18 | =head1 NOTES | ||
19 | |||
20 | For all current standard OpenSSL public key algorithms SHA1 is returned. | ||
21 | |||
22 | =head1 RETURN VALUES | ||
23 | |||
24 | The EVP_PKEY_get_default_digest_nid() function returns 1 if the message digest | ||
25 | is advisory (that is other digests can be used) and 2 if it is mandatory (other | ||
26 | digests can not be used). It returns 0 or a negative value for failure. In | ||
27 | particular a return value of -2 indicates the operation is not supported by the | ||
28 | public key algorithm. | ||
29 | |||
30 | =head1 SEE ALSO | ||
31 | |||
32 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
33 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
34 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
35 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
36 | |||
37 | =head1 HISTORY | ||
38 | |||
39 | This function was first added to OpenSSL 1.0.0. | ||
40 | |||
41 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod b/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod deleted file mode 100644 index adcf3560e0..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_keygen_init, EVP_PKEY_keygen, EVP_PKEY_paramgen_init, | ||
6 | EVP_PKEY_paramgen, EVP_PKEY_CTX_set_cb, EVP_PKEY_CTX_get_cb, | ||
7 | EVP_PKEY_CTX_get_keygen_info, EVP_PKEY_CTX_set_app_data, | ||
8 | EVP_PKEY_CTX_get_app_data - key and parameter generation functions | ||
9 | |||
10 | =head1 SYNOPSIS | ||
11 | |||
12 | #include <openssl/evp.h> | ||
13 | |||
14 | int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); | ||
15 | int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); | ||
16 | int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); | ||
17 | int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); | ||
18 | |||
19 | typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); | ||
20 | |||
21 | void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); | ||
22 | EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); | ||
23 | |||
24 | int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); | ||
25 | |||
26 | void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); | ||
27 | void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); | ||
28 | |||
29 | =head1 DESCRIPTION | ||
30 | |||
31 | The EVP_PKEY_keygen_init() function initializes a public key algorithm | ||
32 | context using key B<pkey> for a key generation operation. | ||
33 | |||
34 | The EVP_PKEY_keygen() function performs a key generation operation, the | ||
35 | generated key is written to B<ppkey>. | ||
36 | |||
37 | The functions EVP_PKEY_paramgen_init() and EVP_PKEY_paramgen() are similar | ||
38 | except parameters are generated. | ||
39 | |||
40 | The function EVP_PKEY_set_cb() sets the key or parameter generation callback | ||
41 | to B<cb>. The function EVP_PKEY_CTX_get_cb() returns the key or parameter | ||
42 | generation callback. | ||
43 | |||
44 | The function EVP_PKEY_CTX_get_keygen_info() returns parameters associated | ||
45 | with the generation operation. If B<idx> is -1 the total number of | ||
46 | parameters available is returned. Any non negative value returns the value of | ||
47 | that parameter. EVP_PKEY_CTX_gen_keygen_info() with a non-negative value for | ||
48 | B<idx> should only be called within the generation callback. | ||
49 | |||
50 | If the callback returns 0 then the key generation operation is aborted and an | ||
51 | error occurs. This might occur during a time consuming operation where | ||
52 | a user clicks on a "cancel" button. | ||
53 | |||
54 | The functions EVP_PKEY_CTX_set_app_data() and EVP_PKEY_CTX_get_app_data() set | ||
55 | and retrieve an opaque pointer. This can be used to set some application | ||
56 | defined value which can be retrieved in the callback: for example a handle | ||
57 | which is used to update a "progress dialog". | ||
58 | |||
59 | =head1 NOTES | ||
60 | |||
61 | After the call to EVP_PKEY_keygen_init() or EVP_PKEY_paramgen_init() algorithm | ||
62 | specific control operations can be performed to set any appropriate parameters | ||
63 | for the operation. | ||
64 | |||
65 | The functions EVP_PKEY_keygen() and EVP_PKEY_paramgen() can be called more than | ||
66 | once on the same context if several operations are performed using the same | ||
67 | parameters. | ||
68 | |||
69 | The meaning of the parameters passed to the callback will depend on the | ||
70 | algorithm and the specific implementation of the algorithm. Some might not | ||
71 | give any useful information at all during key or parameter generation. Others | ||
72 | might not even call the callback. | ||
73 | |||
74 | The operation performed by key or parameter generation depends on the algorithm | ||
75 | used. In some cases (e.g. EC with a supplied named curve) the "generation" | ||
76 | option merely sets the appropriate fields in an EVP_PKEY structure. | ||
77 | |||
78 | In OpenSSL an EVP_PKEY structure containing a private key also contains the | ||
79 | public key components and parameters (if any). An OpenSSL private key is | ||
80 | equivalent to what some libraries call a "key pair". A private key can be used | ||
81 | in functions which require the use of a public key or parameters. | ||
82 | |||
83 | =head1 RETURN VALUES | ||
84 | |||
85 | EVP_PKEY_keygen_init(), EVP_PKEY_paramgen_init(), EVP_PKEY_keygen() and | ||
86 | EVP_PKEY_paramgen() return 1 for success and 0 or a negative value for failure. | ||
87 | In particular a return value of -2 indicates the operation is not supported by | ||
88 | the public key algorithm. | ||
89 | |||
90 | =head1 EXAMPLES | ||
91 | |||
92 | Generate a 2048 bit RSA key: | ||
93 | |||
94 | #include <openssl/evp.h> | ||
95 | #include <openssl/rsa.h> | ||
96 | |||
97 | EVP_PKEY_CTX *ctx; | ||
98 | EVP_PKEY *pkey = NULL; | ||
99 | ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL); | ||
100 | if (!ctx) | ||
101 | /* Error occurred */ | ||
102 | if (EVP_PKEY_keygen_init(ctx) <= 0) | ||
103 | /* Error */ | ||
104 | if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 2048) <= 0) | ||
105 | /* Error */ | ||
106 | |||
107 | /* Generate key */ | ||
108 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) | ||
109 | /* Error */ | ||
110 | |||
111 | Generate a key from a set of parameters: | ||
112 | |||
113 | #include <openssl/evp.h> | ||
114 | #include <openssl/rsa.h> | ||
115 | |||
116 | EVP_PKEY_CTX *ctx; | ||
117 | EVP_PKEY *pkey = NULL, *param; | ||
118 | /* Assumed param is set up already */ | ||
119 | ctx = EVP_PKEY_CTX_new(param); | ||
120 | if (!ctx) | ||
121 | /* Error occurred */ | ||
122 | if (EVP_PKEY_keygen_init(ctx) <= 0) | ||
123 | /* Error */ | ||
124 | |||
125 | /* Generate key */ | ||
126 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) | ||
127 | /* Error */ | ||
128 | |||
129 | Example of generation callback for OpenSSL public key implementations: | ||
130 | |||
131 | /* Application data is a BIO to output status to */ | ||
132 | |||
133 | EVP_PKEY_CTX_set_app_data(ctx, status_bio); | ||
134 | |||
135 | static int | ||
136 | genpkey_cb(EVP_PKEY_CTX *ctx) | ||
137 | { | ||
138 | char c = '*'; | ||
139 | BIO *b = EVP_PKEY_CTX_get_app_data(ctx); | ||
140 | int p; | ||
141 | |||
142 | p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); | ||
143 | if (p == 0) | ||
144 | c='.'; | ||
145 | if (p == 1) | ||
146 | c='+'; | ||
147 | if (p == 2) | ||
148 | c='*'; | ||
149 | if (p == 3) | ||
150 | c='\n'; | ||
151 | BIO_write(b,&c,1); | ||
152 | (void)BIO_flush(b); | ||
153 | return 1; | ||
154 | } | ||
155 | |||
156 | =head1 SEE ALSO | ||
157 | |||
158 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
159 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
160 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
161 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
162 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
163 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
164 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
165 | |||
166 | =head1 HISTORY | ||
167 | |||
168 | These functions were first added to OpenSSL 1.0.0. | ||
169 | |||
170 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_new.pod b/src/lib/libcrypto/doc/EVP_PKEY_new.pod deleted file mode 100644 index 7792714659..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_new.pod +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_new, EVP_PKEY_free - private key allocation functions. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | EVP_PKEY *EVP_PKEY_new(void); | ||
12 | void EVP_PKEY_free(EVP_PKEY *key); | ||
13 | |||
14 | |||
15 | =head1 DESCRIPTION | ||
16 | |||
17 | The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> | ||
18 | structure which is used by OpenSSL to store private keys. | ||
19 | |||
20 | EVP_PKEY_free() frees up the private key B<key>. | ||
21 | |||
22 | =head1 NOTES | ||
23 | |||
24 | The B<EVP_PKEY> structure is used by various OpenSSL functions | ||
25 | which require a general private key without reference to any | ||
26 | particular algorithm. | ||
27 | |||
28 | The structure returned by EVP_PKEY_new() is empty. To add a | ||
29 | private key to this empty structure the functions described in | ||
30 | L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> should be used. | ||
31 | |||
32 | =head1 RETURN VALUES | ||
33 | |||
34 | EVP_PKEY_new() returns either the newly allocated B<EVP_PKEY> | ||
35 | structure of B<NULL> if an error occurred. | ||
36 | |||
37 | EVP_PKEY_free() does not return a value. | ||
38 | |||
39 | =head1 SEE ALSO | ||
40 | |||
41 | L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> | ||
42 | |||
43 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_print_private.pod b/src/lib/libcrypto/doc/EVP_PKEY_print_private.pod deleted file mode 100644 index eabbaed264..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_print_private.pod +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_print_public, EVP_PKEY_print_private, EVP_PKEY_print_params - public | ||
6 | key algorithm printing routines. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, | ||
13 | int indent, ASN1_PCTX *pctx); | ||
14 | int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, | ||
15 | int indent, ASN1_PCTX *pctx); | ||
16 | int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, | ||
17 | int indent, ASN1_PCTX *pctx); | ||
18 | |||
19 | =head1 DESCRIPTION | ||
20 | |||
21 | The functions EVP_PKEY_print_public(), EVP_PKEY_print_private() and | ||
22 | EVP_PKEY_print_params() print out the public, private or parameter components | ||
23 | of key B<pkey> respectively. The key is sent to BIO B<out> in human readable | ||
24 | form. The parameter B<indent> indicated how far the printout should be indented. | ||
25 | |||
26 | The B<pctx> parameter allows the print output to be finely tuned by using | ||
27 | ASN1 printing options. If B<pctx> is set to NULL then default values will | ||
28 | be used. | ||
29 | |||
30 | =head1 NOTES | ||
31 | |||
32 | Currently no public key algorithms include any options in the B<pctx> parameter | ||
33 | parameter. | ||
34 | |||
35 | If the key does not include all the components indicated by the function then | ||
36 | only those contained in the key will be printed. For example passing a public | ||
37 | key to EVP_PKEY_print_private() will only print the public components. | ||
38 | |||
39 | =head1 RETURN VALUES | ||
40 | |||
41 | These functions all return 1 for success and 0 or a negative value for failure. | ||
42 | In particular a return value of -2 indicates the operation is not supported by | ||
43 | the public key algorithm. | ||
44 | |||
45 | =head1 SEE ALSO | ||
46 | |||
47 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
48 | L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)> | ||
49 | |||
50 | =head1 HISTORY | ||
51 | |||
52 | These functions were first added to OpenSSL 1.0.0. | ||
53 | |||
54 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod deleted file mode 100644 index 096e969fa3..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY, | ||
6 | EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY, | ||
7 | EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, | ||
8 | EVP_PKEY_assign_EC_KEY, EVP_PKEY_type - EVP_PKEY assignment functions. | ||
9 | |||
10 | =head1 SYNOPSIS | ||
11 | |||
12 | #include <openssl/evp.h> | ||
13 | |||
14 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key); | ||
15 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key); | ||
16 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key); | ||
17 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key); | ||
18 | |||
19 | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); | ||
20 | DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); | ||
21 | DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey); | ||
22 | EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); | ||
23 | |||
24 | int EVP_PKEY_assign_RSA(EVP_PKEY *pkey,RSA *key); | ||
25 | int EVP_PKEY_assign_DSA(EVP_PKEY *pkey,DSA *key); | ||
26 | int EVP_PKEY_assign_DH(EVP_PKEY *pkey,DH *key); | ||
27 | int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey,EC_KEY *key); | ||
28 | |||
29 | int EVP_PKEY_type(int type); | ||
30 | |||
31 | =head1 DESCRIPTION | ||
32 | |||
33 | EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and | ||
34 | EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>. | ||
35 | |||
36 | EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and | ||
37 | EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or | ||
38 | B<NULL> if the key is not of the correct type. | ||
39 | |||
40 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
41 | and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key> | ||
42 | however these use the supplied B<key> internally and so B<key> | ||
43 | will be freed when the parent B<pkey> is freed. | ||
44 | |||
45 | EVP_PKEY_type() returns the type of key corresponding to the value | ||
46 | B<type>. The type of a key can be obtained with | ||
47 | EVP_PKEY_type(pkey->type). The return value will be EVP_PKEY_RSA, | ||
48 | EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the corresponding | ||
49 | key types or NID_undef if the key type is unassigned. | ||
50 | |||
51 | =head1 NOTES | ||
52 | |||
53 | In accordance with the OpenSSL naming convention the key obtained | ||
54 | from or assigned to the B<pkey> using the B<1> functions must be | ||
55 | freed as well as B<pkey>. | ||
56 | |||
57 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
58 | EVP_PKEY_assign_EC_KEY() are implemented as macros. | ||
59 | |||
60 | =head1 RETURN VALUES | ||
61 | |||
62 | EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and | ||
63 | EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure. | ||
64 | |||
65 | EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and | ||
66 | EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if | ||
67 | an error occurred. | ||
68 | |||
69 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
70 | and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure. | ||
71 | |||
72 | =head1 SEE ALSO | ||
73 | |||
74 | L<EVP_PKEY_new(3)|EVP_PKEY_new(3)> | ||
75 | |||
76 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_sign.pod b/src/lib/libcrypto/doc/EVP_PKEY_sign.pod deleted file mode 100644 index 1925706d96..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_sign.pod +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
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 = 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_verify_recover(3)|EVP_PKEY_verify_recover(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 | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_verify.pod b/src/lib/libcrypto/doc/EVP_PKEY_verify.pod deleted file mode 100644 index 0f092ca8e1..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_verify.pod +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_verify_init, EVP_PKEY_verify - signature verification using a public | ||
6 | key algorithm | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); | ||
13 | int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, | ||
14 | const unsigned char *sig, size_t siglen, | ||
15 | const unsigned char *tbs, size_t tbslen); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | The EVP_PKEY_verify_init() function initializes a public key algorithm | ||
20 | context using key B<pkey> for a signature verification operation. | ||
21 | |||
22 | The EVP_PKEY_verify() function performs a public key verification operation | ||
23 | using B<ctx>. The signature is specified using the B<sig> and | ||
24 | B<siglen> parameters. The verified data (i.e. the data believed originally | ||
25 | signed) is specified using the B<tbs> and B<tbslen> parameters. | ||
26 | |||
27 | =head1 NOTES | ||
28 | |||
29 | After the call to EVP_PKEY_verify_init() algorithm specific control | ||
30 | operations can be performed to set any appropriate parameters for the | ||
31 | operation. | ||
32 | |||
33 | The function EVP_PKEY_verify() can be called more than once on the same | ||
34 | context if several operations are performed using the same parameters. | ||
35 | |||
36 | =head1 RETURN VALUES | ||
37 | |||
38 | EVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the verification was | ||
39 | successful and 0 if it failed. Unlike other functions the return value 0 from | ||
40 | EVP_PKEY_verify() only indicates that the signature did not verify | ||
41 | successfully (that is tbs did not match the original data or the signature was | ||
42 | of invalid form) it is not an indication of a more serious error. | ||
43 | |||
44 | A negative value indicates an error other that signature verification failure. | ||
45 | In particular a return value of -2 indicates the operation is not supported by | ||
46 | the public key algorithm. | ||
47 | |||
48 | =head1 EXAMPLE | ||
49 | |||
50 | Verify signature using PKCS#1 and SHA256 digest: | ||
51 | |||
52 | #include <openssl/evp.h> | ||
53 | #include <openssl/rsa.h> | ||
54 | |||
55 | EVP_PKEY_CTX *ctx; | ||
56 | unsigned char *md, *sig; | ||
57 | size_t mdlen, siglen; | ||
58 | EVP_PKEY *verify_key; | ||
59 | /* NB: assumes verify_key, sig, siglen md and mdlen are already set up | ||
60 | * and that verify_key is an RSA public key | ||
61 | */ | ||
62 | ctx = EVP_PKEY_CTX_new(verify_key); | ||
63 | if (!ctx) | ||
64 | /* Error occurred */ | ||
65 | if (EVP_PKEY_verify_init(ctx) <= 0) | ||
66 | /* Error */ | ||
67 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) | ||
68 | /* Error */ | ||
69 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) | ||
70 | /* Error */ | ||
71 | |||
72 | /* Perform operation */ | ||
73 | ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen); | ||
74 | |||
75 | /* ret == 1 indicates success, 0 verify failure and < 0 for some | ||
76 | * other error. | ||
77 | */ | ||
78 | |||
79 | =head1 SEE ALSO | ||
80 | |||
81 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
82 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
83 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
84 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
85 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
86 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
87 | |||
88 | =head1 HISTORY | ||
89 | |||
90 | These functions were first added to OpenSSL 1.0.0. | ||
91 | |||
92 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_verify_recover.pod b/src/lib/libcrypto/doc/EVP_PKEY_verify_recover.pod deleted file mode 100644 index 095e53ea2f..0000000000 --- a/src/lib/libcrypto/doc/EVP_PKEY_verify_recover.pod +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover - recover signature using | ||
6 | a public key algorithm | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); | ||
13 | int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, | ||
14 | unsigned char *rout, size_t *routlen, | ||
15 | const unsigned char *sig, size_t siglen); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | The EVP_PKEY_verify_recover_init() function initializes a public key algorithm | ||
20 | context using key B<pkey> for a verify recover operation. | ||
21 | |||
22 | The EVP_PKEY_verify_recover() function recovers signed data | ||
23 | using B<ctx>. The signature is specified using the B<sig> and | ||
24 | B<siglen> parameters. If B<rout> is B<NULL> then the maximum size of the output | ||
25 | buffer is written to the B<routlen> parameter. If B<rout> is not B<NULL> then | ||
26 | before the call the B<routlen> parameter should contain the length of the | ||
27 | B<rout> buffer, if the call is successful recovered data is written to | ||
28 | B<rout> and the amount of data written to B<routlen>. | ||
29 | |||
30 | =head1 NOTES | ||
31 | |||
32 | Normally an application is only interested in whether a signature verification | ||
33 | operation is successful in those cases the EVP_verify() function should be | ||
34 | used. | ||
35 | |||
36 | Sometimes however it is useful to obtain the data originally signed using a | ||
37 | signing operation. Only certain public key algorithms can recover a signature | ||
38 | in this way (for example RSA in PKCS padding mode). | ||
39 | |||
40 | After the call to EVP_PKEY_verify_recover_init() algorithm specific control | ||
41 | operations can be performed to set any appropriate parameters for the | ||
42 | operation. | ||
43 | |||
44 | The function EVP_PKEY_verify_recover() can be called more than once on the same | ||
45 | context if several operations are performed using the same parameters. | ||
46 | |||
47 | =head1 RETURN VALUES | ||
48 | |||
49 | EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1 for | ||
50 | success | ||
51 | and 0 or 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 | |||
54 | =head1 EXAMPLE | ||
55 | |||
56 | Recover digest originally signed using PKCS#1 and SHA256 digest: | ||
57 | |||
58 | #include <openssl/evp.h> | ||
59 | #include <openssl/rsa.h> | ||
60 | |||
61 | EVP_PKEY_CTX *ctx; | ||
62 | unsigned char *rout, *sig; | ||
63 | size_t routlen, siglen; | ||
64 | EVP_PKEY *verify_key; | ||
65 | /* NB: assumes verify_key, sig and siglen are already set up | ||
66 | * and that verify_key is an RSA public key | ||
67 | */ | ||
68 | ctx = EVP_PKEY_CTX_new(verify_key); | ||
69 | if (!ctx) | ||
70 | /* Error occurred */ | ||
71 | if (EVP_PKEY_verify_recover_init(ctx) <= 0) | ||
72 | /* Error */ | ||
73 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) | ||
74 | /* Error */ | ||
75 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) | ||
76 | /* Error */ | ||
77 | |||
78 | /* Determine buffer length */ | ||
79 | if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0) | ||
80 | /* Error */ | ||
81 | |||
82 | rout = malloc(routlen); | ||
83 | |||
84 | if (!rout) | ||
85 | /* malloc failure */ | ||
86 | |||
87 | if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0) | ||
88 | /* Error */ | ||
89 | |||
90 | /* Recovered data is routlen bytes written to buffer rout */ | ||
91 | |||
92 | =head1 SEE ALSO | ||
93 | |||
94 | L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, | ||
95 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
96 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
97 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
98 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
99 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
100 | |||
101 | =head1 HISTORY | ||
102 | |||
103 | These functions were first added to OpenSSL 1.0.0. | ||
104 | |||
105 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod deleted file mode 100644 index 76eebb72a9..0000000000 --- a/src/lib/libcrypto/doc/EVP_SealInit.pod +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | ||
12 | unsigned char **ek, int *ekl, unsigned char *iv, | ||
13 | EVP_PKEY **pubk, int npubk); | ||
14 | int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
15 | int *outl, unsigned char *in, int inl); | ||
16 | int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
17 | int *outl); | ||
18 | |||
19 | =head1 DESCRIPTION | ||
20 | |||
21 | The EVP envelope routines are a high level interface to envelope | ||
22 | encryption. They generate a random key and IV (if required) then | ||
23 | "envelope" it by using public key encryption. Data can then be | ||
24 | encrypted using this key. | ||
25 | |||
26 | EVP_SealInit() initializes a cipher context B<ctx> for encryption | ||
27 | with cipher B<type> using a random secret key and IV. B<type> is normally | ||
28 | supplied by a function such as EVP_aes_256_cbc(). The secret key is encrypted | ||
29 | using one or more public keys, this allows the same encrypted data to be | ||
30 | decrypted using any of the corresponding private keys. B<ek> is an array of | ||
31 | buffers where the public key encrypted secret key will be written, each buffer | ||
32 | must contain enough room for the corresponding encrypted key: that is | ||
33 | B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual | ||
34 | size of each encrypted secret key is written to the array B<ekl>. B<pubk> is | ||
35 | an array of B<npubk> public keys. | ||
36 | |||
37 | The B<iv> parameter is a buffer where the generated IV is written to. It must | ||
38 | contain enough room for the corresponding cipher's IV, as determined by (for | ||
39 | example) EVP_CIPHER_iv_length(type). | ||
40 | |||
41 | If the cipher does not require an IV then the B<iv> parameter is ignored | ||
42 | and can be B<NULL>. | ||
43 | |||
44 | EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties | ||
45 | as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as | ||
46 | documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual | ||
47 | page. | ||
48 | |||
49 | =head1 RETURN VALUES | ||
50 | |||
51 | EVP_SealInit() returns 0 on error or B<npubk> if successful. | ||
52 | |||
53 | EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for | ||
54 | failure. | ||
55 | |||
56 | =head1 NOTES | ||
57 | |||
58 | The public key must be RSA because it is the only OpenSSL public key | ||
59 | algorithm that supports key transport. | ||
60 | |||
61 | Envelope encryption is the usual method of using public key encryption | ||
62 | on large amounts of data, this is because public key encryption is slow | ||
63 | but symmetric encryption is fast. So symmetric encryption is used for | ||
64 | bulk encryption and the small random symmetric key used is transferred | ||
65 | using public key encryption. | ||
66 | |||
67 | It is possible to call EVP_SealInit() twice in the same way as | ||
68 | EVP_EncryptInit(). The first call should have B<npubk> set to 0 | ||
69 | and (after setting any cipher parameters) it should be called again | ||
70 | with B<type> set to NULL. | ||
71 | |||
72 | =head1 SEE ALSO | ||
73 | |||
74 | L<evp(3)|evp(3)>, L<rand(3)|rand(3)>, | ||
75 | L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>, | ||
76 | L<EVP_OpenInit(3)|EVP_OpenInit(3)> | ||
77 | |||
78 | =head1 HISTORY | ||
79 | |||
80 | EVP_SealFinal() did not return a value before OpenSSL 0.9.7. | ||
81 | |||
82 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_SignInit.pod b/src/lib/libcrypto/doc/EVP_SignInit.pod deleted file mode 100644 index 6882211e02..0000000000 --- a/src/lib/libcrypto/doc/EVP_SignInit.pod +++ /dev/null | |||
@@ -1,103 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_SignInit, EVP_SignUpdate, EVP_SignFinal, EVP_PKEY_size | ||
6 | - EVP signing functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); | ||
13 | int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); | ||
14 | int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey); | ||
15 | |||
16 | void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type); | ||
17 | |||
18 | int EVP_PKEY_size(EVP_PKEY *pkey); | ||
19 | |||
20 | =head1 DESCRIPTION | ||
21 | |||
22 | The EVP signature routines are a high level interface to digital | ||
23 | signatures. | ||
24 | |||
25 | EVP_SignInit_ex() sets up signing context B<ctx> to use digest | ||
26 | B<type> from ENGINE B<impl>. B<ctx> must be initialized with | ||
27 | EVP_MD_CTX_init() before calling this function. | ||
28 | |||
29 | EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the | ||
30 | signature context B<ctx>. This function can be called several times on the | ||
31 | same B<ctx> to include additional data. | ||
32 | |||
33 | EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and | ||
34 | places the signature in B<sig>. B<sig> must be at least EVP_PKEY_size(pkey) | ||
35 | bytes in size. B<s> is an OUT parameter, and not used as an IN parameter. | ||
36 | The number of bytes of data written (i.e. the length of the signature) | ||
37 | will be written to the integer at B<s>, at most EVP_PKEY_size(pkey) bytes | ||
38 | will be written. | ||
39 | |||
40 | EVP_SignInit() initializes a signing context B<ctx> to use the default | ||
41 | implementation of digest B<type>. | ||
42 | |||
43 | EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual | ||
44 | signature returned by EVP_SignFinal() may be smaller. | ||
45 | |||
46 | =head1 RETURN VALUES | ||
47 | |||
48 | EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1 | ||
49 | for success and 0 for failure. | ||
50 | |||
51 | EVP_PKEY_size() returns the maximum size of a signature in bytes. | ||
52 | |||
53 | The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | ||
54 | |||
55 | =head1 NOTES | ||
56 | |||
57 | The B<EVP> interface to digital signatures should almost always be used in | ||
58 | preference to the low level interfaces. This is because the code then becomes | ||
59 | transparent to the algorithm used and much more flexible. | ||
60 | |||
61 | Due to the link between message digests and public key algorithms the correct | ||
62 | digest algorithm must be used with the correct public key type. A list of | ||
63 | algorithms and associated public key algorithms appears in | ||
64 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>. | ||
65 | |||
66 | The call to EVP_SignFinal() internally finalizes a copy of the digest context. | ||
67 | This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called | ||
68 | later to digest and sign additional data. | ||
69 | |||
70 | Since only a copy of the digest context is ever finalized the context must | ||
71 | be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak | ||
72 | will occur. | ||
73 | |||
74 | =head1 BUGS | ||
75 | |||
76 | Older versions of this documentation wrongly stated that calls to | ||
77 | EVP_SignUpdate() could not be made after calling EVP_SignFinal(). | ||
78 | |||
79 | Since the private key is passed in the call to EVP_SignFinal() any error | ||
80 | relating to the private key (for example an unsuitable key and digest | ||
81 | combination) will not be indicated until after potentially large amounts of | ||
82 | data have been passed through EVP_SignUpdate(). | ||
83 | |||
84 | It is not possible to change the signing parameters using these function. | ||
85 | |||
86 | The previous two bugs are fixed in the newer EVP_SignDigest*() function. | ||
87 | |||
88 | =head1 SEE ALSO | ||
89 | |||
90 | L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>, | ||
91 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>, | ||
92 | L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, | ||
93 | L<md5(3)|md5(3)>, L<ripemd(3)|ripemd(3)>, | ||
94 | L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> | ||
95 | |||
96 | =head1 HISTORY | ||
97 | |||
98 | EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are | ||
99 | available in all versions of SSLeay and OpenSSL. | ||
100 | |||
101 | EVP_SignInit_ex() was added in OpenSSL 0.9.7. | ||
102 | |||
103 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_VerifyInit.pod b/src/lib/libcrypto/doc/EVP_VerifyInit.pod deleted file mode 100644 index b0d3f8e4c9..0000000000 --- a/src/lib/libcrypto/doc/EVP_VerifyInit.pod +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_VerifyInit, EVP_VerifyUpdate, EVP_VerifyFinal - EVP signature verification | ||
6 | functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/evp.h> | ||
11 | |||
12 | int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); | ||
13 | int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); | ||
14 | int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey); | ||
15 | |||
16 | int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type); | ||
17 | |||
18 | =head1 DESCRIPTION | ||
19 | |||
20 | The EVP signature verification routines are a high level interface to digital | ||
21 | signatures. | ||
22 | |||
23 | EVP_VerifyInit_ex() sets up verification context B<ctx> to use digest | ||
24 | B<type> from ENGINE B<impl>. B<ctx> must be initialized by calling | ||
25 | EVP_MD_CTX_init() before calling this function. | ||
26 | |||
27 | EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the | ||
28 | verification context B<ctx>. This function can be called several times on the | ||
29 | same B<ctx> to include additional data. | ||
30 | |||
31 | EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey> | ||
32 | and against the B<siglen> bytes at B<sigbuf>. | ||
33 | |||
34 | EVP_VerifyInit() initializes verification context B<ctx> to use the default | ||
35 | implementation of digest B<type>. | ||
36 | |||
37 | =head1 RETURN VALUES | ||
38 | |||
39 | EVP_VerifyInit_ex() and EVP_VerifyUpdate() return 1 for success and 0 for | ||
40 | failure. | ||
41 | |||
42 | EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if | ||
43 | some other error occurred. | ||
44 | |||
45 | The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | ||
46 | |||
47 | =head1 NOTES | ||
48 | |||
49 | The B<EVP> interface to digital signatures should almost always be used in | ||
50 | preference to the low level interfaces. This is because the code then becomes | ||
51 | transparent to the algorithm used and much more flexible. | ||
52 | |||
53 | Due to the link between message digests and public key algorithms the correct | ||
54 | digest algorithm must be used with the correct public key type. A list of | ||
55 | algorithms and associated public key algorithms appears in | ||
56 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>. | ||
57 | |||
58 | The call to EVP_VerifyFinal() internally finalizes a copy of the digest context. | ||
59 | This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called | ||
60 | later to digest and verify additional data. | ||
61 | |||
62 | Since only a copy of the digest context is ever finalized the context must | ||
63 | be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak | ||
64 | will occur. | ||
65 | |||
66 | =head1 BUGS | ||
67 | |||
68 | Older versions of this documentation wrongly stated that calls to | ||
69 | EVP_VerifyUpdate() could not be made after calling EVP_VerifyFinal(). | ||
70 | |||
71 | Since the public key is passed in the call to EVP_SignFinal() any error | ||
72 | relating to the private key (for example an unsuitable key and digest | ||
73 | combination) will not be indicated until after potentially large amounts of | ||
74 | data have been passed through EVP_SignUpdate(). | ||
75 | |||
76 | It is not possible to change the signing parameters using these function. | ||
77 | |||
78 | The previous two bugs are fixed in the newer EVP_VerifyDigest*() function. | ||
79 | |||
80 | =head1 SEE ALSO | ||
81 | |||
82 | L<evp(3)|evp(3)>, | ||
83 | L<EVP_SignInit(3)|EVP_SignInit(3)>, | ||
84 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>, | ||
85 | L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, | ||
86 | L<md5(3)|md5(3)>, L<ripemd(3)|ripemd(3)>, | ||
87 | L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> | ||
88 | |||
89 | =head1 HISTORY | ||
90 | |||
91 | EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are | ||
92 | available in all versions of SSLeay and OpenSSL. | ||
93 | |||
94 | EVP_VerifyInit_ex() was added in OpenSSL 0.9.7 | ||
95 | |||
96 | =cut | ||
diff --git a/src/lib/libcrypto/doc/evp.pod b/src/lib/libcrypto/doc/evp.pod deleted file mode 100644 index dfd96d3b98..0000000000 --- a/src/lib/libcrypto/doc/evp.pod +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | evp - high-level cryptographic functions | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | The EVP library provides a high-level interface to cryptographic | ||
14 | functions. | ||
15 | |||
16 | L<B<EVP_Seal>I<...>|EVP_SealInit(3)> and L<B<EVP_Open>I<...>|EVP_OpenInit(3)> | ||
17 | provide public key encryption and decryption to implement digital "envelopes". | ||
18 | |||
19 | The L<B<EVP_DigestSign>I<...>|EVP_DigestSignInit(3)> and | ||
20 | L<B<EVP_DigestVerify>I<...>|EVP_DigestVerifyInit(3)> functions implement | ||
21 | digital signatures and Message Authentication Codes (MACs). Also see the older | ||
22 | L<B<EVP_Sign>I<...>|EVP_SignInit(3)> and L<B<EVP_Verify>I<...>|EVP_VerifyInit(3)> | ||
23 | functions. | ||
24 | |||
25 | Symmetric encryption is available with the L<B<EVP_Encrypt>I<...>|EVP_EncryptInit(3)> | ||
26 | functions. The L<B<EVP_Digest>I<...>|EVP_DigestInit(3)> functions provide message digests. | ||
27 | |||
28 | Authenticated encryption with additional data (AEAD) is available with | ||
29 | the L<B<EVP_AEAD>I<...>|EVP_AEAD_CTX_init(3)> functions. | ||
30 | |||
31 | The B<EVP_PKEY>I<...> functions provide a high level interface to | ||
32 | asymmetric algorithms. To create a new EVP_PKEY see | ||
33 | L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>. EVP_PKEYs can be associated | ||
34 | with a private key of a particular algorithm by using the functions | ||
35 | described on the L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> page, or | ||
36 | new keys can be generated using L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)>. | ||
37 | EVP_PKEYs can be compared using L<EVP_PKEY_cmp(3)|EVP_PKEY_cmp(3)>, or printed using | ||
38 | L<EVP_PKEY_print_private(3)|EVP_PKEY_print_private(3)>. | ||
39 | |||
40 | The EVP_PKEY functions support the full range of asymmetric algorithm operations: | ||
41 | |||
42 | =over | ||
43 | |||
44 | =item For key agreement see L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> | ||
45 | |||
46 | =item For signing and verifying see L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
47 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)> and L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>. | ||
48 | However, note that | ||
49 | these functions do not perform a digest of the data to be signed. Therefore | ||
50 | normally you would use the L<B<EVP_DigestSign>I<...>|EVP_DigestSignInit(3)> | ||
51 | functions for this purpose. | ||
52 | |||
53 | =item For encryption and decryption see L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)> | ||
54 | and L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)> respectively. However, note that | ||
55 | these functions perform encryption and decryption only. As public key | ||
56 | encryption is an expensive operation, normally you would wrap | ||
57 | an encrypted message in a "digital envelope" using the L<B<EVP_Seal>I<...>|EVP_SealInit(3)> and | ||
58 | L<B<EVP_Open>I<...>|EVP_OpenInit(3)> functions. | ||
59 | |||
60 | =back | ||
61 | |||
62 | The L<EVP_BytesToKey(3)|EVP_BytesToKey(3)> function provides some limited support for password | ||
63 | based encryption. Careful selection of the parameters will provide a PKCS#5 PBKDF1 compatible | ||
64 | implementation. However, new applications should not typically use this (preferring, for example, | ||
65 | PBKDF2 from PCKS#5). | ||
66 | |||
67 | Algorithms are loaded with L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>. | ||
68 | |||
69 | All the symmetric algorithms (ciphers), digests and asymmetric algorithms | ||
70 | (public key algorithms) can be replaced by L<ENGINE|engine(3)> modules providing alternative | ||
71 | implementations. If ENGINE implementations of ciphers or digests are registered | ||
72 | as defaults, then the various EVP functions will automatically use those | ||
73 | implementations automatically in preference to built in software | ||
74 | implementations. For more information, consult the engine(3) man page. | ||
75 | |||
76 | Although low level algorithm specific functions exist for many algorithms | ||
77 | their use is discouraged. They cannot be used with an ENGINE and ENGINE | ||
78 | versions of new algorithms cannot be accessed using the low level functions. | ||
79 | Also makes code harder to adapt to new algorithms and some options are not | ||
80 | cleanly supported at the low level and some operations are more efficient | ||
81 | using the high level interface. | ||
82 | |||
83 | =head1 SEE ALSO | ||
84 | |||
85 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, | ||
86 | L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>, | ||
87 | L<EVP_AEAD_CTX_init(3)|EVP_AEAD_CTX_init(3)>, | ||
88 | L<EVP_OpenInit(3)|EVP_OpenInit(3)>, | ||
89 | L<EVP_SealInit(3)|EVP_SealInit(3)>, | ||
90 | L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>, | ||
91 | L<EVP_SignInit(3)|EVP_SignInit(3)>, | ||
92 | L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>, | ||
93 | L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>, | ||
94 | L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)>, | ||
95 | L<EVP_PKEY_keygen(3)|EVP_PKEY_keygen(3)>, | ||
96 | L<EVP_PKEY_print_private(3)|EVP_PKEY_print_private(3)>, | ||
97 | L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, | ||
98 | L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, | ||
99 | L<EVP_PKEY_sign(3)|EVP_PKEY_sign(3)>, | ||
100 | L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, | ||
101 | L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, | ||
102 | L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)>, | ||
103 | L<EVP_BytesToKey(3)|EVP_BytesToKey(3)>, | ||
104 | L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>, | ||
105 | L<engine(3)|engine(3)> | ||
106 | |||
107 | =cut | ||
diff --git a/src/lib/libcrypto/man/EVP_BytesToKey.3 b/src/lib/libcrypto/man/EVP_BytesToKey.3 new file mode 100644 index 0000000000..45a3d9bf33 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_BytesToKey.3 | |||
@@ -0,0 +1,82 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_BYTESTOKEY 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_BytesToKey | ||
6 | .Nd password based encryption routine | ||
7 | .Sh SYNOPSIS | ||
8 | .In openssl/evp.h | ||
9 | .Ft int | ||
10 | .Fo EVP_BytesToKey | ||
11 | .Fa "const EVP_CIPHER *type" | ||
12 | .Fa "const EVP_MD *md" | ||
13 | .Fa "const unsigned char *salt" | ||
14 | .Fa "const unsigned char *data" | ||
15 | .Fa "int datal" | ||
16 | .Fa "int count" | ||
17 | .Fa "unsigned char *key" | ||
18 | .Fa "unsigned char *iv" | ||
19 | .Fc | ||
20 | .Sh DESCRIPTION | ||
21 | .Fn EVP_BytesToKey | ||
22 | derives a key and IV from various parameters. | ||
23 | .Fa type | ||
24 | is the cipher to derive the key and IV for. | ||
25 | .Fa md | ||
26 | is the message digest to use. | ||
27 | The | ||
28 | .Fa salt | ||
29 | parameter is used as a salt in the derivation: it should point to an 8 | ||
30 | byte buffer or | ||
31 | .Dv NULL | ||
32 | if no salt is used. | ||
33 | .Fa data | ||
34 | is a buffer containing | ||
35 | .Fa datal | ||
36 | bytes which is used to derive the keying data. | ||
37 | .Fa count | ||
38 | is the iteration count to use. | ||
39 | The derived key and IV will be written to | ||
40 | .Fa key | ||
41 | and | ||
42 | .Fa iv , | ||
43 | respectively. | ||
44 | .Pp | ||
45 | A typical application of this function is to derive keying material for | ||
46 | an encryption algorithm from a password in the | ||
47 | .Fa data | ||
48 | parameter. | ||
49 | .Pp | ||
50 | Increasing the | ||
51 | .Fa count | ||
52 | parameter slows down the algorithm which makes it harder for an attacker | ||
53 | to perform a brute force attack using a large number of candidate | ||
54 | passwords. | ||
55 | .Pp | ||
56 | If the total key and IV length is less than the digest length and MD5 | ||
57 | is used, then the derivation algorithm is compatible with PKCS#5 v1.5. | ||
58 | Otherwise, a non standard extension is used to derive the extra data. | ||
59 | .Pp | ||
60 | Newer applications should use more standard algorithms such as PBKDF2 as | ||
61 | defined in PKCS#5v2.1 for key derivation. | ||
62 | .Sh KEY DERIVATION ALGORITHM | ||
63 | The key and IV is derived by concatenating D_1, D_2, etc until enough | ||
64 | data is available for the key and IV. | ||
65 | D_i is defined recursively as: | ||
66 | .Pp | ||
67 | .Dl D_i = HASH^count(D_(i-1) || data || salt) | ||
68 | .Pp | ||
69 | where || denotes concatenation, D_0 is empty, HASH is the digest | ||
70 | algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data) is | ||
71 | HASH(HASH(data)) and so on. | ||
72 | .Pp | ||
73 | The initial bytes are used for the key and the subsequent bytes for the | ||
74 | IV. | ||
75 | .Sh RETURN VALUES | ||
76 | .Fn EVP_BytesToKey | ||
77 | returns the size of the derived key in bytes. | ||
78 | .Sh SEE ALSO | ||
79 | .Xr evp 3 , | ||
80 | .Xr EVP_EncryptInit 3 , | ||
81 | .Xr PKCS5_PBKDF2_HMAC 3 , | ||
82 | .Xr rand 3 | ||
diff --git a/src/lib/libcrypto/man/EVP_DigestInit.3 b/src/lib/libcrypto/man/EVP_DigestInit.3 new file mode 100644 index 0000000000..9bcf79241c --- /dev/null +++ b/src/lib/libcrypto/man/EVP_DigestInit.3 | |||
@@ -0,0 +1,520 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_DIGESTINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_MD_CTX_init , | ||
6 | .Nm EVP_MD_CTX_create , | ||
7 | .Nm EVP_DigestInit_ex , | ||
8 | .Nm EVP_DigestUpdate , | ||
9 | .Nm EVP_DigestFinal_ex , | ||
10 | .Nm EVP_MD_CTX_cleanup , | ||
11 | .Nm EVP_MD_CTX_destroy , | ||
12 | .Nm EVP_MAX_MD_SIZE , | ||
13 | .Nm EVP_MD_CTX_copy_ex , | ||
14 | .Nm EVP_MD_CTX_copy , | ||
15 | .Nm EVP_MD_type , | ||
16 | .Nm EVP_MD_pkey_type , | ||
17 | .Nm EVP_MD_size , | ||
18 | .Nm EVP_MD_block_size , | ||
19 | .Nm EVP_MD_CTX_md , | ||
20 | .Nm EVP_MD_CTX_size , | ||
21 | .Nm EVP_MD_CTX_block_size , | ||
22 | .Nm EVP_MD_CTX_type , | ||
23 | .Nm EVP_md_null , | ||
24 | .Nm EVP_md2 , | ||
25 | .Nm EVP_md5 , | ||
26 | .Nm EVP_sha1 , | ||
27 | .Nm EVP_sha224 , | ||
28 | .Nm EVP_sha256 , | ||
29 | .Nm EVP_sha384 , | ||
30 | .Nm EVP_sha512 , | ||
31 | .Nm EVP_dss , | ||
32 | .Nm EVP_dss1 , | ||
33 | .Nm EVP_ripemd160 , | ||
34 | .Nm EVP_get_digestbyname , | ||
35 | .Nm EVP_get_digestbynid , | ||
36 | .Nm EVP_get_digestbyobj , | ||
37 | .Nm EVP_DigestInit , | ||
38 | .Nm EVP_DigestFinal | ||
39 | .Nd EVP digest routines | ||
40 | .Sh SYNOPSIS | ||
41 | .In openssl/evp.h | ||
42 | .Ft void | ||
43 | .Fo EVP_MD_CTX_init | ||
44 | .Fa "EVP_MD_CTX *ctx" | ||
45 | .Fc | ||
46 | .Ft EVP_MD_CTX * | ||
47 | .Fn EVP_MD_CTX_create void | ||
48 | .Ft int | ||
49 | .Fo EVP_DigestInit_ex | ||
50 | .Fa "EVP_MD_CTX *ctx" | ||
51 | .Fa "const EVP_MD *type" | ||
52 | .Fa "ENGINE *impl" | ||
53 | .Fc | ||
54 | .Ft int | ||
55 | .Fo EVP_DigestUpdate | ||
56 | .Fa "EVP_MD_CTX *ctx" | ||
57 | .Fa "const void *d" | ||
58 | .Fa "size_t cnt" | ||
59 | .Fc | ||
60 | .Ft int | ||
61 | .Fo EVP_DigestFinal_ex | ||
62 | .Fa "EVP_MD_CTX *ctx" | ||
63 | .Fa "unsigned char *md" | ||
64 | .Fa "unsigned int *s" | ||
65 | .Fc | ||
66 | .Ft int | ||
67 | .Fo EVP_MD_CTX_cleanup | ||
68 | .Fa "EVP_MD_CTX *ctx" | ||
69 | .Fc | ||
70 | .Ft void | ||
71 | .Fo EVP_MD_CTX_destroy | ||
72 | .Fa "EVP_MD_CTX *ctx" | ||
73 | .Fc | ||
74 | .Ft int | ||
75 | .Fo EVP_MD_CTX_copy_ex | ||
76 | .Fa "EVP_MD_CTX *out" | ||
77 | .Fa "const EVP_MD_CTX *in" | ||
78 | .Fc | ||
79 | .Ft int | ||
80 | .Fo EVP_DigestInit | ||
81 | .Fa "EVP_MD_CTX *ctx" | ||
82 | .Fa "const EVP_MD *type" | ||
83 | .Fc | ||
84 | .Ft int | ||
85 | .Fo EVP_DigestFinal | ||
86 | .Fa "EVP_MD_CTX *ctx" | ||
87 | .Fa "unsigned char *md" | ||
88 | .Fa "unsigned int *s" | ||
89 | .Fc | ||
90 | .Ft int | ||
91 | .Fo EVP_MD_CTX_copy | ||
92 | .Fa "EVP_MD_CTX *out" | ||
93 | .Fa "EVP_MD_CTX *in" | ||
94 | .Fc | ||
95 | .Fd #define EVP_MAX_MD_SIZE 64 /* SHA512 */ | ||
96 | .Ft int | ||
97 | .Fo EVP_MD_type | ||
98 | .Fa "const EVP_MD *md" | ||
99 | .Fc | ||
100 | .Ft int | ||
101 | .Fo EVP_MD_pkey_type | ||
102 | .Fa "const EVP_MD *md" | ||
103 | .Fc | ||
104 | .Ft int | ||
105 | .Fo EVP_MD_size | ||
106 | .Fa "const EVP_MD *md" | ||
107 | .Fc | ||
108 | .Ft int | ||
109 | .Fo EVP_MD_block_size | ||
110 | .Fa "const EVP_MD *md" | ||
111 | .Fc | ||
112 | .Ft const EVP_MD * | ||
113 | .Fo EVP_MD_CTX_md | ||
114 | .Fa "const EVP_MD_CTX *ctx" | ||
115 | .Fc | ||
116 | .Fd #define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) | ||
117 | .Fd #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
118 | .Fd #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | ||
119 | .Ft const EVP_MD * | ||
120 | .Fn EVP_md_null void | ||
121 | .Ft const EVP_MD * | ||
122 | .Fn EVP_md2 void | ||
123 | .Ft const EVP_MD * | ||
124 | .Fn EVP_md5 void | ||
125 | .Ft const EVP_MD * | ||
126 | .Fn EVP_sha1 void | ||
127 | .Ft const EVP_MD * | ||
128 | .Fn EVP_dss void | ||
129 | .Ft const EVP_MD * | ||
130 | .Fn EVP_dss1 void | ||
131 | .Ft const EVP_MD * | ||
132 | .Fn EVP_ripemd160 void | ||
133 | .Ft const EVP_MD * | ||
134 | .Fn EVP_sha224 void | ||
135 | .Ft const EVP_MD * | ||
136 | .Fn EVP_sha256 void | ||
137 | .Ft const EVP_MD * | ||
138 | .Fn EVP_sha384 void | ||
139 | .Ft const EVP_MD * | ||
140 | .Fn EVP_sha512 void | ||
141 | .Ft const EVP_MD * | ||
142 | .Fo EVP_get_digestbyname | ||
143 | .Fa "const char *name" | ||
144 | .Fc | ||
145 | .Fd #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
146 | .Fd #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
147 | .Sh DESCRIPTION | ||
148 | The EVP digest routines are a high level interface to message digests. | ||
149 | .Pp | ||
150 | .Fn EVP_MD_CTX_init | ||
151 | initializes the digest context | ||
152 | .Fa ctx . | ||
153 | .Pp | ||
154 | .Fn EVP_MD_CTX_create | ||
155 | allocates, initializes, and returns a digest context. | ||
156 | .Pp | ||
157 | .Fn EVP_DigestInit_ex | ||
158 | sets up digest context | ||
159 | .Fa ctx | ||
160 | to use a digest | ||
161 | .Fa type | ||
162 | from | ||
163 | .Vt ENGINE | ||
164 | .Fa impl . | ||
165 | .Fa ctx | ||
166 | must be initialized before calling this function. | ||
167 | .Fa type | ||
168 | will typically be supplied by a function such as | ||
169 | .Fn EVP_sha1 . | ||
170 | If | ||
171 | .Fa impl | ||
172 | is | ||
173 | .Dv NULL , | ||
174 | then the default implementation of digest | ||
175 | .Fa type | ||
176 | is used. | ||
177 | .Pp | ||
178 | .Fn EVP_DigestUpdate | ||
179 | hashes | ||
180 | .Fa cnt | ||
181 | bytes of data at | ||
182 | .Fa d | ||
183 | into the digest context | ||
184 | .Fa ctx . | ||
185 | This function can be called several times on the same | ||
186 | .Fa ctx | ||
187 | to hash additional data. | ||
188 | .Pp | ||
189 | .Fn EVP_DigestFinal_ex | ||
190 | retrieves the digest value from | ||
191 | .Fa ctx | ||
192 | and places it in | ||
193 | .Fa md . | ||
194 | If the | ||
195 | .Fa s | ||
196 | parameter is not | ||
197 | .Dv NULL , | ||
198 | then the number of bytes of data written (i.e. the length of the | ||
199 | digest) will be written to the integer at | ||
200 | .Fa s , | ||
201 | at most | ||
202 | .Dv EVP_MAX_MD_SIZE | ||
203 | bytes will be written. | ||
204 | After calling | ||
205 | .Fn EVP_DigestFinal_ex , | ||
206 | no additional calls to | ||
207 | .Fn EVP_DigestUpdate | ||
208 | can be made, but | ||
209 | .Fn EVP_DigestInit_ex | ||
210 | can be called to initialize a new digest operation. | ||
211 | .Pp | ||
212 | .Fn EVP_MD_CTX_cleanup | ||
213 | cleans up the digest context | ||
214 | .Fa ctx . | ||
215 | It should be called after a digest context is no longer needed. | ||
216 | .Pp | ||
217 | .Fn EVP_MD_CTX_destroy | ||
218 | cleans up the digest context | ||
219 | .Fa ctx | ||
220 | and frees up the space allocated to it. | ||
221 | It should be called only on a context created using | ||
222 | .Fn EVP_MD_CTX_create . | ||
223 | .Pp | ||
224 | .Fn EVP_MD_CTX_copy_ex | ||
225 | can be used to copy the message digest state from | ||
226 | .Fa in | ||
227 | to | ||
228 | .Fa out . | ||
229 | This is useful if large amounts of data are to be hashed which only | ||
230 | differ in the last few bytes. | ||
231 | .Fa out | ||
232 | must be initialized before calling this function. | ||
233 | .Pp | ||
234 | .Fn EVP_DigestInit | ||
235 | behaves in the same way as | ||
236 | .Fn EVP_DigestInit_ex | ||
237 | except the passed context | ||
238 | .Fa ctx | ||
239 | does not have to be initialized, and it always uses the default digest | ||
240 | implementation. | ||
241 | .Pp | ||
242 | .Fn EVP_DigestFinal | ||
243 | is similar to | ||
244 | .Fn EVP_DigestFinal_ex | ||
245 | except the digest context | ||
246 | .Fa ctx | ||
247 | is automatically cleaned up. | ||
248 | .Pp | ||
249 | .Fn EVP_MD_CTX_copy | ||
250 | is similar to | ||
251 | .Fn EVP_MD_CTX_copy_ex | ||
252 | except the destination | ||
253 | .Fa out | ||
254 | does not have to be initialized. | ||
255 | .Pp | ||
256 | .Fn EVP_MD_size | ||
257 | and | ||
258 | .Fn EVP_MD_CTX_size | ||
259 | return the size of the message digest when passed an | ||
260 | .Vt EVP_MD | ||
261 | or an | ||
262 | .Vt EVP_MD_CTX | ||
263 | structure, i.e. the size of the hash. | ||
264 | .Pp | ||
265 | .Fn EVP_MD_block_size | ||
266 | and | ||
267 | .Fn EVP_MD_CTX_block_size | ||
268 | return the block size of the message digest when passed an | ||
269 | .Vt EVP_MD | ||
270 | or an | ||
271 | .Vt EVP_MD_CTX | ||
272 | structure. | ||
273 | .Pp | ||
274 | .Fn EVP_MD_type | ||
275 | and | ||
276 | .Fn EVP_MD_CTX_type | ||
277 | return the NID of the OBJECT IDENTIFIER representing the given message | ||
278 | digest when passed an | ||
279 | .Vt EVP_MD | ||
280 | structure. | ||
281 | For example | ||
282 | .Fn EVP_MD_type EVP_sha1() | ||
283 | returns | ||
284 | .Dv NID_sha1 . | ||
285 | This function is normally used when setting ASN1 OIDs. | ||
286 | .Pp | ||
287 | .Fn EVP_MD_CTX_md | ||
288 | returns the | ||
289 | .Vt EVP_MD | ||
290 | structure corresponding to the passed | ||
291 | .Vt EVP_MD_CTX . | ||
292 | .Pp | ||
293 | .Fn EVP_MD_pkey_type | ||
294 | returns the NID of the public key signing algorithm associated with this | ||
295 | digest. | ||
296 | For example | ||
297 | .Fn EVP_sha1 | ||
298 | is associated with RSA so this will return | ||
299 | .Dv NID_sha1WithRSAEncryption . | ||
300 | Since digests and signature algorithms are no longer linked this | ||
301 | function is only retained for compatibility reasons. | ||
302 | .Pp | ||
303 | .Fn EVP_md2 , | ||
304 | .Fn EVP_md5 , | ||
305 | .Fn EVP_sha1 , | ||
306 | .Fn EVP_sha224 , | ||
307 | .Fn EVP_sha256 , | ||
308 | .Fn EVP_sha384 , | ||
309 | .Fn EVP_sha512 , | ||
310 | and | ||
311 | .Fn EVP_ripemd160 | ||
312 | return | ||
313 | .Vt EVP_MD | ||
314 | structures for the MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512 and | ||
315 | RIPEMD160 digest algorithms respectively. | ||
316 | .Pp | ||
317 | .Fn EVP_dss | ||
318 | and | ||
319 | .Fn EVP_dss1 | ||
320 | return | ||
321 | .Vt EVP_MD | ||
322 | structures for SHA1 digest algorithms but using DSS (DSA) for the | ||
323 | signature algorithm. | ||
324 | Note: there is no need to use these pseudo-digests in OpenSSL 1.0.0 and | ||
325 | later, they are however retained for compatibility. | ||
326 | .Pp | ||
327 | .Fn EVP_md_null | ||
328 | is a "null" message digest that does nothing: | ||
329 | i.e. the hash it returns is of zero length. | ||
330 | .Pp | ||
331 | .Fn EVP_get_digestbyname , | ||
332 | .Fn EVP_get_digestbynid , | ||
333 | and | ||
334 | .Fn EVP_get_digestbyobj | ||
335 | return an | ||
336 | .Vt EVP_MD | ||
337 | structure when passed a digest name, a digest NID, or an ASN1_OBJECT | ||
338 | structure respectively. | ||
339 | The digest table must be initialized using, for example, | ||
340 | .Xr OpenSSL_add_all_digests 3 | ||
341 | for these functions to work. | ||
342 | .Pp | ||
343 | The EVP interface to message digests should almost always be used | ||
344 | in preference to the low level interfaces. | ||
345 | This is because the code then becomes transparent to the digest used and | ||
346 | much more flexible. | ||
347 | .Pp | ||
348 | New applications should use the SHA2 digest algorithms such as SHA256. | ||
349 | The other digest algorithms are still in common use. | ||
350 | .Pp | ||
351 | For most applications the | ||
352 | .Fa impl | ||
353 | parameter to | ||
354 | .Fn EVP_DigestInit_ex | ||
355 | will be set to NULL to use the default digest implementation. | ||
356 | .Pp | ||
357 | The functions | ||
358 | .Fn EVP_DigestInit , | ||
359 | .Fn EVP_DigestFinal , | ||
360 | and | ||
361 | .Fn EVP_MD_CTX_copy | ||
362 | are obsolete but are retained to maintain compatibility with existing | ||
363 | code. | ||
364 | New applications should use | ||
365 | .Fn EVP_DigestInit_ex , | ||
366 | .Fn EVP_DigestFinal_ex , | ||
367 | and | ||
368 | .Fn EVP_MD_CTX_copy_ex | ||
369 | because they can efficiently reuse a digest context instead of | ||
370 | initializing and cleaning it up on each call and allow non default | ||
371 | implementations of digests to be specified. | ||
372 | .Pp | ||
373 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after | ||
374 | use memory leaks will occur. | ||
375 | .Pp | ||
376 | Stack allocation of | ||
377 | .Vt EVP_MD_CTX | ||
378 | structures is common, for example: | ||
379 | .Bd -literal -offset indent | ||
380 | EVP_MD_CTX mctx; | ||
381 | EVP_MD_CTX_init(&mctx); | ||
382 | .Ed | ||
383 | .Pp | ||
384 | This will cause binary compatibility issues if the size of | ||
385 | .Vt EVP_MD_CTX | ||
386 | structure changes (this will only happen with a major release of OpenSSL). | ||
387 | Applications wishing to avoid this should use | ||
388 | .Fn EVP_MD_CTX_create | ||
389 | instead: | ||
390 | .Bd -literal -offset indent | ||
391 | EVP_MD_CTX *mctx; | ||
392 | mctx = EVP_MD_CTX_create(); | ||
393 | .Ed | ||
394 | .Sh RETURN VALUES | ||
395 | .Fn EVP_DigestInit_ex , | ||
396 | .Fn EVP_DigestUpdate , | ||
397 | .Fn EVP_DigestFinal_ex , | ||
398 | and | ||
399 | .Fn EVP_MD_CTX_copy_ex | ||
400 | return 1 for success or 0 for failure. | ||
401 | .Pp | ||
402 | .Fn EVP_MD_type , | ||
403 | .Fn EVP_MD_pkey_type , | ||
404 | and | ||
405 | .Fn EVP_MD_type | ||
406 | return the NID of the corresponding OBJECT IDENTIFIER or | ||
407 | .Dv NID_undef | ||
408 | if none exists. | ||
409 | .Pp | ||
410 | .Fn EVP_MD_size , | ||
411 | .Fn EVP_MD_block_size , | ||
412 | .Fn EVP_MD_CTX_size , | ||
413 | and | ||
414 | .Fn EVP_MD_CTX_block_size | ||
415 | return the digest or block size in bytes. | ||
416 | .Pp | ||
417 | .Fn EVP_md_null , | ||
418 | .Fn EVP_md2 , | ||
419 | .Fn EVP_md5 , | ||
420 | .Fn EVP_sha1 , | ||
421 | .Fn EVP_dss , | ||
422 | .Fn EVP_dss1 , | ||
423 | and | ||
424 | .Fn EVP_ripemd160 | ||
425 | return pointers to the corresponding | ||
426 | .Vt EVP_MD | ||
427 | structures. | ||
428 | .Pp | ||
429 | .Fn EVP_get_digestbyname , | ||
430 | .Fn EVP_get_digestbynid , | ||
431 | and | ||
432 | .Fn EVP_get_digestbyobj | ||
433 | return either an | ||
434 | .Vt EVP_MD | ||
435 | structure or | ||
436 | .Dv NULL | ||
437 | if an error occurs. | ||
438 | .Sh EXAMPLES | ||
439 | This example digests the data "Test Message\en" and "Hello World\en", | ||
440 | using the digest name passed on the command line. | ||
441 | .Bd -literal | ||
442 | #include <stdio.h> | ||
443 | #include <openssl/evp.h> | ||
444 | |||
445 | int | ||
446 | main(int argc, char *argv[]) | ||
447 | { | ||
448 | EVP_MD_CTX *mdctx; | ||
449 | const EVP_MD *md; | ||
450 | const char mess1[] = "Test Message\en"; | ||
451 | const char mess2[] = "Hello World\en"; | ||
452 | unsigned char md_value[EVP_MAX_MD_SIZE]; | ||
453 | int md_len, i; | ||
454 | |||
455 | OpenSSL_add_all_digests(); | ||
456 | |||
457 | if (argc <= 1) { | ||
458 | printf("Usage: mdtest digestname\en"); | ||
459 | exit(1); | ||
460 | } | ||
461 | |||
462 | md = EVP_get_digestbyname(argv[1]); | ||
463 | if (md == NULL) { | ||
464 | printf("Unknown message digest %s\en", argv[1]); | ||
465 | exit(1); | ||
466 | } | ||
467 | |||
468 | mdctx = EVP_MD_CTX_create(); | ||
469 | EVP_DigestInit_ex(mdctx, md, NULL); | ||
470 | EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); | ||
471 | EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); | ||
472 | EVP_DigestFinal_ex(mdctx, md_value, &md_len); | ||
473 | EVP_MD_CTX_destroy(mdctx); | ||
474 | |||
475 | printf("Digest is: "); | ||
476 | for(i = 0; i < md_len; i++) | ||
477 | printf("%02x", md_value[i]); | ||
478 | printf("\en"); | ||
479 | } | ||
480 | .Ed | ||
481 | .Sh SEE ALSO | ||
482 | .Xr evp 3 | ||
483 | .Sh HISTORY | ||
484 | .Fn EVP_DigestInit , | ||
485 | .Fn EVP_DigestUpdate , | ||
486 | and | ||
487 | .Fn EVP_DigestFinal | ||
488 | are available in all versions of SSLeay and OpenSSL. | ||
489 | .Pp | ||
490 | .Fn EVP_MD_CTX_init , | ||
491 | .Fn EVP_MD_CTX_create , | ||
492 | .Fn EVP_MD_CTX_copy_ex , | ||
493 | .Fn EVP_MD_CTX_cleanup , | ||
494 | .Fn EVP_MD_CTX_destroy , | ||
495 | .Fn EVP_DigestInit_ex , | ||
496 | and | ||
497 | .Fn EVP_DigestFinal_ex | ||
498 | were added in OpenSSL 0.9.7. | ||
499 | .Pp | ||
500 | .Fn EVP_md_null , | ||
501 | .Fn EVP_md2 , | ||
502 | .Fn EVP_md5 , | ||
503 | .Fn EVP_sha1 , | ||
504 | .Fn EVP_dss , | ||
505 | .Fn EVP_dss1 , | ||
506 | and | ||
507 | .Fn EVP_ripemd160 | ||
508 | were changed to return truely const | ||
509 | .Vt EVP_MD | ||
510 | pointers in OpenSSL 0.9.7. | ||
511 | .Pp | ||
512 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 | ||
513 | and later, so now | ||
514 | .Fn EVP_sha1 | ||
515 | can be used with RSA and DSA, there is no need to use | ||
516 | .Fn EVP_dss1 | ||
517 | any more. | ||
518 | .Pp | ||
519 | OpenSSL 1.0 and later does not include the MD2 digest algorithm in the | ||
520 | default configuration due to its security weaknesses. | ||
diff --git a/src/lib/libcrypto/man/EVP_DigestSignInit.3 b/src/lib/libcrypto/man/EVP_DigestSignInit.3 new file mode 100644 index 0000000000..89a2d7afbd --- /dev/null +++ b/src/lib/libcrypto/man/EVP_DigestSignInit.3 | |||
@@ -0,0 +1,152 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_DIGESTSIGNINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_DigestSignInit , | ||
6 | .Nm EVP_DigestSignUpdate , | ||
7 | .Nm EVP_DigestSignFinal | ||
8 | .Nd EVP signing functions | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_DigestSignInit | ||
13 | .Fa "EVP_MD_CTX *ctx" | ||
14 | .Fa "EVP_PKEY_CTX **pctx" | ||
15 | .Fa "const EVP_MD *type" | ||
16 | .Fa "ENGINE *e" | ||
17 | .Fa "EVP_PKEY *pkey" | ||
18 | .Fc | ||
19 | .Ft int | ||
20 | .Fo EVP_DigestSignUpdate | ||
21 | .Fa "EVP_MD_CTX *ctx" | ||
22 | .Fa "const void *d" | ||
23 | .Fa "unsigned int cnt" | ||
24 | .Fc | ||
25 | .Ft int | ||
26 | .Fo EVP_DigestSignFinal | ||
27 | .Fa "EVP_MD_CTX *ctx" | ||
28 | .Fa "unsigned char *sig" | ||
29 | .Fa "size_t *siglen" | ||
30 | .Fc | ||
31 | .Sh DESCRIPTION | ||
32 | The EVP signature routines are a high level interface to digital | ||
33 | signatures. | ||
34 | .Pp | ||
35 | .Fn EVP_DigestSignInit | ||
36 | sets up the signing context | ||
37 | .Fa ctx | ||
38 | to use the digest | ||
39 | .Fa type | ||
40 | from | ||
41 | .Vt ENGINE | ||
42 | .Fa e | ||
43 | and private key | ||
44 | .Fa pkey . | ||
45 | .Fa ctx | ||
46 | must be initialized with | ||
47 | .Xr EVP_MD_CTX_init 3 | ||
48 | before calling this function. | ||
49 | If | ||
50 | .Fa pctx | ||
51 | is not | ||
52 | .Dv NULL , | ||
53 | the | ||
54 | .Vt EVP_PKEY_CTX | ||
55 | of the signing operation will be written to | ||
56 | .Pf * Fa pctx : | ||
57 | this can be used to set alternative signing options. | ||
58 | .Pp | ||
59 | .Fn EVP_DigestSignUpdate | ||
60 | hashes | ||
61 | .Fa cnt | ||
62 | bytes of data at | ||
63 | .Fa d | ||
64 | into the signature context | ||
65 | .Fa ctx . | ||
66 | This function can be called several times on the same | ||
67 | .Fa ctx | ||
68 | to include additional data. | ||
69 | This function is currently implemented using a macro. | ||
70 | .Pp | ||
71 | .Fn EVP_DigestSignFinal | ||
72 | signs the data in | ||
73 | .Fa ctx | ||
74 | and places the signature in | ||
75 | .Fa sig . | ||
76 | If | ||
77 | .Fa sig | ||
78 | is | ||
79 | .Dv NULL , | ||
80 | then the maximum size of the output buffer is written to | ||
81 | .Pf * Fa siglen . | ||
82 | If | ||
83 | .Fa sig | ||
84 | is not | ||
85 | .Dv NULL , | ||
86 | then before the call | ||
87 | .Fa siglen | ||
88 | should contain the length of the | ||
89 | .Fa sig | ||
90 | buffer. | ||
91 | If the call is successful, the signature is written to | ||
92 | .Fa sig | ||
93 | and the amount of data written to | ||
94 | .Fa siglen . | ||
95 | .Pp | ||
96 | The EVP interface to digital signatures should almost always be | ||
97 | used in preference to the low level interfaces. | ||
98 | This is because the code then becomes transparent to the algorithm used | ||
99 | and much more flexible. | ||
100 | .Pp | ||
101 | In previous versions of OpenSSL, there was a link between message digest | ||
102 | types and public key algorithms. | ||
103 | This meant that "clone" digests such as | ||
104 | .Xr EVP_dss1 3 | ||
105 | needed to be used to sign using SHA1 and DSA. | ||
106 | This is no longer necessary and the use of clone digest is now | ||
107 | discouraged. | ||
108 | .Pp | ||
109 | The call to | ||
110 | .Fn EVP_DigestSignFinal | ||
111 | internally finalizes a copy of the digest context. | ||
112 | This means that | ||
113 | .Fn EVP_DigestSignUpdate | ||
114 | and | ||
115 | .Fn EVP_DigestSignFinal | ||
116 | can be called later to digest and sign additional data. | ||
117 | .Pp | ||
118 | Since only a copy of the digest context is ever finalized, the context | ||
119 | must be cleaned up after use by calling | ||
120 | .Xr EVP_MD_CTX_cleanup 3 , | ||
121 | or a memory leak will occur. | ||
122 | .Pp | ||
123 | The use of | ||
124 | .Xr EVP_PKEY_size 3 | ||
125 | with these functions is discouraged because some signature operations | ||
126 | may have a signature length which depends on the parameters set. | ||
127 | As a result, | ||
128 | .Xr EVP_PKEY_size 3 | ||
129 | would have to return a value which indicates the maximum possible | ||
130 | signature for any set of parameters. | ||
131 | .Sh RETURN VALUES | ||
132 | .Fn EVP_DigestSignInit , | ||
133 | .Fn EVP_DigestSignUpdate , | ||
134 | and | ||
135 | .Fn EVP_DigestSignFinal | ||
136 | return 1 for success and 0 or a negative value for failure. | ||
137 | In particular, a return value of -2 indicates the operation is not | ||
138 | supported by the public key algorithm. | ||
139 | .Pp | ||
140 | The error codes can be obtained from | ||
141 | .Xr ERR_get_error 3 . | ||
142 | .Sh SEE ALSO | ||
143 | .Xr ERR 3 , | ||
144 | .Xr evp 3 , | ||
145 | .Xr EVP_DigestInit 3 , | ||
146 | .Xr EVP_DigestVerifyInit 3 | ||
147 | .Sh HISTORY | ||
148 | .Fn EVP_DigestSignInit , | ||
149 | .Fn EVP_DigestSignUpdate , | ||
150 | and | ||
151 | .Fn EVP_DigestSignFinal | ||
152 | were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_DigestVerifyInit.3 b/src/lib/libcrypto/man/EVP_DigestVerifyInit.3 new file mode 100644 index 0000000000..0b26eb617e --- /dev/null +++ b/src/lib/libcrypto/man/EVP_DigestVerifyInit.3 | |||
@@ -0,0 +1,132 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_DIGESTVERIFYINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_DigestVerifyInit , | ||
6 | .Nm EVP_DigestVerifyUpdate , | ||
7 | .Nm EVP_DigestVerifyFinal | ||
8 | .Nd EVP signature verification functions | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_DigestVerifyInit | ||
13 | .Fa "EVP_MD_CTX *ctx" | ||
14 | .Fa "EVP_PKEY_CTX **pctx" | ||
15 | .Fa "const EVP_MD *type" | ||
16 | .Fa "ENGINE *e" | ||
17 | .Fa "EVP_PKEY *pkey" | ||
18 | .Fc | ||
19 | .Ft int | ||
20 | .Fo EVP_DigestVerifyUpdate | ||
21 | .Fa "EVP_MD_CTX *ctx" | ||
22 | .Fa "const void *d" | ||
23 | .Fa "unsigned int cnt" | ||
24 | .Fc | ||
25 | .Ft int | ||
26 | .Fo EVP_DigestVerifyFinal | ||
27 | .Fa "EVP_MD_CTX *ctx" | ||
28 | .Fa "unsigned char *sig" | ||
29 | .Fa "size_t siglen" | ||
30 | .Fc | ||
31 | .Sh DESCRIPTION | ||
32 | The EVP signature routines are a high level interface to digital | ||
33 | signatures. | ||
34 | .Pp | ||
35 | .Fn EVP_DigestVerifyInit | ||
36 | sets up verification context | ||
37 | .Fa ctx | ||
38 | to use digest | ||
39 | .Fa type | ||
40 | from | ||
41 | .Vt ENGINE | ||
42 | .Fa e | ||
43 | and public key | ||
44 | .Fa pkey . | ||
45 | .Fa ctx | ||
46 | must be initialized with | ||
47 | .Xr EVP_MD_CTX_init 3 | ||
48 | before calling this function. | ||
49 | If | ||
50 | .Fa pctx | ||
51 | is not | ||
52 | .Dv NULL , | ||
53 | the | ||
54 | .Vt EVP_PKEY_CTX | ||
55 | of the verification operation will be written to | ||
56 | .Pf * Fa pctx : | ||
57 | this can be used to set alternative verification options. | ||
58 | .Pp | ||
59 | .Fn EVP_DigestVerifyUpdate | ||
60 | hashes | ||
61 | .Fa cnt | ||
62 | bytes of data at | ||
63 | .Fa d | ||
64 | into the verification context | ||
65 | .Fa ctx . | ||
66 | This function can be called several times on the same | ||
67 | .Fa ctx | ||
68 | to include additional data. | ||
69 | This function is currently implemented using a macro. | ||
70 | .Pp | ||
71 | .Fn EVP_DigestVerifyFinal | ||
72 | verifies the data in | ||
73 | .Fa ctx | ||
74 | against the signature in | ||
75 | .Fa sig | ||
76 | of length | ||
77 | .Fa siglen . | ||
78 | .Pp | ||
79 | The EVP interface to digital signatures should almost always be | ||
80 | used in preference to the low level interfaces. | ||
81 | This is because the code then becomes transparent to the algorithm used | ||
82 | and much more flexible. | ||
83 | .Pp | ||
84 | In previous versions of OpenSSL, there was a link between message digest | ||
85 | types and public key algorithms. | ||
86 | This meant that "clone" digests such as | ||
87 | .Xr EVP_dss1 3 | ||
88 | needed to be used to sign using SHA1 and DSA. | ||
89 | This is no longer necessary and the use of clone digest is now | ||
90 | discouraged. | ||
91 | .Pp | ||
92 | The call to | ||
93 | .Fn EVP_DigestVerifyFinal | ||
94 | internally finalizes a copy of the digest context. | ||
95 | This means that calls to | ||
96 | .Xr EVP_VerifyUpdate 3 | ||
97 | and | ||
98 | .Xr EVP_VerifyFinal 3 | ||
99 | can be called later to digest and verify additional data. | ||
100 | .Pp | ||
101 | Since only a copy of the digest context is ever finalized, the context | ||
102 | must be cleaned up after use by calling | ||
103 | .Xr EVP_MD_CTX_cleanup 3 | ||
104 | or a memory leak will occur. | ||
105 | .Sh RETURN VALUES | ||
106 | .Fn EVP_DigestVerifyInit | ||
107 | and | ||
108 | .Fn EVP_DigestVerifyUpdate | ||
109 | return 1 for success and 0 or a negative value for failure. | ||
110 | In particular a return value of -2 indicates the operation is not | ||
111 | supported by the public key algorithm. | ||
112 | .Pp | ||
113 | Unlike other functions, the return value 0 from | ||
114 | .Fn EVP_DigestVerifyFinal | ||
115 | only indicates that the signature did not verify successfully. | ||
116 | That is it did not match the original data or the signature was of | ||
117 | invalid form. | ||
118 | It is not an indication of a more serious error. | ||
119 | .Pp | ||
120 | The error codes can be obtained from | ||
121 | .Xr ERR_get_error 3 . | ||
122 | .Sh SEE ALSO | ||
123 | .Xr ERR 3 , | ||
124 | .Xr evp 3 , | ||
125 | .Xr EVP_DigestInit 3 , | ||
126 | .Xr EVP_DigestSignInit 3 | ||
127 | .Sh HISTORY | ||
128 | .Fn EVP_DigestVerifyInit , | ||
129 | .Fn EVP_DigestVerifyUpdate , | ||
130 | and | ||
131 | .Fn EVP_DigestVerifyFinal | ||
132 | were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_EncryptInit.3 b/src/lib/libcrypto/man/EVP_EncryptInit.3 new file mode 100644 index 0000000000..44967f863f --- /dev/null +++ b/src/lib/libcrypto/man/EVP_EncryptInit.3 | |||
@@ -0,0 +1,939 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_ENCRYPTINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_CIPHER_CTX_init , | ||
6 | .Nm EVP_EncryptInit_ex , | ||
7 | .Nm EVP_EncryptUpdate , | ||
8 | .Nm EVP_EncryptFinal_ex , | ||
9 | .Nm EVP_DecryptInit_ex , | ||
10 | .Nm EVP_DecryptUpdate , | ||
11 | .Nm EVP_DecryptFinal_ex , | ||
12 | .Nm EVP_CipherInit_ex , | ||
13 | .Nm EVP_CipherUpdate , | ||
14 | .Nm EVP_CipherFinal_ex , | ||
15 | .Nm EVP_CIPHER_CTX_set_key_length , | ||
16 | .Nm EVP_CIPHER_CTX_ctrl , | ||
17 | .Nm EVP_CIPHER_CTX_cleanup , | ||
18 | .Nm EVP_EncryptInit , | ||
19 | .Nm EVP_EncryptFinal , | ||
20 | .Nm EVP_DecryptInit , | ||
21 | .Nm EVP_DecryptFinal , | ||
22 | .Nm EVP_CipherInit , | ||
23 | .Nm EVP_CipherFinal , | ||
24 | .Nm EVP_get_cipherbyname , | ||
25 | .Nm EVP_get_cipherbynid , | ||
26 | .Nm EVP_get_cipherbyobj , | ||
27 | .Nm EVP_CIPHER_nid , | ||
28 | .Nm EVP_CIPHER_block_size , | ||
29 | .Nm EVP_CIPHER_key_length , | ||
30 | .Nm EVP_CIPHER_iv_length , | ||
31 | .Nm EVP_CIPHER_flags , | ||
32 | .Nm EVP_CIPHER_mode , | ||
33 | .Nm EVP_CIPHER_type , | ||
34 | .Nm EVP_CIPHER_CTX_cipher , | ||
35 | .Nm EVP_CIPHER_CTX_nid , | ||
36 | .Nm EVP_CIPHER_CTX_block_size , | ||
37 | .Nm EVP_CIPHER_CTX_key_length , | ||
38 | .Nm EVP_CIPHER_CTX_iv_length , | ||
39 | .Nm EVP_CIPHER_CTX_get_app_data , | ||
40 | .Nm EVP_CIPHER_CTX_set_app_data , | ||
41 | .Nm EVP_CIPHER_CTX_type , | ||
42 | .Nm EVP_CIPHER_CTX_flags , | ||
43 | .Nm EVP_CIPHER_CTX_mode , | ||
44 | .Nm EVP_CIPHER_param_to_asn1 , | ||
45 | .Nm EVP_CIPHER_asn1_to_param , | ||
46 | .Nm EVP_CIPHER_CTX_set_padding , | ||
47 | .Nm EVP_enc_null , | ||
48 | .Nm EVP_des_cbc , | ||
49 | .Nm EVP_des_ecb , | ||
50 | .Nm EVP_des_cfb , | ||
51 | .Nm EVP_des_ofb , | ||
52 | .Nm EVP_des_ede_cbc , | ||
53 | .Nm EVP_des_ede , | ||
54 | .Nm EVP_des_ede_ofb , | ||
55 | .Nm EVP_des_ede_cfb , | ||
56 | .Nm EVP_des_ede3_cbc , | ||
57 | .Nm EVP_des_ede3 , | ||
58 | .Nm EVP_des_ede3_ofb , | ||
59 | .Nm EVP_des_ede3_cfb , | ||
60 | .Nm EVP_desx_cbc , | ||
61 | .Nm EVP_rc4 , | ||
62 | .Nm EVP_rc4_40 , | ||
63 | .Nm EVP_idea_cbc , | ||
64 | .Nm EVP_idea_ecb , | ||
65 | .Nm EVP_idea_cfb , | ||
66 | .Nm EVP_idea_ofb , | ||
67 | .Nm EVP_idea_cbc , | ||
68 | .Nm EVP_rc2_cbc , | ||
69 | .Nm EVP_rc2_ecb , | ||
70 | .Nm EVP_rc2_cfb , | ||
71 | .Nm EVP_rc2_ofb , | ||
72 | .Nm EVP_rc2_40_cbc , | ||
73 | .Nm EVP_rc2_64_cbc , | ||
74 | .Nm EVP_bf_cbc , | ||
75 | .Nm EVP_bf_ecb , | ||
76 | .Nm EVP_bf_cfb , | ||
77 | .Nm EVP_bf_ofb , | ||
78 | .Nm EVP_cast5_cbc , | ||
79 | .Nm EVP_cast5_ecb , | ||
80 | .Nm EVP_cast5_cfb , | ||
81 | .Nm EVP_cast5_ofb , | ||
82 | .Nm EVP_aes_128_gcm , | ||
83 | .Nm EVP_aes_192_gcm , | ||
84 | .Nm EVP_aes_256_gcm , | ||
85 | .Nm EVP_aes_128_ccm , | ||
86 | .Nm EVP_aes_192_ccm , | ||
87 | .Nm EVP_aes_256_ccm , | ||
88 | .Nm EVP_rc5_32_12_16_cbc , | ||
89 | .Nm EVP_rc5_32_12_16_cfb , | ||
90 | .Nm EVP_rc5_32_12_16_ecb , | ||
91 | .Nm EVP_rc5_32_12_16_ofb | ||
92 | .Nd EVP cipher routines | ||
93 | .Sh SYNOPSIS | ||
94 | .In openssl/evp.h | ||
95 | .Ft void | ||
96 | .Fo EVP_CIPHER_CTX_init | ||
97 | .Fa "EVP_CIPHER_CTX *ctx" | ||
98 | .Fc | ||
99 | .Ft int | ||
100 | .Fo EVP_EncryptInit_ex | ||
101 | .Fa "EVP_CIPHER_CTX *ctx" | ||
102 | .Fa "const EVP_CIPHER *type" | ||
103 | .Fa "ENGINE *impl" | ||
104 | .Fa "unsigned char *key" | ||
105 | .Fa "unsigned char *iv" | ||
106 | .Fc | ||
107 | .Ft int | ||
108 | .Fo EVP_EncryptUpdate | ||
109 | .Fa "EVP_CIPHER_CTX *ctx" | ||
110 | .Fa "unsigned char *out" | ||
111 | .Fa "int *outl" | ||
112 | .Fa "unsigned char *in" | ||
113 | .Fa "int inl" | ||
114 | .Fc | ||
115 | .Ft int | ||
116 | .Fo EVP_EncryptFinal_ex | ||
117 | .Fa "EVP_CIPHER_CTX *ctx" | ||
118 | .Fa "unsigned char *out" | ||
119 | .Fa "int *outl" | ||
120 | .Fc | ||
121 | .Ft int | ||
122 | .Fo EVP_DecryptInit_ex | ||
123 | .Fa "EVP_CIPHER_CTX *ctx" | ||
124 | .Fa "const EVP_CIPHER *type" | ||
125 | .Fa "ENGINE *impl" | ||
126 | .Fa "unsigned char *key" | ||
127 | .Fa "unsigned char *iv" | ||
128 | .Fc | ||
129 | .Ft int | ||
130 | .Fo EVP_DecryptUpdate | ||
131 | .Fa "EVP_CIPHER_CTX *ctx" | ||
132 | .Fa "unsigned char *out" | ||
133 | .Fa "int *outl" | ||
134 | .Fa "unsigned char *in" | ||
135 | .Fa "int inl" | ||
136 | .Fc | ||
137 | .Ft int | ||
138 | .Fo EVP_DecryptFinal_ex | ||
139 | .Fa "EVP_CIPHER_CTX *ctx" | ||
140 | .Fa "unsigned char *outm" | ||
141 | .Fa "int *outl" | ||
142 | .Fc | ||
143 | .Ft int | ||
144 | .Fo EVP_CipherInit_ex | ||
145 | .Fa "EVP_CIPHER_CTX *ctx" | ||
146 | .Fa "const EVP_CIPHER *type" | ||
147 | .Fa "ENGINE *impl" | ||
148 | .Fa "unsigned char *key" | ||
149 | .Fa "unsigned char *iv" | ||
150 | .Fa "int enc" | ||
151 | .Fc | ||
152 | .Ft int | ||
153 | .Fo EVP_CipherUpdate | ||
154 | .Fa "EVP_CIPHER_CTX *ctx" | ||
155 | .Fa "unsigned char *out" | ||
156 | .Fa "int *outl" | ||
157 | .Fa "unsigned char *in" | ||
158 | .Fa "int inl" | ||
159 | .Fc | ||
160 | .Ft int | ||
161 | .Fo EVP_CipherFinal_ex | ||
162 | .Fa "EVP_CIPHER_CTX *ctx" | ||
163 | .Fa "unsigned char *outm" | ||
164 | .Fa "int *outl" | ||
165 | .Fc | ||
166 | .Ft int | ||
167 | .Fo EVP_EncryptInit | ||
168 | .Fa "EVP_CIPHER_CTX *ctx" | ||
169 | .Fa "const EVP_CIPHER *type" | ||
170 | .Fa "unsigned char *key" | ||
171 | .Fa "unsigned char *iv" | ||
172 | .Fc | ||
173 | .Ft int | ||
174 | .Fo EVP_EncryptFinal | ||
175 | .Fa "EVP_CIPHER_CTX *ctx" | ||
176 | .Fa "unsigned char *out" | ||
177 | .Fa "int *outl" | ||
178 | .Fc | ||
179 | .Ft int | ||
180 | .Fo EVP_DecryptInit | ||
181 | .Fa "EVP_CIPHER_CTX *ctx" | ||
182 | .Fa "const EVP_CIPHER *type" | ||
183 | .Fa "unsigned char *key" | ||
184 | .Fa "unsigned char *iv" | ||
185 | .Fc | ||
186 | .Ft int | ||
187 | .Fo EVP_DecryptFinal | ||
188 | .Fa "EVP_CIPHER_CTX *ctx" | ||
189 | .Fa "unsigned char *outm" | ||
190 | .Fa "int *outl" | ||
191 | .Fc | ||
192 | .Ft int | ||
193 | .Fo EVP_CipherInit | ||
194 | .Fa "EVP_CIPHER_CTX *ctx" | ||
195 | .Fa "const EVP_CIPHER *type" | ||
196 | .Fa "unsigned char *key" | ||
197 | .Fa "unsigned char *iv" | ||
198 | .Fa "int enc" | ||
199 | .Fc | ||
200 | .Ft int | ||
201 | .Fo EVP_CipherFinal | ||
202 | .Fa "EVP_CIPHER_CTX *ctx" | ||
203 | .Fa "unsigned char *outm" | ||
204 | .Fa "int *outl" | ||
205 | .Fc | ||
206 | .Ft int | ||
207 | .Fo EVP_CIPHER_CTX_set_padding | ||
208 | .Fa "EVP_CIPHER_CTX *x" | ||
209 | .Fa "int padding" | ||
210 | .Fc | ||
211 | .Ft int | ||
212 | .Fo EVP_CIPHER_CTX_set_key_length | ||
213 | .Fa "EVP_CIPHER_CTX *x" | ||
214 | .Fa "int keylen" | ||
215 | .Fc | ||
216 | .Ft int | ||
217 | .Fo EVP_CIPHER_CTX_ctrl | ||
218 | .Fa "EVP_CIPHER_CTX *ctx" | ||
219 | .Fa "int type" | ||
220 | .Fa "int arg" | ||
221 | .Fa "void *ptr" | ||
222 | .Fc | ||
223 | .Ft int | ||
224 | .Fo EVP_CIPHER_CTX_cleanup | ||
225 | .Fa "EVP_CIPHER_CTX *ctx" | ||
226 | .Fc | ||
227 | .Ft const EVP_CIPHER * | ||
228 | .Fo EVP_get_cipherbyname | ||
229 | .Fa "const char *name" | ||
230 | .Fc | ||
231 | .Fd #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
232 | .Fd #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
233 | .Fd #define EVP_CIPHER_nid(e) ((e)->nid) | ||
234 | .Fd #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
235 | .Fd #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
236 | .Fd #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
237 | .Fd #define EVP_CIPHER_flags(e) ((e)->flags) | ||
238 | .Fd #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE) | ||
239 | .Ft int | ||
240 | .Fo EVP_CIPHER_type | ||
241 | .Fa "const EVP_CIPHER *ctx" | ||
242 | .Fc | ||
243 | .Fd #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
244 | .Fd #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
245 | .Fd #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
246 | .Fd #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len) | ||
247 | .Fd #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
248 | .Fd #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
249 | .Fd #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
250 | .Fd #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) | ||
251 | .Fd #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags) | ||
252 | .Fd #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE) | ||
253 | .Ft int | ||
254 | .Fo EVP_CIPHER_param_to_asn1 | ||
255 | .Fa "EVP_CIPHER_CTX *c" | ||
256 | .Fa "ASN1_TYPE *type" | ||
257 | .Fc | ||
258 | .Ft int | ||
259 | .Fo EVP_CIPHER_asn1_to_param | ||
260 | .Fa "EVP_CIPHER_CTX *c" | ||
261 | .Fa "ASN1_TYPE *type" | ||
262 | .Fc | ||
263 | .Sh DESCRIPTION | ||
264 | The EVP cipher routines are a high level interface to certain symmetric | ||
265 | ciphers. | ||
266 | .Pp | ||
267 | .Fn EVP_CIPHER_CTX_init | ||
268 | initializes the cipher context | ||
269 | .Fa ctx . | ||
270 | .Pp | ||
271 | .Fn EVP_EncryptInit_ex | ||
272 | sets up the cipher context | ||
273 | .Fa ctx | ||
274 | for encryption with cipher | ||
275 | .Fa type | ||
276 | from | ||
277 | .Vt ENGINE | ||
278 | .Fa impl . | ||
279 | .Fa ctx | ||
280 | must be initialized before calling this function. | ||
281 | .Fa type | ||
282 | is normally supplied by a function such as | ||
283 | .Fn EVP_aes_256_cbc . | ||
284 | If | ||
285 | .Fa impl | ||
286 | is | ||
287 | .Dv NULL , | ||
288 | then the default implementation is used. | ||
289 | .Fa key | ||
290 | is the symmetric key to use and | ||
291 | .Fa iv | ||
292 | is the IV to use (if necessary), the actual number of bytes used for the | ||
293 | key and IV depends on the cipher. | ||
294 | It is possible to set all parameters to | ||
295 | .Dv NULL | ||
296 | except | ||
297 | .Fa type | ||
298 | in an initial call and supply the remaining parameters in subsequent | ||
299 | calls, all of which have | ||
300 | .Fa type | ||
301 | set to | ||
302 | .Dv NULL . | ||
303 | This is done when the default cipher parameters are not appropriate. | ||
304 | .Pp | ||
305 | .Fn EVP_EncryptUpdate | ||
306 | encrypts | ||
307 | .Fa inl | ||
308 | bytes from the buffer | ||
309 | .Fa in | ||
310 | and writes the encrypted version to | ||
311 | .Fa out . | ||
312 | This function can be called multiple times to encrypt successive blocks | ||
313 | of data. | ||
314 | The amount of data written depends on the block alignment of the | ||
315 | encrypted data: as a result the amount of data written may be anything | ||
316 | from zero bytes to (inl + cipher_block_size - 1) so | ||
317 | .Fa outl | ||
318 | should contain sufficient room. | ||
319 | The actual number of bytes written is placed in | ||
320 | .Fa outl . | ||
321 | .Pp | ||
322 | If padding is enabled (the default) then | ||
323 | .Fn EVP_EncryptFinal_ex | ||
324 | encrypts the "final" data, that is any data that remains in a partial | ||
325 | block. | ||
326 | It uses NOTES (aka PKCS padding). | ||
327 | The encrypted final data is written to | ||
328 | .Fa out | ||
329 | which should have sufficient space for one cipher block. | ||
330 | The number of bytes written is placed in | ||
331 | .Fa outl . | ||
332 | After this function is called the encryption operation is finished and | ||
333 | no further calls to | ||
334 | .Fn EVP_EncryptUpdate | ||
335 | should be made. | ||
336 | .Pp | ||
337 | If padding is disabled then | ||
338 | .Fn EVP_EncryptFinal_ex | ||
339 | will not encrypt any more data and it will return an error if any data | ||
340 | remains in a partial block: that is if the total data length is not a | ||
341 | multiple of the block size. | ||
342 | .Pp | ||
343 | .Fn EVP_DecryptInit_ex , | ||
344 | .Fn EVP_DecryptUpdate , | ||
345 | and | ||
346 | .Fn EVP_DecryptFinal_ex | ||
347 | are the corresponding decryption operations. | ||
348 | .Fn EVP_DecryptFinal | ||
349 | will return an error code if padding is enabled and the final block is | ||
350 | not correctly formatted. | ||
351 | The parameters and restrictions are identical to the encryption | ||
352 | operations except that if padding is enabled the decrypted data buffer | ||
353 | .Fa out | ||
354 | passed to | ||
355 | .Fn EVP_DecryptUpdate | ||
356 | should have sufficient room for (inl + cipher_block_size) bytes | ||
357 | unless the cipher block size is 1 in which case | ||
358 | .Fa inl | ||
359 | bytes is sufficient. | ||
360 | .Pp | ||
361 | .Fn EVP_CipherInit_ex , | ||
362 | .Fn EVP_CipherUpdate , | ||
363 | and | ||
364 | .Fn EVP_CipherFinal_ex | ||
365 | are functions that can be used for decryption or encryption. | ||
366 | The operation performed depends on the value of the | ||
367 | .Fa enc | ||
368 | parameter. | ||
369 | It should be set to 1 for encryption, 0 for decryption and -1 to leave | ||
370 | the value unchanged (the actual value of | ||
371 | .Fa enc | ||
372 | being supplied in a previous call). | ||
373 | .Pp | ||
374 | .Fn EVP_CIPHER_CTX_cleanup | ||
375 | clears all information from a cipher context and free up any allocated | ||
376 | memory associate with it. | ||
377 | It should be called after all operations using a cipher are complete so | ||
378 | sensitive information does not remain in memory. | ||
379 | .Pp | ||
380 | .Fn EVP_EncryptInit , | ||
381 | .Fn EVP_DecryptInit , | ||
382 | and | ||
383 | .Fn EVP_CipherInit | ||
384 | behave in a similar way to | ||
385 | .Fn EVP_EncryptInit_ex , | ||
386 | .Fn EVP_DecryptInit_ex , | ||
387 | and | ||
388 | .Fn EVP_CipherInit_ex | ||
389 | except the | ||
390 | .Fa ctx | ||
391 | parameter does not need to be initialized and they always use the | ||
392 | default cipher implementation. | ||
393 | .Pp | ||
394 | .Fn EVP_EncryptFinal , | ||
395 | .Fn EVP_DecryptFinal , | ||
396 | and | ||
397 | .Fn EVP_CipherFinal | ||
398 | are identical to | ||
399 | .Fn EVP_EncryptFinal_ex , | ||
400 | .Fn EVP_DecryptFinal_ex , | ||
401 | and | ||
402 | .Fn EVP_CipherFinal_ex . | ||
403 | In previous releases of OpenSSL, they also used to clean up the | ||
404 | .Fa ctx , | ||
405 | but this is no longer done and | ||
406 | .Fn EVP_CIPHER_CTX_cleanup | ||
407 | must be called to free any context resources. | ||
408 | .Pp | ||
409 | .Fn EVP_get_cipherbyname , | ||
410 | .Fn EVP_get_cipherbynid , | ||
411 | and | ||
412 | .Fn EVP_get_cipherbyobj | ||
413 | return an | ||
414 | .Vt EVP_CIPHER | ||
415 | structure when passed a cipher name, a NID or an | ||
416 | .Vt ASN1_OBJECT | ||
417 | structure. | ||
418 | .Pp | ||
419 | .Fn EVP_CIPHER_nid | ||
420 | and | ||
421 | .Fn EVP_CIPHER_CTX_nid | ||
422 | return the NID of a cipher when passed an | ||
423 | .Vt EVP_CIPHER | ||
424 | or | ||
425 | .Vt EVP_CIPHER_CTX | ||
426 | structure. | ||
427 | The actual NID value is an internal value which may not have a | ||
428 | corresponding OBJECT IDENTIFIER. | ||
429 | .Pp | ||
430 | .Fn EVP_CIPHER_CTX_set_padding | ||
431 | enables or disables padding. | ||
432 | By default encryption operations are padded using standard block padding | ||
433 | and the padding is checked and removed when decrypting. | ||
434 | If the | ||
435 | .Sy padding | ||
436 | parameter is zero, then no padding is performed, the total amount of data | ||
437 | encrypted or decrypted must then be a multiple of the block size or an | ||
438 | error will occur. | ||
439 | .Pp | ||
440 | .Fn EVP_CIPHER_key_length | ||
441 | and | ||
442 | .Fn EVP_CIPHER_CTX_key_length | ||
443 | return the key length of a cipher when passed an | ||
444 | .Vt EVP_CIPHER | ||
445 | or | ||
446 | .Vt EVP_CIPHER_CTX | ||
447 | structure. | ||
448 | The constant | ||
449 | .Dv EVP_MAX_KEY_LENGTH | ||
450 | is the maximum key length for all ciphers. | ||
451 | Note: although | ||
452 | .Fn EVP_CIPHER_key_length | ||
453 | is fixed for a given cipher, the value of | ||
454 | .Fn EVP_CIPHER_CTX_key_length | ||
455 | may be different for variable key length ciphers. | ||
456 | .Pp | ||
457 | .Fn EVP_CIPHER_CTX_set_key_length | ||
458 | sets the key length of the cipher ctx. | ||
459 | If the cipher is a fixed length cipher, then attempting to set the key | ||
460 | length to any value other than the fixed value is an error. | ||
461 | .Pp | ||
462 | .Fn EVP_CIPHER_iv_length | ||
463 | and | ||
464 | .Fn EVP_CIPHER_CTX_iv_length | ||
465 | return the IV length of a cipher when passed an | ||
466 | .Vt EVP_CIPHER | ||
467 | or | ||
468 | .Vt EVP_CIPHER_CTX . | ||
469 | It will return zero if the cipher does not use an IV. | ||
470 | The constant | ||
471 | .Dv EVP_MAX_IV_LENGTH | ||
472 | is the maximum IV length for all ciphers. | ||
473 | .Pp | ||
474 | .Fn EVP_CIPHER_block_size | ||
475 | and | ||
476 | .Fn EVP_CIPHER_CTX_block_size | ||
477 | return the block size of a cipher when passed an | ||
478 | .Vt EVP_CIPHER | ||
479 | or | ||
480 | .Vt EVP_CIPHER_CTX | ||
481 | structure. | ||
482 | The constant | ||
483 | .Dv EVP_MAX_IV_LENGTH | ||
484 | is also the maximum block length for all ciphers. | ||
485 | .Pp | ||
486 | .Fn EVP_CIPHER_type | ||
487 | and | ||
488 | .Fn EVP_CIPHER_CTX_type | ||
489 | return the type of the passed cipher or context. | ||
490 | This "type" is the actual NID of the cipher OBJECT IDENTIFIER as such it | ||
491 | ignores the cipher parameters and 40 bit RC2 and 128 bit RC2 have the | ||
492 | same NID. If the cipher does not have an object identifier or does not | ||
493 | have ASN1 support this function will return | ||
494 | .Dv NID_undef . | ||
495 | .Pp | ||
496 | .Fn EVP_CIPHER_CTX_cipher | ||
497 | returns the | ||
498 | .Vt EVP_CIPHER | ||
499 | structure when passed an | ||
500 | .Vt EVP_CIPHER_CTX | ||
501 | structure. | ||
502 | .Pp | ||
503 | .Fn EVP_CIPHER_mode | ||
504 | and | ||
505 | .Fn EVP_CIPHER_CTX_mode | ||
506 | return the block cipher mode: | ||
507 | .Dv EVP_CIPH_ECB_MODE , | ||
508 | .Dv EVP_CIPH_CBC_MODE , | ||
509 | .Dv EVP_CIPH_CFB_MODE , | ||
510 | or | ||
511 | .Dv EVP_CIPH_OFB_MODE . | ||
512 | If the cipher is a stream cipher then | ||
513 | .Dv EVP_CIPH_STREAM_CIPHER | ||
514 | is returned. | ||
515 | .Pp | ||
516 | .Fn EVP_CIPHER_param_to_asn1 | ||
517 | sets the AlgorithmIdentifier "parameter" based on the passed cipher. | ||
518 | This will typically include any parameters and an IV. | ||
519 | The cipher IV (if any) must be set when this call is made. | ||
520 | This call should be made before the cipher is actually "used" (before any | ||
521 | .Fn EVP_EncryptUpdate , | ||
522 | .Fn EVP_DecryptUpdate | ||
523 | calls for example). | ||
524 | This function may fail if the cipher does not have any ASN1 support. | ||
525 | .Pp | ||
526 | .Fn EVP_CIPHER_asn1_to_param | ||
527 | sets the cipher parameters based on an ASN1 AlgorithmIdentifier | ||
528 | "parameter". | ||
529 | The precise effect depends on the cipher. | ||
530 | In the case of RC2, for example, it will set the IV and effective | ||
531 | key length. | ||
532 | This function should be called after the base cipher type is set but | ||
533 | before the key is set. | ||
534 | For example | ||
535 | .Fn EVP_CipherInit | ||
536 | will be called with the IV and key set to | ||
537 | .Dv NULL , | ||
538 | .Fn EVP_CIPHER_asn1_to_param | ||
539 | will be called and finally | ||
540 | .Fn EVP_CipherInit | ||
541 | again with all parameters except the key set to | ||
542 | .Dv NULL . | ||
543 | It is possible for this function to fail if the cipher does not | ||
544 | have any ASN1 support or the parameters cannot be set (for example | ||
545 | the RC2 effective key length is not supported). | ||
546 | .Pp | ||
547 | .Fn EVP_CIPHER_CTX_ctrl | ||
548 | allows various cipher specific parameters to be determined and set. | ||
549 | Currently only the RC2 effective key length and the number of rounds of | ||
550 | RC5 can be set. | ||
551 | .Sh RETURN VALUES | ||
552 | .Fn EVP_EncryptInit_ex , | ||
553 | .Fn EVP_EncryptUpdate , | ||
554 | and | ||
555 | .Fn EVP_EncryptFinal_ex | ||
556 | return 1 for success and 0 for failure. | ||
557 | .Pp | ||
558 | .Fn EVP_DecryptInit_ex | ||
559 | and | ||
560 | .Fn EVP_DecryptUpdate | ||
561 | return 1 for success and 0 for failure. | ||
562 | .Fn EVP_DecryptFinal_ex | ||
563 | returns 0 if the decrypt failed or 1 for success. | ||
564 | .Pp | ||
565 | .Fn EVP_CipherInit_ex | ||
566 | and | ||
567 | .Fn EVP_CipherUpdate | ||
568 | return 1 for success and 0 for failure. | ||
569 | .Fn EVP_CipherFinal_ex | ||
570 | returns 0 for a decryption failure or 1 for success. | ||
571 | .Pp | ||
572 | .Fn EVP_CIPHER_CTX_cleanup | ||
573 | returns 1 for success and 0 for failure. | ||
574 | .Pp | ||
575 | .Fn EVP_get_cipherbyname , | ||
576 | .Fn EVP_get_cipherbynid , | ||
577 | and | ||
578 | .Fn EVP_get_cipherbyobj | ||
579 | return an | ||
580 | .Vt EVP_CIPHER | ||
581 | structure or | ||
582 | .Dv NULL | ||
583 | on error. | ||
584 | .Pp | ||
585 | .Fn EVP_CIPHER_nid | ||
586 | and | ||
587 | .Fn EVP_CIPHER_CTX_nid | ||
588 | return a NID. | ||
589 | .Pp | ||
590 | .Fn EVP_CIPHER_block_size | ||
591 | and | ||
592 | .Fn EVP_CIPHER_CTX_block_size | ||
593 | return the block size. | ||
594 | .Pp | ||
595 | .Fn EVP_CIPHER_key_length | ||
596 | and | ||
597 | .Fn EVP_CIPHER_CTX_key_length | ||
598 | return the key length. | ||
599 | .Pp | ||
600 | .Fn EVP_CIPHER_CTX_set_padding | ||
601 | always returns 1. | ||
602 | .Pp | ||
603 | .Fn EVP_CIPHER_iv_length | ||
604 | and | ||
605 | .Fn EVP_CIPHER_CTX_iv_length | ||
606 | return the IV length or zero if the cipher does not use an IV. | ||
607 | .Pp | ||
608 | .Fn EVP_CIPHER_type | ||
609 | and | ||
610 | .Fn EVP_CIPHER_CTX_type | ||
611 | return the NID of the cipher's OBJECT IDENTIFIER or | ||
612 | .Dv NID_undef | ||
613 | if it has no defined OBJECT IDENTIFIER. | ||
614 | .Pp | ||
615 | .Fn EVP_CIPHER_CTX_cipher | ||
616 | returns an | ||
617 | .Vt EVP_CIPHER | ||
618 | structure. | ||
619 | .Pp | ||
620 | .Fn EVP_CIPHER_param_to_asn1 | ||
621 | and | ||
622 | .Fn EVP_CIPHER_asn1_to_param | ||
623 | return 1 for success or 0 for failure. | ||
624 | .Pp | ||
625 | Where possible the EVP interface to symmetric ciphers should be | ||
626 | used in preference to the low level interfaces. | ||
627 | This is because the code then becomes transparent to the cipher used and | ||
628 | much more flexible. | ||
629 | .Pp | ||
630 | PKCS padding works by adding n padding bytes of value n to make the | ||
631 | total length of the encrypted data a multiple of the block size. | ||
632 | Padding is always added so if the data is already a multiple of the | ||
633 | block size n will equal the block size. | ||
634 | For example if the block size is 8 and 11 bytes are to be encrypted then | ||
635 | 5 padding bytes of value 5 will be added. | ||
636 | .Pp | ||
637 | When decrypting the final block is checked to see if it has the correct | ||
638 | form. | ||
639 | .Pp | ||
640 | Although the decryption operation can produce an error if padding is | ||
641 | enabled, it is not a strong test that the input data or key is correct. | ||
642 | A random block has better than 1 in 256 chance of being of the correct | ||
643 | format and problems with the input data earlier on will not produce a | ||
644 | final decrypt error. | ||
645 | .Pp | ||
646 | If padding is disabled then the decryption operation will always succeed | ||
647 | if the total amount of data decrypted is a multiple of the block size. | ||
648 | .Pp | ||
649 | The functions | ||
650 | .Fn EVP_EncryptInit , | ||
651 | .Fn EVP_EncryptFinal , | ||
652 | .Fn EVP_DecryptInit , | ||
653 | .Fn EVP_CipherInit , | ||
654 | and | ||
655 | .Fn EVP_CipherFinal | ||
656 | are obsolete but are retained for compatibility with existing code. | ||
657 | New code should use | ||
658 | .Fn EVP_EncryptInit_ex , | ||
659 | .Fn EVP_EncryptFinal_ex , | ||
660 | .Fn EVP_DecryptInit_ex , | ||
661 | .Fn EVP_DecryptFinal_ex , | ||
662 | .Fn EVP_CipherInit_ex , | ||
663 | and | ||
664 | .Fn EVP_CipherFinal_ex | ||
665 | because they can reuse an existing context without allocating and | ||
666 | freeing it up on each call. | ||
667 | .Sh CIPHER LISTING | ||
668 | All algorithms have a fixed key length unless otherwise stated. | ||
669 | .Bl -tag -width Ds | ||
670 | .It Fn EVP_enc_null void | ||
671 | Null cipher: does nothing. | ||
672 | .It Xo | ||
673 | .Fn EVP_aes_128_cbc void , | ||
674 | .Fn EVP_aes_128_ecb void , | ||
675 | .Fn EVP_aes_128_cfb void , | ||
676 | .Fn EVP_aes_128_ofb void | ||
677 | .Xc | ||
678 | 128-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
679 | .It Xo | ||
680 | .Fn EVP_aes_192_cbc void , | ||
681 | .Fn EVP_aes_192_ecb void , | ||
682 | .Fn EVP_aes_192_cfb void , | ||
683 | .Fn EVP_aes_192_ofb void | ||
684 | .Xc | ||
685 | 192-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
686 | .It Xo | ||
687 | .Fn EVP_aes_256_cbc void , | ||
688 | .Fn EVP_aes_256_ecb void , | ||
689 | .Fn EVP_aes_256_cfb void , | ||
690 | .Fn EVP_aes_256_ofb void | ||
691 | .Xc | ||
692 | 256-bit AES in CBC, ECB, CFB and OFB modes respectively. | ||
693 | .It Xo | ||
694 | .Fn EVP_des_cbc void , | ||
695 | .Fn EVP_des_ecb void , | ||
696 | .Fn EVP_des_cfb void , | ||
697 | .Fn EVP_des_ofb void | ||
698 | .Xc | ||
699 | DES in CBC, ECB, CFB and OFB modes respectively. | ||
700 | .It Xo | ||
701 | .Fn EVP_des_ede_cbc void , | ||
702 | .Fn EVP_des_ede void , | ||
703 | .Fn EVP_des_ede_ofb void , | ||
704 | .Fn EVP_des_ede_cfb void | ||
705 | .Xc | ||
706 | Two key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
707 | .It Xo | ||
708 | .Fn EVP_des_ede3_cbc void , | ||
709 | .Fn EVP_des_ede3 void , | ||
710 | .Fn EVP_des_ede3_ofb void , | ||
711 | .Fn EVP_des_ede3_cfb void | ||
712 | .Xc | ||
713 | Three key triple DES in CBC, ECB, CFB and OFB modes respectively. | ||
714 | .It Fn EVP_desx_cbc void | ||
715 | DESX algorithm in CBC mode. | ||
716 | .It Fn EVP_rc4 void | ||
717 | RC4 stream cipher. | ||
718 | This is a variable key length cipher with default key length 128 bits. | ||
719 | .It Fn EVP_rc4_40 void | ||
720 | RC4 stream cipher with 40 bit key length. | ||
721 | This is obsolete and new code should use | ||
722 | .Fn EVP_rc4 | ||
723 | and the | ||
724 | .Fn EVP_CIPHER_CTX_set_key_length | ||
725 | function. | ||
726 | .It Xo | ||
727 | .Fn EVP_idea_cbc void , | ||
728 | .Fn EVP_idea_ecb void , | ||
729 | .Fn EVP_idea_cfb void , | ||
730 | .Fn EVP_idea_ofb void | ||
731 | .Xc | ||
732 | IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
733 | .It Xo | ||
734 | .Fn EVP_rc2_cbc void , | ||
735 | .Fn EVP_rc2_ecb void , | ||
736 | .Fn EVP_rc2_cfb void , | ||
737 | .Fn EVP_rc2_ofb void | ||
738 | .Xc | ||
739 | RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
740 | This is a variable key length cipher with an additional parameter called | ||
741 | "effective key bits" or "effective key length". | ||
742 | By default both are set to 128 bits. | ||
743 | .It Xo | ||
744 | .Fn EVP_rc2_40_cbc void , | ||
745 | .Fn EVP_rc2_64_cbc void | ||
746 | .Xc | ||
747 | RC2 algorithm in CBC mode with a default key length and effective key | ||
748 | length of 40 and 64 bits. | ||
749 | These are obsolete and new code should use | ||
750 | .Fn EVP_rc2_cbc , | ||
751 | .Fn EVP_CIPHER_CTX_set_key_length , | ||
752 | and | ||
753 | .Fn EVP_CIPHER_CTX_ctrl | ||
754 | to set the key length and effective key length. | ||
755 | .It Xo | ||
756 | .Fn EVP_bf_cbc void , | ||
757 | .Fn EVP_bf_ecb void , | ||
758 | .Fn EVP_bf_cfb void , | ||
759 | .Fn EVP_bf_ofb void | ||
760 | .Xc | ||
761 | Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes | ||
762 | respectively. | ||
763 | This is a variable key length cipher. | ||
764 | .It Xo | ||
765 | .Fn EVP_cast5_cbc void , | ||
766 | .Fn EVP_cast5_ecb void , | ||
767 | .Fn EVP_cast5_cfb void , | ||
768 | .Fn EVP_cast5_ofb void | ||
769 | .Xc | ||
770 | CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
771 | This is a variable key length cipher. | ||
772 | .It Xo | ||
773 | .Fn EVP_rc5_32_12_16_cbc void , | ||
774 | .Fn EVP_rc5_32_12_16_ecb void , | ||
775 | .Fn EVP_rc5_32_12_16_cfb void , | ||
776 | .Fn EVP_rc5_32_12_16_ofb void | ||
777 | .Xc | ||
778 | RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. | ||
779 | This is a variable key length cipher with an additional "number of | ||
780 | rounds" parameter. | ||
781 | By default the key length is set to 128 bits and 12 rounds. | ||
782 | .El | ||
783 | .Sh EXAMPLES | ||
784 | Get the number of rounds used in RC5: | ||
785 | .Bd -literal | ||
786 | int nrounds; | ||
787 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds); | ||
788 | .Ed | ||
789 | .Pp | ||
790 | Get the RC2 effective key length: | ||
791 | .Bd -literal | ||
792 | int key_bits; | ||
793 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits); | ||
794 | .Ed | ||
795 | .Pp | ||
796 | Set the number of rounds used in RC5: | ||
797 | .Bd -literal | ||
798 | int nrounds; | ||
799 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL); | ||
800 | .Ed | ||
801 | .Pp | ||
802 | Set the effective key length used in RC2: | ||
803 | .Bd -literal | ||
804 | int key_bits; | ||
805 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | ||
806 | .Ed | ||
807 | .Pp | ||
808 | Encrypt a string using blowfish: | ||
809 | .Bd -literal | ||
810 | int | ||
811 | do_crypt(char *outfile) | ||
812 | { | ||
813 | unsigned char outbuf[1024]; | ||
814 | int outlen, tmplen; | ||
815 | /* | ||
816 | * Bogus key and IV: we'd normally set these from | ||
817 | * another source. | ||
818 | */ | ||
819 | unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
820 | unsigned char iv[] = {1,2,3,4,5,6,7,8}; | ||
821 | const char intext[] = "Some Crypto Text"; | ||
822 | EVP_CIPHER_CTX ctx; | ||
823 | FILE *out; | ||
824 | EVP_CIPHER_CTX_init(&ctx); | ||
825 | EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); | ||
826 | |||
827 | if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, | ||
828 | strlen(intext))) { | ||
829 | /* Error */ | ||
830 | return 0; | ||
831 | } | ||
832 | /* | ||
833 | * Buffer passed to EVP_EncryptFinal() must be after data just | ||
834 | * encrypted to avoid overwriting it. | ||
835 | */ | ||
836 | if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) { | ||
837 | /* Error */ | ||
838 | return 0; | ||
839 | } | ||
840 | outlen += tmplen; | ||
841 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
842 | /* | ||
843 | * Need binary mode for fopen because encrypted data is | ||
844 | * binary data. Also cannot use strlen() on it because | ||
845 | * it won't be NUL terminated and may contain embedded | ||
846 | * NULs. | ||
847 | */ | ||
848 | out = fopen(outfile, "wb"); | ||
849 | fwrite(outbuf, 1, outlen, out); | ||
850 | fclose(out); | ||
851 | return 1; | ||
852 | } | ||
853 | .Ed | ||
854 | .Pp | ||
855 | The ciphertext from the above example can be decrypted using the | ||
856 | .Xr openssl 1 | ||
857 | utility with the command line: | ||
858 | .Bd -literal | ||
859 | openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F \e | ||
860 | -iv 0102030405060708 -d | ||
861 | .Ed | ||
862 | .Pp | ||
863 | General encryption, decryption function example using FILE I/O and RC2 | ||
864 | with an 80 bit key: | ||
865 | .Bd -literal | ||
866 | int | ||
867 | do_crypt(FILE *in, FILE *out, int do_encrypt) | ||
868 | { | ||
869 | /* Allow enough space in output buffer for additional block */ | ||
870 | inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; | ||
871 | int inlen, outlen; | ||
872 | /* | ||
873 | * Bogus key and IV: we'd normally set these from | ||
874 | * another source. | ||
875 | */ | ||
876 | unsigned char key[] = "0123456789"; | ||
877 | unsigned char iv[] = "12345678"; | ||
878 | |||
879 | /* Don't set key or IV because we will modify the parameters */ | ||
880 | EVP_CIPHER_CTX_init(&ctx); | ||
881 | EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); | ||
882 | EVP_CIPHER_CTX_set_key_length(&ctx, 10); | ||
883 | /* We finished modifying parameters so now we can set key and IV */ | ||
884 | EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt); | ||
885 | |||
886 | for(;;) { | ||
887 | inlen = fread(inbuf, 1, 1024, in); | ||
888 | if (inlen <= 0) | ||
889 | break; | ||
890 | if (!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, | ||
891 | inlen)) { | ||
892 | /* Error */ | ||
893 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
894 | return 0; | ||
895 | } | ||
896 | fwrite(outbuf, 1, outlen, out); | ||
897 | } | ||
898 | if (!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) { | ||
899 | /* Error */ | ||
900 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
901 | return 0; | ||
902 | } | ||
903 | fwrite(outbuf, 1, outlen, out); | ||
904 | |||
905 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
906 | return 1; | ||
907 | } | ||
908 | .Ed | ||
909 | .Sh SEE ALSO | ||
910 | .Xr evp 3 | ||
911 | .Sh HISTORY | ||
912 | .Fn EVP_CIPHER_CTX_init , | ||
913 | .Fn EVP_EncryptInit_ex , | ||
914 | .Fn EVP_EncryptFinal_ex , | ||
915 | .Fn EVP_DecryptInit_ex , | ||
916 | .Fn EVP_DecryptFinal_ex , | ||
917 | .Fn EVP_CipherInit_ex , | ||
918 | .Fn EVP_CipherFinal_ex , | ||
919 | and | ||
920 | .Fn EVP_CIPHER_CTX_set_padding | ||
921 | appeared in OpenSSL 0.9.7. | ||
922 | .Sh BUGS | ||
923 | For RC5 the number of rounds can currently only be set to 8, 12 or 16. | ||
924 | This is a limitation of the current RC5 code rather than the EVP | ||
925 | interface. | ||
926 | .Pp | ||
927 | .Dv EVP_MAX_KEY_LENGTH | ||
928 | and | ||
929 | .Dv EVP_MAX_IV_LENGTH | ||
930 | only refer to the internal ciphers with default key lengths. | ||
931 | If custom ciphers exceed these values the results are unpredictable. | ||
932 | This is because it has become standard practice to define a generic key | ||
933 | as a fixed unsigned char array containing | ||
934 | .Dv EVP_MAX_KEY_LENGTH | ||
935 | bytes. | ||
936 | .Pp | ||
937 | The ASN1 code is incomplete (and sometimes inaccurate) it has only been | ||
938 | tested for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC | ||
939 | mode. | ||
diff --git a/src/lib/libcrypto/man/EVP_OpenInit.3 b/src/lib/libcrypto/man/EVP_OpenInit.3 new file mode 100644 index 0000000000..92873ac453 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_OpenInit.3 | |||
@@ -0,0 +1,98 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_OPENINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_OpenInit , | ||
6 | .Nm EVP_OpenUpdate , | ||
7 | .Nm EVP_OpenFinal | ||
8 | .Nd EVP envelope decryption | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_OpenInit | ||
13 | .Fa "EVP_CIPHER_CTX *ctx" | ||
14 | .Fa "EVP_CIPHER *type" | ||
15 | .Fa "unsigned char *ek" | ||
16 | .Fa "int ekl" | ||
17 | .Fa "unsigned char *iv" | ||
18 | .Fa "EVP_PKEY *priv" | ||
19 | .Fc | ||
20 | .Ft int | ||
21 | .Fo EVP_OpenUpdate | ||
22 | .Fa "EVP_CIPHER_CTX *ctx" | ||
23 | .Fa "unsigned char *out" | ||
24 | .Fa "int *outl" | ||
25 | .Fa "unsigned char *in" | ||
26 | .Fa "int inl" | ||
27 | .Fc | ||
28 | .Ft int | ||
29 | .Fo EVP_OpenFinal | ||
30 | .Fa "EVP_CIPHER_CTX *ctx" | ||
31 | .Fa "unsigned char *out" | ||
32 | .Fa "int *outl" | ||
33 | .Fc | ||
34 | .Sh DESCRIPTION | ||
35 | The EVP envelope routines are a high level interface to envelope | ||
36 | decryption. | ||
37 | They decrypt a public key encrypted symmetric key and then decrypt data | ||
38 | using it. | ||
39 | .Pp | ||
40 | .Fn EVP_OpenInit | ||
41 | initializes a cipher context | ||
42 | .Fa ctx | ||
43 | for decryption with cipher | ||
44 | .Fa type . | ||
45 | It decrypts the encrypted symmetric key of length | ||
46 | .Fa ekl | ||
47 | bytes passed in the | ||
48 | .Fa ek | ||
49 | parameter using the private key | ||
50 | .Fa priv . | ||
51 | The IV is supplied in the | ||
52 | .Fa iv | ||
53 | parameter. | ||
54 | .Pp | ||
55 | .Fn EVP_OpenUpdate | ||
56 | and | ||
57 | .Fn EVP_OpenFinal | ||
58 | have exactly the same properties as the | ||
59 | .Xr EVP_DecryptUpdate 3 | ||
60 | and | ||
61 | .Xr EVP_DecryptFinal 3 | ||
62 | routines. | ||
63 | .Pp | ||
64 | It is possible to call | ||
65 | .Fn EVP_OpenInit | ||
66 | twice in the same way as | ||
67 | .Xr EVP_DecryptInit 3 . | ||
68 | The first call should have | ||
69 | .Fa priv | ||
70 | set to | ||
71 | .Dv NULL | ||
72 | and (after setting any cipher parameters) it should be | ||
73 | called again with | ||
74 | .Fa type | ||
75 | set to | ||
76 | .Dv NULL . | ||
77 | .Pp | ||
78 | If the cipher passed in the | ||
79 | .Fa type | ||
80 | parameter is a variable length cipher then the key length will be set to | ||
81 | the value of the recovered key length. | ||
82 | If the cipher is a fixed length cipher then the recovered key length | ||
83 | must match the fixed cipher length. | ||
84 | .Sh RETURN VALUES | ||
85 | .Fn EVP_OpenInit | ||
86 | returns 0 on error or a non zero integer (actually the recovered secret | ||
87 | key size) if successful. | ||
88 | .Pp | ||
89 | .Fn EVP_OpenUpdate | ||
90 | returns 1 for success or 0 for failure. | ||
91 | .Pp | ||
92 | .Fn EVP_OpenFinal | ||
93 | returns 0 if the decrypt failed or 1 for success. | ||
94 | .Sh SEE ALSO | ||
95 | .Xr evp 3 , | ||
96 | .Xr EVP_EncryptInit 3 , | ||
97 | .Xr EVP_SealInit 3 , | ||
98 | .Xr rand 3 | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_CTX_ctrl.3 b/src/lib/libcrypto/man/EVP_PKEY_CTX_ctrl.3 new file mode 100644 index 0000000000..5b1b94653a --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_CTX_ctrl.3 | |||
@@ -0,0 +1,245 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_CTX_CTRL 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_CTX_ctrl , | ||
6 | .Nm EVP_PKEY_CTX_ctrl_str , | ||
7 | .Nm EVP_PKEY_get_default_digest_nid , | ||
8 | .Nm EVP_PKEY_CTX_set_signature_md , | ||
9 | .Nm EVP_PKEY_CTX_set_rsa_padding , | ||
10 | .Nm EVP_PKEY_CTX_set_rsa_pss_saltlen , | ||
11 | .Nm EVP_PKEY_CTX_set_rsa_rsa_keygen_bits , | ||
12 | .Nm EVP_PKEY_CTX_set_rsa_keygen_pubexp , | ||
13 | .Nm EVP_PKEY_CTX_set_dsa_paramgen_bits , | ||
14 | .Nm EVP_PKEY_CTX_set_dh_paramgen_prime_len , | ||
15 | .Nm EVP_PKEY_CTX_set_dh_paramgen_generator , | ||
16 | .Nm EVP_PKEY_CTX_set_ec_paramgen_curve_nid | ||
17 | .Nd algorithm specific control operations | ||
18 | .Sh SYNOPSIS | ||
19 | .In openssl/evp.h | ||
20 | .Ft int | ||
21 | .Fo EVP_PKEY_CTX_ctrl | ||
22 | .Fa "EVP_PKEY_CTX *ctx" | ||
23 | .Fa "int keytype" | ||
24 | .Fa "int optype" | ||
25 | .Fa "int cmd" | ||
26 | .Fa "int p1" | ||
27 | .Fa "void *p2" | ||
28 | .Fc | ||
29 | .Ft int | ||
30 | .Fo EVP_PKEY_CTX_ctrl_str | ||
31 | .Fa "EVP_PKEY_CTX *ctx" | ||
32 | .Fa "const char *type" | ||
33 | .Fa "const char *value" | ||
34 | .Fc | ||
35 | .Ft int | ||
36 | .Fo EVP_PKEY_get_default_digest_nid | ||
37 | .Fa "EVP_PKEY *pkey" | ||
38 | .Fa "int *pnid" | ||
39 | .Fc | ||
40 | .In openssl/rsa.h | ||
41 | .Ft int | ||
42 | .Fo EVP_PKEY_CTX_set_signature_md | ||
43 | .Fa "EVP_PKEY_CTX *ctx" | ||
44 | .Fa "const EVP_MD *md" | ||
45 | .Fc | ||
46 | .Ft int | ||
47 | .Fo EVP_PKEY_CTX_set_rsa_padding | ||
48 | .Fa "EVP_PKEY_CTX *ctx" | ||
49 | .Fa "int pad" | ||
50 | .Fc | ||
51 | .Ft int | ||
52 | .Fo EVP_PKEY_CTX_set_rsa_pss_saltlen | ||
53 | .Fa "EVP_PKEY_CTX *ctx" | ||
54 | .Fa "int len" | ||
55 | .Fc | ||
56 | .Ft int | ||
57 | .Fo EVP_PKEY_CTX_set_rsa_rsa_keygen_bits | ||
58 | .Fa "EVP_PKEY_CTX *ctx" | ||
59 | .Fa "int mbits" | ||
60 | .Fc | ||
61 | .Ft int | ||
62 | .Fo EVP_PKEY_CTX_set_rsa_keygen_pubexp | ||
63 | .Fa "EVP_PKEY_CTX *ctx" | ||
64 | .Fa "BIGNUM *pubexp" | ||
65 | .Fc | ||
66 | .In openssl/dsa.h | ||
67 | .Ft int | ||
68 | .Fo EVP_PKEY_CTX_set_dsa_paramgen_bits | ||
69 | .Fa "EVP_PKEY_CTX *ctx" | ||
70 | .Fa "int nbits" | ||
71 | .Fc | ||
72 | .In openssl/dh.h | ||
73 | .Ft int | ||
74 | .Fo EVP_PKEY_CTX_set_dh_paramgen_prime_len | ||
75 | .Fa "EVP_PKEY_CTX *ctx" | ||
76 | .Fa "int len" | ||
77 | .Fc | ||
78 | .Ft int | ||
79 | .Fo EVP_PKEY_CTX_set_dh_paramgen_generator | ||
80 | .Fa "EVP_PKEY_CTX *ctx" | ||
81 | .Fa "int gen" | ||
82 | .Fc | ||
83 | .In openssl/ec.h | ||
84 | .Ft int | ||
85 | .Fo EVP_PKEY_CTX_set_ec_paramgen_curve_nid | ||
86 | .Fa "EVP_PKEY_CTX *ctx" | ||
87 | .Fa "int nid" | ||
88 | .Fc | ||
89 | .Sh DESCRIPTION | ||
90 | The function | ||
91 | .Fn EVP_PKEY_CTX_ctrl | ||
92 | sends a control operation to the context | ||
93 | .Fa ctx . | ||
94 | The key type used must match | ||
95 | .Fa keytype | ||
96 | if it is not -1. | ||
97 | The parameter | ||
98 | .Fa optype | ||
99 | is a mask indicating which operations the control can be applied to. | ||
100 | The control command is indicated in | ||
101 | .Fa cmd | ||
102 | and any additional arguments in | ||
103 | .Fa p1 | ||
104 | and | ||
105 | .Fa p2 . | ||
106 | .Pp | ||
107 | Applications will not normally call | ||
108 | .Fn EVP_PKEY_CTX_ctrl | ||
109 | directly but will instead call one of the algorithm specific macros | ||
110 | below. | ||
111 | .Pp | ||
112 | The function | ||
113 | .Fn EVP_PKEY_CTX_ctrl_str | ||
114 | allows an application to send an algorithm specific control operation to | ||
115 | a context | ||
116 | .Fa ctx | ||
117 | in string form. | ||
118 | This is intended to be used for options specified on the command line or | ||
119 | in text files. | ||
120 | The commands supported are documented in the | ||
121 | .Xr openssl 1 | ||
122 | utility command line pages for the option | ||
123 | .Fl pkeyopt | ||
124 | which is supported by the | ||
125 | .Cm pkeyutl , | ||
126 | .Cm genpkey , | ||
127 | and | ||
128 | .Cm req | ||
129 | commands. | ||
130 | .Pp | ||
131 | All the remaining "functions" are implemented as macros. | ||
132 | .Pp | ||
133 | The | ||
134 | .Fn EVP_PKEY_CTX_set_signature_md | ||
135 | macro sets the message digest type used in a signature. | ||
136 | It can be used with any public key algorithm supporting signature | ||
137 | operations. | ||
138 | .Pp | ||
139 | The macro | ||
140 | .Fn EVP_PKEY_CTX_set_rsa_padding | ||
141 | sets the RSA padding mode for | ||
142 | .Fa ctx . | ||
143 | The | ||
144 | .Fa pad | ||
145 | parameter can take the value | ||
146 | .Dv RSA_PKCS1_PADDING | ||
147 | for PKCS#1 padding, | ||
148 | .Dv RSA_SSLV23_PADDING | ||
149 | for SSLv23 padding, | ||
150 | .Dv RSA_NO_PADDING | ||
151 | for no padding, | ||
152 | .Dv RSA_PKCS1_OAEP_PADDING | ||
153 | for OAEP padding (encrypt and decrypt only), | ||
154 | .Dv RSA_X931_PADDING | ||
155 | for X9.31 padding (signature operations only) and | ||
156 | .Dv RSA_PKCS1_PSS_PADDING | ||
157 | (sign and verify only). | ||
158 | .Pp | ||
159 | Two RSA padding modes behave differently if | ||
160 | .Fn EVP_PKEY_CTX_set_signature_md | ||
161 | is used. | ||
162 | If this macro is called for PKCS#1 padding, the plaintext buffer is an | ||
163 | actual digest value and is encapsulated in a DigestInfo structure | ||
164 | according to PKCS#1 when signing and this structure is expected (and | ||
165 | stripped off) when verifying. | ||
166 | If this control is not used with RSA and PKCS#1 padding then the | ||
167 | supplied data is used directly and not encapsulated. | ||
168 | In the case of X9.31 padding for RSA the algorithm identifier byte is | ||
169 | added or checked and removed if this control is called. | ||
170 | If it is not called then the first byte of the plaintext buffer is | ||
171 | expected to be the algorithm identifier byte. | ||
172 | .Pp | ||
173 | The | ||
174 | .Fn EVP_PKEY_CTX_set_rsa_pss_saltlen | ||
175 | macro sets the RSA PSS salt length to | ||
176 | .Fa len | ||
177 | as its name implies it is only supported for PSS padding. | ||
178 | Two special values are supported: -1 sets the salt length to the digest | ||
179 | length. | ||
180 | When signing -2 sets the salt length to the maximum permissible value. | ||
181 | When verifying -2 causes the salt length to be automatically determined | ||
182 | based on the PSS block structure. | ||
183 | If this macro is not called a salt length value of -2 is used by | ||
184 | default. | ||
185 | .Pp | ||
186 | The | ||
187 | .Fn EVP_PKEY_CTX_set_rsa_rsa_keygen_bits | ||
188 | macro sets the RSA key length for RSA key generation to | ||
189 | .Fa mbits . | ||
190 | If not specified, 1024 bits is used. | ||
191 | .Pp | ||
192 | The | ||
193 | .Fn EVP_PKEY_CTX_set_rsa_keygen_pubexp | ||
194 | macro sets the public exponent value for RSA key generation to | ||
195 | .Fa pubexp . | ||
196 | Currently, it should be an odd integer. | ||
197 | The | ||
198 | .Fa pubexp | ||
199 | pointer is used internally by this function, so it should not be modified | ||
200 | or freed after the call. | ||
201 | If this macro is not called, then 65537 is used. | ||
202 | .Pp | ||
203 | The macro | ||
204 | .Fn EVP_PKEY_CTX_set_dsa_paramgen_bits | ||
205 | sets the number of bits used for DSA parameter generation to | ||
206 | .Fa nbits . | ||
207 | If not specified, 1024 is used. | ||
208 | .Pp | ||
209 | The macro | ||
210 | .Fn EVP_PKEY_CTX_set_dh_paramgen_prime_len | ||
211 | sets the length of the DH prime parameter | ||
212 | .Fa len | ||
213 | for DH parameter generation. | ||
214 | If this macro is not called, then 1024 is used. | ||
215 | .Pp | ||
216 | The | ||
217 | .Fn EVP_PKEY_CTX_set_dh_paramgen_generator | ||
218 | macro sets DH generator to | ||
219 | .Fa gen | ||
220 | for DH parameter generation. | ||
221 | If not specified, 2 is used. | ||
222 | .Pp | ||
223 | The | ||
224 | .Fn EVP_PKEY_CTX_set_ec_paramgen_curve_nid | ||
225 | sets the EC curve for EC parameter generation to | ||
226 | .Fa nid . | ||
227 | For EC parameter generation, this macro must be called or an error occurs | ||
228 | because there is no default curve. | ||
229 | .Sh RETURN VALUES | ||
230 | .Fn EVP_PKEY_CTX_ctrl | ||
231 | and its macros return a positive value for success and 0 or a negative | ||
232 | value for failure. | ||
233 | In particular, a return value of -2 indicates the operation is not | ||
234 | supported by the public key algorithm. | ||
235 | .Sh SEE ALSO | ||
236 | .Xr EVP_PKEY_CTX_new 3 , | ||
237 | .Xr EVP_PKEY_decrypt 3 , | ||
238 | .Xr EVP_PKEY_derive 3 , | ||
239 | .Xr EVP_PKEY_encrypt 3 , | ||
240 | .Xr EVP_PKEY_keygen 3 , | ||
241 | .Xr EVP_PKEY_sign 3 , | ||
242 | .Xr EVP_PKEY_verify 3 , | ||
243 | .Xr EVP_PKEY_verify_recover 3 | ||
244 | .Sh HISTORY | ||
245 | These functions were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_CTX_new.3 b/src/lib/libcrypto/man/EVP_PKEY_CTX_new.3 new file mode 100644 index 0000000000..c08db1eb21 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_CTX_new.3 | |||
@@ -0,0 +1,85 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_CTX_NEW 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_CTX_new , | ||
6 | .Nm EVP_PKEY_CTX_new_id , | ||
7 | .Nm EVP_PKEY_CTX_dup , | ||
8 | .Nm EVP_PKEY_CTX_free | ||
9 | .Nd public key algorithm context functions | ||
10 | .Sh SYNOPSIS | ||
11 | .In openssl/evp.h | ||
12 | .Ft EVP_PKEY_CTX * | ||
13 | .Fo EVP_PKEY_CTX_new | ||
14 | .Fa "EVP_PKEY *pkey" | ||
15 | .Fa "ENGINE *e" | ||
16 | .Fc | ||
17 | .Ft EVP_PKEY_CTX * | ||
18 | .Fo EVP_PKEY_CTX_new_id | ||
19 | .Fa "int id" | ||
20 | .Fa "ENGINE *e" | ||
21 | .Fc | ||
22 | .Ft EVP_PKEY_CTX * | ||
23 | .Fo EVP_PKEY_CTX_dup | ||
24 | .Fa "EVP_PKEY_CTX *ctx" | ||
25 | .Fc | ||
26 | .Ft void | ||
27 | .Fo EVP_PKEY_CTX_free | ||
28 | .Fa "EVP_PKEY_CTX *ctx" | ||
29 | .Fc | ||
30 | .Sh DESCRIPTION | ||
31 | The | ||
32 | .Fn EVP_PKEY_CTX_new | ||
33 | function allocates a public key algorithm context using the algorithm | ||
34 | specified in | ||
35 | .Fa pkey | ||
36 | and the | ||
37 | .Vt ENGINE | ||
38 | .Fa e . | ||
39 | .Pp | ||
40 | The | ||
41 | .Fn EVP_PKEY_CTX_new_id | ||
42 | function allocates a public key algorithm context using the algorithm | ||
43 | specified by | ||
44 | .Fa id | ||
45 | and | ||
46 | .Vt ENGINE | ||
47 | .Fa e . | ||
48 | It is normally used when no | ||
49 | .Vt EVP_PKEY | ||
50 | structure is associated with the operations, for example during | ||
51 | parameter generation of key generation for some algorithms. | ||
52 | .Pp | ||
53 | .Fn EVP_PKEY_CTX_dup | ||
54 | duplicates the context | ||
55 | .Fa ctx . | ||
56 | .Pp | ||
57 | .Fn EVP_PKEY_CTX_free | ||
58 | frees up the context | ||
59 | .Fa ctx . | ||
60 | .Sh RETURN VALUES | ||
61 | .Fn EVP_PKEY_CTX_new , | ||
62 | .Fn EVP_PKEY_CTX_new_id , | ||
63 | .Fn EVP_PKEY_CTX_dup | ||
64 | returns either the newly allocated | ||
65 | .Vt EVP_PKEY_CTX | ||
66 | structure of | ||
67 | .Dv NULL | ||
68 | if an error occurred. | ||
69 | .Pp | ||
70 | .Fn EVP_PKEY_CTX_free | ||
71 | does not return a value. | ||
72 | .Sh SEE ALSO | ||
73 | .Xr EVP_PKEY_new 3 | ||
74 | .Sh HISTORY | ||
75 | These functions were first added to OpenSSL 1.0.0. | ||
76 | .Sh CAVEATS | ||
77 | The | ||
78 | .Vt EVP_PKEY_CTX | ||
79 | structure is an opaque public key algorithm context used by the OpenSSL | ||
80 | high level public key API. | ||
81 | Contexts | ||
82 | .Sy MUST NOT | ||
83 | be shared between threads. | ||
84 | It is not permissible to use the same context simultaneously in two | ||
85 | threads. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_cmp.3 b/src/lib/libcrypto/man/EVP_PKEY_cmp.3 new file mode 100644 index 0000000000..a3c3ba4fec --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_cmp.3 | |||
@@ -0,0 +1,92 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_CMP 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_copy_parameters , | ||
6 | .Nm EVP_PKEY_missing_parameters , | ||
7 | .Nm EVP_PKEY_cmp_parameters , | ||
8 | .Nm EVP_PKEY_cmp | ||
9 | .Nd public key parameter and comparison functions | ||
10 | .Sh SYNOPSIS | ||
11 | .In openssl/evp.h | ||
12 | .Ft int | ||
13 | .Fo EVP_PKEY_missing_parameters | ||
14 | .Fa "const EVP_PKEY *pkey" | ||
15 | .Fc | ||
16 | .Ft int | ||
17 | .Fo EVP_PKEY_copy_parameters | ||
18 | .Fa "EVP_PKEY *to" | ||
19 | .Fa "const EVP_PKEY *from" | ||
20 | .Fc | ||
21 | .Ft int | ||
22 | .Fo EVP_PKEY_cmp_parameters | ||
23 | .Fa "const EVP_PKEY *a" | ||
24 | .Fa "const EVP_PKEY *b" | ||
25 | .Fc | ||
26 | .Ft int | ||
27 | .Fo EVP_PKEY_cmp | ||
28 | .Fa "const EVP_PKEY *a" | ||
29 | .Fa "const EVP_PKEY *b" | ||
30 | .Fc | ||
31 | .Sh DESCRIPTION | ||
32 | The function | ||
33 | .Fn EVP_PKEY_missing_parameters | ||
34 | returns 1 if the public key parameters of | ||
35 | .Fa pkey | ||
36 | are missing and 0 if they are present or the algorithm doesn't use | ||
37 | parameters. | ||
38 | .Pp | ||
39 | The function | ||
40 | .Fn EVP_PKEY_copy_parameters | ||
41 | copies the parameters from key | ||
42 | .Fa from | ||
43 | to key | ||
44 | .Fa to . | ||
45 | .Pp | ||
46 | The function | ||
47 | .Fn EVP_PKEY_cmp_parameters | ||
48 | compares the parameters of keys | ||
49 | .Fa a | ||
50 | and | ||
51 | .Fa b . | ||
52 | .Pp | ||
53 | The function | ||
54 | .Fn EVP_PKEY_cmp | ||
55 | compares the public key components and parameters (if present) of keys | ||
56 | .Fa a | ||
57 | and | ||
58 | .Fa b . | ||
59 | .Pp | ||
60 | The main purpose of the functions | ||
61 | .Fn EVP_PKEY_missing_parameters | ||
62 | and | ||
63 | .Fn EVP_PKEY_copy_parameters | ||
64 | is to handle public keys in certificates where the parameters are | ||
65 | sometimes omitted from a public key if they are inherited from the CA | ||
66 | that signed it. | ||
67 | .Pp | ||
68 | Since OpenSSL private keys contain public key components too, the | ||
69 | function | ||
70 | .Fn EVP_PKEY_cmp | ||
71 | can also be used to determine if a private key matches a public key. | ||
72 | .Sh RETURN VALUES | ||
73 | The function | ||
74 | .Fn EVP_PKEY_missing_parameters | ||
75 | returns 1 if the public key parameters of | ||
76 | .Fa pkey | ||
77 | are missing and 0 if they are present or the algorithm doesn't use | ||
78 | parameters. | ||
79 | .Pp | ||
80 | The function | ||
81 | .Fn EVP_PKEY_copy_parameters | ||
82 | returns 1 for success and 0 for failure. | ||
83 | .Pp | ||
84 | The function | ||
85 | .Fn EVP_PKEY_cmp_parameters | ||
86 | and | ||
87 | .Fn EVP_PKEY_cmp | ||
88 | return 1 if the keys match, 0 if they don't match, -1 if the key types | ||
89 | are different and -2 if the operation is not supported. | ||
90 | .Sh SEE ALSO | ||
91 | .Xr EVP_PKEY_CTX_new 3 , | ||
92 | .Xr EVP_PKEY_keygen 3 | ||
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. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_derive.3 b/src/lib/libcrypto/man/EVP_PKEY_derive.3 new file mode 100644 index 0000000000..e67280cf20 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_derive.3 | |||
@@ -0,0 +1,120 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_DERIVE 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_derive_init , | ||
6 | .Nm EVP_PKEY_derive_set_peer , | ||
7 | .Nm EVP_PKEY_derive | ||
8 | .Nd derive public key algorithm shared secret | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_PKEY_derive_init | ||
13 | .Fa "EVP_PKEY_CTX *ctx" | ||
14 | .Fc | ||
15 | .Ft int | ||
16 | .Fo EVP_PKEY_derive_set_peer | ||
17 | .Fa "EVP_PKEY_CTX *ctx" | ||
18 | .Fa "EVP_PKEY *peer" | ||
19 | .Fc | ||
20 | .Ft int | ||
21 | .Fo EVP_PKEY_derive | ||
22 | .Fa "EVP_PKEY_CTX *ctx" | ||
23 | .Fa "unsigned char *key" | ||
24 | .Fa "size_t *keylen" | ||
25 | .Fc | ||
26 | .Sh DESCRIPTION | ||
27 | The | ||
28 | .Fn EVP_PKEY_derive_init | ||
29 | function initializes a public key algorithm context using key | ||
30 | .Fa ctx->pkey | ||
31 | for shared secret derivation. | ||
32 | .Pp | ||
33 | The | ||
34 | .Fn EVP_PKEY_derive_set_peer | ||
35 | function sets the peer key: this will normally be a public key. | ||
36 | .Pp | ||
37 | The | ||
38 | .Fn EVP_PKEY_derive | ||
39 | derives a shared secret using | ||
40 | .Fa ctx . | ||
41 | If | ||
42 | .Fa key | ||
43 | is | ||
44 | .Dv NULL , | ||
45 | then the maximum size of the output buffer is written to the | ||
46 | .Fa keylen | ||
47 | parameter. | ||
48 | If | ||
49 | .Fa key | ||
50 | is not | ||
51 | .Dv NULL | ||
52 | then before the call the | ||
53 | .Fa keylen | ||
54 | parameter should contain the length of the | ||
55 | .Fa key | ||
56 | buffer. | ||
57 | If the call is successful, the shared secret is written to | ||
58 | .Fa key | ||
59 | and the amount of data written to | ||
60 | .Fa keylen . | ||
61 | .Pp | ||
62 | After the call to | ||
63 | .Fn EVP_PKEY_derive_init , | ||
64 | algorithm specific control operations can be performed to set any | ||
65 | appropriate parameters for the operation. | ||
66 | .Pp | ||
67 | The function | ||
68 | .Fn EVP_PKEY_derive | ||
69 | can be called more than once on the same context if several operations | ||
70 | are performed using the same parameters. | ||
71 | .Sh RETURN VALUES | ||
72 | .Fn EVP_PKEY_derive_init | ||
73 | and | ||
74 | .Fn EVP_PKEY_derive | ||
75 | return 1 for success and 0 or a negative value for failure. | ||
76 | In particular, a return value of -2 indicates the operation is not | ||
77 | supported by the public key algorithm. | ||
78 | .Sh EXAMPLES | ||
79 | Derive shared secret (for example DH or EC keys): | ||
80 | .Bd -literal | ||
81 | #include <openssl/evp.h> | ||
82 | #include <openssl/rsa.h> | ||
83 | |||
84 | EVP_PKEY_CTX *ctx; | ||
85 | unsigned char *skey; | ||
86 | size_t skeylen; | ||
87 | EVP_PKEY *pkey, *peerkey; | ||
88 | /* NB: assumes pkey, peerkey have been already set up */ | ||
89 | |||
90 | ctx = EVP_PKEY_CTX_new(pkey); | ||
91 | if (!ctx) | ||
92 | /* Error occurred */ | ||
93 | if (EVP_PKEY_derive_init(ctx) <= 0) | ||
94 | /* Error */ | ||
95 | if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0) | ||
96 | /* Error */ | ||
97 | |||
98 | /* Determine buffer length */ | ||
99 | if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0) | ||
100 | /* Error */ | ||
101 | |||
102 | skey = malloc(skeylen); | ||
103 | |||
104 | if (!skey) | ||
105 | /* malloc failure */ | ||
106 | |||
107 | if (EVP_PKEY_derive(ctx, skey, &skeylen) <= 0) | ||
108 | /* Error */ | ||
109 | |||
110 | /* Shared secret is skey bytes written to buffer skey */ | ||
111 | .Ed | ||
112 | .Sh SEE ALSO | ||
113 | .Xr EVP_PKEY_CTX_new 3 , | ||
114 | .Xr EVP_PKEY_decrypt 3 , | ||
115 | .Xr EVP_PKEY_encrypt 3 , | ||
116 | .Xr EVP_PKEY_sign 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. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_encrypt.3 b/src/lib/libcrypto/man/EVP_PKEY_encrypt.3 new file mode 100644 index 0000000000..bda37ef160 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_encrypt.3 | |||
@@ -0,0 +1,117 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_ENCRYPT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_encrypt_init , | ||
6 | .Nm EVP_PKEY_encrypt | ||
7 | .Nd encrypt using a public key algorithm | ||
8 | .Sh SYNOPSIS | ||
9 | .In openssl/evp.h | ||
10 | .Ft int | ||
11 | .Fo EVP_PKEY_encrypt_init | ||
12 | .Fa "EVP_PKEY_CTX *ctx" | ||
13 | .Fc | ||
14 | .Ft int | ||
15 | .Fo EVP_PKEY_encrypt | ||
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_encrypt_init | ||
25 | function initializes a public key algorithm context using key | ||
26 | .Fa ctx->pkey | ||
27 | for an encryption operation. | ||
28 | .Pp | ||
29 | The | ||
30 | .Fn EVP_PKEY_encrypt | ||
31 | function performs a public key encryption operation using | ||
32 | .Fa ctx . | ||
33 | The data to be encrypted 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 encrypted 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_encrypt_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_encrypt | ||
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_encrypt_init | ||
69 | and | ||
70 | .Fn EVP_PKEY_encrypt | ||
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 EXAMPLES | ||
75 | Encrypt 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 public key | ||
86 | */ | ||
87 | ctx = EVP_PKEY_CTX_new(key); | ||
88 | if (!ctx) | ||
89 | /* Error occurred */ | ||
90 | if (EVP_PKEY_encrypt_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_encrypt(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_encrypt(ctx, out, &outlen, in, inlen) <= 0) | ||
105 | /* Error */ | ||
106 | |||
107 | /* Encrypted 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_decrypt 3 , | ||
112 | .Xr EVP_PKEY_derive 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. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_get_default_digest.3 b/src/lib/libcrypto/man/EVP_PKEY_get_default_digest.3 new file mode 100644 index 0000000000..2266adadf3 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_get_default_digest.3 | |||
@@ -0,0 +1,39 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_GET_DEFAULT_DIGEST 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_get_default_digest_nid | ||
6 | .Nd get default signature digest | ||
7 | .Sh SYNOPSIS | ||
8 | .In openssl/evp.h | ||
9 | .Ft int | ||
10 | .Fo EVP_PKEY_get_default_digest_nid | ||
11 | .Fa "EVP_PKEY *pkey" | ||
12 | .Fa "int *pnid" | ||
13 | .Fc | ||
14 | .Sh DESCRIPTION | ||
15 | The | ||
16 | .Fn EVP_PKEY_get_default_digest_nid | ||
17 | function sets | ||
18 | .Fa pnid | ||
19 | to the default message digest NID for the public key signature | ||
20 | operations associated with key | ||
21 | .Fa pkey . | ||
22 | .Pp | ||
23 | For all current standard OpenSSL public key algorithms, SHA1 is returned. | ||
24 | .Sh RETURN VALUES | ||
25 | The | ||
26 | .Fn EVP_PKEY_get_default_digest_nid | ||
27 | function returns 1 if the message digest is advisory (that is other | ||
28 | digests can be used) and 2 if it is mandatory (other digests cannot be | ||
29 | used). | ||
30 | It returns 0 or a negative value for failure. | ||
31 | In particular, a return value of -2 indicates the operation is not | ||
32 | supported by the public key algorithm. | ||
33 | .Sh SEE ALSO | ||
34 | .Xr EVP_PKEY_CTX_new 3 , | ||
35 | .Xr EVP_PKEY_sign 3 , | ||
36 | .Xr EVP_PKEY_verify 3 , | ||
37 | .Xr EVP_PKEY_verify_recover 3 | ||
38 | .Sh HISTORY | ||
39 | This function was first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_keygen.3 b/src/lib/libcrypto/man/EVP_PKEY_keygen.3 new file mode 100644 index 0000000000..8a5c7be0c6 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_keygen.3 | |||
@@ -0,0 +1,235 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_KEYGEN 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_keygen_init , | ||
6 | .Nm EVP_PKEY_keygen , | ||
7 | .Nm EVP_PKEY_paramgen_init , | ||
8 | .Nm EVP_PKEY_paramgen , | ||
9 | .Nm EVP_PKEY_CTX_set_cb , | ||
10 | .Nm EVP_PKEY_CTX_get_cb , | ||
11 | .Nm EVP_PKEY_CTX_get_keygen_info , | ||
12 | .Nm EVP_PKEY_CTX_set_app_data , | ||
13 | .Nm EVP_PKEY_CTX_get_app_data | ||
14 | .Nd key and parameter generation functions | ||
15 | .Sh SYNOPSIS | ||
16 | .In openssl/evp.h | ||
17 | .Ft int | ||
18 | .Fo EVP_PKEY_keygen_init | ||
19 | .Fa "EVP_PKEY_CTX *ctx" | ||
20 | .Fc | ||
21 | .Ft int | ||
22 | .Fo EVP_PKEY_keygen | ||
23 | .Fa "EVP_PKEY_CTX *ctx" | ||
24 | .Fa "EVP_PKEY **ppkey" | ||
25 | .Fc | ||
26 | .Ft int | ||
27 | .Fo EVP_PKEY_paramgen_init | ||
28 | .Fa "EVP_PKEY_CTX *ctx" | ||
29 | .Fc | ||
30 | .Ft int | ||
31 | .Fo EVP_PKEY_paramgen | ||
32 | .Fa "EVP_PKEY_CTX *ctx" | ||
33 | .Fa "EVP_PKEY **ppkey" | ||
34 | .Fc | ||
35 | .Ft typedef int | ||
36 | .Fo EVP_PKEY_gen_cb | ||
37 | .Fa "EVP_PKEY_CTX *ctx" | ||
38 | .Fc | ||
39 | .Ft void | ||
40 | .Fo EVP_PKEY_CTX_set_cb | ||
41 | .Fa "EVP_PKEY_CTX *ctx" | ||
42 | .Fa "EVP_PKEY_gen_cb *cb" | ||
43 | .Fc | ||
44 | .Ft EVP_PKEY_gen_cb * | ||
45 | .Fo EVP_PKEY_CTX_get_cb | ||
46 | .Fa "EVP_PKEY_CTX *ctx" | ||
47 | .Fc | ||
48 | .Ft int | ||
49 | .Fo EVP_PKEY_CTX_get_keygen_info | ||
50 | .Fa "EVP_PKEY_CTX *ctx" | ||
51 | .Fa "int idx" | ||
52 | .Fc | ||
53 | .Ft void | ||
54 | .Fo EVP_PKEY_CTX_set_app_data | ||
55 | .Fa "EVP_PKEY_CTX *ctx" | ||
56 | .Fa "void *data" | ||
57 | .Fc | ||
58 | .Ft void * | ||
59 | .Fo EVP_PKEY_CTX_get_app_data | ||
60 | .Fa "EVP_PKEY_CTX *ctx" | ||
61 | .Fc | ||
62 | .Sh DESCRIPTION | ||
63 | The | ||
64 | .Fn EVP_PKEY_keygen_init | ||
65 | function initializes a public key algorithm context using key | ||
66 | .Fa ctx->pkey | ||
67 | for a key generation operation. | ||
68 | .Pp | ||
69 | The | ||
70 | .Fn EVP_PKEY_keygen | ||
71 | function performs a key generation operation, the generated key is | ||
72 | written to | ||
73 | .Fa ppkey . | ||
74 | .Pp | ||
75 | The functions | ||
76 | .Fn EVP_PKEY_paramgen_init | ||
77 | and | ||
78 | .Fn EVP_PKEY_paramgen | ||
79 | are similar except parameters are generated. | ||
80 | .Pp | ||
81 | The function | ||
82 | .Fn EVP_PKEY_CTX_set_cb | ||
83 | sets the key or parameter generation callback to | ||
84 | .Fa cb . | ||
85 | The function | ||
86 | .Fn EVP_PKEY_CTX_get_cb | ||
87 | returns the key or parameter generation callback. | ||
88 | .Pp | ||
89 | The function | ||
90 | .Fn EVP_PKEY_CTX_get_keygen_info | ||
91 | returns parameters associated with the generation operation. | ||
92 | If | ||
93 | .Fa idx | ||
94 | is -1, the total number of parameters available is returned. | ||
95 | Any non negative value returns the value of that parameter. | ||
96 | .Fn EVP_PKEY_CTX_get_keygen_info | ||
97 | with a non-negative value for | ||
98 | .Fa idx | ||
99 | should only be called within the generation callback. | ||
100 | .Pp | ||
101 | If the callback returns 0, then the key generation operation is aborted | ||
102 | and an error occurs. | ||
103 | This might occur during a time consuming operation where a user clicks | ||
104 | on a "cancel" button. | ||
105 | .Pp | ||
106 | The functions | ||
107 | .Fn EVP_PKEY_CTX_set_app_data | ||
108 | and | ||
109 | .Fn EVP_PKEY_CTX_get_app_data | ||
110 | set and retrieve an opaque pointer. | ||
111 | This can be used to set some application defined value which can be | ||
112 | retrieved in the callback: for example a handle which is used to update | ||
113 | a "progress dialog". | ||
114 | .Pp | ||
115 | After the call to | ||
116 | .Fn EVP_PKEY_keygen_init | ||
117 | or | ||
118 | .Fn EVP_PKEY_paramgen_init , | ||
119 | algorithm specific control operations can be performed to set any | ||
120 | appropriate parameters for the operation. | ||
121 | .Pp | ||
122 | The functions | ||
123 | .Fn EVP_PKEY_keygen | ||
124 | and | ||
125 | .Fn EVP_PKEY_paramgen | ||
126 | can be called more than once on the same context if several operations | ||
127 | are performed using the same parameters. | ||
128 | .Pp | ||
129 | The meaning of the parameters passed to the callback will depend on the | ||
130 | algorithm and the specific implementation of the algorithm. | ||
131 | Some might not give any useful information at all during key or | ||
132 | parameter generation. | ||
133 | Others might not even call the callback. | ||
134 | .Pp | ||
135 | The operation performed by key or parameter generation depends on the | ||
136 | algorithm used. | ||
137 | In some cases (e.g. EC with a supplied named curve) the "generation" | ||
138 | option merely sets the appropriate fields in an | ||
139 | .Vt EVP_PKEY | ||
140 | structure. | ||
141 | .Pp | ||
142 | In OpenSSL, an | ||
143 | .Vt EVP_PKEY | ||
144 | structure containing a private key also contains the public key | ||
145 | components and parameters (if any). | ||
146 | An OpenSSL private key is equivalent to what some libraries call a "key | ||
147 | pair". | ||
148 | A private key can be used in functions which require the use of a public | ||
149 | key or parameters. | ||
150 | .Sh RETURN VALUES | ||
151 | .Fn EVP_PKEY_keygen_init , | ||
152 | .Fn EVP_PKEY_paramgen_init , | ||
153 | .Fn EVP_PKEY_keygen , | ||
154 | and | ||
155 | .Fn EVP_PKEY_paramgen | ||
156 | return 1 for success and 0 or a negative value for failure. | ||
157 | In particular, a return value of -2 indicates the operation is not | ||
158 | supported by the public key algorithm. | ||
159 | .Sh EXAMPLES | ||
160 | Generate a 2048 bit RSA key: | ||
161 | .Bd -literal | ||
162 | #include <openssl/evp.h> | ||
163 | #include <openssl/rsa.h> | ||
164 | |||
165 | EVP_PKEY_CTX *ctx; | ||
166 | EVP_PKEY *pkey = NULL; | ||
167 | ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL); | ||
168 | if (!ctx) | ||
169 | /* Error occurred */ | ||
170 | if (EVP_PKEY_keygen_init(ctx) <= 0) | ||
171 | /* Error */ | ||
172 | if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 2048) <= 0) | ||
173 | /* Error */ | ||
174 | |||
175 | /* Generate key */ | ||
176 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) | ||
177 | /* Error */ | ||
178 | .Ed | ||
179 | .Pp | ||
180 | Generate a key from a set of parameters: | ||
181 | .Bd -literal | ||
182 | #include <openssl/evp.h> | ||
183 | #include <openssl/rsa.h> | ||
184 | |||
185 | EVP_PKEY_CTX *ctx; | ||
186 | EVP_PKEY *pkey = NULL, *param; | ||
187 | /* Assumed param is set up already */ | ||
188 | ctx = EVP_PKEY_CTX_new(param); | ||
189 | if (!ctx) | ||
190 | /* Error occurred */ | ||
191 | if (EVP_PKEY_keygen_init(ctx) <= 0) | ||
192 | /* Error */ | ||
193 | |||
194 | /* Generate key */ | ||
195 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) | ||
196 | /* Error */ | ||
197 | .Ed | ||
198 | .Pp | ||
199 | Example of generation callback for OpenSSL public key implementations: | ||
200 | .Bd -literal | ||
201 | /* Application data is a BIO to output status to */ | ||
202 | |||
203 | EVP_PKEY_CTX_set_app_data(ctx, status_bio); | ||
204 | |||
205 | static int | ||
206 | genpkey_cb(EVP_PKEY_CTX *ctx) | ||
207 | { | ||
208 | char c = '*'; | ||
209 | BIO *b = EVP_PKEY_CTX_get_app_data(ctx); | ||
210 | int p; | ||
211 | |||
212 | p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); | ||
213 | if (p == 0) | ||
214 | c='.'; | ||
215 | if (p == 1) | ||
216 | c='+'; | ||
217 | if (p == 2) | ||
218 | c='*'; | ||
219 | if (p == 3) | ||
220 | c='\en'; | ||
221 | BIO_write(b,&c,1); | ||
222 | (void)BIO_flush(b); | ||
223 | return 1; | ||
224 | } | ||
225 | .Ed | ||
226 | .Sh SEE ALSO | ||
227 | .Xr EVP_PKEY_CTX_new 3 , | ||
228 | .Xr EVP_PKEY_decrypt 3 , | ||
229 | .Xr EVP_PKEY_derive 3 , | ||
230 | .Xr EVP_PKEY_encrypt 3 , | ||
231 | .Xr EVP_PKEY_sign 3 , | ||
232 | .Xr EVP_PKEY_verify 3 , | ||
233 | .Xr EVP_PKEY_verify_recover 3 | ||
234 | .Sh HISTORY | ||
235 | These functions were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_new.3 b/src/lib/libcrypto/man/EVP_PKEY_new.3 new file mode 100644 index 0000000000..155ca9ad24 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_new.3 | |||
@@ -0,0 +1,44 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_NEW 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_new , | ||
6 | .Nm EVP_PKEY_free | ||
7 | .Nd private key allocation functions | ||
8 | .Sh SYNOPSIS | ||
9 | .In openssl/evp.h | ||
10 | .Ft EVP_PKEY * | ||
11 | .Fn EVP_PKEY_new void | ||
12 | .Ft void | ||
13 | .Fo EVP_PKEY_free | ||
14 | .Fa "EVP_PKEY *key" | ||
15 | .Fc | ||
16 | .Sh DESCRIPTION | ||
17 | The | ||
18 | .Vt EVP_PKEY | ||
19 | structure is used by various OpenSSL functions which require a general | ||
20 | private key without reference to any particular algorithm. | ||
21 | .Pp | ||
22 | The | ||
23 | .Fn EVP_PKEY_new | ||
24 | function allocates an empty | ||
25 | .Vt EVP_PKEY | ||
26 | structure. | ||
27 | To add a private key to it, use the functions described in | ||
28 | .Xr EVP_PKEY_set1_RSA 3 . | ||
29 | .Pp | ||
30 | .Fn EVP_PKEY_free | ||
31 | frees up the private key | ||
32 | .Fa key . | ||
33 | .Sh RETURN VALUES | ||
34 | .Fn EVP_PKEY_new | ||
35 | returns either the newly allocated | ||
36 | .Vt EVP_PKEY | ||
37 | structure or | ||
38 | .Dv NULL | ||
39 | if an error occurred. | ||
40 | .Pp | ||
41 | .Fn EVP_PKEY_free | ||
42 | does not return a value. | ||
43 | .Sh SEE ALSO | ||
44 | .Xr EVP_PKEY_set1_RSA 3 | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_print_private.3 b/src/lib/libcrypto/man/EVP_PKEY_print_private.3 new file mode 100644 index 0000000000..d1f627c6a0 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_print_private.3 | |||
@@ -0,0 +1,76 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_PRINT_PRIVATE 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_print_public , | ||
6 | .Nm EVP_PKEY_print_private , | ||
7 | .Nm EVP_PKEY_print_params | ||
8 | .Nd public key algorithm printing routines | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_PKEY_print_public | ||
13 | .Fa "BIO *out" | ||
14 | .Fa "const EVP_PKEY *pkey" | ||
15 | .Fa "int indent" | ||
16 | .Fa "ASN1_PCTX *pctx" | ||
17 | .Fc | ||
18 | .Ft int | ||
19 | .Fo EVP_PKEY_print_private | ||
20 | .Fa "BIO *out" | ||
21 | .Fa "const EVP_PKEY *pkey" | ||
22 | .Fa "int indent" | ||
23 | .Fa "ASN1_PCTX *pctx" | ||
24 | .Fc | ||
25 | .Ft int | ||
26 | .Fo EVP_PKEY_print_params | ||
27 | .Fa "BIO *out" | ||
28 | .Fa "const EVP_PKEY *pkey" | ||
29 | .Fa "int indent" | ||
30 | .Fa "ASN1_PCTX *pctx" | ||
31 | .Fc | ||
32 | .Sh DESCRIPTION | ||
33 | The functions | ||
34 | .Fn EVP_PKEY_print_public , | ||
35 | .Fn EVP_PKEY_print_private , | ||
36 | and | ||
37 | .Fn EVP_PKEY_print_params | ||
38 | print out the public, private or parameter components of key | ||
39 | .Fa pkey , | ||
40 | respectively. | ||
41 | The key is sent to | ||
42 | .Vt BIO | ||
43 | .Fa out | ||
44 | in human readable form. | ||
45 | The parameter | ||
46 | .Fa indent | ||
47 | indicates how far the printout should be indented. | ||
48 | .Pp | ||
49 | The | ||
50 | .Fa pctx | ||
51 | parameter allows the print output to be finely tuned by using ASN1 | ||
52 | printing options. | ||
53 | If | ||
54 | .Fa pctx | ||
55 | is set to | ||
56 | .Dv NULL , | ||
57 | then default values will be used. | ||
58 | Currently, no public key algorithms include any options in the | ||
59 | .Fa pctx | ||
60 | parameter. | ||
61 | .Pp | ||
62 | If the key does not include all the components indicated by the function, | ||
63 | then only those contained in the key will be printed. | ||
64 | For example, passing a public key to | ||
65 | .Fn EVP_PKEY_print_private | ||
66 | will only print the public components. | ||
67 | .Sh RETURN VALUES | ||
68 | These functions all return 1 for success and 0 or a negative value for | ||
69 | failure. | ||
70 | In particular, a return value of -2 indicates the operation is not | ||
71 | supported by the public key algorithm. | ||
72 | .Sh SEE ALSO | ||
73 | .Xr EVP_PKEY_CTX_new 3 , | ||
74 | .Xr EVP_PKEY_keygen 3 | ||
75 | .Sh HISTORY | ||
76 | These functions were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_set1_RSA.3 b/src/lib/libcrypto/man/EVP_PKEY_set1_RSA.3 new file mode 100644 index 0000000000..986918dc2f --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_set1_RSA.3 | |||
@@ -0,0 +1,171 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_SET1_RSA 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_set1_RSA , | ||
6 | .Nm EVP_PKEY_set1_DSA , | ||
7 | .Nm EVP_PKEY_set1_DH , | ||
8 | .Nm EVP_PKEY_set1_EC_KEY , | ||
9 | .Nm EVP_PKEY_get1_RSA , | ||
10 | .Nm EVP_PKEY_get1_DSA , | ||
11 | .Nm EVP_PKEY_get1_DH , | ||
12 | .Nm EVP_PKEY_get1_EC_KEY , | ||
13 | .Nm EVP_PKEY_assign_RSA , | ||
14 | .Nm EVP_PKEY_assign_DSA , | ||
15 | .Nm EVP_PKEY_assign_DH , | ||
16 | .Nm EVP_PKEY_assign_EC_KEY , | ||
17 | .Nm EVP_PKEY_type | ||
18 | .Nd EVP_PKEY assignment functions | ||
19 | .Sh SYNOPSIS | ||
20 | .In openssl/evp.h | ||
21 | .Ft int | ||
22 | .Fo EVP_PKEY_set1_RSA | ||
23 | .Fa "EVP_PKEY *pkey" | ||
24 | .Fa "RSA *key" | ||
25 | .Fc | ||
26 | .Ft int | ||
27 | .Fo EVP_PKEY_set1_DSA | ||
28 | .Fa "EVP_PKEY *pkey" | ||
29 | .Fa "DSA *key" | ||
30 | .Fc | ||
31 | .Ft int | ||
32 | .Fo EVP_PKEY_set1_DH | ||
33 | .Fa "EVP_PKEY *pkey" | ||
34 | .Fa "DH *key" | ||
35 | .Fc | ||
36 | .Ft int | ||
37 | .Fo EVP_PKEY_set1_EC_KEY | ||
38 | .Fa "EVP_PKEY *pkey" | ||
39 | .Fa "EC_KEY *key" | ||
40 | .Fc | ||
41 | .Ft RSA * | ||
42 | .Fo EVP_PKEY_get1_RSA | ||
43 | .Fa "EVP_PKEY *pkey" | ||
44 | .Fc | ||
45 | .Ft DSA * | ||
46 | .Fo EVP_PKEY_get1_DSA | ||
47 | .Fa "EVP_PKEY *pkey" | ||
48 | .Fc | ||
49 | .Ft DH * | ||
50 | .Fo EVP_PKEY_get1_DH | ||
51 | .Fa "EVP_PKEY *pkey" | ||
52 | .Fc | ||
53 | .Ft EC_KEY * | ||
54 | .Fo EVP_PKEY_get1_EC_KEY | ||
55 | .Fa "EVP_PKEY *pkey" | ||
56 | .Fc | ||
57 | .Ft int | ||
58 | .Fo EVP_PKEY_assign_RSA | ||
59 | .Fa "EVP_PKEY *pkey" | ||
60 | .Fa "RSA *key" | ||
61 | .Fc | ||
62 | .Ft int | ||
63 | .Fo EVP_PKEY_assign_DSA | ||
64 | .Fa "EVP_PKEY *pkey" | ||
65 | .Fa "DSA *key" | ||
66 | .Fc | ||
67 | .Ft int | ||
68 | .Fo EVP_PKEY_assign_DH | ||
69 | .Fa "EVP_PKEY *pkey" | ||
70 | .Fa "DH *key" | ||
71 | .Fc | ||
72 | .Ft int | ||
73 | .Fo EVP_PKEY_assign_EC_KEY | ||
74 | .Fa "EVP_PKEY *pkey" | ||
75 | .Fa "EC_KEY *key" | ||
76 | .Fc | ||
77 | .Ft int | ||
78 | .Fo EVP_PKEY_type | ||
79 | .Fa "int type" | ||
80 | .Fc | ||
81 | .Sh DESCRIPTION | ||
82 | .Fn EVP_PKEY_set1_RSA , | ||
83 | .Fn EVP_PKEY_set1_DSA , | ||
84 | .Fn EVP_PKEY_set1_DH , | ||
85 | and | ||
86 | .Fn EVP_PKEY_set1_EC_KEY | ||
87 | set the key referenced by | ||
88 | .Fa pkey | ||
89 | to | ||
90 | .Fa key . | ||
91 | .Pp | ||
92 | .Fn EVP_PKEY_get1_RSA , | ||
93 | .Fn EVP_PKEY_get1_DSA , | ||
94 | .Fn EVP_PKEY_get1_DH , | ||
95 | and | ||
96 | .Fn EVP_PKEY_get1_EC_KEY | ||
97 | return the key referenced in | ||
98 | .Fa pkey | ||
99 | or | ||
100 | .Dv NULL | ||
101 | if the key is not of the correct type. | ||
102 | .Pp | ||
103 | .Fn EVP_PKEY_assign_RSA , | ||
104 | .Fn EVP_PKEY_assign_DSA , | ||
105 | .Fn EVP_PKEY_assign_DH , | ||
106 | and | ||
107 | .Fn EVP_PKEY_assign_EC_KEY | ||
108 | also set the referenced key to | ||
109 | .Fa key ; | ||
110 | however these use the supplied | ||
111 | .Fa key | ||
112 | internally and so | ||
113 | .Fa key | ||
114 | will be freed when the parent | ||
115 | .Fa pkey | ||
116 | is freed. | ||
117 | .Pp | ||
118 | .Fn EVP_PKEY_type | ||
119 | returns the type of key corresponding to the value | ||
120 | .Fa type . | ||
121 | The type of a key can be obtained with | ||
122 | .Fn EVP_PKEY_type pkey->type . | ||
123 | The return value will be | ||
124 | .Dv EVP_PKEY_RSA , | ||
125 | .Dv EVP_PKEY_DSA , | ||
126 | .Dv EVP_PKEY_DH , | ||
127 | or | ||
128 | .Dv EVP_PKEY_EC | ||
129 | for the corresponding key types or | ||
130 | .Dv NID_undef | ||
131 | if the key type is unassigned. | ||
132 | .Pp | ||
133 | In accordance with the OpenSSL naming convention, the key obtained from | ||
134 | or assigned to | ||
135 | .Fa pkey | ||
136 | using the | ||
137 | .Sy 1 | ||
138 | functions must be freed as well as | ||
139 | .Fa pkey . | ||
140 | .Pp | ||
141 | .Fn EVP_PKEY_assign_RSA , | ||
142 | .Fn EVP_PKEY_assign_DSA , | ||
143 | .Fn EVP_PKEY_assign_DH , | ||
144 | and | ||
145 | .Fn EVP_PKEY_assign_EC_KEY | ||
146 | are implemented as macros. | ||
147 | .Sh RETURN VALUES | ||
148 | .Fn EVP_PKEY_set1_RSA , | ||
149 | .Fn EVP_PKEY_set1_DSA , | ||
150 | .Fn EVP_PKEY_set1_DH , | ||
151 | and | ||
152 | .Fn EVP_PKEY_set1_EC_KEY | ||
153 | return 1 for success or 0 for failure. | ||
154 | .Pp | ||
155 | .Fn EVP_PKEY_get1_RSA , | ||
156 | .Fn EVP_PKEY_get1_DSA , | ||
157 | .Fn EVP_PKEY_get1_DH , | ||
158 | and | ||
159 | .Fn EVP_PKEY_get1_EC_KEY | ||
160 | return the referenced key or | ||
161 | .Dv NULL | ||
162 | if an error occurred. | ||
163 | .Pp | ||
164 | .Fn EVP_PKEY_assign_RSA , | ||
165 | .Fn EVP_PKEY_assign_DSA , | ||
166 | .Fn EVP_PKEY_assign_DH , | ||
167 | and | ||
168 | .Fn EVP_PKEY_assign_EC_KEY | ||
169 | return 1 for success and 0 for failure. | ||
170 | .Sh SEE ALSO | ||
171 | .Xr EVP_PKEY_new 3 | ||
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. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_verify.3 b/src/lib/libcrypto/man/EVP_PKEY_verify.3 new file mode 100644 index 0000000000..bec3283349 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_verify.3 | |||
@@ -0,0 +1,109 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_VERIFY 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_verify_init , | ||
6 | .Nm EVP_PKEY_verify | ||
7 | .Nd signature verification using a public key algorithm | ||
8 | .Sh SYNOPSIS | ||
9 | .In openssl/evp.h | ||
10 | .Ft int | ||
11 | .Fo EVP_PKEY_verify_init | ||
12 | .Fa "EVP_PKEY_CTX *ctx" | ||
13 | .Fc | ||
14 | .Ft int | ||
15 | .Fo EVP_PKEY_verify | ||
16 | .Fa "EVP_PKEY_CTX *ctx" | ||
17 | .Fa "const 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_verify_init | ||
25 | function initializes a public key algorithm context using key | ||
26 | .Fa ctx->pkey | ||
27 | for a signature verification operation. | ||
28 | .Pp | ||
29 | The | ||
30 | .Fn EVP_PKEY_verify | ||
31 | function performs a public key verification operation using | ||
32 | .Fa ctx . | ||
33 | The signature is specified using the | ||
34 | .Fa sig | ||
35 | and | ||
36 | .Fa siglen | ||
37 | parameters. | ||
38 | The verified data (i.e. the data believed originally signed) is | ||
39 | specified using the | ||
40 | .Fa tbs | ||
41 | and | ||
42 | .Fa tbslen | ||
43 | parameters. | ||
44 | .Pp | ||
45 | After the call to | ||
46 | .Fn EVP_PKEY_verify_init , | ||
47 | algorithm specific control operations can be performed to set any | ||
48 | appropriate parameters for the operation. | ||
49 | .Pp | ||
50 | The function | ||
51 | .Fn EVP_PKEY_verify | ||
52 | can be called more than once on the same context if several operations | ||
53 | are performed using the same parameters. | ||
54 | .Sh RETURN VALUES | ||
55 | .Fn EVP_PKEY_verify_init | ||
56 | and | ||
57 | .Fn EVP_PKEY_verify | ||
58 | return 1 if the verification was successful and 0 if it failed. | ||
59 | Unlike other functions the return value 0 from | ||
60 | .Fn EVP_PKEY_verify | ||
61 | only indicates that the signature did not verify successfully. | ||
62 | That is, | ||
63 | .Fa tbs | ||
64 | did not match the original data or the signature was of invalid form. | ||
65 | It is not an indication of a more serious error. | ||
66 | .Pp | ||
67 | A negative value indicates an error other that signature verification | ||
68 | failure. | ||
69 | In particular, a return value of -2 indicates the operation is not | ||
70 | supported by the public key algorithm. | ||
71 | .Sh EXAMPLES | ||
72 | Verify signature using PKCS#1 and SHA256 digest: | ||
73 | .Bd -literal | ||
74 | #include <openssl/evp.h> | ||
75 | #include <openssl/rsa.h> | ||
76 | |||
77 | EVP_PKEY_CTX *ctx; | ||
78 | unsigned char *md, *sig; | ||
79 | size_t mdlen, siglen; | ||
80 | EVP_PKEY *verify_key; | ||
81 | /* NB: assumes verify_key, sig, siglen md and mdlen are already set up | ||
82 | * and that verify_key is an RSA public key | ||
83 | */ | ||
84 | ctx = EVP_PKEY_CTX_new(verify_key); | ||
85 | if (!ctx) | ||
86 | /* Error occurred */ | ||
87 | if (EVP_PKEY_verify_init(ctx) <= 0) | ||
88 | /* Error */ | ||
89 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) | ||
90 | /* Error */ | ||
91 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) | ||
92 | /* Error */ | ||
93 | |||
94 | /* Perform operation */ | ||
95 | ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen); | ||
96 | |||
97 | /* ret == 1 indicates success, 0 verify failure and < 0 for some | ||
98 | * other error. | ||
99 | */ | ||
100 | .Ed | ||
101 | .Sh SEE ALSO | ||
102 | .Xr EVP_PKEY_CTX_new 3 , | ||
103 | .Xr EVP_PKEY_decrypt 3 , | ||
104 | .Xr EVP_PKEY_derive 3 , | ||
105 | .Xr EVP_PKEY_encrypt 3 , | ||
106 | .Xr EVP_PKEY_sign 3 , | ||
107 | .Xr EVP_PKEY_verify_recover 3 | ||
108 | .Sh HISTORY | ||
109 | These functions were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_PKEY_verify_recover.3 b/src/lib/libcrypto/man/EVP_PKEY_verify_recover.3 new file mode 100644 index 0000000000..fc26152ae6 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_PKEY_verify_recover.3 | |||
@@ -0,0 +1,131 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_PKEY_VERIFY_RECOVER 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_PKEY_verify_recover_init , | ||
6 | .Nm EVP_PKEY_verify_recover | ||
7 | .Nd recover signature using a public key algorithm | ||
8 | .Sh SYNOPSIS | ||
9 | .In openssl/evp.h | ||
10 | .Ft int | ||
11 | .Fo EVP_PKEY_verify_recover_init | ||
12 | .Fa "EVP_PKEY_CTX *ctx" | ||
13 | .Fc | ||
14 | .Ft int | ||
15 | .Fo EVP_PKEY_verify_recover | ||
16 | .Fa "EVP_PKEY_CTX *ctx" | ||
17 | .Fa "unsigned char *rout" | ||
18 | .Fa "size_t *routlen" | ||
19 | .Fa "const unsigned char *sig" | ||
20 | .Fa "size_t siglen" | ||
21 | .Fc | ||
22 | .Sh DESCRIPTION | ||
23 | The | ||
24 | .Fn EVP_PKEY_verify_recover_init | ||
25 | function initializes a public key algorithm context using key | ||
26 | .Fa ctx->pkey | ||
27 | for a verify recover operation. | ||
28 | .Pp | ||
29 | The | ||
30 | .Fn EVP_PKEY_verify_recover | ||
31 | function recovers signed data using | ||
32 | .Fa ctx . | ||
33 | The signature is specified using the | ||
34 | .Fa sig | ||
35 | and | ||
36 | .Fa siglen | ||
37 | parameters. | ||
38 | If | ||
39 | .Fa rout | ||
40 | is | ||
41 | .Dv NULL , | ||
42 | then the maximum size of the output buffer is written to the | ||
43 | .Fa routlen | ||
44 | parameter. | ||
45 | If | ||
46 | .Fa rout | ||
47 | is not | ||
48 | .Dv NULL , | ||
49 | then before the call the | ||
50 | .Fa routlen | ||
51 | parameter should contain the length of the | ||
52 | .Fa rout | ||
53 | buffer. | ||
54 | If the call is successful, recovered data is written to | ||
55 | .Fa rout | ||
56 | and the amount of data written to | ||
57 | .Fa routlen . | ||
58 | .Pp | ||
59 | Normally an application is only interested in whether a signature | ||
60 | verification operation is successful. | ||
61 | In those cases, the | ||
62 | .Xr EVP_verify 3 | ||
63 | function should be used. | ||
64 | .Pp | ||
65 | Sometimes however it is useful to obtain the data originally signed | ||
66 | using a signing operation. | ||
67 | Only certain public key algorithms can recover a signature in this way | ||
68 | (for example RSA in PKCS padding mode). | ||
69 | .Pp | ||
70 | After the call to | ||
71 | .Fn EVP_PKEY_verify_recover_init , | ||
72 | algorithm specific control operations can be performed to set any | ||
73 | appropriate parameters for the operation. | ||
74 | .Pp | ||
75 | The function | ||
76 | .Fn EVP_PKEY_verify_recover | ||
77 | can be called more than once on the same context if several operations | ||
78 | are performed using the same parameters. | ||
79 | .Sh RETURN VALUES | ||
80 | .Fn EVP_PKEY_verify_recover_init | ||
81 | and | ||
82 | .Fn EVP_PKEY_verify_recover | ||
83 | return 1 for success and 0 or a negative value for failure. | ||
84 | In particular, a return value of -2 indicates the operation is not | ||
85 | supported by the public key algorithm. | ||
86 | .Sh EXAMPLES | ||
87 | Recover digest originally signed using PKCS#1 and SHA256 digest: | ||
88 | .Bd -literal | ||
89 | #include <openssl/evp.h> | ||
90 | #include <openssl/rsa.h> | ||
91 | |||
92 | EVP_PKEY_CTX *ctx; | ||
93 | unsigned char *rout, *sig; | ||
94 | size_t routlen, siglen; | ||
95 | EVP_PKEY *verify_key; | ||
96 | /* NB: assumes verify_key, sig and siglen are already set up | ||
97 | * and that verify_key is an RSA public key | ||
98 | */ | ||
99 | ctx = EVP_PKEY_CTX_new(verify_key); | ||
100 | if (!ctx) | ||
101 | /* Error occurred */ | ||
102 | if (EVP_PKEY_verify_recover_init(ctx) <= 0) | ||
103 | /* Error */ | ||
104 | if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) | ||
105 | /* Error */ | ||
106 | if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) | ||
107 | /* Error */ | ||
108 | |||
109 | /* Determine buffer length */ | ||
110 | if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0) | ||
111 | /* Error */ | ||
112 | |||
113 | rout = malloc(routlen); | ||
114 | |||
115 | if (!rout) | ||
116 | /* malloc failure */ | ||
117 | |||
118 | if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0) | ||
119 | /* Error */ | ||
120 | |||
121 | /* Recovered data is routlen bytes written to buffer rout */ | ||
122 | .Ed | ||
123 | .Sh SEE ALSO | ||
124 | .Xr EVP_PKEY_CTX_new 3 , | ||
125 | .Xr EVP_PKEY_encrypt 3 , | ||
126 | .Xr EVP_PKEY_decrypt 3 , | ||
127 | .Xr EVP_PKEY_sign 3 , | ||
128 | .Xr EVP_PKEY_verify 3 , | ||
129 | .Xr EVP_PKEY_derive 3 | ||
130 | .Sh HISTORY | ||
131 | These functions were first added to OpenSSL 1.0.0. | ||
diff --git a/src/lib/libcrypto/man/EVP_SealInit.3 b/src/lib/libcrypto/man/EVP_SealInit.3 new file mode 100644 index 0000000000..9511111486 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_SealInit.3 | |||
@@ -0,0 +1,131 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_SEALINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_SealInit , | ||
6 | .Nm EVP_SealUpdate , | ||
7 | .Nm EVP_SealFinal | ||
8 | .Nd EVP envelope encryption | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_SealInit | ||
13 | .Fa "EVP_CIPHER_CTX *ctx" | ||
14 | .Fa "const EVP_CIPHER *type" | ||
15 | .Fa "unsigned char **ek" | ||
16 | .Fa "int *ekl" | ||
17 | .Fa "unsigned char *iv" | ||
18 | .Fa "EVP_PKEY **pubk" | ||
19 | .Fa "int npubk" | ||
20 | .Fc | ||
21 | .Ft int | ||
22 | .Fo EVP_SealUpdate | ||
23 | .Fa "EVP_CIPHER_CTX *ctx" | ||
24 | .Fa "unsigned char *out" | ||
25 | .Fa "int *outl" | ||
26 | .Fa "unsigned char *in" | ||
27 | .Fa "int inl" | ||
28 | .Fc | ||
29 | .Ft int | ||
30 | .Fo EVP_SealFinal | ||
31 | .Fa "EVP_CIPHER_CTX *ctx" | ||
32 | .Fa "unsigned char *out" | ||
33 | .Fa "int *outl" | ||
34 | .Fc | ||
35 | .Sh DESCRIPTION | ||
36 | The EVP envelope routines are a high level interface to envelope | ||
37 | encryption. | ||
38 | They generate a random key and IV (if required) then "envelope" it by | ||
39 | using public key encryption. | ||
40 | Data can then be encrypted using this key. | ||
41 | .Pp | ||
42 | .Fn EVP_SealInit | ||
43 | initializes a cipher context | ||
44 | .Fa ctx | ||
45 | for encryption with cipher | ||
46 | .Fa type | ||
47 | using a random secret key and IV. | ||
48 | .Fa type | ||
49 | is normally supplied by a function such as | ||
50 | .Fn EVP_aes_256_cbc 3 ; | ||
51 | see | ||
52 | .Xr EVP_EncryptInit 3 | ||
53 | for details. | ||
54 | The secret key is encrypted using one or more public keys. | ||
55 | This allows the same encrypted data to be decrypted using any of | ||
56 | the corresponding private keys. | ||
57 | .Fa ek | ||
58 | is an array of buffers where the public key encrypted secret key will be | ||
59 | written. | ||
60 | Each buffer must contain enough room for the corresponding encrypted | ||
61 | key: that is | ||
62 | .Fa ek[i] | ||
63 | must have room for | ||
64 | .Fn EVP_PKEY_size pubk[i] | ||
65 | bytes. | ||
66 | The actual size of each encrypted secret key is written to the array | ||
67 | .Fa ekl . | ||
68 | .Fa pubk | ||
69 | is an array of | ||
70 | .Fa npubk | ||
71 | public keys. | ||
72 | .Pp | ||
73 | The | ||
74 | .Fa iv | ||
75 | parameter is a buffer where the generated IV is written to. | ||
76 | It must contain enough room for the corresponding cipher's IV, as | ||
77 | determined by (for example) | ||
78 | .Fn EVP_CIPHER_iv_length type . | ||
79 | .Pp | ||
80 | If the cipher does not require an IV then the | ||
81 | .Fa iv | ||
82 | parameter is ignored and can be | ||
83 | .Dv NULL . | ||
84 | .Pp | ||
85 | .Fn EVP_SealUpdate | ||
86 | and | ||
87 | .Fn EVP_SealFinal | ||
88 | have exactly the same properties as the | ||
89 | .Xr EVP_EncryptUpdate 3 | ||
90 | and | ||
91 | .Xr EVP_EncryptFinal 3 | ||
92 | routines. | ||
93 | .Pp | ||
94 | The public key must be RSA because it is the only OpenSSL public key | ||
95 | algorithm that supports key transport. | ||
96 | .Pp | ||
97 | Envelope encryption is the usual method of using public key encryption | ||
98 | on large amounts of data. | ||
99 | This is because public key encryption is slow but symmetric encryption | ||
100 | is fast. | ||
101 | So symmetric encryption is used for bulk encryption and the small random | ||
102 | symmetric key used is transferred using public key encryption. | ||
103 | .Pp | ||
104 | It is possible to call | ||
105 | .Fn EVP_SealInit | ||
106 | twice in the same way as | ||
107 | .Xr EVP_EncryptInit 3 . | ||
108 | The first call should have | ||
109 | .Fa npubk | ||
110 | set to 0 and (after setting any cipher parameters) it should be called | ||
111 | again with | ||
112 | .Fa type | ||
113 | set to NULL. | ||
114 | .Sh RETURN VALUES | ||
115 | .Fn EVP_SealInit | ||
116 | returns 0 on error or | ||
117 | .Fa npubk | ||
118 | if successful. | ||
119 | .Pp | ||
120 | .Fn EVP_SealUpdate | ||
121 | and | ||
122 | .Fn EVP_SealFinal | ||
123 | return 1 for success and 0 for failure. | ||
124 | .Sh SEE ALSO | ||
125 | .Xr evp 3 , | ||
126 | .Xr EVP_EncryptInit 3 , | ||
127 | .Xr EVP_OpenInit 3 , | ||
128 | .Xr rand 3 | ||
129 | .Sh HISTORY | ||
130 | .Fn EVP_SealFinal | ||
131 | did not return a value before OpenSSL 0.9.7. | ||
diff --git a/src/lib/libcrypto/man/EVP_SignInit.3 b/src/lib/libcrypto/man/EVP_SignInit.3 new file mode 100644 index 0000000000..22f81148a2 --- /dev/null +++ b/src/lib/libcrypto/man/EVP_SignInit.3 | |||
@@ -0,0 +1,167 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_SIGNINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_SignInit , | ||
6 | .Nm EVP_SignUpdate , | ||
7 | .Nm EVP_SignFinal , | ||
8 | .Nm EVP_PKEY_size | ||
9 | .Nd EVP signing functions | ||
10 | .Sh SYNOPSIS | ||
11 | .In openssl/evp.h | ||
12 | .Ft int | ||
13 | .Fo EVP_SignInit_ex | ||
14 | .Fa "EVP_MD_CTX *ctx" | ||
15 | .Fa "const EVP_MD *type" | ||
16 | .Fa "ENGINE *impl" | ||
17 | .Fc | ||
18 | .Ft int | ||
19 | .Fo EVP_SignUpdate | ||
20 | .Fa "EVP_MD_CTX *ctx" | ||
21 | .Fa "const void *d" | ||
22 | .Fa "unsigned int cnt" | ||
23 | .Fc | ||
24 | .Ft int | ||
25 | .Fo EVP_SignFinal | ||
26 | .Fa "EVP_MD_CTX *ctx" | ||
27 | .Fa "unsigned char *sig" | ||
28 | .Fa "unsigned int *s" | ||
29 | .Fa "EVP_PKEY *pkey" | ||
30 | .Fc | ||
31 | .Ft void | ||
32 | .Fo EVP_SignInit | ||
33 | .Fa "EVP_MD_CTX *ctx" | ||
34 | .Fa "const EVP_MD *type" | ||
35 | .Fc | ||
36 | .Ft int | ||
37 | .Fo EVP_PKEY_size | ||
38 | .Fa "EVP_PKEY *pkey" | ||
39 | .Fc | ||
40 | .Sh DESCRIPTION | ||
41 | The EVP signature routines are a high level interface to digital | ||
42 | signatures. | ||
43 | .Pp | ||
44 | .Fn EVP_SignInit_ex | ||
45 | sets up a signing context | ||
46 | .Fa ctx | ||
47 | to use the digest | ||
48 | .Fa type | ||
49 | from | ||
50 | .Vt ENGINE | ||
51 | .Fa impl . | ||
52 | .Fa ctx | ||
53 | must be initialized with | ||
54 | .Xr EVP_MD_CTX_init 3 | ||
55 | before calling this function. | ||
56 | .Pp | ||
57 | .Fn EVP_SignUpdate | ||
58 | hashes | ||
59 | .Fa cnt | ||
60 | bytes of data at | ||
61 | .Fa d | ||
62 | into the signature context | ||
63 | .Fa ctx . | ||
64 | This function can be called several times on the same | ||
65 | .Fa ctx | ||
66 | to include additional data. | ||
67 | .Pp | ||
68 | .Fn EVP_SignFinal | ||
69 | signs the data in | ||
70 | .Fa ctx | ||
71 | using the private key | ||
72 | .Fa pkey | ||
73 | and places the signature in | ||
74 | .Fa sig . | ||
75 | .Fa sig | ||
76 | must be at least | ||
77 | .Fn EVP_PKEY_size pkey | ||
78 | bytes in size. | ||
79 | .Fa s | ||
80 | is an OUT parameter, and not used as an IN parameter. | ||
81 | The number of bytes of data written (i.e. | ||
82 | the length of the signature) will be written to the integer at | ||
83 | .Fa s . | ||
84 | At most | ||
85 | .Fn EVP_PKEY_size pkey | ||
86 | bytes will be written. | ||
87 | .Pp | ||
88 | .Fn EVP_SignInit | ||
89 | initializes a signing context | ||
90 | .Fa ctx | ||
91 | to use the default implementation of digest | ||
92 | .Fa type . | ||
93 | .Pp | ||
94 | .Fn EVP_PKEY_size | ||
95 | returns the maximum size of a signature in bytes. | ||
96 | The actual signature returned by | ||
97 | .Fn EVP_SignFinal | ||
98 | may be smaller. | ||
99 | .Pp | ||
100 | The EVP interface to digital signatures should almost always be | ||
101 | used in preference to the low level interfaces. | ||
102 | This is because the code then becomes transparent to the algorithm used | ||
103 | and much more flexible. | ||
104 | .Pp | ||
105 | Due to the link between message digests and public key algorithms the | ||
106 | correct digest algorithm must be used with the correct public key type. | ||
107 | A list of algorithms and associated public key algorithms appears in | ||
108 | .Xr EVP_DigestInit 3 . | ||
109 | .Pp | ||
110 | The call to | ||
111 | .Fn EVP_SignFinal | ||
112 | internally finalizes a copy of the digest context. | ||
113 | This means that calls to | ||
114 | .Fn EVP_SignUpdate | ||
115 | and | ||
116 | .Fn EVP_SignFinal | ||
117 | can be called later to digest and sign additional data. | ||
118 | .Pp | ||
119 | Since only a copy of the digest context is ever finalized, the context | ||
120 | must be cleaned up after use by calling | ||
121 | .Xr EVP_MD_CTX_cleanup 3 | ||
122 | or a memory leak will occur. | ||
123 | .Sh RETURN VALUES | ||
124 | .Fn EVP_SignInit_ex , | ||
125 | .Fn EVP_SignUpdate , | ||
126 | and | ||
127 | .Fn EVP_SignFinal | ||
128 | return 1 for success and 0 for failure. | ||
129 | .Pp | ||
130 | .Fn EVP_PKEY_size | ||
131 | returns the maximum size of a signature in bytes. | ||
132 | .Pp | ||
133 | The error codes can be obtained by | ||
134 | .Xr ERR_get_error 3 . | ||
135 | .Sh SEE ALSO | ||
136 | .Xr ERR 3 , | ||
137 | .Xr evp 3 , | ||
138 | .Xr EVP_DigestInit 3 , | ||
139 | .Xr EVP_VerifyInit 3 | ||
140 | .Sh HISTORY | ||
141 | .Fn EVP_SignInit , | ||
142 | .Fn EVP_SignUpdate , | ||
143 | and | ||
144 | .Fn EVP_SignFinal | ||
145 | are available in all versions of SSLeay and OpenSSL. | ||
146 | .Pp | ||
147 | .Fn EVP_SignInit_ex | ||
148 | was added in OpenSSL 0.9.7. | ||
149 | .Sh BUGS | ||
150 | Older versions of this documentation wrongly stated that calls to | ||
151 | .Fn EVP_SignUpdate | ||
152 | could not be made after calling | ||
153 | .Fn EVP_SignFinal . | ||
154 | .Pp | ||
155 | Since the private key is passed in the call to | ||
156 | .Fn EVP_SignFinal | ||
157 | any error relating to the private key (for example an unsuitable key and | ||
158 | digest combination) will not be indicated until after potentially large | ||
159 | amounts of data have been passed through | ||
160 | .Fn EVP_SignUpdate . | ||
161 | .Pp | ||
162 | It is not possible to change the signing parameters using these | ||
163 | function. | ||
164 | .Pp | ||
165 | The previous two bugs are fixed in the newer | ||
166 | .Xr EVP_SignDigest* 3 | ||
167 | function. | ||
diff --git a/src/lib/libcrypto/man/EVP_VerifyInit.3 b/src/lib/libcrypto/man/EVP_VerifyInit.3 new file mode 100644 index 0000000000..b1635d4cac --- /dev/null +++ b/src/lib/libcrypto/man/EVP_VerifyInit.3 | |||
@@ -0,0 +1,146 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_VERIFYINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_VerifyInit , | ||
6 | .Nm EVP_VerifyUpdate , | ||
7 | .Nm EVP_VerifyFinal | ||
8 | .Nd EVP signature verification functions | ||
9 | .Sh SYNOPSIS | ||
10 | .In openssl/evp.h | ||
11 | .Ft int | ||
12 | .Fo EVP_VerifyInit_ex | ||
13 | .Fa "EVP_MD_CTX *ctx" | ||
14 | .Fa "const EVP_MD *type" | ||
15 | .Fa "ENGINE *impl" | ||
16 | .Fc | ||
17 | .Ft int | ||
18 | .Fo EVP_VerifyUpdate | ||
19 | .Fa "EVP_MD_CTX *ctx" | ||
20 | .Fa "const void *d" | ||
21 | .Fa "unsigned int cnt" | ||
22 | .Fc | ||
23 | .Ft int | ||
24 | .Fo EVP_VerifyFinal | ||
25 | .Fa "EVP_MD_CTX *ctx" | ||
26 | .Fa "unsigned char *sigbuf" | ||
27 | .Fa "unsigned int siglen" | ||
28 | .Fa "EVP_PKEY *pkey" | ||
29 | .Fc | ||
30 | .Ft int | ||
31 | .Fo EVP_VerifyInit | ||
32 | .Fa "EVP_MD_CTX *ctx" | ||
33 | .Fa "const EVP_MD *type" | ||
34 | .Fc | ||
35 | .Sh DESCRIPTION | ||
36 | The EVP signature verification routines are a high level interface to | ||
37 | digital signatures. | ||
38 | .Pp | ||
39 | .Fn EVP_VerifyInit_ex | ||
40 | sets up a verification context | ||
41 | .Fa ctx | ||
42 | to use the digest | ||
43 | .Fa type | ||
44 | from | ||
45 | .Vt ENGINE | ||
46 | .Fa impl . | ||
47 | .Fa ctx | ||
48 | must be initialized by calling | ||
49 | .Xr EVP_MD_CTX_init 3 | ||
50 | before calling this function. | ||
51 | .Pp | ||
52 | .Fn EVP_VerifyUpdate | ||
53 | hashes | ||
54 | .Fa cnt | ||
55 | bytes of data at | ||
56 | .Fa d | ||
57 | into the verification context | ||
58 | .Fa ctx . | ||
59 | This function can be called several times on the same | ||
60 | .Fa ctx | ||
61 | to include additional data. | ||
62 | .Pp | ||
63 | .Fn EVP_VerifyFinal | ||
64 | verifies the data in | ||
65 | .Fa ctx | ||
66 | using the public key | ||
67 | .Fa pkey | ||
68 | and against the | ||
69 | .Fa siglen | ||
70 | bytes at | ||
71 | .Fa sigbuf . | ||
72 | .Pp | ||
73 | .Fn EVP_VerifyInit | ||
74 | initializes a verification context | ||
75 | .Fa ctx | ||
76 | to use the default implementation of digest | ||
77 | .Fa type . | ||
78 | .Pp | ||
79 | The EVP interface to digital signatures should almost always be | ||
80 | used in preference to the low level interfaces. | ||
81 | This is because the code then becomes transparent to the algorithm used | ||
82 | and much more flexible. | ||
83 | .Pp | ||
84 | Due to the link between message digests and public key algorithms, the | ||
85 | correct digest algorithm must be used with the correct public key type. | ||
86 | A list of algorithms and associated public key algorithms appears in | ||
87 | .Xr EVP_DigestInit 3 . | ||
88 | .Pp | ||
89 | The call to | ||
90 | .Fn EVP_VerifyFinal | ||
91 | internally finalizes a copy of the digest context. | ||
92 | This means that calls to | ||
93 | .Fn EVP_VerifyUpdate | ||
94 | and | ||
95 | .Fn EVP_VerifyFinal | ||
96 | can be called later to digest and verify additional data. | ||
97 | .Pp | ||
98 | Since only a copy of the digest context is ever finalized, the context | ||
99 | must be cleaned up after use by calling | ||
100 | .Xr EVP_MD_CTX_cleanup 3 , | ||
101 | or a memory leak will occur. | ||
102 | .Sh RETURN VALUES | ||
103 | .Fn EVP_VerifyInit_ex | ||
104 | and | ||
105 | .Fn EVP_VerifyUpdate | ||
106 | return 1 for success and 0 for failure. | ||
107 | .Pp | ||
108 | .Fn EVP_VerifyFinal | ||
109 | returns 1 for a correct signature, 0 for failure, and -1 if some other | ||
110 | error occurred. | ||
111 | .Pp | ||
112 | The error codes can be obtained by | ||
113 | .Xr ERR_get_error 3 . | ||
114 | .Sh SEE ALSO | ||
115 | .Xr ERR 3 , | ||
116 | .Xr evp 3 , | ||
117 | .Xr EVP_DigestInit 3 , | ||
118 | .Xr EVP_SignInit 3 | ||
119 | .Sh HISTORY | ||
120 | .Fn EVP_VerifyInit , | ||
121 | .Fn EVP_VerifyUpdate , | ||
122 | and | ||
123 | .Fn EVP_VerifyFinal | ||
124 | are available in all versions of SSLeay and OpenSSL. | ||
125 | .Pp | ||
126 | .Fn EVP_VerifyInit_ex | ||
127 | was added in OpenSSL 0.9.7. | ||
128 | .Sh BUGS | ||
129 | Older versions of this documentation wrongly stated that calls to | ||
130 | .Fn EVP_VerifyUpdate | ||
131 | could not be made after calling | ||
132 | .Fn EVP_VerifyFinal . | ||
133 | .Pp | ||
134 | Since the public key is passed in the call to | ||
135 | .Xr EVP_SignFinal 3 , | ||
136 | any error relating to the private key (for example an unsuitable key and | ||
137 | digest combination) will not be indicated until after potentially large | ||
138 | amounts of data have been passed through | ||
139 | .Xr EVP_SignUpdate 3 . | ||
140 | .Pp | ||
141 | It is not possible to change the signing parameters using these | ||
142 | functions. | ||
143 | .Pp | ||
144 | The previous two bugs are fixed in the newer functions of the | ||
145 | .Xr EVP_DigestVerifyInit 3 | ||
146 | family. | ||
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile index 5d19e023ab..f4fd152ff7 100644 --- a/src/lib/libcrypto/man/Makefile +++ b/src/lib/libcrypto/man/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.37 2016/11/02 15:23:41 schwarze Exp $ | 1 | # $OpenBSD: Makefile,v 1.38 2016/11/03 09:35:34 schwarze Exp $ |
2 | 2 | ||
3 | .include <bsd.own.mk> # for NOMAN | 3 | .include <bsd.own.mk> # for NOMAN |
4 | 4 | ||
@@ -92,14 +92,6 @@ MAN= \ | |||
92 | ERR_remove_state.3 \ | 92 | ERR_remove_state.3 \ |
93 | ERR_set_mark.3 \ | 93 | ERR_set_mark.3 \ |
94 | EVP_AEAD_CTX_init.3 \ | 94 | EVP_AEAD_CTX_init.3 \ |
95 | UI_new.3 \ | ||
96 | bn_dump.3 \ | ||
97 | crypto.3 \ | ||
98 | d2i_PKCS8PrivateKey_bio.3 \ | ||
99 | des_read_pw.3 \ | ||
100 | lh_new.3 \ | ||
101 | |||
102 | GENMAN= \ | ||
103 | EVP_BytesToKey.3 \ | 95 | EVP_BytesToKey.3 \ |
104 | EVP_DigestInit.3 \ | 96 | EVP_DigestInit.3 \ |
105 | EVP_DigestSignInit.3 \ | 97 | EVP_DigestSignInit.3 \ |
@@ -123,6 +115,15 @@ GENMAN= \ | |||
123 | EVP_SealInit.3 \ | 115 | EVP_SealInit.3 \ |
124 | EVP_SignInit.3 \ | 116 | EVP_SignInit.3 \ |
125 | EVP_VerifyInit.3 \ | 117 | EVP_VerifyInit.3 \ |
118 | UI_new.3 \ | ||
119 | bn_dump.3 \ | ||
120 | crypto.3 \ | ||
121 | d2i_PKCS8PrivateKey_bio.3 \ | ||
122 | des_read_pw.3 \ | ||
123 | evp.3 \ | ||
124 | lh_new.3 \ | ||
125 | |||
126 | GENMAN= \ | ||
126 | HMAC.3 \ | 127 | HMAC.3 \ |
127 | MD5.3 \ | 128 | MD5.3 \ |
128 | OBJ_nid2obj.3 \ | 129 | OBJ_nid2obj.3 \ |
@@ -192,7 +193,6 @@ GENMAN= \ | |||
192 | dsa.3 \ | 193 | dsa.3 \ |
193 | ec.3 \ | 194 | ec.3 \ |
194 | engine.3 \ | 195 | engine.3 \ |
195 | evp.3 \ | ||
196 | i2d_PKCS7_bio_stream.3 \ | 196 | i2d_PKCS7_bio_stream.3 \ |
197 | lh_stats.3 \ | 197 | lh_stats.3 \ |
198 | rsa.3 \ | 198 | rsa.3 \ |
diff --git a/src/lib/libcrypto/man/evp.3 b/src/lib/libcrypto/man/evp.3 new file mode 100644 index 0000000000..7bf7dfec81 --- /dev/null +++ b/src/lib/libcrypto/man/evp.3 | |||
@@ -0,0 +1,151 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm evp | ||
6 | .Nd high-level cryptographic functions | ||
7 | .Sh SYNOPSIS | ||
8 | .In openssl/evp.h | ||
9 | .Sh DESCRIPTION | ||
10 | The EVP library provides a high-level interface to cryptographic | ||
11 | functions. | ||
12 | .Pp | ||
13 | .Xr EVP_SealInit 3 | ||
14 | and | ||
15 | .Xr EVP_OpenInit 3 | ||
16 | provide public key encryption and decryption to implement digital | ||
17 | "envelopes". | ||
18 | .Pp | ||
19 | The | ||
20 | .Xr EVP_DigestSignInit 3 | ||
21 | and | ||
22 | .Xr EVP_DigestVerifyInit 3 | ||
23 | functions implement digital signatures and Message Authentication Codes | ||
24 | (MACs). | ||
25 | Also see the older | ||
26 | .Xr EVP_SignInit 3 | ||
27 | and | ||
28 | .Xr EVP_VerifyInit 3 | ||
29 | functions. | ||
30 | .Pp | ||
31 | Symmetric encryption is available with the | ||
32 | .Xr EVP_EncryptInit 3 | ||
33 | functions. | ||
34 | The | ||
35 | .Xr EVP_DigestInit 3 | ||
36 | functions provide message digests. | ||
37 | .Pp | ||
38 | Authenticated encryption with additional data (AEAD) is available with | ||
39 | the | ||
40 | .Xr EVP_AEAD_CTX_init 3 | ||
41 | functions. | ||
42 | .Pp | ||
43 | The | ||
44 | .Fn EVP_PKEY_* | ||
45 | functions provide a high level interface to asymmetric algorithms. | ||
46 | To create a new | ||
47 | .Vt EVP_PKEY , | ||
48 | see | ||
49 | .Xr EVP_PKEY_new 3 . | ||
50 | .Vt EVP_PKEY Ns s | ||
51 | can be associated with a private key of a particular algorithm | ||
52 | by using the functions described in the | ||
53 | .Xr EVP_PKEY_set1_RSA 3 | ||
54 | page, or new keys can be generated using | ||
55 | .Xr EVP_PKEY_keygen 3 . | ||
56 | .Vt EVP_PKEY Ns s | ||
57 | can be compared using | ||
58 | .Xr EVP_PKEY_cmp 3 | ||
59 | or printed using | ||
60 | .Xr EVP_PKEY_print_private 3 . | ||
61 | .Pp | ||
62 | The | ||
63 | .Fn EVP_PKEY_* | ||
64 | functions support the full range of asymmetric algorithm operations: | ||
65 | .Bl -bullet | ||
66 | .It | ||
67 | For key agreement, see | ||
68 | .Xr EVP_PKEY_derive 3 . | ||
69 | .It | ||
70 | For signing and verifying, see | ||
71 | .Xr EVP_PKEY_sign 3 , | ||
72 | .Xr EVP_PKEY_verify 3 , | ||
73 | and | ||
74 | .Xr EVP_PKEY_verify_recover 3 . | ||
75 | However, note that these functions do not perform a digest of the | ||
76 | data to be signed. | ||
77 | Therefore normally you would use the | ||
78 | .Xr EVP_DigestSignInit 3 | ||
79 | functions for this purpose. | ||
80 | .It | ||
81 | For encryption and decryption see | ||
82 | .Xr EVP_PKEY_encrypt 3 | ||
83 | and | ||
84 | .Xr EVP_PKEY_decrypt 3 , | ||
85 | respectively. | ||
86 | However, note that these functions perform encryption and decryption only. | ||
87 | As public key encryption is an expensive operation, normally you | ||
88 | would wrap an encrypted message in a digital envelope using the | ||
89 | .Xr EVP_SealInit 3 | ||
90 | and | ||
91 | .Xr EVP_OpenInit 3 | ||
92 | functions. | ||
93 | .El | ||
94 | .Pp | ||
95 | The | ||
96 | .Xr EVP_BytesToKey 3 | ||
97 | function provides some limited support for password based encryption. | ||
98 | Careful selection of the parameters will provide a PKCS#5 PBKDF1 | ||
99 | compatible implementation. | ||
100 | However, new applications should typically not use this (preferring, for | ||
101 | example, PBKDF2 from PCKS#5). | ||
102 | .Pp | ||
103 | Algorithms are loaded with | ||
104 | .Xr OpenSSL_add_all_algorithms 3 . | ||
105 | .Pp | ||
106 | All the symmetric algorithms (ciphers), digests and asymmetric | ||
107 | algorithms (public key algorithms) can be replaced by | ||
108 | .Xr engine 3 | ||
109 | modules providing alternative implementations. | ||
110 | If | ||
111 | .Vt ENGINE | ||
112 | implementations of ciphers or digests are registered as defaults, | ||
113 | then the various EVP functions will automatically use those | ||
114 | implementations in preference to built in software implementations. | ||
115 | For more information, consult the | ||
116 | .Xr engine 3 | ||
117 | manual page. | ||
118 | .Pp | ||
119 | Although low level algorithm specific functions exist for many | ||
120 | algorithms, their use is discouraged. | ||
121 | They cannot be used with an | ||
122 | .Vt ENGINE , | ||
123 | and | ||
124 | .Vt ENGINE | ||
125 | versions of new algorithms cannot be accessed using the low level | ||
126 | functions. | ||
127 | Using them also makes code harder to adapt to new algorithms, some | ||
128 | options are not cleanly supported at the low level, and some | ||
129 | operations are more efficient using the high level interfaces. | ||
130 | .Sh SEE ALSO | ||
131 | .Xr engine 3 , | ||
132 | .Xr EVP_AEAD_CTX_init 3 , | ||
133 | .Xr EVP_BytesToKey 3 , | ||
134 | .Xr EVP_DigestInit 3 , | ||
135 | .Xr EVP_DigestSignInit 3 , | ||
136 | .Xr EVP_EncryptInit 3 , | ||
137 | .Xr EVP_OpenInit 3 , | ||
138 | .Xr EVP_PKEY_decrypt 3 , | ||
139 | .Xr EVP_PKEY_derive 3 , | ||
140 | .Xr EVP_PKEY_encrypt 3 , | ||
141 | .Xr EVP_PKEY_keygen 3 , | ||
142 | .Xr EVP_PKEY_new 3 , | ||
143 | .Xr EVP_PKEY_print_private 3 , | ||
144 | .Xr EVP_PKEY_set1_RSA 3 , | ||
145 | .Xr EVP_PKEY_sign 3 , | ||
146 | .Xr EVP_PKEY_verify 3 , | ||
147 | .Xr EVP_PKEY_verify_recover 3 , | ||
148 | .Xr EVP_SealInit 3 , | ||
149 | .Xr EVP_SignInit 3 , | ||
150 | .Xr EVP_VerifyInit 3 , | ||
151 | .Xr OpenSSL_add_all_algorithms 3 | ||