8#include <botan/internal/commoncrypto.h>
9#include <botan/internal/commoncrypto_utils.h>
10#include <botan/cipher_mode.h>
11#include <botan/parsing.h>
12#include <botan/internal/rounding.h>
13#include <botan/scan_name.h>
17std::string CommonCrypto_Error::ccryptorstatus_to_string(
CCCryptorStatus status)
25 case kCCBufferTooSmall:
26 return "BufferTooSmall";
27 case kCCMemoryFailure:
28 return "MemoryFailure";
29 case kCCAlignmentError:
30 return "AlignmentError";
33 case kCCUnimplemented:
34 return "Unimplemented";
39 case kCCUnspecifiedError:
40 return "UnspecifiedError";
41 case kCCCallSequenceError:
42 return "CallSequenceError";
44 return "KeySizeError";
55 if(algo_name.compare(0, 3,
"AES") == 0)
57 opts.
algo = kCCAlgorithmAES;
59 if(algo_name ==
"AES-128")
63 else if(algo_name ==
"AES-192")
67 else if(algo_name ==
"AES-256")
76 else if(algo_name ==
"DES")
78 opts.
algo = kCCAlgorithmDES;
82 else if(algo_name ==
"TripleDES")
84 opts.
algo = kCCAlgorithm3DES;
88 else if(algo_name ==
"Blowfish")
90 opts.
algo = kCCAlgorithmBlowfish;
94 else if(algo_name ==
"CAST-128")
96 opts.
algo = kCCAlgorithmCAST;
115 std::string algo_name = spec.
algo_name();
122 if(cipher_mode.empty() || cipher_mode ==
"ECB")
124 opts.
mode = kCCModeECB;
126 else if(cipher_mode ==
"CBC")
128 opts.
mode = kCCModeCBC;
130 else if(cipher_mode ==
"CTR")
132 opts.
mode = kCCModeCTR;
134 else if(cipher_mode ==
"OFB")
136 opts.
mode = kCCModeOFB;
143 if(cipher_mode_padding ==
"NoPadding")
166 if(opts.
algo == kCCAlgorithmBlowfish && length < 8)
185 full_key.resize(length * repeat);
186 for(
size_t i = 0; i < repeat; i++)
188 copy_mem(full_key.data() + i * length, key, length);
191 else if(opts.
algo == kCCAlgorithm3DES && length == 16)
193 full_key += std::make_pair(key, 8);
const std::string & algo_name() const
std::string cipher_mode_pad() const
std::string cipher_mode() const
CommonCryptor_Opts commoncrypto_opts_from_algo(const std::string &algo)
void copy_mem(T *out, const T *in, size_t n)
CommonCryptor_Opts commoncrypto_opts_from_algo_name(const std::string &algo_name)
void commoncrypto_adjust_key_size(const uint8_t key[], size_t length, const CommonCryptor_Opts &opts, secure_vector< uint8_t > &full_key)
std::vector< T, secure_allocator< T > > secure_vector
Key_Length_Specification key_spec