4 #include <crypto/proposal/proposal_keywords.h>
6 int main(int argc
, char *argv
[])
8 const proposal_token_t
*token
;
11 char buffer
[1024], assoc
[8], iv
[32];
17 lib
->plugins
->load(lib
->plugins
, NULL
, PLUGINS
);
18 atexit(library_deinit
);
20 printf("loaded: %s\n", PLUGINS
);
22 memset(buffer
, 0x12, sizeof(buffer
));
23 memset(assoc
, 0x34, sizeof(assoc
));
24 memset(iv
, 0x56, sizeof(iv
));
28 fprintf(stderr
, "usage: %s <algorithm>!\n", argv
[0]);
33 limit
= atoi(argv
[2]);
36 token
= proposal_get_token(argv
[1], strlen(argv
[1]));
39 fprintf(stderr
, "algorithm '%s' unknown!\n", argv
[1]);
42 if (token
->type
!= ENCRYPTION_ALGORITHM
)
44 fprintf(stderr
, "'%s' is not an encryption/aead algorithm!\n", argv
[1]);
48 if (encryption_algorithm_is_aead(token
->algorithm
))
50 aead
= lib
->crypto
->create_aead(lib
->crypto
,
51 token
->algorithm
, token
->keysize
/ 8);
54 fprintf(stderr
, "aead '%s' not supported!\n", argv
[1]);
60 chunk_create(buffer
, sizeof(buffer
) - aead
->get_icv_size(aead
)),
61 chunk_from_thing(assoc
),
62 chunk_create(iv
, aead
->get_iv_size(aead
)), NULL
);
63 if (!aead
->decrypt(aead
, chunk_create(buffer
, sizeof(buffer
)),
64 chunk_from_thing(assoc
),
65 chunk_create(iv
, aead
->get_iv_size(aead
)), NULL
))
67 fprintf(stderr
, "aead integrity check failed!\n");
70 if (limit
&& ++i
== limit
)
78 crypter
= lib
->crypto
->create_crypter(lib
->crypto
,
79 token
->algorithm
, token
->keysize
/ 8);
82 fprintf(stderr
, "crypter '%s' not supported!\n", argv
[1]);
85 bs
= crypter
->get_block_size(crypter
);
89 crypter
->encrypt(crypter
,
90 chunk_create(buffer
, sizeof(buffer
) / bs
* bs
),
91 chunk_create(iv
, crypter
->get_iv_size(crypter
)), NULL
);
92 crypter
->decrypt(crypter
,
93 chunk_create(buffer
, sizeof(buffer
) / bs
* bs
),
94 chunk_create(iv
, crypter
->get_iv_size(crypter
)), NULL
);
95 if (limit
&& ++i
== limit
)