1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SYSTEM_KEYMASTER_TRIPLE_DES_KEY_H_ 18 #define SYSTEM_KEYMASTER_TRIPLE_DES_KEY_H_ 19 20 #include <openssl/des.h> 21 22 #include "symmetric_key.h" 23 24 namespace keymaster { 25 26 class TripleDesKeyFactory : public SymmetricKeyFactory { 27 public: TripleDesKeyFactory(const SoftwareKeyBlobMaker * blob_maker,const RandomSource * random_source)28 explicit TripleDesKeyFactory(const SoftwareKeyBlobMaker* blob_maker, 29 const RandomSource* random_source) 30 : SymmetricKeyFactory(blob_maker, random_source) {} 31 registry_key()32 keymaster_algorithm_t registry_key() const { return KM_ALGORITHM_TRIPLE_DES; } 33 34 keymaster_error_t LoadKey(KeymasterKeyBlob&& key_material, 35 const AuthorizationSet& additional_params, 36 AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced, 37 UniquePtr<Key>* key) const override; 38 39 OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override; 40 41 private: key_size_supported(size_t key_size_bits)42 bool key_size_supported(size_t key_size_bits) const override { 43 return key_size_bits == 112 || key_size_bits == 168; 44 } key_size_bytes(size_t key_size_bits)45 size_t key_size_bytes(size_t key_size_bits) const override { return key_size_bits / 7; } key_size_bits(size_t key_size_bytes)46 size_t key_size_bits(size_t key_size_bytes) const override { return key_size_bytes * 7; } 47 48 keymaster_error_t validate_algorithm_specific_new_key_params( 49 const AuthorizationSet& key_description) const override; 50 }; 51 52 class TripleDesKey : public SymmetricKey { 53 public: TripleDesKey(KeymasterKeyBlob && key_material,AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,const KeyFactory * key_factory)54 TripleDesKey(KeymasterKeyBlob&& key_material, AuthorizationSet&& hw_enforced, 55 AuthorizationSet&& sw_enforced, const KeyFactory* key_factory) 56 : SymmetricKey(move(key_material), move(hw_enforced), move(sw_enforced), key_factory) {} 57 }; 58 59 } // namespace keymaster 60 61 #endif // SYSTEM_KEYMASTER_TRIPLE_DES_KEY_H_ 62