xref: /netbsd-src/lib/libc/hash/hmac.3 (revision e4acc50303a1206baf999c2c39a6c459379b325d)
1.\" $NetBSD: hmac.3,v 1.6 2018/05/23 02:08:40 christos Exp $
2.\"
3.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\"TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd May 22, 2018
31.Dt HMAC 3
32.Os
33.Sh NAME
34.Nm hmac
35.Nd compute a key-Hash Message Authentication Code
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In stdlib.h
40.Ft ssize_t
41.Fn hmac "const char *hname" "const void *key" "size_t klen" "const void *text" "size_t tlen" "void *digest" "size_t dlen"
42.Sh DESCRIPTION
43The
44.Fn hmac
45function computes the key-Hash Message Authentication Code per
46.Tn RFC 2104
47and places the result in
48.Fa digest
49writing up to
50.Fa dlen
51bytes.
52The actual number of bytes that would be written is returned.
53.Pp
54The hash functions supported are: md2, md4, md5, rmd160, sha1, sha224,
55sha256, sha384, and sha512.
56.Sh RETURN VALUES
57The
58.Fn hmac
59function returns
60.Dv \-1
61if the
62.Fa hname
63is not found.
64Otherwise the actual length of the digest string is returned (which could
65be bigger or smaller than
66.Fa dlen ) .
67This length depends on the hashing function selected.
68.Sh SEE ALSO
69.Xr md2 3 ,
70.Xr md4 3 ,
71.Xr md5 3 ,
72.Xr openssl_HMAC 3 ,
73.Xr openssl_MD2 3 ,
74.Xr openssl_MD4 3 ,
75.Xr openssl_MD5 3 ,
76.Xr rmd160 3 ,
77.Xr sha1 3 ,
78.Xr sha2 3
79.Sh STANDARDS
80.Rs
81.%R RFC 2104
82.Re
83.Sh NOTES
84The maximum digest length has been extended from
85.Dv 64
86to
87.Dv 128
88bytes to handle SHA2.
89.Sh HISTORY
90The
91.Fn hmac
92function appeared in
93.Nx 8 .
94