Migration: go1.20

This commit is contained in:
Dreamacro
2023-02-16 21:43:40 +08:00
parent fbf2f26516
commit 8173d6681b
15 changed files with 65 additions and 69 deletions

View File

@ -2,9 +2,10 @@ package protocol
import (
"bytes"
"crypto/rand"
"encoding/binary"
"math"
"math/rand"
mathRand "math/rand"
"net"
"strconv"
"strings"
@ -198,7 +199,7 @@ func (a *authAES128) packData(poolBuf *bytes.Buffer, data []byte, fullDataLength
}
func trapezoidRandom(max int, d float64) int {
base := rand.Float64()
base := mathRand.Float64()
if d-0 > 1e-6 {
a := 1 - d
base = (math.Sqrt(a*a+4*d*base) - a) / (2 * d)
@ -219,10 +220,10 @@ func (a *authAES128) getRandDataLengthForPackData(dataLength, fullDataLength int
if revLength > -1460 {
return trapezoidRandom(revLength+1460, -0.3)
}
return rand.Intn(32)
return mathRand.Intn(32)
}
if dataLength > 900 {
return rand.Intn(revLength)
return mathRand.Intn(revLength)
}
return trapezoidRandom(revLength, -0.3)
}
@ -247,7 +248,7 @@ func (a *authAES128) packAuthData(poolBuf *bytes.Buffer, data []byte) {
copy(macKey, a.iv)
copy(macKey[len(a.iv):], a.Key)
poolBuf.WriteByte(byte(rand.Intn(256)))
poolBuf.WriteByte(byte(mathRand.Intn(256)))
poolBuf.Write(a.hmac(macKey, poolBuf.Bytes())[:6])
poolBuf.Write(a.userID[:])
err := a.authData.putEncryptedData(poolBuf, a.userKey, [2]int{packedAuthDataLength, randDataLength}, a.salt)
@ -263,9 +264,9 @@ func (a *authAES128) packAuthData(poolBuf *bytes.Buffer, data []byte) {
func (a *authAES128) getRandDataLengthForPackAuthData(size int) int {
if size > 400 {
return rand.Intn(512)
return mathRand.Intn(512)
}
return rand.Intn(1024)
return mathRand.Intn(1024)
}
func (a *authAES128) packRandData(poolBuf *bytes.Buffer, size int) {

View File

@ -4,9 +4,10 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"encoding/binary"
"math/rand"
mathRand "math/rand"
"sync"
"time"
@ -38,7 +39,7 @@ func (a *authData) next() *authData {
defer a.mutex.Unlock()
if a.connectionID > 0xff000000 || a.connectionID == 0 {
rand.Read(a.clientID[:])
a.connectionID = rand.Uint32() & 0xffffff
a.connectionID = mathRand.Uint32() & 0xffffff
}
a.connectionID++
copy(r.clientID[:], a.clientID[:])