AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
OpenSslCryptoCodec.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ACSDKCRYPTO_PRIVATE_OPENSSLCRYPTOCODEC_H_
17 #define ACSDKCRYPTO_PRIVATE_OPENSSLCRYPTOCODEC_H_
18 
19 #include <memory>
20 
21 #include <openssl/evp.h>
22 
26 
27 namespace alexaClientSDK {
28 namespace acsdkCrypto {
29 
32 
41 public:
51  static std::unique_ptr<OpenSslCryptoCodec> createDecoder(AlgorithmType type) noexcept;
61  static std::unique_ptr<OpenSslCryptoCodec> createEncoder(AlgorithmType type) noexcept;
62 
65  ~OpenSslCryptoCodec() noexcept override;
66  bool init(const Key& key, const IV& iv) noexcept override;
67  bool processAAD(const DataBlock& dataIn) noexcept override;
68  bool processAAD(DataBlock::const_iterator dataInBegin, DataBlock::const_iterator dataInEnd) noexcept override;
69  bool process(const DataBlock& dataIn, DataBlock& dataOut) noexcept override;
70  bool process(
71  DataBlock::const_iterator dataInBegin,
72  DataBlock::const_iterator dataInEnd,
73  DataBlock& dataOut) noexcept override;
74  bool finalize(DataBlock& dataOut) noexcept override;
75  bool getTag(Tag& tag) noexcept override;
76  bool setTag(const Tag& tag) noexcept override;
78 
79 private:
90  static std::unique_ptr<OpenSslCryptoCodec> createCodec(AlgorithmType type, CodecType codecType) noexcept;
91 
98  OpenSslCryptoCodec(CodecType codecType, AlgorithmType algorithmType) noexcept;
99 
105  bool isAEADCipher() noexcept;
106 
108  const CodecType m_codecType;
109 
111  const AlgorithmType m_algorithmType;
112 
114  EVP_CIPHER_CTX* m_cipherCtx;
115 
117  bool m_initDone;
118 
120  const EVP_CIPHER* m_cipher;
121 };
122 
123 } // namespace acsdkCrypto
124 } // namespace alexaClientSDK
125 
126 #endif // ACSDKCRYPTO_PRIVATE_OPENSSLCRYPTOCODEC_H_
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::createDecoder
static std::unique_ptr< OpenSslCryptoCodec > createDecoder(AlgorithmType type) noexcept
Create decoder.
Definition: OpenSslCryptoCodec.cpp:30
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::process
bool process(const DataBlock &dataIn, DataBlock &dataOut) noexcept override
Encrypt or decrypt a data block.
Definition: OpenSslCryptoCodec.cpp:194
alexaClientSDK::acsdkCryptoInterfaces::CryptoCodecInterface::DataBlock
std::vector< unsigned char > DataBlock
Data block type. This type represents a byte array.
Definition: CryptoCodecInterface.h:160
AlgorithmType.h
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::createEncoder
static std::unique_ptr< OpenSslCryptoCodec > createEncoder(AlgorithmType type) noexcept
Create encoder.
Definition: OpenSslCryptoCodec.cpp:39
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec
Binary codec implementation.
Definition: OpenSslCryptoCodec.h:40
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::finalize
bool finalize(DataBlock &dataOut) noexcept override
Complete data processing.
Definition: OpenSslCryptoCodec.cpp:198
alexaClientSDK::acsdkCryptoInterfaces::CryptoCodecInterface
Crypto codec (cipher) interface.
Definition: CryptoCodecInterface.h:156
alexaClientSDK::acsdkCryptoInterfaces::CryptoCodecInterface::Tag
std::vector< unsigned char > Tag
Tag vector type. Tag is used with AEAD mode of operation like with Galois/Counter mode.
Definition: CryptoCodecInterface.h:173
alexaClientSDK::acsdkCryptoInterfaces::CryptoCodecInterface::Key
std::vector< unsigned char > Key
Key type. This type contains key bytes.
Definition: CryptoCodecInterface.h:164
OpenSslTypes.h
alexaClientSDK::settings::test::key
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::init
bool init(const Key &key, const IV &iv) noexcept override
Initialize the codec.
Definition: OpenSslCryptoCodec.cpp:70
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::~OpenSslCryptoCodec
~OpenSslCryptoCodec() noexcept override
Definition: OpenSslCryptoCodec.cpp:65
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
alexaClientSDK::acsdkCrypto::CodecType
CodecType
Typed enumeration for codec types to use with EVP API.
Definition: OpenSslTypes.h:38
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::processAAD
bool processAAD(const DataBlock &dataIn) noexcept override
Process AAD data block.
Definition: OpenSslCryptoCodec.cpp:154
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::setTag
bool setTag(const Tag &tag) noexcept override
Sets tag for authenticated decryption.
Definition: OpenSslCryptoCodec.cpp:258
alexaClientSDK::acsdkCrypto::OpenSslCryptoCodec::getTag
bool getTag(Tag &tag) noexcept override
Provides tag from authenticated encryption.
Definition: OpenSslCryptoCodec.cpp:225
alexaClientSDK::acsdkCryptoInterfaces::CryptoCodecInterface::IV
std::vector< unsigned char > IV
Initialization vector type. Initialization vector contains data to initialize codec state before encr...
Definition: CryptoCodecInterface.h:169
CryptoCodecInterface.h
alexaClientSDK::acsdkCryptoInterfaces::AlgorithmType
AlgorithmType
Enumeration of all supported encryption protocols.
Definition: AlgorithmType.h:31

AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0