Resolve the "Klocwork" detected defect and add debug feature.
[platform/framework/native/appfw.git] / inc / FSecPkcsPkcs05Schemes.h
1 //
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FSecPkcsPkcs05Schemes.h
19  * @brief               This is the header file for the %Pkcs05Schemes class.
20  *
21  * This header file contains the declarations of the %Pkcs05Schemes class.
22  */
23
24 #ifndef _FSEC_PKCS_PKCS_05_SCHEMES_H_
25 #define _FSEC_PKCS_PKCS_05_SCHEMES_H_
26
27 #include <FBaseByteBuffer.h>
28 #include <FSecPkcsPkcs05PbKdf2Parameters.h>
29 #include <FSecPkcsPkcs05PbEs2Parameters.h>
30 #include <FSecPkcsPkcs05PbMacParameters.h>
31
32 namespace Tizen { namespace Security { namespace Pkcs
33 {
34
35 /**
36   * @class              Pkcs05Schemes
37   * @brief              This class implements the functionalities specified by the pkcs05 schemes like key derivation function,
38   *                                             encryption and signature schemes.
39   *
40   * @since              2.1
41   *
42   * The %Pkcs05Schemes class implements the functionalities specified by the pkcs05 schemes like key derivation function,
43   *                                             encryption and signature schemes.
44   */
45
46 class _OSP_EXPORT_ Pkcs05Schemes
47         : public Tizen::Base::Object
48 {
49 public:
50         /**
51          * The object is not fully constructed after this constructor is called. @n
52          * For full construction, the Construct() method must be called right after calling this constructor.
53          *
54          * @since       2.1
55          */
56         Pkcs05Schemes(void);
57
58         /**
59          * This destructor overrides Tizen::Base::Object::~Object().
60          *
61          * @since       2.1
62          */
63         virtual ~Pkcs05Schemes(void);
64
65         /**
66          * Initializes this instance of %Pkcs05Schemes with the values of the specified input parameters.
67          *
68          * @since               2.1
69          *
70          * @return              An error code
71          * @param[in]   password                                        An instance of Tizen::Base::ByteBuffer holding the password
72          * @param[in]   derivedKeyLength        A positive integer that contains the length of derived key @n
73          *                                                                                                                      It is a variable length in PbEs2 based on the underlying encryption operation.
74          * @exception   E_SUCCESS                                       The method is successful.
75          * @exception   E_INVALID_ARG                   The specified input parameter is invalid.
76          */
77         result Construct(const Tizen::Base::ByteBuffer& password, int derivedKeyLength);
78
79         /**
80          * Generates the password based derived key using the PBKDF2 scheme. @n
81          * The length of the derived key is essentially unbounded. However, the maximum effective search space for
82          * the derived key may be limited by the structure of the underlying pseudo random function.
83          *
84          * @since               2.1
85          *
86          * @return              A pointer to Tizen::Base::ByteBuffer that contains the derived key, @n
87          *                              else @c null if an error occurs
88          * @param[in]   params                                          An instance of PbKdf2Parameters containing the Kdf2 parameter,
89          *                                                                                                                      salt value, iteration count, and key length
90          * @exception   E_SUCCESS                                       The method is successful.
91          * @exception   E_INVALID_ARG                   The specified input parameter is invalid.
92          * @exception   E_SYSTEM                                        The method cannot proceed due to a severe system error.
93          * @remarks             The specific error code can be accessed using the GetLastResult() method.
94          */
95         Tizen::Base::ByteBuffer* GenerateKeyKdf2N(const Pkcs05PbKdf2Parameters& params);
96
97         /**
98          * Encrypts the message M under a password P to produce a ciphertext C, by applying selected key derivation function KDF
99          * (which is GenerateKeyKdf2N) and selected underlying encryption scheme (which can be any block chiper).
100          *
101          * @since               2.1
102          *
103          * @return              A pointer to Tizen::Base::ByteBuffer that contains the encrypted message, @n
104          *                              else @c null if an error occurs
105          * @param[in]   params                                          An instance of the PbEs2Parameters parameter structure holding AlgorithmIdentifier for key derivation
106          *                                                                                                                      function and AlgorithmIdentifier for underlying encryption scheme
107          * @param[in]   message                                         An instance of Tizen::Base::ByteBuffer holding the plain text to encrypt
108          * @exception   E_SUCCESS                                       The method is successful.
109          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
110          * @exception   E_SYSTEM                                        The method cannot proceed due to a severe system error.
111          * @remarks             The specific error code can be accessed using the GetLastResult() method.
112          */
113         Tizen::Base::ByteBuffer* EncryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message);
114
115         /**
116          * Decrypts the ciphertext C, 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).
118          *
119          * @since               2.1
120          *
121          * @return              A pointer to Tizen::Base::ByteBuffer that contains the plain text message
122          * @param[in]   params                                          An instance of the PbEs2Parameters parameter structure holding AlgorithmIdentifier for key derivation
123          *                                                                                                                      function and AlgorithmIdentifier for underlying encryption scheme
124          * @param[in]   message                                         An instance of Tizen::Base::ByteBuffer holding the cipher text to decrypt
125          * @exception   E_SUCCESS                                       The method is successful.
126          * @exception   E_INVALID_ARG                   A 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.
129          */
130         Tizen::Base::ByteBuffer* DecryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message);
131
132         /**
133          * Gets 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). @n 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.
139          *
140          * @since               2.1
141          *
142          * @return              A pointer to Tizen::Base::ByteBuffer containing the HMAC generated from message, @n
143          *                              else @c null if an error occurs
144          * @param[in]   params                                          An instance of the PbMacParameters parameter structure holding AlgorithmIdentifier for key derivation
145          *                                                                                                                      function and AlgorithmIdentifier for underlying encryption scheme
146          * @param[in]   message                                         An instance of Tizen::Base::ByteBuffer holding the message for which MAC needs to generate
147          * @exception   E_SUCCESS                                       The method is successful.
148          * @exception   E_INVALID_ARG                   A 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.
151          */
152         Tizen::Base::ByteBuffer* GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message);
153
154         /**
155          * Verifies 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). @n The key length and any other parameters
159          * for the underlying message authentication scheme depend on the scheme.
160          *
161          * @since               2.1
162          *
163          * @return              An error code
164          * @param[in]   params                                                  An instance of the PbMacParameters parameter structure holding AlgorithmIdentifier for key derivation
165          *                                                                                                                              function and AlgorithmIdentifier for underlying encryption scheme
166          * @param[in]   message                                                 An instance of Tizen::Base::ByteBuffer holding the message M
167          * @param[in]   mac                                                                     An instance of Tizen::Base::ByteBuffer holding the HMAC mac that needs to verify against the message
168          * @exception   E_SUCCESS                                               The method is successful.
169          * @exception   E_INVALID_ARG                           A 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.
172          */
173         result VerifyPbMac(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message, const Tizen::Base::ByteBuffer& mac);
174
175 private:
176         // This copy constructor is intentionally declared as private to prohibit @n
177         // copying of objects by users.
178         //
179         // @since               2.1
180         Pkcs05Schemes(const Pkcs05Schemes& rhs);
181
182         // The implementation of this copy assignment operator is intentionally blank and @n
183         // declared as private to prohibit copying of objects.
184         //
185         // @since               2.1
186         Pkcs05Schemes& operator =(const Pkcs05Schemes& rhs);
187
188 private:
189         class _Pkcs05SchemesImpl* __pPkcs05SchemesImpl;
190         friend class _Pkcs05SchemesImpl;
191
192 }; //Pkcs05Schemes
193
194 } } } // Tizen::Security::Pkcs
195
196 #endif //_FSEC_PKCS_PKCS_05_SCHEMES_H_