diff --git a/twofish/primitives.ml b/twofish/primitives.ml index 2228dab..56a626c 100644 --- a/twofish/primitives.ml +++ b/twofish/primitives.ml @@ -351,10 +351,15 @@ let mds_rem a b = in mds_rem_ab ((Int64.of_int32 a) & 0xFFFFFFFFL) ((Int64.of_int32 b) & 0xFFFFFFFFL) 0 +let key_size = 32 + let init key = let keylength = String.length key in - if keylength != 32 then - failwith ("init: key length must be 32, got key length "^string_of_int (keylength)) + if keylength != key_size then + failwith (Printf.sprintf + "init: key length must be %d, got key length %d" + key_size + (string_of_int keylength)) else let le_longs = unpack_longs key 8 in diff --git a/twofish/primitives.mli b/twofish/primitives.mli index 8ad5ba4..bd4fc61 100644 --- a/twofish/primitives.mli +++ b/twofish/primitives.mli @@ -1,4 +1,11 @@ type ctx +(** Some context? *) +(* XXX: Is this stateful?? *) +val key_size : int +(** [key_size] is the size of twofish keys. *) val init : string -> ctx +(** [init key] is the context / state initialized from secret key [key]. *) val encrypt : ctx -> string -> string +(** [encrypt ctx plain_text] is a single block encrypted with [ctx]. *) val decrypt : ctx -> string -> string +(** [encrypt ctx cipher_text] is a single block decrypted with [ctx]. *)