LCOV - code coverage report
Current view: top level - tests - genhashdata.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 61 0.0 %
Date: 2016-11-29 14:56:30 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* genhashdata.c - Create data for hash tests
       2             :  * Copyright (C) 2013 g10 Code GmbH
       3             :  *
       4             :  * This file is part of Libgcrypt.
       5             :  *
       6             :  * Libgcrypt is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU Lesser General Public License as
       8             :  * published by the Free Software Foundation; either version 2.1 of
       9             :  * the License, or (at your option) any later version.
      10             :  *
      11             :  * Libgcrypt is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : /* Results:
      21             : 
      22             : $  for i in -64 -1 0 1 64; do ./genhashdata --gigs 256 --bytes $i|sha1sum;done
      23             : 92fc51850c7b750e6e774b75f294f6979d4059f0  -
      24             : 4bddeeb4c08683f02d4944d93dbcb02ebab50134  -
      25             : 71b923afde1c8c040884c723a2e3335b333e64c6  -
      26             : 2d99f9b5b86e9c9c937104f4242bd6b8bc0927ef  -
      27             : a60dabe8d749f798b7ec3a684cc3eab487451482  -
      28             : 
      29             : $ for i in -64 -1 0 1 64; do ./genhashdata --gigs 256 --bytes $i|sha224sum;done
      30             : b5672b54d2480a5688a2dc727a1ad4db7a81ef31ce8999e0bbaeffdc  -
      31             : 814ea7159473e6ffc1c64b90026a542e13ac6980f7f3ca3c4582a9b8  -
      32             : 9ec0e1829455db8650ec7a8b06912196f97a7358bc3a73c79911cd4e  -
      33             : e578d5d523320876565bbbc892511a485427caee6dd754d57e3e58c2  -
      34             : ff0464df248cd298b63765bc4f87f21e25c93c657fdf3656d3c878e5  -
      35             : 
      36             : $ for i in -64 -1 0 1 64; do ./genhashdata --gigs 256 --bytes $i|sha256sum;done
      37             : 87a9828d3de78d55d252341db2a622908c4e0ceaee9961ecf9768700fc799ec8  -
      38             : 823bf95f64ef04a4a77579c38760b1d401b56bf3a8e664bdf56ca15afb468a03  -
      39             : 2d0723878cb2c3d5c59dfad910cdb857f4430a6ba2a7d687938d7a20e63dde47  -
      40             : 5a2e21b1e79cd866acf53a2a18ca76bd4e02c4b01bf4627354171824c812d95f  -
      41             : 34444808af8e9d995e67f9e155ed94bf55f195a51dc1d8a989e6bcf95511c8a2  -
      42             : 
      43             : 
      44             : $ for i in -64 -1 0 1 64; do ./genhashdata --gigs 256 --bytes $i|sha512sum;done
      45             : e01bf8140874bf240e8426cb2bcbc377cbed2e6037334116637149e1cd8cd462 \
      46             : 96828b71f32b9f002771d4cb51172ce578b73b7939221e4df655ecd08601e655  -
      47             : 4917ff94514b1757705c289fdc3e7d6ffcce5771b20ae237ebc03d2ec9eb435f \
      48             : b7ce9f0e27272be8cced77a5edae1a01a0ad62b0a44169d88bbee45474a17734  -
      49             : 1e28e8b3c79f2f47da11f3c0b7da4e7981e7d932db6d17d528a31e191922edda \
      50             : 8fc4bb2df10ea876232db5a1c606bc41886e8b2c570a3e721221f60c8c7dc4ab  -
      51             : 027d3324dd1cf127770ceb53681f4c70937c9bca4e3acd5fd76cb266c7d4527d \
      52             : 58140290a1822e8d60c4d3ae9725fb923183230d6dfd2d7d73c0d74a4757f34a  -
      53             : 49920704ea9d6ee19f0742d6c868110fa3eda8ac09f026e9ef22cc731af53020 \
      54             : de40eedef66cb1afd94c61e285fa9327e01336e804903740a9145ab1f065c2d5  -
      55             : 
      56             : */
      57             : 
      58             : #include <stdarg.h>
      59             : #include <stdio.h>
      60             : #include <stdlib.h>
      61             : #include <string.h>
      62             : #include <errno.h>
      63             : 
      64             : #define PGM "genhashdata"
      65             : 
      66             : static void
      67           0 : die (const char *format, ...)
      68             : {
      69             :   va_list arg_ptr ;
      70             : 
      71           0 :   fflush (stdout);
      72           0 :   fprintf (stderr, "%s: ", PGM);
      73           0 :   va_start (arg_ptr, format ) ;
      74           0 :   vfprintf (stderr, format, arg_ptr );
      75           0 :   va_end(arg_ptr);
      76           0 :   if (*format && format[strlen(format)-1] != '\n')
      77           0 :     putc ('\n', stderr);
      78           0 :   exit (1);
      79             : }
      80             : 
      81             : int
      82           0 : main (int argc, char **argv)
      83             : {
      84           0 :   int last_argc = -1;
      85           0 :   int gigs = 0;
      86           0 :   int bytes = 0;
      87             :   char pattern[1024];
      88             :   int i, g;
      89             : 
      90           0 :   if (argc)
      91           0 :     { argc--; argv++; }
      92             : 
      93           0 :   while (argc && last_argc != argc )
      94             :     {
      95           0 :       last_argc = argc;
      96           0 :       if (!strcmp (*argv, "--"))
      97             :         {
      98           0 :           argc--; argv++;
      99           0 :           break;
     100             :         }
     101           0 :       else if (!strcmp (*argv, "--help"))
     102             :         {
     103           0 :           fputs ("usage: " PGM " [options]\n"
     104             :                  "Options:\n"
     105             :                  "  --gigs  N     Emit N GiB of test bytes\n"
     106             :                  "  --bytes DIFF  Stop DIFF bytes earlier or later\n",
     107             :                  stdout);
     108           0 :           exit (0);
     109             :         }
     110           0 :       else if (!strcmp (*argv, "--gigs"))
     111             :         {
     112           0 :           argc--; argv++;
     113           0 :           if (argc)
     114             :             {
     115           0 :               gigs = atoi (*argv);
     116           0 :               argc--; argv++;
     117             :             }
     118             :         }
     119           0 :       else if (!strcmp (*argv, "--bytes"))
     120             :         {
     121           0 :           argc--; argv++;
     122           0 :           if (argc)
     123             :             {
     124           0 :               bytes = atoi (*argv);
     125           0 :               argc--; argv++;
     126             :             }
     127             :         }
     128           0 :       else if (!strncmp (*argv, "--", 2))
     129           0 :         die ("unknown option '%s'", *argv);
     130             :     }
     131             : 
     132           0 :   if (gigs < 0 || gigs > 1024*1024)
     133           0 :     die ("value for --gigs must be in the range 0 to %d", 1024*1024);
     134           0 :   if (bytes < -1024 || bytes > 1024)
     135           0 :       die ("value for --bytes must be in the range -1024 to 1024");
     136             :   if (sizeof pattern != 1024)
     137             :     die ("internal error");
     138             : 
     139           0 :   if (argc > 1)
     140           0 :     die ("arguments are not expected");
     141             : 
     142           0 :   memset (pattern, 'a', sizeof pattern);
     143             : 
     144           0 :   for (g=0; g < gigs; g++)
     145             :     {
     146           0 :       if (g + 1 == gigs && bytes < 0)
     147             :         {
     148           0 :           for (i = 0; i < 1024*1023; i++)
     149           0 :             if (fwrite (pattern, sizeof pattern, 1, stdout) != 1)
     150           0 :               die ("writing to stdout failed: %s", strerror (errno));
     151           0 :           for (i = 0; i < 1023; i++)
     152           0 :             if (fwrite (pattern, sizeof pattern, 1, stdout) != 1)
     153           0 :               die ("writing to stdout failed: %s", strerror (errno));
     154           0 :           if (fwrite (pattern, sizeof pattern + bytes, 1, stdout) != 1)
     155           0 :             die ("writing to stdout failed: %s", strerror (errno));
     156             :         }
     157             :       else
     158             :         {
     159           0 :           for (i = 0; i < 1024*1024; i++)
     160           0 :             if (fwrite (pattern, sizeof pattern, 1, stdout) != 1)
     161           0 :               die ("writing to stdout failed: %s", strerror (errno));
     162             :         }
     163             :     }
     164           0 :   if (bytes > 0)
     165           0 :     if (fwrite (pattern, bytes, 1, stdout) != 1)
     166           0 :       die ("writing to stdout failed: %s", strerror (errno));
     167           0 :   if (fflush (stdout))
     168           0 :     die ("writing to stdout failed: %s", strerror (errno));
     169             : 
     170           0 :   return 0;
     171             : }

Generated by: LCOV version 1.11