xref: /rk3399_rockchip-uboot/include/hash.h (revision 218da0f35f4b5e5bf13d3dba6d975d4d5d65516f)
1460408efSSimon Glass /*
2460408efSSimon Glass  * Copyright (c) 2012 The Chromium OS Authors.
3460408efSSimon Glass  * See file CREDITS for list of people who contributed to this
4460408efSSimon Glass  * project.
5460408efSSimon Glass  *
6460408efSSimon Glass  * This program is free software; you can redistribute it and/or
7460408efSSimon Glass  * modify it under the terms of the GNU General Public License as
8460408efSSimon Glass  * published by the Free Software Foundation; either version 2 of
9460408efSSimon Glass  * the License, or (at your option) any later version.
10460408efSSimon Glass  *
11460408efSSimon Glass  * This program is distributed in the hope that it will be useful,
12460408efSSimon Glass  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13460408efSSimon Glass  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14460408efSSimon Glass  * GNU General Public License for more details.
15460408efSSimon Glass  *
16460408efSSimon Glass  * You should have received a copy of the GNU General Public License
17460408efSSimon Glass  * along with this program; if not, write to the Free Software
18460408efSSimon Glass  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19460408efSSimon Glass  * MA 02111-1307 USA
20460408efSSimon Glass  */
21460408efSSimon Glass 
22460408efSSimon Glass #ifndef _HASH_H
23460408efSSimon Glass #define _HASH_H
24460408efSSimon Glass 
25d20a40deSSimon Glass #if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
26460408efSSimon Glass #define CONFIG_HASH_VERIFY
27460408efSSimon Glass #endif
28460408efSSimon Glass 
29460408efSSimon Glass struct hash_algo {
30460408efSSimon Glass 	const char *name;			/* Name of algorithm */
31460408efSSimon Glass 	int digest_size;			/* Length of digest */
32460408efSSimon Glass 	/**
33460408efSSimon Glass 	 * hash_func_ws: Generic hashing function
34460408efSSimon Glass 	 *
35460408efSSimon Glass 	 * This is the generic prototype for a hashing function. We only
36460408efSSimon Glass 	 * have the watchdog version at present.
37460408efSSimon Glass 	 *
38460408efSSimon Glass 	 * @input:	Input buffer
39460408efSSimon Glass 	 * @ilen:	Input buffer length
40460408efSSimon Glass 	 * @output:	Checksum result (length depends on algorithm)
41460408efSSimon Glass 	 * @chunk_sz:	Trigger watchdog after processing this many bytes
42460408efSSimon Glass 	 */
43460408efSSimon Glass 	void (*hash_func_ws)(const unsigned char *input, unsigned int ilen,
44460408efSSimon Glass 		unsigned char *output, unsigned int chunk_sz);
45460408efSSimon Glass 	int chunk_size;				/* Watchdog chunk size */
46460408efSSimon Glass };
47460408efSSimon Glass 
48460408efSSimon Glass /*
49460408efSSimon Glass  * Maximum digest size for all algorithms we support. Having this value
50460408efSSimon Glass  * avoids a malloc() or C99 local declaration in common/cmd_hash.c.
51460408efSSimon Glass  */
52460408efSSimon Glass #define HASH_MAX_DIGEST_SIZE	32
53460408efSSimon Glass 
54d5b76673SSimon Glass enum {
55d5b76673SSimon Glass 	HASH_FLAG_VERIFY	= 1 << 0,	/* Enable verify mode */
56d5b76673SSimon Glass 	HASH_FLAG_ENV		= 1 << 1,	/* Allow env vars */
57d5b76673SSimon Glass };
58d5b76673SSimon Glass 
59460408efSSimon Glass /**
60460408efSSimon Glass  * hash_command: Process a hash command for a particular algorithm
61460408efSSimon Glass  *
62460408efSSimon Glass  * This common function is used to implement specific hash commands.
63460408efSSimon Glass  *
64*218da0f3SSimon Glass  * @algo_name:		Hash algorithm being used (lower case!)
65d5b76673SSimon Glass  * @flags:		Flags value (HASH_FLAG_...)
66460408efSSimon Glass  * @cmdtp:		Pointer to command table entry
67460408efSSimon Glass  * @flag:		Some flags normally 0 (see CMD_FLAG_.. above)
68460408efSSimon Glass  * @argc:		Number of arguments (arg 0 must be the command text)
69460408efSSimon Glass  * @argv:		Arguments
70460408efSSimon Glass  */
71d5b76673SSimon Glass int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
72460408efSSimon Glass 		 int argc, char * const argv[]);
73460408efSSimon Glass 
74460408efSSimon Glass #endif
75