From bec05fe364bea89b0886f1fdfbbec17e90490c6e Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 18 Mar 2024 12:01:56 +0100 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Reynir Björnsson --- src/cipher_block.ml | 6 +++--- src/cipher_stream.ml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cipher_block.ml b/src/cipher_block.ml index 5716c5dd..3ae5cb3c 100644 --- a/src/cipher_block.ml +++ b/src/cipher_block.ml @@ -181,7 +181,7 @@ module Modes = struct let decrypt ~key:(_, key) ~iv src = bounds_check ~iv src ; - let msg = Bytes.of_string src + let msg = Bytes.create (String.length src) and b = String.length src / block in if b > 0 then begin Core.decrypt ~key ~blocks:b src 0 msg 0 ; @@ -329,8 +329,8 @@ module Modes = struct let (key_sizes, block_size) = C.(key, block) let cipher ~key src ~src_off dst ~dst_off = - if String.length src < block_size || Bytes.length dst < block_size then - invalid_arg "src len %u, dst len %u" (String.length src) (Bytes.length dst); + if String.length src - src_off < block_size || Bytes.length dst - dst_off < block_size then + invalid_arg "src len %u, dst len %u" (String.length src - src_off) (Bytes.length dst - dst_off); C.encrypt ~key ~blocks:1 src src_off dst dst_off let authenticate_encrypt_tag ~key ~nonce ?(adata = "") cs = diff --git a/src/cipher_stream.ml b/src/cipher_stream.ml index 561ddb8e..87aaec0c 100644 --- a/src/cipher_stream.ml +++ b/src/cipher_stream.ml @@ -43,7 +43,7 @@ module ARC4 = struct let sj = s.(j) in s.(i) <- sj ; s.(j) <- si ; let k = s.((si + sj) land 0xff) in - Bytes.(set_uint8 res n (k lxor string_get_uint8 buf n)); + Bytes.set_uint8 res n (k lxor string_get_uint8 buf n); mix i j (succ n) in let key' = mix i j 0 in