RSAKeyEncapsulation.smali
.class public Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;
.super Ljava/lang/Object;
.source "RSAKeyEncapsulation.java"
# interfaces
.implements Lorg/spongycastle/crypto/KeyEncapsulation;
# static fields
.field private static final ONE:Ljava/math/BigInteger;
.field private static final ZERO:Ljava/math/BigInteger;
# instance fields
.field private kdf:Lorg/spongycastle/crypto/DerivationFunction;
.field private key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
.field private rnd:Ljava/security/SecureRandom;
# direct methods
.method static constructor <clinit>()V
.registers 2
.prologue
.line 20
const-wide/16 v0, 0x0
invoke-static {v0, v1}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v0
sput-object v0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->ZERO:Ljava/math/BigInteger;
.line 21
const-wide/16 v0, 0x1
invoke-static {v0, v1}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v0
sput-object v0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->ONE:Ljava/math/BigInteger;
return-void
.end method
.method public constructor <init>(Lorg/spongycastle/crypto/DerivationFunction;Ljava/security/SecureRandom;)V
.registers 3
.prologue
.line 36
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 37
iput-object p1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
.line 38
iput-object p2, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->rnd:Ljava/security/SecureRandom;
.line 39
return-void
.end method
# virtual methods
.method public decrypt([BI)Lorg/spongycastle/crypto/CipherParameters;
.registers 5
.prologue
.line 139
const/4 v0, 0x0
array-length v1, p1
invoke-virtual {p0, p1, v0, v1, p2}, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->decrypt([BIII)Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
return-object v0
.end method
.method public decrypt([BIII)Lorg/spongycastle/crypto/CipherParameters;
.registers 10
.prologue
.line 111
iget-object v0, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->isPrivate()Z
move-result v0
if-nez v0, :cond_10
.line 113
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "Private key required for decryption"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 116
:cond_10
iget-object v0, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->getModulus()Ljava/math/BigInteger;
move-result-object v0
.line 117
iget-object v1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v1}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->getExponent()Ljava/math/BigInteger;
move-result-object v1
.line 120
new-array v2, p3, [B
.line 121
const/4 v3, 0x0
invoke-static {p1, p2, v2, v3, p3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 122
new-instance v3, Ljava/math/BigInteger;
const/4 v4, 0x1
invoke-direct {v3, v4, v2}, Ljava/math/BigInteger;-><init>(I[B)V
.line 125
invoke-virtual {v3, v1, v0}, Ljava/math/BigInteger;->modPow(Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 127
invoke-virtual {p0, v0, v1, p4}, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->generateKey(Ljava/math/BigInteger;Ljava/math/BigInteger;I)Lorg/spongycastle/crypto/params/KeyParameter;
move-result-object v0
return-object v0
.end method
.method public encrypt([BI)Lorg/spongycastle/crypto/CipherParameters;
.registers 4
.prologue
.line 96
const/4 v0, 0x0
invoke-virtual {p0, p1, v0, p2}, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->encrypt([BII)Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
return-object v0
.end method
.method public encrypt([BII)Lorg/spongycastle/crypto/CipherParameters;
.registers 9
.prologue
.line 68
iget-object v0, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->isPrivate()Z
move-result v0
if-eqz v0, :cond_10
.line 70
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "Public key required for encryption"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 73
:cond_10
iget-object v0, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->getModulus()Ljava/math/BigInteger;
move-result-object v0
.line 74
iget-object v1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
invoke-virtual {v1}, Lorg/spongycastle/crypto/params/RSAKeyParameters;->getExponent()Ljava/math/BigInteger;
move-result-object v1
.line 77
sget-object v2, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->ZERO:Ljava/math/BigInteger;
sget-object v3, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->ONE:Ljava/math/BigInteger;
invoke-virtual {v0, v3}, Ljava/math/BigInteger;->subtract(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v3
iget-object v4, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->rnd:Ljava/security/SecureRandom;
invoke-static {v2, v3, v4}, Lorg/spongycastle/util/BigIntegers;->createRandomInRange(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/security/SecureRandom;)Ljava/math/BigInteger;
move-result-object v2
.line 80
invoke-virtual {v2, v1, v0}, Ljava/math/BigInteger;->modPow(Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 81
invoke-virtual {v0}, Ljava/math/BigInteger;->bitLength()I
move-result v3
add-int/lit8 v3, v3, 0x7
div-int/lit8 v3, v3, 0x8
invoke-static {v3, v1}, Lorg/spongycastle/util/BigIntegers;->asUnsignedByteArray(ILjava/math/BigInteger;)[B
move-result-object v1
.line 82
const/4 v3, 0x0
array-length v4, v1
invoke-static {v1, v3, p1, p2, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 84
invoke-virtual {p0, v0, v2, p3}, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->generateKey(Ljava/math/BigInteger;Ljava/math/BigInteger;I)Lorg/spongycastle/crypto/params/KeyParameter;
move-result-object v0
return-object v0
.end method
.method protected generateKey(Ljava/math/BigInteger;Ljava/math/BigInteger;I)Lorg/spongycastle/crypto/params/KeyParameter;
.registers 8
.prologue
.line 144
invoke-virtual {p1}, Ljava/math/BigInteger;->bitLength()I
move-result v0
add-int/lit8 v0, v0, 0x7
div-int/lit8 v0, v0, 0x8
invoke-static {v0, p2}, Lorg/spongycastle/util/BigIntegers;->asUnsignedByteArray(ILjava/math/BigInteger;)[B
move-result-object v0
.line 147
iget-object v1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
new-instance v2, Lorg/spongycastle/crypto/params/KDFParameters;
const/4 v3, 0x0
invoke-direct {v2, v0, v3}, Lorg/spongycastle/crypto/params/KDFParameters;-><init>([B[B)V
invoke-interface {v1, v2}, Lorg/spongycastle/crypto/DerivationFunction;->init(Lorg/spongycastle/crypto/DerivationParameters;)V
.line 150
new-array v0, p3, [B
.line 151
iget-object v1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
const/4 v2, 0x0
invoke-interface {v1, v0, v2, p3}, Lorg/spongycastle/crypto/DerivationFunction;->generateBytes([BII)I
.line 153
new-instance v1, Lorg/spongycastle/crypto/params/KeyParameter;
invoke-direct {v1, v0}, Lorg/spongycastle/crypto/params/KeyParameter;-><init>([B)V
return-object v1
.end method
.method public init(Lorg/spongycastle/crypto/CipherParameters;)V
.registers 4
.prologue
.line 49
instance-of v0, p1, Lorg/spongycastle/crypto/params/RSAKeyParameters;
if-nez v0, :cond_c
.line 51
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "RSA key required"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 54
:cond_c
check-cast p1, Lorg/spongycastle/crypto/params/RSAKeyParameters;
iput-object p1, p0, Lorg/spongycastle/crypto/kems/RSAKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/RSAKeyParameters;
.line 55
return-void
.end method