diff options
author | Shawn Willden <swillden@google.com> | 2015-05-25 23:12:48 -0600 |
---|---|---|
committer | Shawn Willden <swillden@google.com> | 2015-05-31 09:28:56 -0600 |
commit | 0629810b145187575bc26c910dded0d24c64569d (patch) | |
tree | 5c1309696f2205777f6aad1c1b5b65aeaa64c9b7 /soft_keymaster_context.cpp | |
parent | 6270aca8571399aca8ea538acd7386ddecdcc112 (diff) | |
download | keymaster-0629810b145187575bc26c910dded0d24c64569d.tar.gz |
Another refactor, deleting AbstractFactoryRegistry.
I should have known better than to make these singletons to begin
with. Globals create problems. This undoes that mistake.
Change-Id: Idf61d5f72e3c34b5c4ddb27cc94b05f506561743
Diffstat (limited to 'soft_keymaster_context.cpp')
-rw-r--r-- | soft_keymaster_context.cpp | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/soft_keymaster_context.cpp b/soft_keymaster_context.cpp index 8751a27..bda5dbe 100644 --- a/soft_keymaster_context.cpp +++ b/soft_keymaster_context.cpp @@ -47,21 +47,45 @@ const int TAG_LENGTH = 16; const KeymasterKeyBlob MASTER_KEY(master_key_bytes, array_length(master_key_bytes)); } // anonymous namespace -class SoftKeymasterKeyRegistrations { - public: - SoftKeymasterKeyRegistrations(SoftKeymasterContext* context, Keymaster0Engine* engine) - : rsa_(context, engine), ec_(context, engine), hmac_(context), aes_(context) {} - - KeyFactoryRegistry::Registration<RsaKeymaster0KeyFactory> rsa_; - KeyFactoryRegistry::Registration<EcdsaKeymaster0KeyFactory> ec_; - KeyFactoryRegistry::Registration<HmacKeyFactory> hmac_; - KeyFactoryRegistry::Registration<AesKeyFactory> aes_; -}; - SoftKeymasterContext::SoftKeymasterContext(keymaster0_device_t* keymaster0_device) { if (keymaster0_device && (keymaster0_device->flags & KEYMASTER_SOFTWARE_ONLY) == 0) engine_.reset(new Keymaster0Engine(keymaster0_device)); - registrations_.reset(new SoftKeymasterKeyRegistrations(this, engine_.get())); + rsa_factory_.reset(new RsaKeymaster0KeyFactory(this, engine_.get())); + ec_factory_.reset(new EcdsaKeymaster0KeyFactory(this, engine_.get())); + aes_factory_.reset(new AesKeyFactory(this)); + hmac_factory_.reset(new HmacKeyFactory(this)); +} + +KeyFactory* SoftKeymasterContext::GetKeyFactory(keymaster_algorithm_t algorithm) const { + switch (algorithm) { + case KM_ALGORITHM_RSA: + return rsa_factory_.get(); + case KM_ALGORITHM_EC: + return ec_factory_.get(); + case KM_ALGORITHM_AES: + return aes_factory_.get(); + case KM_ALGORITHM_HMAC: + return hmac_factory_.get(); + default: + return nullptr; + } +} + +static keymaster_algorithm_t supported_algorithms[] = {KM_ALGORITHM_RSA, KM_ALGORITHM_EC, + KM_ALGORITHM_AES, KM_ALGORITHM_HMAC}; + +keymaster_algorithm_t* +SoftKeymasterContext::GetSupportedAlgorithms(size_t* algorithms_count) const { + *algorithms_count = array_length(supported_algorithms); + return supported_algorithms; +} + +OperationFactory* SoftKeymasterContext::GetOperationFactory(keymaster_algorithm_t algorithm, + keymaster_purpose_t purpose) const { + KeyFactory* key_factory = GetKeyFactory(algorithm); + if (!key_factory) + return nullptr; + return key_factory->GetOperationFactory(purpose); } static keymaster_error_t TranslateAuthorizationSetError(AuthorizationSet::Error err) { @@ -137,7 +161,6 @@ keymaster_error_t SoftKeymasterContext::CreateKeyBlob(const AuthorizationSet& ke KeymasterKeyBlob* blob, AuthorizationSet* hw_enforced, AuthorizationSet* sw_enforced) const { - keymaster_error_t error = SetAuthorizations(key_description, origin, hw_enforced, sw_enforced); if (error != KM_ERROR_OK) return error; |