/ tests / blake2b.t
blake2b.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 => 'Blake2b-160 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                                    'blake2b-160')
 38              }
 39          ],
 40          vectors => [
 41              {
 42                  tests => [
 43                      {
 44                          input   => $empty,
 45                          output  => "3345524abf6bbe1809449224b5972c41790b6cf2",
 46                      },
 47                      {
 48                          input   => $abc,
 49                          output  => "384264f676f39536840523f284921cdc68b6846b",
 50                      }
 51                  ]
 52              },
 53          ]
 54      },
 55      {
 56          title => 'Blake2b-256 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                                    'blake2b-256')
 64              }
 65          ],
 66          vectors => [
 67              {
 68                  tests => [
 69                      {
 70                          input   => $empty,
 71                          output  => "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8",
 72                      },
 73                      {
 74                          input   => $abc,
 75                          output  => "bddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319",
 76                      },
 77                      {
 78                          input   => $digits_30_times,
 79                          output  => "0f6e018d38d63f084d58e30c90fba2415fca17fa662649f38a30417c57cda814",
 80                      }
 81                  ]
 82              }
 83          ]
 84      },
 85      {
 86          title => 'Blake2b-384 with test vectors from libtomcrypt',
 87          cases => [
 88              hash => {
 89                  input   => 'input',
 90                  output  => 'output',
 91                  cmd     => mk_cmd('lesec-tool', 'digest',
 92                                    '-plugin' => 'ltc',
 93                                    'blake2b-384')
 94              }
 95          ],
 96          vectors => [
 97              {
 98                  tests => [
 99                      {
100                          input   => $empty,
101                          output  => "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100",
102                      },
103                      {
104                          input   => $abc,
105                          output  => "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4"
106                      }
107                  ]
108              }
109          ]
110      },
111      {
112          title => 'Blake2b-512 with test vectors from libtomcrypt',
113          cases => [
114              hash => {
115                  input   => 'input',
116                  output  => 'output',
117                  cmd     => mk_cmd('lesec-tool', 'digest',
118                                    '-plugin' => 'ltc',
119                                    'blake2b-512')
120              }
121          ],
122          vectors => [
123              {
124                  tests => [
125                      {
126                          input   => $empty,
127                          output  => "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce",
128                      },
129                      {
130                          input   => $abc,
131                          output  => "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923",
132                      }
133                  ]
134              }
135          ]
136      },
137  );