Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FSecDhKeyParameters.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                FSecDhKeyParameters.h
19  * @brief               This is the header file for the %DhKeyParameters class.
20  *
21  * This header file contains the declarations of the %DhKeyParameters class.
22  */
23 #ifndef _FSEC_DH_KEY_PARAMETERS_H_
24 #define _FSEC_DH_KEY_PARAMETERS_H_
25
26 #include <FSecIKeyParameters.h>
27
28
29 namespace Tizen { namespace Security
30 {
31
32 /**
33  * @class               DhKeyParameters
34  * @brief               This class provides methods for retrieving the parameters for the Diffie-Hellman (DH) algorithm.
35  *
36  * @since               2.0
37  *
38  * The %DhKeyParameters class provides a subset of the domain parameters for the DH algorithm.
39  * For example, a prime number and a generator value are used to exchange keys between two parties. @n
40  *
41  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/key_exchange_algorithm.htm">Key exchanging</a>.
42  *
43  * @see IKeyParameters
44  *
45  * The following example demonstrates how to use the %DhKeyParameters class.
46  *
47  *  @code
48  *      void GetParameterExample(void)
49  *      {
50  *              result r = E_SUCCESS;
51  *              KeyPairGenerator *pKeyPairGen = null;
52  *              IKeyParameters *pKeyParams = null;
53  *
54  *              int size = 1024;
55  *              int nResult = 0;
56  *              ByteBuffer* pResult = null;
57  *
58  *              // Generates the key.
59  *              pKeyPairGen = new KeyPairGenerator();
60  *              if (null == pKeyPairGen)
61  *              {
62  *                      goto CATCH;
63  *              }
64  *
65  *              r = pKeyPairGen->Construct(size, L"DH");
66  *              if (IsFailed(r))
67  *              {
68  *                      goto CATCH;
69  *              }
70  *
71  *              pKeyParams = pKeyPairGen->GenerateKeyParametersN();
72  *              if (null == pKeyParams)
73  *              {
74  *                      goto CATCH;
75  *              }
76  *
77  *              pResult  = pKeyParams->GetParameterValueN(KEY_PARAMETER_DH_P);
78  *              if (null == pResult)
79  *              {
80  *                      goto CATCH;
81  *              }
82  *
83  *              nResult  = pKeyParams->GetParameterSize(KEY_PARAMETER_DH_PRIVATE_KEY_SIZE);
84  *
85  *      CATCH:
86  *              delete pKeyPairGen;
87  *              delete pResult;
88  *              delete pKeyParams;
89  *
90  *      }
91  * @endcode
92  */
93
94 class _OSP_EXPORT_ DhKeyParameters
95         : public IKeyParameters
96         , public Tizen::Base::Object
97 {
98
99 public:
100         /**
101          * The object is not fully constructed after this constructor is called. For full construction, @n
102          * the Construct() method must be called right after calling this constructor.
103          *
104          * @since               2.0
105          */
106         DhKeyParameters(void);
107
108         /**
109          * This destructor overrides Tizen::Base::Object::~Object().
110          *
111          * @since               2.0
112          */
113         virtual ~DhKeyParameters(void);
114
115         /**
116          * Constructs and initializes this instance of IKeyParameters with the specified key parameters.
117          *
118          * @since               2.0
119          *
120          * @return              An error code
121          * @param[in]   primeNumber                                     The prime number 'p' to instantiate
122          * @param[in]   generatorNumber                         The generator value 'g' to instantiate
123          * @param[in]   privateKeySize                          The size of the private key to instantiate
124          * @exception   E_SUCCESS                                       The method is successful.
125          * @exception   E_INVALID_ARG                           A specified input parameter is invalid.
126          * @exception   E_OUT_OF_MEMORY                         The memory is insufficient.
127          */
128         result Construct(const Tizen::Base::ByteBuffer& primeNumber, const Tizen::Base::ByteBuffer& generatorNumber, int privateKeySize);
129
130         /**
131          * Gets the value of domain parameters (in Tizen::Base::ByteBuffer format) for the specified key parameter type.
132          *
133          * @since               2.0
134          *
135          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the parameter values, @n
136          *                              else @c null if an error occurs
137          * @param[in]   paramType                                       The type of the parameter
138          * @exception   E_SUCCESS                                       The method is successful.
139          * @exception   E_OUT_OF_MEMORY                         The memory is insufficient.
140          * @exception   E_UNSUPPORTED_TYPE                      The specified @c paramType is not supported.
141          * @remarks             The specific error code can be accessed using the GetLastResult() method.
142          */
143         virtual Tizen::Base::ByteBuffer* GetParameterValueN(KeyParameterType paramType) const;
144
145         /**
146          * Gets the size of the private key component.
147          *
148          * @since                       2.0
149          *
150          * @return              The size of the private key component
151          * @param[in]   paramType                                       The type of the parameter
152          * @exception   E_SUCCESS                                       The method is successful.
153          * @exception   E_UNSUPPORTED_TYPE                      The specified @c paramType is not supported.
154          * @remarks             The specific error code can be accessed using the GetLastResult() method.
155          */
156         virtual int GetParameterSize(KeyParameterType paramType) const;
157
158 private:
159
160         //
161         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
162         //
163         // @since 2.0
164         //
165         DhKeyParameters(const DhKeyParameters& rhs);
166
167         //
168         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
169         //
170         // @since 2.0
171         //
172         DhKeyParameters& operator =(const DhKeyParameters& rhs);
173
174 private:
175         Tizen::Base::ByteBuffer __prime;
176         Tizen::Base::ByteBuffer __generator;
177         int __privateKeySize;
178
179         class _DhKeyParametersImpl* __pDhKeyParametersImpl;
180         friend class _DhKeyParametersImpl;
181
182 }; //DhKeyParameters
183
184 } } //Tizen::Security
185
186 #endif //_FSEC_DH_KEY_PARAMETERS_H_