fixed Doxygen warning
[platform/framework/native/appfw.git] / inc / FSecKeyPairGenerator.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                        FSecKeyPairGenerator.h
19  * @brief               This is the header file for the %KeyPairGenerator class.
20  *
21  * This header file contains the declarations of the %KeyPairGenerator class.
22  */
23 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
24 #define _FSEC_KEY_PAIR_GENERATOR_H_
25
26 #include <FSecIKeyPairGenerator.h>
27 #include <FSecISecureRandom.h>
28 #include <FSecIKeyParameters.h>
29
30 namespace Tizen { namespace Security
31 {
32
33 /**
34  *      @class          KeyPairGenerator
35  *      @brief          This class provides methods for generating a pair of public and private keys for the Public key algorithm.
36  *
37  *      @since          2.0
38  *
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
42  *
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>.
44  *
45  *      @see Tizen::Security::IKeyPairGenerator
46  *      @see Tizen::Security::KeyPair
47  */
48 class _OSP_EXPORT_ KeyPairGenerator
49         : public virtual IKeyPairGenerator
50         , public Tizen::Base::Object
51 {
52
53 public:
54         /**
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.
57          *
58          *      @since          2.0
59          */
60         KeyPairGenerator(void);
61
62         /**
63          *      This destructor overrides Tizen::Base::Object::~Object().
64          *
65          *      @since          2.0
66          */
67         virtual ~KeyPairGenerator(void);
68
69         /**
70          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
71          *
72          *      @since          2.0
73          *
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.
80          */
81         virtual result Construct(int modulusBitSize);
82
83         /**
84          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
85          *
86          *      @since          2.0
87          *
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.
99          */
100         result Construct(int modulusBitSize, Tizen::Base::String algorithm);
101
102         /**
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.
109          *
110          *      @since          2.0
111          *
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
118          *                                                      The size must be:
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.
129          */
130         Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
131
132         /**
133          *      Generates a new key pair.
134          *
135          *      @since          2.0
136          *
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.
148          */
149         Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
150
151         /**
152          *      Generates a new key pair.
153          *
154          *      @since          2.0
155          *
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.
166          */
167         virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
168
169 private:
170         //
171         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
172         //
173         // @since 2.0
174         //
175         KeyPairGenerator(const KeyPairGenerator& rhs);
176
177         //
178         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
179         //
180         // @since 2.0
181         //
182         KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
183
184 private:
185         Tizen::Base::String __algorithm;
186         int __modulusBitSize;
187
188         class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
189         friend class _KeyPairGeneratorImpl;
190
191 }; //KeyPairGenerator
192
193 } } //Tizen::Security
194
195 #endif // _FSEC_KEY_PAIR_GENERATOR_H_