183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 21f9c9280SAkshay Saraswat /* 31f9c9280SAkshay Saraswat * Header file for SHA hardware acceleration 41f9c9280SAkshay Saraswat * 51f9c9280SAkshay Saraswat * Copyright (c) 2012 Samsung Electronics 61f9c9280SAkshay Saraswat */ 71f9c9280SAkshay Saraswat #ifndef __HW_SHA_H 81f9c9280SAkshay Saraswat #define __HW_SHA_H 994e3c8c4Sgaurav rana #include <hash.h> 101f9c9280SAkshay Saraswat 111f9c9280SAkshay Saraswat /** 121f9c9280SAkshay Saraswat * Computes hash value of input pbuf using h/w acceleration 131f9c9280SAkshay Saraswat * 141f9c9280SAkshay Saraswat * @param in_addr A pointer to the input buffer 151f9c9280SAkshay Saraswat * @param bufleni Byte length of input buffer 161f9c9280SAkshay Saraswat * @param out_addr A pointer to the output buffer. When complete 17*45e7dfa9SJoel Stanley * 64 bytes are copied to pout[0]...pout[63]. Thus, a user 18*45e7dfa9SJoel Stanley * should allocate at least 64 bytes at pOut in advance. 19*45e7dfa9SJoel Stanley * @param chunk_size chunk size for sha512 20*45e7dfa9SJoel Stanley */ 21*45e7dfa9SJoel Stanley void hw_sha512(const uchar *in_addr, uint buflen, uchar *out_addr, 22*45e7dfa9SJoel Stanley uint chunk_size); 23*45e7dfa9SJoel Stanley 24*45e7dfa9SJoel Stanley /** 25*45e7dfa9SJoel Stanley * Computes hash value of input pbuf using h/w acceleration 26*45e7dfa9SJoel Stanley * 27*45e7dfa9SJoel Stanley * @param in_addr A pointer to the input buffer 28*45e7dfa9SJoel Stanley * @param bufleni Byte length of input buffer 29*45e7dfa9SJoel Stanley * @param out_addr A pointer to the output buffer. When complete 30*45e7dfa9SJoel Stanley * 48 bytes are copied to pout[0]...pout[47]. Thus, a user 31*45e7dfa9SJoel Stanley * should allocate at least 48 bytes at pOut in advance. 32*45e7dfa9SJoel Stanley * @param chunk_size chunk size for sha384 33*45e7dfa9SJoel Stanley */ 34*45e7dfa9SJoel Stanley void hw_sha384(const uchar *in_addr, uint buflen, uchar *out_addr, 35*45e7dfa9SJoel Stanley uint chunk_size); 36*45e7dfa9SJoel Stanley 37*45e7dfa9SJoel Stanley /** 38*45e7dfa9SJoel Stanley * Computes hash value of input pbuf using h/w acceleration 39*45e7dfa9SJoel Stanley * 40*45e7dfa9SJoel Stanley * @param in_addr A pointer to the input buffer 41*45e7dfa9SJoel Stanley * @param bufleni Byte length of input buffer 42*45e7dfa9SJoel Stanley * @param out_addr A pointer to the output buffer. When complete 431f9c9280SAkshay Saraswat * 32 bytes are copied to pout[0]...pout[31]. Thus, a user 441f9c9280SAkshay Saraswat * should allocate at least 32 bytes at pOut in advance. 451f9c9280SAkshay Saraswat * @param chunk_size chunk size for sha256 461f9c9280SAkshay Saraswat */ 47608acf86SJoel Stanley void hw_sha256(const uchar *in_addr, uint buflen, uchar *out_addr, 48608acf86SJoel Stanley uint chunk_size); 491f9c9280SAkshay Saraswat 501f9c9280SAkshay Saraswat /** 511f9c9280SAkshay Saraswat * Computes hash value of input pbuf using h/w acceleration 521f9c9280SAkshay Saraswat * 531f9c9280SAkshay Saraswat * @param in_addr A pointer to the input buffer 541f9c9280SAkshay Saraswat * @param bufleni Byte length of input buffer 551f9c9280SAkshay Saraswat * @param out_addr A pointer to the output buffer. When complete 561f9c9280SAkshay Saraswat * 32 bytes are copied to pout[0]...pout[31]. Thus, a user 571f9c9280SAkshay Saraswat * should allocate at least 32 bytes at pOut in advance. 581f9c9280SAkshay Saraswat * @param chunk_size chunk_size for sha1 591f9c9280SAkshay Saraswat */ 60608acf86SJoel Stanley void hw_sha1(const uchar *in_addr, uint buflen, uchar *out_addr, 61608acf86SJoel Stanley uint chunk_size); 6294e3c8c4Sgaurav rana 6394e3c8c4Sgaurav rana /* 6494e3c8c4Sgaurav rana * Create the context for sha progressive hashing using h/w acceleration 6594e3c8c4Sgaurav rana * 6694e3c8c4Sgaurav rana * @algo: Pointer to the hash_algo struct 6794e3c8c4Sgaurav rana * @ctxp: Pointer to the pointer of the context for hashing 6894e3c8c4Sgaurav rana * @return 0 if ok, -ve on error 6994e3c8c4Sgaurav rana */ 7094e3c8c4Sgaurav rana int hw_sha_init(struct hash_algo *algo, void **ctxp); 7194e3c8c4Sgaurav rana 7294e3c8c4Sgaurav rana /* 7394e3c8c4Sgaurav rana * Update buffer for sha progressive hashing using h/w acceleration 7494e3c8c4Sgaurav rana * 7594e3c8c4Sgaurav rana * The context is freed by this function if an error occurs. 7694e3c8c4Sgaurav rana * 7794e3c8c4Sgaurav rana * @algo: Pointer to the hash_algo struct 7894e3c8c4Sgaurav rana * @ctx: Pointer to the context for hashing 7994e3c8c4Sgaurav rana * @buf: Pointer to the buffer being hashed 8094e3c8c4Sgaurav rana * @size: Size of the buffer being hashed 8194e3c8c4Sgaurav rana * @is_last: 1 if this is the last update; 0 otherwise 8294e3c8c4Sgaurav rana * @return 0 if ok, -ve on error 8394e3c8c4Sgaurav rana */ 8494e3c8c4Sgaurav rana int hw_sha_update(struct hash_algo *algo, void *ctx, const void *buf, 8594e3c8c4Sgaurav rana unsigned int size, int is_last); 8694e3c8c4Sgaurav rana 8794e3c8c4Sgaurav rana /* 8894e3c8c4Sgaurav rana * Copy sha hash result at destination location 8994e3c8c4Sgaurav rana * 9094e3c8c4Sgaurav rana * The context is freed after completion of hash operation or after an error. 9194e3c8c4Sgaurav rana * 9294e3c8c4Sgaurav rana * @algo: Pointer to the hash_algo struct 9394e3c8c4Sgaurav rana * @ctx: Pointer to the context for hashing 9494e3c8c4Sgaurav rana * @dest_buf: Pointer to the destination buffer where hash is to be copied 9594e3c8c4Sgaurav rana * @size: Size of the buffer being hashed 9694e3c8c4Sgaurav rana * @return 0 if ok, -ve on error 9794e3c8c4Sgaurav rana */ 9894e3c8c4Sgaurav rana int hw_sha_finish(struct hash_algo *algo, void *ctx, void *dest_buf, 9994e3c8c4Sgaurav rana int size); 10094e3c8c4Sgaurav rana 1011f9c9280SAkshay Saraswat #endif 102