Merge "Fix accessing freed memory in X509CertificateStore::Update()" into tizen
[platform/framework/native/appfw.git] / src / security / crypto / FSecCrypto_SymmetricCipher.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        FSecCrypto_SymmetricCipher.h
19  * @brief       This header file contains declarations of common operations for Symmetric Ciphers available.
20  */
21 #ifndef _FSEC_CRYPTO_INTERNAL_SYMMETRIC_CIPHER_H_
22 #define _FSEC_CRYPTO_INTERNAL_SYMMETRIC_CIPHER_H_
23
24 #include <unique_ptr.h>
25 #include <FSecCryptoTypes.h>
26 #include <FBaseByteBuffer.h>
27
28 struct evp_cipher_st;
29 struct evp_cipher_ctx_st;
30
31
32 namespace Tizen { namespace Security { namespace Crypto
33 {
34
35 class _SymmetricCipher
36 {
37
38 public:
39         _SymmetricCipher(void);
40         virtual ~_SymmetricCipher(void);
41         result SetCipherAlgorithm(const Tizen::Base::String& cipherAlgorithm);
42         result SetKey(const Tizen::Security::ISecretKey& key);
43         result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
44         result SetTransformation(const evp_cipher_st* pCipherAlgorithm, bool padding);
45         result SetCipherOperation(CipherOperation opMode);
46         Tizen::Base::ByteBuffer* DoCipherN(const Tizen::Base::ByteBuffer& input, bool variableKeyFlag = false);
47         result Initialize(bool variableKeyFlag = false);
48         Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
49         Tizen::Base::ByteBuffer* FinalizeN(void);
50         Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
51         Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
52
53 private:
54         _SymmetricCipher(const _SymmetricCipher& rhs);
55         _SymmetricCipher& operator =(const _SymmetricCipher& rhs);
56         Tizen::Base::ByteBuffer* DoWrapN(const Tizen::Base::ByteBuffer& secretKey);
57         Tizen::Base::ByteBuffer* DoUnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
58
59 private:
60         const evp_cipher_st* __pCipherAlgorithm;
61         Tizen::Base::String __cipherAlgorithm;
62         std::unique_ptr <evp_cipher_ctx_st> __pCipherCtx;
63         CipherOperation __opMode;
64         bool __padding;
65         Tizen::Base::ByteBuffer __initVector;
66         Tizen::Base::ByteBuffer __keyBytes;
67
68 }; //_SymmetricCipher
69
70 } } } // Tizen::Security::Crypto
71
72 #endif //_FSEC_CRYPTO_INTERNAL_SYMMETRIC_CIPHER_H_