31 #ifndef _SCC_CRYPTO_CIPHER_H
32 #define _SCC_CRYPTO_CIPHER_H
39 namespace scc::crypto {
85 virtual void reset(
const void*,
int,
const void*,
int) = 0;
86 virtual void aad(
const void*,
int) = 0;
87 virtual void encrypt(
const void*,
int,
void*,
int) = 0;
88 virtual void decrypt(
const void*,
int,
void*,
int) = 0;
89 virtual void auth_tag(
void*,
int) = 0;
134 Cipher(Type type,
const void* key_loc,
int key_len,
int = 16);
135 Cipher(Type type,
const std::vector<char>& key,
int tag_len = 16) :
Cipher(type, key.data(), key.size(), tag_len) {}
136 Cipher(Type type,
const std::string& key,
int tag_len = 16) :
Cipher(type, key.data(), key.size(), tag_len) {}
143 m_type = other.m_type;
144 other.m_ctx =
nullptr;
150 m_type = other.m_type;
151 other.m_ctx =
nullptr;
156 size_t nonce_min()
const
160 case aes_gcm_type:
return 1;
161 case aes_ccm_type:
return 8;
164 size_t nonce_max()
const
168 case aes_gcm_type:
return 128;
169 case aes_ccm_type:
return 12;
191 void reset(
const void* nonce_loc,
int nonce_len,
const void* aad_loc =
nullptr,
int aad_len = 0)
193 m_ctx->reset(nonce_loc, nonce_len, aad_loc, aad_len);
204 void aad(
const void* aad_loc,
int aad_len)
206 m_ctx->aad(aad_loc, aad_len);
220 void encrypt(
const void* msg_loc,
int msg_len,
void* cipher_loc,
int cipher_len)
222 m_ctx->encrypt(msg_loc, msg_len, cipher_loc, cipher_len);
236 void decrypt(
const void* cipher_loc,
int cipher_len,
void* msg_loc,
int msg_len)
238 m_ctx->decrypt(cipher_loc, cipher_len, msg_loc, msg_len);
250 m_ctx->auth_tag(tag_loc, tag_len);
Cipher(Type type, const void *key_loc, int key_len, int=16)
Create a cipher.
void decrypt(const void *cipher_loc, int cipher_len, void *msg_loc, int msg_len)
Decrypt a message.
void reset(const void *nonce_loc, int nonce_len, const void *aad_loc=nullptr, int aad_len=0)
Reset the processor to prepare to encrypt or decrypt a new message.
void encrypt(const void *msg_loc, int msg_len, void *cipher_loc, int cipher_len)
Encrypt a message.
void aad(const void *aad_loc, int aad_len)
Set additional authenticated data (for GCM type only).
void auth_tag(char *tag_loc, int tag_len)
Gets the authentication tag.