1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: error on a.slice(x,y) outside builtin

This commit is contained in:
Delyan Angelov
2021-01-19 14:34:25 +02:00
parent 129eee346b
commit d9532eda30
7 changed files with 41 additions and 24 deletions

View File

@ -94,21 +94,20 @@ pub fn (mut x AesCbc) decrypt_blocks(mut dst []byte, src []byte) {
mut start := end - x.block_size
mut prev := start - x.block_size
// Copy the last block of ciphertext in preparation as the new iv.
copy(x.tmp, src.slice(start, end))
copy(x.tmp, src[start..end])
// Loop over all but the first block.
for start > 0 {
mut src_chunk := src.slice(start, end)
x.b.decrypt(mut (*dst).slice(start, end), mut src_chunk)
cipher.xor_bytes(mut (*dst).slice(start, end), (*dst).slice(start, end), src.slice(prev,
start))
mut src_chunk := src[start..end]
x.b.decrypt(mut (*dst)[start..end], mut src_chunk)
cipher.xor_bytes(mut (*dst)[start..end], (*dst)[start..end], src[prev..start])
end = start
start = prev
prev -= x.block_size
}
// The first block is special because it uses the saved iv.
mut src_chunk := src.slice(start, end)
x.b.decrypt(mut (*dst).slice(start, end), mut src_chunk)
cipher.xor_bytes(mut (*dst).slice(start, end), (*dst).slice(start, end), x.iv)
mut src_chunk := src[start..end]
x.b.decrypt(mut (*dst)[start..end], mut src_chunk)
cipher.xor_bytes(mut (*dst)[start..end], (*dst)[start..end], x.iv)
// Set the new iv to the first block we copied earlier.
x.iv = x.tmp
x.tmp = x.iv

View File

@ -41,9 +41,9 @@ import encoding.binary
fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
_ = src[15] // early bounds check
mut s0 := binary.big_endian_u32(src[..4])
mut s1 := binary.big_endian_u32(src.slice(4, 8))
mut s2 := binary.big_endian_u32(src.slice(8, 12))
mut s3 := binary.big_endian_u32(src.slice(12, 16))
mut s1 := binary.big_endian_u32(src[4..8])
mut s2 := binary.big_endian_u32(src[8..12])
mut s3 := binary.big_endian_u32(src[12..16])
// First round just XORs input with key.
s0 ^= xk[0]
s1 ^= xk[1]
@ -83,18 +83,18 @@ fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
s3 ^= xk[k + 3]
_ := dst[15] // early bounds check
binary.big_endian_put_u32(mut (*dst)[0..4], s0)
binary.big_endian_put_u32(mut (*dst).slice(4, 8), s1)
binary.big_endian_put_u32(mut (*dst).slice(8, 12), s2)
binary.big_endian_put_u32(mut (*dst).slice(12, 16), s3)
binary.big_endian_put_u32(mut (*dst)[4..8], s1)
binary.big_endian_put_u32(mut (*dst)[8..12], s2)
binary.big_endian_put_u32(mut (*dst)[12..16], s3)
}
// Decrypt one block from src into dst, using the expanded key xk.
fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
_ = src[15] // early bounds check
mut s0 := binary.big_endian_u32(src[0..4])
mut s1 := binary.big_endian_u32(src.slice(4, 8))
mut s2 := binary.big_endian_u32(src.slice(8, 12))
mut s3 := binary.big_endian_u32(src.slice(12, 16))
mut s1 := binary.big_endian_u32(src[4..8])
mut s2 := binary.big_endian_u32(src[8..12])
mut s3 := binary.big_endian_u32(src[12..16])
// First round just XORs input with key.
s0 ^= xk[0]
s1 ^= xk[1]
@ -134,9 +134,9 @@ fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
s3 ^= xk[k + 3]
_ = dst[15] // early bounds check
binary.big_endian_put_u32(mut (*dst)[..4], s0)
binary.big_endian_put_u32(mut (*dst).slice(4, 8), s1)
binary.big_endian_put_u32(mut (*dst).slice(8, 12), s2)
binary.big_endian_put_u32(mut (*dst).slice(12, 16), s3)
binary.big_endian_put_u32(mut (*dst)[4..8], s1)
binary.big_endian_put_u32(mut (*dst)[8..12], s2)
binary.big_endian_put_u32(mut (*dst)[12..16], s3)
}
// Apply s_box0 to each byte in w.