2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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>.
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
19 static int burn_crypter(const proposal_token_t
*token
, u_int limit
)
26 crypter
= lib
->crypto
->create_crypter(lib
->crypto
, token
->algorithm
,
30 fprintf(stderr
, "%N-%zu not supported\n",
31 encryption_algorithm_names
, token
->algorithm
, token
->keysize
);
35 iv
= chunk_alloc(crypter
->get_iv_size(crypter
));
36 memset(iv
.ptr
, 0xFF, iv
.len
);
37 data
= chunk_alloc(round_up(1024, crypter
->get_block_size(crypter
)));
38 memset(data
.ptr
, 0xDD, data
.len
);
43 if (!crypter
->encrypt(crypter
, data
, iv
, NULL
))
45 fprintf(stderr
, "encryption failed!\n");
49 if (!crypter
->decrypt(crypter
, data
, iv
, NULL
))
51 fprintf(stderr
, "decryption failed!\n");
55 if (limit
&& ++i
== limit
)
60 crypter
->destroy(crypter
);
68 static bool burn_aead(const proposal_token_t
*token
, u_int limit
)
70 chunk_t iv
, data
, dataicv
, assoc
;
75 aead
= lib
->crypto
->create_aead(lib
->crypto
, token
->algorithm
,
76 token
->keysize
/ 8, 0);
79 fprintf(stderr
, "%N-%zu not supported\n",
80 encryption_algorithm_names
, token
->algorithm
, token
->keysize
);
84 iv
= chunk_alloc(aead
->get_iv_size(aead
));
85 memset(iv
.ptr
, 0xFF, iv
.len
);
86 dataicv
= chunk_alloc(round_up(1024, aead
->get_block_size(aead
)) +
87 aead
->get_icv_size(aead
));
88 data
= chunk_create(dataicv
.ptr
, dataicv
.len
- aead
->get_icv_size(aead
));
89 memset(data
.ptr
, 0xDD, data
.len
);
90 assoc
= chunk_alloc(13);
91 memset(assoc
.ptr
, 0xCC, assoc
.len
);
96 if (!aead
->encrypt(aead
, data
, assoc
, iv
, NULL
))
98 fprintf(stderr
, "aead encryption failed!\n");
102 if (!aead
->decrypt(aead
, dataicv
, assoc
, iv
, NULL
))
104 fprintf(stderr
, "aead integrity check failed!\n");
108 if (limit
&& ++i
== limit
)
121 int main(int argc
, char *argv
[])
123 const proposal_token_t
*token
;
127 library_init(NULL
, "crypt_burn");
128 lib
->plugins
->load(lib
->plugins
, getenv("PLUGINS") ?: PLUGINS
);
129 atexit(library_deinit
);
131 fprintf(stderr
, "loaded: %s\n", lib
->plugins
->loaded_plugins(lib
->plugins
));
135 fprintf(stderr
, "usage: %s <algorithm>!\n", argv
[0]);
140 limit
= atoi(argv
[2]);
143 token
= lib
->proposal
->get_token(lib
->proposal
, argv
[1]);
146 fprintf(stderr
, "algorithm '%s' unknown!\n", argv
[1]);
152 case ENCRYPTION_ALGORITHM
:
153 if (encryption_algorithm_is_aead(token
->algorithm
))
155 ok
= burn_aead(token
, limit
);
159 ok
= burn_crypter(token
, limit
);
163 fprintf(stderr
, "'%s' is not a crypter/aead algorithm!\n", argv
[1]);