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

Commit 59965371 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add more symmetric KeyMint tests" am: 3b2b180a am: 232fe779 am:...

Merge "Add more symmetric KeyMint tests" am: 3b2b180a am: 232fe779 am: 6ac16ced am: 589b6237

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1621103

Change-Id: I0e193ee0a5abcb0a5465bc951af05a81eaec5c2b
parents 4f9cd8e7 589b6237
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ using AttestKeyTest = KeyMintAidlTestBase;
TEST_P(AttestKeyTest, AllRsaSizes) {
    for (auto size : ValidKeySizes(Algorithm::RSA)) {
        /*
         * Create attestaton key.
         * Create attestation key.
         */
        AttestationKey attest_key;
        vector<KeyCharacteristics> attest_key_characteristics;
@@ -482,7 +482,7 @@ TEST_P(AttestKeyTest, AlternateAttestKeyChaining) {
TEST_P(AttestKeyTest, AllEcCurves) {
    for (auto curve : ValidCurves()) {
        /*
         * Create attestaton key.
         * Create attestation key.
         */
        AttestationKey attest_key;
        vector<KeyCharacteristics> attest_key_characteristics;
@@ -566,7 +566,7 @@ TEST_P(AttestKeyTest, AllEcCurves) {
}

TEST_P(AttestKeyTest, AttestWithNonAttestKey) {
    // Create non-attestaton key.
    // Create non-attestation key.
    AttestationKey non_attest_key;
    vector<KeyCharacteristics> non_attest_key_characteristics;
    vector<Certificate> non_attest_key_cert_chain;
+71 −0
Original line number Diff line number Diff line
@@ -743,6 +743,15 @@ vector<uint32_t> KeyMintAidlTestBase::InvalidKeySizes(Algorithm algorithm) {
                return {224, 384, 521};
            case Algorithm::AES:
                return {192};
            case Algorithm::TRIPLE_DES:
                return {56};
            default:
                return {};
        }
    } else {
        switch (algorithm) {
            case Algorithm::TRIPLE_DES:
                return {56};
            default:
                return {};
        }
@@ -750,6 +759,68 @@ vector<uint32_t> KeyMintAidlTestBase::InvalidKeySizes(Algorithm algorithm) {
    return {};
}

vector<BlockMode> KeyMintAidlTestBase::ValidBlockModes(Algorithm algorithm) {
    switch (algorithm) {
        case Algorithm::AES:
            return {
                    BlockMode::CBC,
                    BlockMode::CTR,
                    BlockMode::ECB,
                    BlockMode::GCM,
            };
        case Algorithm::TRIPLE_DES:
            return {
                    BlockMode::CBC,
                    BlockMode::ECB,
            };
        default:
            return {};
    }
}

vector<PaddingMode> KeyMintAidlTestBase::ValidPaddingModes(Algorithm algorithm,
                                                           BlockMode blockMode) {
    switch (algorithm) {
        case Algorithm::AES:
            switch (blockMode) {
                case BlockMode::CBC:
                case BlockMode::ECB:
                    return {PaddingMode::NONE, PaddingMode::PKCS7};
                case BlockMode::CTR:
                case BlockMode::GCM:
                    return {PaddingMode::NONE};
                default:
                    return {};
            };
        case Algorithm::TRIPLE_DES:
            switch (blockMode) {
                case BlockMode::CBC:
                case BlockMode::ECB:
                    return {PaddingMode::NONE, PaddingMode::PKCS7};
                default:
                    return {};
            };
        default:
            return {};
    }
}

vector<PaddingMode> KeyMintAidlTestBase::InvalidPaddingModes(Algorithm algorithm,
                                                             BlockMode blockMode) {
    switch (algorithm) {
        case Algorithm::AES:
            switch (blockMode) {
                case BlockMode::CTR:
                case BlockMode::GCM:
                    return {PaddingMode::PKCS7};
                default:
                    return {};
            };
        default:
            return {};
    }
}

vector<EcCurve> KeyMintAidlTestBase::ValidCurves() {
    if (securityLevel_ == SecurityLevel::STRONGBOX) {
        return {EcCurve::P_256};
+4 −0
Original line number Diff line number Diff line
@@ -230,6 +230,10 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam<string> {
    vector<uint32_t> ValidKeySizes(Algorithm algorithm);
    vector<uint32_t> InvalidKeySizes(Algorithm algorithm);

    vector<BlockMode> ValidBlockModes(Algorithm algorithm);
    vector<PaddingMode> ValidPaddingModes(Algorithm algorithm, BlockMode blockMode);
    vector<PaddingMode> InvalidPaddingModes(Algorithm algorithm, BlockMode blockMode);

    vector<EcCurve> ValidCurves();
    vector<EcCurve> InvalidCurves();

+394 −25

File changed.

Preview size limit exceeded, changes collapsed.