xref: /rk3399_rockchip-uboot/include/hw_sha.h (revision b9cb64825b5e6efeb715abd8b48d9b12f98973e9)
11f9c9280SAkshay Saraswat /*
21f9c9280SAkshay Saraswat  * Header file for SHA hardware acceleration
31f9c9280SAkshay Saraswat  *
41f9c9280SAkshay Saraswat  * Copyright (c) 2012  Samsung Electronics
51f9c9280SAkshay Saraswat  *
61a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
71f9c9280SAkshay Saraswat  */
81f9c9280SAkshay Saraswat #ifndef __HW_SHA_H
91f9c9280SAkshay Saraswat #define __HW_SHA_H
10*94e3c8c4Sgaurav rana #include <hash.h>
111f9c9280SAkshay Saraswat 
121f9c9280SAkshay Saraswat /**
131f9c9280SAkshay Saraswat  * Computes hash value of input pbuf using h/w acceleration
141f9c9280SAkshay Saraswat  *
151f9c9280SAkshay Saraswat  * @param in_addr	A pointer to the input buffer
161f9c9280SAkshay Saraswat  * @param bufleni	Byte length of input buffer
171f9c9280SAkshay Saraswat  * @param out_addr	A pointer to the output buffer. When complete
181f9c9280SAkshay Saraswat  *			32 bytes are copied to pout[0]...pout[31]. Thus, a user
191f9c9280SAkshay Saraswat  *			should allocate at least 32 bytes at pOut in advance.
201f9c9280SAkshay Saraswat  * @param chunk_size	chunk size for sha256
211f9c9280SAkshay Saraswat  */
221f9c9280SAkshay Saraswat void hw_sha256(const uchar * in_addr, uint buflen,
231f9c9280SAkshay Saraswat 			uchar * out_addr, uint chunk_size);
241f9c9280SAkshay Saraswat 
251f9c9280SAkshay Saraswat /**
261f9c9280SAkshay Saraswat  * Computes hash value of input pbuf using h/w acceleration
271f9c9280SAkshay Saraswat  *
281f9c9280SAkshay Saraswat  * @param in_addr	A pointer to the input buffer
291f9c9280SAkshay Saraswat  * @param bufleni	Byte length of input buffer
301f9c9280SAkshay Saraswat  * @param out_addr	A pointer to the output buffer. When complete
311f9c9280SAkshay Saraswat  *			32 bytes are copied to pout[0]...pout[31]. Thus, a user
321f9c9280SAkshay Saraswat  *			should allocate at least 32 bytes at pOut in advance.
331f9c9280SAkshay Saraswat  * @param chunk_size	chunk_size for sha1
341f9c9280SAkshay Saraswat  */
351f9c9280SAkshay Saraswat void hw_sha1(const uchar * in_addr, uint buflen,
361f9c9280SAkshay Saraswat 			uchar * out_addr, uint chunk_size);
37*94e3c8c4Sgaurav rana 
38*94e3c8c4Sgaurav rana /*
39*94e3c8c4Sgaurav rana  * Create the context for sha progressive hashing using h/w acceleration
40*94e3c8c4Sgaurav rana  *
41*94e3c8c4Sgaurav rana  * @algo: Pointer to the hash_algo struct
42*94e3c8c4Sgaurav rana  * @ctxp: Pointer to the pointer of the context for hashing
43*94e3c8c4Sgaurav rana  * @return 0 if ok, -ve on error
44*94e3c8c4Sgaurav rana  */
45*94e3c8c4Sgaurav rana int hw_sha_init(struct hash_algo *algo, void **ctxp);
46*94e3c8c4Sgaurav rana 
47*94e3c8c4Sgaurav rana /*
48*94e3c8c4Sgaurav rana  * Update buffer for sha progressive hashing using h/w acceleration
49*94e3c8c4Sgaurav rana  *
50*94e3c8c4Sgaurav rana  * The context is freed by this function if an error occurs.
51*94e3c8c4Sgaurav rana  *
52*94e3c8c4Sgaurav rana  * @algo: Pointer to the hash_algo struct
53*94e3c8c4Sgaurav rana  * @ctx: Pointer to the context for hashing
54*94e3c8c4Sgaurav rana  * @buf: Pointer to the buffer being hashed
55*94e3c8c4Sgaurav rana  * @size: Size of the buffer being hashed
56*94e3c8c4Sgaurav rana  * @is_last: 1 if this is the last update; 0 otherwise
57*94e3c8c4Sgaurav rana  * @return 0 if ok, -ve on error
58*94e3c8c4Sgaurav rana  */
59*94e3c8c4Sgaurav rana int hw_sha_update(struct hash_algo *algo, void *ctx, const void *buf,
60*94e3c8c4Sgaurav rana 		     unsigned int size, int is_last);
61*94e3c8c4Sgaurav rana 
62*94e3c8c4Sgaurav rana /*
63*94e3c8c4Sgaurav rana  * Copy sha hash result at destination location
64*94e3c8c4Sgaurav rana  *
65*94e3c8c4Sgaurav rana  * The context is freed after completion of hash operation or after an error.
66*94e3c8c4Sgaurav rana  *
67*94e3c8c4Sgaurav rana  * @algo: Pointer to the hash_algo struct
68*94e3c8c4Sgaurav rana  * @ctx: Pointer to the context for hashing
69*94e3c8c4Sgaurav rana  * @dest_buf: Pointer to the destination buffer where hash is to be copied
70*94e3c8c4Sgaurav rana  * @size: Size of the buffer being hashed
71*94e3c8c4Sgaurav rana  * @return 0 if ok, -ve on error
72*94e3c8c4Sgaurav rana  */
73*94e3c8c4Sgaurav rana int hw_sha_finish(struct hash_algo *algo, void *ctx, void *dest_buf,
74*94e3c8c4Sgaurav rana 		     int size);
75*94e3c8c4Sgaurav rana 
761f9c9280SAkshay Saraswat #endif
77