Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. |
| 2 | * |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef __CRYPTO_HASH_H__ |
| 30 | #define __CRYPYO_HASH_H__ |
| 31 | |
| 32 | #ifndef NULL |
| 33 | #define NULL 0 |
| 34 | #endif |
| 35 | |
| 36 | #define TRUE 1 |
| 37 | #define FALSE 0 |
| 38 | |
| 39 | #define SHA256_INIT_VECTOR_SIZE 8 |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 40 | #define SHA1_INIT_VECTOR_SIZE 5 |
| 41 | |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 42 | #define CRYPTO_SHA_BLOCK_SIZE 64 |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 43 | |
Shashank Mittal | 1fcde7a | 2011-07-25 13:41:50 -0700 | [diff] [blame] | 44 | #define CRYPTO_ERR_NONE 0x01 |
| 45 | #define CRYPTO_ERR_FAIL 0x02 |
| 46 | |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 47 | typedef enum { |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 48 | CRYPTO_FIRST_CHUNK = 1, |
| 49 | CRYPTO_LAST_CHUNK = 2, |
| 50 | } crypto_flag_type; |
| 51 | |
| 52 | typedef enum { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 53 | CRYPTO_SHA_ERR_NONE, |
| 54 | CRYPTO_SHA_ERR_BUSY, |
| 55 | CRYPTO_SHA_ERR_FAIL, |
| 56 | CRYPTO_SHA_ERR_INVALID_PARAM, |
| 57 | } crypto_result_type; |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 58 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 59 | typedef enum { |
Deepa Dinamani | 5e5c21a | 2012-02-16 18:59:57 -0800 | [diff] [blame] | 60 | CRYPTO_ENGINE_TYPE_NONE, |
| 61 | CRYPTO_ENGINE_TYPE_SW, |
| 62 | CRYPTO_ENGINE_TYPE_HW, |
| 63 | }crypto_engine_type; |
| 64 | |
| 65 | typedef enum { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 66 | CRYPTO_AUTH_ALG_SHA1 = 1, |
| 67 | CRYPTO_AUTH_ALG_SHA256 |
| 68 | } crypto_auth_alg_type; |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 69 | |
| 70 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 71 | unsigned int auth_bytecnt[2]; |
| 72 | unsigned char saved_buff[64]; |
| 73 | unsigned char saved_buff_indx; |
Sundarajan Srinivasan | 5bba3de | 2013-11-11 18:48:27 -0800 | [diff] [blame^] | 74 | uint32_t bytes_to_write; |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 75 | uint32_t flags; |
Sundarajan Srinivasan | 5bba3de | 2013-11-11 18:48:27 -0800 | [diff] [blame^] | 76 | unsigned int auth_iv[5]; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 77 | } crypto_SHA1_ctx; |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 78 | |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 79 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 80 | unsigned int auth_bytecnt[2]; |
| 81 | unsigned char saved_buff[64]; |
| 82 | unsigned char saved_buff_indx; |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 83 | uint32_t bytes_to_write; |
| 84 | uint32_t flags; |
Sundarajan Srinivasan | 5bba3de | 2013-11-11 18:48:27 -0800 | [diff] [blame^] | 85 | unsigned int auth_iv[8]; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 86 | } crypto_SHA256_ctx; |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 87 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 88 | extern void crypto_eng_reset(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 89 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 90 | extern void crypto_eng_init(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 91 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 92 | extern void crypto_set_sha_ctx(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 93 | unsigned int bytes_to_write, |
| 94 | crypto_auth_alg_type auth_alg, |
| 95 | bool first, bool last); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 96 | |
| 97 | extern void crypto_send_data(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 98 | unsigned char *data_ptr, unsigned int buff_size, |
| 99 | unsigned int bytes_to_write, |
| 100 | unsigned int *ret_status); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 101 | |
| 102 | extern void crypto_get_digest(unsigned char *digest_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 103 | unsigned int *ret_status, |
| 104 | crypto_auth_alg_type auth_alg, bool last); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 105 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 106 | extern void crypto_get_ctx(void *ctx_ptr); |
| 107 | |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 108 | extern uint32_t crypto_get_max_auth_blk_size(); |
| 109 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 110 | static void crypto_init(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 111 | |
| 112 | static crypto_result_type do_sha(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 113 | unsigned int buff_size, |
| 114 | unsigned char *digest_ptr, |
| 115 | crypto_auth_alg_type auth_alg); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 116 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 117 | static crypto_result_type do_sha_update(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 118 | unsigned char *buff_ptr, |
| 119 | unsigned int buff_size, |
| 120 | crypto_auth_alg_type auth_alg, |
| 121 | bool first, bool last); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 122 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 123 | static unsigned int calc_num_bytes_to_send(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | unsigned int buff_size, bool last); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 125 | |
| 126 | static crypto_result_type crypto_sha256(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 127 | unsigned int buff_size, |
| 128 | unsigned char *digest_ptr); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 129 | |
| 130 | static crypto_result_type crypto_sha1(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 131 | unsigned int buff_size, |
| 132 | unsigned char *digest_ptr); |
Channagoud Kadabi | 1d3e9b4 | 2013-12-04 12:35:46 -0800 | [diff] [blame] | 133 | |
| 134 | bool crypto_initialized(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 135 | #endif |