blob: 09fee594d263fa94e1060cf113f9e603b521b99d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: LGPL-2.1 */
Heiko Schocher633e03a2007-06-22 19:11:54 +02002/**
3 * \file sha1.h
4 * based from http://xyssl.org/code/source/sha1/
5 * FIPS-180-1 compliant SHA-1 implementation
6 *
7 * Copyright (C) 2003-2006 Christophe Devine
Heiko Schocher633e03a2007-06-22 19:11:54 +02008 */
9/*
10 * The SHA-1 standard was published by NIST in 1993.
11 *
12 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
13 */
14#ifndef _SHA1_H
15#define _SHA1_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#define SHA1_SUM_POS -0x20
22#define SHA1_SUM_LEN 20
Andrew Duda3db9ff02016-11-08 18:53:40 +000023#define SHA1_DER_LEN 15
24
25extern const uint8_t sha1_der_prefix[];
Heiko Schocher633e03a2007-06-22 19:11:54 +020026
27/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020028 * \brief SHA-1 context structure
Heiko Schocher633e03a2007-06-22 19:11:54 +020029 */
30typedef struct
31{
Wolfgang Denka0453aa2007-07-10 00:01:28 +020032 unsigned long total[2]; /*!< number of bytes processed */
Loic Poulainc7799b02022-06-01 20:26:28 +020033 uint32_t state[5]; /*!< intermediate digest state */
Wolfgang Denka0453aa2007-07-10 00:01:28 +020034 unsigned char buffer[64]; /*!< data block being processed */
Heiko Schocher633e03a2007-06-22 19:11:54 +020035}
36sha1_context;
37
38/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020039 * \brief SHA-1 context setup
Heiko Schocher633e03a2007-06-22 19:11:54 +020040 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020041 * \param ctx SHA-1 context to be initialized
Heiko Schocher633e03a2007-06-22 19:11:54 +020042 */
43void sha1_starts( sha1_context *ctx );
44
45/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020046 * \brief SHA-1 process buffer
Heiko Schocher633e03a2007-06-22 19:11:54 +020047 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020048 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020049 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020050 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020051 */
Simon Glass5f60fa22012-12-05 14:46:33 +000052void sha1_update(sha1_context *ctx, const unsigned char *input,
53 unsigned int ilen);
Heiko Schocher633e03a2007-06-22 19:11:54 +020054
55/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020056 * \brief SHA-1 final digest
Heiko Schocher633e03a2007-06-22 19:11:54 +020057 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020058 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020059 * \param output SHA-1 checksum result
60 */
61void sha1_finish( sha1_context *ctx, unsigned char output[20] );
62
63/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020064 * \brief Output = SHA-1( input buffer )
Heiko Schocher633e03a2007-06-22 19:11:54 +020065 *
66 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020067 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020068 * \param output SHA-1 checksum result
69 */
Simon Glass5f60fa22012-12-05 14:46:33 +000070void sha1_csum(const unsigned char *input, unsigned int ilen,
71 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020072
73/**
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020074 * \brief Output = SHA-1( input buffer ), with watchdog triggering
75 *
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 * \param output SHA-1 checksum result
79 * \param chunk_sz watchdog triggering period (in bytes of input processed)
80 */
Simon Glass5f60fa22012-12-05 14:46:33 +000081void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
82 unsigned char *output, unsigned int chunk_sz);
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020083
84/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020085 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
Heiko Schocher633e03a2007-06-22 19:11:54 +020086 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020087 * \param key HMAC secret key
Heiko Schocher633e03a2007-06-22 19:11:54 +020088 * \param keylen length of the HMAC key
89 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020090 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020091 * \param output HMAC-SHA-1 result
92 */
Simon Glass5f60fa22012-12-05 14:46:33 +000093void sha1_hmac(const unsigned char *key, int keylen,
94 const unsigned char *input, unsigned int ilen,
95 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020096
97/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020098 * \brief Checkup routine
Heiko Schocher633e03a2007-06-22 19:11:54 +020099 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +0200100 * \return 0 if successful, or 1 if the test failed
Heiko Schocher633e03a2007-06-22 19:11:54 +0200101 */
102int sha1_self_test( void );
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* sha1.h */