forked from quic-go/quic-go
move nonce generation to separate file
This commit is contained in:
@@ -2,7 +2,6 @@ package crypto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/aead/chacha20"
|
"github.com/aead/chacha20"
|
||||||
@@ -50,10 +49,3 @@ func (aead *aeadChacha20Poly1305) Open(dst, src []byte, packetNumber protocol.Pa
|
|||||||
func (aead *aeadChacha20Poly1305) Seal(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) []byte {
|
func (aead *aeadChacha20Poly1305) Seal(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) []byte {
|
||||||
return aead.encrypter.Seal(dst, makeNonce(aead.myIV, packetNumber), src, associatedData)
|
return aead.encrypter.Seal(dst, makeNonce(aead.myIV, packetNumber), src, associatedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeNonce(iv []byte, packetNumber protocol.PacketNumber) []byte {
|
|
||||||
res := make([]byte, 12)
|
|
||||||
copy(res[0:4], iv)
|
|
||||||
binary.LittleEndian.PutUint64(res[4:12], uint64(packetNumber))
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|||||||
14
crypto/nonce.go
Normal file
14
crypto/nonce.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package crypto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
|
||||||
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeNonce(iv []byte, packetNumber protocol.PacketNumber) []byte {
|
||||||
|
res := make([]byte, 12)
|
||||||
|
copy(res[0:4], iv)
|
||||||
|
binary.LittleEndian.PutUint64(res[4:12], uint64(packetNumber))
|
||||||
|
return res
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user