1 /* 2 * Copyright (c) 2012 The Chromium OS Authors. 3 * SPDX-License-Identifier: GPL-2.0+ 4 */ 5 6 #ifndef _HASH_H 7 #define _HASH_H 8 9 #if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY) 10 #define CONFIG_HASH_VERIFY 11 #endif 12 13 struct hash_algo { 14 const char *name; /* Name of algorithm */ 15 int digest_size; /* Length of digest */ 16 /** 17 * hash_func_ws: Generic hashing function 18 * 19 * This is the generic prototype for a hashing function. We only 20 * have the watchdog version at present. 21 * 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 26 */ 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 */ 30 }; 31 32 /* 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. 35 */ 36 #define HASH_MAX_DIGEST_SIZE 32 37 38 enum { 39 HASH_FLAG_VERIFY = 1 << 0, /* Enable verify mode */ 40 HASH_FLAG_ENV = 1 << 1, /* Allow env vars */ 41 }; 42 43 /** 44 * hash_command: Process a hash command for a particular algorithm 45 * 46 * This common function is used to implement specific hash commands. 47 * 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) 53 * @argv: Arguments 54 */ 55 int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, 56 int argc, char * const argv[]); 57 58 /** 59 * hash_block() - Hash a block according to the requested algorithm 60 * 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 63 * provided. 64 * 65 * @algo_name: Hash algorithm to use 66 * @data: Data to hash 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. 76 */ 77 int hash_block(const char *algo_name, const void *data, unsigned int len, 78 uint8_t *output, int *output_size); 79 80 #endif 81