2 // Copyright (c) 2012 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 FSecKeyPairGenerator.h
19 * @brief This is the header file for the %KeyPairGenerator class.
21 * This header file contains the declarations of the %KeyPairGenerator class.
23 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
24 #define _FSEC_KEY_PAIR_GENERATOR_H_
26 #include <FSecIKeyPairGenerator.h>
27 #include <FSecISecureRandom.h>
28 #include <FSecIKeyParameters.h>
30 namespace Tizen { namespace Security
34 * @class KeyPairGenerator
35 * @brief This class provides methods for generating a pair of public and private keys for the Public key algorithm.
39 * The %KeyPairGenerator class generates a key pair and its parameters that consists of a public and private key.
40 * These are used in asymmetric ciphers. The generated key pair and parameters are based on the underlying key pair
41 * encryption algorithm. @n
43 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/key_mgmt_and_csprng.htm">Key Management and CSPRNG</a>.
45 * @see Tizen::Security::IKeyPairGenerator
46 * @see Tizen::Security::KeyPair
48 class _OSP_EXPORT_ KeyPairGenerator
49 : public virtual IKeyPairGenerator
50 , public Tizen::Base::Object
55 * The object is not fully constructed after this constructor is called. For full construction, @n
56 * the Construct() method must be called right after calling this constructor.
60 KeyPairGenerator(void);
63 * This destructor overrides Tizen::Base::Object::~Object().
67 virtual ~KeyPairGenerator(void);
70 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
74 * @return An error code
75 * @param[in] modulusBitSize The modulus size in bits
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_INVALID_ARG The specified size is invalid. @n
78 * The modulus size must be at least greater than or equal to @c 1024 bits
79 * to generate cryptographically secure keys.
81 virtual result Construct(int modulusBitSize);
84 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
88 * @return An error code
89 * @param[in] modulusBitSize The modulus size in bits @n
90 * This is used for key generation.
91 * @param[in] algorithm The algorithm used to generate the key parameters @n
92 * The supported algorithms are RSA, DH, and KEA. The default value is RSA.
93 * @exception E_SUCCESS The method is successful.
94 * @exception E_INVALID_ARG The specified size is invalid. @n
95 * @exception E_UNSUPPORTED_ALGORITHM Either of the following conditions has occurred:
96 * - The requested @c algorithm is not supported.
97 * - The modulus size must be at least greater than or equal to @c 1024 bits
98 * to generate cryptographically secure keys.
100 result Construct(int modulusBitSize, Tizen::Base::String algorithm);
103 * Generates the key parameters based on the underlying key pair algorithm. @n
104 * For example, in case of the DH or KEA algorithm, this method generates key parameters based on the DSA
105 * algorithm (X186.3 specification).
106 * The supported algorithms are RSA, DH, and KEA.
107 * The generated key parameters may be required to create a key pair. The RSA algorithm
108 * does not call this method to generate a key pair.
112 * @return A pointer to the IKeyParameters instance that contains a subset of the domain parameters ('p' prime
113 * number, 'g' generator) that are used to generate the key pair, @n
114 * else @c null if the method fails to create the key parameters
115 * @param[in] lInBits The size of 'p', a prime number in bits @n
116 * The size must be @c 1024 bits, @c 2048 bits, or @c 3072 bits.
117 * @param[in] nInBits The size of 'g', a generator value in bits @n
119 * - 160 bits, when @c lInBits is @c 1024 bits.
120 * - 254 or 256 bits, when @c lInBits is @c 2048 bits.
121 * - 256 bits, when @c lInBits is @c 3072 bits.
122 * @exception E_SUCCESS The method is successful.
123 * @exception E_OUT_OF_MEMORY The memory is insufficient.
124 * @exception E_SYSTEM Either of the following conditions has occurred:
125 * - The method cannot proceed due to a severe system error.
126 * - The method has failed to operate with the OpenSSL library.
127 * - The Tizen::Base::ByteBuffer operation has failed.
128 * @remarks The specific error code can be accessed using the GetLastResult() method.
130 Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
133 * Generates a new key pair.
137 * @return A pointer to the KeyPair instance, @n
138 * else @c null if the method fails to create the key pair
139 * @param[in] pKeyParams The domain parameters of the key exchange algorithm @n
140 * These parameters are instantiated.
141 * @exception E_SUCCESS The method is successful.
142 * @exception E_OUT_OF_MEMORY The memory is insufficient.
143 * @exception E_SYSTEM Either of the following conditions has occurred:
144 * - The method cannot proceed due to a severe system error.
145 * - The method has failed to operate with the OpenSSL library.
146 * - The Tizen::Base::ByteBuffer operation has failed.
147 * @remarks The specific error code can be accessed using the GetLastResult() method.
149 Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
152 * Generates a new key pair.
156 * @return A pointer to the KeyPair instance, @n
157 * else @c null if the method fails to create the key pair. @n
158 * The default key format will be pkcs1 for private key and x509 for public key.
159 * @exception E_SUCCESS The method is successful.
160 * @exception E_OUT_OF_MEMORY The memory is insufficient.
161 * @exception E_SYSTEM Either of the following conditions has occurred:
162 * - The method cannot proceed due to a severe system error.
163 * - The method has failed to operate with the OpenSSL library.
164 * - The Tizen::Base::ByteBuffer operation has failed.
165 * @remarks The specific error code can be accessed using the GetLastResult() method.
167 virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
171 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
175 KeyPairGenerator(const KeyPairGenerator& rhs);
178 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
182 KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
185 Tizen::Base::String __algorithm;
186 int __modulusBitSize;
188 class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
189 friend class _KeyPairGeneratorImpl;
191 }; //KeyPairGenerator
193 } } //Tizen::Security
195 #endif // _FSEC_KEY_PAIR_GENERATOR_H_