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 FSecPkcsPkcs05Schemes.h
20 * @brief This is the header file for the %Pkcs05Schemes class.
22 * This header file contains the declarations of the %Pkcs05Schemes class.
25 #ifndef _FSEC_PKCS_PKCS_05_SCHEMES_H_
26 #define _FSEC_PKCS_PKCS_05_SCHEMES_H_
28 #include <FBaseByteBuffer.h>
29 #include <FSecPkcsPkcs05PbKdf2Parameters.h>
30 #include <FSecPkcsPkcs05PbEs2Parameters.h>
31 #include <FSecPkcsPkcs05PbMacParameters.h>
33 namespace Tizen { namespace Security { namespace Pkcs
37 * @class Pkcs05Schemes
38 * @brief This class implements the functionalities specified by the pkcs05 schemes like Key derivation function,
39 * encryption and signature schemes.
44 class _OSP_EXPORT_ Pkcs05Schemes
45 : public Tizen::Base::Object
49 * The object is not fully constructed after this constructor is called. @n
50 * For full construction, the Construct() method must be called right after calling this constructor.
57 * This destructor overrides Tizen::Base::Object::~Object().
61 virtual ~Pkcs05Schemes(void);
64 * Initializes the %Pkcs05Schemes with supplied input parameters values.
68 * @return An error code.
69 * @param[in] password An instance of ByteBuffer , holding the password.
70 * @param[in] derivedKeyLength A positive integer contains the length of derived key.@n
71 * It is a variable length in PbEs2 based on underlying encryption operation.
72 * @exception E_SUCCESS The method is successful.
73 * @exception E_INVALID_ARG The specified input parameter is invalid.
75 result Construct(const Tizen::Base::ByteBuffer& password, int derivedKeyLength);
78 * This API will generate the Password based derived key using PBKDF2 scheme.
79 * The length of the derived key is essentially unbounded. However, the maximum effective search space for
80 * the derived key may be limited by the structure of the underlying pseudo random function.
84 * @return A pointer to ByteBuffer contains the derived key, @n
85 * else @c null if an error occurs.
86 * @param[in] params An instance of PbKdf2Parameters, containing Kdf2 parameter.
87 * salt value, iteration count and key length.
88 * @exception E_SUCCESS The method is successful.
89 * @exception E_INVALID_ARG The specified input parameter is invalid.
90 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
91 * @remarks The specific error code can be accessed using the GetLastResult() method.
93 Tizen::Base::ByteBuffer* GenerateKeyKdf2N(const Pkcs05PbKdf2Parameters& params);
96 * This API implements EncryptionScheme2N API which combines the GenerateKeyKdf2N function and encrypts the
97 * message M under a password P to produce a ciphertext C, by applying selected key derivation function KDF
98 * (which is GenerateKeyKdf2N) and selected underlying encryption scheme (which can be any block chiper).
102 * @return Pointer to ByteBuffer contains the encrypted message, @n
103 * else @c null if an error occurs.
104 * @param[in] params An instance of PbEs2Parameters, parameter structure holding AlgorithmIdentifier for key derivation
105 * function and AlgorithmIdentifier for underlying encryption scheme.
106 * @param[in] message An instance of ByteBuffer, holding the plain text to encrypt.
107 * @exception E_SUCCESS The method is successful.
108 * @exception E_INVALID_ARG The specified input parameter is invalid.
109 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
110 * @remarks The specific error code can be accessed using the GetLastResult() method.
112 Tizen::Base::ByteBuffer* EncryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message);
115 * This API implements DecryptionScheme2N API which combines the GenerateKeyKdf2N function and decrypts the ciphertext C,
116 * under a password P to recover message M , by applying selected key derivation function KDF(which is GenerateKeyKdf2N)
117 * and selected underlying decryption algorithm (which can be any block cipher).
121 * @return Pointer to ByteBuffer contains the plain text message.
122 * @param[in] params An instance of PbEs2Parameters, parameter structure holding AlgorithmIdentifier for key derivation
123 * function and AlgorithmIdentifier for underlying encryption scheme.
124 * @param[in] message An instance of ByteBuffer, holding the cipher text to decrypt.
125 * @exception E_SUCCESS The method is successful.
126 * @exception E_INVALID_ARG The specified input parameter is invalid.
127 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
128 * @remarks The specific error code can be accessed using the GetLastResult() method.
130 Tizen::Base::ByteBuffer* DecryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message);
133 * This API implements GetPbHMacN API process a message M under a password P to generate a message authentication code T,
134 * by applying selected key derivation function KDF(which is GenerateKeyKdf2N) and selected underlying message authentication scheme
135 * (which can be any HMAC algorithm). GenerateMacN combines a password-based key derivation function, which shall be
136 * GenerateKeyKdf2N for this version of PKCS #5, with an underlying message authentication scheme
137 * The key length and any other parameters for the underlying message authentication scheme
138 * depend on the scheme.
142 * @return Pointer to ByteBuffer containing the HMAC generated from message, @n
143 * else @c null if an error occurs.
144 * @param[in] params An instance of bMacParameters, parameter structure holding AlgorithmIdentifier for key derivation
145 * function and AlgorithmIdentifier for underlying encryption scheme.
146 * @param[in] message An instance of ByteBuffer, holding the message for which MAC needs to be generated.
147 * @exception E_SUCCESS The method is successful.
148 * @exception E_INVALID_ARG The specified input parameter is invalid.
149 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
150 * @remarks The specific error code can be accessed using the GetLastResult() method.
152 Tizen::Base::ByteBuffer* GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message);
155 * This API implements VerifyMac API which processes a message M under a password P to verify a message authentication code T,
156 * by applying a selected key derivation function KDF2 and a selected underlying message authentication scheme combines a
157 * password-based key derivation function, which shall be GenerateKeyKdf2N for this version of PKCS #5, with an underlying
158 * message authentication scheme (which can be any SHA-1 or any SHA-2 algorithm). The key length and any other parameters
159 * for the underlying message authentication scheme depend on the scheme.
163 * @return An error code
164 * @param[in] params An instance of PbMacParameters, parameter structure holding AlgorithmIdentifier for key derivation
165 * function and AlgorithmIdentifier for underlying encryption scheme.
166 * @param[in] message An instance of ByteBuffer, holding the message M.
167 * @param[in] mac An instance of ByteBuffer, holding the HMAC mac that needs to be verified against message.
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_INVALID_ARG The specified input parameter is invalid.
170 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
171 * @remarks The specific error code can be accessed using the GetLastResult() method.
173 result VerifyPbMac(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message, const Tizen::Base::ByteBuffer& mac);
176 // This copy constructor is intentionally declared as private to prohibit @n
177 // copying of objects by users.
180 Pkcs05Schemes(const Pkcs05Schemes& rhs);
182 // The implementation of this copy assignment operator is intentionally blank and @n
183 // declared as private to prohibit copying of objects.
186 Pkcs05Schemes& operator =(const Pkcs05Schemes& rhs);
189 class _Pkcs05SchemesImpl* __pPkcs05SchemesImpl;
190 friend class _Pkcs05SchemesImpl;
194 } } } // Tizen::Security::Pkcs
196 #endif //_FSEC_PKCS_PKCS_05_SCHEMES_H_