You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8KB

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