hmac.h 2.7 KB

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