IDEA/Serpent tests
Karel Miko
6 years ago
323 | 323 | PROTOTYPES: DISABLE |
324 | 324 | |
325 | 325 | BOOT: |
326 | if(register_cipher(&blowfish_desc)==-1) { croak("FATAL: cannot register_cipher blowfish"); } | |
327 | if(register_cipher(&rc5_desc)==-1) { croak("FATAL: cannot register_cipher rc5"); } | |
328 | if(register_cipher(&rc6_desc)==-1) { croak("FATAL: cannot register_cipher rc6"); } | |
329 | if(register_cipher(&rc2_desc)==-1) { croak("FATAL: cannot register_cipher rc2"); } | |
330 | if(register_cipher(&saferp_desc)==-1) { croak("FATAL: cannot register_cipher saferp"); } | |
331 | if(register_cipher(&safer_k64_desc)==-1) { croak("FATAL: cannot register_cipher safer_k64"); } | |
332 | if(register_cipher(&safer_k128_desc)==-1) { croak("FATAL: cannot register_cipher safer_k128"); } | |
333 | if(register_cipher(&safer_sk64_desc)==-1) { croak("FATAL: cannot register_cipher safer_sk64"); } | |
334 | if(register_cipher(&safer_sk128_desc)==-1) { croak("FATAL: cannot register_cipher safer_sk128"); } | |
335 | if(register_cipher(&aes_desc)==-1) { croak("FATAL: cannot register_cipher aes"); } | |
336 | if(register_cipher(&xtea_desc)==-1) { croak("FATAL: cannot register_cipher xtea"); } | |
337 | if(register_cipher(&twofish_desc)==-1) { croak("FATAL: cannot register_cipher twofish"); } | |
338 | if(register_cipher(&des_desc)==-1) { croak("FATAL: cannot register_cipher des"); } | |
339 | if(register_cipher(&des3_desc)==-1) { croak("FATAL: cannot register_cipher des3"); } | |
340 | if(register_cipher(&cast5_desc)==-1) { croak("FATAL: cannot register_cipher cast5"); } | |
341 | if(register_cipher(&noekeon_desc)==-1) { croak("FATAL: cannot register_cipher noekeon"); } | |
342 | if(register_cipher(&skipjack_desc)==-1) { croak("FATAL: cannot register_cipher skipjack"); } | |
343 | if(register_cipher(&khazad_desc)==-1) { croak("FATAL: cannot register_cipher khazad"); } | |
344 | if(register_cipher(&anubis_desc)==-1) { croak("FATAL: cannot register_cipher anubis"); } | |
345 | if(register_cipher(&kseed_desc)==-1) { croak("FATAL: cannot register_cipher kseed"); } | |
346 | if(register_cipher(&kasumi_desc)==-1) { croak("FATAL: cannot register_cipher kasumi"); } | |
347 | if(register_cipher(&multi2_desc)==-1) { croak("FATAL: cannot register_cipher multi2"); } | |
348 | if(register_cipher(&camellia_desc)==-1) { croak("FATAL: cannot register_cipher camellia"); } | |
349 | /* --- */ | |
350 | if(register_hash(&chc_desc)==-1) { croak("FATAL: cannot register_hash chc_hash"); } | |
351 | if(register_hash(&md2_desc)==-1) { croak("FATAL: cannot register_hash md2"); } | |
352 | if(register_hash(&md4_desc)==-1) { croak("FATAL: cannot register_hash md4"); } | |
353 | if(register_hash(&md5_desc)==-1) { croak("FATAL: cannot register_hash md5"); } | |
354 | if(register_hash(&rmd128_desc)==-1) { croak("FATAL: cannot register_hash rmd128"); } | |
355 | if(register_hash(&rmd160_desc)==-1) { croak("FATAL: cannot register_hash rmd160"); } | |
356 | if(register_hash(&rmd256_desc)==-1) { croak("FATAL: cannot register_hash rmd256"); } | |
357 | if(register_hash(&rmd320_desc)==-1) { croak("FATAL: cannot register_hash rmd320"); } | |
358 | if(register_hash(&sha1_desc)==-1) { croak("FATAL: cannot register_hash sha1"); } | |
359 | if(register_hash(&sha224_desc)==-1) { croak("FATAL: cannot register_hash sha224"); } | |
360 | if(register_hash(&sha256_desc)==-1) { croak("FATAL: cannot register_hash sha256"); } | |
361 | if(register_hash(&sha384_desc)==-1) { croak("FATAL: cannot register_hash sha384"); } | |
362 | if(register_hash(&sha512_desc)==-1) { croak("FATAL: cannot register_hash sha512"); } | |
363 | if(register_hash(&sha512_224_desc)==-1) { croak("FATAL: cannot register_hash sha512_224"); } | |
364 | if(register_hash(&sha512_256_desc)==-1) { croak("FATAL: cannot register_hash sha512_256"); } | |
365 | if(register_hash(&sha3_224_desc)==-1) { croak("FATAL: cannot register_hash sha3_224"); } | |
366 | if(register_hash(&sha3_256_desc)==-1) { croak("FATAL: cannot register_hash sha3_256"); } | |
367 | if(register_hash(&sha3_384_desc)==-1) { croak("FATAL: cannot register_hash sha3_384"); } | |
368 | if(register_hash(&sha3_512_desc)==-1) { croak("FATAL: cannot register_hash sha3_512"); } | |
369 | if(register_hash(&tiger_desc)==-1) { croak("FATAL: cannot register_hash tiger"); } | |
370 | if(register_hash(&whirlpool_desc)==-1) { croak("FATAL: cannot register_hash whirlpool"); } | |
371 | if(register_hash(&blake2b_160_desc)==-1) { croak("FATAL: cannot register_hash blake2b_160"); } | |
372 | if(register_hash(&blake2b_256_desc)==-1) { croak("FATAL: cannot register_hash blake2b_256"); } | |
373 | if(register_hash(&blake2b_384_desc)==-1) { croak("FATAL: cannot register_hash blake2b_384"); } | |
374 | if(register_hash(&blake2b_512_desc)==-1) { croak("FATAL: cannot register_hash blake2b_512"); } | |
375 | if(register_hash(&blake2s_128_desc)==-1) { croak("FATAL: cannot register_hash blake2s_128"); } | |
376 | if(register_hash(&blake2s_160_desc)==-1) { croak("FATAL: cannot register_hash blake2s_160"); } | |
377 | if(register_hash(&blake2s_224_desc)==-1) { croak("FATAL: cannot register_hash blake2s_224"); } | |
378 | if(register_hash(&blake2s_256_desc)==-1) { croak("FATAL: cannot register_hash blake2s_256"); } | |
379 | /* --- */ | |
380 | if(chc_register(find_cipher("aes"))==-1) { croak("FATAL: chc_register failed"); } | |
381 | /* --- */ | |
382 | if(register_prng(&fortuna_desc)==-1) { croak("FATAL: cannot register_prng fortuna"); } | |
383 | if(register_prng(&yarrow_desc)==-1) { croak("FATAL: cannot register_prng yarrow"); } | |
384 | if(register_prng(&rc4_desc)==-1) { croak("FATAL: cannot register_prng rc4"); } | |
385 | if(register_prng(&sober128_desc)==-1) { croak("FATAL: cannot register_prng sober128"); } | |
386 | if(register_prng(&chacha20_prng_desc)==-1) { croak("FATAL: cannot register_prng chacha20"); } | |
387 | /* --- */ | |
388 | #ifdef TFM_DESC | |
389 | ltc_mp = tfm_desc; | |
390 | #else | |
326 | if(register_all_ciphers() == CRYPT_ERROR) { croak("FATAL: register_all_ciphers failed"); } | |
327 | if(register_all_hashes() == CRYPT_ERROR) { croak("FATAL: register_all_hashes failed"); } | |
328 | if(register_all_prngs() == CRYPT_ERROR) { croak("FATAL: register_all_prngs failed"); } | |
329 | if(chc_register(find_cipher("aes"))==-1) { croak("FATAL: chc_register failed"); } | |
391 | 330 | ltc_mp = ltm_desc; |
392 | #endif | |
393 | 331 | |
394 | 332 | SV * |
395 | 333 | CryptX__encode_base64url(SV * in) |
0 | ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! | |
1 | ||
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use Test::More tests => 38; | |
6 | ||
7 | use Crypt::Cipher; | |
8 | use Crypt::Cipher::IDEA; | |
9 | ||
10 | is( Crypt::Cipher::IDEA::blocksize, 8, '::blocksize'); | |
11 | is( Crypt::Cipher::IDEA::keysize, 16, '::keysize'); | |
12 | is( Crypt::Cipher::IDEA::max_keysize, 16, '::max_keysize'); | |
13 | is( Crypt::Cipher::IDEA::min_keysize, 16, '::min_keysize'); | |
14 | is( Crypt::Cipher::IDEA::default_rounds, 8, '::default_rounds'); | |
15 | ||
16 | is( Crypt::Cipher::IDEA->blocksize, 8, '->blocksize'); | |
17 | is( Crypt::Cipher::IDEA->keysize, 16, '->keysize'); | |
18 | is( Crypt::Cipher::IDEA->max_keysize, 16, '->max_keysize'); | |
19 | is( Crypt::Cipher::IDEA->min_keysize, 16, '->min_keysize'); | |
20 | is( Crypt::Cipher::IDEA->default_rounds, 8, '->default_rounds'); | |
21 | ||
22 | my $min_key = 'kkkkkkkkkkkkkkkk'; | |
23 | my $max_key = 'KKKKKKKKKKKKKKKK'; | |
24 | ||
25 | is( Crypt::Cipher::blocksize('IDEA'), 8, 'Cipher->blocksize'); | |
26 | is( Crypt::Cipher::keysize('IDEA'), 16, 'Cipher->keysize'); | |
27 | is( Crypt::Cipher::max_keysize('IDEA'), 16, 'Cipher->max_keysize'); | |
28 | is( Crypt::Cipher::min_keysize('IDEA'), 16, 'Cipher->min_keysize'); | |
29 | is( Crypt::Cipher::default_rounds('IDEA'), 8, 'Cipher->default_rounds'); | |
30 | ||
31 | is( Crypt::Cipher->blocksize('IDEA'), 8, 'Cipher->blocksize'); | |
32 | is( Crypt::Cipher->keysize('IDEA'), 16, 'Cipher->keysize'); | |
33 | is( Crypt::Cipher->max_keysize('IDEA'), 16, 'Cipher->max_keysize'); | |
34 | is( Crypt::Cipher->min_keysize('IDEA'), 16, 'Cipher->min_keysize'); | |
35 | is( Crypt::Cipher->default_rounds('IDEA'), 8, 'Cipher->default_rounds'); | |
36 | ||
37 | is( Crypt::Cipher::IDEA->new($min_key)->blocksize, 8, 'IDEA->new()->blocksize'); | |
38 | is( Crypt::Cipher::IDEA->new($min_key)->keysize, 16, 'IDEA->new()->keysize'); | |
39 | is( Crypt::Cipher::IDEA->new($min_key)->max_keysize, 16, 'IDEA->new()->max_keysize'); | |
40 | is( Crypt::Cipher::IDEA->new($min_key)->min_keysize, 16, 'IDEA->new()->min_keysize'); | |
41 | is( Crypt::Cipher::IDEA->new($min_key)->default_rounds, 8, 'IDEA->new()->default_rounds'); | |
42 | ||
43 | is( Crypt::Cipher->new('IDEA', $min_key)->blocksize, 8, 'Cipher->new()->blocksize'); | |
44 | is( Crypt::Cipher->new('IDEA', $min_key)->keysize, 16, 'Cipher->new()->keysize'); | |
45 | is( Crypt::Cipher->new('IDEA', $min_key)->max_keysize, 16, 'Cipher->new()->max_keysize'); | |
46 | is( Crypt::Cipher->new('IDEA', $min_key)->min_keysize, 16, 'Cipher->new()->min_keysize'); | |
47 | is( Crypt::Cipher->new('IDEA', $min_key)->default_rounds, 8, 'Cipher->new()->default_rounds'); | |
48 | ||
49 | my $block_plain = 'BBBBBBBB'; | |
50 | my $block_encrypted_min_key_hex = '02bb362ef47743bc'; | |
51 | my $block_encrypted_max_key_hex = '041aa0caeb50668f'; | |
52 | ||
53 | is( unpack('H*', Crypt::Cipher::IDEA->new($min_key)->encrypt($block_plain)), $block_encrypted_min_key_hex, 'IDEA->encrypt'); | |
54 | is( Crypt::Cipher::IDEA->new($min_key)->decrypt(pack('H*', $block_encrypted_min_key_hex)), $block_plain, 'IDEA->decrypt'); | |
55 | ||
56 | is( unpack('H*', Crypt::Cipher->new('IDEA', $min_key)->encrypt($block_plain)), $block_encrypted_min_key_hex, 'Cipher->encrypt'); | |
57 | is( Crypt::Cipher->new('IDEA', $min_key)->decrypt(pack('H*', $block_encrypted_min_key_hex)), $block_plain, 'Cipher->decrypt'); | |
58 | ||
59 | is( unpack('H*', Crypt::Cipher::IDEA->new($max_key)->encrypt($block_plain)), $block_encrypted_max_key_hex, 'IDEA->encrypt'); | |
60 | is( Crypt::Cipher::IDEA->new($max_key)->decrypt(pack('H*', $block_encrypted_max_key_hex)), $block_plain, 'IDEA->decrypt'); | |
61 | ||
62 | is( unpack('H*', Crypt::Cipher->new('IDEA', $max_key)->encrypt($block_plain)), $block_encrypted_max_key_hex, 'Cipher->encrypt'); | |
63 | is( Crypt::Cipher->new('IDEA', $max_key)->decrypt(pack('H*', $block_encrypted_max_key_hex)), $block_plain, 'Cipher->decrypt'); | |
64 |
0 | ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! | |
1 | ||
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use Test::More tests => 38; | |
6 | ||
7 | use Crypt::Cipher; | |
8 | use Crypt::Cipher::Serpent; | |
9 | ||
10 | is( Crypt::Cipher::Serpent::blocksize, 16, '::blocksize'); | |
11 | is( Crypt::Cipher::Serpent::keysize, 32, '::keysize'); | |
12 | is( Crypt::Cipher::Serpent::max_keysize, 32, '::max_keysize'); | |
13 | is( Crypt::Cipher::Serpent::min_keysize, 16, '::min_keysize'); | |
14 | is( Crypt::Cipher::Serpent::default_rounds, 32, '::default_rounds'); | |
15 | ||
16 | is( Crypt::Cipher::Serpent->blocksize, 16, '->blocksize'); | |
17 | is( Crypt::Cipher::Serpent->keysize, 32, '->keysize'); | |
18 | is( Crypt::Cipher::Serpent->max_keysize, 32, '->max_keysize'); | |
19 | is( Crypt::Cipher::Serpent->min_keysize, 16, '->min_keysize'); | |
20 | is( Crypt::Cipher::Serpent->default_rounds, 32, '->default_rounds'); | |
21 | ||
22 | my $min_key = 'kkkkkkkkkkkkkkkk'; | |
23 | my $max_key = 'KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK'; | |
24 | ||
25 | is( Crypt::Cipher::blocksize('Serpent'), 16, 'Cipher->blocksize'); | |
26 | is( Crypt::Cipher::keysize('Serpent'), 32, 'Cipher->keysize'); | |
27 | is( Crypt::Cipher::max_keysize('Serpent'), 32, 'Cipher->max_keysize'); | |
28 | is( Crypt::Cipher::min_keysize('Serpent'), 16, 'Cipher->min_keysize'); | |
29 | is( Crypt::Cipher::default_rounds('Serpent'), 32, 'Cipher->default_rounds'); | |
30 | ||
31 | is( Crypt::Cipher->blocksize('Serpent'), 16, 'Cipher->blocksize'); | |
32 | is( Crypt::Cipher->keysize('Serpent'), 32, 'Cipher->keysize'); | |
33 | is( Crypt::Cipher->max_keysize('Serpent'), 32, 'Cipher->max_keysize'); | |
34 | is( Crypt::Cipher->min_keysize('Serpent'), 16, 'Cipher->min_keysize'); | |
35 | is( Crypt::Cipher->default_rounds('Serpent'), 32, 'Cipher->default_rounds'); | |
36 | ||
37 | is( Crypt::Cipher::Serpent->new($min_key)->blocksize, 16, 'Serpent->new()->blocksize'); | |
38 | is( Crypt::Cipher::Serpent->new($min_key)->keysize, 32, 'Serpent->new()->keysize'); | |
39 | is( Crypt::Cipher::Serpent->new($min_key)->max_keysize, 32, 'Serpent->new()->max_keysize'); | |
40 | is( Crypt::Cipher::Serpent->new($min_key)->min_keysize, 16, 'Serpent->new()->min_keysize'); | |
41 | is( Crypt::Cipher::Serpent->new($min_key)->default_rounds, 32, 'Serpent->new()->default_rounds'); | |
42 | ||
43 | is( Crypt::Cipher->new('Serpent', $min_key)->blocksize, 16, 'Cipher->new()->blocksize'); | |
44 | is( Crypt::Cipher->new('Serpent', $min_key)->keysize, 32, 'Cipher->new()->keysize'); | |
45 | is( Crypt::Cipher->new('Serpent', $min_key)->max_keysize, 32, 'Cipher->new()->max_keysize'); | |
46 | is( Crypt::Cipher->new('Serpent', $min_key)->min_keysize, 16, 'Cipher->new()->min_keysize'); | |
47 | is( Crypt::Cipher->new('Serpent', $min_key)->default_rounds, 32, 'Cipher->new()->default_rounds'); | |
48 | ||
49 | my $block_plain = 'BBBBBBBBBBBBBBBB'; | |
50 | my $block_encrypted_min_key_hex = '094d7ab58dc7b85796ffe99969ddef9a'; | |
51 | my $block_encrypted_max_key_hex = '93b33ee7b88de79c6045e461552403f0'; | |
52 | ||
53 | is( unpack('H*', Crypt::Cipher::Serpent->new($min_key)->encrypt($block_plain)), $block_encrypted_min_key_hex, 'Serpent->encrypt'); | |
54 | is( Crypt::Cipher::Serpent->new($min_key)->decrypt(pack('H*', $block_encrypted_min_key_hex)), $block_plain, 'Serpent->decrypt'); | |
55 | ||
56 | is( unpack('H*', Crypt::Cipher->new('Serpent', $min_key)->encrypt($block_plain)), $block_encrypted_min_key_hex, 'Cipher->encrypt'); | |
57 | is( Crypt::Cipher->new('Serpent', $min_key)->decrypt(pack('H*', $block_encrypted_min_key_hex)), $block_plain, 'Cipher->decrypt'); | |
58 | ||
59 | is( unpack('H*', Crypt::Cipher::Serpent->new($max_key)->encrypt($block_plain)), $block_encrypted_max_key_hex, 'Serpent->encrypt'); | |
60 | is( Crypt::Cipher::Serpent->new($max_key)->decrypt(pack('H*', $block_encrypted_max_key_hex)), $block_plain, 'Serpent->decrypt'); | |
61 | ||
62 | is( unpack('H*', Crypt::Cipher->new('Serpent', $max_key)->encrypt($block_plain)), $block_encrypted_max_key_hex, 'Cipher->encrypt'); | |
63 | is( Crypt::Cipher->new('Serpent', $max_key)->decrypt(pack('H*', $block_encrypted_max_key_hex)), $block_plain, 'Cipher->decrypt'); | |
64 |