ECIESKeyEncapsulation.smali
.class public Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;
.super Ljava/lang/Object;
.source "ECIESKeyEncapsulation.java"
# interfaces
.implements Lorg/spongycastle/crypto/KeyEncapsulation;
# static fields
.field private static final ONE:Ljava/math/BigInteger;
# instance fields
.field private CofactorMode:Z
.field private OldCofactorMode:Z
.field private SingleHashMode:Z
.field private kdf:Lorg/spongycastle/crypto/DerivationFunction;
.field private key:Lorg/spongycastle/crypto/params/ECKeyParameters;
.field private rnd:Ljava/security/SecureRandom;
# direct methods
.method static constructor <clinit>()V
.registers 2
.prologue
.line 28
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/ECIESKeyEncapsulation;->ONE:Ljava/math/BigInteger;
return-void
.end method
.method public constructor <init>(Lorg/spongycastle/crypto/DerivationFunction;Ljava/security/SecureRandom;)V
.registers 4
.prologue
const/4 v0, 0x0
.line 46
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 47
iput-object p1, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
.line 48
iput-object p2, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->rnd:Ljava/security/SecureRandom;
.line 49
iput-boolean v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->CofactorMode:Z
.line 50
iput-boolean v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->OldCofactorMode:Z
.line 51
iput-boolean v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->SingleHashMode:Z
.line 52
return-void
.end method
.method public constructor <init>(Lorg/spongycastle/crypto/DerivationFunction;Ljava/security/SecureRandom;ZZZ)V
.registers 6
.prologue
.line 69
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 70
iput-object p1, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
.line 71
iput-object p2, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->rnd:Ljava/security/SecureRandom;
.line 75
iput-boolean p3, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->CofactorMode:Z
.line 76
iput-boolean p4, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->OldCofactorMode:Z
.line 77
iput-boolean p5, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->SingleHashMode:Z
.line 78
return-void
.end method
# virtual methods
.method protected createBasePointMultiplier()Lorg/spongycastle/math/ec/ECMultiplier;
.registers 2
.prologue
.line 225
new-instance v0, Lorg/spongycastle/math/ec/FixedPointCombMultiplier;
invoke-direct {v0}, Lorg/spongycastle/math/ec/FixedPointCombMultiplier;-><init>()V
return-object v0
.end method
.method public decrypt([BI)Lorg/spongycastle/crypto/CipherParameters;
.registers 5
.prologue
.line 220
const/4 v0, 0x0
array-length v1, p1
invoke-virtual {p0, p1, v0, v1, p2}, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->decrypt([BIII)Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
return-object v0
.end method
.method public decrypt([BIII)Lorg/spongycastle/crypto/CipherParameters;
.registers 11
.prologue
.line 172
iget-object v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/ECKeyParameters;
instance-of v0, v0, Lorg/spongycastle/crypto/params/ECPrivateKeyParameters;
if-nez v0, :cond_e
.line 174
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "Private key required for encryption"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 177
:cond_e
iget-object v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/ECKeyParameters;
check-cast v0, Lorg/spongycastle/crypto/params/ECPrivateKeyParameters;
.line 178
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECPrivateKeyParameters;->getParameters()Lorg/spongycastle/crypto/params/ECDomainParameters;
move-result-object v1
.line 179
invoke-virtual {v1}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getCurve()Lorg/spongycastle/math/ec/ECCurve;
move-result-object v2
.line 180
invoke-virtual {v1}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getN()Ljava/math/BigInteger;
move-result-object v3
.line 181
invoke-virtual {v1}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getH()Ljava/math/BigInteger;
move-result-object v4
.line 184
new-array v5, p3, [B
.line 185
const/4 v1, 0x0
invoke-static {p1, p2, v5, v1, p3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 188
invoke-virtual {v2, v5}, Lorg/spongycastle/math/ec/ECCurve;->decodePoint([B)Lorg/spongycastle/math/ec/ECPoint;
move-result-object v1
.line 192
iget-boolean v2, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->CofactorMode:Z
if-nez v2, :cond_34
iget-boolean v2, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->OldCofactorMode:Z
if-eqz v2, :cond_38
.line 194
:cond_34
invoke-virtual {v1, v4}, Lorg/spongycastle/math/ec/ECPoint;->multiply(Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;
move-result-object v1
.line 197
:cond_38
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECPrivateKeyParameters;->getD()Ljava/math/BigInteger;
move-result-object v0
.line 198
iget-boolean v2, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->CofactorMode:Z
if-eqz v2, :cond_4c
.line 200
invoke-virtual {v4, v3}, Ljava/math/BigInteger;->modInverse(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v2
invoke-virtual {v0, v2}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v0
invoke-virtual {v0, v3}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v0
.line 203
:cond_4c
invoke-virtual {v1, v0}, Lorg/spongycastle/math/ec/ECPoint;->multiply(Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;
move-result-object v0
invoke-virtual {v0}, Lorg/spongycastle/math/ec/ECPoint;->normalize()Lorg/spongycastle/math/ec/ECPoint;
move-result-object v0
.line 206
invoke-virtual {v0}, Lorg/spongycastle/math/ec/ECPoint;->getAffineXCoord()Lorg/spongycastle/math/ec/ECFieldElement;
move-result-object v0
invoke-virtual {v0}, Lorg/spongycastle/math/ec/ECFieldElement;->getEncoded()[B
move-result-object v0
.line 208
invoke-virtual {p0, p4, v5, v0}, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->deriveKey(I[B[B)Lorg/spongycastle/crypto/params/KeyParameter;
move-result-object v0
return-object v0
.end method
.method protected deriveKey(I[B[B)Lorg/spongycastle/crypto/params/KeyParameter;
.registers 8
.prologue
const/4 v3, 0x0
.line 230
.line 231
iget-boolean v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->SingleHashMode:Z
if-eqz v0, :cond_d
.line 233
invoke-static {p2, p3}, Lorg/spongycastle/util/Arrays;->concatenate([B[B)[B
move-result-object v0
.line 234
invoke-static {p3, v3}, Lorg/spongycastle/util/Arrays;->fill([BB)V
move-object p3, v0
.line 240
:cond_d
:try_start_d
iget-object v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
new-instance v1, Lorg/spongycastle/crypto/params/KDFParameters;
const/4 v2, 0x0
invoke-direct {v1, p3, v2}, Lorg/spongycastle/crypto/params/KDFParameters;-><init>([B[B)V
invoke-interface {v0, v1}, Lorg/spongycastle/crypto/DerivationFunction;->init(Lorg/spongycastle/crypto/DerivationParameters;)V
.line 243
new-array v0, p1, [B
.line 244
iget-object v1, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->kdf:Lorg/spongycastle/crypto/DerivationFunction;
const/4 v2, 0x0
invoke-interface {v1, v0, v2, p1}, Lorg/spongycastle/crypto/DerivationFunction;->generateBytes([BII)I
.line 247
new-instance v1, Lorg/spongycastle/crypto/params/KeyParameter;
invoke-direct {v1, v0}, Lorg/spongycastle/crypto/params/KeyParameter;-><init>([B)V
:try_end_25
.catchall {:try_start_d .. :try_end_25} :catchall_29
.line 251
invoke-static {p3, v3}, Lorg/spongycastle/util/Arrays;->fill([BB)V
return-object v1
:catchall_29
move-exception v0
invoke-static {p3, v3}, Lorg/spongycastle/util/Arrays;->fill([BB)V
throw v0
.end method
.method public encrypt([BI)Lorg/spongycastle/crypto/CipherParameters;
.registers 4
.prologue
.line 157
const/4 v0, 0x0
invoke-virtual {p0, p1, v0, p2}, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->encrypt([BII)Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
return-object v0
.end method
.method public encrypt([BII)Lorg/spongycastle/crypto/CipherParameters;
.registers 13
.prologue
const/4 v8, 0x1
const/4 v7, 0x0
.line 109
iget-object v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/ECKeyParameters;
instance-of v0, v0, Lorg/spongycastle/crypto/params/ECPublicKeyParameters;
if-nez v0, :cond_10
.line 111
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 114
:cond_10
iget-object v0, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/ECKeyParameters;
check-cast v0, Lorg/spongycastle/crypto/params/ECPublicKeyParameters;
.line 115
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECPublicKeyParameters;->getParameters()Lorg/spongycastle/crypto/params/ECDomainParameters;
move-result-object v3
.line 116
invoke-virtual {v3}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getCurve()Lorg/spongycastle/math/ec/ECCurve;
move-result-object v4
.line 117
invoke-virtual {v3}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getN()Ljava/math/BigInteger;
move-result-object v1
.line 118
invoke-virtual {v3}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getH()Ljava/math/BigInteger;
move-result-object v5
.line 121
sget-object v2, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->ONE:Ljava/math/BigInteger;
iget-object v6, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->rnd:Ljava/security/SecureRandom;
invoke-static {v2, v1, v6}, Lorg/spongycastle/util/BigIntegers;->createRandomInRange(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/security/SecureRandom;)Ljava/math/BigInteger;
move-result-object v2
.line 124
iget-boolean v6, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->CofactorMode:Z
if-eqz v6, :cond_6f
invoke-virtual {v2, v5}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v5
invoke-virtual {v5, v1}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 126
:goto_38
invoke-virtual {p0}, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->createBasePointMultiplier()Lorg/spongycastle/math/ec/ECMultiplier;
move-result-object v5
.line 128
const/4 v6, 0x2
new-array v6, v6, [Lorg/spongycastle/math/ec/ECPoint;
.line 129
invoke-virtual {v3}, Lorg/spongycastle/crypto/params/ECDomainParameters;->getG()Lorg/spongycastle/math/ec/ECPoint;
move-result-object v3
invoke-interface {v5, v3, v2}, Lorg/spongycastle/math/ec/ECMultiplier;->multiply(Lorg/spongycastle/math/ec/ECPoint;Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;
move-result-object v2
aput-object v2, v6, v7
.line 130
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ECPublicKeyParameters;->getQ()Lorg/spongycastle/math/ec/ECPoint;
move-result-object v0
invoke-virtual {v0, v1}, Lorg/spongycastle/math/ec/ECPoint;->multiply(Ljava/math/BigInteger;)Lorg/spongycastle/math/ec/ECPoint;
move-result-object v0
aput-object v0, v6, v8
.line 134
invoke-virtual {v4, v6}, Lorg/spongycastle/math/ec/ECCurve;->normalizeAll([Lorg/spongycastle/math/ec/ECPoint;)V
.line 136
aget-object v0, v6, v7
aget-object v1, v6, v8
.line 139
invoke-virtual {v0, v7}, Lorg/spongycastle/math/ec/ECPoint;->getEncoded(Z)[B
move-result-object v0
.line 140
array-length v2, v0
invoke-static {v0, v7, p1, p2, v2}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 143
invoke-virtual {v1}, Lorg/spongycastle/math/ec/ECPoint;->getAffineXCoord()Lorg/spongycastle/math/ec/ECFieldElement;
move-result-object v1
invoke-virtual {v1}, Lorg/spongycastle/math/ec/ECFieldElement;->getEncoded()[B
move-result-object v1
.line 145
invoke-virtual {p0, p3, v0, v1}, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->deriveKey(I[B[B)Lorg/spongycastle/crypto/params/KeyParameter;
move-result-object v0
return-object v0
:cond_6f
move-object v1, v2
.line 124
goto :goto_38
.end method
.method public init(Lorg/spongycastle/crypto/CipherParameters;)V
.registers 4
.prologue
.line 88
instance-of v0, p1, Lorg/spongycastle/crypto/params/ECKeyParameters;
if-nez v0, :cond_c
.line 90
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "EC key required"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 94
:cond_c
check-cast p1, Lorg/spongycastle/crypto/params/ECKeyParameters;
iput-object p1, p0, Lorg/spongycastle/crypto/kems/ECIESKeyEncapsulation;->key:Lorg/spongycastle/crypto/params/ECKeyParameters;
.line 96
return-void
.end method