8#include <botan/internal/commoncrypto.h>
9#include <botan/internal/commoncrypto_utils.h>
10#include <botan/cipher_mode.h>
11#include <botan/internal/parsing.h>
12#include <botan/internal/scan_name.h>
13#include <botan/internal/fmt.h>
22 Exception(
fmt(
"CommonCrypto op {} failed with err {} ({})",
23 what, status, ccryptorstatus_to_string(status))),
26std::string CommonCrypto_Error::ccryptorstatus_to_string(
CCCryptorStatus status)
34 case kCCBufferTooSmall:
35 return "BufferTooSmall";
36 case kCCMemoryFailure:
37 return "MemoryFailure";
38 case kCCAlignmentError:
39 return "AlignmentError";
42 case kCCUnimplemented:
43 return "Unimplemented";
48 case kCCUnspecifiedError:
49 return "UnspecifiedError";
50 case kCCCallSequenceError:
51 return "CallSequenceError";
53 return "KeySizeError";
64 if(algo_name.compare(0, 3,
"AES") == 0)
66 opts.
algo = kCCAlgorithmAES;
68 if(algo_name ==
"AES-128")
72 else if(algo_name ==
"AES-192")
76 else if(algo_name ==
"AES-256")
85 else if(algo_name ==
"DES")
87 opts.
algo = kCCAlgorithmDES;
91 else if(algo_name ==
"TripleDES")
93 opts.
algo = kCCAlgorithm3DES;
97 else if(algo_name ==
"Blowfish")
99 opts.
algo = kCCAlgorithmBlowfish;
103 else if(algo_name ==
"CAST-128")
105 opts.
algo = kCCAlgorithmCAST;
124 std::string algo_name = spec.
algo_name();
131 if(cipher_mode.empty() || cipher_mode ==
"ECB")
133 opts.
mode = kCCModeECB;
135 else if(cipher_mode ==
"CBC")
137 opts.
mode = kCCModeCBC;
139 else if(cipher_mode ==
"CTR")
141 opts.
mode = kCCModeCTR;
143 else if(cipher_mode ==
"OFB")
145 opts.
mode = kCCModeOFB;
152 if(cipher_mode_padding ==
"NoPadding")
175 if(opts.
algo == kCCAlgorithmBlowfish && length < 8)
194 full_key.resize(length * repeat);
195 for(
size_t i = 0; i < repeat; i++)
197 copy_mem(full_key.data() + i * length, key, length);
200 else if(opts.
algo == kCCAlgorithm3DES && length == 16)
202 full_key += std::make_pair(key, 8);
CommonCrypto_Error(std::string_view what)
const std::string algo_name() const
std::string cipher_mode_pad() const
std::string cipher_mode() const
std::string fmt(std::string_view format, const T &... args)
constexpr void copy_mem(T *out, const T *in, size_t n)
void commoncrypto_adjust_key_size(const uint8_t key[], size_t length, const CommonCryptor_Opts &opts, secure_vector< uint8_t > &full_key)
CommonCryptor_Opts commoncrypto_opts_from_algo(std::string_view algo)
std::vector< T, secure_allocator< T > > secure_vector
CommonCryptor_Opts commoncrypto_opts_from_algo_name(std::string_view algo_name)
Key_Length_Specification key_spec