Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_ecb_3des_decrypt.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mcrypt_cbc() 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_DECRYPT;
        !            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: $data1 = array(
        !            32:    '0D4ArM3ejyhic9rnCcIW9A==',
        !            33:    'q0wt1YeOjLpnKm5WsrzKEw==',
        !            34:    'zwKEFeqHkhlj+7HZTRA/yA==',
        !            35:    'zwKEFeqHkhlj+7HZTRA/yA=='
        !            36: );
        !            37: // tripledes is a block cipher of 64 bits (8 bytes)
        !            38: $ivs = array(
        !            39:    b'1234', 
        !            40:    b'12345678', 
        !            41:    b'123456789'
        !            42: );
        !            43: $data2 = array(
        !            44:    '+G7nGcWIxigQcJD+2P14HA==',
        !            45:    '+G7nGcWIxigQcJD+2P14HA==',
        !            46:    '+G7nGcWIxigQcJD+2P14HA=='
        !            47: );
        !            48: 
        !            49: $iv = b'12345678';
        !            50: echo "\n--- testing different key lengths\n";
        !            51: for ($i = 0; $i < sizeof($keys); $i++) {
        !            52:    echo "\nkey length=".strlen($keys[$i])."\n";
        !            53:    special_var_dump(mcrypt_ecb($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
        !            54: }
        !            55: 
        !            56: $key = b'1234567890123456';  
        !            57: echo "\n--- testing different iv lengths\n";
        !            58: for ($i = 0; $i < sizeof($ivs); $i++) {
        !            59:    echo "\niv length=".strlen($ivs[$i])."\n";
        !            60:    special_var_dump(mcrypt_ecb($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
        !            61: }
        !            62: 
        !            63: function special_var_dump($str) {
        !            64:    var_dump(bin2hex($str));
        !            65: }  
        !            66: ?>
        !            67: ===DONE===
        !            68: --EXPECTF--
        !            69: *** Testing mcrypt_ecb() : basic functionality ***
        !            70: 
        !            71: --- testing different key lengths
        !            72: 
        !            73: key length=8
        !            74: string(32) "736563726574206d6573736167650000"
        !            75: 
        !            76: key length=20
        !            77: string(32) "736563726574206d6573736167650000"
        !            78: 
        !            79: key length=24
        !            80: string(32) "736563726574206d6573736167650000"
        !            81: 
        !            82: key length=26
        !            83: 
        !            84: Warning: mcrypt_ecb(): Size of key is too large for this algorithm in %s on line %d
        !            85: string(32) "736563726574206d6573736167650000"
        !            86: 
        !            87: --- testing different iv lengths
        !            88: 
        !            89: iv length=4
        !            90: string(32) "736563726574206d6573736167650000"
        !            91: 
        !            92: iv length=8
        !            93: string(32) "736563726574206d6573736167650000"
        !            94: 
        !            95: iv length=9
        !            96: string(32) "736563726574206d6573736167650000"
        !            97: ===DONE===

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