TlsRSAUtils.smali
.class public Lorg/spongycastle/crypto/tls/TlsRSAUtils;
.super Ljava/lang/Object;
.source "TlsRSAUtils.java"
# direct methods
.method public constructor <init>()V
.registers 1
.prologue
.line 13
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static generateEncryptedPreMasterSecret(Lorg/spongycastle/crypto/tls/TlsContext;Lorg/spongycastle/crypto/params/RSAKeyParameters;Ljava/io/OutputStream;)[B
.registers 8
.prologue
const/16 v0, 0x30
const/4 v2, 0x0
.line 21
new-array v0, v0, [B
.line 22
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getSecureRandom()Ljava/security/SecureRandom;
move-result-object v1
invoke-virtual {v1, v0}, Ljava/security/SecureRandom;->nextBytes([B)V
.line 23
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getClientVersion()Lorg/spongycastle/crypto/tls/ProtocolVersion;
move-result-object v1
invoke-static {v1, v0, v2}, Lorg/spongycastle/crypto/tls/TlsUtils;->writeVersion(Lorg/spongycastle/crypto/tls/ProtocolVersion;[BI)V
.line 25
new-instance v1, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;
new-instance v2, Lorg/spongycastle/crypto/engines/RSABlindedEngine;
invoke-direct {v2}, Lorg/spongycastle/crypto/engines/RSABlindedEngine;-><init>()V
invoke-direct {v1, v2}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;-><init>(Lorg/spongycastle/crypto/AsymmetricBlockCipher;)V
.line 26
const/4 v2, 0x1
new-instance v3, Lorg/spongycastle/crypto/params/ParametersWithRandom;
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getSecureRandom()Ljava/security/SecureRandom;
move-result-object v4
invoke-direct {v3, p1, v4}, Lorg/spongycastle/crypto/params/ParametersWithRandom;-><init>(Lorg/spongycastle/crypto/CipherParameters;Ljava/security/SecureRandom;)V
invoke-virtual {v1, v2, v3}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 30
const/4 v2, 0x0
const/16 v3, 0x30
:try_start_2d
invoke-virtual {v1, v0, v2, v3}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;->processBlock([BII)[B
move-result-object v1
.line 32
invoke-static {p0}, Lorg/spongycastle/crypto/tls/TlsUtils;->isSSL(Lorg/spongycastle/crypto/tls/TlsContext;)Z
move-result v2
if-eqz v2, :cond_3b
.line 35
invoke-virtual {p2, v1}, Ljava/io/OutputStream;->write([B)V
.line 50
:goto_3a
return-object v0
.line 39
:cond_3b
invoke-static {v1, p2}, Lorg/spongycastle/crypto/tls/TlsUtils;->writeOpaque16([BLjava/io/OutputStream;)V
:try_end_3e
.catch Lorg/spongycastle/crypto/InvalidCipherTextException; {:try_start_2d .. :try_end_3e} :catch_3f
goto :goto_3a
.line 42
:catch_3f
move-exception v0
.line 47
new-instance v1, Lorg/spongycastle/crypto/tls/TlsFatalAlert;
const/16 v2, 0x50
invoke-direct {v1, v2, v0}, Lorg/spongycastle/crypto/tls/TlsFatalAlert;-><init>(SLjava/lang/Throwable;)V
throw v1
.end method
.method public static safeDecryptPreMasterSecret(Lorg/spongycastle/crypto/tls/TlsContext;Lorg/spongycastle/crypto/params/RSAKeyParameters;[B)[B
.registers 12
.prologue
const/16 v8, 0x30
const/4 v1, 0x0
.line 59
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getClientVersion()Lorg/spongycastle/crypto/tls/ProtocolVersion;
move-result-object v2
.line 68
new-array v3, v8, [B
.line 69
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getSecureRandom()Ljava/security/SecureRandom;
move-result-object v0
invoke-virtual {v0, v3}, Ljava/security/SecureRandom;->nextBytes([B)V
.line 71
invoke-static {v3}, Lorg/spongycastle/util/Arrays;->clone([B)[B
move-result-object v0
.line 74
:try_start_14
new-instance v4, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;
new-instance v5, Lorg/spongycastle/crypto/engines/RSABlindedEngine;
invoke-direct {v5}, Lorg/spongycastle/crypto/engines/RSABlindedEngine;-><init>()V
invoke-direct {v4, v5, v3}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;-><init>(Lorg/spongycastle/crypto/AsymmetricBlockCipher;[B)V
.line 75
const/4 v5, 0x0
new-instance v6, Lorg/spongycastle/crypto/params/ParametersWithRandom;
.line 76
invoke-interface {p0}, Lorg/spongycastle/crypto/tls/TlsContext;->getSecureRandom()Ljava/security/SecureRandom;
move-result-object v7
invoke-direct {v6, p1, v7}, Lorg/spongycastle/crypto/params/ParametersWithRandom;-><init>(Lorg/spongycastle/crypto/CipherParameters;Ljava/security/SecureRandom;)V
.line 75
invoke-virtual {v4, v5, v6}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 78
const/4 v5, 0x0
array-length v6, p2
invoke-virtual {v4, p2, v5, v6}, Lorg/spongycastle/crypto/encodings/PKCS1Encoding;->processBlock([BII)[B
:try_end_30
.catch Ljava/lang/Exception; {:try_start_14 .. :try_end_30} :catch_66
move-result-object v0
.line 114
:goto_31
invoke-virtual {v2}, Lorg/spongycastle/crypto/tls/ProtocolVersion;->getMajorVersion()I
move-result v4
aget-byte v5, v0, v1
and-int/lit16 v5, v5, 0xff
xor-int/2addr v4, v5
.line 115
invoke-virtual {v2}, Lorg/spongycastle/crypto/tls/ProtocolVersion;->getMinorVersion()I
move-result v2
const/4 v5, 0x1
aget-byte v5, v0, v5
and-int/lit16 v5, v5, 0xff
xor-int/2addr v2, v5
or-int/2addr v2, v4
.line 116
shr-int/lit8 v4, v2, 0x1
or-int/2addr v2, v4
.line 117
shr-int/lit8 v4, v2, 0x2
or-int/2addr v2, v4
.line 118
shr-int/lit8 v4, v2, 0x4
or-int/2addr v2, v4
.line 119
and-int/lit8 v2, v2, 0x1
add-int/lit8 v2, v2, -0x1
xor-int/lit8 v2, v2, -0x1
.line 124
:goto_54
if-ge v1, v8, :cond_65
.line 126
aget-byte v4, v0, v1
xor-int/lit8 v5, v2, -0x1
and-int/2addr v4, v5
aget-byte v5, v3, v1
and-int/2addr v5, v2
or-int/2addr v4, v5
int-to-byte v4, v4
aput-byte v4, v0, v1
.line 124
add-int/lit8 v1, v1, 0x1
goto :goto_54
.line 129
:cond_65
return-object v0
:catch_66
move-exception v4
goto :goto_31
.end method