Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89575b67 authored by Alex Klyubin's avatar Alex Klyubin Committed by Android (Google) Code Review
Browse files

Merge "Enforce IND-CPA requirement when generating asymmetric keys." into mnc-dev

parents 40fab055 fdbc02a4
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -287,6 +287,22 @@ public abstract class AndroidKeyStoreKeyPairGeneratorSpi extends KeyPairGenerato
                mKeymasterBlockModes = KeyProperties.BlockMode.allToKeymaster(spec.getBlockModes());
                mKeymasterEncryptionPaddings = KeyProperties.EncryptionPadding.allToKeymaster(
                        spec.getEncryptionPaddings());
                if (((spec.getPurposes() & KeyProperties.PURPOSE_ENCRYPT) != 0)
                        && (spec.isRandomizedEncryptionRequired())) {
                    for (int keymasterPadding : mKeymasterEncryptionPaddings) {
                        if (!KeymasterUtils
                                .isKeymasterPaddingSchemeIndCpaCompatibleWithAsymmetricCrypto(
                                        keymasterPadding)) {
                            throw new InvalidAlgorithmParameterException(
                                    "Randomized encryption (IND-CPA) required but may be violated"
                                    + " by padding scheme: "
                                    + KeyProperties.EncryptionPadding.fromKeymaster(
                                            keymasterPadding)
                                    + ". See " + KeyGenParameterSpec.class.getName()
                                    + " documentation.");
                        }
                    }
                }
                mKeymasterSignaturePaddings = KeyProperties.SignaturePadding.allToKeymaster(
                        spec.getSignaturePaddings());
                if (spec.isDigestsSpecified()) {
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public abstract class KeymasterUtils {
                return true;
            default:
                throw new IllegalArgumentException(
                        "Unsupported encryption padding scheme: " + keymasterPadding);
                        "Unsupported asymmetric encryption padding scheme: " + keymasterPadding);
        }
    }