2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSecCryptoISignature.h
20 * @brief This is the header file for the %ISignature interface.
22 * This header file contains the declarations of the %ISignature interface.
24 #ifndef _FSEC_CRYPTO_ISIGNATURE_H_
25 #define _FSEC_CRYPTO_ISIGNATURE_H_
27 #include <FBaseString.h>
28 #include <FBaseByteBuffer.h>
31 namespace Tizen { namespace Security { namespace Crypto
35 * @interface ISignature
36 * @brief This interface provides the functionality of a digital signature algorithm.
40 * The %ISignature interface provides the functionality of a digital signature algorithm. @n
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>. @n
44 * The following example demonstrates how to use the %ISignature interface.
49 * MyClass::TestSignatureSample(void)
51 * result r = E_FAILURE;
52 * ISignature *pSignature = null;
53 * IKeyPairGenerator *pKeyPairGen = null;
54 * KeyPair *pKeyPair = null;
55 * IPrivateKey *pPriKey = null;
56 * IPublicKey *pPubKey = null;
58 * ByteBuffer *pOutput = null;
59 * ByteBuffer keyBytes;
61 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
65 * r = input.Construct(16);
66 * r = input.SetArray(pArray, 0, 16);
69 * pSignature = new RsaSignature();
70 * if (pSignature == null)
75 * // Generates the key.
76 * pKeyPairGen = new KeyPairGenerator();
77 * if (pKeyPairGen == null)
82 * r = pKeyPairGen->Construct(size);
88 * pKeyPair = pKeyPairGen->GenerateKeyPairN();
89 * if (pKeyPair == null)
94 * pPubKey = pKeyPair->GetPublicKey();
95 * if (pPubKey == null)
100 * pPriKey = pKeyPair->GetPrivateKey();
101 * if (pPriKey == null)
106 * r = pSignature->SetPrivateKey(*pPriKey);
112 * pOutput = pSignature->SignN(input);
113 * if (pOutput == null)
115 * r = GetLastResult();
119 * r = pSignature->SetPublicKey(*pPubKey);
125 * res = pSignature->Verify(input, *pOutput);
128 * r = GetLastResult();
137 * delete pKeyPairGen;
144 class _OSP_EXPORT_ ISignature
149 * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes @n
150 * are called when the destructor of this interface is called.
154 virtual ~ISignature(void) {}
157 * Sets an asymmetric private key for signature.
161 * @return An error code
162 * @param[in] key An instance of IKey
163 * @exception E_SUCCESS The method is successful.
164 * @exception E_INVALID_ARG The specified @c key is invalid.
165 * @exception E_OUT_OF_MEMORY The memory is insufficient.
167 virtual result SetPrivateKey(const Tizen::Security::IKey& key) = 0;
170 * Sets an asymmetric public key for verification.
174 * @return An error code
175 * @param[in] key An instance of IKey
176 * @exception E_SUCCESS The method is successful.
177 * @exception E_INVALID_ARG The specified @c key is invalid.
178 * @exception E_OUT_OF_MEMORY The memory is insufficient.
180 virtual result SetPublicKey(const Tizen::Security::IKey& key) = 0;
187 * @return A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
188 * else @c null if an error occurs
189 * @param[in] input An instance of Tizen::Base::ByteBuffer
190 * @exception E_SUCCESS The method is successful.
191 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
192 * @exception E_OUT_OF_MEMORY The memory is insufficient.
193 * @exception E_KEY_NOT_FOUND The specified key is not found.
194 * @exception E_SYSTEM A system error has occurred. @n
195 * The method has failed to operate with the openssl library, or
196 * the Tizen::Base::ByteBuffer operation has failed.
198 virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input) = 0;
201 * Verifies the data. @n
202 * The verification is done by comparing the @c signedData to the signature created by the @c data.
206 * @return @c true if the signed data is correct, @n
208 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
209 * @param[in] signedData An instance of Tizen::Base::ByteBuffer that contains the signed data
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
213 * @exception E_KEY_NOT_FOUND The specified key is not found.
214 * @exception E_SYSTEM A system error has occurred. @n
215 * The method has failed to operate with the openssl library, or
216 * the Tizen::Base::ByteBuffer operation has failed.
218 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData) = 0;
222 // This method is for internal use only. Using this method can cause behavioral, security-related,
223 // and consistency-related issues in the application.
225 // This method is reserved and may change its name at any time without prior notice.
229 virtual void ISignature_Reserved1(void) {}
233 } } } //Tizen::Security::Crypto
235 #endif //_FSEC_CRYPTO_ISIGNATURE_H_