twofish.t
1 #! /usr/bin/env perl 2 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # See the NOTICE file distributed with this work for additional 6 # information regarding copyright ownership. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 use strict; 18 use warnings; 19 20 use FindBin; 21 use lib "$FindBin::Bin"; 22 use driver; 23 use cmd_helpers; 24 25 runtests( 26 { 27 title => 'Twofish-ECB with test vector from libtomcrypt', 28 cases => [ 29 encrypt => { 30 input => 'input', 31 output => 'output', 32 auxilliary => 'key', 33 cmd => mk_cmd('lesec-tool', 'enc', 34 '-plugin ltc', 35 'twofish-ecb', 36 mk_key_from('key'), 37 mk_opts(-pad => 'STRING')), 38 }, 39 decrypt => { 40 input => 'output', 41 output => 'input', 42 auxilliary => 'key', 43 cmd => mk_cmd('lesec-tool', 'dec', 44 '-plugin ltc', 45 'twofish-ecb', 46 mk_key_from('key'), 47 mk_opts(-pad => 'STRING')), 48 }, 49 ], 50 vectors => [ 51 { 52 title => '128 bit key', 53 key => { key => "9F589F5CF6122C32B6BFEC2F2AE8C35A" }, 54 -pad => 0, 55 tests => [ 56 { 57 input => "D491DB16E7B1C39E86CB086B789F5419", 58 output => "019F9809DE1711858FAAC3A3BA20FBC3" 59 }, 60 ] 61 }, 62 { 63 title => '192 bit key', 64 key => { key => "88B2B2706B105E36B446BB6D731A1E88EFA71F788965BD44" }, 65 -pad => 0, 66 tests => [ 67 { 68 input => "39DA69D6BA4997D585B6DC073CA341B2", 69 output => "182B02D81497EA45F9DAACDC29193A65" 70 }, 71 ] 72 }, 73 { 74 title => '256 bit key', 75 key => { key => "D43BB7556EA32E46F2A282B7D45B4E0D57FF739D4DC92C1BD7FC01700CC8216F" }, 76 -pad => 0, 77 tests => [ 78 { 79 input => "90AFE91BB288544F2C32DC239B2635E6", 80 output => "6CB4561C40BF0A9705931CB6D408E7FA" 81 }, 82 ] 83 } 84 ] 85 } 86 );