2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSecPkcsPkcs05PbKdf2Parameters.h
19 * @brief This is the header file for the %Pkcs05PbKdf2Parameters class.
21 * This header file contains the declarations of the %Pkcs05PbKdf2Parameters class.
24 #ifndef _FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_
25 #define _FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_
27 #include <FBaseByteBuffer.h>
28 #include <FSecPkcsIAlgorithmParameters.h>
29 #include <FSecPkcsAlgorithmIdentifier.h>
30 #include <FSecPkcsTypes.h>
32 namespace Tizen { namespace Security { namespace Pkcs
36 * @class Pkcs05PbKdf2Parameters
37 * @brief This class implements the functionalities specified by the PKCS05 KDF2 scheme.
41 * The %Pkcs05PbKdf2Parameters class implements the functionalities specified by the PKCS05 KDF2 scheme. PBKDF2 applies a pseudo random function to derive
42 * keys. The length of the derived key is essentially unbounded. However, the maximum effective search space for the derived key can
43 * be limited by the structure of the underlying pseudo random function.
45 * This is defined in ASN.1 as demonstrated in the following code:
47 * PBKDF2-params ::= SEQUENCE {
49 * specified OCTET STRING,
50 * otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
52 * iterationCount INTEGER (1..MAX),
53 * keyLength INTEGER (1..MAX) OPTIONAL,
54 * prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
55 * algid-hmacWithSHA1 }
60 class _OSP_EXPORT_ Pkcs05PbKdf2Parameters
61 : public virtual IAlgorithmParameters
62 , public Tizen::Base::Object
67 * The object is not fully constructed after this constructor is called. @n
68 * For full construction, the Construct() method must be called right after calling this constructor.
72 Pkcs05PbKdf2Parameters(void);
75 * This destructor overrides Tizen::Base::Object::~Object().
79 virtual ~Pkcs05PbKdf2Parameters(void);
82 * 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.
86 * @return An error code
87 * @param[in] encodedData DER encoded Tizen::Base::ByteBuffer of %Pkcs05PbKdf2Parameters
88 * @exception E_SUCCESS The method is successful.
89 * @exception E_INVALID_ARG The specified input parameter is invalid.
91 result Construct(const Tizen::Base::ByteBuffer& encodedData);
94 * Initializes the %Pkcs05PbKdf2Parameters with specified input parameters values.
98 * @return An error code
99 * @param[in] saltBuffer An instance of Tizen::Base::ByteBuffer, holding salt value
100 * @param[in] iterationCount Integer value holding the positive integer specifying iteration count
101 * for generation of password based key
102 * @param[in] derivedKeyLength Positive integer specifying length of password based key to generate
103 * @exception E_SUCCESS The method is successful.
104 * @exception E_INVALID_ARG The specified input parameter is invalid.
105 * @remark In this case, when pseudo random function algorithm is not passed, then default HMAC-SHA1 will be used.
107 result Construct(const Tizen::Base::ByteBuffer& saltBuffer, int iterationCount, int derivedKeyLength = 0);
110 * Initializes this %Pkcs05PbKdf2Parameters with supplied input parameters values.
114 * @return An error code
115 * @param[in] saltBuffer An instance of Tizen::Base::ByteBuffer, holding salt value
116 * @param[in] iterationCount Integer value holding the positive integer specifying iteration count
117 * for generation of password based key
118 * @param[in] prf An instance of AlgorithIdentifier, holding the underlying pseudo random function to use to generate a password based key
119 * @param[in] derivedKeyLength Positive integer specifying length of password based key to generate
120 * @exception E_SUCCESS The method is successful.
121 * @exception E_INVALID_ARG The specified input parameter is invalid.
123 result Construct(const Tizen::Base::ByteBuffer& saltBuffer, int iterationCount, const AlgorithmIdentifier& prf, int derivedKeyLength = 0);
126 * Gets the encoded form of the %Pkcs05PbKdf2Parameters. @n
127 * It is assumed that each %Pkcs05PbKdf2Parameters will have only a single form of encoding, for example: ASN.1 DER.
131 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
132 * else @c null if an error occurs
133 * @exception E_SUCCESS The method is successful.
134 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
135 * @remarks The specific error code can be accessed using the GetLastResult() method.
137 Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
140 * Gets the salt byte buffer.
144 * @return A reference to salt Tizen::Base::ByteBuffer containing the specified salt value
145 * @remarks The specific error code can be accessed using the GetLastResult() method.
147 const Tizen::Base::ByteBuffer& GetSaltValue(void) const;
150 * Gets the iteration count. @n
151 * The purpose of this count is to increase the cost of producing keys from a password, thereby, also increasing the difficulty of attack.
155 * @return An integer value containing the iteration count for PBKDF2
158 int GetIterationCount(void) const;
161 * Gets the derived key length. @n
162 * The %GetDerivedKeyLength() method returns the length of the derived key that is used to generate the password based key.
166 * @return An integer value containing the length of the derived key
169 int GetDerivedKeyLength(void) const;
172 * Gets the reference to the AlgorithmIdentifier that identifies the underlying pseudo random function.
176 * @return A reference to AlgorithmIdentifier containing the algorithm identifier of underlying pseudo random function
177 * @remarks The specific error code can be accessed using the GetLastResult() method.
179 const AlgorithmIdentifier& GetPrf(void) const;
183 * Gets the pointer to the AlgorithmParameters that identifies the underlying parameters such as PbKdf2,PbEs2,PbMac1. @n
184 * For this class %AlgorithmParameters will be of PbKdf2 type.
188 * @return Pointer to IAlgorithmParameters containing the algorithm identifier of underlying pseudo random function, @n
189 * else @c null if an error occurs
190 * @remarks The specific error code can be accessed using the GetLastResult() method.
192 virtual IAlgorithmParameters* CloneN(void) const;
195 * Gets the PkcsAlgorithmParameterType value.
199 * @return PkcsAlgorithmParameterType holding enum value @c PKCS_ALGO_PARAM_TYPE_PKCS05_KDF02 for KDF2 Parameters
201 virtual PkcsAlgorithmParameterType GetType(void) const;
204 * Checks whether the specified instance of %Pkcs05PbKdf2Parameters equals the current instance.
208 * @return @c true if the specified instance equals the current instance, @n
210 * @param[in] rhs An instance of %Pkcs05PbKdf2Parameters
211 * @exception E_SUCCESS The method is successful.
212 * @exception E_INVALID_ARG The specified input parameter is invalid.
213 * @remarks The specific error code can be accessed using the GetLastResult() method.
215 virtual bool Equals(const Tizen::Base::Object& rhs) const;
218 * Gets the hash value of the current instance of %Pkcs05PbKdf2Parameters.
222 * @return An integer value indicating the hash value of the current instance of %Pkcs05PbKdf2Parameters
224 virtual int GetHashCode(void) const;
227 // This copy constructor is intentionally declared as private to prohibit @n
228 // copying of objects by users.
231 Pkcs05PbKdf2Parameters(const Pkcs05PbKdf2Parameters& rhs);
233 // The implementation of this copy assignment operator is intentionally blank and @n
234 // declared as private to prohibit copying of objects.Use CloneN() to get an exact copy of the instance. @n
235 // Use Equals() to compare the contents of one instance with the other.
238 Pkcs05PbKdf2Parameters& operator =(const Pkcs05PbKdf2Parameters& rhs);
241 class _Pkcs05PbKdf2ParametersImpl* __pPkcs05PbKdf2ParametersImpl;
242 friend class _Pkcs05PbKdf2ParametersImpl;
243 }; // Pkcs05PbKdf2Parameters
245 } } } // Tizen::Security::Pkcs
247 #endif //_FSEC_PKCS_PKCS_05_PBKDF2_PARAMETERS_H_