Blame crypt/md5test-giant.c

Packit Service 82fcde
/* Testcase for https://sourceware.org/bugzilla/show_bug.cgi?id=14090.
Packit Service 82fcde
   Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   This program is free software; you can redistribute it and/or modify
Packit Service 82fcde
   it under the terms of the GNU General Public License as published
Packit Service 82fcde
   by the Free Software Foundation; version 2 of the License, or
Packit Service 82fcde
   (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   This program is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 82fcde
   GNU General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU General Public License
Packit Service 82fcde
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <sys/mman.h>
Packit Service 82fcde
Packit Service 82fcde
#include "md5.h"
Packit Service 82fcde
Packit Service 82fcde
/* This test will not work with 32-bit size_t, so let it succeed
Packit Service 82fcde
   there.  */
Packit Service 82fcde
#if SIZE_MAX <= UINT32_MAX
Packit Service 82fcde
static int
Packit Service 82fcde
do_test (void)
Packit Service 82fcde
{
Packit Service 82fcde
  return 0;
Packit Service 82fcde
}
Packit Service 82fcde
#else
Packit Service 82fcde
Packit Service 82fcde
# define CONST_2G  0x080000000
Packit Service 82fcde
# define CONST_10G 0x280000000
Packit Service 82fcde
Packit Service 82fcde
/* MD5 sum values of zero-filled blocks of specified sizes.  */
Packit Service 82fcde
static const struct test_data_s
Packit Service 82fcde
{
Packit Service 82fcde
  const char ref[16];
Packit Service 82fcde
  size_t len;
Packit Service 82fcde
} test_data[] =
Packit Service 82fcde
  {
Packit Service 82fcde
    { "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",
Packit Service 82fcde
      0x000000000 },
Packit Service 82fcde
    { "\xa9\x81\x13\x0c\xf2\xb7\xe0\x9f\x46\x86\xdc\x27\x3c\xf7\x18\x7e",
Packit Service 82fcde
      0x080000000 },
Packit Service 82fcde
    { "\xc9\xa5\xa6\x87\x8d\x97\xb4\x8c\xc9\x65\xc1\xe4\x18\x59\xf0\x34",
Packit Service 82fcde
      0x100000000 },
Packit Service 82fcde
    { "\x58\xcf\x63\x8a\x73\x3f\x91\x90\x07\xb4\x28\x7c\xf5\x39\x6d\x0c",
Packit Service 82fcde
      0x180000000 },
Packit Service 82fcde
    { "\xb7\x70\x35\x1f\xad\xae\x5a\x96\xbb\xaf\x97\x02\xed\x97\xd2\x8d",
Packit Service 82fcde
      0x200000000 },
Packit Service 82fcde
    { "\x2d\xd2\x6c\x4d\x47\x99\xeb\xd2\x9f\xa3\x1e\x48\xd4\x9e\x8e\x53",
Packit Service 82fcde
      0x280000000 },
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
static int
Packit Service 82fcde
report (const char *id, const char *md5, size_t len, const char *ref)
Packit Service 82fcde
{
Packit Service 82fcde
  if (memcmp (md5, ref, 16))
Packit Service 82fcde
    {
Packit Service 82fcde
      printf ("test %s with size %zd failed\n", id, len);
Packit Service 82fcde
      return 1;
Packit Service 82fcde
    }
Packit Service 82fcde
  return 0;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
/* Test md5 in a single md5_process_bytes call.  */
Packit Service 82fcde
static int
Packit Service 82fcde
test_single (void *buf, size_t len, const char *ref)
Packit Service 82fcde
{
Packit Service 82fcde
  char sum[16];
Packit Service 82fcde
  struct md5_ctx ctx;
Packit Service 82fcde
Packit Service 82fcde
  __md5_init_ctx (&ctx;;
Packit Service 82fcde
  __md5_process_bytes (buf, len, &ctx;;
Packit Service 82fcde
  __md5_finish_ctx (&ctx, sum);
Packit Service 82fcde
Packit Service 82fcde
  return report ("single", sum, len, ref);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
/* Test md5 with two md5_process_bytes calls to trigger a
Packit Service 82fcde
   different path in md5_process_block for sizes > 2 GB.  */
Packit Service 82fcde
static int
Packit Service 82fcde
test_double (void *buf, size_t len, const char *ref)
Packit Service 82fcde
{
Packit Service 82fcde
  char sum[16];
Packit Service 82fcde
  struct md5_ctx ctx;
Packit Service 82fcde
Packit Service 82fcde
  __md5_init_ctx (&ctx;;
Packit Service 82fcde
  if (len >= CONST_2G)
Packit Service 82fcde
    {
Packit Service 82fcde
      __md5_process_bytes (buf, CONST_2G, &ctx;;
Packit Service 82fcde
      __md5_process_bytes (buf + CONST_2G, len - CONST_2G, &ctx;;
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    __md5_process_bytes (buf, len, &ctx;;
Packit Service 82fcde
Packit Service 82fcde
  __md5_finish_ctx (&ctx, sum);
Packit Service 82fcde
Packit Service 82fcde
  return report ("double", sum, len, ref);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static int
Packit Service 82fcde
do_test (void)
Packit Service 82fcde
{
Packit Service 82fcde
  void *buf;
Packit Service 82fcde
  unsigned int j;
Packit Service 82fcde
  int result = 0;
Packit Service 82fcde
Packit Service 82fcde
  buf = mmap64 (0, CONST_10G, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
Packit Service 82fcde
  if (buf == MAP_FAILED)
Packit Service 82fcde
    {
Packit Service 82fcde
      puts ("Could not allocate 10 GB via mmap, skipping test.");
Packit Service 82fcde
      return 0;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  for (j = 0; j < sizeof (test_data) / sizeof (struct test_data_s); j++)
Packit Service 82fcde
    {
Packit Service 82fcde
      if (test_single (buf, test_data[j].len, test_data[j].ref))
Packit Service 82fcde
	result = 1;
Packit Service 82fcde
      if (test_double (buf, test_data[j].len, test_data[j].ref))
Packit Service 82fcde
	result = 1;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  return result;
Packit Service 82fcde
}
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
/* This needs on a fast machine 90s.  */
Packit Service 82fcde
#define TIMEOUT 480
Packit Service 82fcde
#define TEST_FUNCTION do_test ()
Packit Service 82fcde
#include "../test-skeleton.c"