]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/hash.h
ARM: versatile: pass console setting to the kernel
[people/ms/u-boot.git] / include / hash.h
CommitLineData
460408ef
SG
1/*
2 * Copyright (c) 2012 The Chromium OS Authors.
1a459660 3 * SPDX-License-Identifier: GPL-2.0+
460408ef
SG
4 */
5
6#ifndef _HASH_H
7#define _HASH_H
8
d20a40de 9#if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
460408ef
SG
10#define CONFIG_HASH_VERIFY
11#endif
12
13struct 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
d5b76673
SG
38enum {
39 HASH_FLAG_VERIFY = 1 << 0, /* Enable verify mode */
40 HASH_FLAG_ENV = 1 << 1, /* Allow env vars */
41};
42
460408ef
SG
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 *
218da0f3 48 * @algo_name: Hash algorithm being used (lower case!)
d5b76673 49 * @flags: Flags value (HASH_FLAG_...)
460408ef
SG
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 */
d5b76673 55int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
460408ef
SG
56 int argc, char * const argv[]);
57
6f907b42
SG
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 */
77int hash_block(const char *algo_name, const void *data, unsigned int len,
78 uint8_t *output, int *output_size);
79
460408ef 80#endif