2 * Copyright (C) 2012 Martin Storsjo
4 * This file is part of Libav.
6 * Libav 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.
11 * Libav 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 * @defgroup lavu_hmac HMAC
28 * @ingroup lavu_crypto
37 typedef struct AVHMAC AVHMAC;
40 * Allocate an AVHMAC context.
41 * @param type The hash function used for the HMAC.
43 AVHMAC *av_hmac_alloc(enum AVHMACType type);
46 * Free an AVHMAC context.
47 * @param ctx The context to free, may be NULL
49 void av_hmac_free(AVHMAC *ctx);
52 * Initialize an AVHMAC context with an authentication key.
53 * @param ctx The HMAC context
54 * @param key The authentication key
55 * @param keylen The length of the key, in bytes
57 void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
60 * Hash data with the HMAC.
61 * @param ctx The HMAC context
62 * @param data The data to hash
63 * @param len The length of the data, in bytes
65 void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
68 * Finish hashing and output the HMAC digest.
69 * @param ctx The HMAC context
70 * @param out The output buffer to write the digest into
71 * @param outlen The length of the out buffer, in bytes
72 * @return The number of bytes written to out, or a negative error code.
74 int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
77 * Hash an array of data with a key.
78 * @param ctx The HMAC context
79 * @param data The data to hash
80 * @param len The length of the data, in bytes
81 * @param key The authentication key
82 * @param keylen The length of the key, in bytes
83 * @param out The output buffer to write the digest into
84 * @param outlen The length of the out buffer, in bytes
85 * @return The number of bytes written to out, or a negative error code.
87 int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
88 const uint8_t *key, unsigned int keylen,
89 uint8_t *out, unsigned int outlen);
95 #endif /* AVUTIL_HMAC_H */