sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FSecKeyPairGenerator.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                        FSecKeyPairGenerator.h
20  * @brief               This is the header file for the %KeyPairGenerator class.
21  *
22  * This header file contains the declarations of the %KeyPairGenerator class.
23  */
24 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
25 #define _FSEC_KEY_PAIR_GENERATOR_H_
26
27 #include <FSecIKeyPairGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecIKeyParameters.h>
30
31
32 namespace Tizen { namespace Security
33 {
34
35 /**
36  *  @class              KeyPairGenerator
37  *  @brief              This class provides a pair of public and private keys for the Public key algorithm.
38  *
39  *  @since  2.0
40  *
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
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 @n
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 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.
98          */
99         result Construct(int modulusBitSize, const Tizen::Base::String algorithm);
100
101         /**
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.
108         *
109         *       @since                  2.0
110         *
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
117         *                                                       The size must be:
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.
127         */
128         Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
129
130         /**
131          *      Generates a new key pair.
132          *
133          *      @since          2.0
134          *
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.
145          */
146         Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
147
148         /**
149          *      Generates a new key pair.
150          *
151          *      @since          2.0
152          *
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.
161          */
162         virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
163
164 private:
165
166         //
167         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
168         //
169         // @since 2.0
170         //
171         KeyPairGenerator(const KeyPairGenerator& rhs);
172
173         //
174         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
175         //
176         // @since 2.0
177         //
178         KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
179
180 private:
181         Tizen::Base::String __algorithm;
182         int __modulusBitSize;
183
184         class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
185         friend class _KeyPairGeneratorImpl;
186
187 }; //KeyPairGenerator
188
189 } } //Tizen::Security
190
191 #endif // _FSEC_KEY_PAIR_GENERATOR_H_