package com.android.org.conscrypt;

import com.android.org.conscrypt.OpenSSLCipher;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/* JADX INFO: loaded from: classes.dex */
public class OpenSSLAeadCipherChaCha20 extends OpenSSLAeadCipher {
    public OpenSSLAeadCipherChaCha20() {
        super(OpenSSLCipher.Mode.POLY1305);
    }

    @Override // com.android.org.conscrypt.OpenSSLCipher
    void checkSupportedKeySize(int i3) throws InvalidKeyException {
        if (i3 == 32) {
            return;
        }
        throw new InvalidKeyException("Unsupported key size: " + i3 + " bytes (must be 32)");
    }

    @Override // com.android.org.conscrypt.OpenSSLCipher
    void checkSupportedMode(OpenSSLCipher.Mode mode) throws NoSuchAlgorithmException {
        if (mode != OpenSSLCipher.Mode.POLY1305) {
            throw new NoSuchAlgorithmException("Mode must be Poly1305");
        }
    }

    @Override // com.android.org.conscrypt.OpenSSLCipher
    String getBaseCipherName() {
        return "ChaCha20";
    }

    @Override // com.android.org.conscrypt.OpenSSLCipher
    int getCipherBlockSize() {
        return 0;
    }

    @Override // com.android.org.conscrypt.OpenSSLAeadCipher
    long getEVP_AEAD(int i3) throws InvalidKeyException {
        if (i3 == 32) {
            return NativeCrypto.EVP_aead_chacha20_poly1305();
        }
        throw new RuntimeException("Unexpected key length: " + i3);
    }

    @Override // com.android.org.conscrypt.OpenSSLAeadCipher, com.android.org.conscrypt.OpenSSLCipher
    int getOutputSizeForFinal(int i3) {
        return isEncrypting() ? this.bufCount + i3 + 16 : Math.max(0, (this.bufCount + i3) - 16);
    }
}
