Commit dd3fc1ec authored by gerd's avatar gerd

Some additions have been turned into lor operations (faster).

	The Lazy.force calls in the 'des' functions have been avoided.


git-svn-id: https://godirepo.camlcity.org/svn/lib-cryptgps/trunk@9 b101cce4-44db-0310-b718-db4b2d8d2e05
parent 7b25cd71
(* $Id: crypt_des.ml,v 1.7 1999/06/17 20:39:46 gerd Exp $
(* $Id: crypt_des.ml,v 1.8 1999/06/17 21:00:31 gerd Exp $
* ----------------------------------------------------------------------
*
*)
......@@ -530,28 +530,34 @@ module Cryptsystem : Cryptsystem_64.T =
k_enc : value48 array;
k_dec : value48 array;
fperm : perm64;
ixperm : perm64;
sbox1 : (int * int) array;
sbox2 : (int * int) array;
sbox3 : (int * int) array;
sbox4 : (int * int) array;
sbox5 : (int * int) array;
sbox6 : (int * int) array;
sbox7 : (int * int) array;
sbox8 : (int * int) array;
(* k_enc: encryption keys for 16 rounds;
* k_dec: decryption keys for 16 rounds
*)
}
let des k x =
let iperm = Lazy.force des_iperm in
let fperm = Lazy.force des_fperm in
let kperm = Lazy.force des_kperm in
let cperm = Lazy.force des_cperm in
let xperm = Lazy.force des_xperm in
let ixperm = Lazy.force des_ixperm in
let pboxperm = Lazy.force des_pboxperm in
let s1 = Lazy.force sbox1 in
let s2 = Lazy.force sbox2 in
let s3 = Lazy.force sbox3 in
let s4 = Lazy.force sbox4 in
let s5 = Lazy.force sbox5 in
let s6 = Lazy.force sbox6 in
let s7 = Lazy.force sbox7 in
let s8 = Lazy.force sbox8 in
let des key k x =
let fperm = key.fperm in
let ixperm = key.ixperm in
let s1 = key.sbox1 in
let s2 = key.sbox2 in
let s3 = key.sbox3 in
let s4 = key.sbox4 in
let s5 = key.sbox5 in
let s6 = key.sbox6 in
let s7 = key.sbox7 in
let s8 = key.sbox8 in
let rec do_rounds i blast0 blast1 last0 last1 =
let l48_0 = blast0 in
......@@ -600,14 +606,14 @@ module Cryptsystem : Cryptsystem_64.T =
(* --------- manually inlined code ---------- *)
(* OLD: do_perm64 fperm (last0, last1, blast0, blast1) *)
let (a0,b0,c0,d0) = fperm.( r32_0 lsr 8 ) in
let (a1,b1,c1,d1) = fperm.( 256 + (r32_0 land 0xff)) in
let (a2,b2,c2,d2) = fperm.( 512 + (r32_1 lsr 8) ) in
let (a3,b3,c3,d3) = fperm.( 768 + (r32_1 land 0xff) ) in
let (a4,b4,c4,d4) = fperm.( 1024 + (l32_0 lsr 8) ) in
let (a5,b5,c5,d5) = fperm.( 1280 + (l32_0 land 0xff) ) in
let (a6,b6,c6,d6) = fperm.( 1536 + (l32_1 lsr 8) ) in
let (a7,b7,c7,d7) = fperm.( 1792 + (l32_1 land 0xff) ) in
let (a0,b0,c0,d0) = fperm.( r32_0 lsr 8 ) in
let (a1,b1,c1,d1) = fperm.( 256 lor (r32_0 land 0xff)) in
let (a2,b2,c2,d2) = fperm.( 512 lor (r32_1 lsr 8) ) in
let (a3,b3,c3,d3) = fperm.( 768 lor (r32_1 land 0xff) ) in
let (a4,b4,c4,d4) = fperm.( 1024 lor (l32_0 lsr 8) ) in
let (a5,b5,c5,d5) = fperm.( 1280 lor (l32_0 land 0xff) ) in
let (a6,b6,c6,d6) = fperm.( 1536 lor (l32_1 lsr 8) ) in
let (a7,b7,c7,d7) = fperm.( 1792 lor (l32_1 land 0xff) ) in
(a0 lor a1 lor a2 lor a3 lor a4 lor a5 lor a6 lor a7,
b0 lor b1 lor b2 lor b3 lor b4 lor b5 lor b6 lor b7,
......@@ -619,14 +625,14 @@ module Cryptsystem : Cryptsystem_64.T =
(* --------- manually inlined code ---------- *)
(* OLD: let (l00_48, l01_48, r00_48, r01_48) = do_perm64 ixperm x in *)
let (a,b,c,d) = x in
let (a0,b0,c0,d0) = ixperm.( a lsr 8 ) in
let (a1,b1,c1,d1) = ixperm.( 256 + (a land 0xff)) in
let (a2,b2,c2,d2) = ixperm.( 512 + (b lsr 8) ) in
let (a3,b3,c3,d3) = ixperm.( 768 + (b land 0xff) ) in
let (a4,b4,c4,d4) = ixperm.( 1024 + (c lsr 8) ) in
let (a5,b5,c5,d5) = ixperm.( 1280 + (c land 0xff) ) in
let (a6,b6,c6,d6) = ixperm.( 1536 + (d lsr 8) ) in
let (a7,b7,c7,d7) = ixperm.( 1792 + (d land 0xff) ) in
let (a0,b0,c0,d0) = ixperm.( a lsr 8 ) in
let (a1,b1,c1,d1) = ixperm.( 256 lor (a land 0xff)) in
let (a2,b2,c2,d2) = ixperm.( 512 lor (b lsr 8) ) in
let (a3,b3,c3,d3) = ixperm.( 768 lor (b land 0xff) ) in
let (a4,b4,c4,d4) = ixperm.( 1024 lor (c lsr 8) ) in
let (a5,b5,c5,d5) = ixperm.( 1280 lor (c land 0xff) ) in
let (a6,b6,c6,d6) = ixperm.( 1536 lor (d lsr 8) ) in
let (a7,b7,c7,d7) = ixperm.( 1792 lor (d land 0xff) ) in
let l00_48 = a0 lor a1 lor a2 lor a3 lor a4 lor a5 lor a6 lor a7 in
let l01_48 = b0 lor b1 lor b2 lor b3 lor b4 lor b5 lor b6 lor b7 in
let r00_48 = c0 lor c1 lor c2 lor c3 lor c4 lor c5 lor c6 lor c7 in
......@@ -637,10 +643,10 @@ module Cryptsystem : Cryptsystem_64.T =
let encrypt_ecb k x =
des k.k_enc x
des k k.k_enc x
let decrypt_ecb k x =
des k.k_dec x
des k k.k_dec x
let prepare key =
......@@ -725,7 +731,17 @@ module Cryptsystem : Cryptsystem_64.T =
k64 = k64;
k56 = k56;
k_enc = k_enc;
k_dec = k_dec
k_dec = k_dec;
fperm = Lazy.force des_fperm;
ixperm = Lazy.force des_ixperm;
sbox1 = Lazy.force sbox1;
sbox2 = Lazy.force sbox2;
sbox3 = Lazy.force sbox3;
sbox4 = Lazy.force sbox4;
sbox5 = Lazy.force sbox5;
sbox6 = Lazy.force sbox6;
sbox7 = Lazy.force sbox7;
sbox8 = Lazy.force sbox8;
}
......@@ -813,6 +829,10 @@ module Cryptmodes = Cryptmodes_64.Make_modes(Cryptsystem)
* history:
*
* $Log: crypt_des.ml,v $
* Revision 1.8 1999/06/17 21:00:31 gerd
* Some additions have been turned into lor operations (faster).
* The Lazy.force calls in the 'des' functions have been avoided.
*
* Revision 1.7 1999/06/17 20:39:46 gerd
* The initial iperm and xperm permutations have been combined
* such that only one table lookup is necessary.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment