Add HmacSHA256 backed by AndroidKeyStore.
This also adds the MAC length constraint on imported HMAC keys. HMAC doesn't work without this constraint at the moment. Bug: 18088752 Change-Id: I8613f58f5d2a84df00bcf6179d13e30619440330
This commit is contained in:
@@ -494,6 +494,19 @@ public class AndroidKeyStore extends KeyStoreSpi {
|
||||
args.addInt(KeymasterDefs.KM_TAG_DIGEST,
|
||||
KeyStoreKeyConstraints.Digest.toKeymaster(digest));
|
||||
}
|
||||
if (keyAlgorithm == KeyStoreKeyConstraints.Algorithm.HMAC) {
|
||||
if (digest == null) {
|
||||
throw new IllegalStateException("Digest algorithm must be specified for key"
|
||||
+ " algorithm " + keyAlgorithmString);
|
||||
}
|
||||
Integer digestOutputSizeBytes =
|
||||
KeyStoreKeyConstraints.Digest.getOutputSizeBytes(digest);
|
||||
if (digestOutputSizeBytes != null) {
|
||||
// TODO: Remove MAC length constraint once Keymaster API no longer requires it.
|
||||
// TODO: Switch to bits instead of bytes, once this is fixed in Keymaster
|
||||
args.addInt(KeymasterDefs.KM_TAG_MAC_LENGTH, digestOutputSizeBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@KeyStoreKeyConstraints.PurposeEnum int purposes = (params.getPurposes() != null)
|
||||
? params.getPurposes()
|
||||
|
||||
Reference in New Issue
Block a user