Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_ecb_3des_encrypt.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mcrypt_ecb() function : basic functionality 
                      3: --SKIPIF--
                      4: <?php 
                      5: if (!extension_loaded("mcrypt")) {
                      6:        print "skip - mcrypt extension not loaded"; 
                      7: }       
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11: /* Prototype  : string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
                     12:  * Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv 
                     13:  * Source code: ext/mcrypt/mcrypt.c
                     14:  * Alias to functions: 
                     15:  */
                     16: 
                     17: echo "*** Testing mcrypt_ecb() : basic functionality ***\n";
                     18: 
                     19: 
                     20: $cipher = MCRYPT_TRIPLEDES;
                     21: $data = b"This is the secret message which must be encrypted";
                     22: $mode = MCRYPT_ENCRYPT;
                     23: 
                     24: // tripledes uses keys upto 192 bits (24 bytes)
                     25: $keys = array(
                     26:    b'12345678', 
                     27:    b'12345678901234567890', 
                     28:    b'123456789012345678901234', 
                     29:    b'12345678901234567890123456'
                     30: );
                     31: // tripledes is a block cipher of 64 bits (8 bytes)
                     32: $ivs = array(
                     33:    b'1234', 
                     34:    b'12345678', 
                     35:    b'123456789'
                     36: );
                     37: 
                     38: $iv = b'12345678';
                     39: echo "\n--- testing different key lengths\n";
                     40: foreach ($keys as $key) {
                     41:    echo "\nkey length=".strlen($key)."\n";
                     42:    var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $mode, $iv)));
                     43: }
                     44: 
                     45: $key = b'1234567890123456';  
                     46: echo "\n--- testing different iv lengths\n";
                     47: foreach ($ivs as $iv) {
                     48:    echo "\niv length=".strlen($iv)."\n";
                     49:    var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $mode, $iv)));
                     50: }
                     51: ?>
                     52: ===DONE===
                     53: --EXPECTF--
                     54: *** Testing mcrypt_ecb() : basic functionality ***
                     55: 
                     56: --- testing different key lengths
                     57: 
                     58: key length=8
                     59: string(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
                     60: 
                     61: key length=20
                     62: string(112) "0fc7045c4fb4dbcf44baf9ed15ab40331a42ff0632318a16b12ed5873f02e7945e4f63f408d6849534cbb7419c22c8854aaa85e0e05a28e6"
                     63: 
                     64: key length=24
                     65: string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
                     66: 
                     67: key length=26
                     68: 
                     69: Warning: mcrypt_ecb(): Size of key is too large for this algorithm in %s on line %d
                     70: string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
                     71: 
                     72: --- testing different iv lengths
                     73: 
                     74: iv length=4
                     75: string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
                     76: 
                     77: iv length=8
                     78: string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
                     79: 
                     80: iv length=9
                     81: string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
                     82: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>