2 // Open Service Platform
3 // Copyright (c) 2012 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 FSecKeyPairGenerator.h
20 * @brief This is the header file for the %KeyPairGenerator class.
22 * This header file contains the declarations of the %KeyPairGenerator class.
24 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
25 #define _FSEC_KEY_PAIR_GENERATOR_H_
27 #include <FSecIKeyPairGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecIKeyParameters.h>
32 namespace Tizen { namespace Security
36 * @class KeyPairGenerator
37 * @brief This class provides a pair of public and private keys for the Public key algorithm.
41 * 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
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 @n
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 The requested @c algorithm is not supported. @n
96 * The modulus size must be at least greater than or equal to @c 1024 bits @n
97 * to generate cryptographically secure keys.
99 result Construct(int modulusBitSize, const Tizen::Base::String algorithm);
102 * Generates the key parameters based on the underlying key pair algorithm. @n
103 * For example, in case of the DH or KEA algorithm, this method generates key parameters based on the DSA
104 * algorithm (X186.3 specification).
105 * The supported algorithms are RSA, DH, and KEA.
106 * The generated key parameters may be required to create a key pair. The RSA algorithm
107 * does not call this method to generate a key pair.
111 * @return A pointer to the IKeyParameters class that contains a subset of the domain parameters ('p' prime
112 * number, 'g' generator) that are used to generate a key pair, @n
113 * else @c null if the method fails to create the key parameters
114 * @param[in] lInBits The size of 'p', a prime number in bits @n
115 * The size must be @c 1024 bits, @c 2048 bits, or @c 3072 bits.
116 * @param[in] nInBits The size of 'g', a generator value in bits @n
118 * - 160 bits, when @c lInBits is @c 1024 bits.
119 * - 254 or 256 bits, when @c lInBits is @c 2048 bits.
120 * - 256 bits, when @c lInBits is @c 3072 bits.
121 * @exception E_SUCCESS The method is successful.
122 * @exception E_UNSUPPORTED_ALGORITHM The requested algorithm is not supported.
123 * @exception E_OUT_OF_MEMORY The memory is insufficient.
124 * @exception E_SYSTEM A system error has occurred. @n
125 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
126 * @remarks The specific error code can be accessed using the GetLastResult() method.
128 Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
131 * Generates a new key pair.
135 * @return A pointer to the KeyPair class, @n
136 * else @c null if the method fails to create the key pair
137 * @param[in] pKeyParams The domain parameters of the key exchange algorithm @n
138 * These parameters are instantiated.
139 * @exception E_SUCCESS The method is successful.
140 * @exception E_UNSUPPORTED_ALGORITHM The requested algorithm is not supported.
141 * @exception E_OUT_OF_MEMORY The memory is insufficient.
142 * @exception E_SYSTEM A system error has occurred. @n
143 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
144 * @remarks The specific error code can be accessed using the GetLastResult() method.
146 Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
149 * Generates a new key pair.
153 * @return A pointer to the KeyPair class, @n
154 else @c null if the method fails to create the key pair
155 * @exception E_SUCCESS The method is successful.
156 * @exception E_UNSUPPORTED_ALGORITHM The requested algorithm is not supported.
157 * @exception E_OUT_OF_MEMORY The memory is insufficient.
158 * @exception E_SYSTEM A system error has occurred. @n
159 * The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
160 * @remarks The specific error code can be accessed using the GetLastResult() method.
162 virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
167 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
171 KeyPairGenerator(const KeyPairGenerator& rhs);
174 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
178 KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
181 Tizen::Base::String __algorithm;
182 int __modulusBitSize;
184 class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
185 friend class _KeyPairGeneratorImpl;
187 }; //KeyPairGenerator
189 } } //Tizen::Security
191 #endif // _FSEC_KEY_PAIR_GENERATOR_H_