Revert "Merge branch 'upstream' into tizen"
[platform/upstream/nettle.git] / ctr.h
1 /* ctr.h
2  *
3  * Counter mode, using an network byte order incremented counter,
4  * matching the testcases of NIST 800-38A.
5  */
6
7 /* nettle, low-level cryptographics library
8  *
9  * Copyright (C) 2005 Niels Möller
10  *  
11  * The nettle library is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or (at your
14  * option) any later version.
15  * 
16  * The nettle library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19  * License for more details.
20  * 
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with the nettle library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02111-1301, USA.
25  */
26
27 #ifndef NETTLE_CTR_H_INCLUDED
28 #define NETTLE_CTR_H_INCLUDED
29
30 #include "nettle-types.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* Name mangling */
37 #define ctr_crypt nettle_ctr_crypt
38
39 void
40 ctr_crypt(void *ctx, nettle_crypt_func *f,
41           unsigned block_size, uint8_t *ctr,
42           unsigned length, uint8_t *dst,
43           const uint8_t *src);
44
45 #define CTR_CTX(type, size) \
46 { type ctx; uint8_t ctr[size]; }
47
48 #define CTR_SET_COUNTER(ctx, data) \
49 memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
50
51 #define CTR_CRYPT(self, f, length, dst, src)            \
52 (0 ? ((f)(&(self)->ctx, 0, NULL, NULL))                 \
53    : ctr_crypt((void *) &(self)->ctx,                   \
54                (nettle_crypt_func *) (f),               \
55                sizeof((self)->ctr), (self)->ctr,        \
56                (length), (dst), (src)))
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif /* NETTLE_CTR_H_INCLUDED */