@@ -47,7 +47,7 @@ class CBC : public Mode<T> {
47
47
// FIXME: We should have two of these encrypt/decrypt functions that
48
48
// we SFINAE out based on whether the Cipher mode needs an ivec
49
49
VERIFY (!ivec.is_empty ());
50
- const auto * iv = ivec. data () ;
50
+ ReadonlyBytes iv = ivec;
51
51
52
52
m_cipher_block.set_padding_mode (cipher.padding_mode ());
53
53
size_t offset { 0 };
@@ -59,7 +59,7 @@ class CBC : public Mode<T> {
59
59
cipher.encrypt_block (m_cipher_block, m_cipher_block);
60
60
VERIFY (offset + block_size <= out.size ());
61
61
__builtin_memcpy (out.offset (offset), m_cipher_block.bytes ().data (), block_size);
62
- iv = out.offset (offset);
62
+ iv = out.slice (offset);
63
63
length -= block_size;
64
64
offset += block_size;
65
65
}
@@ -70,11 +70,11 @@ class CBC : public Mode<T> {
70
70
cipher.encrypt_block (m_cipher_block, m_cipher_block);
71
71
VERIFY (offset + block_size <= out.size ());
72
72
__builtin_memcpy (out.offset (offset), m_cipher_block.bytes ().data (), block_size);
73
- iv = out.offset (offset);
73
+ iv = out.slice (offset);
74
74
}
75
75
76
76
if (ivec_out)
77
- __builtin_memcpy (ivec_out->data (), iv, min (IV_length (), ivec_out->size ()));
77
+ __builtin_memcpy (ivec_out->data (), iv. data () , min (IV_length (), ivec_out->size ()));
78
78
}
79
79
80
80
virtual void decrypt (ReadonlyBytes in, Bytes& out, ReadonlyBytes ivec = {}) override
@@ -86,7 +86,7 @@ class CBC : public Mode<T> {
86
86
auto & cipher = this ->cipher ();
87
87
88
88
VERIFY (!ivec.is_empty ());
89
- const auto * iv = ivec. data () ;
89
+ ReadonlyBytes iv = ivec;
90
90
91
91
auto block_size = cipher.block_size ();
92
92
@@ -98,8 +98,8 @@ class CBC : public Mode<T> {
98
98
size_t offset { 0 };
99
99
100
100
while (length > 0 ) {
101
- auto * slice = in.offset (offset);
102
- m_cipher_block.overwrite (slice, block_size);
101
+ auto slice = in.slice (offset);
102
+ m_cipher_block.overwrite (slice. data () , block_size);
103
103
cipher.decrypt_block (m_cipher_block, m_cipher_block);
104
104
m_cipher_block.apply_initialization_vector (iv);
105
105
auto decrypted = m_cipher_block.bytes ();
0 commit comments