/* hash-common.c - Common code for hash algorithms
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* Libgcrypt 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include "g10lib.h"
#include "hash-common.h"
/* Run a selftest for hash algorithm ALGO. If the resulting digest
return NULL. If an error occurs, return a static text string
describing the error.
DATAMODE controls what will be hashed according to this table:
0 - Hash the supplied DATA of DATALEN.
1 - Hash one million times a 'a'. DATA and DATALEN are ignored.
*/
const char *
{
unsigned char *digest;
return "digest size does not match expected size";
if (err)
return "gcry_md_open failed";
switch (datamode)
{
case 0:
break;
case 1: /* Hash one million times an "a". */
{
int i;
/* Write in odd size chunks so that we test the buffering. */
for (i = 0; i < 1000; i++)
}
break;
default:
result = "invalid DATAMODE";
}
if (!result)
{
result = "digest mismatch";
}
_gcry_md_close (hd);
return result;
}