Skip to content

Commit

Permalink
fix bug, assiging to nil MAP in album Updates chan,
Browse files Browse the repository at this point in the history
add pollarid rho Algorithm in SplitPQ (15x faster) (Authkey Gen)
  • Loading branch information
AmarnathCJD committed Feb 7, 2024
1 parent ae5b421 commit f3a051f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func DoRSAencrypt(block []byte, key *rsa.PublicKey) []byte {
// SplitPQ splits a number into two primes, while p1 < p2
// Part of diffie hellman's algorithm, how it works - no idea
func SplitPQ(pq *big.Int) (p1, p2 *big.Int) {
// Benchmark: Fac 15x faster than SplitPQ
return Fac(pq) // TODO: test extensively for fail cases
rndmax := big.NewInt(0).SetBit(big.NewInt(0), 64, 1)

what := big.NewInt(0).Set(pq)
Expand Down Expand Up @@ -127,3 +129,42 @@ func Xor(dst, src []byte) {
dst[i] ^= src[i]
}
}

// Fac splits a number into two primes, while p < q
// Part of diffie hellman's algorithm
// Uses Pollard's rho algorithm
func Fac(pq *big.Int) (p, q *big.Int) {
p = big.NewInt(0).Set(pq)
q = big.NewInt(1)

x := big.NewInt(2)
y := big.NewInt(2)
d := big.NewInt(1)

for d.Cmp(big.NewInt(1)) == 0 {
x = f(x, pq)
y = f(f(y, pq), pq)

temp := big.NewInt(0).Set(x)
temp.Sub(temp, y)
temp.Abs(temp)
d.GCD(nil, nil, temp, pq)
}

p.Set(d)
q.Div(pq, d)

if p.Cmp(q) == 1 {
p, q = q, p
}

return p, q
}

func f(x, n *big.Int) *big.Int {
result := big.NewInt(0).Set(x)
result.Mul(result, result)
result.Add(result, big.NewInt(1))
result.Mod(result, n)
return result
}
3 changes: 3 additions & 0 deletions telegram/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func (c *Client) handleAlbum(message MessageObj) {
messages: []*NewMessage{packMessage(c, &message)},
groupedId: message.GroupedID,
}
if c.dispatcher.activeAlbums == nil {
c.dispatcher.activeAlbums = make(map[int64]*albumBox)
}
c.dispatcher.activeAlbums[message.GroupedID] = abox
go func() {
<-abox.waitExit
Expand Down

0 comments on commit f3a051f

Please sign in to comment.