aes_ctr.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * AES-CTR cipher
  3. * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVUTIL_AES_CTR_H
  22. #define AVUTIL_AES_CTR_H
  23. /**
  24. * @defgroup lavu_aes_ctr AES-CTR
  25. * @ingroup lavu_crypto
  26. * @{
  27. */
  28. #include <stdint.h>
  29. #include "attributes.h"
  30. #define AES_CTR_KEY_SIZE (16)
  31. #define AES_CTR_IV_SIZE (8)
  32. struct AVAESCTR;
  33. /**
  34. * Allocate an AVAESCTR context.
  35. */
  36. struct AVAESCTR *av_aes_ctr_alloc(void);
  37. /**
  38. * Initialize an AVAESCTR context.
  39. *
  40. * @param a The AVAESCTR context to initialize
  41. * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
  42. */
  43. int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key);
  44. /**
  45. * Release an AVAESCTR context.
  46. *
  47. * @param a The AVAESCTR context
  48. */
  49. void av_aes_ctr_free(struct AVAESCTR *a);
  50. /**
  51. * Process a buffer using a previously initialized context.
  52. *
  53. * @param a The AVAESCTR context
  54. * @param dst destination array, can be equal to src
  55. * @param src source array, can be equal to dst
  56. * @param size the size of src and dst
  57. */
  58. void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int size);
  59. /**
  60. * Get the current iv
  61. */
  62. const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
  63. /**
  64. * Generate a random iv
  65. */
  66. void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
  67. /**
  68. * Forcefully change the 8-byte iv
  69. */
  70. void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
  71. /**
  72. * Forcefully change the "full" 16-byte iv, including the counter
  73. */
  74. void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
  75. /**
  76. * Increment the top 64 bit of the iv (performed after each frame)
  77. */
  78. void av_aes_ctr_increment_iv(struct AVAESCTR *a);
  79. /**
  80. * @}
  81. */
  82. #endif /* AVUTIL_AES_CTR_H */