blob: b0d9ce9db9d575194a54e09ca3fe0920ac06fd82 [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
24
25/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020026 * \brief SHA-1 context structure
Heiko Schocher633e03a2007-06-22 19:11:54 +020027 */
28typedef struct
29{
Wolfgang Denka0453aa2007-07-10 00:01:28 +020030 unsigned long total[2]; /*!< number of bytes processed */
31 unsigned long state[5]; /*!< intermediate digest state */
32 unsigned char buffer[64]; /*!< data block being processed */
Heiko Schocher633e03a2007-06-22 19:11:54 +020033}
34sha1_context;
35
36/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020037 * \brief SHA-1 context setup
Heiko Schocher633e03a2007-06-22 19:11:54 +020038 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020039 * \param ctx SHA-1 context to be initialized
Heiko Schocher633e03a2007-06-22 19:11:54 +020040 */
41void sha1_starts( sha1_context *ctx );
42
43/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020044 * \brief SHA-1 process buffer
Heiko Schocher633e03a2007-06-22 19:11:54 +020045 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020046 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020047 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020048 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020049 */
Simon Glass5f60fa22012-12-05 14:46:33 +000050void sha1_update(sha1_context *ctx, const unsigned char *input,
51 unsigned int ilen);
Heiko Schocher633e03a2007-06-22 19:11:54 +020052
53/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020054 * \brief SHA-1 final digest
Heiko Schocher633e03a2007-06-22 19:11:54 +020055 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020056 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020057 * \param output SHA-1 checksum result
58 */
59void sha1_finish( sha1_context *ctx, unsigned char output[20] );
60
61/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020062 * \brief Output = SHA-1( input buffer )
Heiko Schocher633e03a2007-06-22 19:11:54 +020063 *
64 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020065 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020066 * \param output SHA-1 checksum result
67 */
Simon Glass5f60fa22012-12-05 14:46:33 +000068void sha1_csum(const unsigned char *input, unsigned int ilen,
69 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020070
71/**
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020072 * \brief Output = SHA-1( input buffer ), with watchdog triggering
73 *
74 * \param input buffer holding the data
75 * \param ilen length of the input data
76 * \param output SHA-1 checksum result
77 * \param chunk_sz watchdog triggering period (in bytes of input processed)
78 */
Simon Glass5f60fa22012-12-05 14:46:33 +000079void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
80 unsigned char *output, unsigned int chunk_sz);
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020081
82/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020083 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
Heiko Schocher633e03a2007-06-22 19:11:54 +020084 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020085 * \param key HMAC secret key
Heiko Schocher633e03a2007-06-22 19:11:54 +020086 * \param keylen length of the HMAC key
87 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020088 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020089 * \param output HMAC-SHA-1 result
90 */
Simon Glass5f60fa22012-12-05 14:46:33 +000091void sha1_hmac(const unsigned char *key, int keylen,
92 const unsigned char *input, unsigned int ilen,
93 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020094
95/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020096 * \brief Checkup routine
Heiko Schocher633e03a2007-06-22 19:11:54 +020097 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020098 * \return 0 if successful, or 1 if the test failed
Heiko Schocher633e03a2007-06-22 19:11:54 +020099 */
100int sha1_self_test( void );
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif /* sha1.h */