From 43d94fdf501fad64a132177be029d86a762eae73 Mon Sep 17 00:00:00 2001 From: Simon Maddocks Date: Sat, 5 Feb 2022 02:58:28 +0000 Subject: [PATCH] Set len to 0 on init --- romulus_m.go | 6 +++--- romulus_m_reference.go | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/romulus_m.go b/romulus_m.go index 936e632..ae1886d 100644 --- a/romulus_m.go +++ b/romulus_m.go @@ -12,7 +12,7 @@ const noncesize int = 16 func Encrypt(key []byte, plaintext []byte, additionalData []byte) ([]byte, error) { cipher := make([]byte, len(plaintext)+abytes+noncesize) - var cipherlen uint64 + var cipherlen uint64 = (uint64)(len(cipher)) nonce := genNonce() ret := romulus_m_encrypt( cipher[noncesize:], @@ -30,13 +30,13 @@ func Encrypt(key []byte, plaintext []byte, additionalData []byte) ([]byte, error return nil, errors.New("Failed to decrypt") } copy(cipher, nonce) - return cipher[:cipherlen], nil + return cipher[:(int)(cipherlen)+noncesize], nil } func Decrypt(key []byte, ciphertext []byte, additionalData []byte) ([]byte, bool, error) { plaintext := make([]byte, len(ciphertext)) - var plaintextLen uint64 + var plaintextLen uint64 = (uint64)(len(plaintext)) ret := romulus_m_decrypt( plaintext, &plaintextLen, diff --git a/romulus_m_reference.go b/romulus_m_reference.go index 58702a6..26d8282 100644 --- a/romulus_m_reference.go +++ b/romulus_m_reference.go @@ -439,9 +439,7 @@ func romulus_m_decrypt(m []byte, mlen *uint64, nsec []byte, c []byte, clen uint6 reset_lfsr_gf56(CNT[:]) - for i = 0; i < 16; i++ { - T[i] = (c[clen-16+uint64(i):])[0] - } + copy(T[:], c[len(c)-len(T):]) for i = 0; i < n; i = i + 1 { s[i] = T[i]