mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 20:24:03 +03:00
Small subtle optimizations of faketls
This commit is contained in:
@@ -3,6 +3,7 @@ package faketls
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -39,10 +40,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
||||
}
|
||||
|
||||
copy(hello.Random[:], handshake[ClientHelloRandomOffset:])
|
||||
|
||||
for i := ClientHelloRandomOffset; i < ClientHelloRandomOffset+RandomLen; i++ {
|
||||
handshake[i] = 0
|
||||
}
|
||||
copy(handshake[ClientHelloRandomOffset:], clientHelloEmptyRandom)
|
||||
|
||||
rec := record.AcquireRecord()
|
||||
defer record.ReleaseRecord(rec)
|
||||
@@ -62,10 +60,8 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
||||
computedRandom[i] ^= hello.Random[i]
|
||||
}
|
||||
|
||||
for i := 0; i < RandomLen-4; i++ {
|
||||
if computedRandom[i] != 0 {
|
||||
return hello, ErrBadDigest
|
||||
}
|
||||
if subtle.ConstantTimeCompare(clientHelloEmptyRandom[:RandomLen-4], computedRandom[:RandomLen-4]) != 1 {
|
||||
return hello, ErrBadDigest
|
||||
}
|
||||
|
||||
timestamp := int64(binary.LittleEndian.Uint32(computedRandom[RandomLen-4:]))
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package faketls
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
RandomLen = 32
|
||||
@@ -34,4 +37,5 @@ var (
|
||||
0x00, 0x1d, // x25519 curve
|
||||
0x00, 0x20, // 32 bytes of key
|
||||
}
|
||||
clientHelloEmptyRandom = bytes.Repeat([]byte{0}, RandomLen)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user