forked from quic-go/quic-go
fix randomness
This commit is contained in:
@@ -3,6 +3,7 @@ package crypto
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
|
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
@@ -18,7 +19,7 @@ var _ KeyExchange = &curve25519KEX{}
|
|||||||
// NewCurve25519KEX creates a new KeyExchange using Curve25519, see https://cr.yp.to/ecdh.html
|
// NewCurve25519KEX creates a new KeyExchange using Curve25519, see https://cr.yp.to/ecdh.html
|
||||||
func NewCurve25519KEX() KeyExchange {
|
func NewCurve25519KEX() KeyExchange {
|
||||||
c := &curve25519KEX{}
|
c := &curve25519KEX{}
|
||||||
if n, err := rand.Reader.Read(c.secret[:]); n != 32 || err != nil {
|
if _, err := io.ReadFull(rand.Reader, c.secret[:]); err != nil {
|
||||||
panic("Curve25519: could not create private key")
|
panic("Curve25519: could not create private key")
|
||||||
}
|
}
|
||||||
// See https://cr.yp.to/ecdh.html
|
// See https://cr.yp.to/ecdh.html
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/crypto"
|
"github.com/lucas-clemente/quic-go/crypto"
|
||||||
@@ -37,7 +38,7 @@ var _ crypto.AEAD = &CryptoSetup{}
|
|||||||
// NewCryptoSetup creates a new CryptoSetup instance
|
// NewCryptoSetup creates a new CryptoSetup instance
|
||||||
func NewCryptoSetup(connID protocol.ConnectionID, version protocol.VersionNumber, scfg *ServerConfig, cryptoStream utils.Stream) *CryptoSetup {
|
func NewCryptoSetup(connID protocol.ConnectionID, version protocol.VersionNumber, scfg *ServerConfig, cryptoStream utils.Stream) *CryptoSetup {
|
||||||
nonce := make([]byte, 32)
|
nonce := make([]byte, 32)
|
||||||
if _, err := rand.Reader.Read(nonce); err != nil {
|
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return &CryptoSetup{
|
return &CryptoSetup{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package handshake
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/crypto"
|
"github.com/lucas-clemente/quic-go/crypto"
|
||||||
)
|
)
|
||||||
@@ -17,7 +18,7 @@ type ServerConfig struct {
|
|||||||
// NewServerConfig creates a new server config
|
// NewServerConfig creates a new server config
|
||||||
func NewServerConfig(kex crypto.KeyExchange, signer crypto.Signer) *ServerConfig {
|
func NewServerConfig(kex crypto.KeyExchange, signer crypto.Signer) *ServerConfig {
|
||||||
id := make([]byte, 16)
|
id := make([]byte, 16)
|
||||||
_, err := rand.Reader.Read(id)
|
_, err := io.ReadFull(rand.Reader, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user