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