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