]>
Commit | Line | Data |
---|---|---|
f3af4969 TB |
1 | /* |
2 | * Copyright (C) 2010 Martin Willi | |
3 | * Copyright (C) 2010 revosec AG | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | * for more details. | |
14 | */ | |
37e52c3f MW |
15 | |
16 | #include <stdio.h> | |
17 | #include <library.h> | |
37e52c3f MW |
18 | |
19 | int main(int argc, char *argv[]) | |
20 | { | |
21 | const proposal_token_t *token; | |
22 | aead_t *aead; | |
23 | crypter_t *crypter; | |
24 | char buffer[1024], assoc[8], iv[32]; | |
25 | size_t bs; | |
26 | int i = 0, limit = 0; | |
27 | ||
28 | ||
34d3bfcf | 29 | library_init(NULL, "crypt_burn"); |
b18a5317 | 30 | lib->plugins->load(lib->plugins, PLUGINS); |
37e52c3f MW |
31 | atexit(library_deinit); |
32 | ||
33 | printf("loaded: %s\n", PLUGINS); | |
34 | ||
35 | memset(buffer, 0x12, sizeof(buffer)); | |
36 | memset(assoc, 0x34, sizeof(assoc)); | |
37 | memset(iv, 0x56, sizeof(iv)); | |
38 | ||
39 | if (argc < 2) | |
40 | { | |
41 | fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]); | |
42 | return 1; | |
43 | } | |
44 | if (argc > 2) | |
45 | { | |
46 | limit = atoi(argv[2]); | |
47 | } | |
48 | ||
4c57c630 | 49 | token = lib->proposal->get_token(lib->proposal, argv[1]); |
37e52c3f MW |
50 | if (!token) |
51 | { | |
52 | fprintf(stderr, "algorithm '%s' unknown!\n", argv[1]); | |
53 | return 1; | |
54 | } | |
55 | if (token->type != ENCRYPTION_ALGORITHM) | |
56 | { | |
57 | fprintf(stderr, "'%s' is not an encryption/aead algorithm!\n", argv[1]); | |
58 | return 1; | |
59 | } | |
60 | ||
61 | if (encryption_algorithm_is_aead(token->algorithm)) | |
62 | { | |
63 | aead = lib->crypto->create_aead(lib->crypto, | |
e5d73b0d | 64 | token->algorithm, token->keysize / 8, 0); |
37e52c3f MW |
65 | if (!aead) |
66 | { | |
67 | fprintf(stderr, "aead '%s' not supported!\n", argv[1]); | |
68 | return 1; | |
69 | } | |
70 | while (TRUE) | |
71 | { | |
e2ed7bfd | 72 | if (!aead->encrypt(aead, |
37e52c3f MW |
73 | chunk_create(buffer, sizeof(buffer) - aead->get_icv_size(aead)), |
74 | chunk_from_thing(assoc), | |
e2ed7bfd MW |
75 | chunk_create(iv, aead->get_iv_size(aead)), NULL)) |
76 | { | |
77 | fprintf(stderr, "aead encryption failed!\n"); | |
78 | return 1; | |
79 | } | |
37e52c3f MW |
80 | if (!aead->decrypt(aead, chunk_create(buffer, sizeof(buffer)), |
81 | chunk_from_thing(assoc), | |
82 | chunk_create(iv, aead->get_iv_size(aead)), NULL)) | |
83 | { | |
84 | fprintf(stderr, "aead integrity check failed!\n"); | |
79d5c4f0 | 85 | return 1; |
37e52c3f MW |
86 | } |
87 | if (limit && ++i == limit) | |
88 | { | |
89 | break; | |
90 | } | |
91 | } | |
51caeeb1 | 92 | aead->destroy(aead); |
37e52c3f MW |
93 | } |
94 | else | |
95 | { | |
96 | crypter = lib->crypto->create_crypter(lib->crypto, | |
97 | token->algorithm, token->keysize / 8); | |
98 | if (!crypter) | |
99 | { | |
100 | fprintf(stderr, "crypter '%s' not supported!\n", argv[1]); | |
101 | return 1; | |
102 | } | |
103 | bs = crypter->get_block_size(crypter); | |
104 | ||
d4f2f3dd | 105 | while (TRUE) |
37e52c3f | 106 | { |
e35abbe5 MW |
107 | if (!crypter->encrypt(crypter, |
108 | chunk_create(buffer, sizeof(buffer) / bs * bs), | |
109 | chunk_create(iv, crypter->get_iv_size(crypter)), NULL)) | |
110 | { | |
111 | continue; | |
112 | } | |
3b96189a MW |
113 | if (!crypter->decrypt(crypter, |
114 | chunk_create(buffer, sizeof(buffer) / bs * bs), | |
115 | chunk_create(iv, crypter->get_iv_size(crypter)), NULL)) | |
116 | { | |
117 | continue; | |
118 | } | |
37e52c3f MW |
119 | if (limit && ++i == limit) |
120 | { | |
121 | break; | |
122 | } | |
123 | } | |
51caeeb1 | 124 | crypter->destroy(crypter); |
37e52c3f MW |
125 | } |
126 | return 0; | |
127 | } |