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