From 1a79e5419f4f6513e21f71da5256d2f2d3ae002d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 23 Apr 2020 16:45:25 +0300 Subject: [PATCH] tests: fix aes_test.v by manually dereferencing the mut dst parameter --- cmd/tools/vtest-fixed.v | 2 -- vlib/crypto/aes/aes_cbc.v | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/tools/vtest-fixed.v b/cmd/tools/vtest-fixed.v index 8151dd457a..bfb1bf950f 100644 --- a/cmd/tools/vtest-fixed.v +++ b/cmd/tools/vtest-fixed.v @@ -7,8 +7,6 @@ import v.pref const ( skip_test_files = [ 'vlib/arrays/arrays_test.v', - 'vlib/crypto/aes/aes_test.v', - 'vlib/crypto/rc4/rc4_test.v', 'vlib/eventbus/eventbus_test.v', 'vlib/json/json_test.v', 'vlib/net/ftp/ftp_test.v', diff --git a/vlib/crypto/aes/aes_cbc.v b/vlib/crypto/aes/aes_cbc.v index cbaa7f8538..2093258e4d 100644 --- a/vlib/crypto/aes/aes_cbc.v +++ b/vlib/crypto/aes/aes_cbc.v @@ -56,7 +56,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) { if dst.len < src.len { panic('crypto.cipher: output smaller than input') } - if subtle.inexact_overlap(dst[..src.len], src) { + if subtle.inexact_overlap((*dst)[..src.len], src) { panic('crypto.cipher: invalid buffer overlap') } @@ -64,17 +64,17 @@ pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) { for src.len > 0 { // Write the xor to dst, then encrypt in place. - cipher.xor_bytes(mut dst[..x.block_size], src[..x.block_size], iv) - x.b.encrypt(dst[..x.block_size], dst[..x.block_size]) + cipher.xor_bytes(mut (*dst)[..x.block_size], src[..x.block_size], iv) + x.b.encrypt((*dst)[..x.block_size], (*dst)[..x.block_size]) // Move to the next block with this block as the next iv. - iv = dst[..x.block_size] + iv = (*dst)[..x.block_size] if x.block_size >= src.len { src = [] } else { src = src[x.block_size..] } - (*dst) = dst[x.block_size..] + (*dst) = (*dst)[x.block_size..] } // Save the iv for the next crypt_blocks call. @@ -88,7 +88,7 @@ pub fn (x mut AesCbc) decrypt_blocks(dst mut []byte, src []byte) { if dst.len < src.len { panic('crypto.cipher: output smaller than input') } - if subtle.inexact_overlap(dst[..src.len], src) { + if subtle.inexact_overlap((*dst)[..src.len], src) { panic('crypto.cipher: invalid buffer overlap') } if src.len == 0 { @@ -106,8 +106,8 @@ pub fn (x mut AesCbc) decrypt_blocks(dst mut []byte, src []byte) { // Loop over all but the first block. for start > 0 { - x.b.decrypt(dst.slice(start, end), src.slice(start, end)) - cipher.xor_bytes(mut dst.slice(start, end), dst.slice(start, end), src.slice(prev, start)) + x.b.decrypt((*dst).slice(start, end), src.slice(start, end)) + cipher.xor_bytes(mut (*dst).slice(start, end), (*dst).slice(start, end), src.slice(prev, start)) end = start start = prev @@ -115,8 +115,8 @@ pub fn (x mut AesCbc) decrypt_blocks(dst mut []byte, src []byte) { } // The first block is special because it uses the saved iv. - x.b.decrypt(dst.slice(start, end), src.slice(start, end)) - cipher.xor_bytes(mut dst.slice(start, end), dst.slice(start, end), x.iv) + x.b.decrypt((*dst).slice(start, end), src.slice(start, end)) + cipher.xor_bytes(mut (*dst).slice(start, end), (*dst).slice(start, end), x.iv) // Set the new iv to the first block we copied earlier.