/ tests / blake2s.t
blake2s.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  my $digits_30_times = unpack('H*', "1234567890" x 30);
 26  my $empty = '';
 27  my $abc = unpack('H*', "abc");
 28  runtests(
 29      {
 30          title => 'Blake2s-128 with test vectors from libtomcrypt',
 31          cases => [
 32              hash => {
 33                  input   => 'input',
 34                  output  => 'output',
 35                  cmd     => mk_cmd('lesec-tool', 'digest',
 36                                    '-plugin' => 'ltc',
 37                                    'blake2s-128')
 38              }
 39          ],
 40          vectors => [
 41              {
 42                  tests => [
 43                      {
 44                          input   => $empty,
 45                          output  => "64550d6ffe2c0a01a14aba1eade0200c",
 46                      },
 47                      {
 48                          input   => $abc,
 49                          output  => "aa4938119b1dc7b87cbad0ffd200d0ae",
 50                      }
 51                  ]
 52              }
 53          ]
 54      },
 55      {
 56          title => 'Blake2s-160 with test vectors from libtomcrypt',
 57          cases => [
 58              hash => {
 59                  input   => 'input',
 60                  output  => 'output',
 61                  cmd     => mk_cmd('lesec-tool', 'digest',
 62                                    '-plugin' => 'ltc',
 63                                    'blake2s-160')
 64              }
 65          ],
 66          vectors => [
 67              {
 68                  tests => [
 69                      {
 70                          input   => $empty,
 71                          output  => "354c9c33f735962418bdacb9479873429c34916f"
 72                      },
 73                      {
 74                          input   => $abc,
 75                          output  => "5ae3b99be29b01834c3b508521ede60438f8de17",
 76                      }
 77                  ]
 78              }
 79          ]
 80      },
 81      {
 82          title => 'Blake2s-224 with test vectors from libtomcrypt',
 83          cases => [
 84              hash => {
 85                  input   => 'input',
 86                  output  => 'output',
 87                  cmd     => mk_cmd('lesec-tool', 'digest',
 88                                    '-plugin' => 'ltc',
 89                                    'blake2s-224')
 90              }
 91          ],
 92          vectors => [
 93              {
 94                  tests => [
 95                      {
 96                          input   => $empty,
 97                          output  => "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4",
 98                      },
 99                      {
100                          input   => $abc,
101                          output  => "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55"
102                      }
103                  ]
104              }
105          ]
106      },
107      {
108          title => 'Blake2s-256 with test vectors from libtomcrypt',
109          cases => [
110              hash => {
111                  input   => 'input',
112                  output  => 'output',
113                  cmd     => mk_cmd('lesec-tool', 'digest',
114                                    '-plugin' => 'ltc',
115                                    'blake2s-256')
116              }
117          ],
118          vectors => [
119              {
120                  tests => [
121                      {
122                          input   => $empty,
123                          output  => "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9",
124                      },
125                      {
126                          input   => $abc,
127                          output  => "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982",
128                      },
129                      {
130                          input   => $digits_30_times,
131                          output  => "a3788b5b59eee44195235800a4f9fa41860c7b1c35a2427050807956e3be3174",
132                      }
133                  ]
134              }
135          ]
136      },
137  );