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; |
| 74 | unsigned int auth_iv[5]; |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 75 | uint32_t flags; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 76 | } crypto_SHA1_ctx; |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 77 | |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 78 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 79 | unsigned int auth_bytecnt[2]; |
| 80 | unsigned char saved_buff[64]; |
| 81 | unsigned char saved_buff_indx; |
| 82 | unsigned int auth_iv[8]; |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 83 | uint32_t bytes_to_write; |
| 84 | uint32_t flags; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 85 | } crypto_SHA256_ctx; |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 86 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 87 | extern void crypto_eng_reset(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 88 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 89 | extern void crypto_eng_init(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 90 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 91 | extern void crypto_set_sha_ctx(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 92 | unsigned int bytes_to_write, |
| 93 | crypto_auth_alg_type auth_alg, |
| 94 | bool first, bool last); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 95 | |
| 96 | extern void crypto_send_data(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 97 | unsigned char *data_ptr, unsigned int buff_size, |
| 98 | unsigned int bytes_to_write, |
| 99 | unsigned int *ret_status); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 100 | |
| 101 | extern void crypto_get_digest(unsigned char *digest_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 102 | unsigned int *ret_status, |
| 103 | crypto_auth_alg_type auth_alg, bool last); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 104 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 105 | extern void crypto_get_ctx(void *ctx_ptr); |
| 106 | |
Amol Jadi | 7d3ad06 | 2013-01-04 15:30:19 -0800 | [diff] [blame] | 107 | extern uint32_t crypto_get_max_auth_blk_size(); |
| 108 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 109 | static void crypto_init(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 110 | |
| 111 | static crypto_result_type do_sha(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 112 | unsigned int buff_size, |
| 113 | unsigned char *digest_ptr, |
| 114 | crypto_auth_alg_type auth_alg); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 115 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 116 | static crypto_result_type do_sha_update(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 117 | unsigned char *buff_ptr, |
| 118 | unsigned int buff_size, |
| 119 | crypto_auth_alg_type auth_alg, |
| 120 | bool first, bool last); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 121 | |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 122 | static unsigned int calc_num_bytes_to_send(void *ctx_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 123 | unsigned int buff_size, bool last); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 124 | |
| 125 | static crypto_result_type crypto_sha256(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 126 | unsigned int buff_size, |
| 127 | unsigned char *digest_ptr); |
Subbaraman Narayanamurthy | 8fcccbd | 2011-01-28 13:26:00 -0800 | [diff] [blame] | 128 | |
| 129 | static crypto_result_type crypto_sha1(unsigned char *buff_ptr, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 130 | unsigned int buff_size, |
| 131 | unsigned char *digest_ptr); |
Channagoud Kadabi | 1d3e9b4 | 2013-12-04 12:35:46 -0800 | [diff] [blame] | 132 | |
| 133 | bool crypto_initialized(void); |
Subbaraman Narayanamurthy | 9b7276c | 2011-01-25 17:25:30 -0800 | [diff] [blame] | 134 | #endif |