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.

105 lines
2.9KB

  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. #if FF_API_HMAC
  35. AV_HMAC_SHA224_DEPRECATED = 10,
  36. AV_HMAC_SHA256_DEPRECATED,
  37. #endif
  38. AV_HMAC_SHA384 = 12,
  39. AV_HMAC_SHA512,
  40. };
  41. typedef struct AVHMAC AVHMAC;
  42. /**
  43. * Allocate an AVHMAC context.
  44. * @param type The hash function used for the HMAC.
  45. */
  46. AVHMAC *av_hmac_alloc(enum AVHMACType type);
  47. /**
  48. * Free an AVHMAC context.
  49. * @param ctx The context to free, may be NULL
  50. */
  51. void av_hmac_free(AVHMAC *ctx);
  52. /**
  53. * Initialize an AVHMAC context with an authentication key.
  54. * @param ctx The HMAC context
  55. * @param key The authentication key
  56. * @param keylen The length of the key, in bytes
  57. */
  58. void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
  59. /**
  60. * Hash data with the HMAC.
  61. * @param ctx The HMAC context
  62. * @param data The data to hash
  63. * @param len The length of the data, in bytes
  64. */
  65. void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
  66. /**
  67. * Finish hashing and output the HMAC digest.
  68. * @param ctx The HMAC context
  69. * @param out The output buffer to write the digest into
  70. * @param outlen The length of the out buffer, in bytes
  71. * @return The number of bytes written to out, or a negative error code.
  72. */
  73. int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
  74. /**
  75. * Hash an array of data with a key.
  76. * @param ctx The HMAC context
  77. * @param data The data to hash
  78. * @param len The length of the data, in bytes
  79. * @param key The authentication key
  80. * @param keylen The length of the key, in bytes
  81. * @param out The output buffer to write the digest into
  82. * @param outlen The length of the out buffer, in bytes
  83. * @return The number of bytes written to out, or a negative error code.
  84. */
  85. int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
  86. const uint8_t *key, unsigned int keylen,
  87. uint8_t *out, unsigned int outlen);
  88. /**
  89. * @}
  90. */
  91. #endif /* AVUTIL_HMAC_H */