root/maint/gnulib/tests/test-md2-buffer.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (C) 2005, 2010-2021 Free Software Foundation, Inc.
   3  *
   4  * This program is free software; you can redistribute it and/or modify
   5  * it under the terms of the GNU General Public License as published by
   6  * the Free Software Foundation; either version 3, or (at your option)
   7  * any later version.
   8  *
   9  * This program is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Simon Josefsson. */
  18 
  19 #include <config.h>
  20 
  21 #include "md2.h"
  22 
  23 #include <stdio.h>
  24 #include <string.h>
  25 
  26 int
  27 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29   const char *in1 = "abc";
  30   const char *out1 =
  31     "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde\xd6\xbb";
  32   const char *in2 = "abcdefghijklmnopqrstuvwxyz";
  33   const char *out2 =
  34     "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b";
  35   char buf[MD2_DIGEST_SIZE];
  36 
  37   if (memcmp (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE) !=
  38       0)
  39     {
  40       size_t i;
  41       printf ("expected:\n");
  42       for (i = 0; i < MD2_DIGEST_SIZE; i++)
  43         printf ("%02x ", out1[i] & 0xFF);
  44       printf ("\ncomputed:\n");
  45       for (i = 0; i < MD2_DIGEST_SIZE; i++)
  46         printf ("%02x ", buf[i] & 0xFF);
  47       printf ("\n");
  48       return 1;
  49     }
  50 
  51   if (memcmp (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE) !=
  52       0)
  53     {
  54       size_t i;
  55       printf ("expected:\n");
  56       for (i = 0; i < MD2_DIGEST_SIZE; i++)
  57         printf ("%02x ", out2[i] & 0xFF);
  58       printf ("\ncomputed:\n");
  59       for (i = 0; i < MD2_DIGEST_SIZE; i++)
  60         printf ("%02x ", buf[i] & 0xFF);
  61       printf ("\n");
  62       return 1;
  63     }
  64 
  65   return 0;
  66 }

/* [previous][next][first][last][top][bottom][index][help] */