summaryrefslogtreecommitdiffstats
path: root/lib/srp.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2022-04-10 12:30:20 -0400
committersiddharth <s@ricketyspace.net>2022-04-10 12:30:20 -0400
commitf613d9d03211efed74dcc9e5674f7eb8d9a94325 (patch)
treece5e9d7b96156960d8f391857dd274dc9aae5c82 /lib/srp.go
parentac3632e554c576c4d7e24bca17d3f23abf664883 (diff)
lib: add srp scrambling parameter functions
Diffstat (limited to 'lib/srp.go')
-rw-r--r--lib/srp.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/srp.go b/lib/srp.go
index 05b61ab..2303793 100644
--- a/lib/srp.go
+++ b/lib/srp.go
@@ -170,6 +170,35 @@ func (u *SRPUser) EphemeralKeyPub() (*big.Int, error) {
return pub, nil
}
+func (u *SRPUser) SetScramblingParam(a *big.Int) error {
+ b, err := u.EphemeralKeyPub()
+ if err != nil {
+ return err
+ }
+ bb := b.Bytes()
+ ab := a.Bytes()
+
+ // Make M=A+B
+ m := make([]byte, 0)
+ m = append(m, ab...)
+ m = append(m, bb...)
+ if len(m) != (len(ab) + len(bb)) {
+ return CPError{"length of m is incorrect"}
+ }
+
+ // Hash M
+ u.h.Message(m)
+ h := u.h.Hash()
+
+ // Set scrambling paramter u
+ u.u = new(big.Int)
+ u.u.SetBytes(h)
+ if u.u.Cmp(big.NewInt(0)) != 1 {
+ return CPError{"u is invalid"}
+ }
+ return nil
+}
+
func NewSRPClientSession(n, g, k, ident string) (*SRPClientSession, error) {
var ok bool
@@ -212,3 +241,32 @@ func (s *SRPClientSession) EphemeralKeyPub() (*big.Int, error) {
return pub, nil
}
+
+func (s *SRPClientSession) SetScramblingParam(b *big.Int) error {
+ a, err := s.EphemeralKeyPub()
+ if err != nil {
+ return err
+ }
+ ab := a.Bytes()
+ bb := b.Bytes()
+
+ // Make M=A+B
+ m := make([]byte, 0)
+ m = append(m, ab...)
+ m = append(m, bb...)
+ if len(m) != (len(ab) + len(bb)) {
+ return CPError{"length of m is incorrect"}
+ }
+
+ // Hash M
+ s.h.Message(m)
+ h := s.h.Hash()
+
+ // Set scrambling paramter u
+ s.u = new(big.Int)
+ s.u.SetBytes(h)
+ if s.u.Cmp(big.NewInt(0)) != 1 {
+ return CPError{"u is invalid"}
+ }
+ return nil
+}