1 /*
2  * Copyright 2014 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_AES_KEY_H_
18 #define SYSTEM_KEYMASTER_AES_KEY_H_
19 
20 #include <openssl/aes.h>
21 
22 #include "symmetric_key.h"
23 
24 namespace keymaster {
25 
26 const size_t kMinGcmTagLength = 12 * 8;
27 const size_t kMaxGcmTagLength = 16 * 8;
28 
29 class AesKeyFactory : public SymmetricKeyFactory {
30   public:
AesKeyFactory(const KeymasterContext * context)31     AesKeyFactory(const KeymasterContext* context) : SymmetricKeyFactory(context) {}
32 
registry_key()33     keymaster_algorithm_t registry_key() const { return KM_ALGORITHM_AES; }
34 
35     keymaster_error_t LoadKey(const KeymasterKeyBlob& key_material,
36                               const AuthorizationSet& hw_enforced,
37                               const AuthorizationSet& sw_enforced,
38                               UniquePtr<Key>* key) const override;
39 
40     OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override;
41 
42   private:
key_size_supported(size_t key_size_bits)43     bool key_size_supported(size_t key_size_bits) const override {
44         return key_size_bits == 128 || key_size_bits == 192 || key_size_bits == 256;
45     }
46     keymaster_error_t validate_algorithm_specific_new_key_params(
47         const AuthorizationSet& key_description) const override;
48 };
49 
50 class AesKey : public SymmetricKey {
51   public:
AesKey(const KeymasterKeyBlob & key_material,const AuthorizationSet & hw_enforced,const AuthorizationSet & sw_enforced,keymaster_error_t * error)52     AesKey(const KeymasterKeyBlob& key_material, const AuthorizationSet& hw_enforced,
53            const AuthorizationSet& sw_enforced, keymaster_error_t* error)
54         : SymmetricKey(key_material, hw_enforced, sw_enforced, error) {}
55 };
56 
57 }  // namespace keymaster
58 
59 #endif  // SYSTEM_KEYMASTER_AES_KEY_H_
60