]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/u-boot/sha1.h
Merge git://git.denx.de/u-boot-mmc
[people/ms/u-boot.git] / include / u-boot / sha1.h
CommitLineData
566a494f
HS
1/**
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 *
5b8031cc 8 * SPDX-License-Identifier: LGPL-2.1
566a494f
HS
9 */
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
da29f299
AD
24#define SHA1_DER_LEN 15
25
26extern const uint8_t sha1_der_prefix[];
566a494f
HS
27
28/**
4ef218f6 29 * \brief SHA-1 context structure
566a494f
HS
30 */
31typedef struct
32{
4ef218f6
WD
33 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 */
566a494f
HS
36}
37sha1_context;
38
39/**
4ef218f6 40 * \brief SHA-1 context setup
566a494f 41 *
4ef218f6 42 * \param ctx SHA-1 context to be initialized
566a494f
HS
43 */
44void sha1_starts( sha1_context *ctx );
45
46/**
4ef218f6 47 * \brief SHA-1 process buffer
566a494f 48 *
4ef218f6 49 * \param ctx SHA-1 context
566a494f 50 * \param input buffer holding the data
4ef218f6 51 * \param ilen length of the input data
566a494f 52 */
a7d1d765
SG
53void sha1_update(sha1_context *ctx, const unsigned char *input,
54 unsigned int ilen);
566a494f
HS
55
56/**
4ef218f6 57 * \brief SHA-1 final digest
566a494f 58 *
4ef218f6 59 * \param ctx SHA-1 context
566a494f
HS
60 * \param output SHA-1 checksum result
61 */
62void sha1_finish( sha1_context *ctx, unsigned char output[20] );
63
64/**
4ef218f6 65 * \brief Output = SHA-1( input buffer )
566a494f
HS
66 *
67 * \param input buffer holding the data
4ef218f6 68 * \param ilen length of the input data
566a494f
HS
69 * \param output SHA-1 checksum result
70 */
a7d1d765
SG
71void sha1_csum(const unsigned char *input, unsigned int ilen,
72 unsigned char *output);
566a494f 73
215b01bb
BS
74/**
75 * \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 */
a7d1d765
SG
82void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
83 unsigned char *output, unsigned int chunk_sz);
566a494f
HS
84
85/**
4ef218f6 86 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
566a494f 87 *
4ef218f6 88 * \param key HMAC secret key
566a494f
HS
89 * \param keylen length of the HMAC key
90 * \param input buffer holding the data
4ef218f6 91 * \param ilen length of the input data
566a494f
HS
92 * \param output HMAC-SHA-1 result
93 */
a7d1d765
SG
94void sha1_hmac(const unsigned char *key, int keylen,
95 const unsigned char *input, unsigned int ilen,
96 unsigned char *output);
566a494f
HS
97
98/**
4ef218f6 99 * \brief Checkup routine
566a494f 100 *
4ef218f6 101 * \return 0 if successful, or 1 if the test failed
566a494f
HS
102 */
103int sha1_self_test( void );
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* sha1.h */