summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2018-02-18 17:32:13 +0000
committerschwarze <>2018-02-18 17:32:13 +0000
commit03918dd5ed45cded781dc5051f6615ad3ff2d895 (patch)
tree89f6b42f6d6d2999358eab8574134514f6f7defe /src
parent013daaebb7c1272d647e1be37b16ea8beb3cb569 (diff)
downloadopenbsd-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.3213
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
159is 180is
160.Dv NULL , 181.Dv NULL ,
161the digest is placed in a static array. 182the digest is placed in a static array, which is not thread safe.
162The size of the output is placed in 183The size of the output is placed in
163.Fa md_len , 184.Fa md_len ,
164unless it is 185unless it is
@@ -170,19 +191,48 @@ can be
170.Xr EVP_ripemd160 3 , 191.Xr EVP_ripemd160 3 ,
171etc. 192etc.
172.Pp 193.Pp
194.Fn HMAC_CTX_new
195allocates and initializes a new
196.Vt HMAC_CTX
197object.
198.Pp
199.Fn HMAC_CTX_reset
200zeroes and re-initializes
201.Fa ctx
202and associated resources, making it suitable for new computations
203as if it was deleted with
204.Fn HMAC_CTX_free
205and newly created with
206.Fn HMAC_CTX_new .
207.Pp
208.Fn HMAC_CTX_free
209erases the key and other data from
210.Fa ctx ,
211releases any associated resources, and finally frees
212.Fa ctx
213itself.
214.Pp
173.Fn HMAC_CTX_init 215.Fn HMAC_CTX_init
174initialises a 216is a deprecated function to initialize an empty
175.Vt HMAC_CTX 217.Vt HMAC_CTX
176before first use. 218object, similar to
177It must be called. 219.Fn CTX_new
220but without the allocation.
221Calling it is required for static objects and objects on the stack
222before using them.
178.Pp 223.Pp
179.Fn HMAC_CTX_cleanup 224.Fn HMAC_CTX_cleanup
180erases the key and other data from the 225is a deprecated function to erase the key and other data from
181.Vt HMAC_CTX 226.Fa ctx
182and releases any associated resources. 227and release any associated resources, similar to
183It must be called when an 228.Fn HMAC_CTX_free
184.Vt HMAC_CTX 229but without freeing
185is no longer required. 230.Fa ctx
231itself.
232Calling it is required for static objects and objects on the stack
233that were initialized with
234.Fn HMAC_CTX_init
235and are no longer needed.
186.Pp 236.Pp
187.Fn HMAC_cleanup 237.Fn HMAC_cleanup
188is an alias for 238is an alias for
@@ -193,39 +243,66 @@ It is deprecated and implemented as a macro.
193The following functions may be used if the message is not completely 243The following functions may be used if the message is not completely
194stored in memory: 244stored in memory:
195.Pp 245.Pp
196.Fn HMAC_Init
197initializes a
198.Vt HMAC_CTX
199structure to use the hash function
200.Fa evp_md
201and the key
202.Fa key
203which is
204.Fa key_len
205bytes long.
206It is deprecated and only included for backward compatibility with
207OpenSSL 0.9.6b.
208.Pp
209.Fn HMAC_Init_ex 246.Fn HMAC_Init_ex
210initializes or reuses a 247sets up or reuses
211.Vt HMAC_CTX 248.Fa ctx
212structure to use the function 249to use the hash function
213.Fa evp_md 250.Fa evp_md
214and key 251and the key
215.Fa key . 252.Fa key .
216Either can be 253Either can be
217.Dv NULL , 254.Dv NULL ,
218in which case the existing one will be reused. 255in which case the existing one is reused.
256The
257.Fa ctx
258must have been created with
259.Fn HMAC_CTX_new
260or initialized with
219.Fn HMAC_CTX_init 261.Fn HMAC_CTX_init
220must have been called before the first use of an 262before the first use in this function.
221.Vt HMAC_CTX 263If
222in this function.
223.Sy N.B.
224.Fn HMAC_Init
225had this undocumented behaviour in previous versions of OpenSSL -
226failure to switch to
227.Fn HMAC_Init_ex 264.Fn HMAC_Init_ex
228in programs that expect it will cause them to stop working. 265is called with a
266.Dv NULL
267.Fa key
268but
269.Fa evp_md
270is neither
271.Dv NULL
272nor the same as the previous digest used by
273.Fa ctx ,
274then an error is returned because reuse of an existing key with a
275different digest is not supported.
276.Pp
277.Fn HMAC_Init
278is a deprecated wrapper around
279.Fn HMAC_Init_ex .
280If called with both
281.Fa key
282and
283.Fa md ,
284it calls
285.Fn HMAC_CTX_init
286first, which only makes sense for an empty, uninitialized
287.Fa ctx ,
288but not for one already initialized with
289.Fn HMAC_CTX_new
290or
291.Fn HMAC_CTX_init .
292If
293.Fa key
294or
295.Fa md
296is
297.Dv NULL ,
298it does not call
299.Fn HMAC_CTX_init ;
300so in this case,
301.Fa ctx
302already needs to be initialized with
303.Fn HMAC_CTX_new
304or
305.Fn HMAC_CTX_init .
229.Pp 306.Pp
230.Fn HMAC_Update 307.Fn HMAC_Update
231can be called repeatedly with chunks of the message to be authenticated 308can 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
261if an error occurred. 338if an error occurred.
262.Pp 339.Pp
340.Fn HMAC_CTX_new
341returns a pointer to the new
342.Vt HMAC_CTX
343object or
344.Dv NULL
345if 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
268return 1 for success or 0 if an error occurred. 353return 1 for success or 0 if an error occurred.
269.Pp 354.Pp
355.Fn HMAC_CTX_get_md
356returns the message digest that was previously set for
357.Fa ctx
358with
359.Fn HMAC_Init_ex ,
360or
361.Dv NULL
362if none was set.
363.Pp
270.Fn HMAC_size 364.Fn HMAC_size
271returns the length in bytes of the underlying hash function output 365returns the length in bytes of the underlying hash function output
272or 0 on error. 366or 0 on error.
@@ -289,6 +383,13 @@ and
289.Fn HMAC_CTX_cleanup 383.Fn HMAC_CTX_cleanup
290are available since OpenSSL 0.9.7. 384are 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 ,
389and
390.Fn HMAC_CTX_get_md
391first 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 ,
294and 395and