blob: 2634a29c20d9d8c736f62a8d0725c33d04ae70fa [file] [log] [blame]
Heiko Schocher633e03a2007-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 *
Tom Rinie2378802016-01-14 22:05:13 -05008 * SPDX-License-Identifier: LGPL-2.1
Heiko Schocher633e03a2007-06-22 19:11:54 +02009 */
10/*
11 * The SHA-1 standard was published by NIST in 1993.
12 *
13 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
14 */
15#ifndef _SHA1_H
16#define _SHA1_H
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define SHA1_SUM_POS -0x20
23#define SHA1_SUM_LEN 20
Andrew Duda3db9ff02016-11-08 18:53:40 +000024#define SHA1_DER_LEN 15
25
26extern const uint8_t sha1_der_prefix[];
Heiko Schocher633e03a2007-06-22 19:11:54 +020027
28/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020029 * \brief SHA-1 context structure
Heiko Schocher633e03a2007-06-22 19:11:54 +020030 */
31typedef struct
32{
Wolfgang Denka0453aa2007-07-10 00:01:28 +020033 unsigned long total[2]; /*!< number of bytes processed */
34 unsigned long state[5]; /*!< intermediate digest state */
35 unsigned char buffer[64]; /*!< data block being processed */
Heiko Schocher633e03a2007-06-22 19:11:54 +020036}
37sha1_context;
38
39/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020040 * \brief SHA-1 context setup
Heiko Schocher633e03a2007-06-22 19:11:54 +020041 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020042 * \param ctx SHA-1 context to be initialized
Heiko Schocher633e03a2007-06-22 19:11:54 +020043 */
44void sha1_starts( sha1_context *ctx );
45
46/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020047 * \brief SHA-1 process buffer
Heiko Schocher633e03a2007-06-22 19:11:54 +020048 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020049 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020050 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020051 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020052 */
Simon Glass5f60fa22012-12-05 14:46:33 +000053void sha1_update(sha1_context *ctx, const unsigned char *input,
54 unsigned int ilen);
Heiko Schocher633e03a2007-06-22 19:11:54 +020055
56/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020057 * \brief SHA-1 final digest
Heiko Schocher633e03a2007-06-22 19:11:54 +020058 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020059 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020060 * \param output SHA-1 checksum result
61 */
62void sha1_finish( sha1_context *ctx, unsigned char output[20] );
63
64/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020065 * \brief Output = SHA-1( input buffer )
Heiko Schocher633e03a2007-06-22 19:11:54 +020066 *
67 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020068 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020069 * \param output SHA-1 checksum result
70 */
Simon Glass5f60fa22012-12-05 14:46:33 +000071void sha1_csum(const unsigned char *input, unsigned int ilen,
72 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020073
74/**
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020075 * \brief Output = SHA-1( input buffer ), with watchdog triggering
76 *
77 * \param input buffer holding the data
78 * \param ilen length of the input data
79 * \param output SHA-1 checksum result
80 * \param chunk_sz watchdog triggering period (in bytes of input processed)
81 */
Simon Glass5f60fa22012-12-05 14:46:33 +000082void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
83 unsigned char *output, unsigned int chunk_sz);
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020084
85/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020086 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
Heiko Schocher633e03a2007-06-22 19:11:54 +020087 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020088 * \param key HMAC secret key
Heiko Schocher633e03a2007-06-22 19:11:54 +020089 * \param keylen length of the HMAC key
90 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020091 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020092 * \param output HMAC-SHA-1 result
93 */
Simon Glass5f60fa22012-12-05 14:46:33 +000094void sha1_hmac(const unsigned char *key, int keylen,
95 const unsigned char *input, unsigned int ilen,
96 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020097
98/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020099 * \brief Checkup routine
Heiko Schocher633e03a2007-06-22 19:11:54 +0200100 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +0200101 * \return 0 if successful, or 1 if the test failed
Heiko Schocher633e03a2007-06-22 19:11:54 +0200102 */
103int sha1_self_test( void );
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* sha1.h */