move nonce generation to separate file

This commit is contained in:
Lucas Clemente
2016-08-01 16:27:38 +02:00
parent 8a9f5f9833
commit 8a08171322
2 changed files with 14 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package crypto
import (
"crypto/cipher"
"encoding/binary"
"errors"
"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 {
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
View 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
}