1 | /* ctr.h |
2 | |
3 | Counter mode, using an network byte order incremented counter, |
4 | matching the testcases of NIST 800-38A. |
5 | |
6 | Copyright (C) 2005 Niels Möller |
7 | |
8 | This file is part of GNU Nettle. |
9 | |
10 | GNU Nettle is free software: you can redistribute it and/or |
11 | modify it under the terms of either: |
12 | |
13 | * the GNU Lesser General Public License as published by the Free |
14 | Software Foundation; either version 3 of the License, or (at your |
15 | option) any later version. |
16 | |
17 | or |
18 | |
19 | * the GNU General Public License as published by the Free |
20 | Software Foundation; either version 2 of the License, or (at your |
21 | option) any later version. |
22 | |
23 | or both in parallel, as here. |
24 | |
25 | GNU Nettle is distributed in the hope that it will be useful, |
26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
28 | General Public License for more details. |
29 | |
30 | You should have received copies of the GNU General Public License and |
31 | the GNU Lesser General Public License along with this program. If |
32 | not, see http://www.gnu.org/licenses/. |
33 | */ |
34 | |
35 | #ifndef NETTLE_CTR_H_INCLUDED |
36 | #define NETTLE_CTR_H_INCLUDED |
37 | |
38 | #include "nettle-types.h" |
39 | |
40 | #ifdef __cplusplus |
41 | extern "C" { |
42 | #endif |
43 | |
44 | /* Name mangling */ |
45 | #define ctr_crypt nettle_ctr_crypt |
46 | |
47 | void |
48 | ctr_crypt(const void *ctx, nettle_cipher_func *f, |
49 | size_t block_size, uint8_t *ctr, |
50 | size_t length, uint8_t *dst, |
51 | const uint8_t *src); |
52 | |
53 | #define CTR_CTX(type, size) \ |
54 | { type ctx; uint8_t ctr[size]; } |
55 | |
56 | #define CTR_SET_COUNTER(ctx, data) \ |
57 | memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr)) |
58 | |
59 | #define CTR_CRYPT(self, f, length, dst, src) \ |
60 | (0 ? ((f)(&(self)->ctx, ~(size_t) 0, \ |
61 | (uint8_t *) 0, (const uint8_t *) 0)) \ |
62 | : ctr_crypt((void *) &(self)->ctx, \ |
63 | (nettle_cipher_func *) (f), \ |
64 | sizeof((self)->ctr), (self)->ctr, \ |
65 | (length), (dst), (src))) |
66 | |
67 | #ifdef __cplusplus |
68 | } |
69 | #endif |
70 | |
71 | #endif /* NETTLE_CTR_H_INCLUDED */ |
72 | |