hash.h 3.5 KB

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