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:
Alex Klyubin
2015-03-27 16:53:44 -07:00
parent 36ee836d2f
commit 4ab8ea4498
9 changed files with 472 additions and 4 deletions

View File

@@ -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()