Blame hash_intmd5.c

Packit 96c956
/*
Packit 96c956
  chronyd/chronyc - Programs for keeping computer clocks accurate.
Packit 96c956
Packit 96c956
 **********************************************************************
Packit 96c956
 * Copyright (C) Miroslav Lichvar  2012
Packit 96c956
 * 
Packit 96c956
 * This program is free software; you can redistribute it and/or modify
Packit 96c956
 * it under the terms of version 2 of the GNU General Public License as
Packit 96c956
 * published by the Free Software Foundation.
Packit 96c956
 * 
Packit 96c956
 * This program is distributed in the hope that it will be useful, but
Packit 96c956
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 96c956
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 96c956
 * General Public License for more details.
Packit 96c956
 * 
Packit 96c956
 * You should have received a copy of the GNU General Public License along
Packit 96c956
 * with this program; if not, write to the Free Software Foundation, Inc.,
Packit 96c956
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Packit 96c956
 * 
Packit 96c956
 **********************************************************************
Packit 96c956
Packit 96c956
  =======================================================================
Packit 96c956
Packit 96c956
  Routines implementing crypto hashing using internal MD5 implementation.
Packit 96c956
Packit 96c956
  */
Packit 96c956
Packit 96c956
#include "config.h"
Packit 96c956
#include "sysincl.h"
Packit 96c956
#include "hash.h"
Packit 96c956
#include "memory.h"
Packit 96c956
#include "util.h"
Packit 96c956
Packit 96c956
#include "md5.c"
Packit 96c956
Packit 96c956
static MD5_CTX ctx;
Packit 96c956
Packit 96c956
int
Packit 96c956
HSH_GetHashId(const char *name)
Packit 96c956
{
Packit 96c956
  /* only MD5 is supported */
Packit 96c956
  if (strcmp(name, "MD5"))
Packit 96c956
    return -1;
Packit 96c956
Packit 96c956
  return 0;
Packit 96c956
}
Packit 96c956
Packit 96c956
unsigned int
Packit 96c956
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
Packit 96c956
    const unsigned char *in2, unsigned int in2_len,
Packit 96c956
    unsigned char *out, unsigned int out_len)
Packit 96c956
{
Packit 96c956
  MD5Init(&ctx;;
Packit 96c956
  MD5Update(&ctx, in1, in1_len);
Packit 96c956
  if (in2)
Packit 96c956
    MD5Update(&ctx, in2, in2_len);
Packit 96c956
  MD5Final(&ctx;;
Packit 96c956
Packit 96c956
  out_len = MIN(out_len, 16);
Packit 96c956
Packit 96c956
  memcpy(out, ctx.digest, out_len);
Packit 96c956
Packit 96c956
  return out_len;
Packit 96c956
}
Packit 96c956
Packit 96c956
void
Packit 96c956
HSH_Finalise(void)
Packit 96c956
{
Packit 96c956
}