xref: /openbmc/u-boot/include/hash.h (revision 1a2621ba)
1 /*
2  * Copyright (c) 2012 The Chromium OS Authors.
3  * See file CREDITS for list of people who contributed to this
4  * project.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21 
22 #ifndef _HASH_H
23 #define _HASH_H
24 
25 #ifdef CONFIG_SHA1SUM_VERIFY
26 #define CONFIG_HASH_VERIFY
27 #endif
28 
29 struct hash_algo {
30 	const char *name;			/* Name of algorithm */
31 	int digest_size;			/* Length of digest */
32 	/**
33 	 * hash_func_ws: Generic hashing function
34 	 *
35 	 * This is the generic prototype for a hashing function. We only
36 	 * have the watchdog version at present.
37 	 *
38 	 * @input:	Input buffer
39 	 * @ilen:	Input buffer length
40 	 * @output:	Checksum result (length depends on algorithm)
41 	 * @chunk_sz:	Trigger watchdog after processing this many bytes
42 	 */
43 	void (*hash_func_ws)(const unsigned char *input, unsigned int ilen,
44 		unsigned char *output, unsigned int chunk_sz);
45 	int chunk_size;				/* Watchdog chunk size */
46 };
47 
48 /*
49  * Maximum digest size for all algorithms we support. Having this value
50  * avoids a malloc() or C99 local declaration in common/cmd_hash.c.
51  */
52 #define HASH_MAX_DIGEST_SIZE	32
53 
54 /**
55  * hash_command: Process a hash command for a particular algorithm
56  *
57  * This common function is used to implement specific hash commands.
58  *
59  * @algo_name:		Hash algorithm being used
60  * @verify:		Non-zero to enable verify mode
61  * @cmdtp:		Pointer to command table entry
62  * @flag:		Some flags normally 0 (see CMD_FLAG_.. above)
63  * @argc:		Number of arguments (arg 0 must be the command text)
64  * @argv:		Arguments
65  */
66 int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag,
67 		 int argc, char * const argv[]);
68 
69 #endif
70