Skip to content

Commit

Permalink
move a few functions from utils.go to srp.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Jan 23, 2021
1 parent 0cfab75 commit b8d7475
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 24 additions & 0 deletions srp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ func pad(v *big.Int) []byte {
return buf[i:]
}

func bigIntToBytes(v *big.Int) []byte {
buf := pad(v)
for i, _ := range buf {
if buf[i] != 0 {
return buf[i:]
}
}

return buf[:1] // 0
}

func bytesToBigInt(v []byte) (r *big.Int) {
m := new(big.Int)
m.SetInt64(256)
a := new(big.Int)
r = new(big.Int)
r.SetInt64(0)
for _, b := range v {
r = r.Mul(r, m)
r = r.Add(r, a.SetInt64(int64(b)))
}
return r
}

func getPrime() (prime *big.Int, g *big.Int, k *big.Int) {
prime = bigIntFromHexString("E67D2E994B2F900C3F41F08F5BB2627ED0D49EE1FE767A52EFCD565CD6E768812C3E1E9CE8F0A8BEA6CB13CD29DDEBF7A96D4A93B55D488DF099A15C89DCB0640738EB2CBDD9A8F7BAB561AB1B0DC1C6CDABF303264A08D1BCA932D1F1EE428B619D970F342ABA9A65793B8B2F041AE5364350C16F735F56ECBCA87BD57B29E7")
g = big.NewInt(2)
Expand Down
24 changes: 0 additions & 24 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,6 @@ func bigIntFromString(s string) *big.Int {
return ret
}

func bigIntToBytes(v *big.Int) []byte {
buf := pad(v)
for i, _ := range buf {
if buf[i] != 0 {
return buf[i:]
}
}

return buf[:1] // 0
}

func bytesToBigInt(v []byte) (r *big.Int) {
m := new(big.Int)
m.SetInt64(256)
a := new(big.Int)
r = new(big.Int)
r.SetInt64(0)
for _, b := range v {
r = r.Mul(r, m)
r = r.Add(r, a.SetInt64(int64(b)))
}
return r
}

func bigIntToSha1(n *big.Int) []byte {
sha1 := sha1.New()
sha1.Write(n.Bytes())
Expand Down

0 comments on commit b8d7475

Please sign in to comment.