12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "triple_des_operation.h"
- namespace keymaster {
- static const keymaster_block_mode_t supported_block_modes[] = {KM_MODE_ECB, KM_MODE_CBC};
- const keymaster_block_mode_t*
- TripleDesEvpCipherDescription::SupportedBlockModes(size_t* block_mode_count) const {
- *block_mode_count = array_length(supported_block_modes);
- return supported_block_modes;
- }
- const EVP_CIPHER*
- TripleDesEvpCipherDescription::GetCipherInstance(size_t key_size, keymaster_block_mode_t block_mode,
- keymaster_error_t* error) const {
- *error = KM_ERROR_OK;
- switch (block_mode) {
- case KM_MODE_ECB:
- switch (key_size) {
- case 16:
- return EVP_des_ede();
- case 24:
- return EVP_des_ede3();
- default:
- *error = KM_ERROR_UNSUPPORTED_KEY_SIZE;
- break;
- }
- break;
- case KM_MODE_CBC:
- switch (key_size) {
- case 16:
- return EVP_des_ede_cbc();
- case 24:
- return EVP_des_ede3_cbc();
- default:
- *error = KM_ERROR_UNSUPPORTED_KEY_SIZE;
- break;
- }
- break;
- default:
- *error = KM_ERROR_UNSUPPORTED_BLOCK_MODE;
- break;
- }
- assert(*error != KM_ERROR_OK);
- return nullptr;
- }
- static TripleDesEvpCipherDescription description;
- const EvpCipherDescription& TripleDesOperationFactory::GetCipherDescription() const {
- return description;
- }
- }
|