From cc68f6f8673d12d6ce46ced54891bcaffa23ae02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Thu, 4 Oct 2018 09:40:32 +0200 Subject: [PATCH] CBC mode is without padding --- twofish/cbc.ml | 2 ++ twofish/cbc.mli | 3 +++ 2 files changed, 5 insertions(+) diff --git a/twofish/cbc.ml b/twofish/cbc.ml index f592c56..7e1265a 100644 --- a/twofish/cbc.ml +++ b/twofish/cbc.ml @@ -36,11 +36,13 @@ let xor_strings b c = let encrypt cbc enc p = + assert (String.length p = Primitive.key_ize); let p' = xor_strings p cbc.prev_v in let c = enc p' in (cbc.prev_v <- c; c) let decrypt cbc dec c = + assert (String.length p = Primitive.key_ize); let p = dec c in let p' = xor_strings p cbc.prev_v in (cbc.prev_v <- c; p') diff --git a/twofish/cbc.mli b/twofish/cbc.mli index 947fdea..12b5353 100644 --- a/twofish/cbc.mli +++ b/twofish/cbc.mli @@ -4,5 +4,8 @@ type state = } val init : string -> state +(** [init iv] is the initial state using [iv] a the initialization vector. *) val encrypt : state -> (string -> string) -> string -> string +(** Encrypt a single block in CBC mode. *) val decrypt : state -> (string -> string) -> string -> string +(** Decrypt a single block in CBC mode. *)