#ifndef TEST_PROCESS_COMMON_ENCRYPTION_H
#define TEST_PROCESS_COMMON_ENCRYPTION_H
#include "sa_cenc.h"
#include <memory>
#include <openssl/evp.h>
#include <vector>
typedef struct {
std::vector<uint8_t> clear;
std::shared_ptr<sa_buffer> in;
std::shared_ptr<sa_buffer> out;
std::vector<sa_subsample_length> subsample_lengths;
} sample_data;
class ProcessCommonEncryptionBase {
protected:
bool build_samples(
size_t sample_size,
size_t crypt_byte_block,
size_t skip_byte_block,
size_t subsample_count,
size_t bytes_of_clear_data,
std::vector<uint8_t>& iv,
sa_cipher_algorithm cipher_algorithm,
std::vector<uint8_t>& clear_key,
const std::shared_ptr<sa_crypto_cipher_context>& cipher,
sample_data& sample_data,
std::vector<sa_sample>& samples);
virtual sa_status svp_buffer_write(
sa_svp_buffer out,
const void* in,
size_t in_length) = 0;
~ProcessCommonEncryptionBase() = default;
private:
static EVP_CIPHER_CTX* openssl_init(
const void* iv,
const uint8_t* key,
sa_cipher_algorithm cipher_algorithm);
static bool encrypt(
uint8_t* out_bytes,
uint8_t* in_bytes,
size_t bytes_to_process,
size_t* enc_byte_count,
uint8_t* iv,
EVP_CIPHER_CTX* context);
static bool encrypt_samples(
uint8_t* in_bytes,
std::vector<sa_sample>& samples,
std::vector<uint8_t>& clear_key,
sa_cipher_algorithm cipher_algorithm);
};
#endif