yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * crypto_struct.h |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * UMOLYE |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * Defines crypto engine service ILM structure |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | * ========================================================================== |
| 54 | * $Log$ * |
| 55 | * |
| 56 | * |
| 57 | ****************************************************************************/ |
| 58 | #ifndef __CRYPTO_STRUCT_H__ |
| 59 | #define __CRYPTO_STRUCT_H__ |
| 60 | |
| 61 | #include "kal_public_defs.h" |
| 62 | #include "kal_public_api.h" |
| 63 | #include "kal_general_types.h" |
| 64 | |
| 65 | typedef enum{ |
| 66 | CAL_EC_CURVE_START, |
| 67 | CAL_EC_CURVE_NSIT_P_256 = CAL_EC_CURVE_START, /* NID_X9_62_prime256v1 */ |
| 68 | CAL_EC_CURVE_NSIT_P_384, /* NID_secp384r1 */ |
| 69 | CAL_EC_CURVE_NSIT_P_521, /* NID_secp521r1 */ |
| 70 | CAL_EC_CURVE_END |
| 71 | }cal_ec_named_curves_t; |
| 72 | |
| 73 | |
| 74 | typedef enum{ |
| 75 | CAL_PKEY_TYPE_START, |
| 76 | CAL_PKEY_TYPE_DH = CAL_PKEY_TYPE_START, |
| 77 | CAL_PKEY_TYPE_RSA, |
| 78 | CAL_PKEY_TYPE_DSA, |
| 79 | CAL_PKEY_TYPE_EC, |
| 80 | CAL_PKEY_TYPE_END |
| 81 | }cal_pkey_types_t; |
| 82 | |
| 83 | typedef struct |
| 84 | { |
| 85 | kal_int32 data_len; |
| 86 | kal_int32 key_len; |
| 87 | kal_int32 iv_len; |
| 88 | kal_int32 aad_len; |
| 89 | kal_int32 tag_len; |
| 90 | kal_uint8 *data; /* Plain text */ |
| 91 | kal_uint8 *key; |
| 92 | kal_uint8 *iv; /* Initialization vector */ |
| 93 | kal_uint8 *aad; /* Additional Authentical Data */ |
| 94 | } cipher_encrypt_in_para_struct; |
| 95 | |
| 96 | typedef struct{ |
| 97 | kal_int32 tag_len; |
| 98 | kal_uint8 *data; |
| 99 | kal_uint8 *tag; |
| 100 | } cipher_encrypt_out_para_struct; |
| 101 | |
| 102 | typedef struct |
| 103 | { |
| 104 | kal_int32 data_len; |
| 105 | kal_int32 key_len; |
| 106 | kal_int32 iv_len; |
| 107 | kal_int32 aad_len; |
| 108 | kal_int32 tag_len; |
| 109 | kal_uint8 *data; /* Encrypted text */ |
| 110 | kal_uint8 *key; |
| 111 | kal_uint8 *iv; /* Initialization vector */ |
| 112 | kal_uint8 *aad; /* Additional Authentical Data */ |
| 113 | kal_uint8 *tag; |
| 114 | } cipher_decrypt_in_para_struct; |
| 115 | |
| 116 | typedef struct{ |
| 117 | kal_uint8 *data; |
| 118 | } cipher_decrypt_out_para_struct; |
| 119 | |
| 120 | |
| 121 | typedef struct{ |
| 122 | kal_int32 data_len; |
| 123 | kal_int32 key_len; |
| 124 | kal_uint8 *data; /* Plain text */ |
| 125 | kal_uint8 *key; |
| 126 | } generate_hmac_in_para_struct; |
| 127 | |
| 128 | typedef struct{ |
| 129 | kal_uint8 *data; |
| 130 | } generate_hmac_out_para_struct; |
| 131 | |
| 132 | typedef generate_hmac_in_para_struct generate_prn_in_para_struct; |
| 133 | typedef generate_hmac_out_para_struct generate_prn_out_para_struct; |
| 134 | |
| 135 | typedef struct{ |
| 136 | kal_int32 message_len; |
| 137 | kal_uint8 *message; |
| 138 | } message_digest_in_para_struct; |
| 139 | |
| 140 | typedef struct{ |
| 141 | kal_uint32 digest_len; |
| 142 | kal_uint8 *digest; |
| 143 | } message_digest_out_para_struct; |
| 144 | |
| 145 | typedef struct{ |
| 146 | kal_int32 message_len; |
| 147 | kal_int32 key_len; |
| 148 | kal_uint8 *message; /* Plain text */ |
| 149 | kal_uint8 *key; |
| 150 | |
| 151 | } pkey_generate_cmac_in_para_struct; |
| 152 | |
| 153 | typedef struct{ |
| 154 | kal_int32 mac_len; |
| 155 | kal_uint8 *mac; |
| 156 | } pkey_generate_cmac_out_para_struct; |
| 157 | |
| 158 | typedef struct{ |
| 159 | kal_uint32 scheme; /* Signature scheme cal_signature_scheme_type_t */ |
| 160 | kal_int32 pubkey_len; |
| 161 | kal_int32 pubkey_exp_len; |
| 162 | kal_int32 msg_len; |
| 163 | kal_int32 signature_len; |
| 164 | kal_uint8 *pubkey; /* For ECDSA : Public key, For RSA : RSA modulus */ |
| 165 | kal_uint8 *pubkey_exp; /* For ECDSA : NULL, For RSA : RSA public exponent */ |
| 166 | kal_uint8 *msg; |
| 167 | kal_uint8 *signature; |
| 168 | } pkey_verify_signature_in_para_struct; |
| 169 | |
| 170 | typedef struct{ |
| 171 | kal_int32 p_len; |
| 172 | kal_int32 g_len; |
| 173 | kal_uint8 *p; |
| 174 | kal_uint8 *g; |
| 175 | } pkey_generate_dh_key_in_para_struct; |
| 176 | |
| 177 | typedef struct |
| 178 | { |
| 179 | kal_int32 pub_len; |
| 180 | void *dh; |
| 181 | kal_uint8 *pub; |
| 182 | } pkey_generate_dh_key_out_para_struct; |
| 183 | |
| 184 | typedef struct |
| 185 | { |
| 186 | kal_int32 peer_pub_len; |
| 187 | void *dh; |
| 188 | kal_uint8 *peer_pub; |
| 189 | } pkey_compute_dh_secret_in_struct; |
| 190 | |
| 191 | typedef struct |
| 192 | { |
| 193 | kal_int32 secret_len; |
| 194 | kal_uint8 *secret; |
| 195 | } pkey_compute_dh_secret_out_struct; |
| 196 | |
| 197 | /************************************************** |
| 198 | * CRYPTO ilm struct |
| 199 | **************************************************/ |
| 200 | |
| 201 | // MSG_ID_CRPTBRG_CIPHER_ENCRYPT_REQ |
| 202 | typedef struct |
| 203 | { |
| 204 | LOCAL_PARA_HDR |
| 205 | |
| 206 | kal_uint32 req_id; |
| 207 | kal_uint32 algo; /* Crypto algorithm to be used for decryption */ |
| 208 | kal_uint32 flags; |
| 209 | cipher_encrypt_in_para_struct in; |
| 210 | kal_uint8 *out; /* Cipher text */ |
| 211 | kal_uint8 *tag; /* Tag/Digest */ |
| 212 | |
| 213 | } crptbrg_cipher_encrypt_req_struct; |
| 214 | |
| 215 | // MSG_ID_CRPTBRG_CIPHER_DECRYPT_REQ |
| 216 | typedef struct |
| 217 | { |
| 218 | LOCAL_PARA_HDR |
| 219 | |
| 220 | kal_uint32 req_id; |
| 221 | kal_uint32 algo; /* Crypto algorithm to be used for decryption */ |
| 222 | kal_uint32 flags; |
| 223 | cipher_decrypt_in_para_struct in; |
| 224 | kal_uint8 *out; /* Plain text */ |
| 225 | } crptbrg_cipher_decrypt_req_struct; |
| 226 | |
| 227 | |
| 228 | // MSG_ID_CRPTBRG_GENERATE_HMAC_REQ |
| 229 | typedef struct |
| 230 | { |
| 231 | LOCAL_PARA_HDR |
| 232 | |
| 233 | kal_uint32 req_id; |
| 234 | kal_uint32 algo; /* Crypto algorithm to be used for encryption */ |
| 235 | generate_hmac_in_para_struct in; |
| 236 | kal_uint8 *out; |
| 237 | } crptbrg_generate_hmac_req_struct; |
| 238 | |
| 239 | // MSG_ID_CRPTBRG_GENERATE_PRN_REQ |
| 240 | typedef crptbrg_generate_hmac_req_struct crptbrg_generate_prn_req_struct; |
| 241 | |
| 242 | |
| 243 | // MSG_ID_CRPTBRG_VERIFY_SIGNATURE_REQ |
| 244 | typedef struct |
| 245 | { |
| 246 | LOCAL_PARA_HDR |
| 247 | |
| 248 | kal_uint32 req_id; |
| 249 | pkey_verify_signature_in_para_struct in; |
| 250 | |
| 251 | } crptbrg_verify_signature_req_struct; |
| 252 | |
| 253 | // MSG_ID_CRPTBRG_GENERATE_DH_KEY_REQ |
| 254 | typedef struct |
| 255 | { |
| 256 | LOCAL_PARA_HDR |
| 257 | |
| 258 | kal_uint32 req_id; |
| 259 | pkey_generate_dh_key_in_para_struct in; |
| 260 | kal_uint8 *out; /* Public key */ |
| 261 | |
| 262 | } crptbrg_generate_dh_key_req_struct; |
| 263 | |
| 264 | // MSG_ID_CRPTBRG_COMPUTE_DH_SECRET_REQ |
| 265 | typedef struct |
| 266 | { |
| 267 | LOCAL_PARA_HDR |
| 268 | |
| 269 | kal_uint32 req_id; |
| 270 | pkey_compute_dh_secret_in_struct in; |
| 271 | kal_uint8 *out; /* Shared secret */ |
| 272 | |
| 273 | } crptbrg_compute_dh_secret_req_struct; |
| 274 | |
| 275 | // MSG_ID_CRPTBRG_ABORT_DH_KEY_IND |
| 276 | typedef struct |
| 277 | { |
| 278 | LOCAL_PARA_HDR |
| 279 | void *dh; |
| 280 | } crptbrg_abort_dh_key_ind_struct; |
| 281 | |
| 282 | // MSG_ID_CRPTBRG_CIPHER_ENCRYPT_CNF |
| 283 | typedef struct |
| 284 | { |
| 285 | LOCAL_PARA_HDR |
| 286 | |
| 287 | kal_uint32 req_id; |
| 288 | kal_int32 out_len; |
| 289 | kal_int32 tag_len; |
| 290 | cipher_encrypt_in_para_struct in; /* Input struct back to app to free memory */ |
| 291 | kal_uint8 *out; /* Cipher text */ |
| 292 | kal_uint8 *tag; |
| 293 | } crptbrg_cipher_encrypt_cnf_struct; |
| 294 | |
| 295 | // MSG_ID_CRPTBRG_CIPHER_DECRYPT_CNF |
| 296 | typedef struct |
| 297 | { |
| 298 | LOCAL_PARA_HDR |
| 299 | |
| 300 | kal_uint32 req_id; |
| 301 | kal_int32 out_len; |
| 302 | cipher_decrypt_in_para_struct in; /* Input struct back to app to free memory */ |
| 303 | kal_uint8 *out; /* Plain text */ |
| 304 | } crptbrg_cipher_decrypt_cnf_struct; |
| 305 | |
| 306 | |
| 307 | // MSG_ID_CRPTBRG_GENERATE_HMAC_CNF |
| 308 | typedef struct |
| 309 | { |
| 310 | LOCAL_PARA_HDR |
| 311 | |
| 312 | kal_uint32 req_id; |
| 313 | kal_int32 out_len; |
| 314 | generate_hmac_in_para_struct in; /* Input struct back to app to free memory */ |
| 315 | kal_uint8 *out; |
| 316 | } crptbrg_generate_hmac_cnf_struct; |
| 317 | |
| 318 | // MSG_ID_CRPTBRG_GENERATE_PRN_CNF |
| 319 | typedef crptbrg_generate_hmac_cnf_struct crptbrg_generate_prn_cnf_struct; |
| 320 | |
| 321 | // MSG_ID_CRPTBRG_VERIFY_SIGNATURE_CNF |
| 322 | typedef struct |
| 323 | { |
| 324 | LOCAL_PARA_HDR |
| 325 | |
| 326 | kal_uint32 req_id; |
| 327 | kal_uint32 out; /* Verify success or fail; 1 : Success, everything else is fail */ |
| 328 | pkey_verify_signature_in_para_struct in; |
| 329 | |
| 330 | } crptbrg_verify_signature_cnf_struct; |
| 331 | |
| 332 | // MSG_ID_CRPTBRG_GENERATE_DH_KEY_CNF |
| 333 | typedef struct |
| 334 | { |
| 335 | LOCAL_PARA_HDR |
| 336 | |
| 337 | kal_uint32 req_id; |
| 338 | kal_int32 out_len; |
| 339 | pkey_generate_dh_key_in_para_struct in; /* Input struct back to app to free memory */ |
| 340 | kal_uint8 *out; /* Public key */ |
| 341 | void *dh; /* Needed by CAL to compute shared secret */ |
| 342 | } crptbrg_generate_dh_key_cnf_struct; |
| 343 | |
| 344 | // MSG_ID_CRPTBRG_COMPUTE_DH_SECRET_CNF |
| 345 | typedef struct |
| 346 | { |
| 347 | LOCAL_PARA_HDR |
| 348 | |
| 349 | kal_uint32 req_id; |
| 350 | kal_int32 out_len; |
| 351 | pkey_compute_dh_secret_in_struct in; /* Input struct back to app to free memory */ |
| 352 | kal_uint8 *out; /* Shared secret */ |
| 353 | |
| 354 | } crptbrg_compute_dh_secret_cnf_struct; |
| 355 | |
| 356 | typedef struct |
| 357 | { |
| 358 | LOCAL_PARA_HDR |
| 359 | kal_uint32 req_id; |
| 360 | kal_uint32 algo; /* Crypto algorithm to be used for decryption */ |
| 361 | pkey_generate_cmac_in_para_struct in; |
| 362 | kal_uint8 *out; /* memory for cmac*/ |
| 363 | } crptbrg_generate_cmac_req_struct; |
| 364 | |
| 365 | typedef struct |
| 366 | { |
| 367 | LOCAL_PARA_HDR |
| 368 | kal_uint32 req_id; |
| 369 | kal_int32 out_len; |
| 370 | pkey_generate_cmac_in_para_struct in; /* Input struct back to app to free memory */ |
| 371 | kal_uint8 *out; /* cmac */ |
| 372 | } crptbrg_generate_cmac_cnf_struct; |
| 373 | |
| 374 | |
| 375 | |
| 376 | /*********************************************************************** |
| 377 | * CRYPTO Internal Task ilm structs : NOT TO BE USED BY OTHER MODULES * |
| 378 | ***********************************************************************/ |
| 379 | |
| 380 | // MSG_ID_CRYPTO_INTERNAL_GENERATE_DH_KEY_REQ |
| 381 | typedef struct |
| 382 | { |
| 383 | LOCAL_PARA_HDR |
| 384 | |
| 385 | kal_uint32 src_mod_id; |
| 386 | kal_uint32 req_id; |
| 387 | pkey_generate_dh_key_in_para_struct in; |
| 388 | kal_uint8 *out; /* Public key */ |
| 389 | |
| 390 | } crypto_internal_generate_dh_key_req_struct; |
| 391 | |
| 392 | // MSG_ID_CRYPTO_INTERNAL_COMPUTE_DH_SECRET_REQ |
| 393 | typedef struct |
| 394 | { |
| 395 | LOCAL_PARA_HDR |
| 396 | |
| 397 | kal_uint32 src_mod_id; |
| 398 | kal_uint32 req_id; |
| 399 | pkey_compute_dh_secret_in_struct in; |
| 400 | kal_uint8 *out; /* Shared secret */ |
| 401 | |
| 402 | } crypto_internal_compute_dh_secret_req_struct; |
| 403 | |
| 404 | |
| 405 | #endif // __CRYPTO_STRUCT_H__ |