From afc801186f2591555eb43c0138ac1951da02cea4 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 9 Apr 2022 20:26:52 -0400 Subject: lib: add NewSRPClientSession --- lib/srp.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/srp.go') diff --git a/lib/srp.go b/lib/srp.go index 20208a6..491565c 100644 --- a/lib/srp.go +++ b/lib/srp.go @@ -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 +} -- cgit v1.2.3