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 FSecPkcsPkcs05PbKdf2Parameters.h
20 * @brief This is the header file for the %Pkcs05PbKdf2Parameters class.
22 * This header file contains the declarations of the %Pkcs05PbKdf2Parameters class.
25 #ifndef _FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_
26 #define _FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_
28 #include <FBaseByteBuffer.h>
29 #include <FSecPkcsIAlgorithmParameters.h>
30 #include <FSecPkcsAlgorithmIdentifier.h>
31 #include <FSecPkcsTypes.h>
33 namespace Tizen { namespace Security { namespace Pkcs
37 * @class Pkcs05PbKdf2Parameters
38 * @brief This class implements the functionalities specified by the PKCS05 KDF2 scheme.
42 * The %Pkcs05PbKdf2Parameters class implements the functionalities specified by the PKCS05 KDF2 scheme. PBKDF2 applies a pseudo random function to derive
43 * keys. The length of the derived key is essentially unbounded. However, the maximum effective search space for the derived key can
44 * be limited by the structure of the underlying pseudo random function.
46 * This is defined in ASN.1 as demonstrated in the following code:
48 * PBKDF2-params ::= SEQUENCE {
50 * specified OCTET STRING,
51 * otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
53 * iterationCount INTEGER (1..MAX),
54 * keyLength INTEGER (1..MAX) OPTIONAL,
55 * prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
56 * algid-hmacWithSHA1 }
61 class _OSP_EXPORT_ Pkcs05PbKdf2Parameters
62 : public virtual IAlgorithmParameters
63 , public Tizen::Base::Object
68 * The object is not fully constructed after this constructor is called. @n
69 * For full construction, the Construct() method must be called right after calling this constructor.
73 Pkcs05PbKdf2Parameters(void);
76 * This destructor overrides Tizen::Base::Object::~Object().
80 virtual ~Pkcs05PbKdf2Parameters(void);
83 * Initializes this instance of %Pkcs05PbKdf2Parameters with the encoded Tizen::Base::Bytebuffer that contains Password Based Key Derivation Function parameters structure(PBKDF2) in ASN.1 DER format.
87 * @return An error code
88 * @param[in] encodedData DER encoded Tizen::Base::ByteBuffer of %Pkcs05PbKdf2Parameters
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_INVALID_ARG The specified input parameter is invalid.
92 result Construct(const Tizen::Base::ByteBuffer& encodedData);
95 * Initializes the %Pkcs05PbKdf2Parameters with specified input parameters values.
99 * @return An error code
100 * @param[in] saltBuffer An instance of Tizen::Base::ByteBuffer, holding salt value
101 * @param[in] iterationCount Integer value holding the positive integer specifying iteration count
102 * for generation of password based key
103 * @param[in] derivedKeyLength Positive integer specifying length of password based key to generate
104 * @exception E_SUCCESS The method is successful.
105 * @exception E_INVALID_ARG The specified input parameter is invalid.
106 * @remark In this case, when pseudo random function algorithm is not passed, then default HMAC-SHA1 will be used.
108 result Construct(const Tizen::Base::ByteBuffer& saltBuffer, int iterationCount, int derivedKeyLength = 0);
111 * Initializes this %Pkcs05PbKdf2Parameters with supplied input parameters values.
115 * @return An error code
116 * @param[in] saltBuffer An instance of Tizen::Base::ByteBuffer, holding salt value
117 * @param[in] iterationCount Integer value holding the positive integer specifying iteration count
118 * for generation of password based key
119 * @param[in] prf An instance of AlgorithIdentifier, holding the underlying pseudo random function to use to generate a password based key
120 * @param[in] derivedKeyLength Positive integer specifying length of password based key to generate
121 * @exception E_SUCCESS The method is successful.
122 * @exception E_INVALID_ARG The specified input parameter is invalid.
124 result Construct(const Tizen::Base::ByteBuffer& saltBuffer, int iterationCount, const AlgorithmIdentifier& prf, int derivedKeyLength = 0);
127 * Gets the encoded form of the %Pkcs05PbKdf2Parameters. @n
128 * It is assumed that each %Pkcs05PbKdf2Parameters will have only a single form of encoding, for example: ASN.1 DER.
132 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
133 * else @c null if an error occurs
134 * @exception E_SUCCESS The method is successful.
135 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
136 * @remarks The specific error code can be accessed using the GetLastResult() method.
138 Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
141 * Gets the salt byte buffer.
145 * @return A reference to salt Tizen::Base::ByteBuffer containing the specified salt value
146 * @remarks The specific error code can be accessed using the GetLastResult() method.
148 const Tizen::Base::ByteBuffer& GetSaltValue(void) const;
151 * Gets the iteration count. @n
152 * The purpose of this count is to increase the cost of producing keys from a password, thereby, also increasing the difficulty of attack.
156 * @return An integer value containing the iteration count for PBKDF2
159 int GetIterationCount(void) const;
162 * Gets the derived key length. @n
163 * The %GetDerivedKeyLength() method returns the length of the derived key that is used to generate the password based key.
167 * @return An integer value containing the length of the derived key
170 int GetDerivedKeyLength(void) const;
173 * Gets the reference to the AlgorithmIdentifier that identifies the underlying pseudo random function.
177 * @return A reference to AlgorithmIdentifier containing the algorithm identifier of underlying pseudo random function
178 * @remarks The specific error code can be accessed using the GetLastResult() method.
180 const AlgorithmIdentifier& GetPrf(void) const;
184 * Gets the pointer to the AlgorithmParameters that identifies the underlying parameters such as PbKdf2,PbEs2,PbMac1. @n
185 * For this class %AlgorithmParameters will be of PbKdf2 type.
189 * @return Pointer to IAlgorithmParameters containing the algorithm identifier of underlying pseudo random function, @n
190 * else @c null if an error occurs
191 * @remarks The specific error code can be accessed using the GetLastResult() method.
193 virtual IAlgorithmParameters* CloneN(void) const;
196 * Gets the PkcsAlgorithmParameterType value.
200 * @return PkcsAlgorithmParameterType holding enum value @c PKCS_ALGO_PARAM_TYPE_PKCS05_KDF02 for KDF2 Parameters
202 virtual PkcsAlgorithmParameterType GetType(void) const;
205 * Checks whether the specified instance of %Pkcs05PbKdf2Parameters equals the current instance.
209 * @return @c true if the specified instance equals the current instance, @n
211 * @param[in] rhs An instance of %Pkcs05PbKdf2Parameters
212 * @exception E_SUCCESS The method is successful.
213 * @exception E_INVALID_ARG The specified input parameter is invalid.
214 * @remarks The specific error code can be accessed using the GetLastResult() method.
216 virtual bool Equals(const Tizen::Base::Object& rhs) const;
219 * Gets the hash value of the current instance of %Pkcs05PbKdf2Parameters.
223 * @return An integer value indicating the hash value of the current instance of %Pkcs05PbKdf2Parameters
225 virtual int GetHashCode(void) const;
228 // This copy constructor is intentionally declared as private to prohibit @n
229 // copying of objects by users.
232 Pkcs05PbKdf2Parameters(const Pkcs05PbKdf2Parameters& rhs);
234 // The implementation of this copy assignment operator is intentionally blank and @n
235 // declared as private to prohibit copying of objects.Use CloneN() to get an exact copy of the instance. @n
236 // Use Equals() to compare the contents of one instance with the other.
239 Pkcs05PbKdf2Parameters& operator =(const Pkcs05PbKdf2Parameters& rhs);
242 class _Pkcs05PbKdf2ParametersImpl* __pPkcs05PbKdf2ParametersImpl;
243 friend class _Pkcs05PbKdf2ParametersImpl;
244 }; // Pkcs05PbKdf2Parameters
246 } } } // Tizen::Security::Pkcs
248 #endif //_FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_