ArrayEncoder.smali
.class public Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;
.super Ljava/lang/Object;
.source "ArrayEncoder.java"
# static fields
.field private static final BIT1_TABLE:[I
.field private static final BIT2_TABLE:[I
.field private static final BIT3_TABLE:[I
.field private static final COEFF1_TABLE:[I
.field private static final COEFF2_TABLE:[I
# direct methods
.method static constructor <clinit>()V
.registers 3
.prologue
const/16 v2, 0x8
const/16 v1, 0x9
.line 33
new-array v0, v2, [I
fill-array-data v0, :array_28
sput-object v0, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->COEFF1_TABLE:[I
.line 34
new-array v0, v2, [I
fill-array-data v0, :array_3c
sput-object v0, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->COEFF2_TABLE:[I
.line 55
new-array v0, v1, [I
fill-array-data v0, :array_50
sput-object v0, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT1_TABLE:[I
.line 56
new-array v0, v1, [I
fill-array-data v0, :array_66
sput-object v0, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT2_TABLE:[I
.line 57
new-array v0, v1, [I
fill-array-data v0, :array_7c
sput-object v0, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT3_TABLE:[I
return-void
.line 33
:array_28
.array-data 4
0x0
0x0
0x0
0x1
0x1
0x1
-0x1
-0x1
.end array-data
.line 34
:array_3c
.array-data 4
0x0
0x1
-0x1
0x0
0x1
-0x1
0x0
0x1
.end array-data
.line 55
:array_50
.array-data 4
0x1
0x1
0x1
0x0
0x0
0x0
0x1
0x0
0x1
.end array-data
.line 56
:array_66
.array-data 4
0x1
0x1
0x1
0x1
0x0
0x0
0x0
0x1
0x0
.end array-data
.line 57
:array_7c
.array-data 4
0x1
0x0
0x1
0x0
0x0
0x1
0x1
0x1
0x0
.end array-data
.end method
.method public constructor <init>()V
.registers 1
.prologue
.line 12
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static decodeMod3Sves([BI)[I
.registers 8
.prologue
const/4 v0, 0x0
.line 155
new-array v2, p1, [I
move v1, v0
.line 157
:cond_4
array-length v3, p0
shl-int/lit8 v3, v3, 0x3
if-ge v0, v3, :cond_35
.line 159
add-int/lit8 v3, v0, 0x1
invoke-static {p0, v0}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->getBit([BI)I
move-result v4
.line 160
add-int/lit8 v5, v3, 0x1
invoke-static {p0, v3}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->getBit([BI)I
move-result v3
.line 161
add-int/lit8 v0, v5, 0x1
invoke-static {p0, v5}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->getBit([BI)I
move-result v5
.line 162
shl-int/lit8 v4, v4, 0x2
shl-int/lit8 v3, v3, 0x1
add-int/2addr v3, v4
add-int/2addr v3, v5
.line 163
add-int/lit8 v4, v1, 0x1
sget-object v5, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->COEFF1_TABLE:[I
aget v5, v5, v3
aput v5, v2, v1
.line 164
add-int/lit8 v1, v4, 0x1
sget-object v5, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->COEFF2_TABLE:[I
aget v3, v5, v3
aput v3, v2, v4
.line 166
add-int/lit8 v3, p1, -0x2
if-le v1, v3, :cond_4
.line 171
:cond_35
return-object v2
.end method
.method public static decodeMod3Tight(Ljava/io/InputStream;I)[I
.registers 6
.prologue
.line 283
int-to-double v0, p1
const-wide/high16 v2, 0x4008000000000000L # 3.0
invoke-static {v2, v3}, Ljava/lang/Math;->log(D)D
move-result-wide v2
mul-double/2addr v0, v2
const-wide/high16 v2, 0x4000000000000000L # 2.0
invoke-static {v2, v3}, Ljava/lang/Math;->log(D)D
move-result-wide v2
div-double/2addr v0, v2
const-wide/high16 v2, 0x4020000000000000L # 8.0
div-double/2addr v0, v2
invoke-static {v0, v1}, Ljava/lang/Math;->ceil(D)D
move-result-wide v0
double-to-int v0, v0
.line 284
invoke-static {p0, v0}, Lorg/spongycastle/pqc/math/ntru/util/Util;->readFullLength(Ljava/io/InputStream;I)[B
move-result-object v0
.line 285
invoke-static {v0, p1}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->decodeMod3Tight([BI)[I
move-result-object v0
return-object v0
.end method
.method public static decodeMod3Tight([BI)[I
.registers 10
.prologue
const-wide/16 v6, 0x3
const/4 v4, 0x1
.line 259
new-instance v1, Ljava/math/BigInteger;
invoke-direct {v1, v4, p0}, Ljava/math/BigInteger;-><init>(I[B)V
.line 260
new-array v2, p1, [I
.line 261
const/4 v0, 0x0
:goto_b
if-ge v0, p1, :cond_32
.line 263
invoke-static {v6, v7}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v3
invoke-virtual {v1, v3}, Ljava/math/BigInteger;->mod(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v3
invoke-virtual {v3}, Ljava/math/BigInteger;->intValue()I
move-result v3
add-int/lit8 v3, v3, -0x1
aput v3, v2, v0
.line 264
aget v3, v2, v0
if-le v3, v4, :cond_27
.line 266
aget v3, v2, v0
add-int/lit8 v3, v3, -0x3
aput v3, v2, v0
.line 268
:cond_27
invoke-static {v6, v7}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v3
invoke-virtual {v1, v3}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 261
add-int/lit8 v0, v0, 0x1
goto :goto_b
.line 270
:cond_32
return-object v2
.end method
.method public static decodeModQ(Ljava/io/InputStream;II)[I
.registers 4
.prologue
.line 137
invoke-static {p2}, Ljava/lang/Integer;->numberOfLeadingZeros(I)I
move-result v0
rsub-int/lit8 v0, v0, 0x1f
.line 138
mul-int/2addr v0, p1
add-int/lit8 v0, v0, 0x7
div-int/lit8 v0, v0, 0x8
.line 139
invoke-static {p0, v0}, Lorg/spongycastle/pqc/math/ntru/util/Util;->readFullLength(Ljava/io/InputStream;I)[B
move-result-object v0
.line 140
invoke-static {v0, p1, p2}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->decodeModQ([BII)[I
move-result-object v0
return-object v0
.end method
.method public static decodeModQ([BII)[I
.registers 11
.prologue
const/4 v0, 0x0
.line 108
new-array v2, p1, [I
.line 109
invoke-static {p2}, Ljava/lang/Integer;->numberOfLeadingZeros(I)I
move-result v1
rsub-int/lit8 v3, v1, 0x1f
.line 110
mul-int v4, p1, v3
move v1, v0
.line 112
:goto_c
if-ge v1, v4, :cond_25
.line 114
if-lez v1, :cond_16
rem-int v5, v1, v3
if-nez v5, :cond_16
.line 116
add-int/lit8 v0, v0, 0x1
.line 118
:cond_16
invoke-static {p0, v1}, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->getBit([BI)I
move-result v5
.line 119
aget v6, v2, v0
rem-int v7, v1, v3
shl-int/2addr v5, v7
add-int/2addr v5, v6
aput v5, v2, v0
.line 112
add-int/lit8 v1, v1, 0x1
goto :goto_c
.line 121
:cond_25
return-object v2
.end method
.method public static encodeMod3Sves([I)[B
.registers 11
.prologue
const/4 v9, 0x3
const/4 v1, 0x0
.line 185
array-length v0, p0
mul-int/lit8 v0, v0, 0x3
add-int/lit8 v0, v0, 0x1
div-int/lit8 v0, v0, 0x2
.line 186
add-int/lit8 v0, v0, 0x7
div-int/lit8 v0, v0, 0x8
.line 187
new-array v5, v0, [B
move v0, v1
move v2, v1
move v3, v1
.line 190
:cond_12
array-length v4, p0
div-int/lit8 v4, v4, 0x2
shl-int/lit8 v4, v4, 0x1
if-ge v0, v4, :cond_62
.line 192
add-int/lit8 v4, v0, 0x1
aget v0, p0, v0
add-int/lit8 v6, v0, 0x1
.line 193
add-int/lit8 v0, v4, 0x1
aget v4, p0, v4
add-int/lit8 v4, v4, 0x1
.line 194
if-nez v6, :cond_31
if-nez v4, :cond_31
.line 196
new-instance v0, Ljava/lang/IllegalStateException;
const-string v1, "Illegal encoding!"
invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.line 198
:cond_31
mul-int/lit8 v6, v6, 0x3
add-int/2addr v4, v6
.line 199
new-array v6, v9, [I
sget-object v7, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT1_TABLE:[I
aget v7, v7, v4
aput v7, v6, v1
const/4 v7, 0x1
sget-object v8, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT2_TABLE:[I
aget v8, v8, v4
aput v8, v6, v7
const/4 v7, 0x2
sget-object v8, Lorg/spongycastle/pqc/math/ntru/util/ArrayEncoder;->BIT3_TABLE:[I
aget v4, v8, v4
aput v4, v6, v7
move v4, v1
.line 200
:goto_4b
if-ge v4, v9, :cond_12
.line 202
aget-byte v7, v5, v2
aget v8, v6, v4
shl-int/2addr v8, v3
or-int/2addr v7, v8
int-to-byte v7, v7
aput-byte v7, v5, v2
.line 203
const/4 v7, 0x7
if-ne v3, v7, :cond_5f
.line 206
add-int/lit8 v2, v2, 0x1
move v3, v1
.line 200
:goto_5c
add-int/lit8 v4, v4, 0x1
goto :goto_4b
.line 210
:cond_5f
add-int/lit8 v3, v3, 0x1
goto :goto_5c
.line 214
:cond_62
return-object v5
.end method
.method public static encodeMod3Tight([I)[B
.registers 7
.prologue
const-wide/16 v4, 0x3
.line 224
sget-object v1, Ljava/math/BigInteger;->ZERO:Ljava/math/BigInteger;
.line 225
array-length v0, p0
add-int/lit8 v0, v0, -0x1
:goto_7
if-ltz v0, :cond_21
.line 227
invoke-static {v4, v5}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v2
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 228
aget v2, p0, v0
add-int/lit8 v2, v2, 0x1
int-to-long v2, v2
invoke-static {v2, v3}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v2
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
.line 225
add-int/lit8 v0, v0, -0x1
goto :goto_7
.line 231
:cond_21
invoke-static {v4, v5}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
move-result-object v0
array-length v2, p0
invoke-virtual {v0, v2}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
move-result-object v0
invoke-virtual {v0}, Ljava/math/BigInteger;->bitLength()I
move-result v0
add-int/lit8 v0, v0, 0x7
div-int/lit8 v2, v0, 0x8
.line 232
invoke-virtual {v1}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v0
.line 234
array-length v1, v0
if-ge v1, v2, :cond_44
.line 237
new-array v1, v2, [B
.line 238
const/4 v3, 0x0
array-length v4, v0
sub-int/2addr v2, v4
array-length v4, v0
invoke-static {v0, v3, v1, v2, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
move-object v0, v1
.line 247
:cond_43
:goto_43
return-object v0
.line 242
:cond_44
array-length v1, v0
if-le v1, v2, :cond_43
.line 245
const/4 v1, 0x1
array-length v2, v0
invoke-static {v0, v1, v2}, Lorg/spongycastle/util/Arrays;->copyOfRange([BII)[B
move-result-object v0
goto :goto_43
.end method
.method public static encodeModQ([II)[B
.registers 11
.prologue
const/4 v1, 0x0
.line 70
invoke-static {p1}, Ljava/lang/Integer;->numberOfLeadingZeros(I)I
move-result v0
rsub-int/lit8 v5, v0, 0x1f
.line 71
array-length v0, p0
mul-int/2addr v0, v5
.line 72
add-int/lit8 v0, v0, 0x7
div-int/lit8 v0, v0, 0x8
.line 73
new-array v6, v0, [B
move v0, v1
move v2, v1
move v3, v1
.line 76
:goto_12
array-length v4, p0
if-ge v0, v4, :cond_33
move v4, v1
.line 78
:goto_16
if-ge v4, v5, :cond_30
.line 80
aget v7, p0, v0
shr-int/2addr v7, v4
and-int/lit8 v7, v7, 0x1
.line 81
aget-byte v8, v6, v2
shl-int/2addr v7, v3
or-int/2addr v7, v8
int-to-byte v7, v7
aput-byte v7, v6, v2
.line 82
const/4 v7, 0x7
if-ne v3, v7, :cond_2d
.line 85
add-int/lit8 v2, v2, 0x1
move v3, v1
.line 78
:goto_2a
add-int/lit8 v4, v4, 0x1
goto :goto_16
.line 89
:cond_2d
add-int/lit8 v3, v3, 0x1
goto :goto_2a
.line 76
:cond_30
add-int/lit8 v0, v0, 0x1
goto :goto_12
.line 93
:cond_33
return-object v6
.end method
.method private static getBit([BI)I
.registers 4
.prologue
.line 290
div-int/lit8 v0, p1, 0x8
.line 291
aget-byte v0, p0, v0
and-int/lit16 v0, v0, 0xff
.line 292
rem-int/lit8 v1, p1, 0x8
shr-int/2addr v0, v1
and-int/lit8 v0, v0, 0x1
return v0
.end method