diff options
author | schwarze <> | 2018-02-18 17:32:13 +0000 |
---|---|---|
committer | schwarze <> | 2018-02-18 17:32:13 +0000 |
commit | 03918dd5ed45cded781dc5051f6615ad3ff2d895 (patch) | |
tree | 89f6b42f6d6d2999358eab8574134514f6f7defe /src | |
parent | 013daaebb7c1272d647e1be37b16ea8beb3cb569 (diff) | |
download | openbsd-03918dd5ed45cded781dc5051f6615ad3ff2d895.tar.gz openbsd-03918dd5ed45cded781dc5051f6615ad3ff2d895.tar.bz2 openbsd-03918dd5ed45cded781dc5051f6615ad3ff2d895.zip |
In hmac.c rev. 1.13 2018/02/17 14:53:59, jsing@ provided HMAC_CTX_new(3),
HMAC_CTX_free(3), HMAC_CTX_reset(3), and HMAC_CTX_get_md(3).
Merge the documentation from OpenSSL, with many tweaks by me.
Also include a few earlier improvements from OpenSSL.
While here, improve the order of the functions, the description of
deprecated functions, and remove a confusing warning about the
behaviour of HMAC_Init(3) in historical versions of OpenSSL.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/man/HMAC.3 | 213 |
1 files changed, 157 insertions, 56 deletions
diff --git a/src/lib/libcrypto/man/HMAC.3 b/src/lib/libcrypto/man/HMAC.3 index 595d5ed5ce..cc73d360d9 100644 --- a/src/lib/libcrypto/man/HMAC.3 +++ b/src/lib/libcrypto/man/HMAC.3 | |||
@@ -1,9 +1,12 @@ | |||
1 | .\" $OpenBSD: HMAC.3,v 1.7 2017/08/01 14:57:03 schwarze Exp $ | 1 | .\" $OpenBSD: HMAC.3,v 1.8 2018/02/18 17:32:13 schwarze Exp $ |
2 | .\" OpenSSL a528d4f0 Oct 27 13:40:11 2015 -0400 | 2 | .\" full merge up to: OpenSSL crypto/hmac a528d4f0 Oct 27 13:40:11 2015 -0400 |
3 | .\" selective merge up to: OpenSSL man3/HMAC b3696a55 Sep 2 09:35:50 2017 -0400 | ||
3 | .\" | 4 | .\" |
4 | .\" This file was written by Ulf Moeller <ulf@openssl.org>. | 5 | .\" This file was written by Ulf Moeller <ulf@openssl.org>, |
5 | .\" Copyright (c) 2000-2002, 2006, 2008, 2009, 2013, 2016 The OpenSSL Project. | 6 | .\" Richard Levitte <levitte@openssl.org>, and |
6 | .\" All rights reserved. | 7 | .\" Matt Caswell <matt@openssl.org>. |
8 | .\" Copyright (c) 2000-2002, 2006, 2008, 2009, 2013, 2015, 2016 | ||
9 | .\" The OpenSSL Project. All rights reserved. | ||
7 | .\" | 10 | .\" |
8 | .\" Redistribution and use in source and binary forms, with or without | 11 | .\" Redistribution and use in source and binary forms, with or without |
9 | .\" modification, are permitted provided that the following conditions | 12 | .\" modification, are permitted provided that the following conditions |
@@ -49,20 +52,24 @@ | |||
49 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 52 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
50 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 53 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
51 | .\" | 54 | .\" |
52 | .Dd $Mdocdate: August 1 2017 $ | 55 | .Dd $Mdocdate: February 18 2018 $ |
53 | .Dt HMAC 3 | 56 | .Dt HMAC 3 |
54 | .Os | 57 | .Os |
55 | .Sh NAME | 58 | .Sh NAME |
56 | .Nm HMAC , | 59 | .Nm HMAC , |
60 | .Nm HMAC_CTX_new , | ||
61 | .Nm HMAC_CTX_reset , | ||
62 | .Nm HMAC_CTX_free , | ||
57 | .Nm HMAC_CTX_init , | 63 | .Nm HMAC_CTX_init , |
58 | .Nm HMAC_Init , | 64 | .Nm HMAC_CTX_cleanup , |
65 | .Nm HMAC_cleanup , | ||
59 | .Nm HMAC_Init_ex , | 66 | .Nm HMAC_Init_ex , |
67 | .Nm HMAC_Init , | ||
60 | .Nm HMAC_Update , | 68 | .Nm HMAC_Update , |
61 | .Nm HMAC_Final , | 69 | .Nm HMAC_Final , |
62 | .Nm HMAC_CTX_cleanup , | ||
63 | .Nm HMAC_cleanup , | ||
64 | .Nm HMAC_CTX_copy , | 70 | .Nm HMAC_CTX_copy , |
65 | .Nm HMAC_CTX_set_flags , | 71 | .Nm HMAC_CTX_set_flags , |
72 | .Nm HMAC_CTX_get_md , | ||
66 | .Nm HMAC_size | 73 | .Nm HMAC_size |
67 | .Nd HMAC message authentication code | 74 | .Nd HMAC message authentication code |
68 | .Sh SYNOPSIS | 75 | .Sh SYNOPSIS |
@@ -77,24 +84,42 @@ | |||
77 | .Fa "unsigned char *md" | 84 | .Fa "unsigned char *md" |
78 | .Fa "unsigned int *md_len" | 85 | .Fa "unsigned int *md_len" |
79 | .Fc | 86 | .Fc |
87 | .Ft HMAC_CTX * | ||
88 | .Fn HMAC_CTX_new void | ||
89 | .Ft int | ||
90 | .Fo HMAC_CTX_reset | ||
91 | .Fa "HMAC_CTX *ctx" | ||
92 | .Fc | ||
93 | .Ft void | ||
94 | .Fo HMAC_CTX_free | ||
95 | .Fa "HMAC_CTX *ctx" | ||
96 | .Fc | ||
80 | .Ft void | 97 | .Ft void |
81 | .Fo HMAC_CTX_init | 98 | .Fo HMAC_CTX_init |
82 | .Fa "HMAC_CTX *ctx" | 99 | .Fa "HMAC_CTX *ctx" |
83 | .Fc | 100 | .Fc |
101 | .Ft void | ||
102 | .Fo HMAC_CTX_cleanup | ||
103 | .Fa "HMAC_CTX *ctx" | ||
104 | .Fc | ||
105 | .Ft void | ||
106 | .Fo HMAC_cleanup | ||
107 | .Fa "HMAC_CTX *ctx" | ||
108 | .Fc | ||
84 | .Ft int | 109 | .Ft int |
85 | .Fo HMAC_Init | 110 | .Fo HMAC_Init_ex |
86 | .Fa "HMAC_CTX *ctx" | 111 | .Fa "HMAC_CTX *ctx" |
87 | .Fa "const void *key" | 112 | .Fa "const void *key" |
88 | .Fa "int key_len" | 113 | .Fa "int key_len" |
89 | .Fa "const EVP_MD *md" | 114 | .Fa "const EVP_MD *md" |
115 | .Fa "ENGINE *impl" | ||
90 | .Fc | 116 | .Fc |
91 | .Ft int | 117 | .Ft int |
92 | .Fo HMAC_Init_ex | 118 | .Fo HMAC_Init |
93 | .Fa "HMAC_CTX *ctx" | 119 | .Fa "HMAC_CTX *ctx" |
94 | .Fa "const void *key" | 120 | .Fa "const void *key" |
95 | .Fa "int key_len" | 121 | .Fa "int key_len" |
96 | .Fa "const EVP_MD *md" | 122 | .Fa "const EVP_MD *md" |
97 | .Fa "ENGINE *impl" | ||
98 | .Fc | 123 | .Fc |
99 | .Ft int | 124 | .Ft int |
100 | .Fo HMAC_Update | 125 | .Fo HMAC_Update |
@@ -108,14 +133,6 @@ | |||
108 | .Fa "unsigned char *md" | 133 | .Fa "unsigned char *md" |
109 | .Fa "unsigned int *len" | 134 | .Fa "unsigned int *len" |
110 | .Fc | 135 | .Fc |
111 | .Ft void | ||
112 | .Fo HMAC_CTX_cleanup | ||
113 | .Fa "HMAC_CTX *ctx" | ||
114 | .Fc | ||
115 | .Ft void | ||
116 | .Fo HMAC_cleanup | ||
117 | .Fa "HMAC_CTX *ctx" | ||
118 | .Fc | ||
119 | .Ft int | 136 | .Ft int |
120 | .Fo HMAC_CTX_copy | 137 | .Fo HMAC_CTX_copy |
121 | .Fa "HMAC_CTX *dctx" | 138 | .Fa "HMAC_CTX *dctx" |
@@ -126,6 +143,10 @@ | |||
126 | .Fa "HMAC_CTX *ctx" | 143 | .Fa "HMAC_CTX *ctx" |
127 | .Fa "unsigned long flags" | 144 | .Fa "unsigned long flags" |
128 | .Fc | 145 | .Fc |
146 | .Ft const EVP_MD * | ||
147 | .Fo HMAC_CTX_get_md | ||
148 | .Fa "const HMAC_CTX *ctx" | ||
149 | .Fc | ||
129 | .Ft size_t | 150 | .Ft size_t |
130 | .Fo HMAC_size | 151 | .Fo HMAC_size |
131 | .Fa "const HMAC_CTX *e" | 152 | .Fa "const HMAC_CTX *e" |
@@ -158,7 +179,7 @@ If | |||
158 | .Fa md | 179 | .Fa md |
159 | is | 180 | is |
160 | .Dv NULL , | 181 | .Dv NULL , |
161 | the digest is placed in a static array. | 182 | the digest is placed in a static array, which is not thread safe. |
162 | The size of the output is placed in | 183 | The size of the output is placed in |
163 | .Fa md_len , | 184 | .Fa md_len , |
164 | unless it is | 185 | unless it is |
@@ -170,19 +191,48 @@ can be | |||
170 | .Xr EVP_ripemd160 3 , | 191 | .Xr EVP_ripemd160 3 , |
171 | etc. | 192 | etc. |
172 | .Pp | 193 | .Pp |
194 | .Fn HMAC_CTX_new | ||
195 | allocates and initializes a new | ||
196 | .Vt HMAC_CTX | ||
197 | object. | ||
198 | .Pp | ||
199 | .Fn HMAC_CTX_reset | ||
200 | zeroes and re-initializes | ||
201 | .Fa ctx | ||
202 | and associated resources, making it suitable for new computations | ||
203 | as if it was deleted with | ||
204 | .Fn HMAC_CTX_free | ||
205 | and newly created with | ||
206 | .Fn HMAC_CTX_new . | ||
207 | .Pp | ||
208 | .Fn HMAC_CTX_free | ||
209 | erases the key and other data from | ||
210 | .Fa ctx , | ||
211 | releases any associated resources, and finally frees | ||
212 | .Fa ctx | ||
213 | itself. | ||
214 | .Pp | ||
173 | .Fn HMAC_CTX_init | 215 | .Fn HMAC_CTX_init |
174 | initialises a | 216 | is a deprecated function to initialize an empty |
175 | .Vt HMAC_CTX | 217 | .Vt HMAC_CTX |
176 | before first use. | 218 | object, similar to |
177 | It must be called. | 219 | .Fn CTX_new |
220 | but without the allocation. | ||
221 | Calling it is required for static objects and objects on the stack | ||
222 | before using them. | ||
178 | .Pp | 223 | .Pp |
179 | .Fn HMAC_CTX_cleanup | 224 | .Fn HMAC_CTX_cleanup |
180 | erases the key and other data from the | 225 | is a deprecated function to erase the key and other data from |
181 | .Vt HMAC_CTX | 226 | .Fa ctx |
182 | and releases any associated resources. | 227 | and release any associated resources, similar to |
183 | It must be called when an | 228 | .Fn HMAC_CTX_free |
184 | .Vt HMAC_CTX | 229 | but without freeing |
185 | is no longer required. | 230 | .Fa ctx |
231 | itself. | ||
232 | Calling it is required for static objects and objects on the stack | ||
233 | that were initialized with | ||
234 | .Fn HMAC_CTX_init | ||
235 | and are no longer needed. | ||
186 | .Pp | 236 | .Pp |
187 | .Fn HMAC_cleanup | 237 | .Fn HMAC_cleanup |
188 | is an alias for | 238 | is an alias for |
@@ -193,39 +243,66 @@ It is deprecated and implemented as a macro. | |||
193 | The following functions may be used if the message is not completely | 243 | The following functions may be used if the message is not completely |
194 | stored in memory: | 244 | stored in memory: |
195 | .Pp | 245 | .Pp |
196 | .Fn HMAC_Init | ||
197 | initializes a | ||
198 | .Vt HMAC_CTX | ||
199 | structure to use the hash function | ||
200 | .Fa evp_md | ||
201 | and the key | ||
202 | .Fa key | ||
203 | which is | ||
204 | .Fa key_len | ||
205 | bytes long. | ||
206 | It is deprecated and only included for backward compatibility with | ||
207 | OpenSSL 0.9.6b. | ||
208 | .Pp | ||
209 | .Fn HMAC_Init_ex | 246 | .Fn HMAC_Init_ex |
210 | initializes or reuses a | 247 | sets up or reuses |
211 | .Vt HMAC_CTX | 248 | .Fa ctx |
212 | structure to use the function | 249 | to use the hash function |
213 | .Fa evp_md | 250 | .Fa evp_md |
214 | and key | 251 | and the key |
215 | .Fa key . | 252 | .Fa key . |
216 | Either can be | 253 | Either can be |
217 | .Dv NULL , | 254 | .Dv NULL , |
218 | in which case the existing one will be reused. | 255 | in which case the existing one is reused. |
256 | The | ||
257 | .Fa ctx | ||
258 | must have been created with | ||
259 | .Fn HMAC_CTX_new | ||
260 | or initialized with | ||
219 | .Fn HMAC_CTX_init | 261 | .Fn HMAC_CTX_init |
220 | must have been called before the first use of an | 262 | before the first use in this function. |
221 | .Vt HMAC_CTX | 263 | If |
222 | in this function. | ||
223 | .Sy N.B. | ||
224 | .Fn HMAC_Init | ||
225 | had this undocumented behaviour in previous versions of OpenSSL - | ||
226 | failure to switch to | ||
227 | .Fn HMAC_Init_ex | 264 | .Fn HMAC_Init_ex |
228 | in programs that expect it will cause them to stop working. | 265 | is called with a |
266 | .Dv NULL | ||
267 | .Fa key | ||
268 | but | ||
269 | .Fa evp_md | ||
270 | is neither | ||
271 | .Dv NULL | ||
272 | nor the same as the previous digest used by | ||
273 | .Fa ctx , | ||
274 | then an error is returned because reuse of an existing key with a | ||
275 | different digest is not supported. | ||
276 | .Pp | ||
277 | .Fn HMAC_Init | ||
278 | is a deprecated wrapper around | ||
279 | .Fn HMAC_Init_ex . | ||
280 | If called with both | ||
281 | .Fa key | ||
282 | and | ||
283 | .Fa md , | ||
284 | it calls | ||
285 | .Fn HMAC_CTX_init | ||
286 | first, which only makes sense for an empty, uninitialized | ||
287 | .Fa ctx , | ||
288 | but not for one already initialized with | ||
289 | .Fn HMAC_CTX_new | ||
290 | or | ||
291 | .Fn HMAC_CTX_init . | ||
292 | If | ||
293 | .Fa key | ||
294 | or | ||
295 | .Fa md | ||
296 | is | ||
297 | .Dv NULL , | ||
298 | it does not call | ||
299 | .Fn HMAC_CTX_init ; | ||
300 | so in this case, | ||
301 | .Fa ctx | ||
302 | already needs to be initialized with | ||
303 | .Fn HMAC_CTX_new | ||
304 | or | ||
305 | .Fn HMAC_CTX_init . | ||
229 | .Pp | 306 | .Pp |
230 | .Fn HMAC_Update | 307 | .Fn HMAC_Update |
231 | can be called repeatedly with chunks of the message to be authenticated | 308 | can be called repeatedly with chunks of the message to be authenticated |
@@ -260,6 +337,14 @@ returns a pointer to the message authentication code or | |||
260 | .Dv NULL | 337 | .Dv NULL |
261 | if an error occurred. | 338 | if an error occurred. |
262 | .Pp | 339 | .Pp |
340 | .Fn HMAC_CTX_new | ||
341 | returns a pointer to the new | ||
342 | .Vt HMAC_CTX | ||
343 | object or | ||
344 | .Dv NULL | ||
345 | if an error occurred. | ||
346 | .Pp | ||
347 | .Fn HMAC_CTX_reset , | ||
263 | .Fn HMAC_Init_ex , | 348 | .Fn HMAC_Init_ex , |
264 | .Fn HMAC_Update , | 349 | .Fn HMAC_Update , |
265 | .Fn HMAC_Final , | 350 | .Fn HMAC_Final , |
@@ -267,6 +352,15 @@ and | |||
267 | .Fn HMAC_CTX_copy | 352 | .Fn HMAC_CTX_copy |
268 | return 1 for success or 0 if an error occurred. | 353 | return 1 for success or 0 if an error occurred. |
269 | .Pp | 354 | .Pp |
355 | .Fn HMAC_CTX_get_md | ||
356 | returns the message digest that was previously set for | ||
357 | .Fa ctx | ||
358 | with | ||
359 | .Fn HMAC_Init_ex , | ||
360 | or | ||
361 | .Dv NULL | ||
362 | if none was set. | ||
363 | .Pp | ||
270 | .Fn HMAC_size | 364 | .Fn HMAC_size |
271 | returns the length in bytes of the underlying hash function output | 365 | returns the length in bytes of the underlying hash function output |
272 | or 0 on error. | 366 | or 0 on error. |
@@ -289,6 +383,13 @@ and | |||
289 | .Fn HMAC_CTX_cleanup | 383 | .Fn HMAC_CTX_cleanup |
290 | are available since OpenSSL 0.9.7. | 384 | are available since OpenSSL 0.9.7. |
291 | .Pp | 385 | .Pp |
386 | .Fn HMAC_CTX_new , | ||
387 | .Fn HMAC_CTX_reset , | ||
388 | .Fn HMAC_CTX_free , | ||
389 | and | ||
390 | .Fn HMAC_CTX_get_md | ||
391 | first appeared in OpenSSL 1.1.0. | ||
392 | .Pp | ||
292 | .Fn HMAC_Init_ex , | 393 | .Fn HMAC_Init_ex , |
293 | .Fn HMAC_Update , | 394 | .Fn HMAC_Update , |
294 | and | 395 | and |