DESedeWrapEngine.smali
.class public Lorg/spongycastle/crypto/engines/DESedeWrapEngine;
.super Ljava/lang/Object;
.source "DESedeWrapEngine.java"
# interfaces
.implements Lorg/spongycastle/crypto/Wrapper;
# static fields
.field private static final IV2:[B
# instance fields
.field digest:[B
.field private engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
.field private forWrapping:Z
.field private iv:[B
.field private param:Lorg/spongycastle/crypto/params/KeyParameter;
.field private paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
.field sha1:Lorg/spongycastle/crypto/Digest;
# direct methods
.method static constructor <clinit>()V
.registers 1
.prologue
.line 47
const/16 v0, 0x8
new-array v0, v0, [B
fill-array-data v0, :array_a
sput-object v0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->IV2:[B
return-void
:array_a
.array-data 1
0x4at
-0x23t
-0x5et
0x2ct
0x79t
-0x18t
0x21t
0x5t
.end array-data
.end method
.method public constructor <init>()V
.registers 2
.prologue
.line 28
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 54
new-instance v0, Lorg/spongycastle/crypto/digests/SHA1Digest;
invoke-direct {v0}, Lorg/spongycastle/crypto/digests/SHA1Digest;-><init>()V
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->sha1:Lorg/spongycastle/crypto/Digest;
.line 55
const/16 v0, 0x14
new-array v0, v0, [B
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->digest:[B
return-void
.end method
.method private calculateCMSKeyChecksum([B)[B
.registers 7
.prologue
const/16 v4, 0x8
const/4 v3, 0x0
.line 316
new-array v0, v4, [B
.line 318
iget-object v1, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->sha1:Lorg/spongycastle/crypto/Digest;
array-length v2, p1
invoke-interface {v1, p1, v3, v2}, Lorg/spongycastle/crypto/Digest;->update([BII)V
.line 319
iget-object v1, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->sha1:Lorg/spongycastle/crypto/Digest;
iget-object v2, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->digest:[B
invoke-interface {v1, v2, v3}, Lorg/spongycastle/crypto/Digest;->doFinal([BI)I
.line 321
iget-object v1, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->digest:[B
invoke-static {v1, v3, v0, v3, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 323
return-object v0
.end method
.method private checkCMSKeyChecksum([B[B)Z
.registers 4
.prologue
.line 337
invoke-direct {p0, p1}, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->calculateCMSKeyChecksum([B)[B
move-result-object v0
invoke-static {v0, p2}, Lorg/spongycastle/util/Arrays;->constantTimeAreEqual([B[B)Z
move-result v0
return v0
.end method
.method private static reverse([B)[B
.registers 5
.prologue
.line 342
array-length v0, p0
new-array v1, v0, [B
.line 343
const/4 v0, 0x0
:goto_4
array-length v2, p0
if-ge v0, v2, :cond_12
.line 345
array-length v2, p0
add-int/lit8 v3, v0, 0x1
sub-int/2addr v2, v3
aget-byte v2, p0, v2
aput-byte v2, v1, v0
.line 343
add-int/lit8 v0, v0, 0x1
goto :goto_4
.line 347
:cond_12
return-object v1
.end method
# virtual methods
.method public getAlgorithmName()Ljava/lang/String;
.registers 2
.prologue
.line 124
const-string v0, "DESede"
return-object v0
.end method
.method public init(ZLorg/spongycastle/crypto/CipherParameters;)V
.registers 7
.prologue
const/16 v3, 0x8
.line 66
iput-boolean p1, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->forWrapping:Z
.line 67
new-instance v0, Lorg/spongycastle/crypto/modes/CBCBlockCipher;
new-instance v1, Lorg/spongycastle/crypto/engines/DESedeEngine;
invoke-direct {v1}, Lorg/spongycastle/crypto/engines/DESedeEngine;-><init>()V
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;-><init>(Lorg/spongycastle/crypto/BlockCipher;)V
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
.line 70
instance-of v0, p2, Lorg/spongycastle/crypto/params/ParametersWithRandom;
if-eqz v0, :cond_3f
.line 72
check-cast p2, Lorg/spongycastle/crypto/params/ParametersWithRandom;
.line 73
invoke-virtual {p2}, Lorg/spongycastle/crypto/params/ParametersWithRandom;->getParameters()Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
.line 74
invoke-virtual {p2}, Lorg/spongycastle/crypto/params/ParametersWithRandom;->getRandom()Ljava/security/SecureRandom;
move-result-object v1
.line 81
:goto_1e
instance-of v2, v0, Lorg/spongycastle/crypto/params/KeyParameter;
if-eqz v2, :cond_47
.line 83
check-cast v0, Lorg/spongycastle/crypto/params/KeyParameter;
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
.line 85
iget-boolean v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->forWrapping:Z
if-eqz v0, :cond_3e
.line 90
new-array v0, v3, [B
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
.line 91
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
invoke-virtual {v1, v0}, Ljava/security/SecureRandom;->nextBytes([B)V
.line 93
new-instance v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
iget-object v1, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
iget-object v2, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
invoke-direct {v0, v1, v2}, Lorg/spongycastle/crypto/params/ParametersWithIV;-><init>(Lorg/spongycastle/crypto/CipherParameters;[B)V
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
.line 115
:cond_3e
return-void
.line 78
:cond_3f
new-instance v0, Ljava/security/SecureRandom;
invoke-direct {v0}, Ljava/security/SecureRandom;-><init>()V
move-object v1, v0
move-object v0, p2
goto :goto_1e
.line 96
:cond_47
instance-of v1, v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
if-eqz v1, :cond_3e
.line 98
check-cast v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
.line 99
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ParametersWithIV;->getIV()[B
move-result-object v0
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
.line 100
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ParametersWithIV;->getParameters()Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
check-cast v0, Lorg/spongycastle/crypto/params/KeyParameter;
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
.line 102
iget-boolean v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->forWrapping:Z
if-eqz v0, :cond_76
.line 104
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
if-eqz v0, :cond_6e
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
array-length v0, v0
if-eq v0, v3, :cond_3e
.line 106
:cond_6e
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "IV is not 8 octets"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 111
:cond_76
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "You should not supply an IV for unwrapping"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.end method
.method public unwrap([BII)[B
.registers 11
.prologue
const/16 v6, 0x8
const/4 v1, 0x0
.line 210
iget-boolean v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->forWrapping:Z
if-eqz v0, :cond_f
.line 212
new-instance v0, Ljava/lang/IllegalStateException;
const-string v1, "Not set for unwrapping"
invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.line 215
:cond_f
if-nez p1, :cond_19
.line 217
new-instance v0, Lorg/spongycastle/crypto/InvalidCipherTextException;
const-string v1, "Null pointer as ciphertext"
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/InvalidCipherTextException;-><init>(Ljava/lang/String;)V
throw v0
.line 220
:cond_19
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->getBlockSize()I
move-result v2
.line 221
rem-int v0, p3, v2
if-eqz v0, :cond_38
.line 223
new-instance v0, Lorg/spongycastle/crypto/InvalidCipherTextException;
new-instance v1, Ljava/lang/StringBuilder;
const-string v3, "Ciphertext not multiple of "
invoke-direct {v1, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
move-result-object v1
invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v1
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/InvalidCipherTextException;-><init>(Ljava/lang/String;)V
throw v0
.line 244
:cond_38
new-instance v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
iget-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
sget-object v4, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->IV2:[B
invoke-direct {v0, v3, v4}, Lorg/spongycastle/crypto/params/ParametersWithIV;-><init>(Lorg/spongycastle/crypto/CipherParameters;[B)V
.line 246
iget-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v3, v1, v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 248
new-array v3, p3, [B
move v0, v1
.line 250
:goto_49
if-eq v0, p3, :cond_54
.line 252
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
add-int v5, p2, v0
invoke-virtual {v4, p1, v5, v3, v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->processBlock([BI[BI)I
.line 250
add-int/2addr v0, v2
goto :goto_49
.line 256
:cond_54
invoke-static {v3}, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->reverse([B)[B
move-result-object v0
.line 259
new-array v3, v6, [B
iput-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
.line 261
array-length v3, v0
add-int/lit8 v3, v3, -0x8
new-array v3, v3, [B
.line 263
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
invoke-static {v0, v1, v4, v1, v6}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 264
array-length v4, v0
add-int/lit8 v4, v4, -0x8
invoke-static {v0, v6, v3, v1, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 268
new-instance v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
iget-object v5, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
invoke-direct {v0, v4, v5}, Lorg/spongycastle/crypto/params/ParametersWithIV;-><init>(Lorg/spongycastle/crypto/CipherParameters;[B)V
iput-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
.line 270
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
invoke-virtual {v0, v1, v4}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 272
array-length v0, v3
new-array v4, v0, [B
move v0, v1
.line 274
:goto_82
array-length v5, v4
if-eq v0, v5, :cond_8c
.line 276
iget-object v5, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v5, v3, v0, v4, v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->processBlock([BI[BI)I
.line 274
add-int/2addr v0, v2
goto :goto_82
.line 281
:cond_8c
array-length v0, v4
add-int/lit8 v0, v0, -0x8
new-array v0, v0, [B
.line 282
new-array v2, v6, [B
.line 284
array-length v3, v4
add-int/lit8 v3, v3, -0x8
invoke-static {v4, v1, v0, v1, v3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 285
array-length v3, v4
add-int/lit8 v3, v3, -0x8
invoke-static {v4, v3, v2, v1, v6}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 289
invoke-direct {p0, v0, v2}, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->checkCMSKeyChecksum([B[B)Z
move-result v1
if-nez v1, :cond_ad
.line 291
new-instance v0, Lorg/spongycastle/crypto/InvalidCipherTextException;
const-string v1, "Checksum inside ciphertext is corrupted"
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/InvalidCipherTextException;-><init>(Ljava/lang/String;)V
throw v0
.line 296
:cond_ad
return-object v0
.end method
.method public wrap([BII)[B
.registers 11
.prologue
const/4 v6, 0x1
const/4 v1, 0x0
.line 137
iget-boolean v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->forWrapping:Z
if-nez v0, :cond_e
.line 139
new-instance v0, Ljava/lang/IllegalStateException;
const-string v1, "Not initialized for wrapping"
invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.line 142
:cond_e
new-array v0, p3, [B
.line 144
invoke-static {p1, p2, v0, v1, p3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 147
invoke-direct {p0, v0}, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->calculateCMSKeyChecksum([B)[B
move-result-object v2
.line 150
array-length v3, v2
add-int/2addr v3, p3
new-array v3, v3, [B
.line 152
invoke-static {v0, v1, v3, v1, p3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 153
array-length v0, v2
invoke-static {v2, v1, v3, p3, v0}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 158
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->getBlockSize()I
move-result v2
.line 160
array-length v0, v3
rem-int/2addr v0, v2
if-eqz v0, :cond_34
.line 162
new-instance v0, Ljava/lang/IllegalStateException;
const-string v1, "Not multiple of block length"
invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.line 165
:cond_34
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->paramPlusIV:Lorg/spongycastle/crypto/params/ParametersWithIV;
invoke-virtual {v0, v6, v4}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 167
array-length v0, v3
new-array v4, v0, [B
move v0, v1
.line 169
:goto_3f
array-length v5, v3
if-eq v0, v5, :cond_49
.line 171
iget-object v5, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v5, v3, v0, v4, v0}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->processBlock([BI[BI)I
.line 169
add-int/2addr v0, v2
goto :goto_3f
.line 175
:cond_49
iget-object v0, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
array-length v0, v0
array-length v3, v4
add-int/2addr v0, v3
new-array v0, v0, [B
.line 177
iget-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
iget-object v5, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
array-length v5, v5
invoke-static {v3, v1, v0, v1, v5}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 178
iget-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->iv:[B
array-length v3, v3
array-length v5, v4
invoke-static {v4, v1, v0, v3, v5}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 181
invoke-static {v0}, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->reverse([B)[B
move-result-object v0
.line 186
new-instance v3, Lorg/spongycastle/crypto/params/ParametersWithIV;
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->param:Lorg/spongycastle/crypto/params/KeyParameter;
sget-object v5, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->IV2:[B
invoke-direct {v3, v4, v5}, Lorg/spongycastle/crypto/params/ParametersWithIV;-><init>(Lorg/spongycastle/crypto/CipherParameters;[B)V
.line 188
iget-object v4, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v4, v6, v3}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->init(ZLorg/spongycastle/crypto/CipherParameters;)V
.line 190
:goto_71
array-length v3, v0
if-eq v1, v3, :cond_7b
.line 192
iget-object v3, p0, Lorg/spongycastle/crypto/engines/DESedeWrapEngine;->engine:Lorg/spongycastle/crypto/modes/CBCBlockCipher;
invoke-virtual {v3, v0, v1, v0, v1}, Lorg/spongycastle/crypto/modes/CBCBlockCipher;->processBlock([BI[BI)I
.line 190
add-int/2addr v1, v2
goto :goto_71
.line 195
:cond_7b
return-object v0
.end method