Commit 103d6e17 authored by gerd's avatar gerd

Instead of calling 'f' sequently, there is now a loop. This

prevents the compiler from inlining the 16 invocations of 'f', which
leads to shorter code and MUCH better cache performance.


git-svn-id: https://godirepo.camlcity.org/svn/lib-cryptgps/trunk@3 b101cce4-44db-0310-b718-db4b2d8d2e05
parent eba42ba4
(* $Id: crypt_des.ml,v 1.1 1999/06/17 14:55:04 gerd Exp $
(* $Id: crypt_des.ml,v 1.2 1999/06/17 15:24:24 gerd Exp $
* ----------------------------------------------------------------------
*
*)
......@@ -518,24 +518,17 @@ module Cryptsystem : Cryptsystem_64.T =
(p0 lxor l32_0, p1 lxor l32_1)
in
let rec do_rounds i blast0 blast1 last0 last1 =
if i < 16 then
let r0,r1 = f k.(i) blast0 blast1 last0 last1 in
do_rounds (i+1) last0 last1 r0 r1
else
do_perm64 fperm (last0, last1, blast0, blast1)
in
let (l00, l01, r00, r01) = do_perm64 iperm x in
let (r10, r11) = f k.(0) l00 l01 r00 r01 in
let (r20, r21) = f k.(1) r00 r01 r10 r11 in
let (r30, r31) = f k.(2) r10 r11 r20 r21 in
let (r40, r41) = f k.(3) r20 r21 r30 r31 in
let (r50, r51) = f k.(4) r30 r31 r40 r41 in
let (r60, r61) = f k.(5) r40 r41 r50 r51 in
let (r70, r71) = f k.(6) r50 r51 r60 r61 in
let (r80, r81) = f k.(7) r60 r61 r70 r71 in
let (r90, r91) = f k.(8) r70 r71 r80 r81 in
let (ra0, ra1) = f k.(9) r80 r81 r90 r91 in
let (rb0, rb1) = f k.(10) r90 r91 ra0 ra1 in
let (rc0, rc1) = f k.(11) ra0 ra1 rb0 rb1 in
let (rd0, rd1) = f k.(12) rb0 rb1 rc0 rc1 in
let (re0, re1) = f k.(13) rc0 rc1 rd0 rd1 in
let (rf0, rf1) = f k.(14) rd0 rd1 re0 re1 in
let (rg0, rg1) = f k.(15) re0 re1 rf0 rf1 in
do_perm64 fperm (rg0, rg1, rf0, rf1)
do_rounds 0 l00 l01 r00 r01
let encrypt_ecb k x =
des k.k_enc x
......@@ -714,6 +707,11 @@ module Cryptmodes = Cryptmodes_64.Make_modes(Cryptsystem)
* history:
*
* $Log: crypt_des.ml,v $
* Revision 1.2 1999/06/17 15:24:24 gerd
* Instead of calling 'f' sequently, there is now a loop. This
* prevents the compiler from inlining the 16 invocations of 'f', which
* leads to shorter code and MUCH better cache performance.
*
* Revision 1.1 1999/06/17 14:55:04 gerd
* Added module for DES.
*
......
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