hmac.h 2.8 KB

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