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.

135 lines
3.7KB

  1. /*
  2. * Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
  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. * @file
  22. * @ingroup lavu_hash_generic
  23. * Generic hashing API
  24. */
  25. #ifndef AVUTIL_HASH_H
  26. #define AVUTIL_HASH_H
  27. #include <stdint.h>
  28. /**
  29. * @defgroup lavu_hash Hash Functions
  30. * @ingroup lavu_crypto
  31. *
  32. * @{
  33. *
  34. * @defgroup lavu_hash_generic Generic Hashing API
  35. *
  36. * @{
  37. */
  38. struct AVHashContext;
  39. /**
  40. * Allocate a hash context for the algorithm specified by name.
  41. *
  42. * @return >= 0 for success, a negative error code for failure
  43. * @note The context is not initialized, you must call av_hash_init().
  44. */
  45. int av_hash_alloc(struct AVHashContext **ctx, const char *name);
  46. /**
  47. * Get the names of available hash algorithms.
  48. *
  49. * This function can be used to enumerate the algorithms.
  50. *
  51. * @param i index of the hash algorithm, starting from 0
  52. * @return a pointer to a static string or NULL if i is out of range
  53. */
  54. const char *av_hash_names(int i);
  55. /**
  56. * Get the name of the algorithm corresponding to the given hash context.
  57. */
  58. const char *av_hash_get_name(const struct AVHashContext *ctx);
  59. /**
  60. * Maximum value that av_hash_get_size will currently return.
  61. *
  62. * You can use this if you absolutely want or need to use static allocation
  63. * and are fine with not supporting hashes newly added to libavutil without
  64. * recompilation.
  65. * Note that you still need to check against av_hash_get_size, adding new hashes
  66. * with larger sizes will not be considered an ABI change and should not cause
  67. * your code to overflow a buffer.
  68. */
  69. #define AV_HASH_MAX_SIZE 64
  70. /**
  71. * Get the size of the resulting hash value in bytes.
  72. *
  73. * The pointer passed to av_hash_final have space for at least this many bytes.
  74. */
  75. int av_hash_get_size(const struct AVHashContext *ctx);
  76. /**
  77. * Initialize or reset a hash context.
  78. */
  79. void av_hash_init(struct AVHashContext *ctx);
  80. /**
  81. * Update a hash context with additional data.
  82. */
  83. void av_hash_update(struct AVHashContext *ctx, const uint8_t *src, int len);
  84. /**
  85. * Finalize a hash context and compute the actual hash value.
  86. */
  87. void av_hash_final(struct AVHashContext *ctx, uint8_t *dst);
  88. /**
  89. * Finalize a hash context and compute the actual hash value.
  90. * If size is smaller than the hash size, the hash is truncated;
  91. * if size is larger, the buffer is padded with 0.
  92. */
  93. void av_hash_final_bin(struct AVHashContext *ctx, uint8_t *dst, int size);
  94. /**
  95. * Finalize a hash context and compute the actual hash value as a hex string.
  96. * The string is always 0-terminated.
  97. * If size is smaller than 2 * hash_size + 1, the hex string is truncated.
  98. */
  99. void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size);
  100. /**
  101. * Finalize a hash context and compute the actual hash value as a base64 string.
  102. * The string is always 0-terminated.
  103. * If size is smaller than AV_BASE64_SIZE(hash_size), the base64 string is
  104. * truncated.
  105. */
  106. void av_hash_final_b64(struct AVHashContext *ctx, uint8_t *dst, int size);
  107. /**
  108. * Free hash context.
  109. */
  110. void av_hash_freep(struct AVHashContext **ctx);
  111. /**
  112. * @}
  113. * @}
  114. */
  115. #endif /* AVUTIL_HASH_H */