blob: 4faca91e2dcd85077bb62768097612c09d84f642 [file] [log] [blame]
Channagoud Kadabifb6ff7e2015-07-13 20:13:05 -07001/* Copyright (c) 2010-2015, The Linux Foundation. All rights reserved.
Amol Jadi7d3ad062013-01-04 15:30:19 -08002 *
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -08003 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
Amol Jadi7d3ad062013-01-04 15:30:19 -08006 * * 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 Narayanamurthy9b7276c2011-01-25 17:25:30 -080015 *
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
Channagoud Kadabifb6ff7e2015-07-13 20:13:05 -070032#include <sys/types.h>
33
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080034#ifndef NULL
35#define NULL 0
36#endif
37
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080038#define SHA256_INIT_VECTOR_SIZE 8
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080039#define SHA1_INIT_VECTOR_SIZE 5
40
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080041#define CRYPTO_SHA_BLOCK_SIZE 64
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080042
Shashank Mittal1fcde7a2011-07-25 13:41:50 -070043#define CRYPTO_ERR_NONE 0x01
44#define CRYPTO_ERR_FAIL 0x02
45
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080046typedef enum {
Amol Jadi7d3ad062013-01-04 15:30:19 -080047 CRYPTO_FIRST_CHUNK = 1,
48 CRYPTO_LAST_CHUNK = 2,
49} crypto_flag_type;
50
51typedef enum {
Ajay Dudanib01e5062011-12-03 23:23:42 -080052 CRYPTO_SHA_ERR_NONE,
53 CRYPTO_SHA_ERR_BUSY,
54 CRYPTO_SHA_ERR_FAIL,
55 CRYPTO_SHA_ERR_INVALID_PARAM,
56} crypto_result_type;
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080057
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080058typedef enum {
Deepa Dinamani5e5c21a2012-02-16 18:59:57 -080059 CRYPTO_ENGINE_TYPE_NONE,
60 CRYPTO_ENGINE_TYPE_SW,
61 CRYPTO_ENGINE_TYPE_HW,
62}crypto_engine_type;
63
64typedef enum {
Ajay Dudanib01e5062011-12-03 23:23:42 -080065 CRYPTO_AUTH_ALG_SHA1 = 1,
66 CRYPTO_AUTH_ALG_SHA256
67} crypto_auth_alg_type;
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080068
69typedef struct {
Ajay Dudanib01e5062011-12-03 23:23:42 -080070 unsigned int auth_bytecnt[2];
71 unsigned char saved_buff[64];
72 unsigned char saved_buff_indx;
Sundarajan Srinivasan6a2bad22013-11-11 18:48:27 -080073 uint32_t bytes_to_write;
Amol Jadi7d3ad062013-01-04 15:30:19 -080074 uint32_t flags;
Sundarajan Srinivasan6a2bad22013-11-11 18:48:27 -080075 unsigned int auth_iv[5];
Ajay Dudanib01e5062011-12-03 23:23:42 -080076} crypto_SHA1_ctx;
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080077
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080078typedef struct {
Ajay Dudanib01e5062011-12-03 23:23:42 -080079 unsigned int auth_bytecnt[2];
80 unsigned char saved_buff[64];
81 unsigned char saved_buff_indx;
Amol Jadi7d3ad062013-01-04 15:30:19 -080082 uint32_t bytes_to_write;
83 uint32_t flags;
Sundarajan Srinivasan6a2bad22013-11-11 18:48:27 -080084 unsigned int auth_iv[8];
Ajay Dudanib01e5062011-12-03 23:23:42 -080085} crypto_SHA256_ctx;
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080086
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080087extern void crypto_eng_reset(void);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080088
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080089extern void crypto_eng_init(void);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -080090
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080091extern void crypto_set_sha_ctx(void *ctx_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -080092 unsigned int bytes_to_write,
93 crypto_auth_alg_type auth_alg,
94 bool first, bool last);
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -080095
96extern void crypto_send_data(void *ctx_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -080097 unsigned char *data_ptr, unsigned int buff_size,
98 unsigned int bytes_to_write,
99 unsigned int *ret_status);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800100
101extern void crypto_get_digest(unsigned char *digest_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800102 unsigned int *ret_status,
103 crypto_auth_alg_type auth_alg, bool last);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800104
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800105extern void crypto_get_ctx(void *ctx_ptr);
106
Amol Jadi7d3ad062013-01-04 15:30:19 -0800107extern uint32_t crypto_get_max_auth_blk_size();
108
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800109static void crypto_init(void);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800110
111static crypto_result_type do_sha(unsigned char *buff_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800112 unsigned int buff_size,
113 unsigned char *digest_ptr,
114 crypto_auth_alg_type auth_alg);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800115
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800116static crypto_result_type do_sha_update(void *ctx_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800117 unsigned char *buff_ptr,
118 unsigned int buff_size,
119 crypto_auth_alg_type auth_alg,
120 bool first, bool last);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800121
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800122static unsigned int calc_num_bytes_to_send(void *ctx_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800123 unsigned int buff_size, bool last);
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800124
125static crypto_result_type crypto_sha256(unsigned char *buff_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800126 unsigned int buff_size,
127 unsigned char *digest_ptr);
Subbaraman Narayanamurthy8fcccbd2011-01-28 13:26:00 -0800128
129static crypto_result_type crypto_sha1(unsigned char *buff_ptr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800130 unsigned int buff_size,
131 unsigned char *digest_ptr);
Channagoud Kadabid7df33d2013-12-04 12:35:46 -0800132
133bool crypto_initialized(void);
vijay kumar4f4405f2014-08-08 11:49:53 +0530134void
135hash_find(unsigned char *addr, unsigned int size, unsigned char *digest,
136 unsigned char auth_alg);
137
138crypto_engine_type board_ce_type(void);
Subbaraman Narayanamurthy9b7276c2011-01-25 17:25:30 -0800139#endif