Apply reviewed doxygen header
[platform/framework/native/appfw.git] / inc / FSecCryptoRsaSignature.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                FSecCryptoRsaSignature.h
19  * @brief               This is the header file for the %RsaSignature class.
20  *
21  * This header file contains the declarations of the %RsaSignature class.
22  */
23 #ifndef _FSEC_CRYPTO_RSA_SIGNATURE_H_
24 #define _FSEC_CRYPTO_RSA_SIGNATURE_H_
25
26 #include <FSecCryptoISignature.h>
27 #include <FBase.h>
28
29
30 namespace Tizen { namespace Security { namespace Crypto
31 {
32
33 /**
34  *      @class          RsaSignature
35  *      @brief          This class implements the Rivest Shamir Adleman (RSA) signatures.
36  *
37  *      @since          2.0
38  *
39  *      The %RsaSignature class implements the Rivest Shamir Adleman (RSA) signatures. @n
40  *
41  *      For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
42  *
43  *      @see ISignature
44  *      @see IKeyPairGenerator
45  *      @see KeyPair
46  *      @see IPublicKey
47  *      @see IPrivateKey
48  *      @see PublicKey
49  *      @see PrivateKey
50  */
51 class _OSP_EXPORT_ RsaSignature
52         : public virtual ISignature
53         , public Tizen::Base::Object
54 {
55
56 public:
57         /**
58          *      This is the default constructor for this class.
59          *
60          *      @since          2.0
61          */
62         RsaSignature(void);
63
64         /**
65          *      This destructor overrides Tizen::Base::Object::~Object().
66          *
67          *      @since          2.0
68          */
69         virtual ~RsaSignature(void);
70
71         /**
72          *      Sets the asymmetric private key for signature.
73          *
74          *      @since          2.0
75          *
76          *      @return         An error code
77          *      @param[in]      key                                                     An instance of IKey
78          *                                                                                      The key can be in PEM/DER/PKCS8 format only.
79          *      @exception      E_SUCCESS                                       The method is successful.
80          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
81          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
82          */
83         virtual result SetPrivateKey(const Tizen::Security::IKey& key);
84
85         /**
86          *      Sets the asymmetric public key for verification.
87          *
88          *      @since          2.0
89          *
90          *      @return         An error code
91          *      @param[in]      key                                                     An instance of IKey
92          *                                                                                      The key can be in PEM/DER/X509 public key format only.
93          *      @exception      E_SUCCESS                                       The method is successful.
94          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
95          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
96          */
97         virtual result SetPublicKey(const Tizen::Security::IKey& key);
98
99         /**
100          *      Signs the data. @n
101          *      The %SignN() method only supports sha1withRsa for signing the data
102          *      @since          2.0
103          *
104          *      @return         A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
105          *                              else @c null if an error occurs
106          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
107          *      @exception      E_SUCCESS                                       The method is successful.
108          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
109          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
110          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
111          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
112          *                                                                                      - A system error has occurred.                                                                  
113          *                                                                                      - The method has failed to operate with the OpenSSL library.
114          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
115          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
116          */
117         virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input);
118
119         /**
120          *      Signs the data. @n
121          *      The %SignN() method provides the additional option for setting the digest algorithm that is needed for signing the data
122          *
123          *      @since          2.0
124          *
125          *      @return         A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
126          *                              else @c null if an error occurs
127          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
128          *      @param[in]      algorithm                                       The Tizen::Base::String instance that contains the digest algorithm. @n
129          *                                                                                      The valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
130          *      @exception      E_SUCCESS                                       The method is successful.
131          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
132          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
133          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
134          *      @exception      E_UNSUPPORTED_ALGORITHM         The specified algorithm is not supported.
135          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
136          *                                                                                      - A system error has occurred.                                                                          
137          *                                                                                      - The method has failed to operate with the OpenSSL library.
138          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
139          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
140          */
141         Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input, const Tizen::Base::String& algorithm);
142
143         /**
144          *      Verifies the data. @n
145          *      The verification is done by comparing the @c signedData to the signature created by the @c data. @
146          *      The %Verify() method only supports sha1withRsa for verifying the signed data
147          *
148          *      @since          2.0
149          *
150          *      @return         @c true if the signed data is correct, @n
151          *                              else @c false
152          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
153          *      @param[in]      signedData                                      An instance of Tizen::Base::ByteBuffer that contains the signed data
154          *      @exception      E_SUCCESS                                       The method is successful.
155          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
156          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
157          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
158          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
159          *                                                                                      - A system error has occurred.                                                                  
160          *                                                                                      - The method has failed to operate with the OpenSSL library.
161          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
162          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
163          */
164         virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
165
166         /**
167          *      Verifies the data. @n
168          *      The verification is done by comparing the @c signedData to the signature created by the @c data. @n
169          *      The %Verify() method provides the additional option for setting the digest algorithm that is needed for verifying the signed data
170          *
171          *      @since          2.0
172          *
173          *      @return         @c true if the signed data is correct, @n
174          *                              else @c false
175          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
176          *      @param[in]      signedData                                      An instance of Tizen::Base::ByteBuffer that contains the signed data
177          *      @param[in]      algorithm                                       The Tizen::Base::String instance that contains the digest algorithm. @n
178          *                                                                                      The valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
179          *      @exception      E_SUCCESS                                       The method is successful.
180          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
181          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
182          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
183          *      @exception      E_UNSUPPORTED_ALGORITHM         The specified algorithm is not supported.
184          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
185          *                                                                                      - A system error has occurred.                                                                          
186          *                                                                                      - The method has failed to operate with the OpenSSL library.
187          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
188          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
189          */
190         bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData, const Tizen::Base::String& algorithm);
191
192 private:
193
194         //
195         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
196         //
197         // @since 2.0
198         //
199         RsaSignature(const RsaSignature& rhs);
200
201         //
202         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
203         //
204         // @since 2.0
205         //
206         RsaSignature& operator =(const RsaSignature& rhs);
207
208 private:
209         Tizen::Base::ByteBuffer __privateKey;
210         Tizen::Base::ByteBuffer __publicKey;
211
212         class _RsaSignatureImpl* __pRsaSignatureImpl;
213         friend class _RsaSignatureImpl;
214
215 }; //RsaSignature
216
217 } } } //Tizen::Security::Crypto
218
219 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_