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 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. These are used in asymmetric ciphers. The generated key pair and parameters are based on the underlying key pair encryption algorithm. @n
41 * 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>.
43 * @see Tizen::Security::IKeyPairGenerator
44 * @see Tizen::Security::KeyPair
46 class _OSP_EXPORT_ KeyPairGenerator
47 : public virtual IKeyPairGenerator
48 , public Tizen::Base::Object
53 * The object is not fully constructed after this constructor is called. For full construction, @n
54 * the Construct() method must be called right after calling this constructor.
58 KeyPairGenerator(void);
61 * This destructor overrides Tizen::Base::Object::~Object().
65 virtual ~KeyPairGenerator(void);
68 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
72 * @return An error code
73 * @param[in] modulusBitSize The modulus size in bits
74 * @exception E_SUCCESS The method is successful.
75 * @exception E_INVALID_ARG The specified size is invalid. @n
76 * The modulus size must be at least greater than or equal to @c 1024 bits @n
77 * to generate cryptographically secure keys.
79 virtual result Construct(int modulusBitSize);
82 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
86 * @return An error code
87 * @param[in] modulusBitSize The modulus size in bits @n
88 * This is used for key generation.
89 * @param[in] algorithm The algorithm used to generate the key parameters @n
90 * The supported algorithms are RSA, DH, and KEA. The default value is RSA.
91 * @exception E_SUCCESS The method is successful.
92 * @exception E_INVALID_ARG The specified size is invalid. @n
93 * @exception E_UNSUPPORTED_ALGORITHM The requested @c algorithm is not supported. @n
94 * The modulus size must be at least greater than or equal to @c 1024 bits @n
95 * to generate cryptographically secure keys.
97 result Construct(int modulusBitSize, Tizen::Base::String algorithm);
100 * Generates the key parameters based on the underlying key pair algorithm. @n
101 * For example, in case of the DH or KEA algorithm, this method generates key parameters based on the DSA
102 * algorithm (X186.3 specification).
103 * The supported algorithms are RSA, DH, and KEA.
104 * The generated key parameters may be required to create a key pair. The RSA algorithm
105 * does not call this method to generate a key pair.
109 * @return A pointer to the IKeyParameters class that contains a subset of the domain parameters ('p' prime
110 * number, 'g' generator) that are used to generate a key pair, @n
111 * else @c null if the method fails to create the key parameters
112 * @param[in] lInBits The size of 'p', a prime number in bits @n
113 * The size must be @c 1024 bits, @c 2048 bits, or @c 3072 bits.
114 * @param[in] nInBits The size of 'g', a generator value in bits @n
116 * - 160 bits, when @c lInBits is @c 1024 bits.
117 * - 254 or 256 bits, when @c lInBits is @c 2048 bits.
118 * - 256 bits, when @c lInBits is @c 3072 bits.
119 * @exception E_SUCCESS The method is successful.
120 * @exception E_OUT_OF_MEMORY The memory is insufficient.
121 * @exception E_SYSTEM The method cannot proceed due to a severe system error. @n
122 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
123 * @remarks The specific error code can be accessed using the GetLastResult() method.
125 Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
128 * Generates a new key pair.
132 * @return A pointer to the KeyPair class, @n
133 * else @c null if the method fails to create the key pair
134 * @param[in] pKeyParams The domain parameters of the key exchange algorithm @n
135 * These parameters are instantiated.
136 * @exception E_SUCCESS The method is successful.
137 * @exception E_OUT_OF_MEMORY The memory is insufficient.
138 * @exception E_SYSTEM The method cannot proceed due to a severe system error. @n
139 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
140 * @remarks The specific error code can be accessed using the GetLastResult() method.
142 Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
145 * Generates a new key pair.
149 * @return A pointer to the KeyPair class, @n
150 else @c null if the method fails to create the key pair.
151 * Default key format will be pkcs1 for private key and x509 for public key.
152 * @exception E_SUCCESS The method is successful.
153 * @exception E_OUT_OF_MEMORY The memory is insufficient.
154 * @exception E_SYSTEM The method cannot proceed due to a severe system error. @n
155 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
156 * @remarks The specific error code can be accessed using the GetLastResult() method.
158 virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
162 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
166 KeyPairGenerator(const KeyPairGenerator& rhs);
169 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
173 KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
176 Tizen::Base::String __algorithm;
177 int __modulusBitSize;
179 class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
180 friend class _KeyPairGeneratorImpl;
182 }; //KeyPairGenerator
184 } } //Tizen::Security
186 #endif // _FSEC_KEY_PAIR_GENERATOR_H_