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