8 #include <botan/cipher_mode.h>
9 #include <botan/parsing.h>
10 #include <botan/internal/commoncrypto.h>
11 #include <botan/internal/rounding.h>
12 #include <botan/scan_name.h>
18 std::string CommonCrypto_Error::ccryptorstatus_to_string(CCCryptorStatus status)
26 case kCCBufferTooSmall:
27 return "BufferTooSmall";
28 case kCCMemoryFailure:
29 return "MemoryFailure";
30 case kCCAlignmentError:
31 return "AlignmentError";
34 case kCCUnimplemented:
35 return "Unimplemented";
40 case kCCUnspecifiedError:
41 return "UnspecifiedError";
42 case kCCCallSequenceError:
43 return "CallSequenceError";
45 return "KeySizeError";
62 if(algo_name.compare(0, 3,
"AES") == 0)
64 opts.
algo = kCCAlgorithmAES;
66 if(algo_name ==
"AES-128")
70 else if(algo_name ==
"AES-192")
74 else if(algo_name ==
"AES-256")
83 else if(algo_name ==
"DES")
85 opts.
algo = kCCAlgorithmDES;
89 else if(algo_name ==
"TripleDES")
91 opts.
algo = kCCAlgorithm3DES;
95 else if(algo_name ==
"Blowfish")
97 opts.
algo = kCCAlgorithmBlowfish;
101 else if(algo_name ==
"CAST-128")
103 opts.
algo = kCCAlgorithmCAST;
115 if(cipher_mode.empty() || cipher_mode ==
"ECB")
117 opts.
mode = kCCModeECB;
119 else if(cipher_mode ==
"CBC")
121 opts.
mode = kCCModeCBC;
123 else if(cipher_mode ==
"CTR")
125 opts.
mode = kCCModeCTR;
127 else if(cipher_mode ==
"OFB")
129 opts.
mode = kCCModeOFB;
136 if(cipher_mode_padding ==
"NoPadding")
159 if(opts.
algo == kCCAlgorithmBlowfish && length < 8)
178 full_key.resize(length * repeat);
179 for(
size_t i = 0; i < repeat; i++)
181 copy_mem(full_key.data() + i * length, key, length);
184 else if(opts.
algo == kCCAlgorithm3DES && length == 16)
186 full_key += std::make_pair(key, 8);
std::string cipher_mode() const
CommonCryptor_Opts commoncrypto_opts_from_algo(const std::string &algo)
std::vector< T, secure_allocator< T >> secure_vector
std::string cipher_mode_pad() const
Key_Length_Specification key_spec
void copy_mem(T *out, const T *in, size_t n)
const std::string & algo_name() const
void commoncrypto_adjust_key_size(const uint8_t key[], size_t length, const CommonCryptor_Opts &opts, secure_vector< uint8_t > &full_key)