• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef DECODE_LOCAL_H
17 #define DECODE_LOCAL_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_CODECS
21 #include "crypt_eal_implprovider.h"
22 #include "bsl_list.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
28 #define CRYPT_DECODER_STATE_UNTRIED 1
29 #define CRYPT_DECODER_STATE_TRING 2
30 #define CRYPT_DECODER_STATE_TRIED 3
31 #define CRYPT_DECODER_STATE_SUCCESS 4
32 #define MAX_CRYPT_DECODER_FORMAT_TYPE_STR_LEN 64
33 /**
34  * @brief Decoder context structure
35  */
36 typedef struct CRYPT_DECODER_Method {
37     CRYPT_DECODER_IMPL_NewCtx newCtx;               /* New context function */
38     CRYPT_DECODER_IMPL_SetParam setParam;           /* Set parameter function */
39     CRYPT_DECODER_IMPL_GetParam getParam;           /* Get parameter function */
40     CRYPT_DECODER_IMPL_Decode decode;               /* Decode function */
41     CRYPT_DECODER_IMPL_FreeOutData freeOutData;     /* Free output data function */
42     CRYPT_DECODER_IMPL_FreeCtx freeCtx;             /* Free context function */
43 } CRYPT_DECODER_Method;
44 
45 struct CRYPT_DecoderCtx {
46     /* To get the provider manager context when query */
47     CRYPT_EAL_ProvMgrCtx *providerMgrCtx;     /* Provider manager context */
48     char *attrName;                     /* Attribute name */
49     const char *inFormat;                     /* Input data format */
50     const char *inType;                       /* Input data type */
51     const char *outFormat;                    /* Output data format */
52     const char *outType;                      /* Output data type */
53     void *decoderCtx;                   /* Decoder internal context */
54     CRYPT_DECODER_Method *method;             /* Decoder method */
55     int32_t decoderState;               /* Decoder state */
56 };
57 
58 typedef struct {
59     const char *format;                    /* Data format */
60     const char *type;                      /* Data type */
61     BSL_Param *data;                       /* Data */
62 } DataInfo;
63 
64 typedef struct CRYPT_DECODER_Node {
65     DataInfo inData;                       /* Input data */
66     DataInfo outData;                      /* Output data */
67     CRYPT_DECODER_Ctx *decoderCtx;         /* Decoder context */
68 } CRYPT_DECODER_Node;
69 
70 
71 #define MAX_CRYPT_DECODE_FORMAT_TYPE_SIZE 128
72 struct CRYPT_DECODER_PoolCtx {
73     CRYPT_EAL_LibCtx *libCtx;               /* EAL library context */
74     const char *attrName;                   /* Attribute name */
75     const char *inputFormat;                /* Input data format */
76     const char *inputType;                  /* Input data type */
77     int32_t inputKeyType;                   /* Input data key type */
78     BSL_Param *input;                       /* Input data */
79     const char *targetFormat;               /* Target format */
80     const char *targetType;                 /* Target type */
81     int32_t targetKeyType;                  /* Target data key type */
82     BslList *decoders;                      /* The decoders pool of all provider, the entry is CRYPT_DECODER_Ctx */
83     BslList *decoderPath;                   /* The path of the decoder, the entry is CRYPT_DECODER_Node */
84 };
85 
86 typedef struct {
87     char *attrName;
88     const char *inFormat;
89     const char *inType;
90     const char *outFormat;
91     const char *outType;
92 } DECODER_AttrInfo;
93 
94 int32_t CRYPT_DECODE_ParseDecoderAttr(const char *attrName, DECODER_AttrInfo *info);
95 
96 CRYPT_DECODER_Ctx *CRYPT_DECODE_NewDecoderCtxByMethod(const CRYPT_EAL_Func *funcs, CRYPT_EAL_ProvMgrCtx *mgrCtx,
97     const char *attrName);
98 
99 #ifdef __cplusplus
100 }
101 #endif /* __cplusplus */
102 #endif /* HITLS_CRYPTO_CODECS */
103 
104 #endif /* DECODE_LOCAL_H */