2 * Copyright (c) 2012 The Chromium OS Authors.
3 * SPDX-License-Identifier: GPL-2.0+
9 #if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
10 #define CONFIG_HASH_VERIFY
14 const char *name; /* Name of algorithm */
15 int digest_size; /* Length of digest */
17 * hash_func_ws: Generic hashing function
19 * This is the generic prototype for a hashing function. We only
20 * have the watchdog version at present.
22 * @input: Input buffer
23 * @ilen: Input buffer length
24 * @output: Checksum result (length depends on algorithm)
25 * @chunk_sz: Trigger watchdog after processing this many bytes
27 void (*hash_func_ws)(const unsigned char *input, unsigned int ilen,
28 unsigned char *output, unsigned int chunk_sz);
29 int chunk_size; /* Watchdog chunk size */
33 * Maximum digest size for all algorithms we support. Having this value
34 * avoids a malloc() or C99 local declaration in common/cmd_hash.c.
36 #define HASH_MAX_DIGEST_SIZE 32
39 HASH_FLAG_VERIFY = 1 << 0, /* Enable verify mode */
40 HASH_FLAG_ENV = 1 << 1, /* Allow env vars */
44 * hash_command: Process a hash command for a particular algorithm
46 * This common function is used to implement specific hash commands.
48 * @algo_name: Hash algorithm being used (lower case!)
49 * @flags: Flags value (HASH_FLAG_...)
50 * @cmdtp: Pointer to command table entry
51 * @flag: Some flags normally 0 (see CMD_FLAG_.. above)
52 * @argc: Number of arguments (arg 0 must be the command text)
55 int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
56 int argc, char * const argv[]);
59 * hash_block() - Hash a block according to the requested algorithm
61 * The caller probably knows the hash length for the chosen algorithm, but
62 * in order to provide a general interface, and output_size parameter is
65 * @algo_name: Hash algorithm to use
67 * @len: Lengh of data to hash in bytes
68 * @output: Place to put hash value
69 * @output_size: On entry, pointer to the number of bytes available in
70 * output. On exit, pointer to the number of bytes used.
71 * If NULL, then it is assumed that the caller has
72 * allocated enough space for the hash. This is possible
73 * since the caller is selecting the algorithm.
74 * @return 0 if ok, -ve on error: -EPROTONOSUPPORT for an unknown algorithm,
75 * -ENOSPC if the output buffer is not large enough.
77 int hash_block(const char *algo_name, const void *data, unsigned int len,
78 uint8_t *output, int *output_size);