xref: /openbmc/u-boot/include/hw_sha.h (revision 9ec4a67e)
1 /*
2  * Header file for SHA hardware acceleration
3  *
4  * Copyright (c) 2012  Samsung Electronics
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 #ifndef __HW_SHA_H
9 #define __HW_SHA_H
10 #include <hash.h>
11 
12 /**
13  * Computes hash value of input pbuf using h/w acceleration
14  *
15  * @param in_addr	A pointer to the input buffer
16  * @param bufleni	Byte length of input buffer
17  * @param out_addr	A pointer to the output buffer. When complete
18  *			32 bytes are copied to pout[0]...pout[31]. Thus, a user
19  *			should allocate at least 32 bytes at pOut in advance.
20  * @param chunk_size	chunk size for sha256
21  */
22 void hw_sha256(const uchar * in_addr, uint buflen,
23 			uchar * out_addr, uint chunk_size);
24 
25 /**
26  * Computes hash value of input pbuf using h/w acceleration
27  *
28  * @param in_addr	A pointer to the input buffer
29  * @param bufleni	Byte length of input buffer
30  * @param out_addr	A pointer to the output buffer. When complete
31  *			32 bytes are copied to pout[0]...pout[31]. Thus, a user
32  *			should allocate at least 32 bytes at pOut in advance.
33  * @param chunk_size	chunk_size for sha1
34  */
35 void hw_sha1(const uchar * in_addr, uint buflen,
36 			uchar * out_addr, uint chunk_size);
37 
38 /*
39  * Create the context for sha progressive hashing using h/w acceleration
40  *
41  * @algo: Pointer to the hash_algo struct
42  * @ctxp: Pointer to the pointer of the context for hashing
43  * @return 0 if ok, -ve on error
44  */
45 int hw_sha_init(struct hash_algo *algo, void **ctxp);
46 
47 /*
48  * Update buffer for sha progressive hashing using h/w acceleration
49  *
50  * The context is freed by this function if an error occurs.
51  *
52  * @algo: Pointer to the hash_algo struct
53  * @ctx: Pointer to the context for hashing
54  * @buf: Pointer to the buffer being hashed
55  * @size: Size of the buffer being hashed
56  * @is_last: 1 if this is the last update; 0 otherwise
57  * @return 0 if ok, -ve on error
58  */
59 int hw_sha_update(struct hash_algo *algo, void *ctx, const void *buf,
60 		     unsigned int size, int is_last);
61 
62 /*
63  * Copy sha hash result at destination location
64  *
65  * The context is freed after completion of hash operation or after an error.
66  *
67  * @algo: Pointer to the hash_algo struct
68  * @ctx: Pointer to the context for hashing
69  * @dest_buf: Pointer to the destination buffer where hash is to be copied
70  * @size: Size of the buffer being hashed
71  * @return 0 if ok, -ve on error
72  */
73 int hw_sha_finish(struct hash_algo *algo, void *ctx, void *dest_buf,
74 		     int size);
75 
76 #endif
77