88f5abcdb483af6ccafb4655d32e7a9f7882fa85
[openssl.git] / doc / crypto / hmac.pod
1 =pod
2
3 =head1 NAME
4
5 HMAC, HMAC_CTX_init, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final, HMAC_CTX_cleanup - HMAC message authentication code
6
7 =head1 SYNOPSIS
8
9  #include <openssl/hmac.h>
10
11  unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
12                int key_len, const unsigned char *d, int n,
13                unsigned char *md, unsigned int *md_len);
14
15  void HMAC_CTX_init(HMAC_CTX *ctx);
16
17  int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
18                const EVP_MD *md);
19  int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
20                    const EVP_MD *md, ENGINE *impl);
21  int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
22  int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
23
24  void HMAC_CTX_cleanup(HMAC_CTX *ctx);
25
26 =head1 DESCRIPTION
27
28 HMAC is a MAC (message authentication code), i.e. a keyed hash
29 function used for message authentication, which is based on a hash
30 function.
31
32 HMAC() computes the message authentication code of the B<n> bytes at
33 B<d> using the hash function B<evp_md> and the key B<key> which is
34 B<key_len> bytes long.
35
36 It places the result in B<md> (which must have space for the output of
37 the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
38 If B<md> is NULL, the digest is placed in a static array.  The size of
39 the output is placed in B<md_len>, unless it is B<NULL>.
40
41 B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
42
43 HMAC_CTX_init() initialises a B<HMAC_CTX> before first use. It must be
44 called.
45
46 HMAC_CTX_cleanup() erases the key and other data from the B<HMAC_CTX>
47 and releases any associated resources. It must be called when an
48 B<HMAC_CTX> is no longer required.
49
50 The following functions may be used if the message is not completely
51 stored in memory:
52
53 HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
54 function B<evp_md> and the key B<key> which is B<key_len> bytes
55 long. It is deprecated and only included for backward compatibility
56 with OpenSSL 0.9.6b.
57
58 HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use
59 the function B<evp_md> and key B<key>. Either can be NULL, in which
60 case the existing one will be reused. HMAC_CTX_init() must have been
61 called before the first use of an B<HMAC_CTX> in this
62 function. B<N.B. HMAC_Init() had this undocumented behaviour in
63 previous versions of OpenSSL - failure to switch to HMAC_Init_ex() in
64 programs that expect it will cause them to stop working>.
65
66 HMAC_Update() can be called repeatedly with chunks of the message to
67 be authenticated (B<len> bytes at B<data>).
68
69 HMAC_Final() places the message authentication code in B<md>, which
70 must have space for the hash function output.
71
72 =head1 RETURN VALUES
73
74 HMAC() returns a pointer to the message authentication code or NULL if
75 an error occurred.
76
77 HMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or 0 if
78 an error occurred.
79
80 HMAC_CTX_init() and HMAC_CTX_cleanup() do not return values.
81
82 =head1 CONFORMING TO
83
84 RFC 2104
85
86 =head1 SEE ALSO
87
88 L<sha(3)>, L<evp(3)>
89
90 =head1 HISTORY
91
92 HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup()
93 are available since SSLeay 0.9.0.
94
95 HMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available
96 since OpenSSL 0.9.7.
97
98 HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
99 versions of OpenSSL before 1.0.0.
100
101 =cut