blob: 734d1fb153dc7d448e7f08e9e54f44e033b184bc [file] [log] [blame]
Heiko Schocher566a4942007-06-22 19:11:54 +02001/**
2 * \file sha1.h
3 * based from http://xyssl.org/code/source/sha1/
4 * FIPS-180-1 compliant SHA-1 implementation
5 *
6 * Copyright (C) 2003-2006 Christophe Devine
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License, version 2.1 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020020 * MA 02110-1301 USA
Heiko Schocher566a4942007-06-22 19:11:54 +020021 */
22/*
23 * The SHA-1 standard was published by NIST in 1993.
24 *
25 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
26 */
27#ifndef _SHA1_H
28#define _SHA1_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define SHA1_SUM_POS -0x20
35#define SHA1_SUM_LEN 20
36
37/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020038 * \brief SHA-1 context structure
Heiko Schocher566a4942007-06-22 19:11:54 +020039 */
40typedef struct
41{
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020042 unsigned long total[2]; /*!< number of bytes processed */
43 unsigned long state[5]; /*!< intermediate digest state */
44 unsigned char buffer[64]; /*!< data block being processed */
Heiko Schocher566a4942007-06-22 19:11:54 +020045}
46sha1_context;
47
48/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020049 * \brief SHA-1 context setup
Heiko Schocher566a4942007-06-22 19:11:54 +020050 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020051 * \param ctx SHA-1 context to be initialized
Heiko Schocher566a4942007-06-22 19:11:54 +020052 */
53void sha1_starts( sha1_context *ctx );
54
55/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020056 * \brief SHA-1 process buffer
Heiko Schocher566a4942007-06-22 19:11:54 +020057 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020058 * \param ctx SHA-1 context
Heiko Schocher566a4942007-06-22 19:11:54 +020059 * \param input buffer holding the data
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020060 * \param ilen length of the input data
Heiko Schocher566a4942007-06-22 19:11:54 +020061 */
62void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
63
64/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020065 * \brief SHA-1 final digest
Heiko Schocher566a4942007-06-22 19:11:54 +020066 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020067 * \param ctx SHA-1 context
Heiko Schocher566a4942007-06-22 19:11:54 +020068 * \param output SHA-1 checksum result
69 */
70void sha1_finish( sha1_context *ctx, unsigned char output[20] );
71
72/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020073 * \brief Output = SHA-1( input buffer )
Heiko Schocher566a4942007-06-22 19:11:54 +020074 *
75 * \param input buffer holding the data
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020076 * \param ilen length of the input data
Heiko Schocher566a4942007-06-22 19:11:54 +020077 * \param output SHA-1 checksum result
78 */
79void sha1_csum( unsigned char *input, int ilen,
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020080 unsigned char output[20] );
Heiko Schocher566a4942007-06-22 19:11:54 +020081
82/**
Bartlomiej Sieka215b01b2008-04-22 12:27:56 +020083 * \brief Output = SHA-1( input buffer ), with watchdog triggering
84 *
85 * \param input buffer holding the data
86 * \param ilen length of the input data
87 * \param output SHA-1 checksum result
88 * \param chunk_sz watchdog triggering period (in bytes of input processed)
89 */
90void sha1_csum_wd (unsigned char *input, int ilen,
91 unsigned char output[20], unsigned int chunk_sz);
92
93/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020094 * \brief Output = SHA-1( file contents )
Heiko Schocher566a4942007-06-22 19:11:54 +020095 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020096 * \param path input file name
Heiko Schocher566a4942007-06-22 19:11:54 +020097 * \param output SHA-1 checksum result
Wolfgang Denk4ef218f2007-07-10 00:01:28 +020098 * \return 0 if successful, or 1 if fopen failed
Heiko Schocher566a4942007-06-22 19:11:54 +020099 */
100int sha1_file( char *path, unsigned char output[20] );
101
102/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200103 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
Heiko Schocher566a4942007-06-22 19:11:54 +0200104 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200105 * \param key HMAC secret key
Heiko Schocher566a4942007-06-22 19:11:54 +0200106 * \param keylen length of the HMAC key
107 * \param input buffer holding the data
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200108 * \param ilen length of the input data
Heiko Schocher566a4942007-06-22 19:11:54 +0200109 * \param output HMAC-SHA-1 result
110 */
111void sha1_hmac( unsigned char *key, int keylen,
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200112 unsigned char *input, int ilen,
113 unsigned char output[20] );
Heiko Schocher566a4942007-06-22 19:11:54 +0200114
115/**
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200116 * \brief Checkup routine
Heiko Schocher566a4942007-06-22 19:11:54 +0200117 *
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200118 * \return 0 if successful, or 1 if the test failed
Heiko Schocher566a4942007-06-22 19:11:54 +0200119 */
120int sha1_self_test( void );
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* sha1.h */