Set len to 0 on init
This commit is contained in:
parent
01792a7f59
commit
43d94fdf50
|
@ -12,7 +12,7 @@ const noncesize int = 16
|
||||||
func Encrypt(key []byte, plaintext []byte, additionalData []byte) ([]byte, error) {
|
func Encrypt(key []byte, plaintext []byte, additionalData []byte) ([]byte, error) {
|
||||||
|
|
||||||
cipher := make([]byte, len(plaintext)+abytes+noncesize)
|
cipher := make([]byte, len(plaintext)+abytes+noncesize)
|
||||||
var cipherlen uint64
|
var cipherlen uint64 = (uint64)(len(cipher))
|
||||||
nonce := genNonce()
|
nonce := genNonce()
|
||||||
ret := romulus_m_encrypt(
|
ret := romulus_m_encrypt(
|
||||||
cipher[noncesize:],
|
cipher[noncesize:],
|
||||||
|
@ -30,13 +30,13 @@ func Encrypt(key []byte, plaintext []byte, additionalData []byte) ([]byte, error
|
||||||
return nil, errors.New("Failed to decrypt")
|
return nil, errors.New("Failed to decrypt")
|
||||||
}
|
}
|
||||||
copy(cipher, nonce)
|
copy(cipher, nonce)
|
||||||
return cipher[:cipherlen], nil
|
return cipher[:(int)(cipherlen)+noncesize], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Decrypt(key []byte, ciphertext []byte, additionalData []byte) ([]byte, bool, error) {
|
func Decrypt(key []byte, ciphertext []byte, additionalData []byte) ([]byte, bool, error) {
|
||||||
|
|
||||||
plaintext := make([]byte, len(ciphertext))
|
plaintext := make([]byte, len(ciphertext))
|
||||||
var plaintextLen uint64
|
var plaintextLen uint64 = (uint64)(len(plaintext))
|
||||||
ret := romulus_m_decrypt(
|
ret := romulus_m_decrypt(
|
||||||
plaintext,
|
plaintext,
|
||||||
&plaintextLen,
|
&plaintextLen,
|
||||||
|
|
|
@ -439,9 +439,7 @@ func romulus_m_decrypt(m []byte, mlen *uint64, nsec []byte, c []byte, clen uint6
|
||||||
|
|
||||||
reset_lfsr_gf56(CNT[:])
|
reset_lfsr_gf56(CNT[:])
|
||||||
|
|
||||||
for i = 0; i < 16; i++ {
|
copy(T[:], c[len(c)-len(T):])
|
||||||
T[i] = (c[clen-16+uint64(i):])[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
for i = 0; i < n; i = i + 1 {
|
for i = 0; i < n; i = i + 1 {
|
||||||
s[i] = T[i]
|
s[i] = T[i]
|
||||||
|
|
Loading…
Reference in New Issue