aes_ctr.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <stdint.h>
  24. #include "attributes.h"
  25. #include "version.h"
  26. #define AES_CTR_KEY_SIZE (16)
  27. #define AES_CTR_IV_SIZE (8)
  28. struct AVAESCTR;
  29. /**
  30. * Allocate an AVAESCTR context.
  31. */
  32. struct AVAESCTR *av_aes_ctr_alloc(void);
  33. /**
  34. * Initialize an AVAESCTR context.
  35. * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
  36. */
  37. int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key);
  38. /**
  39. * Release an AVAESCTR context.
  40. */
  41. void av_aes_ctr_free(struct AVAESCTR *a);
  42. /**
  43. * Process a buffer using a previously initialized context.
  44. * @param dst destination array, can be equal to src
  45. * @param src source array, can be equal to dst
  46. * @param size the size of src and dst
  47. */
  48. void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int size);
  49. /**
  50. * Get the current iv
  51. */
  52. const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
  53. /**
  54. * Generate a random iv
  55. */
  56. void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
  57. /**
  58. * Forcefully change the iv
  59. */
  60. void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
  61. /**
  62. * Increment the top 64 bit of the iv (performed after each frame)
  63. */
  64. void av_aes_ctr_increment_iv(struct AVAESCTR *a);
  65. /**
  66. * @}
  67. */
  68. #endif /* AVUTIL_AES_CTR_H */