1 /*
2  * Copyright (C) 2012 Martin Storsjo
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 module ffmpeg.libavutil.hmac;
21 extern (C) @nogc nothrow:
22 
23 /**
24  * @defgroup lavu_hmac HMAC
25  * @ingroup lavu_crypto
26  * @{
27  */
28 
29 enum AVHMACType
30 {
31     AV_HMAC_MD5 = 0,
32     AV_HMAC_SHA1 = 1,
33     AV_HMAC_SHA224 = 2,
34     AV_HMAC_SHA256 = 3,
35     AV_HMAC_SHA384 = 4,
36     AV_HMAC_SHA512 = 5
37 }
38 
39 struct AVHMAC;
40 
41 /**
42  * Allocate an AVHMAC context.
43  * @param type The hash function used for the HMAC.
44  */
45 AVHMAC* av_hmac_alloc (AVHMACType type);
46 
47 /**
48  * Free an AVHMAC context.
49  * @param ctx The context to free, may be NULL
50  */
51 void av_hmac_free (AVHMAC* ctx);
52 
53 /**
54  * Initialize an AVHMAC context with an authentication key.
55  * @param ctx    The HMAC context
56  * @param key    The authentication key
57  * @param keylen The length of the key, in bytes
58  */
59 void av_hmac_init (AVHMAC* ctx, const(ubyte)* key, uint keylen);
60 
61 /**
62  * Hash data with the HMAC.
63  * @param ctx  The HMAC context
64  * @param data The data to hash
65  * @param len  The length of the data, in bytes
66  */
67 void av_hmac_update (AVHMAC* ctx, const(ubyte)* data, uint len);
68 
69 /**
70  * Finish hashing and output the HMAC digest.
71  * @param ctx    The HMAC context
72  * @param out    The output buffer to write the digest into
73  * @param outlen The length of the out buffer, in bytes
74  * @return       The number of bytes written to out, or a negative error code.
75  */
76 int av_hmac_final (AVHMAC* ctx, ubyte* out_, uint outlen);
77 
78 /**
79  * Hash an array of data with a key.
80  * @param ctx    The HMAC context
81  * @param data   The data to hash
82  * @param len    The length of the data, in bytes
83  * @param key    The authentication key
84  * @param keylen The length of the key, in bytes
85  * @param out    The output buffer to write the digest into
86  * @param outlen The length of the out buffer, in bytes
87  * @return       The number of bytes written to out, or a negative error code.
88  */
89 int av_hmac_calc (
90     AVHMAC* ctx,
91     const(ubyte)* data,
92     uint len,
93     const(ubyte)* key,
94     uint keylen,
95     ubyte* out_,
96     uint outlen);
97 
98 /**
99  * @}
100  */
101 
102 /* AVUTIL_HMAC_H */