From 341e0c26819ce4c1a26b95b3c780bed88036d211 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 19 Sep 2021 01:30:12 +0200 Subject: md2-buffer tests: New module. * tests/test-md2-buffer.c: Renamed from tests/test-md2.c. * modules/crypto/md2-buffer-tests: Renamed from modules/crypto/md2-tests. Test tests/test-md2-buffer.c instead of tests/test-md2.c. --- tests/test-md2-buffer.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/test-md2-buffer.c (limited to 'tests/test-md2-buffer.c') diff --git a/tests/test-md2-buffer.c b/tests/test-md2-buffer.c new file mode 100644 index 0000000000..1dd854dd4f --- /dev/null +++ b/tests/test-md2-buffer.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2005, 2010-2021 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . */ + +/* Written by Simon Josefsson. */ + +#include + +#include "md2.h" + +#include +#include + +int +main (int argc, char *argv[]) +{ + const char *in1 = "abc"; + const char *out1 = + "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde\xd6\xbb"; + const char *in2 = "abcdefghijklmnopqrstuvwxyz"; + const char *out2 = + "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b"; + char buf[MD2_DIGEST_SIZE]; + + if (memcmp (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE) != + 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < MD2_DIGEST_SIZE; i++) + printf ("%02x ", out1[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < MD2_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFF); + printf ("\n"); + return 1; + } + + if (memcmp (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE) != + 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < MD2_DIGEST_SIZE; i++) + printf ("%02x ", out2[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < MD2_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFF); + printf ("\n"); + return 1; + } + + return 0; +} -- cgit v1.2.1