2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSecPkcs_PkcsUtility.h
20 * @brief This is the header file for the %_PkcsUtility class.
22 * This header file contains the declarations of the %_PkcsUtility class.
25 #ifndef _FSEC_PKCS_INTERNAL_PKCS_UTILITY_H_
26 #define _FSEC_PKCS_INTERNAL_PKCS_UTILITY_H_
29 #include <FSecPkcsAlgorithmIdentifier.h>
30 #include <FSecPkcsTypes.h>
34 namespace Tizen { namespace Security { namespace Pkcs
39 *@brief This class contains the declarations for FSecurity PKCS Utility Operations.
47 * Defines the type of Oid.
59 _OID_TYPE_HMAC_SHA2_224,
60 _OID_TYPE_HMAC_SHA2_256,
61 _OID_TYPE_HMAC_SHA2_384,
62 _OID_TYPE_HMAC_SHA2_512,
64 _OID_TYPE_DES_CBC_EDE3,
65 _OID_TYPE_AES_128_CBC,
66 _OID_TYPE_AES_192_CBC,
67 _OID_TYPE_AES_256_CBC,
70 _OID_TYPE_RSA_ENCRYPTION,
76 : public Tizen::Base::Object
80 * This function takes the parameters for encryption and decryption of a message.
84 * @return Returns a pointer to ByteBuffer, contains encrypted/decrypted output data,@n
85 * else @c null if an error occurs.
86 * @param [in] algo An instance of Algorithm Identifier, contains the algorithm.
87 * @param [in] derivedKey An instance of ByteBuffer, contains derived key generated from _OID_TYPE_PBKDF2.
88 * @param [in] dataIn An instance of ByteBuffer, contains the input data.
89 * @param [in] opMode Specifies the Cipher Operation, contains the operation mode(encryption(1)/decryption(0)).
91 * @exception E_SUCCESS The method is successful.
92 * @exception E_OUT_OF_MEMORY The memory is insufficient.
93 * @exception E_SYSTEM Failed to operate openssl library.
94 * @exception E_INVALID_ARG The specified input parameter is invalid.
95 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
96 * @remarks The specific error code can be accessed using the GetLastResult() method.
98 static Tizen::Base::ByteBuffer* EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base::ByteBuffer& derivedKey, const Tizen::Base::ByteBuffer& dataIn, int opMode);
101 * This function takes the algorithm and return the _OidType enum value depending on the algorithm.
105 * @return Returns a _OidType enum value.
106 * @param [in] algorithm String value that contains the algorithm like OID_PBKDF2 etc.
107 * @exception E_SUCCESS The method is successful.
108 * @exception E_INVALID_ARG The specified input parameter is invalid.
109 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
110 * @remarks The specific error code can be accessed using the GetLastResult() method.
112 static _OidType ConvertOidToEnum(Tizen::Base::String algorithm);
115 * This function takes the algorithm and return the defined standard nid value of algorithm.
119 * @return Returns a defined standard nid value of algorithm.
120 * @param [in] algorithm String value that contains the algorithm like OID_PBKDF2 etc.
121 * @exception E_SUCCESS The method is successful.
122 * @exception E_INVALID_ARG The specified input parameter is invalid.
123 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
124 * @remarks The specific error code can be accessed using the GetLastResult() method.
126 static int ConvertToNid(Tizen::Base::String algorithm);
129 * This function takes the standard nid value of algorithm and return the algorithm Oid in String format.
133 * @return Returns a algorithm Oid in String format.
134 * @exception E_SUCCESS The method is successful.
135 * @exception E_INVALID_ARG The specified input parameter is invalid.
136 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
137 * @remarks The specific error code can be accessed using the GetLastResult() method.
139 static Tizen::Base::String ConvertToOid(int nid);
142 * This function takes the standard asn1 tag value of an attribute and return the Pkcs08 tag value.
146 * @return Returns a enum value contains Pkcs08 tag value.
147 * @exception E_SUCCESS The method is successful.
148 * @exception E_INVALID_ARG The specified input parameter is invalid.
149 * @remarks The specific error code can be accessed using the GetLastResult() method.
151 static Pkcs08TagValue ConvertToTagValue(int ans1Type);
154 * This function takes the parameters of _OID_TYPE_PBKDF2 and return the X509_ALGOR structure of openssl same as AlgorithmIdentifier for _OID_TYPE_PBKDF2.
155 * It is used for creating the encoded data for _OID_TYPE_PBES2. This structure is used for pbe2->keyfunc. This function is used internally for encoding/decoding.
159 * @return A pointer to the algorithm identifier structure of openssl,@n
160 * else @c null if an error occurs.
161 * @param [in] iter Integer value contains the iteration count.
162 * @param [in] pSaltValue An instance of char pointer contains the salt value.
163 * @param [in] saltLen Integer value contains the salt length.
164 * @param [in] prfNid Integer value contain the nid value of hmac algorithm.
165 * @param [in] keyLen Integer value contains the derived key length.
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_INVALID_ARG The specified input parameter is invalid.
168 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
169 * @remarks The specific error code can be accessed using the GetLastResult() method.
171 static X509_algor_st* GenerateKdfParametersN(int iter, unsigned char* pSaltValue, int saltLen, int prfNid, int keyLen);
174 * This function takes the pointer to the X509_ALGOR structure of openssl and the oid value of the algorithm amd return the
175 * algorithm parameters after parsing this openssl structure depending on the algorithm passed.
179 * @return Returns a pointer to the IALgorithmParamters interface,@n
180 * else @c null if an error occurs.
181 * @param [in] algoOid Oid value of the algorithm in string format.
182 * @param [in] pAlgoObj Pointer to the X509_ALGOR structure of openssl.
183 * @exception E_SUCCESS The method is successful.
184 * @exception E_INVALID_ARG The specified input parameter is invalid.
185 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
186 * @remarks The specific error code can be accessed using the GetLastResult() method.
188 static IAlgorithmParameters* GernerateParametersFromOidN(Tizen::Base::String algoOid, X509_algor_st* pAlgoObj);
191 * This function takes the pointer to the IAlgorithmParameters and the oid value of the algorithm and return the pointer to the
192 * X509_ALGOR of openssl structure depending on the algorithm passed.
196 * @return A pointer to the algorithm identifier structure of openssl,@n
197 * else @c null if an error occurs.
198 * @param [in] algoOid Oid value of the algorithm in string format.
199 * @param [in] pAlgoParam Pointer to the IAlgorithmParameters contains the parameters for any type depending on the algorithm.
201 * @exception E_SUCCESS The method is successful.
202 * @exception E_INVALID_ARG The specified input parameter is invalid.
203 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
204 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
205 * @remarks The specific error code can be accessed using the GetLastResult() method.
207 static X509_algor_st* GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, IAlgorithmParameters* pAlgoParam);
210 * This function takes the algorithm oid and check whether the parameters exist for this algorithm or not.
214 * @return Returns true if parameters supported for the input algorithm otherwise false.
215 * @param [in] algorithm Oid value of the algorithm in string format.
216 * @exception E_SUCCESS The method is successful.
217 * @exception E_INVALID_ARG The specified input parameter is invalid.
218 * @exception E_UNSUPPORTED_ALGORITHM The input algorithm is not supported.
219 * @remarks The specific error code can be accessed using the GetLastResult() method.
221 static bool IsParameterSupported(Tizen::Base::String algorithm);
224 // This default constructor is intentionally declared as private because this class cannot be constructed.
229 // This default destructor is intentionally declared as private because this class cannot be constructed.
232 virtual ~_PkcsUtility(void);
234 // This copy constructor is intentionally declared as private to prohibit @n
235 // copying of objects by users.
238 _PkcsUtility(const _PkcsUtility& rhs);
240 // The implementation of this copy assignment operator is intentionally blank and @n
241 // declared as private to prohibit copying of objects.
244 _PkcsUtility& operator =(const _PkcsUtility& rhs);
248 } } } // Tizen::Security::Pkcs
250 #endif //_FSEC_PKCS_INTERNAL_PKCS_UTILITY_H_