mirror of
https://github.com/slackhq/nebula.git
synced 2026-05-16 04:47:38 +02:00
save pennies
This commit is contained in:
12
noise.go
12
noise.go
@@ -15,14 +15,14 @@ type endianness interface {
|
|||||||
var noiseEndianness endianness = binary.BigEndian
|
var noiseEndianness endianness = binary.BigEndian
|
||||||
|
|
||||||
type NebulaCipherState struct {
|
type NebulaCipherState struct {
|
||||||
c noise.Cipher
|
c cipher.AEAD
|
||||||
//k [32]byte
|
//k [32]byte
|
||||||
//n uint64
|
//n uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNebulaCipherState(s *noise.CipherState) *NebulaCipherState {
|
func NewNebulaCipherState(s *noise.CipherState) *NebulaCipherState {
|
||||||
return &NebulaCipherState{c: s.Cipher()}
|
x := s.Cipher()
|
||||||
|
return &NebulaCipherState{c: x.(cipher.AEAD)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncryptDanger encrypts and authenticates a given payload.
|
// EncryptDanger encrypts and authenticates a given payload.
|
||||||
@@ -46,7 +46,7 @@ func (s *NebulaCipherState) EncryptDanger(out, ad, plaintext []byte, n uint64, n
|
|||||||
nb[2] = 0
|
nb[2] = 0
|
||||||
nb[3] = 0
|
nb[3] = 0
|
||||||
noiseEndianness.PutUint64(nb[4:], n)
|
noiseEndianness.PutUint64(nb[4:], n)
|
||||||
out = s.c.(cipher.AEAD).Seal(out, nb, plaintext, ad)
|
out = s.c.Seal(out, nb, plaintext, ad)
|
||||||
//l.Debugf("Encryption: outlen: %d, nonce: %d, ad: %s, plainlen %d", len(out), n, ad, len(plaintext))
|
//l.Debugf("Encryption: outlen: %d, nonce: %d, ad: %s, plainlen %d", len(out), n, ad, len(plaintext))
|
||||||
return out, nil
|
return out, nil
|
||||||
} else {
|
} else {
|
||||||
@@ -61,7 +61,7 @@ func (s *NebulaCipherState) DecryptDanger(out, ad, ciphertext []byte, n uint64,
|
|||||||
nb[2] = 0
|
nb[2] = 0
|
||||||
nb[3] = 0
|
nb[3] = 0
|
||||||
noiseEndianness.PutUint64(nb[4:], n)
|
noiseEndianness.PutUint64(nb[4:], n)
|
||||||
return s.c.(cipher.AEAD).Open(out, nb, ciphertext, ad)
|
return s.c.Open(out, nb, ciphertext, ad)
|
||||||
} else {
|
} else {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ func (s *NebulaCipherState) DecryptDanger(out, ad, ciphertext []byte, n uint64,
|
|||||||
|
|
||||||
func (s *NebulaCipherState) Overhead() int {
|
func (s *NebulaCipherState) Overhead() int {
|
||||||
if s != nil {
|
if s != nil {
|
||||||
return s.c.(cipher.AEAD).Overhead()
|
return s.c.Overhead()
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user