FFmpeg
aes_ctr.h
Go to the documentation of this file.
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 
22 #ifndef AVUTIL_AES_CTR_H
23 #define AVUTIL_AES_CTR_H
24 
25 /**
26  * @defgroup lavu_aes_ctr AES-CTR
27  * @ingroup lavu_crypto
28  * @{
29  */
30 
31 #include <stdint.h>
32 
33 #include "attributes.h"
34 
35 #define AES_CTR_KEY_SIZE (16)
36 #define AES_CTR_IV_SIZE (8)
37 
38 struct AVAESCTR;
39 
40 /**
41  * Allocate an AVAESCTR context.
42  */
43 struct AVAESCTR *av_aes_ctr_alloc(void);
44 
45 /**
46  * Initialize an AVAESCTR context.
47  *
48  * @param a The AVAESCTR context to initialize
49  * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
50  */
51 int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key);
52 
53 /**
54  * Release an AVAESCTR context.
55  *
56  * @param a The AVAESCTR context
57  */
58 void av_aes_ctr_free(struct AVAESCTR *a);
59 
60 /**
61  * Process a buffer using a previously initialized context.
62  *
63  * @param a The AVAESCTR context
64  * @param dst destination array, can be equal to src
65  * @param src source array, can be equal to dst
66  * @param size the size of src and dst
67  */
68 void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int size);
69 
70 /**
71  * Get the current iv
72  */
73 const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
74 
75 /**
76  * Generate a random iv
77  */
78 void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
79 
80 /**
81  * Forcefully change the 8-byte iv
82  */
83 void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
84 
85 /**
86  * Forcefully change the "full" 16-byte iv, including the counter
87  */
88 void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
89 
90 /**
91  * Increment the top 64 bit of the iv (performed after each frame)
92  */
93 void av_aes_ctr_increment_iv(struct AVAESCTR *a);
94 
95 /**
96  * @}
97  */
98 
99 #endif /* AVUTIL_AES_CTR_H */
av_aes_ctr_set_random_iv
void av_aes_ctr_set_random_iv(struct AVAESCTR *a)
Generate a random iv.
Definition: aes_ctr.c:63
av_aes_ctr_get_iv
const uint8_t * av_aes_ctr_get_iv(struct AVAESCTR *a)
Get the current iv.
Definition: aes_ctr.c:58
key
const char * key
Definition: hwcontext_opencl.c:174
av_aes_ctr_alloc
struct AVAESCTR * av_aes_ctr_alloc(void)
Allocate an AVAESCTR context.
Definition: aes_ctr.c:40
av_aes_ctr_init
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
Initialize an AVAESCTR context.
Definition: aes_ctr.c:73
size
int size
Definition: twinvq_data.h:10344
av_aes_ctr_set_iv
void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t *iv)
Forcefully change the 8-byte iv.
Definition: aes_ctr.c:45
av_aes_ctr_set_full_iv
void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t *iv)
Forcefully change the "full" 16-byte iv, including the counter.
Definition: aes_ctr.c:52
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
attributes.h
av_aes_ctr_free
void av_aes_ctr_free(struct AVAESCTR *a)
Release an AVAESCTR context.
Definition: aes_ctr.c:83
av_aes_ctr_increment_iv
void av_aes_ctr_increment_iv(struct AVAESCTR *a)
Increment the top 64 bit of the iv (performed after each frame)
Definition: aes_ctr.c:100
av_aes_ctr_crypt
void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int size)
Process a buffer using a previously initialized context.
Definition: aes_ctr.c:107
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVAESCTR
Definition: aes_ctr.c:33