s.smali
.class public final Lcom/subgraph/orchid/crypto/s;
.super Ljava/lang/Object;
.source "TorTapKeyAgreement.java"
# interfaces
.implements Lcom/subgraph/orchid/crypto/k;
# static fields
.field private static final bGu:Ljava/math/BigInteger;
.field private static final bGv:Ljava/math/BigInteger;
.field private static final bGw:Ljavax/crypto/spec/DHParameterSpec;
# instance fields
.field public final bED:Lcom/subgraph/orchid/crypto/o;
.field private final bGx:Ljavax/crypto/KeyAgreement;
.field private final bGy:Ljava/security/KeyPair;
# direct methods
.method static constructor <clinit>()V
.registers 4
.prologue
.line 43
new-instance v0, Ljava/math/BigInteger;
const-string v1, "00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"
const/16 v2, 0x10
invoke-direct {v0, v1, v2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;I)V
sput-object v0, Lcom/subgraph/orchid/crypto/s;->bGu:Ljava/math/BigInteger;
.line 49
new-instance v0, Ljava/math/BigInteger;
const-string v1, "2"
invoke-direct {v0, v1}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V
sput-object v0, Lcom/subgraph/orchid/crypto/s;->bGv:Ljava/math/BigInteger;
.line 58
new-instance v0, Ljavax/crypto/spec/DHParameterSpec;
sget-object v1, Lcom/subgraph/orchid/crypto/s;->bGu:Ljava/math/BigInteger;
sget-object v2, Lcom/subgraph/orchid/crypto/s;->bGv:Ljava/math/BigInteger;
const/16 v3, 0x140
invoke-direct {v0, v1, v2, v3}, Ljavax/crypto/spec/DHParameterSpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;I)V
sput-object v0, Lcom/subgraph/orchid/crypto/s;->bGw:Ljavax/crypto/spec/DHParameterSpec;
return-void
.end method
.method public constructor <init>()V
.registers 2
.prologue
.line 77
const/4 v0, 0x0
invoke-direct {p0, v0}, Lcom/subgraph/orchid/crypto/s;-><init>(Lcom/subgraph/orchid/crypto/o;)V
.line 78
return-void
.end method
.method public constructor <init>(Lcom/subgraph/orchid/crypto/o;)V
.registers 3
.prologue
.line 69
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 70
invoke-static {}, Lcom/subgraph/orchid/crypto/s;->generateKeyPair()Ljava/security/KeyPair;
move-result-object v0
iput-object v0, p0, Lcom/subgraph/orchid/crypto/s;->bGy:Ljava/security/KeyPair;
.line 71
invoke-direct {p0}, Lcom/subgraph/orchid/crypto/s;->Mn()Ljavax/crypto/KeyAgreement;
move-result-object v0
iput-object v0, p0, Lcom/subgraph/orchid/crypto/s;->bGx:Ljavax/crypto/KeyAgreement;
.line 72
iput-object p1, p0, Lcom/subgraph/orchid/crypto/s;->bED:Lcom/subgraph/orchid/crypto/o;
.line 74
return-void
.end method
.method private final Mn()Ljavax/crypto/KeyAgreement;
.registers 3
.prologue
.line 151
:try_start_0
const-string v0, "DH"
invoke-static {v0}, Ljavax/crypto/KeyAgreement;->getInstance(Ljava/lang/String;)Ljavax/crypto/KeyAgreement;
move-result-object v0
.line 152
iget-object v1, p0, Lcom/subgraph/orchid/crypto/s;->bGy:Ljava/security/KeyPair;
invoke-virtual {v1}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;
move-result-object v1
invoke-virtual {v0, v1}, Ljavax/crypto/KeyAgreement;->init(Ljava/security/Key;)V
:try_end_f
.catch Ljava/security/GeneralSecurityException; {:try_start_0 .. :try_end_f} :catch_10
.line 153
return-object v0
.line 154
:catch_10
move-exception v0
.line 155
new-instance v1, Lcom/subgraph/orchid/TorException;
invoke-direct {v1, v0}, Lcom/subgraph/orchid/TorException;-><init>(Ljava/lang/Throwable;)V
throw v1
.end method
.method public static f(Ljava/math/BigInteger;)Z
.registers 4
.prologue
const/4 v0, 0x0
.line 124
invoke-virtual {p0}, Ljava/math/BigInteger;->signum()I
move-result v1
if-lez v1, :cond_f
sget-object v1, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
invoke-virtual {p0, v1}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
move-result v1
if-eqz v1, :cond_10
.line 128
:cond_f
:goto_f
return v0
.line 126
:cond_10
sget-object v1, Lcom/subgraph/orchid/crypto/s;->bGu:Ljava/math/BigInteger;
sget-object v2, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->subtract(Ljava/math/BigInteger;)Ljava/math/BigInteger;
move-result-object v1
invoke-virtual {p0, v1}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
move-result v1
if-gez v1, :cond_f
.line 128
const/4 v0, 0x1
goto :goto_f
.end method
.method private g(Ljava/math/BigInteger;)[B
.registers 6
.prologue
.line 140
:try_start_0
const-string v0, "DH"
invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v0
.line 141
new-instance v1, Ljavax/crypto/spec/DHPublicKeySpec;
sget-object v2, Lcom/subgraph/orchid/crypto/s;->bGu:Ljava/math/BigInteger;
sget-object v3, Lcom/subgraph/orchid/crypto/s;->bGv:Ljava/math/BigInteger;
invoke-direct {v1, p1, v2, v3}, Ljavax/crypto/spec/DHPublicKeySpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/BigInteger;)V
.line 142
invoke-virtual {v0, v1}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
move-result-object v0
.line 143
iget-object v1, p0, Lcom/subgraph/orchid/crypto/s;->bGx:Ljavax/crypto/KeyAgreement;
const/4 v2, 0x1
invoke-virtual {v1, v0, v2}, Ljavax/crypto/KeyAgreement;->doPhase(Ljava/security/Key;Z)Ljava/security/Key;
.line 144
iget-object v0, p0, Lcom/subgraph/orchid/crypto/s;->bGx:Ljavax/crypto/KeyAgreement;
invoke-virtual {v0}, Ljavax/crypto/KeyAgreement;->generateSecret()[B
:try_end_1e
.catch Ljava/security/GeneralSecurityException; {:try_start_0 .. :try_end_1e} :catch_20
move-result-object v0
return-object v0
.line 145
:catch_20
move-exception v0
.line 146
new-instance v1, Lcom/subgraph/orchid/TorException;
invoke-direct {v1, v0}, Lcom/subgraph/orchid/TorException;-><init>(Ljava/lang/Throwable;)V
throw v1
.end method
.method private static generateKeyPair()Ljava/security/KeyPair;
.registers 2
.prologue
.line 161
:try_start_0
const-string v0, "DH"
invoke-static {v0}, Ljava/security/KeyPairGenerator;->getInstance(Ljava/lang/String;)Ljava/security/KeyPairGenerator;
move-result-object v0
.line 162
sget-object v1, Lcom/subgraph/orchid/crypto/s;->bGw:Ljavax/crypto/spec/DHParameterSpec;
invoke-virtual {v0, v1}, Ljava/security/KeyPairGenerator;->initialize(Ljava/security/spec/AlgorithmParameterSpec;)V
.line 163
invoke-virtual {v0}, Ljava/security/KeyPairGenerator;->generateKeyPair()Ljava/security/KeyPair;
:try_end_e
.catch Ljava/security/GeneralSecurityException; {:try_start_0 .. :try_end_e} :catch_10
move-result-object v0
return-object v0
.line 164
:catch_10
move-exception v0
.line 165
new-instance v1, Lcom/subgraph/orchid/TorException;
invoke-direct {v1, v0}, Lcom/subgraph/orchid/TorException;-><init>(Ljava/lang/Throwable;)V
throw v1
.end method
# virtual methods
.method public final a(Ljava/math/BigInteger;[B[B[B)Z
.registers 7
.prologue
.line 187
invoke-static {p1}, Lcom/subgraph/orchid/crypto/s;->f(Ljava/math/BigInteger;)Z
move-result v0
if-nez v0, :cond_e
.line 188
new-instance v0, Lcom/subgraph/orchid/TorException;
const-string v1, "Illegal DH public value"
invoke-direct {v0, v1}, Lcom/subgraph/orchid/TorException;-><init>(Ljava/lang/String;)V
throw v0
.line 190
:cond_e
invoke-direct {p0, p1}, Lcom/subgraph/orchid/crypto/s;->g(Ljava/math/BigInteger;)[B
move-result-object v0
.line 191
new-instance v1, Lcom/subgraph/orchid/crypto/l;
invoke-direct {v1, v0}, Lcom/subgraph/orchid/crypto/l;-><init>([B)V
.line 192
invoke-virtual {v1, p3, p4}, Lcom/subgraph/orchid/crypto/l;->g([B[B)V
.line 193
invoke-static {p4, p2}, Ljava/util/Arrays;->equals([B[B)Z
move-result v0
return v0
.end method
.method public final b([B[B[B)Z
.registers 8
.prologue
.line 177
invoke-static {p1}, Ljava/nio/ByteBuffer;->wrap([B)Ljava/nio/ByteBuffer;
move-result-object v0
.line 178
const/16 v1, 0x80
new-array v1, v1, [B
.line 179
const/16 v2, 0x14
new-array v2, v2, [B
.line 180
invoke-virtual {v0, v1}, Ljava/nio/ByteBuffer;->get([B)Ljava/nio/ByteBuffer;
.line 181
invoke-virtual {v0, v2}, Ljava/nio/ByteBuffer;->get([B)Ljava/nio/ByteBuffer;
.line 182
new-instance v0, Ljava/math/BigInteger;
const/4 v3, 0x1
invoke-direct {v0, v3, v1}, Ljava/math/BigInteger;-><init>(I[B)V
.line 183
invoke-virtual {p0, v0, v2, p2, p3}, Lcom/subgraph/orchid/crypto/s;->a(Ljava/math/BigInteger;[B[B[B)Z
move-result v0
return v0
.end method
.method public final getPublicKeyBytes()[B
.registers 7
.prologue
const/16 v5, 0x80
const/4 v4, 0x0
.line 97
new-array v1, v5, [B
.line 1086
iget-object v0, p0, Lcom/subgraph/orchid/crypto/s;->bGy:Ljava/security/KeyPair;
invoke-virtual {v0}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;
move-result-object v0
check-cast v0, Ljavax/crypto/interfaces/DHPublicKey;
.line 1087
invoke-interface {v0}, Ljavax/crypto/interfaces/DHPublicKey;->getY()Ljava/math/BigInteger;
move-result-object v0
.line 98
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v0
.line 99
aget-byte v2, v0, v4
if-nez v2, :cond_23
array-length v2, v0
const/16 v3, 0x81
if-ne v2, v3, :cond_23
.line 100
const/4 v2, 0x1
invoke-static {v0, v2, v1, v4, v5}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
.line 107
:goto_22
return-object v1
.line 101
:cond_23
array-length v2, v0
if-gt v2, v5, :cond_2e
.line 102
array-length v2, v0
rsub-int v2, v2, 0x80
.line 103
array-length v3, v0
invoke-static {v0, v4, v1, v2, v3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
goto :goto_22
.line 105
:cond_2e
new-instance v0, Ljava/lang/IllegalStateException;
const-string v1, "Public value is longer than DH_LEN but not because of sign bit"
invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
throw v0
.end method