Revise Tizen::Io doxygen
[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 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. These are used in asymmetric ciphers. The generated key pair and parameters are based on the underlying key pair encryption algorithm. @n
40  *
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>.
42  *
43  *  @see Tizen::Security::IKeyPairGenerator
44  *  @see Tizen::Security::KeyPair
45  */
46 class _OSP_EXPORT_ KeyPairGenerator
47         : public virtual IKeyPairGenerator
48         , public Tizen::Base::Object
49 {
50
51 public:
52         /**
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.
55          *
56          * @since               2.0
57          */
58         KeyPairGenerator(void);
59
60         /**
61          * This destructor overrides Tizen::Base::Object::~Object().
62          *
63          * @since               2.0
64          */
65         virtual ~KeyPairGenerator(void);
66
67         /**
68          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
69          *
70          *      @since          2.0
71          *
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.
78          */
79         virtual result Construct(int modulusBitSize);
80
81         /**
82          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
83          *
84          * @since               2.0
85          *
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.
96          */
97         result Construct(int modulusBitSize, Tizen::Base::String algorithm);
98
99         /**
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.
106          *
107          *      @since                  2.0
108          *
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
115          *                                                      The size must be:
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.
124          */
125         Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
126
127         /**
128          *      Generates a new key pair.
129          *
130          *      @since          2.0
131          *
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.
141          */
142         Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
143
144         /**
145          *      Generates a new key pair.
146          *
147          *      @since          2.0
148          *
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.
157          */
158         virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
159
160 private:
161         //
162         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
163         //
164         // @since 2.0
165         //
166         KeyPairGenerator(const KeyPairGenerator& rhs);
167
168         //
169         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
170         //
171         // @since 2.0
172         //
173         KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
174
175 private:
176         Tizen::Base::String __algorithm;
177         int __modulusBitSize;
178
179         class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
180         friend class _KeyPairGeneratorImpl;
181
182 };     //KeyPairGenerator
183
184 } } //Tizen::Security
185
186 #endif // _FSEC_KEY_PAIR_GENERATOR_H_