This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRP6SrvSesKey.java
64 lines (54 loc) · 1.7 KB
/
SRP6SrvSesKey.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.github.glusk2.wse.common.crypto.srp6;
import java.math.BigInteger;
import com.github.glusk2.wse.common.util.Mapping;
/** SRP-6 Server Session Key - S. */
@SuppressWarnings("checkstyle:membername")
public final class SRP6SrvSesKey implements SRP6Integer {
private final SRP6Integer srp6_N;
private final SRP6Integer srp6_A;
private final SRP6Integer srp6_v;
private final SRP6Integer srp6_b;
private final SRP6Integer srp6_u;
private final Mapping<BigInteger, SRP6Integer> rule;
private SRP6Integer cachedValue;
@SuppressWarnings("checkstyle:parametername")
public SRP6SrvSesKey(
SRP6Integer N,
SRP6Integer A,
SRP6Integer v,
SRP6Integer u,
SRP6Integer b,
Mapping<BigInteger, SRP6Integer> rule
) {
this.srp6_N = N;
this.srp6_A = A;
this.srp6_v = v;
this.srp6_u = u;
this.srp6_b = b;
this.rule = rule;
}
@SuppressWarnings("checkstyle:localvariablename")
private SRP6Integer computeInteger() {
BigInteger N = srp6_N.bigInteger();
BigInteger A = srp6_A.bigInteger();
BigInteger v = srp6_v.bigInteger();
BigInteger b = srp6_b.bigInteger();
BigInteger u = srp6_u.bigInteger();
// S = (A*v^u)^b
return rule.map(A.multiply(v.modPow(u, N)).modPow(b, N));
}
@Override
public byte[] bytes() {
if (cachedValue == null) {
cachedValue = computeInteger();
}
return cachedValue.bytes();
}
@Override
public BigInteger bigInteger() {
if (cachedValue == null) {
cachedValue = computeInteger();
}
return cachedValue.bigInteger();
}
}