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. --- ChangeLog | 6 ++++ modules/crypto/md2-buffer-tests | 10 +++++++ modules/crypto/md2-tests | 10 ------- tests/test-md2-buffer.c | 66 +++++++++++++++++++++++++++++++++++++++++ tests/test-md2.c | 66 ----------------------------------------- 5 files changed, 82 insertions(+), 76 deletions(-) create mode 100644 modules/crypto/md2-buffer-tests delete mode 100644 modules/crypto/md2-tests create mode 100644 tests/test-md2-buffer.c delete mode 100644 tests/test-md2.c diff --git a/ChangeLog b/ChangeLog index ed35ce693b..43f605b3ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-09-18 Bruno Haible + 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. + md2-buffer: New module. * lib/md2-stream.c: New file, extracted from lib/md2.c. * lib/md2.c: Don't include stdlib.h, unlocked-io.h. diff --git a/modules/crypto/md2-buffer-tests b/modules/crypto/md2-buffer-tests new file mode 100644 index 0000000000..20b2e9f41a --- /dev/null +++ b/modules/crypto/md2-buffer-tests @@ -0,0 +1,10 @@ +Files: +tests/test-md2-buffer.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-md2-buffer +check_PROGRAMS += test-md2-buffer diff --git a/modules/crypto/md2-tests b/modules/crypto/md2-tests deleted file mode 100644 index 2beed8747a..0000000000 --- a/modules/crypto/md2-tests +++ /dev/null @@ -1,10 +0,0 @@ -Files: -tests/test-md2.c - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-md2 -check_PROGRAMS += test-md2 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; +} diff --git a/tests/test-md2.c b/tests/test-md2.c deleted file mode 100644 index 1dd854dd4f..0000000000 --- a/tests/test-md2.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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