HC256Engine.smali
.class public Lorg/spongycastle/crypto/engines/HC256Engine;
.super Ljava/lang/Object;
.source "HC256Engine.java"
# interfaces
.implements Lorg/spongycastle/crypto/StreamCipher;
# instance fields
.field private buf:[B
.field private cnt:I
.field private idx:I
.field private initialised:Z
.field private iv:[B
.field private key:[B
.field private p:[I
.field private q:[I
# direct methods
.method public constructor <init>()V
.registers 4
.prologue
const/16 v2, 0x400
const/4 v1, 0x0
.line 24
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 27
new-array v0, v2, [I
iput-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
.line 28
new-array v0, v2, [I
iput-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
.line 29
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
.line 182
const/4 v0, 0x4
new-array v0, v0, [B
iput-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
.line 183
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
return-void
.end method
.method private getByte()B
.registers 5
.prologue
.line 187
iget v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
if-nez v0, :cond_26
.line 189
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->step()I
move-result v0
.line 190
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
const/4 v2, 0x0
int-to-byte v3, v0
aput-byte v3, v1, v2
.line 191
shr-int/lit8 v0, v0, 0x8
.line 192
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
const/4 v2, 0x1
int-to-byte v3, v0
aput-byte v3, v1, v2
.line 193
shr-int/lit8 v0, v0, 0x8
.line 194
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
const/4 v2, 0x2
int-to-byte v3, v0
aput-byte v3, v1, v2
.line 195
shr-int/lit8 v0, v0, 0x8
.line 196
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
const/4 v2, 0x3
int-to-byte v0, v0
aput-byte v0, v1, v2
.line 198
:cond_26
iget-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->buf:[B
iget v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
aget-byte v0, v0, v1
.line 199
iget v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
add-int/lit8 v1, v1, 0x1
and-int/lit8 v1, v1, 0x3
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
.line 200
return v0
.end method
.method private init()V
.registers 12
.prologue
const/16 v10, 0xa00
const/16 v9, 0x400
const/16 v0, 0x10
const/16 v8, 0x20
const/4 v1, 0x0
.line 70
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
array-length v2, v2
if-eq v2, v8, :cond_1b
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
array-length v2, v2
if-eq v2, v0, :cond_1b
.line 72
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "The key must be 128/256 bits long"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 76
:cond_1b
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
array-length v2, v2
if-ge v2, v0, :cond_28
.line 78
new-instance v0, Ljava/lang/IllegalArgumentException;
const-string v1, "The IV must be at least 128 bits long"
invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.line 82
:cond_28
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
array-length v2, v2
if-eq v2, v8, :cond_41
.line 84
new-array v2, v8, [B
.line 86
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
iget-object v4, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
array-length v4, v4
invoke-static {v3, v1, v2, v1, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 87
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
iget-object v4, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
array-length v4, v4
invoke-static {v3, v1, v2, v0, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 89
iput-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
.line 92
:cond_41
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
array-length v2, v2
if-ge v2, v8, :cond_5f
.line 94
new-array v2, v8, [B
.line 96
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
iget-object v4, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
array-length v4, v4
invoke-static {v3, v1, v2, v1, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 97
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
iget-object v4, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
array-length v4, v4
iget-object v5, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
array-length v5, v5
rsub-int/lit8 v5, v5, 0x20
invoke-static {v3, v1, v2, v4, v5}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 99
iput-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
.line 102
:cond_5f
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->idx:I
.line 103
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
.line 105
new-array v3, v10, [I
move v2, v1
.line 107
:goto_66
if-ge v2, v8, :cond_7d
.line 109
shr-int/lit8 v4, v2, 0x2
aget v5, v3, v4
iget-object v6, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
aget-byte v6, v6, v2
and-int/lit16 v6, v6, 0xff
and-int/lit8 v7, v2, 0x3
mul-int/lit8 v7, v7, 0x8
shl-int/2addr v6, v7
or-int/2addr v5, v6
aput v5, v3, v4
.line 107
add-int/lit8 v2, v2, 0x1
goto :goto_66
:cond_7d
move v2, v1
.line 112
:goto_7e
if-ge v2, v8, :cond_97
.line 114
shr-int/lit8 v4, v2, 0x2
add-int/lit8 v4, v4, 0x8
aget v5, v3, v4
iget-object v6, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
aget-byte v6, v6, v2
and-int/lit16 v6, v6, 0xff
and-int/lit8 v7, v2, 0x3
mul-int/lit8 v7, v7, 0x8
shl-int/2addr v6, v7
or-int/2addr v5, v6
aput v5, v3, v4
.line 112
add-int/lit8 v2, v2, 0x1
goto :goto_7e
.line 117
:cond_97
:goto_97
if-ge v0, v10, :cond_d1
.line 119
add-int/lit8 v2, v0, -0x2
aget v2, v3, v2
.line 120
add-int/lit8 v4, v0, -0xf
aget v4, v3, v4
.line 121
const/16 v5, 0x11
invoke-static {v2, v5}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v5
const/16 v6, 0x13
invoke-static {v2, v6}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v6
xor-int/2addr v5, v6
ushr-int/lit8 v2, v2, 0xa
xor-int/2addr v2, v5
add-int/lit8 v5, v0, -0x7
aget v5, v3, v5
add-int/2addr v2, v5
const/4 v5, 0x7
.line 123
invoke-static {v4, v5}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v5
const/16 v6, 0x12
invoke-static {v4, v6}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v6
xor-int/2addr v5, v6
ushr-int/lit8 v4, v4, 0x3
xor-int/2addr v4, v5
add-int/2addr v2, v4
add-int/lit8 v4, v0, -0x10
aget v4, v3, v4
add-int/2addr v2, v4
add-int/2addr v2, v0
aput v2, v3, v0
.line 117
add-int/lit8 v0, v0, 0x1
goto :goto_97
.line 127
:cond_d1
const/16 v0, 0x200
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
invoke-static {v3, v0, v2, v1, v9}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 128
const/16 v0, 0x600
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
invoke-static {v3, v0, v2, v1, v9}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
move v0, v1
.line 130
:goto_e0
const/16 v2, 0x1000
if-ge v0, v2, :cond_ea
.line 132
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->step()I
.line 130
add-int/lit8 v0, v0, 0x1
goto :goto_e0
.line 135
:cond_ea
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
.line 136
return-void
.end method
.method private static rotateRight(II)I
.registers 4
.prologue
.line 244
ushr-int v0, p0, p1
neg-int v1, p1
shl-int v1, p0, v1
or-int/2addr v0, v1
return v0
.end method
.method private step()I
.registers 10
.prologue
const/16 v8, 0x17
const/16 v7, 0xa
.line 33
iget v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
and-int/lit16 v0, v0, 0x3ff
.line 35
iget v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
const/16 v2, 0x400
if-ge v1, v2, :cond_7a
.line 37
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
add-int/lit8 v2, v0, -0x3
and-int/lit16 v2, v2, 0x3ff
aget v1, v1, v2
.line 38
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
add-int/lit16 v3, v0, -0x3ff
and-int/lit16 v3, v3, 0x3ff
aget v2, v2, v3
.line 39
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
aget v4, v3, v0
iget-object v5, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
add-int/lit8 v6, v0, -0xa
and-int/lit16 v6, v6, 0x3ff
aget v5, v5, v6
.line 40
invoke-static {v1, v7}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v6
invoke-static {v2, v8}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v7
xor-int/2addr v6, v7
add-int/2addr v5, v6
iget-object v6, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
xor-int/2addr v1, v2
and-int/lit16 v1, v1, 0x3ff
aget v1, v6, v1
add-int/2addr v1, v5
add-int/2addr v1, v4
aput v1, v3, v0
.line 43
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
add-int/lit8 v2, v0, -0xc
and-int/lit16 v2, v2, 0x3ff
aget v1, v1, v2
.line 44
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
and-int/lit16 v3, v1, 0xff
aget v2, v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
shr-int/lit8 v4, v1, 0x8
and-int/lit16 v4, v4, 0xff
add-int/lit16 v4, v4, 0x100
aget v3, v3, v4
add-int/2addr v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
shr-int/lit8 v4, v1, 0x10
and-int/lit16 v4, v4, 0xff
add-int/lit16 v4, v4, 0x200
aget v3, v3, v4
add-int/2addr v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
ushr-int/lit8 v1, v1, 0x18
add-int/lit16 v1, v1, 0x300
aget v1, v3, v1
add-int/2addr v1, v2
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
aget v0, v2, v0
xor-int/2addr v0, v1
.line 61
:goto_71
iget v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
add-int/lit8 v1, v1, 0x1
and-int/lit16 v1, v1, 0x7ff
iput v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->cnt:I
.line 62
return v0
.line 50
:cond_7a
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
add-int/lit8 v2, v0, -0x3
and-int/lit16 v2, v2, 0x3ff
aget v1, v1, v2
.line 51
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
add-int/lit16 v3, v0, -0x3ff
and-int/lit16 v3, v3, 0x3ff
aget v2, v2, v3
.line 52
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
aget v4, v3, v0
iget-object v5, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
add-int/lit8 v6, v0, -0xa
and-int/lit16 v6, v6, 0x3ff
aget v5, v5, v6
.line 53
invoke-static {v1, v7}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v6
invoke-static {v2, v8}, Lorg/spongycastle/crypto/engines/HC256Engine;->rotateRight(II)I
move-result v7
xor-int/2addr v6, v7
add-int/2addr v5, v6
iget-object v6, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
xor-int/2addr v1, v2
and-int/lit16 v1, v1, 0x3ff
aget v1, v6, v1
add-int/2addr v1, v5
add-int/2addr v1, v4
aput v1, v3, v0
.line 56
iget-object v1, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
add-int/lit8 v2, v0, -0xc
and-int/lit16 v2, v2, 0x3ff
aget v1, v1, v2
.line 57
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
and-int/lit16 v3, v1, 0xff
aget v2, v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
shr-int/lit8 v4, v1, 0x8
and-int/lit16 v4, v4, 0xff
add-int/lit16 v4, v4, 0x100
aget v3, v3, v4
add-int/2addr v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
shr-int/lit8 v4, v1, 0x10
and-int/lit16 v4, v4, 0xff
add-int/lit16 v4, v4, 0x200
aget v3, v3, v4
add-int/2addr v2, v3
iget-object v3, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->p:[I
ushr-int/lit8 v1, v1, 0x18
add-int/lit16 v1, v1, 0x300
aget v1, v3, v1
add-int/2addr v1, v2
iget-object v2, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->q:[I
aget v0, v2, v0
xor-int/2addr v0, v1
goto :goto_71
.end method
# virtual methods
.method public getAlgorithmName()Ljava/lang/String;
.registers 2
.prologue
.line 140
const-string v0, "HC-256"
return-object v0
.end method
.method public init(ZLorg/spongycastle/crypto/CipherParameters;)V
.registers 6
.prologue
.line 155
.line 157
instance-of v0, p2, Lorg/spongycastle/crypto/params/ParametersWithIV;
if-eqz v0, :cond_27
move-object v0, p2
.line 159
check-cast v0, 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/HC256Engine;->iv:[B
move-object v0, p2
.line 160
check-cast v0, Lorg/spongycastle/crypto/params/ParametersWithIV;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/ParametersWithIV;->getParameters()Lorg/spongycastle/crypto/CipherParameters;
move-result-object v0
.line 167
:goto_14
instance-of v1, v0, Lorg/spongycastle/crypto/params/KeyParameter;
if-eqz v1, :cond_2e
.line 169
check-cast v0, Lorg/spongycastle/crypto/params/KeyParameter;
invoke-virtual {v0}, Lorg/spongycastle/crypto/params/KeyParameter;->getKey()[B
move-result-object v0
iput-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->key:[B
.line 170
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->init()V
.line 179
const/4 v0, 0x1
iput-boolean v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->initialised:Z
.line 180
return-void
.line 164
:cond_27
const/4 v0, 0x0
new-array v0, v0, [B
iput-object v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->iv:[B
move-object v0, p2
goto :goto_14
.line 174
:cond_2e
new-instance v0, Ljava/lang/IllegalArgumentException;
new-instance v1, Ljava/lang/StringBuilder;
const-string v2, "Invalid parameter passed to HC256 init - "
invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V
.line 176
invoke-virtual {p2}, Ljava/lang/Object;->getClass()Ljava/lang/Class;
move-result-object v2
invoke-virtual {v2}, Ljava/lang/Class;->getName()Ljava/lang/String;
move-result-object v2
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)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}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
.end method
.method public processBytes([BII[BI)I
.registers 10
.prologue
.line 206
iget-boolean v0, p0, Lorg/spongycastle/crypto/engines/HC256Engine;->initialised:Z
if-nez v0, :cond_21
.line 208
new-instance v0, Ljava/lang/IllegalStateException;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
invoke-virtual {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->getAlgorithmName()Ljava/lang/String;
move-result-object v2
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
move-result-object v1
const-string v2, " not initialised"
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)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}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.line 212
:cond_21
add-int v0, p2, p3
array-length v1, p1
if-le v0, v1, :cond_2e
.line 214
new-instance v0, Lorg/spongycastle/crypto/DataLengthException;
const-string v1, "input buffer too short"
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/DataLengthException;-><init>(Ljava/lang/String;)V
throw v0
.line 217
:cond_2e
add-int v0, p5, p3
array-length v1, p4
if-le v0, v1, :cond_3b
.line 219
new-instance v0, Lorg/spongycastle/crypto/OutputLengthException;
const-string v1, "output buffer too short"
invoke-direct {v0, v1}, Lorg/spongycastle/crypto/OutputLengthException;-><init>(Ljava/lang/String;)V
throw v0
.line 222
:cond_3b
const/4 v0, 0x0
:goto_3c
if-ge v0, p3, :cond_4f
.line 224
add-int v1, p5, v0
add-int v2, p2, v0
aget-byte v2, p1, v2
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->getByte()B
move-result v3
xor-int/2addr v2, v3
int-to-byte v2, v2
aput-byte v2, p4, v1
.line 222
add-int/lit8 v0, v0, 0x1
goto :goto_3c
.line 227
:cond_4f
return p3
.end method
.method public reset()V
.registers 1
.prologue
.line 232
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->init()V
.line 233
return-void
.end method
.method public returnByte(B)B
.registers 3
.prologue
.line 237
invoke-direct {p0}, Lorg/spongycastle/crypto/engines/HC256Engine;->getByte()B
move-result v0
xor-int/2addr v0, p1
int-to-byte v0, v0
return v0
.end method