]>
git.ipfire.org Git - people/ms/strongswan.git/blob - scripts/crypt_burn.c
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 int main(int argc
, char *argv
[])
21 const proposal_token_t
*token
;
24 char buffer
[1024], assoc
[8], iv
[32];
29 library_init(NULL
, "crypt_burn");
30 lib
->plugins
->load(lib
->plugins
, PLUGINS
);
31 atexit(library_deinit
);
33 printf("loaded: %s\n", PLUGINS
);
35 memset(buffer
, 0x12, sizeof(buffer
));
36 memset(assoc
, 0x34, sizeof(assoc
));
37 memset(iv
, 0x56, sizeof(iv
));
41 fprintf(stderr
, "usage: %s <algorithm>!\n", argv
[0]);
46 limit
= atoi(argv
[2]);
49 token
= lib
->proposal
->get_token(lib
->proposal
, argv
[1]);
52 fprintf(stderr
, "algorithm '%s' unknown!\n", argv
[1]);
55 if (token
->type
!= ENCRYPTION_ALGORITHM
)
57 fprintf(stderr
, "'%s' is not an encryption/aead algorithm!\n", argv
[1]);
61 if (encryption_algorithm_is_aead(token
->algorithm
))
63 aead
= lib
->crypto
->create_aead(lib
->crypto
,
64 token
->algorithm
, token
->keysize
/ 8, 0);
67 fprintf(stderr
, "aead '%s' not supported!\n", argv
[1]);
72 if (!aead
->encrypt(aead
,
73 chunk_create(buffer
, sizeof(buffer
) - aead
->get_icv_size(aead
)),
74 chunk_from_thing(assoc
),
75 chunk_create(iv
, aead
->get_iv_size(aead
)), NULL
))
77 fprintf(stderr
, "aead encryption failed!\n");
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
))
84 fprintf(stderr
, "aead integrity check failed!\n");
87 if (limit
&& ++i
== limit
)
96 crypter
= lib
->crypto
->create_crypter(lib
->crypto
,
97 token
->algorithm
, token
->keysize
/ 8);
100 fprintf(stderr
, "crypter '%s' not supported!\n", argv
[1]);
103 bs
= crypter
->get_block_size(crypter
);
107 if (!crypter
->encrypt(crypter
,
108 chunk_create(buffer
, sizeof(buffer
) / bs
* bs
),
109 chunk_create(iv
, crypter
->get_iv_size(crypter
)), NULL
))
113 if (!crypter
->decrypt(crypter
,
114 chunk_create(buffer
, sizeof(buffer
) / bs
* bs
),
115 chunk_create(iv
, crypter
->get_iv_size(crypter
)), NULL
))
119 if (limit
&& ++i
== limit
)
124 crypter
->destroy(crypter
);