/ tests / cast5.t
cast5.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 => 'CAST5-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                                            'cast5-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                                            'cast5-ecb',
46                                            mk_key_from('key'),
47                                            mk_opts(-pad  => 'STRING')),
48              },
49          ],
50          vectors => [
51              {
52                  title => '128 bit key',
53                  key   => { key => "0123456712345678234567893456789A" },
54                  -pad  => 0,
55                  tests => [
56                      {
57                          input   => "0123456789ABCDEF",
58                          output  => "238B4FE5847E44B2"
59                      },
60                  ]
61              },
62              {
63                  title => '80 bit key',
64                  key   => { key => "01234567123456782345" },
65                  -pad  => 0,
66                  tests => [
67                      {
68                          input   => "0123456789ABCDEF",
69                          output  => "EB6A711A2C02271B"
70                      },
71                  ]
72              },
73              {
74                  title => '40 bit key',
75                  key   => { key => "0123456712" },
76                  -pad  => 0,
77                  tests => [
78                      {
79                          input   => "0123456789ABCDEF",
80                          output  => "7AC816D16E9B302E"
81                      },
82                  ]
83              }
84          ]
85      }
86  );