yading@11: /* yading@11: * Copyright (C) 2012 Martin Storsjo yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_HMAC_H yading@11: #define AVUTIL_HMAC_H yading@11: yading@11: #include yading@11: yading@11: /** yading@11: * @defgroup lavu_hmac HMAC yading@11: * @ingroup lavu_crypto yading@11: * @{ yading@11: */ yading@11: yading@11: enum AVHMACType { yading@11: AV_HMAC_MD5, yading@11: AV_HMAC_SHA1, yading@11: }; yading@11: yading@11: typedef struct AVHMAC AVHMAC; yading@11: yading@11: /** yading@11: * Allocate an AVHMAC context. yading@11: * @param type The hash function used for the HMAC. yading@11: */ yading@11: AVHMAC *av_hmac_alloc(enum AVHMACType type); yading@11: yading@11: /** yading@11: * Free an AVHMAC context. yading@11: * @param ctx The context to free, may be NULL yading@11: */ yading@11: void av_hmac_free(AVHMAC *ctx); yading@11: yading@11: /** yading@11: * Initialize an AVHMAC context with an authentication key. yading@11: * @param ctx The HMAC context yading@11: * @param key The authentication key yading@11: * @param keylen The length of the key, in bytes yading@11: */ yading@11: void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen); yading@11: yading@11: /** yading@11: * Hash data with the HMAC. yading@11: * @param ctx The HMAC context yading@11: * @param data The data to hash yading@11: * @param len The length of the data, in bytes yading@11: */ yading@11: void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len); yading@11: yading@11: /** yading@11: * Finish hashing and output the HMAC digest. yading@11: * @param ctx The HMAC context yading@11: * @param out The output buffer to write the digest into yading@11: * @param outlen The length of the out buffer, in bytes yading@11: * @return The number of bytes written to out, or a negative error code. yading@11: */ yading@11: int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen); yading@11: yading@11: /** yading@11: * Hash an array of data with a key. yading@11: * @param ctx The HMAC context yading@11: * @param data The data to hash yading@11: * @param len The length of the data, in bytes yading@11: * @param key The authentication key yading@11: * @param keylen The length of the key, in bytes yading@11: * @param out The output buffer to write the digest into yading@11: * @param outlen The length of the out buffer, in bytes yading@11: * @return The number of bytes written to out, or a negative error code. yading@11: */ yading@11: int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len, yading@11: const uint8_t *key, unsigned int keylen, yading@11: uint8_t *out, unsigned int outlen); yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #endif /* AVUTIL_HMAC_H */