Repository navigation
Expand file tree
/
Copy pathclient.go
More file actions
78 lines (67 loc) · 1.51 KB
/
Copy pathclient.go
File metadata and controls
78 lines (67 loc) · 1.51 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package srp
import (
"bytes"
"crypto/rand"
"errors"
"math/big"
)
type SRPClient struct {
Params *SRPParams
Secret1 *big.Int
Multiplier *big.Int
A *big.Int
X *big.Int
M1 []byte
M2 []byte
K []byte
u *big.Int
s *big.Int
}
func NewSRPClient(param *SRPParams, a []byte) *SRPClient {
if len(a) == 0 {
a = make([]byte, 32)
rand.Read(a)
}
sec := a
multiplier := param.getMultiplier()
secret1Int := intFromBytes(sec)
Ab := param.calculateA(secret1Int)
A := intFromBytes(Ab)
return &SRPClient{
Params: param,
Multiplier: multiplier,
Secret1: secret1Int,
A: A,
}
}
// * ProcessClientChanllenge username, password, salt, B
func (kls *SRPClient) ProcessClientChanllenge(username, password, salt, B []byte) {
c := kls
c.X = c.Params.calculateX(salt, username, password)
bigB := intFromBytes(B)
u := c.Params.calculateU(c.A, bigB)
k := c.Multiplier
S := c.Params.calculateS(k, c.X, c.Secret1, bigB, u)
c.K = c.Params.calculateK(S)
c.u = u
c.s = intFromBytes(S)
A := padToN(c.A, c.Params)
c.M1 = c.Params.calculateM1(username, salt, A, B, c.K)
c.M2 = c.Params.calculateM2(A, c.M1, c.K)
}
func (c *SRPClient) GetABytes() []byte {
return padToN(c.A, c.Params)
}
func (c *SRPClient) GetM1Bytes() []byte {
return c.M1
}
func (c *SRPClient) GetSessionKey() []byte {
return c.K
}
func (c *SRPClient) CheckM2(M2 []byte) error {
if !bytes.Equal(c.M2, M2) {
return errors.New("M2 didn't check")
} else {
return nil
}
}