xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_crypto.h (revision 3149adf58a329e17232a4c0e58d460d025edd55a)
1 /*
2  * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: qdf_crypto.h
21  * This file provides OS abstraction for crypto APIs.
22  */
23 
24 #if !defined(__QDF_CRYPTO_H)
25 #define __QDF_CRYPTO_H
26 
27 /* Include Files */
28 #include "qdf_status.h"
29 #include <qdf_types.h>
30 #include <qdf_trace.h>
31 
32 /* Preprocessor definitions and constants */
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 
37 #define AES_BLOCK_SIZE 16
38 #define HMAC_SHA256_CRYPTO_TYPE "hmac(sha256)"
39 #define HMAC_SHA386_CRYPTO_TYPE "hmac(sha384)"
40 
41 #define SHA256_CRYPTO_TYPE "sha256"
42 #define SHA386_CRYPTO_TYPE "sha384"
43 
44 #define SHA256_DIGEST_SIZE 32
45 #define SHA384_DIGEST_SIZE 48
46 
47 #define FIXED_PARAM_OFFSET_ASSOC_REQ 4
48 #define FIXED_PARAM_OFFSET_ASSOC_RSP 6
49 
50 #define AAD_LEN 20
51 #define IEEE80211_MMIE_GMAC_MICLEN  16
52 
53 #define IS_VALID_CTR_KEY_LEN(len) ((((len) == 16) || ((len) == 32) || \
54 	((len) == 48)) ? 1 : 0)
55 
56 /* Function declarations and documenation */
57 
58 /**
59  * qdf_get_hash: API to get hash using specific crypto and scatterlist
60  * @type: crypto type
61  * @element_cnt: scatterlist element count
62  * @addr: scatterlist element array
63  * @addr_len: element length array
64  * @hash: new hash
65  *
66  * Return: 0 if success else error code
67  */
68 int qdf_get_hash(uint8_t *type, uint8_t element_cnt,
69 		uint8_t *addr[], uint32_t *addr_len,
70 		int8_t *hash);
71 
72 /**
73  * qdf_get_hmac_hash: API to get hmac hash using specific crypto and
74  * scatterlist elements.
75  * @type: crypto type
76  * @key: key needs to be used for hmac api
77  * @keylen: length of key
78  * @element_cnt: scatterlist element count
79  * @addr: scatterlist element array
80  * @addr_len: element length array
81  * @hash: new hash
82  *
83  * Return: 0 if success else error code
84  */
85 int qdf_get_hmac_hash(uint8_t *type, uint8_t *key,
86 		uint32_t keylen, uint8_t element_cnt,
87 		uint8_t *addr[], uint32_t *addr_len, int8_t *hash);
88 
89 /**
90  * qdf_get_keyed_hash: API to get hash using specific crypto and
91  * scatterlist elements.
92  * @type: crypto type
93  * @key: key needs to be used for hmac api
94  * @keylen: length of key
95  * @element_cnt: scatterlist element count
96  * @addr: scatterlist element array
97  * @addr_len: element length array
98  * @hash: new hash
99  *
100  * Return: 0 if success else error code
101  */
102 int qdf_get_keyed_hash(const char *alg, const uint8_t *key,
103 			unsigned int key_len, const uint8_t *src[],
104 			size_t *src_len, size_t num_elements, uint8_t *out);
105 /**
106  * qdf_update_dbl: This API does the doubling operation as defined in RFC5297
107  * @d: input for doubling
108  *
109  * Return: None
110  */
111 void qdf_update_dbl(uint8_t *d);
112 
113 /**
114  * qdf_aes_s2v: This API gets vector from AES string as defined in RFC5297
115  * output length will be AES_BLOCK_SIZE.
116  * @key: key used for operation
117  * @key_len: key len
118  * @s: addresses of elements to be used
119  * @s_len: array of element length
120  * @num_s: number of elements
121  * @out: pointer to output vector
122  *
123  * Return: 0 if success else Error number
124  */
125 int qdf_aes_s2v(const uint8_t *key, unsigned int key_len, const uint8_t *s[],
126 		   size_t s_len[], size_t num_s, uint8_t *out);
127 
128 /**
129  * qdf_aes_ctr: This API defines AES Counter Mode
130  * @key: key used for operation
131  * @key_len: key len
132  * @siv: Initialization vector
133  * @src: input
134  * @src_len: input len
135  * @dest: output
136  * @enc: if encryption needs to be done or decryption
137  *
138  * Return: 0 if success else Error number
139  */
140 int qdf_aes_ctr(const uint8_t *key, unsigned int key_len, uint8_t *siv,
141 		const uint8_t *src, size_t src_len, uint8_t *dest, bool enc);
142 
143 /**
144  * qdf_crypto_aes_gmac: This API calculates MIC for GMAC
145  * @key: key used for operation
146  * @key_length: key length
147  * @iv: Initialization vector
148  * @aad: Additional authentication data
149  * @data: Pointer to data
150  * @data_len: Length of data
151  * @mic: Pointer to MIC
152  *
153  * Return: 0 if success else Error number
154  */
155 int qdf_crypto_aes_gmac(uint8_t *key, uint16_t key_length,
156 			uint8_t *iv, uint8_t *aad, uint8_t *data,
157 			uint16_t data_len, uint8_t *mic);
158 
159 #ifdef __cplusplus
160 }
161 #endif /* __cplusplus */
162 #endif /* __QDF_CRYPTO_H */
163