diff options
author | siddharth <s@ricketyspace.net> | 2022-04-09 20:26:52 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2022-04-09 20:26:52 -0400 |
commit | afc801186f2591555eb43c0138ac1951da02cea4 (patch) | |
tree | 54bd9e50c1a7e7024935dd7b8dd1e1a122c810a9 /lib/srp.go | |
parent | 33423e8e822165045f0506101763ff527cce9d22 (diff) |
lib: add NewSRPClientSession
Diffstat (limited to 'lib/srp.go')
-rw-r--r-- | lib/srp.go | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -78,6 +78,8 @@ type SRPClientSession struct { // Multipier parameter. Client and server agree upon the value // of N. k *big.Int + // Hashing object for H() function. + h Sha256 // User's email address ident string // Scrambling parameter. @@ -131,3 +133,31 @@ func NewSRPUser(n, g, k, ident, pass string) (*SRPUser, error) { return user, nil } + +func NewSRPClientSession(n, g, k, ident string) (*SRPClientSession, error) { + var ok bool + + session := new(SRPClientSession) + session.n, ok = new(big.Int).SetString(StripSpaceChars(n), 16) + if !ok { + return nil, CPError{"n is invalid"} + } + session.g, ok = new(big.Int).SetString(StripSpaceChars(g), 16) + if !ok { + return nil, CPError{"g is invalid"} + } + session.k, ok = new(big.Int).SetString(StripSpaceChars(k), 16) + if !ok { + return nil, CPError{"k is invalid"} + } + session.ident = ident + + // Initialize hashing object. + session.h = Sha256{} + session.h.Init([]uint32{}) + + // Generate secret ephemeral value. + session.a = big.NewInt(RandomInt(1, 10000000)) + + return session, nil +} |