blob: c1e9f67068d4f194b5a15df6f51d580abaf096e1 [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
Tom Rini23e3a842024-04-30 07:35:28 -060017#include <linux/types.h>
18
Heiko Schocher633e03a2007-06-22 19:11:54 +020019#ifdef __cplusplus
20extern "C" {
21#endif
22
23#define SHA1_SUM_POS -0x20
24#define SHA1_SUM_LEN 20
Andrew Duda3db9ff02016-11-08 18:53:40 +000025#define SHA1_DER_LEN 15
26
27extern const uint8_t sha1_der_prefix[];
Heiko Schocher633e03a2007-06-22 19:11:54 +020028
29/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020030 * \brief SHA-1 context structure
Heiko Schocher633e03a2007-06-22 19:11:54 +020031 */
32typedef struct
33{
Wolfgang Denka0453aa2007-07-10 00:01:28 +020034 unsigned long total[2]; /*!< number of bytes processed */
Loic Poulainc7799b02022-06-01 20:26:28 +020035 uint32_t state[5]; /*!< intermediate digest state */
Wolfgang Denka0453aa2007-07-10 00:01:28 +020036 unsigned char buffer[64]; /*!< data block being processed */
Heiko Schocher633e03a2007-06-22 19:11:54 +020037}
38sha1_context;
39
40/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020041 * \brief SHA-1 context setup
Heiko Schocher633e03a2007-06-22 19:11:54 +020042 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020043 * \param ctx SHA-1 context to be initialized
Heiko Schocher633e03a2007-06-22 19:11:54 +020044 */
45void sha1_starts( sha1_context *ctx );
46
47/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020048 * \brief SHA-1 process buffer
Heiko Schocher633e03a2007-06-22 19:11:54 +020049 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020050 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020051 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020052 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020053 */
Simon Glass5f60fa22012-12-05 14:46:33 +000054void sha1_update(sha1_context *ctx, const unsigned char *input,
55 unsigned int ilen);
Heiko Schocher633e03a2007-06-22 19:11:54 +020056
57/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020058 * \brief SHA-1 final digest
Heiko Schocher633e03a2007-06-22 19:11:54 +020059 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020060 * \param ctx SHA-1 context
Heiko Schocher633e03a2007-06-22 19:11:54 +020061 * \param output SHA-1 checksum result
62 */
63void sha1_finish( sha1_context *ctx, unsigned char output[20] );
64
65/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020066 * \brief Output = SHA-1( input buffer )
Heiko Schocher633e03a2007-06-22 19:11:54 +020067 *
68 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020069 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020070 * \param output SHA-1 checksum result
71 */
Simon Glass5f60fa22012-12-05 14:46:33 +000072void sha1_csum(const unsigned char *input, unsigned int ilen,
73 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020074
75/**
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020076 * \brief Output = SHA-1( input buffer ), with watchdog triggering
77 *
78 * \param input buffer holding the data
79 * \param ilen length of the input data
80 * \param output SHA-1 checksum result
81 * \param chunk_sz watchdog triggering period (in bytes of input processed)
82 */
Simon Glass5f60fa22012-12-05 14:46:33 +000083void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
84 unsigned char *output, unsigned int chunk_sz);
Bartlomiej Siekada5045d2008-04-22 12:27:56 +020085
86/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +020087 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
Heiko Schocher633e03a2007-06-22 19:11:54 +020088 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +020089 * \param key HMAC secret key
Heiko Schocher633e03a2007-06-22 19:11:54 +020090 * \param keylen length of the HMAC key
91 * \param input buffer holding the data
Wolfgang Denka0453aa2007-07-10 00:01:28 +020092 * \param ilen length of the input data
Heiko Schocher633e03a2007-06-22 19:11:54 +020093 * \param output HMAC-SHA-1 result
94 */
Simon Glass5f60fa22012-12-05 14:46:33 +000095void sha1_hmac(const unsigned char *key, int keylen,
96 const unsigned char *input, unsigned int ilen,
97 unsigned char *output);
Heiko Schocher633e03a2007-06-22 19:11:54 +020098
99/**
Wolfgang Denka0453aa2007-07-10 00:01:28 +0200100 * \brief Checkup routine
Heiko Schocher633e03a2007-06-22 19:11:54 +0200101 *
Wolfgang Denka0453aa2007-07-10 00:01:28 +0200102 * \return 0 if successful, or 1 if the test failed
Heiko Schocher633e03a2007-06-22 19:11:54 +0200103 */
104int sha1_self_test( void );
105
106#ifdef __cplusplus
107}
108#endif
109
110#endif /* sha1.h */