sha1.h 1.89 KB
/**
 * \file
 * This is a drop in replacement for the openssl sha1 code.
 * It has a small performance penalty compared to the openssl code,
 * but that's no surprise at all as the openssl code is highly
 * optimized.
 *
 * \author	Georg Hopp
 *
 * \copyright
 * Copyright © 2014 Georg Hopp
 *
 * 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 of the License, 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 <http://www.gnu.org/licenses/>.
 */
#ifndef __TR_SHA1_H__
#define __TR_SHA1_H__

#ifdef HAS_OPENSSL

#include <openssl/sha.h>
#define TR_SHA_CTX     SHA_CTX
#define TR_SHA1_Init   SHA1_Init
#define TR_SHA1_Update SHA1_Update
#define TR_SHA1_Final  SHA1_Final

#else

// for size_t
#include <sys/types.h>
// for uint32_t
#include <stdint.h>

#define TR_SHA1_INIT_CTX {                                             \
	{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0},      \
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  \
	 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
	0, 0}

typedef uint32_t TR_Sha1[5];

typedef struct s_TR_SHA_CTX {
	TR_Sha1       hash;
	unsigned char temp_buffer[64];
	size_t        ntemp_buffer;
	size_t        size;
} TR_SHA_CTX;

int TR_SHA1_Init(TR_SHA_CTX *);
int TR_SHA1_Update(TR_SHA_CTX *, const void *, size_t);
int TR_SHA1_Final(unsigned char * const, TR_SHA_CTX *);

#endif //HAS_OPENSSL
#endif //__TR_SHA1_H__

// vim: set ts=4 sw=4: