Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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.  
  21. #ifndef AVUTIL_HMAC_H
  22. #define AVUTIL_HMAC_H
  23.  
  24. #include <stdint.h>
  25.  
  26. #include "version.h"
  27. /**
  28.  * @defgroup lavu_hmac HMAC
  29.  * @ingroup lavu_crypto
  30.  * @{
  31.  */
  32.  
  33. enum AVHMACType {
  34.     AV_HMAC_MD5,
  35.     AV_HMAC_SHA1,
  36.     AV_HMAC_SHA224,
  37.     AV_HMAC_SHA256,
  38. #if FF_API_HMAC
  39.     AV_HMAC_SHA224_DEPRECATED = 10,
  40.     AV_HMAC_SHA256_DEPRECATED,
  41. #endif
  42.     AV_HMAC_SHA384 = 12,
  43.     AV_HMAC_SHA512,
  44. };
  45.  
  46. typedef struct AVHMAC AVHMAC;
  47.  
  48. /**
  49.  * Allocate an AVHMAC context.
  50.  * @param type The hash function used for the HMAC.
  51.  */
  52. AVHMAC *av_hmac_alloc(enum AVHMACType type);
  53.  
  54. /**
  55.  * Free an AVHMAC context.
  56.  * @param ctx The context to free, may be NULL
  57.  */
  58. void av_hmac_free(AVHMAC *ctx);
  59.  
  60. /**
  61.  * Initialize an AVHMAC context with an authentication key.
  62.  * @param ctx    The HMAC context
  63.  * @param key    The authentication key
  64.  * @param keylen The length of the key, in bytes
  65.  */
  66. void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
  67.  
  68. /**
  69.  * Hash data with the HMAC.
  70.  * @param ctx  The HMAC context
  71.  * @param data The data to hash
  72.  * @param len  The length of the data, in bytes
  73.  */
  74. void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
  75.  
  76. /**
  77.  * Finish hashing and output the HMAC digest.
  78.  * @param ctx    The HMAC context
  79.  * @param out    The output buffer to write the digest into
  80.  * @param outlen The length of the out buffer, in bytes
  81.  * @return       The number of bytes written to out, or a negative error code.
  82.  */
  83. int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
  84.  
  85. /**
  86.  * Hash an array of data with a key.
  87.  * @param ctx    The HMAC context
  88.  * @param data   The data to hash
  89.  * @param len    The length of the data, in bytes
  90.  * @param key    The authentication key
  91.  * @param keylen The length of the key, in bytes
  92.  * @param out    The output buffer to write the digest into
  93.  * @param outlen The length of the out buffer, in bytes
  94.  * @return       The number of bytes written to out, or a negative error code.
  95.  */
  96. int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
  97.                  const uint8_t *key, unsigned int keylen,
  98.                  uint8_t *out, unsigned int outlen);
  99.  
  100. /**
  101.  * @}
  102.  */
  103.  
  104. #endif /* AVUTIL_HMAC_H */
  105.