blob: 25eca2c7802522956d86881beca34acdab8d0646 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
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) 2007
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 *
38 * Filename:
39 * ---------
40 * che_api.h
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * Cipher/Hash Engine API.
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 *
60 * removed!
61 * removed!
62 * removed!
63 *
64 * removed!
65 * removed!
66 * removed!
67 *
68 * removed!
69 * removed!
70 * removed!
71 *
72 * removed!
73 * removed!
74 * removed!
75 *
76 * removed!
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 *
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92 * removed!
93 * removed!
94 * removed!
95 *
96 * removed!
97 * removed!
98 * removed!
99 *
100 * removed!
101 * removed!
102 * removed!
103 *
104 * removed!
105 * removed!
106 * removed!
107 *
108 * removed!
109 * removed!
110 * removed!
111 *
112 * removed!
113 * removed!
114 * removed!
115 *
116 * removed!
117 * removed!
118 * removed!
119 *
120 * removed!
121 * removed!
122 * removed!
123 *
124 * removed!
125 * removed!
126 * removed!
127 *
128 * removed!
129 * removed!
130 * removed!
131 *
132 * removed!
133 * removed!
134 * removed!
135 *
136 * removed!
137 * removed!
138 * removed!
139 *
140 * removed!
141 * removed!
142 * removed!
143 *
144 * removed!
145 * removed!
146 * removed!
147 *
148 * removed!
149 * removed!
150 * removed!
151 *
152 * removed!
153 * removed!
154 * removed!
155 *
156 * removed!
157 * removed!
158 * removed!
159 *
160 * removed!
161 * removed!
162 * removed!
163 *
164 * removed!
165 * removed!
166 * removed!
167 *
168 * removed!
169 * removed!
170 *
171 *
172 * removed!
173 * removed!
174 *
175 *
176 * removed!
177 * removed!
178 *
179 *
180 * removed!
181 * removed!
182 *
183 *
184 * removed!
185 * removed!
186 *
187 *
188 * removed!
189 * removed!
190 *
191 *
192 * removed!
193 * removed!
194 *
195 *
196 * removed!
197 * removed!
198 *
199 *
200 *------------------------------------------------------------------------------
201 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
202 *============================================================================
203 ****************************************************************************/
204
205
206/*! \mainpage Cipher Hash Engine
207 * @author Julie Yang
208 * @version 1.0
209 * @date 2007/06/14
210 *
211 * \section CHE CHE API Introduction
212 *
213 * This document is an introduction of MTK Cipher and Hash Engine API. There is an interface
214 * between Application and Cipher/Hash engine. The interface layer includes four functions.
215 * User and application can just use these four functions to set
216 * cipher/hash condition, and trigger the process of the cipher/hash engine. Either the
217 * bottom layer is hardware or software driver.\n\n
218 *
219 * CHE API also release four enum structures to define the setting parameters for AP using.
220 * User can just use these structures to set cipher/hash conditions,
221 * and trigger the process of the cipher/hash engine.\n
222 *
223 * The header file is in \\mcu\\applib\\misc\\include\\che_api.h\n
224 *
225 * The API is supported after 07A branch. \n
226 *
227 *
228 */
229
230/** @defgroup CHE Cipher/Hash Engine Interface
231 * @{
232 */
233
234/** @defgroup CHE Cipher/Hash Engine Interface
235 * @{
236 */
237#ifndef _CHE_API_H
238#define _CHE_API_H
239
240#include "kal_public_api.h" //MSBB change #include "kal_release.h"
241#include "fsal.h"
242//#include "md5.h"
243//#include "sha1.h"
244//#include "md4.h"
245
246/* DOM-NOT_FOR_SDK-BEGIN */
247/* DNS context structure */
248typedef struct DES_CNXT_T
249{
250#if defined(__HW_CHE__)
251 kal_uint8 cheCKey[36]; /* des; 3des;convert_aes_128_key;convert_aes_192_key;convert_aes_256_key */
252 kal_uint8 cheDataAddr[120]; /* che_hw_des;che_hw_aes;che_hw_hash */
253#else /* defined(__HW_CHE__) */
254 kal_uint8 cheLastBlock[16]; /* Last block used in counter mode (store the previous cipher text) */
255 kal_uint8 cheLastReminder[16]; /* Last remainder block */
256 kal_uint8 cheKeySchedule[128]; /* key schedule */
257 kal_uint8 iv[64]; /* initial vector */
258#endif /* defined(__HW_CHE__) */
259}DES_CNXT;
260
261/* AES context structure */
262typedef struct AES_CNXT_T
263{
264#if defined(__HW_CHE__)
265 kal_uint8 cheCKey[36]; /* des; 3des;convert_aes_128_key;convert_aes_192_key;convert_aes_256_key */
266 kal_uint8 cheDataAddr[120]; /* che_hw_des;che_hw_aes;che_hw_hash */
267#else /* defined(__HW_CHE__) */
268 kal_uint8 cheLastReminder[16]; /* Last remaining segment */
269 kal_uint8 orgIV[64]; /* Initial vector */
270#endif /* defined(__HW_CHE__) */
271}AES_CNXT;
272
273/* MD5 and SH1 structure */
274typedef struct MD5_CNXT_T
275{
276#if defined(__HW_CHE__)
277 kal_uint8 cheDataAddr[120]; /* che_hw_des;che_hw_aes;che_hw_hash */
278#else
279 kal_uint8 *working_buffer; /* working buffer */
280#endif
281}MD5_CNXT, SHA1_CNXT;
282
283/* structure used for MD5,SHA1, MAC_MD5, MAC_SHA1, MD4, DHM */
284typedef struct CNXT_T
285{
286 kal_uint8 *working_buffer; /* working buffer */
287}SW_MISC_CNXT;
288
289/* RC4 structure */
290typedef struct RC4_CNXT_T
291{
292 kal_uint32 x, y; /* the swap index */
293 kal_uint8 keyStream[256]; /* key stream */
294} RC4_CNXT;
295
296/* used only for HW HASH ;che_hw_des;che_hw_aes;che_hw_hash */
297typedef struct HASH_CNXT_T
298{
299 kal_uint8 cheDataAddr[120]; /* Data address */
300}HASH_CNXT;
301
302/* RSA structure */
303#if 0
304/* under construction !*/
305/* under construction !*/
306/* under construction !*/
307/* under construction !*/
308/* under construction !*/
309/* under construction !*/
310/* under construction !*/
311/* under construction !*/
312/* under construction !*/
313/* under construction !*/
314/* under construction !*/
315/* under construction !*/
316/* under construction !*/
317/* under construction !*/
318/* under construction !*/
319/* under construction !*/
320/* under construction !*/
321/* under construction !*/
322/* under construction !*/
323/* under construction !*/
324/* under construction !*/
325/* under construction !*/
326/* under construction !*/
327#endif
328
329/* #define __CHE_RSA_GEN_KEY__ */
330
331/** The structure STCHE is defined to record and maintain the context of CHE */
332typedef struct STCHE_T
333{
334 kal_uint32 cheLastLength; /* last block length */
335 kal_uint8 *cheLastDstAddr; /* last destination address */
336
337 kal_uint8 *cheWorkBuf; /* pointe to a space used by each algorithm */
338 kal_uint32 cheBufLen; /* the length of cheWorkBuf. It depends on the encrypt algorithm */
339 kal_uint32 cipher_type; /* cipher type */
340
341 kal_uint8 *cheKey; /* key stream */
342 kal_uint8 *cheIV; /* initial vector */
343 kal_uint32 cheKeyLength; /* key stream length */
344 kal_uint32 cheIVLength; /* initial vector length */
345
346#if defined(__HW_CHE__)
347 kal_bool cheResetKeyFlag; /* Reset key flag */
348 kal_bool cheResetIVFlag; /* Reset initial vector flag */
349#endif /* defined(__HW_CHE__) */
350
351 kal_bool cheFirstFlag; /* first block flag */
352 } STCHE;
353
354/* DOM-NOT_FOR_SDK-END */
355
356/* CHE error cause */
357typedef enum
358{
359 CHE_OK = 0, /* success */
360 CHE_ERROR = -1, /* error occurs */
361 CHE_KEY_CHK_FAIL = -2, /* public or private key check fail */
362 CHE_INVALID_LENGTH = -3, /* buffer length too small or too long */
363 CHE_OPERATION_FAIL = -4 /* che operation fails, such as cipher fail */
364} che_result_error_enum;
365
366/** CHE_TYPE define the cipher and hash function algorithm type */
367typedef enum
368{
369 CHE_MD5 = 1, /* MD5 hash algorithm. The output length is fixed 16 bytes */
370 CHE_DES, /* DES block cipher algorithm. The CHE will do auto padding in DES type.
371 The maximum padding length is 8 bytes */
372 CHE_3DES, /* 3DES block cipher algorithm. The CHE will do auto padding in 3DES type.
373 The maximum padding length is 8 bytes */
374 CHE_AES, /* AES block cipher algorithm. The CHE will do auto padding in AES(ECB, CBC) type.
375 The maximum padding length is 16 bytes */
376
377 CHE_MAC_MD5, /* HMAC_MD5 hash algorithm. The output length is fixed 16 bytes */
378 CHE_RC4, /* RC4 stream cipher algorithm. No padding */
379
380 CHE_DH, /* Diffie Hellman cipher algorithm used to generate the key. No padding */
381 CHE_MAC_SHA224, /* HMAC_SHA224 hash algorithm. The output length is fixed 28 bytes */
382 CHE_MAC_SHA256, /* HMAC_SHA256 hash algorithm. The output length is fixed 32 bytes */
383 CHE_SHA224, /* SHA 224 algorithm */
384 CHE_SHA256 /* SHA 256 algorithm */
385 //CHE_SHA1, /* SHA1 hash algorithm. The output length is fixed 20 bytes */
386 //CHE_MD4, /* MD4 hash algorithm. The output length is fixed 16 bytes */
387 //CHE_MAC_SHA1, /* HMAC_SHA1 hash algorithm. The output length is fixed 20 bytes */
388 //CHE_RSA, /* RSA asym cipher algorithm. */
389
390} CHE_TYPE;
391
392/* CHE_OPERATION_MODE define the cipher function mode. For hash function, it could be set CHE_MODE_NULL */
393typedef enum
394{
395 CHE_MODE_NULL = 0, /* null mode. This mode is used when there is no mode operation */
396 CHE_ECB, /* AES/DES ECB mode */
397 CHE_CBC, /* AES/DES CBC mode */
398 CHE_CTR, /* AES CTR(counter) mode */
399 CHE_F8, /* AES F8 mode */
400
401 CHE_SKIP, /* RC4 Skip mode */
402 CHE_KEY_WRAP, /* AES key wrap mode */
403 CHE_KEY_UNWRAP /* AES key unwrap mode */
404
405} CHE_OPERATION_MODE;
406
407#if 0
408/* under construction !*/
409/* under construction !*/
410/* under construction !*/
411/* under construction !*/
412/* under construction !*/
413/* under construction !*/
414/* under construction !*/
415/* under construction !*/
416#endif
417
418/* CHE_ACTION define this CHE process should run hash, encipher or decipher */
419typedef enum
420{
421 CHE_HASH, /* generate hash value */
422 CHE_ENC, /* encryption data */
423 CHE_DEC, /* decryption data */
424 CHE_MAC_HASH, /* generate HMAC value */
425
426 DH_INIT, /* initialize the Diffie-Hellman */
427 DH_MAKE_PARAMS, /* Suppose A=G^a mod p. generate discrete logarithms(a) and A */
428 DH_MAKE_PUBLIC, /* Suppose A=G^a mod p. generate discrete logarithms(a) and A */
429 DH_CALC_SECRET, /* Suppose B=G^b mod p. Calculate the shared secret (G^b)^a mod P */
430 DH_FREE /* finialize the Diffie-Hellman */
431} CHE_ACTION;
432
433/* CHE_KEY_ACTION define the CHE Key process. The life cycle of input key buffer should
434 * be maintained until che_deinit except RSA.
435 */
436typedef enum
437{
438 CHE_GEN_KEY, /* generate the key exclude asynmetry and RC4 algirhtm */
439 CHE_SET_KEY, /* set the key exclude asynmetry and RC4 algirhtm */
440 CHE_GET_KEY, /* get the key exclude asynmetry and RC4 algirhtm*/
441 CHE_DEL_KEY, /* delete the key exclude asynmetry and RC4 algirhtm */
442
443 CHE_SET_RC4_KEY, /* set the RC4 key */
444
445#if defined(__CHE_RSA_GEN_KEY__)
446 CHE_GEN_RSA_KEY, /* generate RSA key for hardware */
447 CHE_DEL_RSA_KEY, /* delete the RSA key for hardward */
448#endif /* defined(__CHE_RSA_GEN_KEY__) */
449 CHE_SET_RSA_N, /* set the RSA modulus N. N=P*Q. N is prime number.
450 The input N is a binary data */
451 CHE_SET_RSA_E, /* set the RSA public exponent: E.
452 The input E is a binary data */
453 CHE_SET_RSA_D, /* set the RSA private exponent: D.
454 The input D is a binary data */
455 CHE_SET_RSA_P, /* set the RSA modulus P(CRT format).
456 The input P is a binary data */
457 CHE_SET_RSA_Q, /* set the RSA modulus Q(CRT format).
458 The input Q is the binary data */
459 CHE_SET_RSA_dModPm1, /* set the RSA private exponent(CRT format): DP.
460 The input DP is a binary data */
461 CHE_SET_RSA_dModQm1, /* set the RSA private exponent(CRT format): DQ.
462 The input DQ is a binary data */
463 CHE_SET_RSA_qInvModP, /* set the coefficient Integer(CRT format): inverse Q.
464 The input InvQ is a binary data */
465
466 CHE_SET_DH_P, /* set the DH modulus: P. The input P is a binary data. */
467 CHE_SET_DH_G, /* set the DH prime root: G. The input G is a binary data */
468 CHE_SET_DH_SELF_PUBLIC, /* set the self public value. G^X mod P. The input is a binary data. */
469 CHE_SET_DH_PEER_PUBLIC, /* set the peer public value. G^Y mod P. The input is a binary data. */
470 CHE_SET_DH_PRIVATE, /* set the discrete logarithms(private key): X.
471 The input X is a binary data. */
472
473 CHE_GET_DH_SELF_PUBLIC_LEN, /* get the self public length */
474 CHE_GET_DH_PRIVATE_LEN, /* get the discrete logarithm length */
475 CHE_GET_DH_SECRET_LEN, /* get the secret length */
476
477 CHE_GET_DH_SELF_PUBLIC, /* get self public value */
478 CHE_GET_DH_PRIVATE, /* get the discrete logarithm */
479 CHE_GET_DH_SECRET, /* get the shared key,i.e. key. key = GY^X mod P */
480
481 CHE_GET_RSA_N, /* get the RSA modulus N. N=P*Q. N is prime number. The output N is binary data */
482 CHE_GET_RSA_E, /* get the RSA public exponent: E. The output E is a binary data */
483 CHE_GET_RSA_D, /* get the RSA private exponent: D. The output D is a binary data */
484 CHE_GET_RSA_P, /* get the RSA modulus P(CRT format). The output P is a binary data */
485 CHE_GET_RSA_Q, /* get the RSA modulus Q(CRT format). The output Q is the binary data */
486 CHE_GET_RSA_dModPm1, /* get the RSA private exponent(CRT format): DP. The output DP is a binary data */
487 CHE_GET_RSA_dModQm1, /* get the RSA private exponent(CRT format): DQ. The output DQ is a binary data */
488 CHE_GET_RSA_qInvModP, /* get the coefficient Integer(CRT format): inverse Q. The output InvQ is a binary data */
489
490 CHE_GET_RSA_N_LEN, /* get the RSA modulus N. N=P*Q. N is prime number. The output N is binary data */
491 CHE_GET_RSA_E_LEN, /* get the RSA public exponent: E. The output E is a binary data */
492 CHE_GET_RSA_D_LEN, /* get the RSA private exponent: D. The output D is a binary data */
493 CHE_GET_RSA_P_LEN, /* get the RSA modulus P(CRT format). The output P is a binary data */
494 CHE_GET_RSA_Q_LEN, /* get the RSA modulus Q(CRT format). The output Q is the binary data */
495 CHE_GET_RSA_dModPm1_LEN, /* get the RSA private exponent(CRT format): DP. The output DP is a binary data */
496 CHE_GET_RSA_dModQm1_LEN, /* get the RSA private exponent(CRT format): DQ. The output DQ is a binary data */
497 CHE_GET_RSA_qInvModP_LEN /* get the coefficient Integer(CRT format): inverse Q. The output InvQ is a binary data */
498
499} CHE_KEY_ACTION;
500
501typedef enum
502{
503 CHE_NO_ERROR = 0, /* success */
504 CHE_NOT_SUPPORT_ALGO, /* not support error */
505 CHE_INVALID_NULL_POINTER, /* input NULL pointer */
506 CHE_INVALID_KEY_POINTER, /* key NULL pointer */
507 CHE_CALCULATE_FAIL /* calculate fail */
508
509} CHE_CALCULATE_ERROR;
510
511#include "che_trick.h"
512
513
514/*****************************************************************************
515 * FUNCTION
516 * che_init
517 * DESCRIPTION
518 * Initialize the CHE_CONTEXT data structure created from AP
519 * PARAMETERS
520 * che_context : [IN] CHE context
521 * type : [IN] CHE type (CHE_TYPE)
522 * RETURN VALUES
523 * void
524 * SEE ALSO
525 * che_deinit
526 * EXAMPLE
527 * <code>
528 * STCHE context;
529 * che_init(&context, CHE_SHA1);
530 * </code>
531 *****************************************************************************/
532extern void che_init(STCHE *che_context, kal_uint32 type);
533
534/*****************************************************************************
535 * FUNCTION
536 * che_deinit
537 * DESCRIPTION
538 * Deinitialize the CHE_CONTEXT
539 * PARAMETERS
540 * che_context : [IN] CHE context
541 * RETURN VALUES
542 * void
543 * SEE ALSO
544 * che_init
545 * EXAMPLE
546 * <code>
547 * STCHE context;
548 * che_init(&context, CHE_SHA1);
549 * ...
550 * che_deinit(&context);
551 * </code>
552 *****************************************************************************/
553extern void che_deinit(STCHE *che_context);
554
555/*****************************************************************************
556 * DESCRIPTION
557 * API used to set, get, delete, generate the key value.
558 * If user uses this API to get the key, CHE only stores the pointer of the key.
559 * Thus, the key has to be kept until the che_deinit is called. There is only
560 * One exception, in the RSA, we will allocate another space to store the key.
561 * Thus, user doesn't have to care if they can release the buffer of key.
562 * PARAMETERS
563 * che_context : [IN] che context
564 * key_act : [IN] key action (CHE_KEY_ACTION)
565 * key : [IN/OUT] key stream
566 * key_ley : [IN] key stream length
567 * EXAMPLE
568 * <code>
569 * STCHE che_context;
570 * che_init(&che_context, CHE_MAC_MD5);
571 * che_key_action(&che_context, CHE_SET_KEY, (kal_uint8 *) key, key_len);
572 * </code>
573 *****************************************************************************/
574#define che_key_action(che_context, key_act, key, key_len) \
575 \
576 ((void)TRICK_##key_act, run_##key_act##_process(che_context, key, key_len))
577
578/*****************************************************************************
579 * FUNCTION
580 * che_set_iv
581 * DESCRIPTION
582 * Set initial vector for CBC or CTR or AES_F8 mode. CHE only stores the pointer address.
583 * The iv buffer should be kept by the user until the first block is computed.
584 * To avoid confusion, user can keep the buffer until the che_deinit is called.
585 * PARAMETERS
586 * che_context : [IN] CHE context
587 * iv : [IN] initial vector.
588 * the input has to be 4-byte alignment on ARM platform
589 * iv_len : [IN] initial vector length
590 * RETURN VALUES
591 * void
592 * EXAMPLE
593 * <code>
594 * STCHE context;
595 * che_init(&context, CHE_AES);
596 * che_set_iv(&che_context, iv, 16);
597 * ...
598 * che_deinit(&context);
599 * </code>
600 *****************************************************************************/
601extern void che_set_iv(STCHE *che_context, kal_uint8 *iv, kal_uint32 iv_len);
602
603
604/*****************************************************************************
605 * DESCRIPTION
606 * API used to execute cipher and hash process function.
607 * Since using Marco to reduce linkage code size, please pass the "type" parameter
608 * as the constant announced in CHE_TYPE enum. It doesn't allow passing variable.
609 * The dest buffer size should be refer to the RFC standard specification.
610 * The DES/AES in CBC/ECB mode will do the auto padding if application uses the CHE's auto padding,
611 * the destination buffer address has to be at least source_length + 1 DES block size(8 bytes) .
612 * Otherwise, there will be a memory corruption. If application doesn't want to use auto padding,
613 * it cannot set the last_block to "TRUE". That is to say, as long as the last_block is not set to
614 * TRUE, there will no auto padding. The auto padding CHE uses is PKCS#1 v15. This padding is standard
615 * padding used in PCKS#5.
616 * P.S. The input and output buffer should be different buffer. Don't use the same buffer.
617 *
618 * PARAMETERS
619 * che_context : [IN] che context
620 * type : [IN] che type (CHE_TYPE)
621 * mode : [IN] che operation mode (CHE_OPERATION_MODE)
622 * act : [IN] che action (CHE_ACTION)
623 * source : [IN] source input data buffer (it has to be 4-byte alignment for DES and AES)
624 * dest : [OUT] destination buffer (it has to be 4-byte alignment for DES)
625 * source_length : [IN] source input buffer length
626 * final : [IN] KAL_TRUE: do the standard auto padding(PKCS#5).
627 * KAL_FLASE: don't do the standard auto padding(PKCS#5).
628 * If user wants the auto padding, s/he has to set the final to TRUE in its final block
629 * operation. On the contrary, if s/he doesn't want the auto padding, please do not set
630 * final to TRUE.
631 * RETURN VALUES
632 * KAL_TRUE : CHE process successful
633 * KAL_FLASE : CHE process fail
634 * SEE ALSO
635 * che_process_from_file
636 * EXAMPLE
637 * Symmetry Block Cipher Examples:
638 *
639 * 1. DES Encryption (CBC mode):
640 * The input, initial vector and destination address have to be in 4-byte alignment.
641 *
642 * With auto padding:
643 * <code>
644 * STCHE che_context;
645 * che_init(&che_context, CHE_DES);
646 * che_key_action(&che_context, CHE_SET_KEY, key, key_length);
647 * che_set_iv(&che_context, init_vector, vec_length);
648 * che_process(&che_context, CHE_DES, CHE_CBC , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
649 * ...
650 * //if the last segmemnt in source buffer is intended to be processed and we want to use the auto padding,
651 * //we set final to TRUE
652 * che_process(&che_context, CHE_DES, CHE_CBC , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_TRUE);
653 * // do other operation
654 * ...
655 * //Deinitialize when all cipher operation is finish
656 * che_deinit(&che_context);
657 * </code>
658 *
659 * Without auto padding:
660 * <code>
661 * STCHE che_context;
662 * che_init(&che_context, CHE_DES);
663 * che_key_action(&che_context, CHE_SET_KEY, key, key_length);
664 * che_set_iv(&che_context, init_vector, vec_length);
665 * che_process(&che_context, CHE_DES, CHE_CBC , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
666 * ...
667 * //if the last segmemnt in source buffer is intended to be processed and we don't want the auto padding,
668 * //we set final to FALSE
669 * che_process(&che_context, CHE_DES, CHE_CBC , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
670 * // do other operation
671 * ...
672 * //Deinitialize when all cipher operation is finish
673 * che_deinit(&che_context);
674 * </code>
675 * 2. DES Encryption (ECB mode):
676 * With auto padding:
677 * <code>
678 * STCHE che_context;
679 * che_init(&che_context, CHE_DES);
680 * che_key_action(&che_context, CHE_SET_KEY, key, key_length);
681 * che_process(&che_context, CHE_DES, CHE_ECB , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
682 * ...
683 * //if the last segmemnt in source buffer is intended to be processed and we want to use the auto padding,
684 * //we set final to TRUE
685 * che_process(&che_context, CHE_DES, CHE_ECB , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_TRUE);
686 * // do other operation
687 * ...
688 * //Deinitialize when all cipher operation is finish
689 * che_deinit(&che_context);
690 * </code>
691 *
692 * Without auto padding:
693 * <code>
694 * STCHE che_context;
695 * che_init(&che_context, CHE_DES);
696 * che_key_action(&che_context, CHE_SET_KEY, key, key_length);
697 * che_process(&che_context, CHE_DES, CHE_ECB , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
698 * ...
699 * //if the last segmemnt in source buffer is intended to be processed and we don't want to use the
700 * //auto padding, we set final to TRUE
701 * che_process(&che_context, CHE_DES, CHE_ECB , CHE_ENC, src_buffer, dst_buffer, src_len, KAL_FALSE);
702 * // do other operation
703 * ...
704 * //Deinitialize when all cipher operation is finish
705 * che_deinit(&che_context);
706 * </code>
707 * 3. AES Encryption (Counter mode):
708 * Because this mode doesn't need padding, we don't care the "final" parameter in this mode.
709 * Its input data can not in block boundary size.
710 * <code>
711 * STCHE che_cntx;
712 * che_init(&che_cntx, CHE_AES);
713 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
714 * che_set_iv(&che_cntx, iv, 16);
715 * che_process(&che_cntx, CHE_AES, CHE_CTR, CHE_ENC, src_data, dst_data, src_len, KAL_TRUE);
716 * // do other operation
717 * ...
718 * //Deinitialize when all cipher operation is finish
719 * che_deinit(&che_cntx);
720 * </code>
721 *
722 * 4. AES Encryption (Key WRAP mode):
723 * The input data has to be in multiple of 64 bits block size.
724 * Because this mode doesn't need padding, we don't care the "final" parameter in this mode.
725 * Because one more block is generated for checking in KEY WRAP mode,
726 * the input and output buffer should be different one in KEY_WRAP and KEY_UNWRAP mode.
727 * <code>
728 * STCHE che_cntx;
729 * che_init(&che_cntx, CHE_AES);
730 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
731 * che_set_iv(&che_cntx, iv, 16);
732 * che_process(&che_cntx, CHE_AES, CHE_KEY_WRAP, CHE_ENC, src_data, dst_data, src_len, KAL_TRUE);
733 * // do other operation
734 * ...
735 * //Deinitialize when all cipher operation is finish
736 * che_deinit(&che_cntx);
737 * </code>
738 *
739 * 5. AES Encryption (CBC mode):
740 * The input and initial vector address have to be in 4-byte alignment.
741 *
742 * With auto padding:
743 * <code>
744 * STCHE che_cntx;
745 * che_init(&che_cntx, CHE_AES);
746 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
747 * che_set_iv(&che_cntx, iv, 16);
748 * che_process(&che_cntx, CHE_AES, CHE_CBC, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
749 * //final block
750 * che_process(&che_cntx, CHE_AES, CHE_CBC, CHE_ENC, src_data, dst_data, src_len, KAL_TRUE);
751 * // do other operation
752 * ...
753 * //Deinitialize when all cipher operation is finish
754 * che_deinit(&che_cntx);
755 * </code>
756 *
757 * Without auto padding:
758 * <code>
759 * STCHE che_cntx;
760 * che_init(&che_cntx, CHE_AES);
761 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
762 * che_set_iv(&che_cntx, iv, 16);
763 * che_process(&che_cntx, CHE_AES, CHE_CBC, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
764 * // final block
765 * che_process(&che_cntx, CHE_AES, CHE_CBC, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
766 * // do other operation
767 * ...
768 * //Deinitialize when all cipher operation is finish
769 * che_deinit(&che_cntx);
770 * </code>
771 * 6. AES Encryption (ECB mode):
772 * The input address have to be in 4-byte alignment.
773 *
774 * With auto padding:
775 * <code>
776 * STCHE che_cntx;
777 * che_init(&che_cntx, CHE_AES);
778 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
779 * che_process(&che_cntx, CHE_AES, CHE_ECB, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
780 * //final block
781 * che_process(&che_cntx, CHE_AES, CHE_ECB, CHE_ENC, src_data, dst_data, src_len, KAL_TRUE);
782 * // do other operation
783 * ...
784 * //Deinitialize when all cipher operation is finish
785 * che_deinit(&che_cntx);
786 * </code>
787 *
788 * Without auto padding:
789 * <code>
790 * STCHE che_cntx;
791 * che_init(&che_cntx, CHE_AES);
792 * che_key_action(&che_cntx, CHE_SET_KEY, key, 16);
793 * che_process(&che_cntx, CHE_AES, CHE_ECB, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
794 * //final block
795 * che_process(&che_cntx, CHE_AES, CHE_ECB, CHE_ENC, src_data, dst_data, src_len, KAL_FALSE);
796 * // do other operation
797 * ...
798 * //Deinitialize when all cipher operation is finish
799 * che_deinit(&che_cntx);
800 * </code>
801 *
802 * Symmetry Stream Cipher Example:
803 *
804 * 1. RC4 Encryption:
805 * Because this mode doesn't need padding, we don't care the "final" parameter in this mode.
806 *
807 * Use default RC4 mode:
808 * <code>
809 * STCHE che_ctx;
810 * che_init(&che_ctx, CHE_RC4);
811 * che_key_action(&che_ctx, CHE_SET_KEY, (kal_uint8 *)key, key_len);
812 * che_process(&che_ctx, CHE_RC4, CHE_MODE_NULL, CHE_ENC, (kal_uint8 *)input,
813 * (kal_uint8 *)output, (kal_int32)input_size, KAL_TRUE);
814 * // do other operation
815 * ...
816 * //Deinitialize when all cipher operation is finish
817 * che_deinit(&che_ctx);
818 * </code>
819 *
820 * Use CHE_SKIP mode:
821 * skip the first 256 byts key data because first 256 bytes are not random enough.
822 * <code>
823 * STCHE che_ctx;
824 * che_init(&che_ctx, CHE_RC4);
825 * che_key_action(&che_ctx, CHE_SET_KEY, (kal_uint8 *)key, key_len);
826 * che_process(&che_ctx, CHE_RC4, CHE_SKIP, CHE_ENC, (kal_uint8 *)input,
827 * (kal_uint8 *)output, (kal_int32)input_size, KAL_TRUE);
828 * // do other operation
829 * ...
830 * //Deinitialize when all cipher operation is finish
831 * che_deinit(&che_ctx);
832 * </code>
833 *
834 * Hash Operation:
835 *
836 * 1. MD5 Hash generation:
837 * we have to set the final block to TRUE for hash operation. The mode field is useless for hash algorithm.
838 * HASH doesn't have any mode options. Thus, we set it to CHE_MODE_NULL.
839 *
840 * <code>
841 * STCHE che_context;
842 * kal_uint8 digest[16];
843 * che_init(&che_context, CHE_MD5);
844 * che_process(&che_context,CHE_MD5,CHE_MODE_NULL,CHE_HASH,(kal_uint8*)input,digest,input_len, KAL_FALSE);
845 * ...
846 * che_process(&che_context,CHE_MD5,CHE_MODE_NULL,CHE_HASH,(kal_uint8*)input,digest,input_len, KAL_TRUE);
847 * // do other operation
848 * ...
849 * //Deinitialize when all hash operation is finish
850 * che_deinit(&che_context);
851 * </code>
852 *
853 * 2. SHA1 Hash generation:
854 * we have to set the final block to TRUE for hash operation. The mode field is useless for hash algorithm.
855 * HASH doesn't have any mode options. Thus, we set it to CHE_MODE_NULL.
856 *
857 * <code>
858 * STCHE che_context;
859 * kal_uint8 digest[20];
860 * che_init(&che_context, CHE_SHA1);
861 * che_process(&che_context,CHE_SHA1,CHE_MODE_NULL,CHE_HASH,(kal_uint8*)input,digest,input_len, KAL_FALSE);
862 * ...
863 * che_process(&che_context,CHE_SHA1,CHE_MODE_NULL,CHE_HASH,(kal_uint8*)input,digest,input_len, KAL_TRUE);
864 * che_deinit(&che_context);
865 * // do other operation
866 * ...
867 * //Deinitialize when all hash operation is finish
868 * </code>
869 *
870 * 3. HMAC MD5 generation:
871 * we have to set the final block to TRUE for HMAC operation because HMAC doesn't have padding consideartion for last block.
872 * The mode field is useless for HMAC algorithm. HMAC doesn't have any mode options. Thus, we set it to CHE_MODE_NULL.
873 *
874 * <code>
875 * STCHE che_context;
876 * kal_uint8 digest[16];
877 * che_init(&che_context, CHE_MAC_MD5);
878 * che_key_action(&che_context, CHE_SET_KEY, (kal_uint8 *) key, key_len);
879 * che_process(&che_context, CHE_MAC_MD5, CHE_MODE_NULL, CHE_HASH, (kal_uint8 *) input, digest, input_len, KAL_FALSE);
880 * ...
881 * che_process(&che_context, CHE_MAC_MD5, CHE_MODE_NULL, CHE_HASH, (kal_uint8 *) input, digest, input_len, KAL_TRUE);
882 * // do other operation
883 * ...
884 * //Deinitialize when all hash operation is finish
885 * che_deinit(&che_context);
886 * </code>
887 *
888 * 4. SHA2 Hash generation:
889 * we have to set the final block to TRUE for hash operation. The mode field is useless for hash algorithm.
890 * HASH doesn't have any mode options. Thus, we set it to CHE_MODE_NULL.
891 *
892 * <code>
893 * STCHE che_context;
894 * kal_uint8 digest[32];
895 * che_init(&che_context, CHE_SHA256);
896 * che_process(&che_context, CHE_SHA256, CHE_MODE_NULL, CHE_HASH, (kal_uint8 *) input, digest, input_len, KAL_FALSE);
897 * ...
898 * che_process(&che_context, CHE_SHA256, CHE_MODE_NULL, CHE_HASH, (kal_uint8 *) input, digest, input_len, KAL_TRUE);
899 * // do other operation
900 * ...
901 * //Deinitialize when all hash operation is finish
902 * che_deinit(&che_context);
903 * </code>
904 *
905 * Public Key or Key Agreement:
906 *
907 * 1. Diffie-Hellman:
908 * The source and dest parameter is useless for DH.
909 * The output data is get through che_key_action.
910 * <code>
911 * STCHE che_ctx_dh;
912 * kal_uint32 dh_secret_len;
913 * kal_uint8 *dh_secret_key = NULL;
914 *
915 * che_init(&che_ctx_dh, CHE_DH);
916 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_INIT, NULL, NULL, 0, KAL_TRUE);
917 * // set the p and g. p and g must in binary format
918 * che_key_action(&che_ctx_dh, CHE_SET_DH_P, (kal_uint8*) P, P_Len);
919 * che_key_action(&che_ctx_dh, CHE_SET_DH_G, G, G_Len);
920 * // Compute self public B = (g^b mod p) and private (b)
921 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_MAKE_PARAMS, NULL, NULL, 0, KAL_TRUE);
922 * // Set the peer public key (A) in binary format
923 * che_key_action(&che_ctx_dh, CHE_SET_DH_PEER_PUBLIC, (kal_uint8*)peer_public, peer_public_len);
924 * // calculate the shared secret: K
925 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_CALC_SECRET, NULL, NULL, 0, KAL_TRUE);
926 * //get the shared secret key
927 * che_key_action(&che_ctx_dh, CHE_GET_DH_SECRET_LEN, (void*)&dh_secret_len, sizeof(int));
928 * dh_secret_key = malloc(dh_secret_len);
929 * che_key_action(&che_ctx_dh, CHE_GET_DH_SECRET, (kal_uint8*) dh_secret_key, dh_secret_len);
930 * //call deinit when all operations are finish
931 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_FREE, NULL, NULL, 0, KAL_TRUE);
932 * che_deinit(&che_ctx_dh);
933 * </code>
934 *****************************************************************************/
935#define che_process(che_context, type, mode, act, source, dest, source_length, final) \
936 \
937 ((void)TRICK_##type, run_##type##_process(che_context, type, mode, act, source, dest, source_length, final, 0))
938
939
940#define che_AES_process(che_context, type, mode, act, source, dest, source_length, final, aes_param) \
941 \
942 ((void)TRICK_##type, run_##type##_process(che_context, type, mode, act, source, dest, source_length, final, 0, aes_param))
943/*****************************************************************************
944 * DESCRIPTION
945 * API used to do the CHE computation. The input message is from the "file".
946 * The usage is the same as che_process except the source of input data.
947 * For detail algorithm usage, please also take the reference of "che_process"
948 * PARAMETERS
949 * che_context : [IN] che context
950 * type : [IN] che type (CHE_TYPE)
951 * mode : [IN] che operation mode (CHE_OPERATION_MODE)
952 * act : [IN] che action (CHE_ACTION)
953 * pstFSAL : [IN] source file handler
954 * dest : [OUT] destination buffer (it has to be 4-byte alignment for DES)
955 * RETURN VALUES
956 * KAL_TRUE : CHE process successful
957 * KAL_FLASE : CHE process fail
958 * SEE ALSO
959 * che_process
960 * EXAMPLE
961 * 1. DES Encryption (CBC mode):
962 * The initial vector and destination address have to be in 4-byte alignment.
963 *
964 * <code>
965 * STFSAL pstFSAL;
966 * kal_uint8 pbBuf[512];
967 * STCHE che_str;
968 * che_init(&che_str, CHE_DES);
969 * che_key_action(&che_str, CHE_SET_KEY, key, key_length);
970 * che_set_iv(&che_str, init_vector, vec_length);
971 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
972 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
973 * if (che_process_from_file(&che_str, CHE_DES, CHE_CBC, CHE_ENC,
974 * &pstFSAL, dst_buf) == KAL_FALSE)
975 * {
976 * FSAL_Close(&pstFSAL);
977 * che_deinit(&che_str);
978 * return ERROR;
979 * }
980 * ...
981 * FSAL_Close(&pstFSAL);
982 * // do other operations
983 * ...
984 * //Deinitialize when all operations are finish
985 * che_deinit(&che_str);
986 * </code>
987 *
988 * 2. DES Encryption (ECB mode):
989 * <code>
990 * STFSAL pstFSAL;
991 * kal_uint8 pbBuf[512];
992 * STCHE che_str;
993 * che_init(&che_str, CHE_DES);
994 * che_key_action(&che_str, CHE_SET_KEY, key, key_length);
995 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
996 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
997 * if (che_process_from_file(&che_str, CHE_DES, CHE_ECB, CHE_ENC,
998 * &pstFSAL, dst_buf) == KAL_FALSE)
999 * {
1000 * FSAL_Close(&pstFSAL);
1001 * che_deinit(&che_str);
1002 * return ERROR;
1003 * }
1004 * ...
1005 * FSAL_Close(&pstFSAL);
1006 * // do other operations
1007 * ...
1008 * //Deinitialize when all operations are finish
1009 * che_deinit(&che_str);
1010 * </code>
1011 *
1012 * 3. AES Encryption (CBC mode):
1013 * <code>
1014 * STFSAL pstFSAL;
1015 * kal_uint8 pbBuf[512];
1016 * STCHE che_str;
1017 * che_init(&che_str, CHE_AES);
1018 * che_key_action(&che_str, CHE_SET_KEY, key, key_length);
1019 * che_set_iv(&che_str, init_vector, vec_length);
1020 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
1021 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
1022 * if (che_process_from_file(&che_str, CHE_AES, CHE_CBC, CHE_ENC,
1023 * &pstFSAL, dst_buf) == KAL_FALSE)
1024 * {
1025 * FSAL_Close(&pstFSAL);
1026 * che_deinit(&che_str);
1027 * return ERROR;
1028 * }
1029 * ...
1030 * FSAL_Close(&pstFSAL);
1031 * // do other operations
1032 * ...
1033 * //Deinitialize when all operations are finish
1034 * che_deinit(&che_str);
1035 * </code>
1036 *
1037 * 4. MD5 Hash generation:
1038 * <code>
1039 * STFSAL pstFSAL;
1040 * kal_uint8 pbBuf[512];
1041 * STCHE che_str;
1042 * kal_uint8 digest[16];
1043 * che_init(&che_str, CHE_MD5);
1044 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
1045 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
1046 * if (che_process_from_file(&che_str, CHE_MD5, CHE_MODE_NULL, CHE_HASH,
1047 * &pstFSAL, digest) == KAL_FALSE)
1048 * {
1049 * FSAL_Close(&pstFSAL);
1050 * che_deinit(&che_str);
1051 * return ERROR;
1052 * }
1053 * ...
1054 * FSAL_Close(&pstFSAL);
1055 * // do other operations
1056 * ...
1057 * //Deinitialize when all operations are finish
1058 * che_deinit(&che_str);
1059 * </code>
1060 *
1061 * 5. HMAC MD5 generation:
1062 * <code>
1063 * STFSAL pstFSAL;
1064 * kal_uint8 pbBuf[512];
1065 * STCHE che_str;
1066 * kal_uint8 digest[16];
1067 * che_init(&che_str, CHE_MAC_MD5);
1068 * che_key_action(&che_context, CHE_SET_KEY, (kal_uint8 *) key, key_len);
1069 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
1070 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
1071 * if (che_process_from_file(&che_str, CHE_MAC_MD5, CHE_MODE_NULL, CHE_HASH,
1072 * &pstFSAL, digest) == KAL_FALSE)
1073 * {
1074 * FSAL_Close(&pstFSAL);
1075 * che_deinit(&che_str);
1076 * return ERROR;
1077 * }
1078 * ...
1079 * FSAL_Close(&pstFSAL);
1080 * // do other operations
1081 * ...
1082 * //Deinitialize when all operations are finish
1083 * che_deinit(&che_str);
1084 * </code>
1085 *
1086 * 6. Diffie-Hellman: (key = (G^Y)^X mod P)
1087 * get the discrete logarithms (X) and compute self public value (G^X mod P)
1088 * <code>
1089 * STFSAL pstFSAL;
1090 * kal_uint8 pbBuf[512];
1091 * STCHE che_str;
1092 * che_init(&che_str, CHE_DH);
1093 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_INIT, NULL, NULL, 0, KAL_TRUE);
1094 * // set the P and G that P and G must in binary format
1095 * che_key_action(&che_ctx_dh, CHE_SET_DH_P, (kal_uint8*) P, P_Len);
1096 * che_key_action(&che_ctx_dh, CHE_SET_DH_G, G, G_Len);
1097 * // make self public (G^X mod P) and private (X)
1098 * che_process(&che_ctx_dh, CHE_DH, CHE_MODE_NULL, DH_MAKE_PARAMS, NULL, NULL, 0, KAL_TRUE);
1099 * // get the self public
1100 * che_key_action(&che_ctx_dh, CHE_GET_DH_SELF_PUBLIC_LEN, (void*)&self_public_len, sizeof(int));
1101 * // get the self public
1102 * *self_private = malloc(self_private_len);
1103 * che_key_action(&che_ctx_dh, CHE_GET_DH_PRIVATE, (kal_uint8*) (*priv)->v, dh_private_len);
1104 * FSAL_Open(&pstFSAL, body_data_filepath, FSAL_READ);
1105 * FSAL_SetBuffer(&pstFSAL, 512, pbBuf);
1106 * if (che_process_from_file(&che_str, CHE_MD5, CHE_MODE_NULL, CHE_ENC,
1107 * &pstFSAL, digest) == KAL_FALSE)
1108 * {
1109 * FSAL_Close(&pstFSAL);
1110 * che_deinit(&che_str);
1111 * return ERROR;
1112 * }
1113 * ...
1114 * FSAL_Close(&pstFSAL);
1115 * // do other operations
1116 * ...
1117 * //Deinitialize when all operations are finish
1118 * che_deinit(&che_str);
1119 * </code>
1120 *****************************************************************************/
1121#define che_process_from_file(che_context, type, mode, act, pstFSAL, dest) \
1122 \
1123 ((void)TRICK_##type, run_##type##_process(che_context, type, mode, act, 0, dest, 0, 0, pstFSAL))
1124
1125/*****************************************************************************
1126 * FUNCTION
1127 * che_duplicate
1128 * DESCRIPTION
1129 * Duplicate the CHE structure and current content.
1130 * This API only supports CHE_MD5, CHE_SHA1, CHE_MD4, CHE_MAC_MD5, CHE_MAC_SHA1.
1131 * The situation application may encounter and wish to use this API:
1132 * packet1
1133 * Step 1: A -------------------------> B (B receives packet1 and generates the hash value)
1134 * packet2
1135 * Step 2: A -------------------------> B (B receives another packet2 and generates the hash value again)
1136 *
1137 * In this case, application may wish the result of step 2 is the continue of step 1.
1138 * To fulfill user's need, we provide this API for user to store the temporary CHE cotext for
1139 * later use.
1140 * PARAMETERS
1141 * src_che_context : [IN] source CHE context
1142 * dst_che_context : [IN] destination CHE context
1143 *
1144 * RETURN VALUES
1145 * KAL_TRUE : success
1146 * KAL_FALSE : fail
1147 * EXAMPLE
1148 * <code>
1149 * STCHE dst_context;
1150 * che_duplicate(&dst_context, &src_context);
1151 * </code>
1152 *****************************************************************************/
1153extern kal_bool che_duplicate(STCHE *src_che_context, STCHE *dst_che_context);
1154
1155/*****************************************************************************
1156 * FUNCTION
1157 * che_exc_support_algo
1158 * DESCRIPTION
1159 * Support which algorithm for exception flow (used by che_calculate_exc_ext)
1160 *
1161 * PARAMETERS
1162 * type [IN]
1163 * RETURNS
1164 * kal_bool - KAL_TRUE for support, KAL_FALSE - not support
1165 *****************************************************************************/
1166extern kal_bool che_exc_support_algo(kal_uint32 type);
1167
1168/*****************************************************************************
1169 * FUNCTION
1170 * che_calculate_exc_ext
1171 * DESCRIPTION
1172 * Execute algorithm function for exception flow & normal flow (only support MD5 & HMAC SHA256)
1173 *
1174 * PARAMETERS
1175 * type [IN]
1176 * mode [IN]
1177 * act [IN]
1178 * key [IN]
1179 * key_len [IN]
1180 * source [IN]
1181 * source_length [IN]
1182 * dest [OUT]
1183 * dest_length [OUT]
1184 * RETURNS
1185 * CHE_CALCULATE_ERROR - error code
1186 *****************************************************************************/
1187extern CHE_CALCULATE_ERROR che_calculate_exc_ext(
1188 CHE_TYPE type,
1189 CHE_OPERATION_MODE mode,
1190 CHE_ACTION act,
1191 kal_uint8 *key,
1192 kal_uint32 key_len,
1193 kal_uint8 *source,
1194 kal_uint32 source_length,
1195 kal_uint8 *dest,
1196 kal_uint32 *dest_length);
1197
1198#if 0
1199/* under construction !*/
1200/* under construction !*/
1201/* under construction !*/
1202/* under construction !*/
1203/* under construction !*/
1204/* under construction !*/
1205/* under construction !*/
1206/* under construction !*/
1207/* under construction !*/
1208/* under construction !*/
1209/* under construction !*/
1210/* under construction !*/
1211/* under construction !*/
1212/* under construction !*/
1213/* under construction !*/
1214/* under construction !*/
1215/* under construction !*/
1216/* under construction !*/
1217/* under construction !*/
1218/* under construction !*/
1219/* under construction !*/
1220/* under construction !*/
1221/* under construction !*/
1222/* under construction !*/
1223/* under construction !*/
1224/* under construction !*/
1225/* under construction !*/
1226/* under construction !*/
1227/* under construction !*/
1228/* under construction !*/
1229/* under construction !*/
1230/* under construction !*/
1231/* under construction !*/
1232/* under construction !*/
1233/* under construction !*/
1234/* under construction !*/
1235/* under construction !*/
1236/* under construction !*/
1237/* under construction !*/
1238/* under construction !*/
1239/* under construction !*/
1240/* under construction !*/
1241/* under construction !*/
1242/* under construction !*/
1243/* under construction !*/
1244/* under construction !*/
1245/* under construction !*/
1246/* under construction !*/
1247/* under construction !*/
1248/* under construction !*/
1249/* under construction !*/
1250/* under construction !*/
1251/* under construction !*/
1252/* under construction !*/
1253/* under construction !*/
1254/* under construction !*/
1255/* under construction !*/
1256/* under construction !*/
1257/* under construction !*/
1258/* under construction !*/
1259/* under construction !*/
1260/* under construction !*/
1261/* under construction !*/
1262/* under construction !*/
1263/* under construction !*/
1264/* under construction !*/
1265/* under construction !*/
1266/* under construction !*/
1267/* under construction !*/
1268/* under construction !*/
1269/* under construction !*/
1270/* under construction !*/
1271/* under construction !*/
1272/* under construction !*/
1273/* under construction !*/
1274/* under construction !*/
1275/* under construction !*/
1276/* under construction !*/
1277/* under construction !*/
1278/* under construction !*/
1279/* under construction !*/
1280/* under construction !*/
1281/* under construction !*/
1282/* under construction !*/
1283/* under construction !*/
1284/* under construction !*/
1285/* under construction !*/
1286/* under construction !*/
1287/* under construction !*/
1288/* under construction !*/
1289/* under construction !*/
1290/* under construction !*/
1291/* under construction !*/
1292/* under construction !*/
1293/* under construction !*/
1294/* under construction !*/
1295/* under construction !*/
1296/* under construction !*/
1297/* under construction !*/
1298/* under construction !*/
1299/* under construction !*/
1300/* under construction !*/
1301/* under construction !*/
1302/* under construction !*/
1303/* under construction !*/
1304/* under construction !*/
1305/* under construction !*/
1306/* under construction !*/
1307/* under construction !*/
1308/* under construction !*/
1309/* under construction !*/
1310/* under construction !*/
1311/* under construction !*/
1312/* under construction !*/
1313/* under construction !*/
1314/* under construction !*/
1315/* under construction !*/
1316/* under construction !*/
1317/* under construction !*/
1318/* under construction !*/
1319/* under construction !*/
1320/* under construction !*/
1321/* under construction !*/
1322/* under construction !*/
1323/* under construction !*/
1324/* under construction !*/
1325/* under construction !*/
1326/* under construction !*/
1327/* under construction !*/
1328/* under construction !*/
1329/* under construction !*/
1330/* under construction !*/
1331/* under construction !*/
1332/* under construction !*/
1333/* under construction !*/
1334/* under construction !*/
1335/* under construction !*/
1336/* under construction !*/
1337/* under construction !*/
1338/* under construction !*/
1339/* under construction !*/
1340/* under construction !*/
1341/* under construction !*/
1342/* under construction !*/
1343/* under construction !*/
1344/* under construction !*/
1345/* under construction !*/
1346/* under construction !*/
1347/* under construction !*/
1348/* under construction !*/
1349/* under construction !*/
1350/* under construction !*/
1351/* under construction !*/
1352/* under construction !*/
1353/* under construction !*/
1354/* under construction !*/
1355/* under construction !*/
1356/* under construction !*/
1357/* under construction !*/
1358/* under construction !*/
1359/* under construction !*/
1360/* under construction !*/
1361/* under construction !*/
1362/* under construction !*/
1363/* under construction !*/
1364/* under construction !*/
1365/* under construction !*/
1366/* under construction !*/
1367/* under construction !*/
1368/* under construction !*/
1369/* under construction !*/
1370/* under construction !*/
1371/* under construction !*/
1372/* under construction !*/
1373/* under construction !*/
1374/* under construction !*/
1375/* under construction !*/
1376/* under construction !*/
1377/* under construction !*/
1378/* under construction !*/
1379/* under construction !*/
1380/* under construction !*/
1381/* under construction !*/
1382/* under construction !*/
1383/* under construction !*/
1384/* under construction !*/
1385/* under construction !*/
1386/* under construction !*/
1387/* under construction !*/
1388/* under construction !*/
1389/* under construction !*/
1390/* under construction !*/
1391/* under construction !*/
1392/* under construction !*/
1393/* under construction !*/
1394/* under construction !*/
1395/* under construction !*/
1396/* under construction !*/
1397/* under construction !*/
1398/* under construction !*/
1399/* under construction !*/
1400/* under construction !*/
1401/* under construction !*/
1402/* under construction !*/
1403/* under construction !*/
1404/* under construction !*/
1405/* under construction !*/
1406/* under construction !*/
1407/* under construction !*/
1408/* under construction !*/
1409/* under construction !*/
1410/* under construction !*/
1411/* under construction !*/
1412/* under construction !*/
1413/* under construction !*/
1414/* under construction !*/
1415/* under construction !*/
1416/* under construction !*/
1417/* under construction !*/
1418/* under construction !*/
1419/* under construction !*/
1420/* under construction !*/
1421/* under construction !*/
1422/* under construction !*/
1423/* under construction !*/
1424/* under construction !*/
1425/* under construction !*/
1426/* under construction !*/
1427/* under construction !*/
1428/* under construction !*/
1429/* under construction !*/
1430/* under construction !*/
1431/* under construction !*/
1432/* under construction !*/
1433/* under construction !*/
1434/* under construction !*/
1435/* under construction !*/
1436/* under construction !*/
1437/* under construction !*/
1438/* under construction !*/
1439/* under construction !*/
1440/* under construction !*/
1441/* under construction !*/
1442/* under construction !*/
1443/* under construction !*/
1444/* under construction !*/
1445/* under construction !*/
1446/* under construction !*/
1447/* under construction !*/
1448/* under construction !*/
1449/* under construction !*/
1450/* under construction !*/
1451/* under construction !*/
1452/* under construction !*/
1453/* under construction !*/
1454/* under construction !*/
1455/* under construction !*/
1456/* under construction !*/
1457/* under construction !*/
1458/* under construction !*/
1459/* under construction !*/
1460/* under construction !*/
1461/* under construction !*/
1462/* under construction !*/
1463/* under construction !*/
1464/* under construction !*/
1465/* under construction !*/
1466/* under construction !*/
1467/* under construction !*/
1468/* under construction !*/
1469/* under construction !*/
1470/* under construction !*/
1471/* under construction !*/
1472/* under construction !*/
1473/* under construction !*/
1474/* under construction !*/
1475/* under construction !*/
1476/* under construction !*/
1477/* under construction !*/
1478/* under construction !*/
1479/* under construction !*/
1480/* under construction !*/
1481/* under construction !*/
1482/* under construction !*/
1483/* under construction !*/
1484/* under construction !*/
1485/* under construction !*/
1486/* under construction !*/
1487/* under construction !*/
1488/* under construction !*/
1489/* under construction !*/
1490/* under construction !*/
1491/* under construction !*/
1492/* under construction !*/
1493/* under construction !*/
1494/* under construction !*/
1495/* under construction !*/
1496/* under construction !*/
1497/* under construction !*/
1498/* under construction !*/
1499/* under construction !*/
1500/* under construction !*/
1501/* under construction !*/
1502/* under construction !*/
1503/* under construction !*/
1504/* under construction !*/
1505/* under construction !*/
1506/* under construction !*/
1507/* under construction !*/
1508/* under construction !*/
1509/* under construction !*/
1510/* under construction !*/
1511/* under construction !*/
1512/* under construction !*/
1513/* under construction !*/
1514/* under construction !*/
1515/* under construction !*/
1516/* under construction !*/
1517/* under construction !*/
1518/* under construction !*/
1519/* under construction !*/
1520/* under construction !*/
1521/* under construction !*/
1522/* under construction !*/
1523/* under construction !*/
1524/* under construction !*/
1525/* under construction !*/
1526/* under construction !*/
1527/* under construction !*/
1528/* under construction !*/
1529/* under construction !*/
1530/* under construction !*/
1531/* under construction !*/
1532/* under construction !*/
1533/* under construction !*/
1534/* under construction !*/
1535/* under construction !*/
1536/* under construction !*/
1537/* under construction !*/
1538/* under construction !*/
1539/* under construction !*/
1540/* under construction !*/
1541/* under construction !*/
1542/* under construction !*/
1543/* under construction !*/
1544/* under construction !*/
1545/* under construction !*/
1546/* under construction !*/
1547/* under construction !*/
1548/* under construction !*/
1549/* under construction !*/
1550/* under construction !*/
1551/* under construction !*/
1552/* under construction !*/
1553/* under construction !*/
1554/* under construction !*/
1555/* under construction !*/
1556/* under construction !*/
1557/* under construction !*/
1558/* under construction !*/
1559/* under construction !*/
1560/* under construction !*/
1561/* under construction !*/
1562/* under construction !*/
1563/* under construction !*/
1564/* under construction !*/
1565/* under construction !*/
1566/* under construction !*/
1567/* under construction !*/
1568/* under construction !*/
1569/* under construction !*/
1570/* under construction !*/
1571/* under construction !*/
1572/* under construction !*/
1573/* under construction !*/
1574/* under construction !*/
1575/* under construction !*/
1576/* under construction !*/
1577/* under construction !*/
1578/* under construction !*/
1579/* under construction !*/
1580/* under construction !*/
1581/* under construction !*/
1582/* under construction !*/
1583/* under construction !*/
1584/* under construction !*/
1585/* under construction !*/
1586/* under construction !*/
1587/* under construction !*/
1588/* under construction !*/
1589/* under construction !*/
1590/* under construction !*/
1591/* under construction !*/
1592/* under construction !*/
1593/* under construction !*/
1594#endif
1595
1596extern void SST_SSF_Init(void);
1597
1598extern void SST_SSF_Deinit(void);
1599
1600extern int Base64encode(char *encoded, const char *string, int len);
1601
1602extern int Base64decode(char *bufplain, const char *bufcoded);
1603
1604#endif /* _CHE_API_H */
1605
1606/*
1607 * ! \page page3 Reference
1608 *
1609 * 1) FEDERAL INFORMATION PROCESSING STANDARDS PUBLICATION U.S. DEPARTMENT OF COMMERCE/national Institute of Standards and Technology 46-3 : DATA ENCRYPTION STANDARD (DES)\n
1610 * 2) FEDERAL INFORMATION PROCESSING STANDARDS PUBLICATION 197 : ADVANCED ENCRYPTION STANDARD (AES)\n
1611 * 3) FEDERAL INFORMATION PROCESSING STANDARDS PUBLICATION 180-2 SECURE HASH STANDARD (SHA)\n
1612 * 4) MIT Laboratory for Computer Science and RSA Data Security, Inc. : The MD5 Message-Digest Algorithm\n
1613 *
1614 */
1615