OpenSSLCipherRSA$OAEP.smali
.class public Lorg/conscrypt/OpenSSLCipherRSA$OAEP;
.super Lorg/conscrypt/OpenSSLCipherRSA;
.source ""
# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
value = Lorg/conscrypt/OpenSSLCipherRSA;
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x9
name = "OAEP"
.end annotation
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lorg/conscrypt/OpenSSLCipherRSA$OAEP$SHA512;,
Lorg/conscrypt/OpenSSLCipherRSA$OAEP$SHA384;,
Lorg/conscrypt/OpenSSLCipherRSA$OAEP$SHA256;,
Lorg/conscrypt/OpenSSLCipherRSA$OAEP$SHA224;,
Lorg/conscrypt/OpenSSLCipherRSA$OAEP$SHA1;
}
.end annotation
# instance fields
.field private label:[B
.field private mgf1Md:J
.field private oaepMd:J
.field private oaepMdSizeBytes:I
.field private pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
# direct methods
.method public constructor <init>(JI)V
.registers 5
const/4 v0, 0x4
invoke-direct {p0, v0}, Lorg/conscrypt/OpenSSLCipherRSA;-><init>(I)V
iput-wide p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->mgf1Md:J
iput-wide p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMd:J
iput p3, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMdSizeBytes:I
return-void
.end method
.method private readOAEPParameters(Ljavax/crypto/spec/OAEPParameterSpec;)V
.registers 7
invoke-virtual {p1}, Ljavax/crypto/spec/OAEPParameterSpec;->getMGFAlgorithm()Ljava/lang/String;
move-result-object v0
sget-object v1, Ljava/util/Locale;->US:Ljava/util/Locale;
invoke-virtual {v0, v1}, Ljava/lang/String;->toUpperCase(Ljava/util/Locale;)Ljava/lang/String;
move-result-object v0
invoke-virtual {p1}, Ljavax/crypto/spec/OAEPParameterSpec;->getMGFParameters()Ljava/security/spec/AlgorithmParameterSpec;
move-result-object v2
const-string v3, "MGF1"
invoke-virtual {v3, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v3
if-nez v3, :cond_1e
const-string v3, "1.2.840.113549.1.1.8"
invoke-virtual {v3, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_6e
:cond_1e
instance-of v0, v2, Ljava/security/spec/MGF1ParameterSpec;
if-eqz v0, :cond_6e
check-cast v2, Ljava/security/spec/MGF1ParameterSpec;
invoke-virtual {p1}, Ljavax/crypto/spec/OAEPParameterSpec;->getDigestAlgorithm()Ljava/lang/String;
move-result-object v0
invoke-virtual {v0, v1}, Ljava/lang/String;->toUpperCase(Ljava/util/Locale;)Ljava/lang/String;
move-result-object v0
:try_start_2c
invoke-static {v0}, Lorg/conscrypt/EvpMdRef;->getEVP_MDByJcaDigestAlgorithmStandardName(Ljava/lang/String;)J
move-result-wide v3
iput-wide v3, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMd:J
invoke-static {v0}, Lorg/conscrypt/EvpMdRef;->getDigestSizeBytesByJcaDigestAlgorithmStandardName(Ljava/lang/String;)I
move-result v0
iput v0, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMdSizeBytes:I
invoke-virtual {v2}, Ljava/security/spec/MGF1ParameterSpec;->getDigestAlgorithm()Ljava/lang/String;
move-result-object v0
invoke-static {v0}, Lorg/conscrypt/EvpMdRef;->getEVP_MDByJcaDigestAlgorithmStandardName(Ljava/lang/String;)J
move-result-wide v0
iput-wide v0, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->mgf1Md:J
:try_end_42
.catch Ljava/security/NoSuchAlgorithmException; {:try_start_2c .. :try_end_42} :catch_67
invoke-virtual {p1}, Ljavax/crypto/spec/OAEPParameterSpec;->getPSource()Ljavax/crypto/spec/PSource;
move-result-object p1
invoke-virtual {p1}, Ljavax/crypto/spec/PSource;->getAlgorithm()Ljava/lang/String;
move-result-object v0
const-string v1, "PSpecified"
invoke-virtual {v1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_5f
instance-of v0, p1, Ljavax/crypto/spec/PSource$PSpecified;
if-eqz v0, :cond_5f
check-cast p1, Ljavax/crypto/spec/PSource$PSpecified;
invoke-virtual {p1}, Ljavax/crypto/spec/PSource$PSpecified;->getValue()[B
move-result-object p1
iput-object p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->label:[B
return-void
:cond_5f
new-instance p1, Ljava/security/InvalidAlgorithmParameterException;
const-string v0, "Only PSpecified accepted for PSource"
invoke-direct {p1, v0}, Ljava/security/InvalidAlgorithmParameterException;-><init>(Ljava/lang/String;)V
throw p1
:catch_67
move-exception p1
new-instance v0, Ljava/security/InvalidAlgorithmParameterException;
invoke-direct {v0, p1}, Ljava/security/InvalidAlgorithmParameterException;-><init>(Ljava/lang/Throwable;)V
throw v0
:cond_6e
new-instance p1, Ljava/security/InvalidAlgorithmParameterException;
const-string v0, "Only MGF1 supported as mask generation function"
invoke-direct {p1, v0}, Ljava/security/InvalidAlgorithmParameterException;-><init>(Ljava/lang/String;)V
throw p1
.end method
# virtual methods
.method doCryptoInit(Ljava/security/spec/AlgorithmParameterSpec;)V
.registers 6
new-instance v0, Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
iget-boolean v1, p0, Lorg/conscrypt/OpenSSLCipherRSA;->encrypting:Z
if-eqz v1, :cond_11
iget-object v1, p0, Lorg/conscrypt/OpenSSLCipherRSA;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v1}, Lorg/conscrypt/OpenSSLKey;->getNativeRef()Lorg/conscrypt/NativeRef$EVP_PKEY;
move-result-object v1
invoke-static {v1}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_encrypt_init(Lorg/conscrypt/NativeRef$EVP_PKEY;)J
move-result-wide v1
goto :goto_1b
:cond_11
iget-object v1, p0, Lorg/conscrypt/OpenSSLCipherRSA;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v1}, Lorg/conscrypt/OpenSSLKey;->getNativeRef()Lorg/conscrypt/NativeRef$EVP_PKEY;
move-result-object v1
invoke-static {v1}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_decrypt_init(Lorg/conscrypt/NativeRef$EVP_PKEY;)J
move-result-wide v1
:goto_1b
invoke-direct {v0, v1, v2}, Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;-><init>(J)V
iput-object v0, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
instance-of v0, p1, Ljavax/crypto/spec/OAEPParameterSpec;
if-eqz v0, :cond_29
check-cast p1, Ljavax/crypto/spec/OAEPParameterSpec;
invoke-direct {p0, p1}, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->readOAEPParameters(Ljavax/crypto/spec/OAEPParameterSpec;)V
:cond_29
iget-object p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
iget-wide v0, p1, Lorg/conscrypt/NativeRef;->address:J
const/4 p1, 0x4
invoke-static {v0, v1, p1}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_CTX_set_rsa_padding(JI)V
iget-object p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
iget-wide v0, p1, Lorg/conscrypt/NativeRef;->address:J
iget-wide v2, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMd:J
invoke-static {v0, v1, v2, v3}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_CTX_set_rsa_oaep_md(JJ)V
iget-object p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
iget-wide v0, p1, Lorg/conscrypt/NativeRef;->address:J
iget-wide v2, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->mgf1Md:J
invoke-static {v0, v1, v2, v3}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_CTX_set_rsa_mgf1_md(JJ)V
iget-object p1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->label:[B
if-eqz p1, :cond_51
array-length v0, p1
if-lez v0, :cond_51
iget-object v0, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
iget-wide v0, v0, Lorg/conscrypt/NativeRef;->address:J
invoke-static {v0, v1, p1}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_CTX_set_rsa_oaep_label(J[B)V
:cond_51
return-void
.end method
.method doCryptoOperation([B[B)I
.registers 10
iget-boolean v0, p0, Lorg/conscrypt/OpenSSLCipherRSA;->encrypting:Z
if-eqz v0, :cond_10
iget-object v1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
const/4 v3, 0x0
const/4 v5, 0x0
array-length v6, p1
move-object v2, p2
move-object v4, p1
invoke-static/range {v1 .. v6}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_encrypt(Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;[BI[BII)I
move-result p1
return p1
:cond_10
iget-object v0, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->pkeyCtx:Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;
const/4 v2, 0x0
const/4 v4, 0x0
array-length v5, p1
move-object v1, p2
move-object v3, p1
invoke-static/range {v0 .. v5}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_decrypt(Lorg/conscrypt/NativeRef$EVP_PKEY_CTX;[BI[BII)I
move-result p1
return p1
.end method
.method protected engineGetParameters()Ljava/security/AlgorithmParameters;
.registers 9
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLCipherRSA;->isInitialized()Z
move-result v0
if-nez v0, :cond_8
const/4 v0, 0x0
return-object v0
:cond_8
:try_start_8
const-string v0, "OAEP"
invoke-static {v0}, Ljava/security/AlgorithmParameters;->getInstance(Ljava/lang/String;)Ljava/security/AlgorithmParameters;
move-result-object v0
iget-object v1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->label:[B
if-nez v1, :cond_15
sget-object v1, Ljavax/crypto/spec/PSource$PSpecified;->DEFAULT:Ljavax/crypto/spec/PSource$PSpecified;
goto :goto_1c
:cond_15
new-instance v1, Ljavax/crypto/spec/PSource$PSpecified;
iget-object v2, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->label:[B
invoke-direct {v1, v2}, Ljavax/crypto/spec/PSource$PSpecified;-><init>([B)V
:goto_1c
new-instance v2, Ljavax/crypto/spec/OAEPParameterSpec;
iget-wide v3, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMd:J
invoke-static {v3, v4}, Lorg/conscrypt/EvpMdRef;->getJcaDigestAlgorithmStandardNameFromEVP_MD(J)Ljava/lang/String;
move-result-object v3
const-string v4, "MGF1"
new-instance v5, Ljava/security/spec/MGF1ParameterSpec;
iget-wide v6, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->mgf1Md:J
invoke-static {v6, v7}, Lorg/conscrypt/EvpMdRef;->getJcaDigestAlgorithmStandardNameFromEVP_MD(J)Ljava/lang/String;
move-result-object v6
invoke-direct {v5, v6}, Ljava/security/spec/MGF1ParameterSpec;-><init>(Ljava/lang/String;)V
invoke-direct {v2, v3, v4, v5, v1}, Ljavax/crypto/spec/OAEPParameterSpec;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/security/spec/AlgorithmParameterSpec;Ljavax/crypto/spec/PSource;)V
invoke-virtual {v0, v2}, Ljava/security/AlgorithmParameters;->init(Ljava/security/spec/AlgorithmParameterSpec;)V
:try_end_37
.catch Ljava/security/NoSuchAlgorithmException; {:try_start_8 .. :try_end_37} :catch_40
.catch Ljava/security/spec/InvalidParameterSpecException; {:try_start_8 .. :try_end_37} :catch_38
return-object v0
:catch_38
new-instance v0, Ljava/lang/RuntimeException;
const-string v1, "No providers of AlgorithmParameters.OAEP available"
invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V
throw v0
:catch_40
move-exception v0
new-instance v1, Ljava/lang/AssertionError;
const-string v2, "OAEP not supported"
invoke-direct {v1, v2}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V
invoke-virtual {v1, v0}, Ljava/lang/AssertionError;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;
move-result-object v0
check-cast v0, Ljava/lang/Error;
throw v0
.end method
.method protected engineInit(ILjava/security/Key;Ljava/security/AlgorithmParameters;Ljava/security/SecureRandom;)V
.registers 5
if-eqz p3, :cond_14
:try_start_2
const-class p4, Ljavax/crypto/spec/OAEPParameterSpec;
invoke-virtual {p3, p4}, Ljava/security/AlgorithmParameters;->getParameterSpec(Ljava/lang/Class;)Ljava/security/spec/AlgorithmParameterSpec;
move-result-object p3
check-cast p3, Ljavax/crypto/spec/OAEPParameterSpec;
:try_end_a
.catch Ljava/security/spec/InvalidParameterSpecException; {:try_start_2 .. :try_end_a} :catch_b
goto :goto_15
:catch_b
move-exception p1
new-instance p2, Ljava/security/InvalidAlgorithmParameterException;
const-string p3, "Only OAEP parameters are supported"
invoke-direct {p2, p3, p1}, Ljava/security/InvalidAlgorithmParameterException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V
throw p2
:cond_14
const/4 p3, 0x0
:goto_15
invoke-virtual {p0, p1, p2, p3}, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->engineInitInternal(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V
return-void
.end method
.method protected engineInit(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)V
.registers 5
if-eqz p3, :cond_f
instance-of p4, p3, Ljavax/crypto/spec/OAEPParameterSpec;
if-eqz p4, :cond_7
goto :goto_f
:cond_7
new-instance p1, Ljava/security/InvalidAlgorithmParameterException;
const-string p2, "Only OAEPParameterSpec accepted in OAEP mode"
invoke-direct {p1, p2}, Ljava/security/InvalidAlgorithmParameterException;-><init>(Ljava/lang/String;)V
throw p1
:cond_f
:goto_f
invoke-virtual {p0, p1, p2, p3}, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->engineInitInternal(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V
return-void
.end method
.method engineInitInternal(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V
.registers 5
const/4 v0, 0x1
if-eq p1, v0, :cond_1a
const/4 v0, 0x3
if-ne p1, v0, :cond_7
goto :goto_1a
:cond_7
const/4 v0, 0x2
if-eq p1, v0, :cond_d
const/4 v0, 0x4
if-ne p1, v0, :cond_1e
:cond_d
instance-of v0, p2, Ljava/security/PrivateKey;
if-eqz v0, :cond_12
goto :goto_1e
:cond_12
new-instance p1, Ljava/security/InvalidKeyException;
const-string p2, "Only private keys may be used to decrypt"
invoke-direct {p1, p2}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/String;)V
throw p1
:cond_1a
:goto_1a
instance-of v0, p2, Ljava/security/PublicKey;
if-eqz v0, :cond_22
:cond_1e
:goto_1e
invoke-super {p0, p1, p2, p3}, Lorg/conscrypt/OpenSSLCipherRSA;->engineInitInternal(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V
return-void
:cond_22
new-instance p1, Ljava/security/InvalidKeyException;
const-string p2, "Only public keys may be used to encrypt"
invoke-direct {p1, p2}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/String;)V
throw p1
.end method
.method protected engineSetPadding(Ljava/lang/String;)V
.registers 3
sget-object v0, Ljava/util/Locale;->US:Ljava/util/Locale;
invoke-virtual {p1, v0}, Ljava/lang/String;->toUpperCase(Ljava/util/Locale;)Ljava/lang/String;
move-result-object p1
const-string v0, "OAEPPADDING"
invoke-virtual {p1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result p1
if-eqz p1, :cond_12
const/4 p1, 0x4
iput p1, p0, Lorg/conscrypt/OpenSSLCipherRSA;->padding:I
return-void
:cond_12
new-instance p1, Ljavax/crypto/NoSuchPaddingException;
const-string v0, "Only OAEP padding is supported"
invoke-direct {p1, v0}, Ljavax/crypto/NoSuchPaddingException;-><init>(Ljava/lang/String;)V
throw p1
.end method
.method paddedBlockSizeBytes()I
.registers 3
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLCipherRSA;->keySizeBytes()I
move-result v0
iget v1, p0, Lorg/conscrypt/OpenSSLCipherRSA$OAEP;->oaepMdSizeBytes:I
mul-int/lit8 v1, v1, 0x2
add-int/lit8 v1, v1, 0x2
sub-int/2addr v0, v1
return v0
.end method