1
0
mirror of https://git.code.sf.net/p/lazarus-ccr/dcpcrypt synced 2025-07-02 22:56:50 +02:00

Normalise line endings

This commit is contained in:
Graeme Geldenhuys
2014-01-17 15:22:53 +00:00
parent fa93073a71
commit 610d6570e9
50 changed files with 15367 additions and 15367 deletions

View File

@ -1,264 +1,264 @@
const const
PBoxOrg: array[0..17] of DWord= ( PBoxOrg: array[0..17] of DWord= (
$243f6a88, $85a308d3, $13198a2e, $03707344, $243f6a88, $85a308d3, $13198a2e, $03707344,
$a4093822, $299f31d0, $082efa98, $ec4e6c89, $a4093822, $299f31d0, $082efa98, $ec4e6c89,
$452821e6, $38d01377, $be5466cf, $34e90c6c, $452821e6, $38d01377, $be5466cf, $34e90c6c,
$c0ac29b7, $c97c50dd, $3f84d5b5, $b5470917, $c0ac29b7, $c97c50dd, $3f84d5b5, $b5470917,
$9216d5d9, $8979fb1b); $9216d5d9, $8979fb1b);
SBoxOrg: array[0..3,0..255] of DWord= (( SBoxOrg: array[0..3,0..255] of DWord= ((
$d1310ba6, $98dfb5ac, $2ffd72db, $d01adfb7, $d1310ba6, $98dfb5ac, $2ffd72db, $d01adfb7,
$b8e1afed, $6a267e96, $ba7c9045, $f12c7f99, $b8e1afed, $6a267e96, $ba7c9045, $f12c7f99,
$24a19947, $b3916cf7, $0801f2e2, $858efc16, $24a19947, $b3916cf7, $0801f2e2, $858efc16,
$636920d8, $71574e69, $a458fea3, $f4933d7e, $636920d8, $71574e69, $a458fea3, $f4933d7e,
$0d95748f, $728eb658, $718bcd58, $82154aee, $0d95748f, $728eb658, $718bcd58, $82154aee,
$7b54a41d, $c25a59b5, $9c30d539, $2af26013, $7b54a41d, $c25a59b5, $9c30d539, $2af26013,
$c5d1b023, $286085f0, $ca417918, $b8db38ef, $c5d1b023, $286085f0, $ca417918, $b8db38ef,
$8e79dcb0, $603a180e, $6c9e0e8b, $b01e8a3e, $8e79dcb0, $603a180e, $6c9e0e8b, $b01e8a3e,
$d71577c1, $bd314b27, $78af2fda, $55605c60, $d71577c1, $bd314b27, $78af2fda, $55605c60,
$e65525f3, $aa55ab94, $57489862, $63e81440, $e65525f3, $aa55ab94, $57489862, $63e81440,
$55ca396a, $2aab10b6, $b4cc5c34, $1141e8ce, $55ca396a, $2aab10b6, $b4cc5c34, $1141e8ce,
$a15486af, $7c72e993, $b3ee1411, $636fbc2a, $a15486af, $7c72e993, $b3ee1411, $636fbc2a,
$2ba9c55d, $741831f6, $ce5c3e16, $9b87931e, $2ba9c55d, $741831f6, $ce5c3e16, $9b87931e,
$afd6ba33, $6c24cf5c, $7a325381, $28958677, $afd6ba33, $6c24cf5c, $7a325381, $28958677,
$3b8f4898, $6b4bb9af, $c4bfe81b, $66282193, $3b8f4898, $6b4bb9af, $c4bfe81b, $66282193,
$61d809cc, $fb21a991, $487cac60, $5dec8032, $61d809cc, $fb21a991, $487cac60, $5dec8032,
$ef845d5d, $e98575b1, $dc262302, $eb651b88, $ef845d5d, $e98575b1, $dc262302, $eb651b88,
$23893e81, $d396acc5, $0f6d6ff3, $83f44239, $23893e81, $d396acc5, $0f6d6ff3, $83f44239,
$2e0b4482, $a4842004, $69c8f04a, $9e1f9b5e, $2e0b4482, $a4842004, $69c8f04a, $9e1f9b5e,
$21c66842, $f6e96c9a, $670c9c61, $abd388f0, $21c66842, $f6e96c9a, $670c9c61, $abd388f0,
$6a51a0d2, $d8542f68, $960fa728, $ab5133a3, $6a51a0d2, $d8542f68, $960fa728, $ab5133a3,
$6eef0b6c, $137a3be4, $ba3bf050, $7efb2a98, $6eef0b6c, $137a3be4, $ba3bf050, $7efb2a98,
$a1f1651d, $39af0176, $66ca593e, $82430e88, $a1f1651d, $39af0176, $66ca593e, $82430e88,
$8cee8619, $456f9fb4, $7d84a5c3, $3b8b5ebe, $8cee8619, $456f9fb4, $7d84a5c3, $3b8b5ebe,
$e06f75d8, $85c12073, $401a449f, $56c16aa6, $e06f75d8, $85c12073, $401a449f, $56c16aa6,
$4ed3aa62, $363f7706, $1bfedf72, $429b023d, $4ed3aa62, $363f7706, $1bfedf72, $429b023d,
$37d0d724, $d00a1248, $db0fead3, $49f1c09b, $37d0d724, $d00a1248, $db0fead3, $49f1c09b,
$075372c9, $80991b7b, $25d479d8, $f6e8def7, $075372c9, $80991b7b, $25d479d8, $f6e8def7,
$e3fe501a, $b6794c3b, $976ce0bd, $04c006ba, $e3fe501a, $b6794c3b, $976ce0bd, $04c006ba,
$c1a94fb6, $409f60c4, $5e5c9ec2, $196a2463, $c1a94fb6, $409f60c4, $5e5c9ec2, $196a2463,
$68fb6faf, $3e6c53b5, $1339b2eb, $3b52ec6f, $68fb6faf, $3e6c53b5, $1339b2eb, $3b52ec6f,
$6dfc511f, $9b30952c, $cc814544, $af5ebd09, $6dfc511f, $9b30952c, $cc814544, $af5ebd09,
$bee3d004, $de334afd, $660f2807, $192e4bb3, $bee3d004, $de334afd, $660f2807, $192e4bb3,
$c0cba857, $45c8740f, $d20b5f39, $b9d3fbdb, $c0cba857, $45c8740f, $d20b5f39, $b9d3fbdb,
$5579c0bd, $1a60320a, $d6a100c6, $402c7279, $5579c0bd, $1a60320a, $d6a100c6, $402c7279,
$679f25fe, $fb1fa3cc, $8ea5e9f8, $db3222f8, $679f25fe, $fb1fa3cc, $8ea5e9f8, $db3222f8,
$3c7516df, $fd616b15, $2f501ec8, $ad0552ab, $3c7516df, $fd616b15, $2f501ec8, $ad0552ab,
$323db5fa, $fd238760, $53317b48, $3e00df82, $323db5fa, $fd238760, $53317b48, $3e00df82,
$9e5c57bb, $ca6f8ca0, $1a87562e, $df1769db, $9e5c57bb, $ca6f8ca0, $1a87562e, $df1769db,
$d542a8f6, $287effc3, $ac6732c6, $8c4f5573, $d542a8f6, $287effc3, $ac6732c6, $8c4f5573,
$695b27b0, $bbca58c8, $e1ffa35d, $b8f011a0, $695b27b0, $bbca58c8, $e1ffa35d, $b8f011a0,
$10fa3d98, $fd2183b8, $4afcb56c, $2dd1d35b, $10fa3d98, $fd2183b8, $4afcb56c, $2dd1d35b,
$9a53e479, $b6f84565, $d28e49bc, $4bfb9790, $9a53e479, $b6f84565, $d28e49bc, $4bfb9790,
$e1ddf2da, $a4cb7e33, $62fb1341, $cee4c6e8, $e1ddf2da, $a4cb7e33, $62fb1341, $cee4c6e8,
$ef20cada, $36774c01, $d07e9efe, $2bf11fb4, $ef20cada, $36774c01, $d07e9efe, $2bf11fb4,
$95dbda4d, $ae909198, $eaad8e71, $6b93d5a0, $95dbda4d, $ae909198, $eaad8e71, $6b93d5a0,
$d08ed1d0, $afc725e0, $8e3c5b2f, $8e7594b7, $d08ed1d0, $afc725e0, $8e3c5b2f, $8e7594b7,
$8ff6e2fb, $f2122b64, $8888b812, $900df01c, $8ff6e2fb, $f2122b64, $8888b812, $900df01c,
$4fad5ea0, $688fc31c, $d1cff191, $b3a8c1ad, $4fad5ea0, $688fc31c, $d1cff191, $b3a8c1ad,
$2f2f2218, $be0e1777, $ea752dfe, $8b021fa1, $2f2f2218, $be0e1777, $ea752dfe, $8b021fa1,
$e5a0cc0f, $b56f74e8, $18acf3d6, $ce89e299, $e5a0cc0f, $b56f74e8, $18acf3d6, $ce89e299,
$b4a84fe0, $fd13e0b7, $7cc43b81, $d2ada8d9, $b4a84fe0, $fd13e0b7, $7cc43b81, $d2ada8d9,
$165fa266, $80957705, $93cc7314, $211a1477, $165fa266, $80957705, $93cc7314, $211a1477,
$e6ad2065, $77b5fa86, $c75442f5, $fb9d35cf, $e6ad2065, $77b5fa86, $c75442f5, $fb9d35cf,
$ebcdaf0c, $7b3e89a0, $d6411bd3, $ae1e7e49, $ebcdaf0c, $7b3e89a0, $d6411bd3, $ae1e7e49,
$00250e2d, $2071b35e, $226800bb, $57b8e0af, $00250e2d, $2071b35e, $226800bb, $57b8e0af,
$2464369b, $f009b91e, $5563911d, $59dfa6aa, $2464369b, $f009b91e, $5563911d, $59dfa6aa,
$78c14389, $d95a537f, $207d5ba2, $02e5b9c5, $78c14389, $d95a537f, $207d5ba2, $02e5b9c5,
$83260376, $6295cfa9, $11c81968, $4e734a41, $83260376, $6295cfa9, $11c81968, $4e734a41,
$b3472dca, $7b14a94a, $1b510052, $9a532915, $b3472dca, $7b14a94a, $1b510052, $9a532915,
$d60f573f, $bc9bc6e4, $2b60a476, $81e67400, $d60f573f, $bc9bc6e4, $2b60a476, $81e67400,
$08ba6fb5, $571be91f, $f296ec6b, $2a0dd915, $08ba6fb5, $571be91f, $f296ec6b, $2a0dd915,
$b6636521, $e7b9f9b6, $ff34052e, $c5855664, $b6636521, $e7b9f9b6, $ff34052e, $c5855664,
$53b02d5d, $a99f8fa1, $08ba4799, $6e85076a),( $53b02d5d, $a99f8fa1, $08ba4799, $6e85076a),(
$4b7a70e9, $b5b32944, $db75092e, $c4192623, $4b7a70e9, $b5b32944, $db75092e, $c4192623,
$ad6ea6b0, $49a7df7d, $9cee60b8, $8fedb266, $ad6ea6b0, $49a7df7d, $9cee60b8, $8fedb266,
$ecaa8c71, $699a17ff, $5664526c, $c2b19ee1, $ecaa8c71, $699a17ff, $5664526c, $c2b19ee1,
$193602a5, $75094c29, $a0591340, $e4183a3e, $193602a5, $75094c29, $a0591340, $e4183a3e,
$3f54989a, $5b429d65, $6b8fe4d6, $99f73fd6, $3f54989a, $5b429d65, $6b8fe4d6, $99f73fd6,
$a1d29c07, $efe830f5, $4d2d38e6, $f0255dc1, $a1d29c07, $efe830f5, $4d2d38e6, $f0255dc1,
$4cdd2086, $8470eb26, $6382e9c6, $021ecc5e, $4cdd2086, $8470eb26, $6382e9c6, $021ecc5e,
$09686b3f, $3ebaefc9, $3c971814, $6b6a70a1, $09686b3f, $3ebaefc9, $3c971814, $6b6a70a1,
$687f3584, $52a0e286, $b79c5305, $aa500737, $687f3584, $52a0e286, $b79c5305, $aa500737,
$3e07841c, $7fdeae5c, $8e7d44ec, $5716f2b8, $3e07841c, $7fdeae5c, $8e7d44ec, $5716f2b8,
$b03ada37, $f0500c0d, $f01c1f04, $0200b3ff, $b03ada37, $f0500c0d, $f01c1f04, $0200b3ff,
$ae0cf51a, $3cb574b2, $25837a58, $dc0921bd, $ae0cf51a, $3cb574b2, $25837a58, $dc0921bd,
$d19113f9, $7ca92ff6, $94324773, $22f54701, $d19113f9, $7ca92ff6, $94324773, $22f54701,
$3ae5e581, $37c2dadc, $c8b57634, $9af3dda7, $3ae5e581, $37c2dadc, $c8b57634, $9af3dda7,
$a9446146, $0fd0030e, $ecc8c73e, $a4751e41, $a9446146, $0fd0030e, $ecc8c73e, $a4751e41,
$e238cd99, $3bea0e2f, $3280bba1, $183eb331, $e238cd99, $3bea0e2f, $3280bba1, $183eb331,
$4e548b38, $4f6db908, $6f420d03, $f60a04bf, $4e548b38, $4f6db908, $6f420d03, $f60a04bf,
$2cb81290, $24977c79, $5679b072, $bcaf89af, $2cb81290, $24977c79, $5679b072, $bcaf89af,
$de9a771f, $d9930810, $b38bae12, $dccf3f2e, $de9a771f, $d9930810, $b38bae12, $dccf3f2e,
$5512721f, $2e6b7124, $501adde6, $9f84cd87, $5512721f, $2e6b7124, $501adde6, $9f84cd87,
$7a584718, $7408da17, $bc9f9abc, $e94b7d8c, $7a584718, $7408da17, $bc9f9abc, $e94b7d8c,
$ec7aec3a, $db851dfa, $63094366, $c464c3d2, $ec7aec3a, $db851dfa, $63094366, $c464c3d2,
$ef1c1847, $3215d908, $dd433b37, $24c2ba16, $ef1c1847, $3215d908, $dd433b37, $24c2ba16,
$12a14d43, $2a65c451, $50940002, $133ae4dd, $12a14d43, $2a65c451, $50940002, $133ae4dd,
$71dff89e, $10314e55, $81ac77d6, $5f11199b, $71dff89e, $10314e55, $81ac77d6, $5f11199b,
$043556f1, $d7a3c76b, $3c11183b, $5924a509, $043556f1, $d7a3c76b, $3c11183b, $5924a509,
$f28fe6ed, $97f1fbfa, $9ebabf2c, $1e153c6e, $f28fe6ed, $97f1fbfa, $9ebabf2c, $1e153c6e,
$86e34570, $eae96fb1, $860e5e0a, $5a3e2ab3, $86e34570, $eae96fb1, $860e5e0a, $5a3e2ab3,
$771fe71c, $4e3d06fa, $2965dcb9, $99e71d0f, $771fe71c, $4e3d06fa, $2965dcb9, $99e71d0f,
$803e89d6, $5266c825, $2e4cc978, $9c10b36a, $803e89d6, $5266c825, $2e4cc978, $9c10b36a,
$c6150eba, $94e2ea78, $a5fc3c53, $1e0a2df4, $c6150eba, $94e2ea78, $a5fc3c53, $1e0a2df4,
$f2f74ea7, $361d2b3d, $1939260f, $19c27960, $f2f74ea7, $361d2b3d, $1939260f, $19c27960,
$5223a708, $f71312b6, $ebadfe6e, $eac31f66, $5223a708, $f71312b6, $ebadfe6e, $eac31f66,
$e3bc4595, $a67bc883, $b17f37d1, $018cff28, $e3bc4595, $a67bc883, $b17f37d1, $018cff28,
$c332ddef, $be6c5aa5, $65582185, $68ab9802, $c332ddef, $be6c5aa5, $65582185, $68ab9802,
$eecea50f, $db2f953b, $2aef7dad, $5b6e2f84, $eecea50f, $db2f953b, $2aef7dad, $5b6e2f84,
$1521b628, $29076170, $ecdd4775, $619f1510, $1521b628, $29076170, $ecdd4775, $619f1510,
$13cca830, $eb61bd96, $0334fe1e, $aa0363cf, $13cca830, $eb61bd96, $0334fe1e, $aa0363cf,
$b5735c90, $4c70a239, $d59e9e0b, $cbaade14, $b5735c90, $4c70a239, $d59e9e0b, $cbaade14,
$eecc86bc, $60622ca7, $9cab5cab, $b2f3846e, $eecc86bc, $60622ca7, $9cab5cab, $b2f3846e,
$648b1eaf, $19bdf0ca, $a02369b9, $655abb50, $648b1eaf, $19bdf0ca, $a02369b9, $655abb50,
$40685a32, $3c2ab4b3, $319ee9d5, $c021b8f7, $40685a32, $3c2ab4b3, $319ee9d5, $c021b8f7,
$9b540b19, $875fa099, $95f7997e, $623d7da8, $9b540b19, $875fa099, $95f7997e, $623d7da8,
$f837889a, $97e32d77, $11ed935f, $16681281, $f837889a, $97e32d77, $11ed935f, $16681281,
$0e358829, $c7e61fd6, $96dedfa1, $7858ba99, $0e358829, $c7e61fd6, $96dedfa1, $7858ba99,
$57f584a5, $1b227263, $9b83c3ff, $1ac24696, $57f584a5, $1b227263, $9b83c3ff, $1ac24696,
$cdb30aeb, $532e3054, $8fd948e4, $6dbc3128, $cdb30aeb, $532e3054, $8fd948e4, $6dbc3128,
$58ebf2ef, $34c6ffea, $fe28ed61, $ee7c3c73, $58ebf2ef, $34c6ffea, $fe28ed61, $ee7c3c73,
$5d4a14d9, $e864b7e3, $42105d14, $203e13e0, $5d4a14d9, $e864b7e3, $42105d14, $203e13e0,
$45eee2b6, $a3aaabea, $db6c4f15, $facb4fd0, $45eee2b6, $a3aaabea, $db6c4f15, $facb4fd0,
$c742f442, $ef6abbb5, $654f3b1d, $41cd2105, $c742f442, $ef6abbb5, $654f3b1d, $41cd2105,
$d81e799e, $86854dc7, $e44b476a, $3d816250, $d81e799e, $86854dc7, $e44b476a, $3d816250,
$cf62a1f2, $5b8d2646, $fc8883a0, $c1c7b6a3, $cf62a1f2, $5b8d2646, $fc8883a0, $c1c7b6a3,
$7f1524c3, $69cb7492, $47848a0b, $5692b285, $7f1524c3, $69cb7492, $47848a0b, $5692b285,
$095bbf00, $ad19489d, $1462b174, $23820e00, $095bbf00, $ad19489d, $1462b174, $23820e00,
$58428d2a, $0c55f5ea, $1dadf43e, $233f7061, $58428d2a, $0c55f5ea, $1dadf43e, $233f7061,
$3372f092, $8d937e41, $d65fecf1, $6c223bdb, $3372f092, $8d937e41, $d65fecf1, $6c223bdb,
$7cde3759, $cbee7460, $4085f2a7, $ce77326e, $7cde3759, $cbee7460, $4085f2a7, $ce77326e,
$a6078084, $19f8509e, $e8efd855, $61d99735, $a6078084, $19f8509e, $e8efd855, $61d99735,
$a969a7aa, $c50c06c2, $5a04abfc, $800bcadc, $a969a7aa, $c50c06c2, $5a04abfc, $800bcadc,
$9e447a2e, $c3453484, $fdd56705, $0e1e9ec9, $9e447a2e, $c3453484, $fdd56705, $0e1e9ec9,
$db73dbd3, $105588cd, $675fda79, $e3674340, $db73dbd3, $105588cd, $675fda79, $e3674340,
$c5c43465, $713e38d8, $3d28f89e, $f16dff20, $c5c43465, $713e38d8, $3d28f89e, $f16dff20,
$153e21e7, $8fb03d4a, $e6e39f2b, $db83adf7),( $153e21e7, $8fb03d4a, $e6e39f2b, $db83adf7),(
$e93d5a68, $948140f7, $f64c261c, $94692934, $e93d5a68, $948140f7, $f64c261c, $94692934,
$411520f7, $7602d4f7, $bcf46b2e, $d4a20068, $411520f7, $7602d4f7, $bcf46b2e, $d4a20068,
$d4082471, $3320f46a, $43b7d4b7, $500061af, $d4082471, $3320f46a, $43b7d4b7, $500061af,
$1e39f62e, $97244546, $14214f74, $bf8b8840, $1e39f62e, $97244546, $14214f74, $bf8b8840,
$4d95fc1d, $96b591af, $70f4ddd3, $66a02f45, $4d95fc1d, $96b591af, $70f4ddd3, $66a02f45,
$bfbc09ec, $03bd9785, $7fac6dd0, $31cb8504, $bfbc09ec, $03bd9785, $7fac6dd0, $31cb8504,
$96eb27b3, $55fd3941, $da2547e6, $abca0a9a, $96eb27b3, $55fd3941, $da2547e6, $abca0a9a,
$28507825, $530429f4, $0a2c86da, $e9b66dfb, $28507825, $530429f4, $0a2c86da, $e9b66dfb,
$68dc1462, $d7486900, $680ec0a4, $27a18dee, $68dc1462, $d7486900, $680ec0a4, $27a18dee,
$4f3ffea2, $e887ad8c, $b58ce006, $7af4d6b6, $4f3ffea2, $e887ad8c, $b58ce006, $7af4d6b6,
$aace1e7c, $d3375fec, $ce78a399, $406b2a42, $aace1e7c, $d3375fec, $ce78a399, $406b2a42,
$20fe9e35, $d9f385b9, $ee39d7ab, $3b124e8b, $20fe9e35, $d9f385b9, $ee39d7ab, $3b124e8b,
$1dc9faf7, $4b6d1856, $26a36631, $eae397b2, $1dc9faf7, $4b6d1856, $26a36631, $eae397b2,
$3a6efa74, $dd5b4332, $6841e7f7, $ca7820fb, $3a6efa74, $dd5b4332, $6841e7f7, $ca7820fb,
$fb0af54e, $d8feb397, $454056ac, $ba489527, $fb0af54e, $d8feb397, $454056ac, $ba489527,
$55533a3a, $20838d87, $fe6ba9b7, $d096954b, $55533a3a, $20838d87, $fe6ba9b7, $d096954b,
$55a867bc, $a1159a58, $cca92963, $99e1db33, $55a867bc, $a1159a58, $cca92963, $99e1db33,
$a62a4a56, $3f3125f9, $5ef47e1c, $9029317c, $a62a4a56, $3f3125f9, $5ef47e1c, $9029317c,
$fdf8e802, $04272f70, $80bb155c, $05282ce3, $fdf8e802, $04272f70, $80bb155c, $05282ce3,
$95c11548, $e4c66d22, $48c1133f, $c70f86dc, $95c11548, $e4c66d22, $48c1133f, $c70f86dc,
$07f9c9ee, $41041f0f, $404779a4, $5d886e17, $07f9c9ee, $41041f0f, $404779a4, $5d886e17,
$325f51eb, $d59bc0d1, $f2bcc18f, $41113564, $325f51eb, $d59bc0d1, $f2bcc18f, $41113564,
$257b7834, $602a9c60, $dff8e8a3, $1f636c1b, $257b7834, $602a9c60, $dff8e8a3, $1f636c1b,
$0e12b4c2, $02e1329e, $af664fd1, $cad18115, $0e12b4c2, $02e1329e, $af664fd1, $cad18115,
$6b2395e0, $333e92e1, $3b240b62, $eebeb922, $6b2395e0, $333e92e1, $3b240b62, $eebeb922,
$85b2a20e, $e6ba0d99, $de720c8c, $2da2f728, $85b2a20e, $e6ba0d99, $de720c8c, $2da2f728,
$d0127845, $95b794fd, $647d0862, $e7ccf5f0, $d0127845, $95b794fd, $647d0862, $e7ccf5f0,
$5449a36f, $877d48fa, $c39dfd27, $f33e8d1e, $5449a36f, $877d48fa, $c39dfd27, $f33e8d1e,
$0a476341, $992eff74, $3a6f6eab, $f4f8fd37, $0a476341, $992eff74, $3a6f6eab, $f4f8fd37,
$a812dc60, $a1ebddf8, $991be14c, $db6e6b0d, $a812dc60, $a1ebddf8, $991be14c, $db6e6b0d,
$c67b5510, $6d672c37, $2765d43b, $dcd0e804, $c67b5510, $6d672c37, $2765d43b, $dcd0e804,
$f1290dc7, $cc00ffa3, $b5390f92, $690fed0b, $f1290dc7, $cc00ffa3, $b5390f92, $690fed0b,
$667b9ffb, $cedb7d9c, $a091cf0b, $d9155ea3, $667b9ffb, $cedb7d9c, $a091cf0b, $d9155ea3,
$bb132f88, $515bad24, $7b9479bf, $763bd6eb, $bb132f88, $515bad24, $7b9479bf, $763bd6eb,
$37392eb3, $cc115979, $8026e297, $f42e312d, $37392eb3, $cc115979, $8026e297, $f42e312d,
$6842ada7, $c66a2b3b, $12754ccc, $782ef11c, $6842ada7, $c66a2b3b, $12754ccc, $782ef11c,
$6a124237, $b79251e7, $06a1bbe6, $4bfb6350, $6a124237, $b79251e7, $06a1bbe6, $4bfb6350,
$1a6b1018, $11caedfa, $3d25bdd8, $e2e1c3c9, $1a6b1018, $11caedfa, $3d25bdd8, $e2e1c3c9,
$44421659, $0a121386, $d90cec6e, $d5abea2a, $44421659, $0a121386, $d90cec6e, $d5abea2a,
$64af674e, $da86a85f, $bebfe988, $64e4c3fe, $64af674e, $da86a85f, $bebfe988, $64e4c3fe,
$9dbc8057, $f0f7c086, $60787bf8, $6003604d, $9dbc8057, $f0f7c086, $60787bf8, $6003604d,
$d1fd8346, $f6381fb0, $7745ae04, $d736fccc, $d1fd8346, $f6381fb0, $7745ae04, $d736fccc,
$83426b33, $f01eab71, $b0804187, $3c005e5f, $83426b33, $f01eab71, $b0804187, $3c005e5f,
$77a057be, $bde8ae24, $55464299, $bf582e61, $77a057be, $bde8ae24, $55464299, $bf582e61,
$4e58f48f, $f2ddfda2, $f474ef38, $8789bdc2, $4e58f48f, $f2ddfda2, $f474ef38, $8789bdc2,
$5366f9c3, $c8b38e74, $b475f255, $46fcd9b9, $5366f9c3, $c8b38e74, $b475f255, $46fcd9b9,
$7aeb2661, $8b1ddf84, $846a0e79, $915f95e2, $7aeb2661, $8b1ddf84, $846a0e79, $915f95e2,
$466e598e, $20b45770, $8cd55591, $c902de4c, $466e598e, $20b45770, $8cd55591, $c902de4c,
$b90bace1, $bb8205d0, $11a86248, $7574a99e, $b90bace1, $bb8205d0, $11a86248, $7574a99e,
$b77f19b6, $e0a9dc09, $662d09a1, $c4324633, $b77f19b6, $e0a9dc09, $662d09a1, $c4324633,
$e85a1f02, $09f0be8c, $4a99a025, $1d6efe10, $e85a1f02, $09f0be8c, $4a99a025, $1d6efe10,
$1ab93d1d, $0ba5a4df, $a186f20f, $2868f169, $1ab93d1d, $0ba5a4df, $a186f20f, $2868f169,
$dcb7da83, $573906fe, $a1e2ce9b, $4fcd7f52, $dcb7da83, $573906fe, $a1e2ce9b, $4fcd7f52,
$50115e01, $a70683fa, $a002b5c4, $0de6d027, $50115e01, $a70683fa, $a002b5c4, $0de6d027,
$9af88c27, $773f8641, $c3604c06, $61a806b5, $9af88c27, $773f8641, $c3604c06, $61a806b5,
$f0177a28, $c0f586e0, $006058aa, $30dc7d62, $f0177a28, $c0f586e0, $006058aa, $30dc7d62,
$11e69ed7, $2338ea63, $53c2dd94, $c2c21634, $11e69ed7, $2338ea63, $53c2dd94, $c2c21634,
$bbcbee56, $90bcb6de, $ebfc7da1, $ce591d76, $bbcbee56, $90bcb6de, $ebfc7da1, $ce591d76,
$6f05e409, $4b7c0188, $39720a3d, $7c927c24, $6f05e409, $4b7c0188, $39720a3d, $7c927c24,
$86e3725f, $724d9db9, $1ac15bb4, $d39eb8fc, $86e3725f, $724d9db9, $1ac15bb4, $d39eb8fc,
$ed545578, $08fca5b5, $d83d7cd3, $4dad0fc4, $ed545578, $08fca5b5, $d83d7cd3, $4dad0fc4,
$1e50ef5e, $b161e6f8, $a28514d9, $6c51133c, $1e50ef5e, $b161e6f8, $a28514d9, $6c51133c,
$6fd5c7e7, $56e14ec4, $362abfce, $ddc6c837, $6fd5c7e7, $56e14ec4, $362abfce, $ddc6c837,
$d79a3234, $92638212, $670efa8e, $406000e0),( $d79a3234, $92638212, $670efa8e, $406000e0),(
$3a39ce37, $d3faf5cf, $abc27737, $5ac52d1b, $3a39ce37, $d3faf5cf, $abc27737, $5ac52d1b,
$5cb0679e, $4fa33742, $d3822740, $99bc9bbe, $5cb0679e, $4fa33742, $d3822740, $99bc9bbe,
$d5118e9d, $bf0f7315, $d62d1c7e, $c700c47b, $d5118e9d, $bf0f7315, $d62d1c7e, $c700c47b,
$b78c1b6b, $21a19045, $b26eb1be, $6a366eb4, $b78c1b6b, $21a19045, $b26eb1be, $6a366eb4,
$5748ab2f, $bc946e79, $c6a376d2, $6549c2c8, $5748ab2f, $bc946e79, $c6a376d2, $6549c2c8,
$530ff8ee, $468dde7d, $d5730a1d, $4cd04dc6, $530ff8ee, $468dde7d, $d5730a1d, $4cd04dc6,
$2939bbdb, $a9ba4650, $ac9526e8, $be5ee304, $2939bbdb, $a9ba4650, $ac9526e8, $be5ee304,
$a1fad5f0, $6a2d519a, $63ef8ce2, $9a86ee22, $a1fad5f0, $6a2d519a, $63ef8ce2, $9a86ee22,
$c089c2b8, $43242ef6, $a51e03aa, $9cf2d0a4, $c089c2b8, $43242ef6, $a51e03aa, $9cf2d0a4,
$83c061ba, $9be96a4d, $8fe51550, $ba645bd6, $83c061ba, $9be96a4d, $8fe51550, $ba645bd6,
$2826a2f9, $a73a3ae1, $4ba99586, $ef5562e9, $2826a2f9, $a73a3ae1, $4ba99586, $ef5562e9,
$c72fefd3, $f752f7da, $3f046f69, $77fa0a59, $c72fefd3, $f752f7da, $3f046f69, $77fa0a59,
$80e4a915, $87b08601, $9b09e6ad, $3b3ee593, $80e4a915, $87b08601, $9b09e6ad, $3b3ee593,
$e990fd5a, $9e34d797, $2cf0b7d9, $022b8b51, $e990fd5a, $9e34d797, $2cf0b7d9, $022b8b51,
$96d5ac3a, $017da67d, $d1cf3ed6, $7c7d2d28, $96d5ac3a, $017da67d, $d1cf3ed6, $7c7d2d28,
$1f9f25cf, $adf2b89b, $5ad6b472, $5a88f54c, $1f9f25cf, $adf2b89b, $5ad6b472, $5a88f54c,
$e029ac71, $e019a5e6, $47b0acfd, $ed93fa9b, $e029ac71, $e019a5e6, $47b0acfd, $ed93fa9b,
$e8d3c48d, $283b57cc, $f8d56629, $79132e28, $e8d3c48d, $283b57cc, $f8d56629, $79132e28,
$785f0191, $ed756055, $f7960e44, $e3d35e8c, $785f0191, $ed756055, $f7960e44, $e3d35e8c,
$15056dd4, $88f46dba, $03a16125, $0564f0bd, $15056dd4, $88f46dba, $03a16125, $0564f0bd,
$c3eb9e15, $3c9057a2, $97271aec, $a93a072a, $c3eb9e15, $3c9057a2, $97271aec, $a93a072a,
$1b3f6d9b, $1e6321f5, $f59c66fb, $26dcf319, $1b3f6d9b, $1e6321f5, $f59c66fb, $26dcf319,
$7533d928, $b155fdf5, $03563482, $8aba3cbb, $7533d928, $b155fdf5, $03563482, $8aba3cbb,
$28517711, $c20ad9f8, $abcc5167, $ccad925f, $28517711, $c20ad9f8, $abcc5167, $ccad925f,
$4de81751, $3830dc8e, $379d5862, $9320f991, $4de81751, $3830dc8e, $379d5862, $9320f991,
$ea7a90c2, $fb3e7bce, $5121ce64, $774fbe32, $ea7a90c2, $fb3e7bce, $5121ce64, $774fbe32,
$a8b6e37e, $c3293d46, $48de5369, $6413e680, $a8b6e37e, $c3293d46, $48de5369, $6413e680,
$a2ae0810, $dd6db224, $69852dfd, $09072166, $a2ae0810, $dd6db224, $69852dfd, $09072166,
$b39a460a, $6445c0dd, $586cdecf, $1c20c8ae, $b39a460a, $6445c0dd, $586cdecf, $1c20c8ae,
$5bbef7dd, $1b588d40, $ccd2017f, $6bb4e3bb, $5bbef7dd, $1b588d40, $ccd2017f, $6bb4e3bb,
$dda26a7e, $3a59ff45, $3e350a44, $bcb4cdd5, $dda26a7e, $3a59ff45, $3e350a44, $bcb4cdd5,
$72eacea8, $fa6484bb, $8d6612ae, $bf3c6f47, $72eacea8, $fa6484bb, $8d6612ae, $bf3c6f47,
$d29be463, $542f5d9e, $aec2771b, $f64e6370, $d29be463, $542f5d9e, $aec2771b, $f64e6370,
$740e0d8d, $e75b1357, $f8721671, $af537d5d, $740e0d8d, $e75b1357, $f8721671, $af537d5d,
$4040cb08, $4eb4e2cc, $34d2466a, $0115af84, $4040cb08, $4eb4e2cc, $34d2466a, $0115af84,
$e1b00428, $95983a1d, $06b89fb4, $ce6ea048, $e1b00428, $95983a1d, $06b89fb4, $ce6ea048,
$6f3f3b82, $3520ab82, $011a1d4b, $277227f8, $6f3f3b82, $3520ab82, $011a1d4b, $277227f8,
$611560b1, $e7933fdc, $bb3a792b, $344525bd, $611560b1, $e7933fdc, $bb3a792b, $344525bd,
$a08839e1, $51ce794b, $2f32c9b7, $a01fbac9, $a08839e1, $51ce794b, $2f32c9b7, $a01fbac9,
$e01cc87e, $bcc7d1f6, $cf0111c3, $a1e8aac7, $e01cc87e, $bcc7d1f6, $cf0111c3, $a1e8aac7,
$1a908749, $d44fbd9a, $d0dadecb, $d50ada38, $1a908749, $d44fbd9a, $d0dadecb, $d50ada38,
$0339c32a, $c6913667, $8df9317c, $e0b12b4f, $0339c32a, $c6913667, $8df9317c, $e0b12b4f,
$f79e59b7, $43f5bb3a, $f2d519ff, $27d9459c, $f79e59b7, $43f5bb3a, $f2d519ff, $27d9459c,
$bf97222c, $15e6fc2a, $0f91fc71, $9b941525, $bf97222c, $15e6fc2a, $0f91fc71, $9b941525,
$fae59361, $ceb69ceb, $c2a86459, $12baa8d1, $fae59361, $ceb69ceb, $c2a86459, $12baa8d1,
$b6c1075e, $e3056a0c, $10d25065, $cb03a442, $b6c1075e, $e3056a0c, $10d25065, $cb03a442,
$e0ec6e0e, $1698db3b, $4c98a0be, $3278e964, $e0ec6e0e, $1698db3b, $4c98a0be, $3278e964,
$9f1f9532, $e0d392df, $d3a0342b, $8971f21e, $9f1f9532, $e0d392df, $d3a0342b, $8971f21e,
$1b0a7441, $4ba3348c, $c5be7120, $c37632d8, $1b0a7441, $4ba3348c, $c5be7120, $c37632d8,
$df359f8d, $9b992f2e, $e60b6f47, $0fe3f11d, $df359f8d, $9b992f2e, $e60b6f47, $0fe3f11d,
$e54cda54, $1edad891, $ce6279cf, $cd3e7e6f, $e54cda54, $1edad891, $ce6279cf, $cd3e7e6f,
$1618b166, $fd2c1d05, $848fd2c5, $f6fb2299, $1618b166, $fd2c1d05, $848fd2c5, $f6fb2299,
$f523f357, $a6327623, $93a83531, $56cccd02, $f523f357, $a6327623, $93a83531, $56cccd02,
$acf08162, $5a75ebb5, $6e163697, $88d273cc, $acf08162, $5a75ebb5, $6e163697, $88d273cc,
$de966292, $81b949d0, $4c50901b, $71c65614, $de966292, $81b949d0, $4c50901b, $71c65614,
$e6c6c7bd, $327a140a, $45e1d006, $c3f27b9a, $e6c6c7bd, $327a140a, $45e1d006, $c3f27b9a,
$c9aa53fd, $62a80f00, $bb25bfe2, $35bdd2f6, $c9aa53fd, $62a80f00, $bb25bfe2, $35bdd2f6,
$71126905, $b2040222, $b6cbcf7c, $cd769c2b, $71126905, $b2040222, $b6cbcf7c, $cd769c2b,
$53113ec0, $1640e3d3, $38abbd60, $2547adf0, $53113ec0, $1640e3d3, $38abbd60, $2547adf0,
$ba38209c, $f746ce76, $77afa1c5, $20756060, $ba38209c, $f746ce76, $77afa1c5, $20756060,
$85cbfe4e, $8ae88dd8, $7aaaf9b0, $4cf9aa7e, $85cbfe4e, $8ae88dd8, $7aaaf9b0, $4cf9aa7e,
$1948c25c, $02fb8a8c, $01c36ae4, $d6ebe1f9, $1948c25c, $02fb8a8c, $01c36ae4, $d6ebe1f9,
$90d4f869, $a65cdea0, $3f09252d, $c208e69f, $90d4f869, $a65cdea0, $3f09252d, $c208e69f,
$b74e6132, $ce77e25b, $578fdfe3, $3ac372e6)); $b74e6132, $ce77e25b, $578fdfe3, $3ac372e6));

File diff suppressed because it is too large Load Diff

View File

@ -1,178 +1,178 @@
const const
S1: array[0..255] of DWord= ( S1: array[0..255] of DWord= (
$30fb40d4, $9fa0ff0b, $6beccd2f, $3f258c7a, $1e213f2f, $9C004dd3, $30fb40d4, $9fa0ff0b, $6beccd2f, $3f258c7a, $1e213f2f, $9C004dd3,
$6003e540, $cf9fc949, $bfd4af27, $88bbbdb5, $e2034090, $98d09675, $6003e540, $cf9fc949, $bfd4af27, $88bbbdb5, $e2034090, $98d09675,
$6e63a0e0, $15c361d2, $c2e7661d, $22d4ff8e, $28683b6f, $c07fd059, $6e63a0e0, $15c361d2, $c2e7661d, $22d4ff8e, $28683b6f, $c07fd059,
$ff2379c8, $775f50e2, $43c340d3, $df2f8656, $887ca41a, $a2d2bd2d, $ff2379c8, $775f50e2, $43c340d3, $df2f8656, $887ca41a, $a2d2bd2d,
$a1c9e0d6, $346c4819, $61b76d87, $22540f2f, $2abe32e1, $aa54166b, $a1c9e0d6, $346c4819, $61b76d87, $22540f2f, $2abe32e1, $aa54166b,
$22568e3a, $a2d341d0, $66db40c8, $a784392f, $004dff2f, $2db9d2de, $22568e3a, $a2d341d0, $66db40c8, $a784392f, $004dff2f, $2db9d2de,
$97943fac, $4a97c1d8, $527644b7, $b5f437a7, $b82cbaef, $d751d159, $97943fac, $4a97c1d8, $527644b7, $b5f437a7, $b82cbaef, $d751d159,
$6ff7f0ed, $5a097a1f, $827b68d0, $90ecf52e, $22b0c054, $bc8e5935, $6ff7f0ed, $5a097a1f, $827b68d0, $90ecf52e, $22b0c054, $bc8e5935,
$4b6d2f7f, $50bb64a2, $d2664910, $bee5812d, $b7332290, $e93b159f, $4b6d2f7f, $50bb64a2, $d2664910, $bee5812d, $b7332290, $e93b159f,
$b48ee411, $4bff345d, $fd45c240, $ad31973f, $c4f6d02e, $55fc8165, $b48ee411, $4bff345d, $fd45c240, $ad31973f, $c4f6d02e, $55fc8165,
$d5b1caad, $a1ac2dae, $a2d4b76d, $c19b0C50, $882240f2, $0c6e4f38, $d5b1caad, $a1ac2dae, $a2d4b76d, $c19b0C50, $882240f2, $0c6e4f38,
$a4e4bfd7, $4f5ba272, $564c1d2f, $c59c5319, $b949e354, $b04669fe, $a4e4bfd7, $4f5ba272, $564c1d2f, $c59c5319, $b949e354, $b04669fe,
$b1b6ab8a, $c71358dd, $6385c545, $110f935d, $57538ad5, $6a390493, $b1b6ab8a, $c71358dd, $6385c545, $110f935d, $57538ad5, $6a390493,
$e63d37e0, $2a54f6b3, $3a787d5f, $6276a0b5, $19a6fcdf, $7a42206a, $e63d37e0, $2a54f6b3, $3a787d5f, $6276a0b5, $19a6fcdf, $7a42206a,
$29f9d4d5, $f61b1891, $bb72275e, $aa508167, $38901091, $c6b505eb, $29f9d4d5, $f61b1891, $bb72275e, $aa508167, $38901091, $c6b505eb,
$84c7cb8c, $2ad75a0f, $874a1427, $a2d1936b, $2ad286af, $aa56d291, $84c7cb8c, $2ad75a0f, $874a1427, $a2d1936b, $2ad286af, $aa56d291,
$d7894360, $425c750d, $93b39e26, $187184c9, $6c00b32d, $73e2bb14, $d7894360, $425c750d, $93b39e26, $187184c9, $6c00b32d, $73e2bb14,
$a0bebc3c, $54623779, $64459eab, $3f328b82, $7718cf82, $59a2cea6, $a0bebc3c, $54623779, $64459eab, $3f328b82, $7718cf82, $59a2cea6,
$04ee002e, $89fe78e6, $3fab0950, $325ff6C2, $81383f05, $6963c5c8, $04ee002e, $89fe78e6, $3fab0950, $325ff6C2, $81383f05, $6963c5c8,
$76cb5ad6, $d49974c9, $ca180dcf, $380782d5, $c7fa5cf6, $8ac31511, $76cb5ad6, $d49974c9, $ca180dcf, $380782d5, $c7fa5cf6, $8ac31511,
$35e79e13, $47da91d0, $f40f9086, $a7e2419e, $31366241, $051ef495, $35e79e13, $47da91d0, $f40f9086, $a7e2419e, $31366241, $051ef495,
$aa573b04, $4a805d8d, $548300d0, $00322a3c, $bf64cddf, $ba57a68e, $aa573b04, $4a805d8d, $548300d0, $00322a3c, $bf64cddf, $ba57a68e,
$75c6372b, $50afd341, $a7c13275, $915a0bf5, $6b54bfab, $2b0b1426, $75c6372b, $50afd341, $a7c13275, $915a0bf5, $6b54bfab, $2b0b1426,
$ab4cc9d7, $449ccd82, $f7fbf265, $ab85c5f3, $1b55db94, $aad4e324, $ab4cc9d7, $449ccd82, $f7fbf265, $ab85c5f3, $1b55db94, $aad4e324,
$cfa4bd3f, $2deaa3e2, $9e204d02, $c8bd25ac, $eadf55b3, $d5bd9e98, $cfa4bd3f, $2deaa3e2, $9e204d02, $c8bd25ac, $eadf55b3, $d5bd9e98,
$e31231b2, $2ad5ad6c, $954329de, $adbe4528, $d8710f69, $aa51c90f, $e31231b2, $2ad5ad6c, $954329de, $adbe4528, $d8710f69, $aa51c90f,
$aa786bf6, $22513f1e, $aa51a79b, $2ad344cc, $7b5a41f0, $d37cfbad, $aa786bf6, $22513f1e, $aa51a79b, $2ad344cc, $7b5a41f0, $d37cfbad,
$1b069505, $41ece491, $b4c332e6, $032268d4, $c9600acc, $ce387e6d, $1b069505, $41ece491, $b4c332e6, $032268d4, $c9600acc, $ce387e6d,
$bf6bb16c, $6a70fb78, $0d03d9c9, $d4df39de, $e01063da, $4736f464, $bf6bb16c, $6a70fb78, $0d03d9c9, $d4df39de, $e01063da, $4736f464,
$5ad328d8, $b347cc96, $75bb0fc3, $98511bfb, $4ffbcc35, $b58bcf6a, $5ad328d8, $b347cc96, $75bb0fc3, $98511bfb, $4ffbcc35, $b58bcf6a,
$e11f0abc, $bfc5fe4a, $a70aec10, $ac39570a, $3f04442f, $6188b153, $e11f0abc, $bfc5fe4a, $a70aec10, $ac39570a, $3f04442f, $6188b153,
$e0397a2e, $5727cb79, $9ceb418f, $1cacd68d, $2ad37c96, $0175cb9d, $e0397a2e, $5727cb79, $9ceb418f, $1cacd68d, $2ad37c96, $0175cb9d,
$c69dff09, $c75b65f0, $d9db40d8, $ec0e7779, $4744ead4, $b11c3274, $c69dff09, $c75b65f0, $d9db40d8, $ec0e7779, $4744ead4, $b11c3274,
$dd24cb9e, $7e1c54bd, $f01144f9, $d2240eb1, $9675b3fd, $a3ac3755, $dd24cb9e, $7e1c54bd, $f01144f9, $d2240eb1, $9675b3fd, $a3ac3755,
$d47c27af, $51c85f4d, $56907596, $a5bb15e6, $580304f0, $ca042cf1, $d47c27af, $51c85f4d, $56907596, $a5bb15e6, $580304f0, $ca042cf1,
$011a37ea, $8dbfaadb, $35ba3e4a, $3526ffa0, $c37b4d09, $bc306ed9, $011a37ea, $8dbfaadb, $35ba3e4a, $3526ffa0, $c37b4d09, $bc306ed9,
$98a52666, $5648f725, $ff5e569d, $0ced63d0, $7c63b2cf, $700b45e1, $98a52666, $5648f725, $ff5e569d, $0ced63d0, $7c63b2cf, $700b45e1,
$d5ea50f1, $85a92872, $af1fbda7, $d4234870, $a7870bf3, $2d3b4d79, $d5ea50f1, $85a92872, $af1fbda7, $d4234870, $a7870bf3, $2d3b4d79,
$42e04198, $0cd0ede7, $26470db8, $f881814C, $474d6ad7, $7c0c5e5c, $42e04198, $0cd0ede7, $26470db8, $f881814C, $474d6ad7, $7c0c5e5c,
$d1231959, $381b7298, $f5d2f4db, $ab838653, $6e2f1e23, $83719c9e, $d1231959, $381b7298, $f5d2f4db, $ab838653, $6e2f1e23, $83719c9e,
$bd91e046, $9a56456e, $dc39200c, $20c8c571, $962bda1c, $e1e696ff, $bd91e046, $9a56456e, $dc39200c, $20c8c571, $962bda1c, $e1e696ff,
$b141ab08, $7cca89b9, $1a69e783, $02cc4843, $a2f7c579, $429ef47d, $b141ab08, $7cca89b9, $1a69e783, $02cc4843, $a2f7c579, $429ef47d,
$427b169c, $5ac9f049, $dd8f0f00, $5c8165bf); $427b169c, $5ac9f049, $dd8f0f00, $5c8165bf);
S2: array[0..255] of DWord= ( S2: array[0..255] of DWord= (
$1f201094, $ef0ba75b, $69e3cf7e, $393f4380, $fe61cf7a, $eec5207a, $1f201094, $ef0ba75b, $69e3cf7e, $393f4380, $fe61cf7a, $eec5207a,
$55889c94, $72fc0651, $ada7ef79, $4e1d7235, $d55a63ce, $de0436ba, $55889c94, $72fc0651, $ada7ef79, $4e1d7235, $d55a63ce, $de0436ba,
$99c430ef, $5f0c0794, $18dcdb7d, $a1d6eff3, $a0b52f7b, $59e83605, $99c430ef, $5f0c0794, $18dcdb7d, $a1d6eff3, $a0b52f7b, $59e83605,
$ee15b094, $e9ffd909, $dc440086, $ef944459, $ba83ccb3, $e0c3cdfb, $ee15b094, $e9ffd909, $dc440086, $ef944459, $ba83ccb3, $e0c3cdfb,
$d1da4181, $3b092ab1, $f997f1c1, $a5e6cf7b, $01420ddb, $e4e7ef5b, $d1da4181, $3b092ab1, $f997f1c1, $a5e6cf7b, $01420ddb, $e4e7ef5b,
$25a1ff41, $e180f806, $1fc41080, $179bee7a, $d37ac6a9, $fe5830a4, $25a1ff41, $e180f806, $1fc41080, $179bee7a, $d37ac6a9, $fe5830a4,
$98de8b7f, $77e83f4e, $79929269, $24fa9f7b, $e113c85b, $acc40083, $98de8b7f, $77e83f4e, $79929269, $24fa9f7b, $e113c85b, $acc40083,
$d7503525, $f7ea615f, $62143154, $0d554b63, $5d681121, $c866c359, $d7503525, $f7ea615f, $62143154, $0d554b63, $5d681121, $c866c359,
$3d63cf73, $cee234c0, $d4d87e87, $5c672b21, $071f6181, $39f7627f, $3d63cf73, $cee234c0, $d4d87e87, $5c672b21, $071f6181, $39f7627f,
$361e3084, $e4eb573b, $602f64a4, $d63acd9c, $1bbc4635, $9e81032d, $361e3084, $e4eb573b, $602f64a4, $d63acd9c, $1bbc4635, $9e81032d,
$2701f50c, $99847ab4, $a0e3df79, $ba6cf38c, $10843094, $2537a95e, $2701f50c, $99847ab4, $a0e3df79, $ba6cf38c, $10843094, $2537a95e,
$f46f6ffe, $a1ff3b1f, $208cfb6a, $8f458c74, $d9e0a227, $4ec73a34, $f46f6ffe, $a1ff3b1f, $208cfb6a, $8f458c74, $d9e0a227, $4ec73a34,
$fc884f69, $3e4de8df, $ef0e0088, $3559648d, $8a45388c, $1d804366, $fc884f69, $3e4de8df, $ef0e0088, $3559648d, $8a45388c, $1d804366,
$721d9bfd, $a58684bb, $e8256333, $844e8212, $128d8098, $fed33fb4, $721d9bfd, $a58684bb, $e8256333, $844e8212, $128d8098, $fed33fb4,
$ce280ae1, $27e19ba5, $d5a6c252, $e49754bd, $c5d655dd, $eb667064, $ce280ae1, $27e19ba5, $d5a6c252, $e49754bd, $c5d655dd, $eb667064,
$77840b4d, $a1b6a801, $84db26a9, $e0b56714, $21f043b7, $e5d05860, $77840b4d, $a1b6a801, $84db26a9, $e0b56714, $21f043b7, $e5d05860,
$54f03084, $066ff472, $a31aa153, $dadc4755, $b5625dbf, $68561be6, $54f03084, $066ff472, $a31aa153, $dadc4755, $b5625dbf, $68561be6,
$83ca6b94, $2d6ed23b, $eccf01db, $a6d3d0ba, $b6803d5c, $af77a709, $83ca6b94, $2d6ed23b, $eccf01db, $a6d3d0ba, $b6803d5c, $af77a709,
$33b4a34c, $397bc8d6, $5ee22b95, $5f0e5304, $81ed6f61, $20e74364, $33b4a34c, $397bc8d6, $5ee22b95, $5f0e5304, $81ed6f61, $20e74364,
$b45e1378, $de18639b, $881ca122, $b96726d1, $8049a7e8, $22b7da7b, $b45e1378, $de18639b, $881ca122, $b96726d1, $8049a7e8, $22b7da7b,
$5e552d25, $5272d237, $79d2951c, $c60d894c, $488cb402, $1ba4fe5b, $5e552d25, $5272d237, $79d2951c, $c60d894c, $488cb402, $1ba4fe5b,
$a4b09f6b, $1ca815cf, $a20c3005, $8871df63, $b9de2fcb, $0cc6c9e9, $a4b09f6b, $1ca815cf, $a20c3005, $8871df63, $b9de2fcb, $0cc6c9e9,
$0beeff53, $e3214517, $b4542835, $9f63293c, $ee41e729, $6e1d2d7c, $0beeff53, $e3214517, $b4542835, $9f63293c, $ee41e729, $6e1d2d7c,
$50045286, $1e6685f3, $f33401c6, $30a22c95, $31a70850, $60930f13, $50045286, $1e6685f3, $f33401c6, $30a22c95, $31a70850, $60930f13,
$73f98417, $a1269859, $ec645c44, $52c877a9, $cdff33a6, $a02b1741, $73f98417, $a1269859, $ec645c44, $52c877a9, $cdff33a6, $a02b1741,
$7cbad9a2, $2180036f, $50d99c08, $cb3f4861, $c26bd765, $64a3f6ab, $7cbad9a2, $2180036f, $50d99c08, $cb3f4861, $c26bd765, $64a3f6ab,
$80342676, $25a75e7b, $e4e6d1fc, $20c710e6, $cdf0b680, $17844d3b, $80342676, $25a75e7b, $e4e6d1fc, $20c710e6, $cdf0b680, $17844d3b,
$31eef84d, $7e0824e4, $2ccb49eb, $846a3bae, $8ff77888, $ee5d60f6, $31eef84d, $7e0824e4, $2ccb49eb, $846a3bae, $8ff77888, $ee5d60f6,
$7af75673, $2fdd5cdb, $a11631c1, $30f66f43, $b3faec54, $157fd7fa, $7af75673, $2fdd5cdb, $a11631c1, $30f66f43, $b3faec54, $157fd7fa,
$ef8579cc, $d152de58, $db2ffd5e, $8f32ce19, $306af97a, $02f03ef8, $ef8579cc, $d152de58, $db2ffd5e, $8f32ce19, $306af97a, $02f03ef8,
$99319ad5, $c242fa0f, $a7e3ebb0, $c68e4906, $b8da230c, $80823028, $99319ad5, $c242fa0f, $a7e3ebb0, $c68e4906, $b8da230c, $80823028,
$dcdef3c8, $d35fb171, $088a1bc8, $bec0c560, $61a3c9e8, $bca8f54d, $dcdef3c8, $d35fb171, $088a1bc8, $bec0c560, $61a3c9e8, $bca8f54d,
$c72feffa, $22822e99, $82c570b4, $d8d94e89, $8b1c34bc, $301e16e6, $c72feffa, $22822e99, $82c570b4, $d8d94e89, $8b1c34bc, $301e16e6,
$273be979, $b0ffeaa6, $61d9b8c6, $00b24869, $b7ffce3f, $08dc283b, $273be979, $b0ffeaa6, $61d9b8c6, $00b24869, $b7ffce3f, $08dc283b,
$43daf65a, $f7e19798, $7619b72f, $8f1c9ba4, $dc8637a0, $16a7d3b1, $43daf65a, $f7e19798, $7619b72f, $8f1c9ba4, $dc8637a0, $16a7d3b1,
$9fc393b7, $a7136eeb, $c6bcc63e, $1a513742, $ef6828bc, $520365d6, $9fc393b7, $a7136eeb, $c6bcc63e, $1a513742, $ef6828bc, $520365d6,
$2d6a77ab, $3527ed4b, $821fd216, $095c6e2e, $db92f2fb, $5eea29cb, $2d6a77ab, $3527ed4b, $821fd216, $095c6e2e, $db92f2fb, $5eea29cb,
$145892f5, $91584f7f, $5483697b, $2667a8cc, $85196048, $8c4bacea, $145892f5, $91584f7f, $5483697b, $2667a8cc, $85196048, $8c4bacea,
$833860d4, $0d23e0f9, $6c387e8a, $0ae6d249, $b284600c, $d835731d, $833860d4, $0d23e0f9, $6c387e8a, $0ae6d249, $b284600c, $d835731d,
$dcb1c647, $ac4c56ea, $3ebd81b3, $230eabb0, $6438bc87, $f0b5b1fa, $dcb1c647, $ac4c56ea, $3ebd81b3, $230eabb0, $6438bc87, $f0b5b1fa,
$8f5ea2b3, $fc184642, $0a036b7a, $4fb089bd, $649da589, $a345415e, $8f5ea2b3, $fc184642, $0a036b7a, $4fb089bd, $649da589, $a345415e,
$5c038323, $3e5d3bb9, $43d79572, $7e6dd07c, $06dfdf1e, $6c6cc4ef, $5c038323, $3e5d3bb9, $43d79572, $7e6dd07c, $06dfdf1e, $6c6cc4ef,
$7160a539, $73bfbe70, $83877605, $4523ecf1); $7160a539, $73bfbe70, $83877605, $4523ecf1);
S3: array[0..255] of DWord= ( S3: array[0..255] of DWord= (
$8defc240, $25fa5d9f, $eb903dbf, $e810c907, $47607fff, $369fe44b, $8defc240, $25fa5d9f, $eb903dbf, $e810c907, $47607fff, $369fe44b,
$8c1fc644, $aececa90, $beb1f9bf, $eefbcaea, $e8cf1950, $51df07ae, $8c1fc644, $aececa90, $beb1f9bf, $eefbcaea, $e8cf1950, $51df07ae,
$920e8806, $f0ad0548, $e13c8d83, $927010d5, $11107d9f, $07647db9, $920e8806, $f0ad0548, $e13c8d83, $927010d5, $11107d9f, $07647db9,
$b2e3e4d4, $3d4f285e, $b9afa820, $fade82e0, $a067268b, $8272792e, $b2e3e4d4, $3d4f285e, $b9afa820, $fade82e0, $a067268b, $8272792e,
$553fb2c0, $489ae22b, $d4ef9794, $125e3fbc, $21fffcee, $825b1bfd, $553fb2c0, $489ae22b, $d4ef9794, $125e3fbc, $21fffcee, $825b1bfd,
$9255c5ed, $1257a240, $4e1a8302, $bae07fff, $528246e7, $8e57140e, $9255c5ed, $1257a240, $4e1a8302, $bae07fff, $528246e7, $8e57140e,
$3373f7bf, $8c9f8188, $a6fc4ee8, $c982b5a5, $a8c01db7, $579fc264, $3373f7bf, $8c9f8188, $a6fc4ee8, $c982b5a5, $a8c01db7, $579fc264,
$67094f31, $f2bd3f5f, $40fff7c1, $1fb78dfc, $8e6bd2c1, $437be59b, $67094f31, $f2bd3f5f, $40fff7c1, $1fb78dfc, $8e6bd2c1, $437be59b,
$99b03dbf, $b5dbc64b, $638dc0e6, $55819d99, $a197c81c, $4a012d6e, $99b03dbf, $b5dbc64b, $638dc0e6, $55819d99, $a197c81c, $4a012d6e,
$c5884a28, $ccc36f71, $b843c213, $6c0743f1, $8309893c, $0feddd5f, $c5884a28, $ccc36f71, $b843c213, $6c0743f1, $8309893c, $0feddd5f,
$2f7fe850, $d7c07f7e, $02507fbf, $5afb9a04, $a747d2d0, $1651192e, $2f7fe850, $d7c07f7e, $02507fbf, $5afb9a04, $a747d2d0, $1651192e,
$af70bf3e, $58c31380, $5f98302e, $727cc3c4, $0a0fb402, $0f7fef82, $af70bf3e, $58c31380, $5f98302e, $727cc3c4, $0a0fb402, $0f7fef82,
$8c96fdad, $5d2c2aae, $8ee99a49, $50da88b8, $8427f4a0, $1eac5790, $8c96fdad, $5d2c2aae, $8ee99a49, $50da88b8, $8427f4a0, $1eac5790,
$796fb449, $8252dc15, $efbd7d9b, $a672597d, $ada840d8, $45f54504, $796fb449, $8252dc15, $efbd7d9b, $a672597d, $ada840d8, $45f54504,
$fa5d7403, $e83ec305, $4f91751a, $925669c2, $23efe941, $a903f12e, $fa5d7403, $e83ec305, $4f91751a, $925669c2, $23efe941, $a903f12e,
$60270df2, $0276e4b6, $94fd6574, $927985b2, $8276dbcb, $02778176, $60270df2, $0276e4b6, $94fd6574, $927985b2, $8276dbcb, $02778176,
$f8af918d, $4e48f79e, $8f616ddf, $e29d840e, $842f7d83, $340ce5c8, $f8af918d, $4e48f79e, $8f616ddf, $e29d840e, $842f7d83, $340ce5c8,
$96bbb682, $93b4b148, $ef303cab, $984faf28, $779faf9b, $92dc560d, $96bbb682, $93b4b148, $ef303cab, $984faf28, $779faf9b, $92dc560d,
$224d1e20, $8437aa88, $7d29dc96, $2756d3dc, $8b907cee, $b51fd240, $224d1e20, $8437aa88, $7d29dc96, $2756d3dc, $8b907cee, $b51fd240,
$e7c07ce3, $e566b4a1, $c3e9615e, $3cf8209d, $6094d1e3, $cd9ca341, $e7c07ce3, $e566b4a1, $c3e9615e, $3cf8209d, $6094d1e3, $cd9ca341,
$5c76460e, $00ea983b, $d4d67881, $fd47572c, $f76cedd9, $bda8229c, $5c76460e, $00ea983b, $d4d67881, $fd47572c, $f76cedd9, $bda8229c,
$127dadaa, $438a074e, $1f97c090, $081bdb8a, $93a07ebe, $b938ca15, $127dadaa, $438a074e, $1f97c090, $081bdb8a, $93a07ebe, $b938ca15,
$97b03cff, $3dc2c0f8, $8d1ab2ec, $64380e51, $68cc7bfb, $d90f2788, $97b03cff, $3dc2c0f8, $8d1ab2ec, $64380e51, $68cc7bfb, $d90f2788,
$12490181, $5de5ffd4, $dd7ef86a, $76a2e214, $b9a40368, $925d958f, $12490181, $5de5ffd4, $dd7ef86a, $76a2e214, $b9a40368, $925d958f,
$4b39fffa, $ba39aee9, $a4ffd30b, $faf7933b, $6d498623, $193cbcfa, $4b39fffa, $ba39aee9, $a4ffd30b, $faf7933b, $6d498623, $193cbcfa,
$27627545, $825cf47a, $61bd8ba0, $d11e42d1, $cead04f4, $127ea392, $27627545, $825cf47a, $61bd8ba0, $d11e42d1, $cead04f4, $127ea392,
$10428db7, $8272a972, $9270c4a8, $127de50b, $285ba1c8, $3c62f44f, $10428db7, $8272a972, $9270c4a8, $127de50b, $285ba1c8, $3c62f44f,
$35c0eaa5, $e805d231, $428929fb, $b4fcdf82, $4fb66a53, $0e7dc15b, $35c0eaa5, $e805d231, $428929fb, $b4fcdf82, $4fb66a53, $0e7dc15b,
$1f081fab, $108618ae, $fcfd086d, $f9ff2889, $694bcc11, $236a5cae, $1f081fab, $108618ae, $fcfd086d, $f9ff2889, $694bcc11, $236a5cae,
$12deca4d, $2c3f8cc5, $d2d02dfe, $f8ef5896, $e4cf52da, $95155b67, $12deca4d, $2c3f8cc5, $d2d02dfe, $f8ef5896, $e4cf52da, $95155b67,
$494a488c, $b9b6a80c, $5c8f82bc, $89d36b45, $3a609437, $ec00c9a9, $494a488c, $b9b6a80c, $5c8f82bc, $89d36b45, $3a609437, $ec00c9a9,
$44715253, $0a874b49, $d773bc40, $7c34671c, $02717ef6, $4feb5536, $44715253, $0a874b49, $d773bc40, $7c34671c, $02717ef6, $4feb5536,
$a2d02fff, $d2bf60c4, $d43f03c0, $50b4ef6d, $07478cd1, $006e1888, $a2d02fff, $d2bf60c4, $d43f03c0, $50b4ef6d, $07478cd1, $006e1888,
$a2e53f55, $b9e6d4bc, $a2048016, $97573833, $d7207d67, $de0f8f3d, $a2e53f55, $b9e6d4bc, $a2048016, $97573833, $d7207d67, $de0f8f3d,
$72f87b33, $abcc4f33, $7688c55d, $7b00a6b0, $947b0001, $570075d2, $72f87b33, $abcc4f33, $7688c55d, $7b00a6b0, $947b0001, $570075d2,
$f9bb88f8, $8942019e, $4264a5ff, $856302e0, $72dbd92b, $ee971b69, $f9bb88f8, $8942019e, $4264a5ff, $856302e0, $72dbd92b, $ee971b69,
$6ea22fde, $5f08ae2b, $af7a616d, $e5c98767, $cf1febd2, $61efc8c2, $6ea22fde, $5f08ae2b, $af7a616d, $e5c98767, $cf1febd2, $61efc8c2,
$f1ac2571, $cc8239c2, $67214cb8, $b1e583d1, $b7dc3e62, $7f10bdce, $f1ac2571, $cc8239c2, $67214cb8, $b1e583d1, $b7dc3e62, $7f10bdce,
$f90a5c38, $0ff0443d, $606e6dc6, $60543a49, $5727c148, $2be98a1d, $f90a5c38, $0ff0443d, $606e6dc6, $60543a49, $5727c148, $2be98a1d,
$8ab41738, $20e1be24, $af96da0f, $68458425, $99833be5, $600d457d, $8ab41738, $20e1be24, $af96da0f, $68458425, $99833be5, $600d457d,
$282f9350, $8334b362, $d91d1120, $2b6d8da0, $642b1e31, $9c305a00, $282f9350, $8334b362, $d91d1120, $2b6d8da0, $642b1e31, $9c305a00,
$52bce688, $1b03588a, $f7baefd5, $4142ed9c, $a4315c11, $83323ec5, $52bce688, $1b03588a, $f7baefd5, $4142ed9c, $a4315c11, $83323ec5,
$dfef4636, $a133c501, $e9d3531c, $ee353783); $dfef4636, $a133c501, $e9d3531c, $ee353783);
S4: array[0..255] of DWord= ( S4: array[0..255] of DWord= (
$9db30420, $1fb6e9de, $a7be7bef, $d273a298, $4a4f7bdb, $64ad8c57, $9db30420, $1fb6e9de, $a7be7bef, $d273a298, $4a4f7bdb, $64ad8c57,
$85510443, $fa020ed1, $7e287aff, $e60fb663, $095f35a1, $79ebf120, $85510443, $fa020ed1, $7e287aff, $e60fb663, $095f35a1, $79ebf120,
$fd059d43, $6497b7b1, $f3641f63, $241e4adf, $28147f5f, $4fa2b8cd, $fd059d43, $6497b7b1, $f3641f63, $241e4adf, $28147f5f, $4fa2b8cd,
$c9430040, $0cc32220, $fdd30b30, $c0a5374f, $1d2d00d9, $24147b15, $c9430040, $0cc32220, $fdd30b30, $c0a5374f, $1d2d00d9, $24147b15,
$ee4d111a, $0fca5167, $71ff904c, $2d195ffe, $1a05645f, $0c13fefe, $ee4d111a, $0fca5167, $71ff904c, $2d195ffe, $1a05645f, $0c13fefe,
$081b08ca, $05170121, $80530100, $e83e5efe, $ac9af4f8, $7fe72701, $081b08ca, $05170121, $80530100, $e83e5efe, $ac9af4f8, $7fe72701,
$d2b8ee5f, $06df4261, $bb9e9b8a, $7293ea25, $ce84ffdf, $f5718801, $d2b8ee5f, $06df4261, $bb9e9b8a, $7293ea25, $ce84ffdf, $f5718801,
$3dd64b04, $a26f263b, $7ed48400, $547eebe6, $446d4ca0, $6cf3d6f5, $3dd64b04, $a26f263b, $7ed48400, $547eebe6, $446d4ca0, $6cf3d6f5,
$2649abdf, $aea0c7f5, $36338cc1, $503f7e93, $d3772061, $11b638e1, $2649abdf, $aea0c7f5, $36338cc1, $503f7e93, $d3772061, $11b638e1,
$72500e03, $f80eb2bb, $abe0502e, $ec8d77de, $57971e81, $e14f6746, $72500e03, $f80eb2bb, $abe0502e, $ec8d77de, $57971e81, $e14f6746,
$c9335400, $6920318f, $081dbb99, $ffc304a5, $4d351805, $7f3d5ce3, $c9335400, $6920318f, $081dbb99, $ffc304a5, $4d351805, $7f3d5ce3,
$a6c866c6, $5d5bcca9, $daec6fea, $9f926f91, $9f46222f, $3991467d, $a6c866c6, $5d5bcca9, $daec6fea, $9f926f91, $9f46222f, $3991467d,
$a5bf6d8e, $1143c44f, $43958302, $d0214eeb, $022083b8, $3fb6180c, $a5bf6d8e, $1143c44f, $43958302, $d0214eeb, $022083b8, $3fb6180c,
$18f8931e, $281658e6, $26486e3e, $8bd78a70, $7477e4c1, $b506e07c, $18f8931e, $281658e6, $26486e3e, $8bd78a70, $7477e4c1, $b506e07c,
$f32d0a25, $79098b02, $e4eabb81, $28123b23, $69dead38, $1574ca16, $f32d0a25, $79098b02, $e4eabb81, $28123b23, $69dead38, $1574ca16,
$df871b62, $211c40b7, $a51a9ef9, $0014377b, $041e8ac8, $09114003, $df871b62, $211c40b7, $a51a9ef9, $0014377b, $041e8ac8, $09114003,
$bd59e4d2, $e3d156d5, $4fe876d5, $2f91a340, $557be8de, $00eae4a7, $bd59e4d2, $e3d156d5, $4fe876d5, $2f91a340, $557be8de, $00eae4a7,
$0ce5c2ec, $4db4bba6, $e756bdff, $dd3369ac, $ec17b035, $06572327, $0ce5c2ec, $4db4bba6, $e756bdff, $dd3369ac, $ec17b035, $06572327,
$99afc8b0, $56c8c391, $6b65811c, $5e146119, $6e85cb75, $be07c002, $99afc8b0, $56c8c391, $6b65811c, $5e146119, $6e85cb75, $be07c002,
$c2325577, $893ff4ec, $5bbfc92d, $d0ec3b25, $b7801ab7, $8d6d3b24, $c2325577, $893ff4ec, $5bbfc92d, $d0ec3b25, $b7801ab7, $8d6d3b24,
$20c763ef, $c366a5fc, $9c382880, $0ace3205, $aac9548a, $eca1d7c7, $20c763ef, $c366a5fc, $9c382880, $0ace3205, $aac9548a, $eca1d7c7,
$041afa32, $1d16625a, $6701902c, $9b757a54, $31d477f7, $9126b031, $041afa32, $1d16625a, $6701902c, $9b757a54, $31d477f7, $9126b031,
$36cc6fdb, $c70b8b46, $d9e66a48, $56e55a79, $026a4ceb, $52437eff, $36cc6fdb, $c70b8b46, $d9e66a48, $56e55a79, $026a4ceb, $52437eff,
$2f8f76b4, $0df980a5, $8674cde3, $edda04eb, $17a9be04, $2c18f4df, $2f8f76b4, $0df980a5, $8674cde3, $edda04eb, $17a9be04, $2c18f4df,
$b7747f9d, $ab2af7b4, $efc34d20, $2e096b7c, $1741a254, $e5b6a035, $b7747f9d, $ab2af7b4, $efc34d20, $2e096b7c, $1741a254, $e5b6a035,
$213d42f6, $2c1c7c26, $61c2f50f, $6552daf9, $d2c231f8, $25130f69, $213d42f6, $2c1c7c26, $61c2f50f, $6552daf9, $d2c231f8, $25130f69,
$d8167fa2, $0418f2c8, $001a96a6, $0d1526ab, $63315c21, $5e0a72ec, $d8167fa2, $0418f2c8, $001a96a6, $0d1526ab, $63315c21, $5e0a72ec,
$49bafefd, $187908d9, $8d0dbd86, $311170a7, $3e9b640c, $cc3e10d7, $49bafefd, $187908d9, $8d0dbd86, $311170a7, $3e9b640c, $cc3e10d7,
$d5cad3b6, $0caec388, $f73001e1, $6c728aff, $71eae2a1, $1f9af36e, $d5cad3b6, $0caec388, $f73001e1, $6c728aff, $71eae2a1, $1f9af36e,
$cfcbd12f, $c1de8417, $ac07be6b, $cb44a1d8, $8b9b0f56, $013988c3, $cfcbd12f, $c1de8417, $ac07be6b, $cb44a1d8, $8b9b0f56, $013988c3,
$b1c52fca, $b4be31cd, $d8782806, $12a3a4e2, $6f7de532, $58fd7eb6, $b1c52fca, $b4be31cd, $d8782806, $12a3a4e2, $6f7de532, $58fd7eb6,
$d01ee900, $24adffc2, $f4990fc5, $9711aac5, $001d7b95, $82e5e7d2, $d01ee900, $24adffc2, $f4990fc5, $9711aac5, $001d7b95, $82e5e7d2,
$109873f6, $00613096, $c32d9521, $ada121ff, $29908415, $7fbb977f, $109873f6, $00613096, $c32d9521, $ada121ff, $29908415, $7fbb977f,
$af9eb3db, $29c9ed2a, $5ce2a465, $a730f32c, $d0aa3fe8, $8a5cc091, $af9eb3db, $29c9ed2a, $5ce2a465, $a730f32c, $d0aa3fe8, $8a5cc091,
$d49e2ce7, $0ce454a9, $d60acd86, $015f1919, $77079103, $dea03af6, $d49e2ce7, $0ce454a9, $d60acd86, $015f1919, $77079103, $dea03af6,
$78a8565e, $dee356df, $21f05cbe, $8b75e387, $b3c50651, $b8a5c3ef, $78a8565e, $dee356df, $21f05cbe, $8b75e387, $b3c50651, $b8a5c3ef,
$d8eeb6d2, $e523be77, $c2154529, $2f69efdf, $afe67afb, $f470c4b2, $d8eeb6d2, $e523be77, $c2154529, $2f69efdf, $afe67afb, $f470c4b2,
$f3e0eb5b, $d6cc9876, $39e4460c, $1fda8538, $1987832f, $ca007367, $f3e0eb5b, $d6cc9876, $39e4460c, $1fda8538, $1987832f, $ca007367,
$a99144f8, $296b299e, $492fc295, $9266beab, $b5676e69, $9bd3ddda, $a99144f8, $296b299e, $492fc295, $9266beab, $b5676e69, $9bd3ddda,
$df7e052f, $db25701c, $1b5e51ee, $f65324e6, $6afce36c, $0316cc04, $df7e052f, $db25701c, $1b5e51ee, $f65324e6, $6afce36c, $0316cc04,
$8644213e, $b7dc59d0, $7965291f, $ccd6fd43, $41823979, $932bcdf6, $8644213e, $b7dc59d0, $7965291f, $ccd6fd43, $41823979, $932bcdf6,
$b657c34d, $4edfd282, $7ae5290c, $3cb9536b, $851e20fe, $9833557e, $b657c34d, $4edfd282, $7ae5290c, $3cb9536b, $851e20fe, $9833557e,
$13ecf0b0, $d3ffb372, $3f85c5c1, $0aef7ed2); $13ecf0b0, $d3ffb372, $3f85c5c1, $0aef7ed2);

View File

@ -1,297 +1,297 @@
const const
shifts2: array[0..15]of byte= shifts2: array[0..15]of byte=
(0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0); (0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0);
des_skb: array[0..7,0..63]of dword=( des_skb: array[0..7,0..63]of dword=(
( (
(* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 *) (* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 *)
$00000000,$00000010,$20000000,$20000010, $00000000,$00000010,$20000000,$20000010,
$00010000,$00010010,$20010000,$20010010, $00010000,$00010010,$20010000,$20010010,
$00000800,$00000810,$20000800,$20000810, $00000800,$00000810,$20000800,$20000810,
$00010800,$00010810,$20010800,$20010810, $00010800,$00010810,$20010800,$20010810,
$00000020,$00000030,$20000020,$20000030, $00000020,$00000030,$20000020,$20000030,
$00010020,$00010030,$20010020,$20010030, $00010020,$00010030,$20010020,$20010030,
$00000820,$00000830,$20000820,$20000830, $00000820,$00000830,$20000820,$20000830,
$00010820,$00010830,$20010820,$20010830, $00010820,$00010830,$20010820,$20010830,
$00080000,$00080010,$20080000,$20080010, $00080000,$00080010,$20080000,$20080010,
$00090000,$00090010,$20090000,$20090010, $00090000,$00090010,$20090000,$20090010,
$00080800,$00080810,$20080800,$20080810, $00080800,$00080810,$20080800,$20080810,
$00090800,$00090810,$20090800,$20090810, $00090800,$00090810,$20090800,$20090810,
$00080020,$00080030,$20080020,$20080030, $00080020,$00080030,$20080020,$20080030,
$00090020,$00090030,$20090020,$20090030, $00090020,$00090030,$20090020,$20090030,
$00080820,$00080830,$20080820,$20080830, $00080820,$00080830,$20080820,$20080830,
$00090820,$00090830,$20090820,$20090830 $00090820,$00090830,$20090820,$20090830
),( ),(
(* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 *) (* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 *)
$00000000,$02000000,$00002000,$02002000, $00000000,$02000000,$00002000,$02002000,
$00200000,$02200000,$00202000,$02202000, $00200000,$02200000,$00202000,$02202000,
$00000004,$02000004,$00002004,$02002004, $00000004,$02000004,$00002004,$02002004,
$00200004,$02200004,$00202004,$02202004, $00200004,$02200004,$00202004,$02202004,
$00000400,$02000400,$00002400,$02002400, $00000400,$02000400,$00002400,$02002400,
$00200400,$02200400,$00202400,$02202400, $00200400,$02200400,$00202400,$02202400,
$00000404,$02000404,$00002404,$02002404, $00000404,$02000404,$00002404,$02002404,
$00200404,$02200404,$00202404,$02202404, $00200404,$02200404,$00202404,$02202404,
$10000000,$12000000,$10002000,$12002000, $10000000,$12000000,$10002000,$12002000,
$10200000,$12200000,$10202000,$12202000, $10200000,$12200000,$10202000,$12202000,
$10000004,$12000004,$10002004,$12002004, $10000004,$12000004,$10002004,$12002004,
$10200004,$12200004,$10202004,$12202004, $10200004,$12200004,$10202004,$12202004,
$10000400,$12000400,$10002400,$12002400, $10000400,$12000400,$10002400,$12002400,
$10200400,$12200400,$10202400,$12202400, $10200400,$12200400,$10202400,$12202400,
$10000404,$12000404,$10002404,$12002404, $10000404,$12000404,$10002404,$12002404,
$10200404,$12200404,$10202404,$12202404 $10200404,$12200404,$10202404,$12202404
),( ),(
(* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 *) (* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 *)
$00000000,$00000001,$00040000,$00040001, $00000000,$00000001,$00040000,$00040001,
$01000000,$01000001,$01040000,$01040001, $01000000,$01000001,$01040000,$01040001,
$00000002,$00000003,$00040002,$00040003, $00000002,$00000003,$00040002,$00040003,
$01000002,$01000003,$01040002,$01040003, $01000002,$01000003,$01040002,$01040003,
$00000200,$00000201,$00040200,$00040201, $00000200,$00000201,$00040200,$00040201,
$01000200,$01000201,$01040200,$01040201, $01000200,$01000201,$01040200,$01040201,
$00000202,$00000203,$00040202,$00040203, $00000202,$00000203,$00040202,$00040203,
$01000202,$01000203,$01040202,$01040203, $01000202,$01000203,$01040202,$01040203,
$08000000,$08000001,$08040000,$08040001, $08000000,$08000001,$08040000,$08040001,
$09000000,$09000001,$09040000,$09040001, $09000000,$09000001,$09040000,$09040001,
$08000002,$08000003,$08040002,$08040003, $08000002,$08000003,$08040002,$08040003,
$09000002,$09000003,$09040002,$09040003, $09000002,$09000003,$09040002,$09040003,
$08000200,$08000201,$08040200,$08040201, $08000200,$08000201,$08040200,$08040201,
$09000200,$09000201,$09040200,$09040201, $09000200,$09000201,$09040200,$09040201,
$08000202,$08000203,$08040202,$08040203, $08000202,$08000203,$08040202,$08040203,
$09000202,$09000203,$09040202,$09040203 $09000202,$09000203,$09040202,$09040203
),( ),(
(* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 *) (* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 *)
$00000000,$00100000,$00000100,$00100100, $00000000,$00100000,$00000100,$00100100,
$00000008,$00100008,$00000108,$00100108, $00000008,$00100008,$00000108,$00100108,
$00001000,$00101000,$00001100,$00101100, $00001000,$00101000,$00001100,$00101100,
$00001008,$00101008,$00001108,$00101108, $00001008,$00101008,$00001108,$00101108,
$04000000,$04100000,$04000100,$04100100, $04000000,$04100000,$04000100,$04100100,
$04000008,$04100008,$04000108,$04100108, $04000008,$04100008,$04000108,$04100108,
$04001000,$04101000,$04001100,$04101100, $04001000,$04101000,$04001100,$04101100,
$04001008,$04101008,$04001108,$04101108, $04001008,$04101008,$04001108,$04101108,
$00020000,$00120000,$00020100,$00120100, $00020000,$00120000,$00020100,$00120100,
$00020008,$00120008,$00020108,$00120108, $00020008,$00120008,$00020108,$00120108,
$00021000,$00121000,$00021100,$00121100, $00021000,$00121000,$00021100,$00121100,
$00021008,$00121008,$00021108,$00121108, $00021008,$00121008,$00021108,$00121108,
$04020000,$04120000,$04020100,$04120100, $04020000,$04120000,$04020100,$04120100,
$04020008,$04120008,$04020108,$04120108, $04020008,$04120008,$04020108,$04120108,
$04021000,$04121000,$04021100,$04121100, $04021000,$04121000,$04021100,$04121100,
$04021008,$04121008,$04021108,$04121108 $04021008,$04121008,$04021108,$04121108
),( ),(
(* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 *) (* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 *)
$00000000,$10000000,$00010000,$10010000, $00000000,$10000000,$00010000,$10010000,
$00000004,$10000004,$00010004,$10010004, $00000004,$10000004,$00010004,$10010004,
$20000000,$30000000,$20010000,$30010000, $20000000,$30000000,$20010000,$30010000,
$20000004,$30000004,$20010004,$30010004, $20000004,$30000004,$20010004,$30010004,
$00100000,$10100000,$00110000,$10110000, $00100000,$10100000,$00110000,$10110000,
$00100004,$10100004,$00110004,$10110004, $00100004,$10100004,$00110004,$10110004,
$20100000,$30100000,$20110000,$30110000, $20100000,$30100000,$20110000,$30110000,
$20100004,$30100004,$20110004,$30110004, $20100004,$30100004,$20110004,$30110004,
$00001000,$10001000,$00011000,$10011000, $00001000,$10001000,$00011000,$10011000,
$00001004,$10001004,$00011004,$10011004, $00001004,$10001004,$00011004,$10011004,
$20001000,$30001000,$20011000,$30011000, $20001000,$30001000,$20011000,$30011000,
$20001004,$30001004,$20011004,$30011004, $20001004,$30001004,$20011004,$30011004,
$00101000,$10101000,$00111000,$10111000, $00101000,$10101000,$00111000,$10111000,
$00101004,$10101004,$00111004,$10111004, $00101004,$10101004,$00111004,$10111004,
$20101000,$30101000,$20111000,$30111000, $20101000,$30101000,$20111000,$30111000,
$20101004,$30101004,$20111004,$30111004 $20101004,$30101004,$20111004,$30111004
),( ),(
(* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 *) (* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 *)
$00000000,$08000000,$00000008,$08000008, $00000000,$08000000,$00000008,$08000008,
$00000400,$08000400,$00000408,$08000408, $00000400,$08000400,$00000408,$08000408,
$00020000,$08020000,$00020008,$08020008, $00020000,$08020000,$00020008,$08020008,
$00020400,$08020400,$00020408,$08020408, $00020400,$08020400,$00020408,$08020408,
$00000001,$08000001,$00000009,$08000009, $00000001,$08000001,$00000009,$08000009,
$00000401,$08000401,$00000409,$08000409, $00000401,$08000401,$00000409,$08000409,
$00020001,$08020001,$00020009,$08020009, $00020001,$08020001,$00020009,$08020009,
$00020401,$08020401,$00020409,$08020409, $00020401,$08020401,$00020409,$08020409,
$02000000,$0A000000,$02000008,$0A000008, $02000000,$0A000000,$02000008,$0A000008,
$02000400,$0A000400,$02000408,$0A000408, $02000400,$0A000400,$02000408,$0A000408,
$02020000,$0A020000,$02020008,$0A020008, $02020000,$0A020000,$02020008,$0A020008,
$02020400,$0A020400,$02020408,$0A020408, $02020400,$0A020400,$02020408,$0A020408,
$02000001,$0A000001,$02000009,$0A000009, $02000001,$0A000001,$02000009,$0A000009,
$02000401,$0A000401,$02000409,$0A000409, $02000401,$0A000401,$02000409,$0A000409,
$02020001,$0A020001,$02020009,$0A020009, $02020001,$0A020001,$02020009,$0A020009,
$02020401,$0A020401,$02020409,$0A020409 $02020401,$0A020401,$02020409,$0A020409
),( ),(
(* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 *) (* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 *)
$00000000,$00000100,$00080000,$00080100, $00000000,$00000100,$00080000,$00080100,
$01000000,$01000100,$01080000,$01080100, $01000000,$01000100,$01080000,$01080100,
$00000010,$00000110,$00080010,$00080110, $00000010,$00000110,$00080010,$00080110,
$01000010,$01000110,$01080010,$01080110, $01000010,$01000110,$01080010,$01080110,
$00200000,$00200100,$00280000,$00280100, $00200000,$00200100,$00280000,$00280100,
$01200000,$01200100,$01280000,$01280100, $01200000,$01200100,$01280000,$01280100,
$00200010,$00200110,$00280010,$00280110, $00200010,$00200110,$00280010,$00280110,
$01200010,$01200110,$01280010,$01280110, $01200010,$01200110,$01280010,$01280110,
$00000200,$00000300,$00080200,$00080300, $00000200,$00000300,$00080200,$00080300,
$01000200,$01000300,$01080200,$01080300, $01000200,$01000300,$01080200,$01080300,
$00000210,$00000310,$00080210,$00080310, $00000210,$00000310,$00080210,$00080310,
$01000210,$01000310,$01080210,$01080310, $01000210,$01000310,$01080210,$01080310,
$00200200,$00200300,$00280200,$00280300, $00200200,$00200300,$00280200,$00280300,
$01200200,$01200300,$01280200,$01280300, $01200200,$01200300,$01280200,$01280300,
$00200210,$00200310,$00280210,$00280310, $00200210,$00200310,$00280210,$00280310,
$01200210,$01200310,$01280210,$01280310 $01200210,$01200310,$01280210,$01280310
),( ),(
(* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 *) (* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 *)
$00000000,$04000000,$00040000,$04040000, $00000000,$04000000,$00040000,$04040000,
$00000002,$04000002,$00040002,$04040002, $00000002,$04000002,$00040002,$04040002,
$00002000,$04002000,$00042000,$04042000, $00002000,$04002000,$00042000,$04042000,
$00002002,$04002002,$00042002,$04042002, $00002002,$04002002,$00042002,$04042002,
$00000020,$04000020,$00040020,$04040020, $00000020,$04000020,$00040020,$04040020,
$00000022,$04000022,$00040022,$04040022, $00000022,$04000022,$00040022,$04040022,
$00002020,$04002020,$00042020,$04042020, $00002020,$04002020,$00042020,$04042020,
$00002022,$04002022,$00042022,$04042022, $00002022,$04002022,$00042022,$04042022,
$00000800,$04000800,$00040800,$04040800, $00000800,$04000800,$00040800,$04040800,
$00000802,$04000802,$00040802,$04040802, $00000802,$04000802,$00040802,$04040802,
$00002800,$04002800,$00042800,$04042800, $00002800,$04002800,$00042800,$04042800,
$00002802,$04002802,$00042802,$04042802, $00002802,$04002802,$00042802,$04042802,
$00000820,$04000820,$00040820,$04040820, $00000820,$04000820,$00040820,$04040820,
$00000822,$04000822,$00040822,$04040822, $00000822,$04000822,$00040822,$04040822,
$00002820,$04002820,$00042820,$04042820, $00002820,$04002820,$00042820,$04042820,
$00002822,$04002822,$00042822,$04042822 $00002822,$04002822,$00042822,$04042822
)); ));
des_sptrans: array[0..7,0..63] of dword=( des_sptrans: array[0..7,0..63] of dword=(
( (
(* nibble 0 *) (* nibble 0 *)
$02080800, $00080000, $02000002, $02080802, $02080800, $00080000, $02000002, $02080802,
$02000000, $00080802, $00080002, $02000002, $02000000, $00080802, $00080002, $02000002,
$00080802, $02080800, $02080000, $00000802, $00080802, $02080800, $02080000, $00000802,
$02000802, $02000000, $00000000, $00080002, $02000802, $02000000, $00000000, $00080002,
$00080000, $00000002, $02000800, $00080800, $00080000, $00000002, $02000800, $00080800,
$02080802, $02080000, $00000802, $02000800, $02080802, $02080000, $00000802, $02000800,
$00000002, $00000800, $00080800, $02080002, $00000002, $00000800, $00080800, $02080002,
$00000800, $02000802, $02080002, $00000000, $00000800, $02000802, $02080002, $00000000,
$00000000, $02080802, $02000800, $00080002, $00000000, $02080802, $02000800, $00080002,
$02080800, $00080000, $00000802, $02000800, $02080800, $00080000, $00000802, $02000800,
$02080002, $00000800, $00080800, $02000002, $02080002, $00000800, $00080800, $02000002,
$00080802, $00000002, $02000002, $02080000, $00080802, $00000002, $02000002, $02080000,
$02080802, $00080800, $02080000, $02000802, $02080802, $00080800, $02080000, $02000802,
$02000000, $00000802, $00080002, $00000000, $02000000, $00000802, $00080002, $00000000,
$00080000, $02000000, $02000802, $02080800, $00080000, $02000000, $02000802, $02080800,
$00000002, $02080002, $00000800, $00080802 $00000002, $02080002, $00000800, $00080802
),( ),(
(* nibble 1 *) (* nibble 1 *)
$40108010, $00000000, $00108000, $40100000, $40108010, $00000000, $00108000, $40100000,
$40000010, $00008010, $40008000, $00108000, $40000010, $00008010, $40008000, $00108000,
$00008000, $40100010, $00000010, $40008000, $00008000, $40100010, $00000010, $40008000,
$00100010, $40108000, $40100000, $00000010, $00100010, $40108000, $40100000, $00000010,
$00100000, $40008010, $40100010, $00008000, $00100000, $40008010, $40100010, $00008000,
$00108010, $40000000, $00000000, $00100010, $00108010, $40000000, $00000000, $00100010,
$40008010, $00108010, $40108000, $40000010, $40008010, $00108010, $40108000, $40000010,
$40000000, $00100000, $00008010, $40108010, $40000000, $00100000, $00008010, $40108010,
$00100010, $40108000, $40008000, $00108010, $00100010, $40108000, $40008000, $00108010,
$40108010, $00100010, $40000010, $00000000, $40108010, $00100010, $40000010, $00000000,
$40000000, $00008010, $00100000, $40100010, $40000000, $00008010, $00100000, $40100010,
$00008000, $40000000, $00108010, $40008010, $00008000, $40000000, $00108010, $40008010,
$40108000, $00008000, $00000000, $40000010, $40108000, $00008000, $00000000, $40000010,
$00000010, $40108010, $00108000, $40100000, $00000010, $40108010, $00108000, $40100000,
$40100010, $00100000, $00008010, $40008000, $40100010, $00100000, $00008010, $40008000,
$40008010, $00000010, $40100000, $00108000 $40008010, $00000010, $40100000, $00108000
),( ),(
(* nibble 2 *) (* nibble 2 *)
$04000001, $04040100, $00000100, $04000101, $04000001, $04040100, $00000100, $04000101,
$00040001, $04000000, $04000101, $00040100, $00040001, $04000000, $04000101, $00040100,
$04000100, $00040000, $04040000, $00000001, $04000100, $00040000, $04040000, $00000001,
$04040101, $00000101, $00000001, $04040001, $04040101, $00000101, $00000001, $04040001,
$00000000, $00040001, $04040100, $00000100, $00000000, $00040001, $04040100, $00000100,
$00000101, $04040101, $00040000, $04000001, $00000101, $04040101, $00040000, $04000001,
$04040001, $04000100, $00040101, $04040000, $04040001, $04000100, $00040101, $04040000,
$00040100, $00000000, $04000000, $00040101, $00040100, $00000000, $04000000, $00040101,
$04040100, $00000100, $00000001, $00040000, $04040100, $00000100, $00000001, $00040000,
$00000101, $00040001, $04040000, $04000101, $00000101, $00040001, $04040000, $04000101,
$00000000, $04040100, $00040100, $04040001, $00000000, $04040100, $00040100, $04040001,
$00040001, $04000000, $04040101, $00000001, $00040001, $04000000, $04040101, $00000001,
$00040101, $04000001, $04000000, $04040101, $00040101, $04000001, $04000000, $04040101,
$00040000, $04000100, $04000101, $00040100, $00040000, $04000100, $04000101, $00040100,
$04000100, $00000000, $04040001, $00000101, $04000100, $00000000, $04040001, $00000101,
$04000001, $00040101, $00000100, $04040000 $04000001, $00040101, $00000100, $04040000
),( ),(
(* nibble 3 *) (* nibble 3 *)
$00401008, $10001000, $00000008, $10401008, $00401008, $10001000, $00000008, $10401008,
$00000000, $10400000, $10001008, $00400008, $00000000, $10400000, $10001008, $00400008,
$10401000, $10000008, $10000000, $00001008, $10401000, $10000008, $10000000, $00001008,
$10000008, $00401008, $00400000, $10000000, $10000008, $00401008, $00400000, $10000000,
$10400008, $00401000, $00001000, $00000008, $10400008, $00401000, $00001000, $00000008,
$00401000, $10001008, $10400000, $00001000, $00401000, $10001008, $10400000, $00001000,
$00001008, $00000000, $00400008, $10401000, $00001008, $00000000, $00400008, $10401000,
$10001000, $10400008, $10401008, $00400000, $10001000, $10400008, $10401008, $00400000,
$10400008, $00001008, $00400000, $10000008, $10400008, $00001008, $00400000, $10000008,
$00401000, $10001000, $00000008, $10400000, $00401000, $10001000, $00000008, $10400000,
$10001008, $00000000, $00001000, $00400008, $10001008, $00000000, $00001000, $00400008,
$00000000, $10400008, $10401000, $00001000, $00000000, $10400008, $10401000, $00001000,
$10000000, $10401008, $00401008, $00400000, $10000000, $10401008, $00401008, $00400000,
$10401008, $00000008, $10001000, $00401008, $10401008, $00000008, $10001000, $00401008,
$00400008, $00401000, $10400000, $10001008, $00400008, $00401000, $10400000, $10001008,
$00001008, $10000000, $10000008, $10401000 $00001008, $10000000, $10000008, $10401000
),( ),(
(* nibble 4 *) (* nibble 4 *)
$08000000, $00010000, $00000400, $08010420, $08000000, $00010000, $00000400, $08010420,
$08010020, $08000400, $00010420, $08010000, $08010020, $08000400, $00010420, $08010000,
$00010000, $00000020, $08000020, $00010400, $00010000, $00000020, $08000020, $00010400,
$08000420, $08010020, $08010400, $00000000, $08000420, $08010020, $08010400, $00000000,
$00010400, $08000000, $00010020, $00000420, $00010400, $08000000, $00010020, $00000420,
$08000400, $00010420, $00000000, $08000020, $08000400, $00010420, $00000000, $08000020,
$00000020, $08000420, $08010420, $00010020, $00000020, $08000420, $08010420, $00010020,
$08010000, $00000400, $00000420, $08010400, $08010000, $00000400, $00000420, $08010400,
$08010400, $08000420, $00010020, $08010000, $08010400, $08000420, $00010020, $08010000,
$00010000, $00000020, $08000020, $08000400, $00010000, $00000020, $08000020, $08000400,
$08000000, $00010400, $08010420, $00000000, $08000000, $00010400, $08010420, $00000000,
$00010420, $08000000, $00000400, $00010020, $00010420, $08000000, $00000400, $00010020,
$08000420, $00000400, $00000000, $08010420, $08000420, $00000400, $00000000, $08010420,
$08010020, $08010400, $00000420, $00010000, $08010020, $08010400, $00000420, $00010000,
$00010400, $08010020, $08000400, $00000420, $00010400, $08010020, $08000400, $00000420,
$00000020, $00010420, $08010000, $08000020 $00000020, $00010420, $08010000, $08000020
),( ),(
(* nibble 5 *) (* nibble 5 *)
$80000040, $00200040, $00000000, $80202000, $80000040, $00200040, $00000000, $80202000,
$00200040, $00002000, $80002040, $00200000, $00200040, $00002000, $80002040, $00200000,
$00002040, $80202040, $00202000, $80000000, $00002040, $80202040, $00202000, $80000000,
$80002000, $80000040, $80200000, $00202040, $80002000, $80000040, $80200000, $00202040,
$00200000, $80002040, $80200040, $00000000, $00200000, $80002040, $80200040, $00000000,
$00002000, $00000040, $80202000, $80200040, $00002000, $00000040, $80202000, $80200040,
$80202040, $80200000, $80000000, $00002040, $80202040, $80200000, $80000000, $00002040,
$00000040, $00202000, $00202040, $80002000, $00000040, $00202000, $00202040, $80002000,
$00002040, $80000000, $80002000, $00202040, $00002040, $80000000, $80002000, $00202040,
$80202000, $00200040, $00000000, $80002000, $80202000, $00200040, $00000000, $80002000,
$80000000, $00002000, $80200040, $00200000, $80000000, $00002000, $80200040, $00200000,
$00200040, $80202040, $00202000, $00000040, $00200040, $80202040, $00202000, $00000040,
$80202040, $00202000, $00200000, $80002040, $80202040, $00202000, $00200000, $80002040,
$80000040, $80200000, $00202040, $00000000, $80000040, $80200000, $00202040, $00000000,
$00002000, $80000040, $80002040, $80202000, $00002000, $80000040, $80002040, $80202000,
$80200000, $00002040, $00000040, $80200040 $80200000, $00002040, $00000040, $80200040
),( ),(
(* nibble 6 *) (* nibble 6 *)
$00004000, $00000200, $01000200, $01000004, $00004000, $00000200, $01000200, $01000004,
$01004204, $00004004, $00004200, $00000000, $01004204, $00004004, $00004200, $00000000,
$01000000, $01000204, $00000204, $01004000, $01000000, $01000204, $00000204, $01004000,
$00000004, $01004200, $01004000, $00000204, $00000004, $01004200, $01004000, $00000204,
$01000204, $00004000, $00004004, $01004204, $01000204, $00004000, $00004004, $01004204,
$00000000, $01000200, $01000004, $00004200, $00000000, $01000200, $01000004, $00004200,
$01004004, $00004204, $01004200, $00000004, $01004004, $00004204, $01004200, $00000004,
$00004204, $01004004, $00000200, $01000000, $00004204, $01004004, $00000200, $01000000,
$00004204, $01004000, $01004004, $00000204, $00004204, $01004000, $01004004, $00000204,
$00004000, $00000200, $01000000, $01004004, $00004000, $00000200, $01000000, $01004004,
$01000204, $00004204, $00004200, $00000000, $01000204, $00004204, $00004200, $00000000,
$00000200, $01000004, $00000004, $01000200, $00000200, $01000004, $00000004, $01000200,
$00000000, $01000204, $01000200, $00004200, $00000000, $01000204, $01000200, $00004200,
$00000204, $00004000, $01004204, $01000000, $00000204, $00004000, $01004204, $01000000,
$01004200, $00000004, $00004004, $01004204, $01004200, $00000004, $00004004, $01004204,
$01000004, $01004200, $01004000, $00004004 $01000004, $01004200, $01004000, $00004004
),( ),(
(* nibble 7 *) (* nibble 7 *)
$20800080, $20820000, $00020080, $00000000, $20800080, $20820000, $00020080, $00000000,
$20020000, $00800080, $20800000, $20820080, $20020000, $00800080, $20800000, $20820080,
$00000080, $20000000, $00820000, $00020080, $00000080, $20000000, $00820000, $00020080,
$00820080, $20020080, $20000080, $20800000, $00820080, $20020080, $20000080, $20800000,
$00020000, $00820080, $00800080, $20020000, $00020000, $00820080, $00800080, $20020000,
$20820080, $20000080, $00000000, $00820000, $20820080, $20000080, $00000000, $00820000,
$20000000, $00800000, $20020080, $20800080, $20000000, $00800000, $20020080, $20800080,
$00800000, $00020000, $20820000, $00000080, $00800000, $00020000, $20820000, $00000080,
$00800000, $00020000, $20000080, $20820080, $00800000, $00020000, $20000080, $20820080,
$00020080, $20000000, $00000000, $00820000, $00020080, $20000000, $00000000, $00820000,
$20800080, $20020080, $20020000, $00800080, $20800080, $20020080, $20020000, $00800080,
$20820000, $00000080, $00800080, $20020000, $20820000, $00000080, $00800080, $20020000,
$20820080, $00800000, $20800000, $20000080, $20820080, $00800000, $20800000, $20000080,
$00820000, $00020080, $20020080, $20800000, $00820000, $00020080, $20020080, $20800000,
$00000080, $20820000, $00820080, $00000000, $00000080, $20820000, $00820080, $00000000,
$20000000, $20800080, $00020000, $00820080 $20000000, $20800080, $00020000, $00820080
)); ));

View File

@ -1,130 +1,130 @@
const const
sTable: array[0..3, 0..255] of DWord= ( sTable: array[0..3, 0..255] of DWord= (
($00072000,$00075000,$00074800,$00071000,$00076800,$00074000,$00070000,$00077000, ($00072000,$00075000,$00074800,$00071000,$00076800,$00074000,$00070000,$00077000,
$00073000,$00075800,$00070800,$00076000,$00073800,$00077800,$00072800,$00071800, $00073000,$00075800,$00070800,$00076000,$00073800,$00077800,$00072800,$00071800,
$0005A000,$0005D000,$0005C800,$00059000,$0005E800,$0005C000,$00058000,$0005F000, $0005A000,$0005D000,$0005C800,$00059000,$0005E800,$0005C000,$00058000,$0005F000,
$0005B000,$0005D800,$00058800,$0005E000,$0005B800,$0005F800,$0005A800,$00059800, $0005B000,$0005D800,$00058800,$0005E000,$0005B800,$0005F800,$0005A800,$00059800,
$00022000,$00025000,$00024800,$00021000,$00026800,$00024000,$00020000,$00027000, $00022000,$00025000,$00024800,$00021000,$00026800,$00024000,$00020000,$00027000,
$00023000,$00025800,$00020800,$00026000,$00023800,$00027800,$00022800,$00021800, $00023000,$00025800,$00020800,$00026000,$00023800,$00027800,$00022800,$00021800,
$00062000,$00065000,$00064800,$00061000,$00066800,$00064000,$00060000,$00067000, $00062000,$00065000,$00064800,$00061000,$00066800,$00064000,$00060000,$00067000,
$00063000,$00065800,$00060800,$00066000,$00063800,$00067800,$00062800,$00061800, $00063000,$00065800,$00060800,$00066000,$00063800,$00067800,$00062800,$00061800,
$00032000,$00035000,$00034800,$00031000,$00036800,$00034000,$00030000,$00037000, $00032000,$00035000,$00034800,$00031000,$00036800,$00034000,$00030000,$00037000,
$00033000,$00035800,$00030800,$00036000,$00033800,$00037800,$00032800,$00031800, $00033000,$00035800,$00030800,$00036000,$00033800,$00037800,$00032800,$00031800,
$0006A000,$0006D000,$0006C800,$00069000,$0006E800,$0006C000,$00068000,$0006F000, $0006A000,$0006D000,$0006C800,$00069000,$0006E800,$0006C000,$00068000,$0006F000,
$0006B000,$0006D800,$00068800,$0006E000,$0006B800,$0006F800,$0006A800,$00069800, $0006B000,$0006D800,$00068800,$0006E000,$0006B800,$0006F800,$0006A800,$00069800,
$0007A000,$0007D000,$0007C800,$00079000,$0007E800,$0007C000,$00078000,$0007F000, $0007A000,$0007D000,$0007C800,$00079000,$0007E800,$0007C000,$00078000,$0007F000,
$0007B000,$0007D800,$00078800,$0007E000,$0007B800,$0007F800,$0007A800,$00079800, $0007B000,$0007D800,$00078800,$0007E000,$0007B800,$0007F800,$0007A800,$00079800,
$00052000,$00055000,$00054800,$00051000,$00056800,$00054000,$00050000,$00057000, $00052000,$00055000,$00054800,$00051000,$00056800,$00054000,$00050000,$00057000,
$00053000,$00055800,$00050800,$00056000,$00053800,$00057800,$00052800,$00051800, $00053000,$00055800,$00050800,$00056000,$00053800,$00057800,$00052800,$00051800,
$00012000,$00015000,$00014800,$00011000,$00016800,$00014000,$00010000,$00017000, $00012000,$00015000,$00014800,$00011000,$00016800,$00014000,$00010000,$00017000,
$00013000,$00015800,$00010800,$00016000,$00013800,$00017800,$00012800,$00011800, $00013000,$00015800,$00010800,$00016000,$00013800,$00017800,$00012800,$00011800,
$0001A000,$0001D000,$0001C800,$00019000,$0001E800,$0001C000,$00018000,$0001F000, $0001A000,$0001D000,$0001C800,$00019000,$0001E800,$0001C000,$00018000,$0001F000,
$0001B000,$0001D800,$00018800,$0001E000,$0001B800,$0001F800,$0001A800,$00019800, $0001B000,$0001D800,$00018800,$0001E000,$0001B800,$0001F800,$0001A800,$00019800,
$00042000,$00045000,$00044800,$00041000,$00046800,$00044000,$00040000,$00047000, $00042000,$00045000,$00044800,$00041000,$00046800,$00044000,$00040000,$00047000,
$00043000,$00045800,$00040800,$00046000,$00043800,$00047800,$00042800,$00041800, $00043000,$00045800,$00040800,$00046000,$00043800,$00047800,$00042800,$00041800,
$0000A000,$0000D000,$0000C800,$00009000,$0000E800,$0000C000,$00008000,$0000F000, $0000A000,$0000D000,$0000C800,$00009000,$0000E800,$0000C000,$00008000,$0000F000,
$0000B000,$0000D800,$00008800,$0000E000,$0000B800,$0000F800,$0000A800,$00009800, $0000B000,$0000D800,$00008800,$0000E000,$0000B800,$0000F800,$0000A800,$00009800,
$00002000,$00005000,$00004800,$00001000,$00006800,$00004000,$00000000,$00007000, $00002000,$00005000,$00004800,$00001000,$00006800,$00004000,$00000000,$00007000,
$00003000,$00005800,$00000800,$00006000,$00003800,$00007800,$00002800,$00001800, $00003000,$00005800,$00000800,$00006000,$00003800,$00007800,$00002800,$00001800,
$0003A000,$0003D000,$0003C800,$00039000,$0003E800,$0003C000,$00038000,$0003F000, $0003A000,$0003D000,$0003C800,$00039000,$0003E800,$0003C000,$00038000,$0003F000,
$0003B000,$0003D800,$00038800,$0003E000,$0003B800,$0003F800,$0003A800,$00039800, $0003B000,$0003D800,$00038800,$0003E000,$0003B800,$0003F800,$0003A800,$00039800,
$0002A000,$0002D000,$0002C800,$00029000,$0002E800,$0002C000,$00028000,$0002F000, $0002A000,$0002D000,$0002C800,$00029000,$0002E800,$0002C000,$00028000,$0002F000,
$0002B000,$0002D800,$00028800,$0002E000,$0002B800,$0002F800,$0002A800,$00029800, $0002B000,$0002D800,$00028800,$0002E000,$0002B800,$0002F800,$0002A800,$00029800,
$0004A000,$0004D000,$0004C800,$00049000,$0004E800,$0004C000,$00048000,$0004F000, $0004A000,$0004D000,$0004C800,$00049000,$0004E800,$0004C000,$00048000,$0004F000,
$0004B000,$0004D800,$00048800,$0004E000,$0004B800,$0004F800,$0004A800,$00049800), $0004B000,$0004D800,$00048800,$0004E000,$0004B800,$0004F800,$0004A800,$00049800),
($03A80000,$03C00000,$03880000,$03E80000,$03D00000,$03980000,$03A00000,$03900000, ($03A80000,$03C00000,$03880000,$03E80000,$03D00000,$03980000,$03A00000,$03900000,
$03F00000,$03F80000,$03E00000,$03B80000,$03B00000,$03800000,$03C80000,$03D80000, $03F00000,$03F80000,$03E00000,$03B80000,$03B00000,$03800000,$03C80000,$03D80000,
$06A80000,$06C00000,$06880000,$06E80000,$06D00000,$06980000,$06A00000,$06900000, $06A80000,$06C00000,$06880000,$06E80000,$06D00000,$06980000,$06A00000,$06900000,
$06F00000,$06F80000,$06E00000,$06B80000,$06B00000,$06800000,$06C80000,$06D80000, $06F00000,$06F80000,$06E00000,$06B80000,$06B00000,$06800000,$06C80000,$06D80000,
$05280000,$05400000,$05080000,$05680000,$05500000,$05180000,$05200000,$05100000, $05280000,$05400000,$05080000,$05680000,$05500000,$05180000,$05200000,$05100000,
$05700000,$05780000,$05600000,$05380000,$05300000,$05000000,$05480000,$05580000, $05700000,$05780000,$05600000,$05380000,$05300000,$05000000,$05480000,$05580000,
$00A80000,$00C00000,$00880000,$00E80000,$00D00000,$00980000,$00A00000,$00900000, $00A80000,$00C00000,$00880000,$00E80000,$00D00000,$00980000,$00A00000,$00900000,
$00F00000,$00F80000,$00E00000,$00B80000,$00B00000,$00800000,$00C80000,$00D80000, $00F00000,$00F80000,$00E00000,$00B80000,$00B00000,$00800000,$00C80000,$00D80000,
$00280000,$00400000,$00080000,$00680000,$00500000,$00180000,$00200000,$00100000, $00280000,$00400000,$00080000,$00680000,$00500000,$00180000,$00200000,$00100000,
$00700000,$00780000,$00600000,$00380000,$00300000,$00000000,$00480000,$00580000, $00700000,$00780000,$00600000,$00380000,$00300000,$00000000,$00480000,$00580000,
$04280000,$04400000,$04080000,$04680000,$04500000,$04180000,$04200000,$04100000, $04280000,$04400000,$04080000,$04680000,$04500000,$04180000,$04200000,$04100000,
$04700000,$04780000,$04600000,$04380000,$04300000,$04000000,$04480000,$04580000, $04700000,$04780000,$04600000,$04380000,$04300000,$04000000,$04480000,$04580000,
$04A80000,$04C00000,$04880000,$04E80000,$04D00000,$04980000,$04A00000,$04900000, $04A80000,$04C00000,$04880000,$04E80000,$04D00000,$04980000,$04A00000,$04900000,
$04F00000,$04F80000,$04E00000,$04B80000,$04B00000,$04800000,$04C80000,$04D80000, $04F00000,$04F80000,$04E00000,$04B80000,$04B00000,$04800000,$04C80000,$04D80000,
$07A80000,$07C00000,$07880000,$07E80000,$07D00000,$07980000,$07A00000,$07900000, $07A80000,$07C00000,$07880000,$07E80000,$07D00000,$07980000,$07A00000,$07900000,
$07F00000,$07F80000,$07E00000,$07B80000,$07B00000,$07800000,$07C80000,$07D80000, $07F00000,$07F80000,$07E00000,$07B80000,$07B00000,$07800000,$07C80000,$07D80000,
$07280000,$07400000,$07080000,$07680000,$07500000,$07180000,$07200000,$07100000, $07280000,$07400000,$07080000,$07680000,$07500000,$07180000,$07200000,$07100000,
$07700000,$07780000,$07600000,$07380000,$07300000,$07000000,$07480000,$07580000, $07700000,$07780000,$07600000,$07380000,$07300000,$07000000,$07480000,$07580000,
$02280000,$02400000,$02080000,$02680000,$02500000,$02180000,$02200000,$02100000, $02280000,$02400000,$02080000,$02680000,$02500000,$02180000,$02200000,$02100000,
$02700000,$02780000,$02600000,$02380000,$02300000,$02000000,$02480000,$02580000, $02700000,$02780000,$02600000,$02380000,$02300000,$02000000,$02480000,$02580000,
$03280000,$03400000,$03080000,$03680000,$03500000,$03180000,$03200000,$03100000, $03280000,$03400000,$03080000,$03680000,$03500000,$03180000,$03200000,$03100000,
$03700000,$03780000,$03600000,$03380000,$03300000,$03000000,$03480000,$03580000, $03700000,$03780000,$03600000,$03380000,$03300000,$03000000,$03480000,$03580000,
$06280000,$06400000,$06080000,$06680000,$06500000,$06180000,$06200000,$06100000, $06280000,$06400000,$06080000,$06680000,$06500000,$06180000,$06200000,$06100000,
$06700000,$06780000,$06600000,$06380000,$06300000,$06000000,$06480000,$06580000, $06700000,$06780000,$06600000,$06380000,$06300000,$06000000,$06480000,$06580000,
$05A80000,$05C00000,$05880000,$05E80000,$05D00000,$05980000,$05A00000,$05900000, $05A80000,$05C00000,$05880000,$05E80000,$05D00000,$05980000,$05A00000,$05900000,
$05F00000,$05F80000,$05E00000,$05B80000,$05B00000,$05800000,$05C80000,$05D80000, $05F00000,$05F80000,$05E00000,$05B80000,$05B00000,$05800000,$05C80000,$05D80000,
$01280000,$01400000,$01080000,$01680000,$01500000,$01180000,$01200000,$01100000, $01280000,$01400000,$01080000,$01680000,$01500000,$01180000,$01200000,$01100000,
$01700000,$01780000,$01600000,$01380000,$01300000,$01000000,$01480000,$01580000, $01700000,$01780000,$01600000,$01380000,$01300000,$01000000,$01480000,$01580000,
$02A80000,$02C00000,$02880000,$02E80000,$02D00000,$02980000,$02A00000,$02900000, $02A80000,$02C00000,$02880000,$02E80000,$02D00000,$02980000,$02A00000,$02900000,
$02F00000,$02F80000,$02E00000,$02B80000,$02B00000,$02800000,$02C80000,$02D80000, $02F00000,$02F80000,$02E00000,$02B80000,$02B00000,$02800000,$02C80000,$02D80000,
$01A80000,$01C00000,$01880000,$01E80000,$01D00000,$01980000,$01A00000,$01900000, $01A80000,$01C00000,$01880000,$01E80000,$01D00000,$01980000,$01A00000,$01900000,
$01F00000,$01F80000,$01E00000,$01B80000,$01B00000,$01800000,$01C80000,$01D80000), $01F00000,$01F80000,$01E00000,$01B80000,$01B00000,$01800000,$01C80000,$01D80000),
($30000002,$60000002,$38000002,$08000002,$28000002,$78000002,$68000002,$40000002, ($30000002,$60000002,$38000002,$08000002,$28000002,$78000002,$68000002,$40000002,
$20000002,$50000002,$48000002,$70000002,$00000002,$18000002,$58000002,$10000002, $20000002,$50000002,$48000002,$70000002,$00000002,$18000002,$58000002,$10000002,
$B0000005,$E0000005,$B8000005,$88000005,$A8000005,$F8000005,$E8000005,$C0000005, $B0000005,$E0000005,$B8000005,$88000005,$A8000005,$F8000005,$E8000005,$C0000005,
$A0000005,$D0000005,$C8000005,$F0000005,$80000005,$98000005,$D8000005,$90000005, $A0000005,$D0000005,$C8000005,$F0000005,$80000005,$98000005,$D8000005,$90000005,
$30000005,$60000005,$38000005,$08000005,$28000005,$78000005,$68000005,$40000005, $30000005,$60000005,$38000005,$08000005,$28000005,$78000005,$68000005,$40000005,
$20000005,$50000005,$48000005,$70000005,$00000005,$18000005,$58000005,$10000005, $20000005,$50000005,$48000005,$70000005,$00000005,$18000005,$58000005,$10000005,
$30000000,$60000000,$38000000,$08000000,$28000000,$78000000,$68000000,$40000000, $30000000,$60000000,$38000000,$08000000,$28000000,$78000000,$68000000,$40000000,
$20000000,$50000000,$48000000,$70000000,$00000000,$18000000,$58000000,$10000000, $20000000,$50000000,$48000000,$70000000,$00000000,$18000000,$58000000,$10000000,
$B0000003,$E0000003,$B8000003,$88000003,$A8000003,$F8000003,$E8000003,$C0000003, $B0000003,$E0000003,$B8000003,$88000003,$A8000003,$F8000003,$E8000003,$C0000003,
$A0000003,$D0000003,$C8000003,$F0000003,$80000003,$98000003,$D8000003,$90000003, $A0000003,$D0000003,$C8000003,$F0000003,$80000003,$98000003,$D8000003,$90000003,
$30000001,$60000001,$38000001,$08000001,$28000001,$78000001,$68000001,$40000001, $30000001,$60000001,$38000001,$08000001,$28000001,$78000001,$68000001,$40000001,
$20000001,$50000001,$48000001,$70000001,$00000001,$18000001,$58000001,$10000001, $20000001,$50000001,$48000001,$70000001,$00000001,$18000001,$58000001,$10000001,
$B0000000,$E0000000,$B8000000,$88000000,$A8000000,$F8000000,$E8000000,$C0000000, $B0000000,$E0000000,$B8000000,$88000000,$A8000000,$F8000000,$E8000000,$C0000000,
$A0000000,$D0000000,$C8000000,$F0000000,$80000000,$98000000,$D8000000,$90000000, $A0000000,$D0000000,$C8000000,$F0000000,$80000000,$98000000,$D8000000,$90000000,
$B0000006,$E0000006,$B8000006,$88000006,$A8000006,$F8000006,$E8000006,$C0000006, $B0000006,$E0000006,$B8000006,$88000006,$A8000006,$F8000006,$E8000006,$C0000006,
$A0000006,$D0000006,$C8000006,$F0000006,$80000006,$98000006,$D8000006,$90000006, $A0000006,$D0000006,$C8000006,$F0000006,$80000006,$98000006,$D8000006,$90000006,
$B0000001,$E0000001,$B8000001,$88000001,$A8000001,$F8000001,$E8000001,$C0000001, $B0000001,$E0000001,$B8000001,$88000001,$A8000001,$F8000001,$E8000001,$C0000001,
$A0000001,$D0000001,$C8000001,$F0000001,$80000001,$98000001,$D8000001,$90000001, $A0000001,$D0000001,$C8000001,$F0000001,$80000001,$98000001,$D8000001,$90000001,
$30000003,$60000003,$38000003,$08000003,$28000003,$78000003,$68000003,$40000003, $30000003,$60000003,$38000003,$08000003,$28000003,$78000003,$68000003,$40000003,
$20000003,$50000003,$48000003,$70000003,$00000003,$18000003,$58000003,$10000003, $20000003,$50000003,$48000003,$70000003,$00000003,$18000003,$58000003,$10000003,
$30000004,$60000004,$38000004,$08000004,$28000004,$78000004,$68000004,$40000004, $30000004,$60000004,$38000004,$08000004,$28000004,$78000004,$68000004,$40000004,
$20000004,$50000004,$48000004,$70000004,$00000004,$18000004,$58000004,$10000004, $20000004,$50000004,$48000004,$70000004,$00000004,$18000004,$58000004,$10000004,
$B0000002,$E0000002,$B8000002,$88000002,$A8000002,$F8000002,$E8000002,$C0000002, $B0000002,$E0000002,$B8000002,$88000002,$A8000002,$F8000002,$E8000002,$C0000002,
$A0000002,$D0000002,$C8000002,$F0000002,$80000002,$98000002,$D8000002,$90000002, $A0000002,$D0000002,$C8000002,$F0000002,$80000002,$98000002,$D8000002,$90000002,
$B0000004,$E0000004,$B8000004,$88000004,$A8000004,$F8000004,$E8000004,$C0000004, $B0000004,$E0000004,$B8000004,$88000004,$A8000004,$F8000004,$E8000004,$C0000004,
$A0000004,$D0000004,$C8000004,$F0000004,$80000004,$98000004,$D8000004,$90000004, $A0000004,$D0000004,$C8000004,$F0000004,$80000004,$98000004,$D8000004,$90000004,
$30000006,$60000006,$38000006,$08000006,$28000006,$78000006,$68000006,$40000006, $30000006,$60000006,$38000006,$08000006,$28000006,$78000006,$68000006,$40000006,
$20000006,$50000006,$48000006,$70000006,$00000006,$18000006,$58000006,$10000006, $20000006,$50000006,$48000006,$70000006,$00000006,$18000006,$58000006,$10000006,
$B0000007,$E0000007,$B8000007,$88000007,$A8000007,$F8000007,$E8000007,$C0000007, $B0000007,$E0000007,$B8000007,$88000007,$A8000007,$F8000007,$E8000007,$C0000007,
$A0000007,$D0000007,$C8000007,$F0000007,$80000007,$98000007,$D8000007,$90000007, $A0000007,$D0000007,$C8000007,$F0000007,$80000007,$98000007,$D8000007,$90000007,
$30000007,$60000007,$38000007,$08000007,$28000007,$78000007,$68000007,$40000007, $30000007,$60000007,$38000007,$08000007,$28000007,$78000007,$68000007,$40000007,
$20000007,$50000007,$48000007,$70000007,$00000007,$18000007,$58000007,$10000007), $20000007,$50000007,$48000007,$70000007,$00000007,$18000007,$58000007,$10000007),
($000000E8,$000000D8,$000000A0,$00000088,$00000098,$000000F8,$000000A8,$000000C8, ($000000E8,$000000D8,$000000A0,$00000088,$00000098,$000000F8,$000000A8,$000000C8,
$00000080,$000000D0,$000000F0,$000000B8,$000000B0,$000000C0,$00000090,$000000E0, $00000080,$000000D0,$000000F0,$000000B8,$000000B0,$000000C0,$00000090,$000000E0,
$000007E8,$000007D8,$000007A0,$00000788,$00000798,$000007F8,$000007A8,$000007C8, $000007E8,$000007D8,$000007A0,$00000788,$00000798,$000007F8,$000007A8,$000007C8,
$00000780,$000007D0,$000007F0,$000007B8,$000007B0,$000007C0,$00000790,$000007E0, $00000780,$000007D0,$000007F0,$000007B8,$000007B0,$000007C0,$00000790,$000007E0,
$000006E8,$000006D8,$000006A0,$00000688,$00000698,$000006F8,$000006A8,$000006C8, $000006E8,$000006D8,$000006A0,$00000688,$00000698,$000006F8,$000006A8,$000006C8,
$00000680,$000006D0,$000006F0,$000006B8,$000006B0,$000006C0,$00000690,$000006E0, $00000680,$000006D0,$000006F0,$000006B8,$000006B0,$000006C0,$00000690,$000006E0,
$00000068,$00000058,$00000020,$00000008,$00000018,$00000078,$00000028,$00000048, $00000068,$00000058,$00000020,$00000008,$00000018,$00000078,$00000028,$00000048,
$00000000,$00000050,$00000070,$00000038,$00000030,$00000040,$00000010,$00000060, $00000000,$00000050,$00000070,$00000038,$00000030,$00000040,$00000010,$00000060,
$000002E8,$000002D8,$000002A0,$00000288,$00000298,$000002F8,$000002A8,$000002C8, $000002E8,$000002D8,$000002A0,$00000288,$00000298,$000002F8,$000002A8,$000002C8,
$00000280,$000002D0,$000002F0,$000002B8,$000002B0,$000002C0,$00000290,$000002E0, $00000280,$000002D0,$000002F0,$000002B8,$000002B0,$000002C0,$00000290,$000002E0,
$000003E8,$000003D8,$000003A0,$00000388,$00000398,$000003F8,$000003A8,$000003C8, $000003E8,$000003D8,$000003A0,$00000388,$00000398,$000003F8,$000003A8,$000003C8,
$00000380,$000003D0,$000003F0,$000003B8,$000003B0,$000003C0,$00000390,$000003E0, $00000380,$000003D0,$000003F0,$000003B8,$000003B0,$000003C0,$00000390,$000003E0,
$00000568,$00000558,$00000520,$00000508,$00000518,$00000578,$00000528,$00000548, $00000568,$00000558,$00000520,$00000508,$00000518,$00000578,$00000528,$00000548,
$00000500,$00000550,$00000570,$00000538,$00000530,$00000540,$00000510,$00000560, $00000500,$00000550,$00000570,$00000538,$00000530,$00000540,$00000510,$00000560,
$00000268,$00000258,$00000220,$00000208,$00000218,$00000278,$00000228,$00000248, $00000268,$00000258,$00000220,$00000208,$00000218,$00000278,$00000228,$00000248,
$00000200,$00000250,$00000270,$00000238,$00000230,$00000240,$00000210,$00000260, $00000200,$00000250,$00000270,$00000238,$00000230,$00000240,$00000210,$00000260,
$000004E8,$000004D8,$000004A0,$00000488,$00000498,$000004F8,$000004A8,$000004C8, $000004E8,$000004D8,$000004A0,$00000488,$00000498,$000004F8,$000004A8,$000004C8,
$00000480,$000004D0,$000004F0,$000004B8,$000004B0,$000004C0,$00000490,$000004E0, $00000480,$000004D0,$000004F0,$000004B8,$000004B0,$000004C0,$00000490,$000004E0,
$00000168,$00000158,$00000120,$00000108,$00000118,$00000178,$00000128,$00000148, $00000168,$00000158,$00000120,$00000108,$00000118,$00000178,$00000128,$00000148,
$00000100,$00000150,$00000170,$00000138,$00000130,$00000140,$00000110,$00000160, $00000100,$00000150,$00000170,$00000138,$00000130,$00000140,$00000110,$00000160,
$000001E8,$000001D8,$000001A0,$00000188,$00000198,$000001F8,$000001A8,$000001C8, $000001E8,$000001D8,$000001A0,$00000188,$00000198,$000001F8,$000001A8,$000001C8,
$00000180,$000001D0,$000001F0,$000001B8,$000001B0,$000001C0,$00000190,$000001E0, $00000180,$000001D0,$000001F0,$000001B8,$000001B0,$000001C0,$00000190,$000001E0,
$00000768,$00000758,$00000720,$00000708,$00000718,$00000778,$00000728,$00000748, $00000768,$00000758,$00000720,$00000708,$00000718,$00000778,$00000728,$00000748,
$00000700,$00000750,$00000770,$00000738,$00000730,$00000740,$00000710,$00000760, $00000700,$00000750,$00000770,$00000738,$00000730,$00000740,$00000710,$00000760,
$00000368,$00000358,$00000320,$00000308,$00000318,$00000378,$00000328,$00000348, $00000368,$00000358,$00000320,$00000308,$00000318,$00000378,$00000328,$00000348,
$00000300,$00000350,$00000370,$00000338,$00000330,$00000340,$00000310,$00000360, $00000300,$00000350,$00000370,$00000338,$00000330,$00000340,$00000310,$00000360,
$000005E8,$000005D8,$000005A0,$00000588,$00000598,$000005F8,$000005A8,$000005C8, $000005E8,$000005D8,$000005A0,$00000588,$00000598,$000005F8,$000005A8,$000005C8,
$00000580,$000005D0,$000005F0,$000005B8,$000005B0,$000005C0,$00000590,$000005E0, $00000580,$000005D0,$000005F0,$000005B8,$000005B0,$000005C0,$00000590,$000005E0,
$00000468,$00000458,$00000420,$00000408,$00000418,$00000478,$00000428,$00000448, $00000468,$00000458,$00000420,$00000408,$00000418,$00000478,$00000428,$00000448,
$00000400,$00000450,$00000470,$00000438,$00000430,$00000440,$00000410,$00000460, $00000400,$00000450,$00000470,$00000438,$00000430,$00000440,$00000410,$00000460,
$00000668,$00000658,$00000620,$00000608,$00000618,$00000678,$00000628,$00000648, $00000668,$00000658,$00000620,$00000608,$00000618,$00000678,$00000628,$00000648,
$00000600,$00000650,$00000670,$00000638,$00000630,$00000640,$00000610,$00000660)); $00000600,$00000650,$00000670,$00000638,$00000630,$00000640,$00000610,$00000660));

View File

@ -1,134 +1,134 @@
const const
S_Box: array[0..511] of DWord= ( S_Box: array[0..511] of DWord= (
$09d0c479, $28c8ffe0, $84aa6c39, $9dad7287, $09d0c479, $28c8ffe0, $84aa6c39, $9dad7287,
$7dff9be3, $d4268361, $c96da1d4, $7974cc93, $7dff9be3, $d4268361, $c96da1d4, $7974cc93,
$85d0582e, $2a4b5705, $1ca16a62, $c3bd279d, $85d0582e, $2a4b5705, $1ca16a62, $c3bd279d,
$0f1f25e5, $5160372f, $c695c1fb, $4d7ff1e4, $0f1f25e5, $5160372f, $c695c1fb, $4d7ff1e4,
$ae5f6bf4, $0d72ee46, $ff23de8a, $b1cf8e83, $ae5f6bf4, $0d72ee46, $ff23de8a, $b1cf8e83,
$f14902e2, $3e981e42, $8bf53eb6, $7f4bf8ac, $f14902e2, $3e981e42, $8bf53eb6, $7f4bf8ac,
$83631f83, $25970205, $76afe784, $3a7931d4, $83631f83, $25970205, $76afe784, $3a7931d4,
$4f846450, $5c64c3f6, $210a5f18, $c6986a26, $4f846450, $5c64c3f6, $210a5f18, $c6986a26,
$28f4e826, $3a60a81c, $d340a664, $7ea820c4, $28f4e826, $3a60a81c, $d340a664, $7ea820c4,
$526687c5, $7eddd12b, $32a11d1d, $9c9ef086, $526687c5, $7eddd12b, $32a11d1d, $9c9ef086,
$80f6e831, $ab6f04ad, $56fb9b53, $8b2e095c, $80f6e831, $ab6f04ad, $56fb9b53, $8b2e095c,
$b68556ae, $d2250b0d, $294a7721, $e21fb253, $b68556ae, $d2250b0d, $294a7721, $e21fb253,
$ae136749, $e82aae86, $93365104, $99404a66, $ae136749, $e82aae86, $93365104, $99404a66,
$78a784dc, $b69ba84b, $04046793, $23db5c1e, $78a784dc, $b69ba84b, $04046793, $23db5c1e,
$46cae1d6, $2fe28134, $5a223942, $1863cd5b, $46cae1d6, $2fe28134, $5a223942, $1863cd5b,
$c190c6e3, $07dfb846, $6eb88816, $2d0dcc4a, $c190c6e3, $07dfb846, $6eb88816, $2d0dcc4a,
$a4ccae59, $3798670d, $cbfa9493, $4f481d45, $a4ccae59, $3798670d, $cbfa9493, $4f481d45,
$eafc8ca8, $db1129d6, $b0449e20, $0f5407fb, $eafc8ca8, $db1129d6, $b0449e20, $0f5407fb,
$6167d9a8, $d1f45763, $4daa96c3, $3bec5958, $6167d9a8, $d1f45763, $4daa96c3, $3bec5958,
$ababa014, $b6ccd201, $38d6279f, $02682215, $ababa014, $b6ccd201, $38d6279f, $02682215,
$8f376cd5, $092c237e, $bfc56593, $32889d2c, $8f376cd5, $092c237e, $bfc56593, $32889d2c,
$854b3e95, $05bb9b43, $7dcd5dcd, $a02e926c, $854b3e95, $05bb9b43, $7dcd5dcd, $a02e926c,
$fae527e5, $36a1c330, $3412e1ae, $f257f462, $fae527e5, $36a1c330, $3412e1ae, $f257f462,
$3c4f1d71, $30a2e809, $68e5f551, $9c61ba44, $3c4f1d71, $30a2e809, $68e5f551, $9c61ba44,
$5ded0ab8, $75ce09c8, $9654f93e, $698c0cca, $5ded0ab8, $75ce09c8, $9654f93e, $698c0cca,
$243cb3e4, $2b062b97, $0f3b8d9e, $00e050df, $243cb3e4, $2b062b97, $0f3b8d9e, $00e050df,
$fc5d6166, $e35f9288, $c079550d, $0591aee8, $fc5d6166, $e35f9288, $c079550d, $0591aee8,
$8e531e74, $75fe3578, $2f6d829a, $f60b21ae, $8e531e74, $75fe3578, $2f6d829a, $f60b21ae,
$95e8eb8d, $6699486b, $901d7d9b, $fd6d6e31, $95e8eb8d, $6699486b, $901d7d9b, $fd6d6e31,
$1090acef, $e0670dd8, $dab2e692, $cd6d4365, $1090acef, $e0670dd8, $dab2e692, $cd6d4365,
$e5393514, $3af345f0, $6241fc4d, $460da3a3, $e5393514, $3af345f0, $6241fc4d, $460da3a3,
$7bcf3729, $8bf1d1e0, $14aac070, $1587ed55, $7bcf3729, $8bf1d1e0, $14aac070, $1587ed55,
$3afd7d3e, $d2f29e01, $29a9d1f6, $efb10c53, $3afd7d3e, $d2f29e01, $29a9d1f6, $efb10c53,
$cf3b870f, $b414935c, $664465ed, $024acac7, $cf3b870f, $b414935c, $664465ed, $024acac7,
$59a744c1, $1d2936a7, $dc580aa6, $cf574ca8, $59a744c1, $1d2936a7, $dc580aa6, $cf574ca8,
$040a7a10, $6cd81807, $8a98be4c, $accea063, $040a7a10, $6cd81807, $8a98be4c, $accea063,
$c33e92b5, $d1e0e03d, $b322517e, $2092bd13, $c33e92b5, $d1e0e03d, $b322517e, $2092bd13,
$386b2c4a, $52e8dd58, $58656dfb, $50820371, $386b2c4a, $52e8dd58, $58656dfb, $50820371,
$41811896, $e337ef7e, $d39fb119, $c97f0df6, $41811896, $e337ef7e, $d39fb119, $c97f0df6,
$68fea01b, $a150a6e5, $55258962, $eb6ff41b, $68fea01b, $a150a6e5, $55258962, $eb6ff41b,
$d7c9cd7a, $a619cd9e, $bcf09576, $2672c073, $d7c9cd7a, $a619cd9e, $bcf09576, $2672c073,
$f003fb3c, $4ab7a50b, $1484126a, $487ba9b1, $f003fb3c, $4ab7a50b, $1484126a, $487ba9b1,
$a64fc9c6, $f6957d49, $38b06a75, $dd805fcd, $a64fc9c6, $f6957d49, $38b06a75, $dd805fcd,
$63d094cf, $f51c999e, $1aa4d343, $b8495294, $63d094cf, $f51c999e, $1aa4d343, $b8495294,
$ce9f8e99, $bffcd770, $c7c275cc, $378453a7, $ce9f8e99, $bffcd770, $c7c275cc, $378453a7,
$7b21be33, $397f41bd, $4e94d131, $92cc1f98, $7b21be33, $397f41bd, $4e94d131, $92cc1f98,
$5915ea51, $99f861b7, $c9980a88, $1d74fd5f, $5915ea51, $99f861b7, $c9980a88, $1d74fd5f,
$b0a495f8, $614deed0, $b5778eea, $5941792d, $b0a495f8, $614deed0, $b5778eea, $5941792d,
$fa90c1f8, $33f824b4, $c4965372, $3ff6d550, $fa90c1f8, $33f824b4, $c4965372, $3ff6d550,
$4ca5fec0, $8630e964, $5b3fbbd6, $7da26a48, $4ca5fec0, $8630e964, $5b3fbbd6, $7da26a48,
$b203231a, $04297514, $2d639306, $2eb13149, $b203231a, $04297514, $2d639306, $2eb13149,
$16a45272, $532459a0, $8e5f4872, $f966c7d9, $16a45272, $532459a0, $8e5f4872, $f966c7d9,
$07128dc0, $0d44db62, $afc8d52d, $06316131, $07128dc0, $0d44db62, $afc8d52d, $06316131,
$d838e7ce, $1bc41d00, $3a2e8c0f, $ea83837e, $d838e7ce, $1bc41d00, $3a2e8c0f, $ea83837e,
$b984737d, $13ba4891, $c4f8b949, $a6d6acb3, $b984737d, $13ba4891, $c4f8b949, $a6d6acb3,
$a215cdce, $8359838b, $6bd1aa31, $f579dd52, $a215cdce, $8359838b, $6bd1aa31, $f579dd52,
$21b93f93, $f5176781, $187dfdde, $e94aeb76, $21b93f93, $f5176781, $187dfdde, $e94aeb76,
$2b38fd54, $431de1da, $ab394825, $9ad3048f, $2b38fd54, $431de1da, $ab394825, $9ad3048f,
$dfea32aa, $659473e3, $623f7863, $f3346c59, $dfea32aa, $659473e3, $623f7863, $f3346c59,
$ab3ab685, $3346a90b, $6b56443e, $c6de01f8, $ab3ab685, $3346a90b, $6b56443e, $c6de01f8,
$8d421fc0, $9b0ed10c, $88f1a1e9, $54c1f029, $8d421fc0, $9b0ed10c, $88f1a1e9, $54c1f029,
$7dead57b, $8d7ba426, $4cf5178a, $551a7cca, $7dead57b, $8d7ba426, $4cf5178a, $551a7cca,
$1a9a5f08, $fcd651b9, $25605182, $e11fc6c3, $1a9a5f08, $fcd651b9, $25605182, $e11fc6c3,
$b6fd9676, $337b3027, $b7c8eb14, $9e5fd030, $b6fd9676, $337b3027, $b7c8eb14, $9e5fd030,
$6b57e354, $ad913cf7, $7e16688d, $58872a69, $6b57e354, $ad913cf7, $7e16688d, $58872a69,
$2c2fc7df, $e389ccc6, $30738df1, $0824a734, $2c2fc7df, $e389ccc6, $30738df1, $0824a734,
$e1797a8b, $a4a8d57b, $5b5d193b, $c8a8309b, $e1797a8b, $a4a8d57b, $5b5d193b, $c8a8309b,
$73f9a978, $73398d32, $0f59573e, $e9df2b03, $73f9a978, $73398d32, $0f59573e, $e9df2b03,
$e8a5b6c8, $848d0704, $98df93c2, $720a1dc3, $e8a5b6c8, $848d0704, $98df93c2, $720a1dc3,
$684f259a, $943ba848, $a6370152, $863b5ea3, $684f259a, $943ba848, $a6370152, $863b5ea3,
$d17b978b, $6d9b58ef, $0a700dd4, $a73d36bf, $d17b978b, $6d9b58ef, $0a700dd4, $a73d36bf,
$8e6a0829, $8695bc14, $e35b3447, $933ac568, $8e6a0829, $8695bc14, $e35b3447, $933ac568,
$8894b022, $2f511c27, $ddfbcc3c, $006662b6, $8894b022, $2f511c27, $ddfbcc3c, $006662b6,
$117c83fe, $4e12b414, $c2bca766, $3a2fec10, $117c83fe, $4e12b414, $c2bca766, $3a2fec10,
$f4562420, $55792e2a, $46f5d857, $ceda25ce, $f4562420, $55792e2a, $46f5d857, $ceda25ce,
$c3601d3b, $6c00ab46, $efac9c28, $b3c35047, $c3601d3b, $6c00ab46, $efac9c28, $b3c35047,
$611dfee3, $257c3207, $fdd58482, $3b14d84f, $611dfee3, $257c3207, $fdd58482, $3b14d84f,
$23becb64, $a075f3a3, $088f8ead, $07adf158, $23becb64, $a075f3a3, $088f8ead, $07adf158,
$7796943c, $facabf3d, $c09730cd, $f7679969, $7796943c, $facabf3d, $c09730cd, $f7679969,
$da44e9ed, $2c854c12, $35935fa3, $2f057d9f, $da44e9ed, $2c854c12, $35935fa3, $2f057d9f,
$690624f8, $1cb0bafd, $7b0dbdc6, $810f23bb, $690624f8, $1cb0bafd, $7b0dbdc6, $810f23bb,
$fa929a1a, $6d969a17, $6742979b, $74ac7d05, $fa929a1a, $6d969a17, $6742979b, $74ac7d05,
$010e65c4, $86a3d963, $f907b5a0, $d0042bd3, $010e65c4, $86a3d963, $f907b5a0, $d0042bd3,
$158d7d03, $287a8255, $bba8366f, $096edc33, $158d7d03, $287a8255, $bba8366f, $096edc33,
$21916a7b, $77b56b86, $951622f9, $a6c5e650, $21916a7b, $77b56b86, $951622f9, $a6c5e650,
$8cea17d1, $cd8c62bc, $a3d63433, $358a68fd, $8cea17d1, $cd8c62bc, $a3d63433, $358a68fd,
$0f9b9d3c, $d6aa295b, $fe33384a, $c000738e, $0f9b9d3c, $d6aa295b, $fe33384a, $c000738e,
$cd67eb2f, $e2eb6dc2, $97338b02, $06c9f246, $cd67eb2f, $e2eb6dc2, $97338b02, $06c9f246,
$419cf1ad, $2b83c045, $3723f18a, $cb5b3089, $419cf1ad, $2b83c045, $3723f18a, $cb5b3089,
$160bead7, $5d494656, $35f8a74b, $1e4e6c9e, $160bead7, $5d494656, $35f8a74b, $1e4e6c9e,
$000399bd, $67466880, $b4174831, $acf423b2, $000399bd, $67466880, $b4174831, $acf423b2,
$ca815ab3, $5a6395e7, $302a67c5, $8bdb446b, $ca815ab3, $5a6395e7, $302a67c5, $8bdb446b,
$108f8fa4, $10223eda, $92b8b48b, $7f38d0ee, $108f8fa4, $10223eda, $92b8b48b, $7f38d0ee,
$ab2701d4, $0262d415, $af224a30, $b3d88aba, $ab2701d4, $0262d415, $af224a30, $b3d88aba,
$f8b2c3af, $daf7ef70, $cc97d3b7, $e9614b6c, $f8b2c3af, $daf7ef70, $cc97d3b7, $e9614b6c,
$2baebff4, $70f687cf, $386c9156, $ce092ee5, $2baebff4, $70f687cf, $386c9156, $ce092ee5,
$01e87da6, $6ce91e6a, $bb7bcc84, $c7922c20, $01e87da6, $6ce91e6a, $bb7bcc84, $c7922c20,
$9d3b71fd, $060e41c6, $d7590f15, $4e03bb47, $9d3b71fd, $060e41c6, $d7590f15, $4e03bb47,
$183c198e, $63eeb240, $2ddbf49a, $6d5cba54, $183c198e, $63eeb240, $2ddbf49a, $6d5cba54,
$923750af, $f9e14236, $7838162b, $59726c72, $923750af, $f9e14236, $7838162b, $59726c72,
$81b66760, $bb2926c1, $48a0ce0d, $a6c0496d, $81b66760, $bb2926c1, $48a0ce0d, $a6c0496d,
$ad43507b, $718d496a, $9df057af, $44b1bde6, $ad43507b, $718d496a, $9df057af, $44b1bde6,
$054356dc, $de7ced35, $d51a138b, $62088cc9, $054356dc, $de7ced35, $d51a138b, $62088cc9,
$35830311, $c96efca2, $686f86ec, $8e77cb68, $35830311, $c96efca2, $686f86ec, $8e77cb68,
$63e1d6b8, $c80f9778, $79c491fd, $1b4c67f2, $63e1d6b8, $c80f9778, $79c491fd, $1b4c67f2,
$72698d7d, $5e368c31, $f7d95e2e, $a1d3493f, $72698d7d, $5e368c31, $f7d95e2e, $a1d3493f,
$dcd9433e, $896f1552, $4bc4ca7a, $a6d1baf4, $dcd9433e, $896f1552, $4bc4ca7a, $a6d1baf4,
$a5a96dcc, $0bef8b46, $a169fda7, $74df40b7, $a5a96dcc, $0bef8b46, $a169fda7, $74df40b7,
$4e208804, $9a756607, $038e87c8, $20211e44, $4e208804, $9a756607, $038e87c8, $20211e44,
$8b7ad4bf, $c6403f35, $1848e36d, $80bdb038, $8b7ad4bf, $c6403f35, $1848e36d, $80bdb038,
$1e62891c, $643d2107, $bf04d6f8, $21092c8c, $1e62891c, $643d2107, $bf04d6f8, $21092c8c,
$f644f389, $0778404e, $7b78adb8, $a2c52d53, $f644f389, $0778404e, $7b78adb8, $a2c52d53,
$42157abe, $a2253e2e, $7bf3f4ae, $80f594f9, $42157abe, $a2253e2e, $7bf3f4ae, $80f594f9,
$953194e7, $77eb92ed, $b3816930, $da8d9336, $953194e7, $77eb92ed, $b3816930, $da8d9336,
$bf447469, $f26d9483, $ee6faed5, $71371235, $bf447469, $f26d9483, $ee6faed5, $71371235,
$de425f73, $b4e59f43, $7dbe2d4e, $2d37b185, $de425f73, $b4e59f43, $7dbe2d4e, $2d37b185,
$49dc9a63, $98c39d98, $1301c9a2, $389b1bbf, $49dc9a63, $98c39d98, $1301c9a2, $389b1bbf,
$0c18588d, $a421c1ba, $7aa3865c, $71e08558, $0c18588d, $a421c1ba, $7aa3865c, $71e08558,
$3c5cfcaa, $7d239ca4, $0297d9dd, $d7dc2830, $3c5cfcaa, $7d239ca4, $0297d9dd, $d7dc2830,
$4b37802b, $7428ab54, $aeee0347, $4b3fbb85, $4b37802b, $7428ab54, $aeee0347, $4b3fbb85,
$692f2f08, $134e578e, $36d9e0bf, $ae8b5fcf, $692f2f08, $134e578e, $36d9e0bf, $ae8b5fcf,
$edb93ecf, $2b27248e, $170eb1ef, $7dc57fd6, $edb93ecf, $2b27248e, $170eb1ef, $7dc57fd6,
$1e760f16, $b1136601, $864e1b9b, $d7ea7319, $1e760f16, $b1136601, $864e1b9b, $d7ea7319,
$3ab871bd, $cfa4d76f, $e31bd782, $0dbeb469, $3ab871bd, $cfa4d76f, $e31bd782, $0dbeb469,
$abb96061, $5370f85d, $ffb07e37, $da30d0fb, $abb96061, $5370f85d, $ffb07e37, $da30d0fb,
$ebc977b6, $0b98b40f, $3a4d0fe6, $df4fc26b, $ebc977b6, $0b98b40f, $3a4d0fe6, $df4fc26b,
$159cf22a, $c298d6e2, $2b78ef6a, $61a94ac0, $159cf22a, $c298d6e2, $2b78ef6a, $61a94ac0,
$ab561187, $14eea0f0, $df0d4164, $19af70ee); $ab561187, $14eea0f0, $df0d4164, $19af70ee);
vk: array[0..6] of DWord= ( vk: array[0..6] of DWord= (
$09d0c479, $28c8ffe0, $84aa6c39, $9dad7287, $7dff9be3, $d4268361, $09d0c479, $28c8ffe0, $84aa6c39, $9dad7287, $7dff9be3, $d4268361,
$c96da1d4); $c96da1d4);

View File

@ -1,43 +1,43 @@
const const
S7TABLE: array[0..$7F] of byte= ( S7TABLE: array[0..$7F] of byte= (
$1b, $32, $33, $5a, $3b, $10, $17, $54, $5b, $1a, $72, $73, $6b, $2c, $66, $49, $1b, $32, $33, $5a, $3b, $10, $17, $54, $5b, $1a, $72, $73, $6b, $2c, $66, $49,
$1f, $24, $13, $6c, $37, $2e, $3f, $4a, $5d, $0f, $40, $56, $25, $51, $1c, $04, $1f, $24, $13, $6c, $37, $2e, $3f, $4a, $5d, $0f, $40, $56, $25, $51, $1c, $04,
$0b, $46, $20, $0d, $7b, $35, $44, $42, $2b, $1e, $41, $14, $4b, $79, $15, $6f, $0b, $46, $20, $0d, $7b, $35, $44, $42, $2b, $1e, $41, $14, $4b, $79, $15, $6f,
$0e, $55, $09, $36, $74, $0c, $67, $53, $28, $0a, $7e, $38, $02, $07, $60, $29, $0e, $55, $09, $36, $74, $0c, $67, $53, $28, $0a, $7e, $38, $02, $07, $60, $29,
$19, $12, $65, $2f, $30, $39, $08, $68, $5f, $78, $2a, $4c, $64, $45, $75, $3d, $19, $12, $65, $2f, $30, $39, $08, $68, $5f, $78, $2a, $4c, $64, $45, $75, $3d,
$59, $48, $03, $57, $7c, $4f, $62, $3c, $1d, $21, $5e, $27, $6a, $70, $4d, $3a, $59, $48, $03, $57, $7c, $4f, $62, $3c, $1d, $21, $5e, $27, $6a, $70, $4d, $3a,
$01, $6d, $6e, $63, $18, $77, $23, $05, $26, $76, $00, $31, $2d, $7a, $7f, $61, $01, $6d, $6e, $63, $18, $77, $23, $05, $26, $76, $00, $31, $2d, $7a, $7f, $61,
$50, $22, $11, $06, $47, $16, $52, $4e, $71, $3e, $69, $43, $34, $5c, $58, $7d); $50, $22, $11, $06, $47, $16, $52, $4e, $71, $3e, $69, $43, $34, $5c, $58, $7d);
S9TABLE: array[0..$1FF] of Dword= ( S9TABLE: array[0..$1FF] of Dword= (
$1c3, $0cb, $153, $19f, $1e3, $0e9, $0fb, $035, $181, $0b9, $117, $1eb, $133, $009, $02d, $0d3, $1c3, $0cb, $153, $19f, $1e3, $0e9, $0fb, $035, $181, $0b9, $117, $1eb, $133, $009, $02d, $0d3,
$0c7, $14a, $037, $07e, $0eb, $164, $193, $1d8, $0a3, $11e, $055, $02c, $01d, $1a2, $163, $118, $0c7, $14a, $037, $07e, $0eb, $164, $193, $1d8, $0a3, $11e, $055, $02c, $01d, $1a2, $163, $118,
$14b, $152, $1d2, $00f, $02b, $030, $13a, $0e5, $111, $138, $18e, $063, $0e3, $0c8, $1f4, $01b, $14b, $152, $1d2, $00f, $02b, $030, $13a, $0e5, $111, $138, $18e, $063, $0e3, $0c8, $1f4, $01b,
$001, $09d, $0f8, $1a0, $16d, $1f3, $01c, $146, $07d, $0d1, $082, $1ea, $183, $12d, $0f4, $19e, $001, $09d, $0f8, $1a0, $16d, $1f3, $01c, $146, $07d, $0d1, $082, $1ea, $183, $12d, $0f4, $19e,
$1d3, $0dd, $1e2, $128, $1e0, $0ec, $059, $091, $011, $12f, $026, $0dc, $0b0, $18c, $10f, $1f7, $1d3, $0dd, $1e2, $128, $1e0, $0ec, $059, $091, $011, $12f, $026, $0dc, $0b0, $18c, $10f, $1f7,
$0e7, $16c, $0b6, $0f9, $0d8, $151, $101, $14c, $103, $0b8, $154, $12b, $1ae, $017, $071, $00c, $0e7, $16c, $0b6, $0f9, $0d8, $151, $101, $14c, $103, $0b8, $154, $12b, $1ae, $017, $071, $00c,
$047, $058, $07f, $1a4, $134, $129, $084, $15d, $19d, $1b2, $1a3, $048, $07c, $051, $1ca, $023, $047, $058, $07f, $1a4, $134, $129, $084, $15d, $19d, $1b2, $1a3, $048, $07c, $051, $1ca, $023,
$13d, $1a7, $165, $03b, $042, $0da, $192, $0ce, $0c1, $06b, $09f, $1f1, $12c, $184, $0fa, $196, $13d, $1a7, $165, $03b, $042, $0da, $192, $0ce, $0c1, $06b, $09f, $1f1, $12c, $184, $0fa, $196,
$1e1, $169, $17d, $031, $180, $10a, $094, $1da, $186, $13e, $11c, $060, $175, $1cf, $067, $119, $1e1, $169, $17d, $031, $180, $10a, $094, $1da, $186, $13e, $11c, $060, $175, $1cf, $067, $119,
$065, $068, $099, $150, $008, $007, $17c, $0b7, $024, $019, $0de, $127, $0db, $0e4, $1a9, $052, $065, $068, $099, $150, $008, $007, $17c, $0b7, $024, $019, $0de, $127, $0db, $0e4, $1a9, $052,
$109, $090, $19c, $1c1, $028, $1b3, $135, $16a, $176, $0df, $1e5, $188, $0c5, $16e, $1de, $1b1, $109, $090, $19c, $1c1, $028, $1b3, $135, $16a, $176, $0df, $1e5, $188, $0c5, $16e, $1de, $1b1,
$0c3, $1df, $036, $0ee, $1ee, $0f0, $093, $049, $09a, $1b6, $069, $081, $125, $00b, $05e, $0b4, $0c3, $1df, $036, $0ee, $1ee, $0f0, $093, $049, $09a, $1b6, $069, $081, $125, $00b, $05e, $0b4,
$149, $1c7, $174, $03e, $13b, $1b7, $08e, $1c6, $0ae, $010, $095, $1ef, $04e, $0f2, $1fd, $085, $149, $1c7, $174, $03e, $13b, $1b7, $08e, $1c6, $0ae, $010, $095, $1ef, $04e, $0f2, $1fd, $085,
$0fd, $0f6, $0a0, $16f, $083, $08a, $156, $09b, $13c, $107, $167, $098, $1d0, $1e9, $003, $1fe, $0fd, $0f6, $0a0, $16f, $083, $08a, $156, $09b, $13c, $107, $167, $098, $1d0, $1e9, $003, $1fe,
$0bd, $122, $089, $0d2, $18f, $012, $033, $06a, $142, $0ed, $170, $11b, $0e2, $14f, $158, $131, $0bd, $122, $089, $0d2, $18f, $012, $033, $06a, $142, $0ed, $170, $11b, $0e2, $14f, $158, $131,
$147, $05d, $113, $1cd, $079, $161, $1a5, $179, $09e, $1b4, $0cc, $022, $132, $01a, $0e8, $004, $147, $05d, $113, $1cd, $079, $161, $1a5, $179, $09e, $1b4, $0cc, $022, $132, $01a, $0e8, $004,
$187, $1ed, $197, $039, $1bf, $1d7, $027, $18b, $0c6, $09c, $0d0, $14e, $06c, $034, $1f2, $06e, $187, $1ed, $197, $039, $1bf, $1d7, $027, $18b, $0c6, $09c, $0d0, $14e, $06c, $034, $1f2, $06e,
$0ca, $025, $0ba, $191, $0fe, $013, $106, $02f, $1ad, $172, $1db, $0c0, $10b, $1d6, $0f5, $1ec, $0ca, $025, $0ba, $191, $0fe, $013, $106, $02f, $1ad, $172, $1db, $0c0, $10b, $1d6, $0f5, $1ec,
$10d, $076, $114, $1ab, $075, $10c, $1e4, $159, $054, $11f, $04b, $0c4, $1be, $0f7, $029, $0a4, $10d, $076, $114, $1ab, $075, $10c, $1e4, $159, $054, $11f, $04b, $0c4, $1be, $0f7, $029, $0a4,
$00e, $1f0, $077, $04d, $17a, $086, $08b, $0b3, $171, $0bf, $10e, $104, $097, $15b, $160, $168, $00e, $1f0, $077, $04d, $17a, $086, $08b, $0b3, $171, $0bf, $10e, $104, $097, $15b, $160, $168,
$0d7, $0bb, $066, $1ce, $0fc, $092, $1c5, $06f, $016, $04a, $0a1, $139, $0af, $0f1, $190, $00a, $0d7, $0bb, $066, $1ce, $0fc, $092, $1c5, $06f, $016, $04a, $0a1, $139, $0af, $0f1, $190, $00a,
$1aa, $143, $17b, $056, $18d, $166, $0d4, $1fb, $14d, $194, $19a, $087, $1f8, $123, $0a7, $1b8, $1aa, $143, $17b, $056, $18d, $166, $0d4, $1fb, $14d, $194, $19a, $087, $1f8, $123, $0a7, $1b8,
$141, $03c, $1f9, $140, $02a, $155, $11a, $1a1, $198, $0d5, $126, $1af, $061, $12e, $157, $1dc, $141, $03c, $1f9, $140, $02a, $155, $11a, $1a1, $198, $0d5, $126, $1af, $061, $12e, $157, $1dc,
$072, $18a, $0aa, $096, $115, $0ef, $045, $07b, $08d, $145, $053, $05f, $178, $0b2, $02e, $020, $072, $18a, $0aa, $096, $115, $0ef, $045, $07b, $08d, $145, $053, $05f, $178, $0b2, $02e, $020,
$1d5, $03f, $1c9, $1e7, $1ac, $044, $038, $014, $0b1, $16b, $0ab, $0b5, $05a, $182, $1c8, $1d4, $1d5, $03f, $1c9, $1e7, $1ac, $044, $038, $014, $0b1, $16b, $0ab, $0b5, $05a, $182, $1c8, $1d4,
$018, $177, $064, $0cf, $06d, $100, $199, $130, $15a, $005, $120, $1bb, $1bd, $0e0, $04f, $0d6, $018, $177, $064, $0cf, $06d, $100, $199, $130, $15a, $005, $120, $1bb, $1bd, $0e0, $04f, $0d6,
$13f, $1c4, $12a, $015, $006, $0ff, $19b, $0a6, $043, $088, $050, $15f, $1e8, $121, $073, $17e, $13f, $1c4, $12a, $015, $006, $0ff, $19b, $0a6, $043, $088, $050, $15f, $1e8, $121, $073, $17e,
$0bc, $0c2, $0c9, $173, $189, $1f5, $074, $1cc, $1e6, $1a8, $195, $01f, $041, $00d, $1ba, $032, $0bc, $0c2, $0c9, $173, $189, $1f5, $074, $1cc, $1e6, $1a8, $195, $01f, $041, $00d, $1ba, $032,
$03d, $1d1, $080, $0a8, $057, $1b9, $162, $148, $0d9, $105, $062, $07a, $021, $1ff, $112, $108, $03d, $1d1, $080, $0a8, $057, $1b9, $162, $148, $0d9, $105, $062, $07a, $021, $1ff, $112, $108,
$1c0, $0a9, $11d, $1b0, $1a6, $0cd, $0f3, $05c, $102, $05b, $1d9, $144, $1f6, $0ad, $0a5, $03a, $1c0, $0a9, $11d, $1b0, $1a6, $0cd, $0f3, $05c, $102, $05b, $1d9, $144, $1f6, $0ad, $0a5, $03a,
$1cb, $136, $17f, $046, $0e1, $01e, $1dd, $0e6, $137, $1fa, $185, $08c, $08f, $040, $1b5, $0be, $1cb, $136, $17f, $046, $0e1, $01e, $1dd, $0e6, $137, $1fa, $185, $08c, $08f, $040, $1b5, $0be,
$078, $000, $0ac, $110, $15e, $124, $002, $1bc, $0a2, $0ea, $070, $1fc, $116, $15c, $04c, $1c2); $078, $000, $0ac, $110, $15e, $124, $002, $1bc, $0a2, $0ea, $070, $1fc, $116, $15c, $04c, $1c2);

View File

@ -1,18 +1,18 @@
const const
sBox: array[0..255] of byte= ( sBox: array[0..255] of byte= (
$D9,$78,$F9,$C4,$19,$DD,$B5,$ED,$28,$E9,$FD,$79,$4A,$A0,$D8,$9D, $D9,$78,$F9,$C4,$19,$DD,$B5,$ED,$28,$E9,$FD,$79,$4A,$A0,$D8,$9D,
$C6,$7E,$37,$83,$2B,$76,$53,$8E,$62,$4C,$64,$88,$44,$8B,$FB,$A2, $C6,$7E,$37,$83,$2B,$76,$53,$8E,$62,$4C,$64,$88,$44,$8B,$FB,$A2,
$17,$9A,$59,$F5,$87,$B3,$4F,$13,$61,$45,$6D,$8D,$09,$81,$7D,$32, $17,$9A,$59,$F5,$87,$B3,$4F,$13,$61,$45,$6D,$8D,$09,$81,$7D,$32,
$BD,$8F,$40,$EB,$86,$B7,$7B,$0B,$F0,$95,$21,$22,$5C,$6B,$4E,$82, $BD,$8F,$40,$EB,$86,$B7,$7B,$0B,$F0,$95,$21,$22,$5C,$6B,$4E,$82,
$54,$D6,$65,$93,$CE,$60,$B2,$1C,$73,$56,$C0,$14,$A7,$8C,$F1,$DC, $54,$D6,$65,$93,$CE,$60,$B2,$1C,$73,$56,$C0,$14,$A7,$8C,$F1,$DC,
$12,$75,$CA,$1F,$3B,$BE,$E4,$D1,$42,$3D,$D4,$30,$A3,$3C,$B6,$26, $12,$75,$CA,$1F,$3B,$BE,$E4,$D1,$42,$3D,$D4,$30,$A3,$3C,$B6,$26,
$6F,$BF,$0E,$DA,$46,$69,$07,$57,$27,$F2,$1D,$9B,$BC,$94,$43,$03, $6F,$BF,$0E,$DA,$46,$69,$07,$57,$27,$F2,$1D,$9B,$BC,$94,$43,$03,
$F8,$11,$C7,$F6,$90,$EF,$3E,$E7,$06,$C3,$D5,$2F,$C8,$66,$1E,$D7, $F8,$11,$C7,$F6,$90,$EF,$3E,$E7,$06,$C3,$D5,$2F,$C8,$66,$1E,$D7,
$08,$E8,$EA,$DE,$80,$52,$EE,$F7,$84,$AA,$72,$AC,$35,$4D,$6A,$2A, $08,$E8,$EA,$DE,$80,$52,$EE,$F7,$84,$AA,$72,$AC,$35,$4D,$6A,$2A,
$96,$1A,$D2,$71,$5A,$15,$49,$74,$4B,$9F,$D0,$5E,$04,$18,$A4,$EC, $96,$1A,$D2,$71,$5A,$15,$49,$74,$4B,$9F,$D0,$5E,$04,$18,$A4,$EC,
$C2,$E0,$41,$6E,$0F,$51,$CB,$CC,$24,$91,$AF,$50,$A1,$F4,$70,$39, $C2,$E0,$41,$6E,$0F,$51,$CB,$CC,$24,$91,$AF,$50,$A1,$F4,$70,$39,
$99,$7C,$3A,$85,$23,$B8,$B4,$7A,$FC,$02,$36,$5B,$25,$55,$97,$31, $99,$7C,$3A,$85,$23,$B8,$B4,$7A,$FC,$02,$36,$5B,$25,$55,$97,$31,
$2D,$5D,$FA,$98,$E3,$8A,$92,$AE,$05,$DF,$29,$10,$67,$6C,$BA,$C9, $2D,$5D,$FA,$98,$E3,$8A,$92,$AE,$05,$DF,$29,$10,$67,$6C,$BA,$C9,
$D3,$00,$E6,$CF,$E1,$9E,$A8,$2C,$63,$16,$01,$3F,$58,$E2,$89,$A9, $D3,$00,$E6,$CF,$E1,$9E,$A8,$2C,$63,$16,$01,$3F,$58,$E2,$89,$A9,
$0D,$38,$34,$1B,$AB,$33,$FF,$B0,$BB,$48,$0C,$5F,$B9,$B1,$CD,$2E, $0D,$38,$34,$1B,$AB,$33,$FF,$B0,$BB,$48,$0C,$5F,$B9,$B1,$CD,$2E,
$C5,$F3,$DB,$47,$E5,$A5,$9C,$77,$0A,$A6,$20,$68,$FE,$7F,$C1,$AD); $C5,$F3,$DB,$47,$E5,$A5,$9C,$77,$0A,$A6,$20,$68,$FE,$7F,$C1,$AD);

File diff suppressed because it is too large Load Diff

View File

@ -1,66 +1,66 @@
const const
p8x8: array[0..1,0..255] of byte= (( p8x8: array[0..1,0..255] of byte= ((
$a9, $67, $b3, $e8, $04, $fd, $a3, $76, $a9, $67, $b3, $e8, $04, $fd, $a3, $76,
$9a, $92, $80, $78, $e4, $dd, $d1, $38, $9a, $92, $80, $78, $e4, $dd, $d1, $38,
$0d, $c6, $35, $98, $18, $f7, $ec, $6c, $0d, $c6, $35, $98, $18, $f7, $ec, $6c,
$43, $75, $37, $26, $fa, $13, $94, $48, $43, $75, $37, $26, $fa, $13, $94, $48,
$f2, $d0, $8b, $30, $84, $54, $df, $23, $f2, $d0, $8b, $30, $84, $54, $df, $23,
$19, $5b, $3d, $59, $f3, $ae, $a2, $82, $19, $5b, $3d, $59, $f3, $ae, $a2, $82,
$63, $01, $83, $2e, $d9, $51, $9b, $7c, $63, $01, $83, $2e, $d9, $51, $9b, $7c,
$a6, $eb, $a5, $be, $16, $0c, $e3, $61, $a6, $eb, $a5, $be, $16, $0c, $e3, $61,
$c0, $8c, $3a, $f5, $73, $2c, $25, $0b, $c0, $8c, $3a, $f5, $73, $2c, $25, $0b,
$bb, $4e, $89, $6b, $53, $6a, $b4, $f1, $bb, $4e, $89, $6b, $53, $6a, $b4, $f1,
$e1, $e6, $bd, $45, $e2, $f4, $b6, $66, $e1, $e6, $bd, $45, $e2, $f4, $b6, $66,
$cc, $95, $03, $56, $d4, $1c, $1e, $d7, $cc, $95, $03, $56, $d4, $1c, $1e, $d7,
$fb, $c3, $8e, $b5, $e9, $cf, $bf, $ba, $fb, $c3, $8e, $b5, $e9, $cf, $bf, $ba,
$ea, $77, $39, $af, $33, $c9, $62, $71, $ea, $77, $39, $af, $33, $c9, $62, $71,
$81, $79, $09, $ad, $24, $cd, $f9, $d8, $81, $79, $09, $ad, $24, $cd, $f9, $d8,
$e5, $c5, $b9, $4d, $44, $08, $86, $e7, $e5, $c5, $b9, $4d, $44, $08, $86, $e7,
$a1, $1d, $aa, $ed, $06, $70, $b2, $d2, $a1, $1d, $aa, $ed, $06, $70, $b2, $d2,
$41, $7b, $a0, $11, $31, $c2, $27, $90, $41, $7b, $a0, $11, $31, $c2, $27, $90,
$20, $f6, $60, $ff, $96, $5c, $b1, $ab, $20, $f6, $60, $ff, $96, $5c, $b1, $ab,
$9e, $9c, $52, $1b, $5f, $93, $0a, $ef, $9e, $9c, $52, $1b, $5f, $93, $0a, $ef,
$91, $85, $49, $ee, $2d, $4f, $8f, $3b, $91, $85, $49, $ee, $2d, $4f, $8f, $3b,
$47, $87, $6d, $46, $d6, $3e, $69, $64, $47, $87, $6d, $46, $d6, $3e, $69, $64,
$2a, $ce, $cb, $2f, $fc, $97, $05, $7a, $2a, $ce, $cb, $2f, $fc, $97, $05, $7a,
$ac, $7f, $d5, $1a, $4b, $0e, $a7, $5a, $ac, $7f, $d5, $1a, $4b, $0e, $a7, $5a,
$28, $14, $3f, $29, $88, $3c, $4c, $02, $28, $14, $3f, $29, $88, $3c, $4c, $02,
$b8, $da, $b0, $17, $55, $1f, $8a, $7d, $b8, $da, $b0, $17, $55, $1f, $8a, $7d,
$57, $c7, $8d, $74, $b7, $c4, $9f, $72, $57, $c7, $8d, $74, $b7, $c4, $9f, $72,
$7e, $15, $22, $12, $58, $07, $99, $34, $7e, $15, $22, $12, $58, $07, $99, $34,
$6e, $50, $de, $68, $65, $bc, $db, $f8, $6e, $50, $de, $68, $65, $bc, $db, $f8,
$c8, $a8, $2b, $40, $dc, $fe, $32, $a4, $c8, $a8, $2b, $40, $dc, $fe, $32, $a4,
$ca, $10, $21, $f0, $d3, $5d, $0f, $00, $ca, $10, $21, $f0, $d3, $5d, $0f, $00,
$6f, $9d, $36, $42, $4a, $5e, $c1, $e0),( $6f, $9d, $36, $42, $4a, $5e, $c1, $e0),(
$75, $f3, $c6, $f4, $db, $7b, $fb, $c8, $75, $f3, $c6, $f4, $db, $7b, $fb, $c8,
$4a, $d3, $e6, $6b, $45, $7d, $e8, $4b, $4a, $d3, $e6, $6b, $45, $7d, $e8, $4b,
$d6, $32, $d8, $fd, $37, $71, $f1, $e1, $d6, $32, $d8, $fd, $37, $71, $f1, $e1,
$30, $0f, $f8, $1b, $87, $fa, $06, $3f, $30, $0f, $f8, $1b, $87, $fa, $06, $3f,
$5e, $ba, $ae, $5b, $8a, $00, $bc, $9d, $5e, $ba, $ae, $5b, $8a, $00, $bc, $9d,
$6d, $c1, $b1, $0e, $80, $5d, $d2, $d5, $6d, $c1, $b1, $0e, $80, $5d, $d2, $d5,
$a0, $84, $07, $14, $b5, $90, $2c, $a3, $a0, $84, $07, $14, $b5, $90, $2c, $a3,
$b2, $73, $4c, $54, $92, $74, $36, $51, $b2, $73, $4c, $54, $92, $74, $36, $51,
$38, $b0, $bd, $5a, $fc, $60, $62, $96, $38, $b0, $bd, $5a, $fc, $60, $62, $96,
$6c, $42, $f7, $10, $7c, $28, $27, $8c, $6c, $42, $f7, $10, $7c, $28, $27, $8c,
$13, $95, $9c, $c7, $24, $46, $3b, $70, $13, $95, $9c, $c7, $24, $46, $3b, $70,
$ca, $e3, $85, $cb, $11, $d0, $93, $b8, $ca, $e3, $85, $cb, $11, $d0, $93, $b8,
$a6, $83, $20, $ff, $9f, $77, $c3, $cc, $a6, $83, $20, $ff, $9f, $77, $c3, $cc,
$03, $6f, $08, $bf, $40, $e7, $2b, $e2, $03, $6f, $08, $bf, $40, $e7, $2b, $e2,
$79, $0c, $aa, $82, $41, $3a, $ea, $b9, $79, $0c, $aa, $82, $41, $3a, $ea, $b9,
$e4, $9a, $a4, $97, $7e, $da, $7a, $17, $e4, $9a, $a4, $97, $7e, $da, $7a, $17,
$66, $94, $a1, $1d, $3d, $f0, $de, $b3, $66, $94, $a1, $1d, $3d, $f0, $de, $b3,
$0b, $72, $a7, $1c, $ef, $d1, $53, $3e, $0b, $72, $a7, $1c, $ef, $d1, $53, $3e,
$8f, $33, $26, $5f, $ec, $76, $2a, $49, $8f, $33, $26, $5f, $ec, $76, $2a, $49,
$81, $88, $ee, $21, $c4, $1a, $eb, $d9, $81, $88, $ee, $21, $c4, $1a, $eb, $d9,
$c5, $39, $99, $cd, $ad, $31, $8b, $01, $c5, $39, $99, $cd, $ad, $31, $8b, $01,
$18, $23, $dd, $1f, $4e, $2d, $f9, $48, $18, $23, $dd, $1f, $4e, $2d, $f9, $48,
$4f, $f2, $65, $8e, $78, $5c, $58, $19, $4f, $f2, $65, $8e, $78, $5c, $58, $19,
$8d, $e5, $98, $57, $67, $7f, $05, $64, $8d, $e5, $98, $57, $67, $7f, $05, $64,
$af, $63, $b6, $fe, $f5, $b7, $3c, $a5, $af, $63, $b6, $fe, $f5, $b7, $3c, $a5,
$ce, $e9, $68, $44, $e0, $4d, $43, $69, $ce, $e9, $68, $44, $e0, $4d, $43, $69,
$29, $2e, $ac, $15, $59, $a8, $0a, $9e, $29, $2e, $ac, $15, $59, $a8, $0a, $9e,
$6e, $47, $df, $34, $35, $6a, $cf, $dc, $6e, $47, $df, $34, $35, $6a, $cf, $dc,
$22, $c9, $c0, $9b, $89, $d4, $ed, $ab, $22, $c9, $c0, $9b, $89, $d4, $ed, $ab,
$12, $a2, $0d, $52, $bb, $02, $2f, $a9, $12, $a2, $0d, $52, $bb, $02, $2f, $a9,
$d7, $61, $1e, $b4, $50, $04, $f6, $c2, $d7, $61, $1e, $b4, $50, $04, $f6, $c2,
$16, $25, $86, $56, $55, $09, $be, $91)); $16, $25, $86, $56, $55, $09, $be, $91));

View File

@ -1,248 +1,248 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Blowfish *****************************} {* A binary compatible implementation of Blowfish *****************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPblowfish; unit DCPblowfish;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_blowfish= class(TDCP_blockcipher64) TDCP_blowfish= class(TDCP_blockcipher64)
protected protected
SBox: array[0..3,0..255] of DWord; SBox: array[0..3,0..255] of DWord;
PBox: array[0..17] of DWord; PBox: array[0..17] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPblowfish.inc} {$I DCPblowfish.inc}
class function TDCP_blowfish.GetID: integer; class function TDCP_blowfish.GetID: integer;
begin begin
Result:= DCP_blowfish; Result:= DCP_blowfish;
end; end;
class function TDCP_blowfish.GetAlgorithm: string; class function TDCP_blowfish.GetAlgorithm: string;
begin begin
Result:= 'Blowfish'; Result:= 'Blowfish';
end; end;
class function TDCP_blowfish.GetMaxKeySize: integer; class function TDCP_blowfish.GetMaxKeySize: integer;
begin begin
Result:= 448; Result:= 448;
end; end;
class function TDCP_blowfish.SelfTest: boolean; class function TDCP_blowfish.SelfTest: boolean;
const const
Key1: array[0..7] of byte= ($00,$00,$00,$00,$00,$00,$00,$00); Key1: array[0..7] of byte= ($00,$00,$00,$00,$00,$00,$00,$00);
Key2: array[0..7] of byte= ($7C,$A1,$10,$45,$4A,$1A,$6E,$57); Key2: array[0..7] of byte= ($7C,$A1,$10,$45,$4A,$1A,$6E,$57);
InData1: array[0..7] of byte= ($00,$00,$00,$00,$00,$00,$00,$00); InData1: array[0..7] of byte= ($00,$00,$00,$00,$00,$00,$00,$00);
InData2: array[0..7] of byte= ($01,$A1,$D6,$D0,$39,$77,$67,$42); InData2: array[0..7] of byte= ($01,$A1,$D6,$D0,$39,$77,$67,$42);
OutData1: array[0..7] of byte= ($4E,$F9,$97,$45,$61,$98,$DD,$78); OutData1: array[0..7] of byte= ($4E,$F9,$97,$45,$61,$98,$DD,$78);
OutData2: array[0..7] of byte= ($59,$C6,$82,$45,$EB,$05,$28,$2B); OutData2: array[0..7] of byte= ($59,$C6,$82,$45,$EB,$05,$28,$2B);
var var
Cipher: TDCP_blowfish; Cipher: TDCP_blowfish;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_blowfish.Create(nil); Cipher:= TDCP_blowfish.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.Reset; Cipher.Reset;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Data); Cipher.EncryptECB(InData2,Data);
Result:= boolean(CompareMem(@Data,@OutData2,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@OutData2,Sizeof(Data))) and Result;
Cipher.Reset; Cipher.Reset;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData2,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData2,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_blowfish.InitKey(const Key; Size: longword); procedure TDCP_blowfish.InitKey(const Key; Size: longword);
var var
i, k: longword; i, k: longword;
A: DWord; A: DWord;
KeyB: PByteArray; KeyB: PByteArray;
Block: array[0..7] of byte; Block: array[0..7] of byte;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Size:= Size div 8; Size:= Size div 8;
KeyB:= @Key; KeyB:= @Key;
Move(SBoxOrg,SBox,Sizeof(SBox)); Move(SBoxOrg,SBox,Sizeof(SBox));
Move(PBoxOrg,PBox,Sizeof(PBox)); Move(PBoxOrg,PBox,Sizeof(PBox));
k:= 0; k:= 0;
for i:= 0 to 17 do for i:= 0 to 17 do
begin begin
A:= dword(KeyB^[(k+3) mod Size]); A:= dword(KeyB^[(k+3) mod Size]);
A:= A + (dword(KeyB^[(k+2) mod Size]) shl 8); A:= A + (dword(KeyB^[(k+2) mod Size]) shl 8);
A:= A + (dword(KeyB^[(k+1) mod Size]) shl 16); A:= A + (dword(KeyB^[(k+1) mod Size]) shl 16);
A:= A + (dword(KeyB^[k]) shl 24); A:= A + (dword(KeyB^[k]) shl 24);
PBox[i]:= PBox[i] xor A; PBox[i]:= PBox[i] xor A;
k:= (k+4) mod Size; k:= (k+4) mod Size;
end; end;
FillChar(Block,Sizeof(Block),0); FillChar(Block,Sizeof(Block),0);
for i:= 0 to 8 do for i:= 0 to 8 do
begin begin
EncryptECB(Block,Block); EncryptECB(Block,Block);
PBox[i*2]:= dword(Block[3]) + (dword(Block[2]) shl 8) + (dword(Block[1]) shl 16) + (dword(Block[0]) shl 24); PBox[i*2]:= dword(Block[3]) + (dword(Block[2]) shl 8) + (dword(Block[1]) shl 16) + (dword(Block[0]) shl 24);
PBox[i*2+1]:= dword(Block[7]) + (dword(Block[6]) shl 8) + (dword(Block[5]) shl 16) + (dword(Block[4]) shl 24); PBox[i*2+1]:= dword(Block[7]) + (dword(Block[6]) shl 8) + (dword(Block[5]) shl 16) + (dword(Block[4]) shl 24);
end; end;
for k:= 0 to 3 do for k:= 0 to 3 do
begin begin
for i:= 0 to 127 do for i:= 0 to 127 do
begin begin
EncryptECB(Block,Block); EncryptECB(Block,Block);
SBox[k,i*2]:= dword(Block[3]) + (dword(Block[2]) shl 8) + (dword(Block[1]) shl 16) + (dword(Block[0]) shl 24); SBox[k,i*2]:= dword(Block[3]) + (dword(Block[2]) shl 8) + (dword(Block[1]) shl 16) + (dword(Block[0]) shl 24);
SBox[k,i*2+1]:= dword(Block[7]) + (dword(Block[6]) shl 8) + (dword(Block[5]) shl 16) + (dword(Block[4]) shl 24); SBox[k,i*2+1]:= dword(Block[7]) + (dword(Block[6]) shl 8) + (dword(Block[5]) shl 16) + (dword(Block[4]) shl 24);
end; end;
end; end;
end; end;
procedure TDCP_blowfish.Burn; procedure TDCP_blowfish.Burn;
begin begin
FillChar(SBox,Sizeof(SBox),$FF); FillChar(SBox,Sizeof(SBox),$FF);
FillChar(PBox,Sizeof(PBox),$FF); FillChar(PBox,Sizeof(PBox),$FF);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_blowfish.EncryptECB(const InData; var OutData); procedure TDCP_blowfish.EncryptECB(const InData; var OutData);
var var
xL, xR: DWord; xL, xR: DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
xL:= Pdword(@InData)^; xL:= Pdword(@InData)^;
xR:= Pdword(pointer(@InData)+4)^; xR:= Pdword(pointer(@InData)+4)^;
xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24); xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24);
xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24); xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24);
xL:= xL xor PBox[0]; xL:= xL xor PBox[0];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[1]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[1];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[2]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[2];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[3]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[3];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[4]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[4];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[5]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[5];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[6]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[6];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[7]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[7];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[8]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[8];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[9]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[9];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[10]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[10];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[11]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[11];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[12]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[12];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[13]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[13];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[14]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[14];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[15]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[15];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[16]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[16];
xR:= xR xor PBox[17]; xR:= xR xor PBox[17];
xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24); xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24);
xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24); xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24);
Pdword(@OutData)^:= xR; Pdword(@OutData)^:= xR;
Pdword(pointer(@OutData)+4)^:= xL; Pdword(pointer(@OutData)+4)^:= xL;
end; end;
procedure TDCP_blowfish.DecryptECB(const InData; var OutData); procedure TDCP_blowfish.DecryptECB(const InData; var OutData);
var var
xL, xR: DWord; xL, xR: DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
xL:= Pdword(@InData)^; xL:= Pdword(@InData)^;
xR:= Pdword(pointer(@InData)+4)^; xR:= Pdword(pointer(@InData)+4)^;
xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24); xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24);
xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24); xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24);
xL:= xL xor PBox[17]; xL:= xL xor PBox[17];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[16]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[16];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[15]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[15];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[14]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[14];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[13]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[13];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[12]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[12];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[11]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[11];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[10]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[10];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[9]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[9];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[8]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[8];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[7]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[7];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[6]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[6];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[5]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[5];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[4]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[4];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[3]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[3];
xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor xR:= xR xor (((SBox[0,(xL shr 24) and $FF] + SBox[1,(xL shr 16) and $FF]) xor
SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[2]; SBox[2,(xL shr 8) and $FF]) + SBox[3,xL and $FF]) xor PBox[2];
xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor xL:= xL xor (((SBox[0,(xR shr 24) and $FF] + SBox[1,(xR shr 16) and $FF]) xor
SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[1]; SBox[2,(xR shr 8) and $FF]) + SBox[3,xR and $FF]) xor PBox[1];
xR:= xR xor PBox[0]; xR:= xR xor PBox[0];
xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24); xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24);
xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24); xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24);
Pdword(@OutData)^:= xR; Pdword(@OutData)^:= xR;
Pdword(pointer(@OutData)+4)^:= xL; Pdword(pointer(@OutData)+4)^:= xL;
end; end;
end. end.

View File

@ -1,382 +1,382 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Cast128 ******************************} {* A binary compatible implementation of Cast128 ******************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPcast128; unit DCPcast128;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_cast128= class(TDCP_blockcipher64) TDCP_cast128= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..31] of DWord; KeyData: array[0..31] of DWord;
Rounds: longword; Rounds: longword;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPcast128.inc} {$I DCPcast128.inc}
function LRot32(a, n: dword): dword; function LRot32(a, n: dword): dword;
begin begin
Result:= (a shl n) or (a shr (32-n)); Result:= (a shl n) or (a shr (32-n));
end; end;
class function TDCP_cast128.GetMaxKeySize: integer; class function TDCP_cast128.GetMaxKeySize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_cast128.GetID: integer; class function TDCP_cast128.GetID: integer;
begin begin
Result:= DCP_cast128; Result:= DCP_cast128;
end; end;
class function TDCP_cast128.GetAlgorithm: string; class function TDCP_cast128.GetAlgorithm: string;
begin begin
Result:= 'Cast128'; Result:= 'Cast128';
end; end;
class function TDCP_cast128.SelfTest: boolean; class function TDCP_cast128.SelfTest: boolean;
const const
Key: array[0..15] of byte= Key: array[0..15] of byte=
($01,$23,$45,$67,$12,$34,$56,$78,$23,$45,$67,$89,$34,$56,$78,$9A); ($01,$23,$45,$67,$12,$34,$56,$78,$23,$45,$67,$89,$34,$56,$78,$9A);
InBlock: array[0..7] of byte= InBlock: array[0..7] of byte=
($01,$23,$45,$67,$89,$AB,$CD,$EF); ($01,$23,$45,$67,$89,$AB,$CD,$EF);
Out128: array[0..7] of byte= Out128: array[0..7] of byte=
($23,$8B,$4F,$E5,$84,$7E,$44,$B2); ($23,$8B,$4F,$E5,$84,$7E,$44,$B2);
Out80: array[0..7] of byte= Out80: array[0..7] of byte=
($EB,$6A,$71,$1A,$2C,$02,$27,$1B); ($EB,$6A,$71,$1A,$2C,$02,$27,$1B);
Out40: array[0..7] of byte= Out40: array[0..7] of byte=
($7A,$C8,$16,$D1,$6E,$9B,$30,$2E); ($7A,$C8,$16,$D1,$6E,$9B,$30,$2E);
var var
Block: array[0..7] of byte; Block: array[0..7] of byte;
Cipher: TDCP_cast128; Cipher: TDCP_cast128;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_cast128.Create(nil); Cipher:= TDCP_cast128.Create(nil);
Cipher.Init(Key,128,nil); Cipher.Init(Key,128,nil);
Cipher.EncryptECB(InBlock,Block); Cipher.EncryptECB(InBlock,Block);
Result:= boolean(CompareMem(@Block,@Out128,8)); Result:= boolean(CompareMem(@Block,@Out128,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock,8)); Result:= Result and boolean(CompareMem(@Block,@InBlock,8));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key,80,nil); Cipher.Init(Key,80,nil);
Cipher.EncryptECB(InBlock,Block); Cipher.EncryptECB(InBlock,Block);
Result:= Result and boolean(CompareMem(@Block,@Out80,8)); Result:= Result and boolean(CompareMem(@Block,@Out80,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock,8)); Result:= Result and boolean(CompareMem(@Block,@InBlock,8));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key,40,nil); Cipher.Init(Key,40,nil);
Cipher.EncryptECB(InBlock,Block); Cipher.EncryptECB(InBlock,Block);
Result:= Result and boolean(CompareMem(@Block,@Out40,8)); Result:= Result and boolean(CompareMem(@Block,@Out40,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock,8)); Result:= Result and boolean(CompareMem(@Block,@InBlock,8));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_cast128.InitKey(const Key; Size: longword); procedure TDCP_cast128.InitKey(const Key; Size: longword);
var var
x, t, z: array[0..3] of DWord; x, t, z: array[0..3] of DWord;
i: longword; i: longword;
begin begin
Size:= Size div 8; Size:= Size div 8;
if Size<= 10 then if Size<= 10 then
Rounds:= 12 Rounds:= 12
else else
Rounds:= 16; Rounds:= 16;
dcpFillChar(x, Sizeof(x), 0); dcpFillChar(x, Sizeof(x), 0);
Move(Key,x,Size); Move(Key,x,Size);
x[0]:= (x[0] shr 24) or ((x[0] shr 8) and $FF00) or ((x[0] shl 8) and $FF0000) or (x[0] shl 24); x[0]:= (x[0] shr 24) or ((x[0] shr 8) and $FF00) or ((x[0] shl 8) and $FF0000) or (x[0] shl 24);
x[1]:= (x[1] shr 24) or ((x[1] shr 8) and $FF00) or ((x[1] shl 8) and $FF0000) or (x[1] shl 24); x[1]:= (x[1] shr 24) or ((x[1] shr 8) and $FF00) or ((x[1] shl 8) and $FF0000) or (x[1] shl 24);
x[2]:= (x[2] shr 24) or ((x[2] shr 8) and $FF00) or ((x[2] shl 8) and $FF0000) or (x[2] shl 24); x[2]:= (x[2] shr 24) or ((x[2] shr 8) and $FF00) or ((x[2] shl 8) and $FF0000) or (x[2] shl 24);
x[3]:= (x[3] shr 24) or ((x[3] shr 8) and $FF00) or ((x[3] shl 8) and $FF0000) or (x[3] shl 24); x[3]:= (x[3] shr 24) or ((x[3] shr 8) and $FF00) or ((x[3] shl 8) and $FF0000) or (x[3] shl 24);
i:= 0; i:= 0;
while i< 32 do while i< 32 do
begin begin
case (i and 4) of case (i and 4) of
0: 0:
begin begin
z[0]:= x[0] xor cast_sbox5[(x[3] shr 16) and $FF] xor z[0]:= x[0] xor cast_sbox5[(x[3] shr 16) and $FF] xor
cast_sbox6[x[3] and $FF] xor cast_sbox7[x[3] shr 24] xor cast_sbox6[x[3] and $FF] xor cast_sbox7[x[3] shr 24] xor
cast_sbox8[(x[3] shr 8) and $FF] xor cast_sbox7[x[2] shr 24]; cast_sbox8[(x[3] shr 8) and $FF] xor cast_sbox7[x[2] shr 24];
t[0]:= z[0]; t[0]:= z[0];
z[1]:= x[2] xor cast_sbox5[z[0] shr 24] xor z[1]:= x[2] xor cast_sbox5[z[0] shr 24] xor
cast_sbox6[(z[0] shr 8) and $FF] xor cast_sbox7[(z[0] shr 16) and $FF] xor cast_sbox6[(z[0] shr 8) and $FF] xor cast_sbox7[(z[0] shr 16) and $FF] xor
cast_sbox8[z[0] and $FF] xor cast_sbox8[(x[2] shr 8) and $FF]; cast_sbox8[z[0] and $FF] xor cast_sbox8[(x[2] shr 8) and $FF];
t[1]:= z[1]; t[1]:= z[1];
z[2]:= x[3] xor cast_sbox5[z[1] and $FF] xor z[2]:= x[3] xor cast_sbox5[z[1] and $FF] xor
cast_sbox6[(z[1] shr 8) and $FF] xor cast_sbox7[(z[1] shr 16) and $FF] xor cast_sbox6[(z[1] shr 8) and $FF] xor cast_sbox7[(z[1] shr 16) and $FF] xor
cast_sbox8[z[1] shr 24] xor cast_sbox5[(x[2] shr 16) and $FF]; cast_sbox8[z[1] shr 24] xor cast_sbox5[(x[2] shr 16) and $FF];
t[2]:= z[2]; t[2]:= z[2];
z[3]:= x[1] xor cast_sbox5[(z[2] shr 8) and $FF] xor z[3]:= x[1] xor cast_sbox5[(z[2] shr 8) and $FF] xor
cast_sbox6[(z[2] shr 16) and $FF] xor cast_sbox7[z[2] and $FF] xor cast_sbox6[(z[2] shr 16) and $FF] xor cast_sbox7[z[2] and $FF] xor
cast_sbox8[z[2] shr 24] xor cast_sbox6[x[2] and $FF]; cast_sbox8[z[2] shr 24] xor cast_sbox6[x[2] and $FF];
t[3]:= z[3]; t[3]:= z[3];
end; end;
4: 4:
begin begin
x[0]:= z[2] xor cast_sbox5[(z[1] shr 16) and $FF] xor x[0]:= z[2] xor cast_sbox5[(z[1] shr 16) and $FF] xor
cast_sbox6[z[1] and $FF] xor cast_sbox7[z[1] shr 24] xor cast_sbox6[z[1] and $FF] xor cast_sbox7[z[1] shr 24] xor
cast_sbox8[(z[1] shr 8) and $FF] xor cast_sbox7[z[0] shr 24]; cast_sbox8[(z[1] shr 8) and $FF] xor cast_sbox7[z[0] shr 24];
t[0]:= x[0]; t[0]:= x[0];
x[1]:= z[0] xor cast_sbox5[x[0] shr 24] xor x[1]:= z[0] xor cast_sbox5[x[0] shr 24] xor
cast_sbox6[(x[0] shr 8) and $FF] xor cast_sbox7[(x[0] shr 16) and $FF] xor cast_sbox6[(x[0] shr 8) and $FF] xor cast_sbox7[(x[0] shr 16) and $FF] xor
cast_sbox8[x[0] and $FF] xor cast_sbox8[(z[0] shr 8) and $FF]; cast_sbox8[x[0] and $FF] xor cast_sbox8[(z[0] shr 8) and $FF];
t[1]:= x[1]; t[1]:= x[1];
x[2]:= z[1] xor cast_sbox5[x[1] and $FF] xor x[2]:= z[1] xor cast_sbox5[x[1] and $FF] xor
cast_sbox6[(x[1] shr 8) and $FF] xor cast_sbox7[(x[1] shr 16) and $FF] xor cast_sbox6[(x[1] shr 8) and $FF] xor cast_sbox7[(x[1] shr 16) and $FF] xor
cast_sbox8[x[1] shr 24] xor cast_sbox5[(z[0] shr 16) and $FF]; cast_sbox8[x[1] shr 24] xor cast_sbox5[(z[0] shr 16) and $FF];
t[2]:= x[2]; t[2]:= x[2];
x[3]:= z[3] xor cast_sbox5[(x[2] shr 8) and $FF] xor x[3]:= z[3] xor cast_sbox5[(x[2] shr 8) and $FF] xor
cast_sbox6[(x[2] shr 16) and $FF] xor cast_sbox7[x[2] and $FF] xor cast_sbox6[(x[2] shr 16) and $FF] xor cast_sbox7[x[2] and $FF] xor
cast_sbox8[x[2] shr 24] xor cast_sbox6[z[0] and $FF]; cast_sbox8[x[2] shr 24] xor cast_sbox6[z[0] and $FF];
t[3]:= x[3]; t[3]:= x[3];
end; end;
end; end;
case (i and 12) of case (i and 12) of
0,12: 0,12:
begin begin
KeyData[i+0]:= cast_sbox5[t[2] shr 24] xor cast_sbox6[(t[2] shr 16) and $FF] xor KeyData[i+0]:= cast_sbox5[t[2] shr 24] xor cast_sbox6[(t[2] shr 16) and $FF] xor
cast_sbox7[t[1] and $FF] xor cast_sbox8[(t[1] shr 8) and $FF]; cast_sbox7[t[1] and $FF] xor cast_sbox8[(t[1] shr 8) and $FF];
KeyData[i+1]:= cast_sbox5[(t[2] shr 8) and $FF] xor cast_sbox6[t[2] and $FF] xor KeyData[i+1]:= cast_sbox5[(t[2] shr 8) and $FF] xor cast_sbox6[t[2] and $FF] xor
cast_sbox7[(t[1] shr 16) and $FF] xor cast_sbox8[t[1] shr 24]; cast_sbox7[(t[1] shr 16) and $FF] xor cast_sbox8[t[1] shr 24];
KeyData[i+2]:= cast_sbox5[t[3] shr 24] xor cast_sbox6[(t[3] shr 16) and $FF] xor KeyData[i+2]:= cast_sbox5[t[3] shr 24] xor cast_sbox6[(t[3] shr 16) and $FF] xor
cast_sbox7[t[0] and $FF] xor cast_sbox8[(t[0] shr 8) and $FF]; cast_sbox7[t[0] and $FF] xor cast_sbox8[(t[0] shr 8) and $FF];
KeyData[i+3]:= cast_sbox5[(t[3] shr 8) and $FF] xor cast_sbox6[t[3] and $FF] xor KeyData[i+3]:= cast_sbox5[(t[3] shr 8) and $FF] xor cast_sbox6[t[3] and $FF] xor
cast_sbox7[(t[0] shr 16) and $FF] xor cast_sbox8[t[0] shr 24]; cast_sbox7[(t[0] shr 16) and $FF] xor cast_sbox8[t[0] shr 24];
end; end;
4,8: 4,8:
begin begin
KeyData[i+0]:= cast_sbox5[t[0] and $FF] xor cast_sbox6[(t[0] shr 8) and $FF] xor KeyData[i+0]:= cast_sbox5[t[0] and $FF] xor cast_sbox6[(t[0] shr 8) and $FF] xor
cast_sbox7[t[3] shr 24] xor cast_sbox8[(t[3] shr 16) and $FF]; cast_sbox7[t[3] shr 24] xor cast_sbox8[(t[3] shr 16) and $FF];
KeyData[i+1]:= cast_sbox5[(t[0] shr 16) and $FF] xor cast_sbox6[t[0] shr 24] xor KeyData[i+1]:= cast_sbox5[(t[0] shr 16) and $FF] xor cast_sbox6[t[0] shr 24] xor
cast_sbox7[(t[3] shr 8) and $FF] xor cast_sbox8[t[3] and $FF]; cast_sbox7[(t[3] shr 8) and $FF] xor cast_sbox8[t[3] and $FF];
KeyData[i+2]:= cast_sbox5[t[1] and $FF] xor cast_sbox6[(t[1] shr 8) and $FF] xor KeyData[i+2]:= cast_sbox5[t[1] and $FF] xor cast_sbox6[(t[1] shr 8) and $FF] xor
cast_sbox7[t[2] shr 24] xor cast_sbox8[(t[2] shr 16) and $FF]; cast_sbox7[t[2] shr 24] xor cast_sbox8[(t[2] shr 16) and $FF];
KeyData[i+3]:= cast_sbox5[(t[1] shr 16) and $FF] xor cast_sbox6[t[1] shr 24] xor KeyData[i+3]:= cast_sbox5[(t[1] shr 16) and $FF] xor cast_sbox6[t[1] shr 24] xor
cast_sbox7[(t[2] shr 8) and $FF] xor cast_sbox8[t[2] and $FF]; cast_sbox7[(t[2] shr 8) and $FF] xor cast_sbox8[t[2] and $FF];
end; end;
end; end;
case (i and 12) of case (i and 12) of
0: 0:
begin begin
KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[(z[0] shr 8) and $FF]; KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[(z[0] shr 8) and $FF];
KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[(z[1] shr 8) and $FF]; KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[(z[1] shr 8) and $FF];
KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[(z[2] shr 16) and $FF]; KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[(z[2] shr 16) and $FF];
KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[z[3] shr 24]; KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[z[3] shr 24];
end; end;
4: 4:
begin begin
KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[x[2] shr 24]; KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[x[2] shr 24];
KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[(x[3] shr 16) and $FF]; KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[(x[3] shr 16) and $FF];
KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[x[0] and $FF]; KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[x[0] and $FF];
KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[x[1] and $FF]; KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[x[1] and $FF];
end; end;
8: 8:
begin begin
KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[(z[2] shr 16) and $FF]; KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[(z[2] shr 16) and $FF];
KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[z[3] shr 24]; KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[z[3] shr 24];
KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[(z[0] shr 8) and $FF]; KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[(z[0] shr 8) and $FF];
KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[(z[1] shr 8) and $FF]; KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[(z[1] shr 8) and $FF];
end; end;
12: 12:
begin begin
KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[x[0] and $FF]; KeyData[i+0]:= KeyData[i+0] xor cast_sbox5[x[0] and $FF];
KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[x[1] and $FF]; KeyData[i+1]:= KeyData[i+1] xor cast_sbox6[x[1] and $FF];
KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[x[2] shr 24]; KeyData[i+2]:= KeyData[i+2] xor cast_sbox7[x[2] shr 24];
KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[(x[3] shr 16) and $FF]; KeyData[i+3]:= KeyData[i+3] xor cast_sbox8[(x[3] shr 16) and $FF];
end; end;
end; end;
if (i >= 16) then if (i >= 16) then
begin begin
KeyData[i+0]:= KeyData[i+0] and 31; KeyData[i+0]:= KeyData[i+0] and 31;
KeyData[i+1]:= KeyData[i+1] and 31; KeyData[i+1]:= KeyData[i+1] and 31;
KeyData[i+2]:= KeyData[i+2] and 31; KeyData[i+2]:= KeyData[i+2] and 31;
KeyData[i+3]:= KeyData[i+3] and 31; KeyData[i+3]:= KeyData[i+3] and 31;
end; end;
Inc(i,4); Inc(i,4);
end; end;
end; end;
procedure TDCP_cast128.Burn; procedure TDCP_cast128.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),$FF); FillChar(KeyData,Sizeof(KeyData),$FF);
Rounds:= 0; Rounds:= 0;
inherited Burn; inherited Burn;
end; end;
procedure TDCP_cast128.EncryptECB(const InData; var OutData); procedure TDCP_cast128.EncryptECB(const InData; var OutData);
var var
t, l, r: DWord; t, l, r: DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
l:= Pdword(@InData)^; l:= Pdword(@InData)^;
r:= Pdword(Pointer(@InData)+4)^; r:= Pdword(Pointer(@InData)+4)^;
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24); l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24); r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
t:= LRot32(KeyData[0]+r, KeyData[0+16]); t:= LRot32(KeyData[0]+r, KeyData[0+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[1] xor l, KeyData[1+16]); t:= LRot32(KeyData[1] xor l, KeyData[1+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[2]-r, KeyData[2+16]); t:= LRot32(KeyData[2]-r, KeyData[2+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[3]+l, KeyData[3+16]); t:= LRot32(KeyData[3]+l, KeyData[3+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[4] xor r, KeyData[4+16]); t:= LRot32(KeyData[4] xor r, KeyData[4+16]);
l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[5]-l, KeyData[5+16]); t:= LRot32(KeyData[5]-l, KeyData[5+16]);
r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[6]+r, KeyData[6+16]); t:= LRot32(KeyData[6]+r, KeyData[6+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[7] xor l, KeyData[7+16]); t:= LRot32(KeyData[7] xor l, KeyData[7+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[8]-r, KeyData[8+16]); t:= LRot32(KeyData[8]-r, KeyData[8+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[9]+l, KeyData[9+16]); t:= LRot32(KeyData[9]+l, KeyData[9+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[10] xor r, KeyData[10+16]); t:= LRot32(KeyData[10] xor r, KeyData[10+16]);
l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[11]-l, KeyData[11+16]); t:= LRot32(KeyData[11]-l, KeyData[11+16]);
r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
if Rounds> 12 then if Rounds> 12 then
begin begin
t:= LRot32(KeyData[12]+r, KeyData[12+16]); t:= LRot32(KeyData[12]+r, KeyData[12+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[13] xor l, KeyData[13+16]); t:= LRot32(KeyData[13] xor l, KeyData[13+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[14]-r, KeyData[14+16]); t:= LRot32(KeyData[14]-r, KeyData[14+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[15]+l, KeyData[15+16]); t:= LRot32(KeyData[15]+l, KeyData[15+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
end; end;
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24); l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24); r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
Pdword(@OutData)^:= r; Pdword(@OutData)^:= r;
Pdword(pointer(@OutData)+4)^:= l; Pdword(pointer(@OutData)+4)^:= l;
end; end;
procedure TDCP_cast128.DecryptECB(const InData; var OutData); procedure TDCP_cast128.DecryptECB(const InData; var OutData);
var var
t, l, r: DWord; t, l, r: DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
r:= Pdword(@InData)^; r:= Pdword(@InData)^;
l:= Pdword(pointer(@InData)+4)^; l:= Pdword(pointer(@InData)+4)^;
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24); l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24); r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
if Rounds> 12 then if Rounds> 12 then
begin begin
t:= LRot32(KeyData[15]+l, KeyData[15+16]); t:= LRot32(KeyData[15]+l, KeyData[15+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[14]-r, KeyData[14+16]); t:= LRot32(KeyData[14]-r, KeyData[14+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[13] xor l, KeyData[13+16]); t:= LRot32(KeyData[13] xor l, KeyData[13+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[12]+r, KeyData[12+16]); t:= LRot32(KeyData[12]+r, KeyData[12+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
end; end;
t:= LRot32(KeyData[11]-l, KeyData[11+16]); t:= LRot32(KeyData[11]-l, KeyData[11+16]);
r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[10] xor r, KeyData[10+16]); t:= LRot32(KeyData[10] xor r, KeyData[10+16]);
l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[9]+l, KeyData[9+16]); t:= LRot32(KeyData[9]+l, KeyData[9+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[8]-r, KeyData[8+16]); t:= LRot32(KeyData[8]-r, KeyData[8+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[7] xor l, KeyData[7+16]); t:= LRot32(KeyData[7] xor l, KeyData[7+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[6]+r, KeyData[6+16]); t:= LRot32(KeyData[6]+r, KeyData[6+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[5]-l, KeyData[5+16]); t:= LRot32(KeyData[5]-l, KeyData[5+16]);
r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor r:= r xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[4] xor r, KeyData[4+16]); t:= LRot32(KeyData[4] xor r, KeyData[4+16]);
l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + l:= l xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[3]+l, KeyData[3+16]); t:= LRot32(KeyData[3]+l, KeyData[3+16]);
r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - r:= r xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
t:= LRot32(KeyData[2]-r, KeyData[2+16]); t:= LRot32(KeyData[2]-r, KeyData[2+16]);
l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor l:= l xor (((cast_sbox1[t shr 24] + cast_sbox2[(t shr 16) and $FF]) xor
cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) - cast_sbox4[t and $FF]);
t:= LRot32(KeyData[1] xor l, KeyData[1+16]); t:= LRot32(KeyData[1] xor l, KeyData[1+16]);
r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) + r:= r xor (((cast_sbox1[t shr 24] - cast_sbox2[(t shr 16) and $FF]) +
cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) xor cast_sbox4[t and $FF]);
t:= LRot32(KeyData[0]+r, KeyData[0+16]); t:= LRot32(KeyData[0]+r, KeyData[0+16]);
l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) - l:= l xor (((cast_sbox1[t shr 24] xor cast_sbox2[(t shr 16) and $FF]) -
cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]); cast_sbox3[(t shr 8) and $FF]) + cast_sbox4[t and $FF]);
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24); l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24); r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
Pdword(@OutData)^:= l; Pdword(@OutData)^:= l;
Pdword(pointer(@OutData)+4)^:= r; Pdword(pointer(@OutData)+4)^:= r;
end; end;
end. end.

View File

@ -1,369 +1,369 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Cast256 ******************************} {* A binary compatible implementation of Cast256 ******************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPcast256; unit DCPcast256;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_cast256= class(TDCP_blockcipher128) TDCP_cast256= class(TDCP_blockcipher128)
protected protected
Kr, Km: array[0..11,0..3] of DWord; Kr, Km: array[0..11,0..3] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPcast256.inc} {$I DCPcast256.inc}
function LRot32(a, n: dword): dword; function LRot32(a, n: dword): dword;
begin begin
Result:= (a shl n) or (a shr (32-n)); Result:= (a shl n) or (a shr (32-n));
end; end;
function SwapDword(a: dword): dword; function SwapDword(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
function F1(a,rk,mk: DWord): DWord; function F1(a,rk,mk: DWord): DWord;
var var
t: DWord; t: DWord;
begin begin
t:= LRot32(mk + a,rk); t:= LRot32(mk + a,rk);
Result:= ((S1[t shr 24] xor S2[(t shr 16) and $FF]) - S3[(t shr 8) and $FF]) + S4[t and $FF]; Result:= ((S1[t shr 24] xor S2[(t shr 16) and $FF]) - S3[(t shr 8) and $FF]) + S4[t and $FF];
end; end;
function F2(a,rk,mk: DWord): DWord; function F2(a,rk,mk: DWord): DWord;
var var
t: DWord; t: DWord;
begin begin
t:= LRot32(mk xor a,rk); t:= LRot32(mk xor a,rk);
Result:= ((S1[t shr 24] - S2[(t shr 16) and $FF]) + S3[(t shr 8) and $FF]) xor S4[t and $FF]; Result:= ((S1[t shr 24] - S2[(t shr 16) and $FF]) + S3[(t shr 8) and $FF]) xor S4[t and $FF];
end; end;
function F3(a,rk,mk: DWord): DWord; function F3(a,rk,mk: DWord): DWord;
var var
t: DWord; t: DWord;
begin begin
t:= LRot32(mk - a,rk); t:= LRot32(mk - a,rk);
Result:= ((S1[t shr 24] + S2[(t shr 16) and $FF]) xor S3[(t shr 8) and $FF]) - S4[t and $FF]; Result:= ((S1[t shr 24] + S2[(t shr 16) and $FF]) xor S3[(t shr 8) and $FF]) - S4[t and $FF];
end; end;
class function TDCP_cast256.GetMaxKeySize: integer; class function TDCP_cast256.GetMaxKeySize: integer;
begin begin
Result:= 256; Result:= 256;
end; end;
class function TDCP_cast256.GetId: integer; class function TDCP_cast256.GetId: integer;
begin begin
Result:= DCP_cast256; Result:= DCP_cast256;
end; end;
class function TDCP_cast256.GetAlgorithm: string; class function TDCP_cast256.GetAlgorithm: string;
begin begin
Result:= 'Cast256'; Result:= 'Cast256';
end; end;
class function TDCP_cast256.SelfTest: boolean; class function TDCP_cast256.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($23,$42,$bb,$9e,$fa,$38,$54,$2c,$0a,$f7,$56,$47,$f2,$9f,$61,$5d); ($23,$42,$bb,$9e,$fa,$38,$54,$2c,$0a,$f7,$56,$47,$f2,$9f,$61,$5d);
InBlock1: array[0..15] of byte= InBlock1: array[0..15] of byte=
($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0c,$9b,$28,$07); ($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0c,$9b,$28,$07);
OutBlock1: array[0..15] of byte= OutBlock1: array[0..15] of byte=
($96,$3a,$8a,$50,$ce,$b5,$4d,$08,$e0,$de,$e0,$f1,$d0,$41,$3d,$cf); ($96,$3a,$8a,$50,$ce,$b5,$4d,$08,$e0,$de,$e0,$f1,$d0,$41,$3d,$cf);
Key2: array[0..23] of byte= Key2: array[0..23] of byte=
($23,$42,$bb,$9e,$fa,$38,$54,$2c,$be,$d0,$ac,$83,$94,$0a,$c2,$98,$ba,$c7,$7a,$77,$17,$94,$28,$63); ($23,$42,$bb,$9e,$fa,$38,$54,$2c,$be,$d0,$ac,$83,$94,$0a,$c2,$98,$ba,$c7,$7a,$77,$17,$94,$28,$63);
InBlock2: array[0..15] of byte= InBlock2: array[0..15] of byte=
($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$de,$25,$5a,$ff); ($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$de,$25,$5a,$ff);
OutBlock2: array[0..15] of byte= OutBlock2: array[0..15] of byte=
($2b,$c1,$92,$9f,$30,$13,$47,$a9,$9d,$3f,$3e,$45,$ad,$34,$01,$e8); ($2b,$c1,$92,$9f,$30,$13,$47,$a9,$9d,$3f,$3e,$45,$ad,$34,$01,$e8);
Key3: array[0..31] of byte= Key3: array[0..31] of byte=
($23,$42,$bb,$9e,$fa,$38,$54,$2c,$be,$d0,$ac,$83,$94,$0a,$c2,$98,$8d,$7c,$47,$ce,$26,$49,$08,$46,$1c,$c1,$b5,$13,$7a,$e6,$b6,$04); ($23,$42,$bb,$9e,$fa,$38,$54,$2c,$be,$d0,$ac,$83,$94,$0a,$c2,$98,$8d,$7c,$47,$ce,$26,$49,$08,$46,$1c,$c1,$b5,$13,$7a,$e6,$b6,$04);
InBlock3: array[0..15] of byte= InBlock3: array[0..15] of byte=
($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$c5,$fc,$eb,$19); ($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$c5,$fc,$eb,$19);
OutBlock3: array[0..15] of byte= OutBlock3: array[0..15] of byte=
($1e,$2e,$bc,$6c,$9f,$2e,$43,$8e,$1d,$90,$d9,$b9,$c6,$85,$32,$86); ($1e,$2e,$bc,$6c,$9f,$2e,$43,$8e,$1d,$90,$d9,$b9,$c6,$85,$32,$86);
var var
Block: array[0..15] of byte; Block: array[0..15] of byte;
Cipher: TDCP_cast256; Cipher: TDCP_cast256;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_cast256.Create(nil); Cipher:= TDCP_cast256.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InBlock1,Block); Cipher.EncryptECB(InBlock1,Block);
Result:= boolean(CompareMem(@Block,@OutBlock1,8)); Result:= boolean(CompareMem(@Block,@OutBlock1,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock1,16)); Result:= Result and boolean(CompareMem(@Block,@InBlock1,16));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InBlock2,Block); Cipher.EncryptECB(InBlock2,Block);
Result:= Result and boolean(CompareMem(@Block,@OutBlock2,8)); Result:= Result and boolean(CompareMem(@Block,@OutBlock2,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock2,16)); Result:= Result and boolean(CompareMem(@Block,@InBlock2,16));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key3,Sizeof(Key3)*8,nil); Cipher.Init(Key3,Sizeof(Key3)*8,nil);
Cipher.EncryptECB(InBlock3,Block); Cipher.EncryptECB(InBlock3,Block);
Result:= Result and boolean(CompareMem(@Block,@OutBlock3,8)); Result:= Result and boolean(CompareMem(@Block,@OutBlock3,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and boolean(CompareMem(@Block,@InBlock3,16)); Result:= Result and boolean(CompareMem(@Block,@InBlock3,16));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_cast256.InitKey(const Key; Size: longword); procedure TDCP_cast256.InitKey(const Key; Size: longword);
var var
x: array[0..7] of DWord; x: array[0..7] of DWord;
cm, cr: DWord; cm, cr: DWord;
i, j: longword; i, j: longword;
tr, tm: array[0..7] of DWord; tr, tm: array[0..7] of DWord;
begin begin
Size:= Size div 8; Size:= Size div 8;
dcpFillChar(x,Sizeof(x),0); dcpFillChar(x,Sizeof(x),0);
Move(Key,x,Size); Move(Key,x,Size);
cm:= $5a827999; cm:= $5a827999;
cr:= 19; cr:= 19;
for i:= 0 to 7 do for i:= 0 to 7 do
x[i]:= (x[i] shl 24) or ((x[i] shl 8) and $FF0000) or ((x[i] shr 8) and $FF00) or (x[i] shr 24); x[i]:= (x[i] shl 24) or ((x[i] shl 8) and $FF0000) or ((x[i] shr 8) and $FF00) or (x[i] shr 24);
for i:= 0 to 11 do for i:= 0 to 11 do
begin begin
for j:= 0 to 7 do for j:= 0 to 7 do
begin begin
tm[j]:= cm; tm[j]:= cm;
Inc(cm,$6ed9eba1); Inc(cm,$6ed9eba1);
tr[j]:= cr; tr[j]:= cr;
Inc(cr,17); Inc(cr,17);
end; end;
x[6]:= x[6] xor f1(x[7],tr[0],tm[0]); x[6]:= x[6] xor f1(x[7],tr[0],tm[0]);
x[5]:= x[5] xor f2(x[6],tr[1],tm[1]); x[5]:= x[5] xor f2(x[6],tr[1],tm[1]);
x[4]:= x[4] xor f3(x[5],tr[2],tm[2]); x[4]:= x[4] xor f3(x[5],tr[2],tm[2]);
x[3]:= x[3] xor f1(x[4],tr[3],tm[3]); x[3]:= x[3] xor f1(x[4],tr[3],tm[3]);
x[2]:= x[2] xor f2(x[3],tr[4],tm[4]); x[2]:= x[2] xor f2(x[3],tr[4],tm[4]);
x[1]:= x[1] xor f3(x[2],tr[5],tm[5]); x[1]:= x[1] xor f3(x[2],tr[5],tm[5]);
x[0]:= x[0] xor f1(x[1],tr[6],tm[6]); x[0]:= x[0] xor f1(x[1],tr[6],tm[6]);
x[7]:= x[7] xor f2(x[0],tr[7],tm[7]); x[7]:= x[7] xor f2(x[0],tr[7],tm[7]);
for j:= 0 to 7 do for j:= 0 to 7 do
begin begin
tm[j]:= cm; tm[j]:= cm;
Inc(cm,$6ed9eba1); Inc(cm,$6ed9eba1);
tr[j]:= cr; tr[j]:= cr;
Inc(cr,17); Inc(cr,17);
end; end;
x[6]:= x[6] xor f1(x[7],tr[0],tm[0]); x[6]:= x[6] xor f1(x[7],tr[0],tm[0]);
x[5]:= x[5] xor f2(x[6],tr[1],tm[1]); x[5]:= x[5] xor f2(x[6],tr[1],tm[1]);
x[4]:= x[4] xor f3(x[5],tr[2],tm[2]); x[4]:= x[4] xor f3(x[5],tr[2],tm[2]);
x[3]:= x[3] xor f1(x[4],tr[3],tm[3]); x[3]:= x[3] xor f1(x[4],tr[3],tm[3]);
x[2]:= x[2] xor f2(x[3],tr[4],tm[4]); x[2]:= x[2] xor f2(x[3],tr[4],tm[4]);
x[1]:= x[1] xor f3(x[2],tr[5],tm[5]); x[1]:= x[1] xor f3(x[2],tr[5],tm[5]);
x[0]:= x[0] xor f1(x[1],tr[6],tm[6]); x[0]:= x[0] xor f1(x[1],tr[6],tm[6]);
x[7]:= x[7] xor f2(x[0],tr[7],tm[7]); x[7]:= x[7] xor f2(x[0],tr[7],tm[7]);
Kr[i,0]:= x[0] and 31; Kr[i,0]:= x[0] and 31;
Kr[i,1]:= x[2] and 31; Kr[i,1]:= x[2] and 31;
Kr[i,2]:= x[4] and 31; Kr[i,2]:= x[4] and 31;
Kr[i,3]:= x[6] and 31; Kr[i,3]:= x[6] and 31;
Km[i,0]:= x[7]; Km[i,0]:= x[7];
Km[i,1]:= x[5]; Km[i,1]:= x[5];
Km[i,2]:= x[3]; Km[i,2]:= x[3];
Km[i,3]:= x[1]; Km[i,3]:= x[1];
end; end;
FillChar(x,Sizeof(x),$FF); FillChar(x,Sizeof(x),$FF);
end; end;
procedure TDCP_cast256.Burn; procedure TDCP_cast256.Burn;
begin begin
FillChar(Kr,Sizeof(Kr),$FF); FillChar(Kr,Sizeof(Kr),$FF);
FillChar(Km,Sizeof(Km),$FF); FillChar(Km,Sizeof(Km),$FF);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_cast256.EncryptECB(const InData; var OutData); procedure TDCP_cast256.EncryptECB(const InData; var OutData);
var var
A: array[0..3] of DWord; A: array[0..3] of DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
A[0]:= PDWord(@InData)^; A[0]:= PDWord(@InData)^;
A[1]:= PDWord(pointer(@InData)+4)^; A[1]:= PDWord(pointer(@InData)+4)^;
A[2]:= PDWord(pointer(@InData)+8)^; A[2]:= PDWord(pointer(@InData)+8)^;
A[3]:= PDWord(pointer(@InData)+12)^; A[3]:= PDWord(pointer(@InData)+12)^;
A[0]:= SwapDWord(A[0]); A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]); A[1]:= SwapDWord(A[1]);
A[2]:= SwapDWord(A[2]); A[2]:= SwapDWord(A[2]);
A[3]:= SwapDWord(A[3]); A[3]:= SwapDWord(A[3]);
A[2]:= A[2] xor f1(A[3],kr[0,0],km[0,0]); A[2]:= A[2] xor f1(A[3],kr[0,0],km[0,0]);
A[1]:= A[1] xor f2(A[2],kr[0,1],km[0,1]); A[1]:= A[1] xor f2(A[2],kr[0,1],km[0,1]);
A[0]:= A[0] xor f3(A[1],kr[0,2],km[0,2]); A[0]:= A[0] xor f3(A[1],kr[0,2],km[0,2]);
A[3]:= A[3] xor f1(A[0],kr[0,3],km[0,3]); A[3]:= A[3] xor f1(A[0],kr[0,3],km[0,3]);
A[2]:= A[2] xor f1(A[3],kr[1,0],km[1,0]); A[2]:= A[2] xor f1(A[3],kr[1,0],km[1,0]);
A[1]:= A[1] xor f2(A[2],kr[1,1],km[1,1]); A[1]:= A[1] xor f2(A[2],kr[1,1],km[1,1]);
A[0]:= A[0] xor f3(A[1],kr[1,2],km[1,2]); A[0]:= A[0] xor f3(A[1],kr[1,2],km[1,2]);
A[3]:= A[3] xor f1(A[0],kr[1,3],km[1,3]); A[3]:= A[3] xor f1(A[0],kr[1,3],km[1,3]);
A[2]:= A[2] xor f1(A[3],kr[2,0],km[2,0]); A[2]:= A[2] xor f1(A[3],kr[2,0],km[2,0]);
A[1]:= A[1] xor f2(A[2],kr[2,1],km[2,1]); A[1]:= A[1] xor f2(A[2],kr[2,1],km[2,1]);
A[0]:= A[0] xor f3(A[1],kr[2,2],km[2,2]); A[0]:= A[0] xor f3(A[1],kr[2,2],km[2,2]);
A[3]:= A[3] xor f1(A[0],kr[2,3],km[2,3]); A[3]:= A[3] xor f1(A[0],kr[2,3],km[2,3]);
A[2]:= A[2] xor f1(A[3],kr[3,0],km[3,0]); A[2]:= A[2] xor f1(A[3],kr[3,0],km[3,0]);
A[1]:= A[1] xor f2(A[2],kr[3,1],km[3,1]); A[1]:= A[1] xor f2(A[2],kr[3,1],km[3,1]);
A[0]:= A[0] xor f3(A[1],kr[3,2],km[3,2]); A[0]:= A[0] xor f3(A[1],kr[3,2],km[3,2]);
A[3]:= A[3] xor f1(A[0],kr[3,3],km[3,3]); A[3]:= A[3] xor f1(A[0],kr[3,3],km[3,3]);
A[2]:= A[2] xor f1(A[3],kr[4,0],km[4,0]); A[2]:= A[2] xor f1(A[3],kr[4,0],km[4,0]);
A[1]:= A[1] xor f2(A[2],kr[4,1],km[4,1]); A[1]:= A[1] xor f2(A[2],kr[4,1],km[4,1]);
A[0]:= A[0] xor f3(A[1],kr[4,2],km[4,2]); A[0]:= A[0] xor f3(A[1],kr[4,2],km[4,2]);
A[3]:= A[3] xor f1(A[0],kr[4,3],km[4,3]); A[3]:= A[3] xor f1(A[0],kr[4,3],km[4,3]);
A[2]:= A[2] xor f1(A[3],kr[5,0],km[5,0]); A[2]:= A[2] xor f1(A[3],kr[5,0],km[5,0]);
A[1]:= A[1] xor f2(A[2],kr[5,1],km[5,1]); A[1]:= A[1] xor f2(A[2],kr[5,1],km[5,1]);
A[0]:= A[0] xor f3(A[1],kr[5,2],km[5,2]); A[0]:= A[0] xor f3(A[1],kr[5,2],km[5,2]);
A[3]:= A[3] xor f1(A[0],kr[5,3],km[5,3]); A[3]:= A[3] xor f1(A[0],kr[5,3],km[5,3]);
A[3]:= A[3] xor f1(A[0],kr[6,3],km[6,3]); A[3]:= A[3] xor f1(A[0],kr[6,3],km[6,3]);
A[0]:= A[0] xor f3(A[1],kr[6,2],km[6,2]); A[0]:= A[0] xor f3(A[1],kr[6,2],km[6,2]);
A[1]:= A[1] xor f2(A[2],kr[6,1],km[6,1]); A[1]:= A[1] xor f2(A[2],kr[6,1],km[6,1]);
A[2]:= A[2] xor f1(A[3],kr[6,0],km[6,0]); A[2]:= A[2] xor f1(A[3],kr[6,0],km[6,0]);
A[3]:= A[3] xor f1(A[0],kr[7,3],km[7,3]); A[3]:= A[3] xor f1(A[0],kr[7,3],km[7,3]);
A[0]:= A[0] xor f3(A[1],kr[7,2],km[7,2]); A[0]:= A[0] xor f3(A[1],kr[7,2],km[7,2]);
A[1]:= A[1] xor f2(A[2],kr[7,1],km[7,1]); A[1]:= A[1] xor f2(A[2],kr[7,1],km[7,1]);
A[2]:= A[2] xor f1(A[3],kr[7,0],km[7,0]); A[2]:= A[2] xor f1(A[3],kr[7,0],km[7,0]);
A[3]:= A[3] xor f1(A[0],kr[8,3],km[8,3]); A[3]:= A[3] xor f1(A[0],kr[8,3],km[8,3]);
A[0]:= A[0] xor f3(A[1],kr[8,2],km[8,2]); A[0]:= A[0] xor f3(A[1],kr[8,2],km[8,2]);
A[1]:= A[1] xor f2(A[2],kr[8,1],km[8,1]); A[1]:= A[1] xor f2(A[2],kr[8,1],km[8,1]);
A[2]:= A[2] xor f1(A[3],kr[8,0],km[8,0]); A[2]:= A[2] xor f1(A[3],kr[8,0],km[8,0]);
A[3]:= A[3] xor f1(A[0],kr[9,3],km[9,3]); A[3]:= A[3] xor f1(A[0],kr[9,3],km[9,3]);
A[0]:= A[0] xor f3(A[1],kr[9,2],km[9,2]); A[0]:= A[0] xor f3(A[1],kr[9,2],km[9,2]);
A[1]:= A[1] xor f2(A[2],kr[9,1],km[9,1]); A[1]:= A[1] xor f2(A[2],kr[9,1],km[9,1]);
A[2]:= A[2] xor f1(A[3],kr[9,0],km[9,0]); A[2]:= A[2] xor f1(A[3],kr[9,0],km[9,0]);
A[3]:= A[3] xor f1(A[0],kr[10,3],km[10,3]); A[3]:= A[3] xor f1(A[0],kr[10,3],km[10,3]);
A[0]:= A[0] xor f3(A[1],kr[10,2],km[10,2]); A[0]:= A[0] xor f3(A[1],kr[10,2],km[10,2]);
A[1]:= A[1] xor f2(A[2],kr[10,1],km[10,1]); A[1]:= A[1] xor f2(A[2],kr[10,1],km[10,1]);
A[2]:= A[2] xor f1(A[3],kr[10,0],km[10,0]); A[2]:= A[2] xor f1(A[3],kr[10,0],km[10,0]);
A[3]:= A[3] xor f1(A[0],kr[11,3],km[11,3]); A[3]:= A[3] xor f1(A[0],kr[11,3],km[11,3]);
A[0]:= A[0] xor f3(A[1],kr[11,2],km[11,2]); A[0]:= A[0] xor f3(A[1],kr[11,2],km[11,2]);
A[1]:= A[1] xor f2(A[2],kr[11,1],km[11,1]); A[1]:= A[1] xor f2(A[2],kr[11,1],km[11,1]);
A[2]:= A[2] xor f1(A[3],kr[11,0],km[11,0]); A[2]:= A[2] xor f1(A[3],kr[11,0],km[11,0]);
A[0]:= SwapDWord(A[0]); A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]); A[1]:= SwapDWord(A[1]);
A[2]:= SwapDWord(A[2]); A[2]:= SwapDWord(A[2]);
A[3]:= SwapDWord(A[3]); A[3]:= SwapDWord(A[3]);
PDWord(@OutData)^:= A[0]; PDWord(@OutData)^:= A[0];
PDWord(pointer(@OutData)+4)^:= A[1]; PDWord(pointer(@OutData)+4)^:= A[1];
PDWord(pointer(@OutData)+8)^:= A[2]; PDWord(pointer(@OutData)+8)^:= A[2];
PDWord(pointer(@OutData)+12)^:= A[3]; PDWord(pointer(@OutData)+12)^:= A[3];
end; end;
procedure TDCP_cast256.DecryptECB(const InData; var OutData); procedure TDCP_cast256.DecryptECB(const InData; var OutData);
var var
A: array[0..3] of DWord; A: array[0..3] of DWord;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
A[0]:= PDWord(@InData)^; A[0]:= PDWord(@InData)^;
A[1]:= PDWord(pointer(@InData)+4)^; A[1]:= PDWord(pointer(@InData)+4)^;
A[2]:= PDWord(pointer(@InData)+8)^; A[2]:= PDWord(pointer(@InData)+8)^;
A[3]:= PDWord(pointer(@InData)+12)^; A[3]:= PDWord(pointer(@InData)+12)^;
A[0]:= SwapDWord(A[0]); A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]); A[1]:= SwapDWord(A[1]);
A[2]:= SwapDWord(A[2]); A[2]:= SwapDWord(A[2]);
A[3]:= SwapDWord(A[3]); A[3]:= SwapDWord(A[3]);
A[2]:= A[2] xor f1(A[3],kr[11,0],km[11,0]); A[2]:= A[2] xor f1(A[3],kr[11,0],km[11,0]);
A[1]:= A[1] xor f2(A[2],kr[11,1],km[11,1]); A[1]:= A[1] xor f2(A[2],kr[11,1],km[11,1]);
A[0]:= A[0] xor f3(A[1],kr[11,2],km[11,2]); A[0]:= A[0] xor f3(A[1],kr[11,2],km[11,2]);
A[3]:= A[3] xor f1(A[0],kr[11,3],km[11,3]); A[3]:= A[3] xor f1(A[0],kr[11,3],km[11,3]);
A[2]:= A[2] xor f1(A[3],kr[10,0],km[10,0]); A[2]:= A[2] xor f1(A[3],kr[10,0],km[10,0]);
A[1]:= A[1] xor f2(A[2],kr[10,1],km[10,1]); A[1]:= A[1] xor f2(A[2],kr[10,1],km[10,1]);
A[0]:= A[0] xor f3(A[1],kr[10,2],km[10,2]); A[0]:= A[0] xor f3(A[1],kr[10,2],km[10,2]);
A[3]:= A[3] xor f1(A[0],kr[10,3],km[10,3]); A[3]:= A[3] xor f1(A[0],kr[10,3],km[10,3]);
A[2]:= A[2] xor f1(A[3],kr[9,0],km[9,0]); A[2]:= A[2] xor f1(A[3],kr[9,0],km[9,0]);
A[1]:= A[1] xor f2(A[2],kr[9,1],km[9,1]); A[1]:= A[1] xor f2(A[2],kr[9,1],km[9,1]);
A[0]:= A[0] xor f3(A[1],kr[9,2],km[9,2]); A[0]:= A[0] xor f3(A[1],kr[9,2],km[9,2]);
A[3]:= A[3] xor f1(A[0],kr[9,3],km[9,3]); A[3]:= A[3] xor f1(A[0],kr[9,3],km[9,3]);
A[2]:= A[2] xor f1(A[3],kr[8,0],km[8,0]); A[2]:= A[2] xor f1(A[3],kr[8,0],km[8,0]);
A[1]:= A[1] xor f2(A[2],kr[8,1],km[8,1]); A[1]:= A[1] xor f2(A[2],kr[8,1],km[8,1]);
A[0]:= A[0] xor f3(A[1],kr[8,2],km[8,2]); A[0]:= A[0] xor f3(A[1],kr[8,2],km[8,2]);
A[3]:= A[3] xor f1(A[0],kr[8,3],km[8,3]); A[3]:= A[3] xor f1(A[0],kr[8,3],km[8,3]);
A[2]:= A[2] xor f1(A[3],kr[7,0],km[7,0]); A[2]:= A[2] xor f1(A[3],kr[7,0],km[7,0]);
A[1]:= A[1] xor f2(A[2],kr[7,1],km[7,1]); A[1]:= A[1] xor f2(A[2],kr[7,1],km[7,1]);
A[0]:= A[0] xor f3(A[1],kr[7,2],km[7,2]); A[0]:= A[0] xor f3(A[1],kr[7,2],km[7,2]);
A[3]:= A[3] xor f1(A[0],kr[7,3],km[7,3]); A[3]:= A[3] xor f1(A[0],kr[7,3],km[7,3]);
A[2]:= A[2] xor f1(A[3],kr[6,0],km[6,0]); A[2]:= A[2] xor f1(A[3],kr[6,0],km[6,0]);
A[1]:= A[1] xor f2(A[2],kr[6,1],km[6,1]); A[1]:= A[1] xor f2(A[2],kr[6,1],km[6,1]);
A[0]:= A[0] xor f3(A[1],kr[6,2],km[6,2]); A[0]:= A[0] xor f3(A[1],kr[6,2],km[6,2]);
A[3]:= A[3] xor f1(A[0],kr[6,3],km[6,3]); A[3]:= A[3] xor f1(A[0],kr[6,3],km[6,3]);
A[3]:= A[3] xor f1(A[0],kr[5,3],km[5,3]); A[3]:= A[3] xor f1(A[0],kr[5,3],km[5,3]);
A[0]:= A[0] xor f3(A[1],kr[5,2],km[5,2]); A[0]:= A[0] xor f3(A[1],kr[5,2],km[5,2]);
A[1]:= A[1] xor f2(A[2],kr[5,1],km[5,1]); A[1]:= A[1] xor f2(A[2],kr[5,1],km[5,1]);
A[2]:= A[2] xor f1(A[3],kr[5,0],km[5,0]); A[2]:= A[2] xor f1(A[3],kr[5,0],km[5,0]);
A[3]:= A[3] xor f1(A[0],kr[4,3],km[4,3]); A[3]:= A[3] xor f1(A[0],kr[4,3],km[4,3]);
A[0]:= A[0] xor f3(A[1],kr[4,2],km[4,2]); A[0]:= A[0] xor f3(A[1],kr[4,2],km[4,2]);
A[1]:= A[1] xor f2(A[2],kr[4,1],km[4,1]); A[1]:= A[1] xor f2(A[2],kr[4,1],km[4,1]);
A[2]:= A[2] xor f1(A[3],kr[4,0],km[4,0]); A[2]:= A[2] xor f1(A[3],kr[4,0],km[4,0]);
A[3]:= A[3] xor f1(A[0],kr[3,3],km[3,3]); A[3]:= A[3] xor f1(A[0],kr[3,3],km[3,3]);
A[0]:= A[0] xor f3(A[1],kr[3,2],km[3,2]); A[0]:= A[0] xor f3(A[1],kr[3,2],km[3,2]);
A[1]:= A[1] xor f2(A[2],kr[3,1],km[3,1]); A[1]:= A[1] xor f2(A[2],kr[3,1],km[3,1]);
A[2]:= A[2] xor f1(A[3],kr[3,0],km[3,0]); A[2]:= A[2] xor f1(A[3],kr[3,0],km[3,0]);
A[3]:= A[3] xor f1(A[0],kr[2,3],km[2,3]); A[3]:= A[3] xor f1(A[0],kr[2,3],km[2,3]);
A[0]:= A[0] xor f3(A[1],kr[2,2],km[2,2]); A[0]:= A[0] xor f3(A[1],kr[2,2],km[2,2]);
A[1]:= A[1] xor f2(A[2],kr[2,1],km[2,1]); A[1]:= A[1] xor f2(A[2],kr[2,1],km[2,1]);
A[2]:= A[2] xor f1(A[3],kr[2,0],km[2,0]); A[2]:= A[2] xor f1(A[3],kr[2,0],km[2,0]);
A[3]:= A[3] xor f1(A[0],kr[1,3],km[1,3]); A[3]:= A[3] xor f1(A[0],kr[1,3],km[1,3]);
A[0]:= A[0] xor f3(A[1],kr[1,2],km[1,2]); A[0]:= A[0] xor f3(A[1],kr[1,2],km[1,2]);
A[1]:= A[1] xor f2(A[2],kr[1,1],km[1,1]); A[1]:= A[1] xor f2(A[2],kr[1,1],km[1,1]);
A[2]:= A[2] xor f1(A[3],kr[1,0],km[1,0]); A[2]:= A[2] xor f1(A[3],kr[1,0],km[1,0]);
A[3]:= A[3] xor f1(A[0],kr[0,3],km[0,3]); A[3]:= A[3] xor f1(A[0],kr[0,3],km[0,3]);
A[0]:= A[0] xor f3(A[1],kr[0,2],km[0,2]); A[0]:= A[0] xor f3(A[1],kr[0,2],km[0,2]);
A[1]:= A[1] xor f2(A[2],kr[0,1],km[0,1]); A[1]:= A[1] xor f2(A[2],kr[0,1],km[0,1]);
A[2]:= A[2] xor f1(A[3],kr[0,0],km[0,0]); A[2]:= A[2] xor f1(A[3],kr[0,0],km[0,0]);
A[0]:= SwapDWord(A[0]); A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]); A[1]:= SwapDWord(A[1]);
A[2]:= SwapDWord(A[2]); A[2]:= SwapDWord(A[2]);
A[3]:= SwapDWord(A[3]); A[3]:= SwapDWord(A[3]);
PDWord(@OutData)^:= A[0]; PDWord(@OutData)^:= A[0];
PDWord(pointer(@OutData)+4)^:= A[1]; PDWord(pointer(@OutData)+4)^:= A[1];
PDWord(pointer(@OutData)+8)^:= A[2]; PDWord(pointer(@OutData)+8)^:= A[2];
PDWord(pointer(@OutData)+12)^:= A[3]; PDWord(pointer(@OutData)+12)^:= A[3];
end; end;
end. end.

View File

@ -1,489 +1,489 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of DES and Triple DES *******************} {* A binary compatible implementation of DES and Triple DES *******************}
{* Based on C source code by Eric Young ***************************************} {* Based on C source code by Eric Young ***************************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
{* This implementation of DES is based on the C implementation by *} {* This implementation of DES is based on the C implementation by *}
{* Eric Young (eay@mincom.oz.au) *} {* Eric Young (eay@mincom.oz.au) *}
{******************************************************************************} {******************************************************************************}
{* DES takes a 64bit key and discards every 8th bit (56bit effectively) *} {* DES takes a 64bit key and discards every 8th bit (56bit effectively) *}
{* 3DES takes either a <= 128bit key and uses one key twice or takes a *} {* 3DES takes either a <= 128bit key and uses one key twice or takes a *}
{* <= 192bit key and uses each once (again discarding every 8th bit) *} {* <= 192bit key and uses each once (again discarding every 8th bit) *}
{******************************************************************************} {******************************************************************************}
unit DCPdes; unit DCPdes;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_customdes= class(TDCP_blockcipher64) TDCP_customdes= class(TDCP_blockcipher64)
protected protected
procedure DoInit(KeyB: PByteArray; KeyData: PDWordArray); procedure DoInit(KeyB: PByteArray; KeyData: PDWordArray);
procedure EncryptBlock(const InData; var OutData; KeyData: PDWordArray); procedure EncryptBlock(const InData; var OutData; KeyData: PDWordArray);
procedure DecryptBlock(const InData; var OutData; KeyData: PDWordArray); procedure DecryptBlock(const InData; var OutData; KeyData: PDWordArray);
end; end;
type type
TDCP_des= class(TDCP_customdes) TDCP_des= class(TDCP_customdes)
protected protected
KeyData: array[0..31] of dword; KeyData: array[0..31] of dword;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
TDCP_3des= class(TDCP_customdes) TDCP_3des= class(TDCP_customdes)
protected protected
KeyData: array[0..2,0..31] of dword; KeyData: array[0..2,0..31] of dword;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPdes.inc} {$I DCPdes.inc}
procedure hperm_op(var a, t: dword; n, m: dword); procedure hperm_op(var a, t: dword; n, m: dword);
begin begin
t:= ((a shl (16 - n)) xor a) and m; t:= ((a shl (16 - n)) xor a) and m;
a:= a xor t xor (t shr (16 - n)); a:= a xor t xor (t shr (16 - n));
end; end;
procedure perm_op(var a, b, t: dword; n, m: dword); procedure perm_op(var a, b, t: dword; n, m: dword);
begin begin
t:= ((a shr n) xor b) and m; t:= ((a shr n) xor b) and m;
b:= b xor t; b:= b xor t;
a:= a xor (t shl n); a:= a xor (t shl n);
end; end;
procedure TDCP_customdes.DoInit(KeyB: PByteArray; KeyData: PDwordArray); procedure TDCP_customdes.DoInit(KeyB: PByteArray; KeyData: PDwordArray);
var var
c, d, t, s, t2, i: dword; c, d, t, s, t2, i: dword;
begin begin
t := 0; t := 0;
c:= KeyB^[0] or (KeyB^[1] shl 8) or (KeyB^[2] shl 16) or (KeyB^[3] shl 24); c:= KeyB^[0] or (KeyB^[1] shl 8) or (KeyB^[2] shl 16) or (KeyB^[3] shl 24);
d:= KeyB^[4] or (KeyB^[5] shl 8) or (KeyB^[6] shl 16) or (KeyB^[7] shl 24); d:= KeyB^[4] or (KeyB^[5] shl 8) or (KeyB^[6] shl 16) or (KeyB^[7] shl 24);
perm_op(d,c,t,4,$0f0f0f0f); perm_op(d,c,t,4,$0f0f0f0f);
hperm_op(c,t,dword(-2),$cccc0000); hperm_op(c,t,dword(-2),$cccc0000);
hperm_op(d,t,dword(-2),$cccc0000); hperm_op(d,t,dword(-2),$cccc0000);
perm_op(d,c,t,1,$55555555); perm_op(d,c,t,1,$55555555);
perm_op(c,d,t,8,$00ff00ff); perm_op(c,d,t,8,$00ff00ff);
perm_op(d,c,t,1,$55555555); perm_op(d,c,t,1,$55555555);
d:= ((d and $ff) shl 16) or (d and $ff00) or ((d and $ff0000) shr 16) or d:= ((d and $ff) shl 16) or (d and $ff00) or ((d and $ff0000) shr 16) or
((c and $f0000000) shr 4); ((c and $f0000000) shr 4);
c:= c and $fffffff; c:= c and $fffffff;
for i:= 0 to 15 do for i:= 0 to 15 do
begin begin
if shifts2[i]<> 0 then if shifts2[i]<> 0 then
begin begin
c:= ((c shr 2) or (c shl 26)); c:= ((c shr 2) or (c shl 26));
d:= ((d shr 2) or (d shl 26)); d:= ((d shr 2) or (d shl 26));
end end
else else
begin begin
c:= ((c shr 1) or (c shl 27)); c:= ((c shr 1) or (c shl 27));
d:= ((d shr 1) or (d shl 27)); d:= ((d shr 1) or (d shl 27));
end; end;
c:= c and $fffffff; c:= c and $fffffff;
d:= d and $fffffff; d:= d and $fffffff;
s:= des_skb[0,c and $3f] or s:= des_skb[0,c and $3f] or
des_skb[1,((c shr 6) and $03) or ((c shr 7) and $3c)] or des_skb[1,((c shr 6) and $03) or ((c shr 7) and $3c)] or
des_skb[2,((c shr 13) and $0f) or ((c shr 14) and $30)] or des_skb[2,((c shr 13) and $0f) or ((c shr 14) and $30)] or
des_skb[3,((c shr 20) and $01) or ((c shr 21) and $06) or ((c shr 22) and $38)]; des_skb[3,((c shr 20) and $01) or ((c shr 21) and $06) or ((c shr 22) and $38)];
t:= des_skb[4,d and $3f] or t:= des_skb[4,d and $3f] or
des_skb[5,((d shr 7) and $03) or ((d shr 8) and $3c)] or des_skb[5,((d shr 7) and $03) or ((d shr 8) and $3c)] or
des_skb[6, (d shr 15) and $3f ] or des_skb[6, (d shr 15) and $3f ] or
des_skb[7,((d shr 21) and $0f) or ((d shr 22) and $30)]; des_skb[7,((d shr 21) and $0f) or ((d shr 22) and $30)];
t2:= ((t shl 16) or (s and $ffff)); t2:= ((t shl 16) or (s and $ffff));
KeyData^[(i shl 1)]:= ((t2 shl 2) or (t2 shr 30)); KeyData^[(i shl 1)]:= ((t2 shl 2) or (t2 shr 30));
t2:= ((s shr 16) or (t and $ffff0000)); t2:= ((s shr 16) or (t and $ffff0000));
KeyData^[(i shl 1)+1]:= ((t2 shl 6) or (t2 shr 26)); KeyData^[(i shl 1)+1]:= ((t2 shl 6) or (t2 shr 26));
end; end;
end; end;
procedure TDCP_customdes.EncryptBlock(const InData; var OutData; KeyData: PDWordArray); procedure TDCP_customdes.EncryptBlock(const InData; var OutData; KeyData: PDWordArray);
var var
l, r, t, u: dword; l, r, t, u: dword;
i: longint; i: longint;
begin begin
r:= PDword(@InData)^; r:= PDword(@InData)^;
l:= PDword(pointer(@InData)+4)^; l:= PDword(pointer(@InData)+4)^;
t:= ((l shr 4) xor r) and $0f0f0f0f; t:= ((l shr 4) xor r) and $0f0f0f0f;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 4); l:= l xor (t shl 4);
t:= ((r shr 16) xor l) and $0000ffff; t:= ((r shr 16) xor l) and $0000ffff;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 16); r:= r xor (t shl 16);
t:= ((l shr 2) xor r) and $33333333; t:= ((l shr 2) xor r) and $33333333;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 2); l:= l xor (t shl 2);
t:= ((r shr 8) xor l) and $00ff00ff; t:= ((r shr 8) xor l) and $00ff00ff;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 8); r:= r xor (t shl 8);
t:= ((l shr 1) xor r) and $55555555; t:= ((l shr 1) xor r) and $55555555;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 1); l:= l xor (t shl 1);
r:= (r shr 29) or (r shl 3); r:= (r shr 29) or (r shl 3);
l:= (l shr 29) or (l shl 3); l:= (l shr 29) or (l shl 3);
i:= 0; i:= 0;
while i< 32 do while i< 32 do
begin begin
u:= r xor KeyData^[i ]; u:= r xor KeyData^[i ];
t:= r xor KeyData^[i+1]; t:= r xor KeyData^[i+1];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= l xor KeyData^[i+2]; u:= l xor KeyData^[i+2];
t:= l xor KeyData^[i+3]; t:= l xor KeyData^[i+3];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= r xor KeyData^[i+4]; u:= r xor KeyData^[i+4];
t:= r xor KeyData^[i+5]; t:= r xor KeyData^[i+5];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= l xor KeyData^[i+6]; u:= l xor KeyData^[i+6];
t:= l xor KeyData^[i+7]; t:= l xor KeyData^[i+7];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
Inc(i,8); Inc(i,8);
end; end;
r:= (r shr 3) or (r shl 29); r:= (r shr 3) or (r shl 29);
l:= (l shr 3) or (l shl 29); l:= (l shr 3) or (l shl 29);
t:= ((r shr 1) xor l) and $55555555; t:= ((r shr 1) xor l) and $55555555;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 1); r:= r xor (t shl 1);
t:= ((l shr 8) xor r) and $00ff00ff; t:= ((l shr 8) xor r) and $00ff00ff;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 8); l:= l xor (t shl 8);
t:= ((r shr 2) xor l) and $33333333; t:= ((r shr 2) xor l) and $33333333;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 2); r:= r xor (t shl 2);
t:= ((l shr 16) xor r) and $0000ffff; t:= ((l shr 16) xor r) and $0000ffff;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 16); l:= l xor (t shl 16);
t:= ((r shr 4) xor l) and $0f0f0f0f; t:= ((r shr 4) xor l) and $0f0f0f0f;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 4); r:= r xor (t shl 4);
PDword(@OutData)^:= l; PDword(@OutData)^:= l;
PDword(pointer(@OutData)+4)^:= r; PDword(pointer(@OutData)+4)^:= r;
end; end;
procedure TDCP_customdes.DecryptBlock(const InData; var OutData; KeyData: PDWordArray); procedure TDCP_customdes.DecryptBlock(const InData; var OutData; KeyData: PDWordArray);
var var
l, r, t, u: dword; l, r, t, u: dword;
i: longint; i: longint;
begin begin
r:= PDword(@InData)^; r:= PDword(@InData)^;
l:= PDword(pointer(@InData)+4)^; l:= PDword(pointer(@InData)+4)^;
t:= ((l shr 4) xor r) and $0f0f0f0f; t:= ((l shr 4) xor r) and $0f0f0f0f;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 4); l:= l xor (t shl 4);
t:= ((r shr 16) xor l) and $0000ffff; t:= ((r shr 16) xor l) and $0000ffff;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 16); r:= r xor (t shl 16);
t:= ((l shr 2) xor r) and $33333333; t:= ((l shr 2) xor r) and $33333333;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 2); l:= l xor (t shl 2);
t:= ((r shr 8) xor l) and $00ff00ff; t:= ((r shr 8) xor l) and $00ff00ff;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 8); r:= r xor (t shl 8);
t:= ((l shr 1) xor r) and $55555555; t:= ((l shr 1) xor r) and $55555555;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 1); l:= l xor (t shl 1);
r:= (r shr 29) or (r shl 3); r:= (r shr 29) or (r shl 3);
l:= (l shr 29) or (l shl 3); l:= (l shr 29) or (l shl 3);
i:= 30; i:= 30;
while i> 0 do while i> 0 do
begin begin
u:= r xor KeyData^[i ]; u:= r xor KeyData^[i ];
t:= r xor KeyData^[i+1]; t:= r xor KeyData^[i+1];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= l xor KeyData^[i-2]; u:= l xor KeyData^[i-2];
t:= l xor KeyData^[i-1]; t:= l xor KeyData^[i-1];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= r xor KeyData^[i-4]; u:= r xor KeyData^[i-4];
t:= r xor KeyData^[i-3]; t:= r xor KeyData^[i-3];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor l:= l xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
u:= l xor KeyData^[i-6]; u:= l xor KeyData^[i-6];
t:= l xor KeyData^[i-5]; t:= l xor KeyData^[i-5];
t:= (t shr 4) or (t shl 28); t:= (t shr 4) or (t shl 28);
r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor r:= r xor des_SPtrans[0,(u shr 2) and $3f] xor
des_SPtrans[2,(u shr 10) and $3f] xor des_SPtrans[2,(u shr 10) and $3f] xor
des_SPtrans[4,(u shr 18) and $3f] xor des_SPtrans[4,(u shr 18) and $3f] xor
des_SPtrans[6,(u shr 26) and $3f] xor des_SPtrans[6,(u shr 26) and $3f] xor
des_SPtrans[1,(t shr 2) and $3f] xor des_SPtrans[1,(t shr 2) and $3f] xor
des_SPtrans[3,(t shr 10) and $3f] xor des_SPtrans[3,(t shr 10) and $3f] xor
des_SPtrans[5,(t shr 18) and $3f] xor des_SPtrans[5,(t shr 18) and $3f] xor
des_SPtrans[7,(t shr 26) and $3f]; des_SPtrans[7,(t shr 26) and $3f];
Dec(i,8); Dec(i,8);
end; end;
r:= (r shr 3) or (r shl 29); r:= (r shr 3) or (r shl 29);
l:= (l shr 3) or (l shl 29); l:= (l shr 3) or (l shl 29);
t:= ((r shr 1) xor l) and $55555555; t:= ((r shr 1) xor l) and $55555555;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 1); r:= r xor (t shl 1);
t:= ((l shr 8) xor r) and $00ff00ff; t:= ((l shr 8) xor r) and $00ff00ff;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 8); l:= l xor (t shl 8);
t:= ((r shr 2) xor l) and $33333333; t:= ((r shr 2) xor l) and $33333333;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 2); r:= r xor (t shl 2);
t:= ((l shr 16) xor r) and $0000ffff; t:= ((l shr 16) xor r) and $0000ffff;
r:= r xor t; r:= r xor t;
l:= l xor (t shl 16); l:= l xor (t shl 16);
t:= ((r shr 4) xor l) and $0f0f0f0f; t:= ((r shr 4) xor l) and $0f0f0f0f;
l:= l xor t; l:= l xor t;
r:= r xor (t shl 4); r:= r xor (t shl 4);
PDword(@OutData)^:= l; PDword(@OutData)^:= l;
PDword(pointer(@OutData)+4)^:= r; PDword(pointer(@OutData)+4)^:= r;
end; end;
class function TDCP_des.GetMaxKeySize: integer; class function TDCP_des.GetMaxKeySize: integer;
begin begin
Result:= 64; Result:= 64;
end; end;
class function TDCP_des.GetID: integer; class function TDCP_des.GetID: integer;
begin begin
Result:= DCP_des; Result:= DCP_des;
end; end;
class function TDCP_des.GetAlgorithm: string; class function TDCP_des.GetAlgorithm: string;
begin begin
Result:= 'DES'; Result:= 'DES';
end; end;
class function TDCP_des.SelfTest: boolean; class function TDCP_des.SelfTest: boolean;
const const
InData1: array[0..7] of byte= InData1: array[0..7] of byte=
($07,$56,$D8,$E0,$77,$47,$61,$D2); ($07,$56,$D8,$E0,$77,$47,$61,$D2);
OutData1: array[0..7] of byte= OutData1: array[0..7] of byte=
($0C,$D3,$DA,$02,$00,$21,$DC,$09); ($0C,$D3,$DA,$02,$00,$21,$DC,$09);
Key1: array[0..7] of byte= Key1: array[0..7] of byte=
($01,$70,$F1,$75,$46,$8F,$B5,$E6); ($01,$70,$F1,$75,$46,$8F,$B5,$E6);
InData2: array[0..7] of byte= InData2: array[0..7] of byte=
($48,$0D,$39,$00,$6E,$E7,$62,$F2); ($48,$0D,$39,$00,$6E,$E7,$62,$F2);
OutData2: array[0..7] of byte= OutData2: array[0..7] of byte=
($A1,$F9,$91,$55,$41,$02,$0B,$56); ($A1,$F9,$91,$55,$41,$02,$0B,$56);
Key2: array[0..7] of byte= Key2: array[0..7] of byte=
($02,$58,$16,$16,$46,$29,$B0,$07); ($02,$58,$16,$16,$46,$29,$B0,$07);
var var
Cipher: TDCP_des; Cipher: TDCP_des;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_des.Create(nil); Cipher:= TDCP_des.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@InData1,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@InData1,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Data); Cipher.EncryptECB(InData2,Data);
Result:= Result and boolean(CompareMem(@Data,@OutData2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@OutData2,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@InData2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@InData2,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_des.InitKey(const Key; Size: longword); procedure TDCP_des.InitKey(const Key; Size: longword);
var var
KeyB: array[0..7] of byte; KeyB: array[0..7] of byte;
begin begin
dcpFillChar(KeyB,Sizeof(KeyB),0); dcpFillChar(KeyB,Sizeof(KeyB),0);
Move(Key,KeyB,Size div 8); Move(Key,KeyB,Size div 8);
DoInit(@KeyB,@KeyData); DoInit(@KeyB,@KeyData);
end; end;
procedure TDCP_des.Burn; procedure TDCP_des.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_des.EncryptECB(const InData; var OutData); procedure TDCP_des.EncryptECB(const InData; var OutData);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
EncryptBlock(InData,OutData,@KeyData); EncryptBlock(InData,OutData,@KeyData);
end; end;
procedure TDCP_des.DecryptECB(const InData; var OutData); procedure TDCP_des.DecryptECB(const InData; var OutData);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
DecryptBlock(InData,OutData,@KeyData); DecryptBlock(InData,OutData,@KeyData);
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_3des.GetMaxKeySize: integer; class function TDCP_3des.GetMaxKeySize: integer;
begin begin
Result:= 192; Result:= 192;
end; end;
class function TDCP_3des.GetID: integer; class function TDCP_3des.GetID: integer;
begin begin
Result:= DCP_3des; Result:= DCP_3des;
end; end;
class function TDCP_3des.GetAlgorithm: string; class function TDCP_3des.GetAlgorithm: string;
begin begin
Result:= '3DES'; Result:= '3DES';
end; end;
class function TDCP_3des.SelfTest: boolean; class function TDCP_3des.SelfTest: boolean;
const const
Key: array[0..23] of byte= Key: array[0..23] of byte=
($01,$23,$45,$67,$89,$ab,$cd,$ef,$fe,$dc,$ba,$98, ($01,$23,$45,$67,$89,$ab,$cd,$ef,$fe,$dc,$ba,$98,
$76,$54,$32,$10,$89,$ab,$cd,$ef,$01,$23,$45,$67); $76,$54,$32,$10,$89,$ab,$cd,$ef,$01,$23,$45,$67);
PlainText: array[0..7] of byte= PlainText: array[0..7] of byte=
($01,$23,$45,$67,$89,$ab,$cd,$e7); ($01,$23,$45,$67,$89,$ab,$cd,$e7);
CipherText: array[0..7] of byte= CipherText: array[0..7] of byte=
($de,$0b,$7c,$06,$ae,$5e,$0e,$d5); ($de,$0b,$7c,$06,$ae,$5e,$0e,$d5);
var var
Cipher: TDCP_3des; Cipher: TDCP_3des;
Block: array[0..7] of byte; Block: array[0..7] of byte;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_3des.Create(nil); Cipher:= TDCP_3des.Create(nil);
Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.Init(Key,Sizeof(Key)*8,nil);
Cipher.EncryptECB(PlainText,Block); Cipher.EncryptECB(PlainText,Block);
Result:= CompareMem(@Block,@CipherText,Sizeof(CipherText)); Result:= CompareMem(@Block,@CipherText,Sizeof(CipherText));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and CompareMem(@Block,@PlainText,Sizeof(PlainText)); Result:= Result and CompareMem(@Block,@PlainText,Sizeof(PlainText));
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_3des.InitKey(const Key; Size: longword); procedure TDCP_3des.InitKey(const Key; Size: longword);
var var
KeyB: array[0..2,0..7] of byte; KeyB: array[0..2,0..7] of byte;
begin begin
dcpFillChar(KeyB,Sizeof(KeyB),0); dcpFillChar(KeyB,Sizeof(KeyB),0);
Move(Key,KeyB,Size div 8); Move(Key,KeyB,Size div 8);
DoInit(@KeyB[0],@KeyData[0]); DoInit(@KeyB[0],@KeyData[0]);
DoInit(@KeyB[1],@KeyData[1]); DoInit(@KeyB[1],@KeyData[1]);
if Size> 128 then if Size> 128 then
DoInit(@KeyB[2],@KeyData[2]) DoInit(@KeyB[2],@KeyData[2])
else else
Move(KeyData[0],KeyData[2],128); Move(KeyData[0],KeyData[2],128);
end; end;
procedure TDCP_3des.Burn; procedure TDCP_3des.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_3des.EncryptECB(const InData; var OutData); procedure TDCP_3des.EncryptECB(const InData; var OutData);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
EncryptBlock(InData,OutData,@KeyData[0]); EncryptBlock(InData,OutData,@KeyData[0]);
DecryptBlock(OutData,OutData,@KeyData[1]); DecryptBlock(OutData,OutData,@KeyData[1]);
EncryptBlock(OutData,OutData,@KeyData[2]); EncryptBlock(OutData,OutData,@KeyData[2]);
end; end;
procedure TDCP_3des.DecryptECB(const InData; var OutData); procedure TDCP_3des.DecryptECB(const InData; var OutData);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
DecryptBlock(InData,OutData,@KeyData[2]); DecryptBlock(InData,OutData,@KeyData[2]);
EncryptBlock(OutData,OutData,@KeyData[1]); EncryptBlock(OutData,OutData,@KeyData[1]);
DecryptBlock(OutData,OutData,@KeyData[0]); DecryptBlock(OutData,OutData,@KeyData[0]);
end; end;
end. end.

View File

@ -1,232 +1,232 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Gost *********************************} {* A binary compatible implementation of Gost *********************************}
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
{* !!WARNING!! !!WARNING!! !!WARNING!!!!WARNING!! !!WARNING!! !!WARNING!! *} {* !!WARNING!! !!WARNING!! !!WARNING!!!!WARNING!! !!WARNING!! !!WARNING!! *}
{* *} {* *}
{* I am not sure if this is compatible with the actual GOST standard *} {* I am not sure if this is compatible with the actual GOST standard *}
{* as a result, use this implementation with extreme caution. *} {* as a result, use this implementation with extreme caution. *}
{* *} {* *}
{* !!WARNING!! !!WARNING!! !!WARNING!!!!WARNING!! !!WARNING!! !!WARNING!! *} {* !!WARNING!! !!WARNING!! !!WARNING!!!!WARNING!! !!WARNING!! !!WARNING!! *}
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPgost; unit DCPgost;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_gost= class(TDCP_blockcipher64) TDCP_gost= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..7] of DWord; KeyData: array[0..7] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPgost.inc} {$I DCPgost.inc}
class function TDCP_gost.GetMaxKeySize: integer; class function TDCP_gost.GetMaxKeySize: integer;
begin begin
Result:= 256; Result:= 256;
end; end;
class function TDCP_gost.GetID: integer; class function TDCP_gost.GetID: integer;
begin begin
Result:= DCP_gost; Result:= DCP_gost;
end; end;
class function TDCP_gost.GetAlgorithm: string; class function TDCP_gost.GetAlgorithm: string;
begin begin
Result:= 'Gost'; Result:= 'Gost';
end; end;
class function TDCP_gost.SelfTest: boolean; class function TDCP_gost.SelfTest: boolean;
const const
Key1: array[0..31] of byte= Key1: array[0..31] of byte=
($BE,$5E,$C2,$00,$6C,$FF,$9D,$CF,$52,$35,$49,$59,$F1,$FF,$0C,$BF, ($BE,$5E,$C2,$00,$6C,$FF,$9D,$CF,$52,$35,$49,$59,$F1,$FF,$0C,$BF,
$E9,$50,$61,$B5,$A6,$48,$C1,$03,$87,$06,$9C,$25,$99,$7C,$06,$72); $E9,$50,$61,$B5,$A6,$48,$C1,$03,$87,$06,$9C,$25,$99,$7C,$06,$72);
InData1: array[0..7] of byte= InData1: array[0..7] of byte=
($0D,$F8,$28,$02,$B7,$41,$A2,$92); ($0D,$F8,$28,$02,$B7,$41,$A2,$92);
OutData1: array[0..7] of byte= OutData1: array[0..7] of byte=
($07,$F9,$02,$7D,$F7,$F7,$DF,$89); ($07,$F9,$02,$7D,$F7,$F7,$DF,$89);
Key2: array[0..31] of byte= Key2: array[0..31] of byte=
($B3,$85,$27,$2A,$C8,$D7,$2A,$5A,$8B,$34,$4B,$C8,$03,$63,$AC,$4D, ($B3,$85,$27,$2A,$C8,$D7,$2A,$5A,$8B,$34,$4B,$C8,$03,$63,$AC,$4D,
$09,$BF,$58,$F4,$1F,$54,$06,$24,$CB,$CB,$8F,$DC,$F5,$53,$07,$D7); $09,$BF,$58,$F4,$1F,$54,$06,$24,$CB,$CB,$8F,$DC,$F5,$53,$07,$D7);
InData2: array[0..7] of byte= InData2: array[0..7] of byte=
($13,$54,$EE,$9C,$0A,$11,$CD,$4C); ($13,$54,$EE,$9C,$0A,$11,$CD,$4C);
OutData2: array[0..7] of byte= OutData2: array[0..7] of byte=
($4F,$B5,$05,$36,$F9,$60,$A7,$B1); ($4F,$B5,$05,$36,$F9,$60,$A7,$B1);
var var
Block: array[0..7] of byte; Block: array[0..7] of byte;
Cipher: TDCP_gost; Cipher: TDCP_gost;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_gost.Create(nil); Cipher:= TDCP_gost.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Block); Cipher.EncryptECB(InData1,Block);
Result:= boolean(CompareMem(@Block,@OutData1,8)); Result:= boolean(CompareMem(@Block,@OutData1,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData1,8)); Result:= Result and boolean(CompareMem(@Block,@InData1,8));
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Block); Cipher.EncryptECB(InData2,Block);
Result:= Result and boolean(CompareMem(@Block,@OutData2,8)); Result:= Result and boolean(CompareMem(@Block,@OutData2,8));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData2,8)); Result:= Result and boolean(CompareMem(@Block,@InData2,8));
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_gost.InitKey(const Key; Size: longword); procedure TDCP_gost.InitKey(const Key; Size: longword);
var var
i: longword; i: longword;
userkey: array[0..31] of byte; userkey: array[0..31] of byte;
begin begin
Size:= Size div 8; Size:= Size div 8;
dcpFillChar(userkey,Sizeof(userkey),0); dcpFillChar(userkey,Sizeof(userkey),0);
Move(Key,userkey,Size); Move(Key,userkey,Size);
for i:= 0 to 7 do for i:= 0 to 7 do
KeyData[i]:= (dword(UserKey[4*i+3]) shl 24) or (dword(UserKey[4*i+2]) shl 16) or KeyData[i]:= (dword(UserKey[4*i+3]) shl 24) or (dword(UserKey[4*i+2]) shl 16) or
(dword(UserKey[4*i+1]) shl 8) or (dword(UserKey[4*i+0])); (dword(UserKey[4*i+1]) shl 8) or (dword(UserKey[4*i+0]));
end; end;
procedure TDCP_gost.Burn; procedure TDCP_gost.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_gost.EncryptECB(const InData; var OutData); procedure TDCP_gost.EncryptECB(const InData; var OutData);
var var
n1, n2: DWord; n1, n2: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
n1:= PDword(@InData)^; n1:= PDword(@InData)^;
n2:= PDword(pointer(@InData)+4)^; n2:= PDword(pointer(@InData)+4)^;
for i:= 0 to 2 do for i:= 0 to 2 do
begin begin
n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[0]) shr 8) and $FF] xor sTable[0,(n1+KeyData[0]) and $FF]); xor sTable[1,((n1+KeyData[0]) shr 8) and $FF] xor sTable[0,(n1+KeyData[0]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[1]) shr 24] xor sTable[2,((n2+KeyData[1]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[1]) shr 24] xor sTable[2,((n2+KeyData[1]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[1]) shr 8) and $FF] xor sTable[0,(n2+KeyData[1]) and $FF]); xor sTable[1,((n2+KeyData[1]) shr 8) and $FF] xor sTable[0,(n2+KeyData[1]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[2]) shr 24] xor sTable[2,((n1+KeyData[2]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[2]) shr 24] xor sTable[2,((n1+KeyData[2]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[2]) shr 8) and $FF] xor sTable[0,(n1+KeyData[2]) and $FF]); xor sTable[1,((n1+KeyData[2]) shr 8) and $FF] xor sTable[0,(n1+KeyData[2]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[3]) shr 24] xor sTable[2,((n2+KeyData[3]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[3]) shr 24] xor sTable[2,((n2+KeyData[3]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[3]) shr 8) and $FF] xor sTable[0,(n2+KeyData[3]) and $FF]); xor sTable[1,((n2+KeyData[3]) shr 8) and $FF] xor sTable[0,(n2+KeyData[3]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[4]) shr 24] xor sTable[2,((n1+KeyData[4]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[4]) shr 24] xor sTable[2,((n1+KeyData[4]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[4]) shr 8) and $FF] xor sTable[0,(n1+KeyData[4]) and $FF]); xor sTable[1,((n1+KeyData[4]) shr 8) and $FF] xor sTable[0,(n1+KeyData[4]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[5]) shr 24] xor sTable[2,((n2+KeyData[5]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[5]) shr 24] xor sTable[2,((n2+KeyData[5]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[5]) shr 8) and $FF] xor sTable[0,(n2+KeyData[5]) and $FF]); xor sTable[1,((n2+KeyData[5]) shr 8) and $FF] xor sTable[0,(n2+KeyData[5]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[6]) shr 24] xor sTable[2,((n1+KeyData[6]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[6]) shr 24] xor sTable[2,((n1+KeyData[6]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[6]) shr 8) and $FF] xor sTable[0,(n1+KeyData[6]) and $FF]); xor sTable[1,((n1+KeyData[6]) shr 8) and $FF] xor sTable[0,(n1+KeyData[6]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[7]) shr 24] xor sTable[2,((n2+KeyData[7]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[7]) shr 24] xor sTable[2,((n2+KeyData[7]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[7]) shr 8) and $FF] xor sTable[0,(n2+KeyData[7]) and $FF]); xor sTable[1,((n2+KeyData[7]) shr 8) and $FF] xor sTable[0,(n2+KeyData[7]) and $FF]);
end; end;
n2:= n2 xor (sTable[3,(n1+KeyData[7]) shr 24] xor sTable[2,((n1+KeyData[7]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[7]) shr 24] xor sTable[2,((n1+KeyData[7]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[7]) shr 8) and $FF] xor sTable[0,(n1+KeyData[7]) and $FF]); xor sTable[1,((n1+KeyData[7]) shr 8) and $FF] xor sTable[0,(n1+KeyData[7]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[6]) shr 24] xor sTable[2,((n2+KeyData[6]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[6]) shr 24] xor sTable[2,((n2+KeyData[6]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[6]) shr 8) and $FF] xor sTable[0,(n2+KeyData[6]) and $FF]); xor sTable[1,((n2+KeyData[6]) shr 8) and $FF] xor sTable[0,(n2+KeyData[6]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[5]) shr 24] xor sTable[2,((n1+KeyData[5]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[5]) shr 24] xor sTable[2,((n1+KeyData[5]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[5]) shr 8) and $FF] xor sTable[0,(n1+KeyData[5]) and $FF]); xor sTable[1,((n1+KeyData[5]) shr 8) and $FF] xor sTable[0,(n1+KeyData[5]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[4]) shr 24] xor sTable[2,((n2+KeyData[4]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[4]) shr 24] xor sTable[2,((n2+KeyData[4]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[4]) shr 8) and $FF] xor sTable[0,(n2+KeyData[4]) and $FF]); xor sTable[1,((n2+KeyData[4]) shr 8) and $FF] xor sTable[0,(n2+KeyData[4]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[3]) shr 24] xor sTable[2,((n1+KeyData[3]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[3]) shr 24] xor sTable[2,((n1+KeyData[3]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[3]) shr 8) and $FF] xor sTable[0,(n1+KeyData[3]) and $FF]); xor sTable[1,((n1+KeyData[3]) shr 8) and $FF] xor sTable[0,(n1+KeyData[3]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[2]) shr 24] xor sTable[2,((n2+KeyData[2]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[2]) shr 24] xor sTable[2,((n2+KeyData[2]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[2]) shr 8) and $FF] xor sTable[0,(n2+KeyData[2]) and $FF]); xor sTable[1,((n2+KeyData[2]) shr 8) and $FF] xor sTable[0,(n2+KeyData[2]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[1]) shr 24] xor sTable[2,((n1+KeyData[1]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[1]) shr 24] xor sTable[2,((n1+KeyData[1]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[1]) shr 8) and $FF] xor sTable[0,(n1+KeyData[1]) and $FF]); xor sTable[1,((n1+KeyData[1]) shr 8) and $FF] xor sTable[0,(n1+KeyData[1]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[0]) shr 24] xor sTable[2,((n2+KeyData[0]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[0]) shr 24] xor sTable[2,((n2+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]); xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]);
PDword(@OutData)^:= n2; PDword(@OutData)^:= n2;
PDword(pointer(@OutData)+4)^:= n1; PDword(pointer(@OutData)+4)^:= n1;
end; end;
procedure TDCP_gost.DecryptECB(const InData; var OutData); procedure TDCP_gost.DecryptECB(const InData; var OutData);
var var
n1, n2: DWord; n1, n2: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
n1:= PDword(@InData)^; n1:= PDword(@InData)^;
n2:= PDword(pointer(@InData)+4)^; n2:= PDword(pointer(@InData)+4)^;
n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[0]) shr 8) and $FF] xor sTable[0,(n1+KeyData[0]) and $FF]); xor sTable[1,((n1+KeyData[0]) shr 8) and $FF] xor sTable[0,(n1+KeyData[0]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[1]) shr 24] xor sTable[2,((n2+KeyData[1]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[1]) shr 24] xor sTable[2,((n2+KeyData[1]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[1]) shr 8) and $FF] xor sTable[0,(n2+KeyData[1]) and $FF]); xor sTable[1,((n2+KeyData[1]) shr 8) and $FF] xor sTable[0,(n2+KeyData[1]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[2]) shr 24] xor sTable[2,((n1+KeyData[2]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[2]) shr 24] xor sTable[2,((n1+KeyData[2]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[2]) shr 8) and $FF] xor sTable[0,(n1+KeyData[2]) and $FF]); xor sTable[1,((n1+KeyData[2]) shr 8) and $FF] xor sTable[0,(n1+KeyData[2]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[3]) shr 24] xor sTable[2,((n2+KeyData[3]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[3]) shr 24] xor sTable[2,((n2+KeyData[3]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[3]) shr 8) and $FF] xor sTable[0,(n2+KeyData[3]) and $FF]); xor sTable[1,((n2+KeyData[3]) shr 8) and $FF] xor sTable[0,(n2+KeyData[3]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[4]) shr 24] xor sTable[2,((n1+KeyData[4]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[4]) shr 24] xor sTable[2,((n1+KeyData[4]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[4]) shr 8) and $FF] xor sTable[0,(n1+KeyData[4]) and $FF]); xor sTable[1,((n1+KeyData[4]) shr 8) and $FF] xor sTable[0,(n1+KeyData[4]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[5]) shr 24] xor sTable[2,((n2+KeyData[5]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[5]) shr 24] xor sTable[2,((n2+KeyData[5]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[5]) shr 8) and $FF] xor sTable[0,(n2+KeyData[5]) and $FF]); xor sTable[1,((n2+KeyData[5]) shr 8) and $FF] xor sTable[0,(n2+KeyData[5]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[6]) shr 24] xor sTable[2,((n1+KeyData[6]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[6]) shr 24] xor sTable[2,((n1+KeyData[6]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[6]) shr 8) and $FF] xor sTable[0,(n1+KeyData[6]) and $FF]); xor sTable[1,((n1+KeyData[6]) shr 8) and $FF] xor sTable[0,(n1+KeyData[6]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[7]) shr 24] xor sTable[2,((n2+KeyData[7]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[7]) shr 24] xor sTable[2,((n2+KeyData[7]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[7]) shr 8) and $FF] xor sTable[0,(n2+KeyData[7]) and $FF]); xor sTable[1,((n2+KeyData[7]) shr 8) and $FF] xor sTable[0,(n2+KeyData[7]) and $FF]);
for i:= 0 to 2 do for i:= 0 to 2 do
begin begin
n2:= n2 xor (sTable[3,(n1+KeyData[7]) shr 24] xor sTable[2,((n1+KeyData[7]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[7]) shr 24] xor sTable[2,((n1+KeyData[7]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[7]) shr 8) and $FF] xor sTable[0,(n1+KeyData[7]) and $FF]); xor sTable[1,((n1+KeyData[7]) shr 8) and $FF] xor sTable[0,(n1+KeyData[7]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[6]) shr 24] xor sTable[2,((n2+KeyData[6]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[6]) shr 24] xor sTable[2,((n2+KeyData[6]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[6]) shr 8) and $FF] xor sTable[0,(n2+KeyData[6]) and $FF]); xor sTable[1,((n2+KeyData[6]) shr 8) and $FF] xor sTable[0,(n2+KeyData[6]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[5]) shr 24] xor sTable[2,((n1+KeyData[5]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[5]) shr 24] xor sTable[2,((n1+KeyData[5]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[5]) shr 8) and $FF] xor sTable[0,(n1+KeyData[5]) and $FF]); xor sTable[1,((n1+KeyData[5]) shr 8) and $FF] xor sTable[0,(n1+KeyData[5]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[4]) shr 24] xor sTable[2,((n2+KeyData[4]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[4]) shr 24] xor sTable[2,((n2+KeyData[4]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[4]) shr 8) and $FF] xor sTable[0,(n2+KeyData[4]) and $FF]); xor sTable[1,((n2+KeyData[4]) shr 8) and $FF] xor sTable[0,(n2+KeyData[4]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[3]) shr 24] xor sTable[2,((n1+KeyData[3]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[3]) shr 24] xor sTable[2,((n1+KeyData[3]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[3]) shr 8) and $FF] xor sTable[0,(n1+KeyData[3]) and $FF]); xor sTable[1,((n1+KeyData[3]) shr 8) and $FF] xor sTable[0,(n1+KeyData[3]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[2]) shr 24] xor sTable[2,((n2+KeyData[2]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[2]) shr 24] xor sTable[2,((n2+KeyData[2]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[2]) shr 8) and $FF] xor sTable[0,(n2+KeyData[2]) and $FF]); xor sTable[1,((n2+KeyData[2]) shr 8) and $FF] xor sTable[0,(n2+KeyData[2]) and $FF]);
n2:= n2 xor (sTable[3,(n1+KeyData[1]) shr 24] xor sTable[2,((n1+KeyData[1]) shr 16) and $FF] n2:= n2 xor (sTable[3,(n1+KeyData[1]) shr 24] xor sTable[2,((n1+KeyData[1]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[1]) shr 8) and $FF] xor sTable[0,(n1+KeyData[1]) and $FF]); xor sTable[1,((n1+KeyData[1]) shr 8) and $FF] xor sTable[0,(n1+KeyData[1]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[0]) shr 24] xor sTable[2,((n2+KeyData[0]) shr 16) and $FF] n1:= n1 xor (sTable[3,(n2+KeyData[0]) shr 24] xor sTable[2,((n2+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]); xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]);
end; end;
PDword(@OutData)^:= n2; PDword(@OutData)^:= n2;
PDword(pointer(@OutData)+4)^:= n1; PDword(pointer(@OutData)+4)^:= n1;
end; end;
end. end.

View File

@ -1,448 +1,448 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Ice and it's variants ****************} {* A binary compatible implementation of Ice and it's variants ****************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPice; unit DCPice;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_customice= class(TDCP_blockcipher64) TDCP_customice= class(TDCP_blockcipher64)
protected protected
rounds: dword; rounds: dword;
ik_keysched: array[0..31,0..2] of dword; ik_keysched: array[0..31,0..2] of dword;
function f(p, sk: dword): dword; function f(p, sk: dword): dword;
procedure key_sched_build(kb: pwordarray; n: dword; keyrot: pdwordarray); procedure key_sched_build(kb: pwordarray; n: dword; keyrot: pdwordarray);
procedure InitIce(const Key; Size: longword; n: dword); procedure InitIce(const Key; Size: longword; n: dword);
public public
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
end; end;
TDCP_ice= class(TDCP_customice) TDCP_ice= class(TDCP_customice)
protected protected
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
end; end;
TDCP_thinice= class(TDCP_customice) TDCP_thinice= class(TDCP_customice)
protected protected
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
end; end;
TDCP_ice2= class(TDCP_customice) TDCP_ice2= class(TDCP_customice)
protected protected
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
var var
ice_sbox: array[0..3,0..1023] of dword; ice_sbox: array[0..3,0..1023] of dword;
ice_sboxdone: boolean; ice_sboxdone: boolean;
const const
ice_smod: array[0..3,0..3] of dword= ( ice_smod: array[0..3,0..3] of dword= (
(333, 313, 505, 369), (333, 313, 505, 369),
(379, 375, 319, 391), (379, 375, 319, 391),
(361, 445, 451, 397), (361, 445, 451, 397),
(397, 425, 395, 505)); (397, 425, 395, 505));
ice_sxor: array[0..3,0..3] of dword= ( ice_sxor: array[0..3,0..3] of dword= (
($83, $85, $9b, $cd), ($83, $85, $9b, $cd),
($cc, $a7, $ad, $41), ($cc, $a7, $ad, $41),
($4b, $2e, $d4, $33), ($4b, $2e, $d4, $33),
($ea, $cb, $2e, $04)); ($ea, $cb, $2e, $04));
ice_keyrot: array[0..15] of dword= ( ice_keyrot: array[0..15] of dword= (
0, 1, 2, 3, 2, 1, 3, 0, 0, 1, 2, 3, 2, 1, 3, 0,
1, 3, 2, 0, 3, 1, 0, 2); 1, 3, 2, 0, 3, 1, 0, 2);
ice_pbox: array[0..31] of dword= ( ice_pbox: array[0..31] of dword= (
$00000001, $00000080, $00000400, $00002000, $00000001, $00000080, $00000400, $00002000,
$00080000, $00200000, $01000000, $40000000, $00080000, $00200000, $01000000, $40000000,
$00000008, $00000020, $00000100, $00004000, $00000008, $00000020, $00000100, $00004000,
$00010000, $00800000, $04000000, $20000000, $00010000, $00800000, $04000000, $20000000,
$00000004, $00000010, $00000200, $00008000, $00000004, $00000010, $00000200, $00008000,
$00020000, $00400000, $08000000, $10000000, $00020000, $00400000, $08000000, $10000000,
$00000002, $00000040, $00000800, $00001000, $00000002, $00000040, $00000800, $00001000,
$00040000, $00100000, $02000000, $80000000); $00040000, $00100000, $02000000, $80000000);
function SwapDword(a: dword): dword; function SwapDword(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
{******************************************************************************} {******************************************************************************}
function gf_mult(a, b, m: dword): dword; function gf_mult(a, b, m: dword): dword;
var var
res: dword; res: dword;
begin begin
res:= 0; res:= 0;
while b<> 0 do while b<> 0 do
begin begin
if (b and 1)<> 0 then if (b and 1)<> 0 then
res:= res xor a; res:= res xor a;
a:= a shl 1; a:= a shl 1;
b:= b shr 1; b:= b shr 1;
if a>= 256 then if a>= 256 then
a:= a xor m; a:= a xor m;
end; end;
Result:= res; Result:= res;
end; end;
function gf_exp7(b, m: dword): dword; function gf_exp7(b, m: dword): dword;
var var
x: dword; x: dword;
begin begin
if b= 0 then if b= 0 then
Result:= 0 Result:= 0
else else
begin begin
x:= gf_mult(b,b,m); x:= gf_mult(b,b,m);
x:= gf_mult(b,x,m); x:= gf_mult(b,x,m);
x:= gf_mult(x,x,m); x:= gf_mult(x,x,m);
Result:= gf_mult(b,x,m); Result:= gf_mult(b,x,m);
end; end;
end; end;
function ice_perm32(x: dword): dword; function ice_perm32(x: dword): dword;
var var
res: dword; res: dword;
pbox: pdword; pbox: pdword;
begin begin
res:= 0; res:= 0;
pbox:= @ice_pbox; pbox:= @ice_pbox;
while x<> 0 do while x<> 0 do
begin begin
if (x and 1)<> 0 then if (x and 1)<> 0 then
res:= res or pbox^; res:= res or pbox^;
Inc(pbox); Inc(pbox);
x:= x shr 1; x:= x shr 1;
end; end;
Result:= res; Result:= res;
end; end;
procedure ice_sboxes_init; procedure ice_sboxes_init;
var var
i, col, row: dword; i, col, row: dword;
x: dword; x: dword;
begin begin
for i:= 0 to 1023 do for i:= 0 to 1023 do
begin begin
col:= (i shr 1) and $FF; col:= (i shr 1) and $FF;
row:= (i and 1) or ((i and $200) shr 8); row:= (i and 1) or ((i and $200) shr 8);
x:= gf_exp7(col xor ice_sxor[0,row],ice_smod[0,row]) shl 24; x:= gf_exp7(col xor ice_sxor[0,row],ice_smod[0,row]) shl 24;
ice_sbox[0,i]:= ice_perm32(x); ice_sbox[0,i]:= ice_perm32(x);
x:= gf_exp7(col xor ice_sxor[1,row],ice_smod[1,row]) shl 16; x:= gf_exp7(col xor ice_sxor[1,row],ice_smod[1,row]) shl 16;
ice_sbox[1,i]:= ice_perm32(x); ice_sbox[1,i]:= ice_perm32(x);
x:= gf_exp7(col xor ice_sxor[2,row],ice_smod[2,row]) shl 8; x:= gf_exp7(col xor ice_sxor[2,row],ice_smod[2,row]) shl 8;
ice_sbox[2,i]:= ice_perm32(x); ice_sbox[2,i]:= ice_perm32(x);
x:= gf_exp7(col xor ice_sxor[3,row],ice_smod[3,row]); x:= gf_exp7(col xor ice_sxor[3,row],ice_smod[3,row]);
ice_sbox[3,i]:= ice_perm32(x); ice_sbox[3,i]:= ice_perm32(x);
end; end;
end; end;
function TDCP_customice.f(p, sk: dword): dword; function TDCP_customice.f(p, sk: dword): dword;
var var
tl, tr, al, ar: dword; tl, tr, al, ar: dword;
begin begin
tl:= ((p shr 16) and $3ff) or (((p shr 14) or (p shl 18)) and $ffc00); tl:= ((p shr 16) and $3ff) or (((p shr 14) or (p shl 18)) and $ffc00);
tr:= (p and $3ff) or ((p shl 2) and $ffc00); tr:= (p and $3ff) or ((p shl 2) and $ffc00);
al:= ik_keysched[sk,2] and (tl xor tr); al:= ik_keysched[sk,2] and (tl xor tr);
ar:= al xor tr; ar:= al xor tr;
al:= al xor tl; al:= al xor tl;
al:= al xor ik_keysched[sk,0]; al:= al xor ik_keysched[sk,0];
ar:= ar xor ik_keysched[sk,1]; ar:= ar xor ik_keysched[sk,1];
Result:= ice_sbox[0,al shr 10] or ice_sbox[1,al and $3ff] or Result:= ice_sbox[0,al shr 10] or ice_sbox[1,al and $3ff] or
ice_sbox[2,ar shr 10] or ice_sbox[3,ar and $3ff]; ice_sbox[2,ar shr 10] or ice_sbox[3,ar and $3ff];
end; end;
procedure TDCP_customice.key_sched_build(kb: pwordarray; n: dword; keyrot: pdwordarray); procedure TDCP_customice.key_sched_build(kb: pwordarray; n: dword; keyrot: pdwordarray);
var var
i, j, k, kr: dword; i, j, k, kr: dword;
keys: pdwordarray; keys: pdwordarray;
currentsk: pdword; currentsk: pdword;
currentkb: pword; currentkb: pword;
bit: dword; bit: dword;
begin begin
for i:= 0 to 7 do for i:= 0 to 7 do
begin begin
kr:= keyrot^[i]; kr:= keyrot^[i];
keys:= @ik_keysched[n+i]; keys:= @ik_keysched[n+i];
for j:= 0 to 2 do for j:= 0 to 2 do
keys^[j]:= 0; keys^[j]:= 0;
for j:= 0 to 14 do for j:= 0 to 14 do
begin begin
currentsk:= @keys^[j mod 3]; currentsk:= @keys^[j mod 3];
for k:= 0 to 3 do for k:= 0 to 3 do
begin begin
currentkb:= @kb^[(kr + k) and 3]; currentkb:= @kb^[(kr + k) and 3];
bit:= currentkb^ and 1; bit:= currentkb^ and 1;
currentsk^:= (currentsk^ shl 1) or bit; currentsk^:= (currentsk^ shl 1) or bit;
currentkb^:= (currentkb^ shr 1) or ((bit xor 1) shl 15); currentkb^:= (currentkb^ shr 1) or ((bit xor 1) shl 15);
end; end;
end; end;
end; end;
end; end;
procedure TDCP_customice.InitIce(const Key; Size: longword; n: dword); procedure TDCP_customice.InitIce(const Key; Size: longword; n: dword);
var var
i, j: dword; i, j: dword;
kb: array[0..3] of word; kb: array[0..3] of word;
keyb: array[0..15] of byte; keyb: array[0..15] of byte;
begin begin
dcpFillChar(keyb,Sizeof(keyb),0); dcpFillChar(keyb,Sizeof(keyb),0);
Move(key,keyb,Size div 8); Move(key,keyb,Size div 8);
if n> 0 then if n> 0 then
rounds:= 16 * n rounds:= 16 * n
else else
rounds:= 8; rounds:= 8;
if rounds= 8 then if rounds= 8 then
begin begin
for i:= 0 to 4 do for i:= 0 to 4 do
kb[3 - i]:= (keyb[i*2] shl 8) or keyb[i*2 + 1]; kb[3 - i]:= (keyb[i*2] shl 8) or keyb[i*2 + 1];
key_sched_build(@kb,0,@ice_keyrot); key_sched_build(@kb,0,@ice_keyrot);
end end
else else
begin begin
for i:= 0 to (n-1) do for i:= 0 to (n-1) do
begin begin
for j:= 0 to 3 do for j:= 0 to 3 do
kb[3-j]:= (keyb[i*8 + j*2] shl 8) or keyb[i*8 + j*2 + 1]; kb[3-j]:= (keyb[i*8 + j*2] shl 8) or keyb[i*8 + j*2 + 1];
key_sched_build(@kb,i*8,@ice_keyrot); key_sched_build(@kb,i*8,@ice_keyrot);
key_sched_build(@kb,rounds - 8 - i*8,@ice_keyrot[8]); key_sched_build(@kb,rounds - 8 - i*8,@ice_keyrot[8]);
end; end;
end; end;
end; end;
procedure TDCP_customice.Burn; procedure TDCP_customice.Burn;
begin begin
FillChar(ik_keysched,Sizeof(ik_keysched),0); FillChar(ik_keysched,Sizeof(ik_keysched),0);
Rounds:= 0; Rounds:= 0;
inherited Burn; inherited Burn;
end; end;
procedure TDCP_customice.EncryptECB(const InData; var OutData); procedure TDCP_customice.EncryptECB(const InData; var OutData);
var var
i, l, r: dword; i, l, r: dword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
l:= SwapDWord(Pdword(@InData)^); l:= SwapDWord(Pdword(@InData)^);
r:= SwapDWord(Pdword(pointer(@InData)+4)^); r:= SwapDWord(Pdword(pointer(@InData)+4)^);
i:= 0; i:= 0;
while i< rounds do while i< rounds do
begin begin
l:= l xor f(r,i); l:= l xor f(r,i);
r:= r xor f(l,i+1); r:= r xor f(l,i+1);
Inc(i,2); Inc(i,2);
end; end;
Pdword(@OutData)^:= SwapDWord(r); Pdword(@OutData)^:= SwapDWord(r);
Pdword(pointer(@OutData)+4)^:= SwapDWord(l); Pdword(pointer(@OutData)+4)^:= SwapDWord(l);
end; end;
procedure TDCP_customice.DecryptECB(const InData; var OutData); procedure TDCP_customice.DecryptECB(const InData; var OutData);
var var
l, r: dword; l, r: dword;
i: integer; i: integer;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
l:= SwapDWord(Pdword(@InData)^); l:= SwapDWord(Pdword(@InData)^);
r:= SwapDWord(Pdword(pointer(@InData)+4)^); r:= SwapDWord(Pdword(pointer(@InData)+4)^);
i:= rounds-1; i:= rounds-1;
while i> 0 do while i> 0 do
begin begin
l:= l xor f(r,i); l:= l xor f(r,i);
r:= r xor f(l,i-1); r:= r xor f(l,i-1);
Dec(i,2); Dec(i,2);
end; end;
Pdword(@OutData)^:= SwapDWord(r); Pdword(@OutData)^:= SwapDWord(r);
Pdword(pointer(@OutData)+4)^:= SwapDWord(l); Pdword(pointer(@OutData)+4)^:= SwapDWord(l);
end; end;
constructor TDCP_customice.Create(AOwner: TComponent); constructor TDCP_customice.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
if not ice_sboxdone then if not ice_sboxdone then
begin begin
ice_sboxes_init; ice_sboxes_init;
ice_sboxdone:= true; ice_sboxdone:= true;
end; end;
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_ice.GetMaxKeySize: integer; class function TDCP_ice.GetMaxKeySize: integer;
begin begin
Result:= 64; Result:= 64;
end; end;
class function TDCP_ice.GetID: integer; class function TDCP_ice.GetID: integer;
begin begin
Result:= DCP_ice; Result:= DCP_ice;
end; end;
class function TDCP_ice.GetAlgorithm: string; class function TDCP_ice.GetAlgorithm: string;
begin begin
Result:= 'Ice'; Result:= 'Ice';
end; end;
class function TDCP_ice.SelfTest: boolean; class function TDCP_ice.SelfTest: boolean;
const const
Key1: array[0..7] of byte= ($de,$ad,$be,$ef,$01,$23,$45,$67); Key1: array[0..7] of byte= ($de,$ad,$be,$ef,$01,$23,$45,$67);
InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10); InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10);
OutData1: array[0..7] of byte= ($7d,$6e,$f1,$ef,$30,$d4,$7a,$96); OutData1: array[0..7] of byte= ($7d,$6e,$f1,$ef,$30,$d4,$7a,$96);
var var
Cipher: TDCP_ice; Cipher: TDCP_ice;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_ice.Create(nil); Cipher:= TDCP_ice.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.Reset; Cipher.Reset;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_ice.InitKey(const Key; Size: longword); procedure TDCP_ice.InitKey(const Key; Size: longword);
begin begin
InitIce(Key,Size,1); InitIce(Key,Size,1);
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_thinice.GetMaxKeySize: integer; class function TDCP_thinice.GetMaxKeySize: integer;
begin begin
Result:= 64; Result:= 64;
end; end;
class function TDCP_thinice.GetID: integer; class function TDCP_thinice.GetID: integer;
begin begin
Result:= DCP_thinice; Result:= DCP_thinice;
end; end;
class function TDCP_thinice.GetAlgorithm: string; class function TDCP_thinice.GetAlgorithm: string;
begin begin
Result:= 'Thin Ice'; Result:= 'Thin Ice';
end; end;
class function TDCP_thinice.SelfTest: boolean; class function TDCP_thinice.SelfTest: boolean;
const const
Key1: array[0..7] of byte= ($de,$ad,$be,$ef,$01,$23,$45,$67); Key1: array[0..7] of byte= ($de,$ad,$be,$ef,$01,$23,$45,$67);
InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10); InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10);
OutData1: array[0..7] of byte= ($de,$24,$0d,$83,$a0,$0a,$9c,$c0); OutData1: array[0..7] of byte= ($de,$24,$0d,$83,$a0,$0a,$9c,$c0);
var var
Cipher: TDCP_thinice; Cipher: TDCP_thinice;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_thinice.Create(nil); Cipher:= TDCP_thinice.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.Reset; Cipher.Reset;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_thinice.InitKey(const Key; Size: longword); procedure TDCP_thinice.InitKey(const Key; Size: longword);
begin begin
InitIce(Key,Size,0); InitIce(Key,Size,0);
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_ice2.GetMaxKeySize: integer; class function TDCP_ice2.GetMaxKeySize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_ice2.GetID: integer; class function TDCP_ice2.GetID: integer;
begin begin
Result:= DCP_ice2; Result:= DCP_ice2;
end; end;
class function TDCP_ice2.GetAlgorithm: string; class function TDCP_ice2.GetAlgorithm: string;
begin begin
Result:= 'Ice2'; Result:= 'Ice2';
end; end;
class function TDCP_ice2.SelfTest: boolean; class function TDCP_ice2.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff); ($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff);
InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10); InData1: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10);
OutData1: array[0..7] of byte= ($f9,$48,$40,$d8,$69,$72,$f2,$1c); OutData1: array[0..7] of byte= ($f9,$48,$40,$d8,$69,$72,$f2,$1c);
var var
Cipher: TDCP_ice2; Cipher: TDCP_ice2;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_ice2.Create(nil); Cipher:= TDCP_ice2.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.Reset; Cipher.Reset;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_ice2.InitKey(const Key; Size: longword); procedure TDCP_ice2.InitKey(const Key; Size: longword);
begin begin
InitIce(Key,Size,2); InitIce(Key,Size,2);
end; end;
initialization initialization
ice_sboxdone:= false; ice_sboxdone:= false;
end. end.

View File

@ -1,298 +1,298 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of IDEA *********************************} {* A binary compatible implementation of IDEA *********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPidea; unit DCPidea;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_idea= class(TDCP_blockcipher64) TDCP_idea= class(TDCP_blockcipher64)
protected protected
EK, DK: array[0..51] of word; EK, DK: array[0..51] of word;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
class function TDCP_idea.GetMaxKeySize: integer; class function TDCP_idea.GetMaxKeySize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_idea.GetID: integer; class function TDCP_idea.GetID: integer;
begin begin
Result:= DCP_idea; Result:= DCP_idea;
end; end;
class function TDCP_idea.GetAlgorithm: string; class function TDCP_idea.GetAlgorithm: string;
begin begin
Result:= 'IDEA'; Result:= 'IDEA';
end; end;
class function TDCP_idea.SelfTest: boolean; class function TDCP_idea.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($3A,$98,$4E,$20,$00,$19,$5D,$B3,$2E,$E5,$01,$C8,$C4,$7C,$EA,$60); ($3A,$98,$4E,$20,$00,$19,$5D,$B3,$2E,$E5,$01,$C8,$C4,$7C,$EA,$60);
InData1: array[0..7] of byte= InData1: array[0..7] of byte=
($01,$02,$03,$04,$05,$06,$07,$08); ($01,$02,$03,$04,$05,$06,$07,$08);
OutData1: array[0..7] of byte= OutData1: array[0..7] of byte=
($97,$BC,$D8,$20,$07,$80,$DA,$86); ($97,$BC,$D8,$20,$07,$80,$DA,$86);
Key2: array[0..15] of byte= Key2: array[0..15] of byte=
($00,$64,$00,$C8,$01,$2C,$01,$90,$01,$F4,$02,$58,$02,$BC,$03,$20); ($00,$64,$00,$C8,$01,$2C,$01,$90,$01,$F4,$02,$58,$02,$BC,$03,$20);
InData2: array[0..7] of byte= InData2: array[0..7] of byte=
($05,$32,$0A,$64,$14,$C8,$19,$FA); ($05,$32,$0A,$64,$14,$C8,$19,$FA);
OutData2: array[0..7] of byte= OutData2: array[0..7] of byte=
($65,$BE,$87,$E7,$A2,$53,$8A,$ED); ($65,$BE,$87,$E7,$A2,$53,$8A,$ED);
var var
Cipher: TDCP_idea; Cipher: TDCP_idea;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_idea.Create(nil); Cipher:= TDCP_idea.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@InData1,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@InData1,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Data); Cipher.EncryptECB(InData2,Data);
Result:= Result and boolean(CompareMem(@Data,@OutData2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@OutData2,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@InData2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@InData2,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
function MulInv(x: word): word; function MulInv(x: word): word;
var var
t0, t1, q, y: word; t0, t1, q, y: word;
begin begin
if x<= 1 then if x<= 1 then
begin begin
Result:= x; Result:= x;
Exit; Exit;
end; end;
t1:= DWord($10001) div x; t1:= DWord($10001) div x;
y:= DWord($10001) mod x; y:= DWord($10001) mod x;
if y= 1 then if y= 1 then
begin begin
Result:= (1 - t1) and $FFFF; Result:= (1 - t1) and $FFFF;
Exit; Exit;
end; end;
t0:= 1; t0:= 1;
repeat repeat
q:= x div y; q:= x div y;
x:= x mod y; x:= x mod y;
t0:= t0 + (q*t1); t0:= t0 + (q*t1);
if x= 1 then if x= 1 then
begin begin
Result:= t0; Result:= t0;
Exit; Exit;
end; end;
q:= y div x; q:= y div x;
y:= y mod x; y:= y mod x;
t1:= t1 + (q*t0); t1:= t1 + (q*t0);
until y= 1; until y= 1;
Result:= (1-t1) and $FFFF; Result:= (1-t1) and $FFFF;
end; end;
procedure TDCP_idea.InitKey(const Key; Size: longword); procedure TDCP_idea.InitKey(const Key; Size: longword);
var var
i: integer; i: integer;
begin begin
Size:= Size div 8; Size:= Size div 8;
FillChar(EK,Sizeof(EK),0); FillChar(EK,Sizeof(EK),0);
Move(Key,EK,Size); Move(Key,EK,Size);
for i:= 0 to 7 do for i:= 0 to 7 do
EK[i]:= (EK[i] shl 8) or (EK[i] shr 8); EK[i]:= (EK[i] shl 8) or (EK[i] shr 8);
for i:= 1 to 5 do for i:= 1 to 5 do
begin begin
EK[(i*8)+0]:= (EK[((i-1)*8)+1] shl 9) or (EK[((i-1)*8)+2] shr 7); EK[(i*8)+0]:= (EK[((i-1)*8)+1] shl 9) or (EK[((i-1)*8)+2] shr 7);
EK[(i*8)+1]:= (EK[((i-1)*8)+2] shl 9) or (EK[((i-1)*8)+3] shr 7); EK[(i*8)+1]:= (EK[((i-1)*8)+2] shl 9) or (EK[((i-1)*8)+3] shr 7);
EK[(i*8)+2]:= (EK[((i-1)*8)+3] shl 9) or (EK[((i-1)*8)+4] shr 7); EK[(i*8)+2]:= (EK[((i-1)*8)+3] shl 9) or (EK[((i-1)*8)+4] shr 7);
EK[(i*8)+3]:= (EK[((i-1)*8)+4] shl 9) or (EK[((i-1)*8)+5] shr 7); EK[(i*8)+3]:= (EK[((i-1)*8)+4] shl 9) or (EK[((i-1)*8)+5] shr 7);
EK[(i*8)+4]:= (EK[((i-1)*8)+5] shl 9) or (EK[((i-1)*8)+6] shr 7); EK[(i*8)+4]:= (EK[((i-1)*8)+5] shl 9) or (EK[((i-1)*8)+6] shr 7);
EK[(i*8)+5]:= (EK[((i-1)*8)+6] shl 9) or (EK[((i-1)*8)+7] shr 7); EK[(i*8)+5]:= (EK[((i-1)*8)+6] shl 9) or (EK[((i-1)*8)+7] shr 7);
EK[(i*8)+6]:= (EK[((i-1)*8)+7] shl 9) or (EK[((i-1)*8)+0] shr 7); EK[(i*8)+6]:= (EK[((i-1)*8)+7] shl 9) or (EK[((i-1)*8)+0] shr 7);
EK[(i*8)+7]:= (EK[((i-1)*8)+0] shl 9) or (EK[((i-1)*8)+1] shr 7); EK[(i*8)+7]:= (EK[((i-1)*8)+0] shl 9) or (EK[((i-1)*8)+1] shr 7);
end; end;
EK[48]:= (EK[41] shl 9) or (EK[42] shr 7); EK[48]:= (EK[41] shl 9) or (EK[42] shr 7);
EK[49]:= (EK[42] shl 9) or (EK[43] shr 7); EK[49]:= (EK[42] shl 9) or (EK[43] shr 7);
EK[50]:= (EK[43] shl 9) or (EK[44] shr 7); EK[50]:= (EK[43] shl 9) or (EK[44] shr 7);
EK[51]:= (EK[44] shl 9) or (EK[45] shr 7); EK[51]:= (EK[44] shl 9) or (EK[45] shr 7);
DK[51]:= MulInv(EK[3]); DK[51]:= MulInv(EK[3]);
DK[50]:= -EK[2]; DK[50]:= -EK[2];
DK[49]:= -EK[1]; DK[49]:= -EK[1];
DK[48]:= MulInv(EK[0]); DK[48]:= MulInv(EK[0]);
for i:= 0 to 6 do for i:= 0 to 6 do
begin begin
DK[47-i*6]:= EK[i*6+5]; DK[47-i*6]:= EK[i*6+5];
DK[46-i*6]:= EK[i*6+4]; DK[46-i*6]:= EK[i*6+4];
DK[45-i*6]:= MulInv(EK[i*6+9]); DK[45-i*6]:= MulInv(EK[i*6+9]);
DK[44-i*6]:= -EK[i*6+7]; DK[44-i*6]:= -EK[i*6+7];
DK[43-i*6]:= -EK[i*6+8]; DK[43-i*6]:= -EK[i*6+8];
DK[42-i*6]:= MulInv(EK[i*6+6]); DK[42-i*6]:= MulInv(EK[i*6+6]);
end; end;
DK[5]:= EK[47]; DK[5]:= EK[47];
DK[4]:= EK[46]; DK[4]:= EK[46];
DK[3]:= MulInv(EK[51]); DK[3]:= MulInv(EK[51]);
DK[2]:= -EK[50]; DK[2]:= -EK[50];
DK[1]:= -EK[49]; DK[1]:= -EK[49];
DK[0]:= MulInv(EK[48]); DK[0]:= MulInv(EK[48]);
end; end;
procedure TDCP_idea.Burn; procedure TDCP_idea.Burn;
begin begin
FillChar(EK,Sizeof(EK),0); FillChar(EK,Sizeof(EK),0);
FillChar(DK,Sizeof(DK),0); FillChar(DK,Sizeof(DK),0);
inherited Burn; inherited Burn;
end; end;
procedure Mul(var x: word; const y: word); procedure Mul(var x: word; const y: word);
var var
p: DWord; p: DWord;
t16: word; t16: word;
begin begin
p:= DWord(x)*y; p:= DWord(x)*y;
if p= 0 then if p= 0 then
x:= 1 - x - y x:= 1 - x - y
else else
begin begin
x:= p shr 16; x:= p shr 16;
t16:= p and $FFFF; t16:= p and $FFFF;
x:= t16 - x; x:= t16 - x;
if (t16 < x) then if (t16 < x) then
Inc(x); Inc(x);
end; end;
end; end;
procedure TDCP_idea.EncryptECB(const InData; var OutData); procedure TDCP_idea.EncryptECB(const InData; var OutData);
var var
x: array[1..4] of word; x: array[1..4] of word;
s3, s2: word; s3, s2: word;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@X[1])^:= PDword(@InData)^; PDword(@X[1])^:= PDword(@InData)^;
PDword(@X[3])^:= PDword(pointer(@InData)+4)^; PDword(@X[3])^:= PDword(pointer(@InData)+4)^;
for i:= 1 to 4 do for i:= 1 to 4 do
x[i]:= (x[i] shl 8) or (x[i] shr 8); x[i]:= (x[i] shl 8) or (x[i] shr 8);
for i:= 0 to 7 do for i:= 0 to 7 do
begin begin
Mul(x[1],EK[(i*6)+0]); Mul(x[1],EK[(i*6)+0]);
Inc(x[2],EK[(i*6)+1]); Inc(x[2],EK[(i*6)+1]);
Inc(x[3],EK[(i*6)+2]); Inc(x[3],EK[(i*6)+2]);
Mul(x[4],EK[(i*6)+3]); Mul(x[4],EK[(i*6)+3]);
s3:= x[3]; s3:= x[3];
x[3]:= x[3] xor x[1]; x[3]:= x[3] xor x[1];
Mul(x[3],EK[(i*6)+4]); Mul(x[3],EK[(i*6)+4]);
s2:= x[2]; s2:= x[2];
x[2]:= x[2] xor x[4]; x[2]:= x[2] xor x[4];
Inc(x[2],x[3]); Inc(x[2],x[3]);
Mul(x[2],EK[(i*6)+5]); Mul(x[2],EK[(i*6)+5]);
Inc(x[3],x[2]); Inc(x[3],x[2]);
x[1]:= x[1] xor x[2]; x[1]:= x[1] xor x[2];
x[4]:= x[4] xor x[3]; x[4]:= x[4] xor x[3];
x[2]:= x[2] xor s3; x[2]:= x[2] xor s3;
x[3]:= x[3] xor s2; x[3]:= x[3] xor s2;
end; end;
Mul(x[1],EK[48]); Mul(x[1],EK[48]);
Inc(x[3],EK[49]); Inc(x[3],EK[49]);
Inc(x[2],EK[50]); Inc(x[2],EK[50]);
Mul(x[4],EK[51]); Mul(x[4],EK[51]);
x[1]:= (x[1] shl 8) or (x[1] shr 8); x[1]:= (x[1] shl 8) or (x[1] shr 8);
s2:= (x[3] shl 8) or (x[3] shr 8); s2:= (x[3] shl 8) or (x[3] shr 8);
x[3]:= (x[2] shl 8) or (x[2] shr 8); x[3]:= (x[2] shl 8) or (x[2] shr 8);
x[4]:= (x[4] shl 8) or (x[4] shr 8); x[4]:= (x[4] shl 8) or (x[4] shr 8);
x[2]:= s2; x[2]:= s2;
PDword(@OutData)^:= PDword(@x[1])^; PDword(@OutData)^:= PDword(@x[1])^;
PDword(pointer(@OutData)+4)^:= PDword(@x[3])^; PDword(pointer(@OutData)+4)^:= PDword(@x[3])^;
end; end;
procedure TDCP_idea.DecryptECB(const InData; var OutData); procedure TDCP_idea.DecryptECB(const InData; var OutData);
var var
x: array[1..4] of word; x: array[1..4] of word;
s3, s2: word; s3, s2: word;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@X[1])^:= PDword(@InData)^; PDword(@X[1])^:= PDword(@InData)^;
PDword(@X[3])^:= PDword(pointer(@InData)+4)^; PDword(@X[3])^:= PDword(pointer(@InData)+4)^;
for i:= 1 to 4 do for i:= 1 to 4 do
x[i]:= (x[i] shl 8) or (x[i] shr 8); x[i]:= (x[i] shl 8) or (x[i] shr 8);
for i:= 0 to 7 do for i:= 0 to 7 do
begin begin
Mul(x[1],DK[(i*6)+0]); Mul(x[1],DK[(i*6)+0]);
Inc(x[2],DK[(i*6)+1]); Inc(x[2],DK[(i*6)+1]);
Inc(x[3],DK[(i*6)+2]); Inc(x[3],DK[(i*6)+2]);
Mul(x[4],DK[(i*6)+3]); Mul(x[4],DK[(i*6)+3]);
s3:= x[3]; s3:= x[3];
x[3]:= x[3] xor x[1]; x[3]:= x[3] xor x[1];
Mul(x[3],DK[(i*6)+4]); Mul(x[3],DK[(i*6)+4]);
s2:= x[2]; s2:= x[2];
x[2]:= x[2] xor x[4]; x[2]:= x[2] xor x[4];
Inc(x[2],x[3]); Inc(x[2],x[3]);
Mul(x[2],DK[(i*6)+5]); Mul(x[2],DK[(i*6)+5]);
Inc(x[3],x[2]); Inc(x[3],x[2]);
x[1]:= x[1] xor x[2]; x[1]:= x[1] xor x[2];
x[4]:= x[4] xor x[3]; x[4]:= x[4] xor x[3];
x[2]:= x[2] xor s3; x[2]:= x[2] xor s3;
x[3]:= x[3] xor s2; x[3]:= x[3] xor s2;
end; end;
Mul(x[1],DK[48]); Mul(x[1],DK[48]);
Inc(x[3],DK[49]); Inc(x[3],DK[49]);
Inc(x[2],DK[50]); Inc(x[2],DK[50]);
Mul(x[4],DK[51]); Mul(x[4],DK[51]);
x[1]:= (x[1] shl 8) or (x[1] shr 8); x[1]:= (x[1] shl 8) or (x[1] shr 8);
s2:= (x[3] shl 8) or (x[3] shr 8); s2:= (x[3] shl 8) or (x[3] shr 8);
x[3]:= (x[2] shl 8) or (x[2] shr 8); x[3]:= (x[2] shl 8) or (x[2] shr 8);
x[4]:= (x[4] shl 8) or (x[4] shr 8); x[4]:= (x[4] shl 8) or (x[4] shr 8);
x[2]:= s2; x[2]:= s2;
PDword(@OutData)^:= PDword(@x[1])^; PDword(@OutData)^:= PDword(@x[1])^;
PDword(pointer(@OutData)+4)^:= PDword(@x[3])^; PDword(pointer(@OutData)+4)^:= PDword(@x[3])^;
end; end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -1,262 +1,262 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Misty1 *******************************} {* A binary compatible implementation of Misty1 *******************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPmisty1; unit DCPmisty1;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
const const
NUMROUNDS= 8; NUMROUNDS= 8;
type type
TDCP_misty1= class(TDCP_blockcipher64) TDCP_misty1= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..31] of DWord; KeyData: array[0..31] of DWord;
function FI(const FI_IN, FI_KEY: DWord): DWord; function FI(const FI_IN, FI_KEY: DWord): DWord;
function FO(const FO_IN: DWord; const k: longword): DWord; function FO(const FO_IN: DWord; const k: longword): DWord;
function FL(const FL_IN: DWord; const k: longword): DWord; function FL(const FL_IN: DWord; const k: longword): DWord;
function FLINV(const FL_IN: DWord; const k: longword): DWord; function FLINV(const FL_IN: DWord; const k: longword): DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPmisty1.inc} {$I DCPmisty1.inc}
function SwapDword(a: dword): dword; function SwapDword(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
class function TDCP_misty1.GetID: integer; class function TDCP_misty1.GetID: integer;
begin begin
Result:= DCP_misty1; Result:= DCP_misty1;
end; end;
class function TDCP_misty1.GetAlgorithm: string; class function TDCP_misty1.GetAlgorithm: string;
begin begin
Result:= 'Misty1'; Result:= 'Misty1';
end; end;
class function TDCP_misty1.GetMaxKeySize: integer; class function TDCP_misty1.GetMaxKeySize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_misty1.SelfTest: boolean; class function TDCP_misty1.SelfTest: boolean;
const const
Key: array[0..15] of byte= Key: array[0..15] of byte=
($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff); ($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff);
Plain1: array[0..7] of byte= ($01,$23,$45,$67,$89,$ab,$cd,$ef); Plain1: array[0..7] of byte= ($01,$23,$45,$67,$89,$ab,$cd,$ef);
Plain2: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10); Plain2: array[0..7] of byte= ($fe,$dc,$ba,$98,$76,$54,$32,$10);
Cipher1: array[0..7] of byte= ($8b,$1d,$a5,$f5,$6a,$b3,$d0,$7c); Cipher1: array[0..7] of byte= ($8b,$1d,$a5,$f5,$6a,$b3,$d0,$7c);
Cipher2: array[0..7] of byte= ($04,$b6,$82,$40,$b1,$3b,$e9,$5d); Cipher2: array[0..7] of byte= ($04,$b6,$82,$40,$b1,$3b,$e9,$5d);
var var
Cipher: TDCP_misty1; Cipher: TDCP_misty1;
Block: array[0..7] of byte; Block: array[0..7] of byte;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_misty1.Create(nil); Cipher:= TDCP_misty1.Create(nil);
Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.Init(Key,Sizeof(Key)*8,nil);
Cipher.EncryptECB(Plain1,Block); Cipher.EncryptECB(Plain1,Block);
Result:= CompareMem(@Cipher1,@Block,Sizeof(Block)); Result:= CompareMem(@Cipher1,@Block,Sizeof(Block));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and CompareMem(@Plain1,@Block,Sizeof(Block)); Result:= Result and CompareMem(@Plain1,@Block,Sizeof(Block));
Cipher.EncryptECB(Plain2,Block); Cipher.EncryptECB(Plain2,Block);
Result:= Result and CompareMem(@Cipher2,@Block,Sizeof(Block)); Result:= Result and CompareMem(@Cipher2,@Block,Sizeof(Block));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Result:= Result and CompareMem(@Plain2,@Block,Sizeof(Block)); Result:= Result and CompareMem(@Plain2,@Block,Sizeof(Block));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
function TDCP_misty1.FI(const FI_IN, FI_KEY: DWord): DWord; function TDCP_misty1.FI(const FI_IN, FI_KEY: DWord): DWord;
var var
d7, d9: DWord; d7, d9: DWord;
begin begin
d9:= (FI_IN shr 7) and $1ff; d9:= (FI_IN shr 7) and $1ff;
d7:= FI_IN and $7f; d7:= FI_IN and $7f;
d9:= S9Table[d9] xor d7; d9:= S9Table[d9] xor d7;
d7:= (S7Table[d7] xor d9) and $7f; d7:= (S7Table[d7] xor d9) and $7f;
d7:= d7 xor ((FI_KEY shr 9) and $7f); d7:= d7 xor ((FI_KEY shr 9) and $7f);
d9:= d9 xor (FI_KEY and $1ff); d9:= d9 xor (FI_KEY and $1ff);
d9:= S9Table[d9] xor d7; d9:= S9Table[d9] xor d7;
Result:= (d7 shl 9) or d9; Result:= (d7 shl 9) or d9;
end; end;
function TDCP_misty1.FO(const FO_IN: DWord; const k: longword): DWord; function TDCP_misty1.FO(const FO_IN: DWord; const k: longword): DWord;
var var
t0, t1: DWord; t0, t1: DWord;
begin begin
t0:= FO_IN shr 16; t0:= FO_IN shr 16;
t1:= FO_IN and $FFFF; t1:= FO_IN and $FFFF;
t0:= t0 xor KeyData[k]; t0:= t0 xor KeyData[k];
t0:= FI(t0,KeyData[((k+5) mod 8) + 8]); t0:= FI(t0,KeyData[((k+5) mod 8) + 8]);
t0:= t0 xor t1; t0:= t0 xor t1;
t1:= t1 xor KeyData[(k+2) mod 8]; t1:= t1 xor KeyData[(k+2) mod 8];
t1:= FI(t1,KeyData[((k+1) mod 8) + 8]); t1:= FI(t1,KeyData[((k+1) mod 8) + 8]);
t1:= t1 xor t0; t1:= t1 xor t0;
t0:= t0 xor KeyData[(k+7) mod 8]; t0:= t0 xor KeyData[(k+7) mod 8];
t0:= FI(t0,KeyData[((k+3) mod 8) + 8]); t0:= FI(t0,KeyData[((k+3) mod 8) + 8]);
t0:= t0 xor t1; t0:= t0 xor t1;
t1:= t1 xor KeyData[(k+4) mod 8]; t1:= t1 xor KeyData[(k+4) mod 8];
Result:= (t1 shl 16) or t0; Result:= (t1 shl 16) or t0;
end; end;
function TDCP_misty1.FL(const FL_IN: DWord; const k: longword): DWord; function TDCP_misty1.FL(const FL_IN: DWord; const k: longword): DWord;
var var
d0, d1: DWord; d0, d1: DWord;
t: byte; t: byte;
begin begin
d0:= FL_IN shr 16; d0:= FL_IN shr 16;
d1:= FL_IN and $FFFF; d1:= FL_IN and $FFFF;
if (k mod 2)<> 0 then if (k mod 2)<> 0 then
begin begin
t:= (k-1) div 2; t:= (k-1) div 2;
d1:= d1 xor (d0 and KeyData[((t + 2) mod 8) + 8]); d1:= d1 xor (d0 and KeyData[((t + 2) mod 8) + 8]);
d0:= d0 xor (d1 or KeyData[(t + 4) mod 8]); d0:= d0 xor (d1 or KeyData[(t + 4) mod 8]);
end end
else else
begin begin
t:= k div 2; t:= k div 2;
d1:= d1 xor (d0 and KeyData[t]); d1:= d1 xor (d0 and KeyData[t]);
d0:= d0 xor (d1 or KeyData[((t+6) mod 8) + 8]); d0:= d0 xor (d1 or KeyData[((t+6) mod 8) + 8]);
end; end;
Result:= (d0 shl 16) or d1; Result:= (d0 shl 16) or d1;
end; end;
function TDCP_misty1.FLINV(const FL_IN: DWord; const k: longword): DWord; function TDCP_misty1.FLINV(const FL_IN: DWord; const k: longword): DWord;
var var
d0, d1: DWord; d0, d1: DWord;
t: byte; t: byte;
begin begin
d0:= FL_IN shr 16; d0:= FL_IN shr 16;
d1:= FL_IN and $FFFF; d1:= FL_IN and $FFFF;
if (k mod 2)<> 0 then if (k mod 2)<> 0 then
begin begin
t:= (k-1) div 2; t:= (k-1) div 2;
d0:= d0 xor (d1 or KeyData[(t+4) mod 8]); d0:= d0 xor (d1 or KeyData[(t+4) mod 8]);
d1:= d1 xor (d0 and KeyData[((t+2) mod 8) + 8]); d1:= d1 xor (d0 and KeyData[((t+2) mod 8) + 8]);
end end
else else
begin begin
t:= k div 2; t:= k div 2;
d0:= d0 xor (d1 or KeyData[((t+6) mod 8) + 8]); d0:= d0 xor (d1 or KeyData[((t+6) mod 8) + 8]);
d1:= d1 xor (d0 and KeyData[t]); d1:= d1 xor (d0 and KeyData[t]);
end; end;
Result:= (d0 shl 16) or d1; Result:= (d0 shl 16) or d1;
end; end;
procedure TDCP_misty1.InitKey(const Key; Size: longword); procedure TDCP_misty1.InitKey(const Key; Size: longword);
var var
KeyB: array[0..15] of byte; KeyB: array[0..15] of byte;
i: longword; i: longword;
begin begin
dcpFillChar(KeyB,Sizeof(KeyB),0); dcpFillChar(KeyB,Sizeof(KeyB),0);
Move(Key,KeyB,Size div 8); Move(Key,KeyB,Size div 8);
for i:= 0 to 7 do for i:= 0 to 7 do
KeyData[i]:= (KeyB[i*2] * 256) + KeyB[i*2+1]; KeyData[i]:= (KeyB[i*2] * 256) + KeyB[i*2+1];
for i:= 0 to 7 do for i:= 0 to 7 do
begin begin
KeyData[i+8]:= FI(KeyData[i],KeyData[(i+1) mod 8]); KeyData[i+8]:= FI(KeyData[i],KeyData[(i+1) mod 8]);
KeyData[i+16]:= KeyData[i+8] and $1FF; KeyData[i+16]:= KeyData[i+8] and $1FF;
KeyData[i+24]:= KeyData[i+8] shr 9; KeyData[i+24]:= KeyData[i+8] shr 9;
end; end;
end; end;
procedure TDCP_misty1.Burn; procedure TDCP_misty1.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_misty1.EncryptECB(const InData; var OutData); procedure TDCP_misty1.EncryptECB(const InData; var OutData);
var var
d0, d1: DWord; d0, d1: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
d0:= SwapDWord(PDWord(@InData)^); d0:= SwapDWord(PDWord(@InData)^);
d1:= SwapDWord(PDWord(pointer(@InData)+4)^); d1:= SwapDWord(PDWord(pointer(@InData)+4)^);
for i:= 0 to NUMROUNDS-1 do for i:= 0 to NUMROUNDS-1 do
begin begin
if (i mod 2)= 0 then if (i mod 2)= 0 then
begin begin
d0:= FL(D0,i); d0:= FL(D0,i);
d1:= FL(D1,i+1); d1:= FL(D1,i+1);
d1:= d1 xor FO(d0,i); d1:= d1 xor FO(d0,i);
end end
else else
d0:= d0 xor FO(d1,i); d0:= d0 xor FO(d1,i);
end; end;
d0:= FL(d0,NUMROUNDS); d0:= FL(d0,NUMROUNDS);
d1:= FL(d1,NUMROUNDS+1); d1:= FL(d1,NUMROUNDS+1);
PDWord(@OutData)^:= SwapDWord(d1); PDWord(@OutData)^:= SwapDWord(d1);
PDWord(pointer(@OutData)+4)^:= SwapDWord(d0); PDWord(pointer(@OutData)+4)^:= SwapDWord(d0);
end; end;
procedure TDCP_misty1.DecryptECB(const InData; var OutData); procedure TDCP_misty1.DecryptECB(const InData; var OutData);
var var
d0, d1: DWord; d0, d1: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
d1:= SwapDWord(PDWord(@InData)^); d1:= SwapDWord(PDWord(@InData)^);
d0:= SwapDWord(PDWord(pointer(@InData)+4)^); d0:= SwapDWord(PDWord(pointer(@InData)+4)^);
d1:= FLINV(d1,NUMROUNDS+1); d1:= FLINV(d1,NUMROUNDS+1);
d0:= FLINV(d0,NUMROUNDS); d0:= FLINV(d0,NUMROUNDS);
for i:= NUMROUNDS-1 downto 0 do for i:= NUMROUNDS-1 downto 0 do
begin begin
if (i mod 2)= 0 then if (i mod 2)= 0 then
begin begin
d1:= d1 xor FO(d0,i); d1:= d1 xor FO(d0,i);
d0:= FLINV(D0,i); d0:= FLINV(D0,i);
d1:= FLINV(D1,i+1); d1:= FLINV(D1,i+1);
end end
else else
d0:= d0 xor FO(d1,i); d0:= d0 xor FO(d1,i);
end; end;
PDWord(@OutData)^:= SwapDWord(d0); PDWord(@OutData)^:= SwapDWord(d0);
PDWord(pointer(@OutData)+4)^:= SwapDWord(d1); PDWord(pointer(@OutData)+4)^:= SwapDWord(d1);
end; end;
end. end.

View File

@ -1,191 +1,191 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of RC2 **********************************} {* A binary compatible implementation of RC2 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPrc2; unit DCPrc2;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_rc2= class(TDCP_blockcipher64) TDCP_rc2= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..63] of word; KeyData: array[0..63] of word;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPrc2.inc} {$I DCPrc2.inc}
function LRot16(a, n: word): word; function LRot16(a, n: word): word;
begin begin
Result:= (a shl n) or (a shr (16-n)); Result:= (a shl n) or (a shr (16-n));
end; end;
function RRot16(a, n: word): word; function RRot16(a, n: word): word;
begin begin
Result:= (a shr n) or (a shl (16-n)); Result:= (a shr n) or (a shl (16-n));
end; end;
class function TDCP_rc2.GetMaxKeySize: integer; class function TDCP_rc2.GetMaxKeySize: integer;
begin begin
Result:= 1024; Result:= 1024;
end; end;
class function TDCP_rc2.GetID: integer; class function TDCP_rc2.GetID: integer;
begin begin
Result:= DCP_rc2; Result:= DCP_rc2;
end; end;
class function TDCP_rc2.GetAlgorithm: string; class function TDCP_rc2.GetAlgorithm: string;
begin begin
Result:= 'RC2'; Result:= 'RC2';
end; end;
class function TDCP_rc2.SelfTest: boolean; class function TDCP_rc2.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F); ($00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F);
InData1: array[0..7] of byte= InData1: array[0..7] of byte=
($00,$00,$00,$00,$00,$00,$00,$00); ($00,$00,$00,$00,$00,$00,$00,$00);
OutData1: array[0..7] of byte= OutData1: array[0..7] of byte=
($50,$DC,$01,$62,$BD,$75,$7F,$31); ($50,$DC,$01,$62,$BD,$75,$7F,$31);
Key2: array[0..15] of byte= Key2: array[0..15] of byte=
($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01); ($00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01);
InData2: array[0..7] of byte= InData2: array[0..7] of byte=
($00,$00,$00,$00,$00,$00,$00,$00); ($00,$00,$00,$00,$00,$00,$00,$00);
OutData2: array[0..7] of byte= OutData2: array[0..7] of byte=
($21,$82,$9C,$78,$A9,$F9,$C0,$74); ($21,$82,$9C,$78,$A9,$F9,$C0,$74);
var var
Cipher: TDCP_rc2; Cipher: TDCP_rc2;
Data: array[0..7] of byte; Data: array[0..7] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_rc2.Create(nil); Cipher:= TDCP_rc2.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Data); Cipher.EncryptECB(InData1,Data);
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Data); Cipher.EncryptECB(InData2,Data);
Result:= boolean(CompareMem(@Data,@OutData2,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@OutData2,Sizeof(Data))) and Result;
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= boolean(CompareMem(@Data,@InData2,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData2,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_rc2.InitKey(const Key; Size: longword); procedure TDCP_rc2.InitKey(const Key; Size: longword);
var var
i: longword; i: longword;
KeyB: array[0..127] of byte; KeyB: array[0..127] of byte;
begin begin
dcpFillChar(KeyB, SizeOf(KeyB), 0); dcpFillChar(KeyB, SizeOf(KeyB), 0);
Move(Key,KeyB,Size div 8); Move(Key,KeyB,Size div 8);
for i:= (Size div 8) to 127 do for i:= (Size div 8) to 127 do
KeyB[i]:= sBox[(KeyB[i-(Size div 8)]+KeyB[i-1]) and $FF]; KeyB[i]:= sBox[(KeyB[i-(Size div 8)]+KeyB[i-1]) and $FF];
KeyB[0]:= sBox[KeyB[0]]; KeyB[0]:= sBox[KeyB[0]];
Move(KeyB,KeyData,Sizeof(KeyData)); Move(KeyB,KeyData,Sizeof(KeyData));
end; end;
procedure TDCP_rc2.Burn; procedure TDCP_rc2.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_rc2.EncryptECB(const InData; var OutData); procedure TDCP_rc2.EncryptECB(const InData; var OutData);
var var
i, j: longword; i, j: longword;
w: array[0..3] of word; w: array[0..3] of word;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
Pdword(@w[0])^:= Pdword(@InData)^; Pdword(@w[0])^:= Pdword(@InData)^;
Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^; Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^;
for i:= 0 to 15 do for i:= 0 to 15 do
begin begin
j:= i*4; j:= i*4;
w[0]:= LRot16((w[0]+(w[1] and (not w[3]))+(w[2] and w[3])+KeyData[j+0]),1); w[0]:= LRot16((w[0]+(w[1] and (not w[3]))+(w[2] and w[3])+KeyData[j+0]),1);
w[1]:= LRot16((w[1]+(w[2] and (not w[0]))+(w[3] and w[0])+KeyData[j+1]),2); w[1]:= LRot16((w[1]+(w[2] and (not w[0]))+(w[3] and w[0])+KeyData[j+1]),2);
w[2]:= LRot16((w[2]+(w[3] and (not w[1]))+(w[0] and w[1])+KeyData[j+2]),3); w[2]:= LRot16((w[2]+(w[3] and (not w[1]))+(w[0] and w[1])+KeyData[j+2]),3);
w[3]:= LRot16((w[3]+(w[0] and (not w[2]))+(w[1] and w[2])+KeyData[j+3]),5); w[3]:= LRot16((w[3]+(w[0] and (not w[2]))+(w[1] and w[2])+KeyData[j+3]),5);
if (i= 4) or (i= 10) then if (i= 4) or (i= 10) then
begin begin
w[0]:= w[0]+KeyData[w[3] and 63]; w[0]:= w[0]+KeyData[w[3] and 63];
w[1]:= w[1]+KeyData[w[0] and 63]; w[1]:= w[1]+KeyData[w[0] and 63];
w[2]:= w[2]+KeyData[w[1] and 63]; w[2]:= w[2]+KeyData[w[1] and 63];
w[3]:= w[3]+KeyData[w[2] and 63]; w[3]:= w[3]+KeyData[w[2] and 63];
end; end;
end; end;
Pdword(@OutData)^:= Pdword(@w[0])^; Pdword(@OutData)^:= Pdword(@w[0])^;
Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^; Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^;
end; end;
procedure TDCP_rc2.DecryptECB(const InData; var OutData); procedure TDCP_rc2.DecryptECB(const InData; var OutData);
var var
i, j: longword; i, j: longword;
w: array[0..3] of word; w: array[0..3] of word;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
Pdword(@w[0])^:= Pdword(@InData)^; Pdword(@w[0])^:= Pdword(@InData)^;
Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^; Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^;
for i:= 15 downto 0 do for i:= 15 downto 0 do
begin begin
j:= i*4; j:= i*4;
w[3]:= RRot16(w[3],5)-(w[0] and (not w[2]))-(w[1] and w[2])-KeyData[j+3]; w[3]:= RRot16(w[3],5)-(w[0] and (not w[2]))-(w[1] and w[2])-KeyData[j+3];
w[2]:= RRot16(w[2],3)-(w[3] and (not w[1]))-(w[0] and w[1])-KeyData[j+2]; w[2]:= RRot16(w[2],3)-(w[3] and (not w[1]))-(w[0] and w[1])-KeyData[j+2];
w[1]:= RRot16(w[1],2)-(w[2] and (not w[0]))-(w[3] and w[0])-KeyData[j+1]; w[1]:= RRot16(w[1],2)-(w[2] and (not w[0]))-(w[3] and w[0])-KeyData[j+1];
w[0]:= RRot16(w[0],1)-(w[1] and (not w[3]))-(w[2] and w[3])-KeyData[j+0]; w[0]:= RRot16(w[0],1)-(w[1] and (not w[3]))-(w[2] and w[3])-KeyData[j+0];
if (i= 5) or (i= 11) then if (i= 5) or (i= 11) then
begin begin
w[3]:= w[3]-KeyData[w[2] and 63]; w[3]:= w[3]-KeyData[w[2] and 63];
w[2]:= w[2]-KeyData[w[1] and 63]; w[2]:= w[2]-KeyData[w[1] and 63];
w[1]:= w[1]-KeyData[w[0] and 63]; w[1]:= w[1]-KeyData[w[0] and 63];
w[0]:= w[0]-KeyData[w[3] and 63]; w[0]:= w[0]-KeyData[w[3] and 63];
end; end;
end; end;
Pdword(@OutData)^:= Pdword(@w[0])^; Pdword(@OutData)^:= Pdword(@w[0])^;
Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^; Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^;
end; end;
end. end.

View File

@ -1,212 +1,212 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of RC4 **********************************} {* A binary compatible implementation of RC4 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPrc4; unit DCPrc4;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_rc4= class(TDCP_cipher) TDCP_rc4= class(TDCP_cipher)
protected protected
KeyData, KeyOrg: array[0..255] of byte; KeyData, KeyOrg: array[0..255] of byte;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init(const Key; Size: longword; InitVector: pointer); override; procedure Init(const Key; Size: longword; InitVector: pointer); override;
procedure Reset; override; procedure Reset; override;
procedure Burn; override; procedure Burn; override;
procedure Encrypt(const InData; var OutData; Size: longword); override; procedure Encrypt(const InData; var OutData; Size: longword); override;
procedure Decrypt(const InData; var OutData; Size: longword); override; procedure Decrypt(const InData; var OutData; Size: longword); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
class function TDCP_rc4.GetID: integer; class function TDCP_rc4.GetID: integer;
begin begin
Result:= DCP_rc4; Result:= DCP_rc4;
end; end;
class function TDCP_rc4.GetAlgorithm: string; class function TDCP_rc4.GetAlgorithm: string;
begin begin
Result:= 'RC4'; Result:= 'RC4';
end; end;
class function TDCP_rc4.GetMaxKeySize: integer; class function TDCP_rc4.GetMaxKeySize: integer;
begin begin
Result:= 2048; Result:= 2048;
end; end;
class function TDCP_rc4.SelfTest: boolean; class function TDCP_rc4.SelfTest: boolean;
const const
Key1: array[0..4] of byte= ($61,$8A,$63,$D2,$FB); Key1: array[0..4] of byte= ($61,$8A,$63,$D2,$FB);
InData1: array[0..4] of byte= ($DC,$EE,$4C,$F9,$2C); InData1: array[0..4] of byte= ($DC,$EE,$4C,$F9,$2C);
OutData1: array[0..4] of byte= ($F1,$38,$29,$C9,$DE); OutData1: array[0..4] of byte= ($F1,$38,$29,$C9,$DE);
var var
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
Data: array[0..4] of byte; Data: array[0..4] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_rc4.Create(nil); Cipher:= TDCP_rc4.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.Encrypt(InData1,Data,Sizeof(Data)); Cipher.Encrypt(InData1,Data,Sizeof(Data));
Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@OutData1,Sizeof(Data)));
Cipher.Reset; Cipher.Reset;
Cipher.Decrypt(Data,Data,Sizeof(Data)); Cipher.Decrypt(Data,Data,Sizeof(Data));
Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result; Result:= boolean(CompareMem(@Data,@InData1,Sizeof(Data))) and Result;
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_rc4.Init(const Key; Size: longword; InitVector: pointer); procedure TDCP_rc4.Init(const Key; Size: longword; InitVector: pointer);
var var
i, j, t: longword; i, j, t: longword;
xKey: array[0..255] of byte; xKey: array[0..255] of byte;
begin begin
if fInitialized then if fInitialized then
Burn; Burn;
inherited Init(Key,Size,nil); inherited Init(Key,Size,nil);
Size:= Size div 8; Size:= Size div 8;
i:= 0; i:= 0;
while i< 255 do while i< 255 do
begin begin
KeyData[i]:= i; KeyData[i]:= i;
xKey[i]:= PByte(pointer(@Key)+(i mod Size))^; xKey[i]:= PByte(pointer(@Key)+(i mod Size))^;
KeyData[i+1]:= i+1; KeyData[i+1]:= i+1;
xKey[i+1]:= PByte(pointer(@Key)+((i+1) mod Size))^; xKey[i+1]:= PByte(pointer(@Key)+((i+1) mod Size))^;
KeyData[i+2]:= i+2; KeyData[i+2]:= i+2;
xKey[i+2]:= PByte(pointer(@Key)+((i+2) mod Size))^; xKey[i+2]:= PByte(pointer(@Key)+((i+2) mod Size))^;
KeyData[i+3]:= i+3; KeyData[i+3]:= i+3;
xKey[i+3]:= PByte(pointer(@Key)+((i+3) mod Size))^; xKey[i+3]:= PByte(pointer(@Key)+((i+3) mod Size))^;
KeyData[i+4]:= i+4; KeyData[i+4]:= i+4;
xKey[i+4]:= PByte(pointer(@Key)+((i+4) mod Size))^; xKey[i+4]:= PByte(pointer(@Key)+((i+4) mod Size))^;
KeyData[i+5]:= i+5; KeyData[i+5]:= i+5;
xKey[i+5]:= PByte(pointer(@Key)+((i+5) mod Size))^; xKey[i+5]:= PByte(pointer(@Key)+((i+5) mod Size))^;
KeyData[i+6]:= i+6; KeyData[i+6]:= i+6;
xKey[i+6]:= PByte(pointer(@Key)+((i+6) mod Size))^; xKey[i+6]:= PByte(pointer(@Key)+((i+6) mod Size))^;
KeyData[i+7]:= i+7; KeyData[i+7]:= i+7;
xKey[i+7]:= PByte(pointer(@Key)+((i+7) mod Size))^; xKey[i+7]:= PByte(pointer(@Key)+((i+7) mod Size))^;
Inc(i,8); Inc(i,8);
end; end;
j:= 0; j:= 0;
i:= 0; i:= 0;
while i< 255 do while i< 255 do
begin begin
j:= (j+KeyData[i]+xKey[i]) and $FF; j:= (j+KeyData[i]+xKey[i]) and $FF;
t:= KeyData[i]; t:= KeyData[i];
KeyData[i]:= KeyData[j]; KeyData[i]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+1]+xKey[i+1]) and $FF; j:= (j+KeyData[i+1]+xKey[i+1]) and $FF;
t:= KeyData[i+1]; t:= KeyData[i+1];
KeyData[i+1]:= KeyData[j]; KeyData[i+1]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+2]+xKey[i+2]) and $FF; j:= (j+KeyData[i+2]+xKey[i+2]) and $FF;
t:= KeyData[i+2]; t:= KeyData[i+2];
KeyData[i+2]:= KeyData[j]; KeyData[i+2]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+3]+xKey[i+3]) and $FF; j:= (j+KeyData[i+3]+xKey[i+3]) and $FF;
t:= KeyData[i+3]; t:= KeyData[i+3];
KeyData[i+3]:= KeyData[j]; KeyData[i+3]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+4]+xKey[i+4]) and $FF; j:= (j+KeyData[i+4]+xKey[i+4]) and $FF;
t:= KeyData[i+4]; t:= KeyData[i+4];
KeyData[i+4]:= KeyData[j]; KeyData[i+4]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+5]+xKey[i+5]) and $FF; j:= (j+KeyData[i+5]+xKey[i+5]) and $FF;
t:= KeyData[i+5]; t:= KeyData[i+5];
KeyData[i+5]:= KeyData[j]; KeyData[i+5]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+6]+xKey[i+6]) and $FF; j:= (j+KeyData[i+6]+xKey[i+6]) and $FF;
t:= KeyData[i+6]; t:= KeyData[i+6];
KeyData[i+6]:= KeyData[j]; KeyData[i+6]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
j:= (j+KeyData[i+7]+xKey[i+7]) and $FF; j:= (j+KeyData[i+7]+xKey[i+7]) and $FF;
t:= KeyData[i+7]; t:= KeyData[i+7];
KeyData[i+7]:= KeyData[j]; KeyData[i+7]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
Inc(i,8); Inc(i,8);
end; end;
Move(KeyData,KeyOrg,Sizeof(KeyOrg)); Move(KeyData,KeyOrg,Sizeof(KeyOrg));
end; end;
procedure TDCP_rc4.Reset; procedure TDCP_rc4.Reset;
begin begin
Move(KeyOrg,KeyData,Sizeof(KeyData)); Move(KeyOrg,KeyData,Sizeof(KeyData));
end; end;
procedure TDCP_rc4.Burn; procedure TDCP_rc4.Burn;
begin begin
FillChar(KeyOrg,Sizeof(KeyOrg),$FF); FillChar(KeyOrg,Sizeof(KeyOrg),$FF);
FillChar(KeyData,Sizeof(KeyData),$FF); FillChar(KeyData,Sizeof(KeyData),$FF);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_rc4.Encrypt(const InData; var OutData; Size: longword); procedure TDCP_rc4.Encrypt(const InData; var OutData; Size: longword);
var var
i, j, t, k: longword; i, j, t, k: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_cipher.Create('Cipher not initialized'); raise EDCP_cipher.Create('Cipher not initialized');
i:= 0; j:= 0; i:= 0; j:= 0;
for k:= 0 to Size-1 do for k:= 0 to Size-1 do
begin begin
i:= (i + 1) and $FF; i:= (i + 1) and $FF;
t:= KeyData[i]; t:= KeyData[i];
j:= (j + t) and $FF; j:= (j + t) and $FF;
KeyData[i]:= KeyData[j]; KeyData[i]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
t:= (t + KeyData[i]) and $FF; t:= (t + KeyData[i]) and $FF;
Pbytearray(@OutData)^[k]:= Pbytearray(@InData)^[k] xor KeyData[t]; Pbytearray(@OutData)^[k]:= Pbytearray(@InData)^[k] xor KeyData[t];
end; end;
end; end;
procedure TDCP_rc4.Decrypt(const InData; var OutData; Size: longword); procedure TDCP_rc4.Decrypt(const InData; var OutData; Size: longword);
var var
i, j, t, k: longword; i, j, t, k: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_cipher.Create('Cipher not initialized'); raise EDCP_cipher.Create('Cipher not initialized');
i:= 0; j:= 0; i:= 0; j:= 0;
for k:= 0 to Size-1 do for k:= 0 to Size-1 do
begin begin
i:= (i + 1) and $FF; i:= (i + 1) and $FF;
t:= KeyData[i]; t:= KeyData[i];
j:= (j + t) and $FF; j:= (j + t) and $FF;
KeyData[i]:= KeyData[j]; KeyData[i]:= KeyData[j];
KeyData[j]:= t; KeyData[j]:= t;
t:= (t + KeyData[i]) and $FF; t:= (t + KeyData[i]) and $FF;
Pbytearray(@OutData)^[k]:= Pbytearray(@InData)^[k] xor KeyData[t]; Pbytearray(@OutData)^[k]:= Pbytearray(@InData)^[k] xor KeyData[t];
end; end;
end; end;
end. end.

View File

@ -1,203 +1,203 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of RC5 **********************************} {* A binary compatible implementation of RC5 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPrc5; unit DCPrc5;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
const const
NUMROUNDS= 12; { number of rounds must be between 12-16 } NUMROUNDS= 12; { number of rounds must be between 12-16 }
type type
TDCP_rc5= class(TDCP_blockcipher64) TDCP_rc5= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..((NUMROUNDS*2)+1)] of DWord; KeyData: array[0..((NUMROUNDS*2)+1)] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
const const
sBox: array[0..33] of dword= ( sBox: array[0..33] of dword= (
$B7E15163,$5618CB1C,$F45044D5,$9287BE8E,$30BF3847,$CEF6B200, $B7E15163,$5618CB1C,$F45044D5,$9287BE8E,$30BF3847,$CEF6B200,
$6D2E2BB9,$0B65A572,$A99D1F2B,$47D498E4,$E60C129D,$84438C56, $6D2E2BB9,$0B65A572,$A99D1F2B,$47D498E4,$E60C129D,$84438C56,
$227B060F,$C0B27FC8,$5EE9F981,$FD21733A,$9B58ECF3,$399066AC, $227B060F,$C0B27FC8,$5EE9F981,$FD21733A,$9B58ECF3,$399066AC,
$D7C7E065,$75FF5A1E,$1436D3D7,$B26E4D90,$50A5C749,$EEDD4102, $D7C7E065,$75FF5A1E,$1436D3D7,$B26E4D90,$50A5C749,$EEDD4102,
$8D14BABB,$2B4C3474,$C983AE2D,$67BB27E6,$05F2A19F,$A42A1B58, $8D14BABB,$2B4C3474,$C983AE2D,$67BB27E6,$05F2A19F,$A42A1B58,
$42619511,$E0990ECA,$7ED08883,$1D08023C); $42619511,$E0990ECA,$7ED08883,$1D08023C);
function LRot32(a, b: longword): longword; function LRot32(a, b: longword): longword;
begin begin
Result:= (a shl b) or (a shr (32-b)); Result:= (a shl b) or (a shr (32-b));
end; end;
function RRot32(a, b: longword): longword; function RRot32(a, b: longword): longword;
begin begin
Result:= (a shr b) or (a shl (32-b)); Result:= (a shr b) or (a shl (32-b));
end; end;
class function TDCP_rc5.GetID: integer; class function TDCP_rc5.GetID: integer;
begin begin
Result:= DCP_rc5; Result:= DCP_rc5;
end; end;
class function TDCP_rc5.GetAlgorithm: string; class function TDCP_rc5.GetAlgorithm: string;
begin begin
Result:= 'RC5'; Result:= 'RC5';
end; end;
class function TDCP_rc5.GetMaxKeySize: integer; class function TDCP_rc5.GetMaxKeySize: integer;
begin begin
Result:= 2048; Result:= 2048;
end; end;
class function TDCP_rc5.SelfTest: boolean; class function TDCP_rc5.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($DC,$49,$DB,$13,$75,$A5,$58,$4F,$64,$85,$B4,$13,$B5,$F1,$2B,$AF); ($DC,$49,$DB,$13,$75,$A5,$58,$4F,$64,$85,$B4,$13,$B5,$F1,$2B,$AF);
Plain1: array[0..1] of dword= Plain1: array[0..1] of dword=
($B7B3422F,$92FC6903); ($B7B3422F,$92FC6903);
Cipher1: array[0..1] of dword= Cipher1: array[0..1] of dword=
($B278C165,$CC97D184); ($B278C165,$CC97D184);
Key2: array[0..15] of byte= Key2: array[0..15] of byte=
($52,$69,$F1,$49,$D4,$1B,$A0,$15,$24,$97,$57,$4D,$7F,$15,$31,$25); ($52,$69,$F1,$49,$D4,$1B,$A0,$15,$24,$97,$57,$4D,$7F,$15,$31,$25);
Plain2: array[0..1] of dword= Plain2: array[0..1] of dword=
($B278C165,$CC97D184); ($B278C165,$CC97D184);
Cipher2: array[0..1] of dword= Cipher2: array[0..1] of dword=
($15E444EB,$249831DA); ($15E444EB,$249831DA);
var var
Cipher: TDCP_rc5; Cipher: TDCP_rc5;
Data: array[0..1] of dword; Data: array[0..1] of dword;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_rc5.Create(nil); Cipher:= TDCP_rc5.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(Plain1,Data); Cipher.EncryptECB(Plain1,Data);
Result:= boolean(CompareMem(@Data,@Cipher1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@Cipher1,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@Plain1,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Plain1,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(Plain2,Data); Cipher.EncryptECB(Plain2,Data);
Result:= Result and boolean(CompareMem(@Data,@Cipher2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Cipher2,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@Plain2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Plain2,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_rc5.InitKey(const Key; Size: longword); procedure TDCP_rc5.InitKey(const Key; Size: longword);
var var
xKeyD: array[0..63] of DWord; xKeyD: array[0..63] of DWord;
i, j, k, xKeyLen: longword; i, j, k, xKeyLen: longword;
A, B: DWord; A, B: DWord;
begin begin
dcpFillChar(xKeyD,Sizeof(xKeyD),0); dcpFillChar(xKeyD,Sizeof(xKeyD),0);
Size:= Size div 8; Size:= Size div 8;
Move(Key,xKeyD,Size); Move(Key,xKeyD,Size);
xKeyLen:= Size div 4; xKeyLen:= Size div 4;
if (Size mod 4)<> 0 then if (Size mod 4)<> 0 then
Inc(xKeyLen); Inc(xKeyLen);
Move(sBox,KeyData,(NUMROUNDS+1)*8); Move(sBox,KeyData,(NUMROUNDS+1)*8);
i:= 0; j:= 0; i:= 0; j:= 0;
A:= 0; B:= 0; A:= 0; B:= 0;
if xKeyLen> ((NUMROUNDS+1)*2) then if xKeyLen> ((NUMROUNDS+1)*2) then
k:= xKeyLen*3 k:= xKeyLen*3
else else
k:= (NUMROUNDS+1)*6; k:= (NUMROUNDS+1)*6;
for k:= k downto 1 do for k:= k downto 1 do
begin begin
A:= LRot32(KeyData[i]+A+B,3); A:= LRot32(KeyData[i]+A+B,3);
KeyData[i]:= A; KeyData[i]:= A;
B:= LRot32(xKeyD[j]+A+B,A+B); B:= LRot32(xKeyD[j]+A+B,A+B);
xKeyD[j]:= B; xKeyD[j]:= B;
i:= (i+1) mod ((NUMROUNDS+1)*2); i:= (i+1) mod ((NUMROUNDS+1)*2);
j:= (j+1) mod xKeyLen; j:= (j+1) mod xKeyLen;
end; end;
FillChar(xKeyD,Sizeof(xKeyD),0); FillChar(xKeyD,Sizeof(xKeyD),0);
end; end;
procedure TDCP_rc5.Burn; procedure TDCP_rc5.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),$FF); FillChar(KeyData,Sizeof(KeyData),$FF);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_rc5.EncryptECB(const InData; var OutData); procedure TDCP_rc5.EncryptECB(const InData; var OutData);
var var
A, B: DWord; A, B: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
A:= PDword(@InData)^ + KeyData[0]; A:= PDword(@InData)^ + KeyData[0];
B:= PDword(pointer(@InData)+4)^ + KeyData[1]; B:= PDword(pointer(@InData)+4)^ + KeyData[1];
for i:= 1 to NUMROUNDS do for i:= 1 to NUMROUNDS do
begin begin
A:= A xor B; A:= A xor B;
A:= LRot32(A,B)+KeyData[2*i]; A:= LRot32(A,B)+KeyData[2*i];
B:= B xor A; B:= B xor A;
B:= LRot32(B,A)+KeyData[(2*i)+1]; B:= LRot32(B,A)+KeyData[(2*i)+1];
end; end;
PDword(@OutData)^:= A; PDword(@OutData)^:= A;
PDword(pointer(@OutData)+4)^:= B; PDword(pointer(@OutData)+4)^:= B;
end; end;
procedure TDCP_rc5.DecryptECB(const InData; var OutData); procedure TDCP_rc5.DecryptECB(const InData; var OutData);
var var
A, B: DWord; A, B: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
A:= PDword(@InData)^; A:= PDword(@InData)^;
B:= PDword(pointer(@InData)+4)^; B:= PDword(pointer(@InData)+4)^;
for i:= NUMROUNDS downto 1 do for i:= NUMROUNDS downto 1 do
begin begin
B:= RRot32(B-KeyData[(2*i)+1],A); B:= RRot32(B-KeyData[(2*i)+1],A);
B:= B xor A; B:= B xor A;
A:= RRot32(A-KeyData[2*i],B); A:= RRot32(A-KeyData[2*i],B);
A:= A xor B; A:= A xor B;
end; end;
PDword(@OutData)^:= A - KeyData[0]; PDword(@OutData)^:= A - KeyData[0];
PDword(pointer(@OutData)+4)^:= B - KeyData[1]; PDword(pointer(@OutData)+4)^:= B - KeyData[1];
end; end;
end. end.

View File

@ -1,228 +1,228 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of RC6 **********************************} {* A binary compatible implementation of RC6 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPrc6; unit DCPrc6;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
const const
NUMROUNDS= 20; { number of rounds must be between 16-24 } NUMROUNDS= 20; { number of rounds must be between 16-24 }
type type
TDCP_rc6= class(TDCP_blockcipher128) TDCP_rc6= class(TDCP_blockcipher128)
protected protected
KeyData: array[0..((NUMROUNDS*2)+3)] of DWord; KeyData: array[0..((NUMROUNDS*2)+3)] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
const const
sBox: array[0..51] of DWord= ( sBox: array[0..51] of DWord= (
$B7E15163,$5618CB1C,$F45044D5,$9287BE8E,$30BF3847,$CEF6B200, $B7E15163,$5618CB1C,$F45044D5,$9287BE8E,$30BF3847,$CEF6B200,
$6D2E2BB9,$0B65A572,$A99D1F2B,$47D498E4,$E60C129D,$84438C56, $6D2E2BB9,$0B65A572,$A99D1F2B,$47D498E4,$E60C129D,$84438C56,
$227B060F,$C0B27FC8,$5EE9F981,$FD21733A,$9B58ECF3,$399066AC, $227B060F,$C0B27FC8,$5EE9F981,$FD21733A,$9B58ECF3,$399066AC,
$D7C7E065,$75FF5A1E,$1436D3D7,$B26E4D90,$50A5C749,$EEDD4102, $D7C7E065,$75FF5A1E,$1436D3D7,$B26E4D90,$50A5C749,$EEDD4102,
$8D14BABB,$2B4C3474,$C983AE2D,$67BB27E6,$05F2A19F,$A42A1B58, $8D14BABB,$2B4C3474,$C983AE2D,$67BB27E6,$05F2A19F,$A42A1B58,
$42619511,$E0990ECA,$7ED08883,$1D08023C,$BB3F7BF5,$5976F5AE, $42619511,$E0990ECA,$7ED08883,$1D08023C,$BB3F7BF5,$5976F5AE,
$F7AE6F67,$95E5E920,$341D62D9,$D254DC92,$708C564B,$0EC3D004, $F7AE6F67,$95E5E920,$341D62D9,$D254DC92,$708C564B,$0EC3D004,
$ACFB49BD,$4B32C376,$E96A3D2F,$87A1B6E8,$25D930A1,$C410AA5A, $ACFB49BD,$4B32C376,$E96A3D2F,$87A1B6E8,$25D930A1,$C410AA5A,
$62482413,$007F9DCC,$9EB71785,$3CEE913E); $62482413,$007F9DCC,$9EB71785,$3CEE913E);
function LRot32(X: DWord; c: longword): DWord; function LRot32(X: DWord; c: longword): DWord;
begin begin
LRot32:= (X shl c) or (X shr (32 - c)); LRot32:= (X shl c) or (X shr (32 - c));
end; end;
function RRot32(X: DWord; c: longword): DWord; function RRot32(X: DWord; c: longword): DWord;
begin begin
RRot32:= (X shr c) or (X shl (32 - c)); RRot32:= (X shr c) or (X shl (32 - c));
end; end;
class function TDCP_rc6.GetID: integer; class function TDCP_rc6.GetID: integer;
begin begin
Result:= DCP_rc6; Result:= DCP_rc6;
end; end;
class function TDCP_rc6.GetAlgorithm: string; class function TDCP_rc6.GetAlgorithm: string;
begin begin
Result:= 'RC6'; Result:= 'RC6';
end; end;
class function TDCP_rc6.GetMaxKeySize: integer; class function TDCP_rc6.GetMaxKeySize: integer;
begin begin
Result:= 2048; Result:= 2048;
end; end;
class function TDCP_rc6.SelfTest: boolean; class function TDCP_rc6.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($01,$23,$45,$67,$89,$ab,$cd,$ef,$01,$12,$23,$34,$45,$56,$67,$78); ($01,$23,$45,$67,$89,$ab,$cd,$ef,$01,$12,$23,$34,$45,$56,$67,$78);
Plain1: array[0..15] of byte= Plain1: array[0..15] of byte=
($02,$13,$24,$35,$46,$57,$68,$79,$8a,$9b,$ac,$bd,$ce,$df,$e0,$f1); ($02,$13,$24,$35,$46,$57,$68,$79,$8a,$9b,$ac,$bd,$ce,$df,$e0,$f1);
Cipher1: array[0..15] of byte= Cipher1: array[0..15] of byte=
($52,$4e,$19,$2f,$47,$15,$c6,$23,$1f,$51,$f6,$36,$7e,$a4,$3f,$18); ($52,$4e,$19,$2f,$47,$15,$c6,$23,$1f,$51,$f6,$36,$7e,$a4,$3f,$18);
Key2: array[0..31] of byte= Key2: array[0..31] of byte=
($01,$23,$45,$67,$89,$ab,$cd,$ef,$01,$12,$23,$34,$45,$56,$67,$78, ($01,$23,$45,$67,$89,$ab,$cd,$ef,$01,$12,$23,$34,$45,$56,$67,$78,
$89,$9a,$ab,$bc,$cd,$de,$ef,$f0,$10,$32,$54,$76,$98,$ba,$dc,$fe); $89,$9a,$ab,$bc,$cd,$de,$ef,$f0,$10,$32,$54,$76,$98,$ba,$dc,$fe);
Plain2: array[0..15] of byte= Plain2: array[0..15] of byte=
($02,$13,$24,$35,$46,$57,$68,$79,$8a,$9b,$ac,$bd,$ce,$df,$e0,$f1); ($02,$13,$24,$35,$46,$57,$68,$79,$8a,$9b,$ac,$bd,$ce,$df,$e0,$f1);
Cipher2: array[0..15] of byte= Cipher2: array[0..15] of byte=
($c8,$24,$18,$16,$f0,$d7,$e4,$89,$20,$ad,$16,$a1,$67,$4e,$5d,$48); ($c8,$24,$18,$16,$f0,$d7,$e4,$89,$20,$ad,$16,$a1,$67,$4e,$5d,$48);
var var
Cipher: TDCP_rc6; Cipher: TDCP_rc6;
Data: array[0..15] of byte; Data: array[0..15] of byte;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_rc6.Create(nil); Cipher:= TDCP_rc6.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(Plain1,Data); Cipher.EncryptECB(Plain1,Data);
Result:= boolean(CompareMem(@Data,@Cipher1,Sizeof(Data))); Result:= boolean(CompareMem(@Data,@Cipher1,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@Plain1,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Plain1,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(Plain2,Data); Cipher.EncryptECB(Plain2,Data);
Result:= Result and boolean(CompareMem(@Data,@Cipher2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Cipher2,Sizeof(Data)));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and boolean(CompareMem(@Data,@Plain2,Sizeof(Data))); Result:= Result and boolean(CompareMem(@Data,@Plain2,Sizeof(Data)));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_rc6.InitKey(const Key; Size: longword); procedure TDCP_rc6.InitKey(const Key; Size: longword);
var var
xKeyD: array[0..63] of DWord; xKeyD: array[0..63] of DWord;
i, j, k, xKeyLen: longword; i, j, k, xKeyLen: longword;
A, B: DWord; A, B: DWord;
begin begin
Size:= Size div 8; Size:= Size div 8;
dcpFillChar(xKeyD,Sizeof(xKeyD),0); dcpFillChar(xKeyD,Sizeof(xKeyD),0);
Move(Key,xKeyD,Size); Move(Key,xKeyD,Size);
xKeyLen:= Size div 4; xKeyLen:= Size div 4;
if (Size mod 4)<> 0 then if (Size mod 4)<> 0 then
Inc(xKeyLen); Inc(xKeyLen);
Move(sBox,KeyData,((NUMROUNDS*2)+4)*4); Move(sBox,KeyData,((NUMROUNDS*2)+4)*4);
i:= 0; j:= 0; i:= 0; j:= 0;
A:= 0; B:= 0; A:= 0; B:= 0;
if xKeyLen> ((NUMROUNDS*2)+4) then if xKeyLen> ((NUMROUNDS*2)+4) then
k:= xKeyLen*3 k:= xKeyLen*3
else else
k:= ((NUMROUNDS*2)+4)*3; k:= ((NUMROUNDS*2)+4)*3;
for k:= 1 to k do for k:= 1 to k do
begin begin
A:= LRot32(KeyData[i]+A+B,3); A:= LRot32(KeyData[i]+A+B,3);
KeyData[i]:= A; KeyData[i]:= A;
B:= LRot32(xKeyD[j]+A+B,A+B); B:= LRot32(xKeyD[j]+A+B,A+B);
xKeyD[j]:= B; xKeyD[j]:= B;
i:= (i+1) mod ((NUMROUNDS*2)+4); i:= (i+1) mod ((NUMROUNDS*2)+4);
j:= (j+1) mod xKeyLen; j:= (j+1) mod xKeyLen;
end; end;
FillChar(xKeyD,Sizeof(xKeyD),0); FillChar(xKeyD,Sizeof(xKeyD),0);
end; end;
procedure TDCP_rc6.Burn; procedure TDCP_rc6.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),$FF); FillChar(KeyData,Sizeof(KeyData),$FF);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_rc6.EncryptECB(const InData; var OutData); procedure TDCP_rc6.EncryptECB(const InData; var OutData);
var var
x0, x1, x2, x3: DWord; x0, x1, x2, x3: DWord;
u, t: DWord; u, t: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
x0:= PDword(@InData)^; x0:= PDword(@InData)^;
x1:= PDword(pointer(@InData)+4)^; x1:= PDword(pointer(@InData)+4)^;
x2:= PDword(pointer(@InData)+8)^; x2:= PDword(pointer(@InData)+8)^;
x3:= PDword(pointer(@InData)+12)^; x3:= PDword(pointer(@InData)+12)^;
x1:= x1 + KeyData[0]; x1:= x1 + KeyData[0];
x3:= x3 + KeyData[1]; x3:= x3 + KeyData[1];
for i:= 1 to NUMROUNDS do for i:= 1 to NUMROUNDS do
begin begin
t:= Lrot32(x1 * (2*x1 + 1),5); t:= Lrot32(x1 * (2*x1 + 1),5);
u:= Lrot32(x3 * (2*x3 + 1),5); u:= Lrot32(x3 * (2*x3 + 1),5);
x0:= Lrot32(x0 xor t,u) + KeyData[2*i]; x0:= Lrot32(x0 xor t,u) + KeyData[2*i];
x2:= Lrot32(x2 xor u,t) + KeyData[2*i+1]; x2:= Lrot32(x2 xor u,t) + KeyData[2*i+1];
t:= x0; x0:= x1; x1:= x2; x2:= x3; x3:= t; t:= x0; x0:= x1; x1:= x2; x2:= x3; x3:= t;
end; end;
x0:= x0 + KeyData[(2*NUMROUNDS)+2]; x0:= x0 + KeyData[(2*NUMROUNDS)+2];
x2:= x2 + KeyData[(2*NUMROUNDS)+3]; x2:= x2 + KeyData[(2*NUMROUNDS)+3];
PDword(@OutData)^:= x0; PDword(@OutData)^:= x0;
PDword(pointer(@OutData)+4)^:= x1; PDword(pointer(@OutData)+4)^:= x1;
PDword(pointer(@OutData)+8)^:= x2; PDword(pointer(@OutData)+8)^:= x2;
PDword(pointer(@OutData)+12)^:= x3; PDword(pointer(@OutData)+12)^:= x3;
end; end;
procedure TDCP_rc6.DecryptECB(const InData; var OutData); procedure TDCP_rc6.DecryptECB(const InData; var OutData);
var var
x0, x1, x2, x3: DWord; x0, x1, x2, x3: DWord;
u, t: DWord; u, t: DWord;
i: longword; i: longword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
x0:= PDword(@InData)^; x0:= PDword(@InData)^;
x1:= PDword(pointer(@InData)+4)^; x1:= PDword(pointer(@InData)+4)^;
x2:= PDword(pointer(@InData)+8)^; x2:= PDword(pointer(@InData)+8)^;
x3:= PDword(pointer(@InData)+12)^; x3:= PDword(pointer(@InData)+12)^;
x2:= x2 - KeyData[(2*NUMROUNDS)+3]; x2:= x2 - KeyData[(2*NUMROUNDS)+3];
x0:= x0 - KeyData[(2*NUMROUNDS)+2]; x0:= x0 - KeyData[(2*NUMROUNDS)+2];
for i:= NUMROUNDS downto 1 do for i:= NUMROUNDS downto 1 do
begin begin
t:= x0; x0:= x3; x3:= x2; x2:= x1; x1:= t; t:= x0; x0:= x3; x3:= x2; x2:= x1; x1:= t;
u:= Lrot32(x3 * (2*x3 + 1),5); u:= Lrot32(x3 * (2*x3 + 1),5);
t:= Lrot32(x1 * (2*x1 + 1),5); t:= Lrot32(x1 * (2*x1 + 1),5);
x2:= Rrot32(x2 - KeyData[2*i+1],t) xor u; x2:= Rrot32(x2 - KeyData[2*i+1],t) xor u;
x0:= Rrot32(x0 - KeyData[2*i],u) xor t; x0:= Rrot32(x0 - KeyData[2*i],u) xor t;
end; end;
x3:= x3 - KeyData[1]; x3:= x3 - KeyData[1];
x1:= x1 - KeyData[0]; x1:= x1 - KeyData[0];
PDword(@OutData)^:= x0; PDword(@OutData)^:= x0;
PDword(pointer(@OutData)+4)^:= x1; PDword(pointer(@OutData)+4)^:= x1;
PDword(pointer(@OutData)+8)^:= x2; PDword(pointer(@OutData)+8)^:= x2;
PDword(pointer(@OutData)+12)^:= x3; PDword(pointer(@OutData)+12)^:= x3;
end; end;
end. end.

View File

@ -1,363 +1,363 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Rijndael *****************************} {* A binary compatible implementation of Rijndael *****************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPrijndael; unit DCPrijndael;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
const const
BC= 4; BC= 4;
MAXROUNDS= 14; MAXROUNDS= 14;
type type
TDCP_rijndael= class(TDCP_blockcipher128) TDCP_rijndael= class(TDCP_blockcipher128)
protected protected
numrounds: longword; numrounds: longword;
rk, drk: array[0..MAXROUNDS,0..7] of DWord; rk, drk: array[0..MAXROUNDS,0..7] of DWord;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$I DCPrijndael.inc} {$I DCPrijndael.inc}
class function TDCP_rijndael.GetMaxKeySize: integer; class function TDCP_rijndael.GetMaxKeySize: integer;
begin begin
Result:= 256; Result:= 256;
end; end;
class function TDCP_rijndael.GetID: integer; class function TDCP_rijndael.GetID: integer;
begin begin
Result:= DCP_rijndael; Result:= DCP_rijndael;
end; end;
class function TDCP_rijndael.GetAlgorithm: string; class function TDCP_rijndael.GetAlgorithm: string;
begin begin
Result:= 'Rijndael'; Result:= 'Rijndael';
end; end;
class function TDCP_rijndael.SelfTest: boolean; class function TDCP_rijndael.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($00,$01,$02,$03,$05,$06,$07,$08,$0A,$0B,$0C,$0D,$0F,$10,$11,$12); ($00,$01,$02,$03,$05,$06,$07,$08,$0A,$0B,$0C,$0D,$0F,$10,$11,$12);
InData1: array[0..15] of byte= InData1: array[0..15] of byte=
($50,$68,$12,$A4,$5F,$08,$C8,$89,$B9,$7F,$59,$80,$03,$8B,$83,$59); ($50,$68,$12,$A4,$5F,$08,$C8,$89,$B9,$7F,$59,$80,$03,$8B,$83,$59);
OutData1: array[0..15] of byte= OutData1: array[0..15] of byte=
($D8,$F5,$32,$53,$82,$89,$EF,$7D,$06,$B5,$06,$A4,$FD,$5B,$E9,$C9); ($D8,$F5,$32,$53,$82,$89,$EF,$7D,$06,$B5,$06,$A4,$FD,$5B,$E9,$C9);
Key2: array[0..23] of byte= Key2: array[0..23] of byte=
($A0,$A1,$A2,$A3,$A5,$A6,$A7,$A8,$AA,$AB,$AC,$AD,$AF,$B0,$B1,$B2, ($A0,$A1,$A2,$A3,$A5,$A6,$A7,$A8,$AA,$AB,$AC,$AD,$AF,$B0,$B1,$B2,
$B4,$B5,$B6,$B7,$B9,$BA,$BB,$BC); $B4,$B5,$B6,$B7,$B9,$BA,$BB,$BC);
InData2: array[0..15] of byte= InData2: array[0..15] of byte=
($4F,$1C,$76,$9D,$1E,$5B,$05,$52,$C7,$EC,$A8,$4D,$EA,$26,$A5,$49); ($4F,$1C,$76,$9D,$1E,$5B,$05,$52,$C7,$EC,$A8,$4D,$EA,$26,$A5,$49);
OutData2: array[0..15] of byte= OutData2: array[0..15] of byte=
($F3,$84,$72,$10,$D5,$39,$1E,$23,$60,$60,$8E,$5A,$CB,$56,$05,$81); ($F3,$84,$72,$10,$D5,$39,$1E,$23,$60,$60,$8E,$5A,$CB,$56,$05,$81);
Key3: array[0..31] of byte= Key3: array[0..31] of byte=
($00,$01,$02,$03,$05,$06,$07,$08,$0A,$0B,$0C,$0D,$0F,$10,$11,$12, ($00,$01,$02,$03,$05,$06,$07,$08,$0A,$0B,$0C,$0D,$0F,$10,$11,$12,
$14,$15,$16,$17,$19,$1A,$1B,$1C,$1E,$1F,$20,$21,$23,$24,$25,$26); $14,$15,$16,$17,$19,$1A,$1B,$1C,$1E,$1F,$20,$21,$23,$24,$25,$26);
InData3: array[0..15] of byte= InData3: array[0..15] of byte=
($5E,$25,$CA,$78,$F0,$DE,$55,$80,$25,$24,$D3,$8D,$A3,$FE,$44,$56); ($5E,$25,$CA,$78,$F0,$DE,$55,$80,$25,$24,$D3,$8D,$A3,$FE,$44,$56);
OutData3: array[0..15] of byte= OutData3: array[0..15] of byte=
($E8,$B7,$2B,$4E,$8B,$E2,$43,$43,$8C,$9F,$FF,$1F,$0E,$20,$58,$72); ($E8,$B7,$2B,$4E,$8B,$E2,$43,$43,$8C,$9F,$FF,$1F,$0E,$20,$58,$72);
var var
Block: array[0..15] of byte; Block: array[0..15] of byte;
Cipher: TDCP_rijndael; Cipher: TDCP_rijndael;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_rijndael.Create(nil); Cipher:= TDCP_rijndael.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Block); Cipher.EncryptECB(InData1,Block);
Result:= boolean(CompareMem(@Block,@OutData1,16)); Result:= boolean(CompareMem(@Block,@OutData1,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData1,16)); Result:= Result and boolean(CompareMem(@Block,@InData1,16));
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Block); Cipher.EncryptECB(InData2,Block);
Result:= Result and boolean(CompareMem(@Block,@OutData2,16)); Result:= Result and boolean(CompareMem(@Block,@OutData2,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData2,16)); Result:= Result and boolean(CompareMem(@Block,@InData2,16));
Cipher.Init(Key3,Sizeof(Key3)*8,nil); Cipher.Init(Key3,Sizeof(Key3)*8,nil);
Cipher.EncryptECB(InData3,Block); Cipher.EncryptECB(InData3,Block);
Result:= Result and boolean(CompareMem(@Block,@OutData3,16)); Result:= Result and boolean(CompareMem(@Block,@OutData3,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData3,16)); Result:= Result and boolean(CompareMem(@Block,@InData3,16));
Cipher.Free; Cipher.Free;
end; end;
procedure InvMixColumn(a: PByteArray; BC: byte); procedure InvMixColumn(a: PByteArray; BC: byte);
var var
j: longword; j: longword;
begin begin
for j:= 0 to (BC-1) do for j:= 0 to (BC-1) do
PDWord(@(a^[j*4]))^:= PDWord(@U1[a^[j*4+0]])^ xor PDWord(@(a^[j*4]))^:= PDWord(@U1[a^[j*4+0]])^ xor
PDWord(@U2[a^[j*4+1]])^ xor PDWord(@U2[a^[j*4+1]])^ xor
PDWord(@U3[a^[j*4+2]])^ xor PDWord(@U3[a^[j*4+2]])^ xor
PDWord(@U4[a^[j*4+3]])^; PDWord(@U4[a^[j*4+3]])^;
end; end;
procedure TDCP_rijndael.InitKey(const Key; Size: longword); procedure TDCP_rijndael.InitKey(const Key; Size: longword);
var var
KC, ROUNDS, j, r, t, rconpointer: longword; KC, ROUNDS, j, r, t, rconpointer: longword;
tk: array[0..MAXKC-1,0..3] of byte; tk: array[0..MAXKC-1,0..3] of byte;
begin begin
Size:= Size div 8; Size:= Size div 8;
dcpFillChar(tk,Sizeof(tk),0); dcpFillChar(tk,Sizeof(tk),0);
Move(Key,tk,Size); Move(Key,tk,Size);
if Size<= 16 then if Size<= 16 then
begin begin
KC:= 4; KC:= 4;
Rounds:= 10; Rounds:= 10;
end end
else if Size<= 24 then else if Size<= 24 then
begin begin
KC:= 6; KC:= 6;
Rounds:= 12; Rounds:= 12;
end end
else else
begin begin
KC:= 8; KC:= 8;
Rounds:= 14; Rounds:= 14;
end; end;
numrounds:= rounds; numrounds:= rounds;
r:= 0; r:= 0;
t:= 0; t:= 0;
j:= 0; j:= 0;
while (j< KC) and (r< (rounds+1)) do while (j< KC) and (r< (rounds+1)) do
begin begin
while (j< KC) and (t< BC) do while (j< KC) and (t< BC) do
begin begin
rk[r,t]:= PDWord(@tk[j])^; rk[r,t]:= PDWord(@tk[j])^;
Inc(j); Inc(j);
Inc(t); Inc(t);
end; end;
if t= BC then if t= BC then
begin begin
t:= 0; t:= 0;
Inc(r); Inc(r);
end; end;
end; end;
rconpointer:= 0; rconpointer:= 0;
while (r< (rounds+1)) do while (r< (rounds+1)) do
begin begin
tk[0,0]:= tk[0,0] xor S[tk[KC-1,1]]; tk[0,0]:= tk[0,0] xor S[tk[KC-1,1]];
tk[0,1]:= tk[0,1] xor S[tk[KC-1,2]]; tk[0,1]:= tk[0,1] xor S[tk[KC-1,2]];
tk[0,2]:= tk[0,2] xor S[tk[KC-1,3]]; tk[0,2]:= tk[0,2] xor S[tk[KC-1,3]];
tk[0,3]:= tk[0,3] xor S[tk[KC-1,0]]; tk[0,3]:= tk[0,3] xor S[tk[KC-1,0]];
tk[0,0]:= tk[0,0] xor rcon[rconpointer]; tk[0,0]:= tk[0,0] xor rcon[rconpointer];
Inc(rconpointer); Inc(rconpointer);
if KC<> 8 then if KC<> 8 then
begin begin
for j:= 1 to (KC-1) do for j:= 1 to (KC-1) do
PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^; PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^;
end end
else else
begin begin
for j:= 1 to ((KC div 2)-1) do for j:= 1 to ((KC div 2)-1) do
PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^; PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^;
tk[KC div 2,0]:= tk[KC div 2,0] xor S[tk[KC div 2 - 1,0]]; tk[KC div 2,0]:= tk[KC div 2,0] xor S[tk[KC div 2 - 1,0]];
tk[KC div 2,1]:= tk[KC div 2,1] xor S[tk[KC div 2 - 1,1]]; tk[KC div 2,1]:= tk[KC div 2,1] xor S[tk[KC div 2 - 1,1]];
tk[KC div 2,2]:= tk[KC div 2,2] xor S[tk[KC div 2 - 1,2]]; tk[KC div 2,2]:= tk[KC div 2,2] xor S[tk[KC div 2 - 1,2]];
tk[KC div 2,3]:= tk[KC div 2,3] xor S[tk[KC div 2 - 1,3]]; tk[KC div 2,3]:= tk[KC div 2,3] xor S[tk[KC div 2 - 1,3]];
for j:= ((KC div 2) + 1) to (KC-1) do for j:= ((KC div 2) + 1) to (KC-1) do
PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^; PDWord(@tk[j])^:= PDWord(@tk[j])^ xor PDWord(@tk[j-1])^;
end; end;
j:= 0; j:= 0;
while (j< KC) and (r< (rounds+1)) do while (j< KC) and (r< (rounds+1)) do
begin begin
while (j< KC) and (t< BC) do while (j< KC) and (t< BC) do
begin begin
rk[r,t]:= PDWord(@tk[j])^; rk[r,t]:= PDWord(@tk[j])^;
Inc(j); Inc(j);
Inc(t); Inc(t);
end; end;
if t= BC then if t= BC then
begin begin
Inc(r); Inc(r);
t:= 0; t:= 0;
end; end;
end; end;
end; end;
Move(rk,drk,Sizeof(rk)); Move(rk,drk,Sizeof(rk));
for r:= 1 to (numrounds-1) do for r:= 1 to (numrounds-1) do
InvMixColumn(@drk[r],BC); InvMixColumn(@drk[r],BC);
end; end;
procedure TDCP_rijndael.Burn; procedure TDCP_rijndael.Burn;
begin begin
numrounds:= 0; numrounds:= 0;
FillChar(rk,Sizeof(rk),0); FillChar(rk,Sizeof(rk),0);
FillChar(drk,Sizeof(drk),0); FillChar(drk,Sizeof(drk),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_rijndael.EncryptECB(const InData; var OutData); procedure TDCP_rijndael.EncryptECB(const InData; var OutData);
var var
r: longword; r: longword;
tempb: array[0..MAXBC-1,0..3] of byte; tempb: array[0..MAXBC-1,0..3] of byte;
a: array[0..MAXBC,0..3] of byte; a: array[0..MAXBC,0..3] of byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@a[0,0])^:= PDword(@InData)^; PDword(@a[0,0])^:= PDword(@InData)^;
PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^; PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^;
PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^; PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^;
PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^; PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^;
for r:= 0 to (numrounds-2) do for r:= 0 to (numrounds-2) do
begin begin
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor rk[r,0]; PDWord(@tempb[0])^:= PDWord(@a[0])^ xor rk[r,0];
PDWord(@tempb[1])^:= PDWord(@a[1])^ xor rk[r,1]; PDWord(@tempb[1])^:= PDWord(@a[1])^ xor rk[r,1];
PDWord(@tempb[2])^:= PDWord(@a[2])^ xor rk[r,2]; PDWord(@tempb[2])^:= PDWord(@a[2])^ xor rk[r,2];
PDWord(@tempb[3])^:= PDWord(@a[3])^ xor rk[r,3]; PDWord(@tempb[3])^:= PDWord(@a[3])^ xor rk[r,3];
PDWord(@a[0])^:= PDWord(@T1[tempb[0,0]])^ xor PDWord(@a[0])^:= PDWord(@T1[tempb[0,0]])^ xor
PDWord(@T2[tempb[1,1]])^ xor PDWord(@T2[tempb[1,1]])^ xor
PDWord(@T3[tempb[2,2]])^ xor PDWord(@T3[tempb[2,2]])^ xor
PDWord(@T4[tempb[3,3]])^; PDWord(@T4[tempb[3,3]])^;
PDWord(@a[1])^:= PDWord(@T1[tempb[1,0]])^ xor PDWord(@a[1])^:= PDWord(@T1[tempb[1,0]])^ xor
PDWord(@T2[tempb[2,1]])^ xor PDWord(@T2[tempb[2,1]])^ xor
PDWord(@T3[tempb[3,2]])^ xor PDWord(@T3[tempb[3,2]])^ xor
PDWord(@T4[tempb[0,3]])^; PDWord(@T4[tempb[0,3]])^;
PDWord(@a[2])^:= PDWord(@T1[tempb[2,0]])^ xor PDWord(@a[2])^:= PDWord(@T1[tempb[2,0]])^ xor
PDWord(@T2[tempb[3,1]])^ xor PDWord(@T2[tempb[3,1]])^ xor
PDWord(@T3[tempb[0,2]])^ xor PDWord(@T3[tempb[0,2]])^ xor
PDWord(@T4[tempb[1,3]])^; PDWord(@T4[tempb[1,3]])^;
PDWord(@a[3])^:= PDWord(@T1[tempb[3,0]])^ xor PDWord(@a[3])^:= PDWord(@T1[tempb[3,0]])^ xor
PDWord(@T2[tempb[0,1]])^ xor PDWord(@T2[tempb[0,1]])^ xor
PDWord(@T3[tempb[1,2]])^ xor PDWord(@T3[tempb[1,2]])^ xor
PDWord(@T4[tempb[2,3]])^; PDWord(@T4[tempb[2,3]])^;
end; end;
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor rk[numrounds-1,0]; PDWord(@tempb[0])^:= PDWord(@a[0])^ xor rk[numrounds-1,0];
PDWord(@tempb[1])^:= PDWord(@a[1])^ xor rk[numrounds-1,1]; PDWord(@tempb[1])^:= PDWord(@a[1])^ xor rk[numrounds-1,1];
PDWord(@tempb[2])^:= PDWord(@a[2])^ xor rk[numrounds-1,2]; PDWord(@tempb[2])^:= PDWord(@a[2])^ xor rk[numrounds-1,2];
PDWord(@tempb[3])^:= PDWord(@a[3])^ xor rk[numrounds-1,3]; PDWord(@tempb[3])^:= PDWord(@a[3])^ xor rk[numrounds-1,3];
a[0,0]:= T1[tempb[0,0],1]; a[0,0]:= T1[tempb[0,0],1];
a[0,1]:= T1[tempb[1,1],1]; a[0,1]:= T1[tempb[1,1],1];
a[0,2]:= T1[tempb[2,2],1]; a[0,2]:= T1[tempb[2,2],1];
a[0,3]:= T1[tempb[3,3],1]; a[0,3]:= T1[tempb[3,3],1];
a[1,0]:= T1[tempb[1,0],1]; a[1,0]:= T1[tempb[1,0],1];
a[1,1]:= T1[tempb[2,1],1]; a[1,1]:= T1[tempb[2,1],1];
a[1,2]:= T1[tempb[3,2],1]; a[1,2]:= T1[tempb[3,2],1];
a[1,3]:= T1[tempb[0,3],1]; a[1,3]:= T1[tempb[0,3],1];
a[2,0]:= T1[tempb[2,0],1]; a[2,0]:= T1[tempb[2,0],1];
a[2,1]:= T1[tempb[3,1],1]; a[2,1]:= T1[tempb[3,1],1];
a[2,2]:= T1[tempb[0,2],1]; a[2,2]:= T1[tempb[0,2],1];
a[2,3]:= T1[tempb[1,3],1]; a[2,3]:= T1[tempb[1,3],1];
a[3,0]:= T1[tempb[3,0],1]; a[3,0]:= T1[tempb[3,0],1];
a[3,1]:= T1[tempb[0,1],1]; a[3,1]:= T1[tempb[0,1],1];
a[3,2]:= T1[tempb[1,2],1]; a[3,2]:= T1[tempb[1,2],1];
a[3,3]:= T1[tempb[2,3],1]; a[3,3]:= T1[tempb[2,3],1];
PDWord(@a[0])^:= PDWord(@a[0])^ xor rk[numrounds,0]; PDWord(@a[0])^:= PDWord(@a[0])^ xor rk[numrounds,0];
PDWord(@a[1])^:= PDWord(@a[1])^ xor rk[numrounds,1]; PDWord(@a[1])^:= PDWord(@a[1])^ xor rk[numrounds,1];
PDWord(@a[2])^:= PDWord(@a[2])^ xor rk[numrounds,2]; PDWord(@a[2])^:= PDWord(@a[2])^ xor rk[numrounds,2];
PDWord(@a[3])^:= PDWord(@a[3])^ xor rk[numrounds,3]; PDWord(@a[3])^:= PDWord(@a[3])^ xor rk[numrounds,3];
PDword(@OutData)^:= PDword(@a[0,0])^; PDword(@OutData)^:= PDword(@a[0,0])^;
PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^; PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^; PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^; PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^;
end; end;
procedure TDCP_rijndael.DecryptECB(const InData; var OutData); procedure TDCP_rijndael.DecryptECB(const InData; var OutData);
var var
r: longword; r: longword;
tempb: array[0..MAXBC-1,0..3] of byte; tempb: array[0..MAXBC-1,0..3] of byte;
a: array[0..MAXBC,0..3] of byte; a: array[0..MAXBC,0..3] of byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@a[0,0])^:= PDword(@InData)^; PDword(@a[0,0])^:= PDword(@InData)^;
PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^; PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^;
PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^; PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^;
PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^; PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^;
for r:= NumRounds downto 2 do for r:= NumRounds downto 2 do
begin begin
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor drk[r,0]; PDWord(@tempb[0])^:= PDWord(@a[0])^ xor drk[r,0];
PDWord(@tempb[1])^:= PDWord(@a[1])^ xor drk[r,1]; PDWord(@tempb[1])^:= PDWord(@a[1])^ xor drk[r,1];
PDWord(@tempb[2])^:= PDWord(@a[2])^ xor drk[r,2]; PDWord(@tempb[2])^:= PDWord(@a[2])^ xor drk[r,2];
PDWord(@tempb[3])^:= PDWord(@a[3])^ xor drk[r,3]; PDWord(@tempb[3])^:= PDWord(@a[3])^ xor drk[r,3];
PDWord(@a[0])^:= PDWord(@T5[tempb[0,0]])^ xor PDWord(@a[0])^:= PDWord(@T5[tempb[0,0]])^ xor
PDWord(@T6[tempb[3,1]])^ xor PDWord(@T6[tempb[3,1]])^ xor
PDWord(@T7[tempb[2,2]])^ xor PDWord(@T7[tempb[2,2]])^ xor
PDWord(@T8[tempb[1,3]])^; PDWord(@T8[tempb[1,3]])^;
PDWord(@a[1])^:= PDWord(@T5[tempb[1,0]])^ xor PDWord(@a[1])^:= PDWord(@T5[tempb[1,0]])^ xor
PDWord(@T6[tempb[0,1]])^ xor PDWord(@T6[tempb[0,1]])^ xor
PDWord(@T7[tempb[3,2]])^ xor PDWord(@T7[tempb[3,2]])^ xor
PDWord(@T8[tempb[2,3]])^; PDWord(@T8[tempb[2,3]])^;
PDWord(@a[2])^:= PDWord(@T5[tempb[2,0]])^ xor PDWord(@a[2])^:= PDWord(@T5[tempb[2,0]])^ xor
PDWord(@T6[tempb[1,1]])^ xor PDWord(@T6[tempb[1,1]])^ xor
PDWord(@T7[tempb[0,2]])^ xor PDWord(@T7[tempb[0,2]])^ xor
PDWord(@T8[tempb[3,3]])^; PDWord(@T8[tempb[3,3]])^;
PDWord(@a[3])^:= PDWord(@T5[tempb[3,0]])^ xor PDWord(@a[3])^:= PDWord(@T5[tempb[3,0]])^ xor
PDWord(@T6[tempb[2,1]])^ xor PDWord(@T6[tempb[2,1]])^ xor
PDWord(@T7[tempb[1,2]])^ xor PDWord(@T7[tempb[1,2]])^ xor
PDWord(@T8[tempb[0,3]])^; PDWord(@T8[tempb[0,3]])^;
end; end;
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor drk[1,0]; PDWord(@tempb[0])^:= PDWord(@a[0])^ xor drk[1,0];
PDWord(@tempb[1])^:= PDWord(@a[1])^ xor drk[1,1]; PDWord(@tempb[1])^:= PDWord(@a[1])^ xor drk[1,1];
PDWord(@tempb[2])^:= PDWord(@a[2])^ xor drk[1,2]; PDWord(@tempb[2])^:= PDWord(@a[2])^ xor drk[1,2];
PDWord(@tempb[3])^:= PDWord(@a[3])^ xor drk[1,3]; PDWord(@tempb[3])^:= PDWord(@a[3])^ xor drk[1,3];
a[0,0]:= S5[tempb[0,0]]; a[0,0]:= S5[tempb[0,0]];
a[0,1]:= S5[tempb[3,1]]; a[0,1]:= S5[tempb[3,1]];
a[0,2]:= S5[tempb[2,2]]; a[0,2]:= S5[tempb[2,2]];
a[0,3]:= S5[tempb[1,3]]; a[0,3]:= S5[tempb[1,3]];
a[1,0]:= S5[tempb[1,0]]; a[1,0]:= S5[tempb[1,0]];
a[1,1]:= S5[tempb[0,1]]; a[1,1]:= S5[tempb[0,1]];
a[1,2]:= S5[tempb[3,2]]; a[1,2]:= S5[tempb[3,2]];
a[1,3]:= S5[tempb[2,3]]; a[1,3]:= S5[tempb[2,3]];
a[2,0]:= S5[tempb[2,0]]; a[2,0]:= S5[tempb[2,0]];
a[2,1]:= S5[tempb[1,1]]; a[2,1]:= S5[tempb[1,1]];
a[2,2]:= S5[tempb[0,2]]; a[2,2]:= S5[tempb[0,2]];
a[2,3]:= S5[tempb[3,3]]; a[2,3]:= S5[tempb[3,3]];
a[3,0]:= S5[tempb[3,0]]; a[3,0]:= S5[tempb[3,0]];
a[3,1]:= S5[tempb[2,1]]; a[3,1]:= S5[tempb[2,1]];
a[3,2]:= S5[tempb[1,2]]; a[3,2]:= S5[tempb[1,2]];
a[3,3]:= S5[tempb[0,3]]; a[3,3]:= S5[tempb[0,3]];
PDWord(@a[0])^:= PDWord(@a[0])^ xor drk[0,0]; PDWord(@a[0])^:= PDWord(@a[0])^ xor drk[0,0];
PDWord(@a[1])^:= PDWord(@a[1])^ xor drk[0,1]; PDWord(@a[1])^:= PDWord(@a[1])^ xor drk[0,1];
PDWord(@a[2])^:= PDWord(@a[2])^ xor drk[0,2]; PDWord(@a[2])^:= PDWord(@a[2])^ xor drk[0,2];
PDWord(@a[3])^:= PDWord(@a[3])^ xor drk[0,3]; PDWord(@a[3])^:= PDWord(@a[3])^ xor drk[0,3];
PDword(@OutData)^:= PDword(@a[0,0])^; PDword(@OutData)^:= PDword(@a[0,0])^;
PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^; PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^; PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^; PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^;
end; end;
end. end.

View File

@ -1,282 +1,282 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Serpent ******************************} {* A binary compatible implementation of Serpent ******************************}
{* Based on C source written by Brian Gladman (gladman@seven77.demon.co.uk) ***} {* Based on C source written by Brian Gladman (gladman@seven77.demon.co.uk) ***}
{* Thanks to Bruce Christensen for the initial Delphi translation *************} {* Thanks to Bruce Christensen for the initial Delphi translation *************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 2002 David Barton *} {* Copyright (c) 2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPserpent; unit DCPserpent;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_serpent= class(TDCP_blockcipher128) TDCP_serpent= class(TDCP_blockcipher128)
protected protected
l_key: array[0..131] of dword; l_key: array[0..131] of dword;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
class function TDCP_serpent.GetID: integer; class function TDCP_serpent.GetID: integer;
begin begin
Result:= DCP_serpent; Result:= DCP_serpent;
end; end;
class function TDCP_serpent.GetAlgorithm: string; class function TDCP_serpent.GetAlgorithm: string;
begin begin
Result:= 'Serpent'; Result:= 'Serpent';
end; end;
class function TDCP_serpent.GetMaxKeySize: integer; class function TDCP_serpent.GetMaxKeySize: integer;
begin begin
Result:= 256; Result:= 256;
end; end;
class function TDCP_serpent.SelfTest: boolean; class function TDCP_serpent.SelfTest: boolean;
const const
Key1: array[0..15] of byte= Key1: array[0..15] of byte=
($ff,$ee,$dd,$cc,$bb,$aa,$99,$88,$77,$66,$55,$44,$33,$22,$11,$00); ($ff,$ee,$dd,$cc,$bb,$aa,$99,$88,$77,$66,$55,$44,$33,$22,$11,$00);
InData1: array[0..15] of byte= InData1: array[0..15] of byte=
($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01); ($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01);
OutData1: array[0..15] of byte= OutData1: array[0..15] of byte=
($d5,$ba,$a0,$0a,$4b,$b9,$d8,$a7,$c9,$81,$c8,$dc,$90,$d8,$9d,$92); ($d5,$ba,$a0,$0a,$4b,$b9,$d8,$a7,$c9,$81,$c8,$dc,$90,$d8,$9d,$92);
Key2: array[0..23] of byte= Key2: array[0..23] of byte=
($88,$99,$aa,$bb,$cc,$dd,$ee,$ff,$ff,$ee,$dd,$cc,$bb,$aa,$99,$88, ($88,$99,$aa,$bb,$cc,$dd,$ee,$ff,$ff,$ee,$dd,$cc,$bb,$aa,$99,$88,
$77,$66,$55,$44,$33,$22,$11,$00); $77,$66,$55,$44,$33,$22,$11,$00);
InData2: array[0..15] of byte= InData2: array[0..15] of byte=
($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01); ($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01);
OutData2: array[0..15] of byte= OutData2: array[0..15] of byte=
($da,$86,$08,$42,$b7,$20,$80,$2b,$f4,$04,$a4,$c7,$10,$34,$87,$9a); ($da,$86,$08,$42,$b7,$20,$80,$2b,$f4,$04,$a4,$c7,$10,$34,$87,$9a);
Key3: array[0..31] of byte= Key3: array[0..31] of byte=
($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff, ($00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff,
$ff,$ee,$dd,$cc,$bb,$aa,$99,$88,$77,$66,$55,$44,$33,$22,$11,$00); $ff,$ee,$dd,$cc,$bb,$aa,$99,$88,$77,$66,$55,$44,$33,$22,$11,$00);
InData3: array[0..15] of byte= InData3: array[0..15] of byte=
($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01); ($10,$32,$54,$76,$98,$ba,$dc,$fe,$ef,$cd,$ab,$89,$67,$45,$23,$01);
OutData3: array[0..15] of byte= OutData3: array[0..15] of byte=
($93,$df,$9a,$3c,$af,$e3,$87,$bd,$99,$9e,$eb,$e3,$93,$a1,$7f,$ca); ($93,$df,$9a,$3c,$af,$e3,$87,$bd,$99,$9e,$eb,$e3,$93,$a1,$7f,$ca);
var var
Block: array[0..15] of byte; Block: array[0..15] of byte;
Cipher: TDCP_serpent; Cipher: TDCP_serpent;
begin begin
dcpFillChar(Block, SizeOf(Block), 0); dcpFillChar(Block, SizeOf(Block), 0);
Cipher:= TDCP_serpent.Create(nil); Cipher:= TDCP_serpent.Create(nil);
Cipher.Init(Key1,Sizeof(Key1)*8,nil); Cipher.Init(Key1,Sizeof(Key1)*8,nil);
Cipher.EncryptECB(InData1,Block); Cipher.EncryptECB(InData1,Block);
Result:= boolean(CompareMem(@Block,@OutData1,16)); Result:= boolean(CompareMem(@Block,@OutData1,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData1,16)); Result:= Result and boolean(CompareMem(@Block,@InData1,16));
Cipher.Init(Key2,Sizeof(Key2)*8,nil); Cipher.Init(Key2,Sizeof(Key2)*8,nil);
Cipher.EncryptECB(InData2,Block); Cipher.EncryptECB(InData2,Block);
Result:= Result and boolean(CompareMem(@Block,@OutData2,16)); Result:= Result and boolean(CompareMem(@Block,@OutData2,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData2,16)); Result:= Result and boolean(CompareMem(@Block,@InData2,16));
Cipher.Init(Key3,Sizeof(Key3)*8,nil); Cipher.Init(Key3,Sizeof(Key3)*8,nil);
Cipher.EncryptECB(InData3,Block); Cipher.EncryptECB(InData3,Block);
Result:= Result and boolean(CompareMem(@Block,@OutData3,16)); Result:= Result and boolean(CompareMem(@Block,@OutData3,16));
Cipher.DecryptECB(Block,Block); Cipher.DecryptECB(Block,Block);
Cipher.Burn; Cipher.Burn;
Result:= Result and boolean(CompareMem(@Block,@InData3,16)); Result:= Result and boolean(CompareMem(@Block,@InData3,16));
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_serpent.InitKey(const Key; Size: longword); procedure TDCP_serpent.InitKey(const Key; Size: longword);
var var
kp: array[0..139] of dword; kp: array[0..139] of dword;
i, n: integer; i, n: integer;
t, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17: dword; t, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17: dword;
a, b, c, d: dword; a, b, c, d: dword;
begin begin
dcpFillChar(kp, SizeOf(kp), 0); dcpFillChar(kp, SizeOf(kp), 0);
Move(Key,kp,Size div 8); Move(Key,kp,Size div 8);
if Size < 256 then if Size < 256 then
begin begin
i:= Size div 32; i:= Size div 32;
t:= 1 shl (Size mod 32); t:= 1 shl (Size mod 32);
kp[i]:= (kp[i] and (t - 1)) or t; kp[i]:= (kp[i] and (t - 1)) or t;
end; end;
for i:= 8 to 139 do for i:= 8 to 139 do
begin begin
t:= kp[i - 8] xor kp[i - 5] xor kp[i - 3] xor kp[i - 1] xor $9e3779b9 xor longword(i-8); t:= kp[i - 8] xor kp[i - 5] xor kp[i - 3] xor kp[i - 1] xor $9e3779b9 xor longword(i-8);
kp[i]:= (t shl 11) or (t shr 21); kp[i]:= (t shl 11) or (t shr 21);
end; end;
for i:= 0 to 3 do for i:= 0 to 3 do
begin begin
n:= i*32; n:= i*32;
a:= kp[n + 4*0 + 8]; b:= kp[n + 4*0 + 9]; c:= kp[n + 4*0 + 10]; d:= kp[n + 4*0 + 11]; a:= kp[n + 4*0 + 8]; b:= kp[n + 4*0 + 9]; c:= kp[n + 4*0 + 10]; d:= kp[n + 4*0 + 11];
t1:= a xor c; t2:= a or d; t3:= a and b; t4:= a and d; t5:= b or t4; t6:= t1 and t2; kp[ 9+n]:= t5 xor t6; t8:= b xor d; t9:= c or t3; t10:= t6 xor t8; kp[ 11+n]:= t9 xor t10; t12:= c xor t3; t13:= t2 and kp[ 11+n]; kp[ 10+n]:= t12 xor t13; t15:= not kp[ 10+n]; t16:= t2 xor t3; t17:= kp[ 9+n] and t15; kp[ 8+n]:= t16 xor t17; t1:= a xor c; t2:= a or d; t3:= a and b; t4:= a and d; t5:= b or t4; t6:= t1 and t2; kp[ 9+n]:= t5 xor t6; t8:= b xor d; t9:= c or t3; t10:= t6 xor t8; kp[ 11+n]:= t9 xor t10; t12:= c xor t3; t13:= t2 and kp[ 11+n]; kp[ 10+n]:= t12 xor t13; t15:= not kp[ 10+n]; t16:= t2 xor t3; t17:= kp[ 9+n] and t15; kp[ 8+n]:= t16 xor t17;
a:= kp[n + 4*1 + 8]; b:= kp[n + 4*1 + 9]; c:= kp[n + 4*1 + 10]; d:= kp[n + 4*1 + 11]; a:= kp[n + 4*1 + 8]; b:= kp[n + 4*1 + 9]; c:= kp[n + 4*1 + 10]; d:= kp[n + 4*1 + 11];
t1:= not a; t2:= b xor d; t3:= c and t1; kp[ 12+n]:= t2 xor t3; t5:= c xor t1; t6:= c xor kp[ 12+n]; t7:= b and t6; kp[ 15+n]:= t5 xor t7; t9:= d or t7; t10:= kp[ 12+n] or t5; t11:= t9 and t10; kp[ 14+n]:= a xor t11; t13:= d or t1; t14:= t2 xor kp[ 15+n]; t15:= kp[ 14+n] xor t13; kp[ 13+n]:= t14 xor t15; t1:= not a; t2:= b xor d; t3:= c and t1; kp[ 12+n]:= t2 xor t3; t5:= c xor t1; t6:= c xor kp[ 12+n]; t7:= b and t6; kp[ 15+n]:= t5 xor t7; t9:= d or t7; t10:= kp[ 12+n] or t5; t11:= t9 and t10; kp[ 14+n]:= a xor t11; t13:= d or t1; t14:= t2 xor kp[ 15+n]; t15:= kp[ 14+n] xor t13; kp[ 13+n]:= t14 xor t15;
a:= kp[n + 4*2 + 8]; b:= kp[n + 4*2 + 9]; c:= kp[n + 4*2 + 10]; d:= kp[n + 4*2 + 11]; a:= kp[n + 4*2 + 8]; b:= kp[n + 4*2 + 9]; c:= kp[n + 4*2 + 10]; d:= kp[n + 4*2 + 11];
t1:= a xor d; t2:= b xor d; t3:= a and b; t4:= not c; t5:= t2 xor t3; kp[ 18+n]:= t4 xor t5; t7:= a xor t2; t8:= b or t4; t9:= d or kp[ 18+n]; t10:= t7 and t9; kp[ 17+n]:= t8 xor t10; t12:= c xor d; t13:= t1 or t2; t14:= kp[ 17+n] xor t12; kp[ 19+n]:= t13 xor t14; t16:= t1 or kp[ 18+n]; t17:= t8 xor t14; kp[ 16+n]:= t16 xor t17; t1:= a xor d; t2:= b xor d; t3:= a and b; t4:= not c; t5:= t2 xor t3; kp[ 18+n]:= t4 xor t5; t7:= a xor t2; t8:= b or t4; t9:= d or kp[ 18+n]; t10:= t7 and t9; kp[ 17+n]:= t8 xor t10; t12:= c xor d; t13:= t1 or t2; t14:= kp[ 17+n] xor t12; kp[ 19+n]:= t13 xor t14; t16:= t1 or kp[ 18+n]; t17:= t8 xor t14; kp[ 16+n]:= t16 xor t17;
a:= kp[n + 4*3 + 8]; b:= kp[n + 4*3 + 9]; c:= kp[n + 4*3 + 10]; d:= kp[n + 4*3 + 11]; a:= kp[n + 4*3 + 8]; b:= kp[n + 4*3 + 9]; c:= kp[n + 4*3 + 10]; d:= kp[n + 4*3 + 11];
t1:= b xor d; t2:= not t1; t3:= a or d; t4:= b xor c; kp[ 23+n]:= t3 xor t4; t6:= a xor b; t7:= a or t4; t8:= c and t6; t9:= t2 or t8; kp[ 20+n]:= t7 xor t9; t11:= a xor kp[ 23+n]; t12:= t1 and t6; t13:= kp[ 20+n] xor t11; kp[ 21+n]:= t12 xor t13; t15:= kp[ 20+n] or kp[ 21+n]; t16:= t3 and t15; kp[ 22+n]:= b xor t16; t1:= b xor d; t2:= not t1; t3:= a or d; t4:= b xor c; kp[ 23+n]:= t3 xor t4; t6:= a xor b; t7:= a or t4; t8:= c and t6; t9:= t2 or t8; kp[ 20+n]:= t7 xor t9; t11:= a xor kp[ 23+n]; t12:= t1 and t6; t13:= kp[ 20+n] xor t11; kp[ 21+n]:= t12 xor t13; t15:= kp[ 20+n] or kp[ 21+n]; t16:= t3 and t15; kp[ 22+n]:= b xor t16;
a:= kp[n + 4*4 + 8]; b:= kp[n + 4*4 + 9]; c:= kp[n + 4*4 + 10]; d:= kp[n + 4*4 + 11]; a:= kp[n + 4*4 + 8]; b:= kp[n + 4*4 + 9]; c:= kp[n + 4*4 + 10]; d:= kp[n + 4*4 + 11];
t1:= not c; t2:= b xor c; t3:= b or t1; t4:= d xor t3; t5:= a and t4; kp[ 27+n]:= t2 xor t5; t7:= a xor d; t8:= b xor t5; t9:= t2 or t8; kp[ 25+n]:= t7 xor t9; t11:= d and t3; t12:= t5 xor kp[ 25+n]; t13:= kp[ 27+n] and t12; kp[ 26+n]:= t11 xor t13; t15:= t1 or t4; t16:= t12 xor kp[ 26+n]; kp[ 24+n]:= t15 xor t16; t1:= not c; t2:= b xor c; t3:= b or t1; t4:= d xor t3; t5:= a and t4; kp[ 27+n]:= t2 xor t5; t7:= a xor d; t8:= b xor t5; t9:= t2 or t8; kp[ 25+n]:= t7 xor t9; t11:= d and t3; t12:= t5 xor kp[ 25+n]; t13:= kp[ 27+n] and t12; kp[ 26+n]:= t11 xor t13; t15:= t1 or t4; t16:= t12 xor kp[ 26+n]; kp[ 24+n]:= t15 xor t16;
a:= kp[n + 4*5 + 8]; b:= kp[n + 4*5 + 9]; c:= kp[n + 4*5 + 10]; d:= kp[n + 4*5 + 11]; a:= kp[n + 4*5 + 8]; b:= kp[n + 4*5 + 9]; c:= kp[n + 4*5 + 10]; d:= kp[n + 4*5 + 11];
t1:= a xor c; t2:= b or d; t3:= b xor c; t4:= not t3; t5:= a and d; kp[ 29+n]:= t4 xor t5; t7:= b or c; t8:= d xor t1; t9:= t7 and t8; kp[ 31+n]:= t2 xor t9; t11:= t1 and t7; t12:= t4 xor t8; t13:= kp[ 31+n] and t11; kp[ 28+n]:= t12 xor t13; t15:= t3 xor t11; t16:= kp[ 31+n] or t15; kp[ 30+n]:= t12 xor t16; t1:= a xor c; t2:= b or d; t3:= b xor c; t4:= not t3; t5:= a and d; kp[ 29+n]:= t4 xor t5; t7:= b or c; t8:= d xor t1; t9:= t7 and t8; kp[ 31+n]:= t2 xor t9; t11:= t1 and t7; t12:= t4 xor t8; t13:= kp[ 31+n] and t11; kp[ 28+n]:= t12 xor t13; t15:= t3 xor t11; t16:= kp[ 31+n] or t15; kp[ 30+n]:= t12 xor t16;
a:= kp[n + 4*6 + 8]; b:= kp[n + 4*6 + 9]; c:= kp[n + 4*6 + 10]; d:= kp[n + 4*6 + 11]; a:= kp[n + 4*6 + 8]; b:= kp[n + 4*6 + 9]; c:= kp[n + 4*6 + 10]; d:= kp[n + 4*6 + 11];
t1:= not a; t2:= a xor b; t3:= a xor d; t4:= c xor t1; t5:= t2 or t3; kp[ 32+n]:= t4 xor t5; t7:= not d; t8:= kp[ 32+n] and t7; kp[ 33+n]:= t2 xor t8; t10:= b or kp[ 33+n]; t11:= c or kp[ 32+n]; t12:= t7 xor t10; kp[ 35+n]:= t11 xor t12; t14:= d or kp[ 33+n]; t15:= t1 xor t14; t16:= kp[ 32+n] or kp[ 35+n]; kp[ 34+n]:= t15 xor t16; t1:= not a; t2:= a xor b; t3:= a xor d; t4:= c xor t1; t5:= t2 or t3; kp[ 32+n]:= t4 xor t5; t7:= not d; t8:= kp[ 32+n] and t7; kp[ 33+n]:= t2 xor t8; t10:= b or kp[ 33+n]; t11:= c or kp[ 32+n]; t12:= t7 xor t10; kp[ 35+n]:= t11 xor t12; t14:= d or kp[ 33+n]; t15:= t1 xor t14; t16:= kp[ 32+n] or kp[ 35+n]; kp[ 34+n]:= t15 xor t16;
a:= kp[n + 4*7 + 8]; b:= kp[n + 4*7 + 9]; c:= kp[n + 4*7 + 10]; d:= kp[n + 4*7 + 11]; a:= kp[n + 4*7 + 8]; b:= kp[n + 4*7 + 9]; c:= kp[n + 4*7 + 10]; d:= kp[n + 4*7 + 11];
t1:= not a; t2:= a xor d; t3:= a xor b; t4:= c xor t1; t5:= t2 or t3; kp[ 36+n]:= t4 xor t5; t7:= not kp[ 36+n]; t8:= b or t7; kp[ 39+n]:= t2 xor t8; t10:= a and kp[ 36+n]; t11:= b xor kp[ 39+n]; t12:= t8 and t11; kp[ 38+n]:= t10 xor t12; t14:= a or t7; t15:= t3 xor t14; t16:= kp[ 39+n] and kp[ 38+n]; kp[ 37+n]:= t15 xor t16; t1:= not a; t2:= a xor d; t3:= a xor b; t4:= c xor t1; t5:= t2 or t3; kp[ 36+n]:= t4 xor t5; t7:= not kp[ 36+n]; t8:= b or t7; kp[ 39+n]:= t2 xor t8; t10:= a and kp[ 36+n]; t11:= b xor kp[ 39+n]; t12:= t8 and t11; kp[ 38+n]:= t10 xor t12; t14:= a or t7; t15:= t3 xor t14; t16:= kp[ 39+n] and kp[ 38+n]; kp[ 37+n]:= t15 xor t16;
end; end;
a:= kp[136]; b:= kp[137]; c:= kp[138]; d:= kp[139]; a:= kp[136]; b:= kp[137]; c:= kp[138]; d:= kp[139];
t1:= a xor c; t2:= a or d; t3:= a and b; t4:= a and d; t5:= b or t4; t6:= t1 and t2; kp[137]:= t5 xor t6; t8:= b xor d; t9:= c or t3; t10:= t6 xor t8; kp[139]:= t9 xor t10; t12:= c xor t3; t13:= t2 and kp[139]; kp[138]:= t12 xor t13; t15:= not kp[138]; t16:= t2 xor t3; t17:= kp[137] and t15; kp[136]:= t16 xor t17; t1:= a xor c; t2:= a or d; t3:= a and b; t4:= a and d; t5:= b or t4; t6:= t1 and t2; kp[137]:= t5 xor t6; t8:= b xor d; t9:= c or t3; t10:= t6 xor t8; kp[139]:= t9 xor t10; t12:= c xor t3; t13:= t2 and kp[139]; kp[138]:= t12 xor t13; t15:= not kp[138]; t16:= t2 xor t3; t17:= kp[137] and t15; kp[136]:= t16 xor t17;
Move(kp[8],l_key,Sizeof(l_key)); Move(kp[8],l_key,Sizeof(l_key));
FillChar(kp,Sizeof(kp),0); FillChar(kp,Sizeof(kp),0);
end; end;
procedure TDCP_serpent.Burn; procedure TDCP_serpent.Burn;
begin begin
FillChar(l_key,Sizeof(l_key),0); FillChar(l_key,Sizeof(l_key),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_serpent.EncryptECB(const InData; var OutData); procedure TDCP_serpent.EncryptECB(const InData; var OutData);
var var
i: integer; i: integer;
a, b, c, d, e, f, g, h: dword; a, b, c, d, e, f, g, h: dword;
t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17: dword; t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17: dword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
a:= PDWord(@InData)^; a:= PDWord(@InData)^;
b:= PDWord(pointer(@InData)+4)^; b:= PDWord(pointer(@InData)+4)^;
c:= PDWord(pointer(@InData)+8)^; c:= PDWord(pointer(@InData)+8)^;
d:= PDWord(pointer(@InData)+12)^; d:= PDWord(pointer(@InData)+12)^;
i:= 0; i:= 0;
while i < 32 do while i < 32 do
begin begin
a:= a xor l_key[4*(i)]; b:= b xor l_key[4*(i)+1]; c:= c xor l_key[4*(i)+2]; d:= d xor l_key[4*(i)+3]; a:= a xor l_key[4*(i)]; b:= b xor l_key[4*(i)+1]; c:= c xor l_key[4*(i)+2]; d:= d xor l_key[4*(i)+3];
t1:= b xor d; t2:= not t1; t3:= a or d; t4:= b xor c; h:= t3 xor t4; t6:= a xor b; t7:= a or t4; t8:= c and t6; t9:= t2 or t8; e:= t7 xor t9; t11:= a xor h; t12:= t1 and t6; t13:= e xor t11; f:= t12 xor t13; t15:= e or f; t16:= t3 and t15; g:= b xor t16; t1:= b xor d; t2:= not t1; t3:= a or d; t4:= b xor c; h:= t3 xor t4; t6:= a xor b; t7:= a or t4; t8:= c and t6; t9:= t2 or t8; e:= t7 xor t9; t11:= a xor h; t12:= t1 and t6; t13:= e xor t11; f:= t12 xor t13; t15:= e or f; t16:= t3 and t15; g:= b xor t16;
e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10); e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10);
e:= e xor l_key[4*(i+1)]; f:= f xor l_key[4*(i+1)+1]; g:= g xor l_key[4*(i+1)+2]; h:= h xor l_key[4*(i+1)+3]; e:= e xor l_key[4*(i+1)]; f:= f xor l_key[4*(i+1)+1]; g:= g xor l_key[4*(i+1)+2]; h:= h xor l_key[4*(i+1)+3];
t1:= e xor h; t2:= f xor h; t3:= e and f; t4:= not g; t5:= t2 xor t3; c:= t4 xor t5; t7:= e xor t2; t8:= f or t4; t9:= h or c; t10:= t7 and t9; b:= t8 xor t10; t12:= g xor h; t13:= t1 or t2; t14:= b xor t12; d:= t13 xor t14; t16:= t1 or c; t17:= t8 xor t14; a:= t16 xor t17; t1:= e xor h; t2:= f xor h; t3:= e and f; t4:= not g; t5:= t2 xor t3; c:= t4 xor t5; t7:= e xor t2; t8:= f or t4; t9:= h or c; t10:= t7 and t9; b:= t8 xor t10; t12:= g xor h; t13:= t1 or t2; t14:= b xor t12; d:= t13 xor t14; t16:= t1 or c; t17:= t8 xor t14; a:= t16 xor t17;
a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10); a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10);
a:= a xor l_key[4*(i+2)]; b:= b xor l_key[4*(i+2)+1]; c:= c xor l_key[4*(i+2)+2]; d:= d xor l_key[4*(i+2)+3]; a:= a xor l_key[4*(i+2)]; b:= b xor l_key[4*(i+2)+1]; c:= c xor l_key[4*(i+2)+2]; d:= d xor l_key[4*(i+2)+3];
t1:= not a; t2:= b xor d; t3:= c and t1; e:= t2 xor t3; t5:= c xor t1; t6:= c xor e; t7:= b and t6; h:= t5 xor t7; t9:= d or t7; t10:= e or t5; t11:= t9 and t10; g:= a xor t11; t13:= d or t1; t14:= t2 xor h; t15:= g xor t13; f:= t14 xor t15; t1:= not a; t2:= b xor d; t3:= c and t1; e:= t2 xor t3; t5:= c xor t1; t6:= c xor e; t7:= b and t6; h:= t5 xor t7; t9:= d or t7; t10:= e or t5; t11:= t9 and t10; g:= a xor t11; t13:= d or t1; t14:= t2 xor h; t15:= g xor t13; f:= t14 xor t15;
e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10); e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10);
e:= e xor l_key[4*(i+3)]; f:= f xor l_key[4*(i+3)+1]; g:= g xor l_key[4*(i+3)+2]; h:= h xor l_key[4*(i+3)+3]; e:= e xor l_key[4*(i+3)]; f:= f xor l_key[4*(i+3)+1]; g:= g xor l_key[4*(i+3)+2]; h:= h xor l_key[4*(i+3)+3];
t1:= e xor g; t2:= e or h; t3:= e and f; t4:= e and h; t5:= f or t4; t6:= t1 and t2; b:= t5 xor t6; t8:= f xor h; t9:= g or t3; t10:= t6 xor t8; d:= t9 xor t10; t12:= g xor t3; t13:= t2 and d; c:= t12 xor t13; t15:= not c; t16:= t2 xor t3; t17:= b and t15; a:= t16 xor t17; t1:= e xor g; t2:= e or h; t3:= e and f; t4:= e and h; t5:= f or t4; t6:= t1 and t2; b:= t5 xor t6; t8:= f xor h; t9:= g or t3; t10:= t6 xor t8; d:= t9 xor t10; t12:= g xor t3; t13:= t2 and d; c:= t12 xor t13; t15:= not c; t16:= t2 xor t3; t17:= b and t15; a:= t16 xor t17;
a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10); a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10);
a:= a xor l_key[4*(i+4)]; b:= b xor l_key[4*(i+4)+1]; c:= c xor l_key[4*(i+4)+2]; d:= d xor l_key[4*(i+4)+3]; a:= a xor l_key[4*(i+4)]; b:= b xor l_key[4*(i+4)+1]; c:= c xor l_key[4*(i+4)+2]; d:= d xor l_key[4*(i+4)+3];
t1:= not a; t2:= a xor d; t3:= a xor b; t4:= c xor t1; t5:= t2 or t3; e:= t4 xor t5; t7:= not e; t8:= b or t7; h:= t2 xor t8; t10:= a and e; t11:= b xor h; t12:= t8 and t11; g:= t10 xor t12; t14:= a or t7; t15:= t3 xor t14; t16:= h and g; f:= t15 xor t16; t1:= not a; t2:= a xor d; t3:= a xor b; t4:= c xor t1; t5:= t2 or t3; e:= t4 xor t5; t7:= not e; t8:= b or t7; h:= t2 xor t8; t10:= a and e; t11:= b xor h; t12:= t8 and t11; g:= t10 xor t12; t14:= a or t7; t15:= t3 xor t14; t16:= h and g; f:= t15 xor t16;
e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10); e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10);
e:= e xor l_key[4*(i+5)]; f:= f xor l_key[4*(i+5)+1]; g:= g xor l_key[4*(i+5)+2]; h:= h xor l_key[4*(i+5)+3]; e:= e xor l_key[4*(i+5)]; f:= f xor l_key[4*(i+5)+1]; g:= g xor l_key[4*(i+5)+2]; h:= h xor l_key[4*(i+5)+3];
t1:= not e; t2:= e xor f; t3:= e xor h; t4:= g xor t1; t5:= t2 or t3; a:= t4 xor t5; t7:= not h; t8:= a and t7; b:= t2 xor t8; t10:= f or b; t11:= g or a; t12:= t7 xor t10; d:= t11 xor t12; t14:= h or b; t15:= t1 xor t14; t16:= a or d; c:= t15 xor t16; t1:= not e; t2:= e xor f; t3:= e xor h; t4:= g xor t1; t5:= t2 or t3; a:= t4 xor t5; t7:= not h; t8:= a and t7; b:= t2 xor t8; t10:= f or b; t11:= g or a; t12:= t7 xor t10; d:= t11 xor t12; t14:= h or b; t15:= t1 xor t14; t16:= a or d; c:= t15 xor t16;
a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10); a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10);
a:= a xor l_key[4*(i+6)]; b:= b xor l_key[4*(i+6)+1]; c:= c xor l_key[4*(i+6)+2]; d:= d xor l_key[4*(i+6)+3]; a:= a xor l_key[4*(i+6)]; b:= b xor l_key[4*(i+6)+1]; c:= c xor l_key[4*(i+6)+2]; d:= d xor l_key[4*(i+6)+3];
t1:= a xor c; t2:= b or d; t3:= b xor c; t4:= not t3; t5:= a and d; f:= t4 xor t5; t7:= b or c; t8:= d xor t1; t9:= t7 and t8; h:= t2 xor t9; t11:= t1 and t7; t12:= t4 xor t8; t13:= h and t11; e:= t12 xor t13; t15:= t3 xor t11; t16:= h or t15; g:= t12 xor t16; t1:= a xor c; t2:= b or d; t3:= b xor c; t4:= not t3; t5:= a and d; f:= t4 xor t5; t7:= b or c; t8:= d xor t1; t9:= t7 and t8; h:= t2 xor t9; t11:= t1 and t7; t12:= t4 xor t8; t13:= h and t11; e:= t12 xor t13; t15:= t3 xor t11; t16:= h or t15; g:= t12 xor t16;
e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10); e:= (e shl 13) or (e shr 19); g:= (g shl 3) or (g shr 29); f:= f xor e xor g; h:= h xor g xor (e shl 3); f:= (f shl 1) or (f shr 31); h:= (h shl 7) or (h shr 25); e:= e xor f xor h; g:= g xor h xor (f shl 7); e:= (e shl 5) or (e shr 27); g:= (g shl 22) or (g shr 10);
e:= e xor l_key[4*(i+7)]; f:= f xor l_key[4*(i+7)+1]; g:= g xor l_key[4*(i+7)+2]; h:= h xor l_key[4*(i+7)+3]; e:= e xor l_key[4*(i+7)]; f:= f xor l_key[4*(i+7)+1]; g:= g xor l_key[4*(i+7)+2]; h:= h xor l_key[4*(i+7)+3];
t1:= not g; t2:= f xor g; t3:= f or t1; t4:= h xor t3; t5:= e and t4; d:= t2 xor t5; t7:= e xor h; t8:= f xor t5; t9:= t2 or t8; b:= t7 xor t9; t11:= h and t3; t12:= t5 xor b; t13:= d and t12; c:= t11 xor t13; t15:= t1 or t4; t16:= t12 xor c; a:= t15 xor t16; t1:= not g; t2:= f xor g; t3:= f or t1; t4:= h xor t3; t5:= e and t4; d:= t2 xor t5; t7:= e xor h; t8:= f xor t5; t9:= t2 or t8; b:= t7 xor t9; t11:= h and t3; t12:= t5 xor b; t13:= d and t12; c:= t11 xor t13; t15:= t1 or t4; t16:= t12 xor c; a:= t15 xor t16;
Inc(i,8); Inc(i,8);
if i < 32 then if i < 32 then
begin begin
a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10); a:= (a shl 13) or (a shr 19); c:= (c shl 3) or (c shr 29); b:= b xor a xor c; d:= d xor c xor (a shl 3); b:= (b shl 1) or (b shr 31); d:= (d shl 7) or (d shr 25); a:= a xor b xor d; c:= c xor d xor (b shl 7); a:= (a shl 5) or (a shr 27); c:= (c shl 22) or (c shr 10);
end; end;
end; end;
a:= a xor l_key[128]; b:= b xor l_key[128+1]; c:= c xor l_key[128+2]; d:= d xor l_key[128+3]; a:= a xor l_key[128]; b:= b xor l_key[128+1]; c:= c xor l_key[128+2]; d:= d xor l_key[128+3];
PDWord(pointer(@OutData)+ 0)^:= a; PDWord(pointer(@OutData)+ 0)^:= a;
PDWord(pointer(@OutData)+ 4)^:= b; PDWord(pointer(@OutData)+ 4)^:= b;
PDWord(pointer(@OutData)+ 8)^:= c; PDWord(pointer(@OutData)+ 8)^:= c;
PDWord(pointer(@OutData)+12)^:= d; PDWord(pointer(@OutData)+12)^:= d;
end; end;
procedure TDCP_serpent.DecryptECB(const InData; var OutData); procedure TDCP_serpent.DecryptECB(const InData; var OutData);
var var
i: integer; i: integer;
a, b, c, d, e, f, g, h: dword; a, b, c, d, e, f, g, h: dword;
t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16: dword; t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16: dword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
a:= PDWord(@InData)^; a:= PDWord(@InData)^;
b:= PDWord(pointer(@InData)+4)^; b:= PDWord(pointer(@InData)+4)^;
c:= PDWord(pointer(@InData)+8)^; c:= PDWord(pointer(@InData)+8)^;
d:= PDWord(pointer(@InData)+12)^; d:= PDWord(pointer(@InData)+12)^;
i:= 32; i:= 32;
a:= a xor l_key[4*32]; b:= b xor l_key[4*32+1]; c:= c xor l_key[4*32+2]; d:= d xor l_key[4*32+3]; a:= a xor l_key[4*32]; b:= b xor l_key[4*32+1]; c:= c xor l_key[4*32+2]; d:= d xor l_key[4*32+3];
while i > 0 do while i > 0 do
begin begin
if i < 32 then if i < 32 then
begin begin
c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19); c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19);
end; end;
t1:= a and b; t2:= a or b; t3:= c or t1; t4:= d and t2; h:= t3 xor t4; t6:= not d; t7:= b xor t4; t8:= h xor t6; t9:= t7 or t8; f:= a xor t9; t11:= c xor t7; t12:= d or f; e:= t11 xor t12; t14:= a and h; t15:= t3 xor f; t16:= e xor t14; g:= t15 xor t16; t1:= a and b; t2:= a or b; t3:= c or t1; t4:= d and t2; h:= t3 xor t4; t6:= not d; t7:= b xor t4; t8:= h xor t6; t9:= t7 or t8; f:= a xor t9; t11:= c xor t7; t12:= d or f; e:= t11 xor t12; t14:= a and h; t15:= t3 xor f; t16:= e xor t14; g:= t15 xor t16;
e:= e xor l_key[4*(i-1)]; f:= f xor l_key[4*(i-1)+1]; g:= g xor l_key[4*(i-1)+2]; h:= h xor l_key[4*(i-1)+3]; e:= e xor l_key[4*(i-1)]; f:= f xor l_key[4*(i-1)+1]; g:= g xor l_key[4*(i-1)+2]; h:= h xor l_key[4*(i-1)+3];
g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19); g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19);
t1:= not g; t2:= e xor g; t3:= f xor h; t4:= e or t1; b:= t3 xor t4; t6:= e or f; t7:= f and t2; t8:= b xor t6; t9:= t7 or t8; a:= g xor t9; t11:= not b; t12:= h or t2; t13:= t9 xor t11; d:= t12 xor t13; t15:= f xor t11; t16:= a and d; c:= t15 xor t16; t1:= not g; t2:= e xor g; t3:= f xor h; t4:= e or t1; b:= t3 xor t4; t6:= e or f; t7:= f and t2; t8:= b xor t6; t9:= t7 or t8; a:= g xor t9; t11:= not b; t12:= h or t2; t13:= t9 xor t11; d:= t12 xor t13; t15:= f xor t11; t16:= a and d; c:= t15 xor t16;
a:= a xor l_key[4*(i-2)]; b:= b xor l_key[4*(i-2)+1]; c:= c xor l_key[4*(i-2)+2]; d:= d xor l_key[4*(i-2)+3]; a:= a xor l_key[4*(i-2)]; b:= b xor l_key[4*(i-2)+1]; c:= c xor l_key[4*(i-2)+2]; d:= d xor l_key[4*(i-2)+3];
c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19); c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19);
t1:= not c; t2:= b and t1; t3:= d xor t2; t4:= a and t3; t5:= b xor t1; h:= t4 xor t5; t7:= b or h; t8:= a and t7; f:= t3 xor t8; t10:= a or d; t11:= t1 xor t7; e:= t10 xor t11; t13:= a xor c; t14:= b and t10; t15:= t4 or t13; g:= t14 xor t15; t1:= not c; t2:= b and t1; t3:= d xor t2; t4:= a and t3; t5:= b xor t1; h:= t4 xor t5; t7:= b or h; t8:= a and t7; f:= t3 xor t8; t10:= a or d; t11:= t1 xor t7; e:= t10 xor t11; t13:= a xor c; t14:= b and t10; t15:= t4 or t13; g:= t14 xor t15;
e:= e xor l_key[4*(i-3)]; f:= f xor l_key[4*(i-3)+1]; g:= g xor l_key[4*(i-3)+2]; h:= h xor l_key[4*(i-3)+3]; e:= e xor l_key[4*(i-3)]; f:= f xor l_key[4*(i-3)+1]; g:= g xor l_key[4*(i-3)+2]; h:= h xor l_key[4*(i-3)+3];
g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19); g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19);
t1:= g xor h; t2:= g or h; t3:= f xor t2; t4:= e and t3; b:= t1 xor t4; t6:= e xor h; t7:= f or h; t8:= t6 and t7; d:= t3 xor t8; t10:= not e; t11:= g xor d; t12:= t10 or t11; a:= t3 xor t12; t14:= g or t4; t15:= t7 xor t14; t16:= d or t10; c:= t15 xor t16; t1:= g xor h; t2:= g or h; t3:= f xor t2; t4:= e and t3; b:= t1 xor t4; t6:= e xor h; t7:= f or h; t8:= t6 and t7; d:= t3 xor t8; t10:= not e; t11:= g xor d; t12:= t10 or t11; a:= t3 xor t12; t14:= g or t4; t15:= t7 xor t14; t16:= d or t10; c:= t15 xor t16;
a:= a xor l_key[4*(i-4)]; b:= b xor l_key[4*(i-4)+1]; c:= c xor l_key[4*(i-4)+2]; d:= d xor l_key[4*(i-4)+3]; a:= a xor l_key[4*(i-4)]; b:= b xor l_key[4*(i-4)+1]; c:= c xor l_key[4*(i-4)+2]; d:= d xor l_key[4*(i-4)+3];
c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19); c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19);
t1:= b xor c; t2:= b or c; t3:= a xor c; t4:= t2 xor t3; t5:= d or t4; e:= t1 xor t5; t7:= a xor d; t8:= t1 or t5; t9:= t2 xor t7; g:= t8 xor t9; t11:= a and t4; t12:= e or t9; f:= t11 xor t12; t14:= a and g; t15:= t2 xor t14; t16:= e and t15; h:= t4 xor t16; t1:= b xor c; t2:= b or c; t3:= a xor c; t4:= t2 xor t3; t5:= d or t4; e:= t1 xor t5; t7:= a xor d; t8:= t1 or t5; t9:= t2 xor t7; g:= t8 xor t9; t11:= a and t4; t12:= e or t9; f:= t11 xor t12; t14:= a and g; t15:= t2 xor t14; t16:= e and t15; h:= t4 xor t16;
e:= e xor l_key[4*(i-5)]; f:= f xor l_key[4*(i-5)+1]; g:= g xor l_key[4*(i-5)+2]; h:= h xor l_key[4*(i-5)+3]; e:= e xor l_key[4*(i-5)]; f:= f xor l_key[4*(i-5)+1]; g:= g xor l_key[4*(i-5)+2]; h:= h xor l_key[4*(i-5)+3];
g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19); g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19);
t1:= f xor h; t2:= not t1; t3:= e xor g; t4:= g xor t1; t5:= f and t4; a:= t3 xor t5; t7:= e or t2; t8:= h xor t7; t9:= t3 or t8; d:= t1 xor t9; t11:= not t4; t12:= a or d; b:= t11 xor t12; t14:= h and t11; t15:= t3 xor t12; c:= t14 xor t15; t1:= f xor h; t2:= not t1; t3:= e xor g; t4:= g xor t1; t5:= f and t4; a:= t3 xor t5; t7:= e or t2; t8:= h xor t7; t9:= t3 or t8; d:= t1 xor t9; t11:= not t4; t12:= a or d; b:= t11 xor t12; t14:= h and t11; t15:= t3 xor t12; c:= t14 xor t15;
a:= a xor l_key[4*(i-6)]; b:= b xor l_key[4*(i-6)+1]; c:= c xor l_key[4*(i-6)+2]; d:= d xor l_key[4*(i-6)+3]; a:= a xor l_key[4*(i-6)]; b:= b xor l_key[4*(i-6)+1]; c:= c xor l_key[4*(i-6)+2]; d:= d xor l_key[4*(i-6)+3];
c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19); c:= (c shr 22) or (c shl 10); a:= (a shr 5) or (a shl 27); c:= c xor d xor (b shl 7); a:= a xor b xor d; d:= (d shr 7) or (d shl 25); b:= (b shr 1) or (b shl 31); d:= d xor c xor (a shl 3); b:= b xor a xor c; c:= (c shr 3) or (c shl 29); a:= (a shr 13) or (a shl 19);
t1:= a xor d; t2:= a and b; t3:= b xor c; t4:= a xor t3; t5:= b or d; h:= t4 xor t5; t7:= c or t1; t8:= b xor t7; t9:= t4 and t8; f:= t1 xor t9; t11:= not t2; t12:= h and f; t13:= t9 xor t11; g:= t12 xor t13; t15:= a and d; t16:= c xor t13; e:= t15 xor t16; t1:= a xor d; t2:= a and b; t3:= b xor c; t4:= a xor t3; t5:= b or d; h:= t4 xor t5; t7:= c or t1; t8:= b xor t7; t9:= t4 and t8; f:= t1 xor t9; t11:= not t2; t12:= h and f; t13:= t9 xor t11; g:= t12 xor t13; t15:= a and d; t16:= c xor t13; e:= t15 xor t16;
e:= e xor l_key[4*(i-7)]; f:= f xor l_key[4*(i-7)+1]; g:= g xor l_key[4*(i-7)+2]; h:= h xor l_key[4*(i-7)+3]; e:= e xor l_key[4*(i-7)]; f:= f xor l_key[4*(i-7)+1]; g:= g xor l_key[4*(i-7)+2]; h:= h xor l_key[4*(i-7)+3];
g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19); g:= (g shr 22) or (g shl 10); e:= (e shr 5) or (e shl 27); g:= g xor h xor (f shl 7); e:= e xor f xor h; h:= (h shr 7) or (h shl 25); f:= (f shr 1) or (f shl 31); h:= h xor g xor (e shl 3); f:= f xor e xor g; g:= (g shr 3) or (g shl 29); e:= (e shr 13) or (e shl 19);
t1:= e xor h; t2:= g xor h; t3:= not t2; t4:= e or f; c:= t3 xor t4; t6:= f xor t1; t7:= g or t6; t8:= e xor t7; t9:= t2 and t8; b:= t6 xor t9; t11:= not t8; t12:= f and h; t13:= b or t12; d:= t11 xor t13; t15:= t2 xor t12; t16:= b or d; a:= t15 xor t16; t1:= e xor h; t2:= g xor h; t3:= not t2; t4:= e or f; c:= t3 xor t4; t6:= f xor t1; t7:= g or t6; t8:= e xor t7; t9:= t2 and t8; b:= t6 xor t9; t11:= not t8; t12:= f and h; t13:= b or t12; d:= t11 xor t13; t15:= t2 xor t12; t16:= b or d; a:= t15 xor t16;
a:= a xor l_key[4*(i-8)]; b:= b xor l_key[4*(i-8)+1]; c:= c xor l_key[4*(i-8)+2]; d:= d xor l_key[4*(i-8)+3]; a:= a xor l_key[4*(i-8)]; b:= b xor l_key[4*(i-8)+1]; c:= c xor l_key[4*(i-8)+2]; d:= d xor l_key[4*(i-8)+3];
Dec(i,8); Dec(i,8);
end; end;
PDWord(pointer(@OutData)+ 0)^:= a; PDWord(pointer(@OutData)+ 0)^:= a;
PDWord(pointer(@OutData)+ 4)^:= b; PDWord(pointer(@OutData)+ 4)^:= b;
PDWord(pointer(@OutData)+ 8)^:= c; PDWord(pointer(@OutData)+ 8)^:= c;
PDWord(pointer(@OutData)+12)^:= d; PDWord(pointer(@OutData)+12)^:= d;
end; end;
end. end.

View File

@ -1,155 +1,155 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Tea **********************************} {* A binary compatible implementation of Tea **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPtea; unit DCPtea;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers; Classes, Sysutils, DCPcrypt2, DCPconst, DCPblockciphers;
type type
TDCP_tea= class(TDCP_blockcipher64) TDCP_tea= class(TDCP_blockcipher64)
protected protected
KeyData: array[0..3] of dword; KeyData: array[0..3] of dword;
procedure InitKey(const Key; Size: longword); override; procedure InitKey(const Key; Size: longword); override;
public public
class function GetID: integer; override; class function GetID: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetMaxKeySize: integer; override; class function GetMaxKeySize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Burn; override; procedure Burn; override;
procedure EncryptECB(const InData; var OutData); override; procedure EncryptECB(const InData; var OutData); override;
procedure DecryptECB(const InData; var OutData); override; procedure DecryptECB(const InData; var OutData); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
const const
Delta: DWord = $9e3779b9; Delta: DWord = $9e3779b9;
Rounds= 32; Rounds= 32;
function SwapDword(a: dword): dword; function SwapDword(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
class function TDCP_tea.GetID: integer; class function TDCP_tea.GetID: integer;
begin begin
Result:= DCP_tea; Result:= DCP_tea;
end; end;
class function TDCP_tea.GetAlgorithm: string; class function TDCP_tea.GetAlgorithm: string;
begin begin
Result:= 'Tea'; Result:= 'Tea';
end; end;
class function TDCP_tea.GetMaxKeySize: integer; class function TDCP_tea.GetMaxKeySize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_tea.SelfTest: boolean; class function TDCP_tea.SelfTest: boolean;
const const
Key: array[0..3] of dword= ($12345678,$9ABCDEF0,$0FEDCBA9,$87654321); Key: array[0..3] of dword= ($12345678,$9ABCDEF0,$0FEDCBA9,$87654321);
PT: array[0..1] of dword= ($12345678,$9ABCDEF0); PT: array[0..1] of dword= ($12345678,$9ABCDEF0);
var var
Data: array[0..1] of dword; Data: array[0..1] of dword;
Cipher: TDCP_tea; Cipher: TDCP_tea;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Cipher:= TDCP_tea.Create(nil); Cipher:= TDCP_tea.Create(nil);
Cipher.Init(Key,Sizeof(Key)*8,nil); Cipher.Init(Key,Sizeof(Key)*8,nil);
Cipher.EncryptECB(PT,Data); Cipher.EncryptECB(PT,Data);
Result:= not CompareMem(@Data,@PT,Sizeof(PT)); Result:= not CompareMem(@Data,@PT,Sizeof(PT));
Cipher.DecryptECB(Data,Data); Cipher.DecryptECB(Data,Data);
Result:= Result and CompareMem(@Data,@PT,Sizeof(PT)); Result:= Result and CompareMem(@Data,@PT,Sizeof(PT));
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
end; end;
procedure TDCP_tea.InitKey(const Key; Size: longword); procedure TDCP_tea.InitKey(const Key; Size: longword);
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
Move(Key,KeyData,Size div 8); Move(Key,KeyData,Size div 8);
KeyData[0]:= SwapDWord(KeyData[0]); KeyData[1]:= SwapDWord(KeyData[1]); KeyData[0]:= SwapDWord(KeyData[0]); KeyData[1]:= SwapDWord(KeyData[1]);
KeyData[2]:= SwapDWord(KeyData[2]); KeyData[3]:= SwapDWord(KeyData[3]); KeyData[2]:= SwapDWord(KeyData[2]); KeyData[3]:= SwapDWord(KeyData[3]);
end; end;
procedure TDCP_tea.Burn; procedure TDCP_tea.Burn;
begin begin
FillChar(KeyData,Sizeof(KeyData),0); FillChar(KeyData,Sizeof(KeyData),0);
inherited Burn; inherited Burn;
end; end;
procedure TDCP_tea.EncryptECB(const InData; var OutData); procedure TDCP_tea.EncryptECB(const InData; var OutData);
var var
a, b, c, d, x, y, n, sum: dword; a, b, c, d, x, y, n, sum: dword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
x:= SwapDWord(pdword(@InData)^); x:= SwapDWord(pdword(@InData)^);
y:= SwapDWord(pdword(pointer(@InData)+4)^); y:= SwapDWord(pdword(pointer(@InData)+4)^);
sum:= 0; a:= KeyData[0]; b:= KeyData[1]; c:= KeyData[2]; d:= KeyData[3]; sum:= 0; a:= KeyData[0]; b:= KeyData[1]; c:= KeyData[2]; d:= KeyData[3];
for n:= 1 to Rounds do for n:= 1 to Rounds do
begin begin
Inc(sum,Delta); Inc(sum,Delta);
Inc(x,(y shl 4) + (a xor y) + (sum xor (y shr 5)) + b); Inc(x,(y shl 4) + (a xor y) + (sum xor (y shr 5)) + b);
Inc(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d); Inc(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d);
end; end;
pdword(@OutData)^:= SwapDWord(x); pdword(@OutData)^:= SwapDWord(x);
pdword(pointer(@OutData)+4)^:= SwapDWord(y); pdword(pointer(@OutData)+4)^:= SwapDWord(y);
end; end;
procedure TDCP_tea.DecryptECB(const InData; var OutData); procedure TDCP_tea.DecryptECB(const InData; var OutData);
var var
a, b, c, d, x, y, n, sum: dword; a, b, c, d, x, y, n, sum: dword;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized'); raise EDCP_blockcipher.Create('Cipher not initialized');
x:= SwapDWord(pdword(@InData)^); x:= SwapDWord(pdword(@InData)^);
y:= SwapDWord(pdword(pointer(@InData)+4)^); y:= SwapDWord(pdword(pointer(@InData)+4)^);
sum:= Delta shl 5; sum:= Delta shl 5;
a:= KeyData[0]; a:= KeyData[0];
b:= KeyData[1]; b:= KeyData[1];
c:= KeyData[2]; c:= KeyData[2];
d:= KeyData[3]; d:= KeyData[3];
for n:= 1 to Rounds do for n:= 1 to Rounds do
begin begin
Dec(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d); Dec(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d);
Dec(x,(y shl 4) + (a xor y) + (sum xor (y shr 5)) + b); Dec(x,(y shl 4) + (a xor y) + (sum xor (y shr 5)) + b);
Dec(sum,Delta); Dec(sum,Delta);
end; end;
pdword(@OutData)^:= SwapDWord(x); pdword(@OutData)^:= SwapDWord(x);
pdword(pointer(@OutData)+4)^:= SwapDWord(y); pdword(pointer(@OutData)+4)^:= SwapDWord(y);
end; end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -1,84 +1,84 @@
<html> <html>
<head> <head>
<title>DCPcrypt v2: Users Guide - Block Ciphers</title> <title>DCPcrypt v2: Users Guide - Block Ciphers</title>
</head> </head>
<body> <body>
<p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br> <p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br>
<font size="+1">Copyright &copy; 1999-2002 David Barton<br> <font size="+1">Copyright &copy; 1999-2002 David Barton<br>
<a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br> <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br>
<a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font> <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font>
<p><font size="+2">Block Ciphers - TDCP_blockcipher</font> <p><font size="+2">Block Ciphers - TDCP_blockcipher</font>
<p>All block ciphers are inherited from the TDCP_blockcipher component via either the TDCP_blockcipher64 and TDCP_blockcipher128 components (the latter implement the block size specific code). <p>All block ciphers are inherited from the TDCP_blockcipher component via either the TDCP_blockcipher64 and TDCP_blockcipher128 components (the latter implement the block size specific code).
<p>The TDCP_blockcipher component extends the TDCP_cipher component to provide chaining mode functions. Functions available are: <p>The TDCP_blockcipher component extends the TDCP_cipher component to provide chaining mode functions. Functions available are:
<pre> <pre>
property <a href="Ciphers.html#Initialized">Initialized</a>: boolean; property <a href="Ciphers.html#Initialized">Initialized</a>: boolean;
property <a href="Ciphers.html#Id">Id</a>: integer; property <a href="Ciphers.html#Id">Id</a>: integer;
property <a href="Ciphers.html#Algorithm">Algorithm</a>: string; property <a href="Ciphers.html#Algorithm">Algorithm</a>: string;
property <a href="Ciphers.html#MaxKeySize">MaxKeySize</a>: integer; property <a href="Ciphers.html#MaxKeySize">MaxKeySize</a>: integer;
property <a href="#BlockSize">BlockSize</a>: integer; property <a href="#BlockSize">BlockSize</a>: integer;
property <a href="#CipherMode">CipherMode</a>: TDCP_ciphermode; property <a href="#CipherMode">CipherMode</a>: TDCP_ciphermode;
class function <a href="Ciphers.html#SelfTest">SelfTest</a>: boolean; class function <a href="Ciphers.html#SelfTest">SelfTest</a>: boolean;
procedure <a href="#SetIV">SetIV</a>(const Value); procedure <a href="#SetIV">SetIV</a>(const Value);
procedure <a href="#GetIV">GetIV</a>(var Value); procedure <a href="#GetIV">GetIV</a>(var Value);
procedure <a href="Ciphers.html#Init">Init</a>(const Key; Size: longword; InitVector: pointer); procedure <a href="Ciphers.html#Init">Init</a>(const Key; Size: longword; InitVector: pointer);
procedure <a href="Ciphers.html#InitStr">InitStr</a>(const Key: string; HashType: TDCP_hashclass); procedure <a href="Ciphers.html#InitStr">InitStr</a>(const Key: string; HashType: TDCP_hashclass);
procedure <a href="Ciphers.html#Burn">Burn</a>; procedure <a href="Ciphers.html#Burn">Burn</a>;
procedure <a href="Ciphers.html#Reset">Reset</a>; procedure <a href="Ciphers.html#Reset">Reset</a>;
procedure <a href="Ciphers.html#Encrypt">Encrypt</a>(const Indata; var Outdata; Size: longword); procedure <a href="Ciphers.html#Encrypt">Encrypt</a>(const Indata; var Outdata; Size: longword);
procedure <a href="Ciphers.html#Decrypt">Decrypt</a>(const Indata; var Outdata; Size: longword); procedure <a href="Ciphers.html#Decrypt">Decrypt</a>(const Indata; var Outdata; Size: longword);
function <a href="Ciphers.html#EncryptStream">EncryptStream</a>(InStream, OutStream: TStream; Size: longword): longword; function <a href="Ciphers.html#EncryptStream">EncryptStream</a>(InStream, OutStream: TStream; Size: longword): longword;
function <a href="Ciphers.html#DecryptStream">DecryptStream</a>(InStream, OutStream: TStream; Size: longword): longword; function <a href="Ciphers.html#DecryptStream">DecryptStream</a>(InStream, OutStream: TStream; Size: longword): longword;
function <a href="Ciphers.html#EncryptString">EncryptString</a>(const Str: string): string; function <a href="Ciphers.html#EncryptString">EncryptString</a>(const Str: string): string;
function <a href="Ciphers.html#DecryptString">DecryptString</a>(const Str: string): string; function <a href="Ciphers.html#DecryptString">DecryptString</a>(const Str: string): string;
procedure <a href="#EncryptECB">EncryptECB</a>(const Indata; var Outdata); procedure <a href="#EncryptECB">EncryptECB</a>(const Indata; var Outdata);
procedure <a href="#DecryptECB">DecryptECB</a>(const Indata; var Outdata); procedure <a href="#DecryptECB">DecryptECB</a>(const Indata; var Outdata);
procedure <a href="#EncryptCBC">EncryptCBC</a>(const Indata; var Outdata; Size: longword); procedure <a href="#EncryptCBC">EncryptCBC</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#DecryptCBC">DecryptCBC</a>(const Indata; var Outdata; Size: longword); procedure <a href="#DecryptCBC">DecryptCBC</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#EncryptCFB8bit">EncryptCFB8bit</a>(const Indata; var Outdata; Size: longword); procedure <a href="#EncryptCFB8bit">EncryptCFB8bit</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#DecryptCFB8bit">DecryptCFB8bit</a>(const Indata; var Outdata; Size: longword); procedure <a href="#DecryptCFB8bit">DecryptCFB8bit</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#EncryptCFBblock">EncryptCFBblock</a>(const Indata; var Outdata; Size: longword); procedure <a href="#EncryptCFBblock">EncryptCFBblock</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#DecryptCFBblock">DecryptCFBblock</a>(const Indata; var Outdata; Size: longword); procedure <a href="#DecryptCFBblock">DecryptCFBblock</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#EncryptOFB">EncryptOFB</a>(const Indata; var Outdata; Size: longword); procedure <a href="#EncryptOFB">EncryptOFB</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#DecryptOFB">DecryptOFB</a>(const Indata; var Outdata; Size: longword); procedure <a href="#DecryptOFB">DecryptOFB</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#EncryptCTR">EncryptCTR</a>(const Indata; var Outdata; Size: longword); procedure <a href="#EncryptCTR">EncryptCTR</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#DecryptCTR">DecryptCTR</a>(const Indata; var Outdata; Size: longword); procedure <a href="#DecryptCTR">DecryptCTR</a>(const Indata; var Outdata; Size: longword);
</pre> </pre>
<hr> <hr>
<p><font size="+2">Function descriptions</font> <p><font size="+2">Function descriptions</font>
<p><font size="+1"><a name="BlockSize">property BlockSize: integer;</a></font> <p><font size="+1"><a name="BlockSize">property BlockSize: integer;</a></font>
<p>This contains the block size of the cipher in BITS. <p>This contains the block size of the cipher in BITS.
<p><font size="+1"><a name="CipherMode">property CipherMode: TDCP_ciphermode;</a></font> <p><font size="+1"><a name="CipherMode">property CipherMode: TDCP_ciphermode;</a></font>
<p>This is the current chaining mode used when <a href="Ciphers.html#Encrypt">Encrypt</a> is called. The available modes are: <p>This is the current chaining mode used when <a href="Ciphers.html#Encrypt">Encrypt</a> is called. The available modes are:
<ul> <ul>
<li>cmCBC - Cipher block chaining. <li>cmCBC - Cipher block chaining.
<li>cmCFB8bit - 8bit cipher feedback. <li>cmCFB8bit - 8bit cipher feedback.
<li>cmCFBblock - Cipher feedback (using the block size of the algorithm). <li>cmCFBblock - Cipher feedback (using the block size of the algorithm).
<li>cmOFB - Output feedback. <li>cmOFB - Output feedback.
<li>cmCTR - Counter. <li>cmCTR - Counter.
</ul> </ul>
<p>Each chaining mode has it's own pro's and cons. See any good book on cryptography or the NIST publication SP800-38A for details on each. <p>Each chaining mode has it's own pro's and cons. See any good book on cryptography or the NIST publication SP800-38A for details on each.
<p><font size="+1"><a name="SetIV">procedure SetIV(const Value);</a></font> <p><font size="+1"><a name="SetIV">procedure SetIV(const Value);</a></font>
<p>Use this procedure to set the current chaining mode information to Value. This variable should be the same size as the block size. When <a href="Ciphers.html#Reset">Reset</a> is called subsequent to this, the chaining information will be set back to Value. <p>Use this procedure to set the current chaining mode information to Value. This variable should be the same size as the block size. When <a href="Ciphers.html#Reset">Reset</a> is called subsequent to this, the chaining information will be set back to Value.
<p><font size="+1"><a name="GetIV">procedure GetIV(var Value);</a></font> <p><font size="+1"><a name="GetIV">procedure GetIV(var Value);</a></font>
<p>This returns in Value the current chaining mode information, to get the initial chaining mode information you need to call <a href="Ciphers.html#Reset">Reset</a> before calling GetIV. The variable passed in Value must be at least the same size as the block size otherwise you will get a buffer overflow. <p>This returns in Value the current chaining mode information, to get the initial chaining mode information you need to call <a href="Ciphers.html#Reset">Reset</a> before calling GetIV. The variable passed in Value must be at least the same size as the block size otherwise you will get a buffer overflow.
<p><font size="+1"><a name="EncryptCBC">procedure EncryptCBC(const Indata; var Outdata; Size: longword);</a></font><br> <p><font size="+1"><a name="EncryptCBC">procedure EncryptCBC(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="DecryptCBC">procedure DecryptCBC(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="DecryptCBC">procedure DecryptCBC(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="EncryptCFB8bit">procedure EncryptCFB8bit(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="EncryptCFB8bit">procedure EncryptCFB8bit(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="DecryptCFB8bit">procedure DecryptCFB8bit(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="DecryptCFB8bit">procedure DecryptCFB8bit(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="EncryptCFBblock">procedure EncryptCFBblock(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="EncryptCFBblock">procedure EncryptCFBblock(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="DecryptCFBblock">procedure DecryptCFBblock(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="DecryptCFBblock">procedure DecryptCFBblock(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="EncryptOFB">procedure EncryptOFB(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="EncryptOFB">procedure EncryptOFB(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="DecryptOFB">procedure DecryptOFB(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="DecryptOFB">procedure DecryptOFB(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="EncryptCTR">procedure EncryptCTR(const Indata; var Outdata; Size: longword);</a></font><br> <font size="+1"><a name="EncryptCTR">procedure EncryptCTR(const Indata; var Outdata; Size: longword);</a></font><br>
<font size="+1"><a name="DecryptCTR">procedure DecryptCTR(const Indata; var Outdata; Size: longword);</a></font> <font size="+1"><a name="DecryptCTR">procedure DecryptCTR(const Indata; var Outdata; Size: longword);</a></font>
<p>These procedures encrypt/decrypt Size bytes of data from Indata and places the result in Outdata. These all employ chaining mode methods of encryption/decryption and so may need to be used inconjunction with <a href="Ciphers.html#Reset">Reset</a>. The CBC method uses short block encryption as specified in Bruce Schneier's "Applied Cryptography" for data blocks that are not multiples of the block size. <p>These procedures encrypt/decrypt Size bytes of data from Indata and places the result in Outdata. These all employ chaining mode methods of encryption/decryption and so may need to be used inconjunction with <a href="Ciphers.html#Reset">Reset</a>. The CBC method uses short block encryption as specified in Bruce Schneier's "Applied Cryptography" for data blocks that are not multiples of the block size.
<p>&nbsp; <p>&nbsp;
<p><a href="Index.html">Index</a>, <a href="Ciphers.html">Ciphers</a>, <a href="Hashes.html">Hashes</a> <p><a href="Index.html">Index</a>, <a href="Ciphers.html">Ciphers</a>, <a href="Hashes.html">Hashes</a>
<p>&nbsp; <p>&nbsp;
<p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br> <p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br>
All trademarks are property of their respective owners.</em> All trademarks are property of their respective owners.</em>
</body> </body>
</html> </html>

View File

@ -1,273 +1,273 @@
<html> <html>
<head> <head>
<title>DCPcrypt v2: Users Guide - Ciphers</title> <title>DCPcrypt v2: Users Guide - Ciphers</title>
</head> </head>
<body> <body>
<p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br> <p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br>
<font size="+1">Copyright &copy; 1999-2002 David Barton<br> <font size="+1">Copyright &copy; 1999-2002 David Barton<br>
<a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br> <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br>
<a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font> <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font>
<p><font size="+2">Ciphers - TDCP_cipher</font> <p><font size="+2">Ciphers - TDCP_cipher</font>
<p>All ciphers are inherited from the TDCP_cipher component either directly for stream ciphers (such as RC4) or via the TDCP_blockcipher component. <p>All ciphers are inherited from the TDCP_cipher component either directly for stream ciphers (such as RC4) or via the TDCP_blockcipher component.
<p>The TDCP_cipher component implements key initialisation features and the basic encryption/decryption interface. Functions available are: <p>The TDCP_cipher component implements key initialisation features and the basic encryption/decryption interface. Functions available are:
<pre> <pre>
property <a href="#Initialized">Initialized</a>: boolean; property <a href="#Initialized">Initialized</a>: boolean;
property <a href="#Id">Id</a>: integer; property <a href="#Id">Id</a>: integer;
property <a href="#Algorithm">Algorithm</a>: string; property <a href="#Algorithm">Algorithm</a>: string;
property <a href="#MaxKeySize">MaxKeySize</a>: integer; property <a href="#MaxKeySize">MaxKeySize</a>: integer;
class function <a href="#SelfTest">SelfTest</a>: boolean; class function <a href="#SelfTest">SelfTest</a>: boolean;
procedure <a href="#Init">Init</a>(const Key; Size: longword; InitVector: pointer); procedure <a href="#Init">Init</a>(const Key; Size: longword; InitVector: pointer);
procedure <a href="#InitStr">InitStr</a>(const Key: string; HashType: TDCP_hashclass); procedure <a href="#InitStr">InitStr</a>(const Key: string; HashType: TDCP_hashclass);
procedure <a href="#Burn">Burn</a>; procedure <a href="#Burn">Burn</a>;
procedure <a href="#Reset">Reset</a>; procedure <a href="#Reset">Reset</a>;
procedure <a href="#Encrypt">Encrypt</a>(const Indata; var Outdata; Size: longword); procedure <a href="#Encrypt">Encrypt</a>(const Indata; var Outdata; Size: longword);
procedure <a href="#Decrypt">Decrypt</a>(const Indata; var Outdata; Size: longword); procedure <a href="#Decrypt">Decrypt</a>(const Indata; var Outdata; Size: longword);
function <a href="#EncryptStream">EncryptStream</a>(InStream, OutStream: TStream; Size: longword): longword; function <a href="#EncryptStream">EncryptStream</a>(InStream, OutStream: TStream; Size: longword): longword;
function <a href="#DecryptStream">DecryptStream</a>(InStream, OutStream: TStream; Size: longword): longword; function <a href="#DecryptStream">DecryptStream</a>(InStream, OutStream: TStream; Size: longword): longword;
function <a href="#EncryptString">EncryptString</a>(const Str: string): string; function <a href="#EncryptString">EncryptString</a>(const Str: string): string;
function <a href="#DecryptString">DecryptString</a>(const Str: string): string; function <a href="#DecryptString">DecryptString</a>(const Str: string): string;
</pre> </pre>
<p>Example usage: <p>Example usage:
<ul> <ul>
<li><a href="#Example1">Example 1</a> - String encryption. <li><a href="#Example1">Example 1</a> - String encryption.
<li><a href="#Example2">Example 2</a> - File encryption. <li><a href="#Example2">Example 2</a> - File encryption.
<li><a href="#Example3">Example 3</a> - General encryption. <li><a href="#Example3">Example 3</a> - General encryption.
</ul> </ul>
<hr> <hr>
<p><font size="+2">Function descriptions</font> <p><font size="+2">Function descriptions</font>
<p><font size="+1"><a name="Initialized">property Initialized: boolean;</a></font> <p><font size="+1"><a name="Initialized">property Initialized: boolean;</a></font>
<p>Once key initialization has been performed this property is set to true, otherwise it is set to false. Calling <a href="#Burn">Burn</a> will immediately set this to false. <p>Once key initialization has been performed this property is set to true, otherwise it is set to false. Calling <a href="#Burn">Burn</a> will immediately set this to false.
<p><font size="+1"><a name="Id">property Id: integer;</a></font> <p><font size="+1"><a name="Id">property Id: integer;</a></font>
<p>Every algorithm I implement gets given a unique ID number so that if I use several different algorithms within a program I can determine which one was used. This is a purely arbitrary numbering system. <p>Every algorithm I implement gets given a unique ID number so that if I use several different algorithms within a program I can determine which one was used. This is a purely arbitrary numbering system.
<p><font size="+1"><a name="Algorithm">property Algorithm: string;</a></font> <p><font size="+1"><a name="Algorithm">property Algorithm: string;</a></font>
<p>This contains the name of the algorithm implemented within the component. <p>This contains the name of the algorithm implemented within the component.
<p><font size="+1"><a name="MaxKeySize">property MaxKeySize: integer;</a></font> <p><font size="+1"><a name="MaxKeySize">property MaxKeySize: integer;</a></font>
<p>This is the maximum size of key you can pass to the cipher (in bits!). <p>This is the maximum size of key you can pass to the cipher (in bits!).
<p><font size="+1"><a name="SelfTest">class function SelfTest: boolean;</a></font> <p><font size="+1"><a name="SelfTest">class function SelfTest: boolean;</a></font>
<p>In order to test whether the implementations have all been compiled correctly you can call the SelfTest function. This compares the results of several encryption/decryption operations with known results for the algorithms (so called test vectors). If all the tests are passed then true is returned. If ANY of the tests are failed then false is returned. You may want to run this function for all the components when you first install the DCPcrypt package and again if you modify any of the source files, you don't need to run this everytime your program is run. Note: this only performs a selection of tests, it is not exhaustive. <p>In order to test whether the implementations have all been compiled correctly you can call the SelfTest function. This compares the results of several encryption/decryption operations with known results for the algorithms (so called test vectors). If all the tests are passed then true is returned. If ANY of the tests are failed then false is returned. You may want to run this function for all the components when you first install the DCPcrypt package and again if you modify any of the source files, you don't need to run this everytime your program is run. Note: this only performs a selection of tests, it is not exhaustive.
<p><font size="+1"><a name="Init">procedure Init(const Key; Size: longword; InitVector: pointer);</a></font> <p><font size="+1"><a name="Init">procedure Init(const Key; Size: longword; InitVector: pointer);</a></font>
<p>This procedure initializes the cipher with the keying material supplied in Key. The Size of the keying material is specified in <b>BITS</b>. The InitVector is a pointer to chaining information (only used for block ciphers). The variable that this points to should be equal to the block size of the algorithm. If <em>nil</em> is specified then (if necessary) an initialization vector is automatically generated from the key. Note: the method for generating automatic IVs is different from DCPcrypt v1.31, if this is a problem uncomment the DCPcrypt v1.31 compatibility mode line in DCPcrypt2.pas. <p>This procedure initializes the cipher with the keying material supplied in Key. The Size of the keying material is specified in <b>BITS</b>. The InitVector is a pointer to chaining information (only used for block ciphers). The variable that this points to should be equal to the block size of the algorithm. If <em>nil</em> is specified then (if necessary) an initialization vector is automatically generated from the key. Note: the method for generating automatic IVs is different from DCPcrypt v1.31, if this is a problem uncomment the DCPcrypt v1.31 compatibility mode line in DCPcrypt2.pas.
<p>Init example: use the hash of a string to initialize the cipher <p>Init example: use the hash of a string to initialize the cipher
<pre> <pre>
<b>procedure</b> TForm1.Button1Click(Sender: TObject); <b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
Hash: TDCP_sha1; Hash: TDCP_sha1;
Digest: <b>array</b>[0..19] <b>of byte</b>; <em>// SHA-1 produces a 160bit (20byte) output</em> Digest: <b>array</b>[0..19] <b>of byte</b>; <em>// SHA-1 produces a 160bit (20byte) output</em>
<b>begin</b> <b>begin</b>
Hash:= TDCP_sha1.Create(Self); Hash:= TDCP_sha1.Create(Self);
Hash.Init; <em>// initialize the hash</em> Hash.Init; <em>// initialize the hash</em>
Hash.UpdateStr(Edit1.Text); <em>// generate a hash of Edit1.Text</em> Hash.UpdateStr(Edit1.Text); <em>// generate a hash of Edit1.Text</em>
Hash.Final(Digest); <em>// save the hash in Digest</em> Hash.Final(Digest); <em>// save the hash in Digest</em>
Hash.Free; Hash.Free;
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.Init(Digest,Sizeof(Digest)*8,<b>nil</b>); <em>// remember size is in BITS (hence sizeof*8)</em> Cipher.Init(Digest,Sizeof(Digest)*8,<b>nil</b>); <em>// remember size is in BITS (hence sizeof*8)</em>
... ...
</pre> </pre>
<p><font size="+1"><a name="InitStr">procedure InitStr(const Key: string; HashType: TDCP_hashclass);</a></font> <p><font size="+1"><a name="InitStr">procedure InitStr(const Key: string; HashType: TDCP_hashclass);</a></font>
<p>This procedure initializes the cipher with a hash of the key string using the specified hash type (in a way similar to the example above). To replicate the behaviour from DCPcrypt v2 Beta 1 use Cipher.InitStr(KeyStr,TDCP_sha1). <p>This procedure initializes the cipher with a hash of the key string using the specified hash type (in a way similar to the example above). To replicate the behaviour from DCPcrypt v2 Beta 1 use Cipher.InitStr(KeyStr,TDCP_sha1).
<p>InitStr example: prompt the user for a passphrase to initialize the cipher <p>InitStr example: prompt the user for a passphrase to initialize the cipher
<pre> <pre>
<b>procedure</b> TForm1.Button1Click(Sender: TObject); <b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
<b>begin</b> <b>begin</b>
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.InitStr(InputBox('Passphrase','Enter a passphrase',''),TDCP_sha1); <em>// prompt for a passphrase</em> Cipher.InitStr(InputBox('Passphrase','Enter a passphrase',''),TDCP_sha1); <em>// prompt for a passphrase</em>
... ...
</pre> </pre>
<p><font size="+1"><a name="Burn">procedure Burn;</a></font> <p><font size="+1"><a name="Burn">procedure Burn;</a></font>
<p>Once you have finished encrypting/decrypting all your data call Burn to erase all keying information. This is automatically called once the cipher is freed, however it is a good habit to call this procedure explicitly. <p>Once you have finished encrypting/decrypting all your data call Burn to erase all keying information. This is automatically called once the cipher is freed, however it is a good habit to call this procedure explicitly.
<p><font size="+1"><a name="Reset">procedure Reset;</a></font> <p><font size="+1"><a name="Reset">procedure Reset;</a></font>
<p>Stream ciphers (and block ciphers in chaining modes) generally store chaining information that is dependant on the information already encrypted. Consequently decrypting a block of information immediately after encrypting it won't result in the original information because when you called the decrypt procedure the chaining information was different from when you called the encrypt procedure. Hence use Reset to restore the chaining information to it's original state. <p>Stream ciphers (and block ciphers in chaining modes) generally store chaining information that is dependant on the information already encrypted. Consequently decrypting a block of information immediately after encrypting it won't result in the original information because when you called the decrypt procedure the chaining information was different from when you called the encrypt procedure. Hence use Reset to restore the chaining information to it's original state.
<p>Remember that calling <a href="#EncryptString">EncryptString</a>, <a href="#DecryptString">DecryptString</a>, <a href="#EncryptStream">EncryptStream</a> and <a href="#DecryptStream">DecryptStream</a> will also affect the chaining information. <p>Remember that calling <a href="#EncryptString">EncryptString</a>, <a href="#DecryptString">DecryptString</a>, <a href="#EncryptStream">EncryptStream</a> and <a href="#DecryptStream">DecryptStream</a> will also affect the chaining information.
<p>Reset example: encrypting and decrypting <p>Reset example: encrypting and decrypting
<pre> <pre>
<b>function</b> TestCipher: <b>boolean</b>; <b>function</b> TestCipher: <b>boolean</b>;
<b>const</b> <b>const</b>
InData: <b>array</b>[0..9] <b>of byte</b>= ($01,$23,$45,$56,$67,$78,$89,$10,$AB,$FF); InData: <b>array</b>[0..9] <b>of byte</b>= ($01,$23,$45,$56,$67,$78,$89,$10,$AB,$FF);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
Data: <b>array</b>[0..9] <b>of byte</b>; Data: <b>array</b>[0..9] <b>of byte</b>;
<b>begin</b> <b>begin</b>
Cipher:= TDCP_rc4.Create(<b>nil</b>); Cipher:= TDCP_rc4.Create(<b>nil</b>);
Cipher.InitStr('Hello World',TDCP_sha1); <em>// initialize the cipher</em> Cipher.InitStr('Hello World',TDCP_sha1); <em>// initialize the cipher</em>
Cipher.Encrypt(InData,Data,Sizeof(Data)); <em>// encrypt some known data</em> Cipher.Encrypt(InData,Data,Sizeof(Data)); <em>// encrypt some known data</em>
Cipher.Decrypt(Data,Data,Sizeof(Data)); <em>// now decrypt it</em> Cipher.Decrypt(Data,Data,Sizeof(Data)); <em>// now decrypt it</em>
Cipher.Burn; <em>// clear keying information</em> Cipher.Burn; <em>// clear keying information</em>
Cipher.Free; Cipher.Free;
Result:= CompareMem(@InData,@Data,Sizeof(Data)); <em>// compare input and output</em> Result:= CompareMem(@InData,@Data,Sizeof(Data)); <em>// compare input and output</em>
<b>end</b>; <b>end</b>;
</pre> </pre>
The above will ALWAYS result in false due to the chaining information. The above will ALWAYS result in false due to the chaining information.
<pre> <pre>
<b>function</b> TestCipher: <b>boolean</b>; <b>function</b> TestCipher: <b>boolean</b>;
<b>const</b> <b>const</b>
InData: <b>array</b>[0..9] <b>of byte</b>= ($01,$23,$45,$56,$67,$78,$89,$10,$AB,$FF); InData: <b>array</b>[0..9] <b>of byte</b>= ($01,$23,$45,$56,$67,$78,$89,$10,$AB,$FF);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
Data: <b>array</b>[0..9] <b>of byte</b>; Data: <b>array</b>[0..9] <b>of byte</b>;
<b>begin</b> <b>begin</b>
Cipher:= TDCP_rc4.Create(<b>nil</b>); Cipher:= TDCP_rc4.Create(<b>nil</b>);
Cipher.InitStr('Hello World',TDCP_sha1); <em>// initialize the cipher</em> Cipher.InitStr('Hello World',TDCP_sha1); <em>// initialize the cipher</em>
Cipher.Encrypt(InData,Data,Sizeof(Data)); <em>// encrypt some known data</em> Cipher.Encrypt(InData,Data,Sizeof(Data)); <em>// encrypt some known data</em>
Cipher.Reset; <em><b>// reset chaining information</b></em> Cipher.Reset; <em><b>// reset chaining information</b></em>
Cipher.Decrypt(Data,Data,Sizeof(Data)); <em>// now decrypt it</em> Cipher.Decrypt(Data,Data,Sizeof(Data)); <em>// now decrypt it</em>
Cipher.Burn; <em>// clear keying information</em> Cipher.Burn; <em>// clear keying information</em>
Cipher.Free; Cipher.Free;
Result:= CompareMem(@InData,@Data,Sizeof(Data)); <em>// compare input and output</em> Result:= CompareMem(@InData,@Data,Sizeof(Data)); <em>// compare input and output</em>
<b>end</b>; <b>end</b>;
</pre> </pre>
The above <em>should</em> always return true. The above <em>should</em> always return true.
<p><font size="+1"><a name="Encrypt">procedure Encrypt(const Indata; var Outdata; Size: longword);</a></font> <p><font size="+1"><a name="Encrypt">procedure Encrypt(const Indata; var Outdata; Size: longword);</a></font>
<p>Encrypt Size bytes from Indata and place it in Outdata. Block ciphers encrypt the data using the method specified by the <a href="BlockCiphers.html#CipherMode">CipherMode</a> property. Also see the notes on <a href="#Reset">Reset</a>. <p>Encrypt Size bytes from Indata and place it in Outdata. Block ciphers encrypt the data using the method specified by the <a href="BlockCiphers.html#CipherMode">CipherMode</a> property. Also see the notes on <a href="#Reset">Reset</a>.
<p><font size="+1"><a name="Decrypt">procedure Decrypt(const Indata; var Outdata; Size: longword);</a></font> <p><font size="+1"><a name="Decrypt">procedure Decrypt(const Indata; var Outdata; Size: longword);</a></font>
<p>Decrypt Size bytes from Indata and place it in Outdata. Block ciphers decrypt the data using the method specified by the <a href="BlockCiphers.html#CipherMode">CipherMode</a> property. Also see the notes on <a href="#Reset">Reset</a>. <p>Decrypt Size bytes from Indata and place it in Outdata. Block ciphers decrypt the data using the method specified by the <a href="BlockCiphers.html#CipherMode">CipherMode</a> property. Also see the notes on <a href="#Reset">Reset</a>.
<p><font size="+1"><a name="EncryptStream">function EncryptStream(InStream, OutStream: TStream; Size: longword): longword;</a></font> <p><font size="+1"><a name="EncryptStream">function EncryptStream(InStream, OutStream: TStream; Size: longword): longword;</a></font>
<p>Encrypt Size bytes from the InStream and place it in the OutStream, returns the number of bytes read from the InStream. Encryption is done by calling the <a href="#Encrypt">Encrypt</a> procedure. Also see the notes on <a href="#Reset">Reset</a>. <p>Encrypt Size bytes from the InStream and place it in the OutStream, returns the number of bytes read from the InStream. Encryption is done by calling the <a href="#Encrypt">Encrypt</a> procedure. Also see the notes on <a href="#Reset">Reset</a>.
<p><font size="+1"><a name="DecryptStream">function DecryptStream(InStream, OutStream: TStream; Size: longword): longword;</a></font> <p><font size="+1"><a name="DecryptStream">function DecryptStream(InStream, OutStream: TStream; Size: longword): longword;</a></font>
<p>Decrypt Size bytes from the InStream and place it in the OutStream, returns the number of bytes read from the InStream. Decryption is done by calling the <a href="#Decrypt">Decrypt</a> procedure. Also see the notes on <a href="#Reset">Reset</a>. <p>Decrypt Size bytes from the InStream and place it in the OutStream, returns the number of bytes read from the InStream. Decryption is done by calling the <a href="#Decrypt">Decrypt</a> procedure. Also see the notes on <a href="#Reset">Reset</a>.
<p><font size="+1"><a name="EncryptString">function EncryptString(const Str: string): string;</a></font> <p><font size="+1"><a name="EncryptString">function EncryptString(const Str: string): string;</a></font>
<p>Encrypt the string Str then Base64 encode it and return the result. For stream ciphers the <a href="#Encrypt">Encrypt</a> procedure is called to do the encryption, for block ciphers the <a href="BlockCiphers.html#EncryptCFB8bit">CFB8bit</a> method is always used. Base64 encoding is used to ensure that the output string doesn't contain non-printing characters. <p>Encrypt the string Str then Base64 encode it and return the result. For stream ciphers the <a href="#Encrypt">Encrypt</a> procedure is called to do the encryption, for block ciphers the <a href="BlockCiphers.html#EncryptCFB8bit">CFB8bit</a> method is always used. Base64 encoding is used to ensure that the output string doesn't contain non-printing characters.
<p><font size="+1"><a name="DecryptString">function DecryptString(const Str: string): string;</a></font> <p><font size="+1"><a name="DecryptString">function DecryptString(const Str: string): string;</a></font>
<p>Base64 decode the string then decrypt it and return the result. For stream ciphers the <a href="#Decrypt">Decrypt</a> procedure is called to do the decryption, for block ciphers the <a href="BlockCiphers.html#DecryptCFB8bit">CFB8bit</a> method is always used. <p>Base64 decode the string then decrypt it and return the result. For stream ciphers the <a href="#Decrypt">Decrypt</a> procedure is called to do the decryption, for block ciphers the <a href="BlockCiphers.html#DecryptCFB8bit">CFB8bit</a> method is always used.
<hr> <hr>
<p><font size="+2"><a name="Example1">Example 1: String encryption</a></font> <p><font size="+2"><a name="Example1">Example 1: String encryption</a></font>
<p>This example shows how you can encrypt the contents of a TMemo and leave the contents printable. <p>This example shows how you can encrypt the contents of a TMemo and leave the contents printable.
<pre> <pre>
<b>procedure</b> TForm1.btnEncryptClick(Sender: TObject); <b>procedure</b> TForm1.btnEncryptClick(Sender: TObject);
<b>var</b> <b>var</b>
i: <b>integer</b>; i: <b>integer</b>;
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
KeyStr: string; KeyStr: string;
<b>begin</b> <b>begin</b>
KeyStr:= ''; KeyStr:= '';
<b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em> <b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em>
<b>begin</b> <b>begin</b>
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em> Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em>
<b>for</b> i:= 0 <b>to</b> Memo1.Lines.Count-1 <b>do</b> <em>// encrypt the contents of the memo</em> <b>for</b> i:= 0 <b>to</b> Memo1.Lines.Count-1 <b>do</b> <em>// encrypt the contents of the memo</em>
Memo1.Lines[i]:= Cipher.EncryptString(Memo1.Lines[i]); Memo1.Lines[i]:= Cipher.EncryptString(Memo1.Lines[i]);
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
<b>procedure</b> TForm1.btnDecryptClick(Sender: TObject); <b>procedure</b> TForm1.btnDecryptClick(Sender: TObject);
<b>var</b> <b>var</b>
i: <b>integer</b>; i: <b>integer</b>;
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
KeyStr: string; KeyStr: string;
<b>begin</b> <b>begin</b>
KeyStr:= ''; KeyStr:= '';
<b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em> <b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em>
<b>begin</b> <b>begin</b>
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em> Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em>
<b>for</b> i:= 0 <b>to</b> Memo1.Lines.Count-1 <b>do</b> <em>// decrypt the contents of the memo</em> <b>for</b> i:= 0 <b>to</b> Memo1.Lines.Count-1 <b>do</b> <em>// decrypt the contents of the memo</em>
Memo1.Lines[i]:= Cipher.DecryptString(Memo1.Lines[i]); Memo1.Lines[i]:= Cipher.DecryptString(Memo1.Lines[i]);
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
</pre> </pre>
<hr> <hr>
<p><font size="+2"><a name="Example2">Example 2: File encryption</a></font> <p><font size="+2"><a name="Example2">Example 2: File encryption</a></font>
<p>This example shows how you can encrypt the contents of a file, takes the input and output file names from two edit boxes: boxInputFile and boxOutputFile. <p>This example shows how you can encrypt the contents of a file, takes the input and output file names from two edit boxes: boxInputFile and boxOutputFile.
<pre> <pre>
<b>procedure</b> TForm1.btnEncryptClick(Sender: TObject); <b>procedure</b> TForm1.btnEncryptClick(Sender: TObject);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
KeyStr: string; KeyStr: string;
Source, Dest: TFileStream; Source, Dest: TFileStream;
<b>begin</b> <b>begin</b>
KeyStr:= ''; KeyStr:= '';
<b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em> <b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em>
<b>begin</b> <b>begin</b>
<b>try</b> <b>try</b>
Source:= TFileStream.Create(boxInputFile.Text,fmOpenRead); Source:= TFileStream.Create(boxInputFile.Text,fmOpenRead);
Dest:= TFileStream.Create(boxOutputFile.Text,fmCreate); Dest:= TFileStream.Create(boxOutputFile.Text,fmCreate);
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em> Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em>
Cipher.EncryptStream(Source,Dest,Source.Size); <em>// encrypt the contents of the file</em> Cipher.EncryptStream(Source,Dest,Source.Size); <em>// encrypt the contents of the file</em>
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
Dest.Free; Dest.Free;
Source.Free; Source.Free;
MessageDlg('File encrypted',mtInformation,[mbOK],0); MessageDlg('File encrypted',mtInformation,[mbOK],0);
<b>except</b> <b>except</b>
MessageDlg('File IO error',mtError,[mbOK],0); MessageDlg('File IO error',mtError,[mbOK],0);
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
<b>procedure</b> TForm1.btnDecryptClick(Sender: TObject); <b>procedure</b> TForm1.btnDecryptClick(Sender: TObject);
<b>var</b> <b>var</b>
Cipher: TDCP_rc4; Cipher: TDCP_rc4;
KeyStr: string; KeyStr: string;
Source, Dest: TFileStream; Source, Dest: TFileStream;
<b>begin</b> <b>begin</b>
KeyStr:= ''; KeyStr:= '';
<b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em> <b>if</b> InputQuery('Passphrase','Enter passphrase',KeyStr) <b>then</b> <em>// get the passphrase</em>
<b>begin</b> <b>begin</b>
<b>try</b> <b>try</b>
Source:= TFileStream.Create(boxInputFile.Text,fmOpenRead); Source:= TFileStream.Create(boxInputFile.Text,fmOpenRead);
Dest:= TFileStream.Create(boxOutputFile.Text,fmCreate); Dest:= TFileStream.Create(boxOutputFile.Text,fmCreate);
Cipher:= TDCP_rc4.Create(Self); Cipher:= TDCP_rc4.Create(Self);
Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em> Cipher.InitStr(KeyStr,TDCP_sha1); <em>// initialize the cipher with a hash of the passphrase</em>
Cipher.DecryptStream(Source,Dest,Source.Size); <em>// decrypt the contents of the file</em> Cipher.DecryptStream(Source,Dest,Source.Size); <em>// decrypt the contents of the file</em>
Cipher.Burn; Cipher.Burn;
Cipher.Free; Cipher.Free;
Dest.Free; Dest.Free;
Source.Free; Source.Free;
MessageDlg('File decrypted',mtInformation,[mbOK],0); MessageDlg('File decrypted',mtInformation,[mbOK],0);
<b>except</b> <b>except</b>
MessageDlg('File IO error',mtError,[mbOK],0); MessageDlg('File IO error',mtError,[mbOK],0);
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
</pre> </pre>
<hr> <hr>
<p><font size="+2"><a name="Example3">Example 3: General encryption</a></font> <p><font size="+2"><a name="Example3">Example 3: General encryption</a></font>
<p>This hypothetical example shows how you might encrypt a packet of information before transmission across a network. <p>This hypothetical example shows how you might encrypt a packet of information before transmission across a network.
<pre> <pre>
<b>type</b> <b>type</b>
TSomePacket= <b>record</b> TSomePacket= <b>record</b>
Date: <b>double</b>; Date: <b>double</b>;
ToUserID: <b>integer</b>; ToUserID: <b>integer</b>;
FromUserID: <b>integer</b>; FromUserID: <b>integer</b>;
MsgLen: <b>integer</b>; MsgLen: <b>integer</b>;
Msg: string; Msg: string;
<b>end</b>; <b>end</b>;
<b>procedure</b> EncryptPacket(Cipher: TDCP_cipher; <b>var</b> Packet: TSomePacket); <b>procedure</b> EncryptPacket(Cipher: TDCP_cipher; <b>var</b> Packet: TSomePacket);
<em>// encrypt the information packet with the cipher <em>// encrypt the information packet with the cipher
// if the cipher isn't initialized then prompt for passphrase</em> // if the cipher isn't initialized then prompt for passphrase</em>
<b>begin</b> <b>begin</b>
<b>if</b> Cipher= <b>nil then</b> <b>if</b> Cipher= <b>nil then</b>
<b>raise</b> Exception.Create('Cipher hasn''t been created!') <b>raise</b> Exception.Create('Cipher hasn''t been created!')
<b>else <b>else
begin</b> begin</b>
<b>if not</b> Cipher.Initialized <b>then</b> <em>// check the cipher has been initialized</em> <b>if not</b> Cipher.Initialized <b>then</b> <em>// check the cipher has been initialized</em>
Cipher.InitStr(InputBox('Passphrase','Enter passphrase',''),TDCP_sha1); Cipher.InitStr(InputBox('Passphrase','Enter passphrase',''),TDCP_sha1);
<b>if</b> Cipher <b>is</b> TDCP_blockcipher <b>then</b> <em>// if a block cipher use CFB 8bit as encrypting small packets</em> <b>if</b> Cipher <b>is</b> TDCP_blockcipher <b>then</b> <em>// if a block cipher use CFB 8bit as encrypting small packets</em>
TDCP_blockcipher(Cipher).CipherMode:= cmCFB8bit; TDCP_blockcipher(Cipher).CipherMode:= cmCFB8bit;
<em>// encrypt the record part by part, could do this in one go if it was a packed record</em> <em>// encrypt the record part by part, could do this in one go if it was a packed record</em>
Cipher.Encrypt(Packet.Date,Packet.Date,Sizeof(Packet.Date)); Cipher.Encrypt(Packet.Date,Packet.Date,Sizeof(Packet.Date));
Cipher.Encrypt(Packet.ToUserID,Packet.ToUserID,Sizeof(Packet.ToUserID)); Cipher.Encrypt(Packet.ToUserID,Packet.ToUserID,Sizeof(Packet.ToUserID));
Cipher.Encrypt(Packet.FromUserID,Packet.FromUserID,Sizeof(Packet.FromUserID)); Cipher.Encrypt(Packet.FromUserID,Packet.FromUserID,Sizeof(Packet.FromUserID));
Cipher.Encrypt(Packet.MsgLen,Packet.MsgLen,Sizeof(Packet.MsgLen)); Cipher.Encrypt(Packet.MsgLen,Packet.MsgLen,Sizeof(Packet.MsgLen));
Cipher.Encrypt(Packet.Msg[1],Packet.Msg[1],Length(Packet.Msg)); <em>// slightly different for strings</em> Cipher.Encrypt(Packet.Msg[1],Packet.Msg[1],Length(Packet.Msg)); <em>// slightly different for strings</em>
<em>// don't bother resetting the cipher, instead keep the chaining information</em> <em>// don't bother resetting the cipher, instead keep the chaining information</em>
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
</pre> </pre>
<p>&nbsp; <p>&nbsp;
<p><a href="Index.html">Index</a>, <a href="BlockCiphers.html">Block Ciphers</a>, <a href="Hashes.html">Hashes</a> <p><a href="Index.html">Index</a>, <a href="BlockCiphers.html">Block Ciphers</a>, <a href="Hashes.html">Hashes</a>
<p>&nbsp; <p>&nbsp;
<p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br> <p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br>
All trademarks are property of their respective owners.</em> All trademarks are property of their respective owners.</em>
</body> </body>
</html> </html>

View File

@ -1,107 +1,107 @@
<html> <html>
<head> <head>
<title>DCPcrypt v2: Users Guide - Hash Algorithms</title> <title>DCPcrypt v2: Users Guide - Hash Algorithms</title>
</head> </head>
<body> <body>
<p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br> <p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2</b></font><br>
<font size="+1">Copyright &copy; 1999-2002 David Barton<br> <font size="+1">Copyright &copy; 1999-2002 David Barton<br>
<a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br> <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br>
<a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font> <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font>
<p><font size="+2">Hash Algorithms - TDCP_hash</font> <p><font size="+2">Hash Algorithms - TDCP_hash</font>
<p>All hashes are derived from the TDCP_hash component. It provides a range of functions to allow the hashing of virtually every type of data. <p>All hashes are derived from the TDCP_hash component. It provides a range of functions to allow the hashing of virtually every type of data.
<p>Functions available are: <p>Functions available are:
<pre> <pre>
property <a href="#Initialized">Initialized</a>: boolean; property <a href="#Initialized">Initialized</a>: boolean;
property <a href="#Id">Id: integer</a>; property <a href="#Id">Id: integer</a>;
property <a href="#Algorithm">Algorithm</a>: string; property <a href="#Algorithm">Algorithm</a>: string;
property <a href="#HashSize">HashSize</a>: integer; property <a href="#HashSize">HashSize</a>: integer;
class function <a href="#SelfTest">SelfTest</a>: boolean; class function <a href="#SelfTest">SelfTest</a>: boolean;
procedure <a href="#Init">Init</a>; procedure <a href="#Init">Init</a>;
procedure <a href="#Final">Final</a>(var Digest); procedure <a href="#Final">Final</a>(var Digest);
procedure <a href="#Burn">Burn</a>; procedure <a href="#Burn">Burn</a>;
procedure <a href="#Update">Update</a>(const Buffer; Size: longword); procedure <a href="#Update">Update</a>(const Buffer; Size: longword);
procedure <a href="#UpdateStream">UpdateStream</a>(Stream: TStream; Size: longword); procedure <a href="#UpdateStream">UpdateStream</a>(Stream: TStream; Size: longword);
procedure <a href="#UpdateStr">UpdateStr</a>(const Str: string); procedure <a href="#UpdateStr">UpdateStr</a>(const Str: string);
</pre> </pre>
<p>Example usage: <p>Example usage:
<ul> <ul>
<li><a href="#Example1">Example 1</a> - File hashing. <li><a href="#Example1">Example 1</a> - File hashing.
</ul> </ul>
<hr> <hr>
<p><font size="+1"><a name="Initialized">property Initialized: boolean;</a></font> <p><font size="+1"><a name="Initialized">property Initialized: boolean;</a></font>
<p>This is set to true after <a href="#Init">Init</a> has been called. <p>This is set to true after <a href="#Init">Init</a> has been called.
<p><font size="+1"><a name="Id">property Id: integer;</a></font> <p><font size="+1"><a name="Id">property Id: integer;</a></font>
<p>Every algorithm I implement gets given a unique ID number so that if I use several different algorithms within a program I can determine which one was used. This is a purely arbitrary numbering system. <p>Every algorithm I implement gets given a unique ID number so that if I use several different algorithms within a program I can determine which one was used. This is a purely arbitrary numbering system.
<p><font size="+1"><a name="Algorithm">property Algorithm: string;</a></font> <p><font size="+1"><a name="Algorithm">property Algorithm: string;</a></font>
<p>This is the name of the algorithm implemented in the component. <p>This is the name of the algorithm implemented in the component.
<p><font size="+1"><a name="HashSize">property HashSize: integer;</a></font> <p><font size="+1"><a name="HashSize">property HashSize: integer;</a></font>
<p>This is the size of the output of the hash algorithm in BITS. <p>This is the size of the output of the hash algorithm in BITS.
<p><font size="+1"><a name="SelfTest">class function SelfTest: boolean;</a></font> <p><font size="+1"><a name="SelfTest">class function SelfTest: boolean;</a></font>
<p>In order to test whether the implementations have all been compiled correctly you can call the SelfTest function. This compares the results of several hash operations with known results for the algorithms (so called test vectors). If all the tests are passed then true is returned. If ANY of the tests are failed then false is returned. You may want to run this function for all the components when you first install the DCPcrypt package and again if you modify any of the source files, you don't need to run this everytime your program is run. Note: this only performs a selection of tests, it is not exhaustive. <p>In order to test whether the implementations have all been compiled correctly you can call the SelfTest function. This compares the results of several hash operations with known results for the algorithms (so called test vectors). If all the tests are passed then true is returned. If ANY of the tests are failed then false is returned. You may want to run this function for all the components when you first install the DCPcrypt package and again if you modify any of the source files, you don't need to run this everytime your program is run. Note: this only performs a selection of tests, it is not exhaustive.
<p><font size="+1"><a name="Init">procedure Init;</a></font> <p><font size="+1"><a name="Init">procedure Init;</a></font>
<p>Call this procedure to initialize the hash algorithm, this must be called before using the <a href="#Update">Update</a> procedure. <p>Call this procedure to initialize the hash algorithm, this must be called before using the <a href="#Update">Update</a> procedure.
<p><font size="+1"><a name="Final">procedure Final(var Digest);</a></font> <p><font size="+1"><a name="Final">procedure Final(var Digest);</a></font>
<p>This procedure returns the final message digest (hash) in Digest. This variable must be the same size as the hash size. This procedure also calls <a href="#Burn">Burn</a> to clear any stored information. <p>This procedure returns the final message digest (hash) in Digest. This variable must be the same size as the hash size. This procedure also calls <a href="#Burn">Burn</a> to clear any stored information.
<p><font size="+1"><a name="Burn">procedure Burn;</a></font> <p><font size="+1"><a name="Burn">procedure Burn;</a></font>
<p>Call this procedure if you want to abort the hashing operation (normally <a href="#Final">Final</a> is used). This clears all information stored within the hash. Before the hash can be used again <a href="#Init">Init</a> must be called. <p>Call this procedure if you want to abort the hashing operation (normally <a href="#Final">Final</a> is used). This clears all information stored within the hash. Before the hash can be used again <a href="#Init">Init</a> must be called.
<p><font size="+1"><a name="Update">procedure Update(const Buffer; Size: longword);</a></font> <p><font size="+1"><a name="Update">procedure Update(const Buffer; Size: longword);</a></font>
<p>This procedure hashes Size bytes of Buffer. To get the hash result call <a href="#Final">Final</a>. <p>This procedure hashes Size bytes of Buffer. To get the hash result call <a href="#Final">Final</a>.
<p>Update example: <p>Update example:
<pre> <pre>
<b>procedure</b> HashBuffer(<b>const</b> Buffer; Size: <b>longint</b>; <b>var</b> Output); <b>procedure</b> HashBuffer(<b>const</b> Buffer; Size: <b>longint</b>; <b>var</b> Output);
<b>var</b> <b>var</b>
Hash: TDCP_ripemd160; Hash: TDCP_ripemd160;
<b>begin</b> <b>begin</b>
Hash:= TDCP_ripemd160.Create(<b>nil</b>); Hash:= TDCP_ripemd160.Create(<b>nil</b>);
Hash.Init; Hash.Init;
Hash.Update(Buffer,Size); Hash.Update(Buffer,Size);
Hash.Final(Output); Hash.Final(Output);
Hash.Free; Hash.Free;
<b>end</b>; <b>end</b>;
</pre> </pre>
<p><font size="+1"><a name="UpdateStream">procedure UpdateStream(Stream: TStream; Size: longword);</a></font> <p><font size="+1"><a name="UpdateStream">procedure UpdateStream(Stream: TStream; Size: longword);</a></font>
<p>This procedure hashes Size bytes from Stream. To get the hash result call <a href="#Final">Final</a>. <p>This procedure hashes Size bytes from Stream. To get the hash result call <a href="#Final">Final</a>.
<p><font size="+1"><a name="UpdateStr">procedure UpdateStr(const Str: string);</a></font> <p><font size="+1"><a name="UpdateStr">procedure UpdateStr(const Str: string);</a></font>
<p>This procedure hashes the string Str. To get the hash result call <a href="#Final">Final</a>. <p>This procedure hashes the string Str. To get the hash result call <a href="#Final">Final</a>.
<hr> <hr>
<p><font size="+2"><a name="Example1">Example 1 - File hashing</a></font> <p><font size="+2"><a name="Example1">Example 1 - File hashing</a></font>
<p>This example shows how you can hash the contents of a file <p>This example shows how you can hash the contents of a file
<pre> <pre>
<b>procedure</b> TForm1.Button1Click(Sender: TObject); <b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b> <b>var</b>
Hash: TDCP_ripemd160; Hash: TDCP_ripemd160;
Digest: <b>array</b>[0..19] <b>of</b> <b>byte</b>; <em>// RipeMD-160 produces a 160bit digest (20bytes)</em> Digest: <b>array</b>[0..19] <b>of</b> <b>byte</b>; <em>// RipeMD-160 produces a 160bit digest (20bytes)</em>
Source: TFileStream; Source: TFileStream;
i: <b>integer</b>; i: <b>integer</b>;
s: string; s: string;
<b>begin</b> <b>begin</b>
Source:= <b>nil</b>; Source:= <b>nil</b>;
<b>try</b> <b>try</b>
Source:= TFileStream.Create(Edit1.Text,fmOpenRead); <em>// open the file specified by Edit1</em> Source:= TFileStream.Create(Edit1.Text,fmOpenRead); <em>// open the file specified by Edit1</em>
<b>except</b> <b>except</b>
MessageDlg('Unable to open file',mtError,[mbOK],0); MessageDlg('Unable to open file',mtError,[mbOK],0);
<b>end</b>; <b>end</b>;
<b>if</b> Source <> <b>nil then</b> <b>if</b> Source <> <b>nil then</b>
<b>begin</b> <b>begin</b>
Hash:= TDCP_ripemd160.Create(Self); <em>// create the hash</em> Hash:= TDCP_ripemd160.Create(Self); <em>// create the hash</em>
Hash.Init; <em>// initialize it</em> Hash.Init; <em>// initialize it</em>
Hash.UpdateStream(Source,Source.Size); <em>// hash the stream contents</em> Hash.UpdateStream(Source,Source.Size); <em>// hash the stream contents</em>
Hash.Final(Digest); <em>// produce the digest</em> Hash.Final(Digest); <em>// produce the digest</em>
Source.Free; Source.Free;
s:= ''; s:= '';
<b>for</b> i:= 0 <b>to</b> 19 <b>do</b> <b>for</b> i:= 0 <b>to</b> 19 <b>do</b>
s:= s + IntToHex(Digest[i],2); s:= s + IntToHex(Digest[i],2);
Edit2.Text:= s; <em>// display the digest</em> Edit2.Text:= s; <em>// display the digest</em>
<b>end</b>; <b>end</b>;
<b>end</b>; <b>end</b>;
</pre> </pre>
<p>&nbsp; <p>&nbsp;
<p><a href="Index.html">Index</a>, <a href="Ciphers.html">Ciphers</a>, <a href="BlockCiphers.html">Block Ciphers</a> <p><a href="Index.html">Index</a>, <a href="Ciphers.html">Ciphers</a>, <a href="BlockCiphers.html">Block Ciphers</a>
<p>&nbsp; <p>&nbsp;
<p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br> <p><em>DCPcrypt is copyrighted &copy; 1999-2002 David Barton.<br>
All trademarks are property of their respective owners.</em> All trademarks are property of their respective owners.</em>
</body> </body>
</html> </html>

View File

@ -1,270 +1,270 @@
<html> <html>
<head> <head>
<title>DCPcrypt v2: Users Guide - Index</title> <title>DCPcrypt v2: Users Guide - Index</title>
</head> </head>
<body> <body>
<p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2 Beta 3</b></font><br> <p align="center"><font size="+2"><b>DCPcrypt Cryptographic Component Library v2 Beta 3</b></font><br>
<font size="+1">Copyright &copy; 1999-2002 David Barton<br> <font size="+1">Copyright &copy; 1999-2002 David Barton<br>
<a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br> <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a><br>
<a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font> <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a></font>
<p><font size="+2">Introduction</font> <p><font size="+2">Introduction</font>
<p>DCPcrypt is a collection of cryptographic components for the Borland Delphi(tm), C++ Builder(tm) and Kylix(tm) programming languages. The supported versions are Delphi 4, 5, 6 and 7, C++ Builder (3?), 4, 5, 6 and Kylix 1 (untested) and 2. <p>DCPcrypt is a collection of cryptographic components for the Borland Delphi(tm), C++ Builder(tm) and Kylix(tm) programming languages. The supported versions are Delphi 4, 5, 6 and 7, C++ Builder (3?), 4, 5, 6 and Kylix 1 (untested) and 2.
<p>The idea behind DCPcrypt is that it should be possible to "drop in" any algorithm implementation to replace another with minimum or no code changes. To aid in this goal all cryptographic components are descended from one of several base classes, TDCP_cipher for encryption algorithms and TDCP_hash for message digest algorithms. <p>The idea behind DCPcrypt is that it should be possible to "drop in" any algorithm implementation to replace another with minimum or no code changes. To aid in this goal all cryptographic components are descended from one of several base classes, TDCP_cipher for encryption algorithms and TDCP_hash for message digest algorithms.
<p> <p>
<table> <table>
<tr> <tr>
<td valign="center"><a href="http://www.opensource.org/docs/definition.php"><img src="osi-certified-120x100.png" border="0"></a></td> <td valign="center"><a href="http://www.opensource.org/docs/definition.php"><img src="osi-certified-120x100.png" border="0"></a></td>
<td valign="center"> <td valign="center">
<p>DCPcrypt is open source software (released under the <a href="MIT_license.txt">MIT license</a>) and as such there is no charge for inclusion in other software. However, I am currently a student and if you are making money from my software I would really appreciate a donation of some sort, whether financial or a license for the software you develop (<em>or if anyone wants to sponsor a Mathematical Modelling (Masters) student for their final year...</em>). Please note THIS IS NOT COMPULSORY IN ANY WAY. See <a href="http://www.cityinthesky.co.uk/cryptography.html">http://www.cityinthesky.co.uk/cryptography.html</a> for details on donations. <p>DCPcrypt is open source software (released under the <a href="MIT_license.txt">MIT license</a>) and as such there is no charge for inclusion in other software. However, I am currently a student and if you are making money from my software I would really appreciate a donation of some sort, whether financial or a license for the software you develop (<em>or if anyone wants to sponsor a Mathematical Modelling (Masters) student for their final year...</em>). Please note THIS IS NOT COMPULSORY IN ANY WAY. See <a href="http://www.cityinthesky.co.uk/cryptography.html">http://www.cityinthesky.co.uk/cryptography.html</a> for details on donations.
<p>This software is OSI Certified Open Source Software. OSI Certified is a certification mark of the <a href="http://www.opensource.org/">Open Source Initiative</a>. <p>This software is OSI Certified Open Source Software. OSI Certified is a certification mark of the <a href="http://www.opensource.org/">Open Source Initiative</a>.
<p>If you maintain a website then a link to my page at <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a> would be great! <p>If you maintain a website then a link to my page at <a href="http://www.cityinthesky.co.uk/">http://www.cityinthesky.co.uk/</a> would be great!
</td> </td>
</tr> </tr>
</table> </table>
<p>&nbsp; <p>&nbsp;
<p><font size="+2">What's New</font> <p><font size="+2">What's New</font>
<p>Changes since DCPcrypt v2 Beta 2: <p>Changes since DCPcrypt v2 Beta 2:
<ul> <ul>
<li>Corrected C++ Builder compilation problem. <li>Corrected C++ Builder compilation problem.
</ul> </ul>
<p>Changes since DCPcrypt v2 Beta 1: <p>Changes since DCPcrypt v2 Beta 1:
<ul> <ul>
<li>Renamed source code files for hashes and ciphers to DCPxxx.pas <li>Renamed source code files for hashes and ciphers to DCPxxx.pas
<li>Change the format of Cipher.InitStr so that the hash algorithm used to generate the key is explicitly specified. In order to get the same functionality as before, use TDCP_sha1. e.g. Cipher.InitStr('Hello World',TDCP_sha1); <li>Change the format of Cipher.InitStr so that the hash algorithm used to generate the key is explicitly specified. In order to get the same functionality as before, use TDCP_sha1. e.g. Cipher.InitStr('Hello World',TDCP_sha1);
<li>Block ciphers are now inherited from an intermediate component that implements the block size specific chaining mode encryption routines. <li>Block ciphers are now inherited from an intermediate component that implements the block size specific chaining mode encryption routines.
<li>Remove the internal component registration, it was more hassle than it was worth. If there is a demand for this to be put back then I might... <li>Remove the internal component registration, it was more hassle than it was worth. If there is a demand for this to be put back then I might...
<li>Added the full range of operation modes for Haval. By changing the defines at the top of DCPhaval.pas you can specify the number of passes and the output hash size. <li>Added the full range of operation modes for Haval. By changing the defines at the top of DCPhaval.pas you can specify the number of passes and the output hash size.
<li>Added the Tiger hash algorithm (192bit digest). <li>Added the Tiger hash algorithm (192bit digest).
<li>Changed the name of the file containing TDCP_ripemd160 for consistency to DCPripemd160 from DCPrmd160. <li>Changed the name of the file containing TDCP_ripemd160 for consistency to DCPripemd160 from DCPrmd160.
<li>GOST no longer appears on the component palette pending verifying what the actual standard is (the code is still included however). <li>GOST no longer appears on the component palette pending verifying what the actual standard is (the code is still included however).
<li>Added the RipeMD-128 hash algorithm (128bit digest). <li>Added the RipeMD-128 hash algorithm (128bit digest).
<li>Added the Serpent block cipher (AES finalist). <li>Added the Serpent block cipher (AES finalist).
<li>Added the SHA-256,384,512 hash algorithms (256, 384, 512bit digest respectively). <li>Added the SHA-256,384,512 hash algorithms (256, 384, 512bit digest respectively).
<li>Added CTR chaining mode to all block ciphers. <li>Added CTR chaining mode to all block ciphers.
</ul> </ul>
<p>&nbsp; <p>&nbsp;
<p><font size="+2">Installation</font> <p><font size="+2">Installation</font>
<p> <p>
<table> <table>
<tr> <tr>
<td width="120">Delphi</td> <td width="120">Delphi</td>
<td>Open the appropriate package, DCPdelphiX.dpk where X is your version of Delphi (either 4, 5 or 6). Then press the install button.</td> <td>Open the appropriate package, DCPdelphiX.dpk where X is your version of Delphi (either 4, 5 or 6). Then press the install button.</td>
</tr> </tr>
<tr> <tr>
<td width="120">C++ Builder</td> <td width="120">C++ Builder</td>
<td>Create a new design time package and add all the .pas files from the DCPcrypt2.zip archive including all those in the Ciphers and Hashes subdirectories. Then press the install button.</td> <td>Create a new design time package and add all the .pas files from the DCPcrypt2.zip archive including all those in the Ciphers and Hashes subdirectories. Then press the install button.</td>
</tr> </tr>
<tr> <tr>
<td width="120">Kylix</td> <td width="120">Kylix</td>
<td>Open the DCPkylix.dpk package and then press the install button (note: Kylix 1 users may need to create a new package as with C++ Builder as this is a Kylix 2 package).</td> <td>Open the DCPkylix.dpk package and then press the install button (note: Kylix 1 users may need to create a new package as with C++ Builder as this is a Kylix 2 package).</td>
</tr> </tr>
<table> <table>
<p>You may need to add the directory containing DCPcrypt (and the Ciphers and Hashes subdirectories) to your library search path (found under Environment Options). <p>You may need to add the directory containing DCPcrypt (and the Ciphers and Hashes subdirectories) to your library search path (found under Environment Options).
<p>Once installed you will find two extra pages of components on your component palette, namely DCPciphers and DCPhashes. You can now place these components onto the form of your application to start using the algorithms. <p>Once installed you will find two extra pages of components on your component palette, namely DCPciphers and DCPhashes. You can now place these components onto the form of your application to start using the algorithms.
<p>&nbsp; <p>&nbsp;
<p><font size="+2">Usage</font> <p><font size="+2">Usage</font>
<p>Please note that an appreciation of the basic principles of encryption/decryption and key management is needed to ensure the correct usage of the ciphers implemented within this package. A good introduction on this subject is provided by Bruce Schneier's "Applied Cryptography" (ISBN: 0-471-11709-9) also see the NIST publication SP800-38A for information on the block cipher chaining modes. <p>Please note that an appreciation of the basic principles of encryption/decryption and key management is needed to ensure the correct usage of the ciphers implemented within this package. A good introduction on this subject is provided by Bruce Schneier's "Applied Cryptography" (ISBN: 0-471-11709-9) also see the NIST publication SP800-38A for information on the block cipher chaining modes.
<ul> <ul>
<li><a href="Ciphers.html">Ciphers</a> - the basic building block of DCPcrypt, the TDCP_cipher component. <li><a href="Ciphers.html">Ciphers</a> - the basic building block of DCPcrypt, the TDCP_cipher component.
<li><a href="BlockCiphers.html">Block Ciphers</a> - the base of all block ciphers, the TDCP_blockcipher component. <li><a href="BlockCiphers.html">Block Ciphers</a> - the base of all block ciphers, the TDCP_blockcipher component.
<li><a href="Hashes.html">Hashes</a> - the base of all hash algorithms, the TDCP_hash component. <li><a href="Hashes.html">Hashes</a> - the base of all hash algorithms, the TDCP_hash component.
</ul> </ul>
<p>DCPcrypt v2 contains the following ciphers and hash algorithms: <p>DCPcrypt v2 contains the following ciphers and hash algorithms:
<p> <p>
<table bgcolor="#FFFFCC" align="center"> <table bgcolor="#FFFFCC" align="center">
<tr> <tr>
<td colspan="4" align="center"><font size="+1"><b>Ciphers</b></font></td> <td colspan="4" align="center"><font size="+1"><b>Ciphers</b></font></td>
</tr> </tr>
<tr> <tr>
<td><b>Name</b></td> <td><b>Name</b></td>
<td><b>Patents</b></td> <td><b>Patents</b></td>
<td><b>Block Size</b></td> <td><b>Block Size</b></td>
<td><b>Max Key Size*</b></td> <td><b>Max Key Size*</b></td>
</tr> </tr>
<tr> <tr>
<td>Blowfish</td> <td>Blowfish</td>
<td>None</td> <td>None</td>
<td>64 bits</td> <td>64 bits</td>
<td>448 bits</td> <td>448 bits</td>
</tr> </tr>
<tr> <tr>
<td>Cast-128</td> <td>Cast-128</td>
<td>None</td> <td>None</td>
<td>64 bits</td> <td>64 bits</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>Cast-256</td> <td>Cast-256</td>
<td>Patented?</td> <td>Patented?</td>
<td>128 bits</td> <td>128 bits</td>
<td>256 bits</td> <td>256 bits</td>
</tr> </tr>
<tr> <tr>
<td>DES</td> <td>DES</td>
<td>None</td> <td>None</td>
<td>64 bits**</td> <td>64 bits**</td>
<td>64 bits</td> <td>64 bits</td>
</tr> </tr>
<tr> <tr>
<td>3DES</td> <td>3DES</td>
<td>None</td> <td>None</td>
<td>64 bits</td> <td>64 bits</td>
<td>192 bits</td> <td>192 bits</td>
</tr> </tr>
<tr> <tr>
<td>Ice</td> <td>Ice</td>
<td>None?</td> <td>None?</td>
<td>64 bits</td> <td>64 bits</td>
<td>64 bits</td> <td>64 bits</td>
</tr> </tr>
<tr> <tr>
<td>Thin Ice</td> <td>Thin Ice</td>
<td>None?</td> <td>None?</td>
<td>64 bits</td> <td>64 bits</td>
<td>64 bits</td> <td>64 bits</td>
</tr> </tr>
<tr> <tr>
<td>Ice 2</td> <td>Ice 2</td>
<td>None?</td> <td>None?</td>
<td>64 bits</td> <td>64 bits</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>IDEA</td> <td>IDEA</td>
<td>Free for non-commercial use</td> <td>Free for non-commercial use</td>
<td>64 bits</td> <td>64 bits</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>MARS</td> <td>MARS</td>
<td>Patented?</td> <td>Patented?</td>
<td>128 bits</td> <td>128 bits</td>
<td>1248 bits</td> <td>1248 bits</td>
</tr> </tr>
<tr> <tr>
<td>Misty1</td> <td>Misty1</td>
<td>Free for non-commercial use</td> <td>Free for non-commercial use</td>
<td>64 bits</td> <td>64 bits</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>RC2</td> <td>RC2</td>
<td>None</td> <td>None</td>
<td>64 bits</td> <td>64 bits</td>
<td>1024 bits</td> <td>1024 bits</td>
</tr> </tr>
<tr> <tr>
<td>RC4</td> <td>RC4</td>
<td>None</td> <td>None</td>
<td>N/A</td> <td>N/A</td>
<td>2048 bits</td> <td>2048 bits</td>
</tr> </tr>
<tr> <tr>
<td>RC5</td> <td>RC5</td>
<td>Patented</td> <td>Patented</td>
<td>64 bits</td> <td>64 bits</td>
<td>2048 bits</td> <td>2048 bits</td>
</tr> </tr>
<tr> <tr>
<td>RC6</td> <td>RC6</td>
<td>Patented</td> <td>Patented</td>
<td>128 bits</td> <td>128 bits</td>
<td>2048 bits</td> <td>2048 bits</td>
</tr> </tr>
<tr> <tr>
<td>Rijndael (AES)</td> <td>Rijndael (AES)</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
<td>256 bits</td> <td>256 bits</td>
</tr> </tr>
<tr> <tr>
<td>Serpent</td> <td>Serpent</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
<td>256 bits</td> <td>256 bits</td>
</tr> </tr>
<tr> <tr>
<td>TEA</td> <td>TEA</td>
<td>None</td> <td>None</td>
<td>64 bits</td> <td>64 bits</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>Twofish</td> <td>Twofish</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
<td>256 bits</td> <td>256 bits</td>
</tr> </tr>
</table> </table>
<p>* although the quoted maximum key size may extremely large it doen't mean that the algorithm is secure to the same level.<br> <p>* although the quoted maximum key size may extremely large it doen't mean that the algorithm is secure to the same level.<br>
** a 64bit key is used for DES then every 8th bit is discarded (parity) so the effective size is 56 bits. ** a 64bit key is used for DES then every 8th bit is discarded (parity) so the effective size is 56 bits.
<p> <p>
<table bgcolor="#FFFFCC" align="center"> <table bgcolor="#FFFFCC" align="center">
<tr> <tr>
<td colspan="3" align="center"><font size="+1"><b>Hash Algorithms</b><font></td> <td colspan="3" align="center"><font size="+1"><b>Hash Algorithms</b><font></td>
</tr> </tr>
<tr> <tr>
<td><b>Name</b></td> <td><b>Name</b></td>
<td><b>Patents</b></td> <td><b>Patents</b></td>
<td><b>Digest Size</b></td> <td><b>Digest Size</b></td>
</tr> </tr>
<tr> <tr>
<td>Haval</td> <td>Haval</td>
<td>None</td> <td>None</td>
<td>128, 160, 192, 224, 256 bits*</td> <td>128, 160, 192, 224, 256 bits*</td>
</tr> </tr>
<tr> <tr>
<td>MD4</td> <td>MD4</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>MD5</td> <td>MD5</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>RipeMD-128</td> <td>RipeMD-128</td>
<td>None</td> <td>None</td>
<td>128 bits</td> <td>128 bits</td>
</tr> </tr>
<tr> <tr>
<td>RipeMD-160</td> <td>RipeMD-160</td>
<td>None</td> <td>None</td>
<td>160 bits</td> <td>160 bits</td>
</tr> </tr>
<tr> <tr>
<td>SHA-1</td> <td>SHA-1</td>
<td>None</td> <td>None</td>
<td>160 bits</td> <td>160 bits</td>
</tr> </tr>
<tr> <tr>
<td>SHA-256</td> <td>SHA-256</td>
<td>None</td> <td>None</td>
<td>256 bits</td> <td>256 bits</td>
</tr> </tr>
<tr> <tr>
<td>SHA-384</td> <td>SHA-384</td>
<td>None</td> <td>None</td>
<td>384 bits</td> <td>384 bits</td>
</tr> </tr>
<tr> <tr>
<td>SHA-512</td> <td>SHA-512</td>
<td>None</td> <td>None</td>
<td>512 bits</td> <td>512 bits</td>
</tr> </tr>
<tr> <tr>
<td>Tiger</td> <td>Tiger</td>
<td>None</td> <td>None</td>
<td>192 bits</td> <td>192 bits</td>
</tr> </tr>
</table> </table>
<p>* The different digest sizes of Haval can be accessed by uncommenting the $defines at the start of DCPhaval.pas. <p>* The different digest sizes of Haval can be accessed by uncommenting the $defines at the start of DCPhaval.pas.
<p>&nbsp; <p>&nbsp;
<p><font size="+2">Contact</font> <p><font size="+2">Contact</font>
<p>I appreciate knowing what DCPcrypt is being used for and also if you have any queries or bug reports please email me at <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a>. <p>I appreciate knowing what DCPcrypt is being used for and also if you have any queries or bug reports please email me at <a href="mailto:crypto@cityinthesky.co.uk">crypto@cityinthesky.co.uk</a>.
<p>&nbsp; <p>&nbsp;
<p><em>DCPcrypt is copyrighted &copy; 1999-2003 David Barton.<br> <p><em>DCPcrypt is copyrighted &copy; 1999-2003 David Barton.<br>
All trademarks are property of their respective owners.</em> All trademarks are property of their respective owners.</em>
</body> </body>
</html> </html>

View File

@ -1,21 +1,21 @@
The MIT License The MIT License
Copyright (c) <year> <copyright holders> Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions: Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.

View File

@ -1,203 +1,203 @@
temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4); temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0];
temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3); temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1];
temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2); temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2];
temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1); temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3];
temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0); temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4];
temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7); temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5];
temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6); temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6];
temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5); temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7];
temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4); temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8];
temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3); temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9];
temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2); temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10];
temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1); temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11];
temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0); temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12];
temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7); temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13];
temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6); temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14];
temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5); temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15];
temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4); temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16];
temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3); temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17];
temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2); temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18];
temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1); temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19];
temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0); temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20];
temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7); temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21];
temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6); temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22];
temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5); temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23];
temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4); temp:= (t2 and (t4 xor t3) xor t6 and t0 xor t5 and t1 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24];
temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3); temp:= (t1 and (t3 xor t2) xor t5 and t7 xor t4 and t0 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25];
temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2); temp:= (t0 and (t2 xor t1) xor t4 and t6 xor t3 and t7 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26];
temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1); temp:= (t7 and (t1 xor t0) xor t3 and t5 xor t2 and t6 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27];
temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0); temp:= (t6 and (t0 xor t7) xor t2 and t4 xor t1 and t5 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28];
temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7); temp:= (t5 and (t7 xor t6) xor t1 and t3 xor t0 and t4 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29];
temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6); temp:= (t4 and (t6 xor t5) xor t0 and t2 xor t7 and t3 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30];
temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5); temp:= (t3 and (t5 xor t4) xor t7 and t1 xor t6 and t2 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31];
temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6); temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6;
temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5); temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377;
temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4); temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF;
temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3); temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C;
temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2); temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7;
temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1); temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD;
temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0); temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5;
temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7); temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917;
temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6); temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9;
temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5); temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B;
temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4); temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6;
temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3); temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC;
temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2); temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB;
temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1); temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7;
temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0); temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED;
temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7); temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96;
temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6); temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045;
temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5); temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99;
temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4); temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947;
temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3); temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7;
temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2); temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2;
temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1); temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16;
temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0); temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8;
temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7); temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69;
temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6); temp:= (t5 and (t3 and not t0 xor t1 and t2 xor t4 xor t6) xor t1 and (t3 xor t2) xor t0 and t2 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3;
temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5); temp:= (t4 and (t2 and not t7 xor t0 and t1 xor t3 xor t5) xor t0 and (t2 xor t1) xor t7 and t1 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E;
temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4); temp:= (t3 and (t1 and not t6 xor t7 and t0 xor t2 xor t4) xor t7 and (t1 xor t0) xor t6 and t0 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F;
temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3); temp:= (t2 and (t0 and not t5 xor t6 and t7 xor t1 xor t3) xor t6 and (t0 xor t7) xor t5 and t7 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658;
temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2); temp:= (t1 and (t7 and not t4 xor t5 and t6 xor t0 xor t2) xor t5 and (t7 xor t6) xor t4 and t6 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58;
temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1); temp:= (t0 and (t6 and not t3 xor t4 and t5 xor t7 xor t1) xor t4 and (t6 xor t5) xor t3 and t5 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE;
temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0); temp:= (t7 and (t5 and not t2 xor t3 and t4 xor t6 xor t0) xor t3 and (t5 xor t4) xor t2 and t4 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D;
temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7); temp:= (t6 and (t4 and not t1 xor t2 and t3 xor t5 xor t7) xor t2 and (t4 xor t3) xor t1 and t3 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5;
temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0); temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539;
temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7); temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013;
temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6); temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023;
temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5); temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0;
temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4); temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918;
temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3); temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF;
temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2); temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0;
temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1); temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E;
temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0); temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B;
temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7); temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E;
temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6); temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1;
temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5); temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27;
temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4); temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA;
temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3); temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60;
temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2); temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3;
temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1); temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94;
temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0); temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862;
temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7); temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440;
temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6); temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A;
temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5); temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6;
temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4); temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34;
temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3); temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE;
temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2); temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF;
temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1); temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993;
temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0); temp:= (t3 and (t5 and t4 xor t6 xor t0) xor t5 and t2 xor t4 and t1 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411;
temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7); temp:= (t2 and (t4 and t3 xor t5 xor t7) xor t4 and t1 xor t3 and t0 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A;
temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6); temp:= (t1 and (t3 and t2 xor t4 xor t6) xor t3 and t0 xor t2 and t7 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D;
temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5); temp:= (t0 and (t2 and t1 xor t3 xor t5) xor t2 and t7 xor t1 and t6 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6;
temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4); temp:= (t7 and (t1 and t0 xor t2 xor t4) xor t1 and t6 xor t0 and t5 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16;
temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3); temp:= (t6 and (t0 and t7 xor t1 xor t3) xor t0 and t5 xor t7 and t4 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E;
temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2); temp:= (t5 and (t7 and t6 xor t0 xor t2) xor t7 and t4 xor t6 and t3 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33;
temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1); temp:= (t4 and (t6 and t5 xor t7 xor t1) xor t6 and t3 xor t5 and t2 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C;

View File

@ -1,272 +1,272 @@
temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0); temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0];
temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7); temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1];
temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6); temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2];
temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5); temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3];
temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4); temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4];
temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3); temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5];
temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2); temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6];
temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1); temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7];
temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0); temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8];
temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7); temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9];
temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6); temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10];
temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5); temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11];
temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4); temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12];
temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3); temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13];
temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2); temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14];
temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1); temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15];
temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0); temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16];
temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7); temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17];
temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6); temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18];
temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5); temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19];
temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4); temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20];
temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3); temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21];
temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2); temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22];
temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1); temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23];
temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0); temp:= (t3 and (t0 xor t1) xor t5 and t6 xor t4 and t2 xor t0);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24];
temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7); temp:= (t2 and (t7 xor t0) xor t4 and t5 xor t3 and t1 xor t7);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25];
temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6); temp:= (t1 and (t6 xor t7) xor t3 and t4 xor t2 and t0 xor t6);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26];
temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5); temp:= (t0 and (t5 xor t6) xor t2 and t3 xor t1 and t7 xor t5);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27];
temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4); temp:= (t7 and (t4 xor t5) xor t1 and t2 xor t0 and t6 xor t4);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28];
temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3); temp:= (t6 and (t3 xor t4) xor t0 and t1 xor t7 and t5 xor t3);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29];
temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2); temp:= (t5 and (t2 xor t3) xor t7 and t0 xor t6 and t4 xor t2);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30];
temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1); temp:= (t4 and (t1 xor t2) xor t6 and t7 xor t5 and t3 xor t1);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31];
temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4); temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6;
temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3); temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377;
temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2); temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF;
temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1); temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C;
temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0); temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7;
temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7); temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD;
temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6); temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5;
temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5); temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917;
temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4); temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9;
temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3); temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B;
temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2); temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6;
temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1); temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC;
temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0); temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB;
temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7); temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7;
temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6); temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED;
temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5); temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96;
temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4); temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045;
temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3); temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99;
temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2); temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947;
temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1); temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7;
temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0); temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2;
temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7); temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16;
temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6); temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8;
temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5); temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69;
temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4); temp:= (t1 and (t6 and not t0 xor t2 and t5 xor t3 xor t4) xor t2 and (t6 xor t5) xor t0 and t5 xor t4);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3;
temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3); temp:= (t0 and (t5 and not t7 xor t1 and t4 xor t2 xor t3) xor t1 and (t5 xor t4) xor t7 and t4 xor t3);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E;
temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2); temp:= (t7 and (t4 and not t6 xor t0 and t3 xor t1 xor t2) xor t0 and (t4 xor t3) xor t6 and t3 xor t2);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F;
temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1); temp:= (t6 and (t3 and not t5 xor t7 and t2 xor t0 xor t1) xor t7 and (t3 xor t2) xor t5 and t2 xor t1);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658;
temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0); temp:= (t5 and (t2 and not t4 xor t6 and t1 xor t7 xor t0) xor t6 and (t2 xor t1) xor t4 and t1 xor t0);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58;
temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7); temp:= (t4 and (t1 and not t3 xor t5 and t0 xor t6 xor t7) xor t5 and (t1 xor t0) xor t3 and t0 xor t7);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE;
temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6); temp:= (t3 and (t0 and not t2 xor t4 and t7 xor t5 xor t6) xor t4 and (t0 xor t7) xor t2 and t7 xor t6);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D;
temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5); temp:= (t2 and (t7 and not t1 xor t3 and t6 xor t4 xor t5) xor t3 and (t7 xor t6) xor t1 and t6 xor t5);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5;
temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5); temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539;
temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4); temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013;
temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3); temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023;
temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2); temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0;
temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1); temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918;
temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0); temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF;
temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7); temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0;
temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6); temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E;
temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5); temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B;
temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4); temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E;
temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3); temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1;
temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2); temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27;
temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1); temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA;
temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0); temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60;
temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7); temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3;
temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6); temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94;
temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5); temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862;
temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4); temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440;
temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3); temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A;
temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2); temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6;
temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1); temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34;
temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0); temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE;
temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7); temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF;
temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6); temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993;
temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5); temp:= (t6 and (t2 and t0 xor t1 xor t5) xor t2 and t3 xor t0 and t4 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411;
temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4); temp:= (t5 and (t1 and t7 xor t0 xor t4) xor t1 and t2 xor t7 and t3 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A;
temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3); temp:= (t4 and (t0 and t6 xor t7 xor t3) xor t0 and t1 xor t6 and t2 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D;
temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2); temp:= (t3 and (t7 and t5 xor t6 xor t2) xor t7 and t0 xor t5 and t1 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6;
temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1); temp:= (t2 and (t6 and t4 xor t5 xor t1) xor t6 and t7 xor t4 and t0 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16;
temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0); temp:= (t1 and (t5 and t3 xor t4 xor t0) xor t5 and t6 xor t3 and t7 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E;
temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7); temp:= (t0 and (t4 and t2 xor t3 xor t7) xor t4 and t5 xor t2 and t6 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33;
temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6); temp:= (t7 and (t3 and t1 xor t2 xor t6) xor t3 and t4 xor t1 and t5 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C;
temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3); temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24] + $7A325381; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24] + $7A325381;
temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2); temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 4] + $28958677; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 4] + $28958677;
temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1); temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 0] + $3B8F4898; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 0] + $3B8F4898;
temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0); temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[14] + $6B4BB9AF; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[14] + $6B4BB9AF;
temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7); temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $C4BFE81B; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $C4BFE81B;
temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6); temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 7] + $66282193; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 7] + $66282193;
temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5); temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $61D809CC; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $61D809CC;
temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4); temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23] + $FB21A991; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23] + $FB21A991;
temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3); temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[26] + $487CAC60; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[26] + $487CAC60;
temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2); temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $5DEC8032; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $5DEC8032;
temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1); temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[30] + $EF845D5D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[30] + $EF845D5D;
temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0); temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $E98575B1; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $E98575B1;
temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7); temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DC262302; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DC262302;
temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6); temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $EB651B88; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $EB651B88;
temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5); temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[19] + $23893E81; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[19] + $23893E81;
temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4); temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 3] + $D396ACC5; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 3] + $D396ACC5;
temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3); temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[22] + $0F6D6FF3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[22] + $0F6D6FF3;
temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2); temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[11] + $83F44239; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[11] + $83F44239;
temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1); temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[31] + $2E0B4482; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[31] + $2E0B4482;
temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0); temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[21] + $A4842004; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[21] + $A4842004;
temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7); temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 8] + $69C8F04A; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 8] + $69C8F04A;
temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6); temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[27] + $9E1F9B5E; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[27] + $9E1F9B5E;
temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5); temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[12] + $21C66842; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[12] + $21C66842;
temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4); temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 9] + $F6E96C9A; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 9] + $F6E96C9A;
temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3); temp:= (t0 and (t4 and not t2 xor t5 and not t6 xor t1 xor t6 xor t3) xor t5 and (t1 and t2 xor t4 xor t6) xor t2 and t6 xor t3);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 1] + $670C9C61; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 1] + $670C9C61;
temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2); temp:= (t7 and (t3 and not t1 xor t4 and not t5 xor t0 xor t5 xor t2) xor t4 and (t0 and t1 xor t3 xor t5) xor t1 and t5 xor t2);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[29] + $ABD388F0; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[29] + $ABD388F0;
temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1); temp:= (t6 and (t2 and not t0 xor t3 and not t4 xor t7 xor t4 xor t1) xor t3 and (t7 and t0 xor t2 xor t4) xor t0 and t4 xor t1);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 5] + $6A51A0D2; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 5] + $6A51A0D2;
temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0); temp:= (t5 and (t1 and not t7 xor t2 and not t3 xor t6 xor t3 xor t0) xor t2 and (t6 and t7 xor t1 xor t3) xor t7 and t3 xor t0);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[15] + $D8542F68; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[15] + $D8542F68;
temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7); temp:= (t4 and (t0 and not t6 xor t1 and not t2 xor t5 xor t2 xor t7) xor t1 and (t5 and t6 xor t0 xor t2) xor t6 and t2 xor t7);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $960FA728; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $960FA728;
temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6); temp:= (t3 and (t7 and not t5 xor t0 and not t1 xor t4 xor t1 xor t6) xor t0 and (t4 and t5 xor t7 xor t1) xor t5 and t1 xor t6);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $AB5133A3; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $AB5133A3;
temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5); temp:= (t2 and (t6 and not t4 xor t7 and not t0 xor t3 xor t0 xor t5) xor t7 and (t3 and t4 xor t6 xor t0) xor t4 and t0 xor t5);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $6EEF0B6C; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $6EEF0B6C;
temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4); temp:= (t1 and (t5 and not t3 xor t6 and not t7 xor t2 xor t7 xor t4) xor t6 and (t2 and t3 xor t5 xor t7) xor t3 and t7 xor t4);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[13] + $137A3BE4; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[13] + $137A3BE4;

View File

@ -1,339 +1,339 @@
temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6); temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0];
temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5); temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1];
temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4); temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2];
temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3); temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3];
temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2); temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4];
temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1); temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5];
temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0); temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6];
temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7); temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7];
temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6); temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8];
temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5); temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9];
temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4); temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10];
temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3); temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11];
temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2); temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12];
temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1); temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13];
temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0); temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14];
temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7); temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15];
temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6); temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16];
temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5); temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17];
temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4); temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18];
temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3); temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19];
temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2); temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20];
temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1); temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21];
temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0); temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22];
temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7); temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23];
temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6); temp:= (t2 and (t6 xor t1) xor t5 and t4 xor t0 and t3 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24]; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24];
temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5); temp:= (t1 and (t5 xor t0) xor t4 and t3 xor t7 and t2 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25]; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25];
temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4); temp:= (t0 and (t4 xor t7) xor t3 and t2 xor t6 and t1 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26]; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26];
temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3); temp:= (t7 and (t3 xor t6) xor t2 and t1 xor t5 and t0 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27]; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27];
temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2); temp:= (t6 and (t2 xor t5) xor t1 and t0 xor t4 and t7 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28]; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28];
temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1); temp:= (t5 and (t1 xor t4) xor t0 and t7 xor t3 and t6 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29]; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29];
temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0); temp:= (t4 and (t0 xor t3) xor t7 and t6 xor t2 and t5 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30]; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30];
temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7); temp:= (t3 and (t7 xor t2) xor t6 and t5 xor t1 and t4 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31]; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31];
temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5); temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6;
temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4); temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377;
temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3); temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF;
temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2); temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C;
temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1); temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7;
temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0); temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD;
temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7); temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5;
temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6); temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917;
temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5); temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9;
temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4); temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B;
temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3); temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6;
temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2); temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC;
temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1); temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB;
temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0); temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7;
temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7); temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED;
temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6); temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96;
temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5); temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045;
temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4); temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99;
temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3); temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947;
temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2); temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7;
temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1); temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $0801F2E2;
temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0); temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[24] + $858EFC16;
temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7); temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[29] + $636920D8;
temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6); temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 6] + $71574E69;
temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5); temp:= (t3 and (t4 and not t0 xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $A458FEA3;
temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4); temp:= (t2 and (t3 and not t7 xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[12] + $F4933D7E;
temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3); temp:= (t1 and (t2 and not t6 xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[15] + $0D95748F;
temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2); temp:= (t0 and (t1 and not t5 xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[13] + $728EB658;
temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1); temp:= (t7 and (t0 and not t4 xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $718BCD58;
temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0); temp:= (t6 and (t7 and not t3 xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $82154AEE;
temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7); temp:= (t5 and (t6 and not t2 xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $7B54A41D;
temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6); temp:= (t4 and (t5 and not t1 xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $C25A59B5;
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5); temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539;
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4); temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013;
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3); temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023;
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2); temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0;
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1); temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918;
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0); temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF;
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7); temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0;
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6); temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E;
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5); temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B;
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4); temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E;
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3); temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1;
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2); temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27;
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1); temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA;
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0); temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60;
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7); temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3;
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6); temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94;
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5); temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862;
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4); temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440;
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3); temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A;
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2); temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6;
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1); temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34;
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0); temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE;
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7); temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF;
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6); temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993;
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5); temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411;
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4); temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A;
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3); temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D;
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2); temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6;
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1); temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16;
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0); temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E;
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7); temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33;
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6); temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C;
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6); temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24] + $7A325381; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24] + $7A325381;
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5); temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 4] + $28958677; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 4] + $28958677;
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4); temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 0] + $3B8F4898; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 0] + $3B8F4898;
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3); temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[14] + $6B4BB9AF; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[14] + $6B4BB9AF;
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2); temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $C4BFE81B; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $C4BFE81B;
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1); temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 7] + $66282193; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 7] + $66282193;
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0); temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $61D809CC; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $61D809CC;
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7); temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23] + $FB21A991; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23] + $FB21A991;
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6); temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[26] + $487CAC60; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[26] + $487CAC60;
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5); temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $5DEC8032; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $5DEC8032;
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4); temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[30] + $EF845D5D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[30] + $EF845D5D;
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3); temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $E98575B1; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $E98575B1;
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2); temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DC262302; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DC262302;
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1); temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $EB651B88; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $EB651B88;
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0); temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[19] + $23893E81; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[19] + $23893E81;
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7); temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 3] + $D396ACC5; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 3] + $D396ACC5;
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6); temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[22] + $0F6D6FF3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[22] + $0F6D6FF3;
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5); temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[11] + $83F44239; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[11] + $83F44239;
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4); temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[31] + $2E0B4482; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[31] + $2E0B4482;
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3); temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[21] + $A4842004; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[21] + $A4842004;
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2); temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 8] + $69C8F04A; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 8] + $69C8F04A;
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1); temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[27] + $9E1F9B5E; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[27] + $9E1F9B5E;
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0); temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[12] + $21C66842; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[12] + $21C66842;
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7); temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 9] + $F6E96C9A; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 9] + $F6E96C9A;
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6); temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 1] + $670C9C61; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 1] + $670C9C61;
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5); temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[29] + $ABD388F0; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[29] + $ABD388F0;
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4); temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 5] + $6A51A0D2; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 5] + $6A51A0D2;
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3); temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[15] + $D8542F68; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[15] + $D8542F68;
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2); temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $960FA728; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $960FA728;
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1); temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $AB5133A3; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $AB5133A3;
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0); temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $6EEF0B6C; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $6EEF0B6C;
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7); temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[13] + $137A3BE4; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[13] + $137A3BE4;
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2); temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[27] + $BA3BF050; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[27] + $BA3BF050;
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1); temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $7EFB2A98; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $7EFB2A98;
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0); temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $A1F1651D; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $A1F1651D;
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7); temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[26] + $39AF0176; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[26] + $39AF0176;
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6); temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $66CA593E; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $66CA593E;
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5); temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $82430E88; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $82430E88;
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4); temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[20] + $8CEE8619; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[20] + $8CEE8619;
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3); temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[29] + $456F9FB4; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[29] + $456F9FB4;
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2); temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $7D84A5C3; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $7D84A5C3;
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1); temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 0] + $3B8B5EBE; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 0] + $3B8B5EBE;
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0); temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[12] + $E06F75D8; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[12] + $E06F75D8;
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7); temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 7] + $85C12073; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 7] + $85C12073;
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6); temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[13] + $401A449F; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[13] + $401A449F;
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5); temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 8] + $56C16AA6; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 8] + $56C16AA6;
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4); temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $4ED3AA62; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $4ED3AA62;
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3); temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[10] + $363F7706; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[10] + $363F7706;
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2); temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $1BFEDF72; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $1BFEDF72;
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1); temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $429B023D; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $429B023D;
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0); temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[14] + $37D0D724; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[14] + $37D0D724;
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7); temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[30] + $D00A1248; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[30] + $D00A1248;
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6); temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DB0FEAD3; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DB0FEAD3;
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5); temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 6] + $49F1C09B; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 6] + $49F1C09B;
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4); temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $075372C9; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $075372C9;
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3); temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[24] + $80991B7B; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[24] + $80991B7B;
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2); temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 2] + $25D479D8; t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 2] + $25D479D8;
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1); temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $F6E8DEF7; t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $F6E8DEF7;
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0); temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[16] + $E3FE501A; t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[16] + $E3FE501A;
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7); temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $B6794C3B; t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $B6794C3B;
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6); temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4] + $976CE0BD; t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4] + $976CE0BD;
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5); temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 1] + $04C006BA; t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 1] + $04C006BA;
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4); temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[25] + $C1A94FB6; t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[25] + $C1A94FB6;
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3); temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15] + $409F60C4; t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15] + $409F60C4;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,237 +1,237 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of MD4 **********************************} {* A binary compatible implementation of MD4 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPmd4; unit DCPmd4;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_md4= class(TDCP_hash) TDCP_md4= class(TDCP_hash)
protected protected
LenHi, LenLo: longword; LenHi, LenLo: longword;
Index: DWord; Index: DWord;
CurrentHash: array[0..3] of DWord; CurrentHash: array[0..3] of DWord;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
function LRot32(a, b: longword): longword; function LRot32(a, b: longword): longword;
begin begin
Result:= (a shl b) or (a shr (32-b)); Result:= (a shl b) or (a shr (32-b));
end; end;
procedure TDCP_md4.Compress; procedure TDCP_md4.Compress;
var var
Data: array[0..15] of dword; Data: array[0..15] of dword;
A, B, C, D: dword; A, B, C, D: dword;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Move(HashBuffer,Data,Sizeof(Data)); Move(HashBuffer,Data,Sizeof(Data));
A:= CurrentHash[0]; A:= CurrentHash[0];
B:= CurrentHash[1]; B:= CurrentHash[1];
C:= CurrentHash[2]; C:= CurrentHash[2];
D:= CurrentHash[3]; D:= CurrentHash[3];
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 0],3); A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 0],3);
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 1],7); D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 1],7);
C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 2],11); C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 2],11);
B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 3],19); B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 3],19);
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 4],3); A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 4],3);
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 5],7); D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 5],7);
C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 6],11); C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 6],11);
B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 7],19); B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 7],19);
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 8],3); A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 8],3);
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 9],7); D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 9],7);
C:= LRot32(C + (B xor (D and (A xor B))) + Data[10],11); C:= LRot32(C + (B xor (D and (A xor B))) + Data[10],11);
B:= LRot32(B + (A xor (C and (D xor A))) + Data[11],19); B:= LRot32(B + (A xor (C and (D xor A))) + Data[11],19);
A:= LRot32(A + (D xor (B and (C xor D))) + Data[12],3); A:= LRot32(A + (D xor (B and (C xor D))) + Data[12],3);
D:= LRot32(D + (C xor (A and (B xor C))) + Data[13],7); D:= LRot32(D + (C xor (A and (B xor C))) + Data[13],7);
C:= LRot32(C + (B xor (D and (A xor B))) + Data[14],11); C:= LRot32(C + (B xor (D and (A xor B))) + Data[14],11);
B:= LRot32(B + (A xor (C and (D xor A))) + Data[15],19); B:= LRot32(B + (A xor (C and (D xor A))) + Data[15],19);
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 0] + $5a827999,3); A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 0] + $5a827999,3);
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 4] + $5a827999,5); D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 4] + $5a827999,5);
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 8] + $5a827999,9); C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 8] + $5a827999,9);
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[12] + $5a827999,13); B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[12] + $5a827999,13);
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 1] + $5a827999,3); A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 1] + $5a827999,3);
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 5] + $5a827999,5); D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 5] + $5a827999,5);
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 9] + $5a827999,9); C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 9] + $5a827999,9);
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[13] + $5a827999,13); B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[13] + $5a827999,13);
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 2] + $5a827999,3); A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 2] + $5a827999,3);
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 6] + $5a827999,5); D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 6] + $5a827999,5);
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[10] + $5a827999,9); C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[10] + $5a827999,9);
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[14] + $5a827999,13); B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[14] + $5a827999,13);
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 3] + $5a827999,3); A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 3] + $5a827999,3);
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 7] + $5a827999,5); D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 7] + $5a827999,5);
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[11] + $5a827999,9); C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[11] + $5a827999,9);
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[15] + $5a827999,13); B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[15] + $5a827999,13);
A:= LRot32(A + (B xor C xor D) + Data[ 0] + $6ed9eba1,3); A:= LRot32(A + (B xor C xor D) + Data[ 0] + $6ed9eba1,3);
D:= LRot32(D + (A xor B xor C) + Data[ 8] + $6ed9eba1,9); D:= LRot32(D + (A xor B xor C) + Data[ 8] + $6ed9eba1,9);
C:= LRot32(C + (D xor A xor B) + Data[ 4] + $6ed9eba1,11); C:= LRot32(C + (D xor A xor B) + Data[ 4] + $6ed9eba1,11);
B:= LRot32(B + (C xor D xor A) + Data[12] + $6ed9eba1,15); B:= LRot32(B + (C xor D xor A) + Data[12] + $6ed9eba1,15);
A:= LRot32(A + (B xor C xor D) + Data[ 2] + $6ed9eba1,3); A:= LRot32(A + (B xor C xor D) + Data[ 2] + $6ed9eba1,3);
D:= LRot32(D + (A xor B xor C) + Data[10] + $6ed9eba1,9); D:= LRot32(D + (A xor B xor C) + Data[10] + $6ed9eba1,9);
C:= LRot32(C + (D xor A xor B) + Data[ 6] + $6ed9eba1,11); C:= LRot32(C + (D xor A xor B) + Data[ 6] + $6ed9eba1,11);
B:= LRot32(B + (C xor D xor A) + Data[14] + $6ed9eba1,15); B:= LRot32(B + (C xor D xor A) + Data[14] + $6ed9eba1,15);
A:= LRot32(A + (B xor C xor D) + Data[ 1] + $6ed9eba1,3); A:= LRot32(A + (B xor C xor D) + Data[ 1] + $6ed9eba1,3);
D:= LRot32(D + (A xor B xor C) + Data[ 9] + $6ed9eba1,9); D:= LRot32(D + (A xor B xor C) + Data[ 9] + $6ed9eba1,9);
C:= LRot32(C + (D xor A xor B) + Data[ 5] + $6ed9eba1,11); C:= LRot32(C + (D xor A xor B) + Data[ 5] + $6ed9eba1,11);
B:= LRot32(B + (C xor D xor A) + Data[13] + $6ed9eba1,15); B:= LRot32(B + (C xor D xor A) + Data[13] + $6ed9eba1,15);
A:= LRot32(A + (B xor C xor D) + Data[ 3] + $6ed9eba1,3); A:= LRot32(A + (B xor C xor D) + Data[ 3] + $6ed9eba1,3);
D:= LRot32(D + (A xor B xor C) + Data[11] + $6ed9eba1,9); D:= LRot32(D + (A xor B xor C) + Data[11] + $6ed9eba1,9);
C:= LRot32(C + (D xor A xor B) + Data[ 7] + $6ed9eba1,11); C:= LRot32(C + (D xor A xor B) + Data[ 7] + $6ed9eba1,11);
B:= LRot32(B + (C xor D xor A) + Data[15] + $6ed9eba1,15); B:= LRot32(B + (C xor D xor A) + Data[15] + $6ed9eba1,15);
Inc(CurrentHash[0],A); Inc(CurrentHash[0],A);
Inc(CurrentHash[1],B); Inc(CurrentHash[1],B);
Inc(CurrentHash[2],C); Inc(CurrentHash[2],C);
Inc(CurrentHash[3],D); Inc(CurrentHash[3],D);
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_md4.GetHashSize: integer; class function TDCP_md4.GetHashSize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_md4.GetId: integer; class function TDCP_md4.GetId: integer;
begin begin
Result:= DCP_md4; Result:= DCP_md4;
end; end;
class function TDCP_md4.GetAlgorithm: string; class function TDCP_md4.GetAlgorithm: string;
begin begin
Result:= 'MD4'; Result:= 'MD4';
end; end;
class function TDCP_md4.SelfTest: boolean; class function TDCP_md4.SelfTest: boolean;
const const
Test1Out: array[0..15] of byte= Test1Out: array[0..15] of byte=
($a4,$48,$01,$7a,$af,$21,$d8,$52,$5f,$c1,$0a,$e8,$7a,$a6,$72,$9d); ($a4,$48,$01,$7a,$af,$21,$d8,$52,$5f,$c1,$0a,$e8,$7a,$a6,$72,$9d);
Test2Out: array[0..15] of byte= Test2Out: array[0..15] of byte=
($d7,$9e,$1c,$30,$8a,$a5,$bb,$cd,$ee,$a8,$ed,$63,$df,$41,$2d,$a9); ($d7,$9e,$1c,$30,$8a,$a5,$bb,$cd,$ee,$a8,$ed,$63,$df,$41,$2d,$a9);
var var
TestHash: TDCP_md4; TestHash: TDCP_md4;
TestOut: array[0..19] of byte; TestOut: array[0..19] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_md4.Create(nil); TestHash:= TDCP_md4.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)); Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz'); TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result; Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_md4.Init; procedure TDCP_md4.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $67452301; CurrentHash[0]:= $67452301;
CurrentHash[1]:= $efcdab89; CurrentHash[1]:= $efcdab89;
CurrentHash[2]:= $98badcfe; CurrentHash[2]:= $98badcfe;
CurrentHash[3]:= $10325476; CurrentHash[3]:= $10325476;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_md4.Burn; procedure TDCP_md4.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_md4.Update(const Buffer; Size: longword); procedure TDCP_md4.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29); Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_md4.Final(var Digest); procedure TDCP_md4.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
PDWord(@HashBuffer[56])^:= LenLo; PDWord(@HashBuffer[56])^:= LenLo;
PDWord(@HashBuffer[60])^:= LenHi; PDWord(@HashBuffer[60])^:= LenHi;
Compress; Compress;
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,254 +1,254 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of MD5 **********************************} {* A binary compatible implementation of MD5 **********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPmd5; unit DCPmd5;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_md5= class(TDCP_hash) TDCP_md5= class(TDCP_hash)
protected protected
LenHi, LenLo: longword; LenHi, LenLo: longword;
Index: DWord; Index: DWord;
CurrentHash: array[0..3] of DWord; CurrentHash: array[0..3] of DWord;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
function LRot32(a, b: longword): longword; function LRot32(a, b: longword): longword;
begin begin
Result:= (a shl b) or (a shr (32-b)); Result:= (a shl b) or (a shr (32-b));
end; end;
procedure TDCP_md5.Compress; procedure TDCP_md5.Compress;
var var
Data: array[0..15] of dword; Data: array[0..15] of dword;
A, B, C, D: dword; A, B, C, D: dword;
begin begin
dcpFillChar(Data, SizeOf(Data), 0); dcpFillChar(Data, SizeOf(Data), 0);
Move(HashBuffer,Data,Sizeof(Data)); Move(HashBuffer,Data,Sizeof(Data));
A:= CurrentHash[0]; A:= CurrentHash[0];
B:= CurrentHash[1]; B:= CurrentHash[1];
C:= CurrentHash[2]; C:= CurrentHash[2];
D:= CurrentHash[3]; D:= CurrentHash[3];
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 0] + $d76aa478,7); A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 0] + $d76aa478,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 1] + $e8c7b756,12); D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 1] + $e8c7b756,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 2] + $242070db,17); C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 2] + $242070db,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 3] + $c1bdceee,22); B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 3] + $c1bdceee,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 4] + $f57c0faf,7); A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 4] + $f57c0faf,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 5] + $4787c62a,12); D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 5] + $4787c62a,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 6] + $a8304613,17); C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 6] + $a8304613,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 7] + $fd469501,22); B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 7] + $fd469501,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 8] + $698098d8,7); A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 8] + $698098d8,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 9] + $8b44f7af,12); D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 9] + $8b44f7af,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[10] + $ffff5bb1,17); C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[10] + $ffff5bb1,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[11] + $895cd7be,22); B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[11] + $895cd7be,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[12] + $6b901122,7); A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[12] + $6b901122,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[13] + $fd987193,12); D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[13] + $fd987193,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[14] + $a679438e,17); C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[14] + $a679438e,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[15] + $49b40821,22); B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[15] + $49b40821,22);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 1] + $f61e2562,5); A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 1] + $f61e2562,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 6] + $c040b340,9); D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 6] + $c040b340,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[11] + $265e5a51,14); C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[11] + $265e5a51,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 0] + $e9b6c7aa,20); B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 0] + $e9b6c7aa,20);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 5] + $d62f105d,5); A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 5] + $d62f105d,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[10] + $02441453,9); D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[10] + $02441453,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[15] + $d8a1e681,14); C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[15] + $d8a1e681,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 4] + $e7d3fbc8,20); B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 4] + $e7d3fbc8,20);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 9] + $21e1cde6,5); A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 9] + $21e1cde6,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[14] + $c33707d6,9); D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[14] + $c33707d6,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 3] + $f4d50d87,14); C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 3] + $f4d50d87,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 8] + $455a14ed,20); B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 8] + $455a14ed,20);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[13] + $a9e3e905,5); A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[13] + $a9e3e905,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 2] + $fcefa3f8,9); D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 2] + $fcefa3f8,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 7] + $676f02d9,14); C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 7] + $676f02d9,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[12] + $8d2a4c8a,20); B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[12] + $8d2a4c8a,20);
A:= B + LRot32(A + (B xor C xor D) + Data[ 5] + $fffa3942,4); A:= B + LRot32(A + (B xor C xor D) + Data[ 5] + $fffa3942,4);
D:= A + LRot32(D + (A xor B xor C) + Data[ 8] + $8771f681,11); D:= A + LRot32(D + (A xor B xor C) + Data[ 8] + $8771f681,11);
C:= D + LRot32(C + (D xor A xor B) + Data[11] + $6d9d6122,16); C:= D + LRot32(C + (D xor A xor B) + Data[11] + $6d9d6122,16);
B:= C + LRot32(B + (C xor D xor A) + Data[14] + $fde5380c,23); B:= C + LRot32(B + (C xor D xor A) + Data[14] + $fde5380c,23);
A:= B + LRot32(A + (B xor C xor D) + Data[ 1] + $a4beea44,4); A:= B + LRot32(A + (B xor C xor D) + Data[ 1] + $a4beea44,4);
D:= A + LRot32(D + (A xor B xor C) + Data[ 4] + $4bdecfa9,11); D:= A + LRot32(D + (A xor B xor C) + Data[ 4] + $4bdecfa9,11);
C:= D + LRot32(C + (D xor A xor B) + Data[ 7] + $f6bb4b60,16); C:= D + LRot32(C + (D xor A xor B) + Data[ 7] + $f6bb4b60,16);
B:= C + LRot32(B + (C xor D xor A) + Data[10] + $bebfbc70,23); B:= C + LRot32(B + (C xor D xor A) + Data[10] + $bebfbc70,23);
A:= B + LRot32(A + (B xor C xor D) + Data[13] + $289b7ec6,4); A:= B + LRot32(A + (B xor C xor D) + Data[13] + $289b7ec6,4);
D:= A + LRot32(D + (A xor B xor C) + Data[ 0] + $eaa127fa,11); D:= A + LRot32(D + (A xor B xor C) + Data[ 0] + $eaa127fa,11);
C:= D + LRot32(C + (D xor A xor B) + Data[ 3] + $d4ef3085,16); C:= D + LRot32(C + (D xor A xor B) + Data[ 3] + $d4ef3085,16);
B:= C + LRot32(B + (C xor D xor A) + Data[ 6] + $04881d05,23); B:= C + LRot32(B + (C xor D xor A) + Data[ 6] + $04881d05,23);
A:= B + LRot32(A + (B xor C xor D) + Data[ 9] + $d9d4d039,4); A:= B + LRot32(A + (B xor C xor D) + Data[ 9] + $d9d4d039,4);
D:= A + LRot32(D + (A xor B xor C) + Data[12] + $e6db99e5,11); D:= A + LRot32(D + (A xor B xor C) + Data[12] + $e6db99e5,11);
C:= D + LRot32(C + (D xor A xor B) + Data[15] + $1fa27cf8,16); C:= D + LRot32(C + (D xor A xor B) + Data[15] + $1fa27cf8,16);
B:= C + LRot32(B + (C xor D xor A) + Data[ 2] + $c4ac5665,23); B:= C + LRot32(B + (C xor D xor A) + Data[ 2] + $c4ac5665,23);
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 0] + $f4292244,6); A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 0] + $f4292244,6);
D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 7] + $432aff97,10); D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 7] + $432aff97,10);
C:= D + LRot32(C + (A xor (D or (not B))) + Data[14] + $ab9423a7,15); C:= D + LRot32(C + (A xor (D or (not B))) + Data[14] + $ab9423a7,15);
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 5] + $fc93a039,21); B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 5] + $fc93a039,21);
A:= B + LRot32(A + (C xor (B or (not D))) + Data[12] + $655b59c3,6); A:= B + LRot32(A + (C xor (B or (not D))) + Data[12] + $655b59c3,6);
D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 3] + $8f0ccc92,10); D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 3] + $8f0ccc92,10);
C:= D + LRot32(C + (A xor (D or (not B))) + Data[10] + $ffeff47d,15); C:= D + LRot32(C + (A xor (D or (not B))) + Data[10] + $ffeff47d,15);
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 1] + $85845dd1,21); B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 1] + $85845dd1,21);
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 8] + $6fa87e4f,6); A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 8] + $6fa87e4f,6);
D:= A + LRot32(D + (B xor (A or (not C))) + Data[15] + $fe2ce6e0,10); D:= A + LRot32(D + (B xor (A or (not C))) + Data[15] + $fe2ce6e0,10);
C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 6] + $a3014314,15); C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 6] + $a3014314,15);
B:= C + LRot32(B + (D xor (C or (not A))) + Data[13] + $4e0811a1,21); B:= C + LRot32(B + (D xor (C or (not A))) + Data[13] + $4e0811a1,21);
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 4] + $f7537e82,6); A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 4] + $f7537e82,6);
D:= A + LRot32(D + (B xor (A or (not C))) + Data[11] + $bd3af235,10); D:= A + LRot32(D + (B xor (A or (not C))) + Data[11] + $bd3af235,10);
C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 2] + $2ad7d2bb,15); C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 2] + $2ad7d2bb,15);
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 9] + $eb86d391,21); B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 9] + $eb86d391,21);
Inc(CurrentHash[0],A); Inc(CurrentHash[0],A);
Inc(CurrentHash[1],B); Inc(CurrentHash[1],B);
Inc(CurrentHash[2],C); Inc(CurrentHash[2],C);
Inc(CurrentHash[3],D); Inc(CurrentHash[3],D);
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_md5.GetHashSize: integer; class function TDCP_md5.GetHashSize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_md5.GetId: integer; class function TDCP_md5.GetId: integer;
begin begin
Result:= DCP_md5; Result:= DCP_md5;
end; end;
class function TDCP_md5.GetAlgorithm: string; class function TDCP_md5.GetAlgorithm: string;
begin begin
Result:= 'MD5'; Result:= 'MD5';
end; end;
class function TDCP_md5.SelfTest: boolean; class function TDCP_md5.SelfTest: boolean;
const const
Test1Out: array[0..15] of byte= Test1Out: array[0..15] of byte=
($90,$01,$50,$98,$3c,$d2,$4f,$b0,$d6,$96,$3f,$7d,$28,$e1,$7f,$72); ($90,$01,$50,$98,$3c,$d2,$4f,$b0,$d6,$96,$3f,$7d,$28,$e1,$7f,$72);
Test2Out: array[0..15] of byte= Test2Out: array[0..15] of byte=
($c3,$fc,$d3,$d7,$61,$92,$e4,$00,$7d,$fb,$49,$6c,$ca,$67,$e1,$3b); ($c3,$fc,$d3,$d7,$61,$92,$e4,$00,$7d,$fb,$49,$6c,$ca,$67,$e1,$3b);
var var
TestHash: TDCP_md5; TestHash: TDCP_md5;
TestOut: array[0..19] of byte; TestOut: array[0..19] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_md5.Create(nil); TestHash:= TDCP_md5.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)); Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz'); TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result; Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_md5.Init; procedure TDCP_md5.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $67452301; CurrentHash[0]:= $67452301;
CurrentHash[1]:= $efcdab89; CurrentHash[1]:= $efcdab89;
CurrentHash[2]:= $98badcfe; CurrentHash[2]:= $98badcfe;
CurrentHash[3]:= $10325476; CurrentHash[3]:= $10325476;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_md5.Burn; procedure TDCP_md5.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_md5.Update(const Buffer; Size: longword); procedure TDCP_md5.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29); Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_md5.Final(var Digest); procedure TDCP_md5.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
PDWord(@HashBuffer[56])^:= LenLo; PDWord(@HashBuffer[56])^:= LenLo;
PDWord(@HashBuffer[60])^:= LenHi; PDWord(@HashBuffer[60])^:= LenHi;
Compress; Compress;
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,321 +1,321 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of RipeMD-128 ***************************} {* A binary compatible implementation of RipeMD-128 ***************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 2002 David Barton *} {* Copyright (c) 2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPripemd128; unit DCPripemd128;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_ripemd128= class(TDCP_hash) TDCP_ripemd128= class(TDCP_hash)
protected protected
LenHi, LenLo: longword; LenHi, LenLo: longword;
Index: DWord; Index: DWord;
CurrentHash: array[0..3] of DWord; CurrentHash: array[0..3] of DWord;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
procedure TDCP_ripemd128.Compress; procedure TDCP_ripemd128.Compress;
var var
X: array[0..15] of DWord; X: array[0..15] of DWord;
a, aa, b, bb, c, cc, d, dd, t: dword; a, aa, b, bb, c, cc, d, dd, t: dword;
begin begin
dcpFillChar(X, SizeOf(X), 0); dcpFillChar(X, SizeOf(X), 0);
Move(HashBuffer,X,Sizeof(X)); Move(HashBuffer,X,Sizeof(X));
a:= CurrentHash[0]; aa:= a; a:= CurrentHash[0]; aa:= a;
b:= CurrentHash[1]; bb:= b; b:= CurrentHash[1]; bb:= b;
c:= CurrentHash[2]; cc:= c; c:= CurrentHash[2]; cc:= c;
d:= CurrentHash[3]; dd:= d; d:= CurrentHash[3]; dd:= d;
t:= a + (b xor c xor d) + X[ 0]; a:= (t shl 11) or (t shr (32-11)); t:= a + (b xor c xor d) + X[ 0]; a:= (t shl 11) or (t shr (32-11));
t:= d + (a xor b xor c) + X[ 1]; d:= (t shl 14) or (t shr (32-14)); t:= d + (a xor b xor c) + X[ 1]; d:= (t shl 14) or (t shr (32-14));
t:= c + (d xor a xor b) + X[ 2]; c:= (t shl 15) or (t shr (32-15)); t:= c + (d xor a xor b) + X[ 2]; c:= (t shl 15) or (t shr (32-15));
t:= b + (c xor d xor a) + X[ 3]; b:= (t shl 12) or (t shr (32-12)); t:= b + (c xor d xor a) + X[ 3]; b:= (t shl 12) or (t shr (32-12));
t:= a + (b xor c xor d) + X[ 4]; a:= (t shl 5) or (t shr (32-5)); t:= a + (b xor c xor d) + X[ 4]; a:= (t shl 5) or (t shr (32-5));
t:= d + (a xor b xor c) + X[ 5]; d:= (t shl 8) or (t shr (32-8)); t:= d + (a xor b xor c) + X[ 5]; d:= (t shl 8) or (t shr (32-8));
t:= c + (d xor a xor b) + X[ 6]; c:= (t shl 7) or (t shr (32-7)); t:= c + (d xor a xor b) + X[ 6]; c:= (t shl 7) or (t shr (32-7));
t:= b + (c xor d xor a) + X[ 7]; b:= (t shl 9) or (t shr (32-9)); t:= b + (c xor d xor a) + X[ 7]; b:= (t shl 9) or (t shr (32-9));
t:= a + (b xor c xor d) + X[ 8]; a:= (t shl 11) or (t shr (32-11)); t:= a + (b xor c xor d) + X[ 8]; a:= (t shl 11) or (t shr (32-11));
t:= d + (a xor b xor c) + X[ 9]; d:= (t shl 13) or (t shr (32-13)); t:= d + (a xor b xor c) + X[ 9]; d:= (t shl 13) or (t shr (32-13));
t:= c + (d xor a xor b) + X[10]; c:= (t shl 14) or (t shr (32-14)); t:= c + (d xor a xor b) + X[10]; c:= (t shl 14) or (t shr (32-14));
t:= b + (c xor d xor a) + X[11]; b:= (t shl 15) or (t shr (32-15)); t:= b + (c xor d xor a) + X[11]; b:= (t shl 15) or (t shr (32-15));
t:= a + (b xor c xor d) + X[12]; a:= (t shl 6) or (t shr (32-6)); t:= a + (b xor c xor d) + X[12]; a:= (t shl 6) or (t shr (32-6));
t:= d + (a xor b xor c) + X[13]; d:= (t shl 7) or (t shr (32-7)); t:= d + (a xor b xor c) + X[13]; d:= (t shl 7) or (t shr (32-7));
t:= c + (d xor a xor b) + X[14]; c:= (t shl 9) or (t shr (32-9)); t:= c + (d xor a xor b) + X[14]; c:= (t shl 9) or (t shr (32-9));
t:= b + (c xor d xor a) + X[15]; b:= (t shl 8) or (t shr (32-8)); t:= b + (c xor d xor a) + X[15]; b:= (t shl 8) or (t shr (32-8));
t:= a + ((b and c) or (not b and d)) + X[ 7]+$5A827999; a:= (t shl 7) or (t shr (32-7)); t:= a + ((b and c) or (not b and d)) + X[ 7]+$5A827999; a:= (t shl 7) or (t shr (32-7));
t:= d + ((a and b) or (not a and c)) + X[ 4]+$5A827999; d:= (t shl 6) or (t shr (32-6)); t:= d + ((a and b) or (not a and c)) + X[ 4]+$5A827999; d:= (t shl 6) or (t shr (32-6));
t:= c + ((d and a) or (not d and b)) + X[13]+$5A827999; c:= (t shl 8) or (t shr (32-8)); t:= c + ((d and a) or (not d and b)) + X[13]+$5A827999; c:= (t shl 8) or (t shr (32-8));
t:= b + ((c and d) or (not c and a)) + X[ 1]+$5A827999; b:= (t shl 13) or (t shr (32-13)); t:= b + ((c and d) or (not c and a)) + X[ 1]+$5A827999; b:= (t shl 13) or (t shr (32-13));
t:= a + ((b and c) or (not b and d)) + X[10]+$5A827999; a:= (t shl 11) or (t shr (32-11)); t:= a + ((b and c) or (not b and d)) + X[10]+$5A827999; a:= (t shl 11) or (t shr (32-11));
t:= d + ((a and b) or (not a and c)) + X[ 6]+$5A827999; d:= (t shl 9) or (t shr (32-9)); t:= d + ((a and b) or (not a and c)) + X[ 6]+$5A827999; d:= (t shl 9) or (t shr (32-9));
t:= c + ((d and a) or (not d and b)) + X[15]+$5A827999; c:= (t shl 7) or (t shr (32-7)); t:= c + ((d and a) or (not d and b)) + X[15]+$5A827999; c:= (t shl 7) or (t shr (32-7));
t:= b + ((c and d) or (not c and a)) + X[ 3]+$5A827999; b:= (t shl 15) or (t shr (32-15)); t:= b + ((c and d) or (not c and a)) + X[ 3]+$5A827999; b:= (t shl 15) or (t shr (32-15));
t:= a + ((b and c) or (not b and d)) + X[12]+$5A827999; a:= (t shl 7) or (t shr (32-7)); t:= a + ((b and c) or (not b and d)) + X[12]+$5A827999; a:= (t shl 7) or (t shr (32-7));
t:= d + ((a and b) or (not a and c)) + X[ 0]+$5A827999; d:= (t shl 12) or (t shr (32-12)); t:= d + ((a and b) or (not a and c)) + X[ 0]+$5A827999; d:= (t shl 12) or (t shr (32-12));
t:= c + ((d and a) or (not d and b)) + X[ 9]+$5A827999; c:= (t shl 15) or (t shr (32-15)); t:= c + ((d and a) or (not d and b)) + X[ 9]+$5A827999; c:= (t shl 15) or (t shr (32-15));
t:= b + ((c and d) or (not c and a)) + X[ 5]+$5A827999; b:= (t shl 9) or (t shr (32-9)); t:= b + ((c and d) or (not c and a)) + X[ 5]+$5A827999; b:= (t shl 9) or (t shr (32-9));
t:= a + ((b and c) or (not b and d)) + X[ 2]+$5A827999; a:= (t shl 11) or (t shr (32-11)); t:= a + ((b and c) or (not b and d)) + X[ 2]+$5A827999; a:= (t shl 11) or (t shr (32-11));
t:= d + ((a and b) or (not a and c)) + X[14]+$5A827999; d:= (t shl 7) or (t shr (32-7)); t:= d + ((a and b) or (not a and c)) + X[14]+$5A827999; d:= (t shl 7) or (t shr (32-7));
t:= c + ((d and a) or (not d and b)) + X[11]+$5A827999; c:= (t shl 13) or (t shr (32-13)); t:= c + ((d and a) or (not d and b)) + X[11]+$5A827999; c:= (t shl 13) or (t shr (32-13));
t:= b + ((c and d) or (not c and a)) + X[ 8]+$5A827999; b:= (t shl 12) or (t shr (32-12)); t:= b + ((c and d) or (not c and a)) + X[ 8]+$5A827999; b:= (t shl 12) or (t shr (32-12));
t:= a + ((b or not c) xor d) + X[ 3]+$6ED9EBA1; a:= (t shl 11) or (t shr (32-11)); t:= a + ((b or not c) xor d) + X[ 3]+$6ED9EBA1; a:= (t shl 11) or (t shr (32-11));
t:= d + ((a or not b) xor c) + X[10]+$6ED9EBA1; d:= (t shl 13) or (t shr (32-13)); t:= d + ((a or not b) xor c) + X[10]+$6ED9EBA1; d:= (t shl 13) or (t shr (32-13));
t:= c + ((d or not a) xor b) + X[14]+$6ED9EBA1; c:= (t shl 6) or (t shr (32-6)); t:= c + ((d or not a) xor b) + X[14]+$6ED9EBA1; c:= (t shl 6) or (t shr (32-6));
t:= b + ((c or not d) xor a) + X[ 4]+$6ED9EBA1; b:= (t shl 7) or (t shr (32-7)); t:= b + ((c or not d) xor a) + X[ 4]+$6ED9EBA1; b:= (t shl 7) or (t shr (32-7));
t:= a + ((b or not c) xor d) + X[ 9]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14)); t:= a + ((b or not c) xor d) + X[ 9]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14));
t:= d + ((a or not b) xor c) + X[15]+$6ED9EBA1; d:= (t shl 9) or (t shr (32-9)); t:= d + ((a or not b) xor c) + X[15]+$6ED9EBA1; d:= (t shl 9) or (t shr (32-9));
t:= c + ((d or not a) xor b) + X[ 8]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13)); t:= c + ((d or not a) xor b) + X[ 8]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13));
t:= b + ((c or not d) xor a) + X[ 1]+$6ED9EBA1; b:= (t shl 15) or (t shr (32-15)); t:= b + ((c or not d) xor a) + X[ 1]+$6ED9EBA1; b:= (t shl 15) or (t shr (32-15));
t:= a + ((b or not c) xor d) + X[ 2]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14)); t:= a + ((b or not c) xor d) + X[ 2]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14));
t:= d + ((a or not b) xor c) + X[ 7]+$6ED9EBA1; d:= (t shl 8) or (t shr (32-8)); t:= d + ((a or not b) xor c) + X[ 7]+$6ED9EBA1; d:= (t shl 8) or (t shr (32-8));
t:= c + ((d or not a) xor b) + X[ 0]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13)); t:= c + ((d or not a) xor b) + X[ 0]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13));
t:= b + ((c or not d) xor a) + X[ 6]+$6ED9EBA1; b:= (t shl 6) or (t shr (32-6)); t:= b + ((c or not d) xor a) + X[ 6]+$6ED9EBA1; b:= (t shl 6) or (t shr (32-6));
t:= a + ((b or not c) xor d) + X[13]+$6ED9EBA1; a:= (t shl 5) or (t shr (32-5)); t:= a + ((b or not c) xor d) + X[13]+$6ED9EBA1; a:= (t shl 5) or (t shr (32-5));
t:= d + ((a or not b) xor c) + X[11]+$6ED9EBA1; d:= (t shl 12) or (t shr (32-12)); t:= d + ((a or not b) xor c) + X[11]+$6ED9EBA1; d:= (t shl 12) or (t shr (32-12));
t:= c + ((d or not a) xor b) + X[ 5]+$6ED9EBA1; c:= (t shl 7) or (t shr (32-7)); t:= c + ((d or not a) xor b) + X[ 5]+$6ED9EBA1; c:= (t shl 7) or (t shr (32-7));
t:= b + ((c or not d) xor a) + X[12]+$6ED9EBA1; b:= (t shl 5) or (t shr (32-5)); t:= b + ((c or not d) xor a) + X[12]+$6ED9EBA1; b:= (t shl 5) or (t shr (32-5));
t:= a + ((b and d) or (c and not d)) + X[ 1]+$8F1BBCDC; a:= (t shl 11) or (t shr (32-11)); t:= a + ((b and d) or (c and not d)) + X[ 1]+$8F1BBCDC; a:= (t shl 11) or (t shr (32-11));
t:= d + ((a and c) or (b and not c)) + X[ 9]+$8F1BBCDC; d:= (t shl 12) or (t shr (32-12)); t:= d + ((a and c) or (b and not c)) + X[ 9]+$8F1BBCDC; d:= (t shl 12) or (t shr (32-12));
t:= c + ((d and b) or (a and not b)) + X[11]+$8F1BBCDC; c:= (t shl 14) or (t shr (32-14)); t:= c + ((d and b) or (a and not b)) + X[11]+$8F1BBCDC; c:= (t shl 14) or (t shr (32-14));
t:= b + ((c and a) or (d and not a)) + X[10]+$8F1BBCDC; b:= (t shl 15) or (t shr (32-15)); t:= b + ((c and a) or (d and not a)) + X[10]+$8F1BBCDC; b:= (t shl 15) or (t shr (32-15));
t:= a + ((b and d) or (c and not d)) + X[ 0]+$8F1BBCDC; a:= (t shl 14) or (t shr (32-14)); t:= a + ((b and d) or (c and not d)) + X[ 0]+$8F1BBCDC; a:= (t shl 14) or (t shr (32-14));
t:= d + ((a and c) or (b and not c)) + X[ 8]+$8F1BBCDC; d:= (t shl 15) or (t shr (32-15)); t:= d + ((a and c) or (b and not c)) + X[ 8]+$8F1BBCDC; d:= (t shl 15) or (t shr (32-15));
t:= c + ((d and b) or (a and not b)) + X[12]+$8F1BBCDC; c:= (t shl 9) or (t shr (32-9)); t:= c + ((d and b) or (a and not b)) + X[12]+$8F1BBCDC; c:= (t shl 9) or (t shr (32-9));
t:= b + ((c and a) or (d and not a)) + X[ 4]+$8F1BBCDC; b:= (t shl 8) or (t shr (32-8)); t:= b + ((c and a) or (d and not a)) + X[ 4]+$8F1BBCDC; b:= (t shl 8) or (t shr (32-8));
t:= a + ((b and d) or (c and not d)) + X[13]+$8F1BBCDC; a:= (t shl 9) or (t shr (32-9)); t:= a + ((b and d) or (c and not d)) + X[13]+$8F1BBCDC; a:= (t shl 9) or (t shr (32-9));
t:= d + ((a and c) or (b and not c)) + X[ 3]+$8F1BBCDC; d:= (t shl 14) or (t shr (32-14)); t:= d + ((a and c) or (b and not c)) + X[ 3]+$8F1BBCDC; d:= (t shl 14) or (t shr (32-14));
t:= c + ((d and b) or (a and not b)) + X[ 7]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5)); t:= c + ((d and b) or (a and not b)) + X[ 7]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5));
t:= b + ((c and a) or (d and not a)) + X[15]+$8F1BBCDC; b:= (t shl 6) or (t shr (32-6)); t:= b + ((c and a) or (d and not a)) + X[15]+$8F1BBCDC; b:= (t shl 6) or (t shr (32-6));
t:= a + ((b and d) or (c and not d)) + X[14]+$8F1BBCDC; a:= (t shl 8) or (t shr (32-8)); t:= a + ((b and d) or (c and not d)) + X[14]+$8F1BBCDC; a:= (t shl 8) or (t shr (32-8));
t:= d + ((a and c) or (b and not c)) + X[ 5]+$8F1BBCDC; d:= (t shl 6) or (t shr (32-6)); t:= d + ((a and c) or (b and not c)) + X[ 5]+$8F1BBCDC; d:= (t shl 6) or (t shr (32-6));
t:= c + ((d and b) or (a and not b)) + X[ 6]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5)); t:= c + ((d and b) or (a and not b)) + X[ 6]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5));
t:= b + ((c and a) or (d and not a)) + X[ 2]+$8F1BBCDC; b:= (t shl 12) or (t shr (32-12)); t:= b + ((c and a) or (d and not a)) + X[ 2]+$8F1BBCDC; b:= (t shl 12) or (t shr (32-12));
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 5]+$50A28BE6; aa:= (t shl 8) or (t shr (32-8)); t:= aa + ((bb and dd) or (cc and not dd)) + X[ 5]+$50A28BE6; aa:= (t shl 8) or (t shr (32-8));
t:= dd + ((aa and cc) or (bb and not cc)) + X[14]+$50A28BE6; dd:= (t shl 9) or (t shr (32-9)); t:= dd + ((aa and cc) or (bb and not cc)) + X[14]+$50A28BE6; dd:= (t shl 9) or (t shr (32-9));
t:= cc + ((dd and bb) or (aa and not bb)) + X[ 7]+$50A28BE6; cc:= (t shl 9) or (t shr (32-9)); t:= cc + ((dd and bb) or (aa and not bb)) + X[ 7]+$50A28BE6; cc:= (t shl 9) or (t shr (32-9));
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 0]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11)); t:= bb + ((cc and aa) or (dd and not aa)) + X[ 0]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11));
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 9]+$50A28BE6; aa:= (t shl 13) or (t shr (32-13)); t:= aa + ((bb and dd) or (cc and not dd)) + X[ 9]+$50A28BE6; aa:= (t shl 13) or (t shr (32-13));
t:= dd + ((aa and cc) or (bb and not cc)) + X[ 2]+$50A28BE6; dd:= (t shl 15) or (t shr (32-15)); t:= dd + ((aa and cc) or (bb and not cc)) + X[ 2]+$50A28BE6; dd:= (t shl 15) or (t shr (32-15));
t:= cc + ((dd and bb) or (aa and not bb)) + X[11]+$50A28BE6; cc:= (t shl 15) or (t shr (32-15)); t:= cc + ((dd and bb) or (aa and not bb)) + X[11]+$50A28BE6; cc:= (t shl 15) or (t shr (32-15));
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 4]+$50A28BE6; bb:= (t shl 5) or (t shr (32-5)); t:= bb + ((cc and aa) or (dd and not aa)) + X[ 4]+$50A28BE6; bb:= (t shl 5) or (t shr (32-5));
t:= aa + ((bb and dd) or (cc and not dd)) + X[13]+$50A28BE6; aa:= (t shl 7) or (t shr (32-7)); t:= aa + ((bb and dd) or (cc and not dd)) + X[13]+$50A28BE6; aa:= (t shl 7) or (t shr (32-7));
t:= dd + ((aa and cc) or (bb and not cc)) + X[ 6]+$50A28BE6; dd:= (t shl 7) or (t shr (32-7)); t:= dd + ((aa and cc) or (bb and not cc)) + X[ 6]+$50A28BE6; dd:= (t shl 7) or (t shr (32-7));
t:= cc + ((dd and bb) or (aa and not bb)) + X[15]+$50A28BE6; cc:= (t shl 8) or (t shr (32-8)); t:= cc + ((dd and bb) or (aa and not bb)) + X[15]+$50A28BE6; cc:= (t shl 8) or (t shr (32-8));
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 8]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11)); t:= bb + ((cc and aa) or (dd and not aa)) + X[ 8]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11));
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 1]+$50A28BE6; aa:= (t shl 14) or (t shr (32-14)); t:= aa + ((bb and dd) or (cc and not dd)) + X[ 1]+$50A28BE6; aa:= (t shl 14) or (t shr (32-14));
t:= dd + ((aa and cc) or (bb and not cc)) + X[10]+$50A28BE6; dd:= (t shl 14) or (t shr (32-14)); t:= dd + ((aa and cc) or (bb and not cc)) + X[10]+$50A28BE6; dd:= (t shl 14) or (t shr (32-14));
t:= cc + ((dd and bb) or (aa and not bb)) + X[ 3]+$50A28BE6; cc:= (t shl 12) or (t shr (32-12)); t:= cc + ((dd and bb) or (aa and not bb)) + X[ 3]+$50A28BE6; cc:= (t shl 12) or (t shr (32-12));
t:= bb + ((cc and aa) or (dd and not aa)) + X[12]+$50A28BE6; bb:= (t shl 6) or (t shr (32-6)); t:= bb + ((cc and aa) or (dd and not aa)) + X[12]+$50A28BE6; bb:= (t shl 6) or (t shr (32-6));
t:= aa + ((bb or not cc) xor dd) + X[ 6]+$5C4DD124; aa:= (t shl 9) or (t shr (32-9)); t:= aa + ((bb or not cc) xor dd) + X[ 6]+$5C4DD124; aa:= (t shl 9) or (t shr (32-9));
t:= dd + ((aa or not bb) xor cc) + X[11]+$5C4DD124; dd:= (t shl 13) or (t shr (32-13)); t:= dd + ((aa or not bb) xor cc) + X[11]+$5C4DD124; dd:= (t shl 13) or (t shr (32-13));
t:= cc + ((dd or not aa) xor bb) + X[ 3]+$5C4DD124; cc:= (t shl 15) or (t shr (32-15)); t:= cc + ((dd or not aa) xor bb) + X[ 3]+$5C4DD124; cc:= (t shl 15) or (t shr (32-15));
t:= bb + ((cc or not dd) xor aa) + X[ 7]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7)); t:= bb + ((cc or not dd) xor aa) + X[ 7]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7));
t:= aa + ((bb or not cc) xor dd) + X[ 0]+$5C4DD124; aa:= (t shl 12) or (t shr (32-12)); t:= aa + ((bb or not cc) xor dd) + X[ 0]+$5C4DD124; aa:= (t shl 12) or (t shr (32-12));
t:= dd + ((aa or not bb) xor cc) + X[13]+$5C4DD124; dd:= (t shl 8) or (t shr (32-8)); t:= dd + ((aa or not bb) xor cc) + X[13]+$5C4DD124; dd:= (t shl 8) or (t shr (32-8));
t:= cc + ((dd or not aa) xor bb) + X[ 5]+$5C4DD124; cc:= (t shl 9) or (t shr (32-9)); t:= cc + ((dd or not aa) xor bb) + X[ 5]+$5C4DD124; cc:= (t shl 9) or (t shr (32-9));
t:= bb + ((cc or not dd) xor aa) + X[10]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11)); t:= bb + ((cc or not dd) xor aa) + X[10]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11));
t:= aa + ((bb or not cc) xor dd) + X[14]+$5C4DD124; aa:= (t shl 7) or (t shr (32-7)); t:= aa + ((bb or not cc) xor dd) + X[14]+$5C4DD124; aa:= (t shl 7) or (t shr (32-7));
t:= dd + ((aa or not bb) xor cc) + X[15]+$5C4DD124; dd:= (t shl 7) or (t shr (32-7)); t:= dd + ((aa or not bb) xor cc) + X[15]+$5C4DD124; dd:= (t shl 7) or (t shr (32-7));
t:= cc + ((dd or not aa) xor bb) + X[ 8]+$5C4DD124; cc:= (t shl 12) or (t shr (32-12)); t:= cc + ((dd or not aa) xor bb) + X[ 8]+$5C4DD124; cc:= (t shl 12) or (t shr (32-12));
t:= bb + ((cc or not dd) xor aa) + X[12]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7)); t:= bb + ((cc or not dd) xor aa) + X[12]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7));
t:= aa + ((bb or not cc) xor dd) + X[ 4]+$5C4DD124; aa:= (t shl 6) or (t shr (32-6)); t:= aa + ((bb or not cc) xor dd) + X[ 4]+$5C4DD124; aa:= (t shl 6) or (t shr (32-6));
t:= dd + ((aa or not bb) xor cc) + X[ 9]+$5C4DD124; dd:= (t shl 15) or (t shr (32-15)); t:= dd + ((aa or not bb) xor cc) + X[ 9]+$5C4DD124; dd:= (t shl 15) or (t shr (32-15));
t:= cc + ((dd or not aa) xor bb) + X[ 1]+$5C4DD124; cc:= (t shl 13) or (t shr (32-13)); t:= cc + ((dd or not aa) xor bb) + X[ 1]+$5C4DD124; cc:= (t shl 13) or (t shr (32-13));
t:= bb + ((cc or not dd) xor aa) + X[ 2]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11)); t:= bb + ((cc or not dd) xor aa) + X[ 2]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11));
t:= aa + ((bb and cc) or (not bb and dd)) + X[15]+$6D703EF3; aa:= (t shl 9) or (t shr (32-9)); t:= aa + ((bb and cc) or (not bb and dd)) + X[15]+$6D703EF3; aa:= (t shl 9) or (t shr (32-9));
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 5]+$6D703EF3; dd:= (t shl 7) or (t shr (32-7)); t:= dd + ((aa and bb) or (not aa and cc)) + X[ 5]+$6D703EF3; dd:= (t shl 7) or (t shr (32-7));
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 1]+$6D703EF3; cc:= (t shl 15) or (t shr (32-15)); t:= cc + ((dd and aa) or (not dd and bb)) + X[ 1]+$6D703EF3; cc:= (t shl 15) or (t shr (32-15));
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 3]+$6D703EF3; bb:= (t shl 11) or (t shr (32-11)); t:= bb + ((cc and dd) or (not cc and aa)) + X[ 3]+$6D703EF3; bb:= (t shl 11) or (t shr (32-11));
t:= aa + ((bb and cc) or (not bb and dd)) + X[ 7]+$6D703EF3; aa:= (t shl 8) or (t shr (32-8)); t:= aa + ((bb and cc) or (not bb and dd)) + X[ 7]+$6D703EF3; aa:= (t shl 8) or (t shr (32-8));
t:= dd + ((aa and bb) or (not aa and cc)) + X[14]+$6D703EF3; dd:= (t shl 6) or (t shr (32-6)); t:= dd + ((aa and bb) or (not aa and cc)) + X[14]+$6D703EF3; dd:= (t shl 6) or (t shr (32-6));
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 6]+$6D703EF3; cc:= (t shl 6) or (t shr (32-6)); t:= cc + ((dd and aa) or (not dd and bb)) + X[ 6]+$6D703EF3; cc:= (t shl 6) or (t shr (32-6));
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 9]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14)); t:= bb + ((cc and dd) or (not cc and aa)) + X[ 9]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14));
t:= aa + ((bb and cc) or (not bb and dd)) + X[11]+$6D703EF3; aa:= (t shl 12) or (t shr (32-12)); t:= aa + ((bb and cc) or (not bb and dd)) + X[11]+$6D703EF3; aa:= (t shl 12) or (t shr (32-12));
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 8]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13)); t:= dd + ((aa and bb) or (not aa and cc)) + X[ 8]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13));
t:= cc + ((dd and aa) or (not dd and bb)) + X[12]+$6D703EF3; cc:= (t shl 5) or (t shr (32-5)); t:= cc + ((dd and aa) or (not dd and bb)) + X[12]+$6D703EF3; cc:= (t shl 5) or (t shr (32-5));
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 2]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14)); t:= bb + ((cc and dd) or (not cc and aa)) + X[ 2]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14));
t:= aa + ((bb and cc) or (not bb and dd)) + X[10]+$6D703EF3; aa:= (t shl 13) or (t shr (32-13)); t:= aa + ((bb and cc) or (not bb and dd)) + X[10]+$6D703EF3; aa:= (t shl 13) or (t shr (32-13));
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 0]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13)); t:= dd + ((aa and bb) or (not aa and cc)) + X[ 0]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13));
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 4]+$6D703EF3; cc:= (t shl 7) or (t shr (32-7)); t:= cc + ((dd and aa) or (not dd and bb)) + X[ 4]+$6D703EF3; cc:= (t shl 7) or (t shr (32-7));
t:= bb + ((cc and dd) or (not cc and aa)) + X[13]+$6D703EF3; bb:= (t shl 5) or (t shr (32-5)); t:= bb + ((cc and dd) or (not cc and aa)) + X[13]+$6D703EF3; bb:= (t shl 5) or (t shr (32-5));
t:= aa + (bb xor cc xor dd) + X[ 8]; aa:= (t shl 15) or (t shr (32-15)); t:= aa + (bb xor cc xor dd) + X[ 8]; aa:= (t shl 15) or (t shr (32-15));
t:= dd + (aa xor bb xor cc) + X[ 6]; dd:= (t shl 5) or (t shr (32-5)); t:= dd + (aa xor bb xor cc) + X[ 6]; dd:= (t shl 5) or (t shr (32-5));
t:= cc + (dd xor aa xor bb) + X[ 4]; cc:= (t shl 8) or (t shr (32-8)); t:= cc + (dd xor aa xor bb) + X[ 4]; cc:= (t shl 8) or (t shr (32-8));
t:= bb + (cc xor dd xor aa) + X[ 1]; bb:= (t shl 11) or (t shr (32-11)); t:= bb + (cc xor dd xor aa) + X[ 1]; bb:= (t shl 11) or (t shr (32-11));
t:= aa + (bb xor cc xor dd) + X[ 3]; aa:= (t shl 14) or (t shr (32-14)); t:= aa + (bb xor cc xor dd) + X[ 3]; aa:= (t shl 14) or (t shr (32-14));
t:= dd + (aa xor bb xor cc) + X[11]; dd:= (t shl 14) or (t shr (32-14)); t:= dd + (aa xor bb xor cc) + X[11]; dd:= (t shl 14) or (t shr (32-14));
t:= cc + (dd xor aa xor bb) + X[15]; cc:= (t shl 6) or (t shr (32-6)); t:= cc + (dd xor aa xor bb) + X[15]; cc:= (t shl 6) or (t shr (32-6));
t:= bb + (cc xor dd xor aa) + X[ 0]; bb:= (t shl 14) or (t shr (32-14)); t:= bb + (cc xor dd xor aa) + X[ 0]; bb:= (t shl 14) or (t shr (32-14));
t:= aa + (bb xor cc xor dd) + X[ 5]; aa:= (t shl 6) or (t shr (32-6)); t:= aa + (bb xor cc xor dd) + X[ 5]; aa:= (t shl 6) or (t shr (32-6));
t:= dd + (aa xor bb xor cc) + X[12]; dd:= (t shl 9) or (t shr (32-9)); t:= dd + (aa xor bb xor cc) + X[12]; dd:= (t shl 9) or (t shr (32-9));
t:= cc + (dd xor aa xor bb) + X[ 2]; cc:= (t shl 12) or (t shr (32-12)); t:= cc + (dd xor aa xor bb) + X[ 2]; cc:= (t shl 12) or (t shr (32-12));
t:= bb + (cc xor dd xor aa) + X[13]; bb:= (t shl 9) or (t shr (32-9)); t:= bb + (cc xor dd xor aa) + X[13]; bb:= (t shl 9) or (t shr (32-9));
t:= aa + (bb xor cc xor dd) + X[ 9]; aa:= (t shl 12) or (t shr (32-12)); t:= aa + (bb xor cc xor dd) + X[ 9]; aa:= (t shl 12) or (t shr (32-12));
t:= dd + (aa xor bb xor cc) + X[ 7]; dd:= (t shl 5) or (t shr (32-5)); t:= dd + (aa xor bb xor cc) + X[ 7]; dd:= (t shl 5) or (t shr (32-5));
t:= cc + (dd xor aa xor bb) + X[10]; cc:= (t shl 15) or (t shr (32-15)); t:= cc + (dd xor aa xor bb) + X[10]; cc:= (t shl 15) or (t shr (32-15));
t:= bb + (cc xor dd xor aa) + X[14]; bb:= (t shl 8) or (t shr (32-8)); t:= bb + (cc xor dd xor aa) + X[14]; bb:= (t shl 8) or (t shr (32-8));
Inc(dd,c + CurrentHash[1]); Inc(dd,c + CurrentHash[1]);
CurrentHash[1]:= CurrentHash[2] + d + aa; CurrentHash[1]:= CurrentHash[2] + d + aa;
CurrentHash[2]:= CurrentHash[3] + a + bb; CurrentHash[2]:= CurrentHash[3] + a + bb;
CurrentHash[3]:= CurrentHash[0] + b + cc; CurrentHash[3]:= CurrentHash[0] + b + cc;
CurrentHash[0]:= dd; CurrentHash[0]:= dd;
FillChar(X,Sizeof(X),0); FillChar(X,Sizeof(X),0);
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_ripemd128.GetHashSize: integer; class function TDCP_ripemd128.GetHashSize: integer;
begin begin
Result:= 128; Result:= 128;
end; end;
class function TDCP_ripemd128.GetId: integer; class function TDCP_ripemd128.GetId: integer;
begin begin
Result:= DCP_ripemd128; Result:= DCP_ripemd128;
end; end;
class function TDCP_ripemd128.GetAlgorithm: string; class function TDCP_ripemd128.GetAlgorithm: string;
begin begin
Result:= 'RipeMD-128'; Result:= 'RipeMD-128';
end; end;
class function TDCP_ripemd128.SelfTest: boolean; class function TDCP_ripemd128.SelfTest: boolean;
const const
Test1Out: array[0..15] of byte= Test1Out: array[0..15] of byte=
($86,$be,$7a,$fa,$33,$9d,$0f,$c7,$cf,$c7,$85,$e7,$2f,$57,$8d,$33); ($86,$be,$7a,$fa,$33,$9d,$0f,$c7,$cf,$c7,$85,$e7,$2f,$57,$8d,$33);
Test2Out: array[0..15] of byte= Test2Out: array[0..15] of byte=
($fd,$2a,$a6,$07,$f7,$1d,$c8,$f5,$10,$71,$49,$22,$b3,$71,$83,$4e); ($fd,$2a,$a6,$07,$f7,$1d,$c8,$f5,$10,$71,$49,$22,$b3,$71,$83,$4e);
var var
TestHash: TDCP_ripemd128; TestHash: TDCP_ripemd128;
TestOut: array[0..15] of byte; TestOut: array[0..15] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_ripemd128.Create(nil); TestHash:= TDCP_ripemd128.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('a'); TestHash.UpdateStr('a');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)); Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz'); TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result; Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_ripemd128.Init; procedure TDCP_ripemd128.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $67452301; CurrentHash[0]:= $67452301;
CurrentHash[1]:= $efcdab89; CurrentHash[1]:= $efcdab89;
CurrentHash[2]:= $98badcfe; CurrentHash[2]:= $98badcfe;
CurrentHash[3]:= $10325476; CurrentHash[3]:= $10325476;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_ripemd128.Burn; procedure TDCP_ripemd128.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_ripemd128.Update(const Buffer; Size: longword); procedure TDCP_ripemd128.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29); Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_ripemd128.Final(var Digest); procedure TDCP_ripemd128.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
PDWord(@HashBuffer[56])^:= LenLo; PDWord(@HashBuffer[56])^:= LenLo;
PDWord(@HashBuffer[60])^:= LenHi; PDWord(@HashBuffer[60])^:= LenHi;
Compress; Compress;
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -1,278 +1,278 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of SHA1 *********************************} {* A binary compatible implementation of SHA1 *********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPsha1; unit DCPsha1;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_sha1= class(TDCP_hash) TDCP_sha1= class(TDCP_hash)
protected protected
LenHi, LenLo: longword; LenHi, LenLo: longword;
Index: DWord; Index: DWord;
CurrentHash: array[0..4] of DWord; CurrentHash: array[0..4] of DWord;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
function SwapDWord(a: dword): dword; function SwapDWord(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
procedure TDCP_sha1.Compress; procedure TDCP_sha1.Compress;
var var
A, B, C, D, E: DWord; A, B, C, D, E: DWord;
W: array[0..79] of DWord; W: array[0..79] of DWord;
i: longword; i: longword;
begin begin
Index:= 0; Index:= 0;
dcpFillChar(W, SizeOf(W), 0); dcpFillChar(W, SizeOf(W), 0);
Move(HashBuffer,W,Sizeof(HashBuffer)); Move(HashBuffer,W,Sizeof(HashBuffer));
for i:= 0 to 15 do for i:= 0 to 15 do
W[i]:= SwapDWord(W[i]); W[i]:= SwapDWord(W[i]);
for i:= 16 to 79 do for i:= 16 to 79 do
W[i]:= ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shl 1) or ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shr 31); W[i]:= ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shl 1) or ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shr 31);
A:= CurrentHash[0]; B:= CurrentHash[1]; C:= CurrentHash[2]; D:= CurrentHash[3]; E:= CurrentHash[4]; A:= CurrentHash[0]; B:= CurrentHash[1]; C:= CurrentHash[2]; D:= CurrentHash[3]; E:= CurrentHash[4];
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 0]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 0]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 1]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 1]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 2]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 2]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 3]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 3]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 4]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 4]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 5]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 5]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 6]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 6]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 7]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 7]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 8]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 8]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 9]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 9]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[10]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[10]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[11]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[11]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[12]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[12]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[13]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[13]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[14]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[14]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[15]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[15]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[16]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[16]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[17]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[17]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[18]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[18]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[19]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[19]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[20]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[20]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[21]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[21]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[22]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[22]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[23]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[23]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[24]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[24]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[25]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[25]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[26]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[26]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[27]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[27]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[28]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[28]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[29]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[29]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[30]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[30]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[31]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[31]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[32]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[32]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[33]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[33]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[34]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[34]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[35]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[35]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[36]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[36]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[37]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[37]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[38]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[38]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[39]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[39]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[40]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[40]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[41]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[41]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[42]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[42]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[43]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[43]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[44]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[44]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[45]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[45]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[46]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[46]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[47]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[47]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[48]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[48]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[49]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[49]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[50]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[50]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[51]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[51]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[52]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[52]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[53]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[53]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[54]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[54]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[55]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[55]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[56]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[56]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[57]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[57]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[58]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[58]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[59]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[59]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[60]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[60]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[61]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[61]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[62]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[62]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[63]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[63]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[64]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[64]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[65]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[65]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[66]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[66]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[67]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[67]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[68]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[68]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[69]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[69]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[70]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[70]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[71]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[71]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[72]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[72]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[73]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[73]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[74]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[74]); C:= (C shl 30) or (C shr 2);
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[75]); B:= (B shl 30) or (B shr 2); Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[75]); B:= (B shl 30) or (B shr 2);
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[76]); A:= (A shl 30) or (A shr 2); Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[76]); A:= (A shl 30) or (A shr 2);
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[77]); E:= (E shl 30) or (E shr 2); Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[77]); E:= (E shl 30) or (E shr 2);
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[78]); D:= (D shl 30) or (D shr 2); Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[78]); D:= (D shl 30) or (D shr 2);
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[79]); C:= (C shl 30) or (C shr 2); Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[79]); C:= (C shl 30) or (C shr 2);
CurrentHash[0]:= CurrentHash[0] + A; CurrentHash[0]:= CurrentHash[0] + A;
CurrentHash[1]:= CurrentHash[1] + B; CurrentHash[1]:= CurrentHash[1] + B;
CurrentHash[2]:= CurrentHash[2] + C; CurrentHash[2]:= CurrentHash[2] + C;
CurrentHash[3]:= CurrentHash[3] + D; CurrentHash[3]:= CurrentHash[3] + D;
CurrentHash[4]:= CurrentHash[4] + E; CurrentHash[4]:= CurrentHash[4] + E;
FillChar(W,Sizeof(W),0); FillChar(W,Sizeof(W),0);
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_sha1.GetAlgorithm: string; class function TDCP_sha1.GetAlgorithm: string;
begin begin
Result:= 'SHA1'; Result:= 'SHA1';
end; end;
class function TDCP_sha1.GetId: integer; class function TDCP_sha1.GetId: integer;
begin begin
Result:= DCP_sha1; Result:= DCP_sha1;
end; end;
class function TDCP_sha1.GetHashSize: integer; class function TDCP_sha1.GetHashSize: integer;
begin begin
Result:= 160; Result:= 160;
end; end;
class function TDCP_sha1.SelfTest: boolean; class function TDCP_sha1.SelfTest: boolean;
const const
Test1Out: array[0..19] of byte= Test1Out: array[0..19] of byte=
($A9,$99,$3E,$36,$47,$06,$81,$6A,$BA,$3E,$25,$71,$78,$50,$C2,$6C,$9C,$D0,$D8,$9D); ($A9,$99,$3E,$36,$47,$06,$81,$6A,$BA,$3E,$25,$71,$78,$50,$C2,$6C,$9C,$D0,$D8,$9D);
Test2Out: array[0..19] of byte= Test2Out: array[0..19] of byte=
($84,$98,$3E,$44,$1C,$3B,$D2,$6E,$BA,$AE,$4A,$A1,$F9,$51,$29,$E5,$E5,$46,$70,$F1); ($84,$98,$3E,$44,$1C,$3B,$D2,$6E,$BA,$AE,$4A,$A1,$F9,$51,$29,$E5,$E5,$46,$70,$F1);
var var
TestHash: TDCP_sha1; TestHash: TDCP_sha1;
TestOut: array[0..19] of byte; TestOut: array[0..19] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_sha1.Create(nil); TestHash:= TDCP_sha1.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out))); Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'); TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result; Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_sha1.Init; procedure TDCP_sha1.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $67452301; CurrentHash[0]:= $67452301;
CurrentHash[1]:= $EFCDAB89; CurrentHash[1]:= $EFCDAB89;
CurrentHash[2]:= $98BADCFE; CurrentHash[2]:= $98BADCFE;
CurrentHash[3]:= $10325476; CurrentHash[3]:= $10325476;
CurrentHash[4]:= $C3D2E1F0; CurrentHash[4]:= $C3D2E1F0;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_sha1.Burn; procedure TDCP_sha1.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_sha1.Update(const Buffer; Size: longword); procedure TDCP_sha1.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29); Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_sha1.Final(var Digest); procedure TDCP_sha1.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
PDWord(@HashBuffer[56])^:= SwapDWord(LenHi); PDWord(@HashBuffer[56])^:= SwapDWord(LenHi);
PDWord(@HashBuffer[60])^:= SwapDWord(LenLo); PDWord(@HashBuffer[60])^:= SwapDWord(LenLo);
Compress; Compress;
CurrentHash[0]:= SwapDWord(CurrentHash[0]); CurrentHash[0]:= SwapDWord(CurrentHash[0]);
CurrentHash[1]:= SwapDWord(CurrentHash[1]); CurrentHash[1]:= SwapDWord(CurrentHash[1]);
CurrentHash[2]:= SwapDWord(CurrentHash[2]); CurrentHash[2]:= SwapDWord(CurrentHash[2]);
CurrentHash[3]:= SwapDWord(CurrentHash[3]); CurrentHash[3]:= SwapDWord(CurrentHash[3]);
CurrentHash[4]:= SwapDWord(CurrentHash[4]); CurrentHash[4]:= SwapDWord(CurrentHash[4]);
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,284 +1,284 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of SHA256 *******************************} {* A binary compatible implementation of SHA256 *******************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPsha256; unit DCPsha256;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_sha256= class(TDCP_hash) TDCP_sha256= class(TDCP_hash)
protected protected
LenHi, LenLo: longword; LenHi, LenLo: longword;
Index: DWord; Index: DWord;
CurrentHash: array[0..7] of DWord; CurrentHash: array[0..7] of DWord;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
function SwapDWord(a: dword): dword; function SwapDWord(a: dword): dword;
begin begin
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24); Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
end; end;
procedure TDCP_sha256.Compress; procedure TDCP_sha256.Compress;
var var
a, b, c, d, e, f, g, h, t1, t2: DWord; a, b, c, d, e, f, g, h, t1, t2: DWord;
W: array[0..63] of DWord; W: array[0..63] of DWord;
i: longword; i: longword;
begin begin
Index:= 0; Index:= 0;
dcpFillChar(W, SizeOf(W), 0); dcpFillChar(W, SizeOf(W), 0);
a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3]; a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3];
e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7]; e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7];
Move(HashBuffer,W,Sizeof(HashBuffer)); Move(HashBuffer,W,Sizeof(HashBuffer));
for i:= 0 to 15 do for i:= 0 to 15 do
W[i]:= SwapDWord(W[i]); W[i]:= SwapDWord(W[i]);
for i:= 16 to 63 do for i:= 16 to 63 do
W[i]:= (((W[i-2] shr 17) or (W[i-2] shl 15)) xor ((W[i-2] shr 19) or (W[i-2] shl 13)) xor W[i]:= (((W[i-2] shr 17) or (W[i-2] shl 15)) xor ((W[i-2] shr 19) or (W[i-2] shl 13)) xor
(W[i-2] shr 10)) + W[i-7] + (((W[i-15] shr 7) or (W[i-15] shl 25)) xor (W[i-2] shr 10)) + W[i-7] + (((W[i-15] shr 7) or (W[i-15] shl 25)) xor
((W[i-15] shr 18) or (W[i-15] shl 14)) xor (W[i-15] shr 3)) + W[i-16]; ((W[i-15] shr 18) or (W[i-15] shl 14)) xor (W[i-15] shr 3)) + W[i-16];
{ {
Non-optimised version Non-optimised version
for i:= 0 to 63 do for i:= 0 to 63 do
begin begin
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) +
((e and f) xor (not e and g)) + K[i] + W[i]; ((e and f) xor (not e and g)) + K[i] + W[i];
t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) +
((a and b) xor (a and c) xor (b and c)); ((a and b) xor (a and c) xor (b and c));
h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2; h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2;
end; end;
} }
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $428a2f98 + W[0]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $428a2f98 + W[0]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $71374491 + W[1]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $71374491 + W[1]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b5c0fbcf + W[2]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b5c0fbcf + W[2]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $e9b5dba5 + W[3]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $e9b5dba5 + W[3]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $3956c25b + W[4]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $3956c25b + W[4]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $59f111f1 + W[5]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $59f111f1 + W[5]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $923f82a4 + W[6]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $923f82a4 + W[6]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $ab1c5ed5 + W[7]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $ab1c5ed5 + W[7]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $d807aa98 + W[8]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $d807aa98 + W[8]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $12835b01 + W[9]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $12835b01 + W[9]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $243185be + W[10]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $243185be + W[10]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $550c7dc3 + W[11]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $550c7dc3 + W[11]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $72be5d74 + W[12]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $72be5d74 + W[12]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $80deb1fe + W[13]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $80deb1fe + W[13]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $9bdc06a7 + W[14]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $9bdc06a7 + W[14]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c19bf174 + W[15]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c19bf174 + W[15]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $e49b69c1 + W[16]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $e49b69c1 + W[16]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $efbe4786 + W[17]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $efbe4786 + W[17]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $0fc19dc6 + W[18]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $0fc19dc6 + W[18]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $240ca1cc + W[19]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $240ca1cc + W[19]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $2de92c6f + W[20]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $2de92c6f + W[20]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4a7484aa + W[21]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4a7484aa + W[21]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5cb0a9dc + W[22]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5cb0a9dc + W[22]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $76f988da + W[23]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $76f988da + W[23]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $983e5152 + W[24]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $983e5152 + W[24]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a831c66d + W[25]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a831c66d + W[25]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b00327c8 + W[26]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b00327c8 + W[26]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $bf597fc7 + W[27]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $bf597fc7 + W[27]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $c6e00bf3 + W[28]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $c6e00bf3 + W[28]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d5a79147 + W[29]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d5a79147 + W[29]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $06ca6351 + W[30]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $06ca6351 + W[30]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $14292967 + W[31]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $14292967 + W[31]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $27b70a85 + W[32]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $27b70a85 + W[32]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $2e1b2138 + W[33]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $2e1b2138 + W[33]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $4d2c6dfc + W[34]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $4d2c6dfc + W[34]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $53380d13 + W[35]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $53380d13 + W[35]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $650a7354 + W[36]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $650a7354 + W[36]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $766a0abb + W[37]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $766a0abb + W[37]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $81c2c92e + W[38]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $81c2c92e + W[38]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $92722c85 + W[39]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $92722c85 + W[39]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $a2bfe8a1 + W[40]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $a2bfe8a1 + W[40]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a81a664b + W[41]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a81a664b + W[41]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $c24b8b70 + W[42]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $c24b8b70 + W[42]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $c76c51a3 + W[43]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $c76c51a3 + W[43]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $d192e819 + W[44]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $d192e819 + W[44]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d6990624 + W[45]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d6990624 + W[45]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $f40e3585 + W[46]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $f40e3585 + W[46]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $106aa070 + W[47]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $106aa070 + W[47]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $19a4c116 + W[48]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $19a4c116 + W[48]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $1e376c08 + W[49]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $1e376c08 + W[49]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $2748774c + W[50]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $2748774c + W[50]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $34b0bcb5 + W[51]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $34b0bcb5 + W[51]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $391c0cb3 + W[52]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $391c0cb3 + W[52]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4ed8aa4a + W[53]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4ed8aa4a + W[53]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5b9cca4f + W[54]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5b9cca4f + W[54]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $682e6ff3 + W[55]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $682e6ff3 + W[55]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $748f82ee + W[56]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1; t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $748f82ee + W[56]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $78a5636f + W[57]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1; t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $78a5636f + W[57]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $84c87814 + W[58]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1; t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $84c87814 + W[58]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $8cc70208 + W[59]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1; t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $8cc70208 + W[59]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $90befffa + W[60]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1; t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $90befffa + W[60]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $a4506ceb + W[61]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1; t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $a4506ceb + W[61]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $bef9a3f7 + W[62]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1; t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $bef9a3f7 + W[62]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c67178f2 + W[63]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1; t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c67178f2 + W[63]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
CurrentHash[0]:= CurrentHash[0] + a; CurrentHash[0]:= CurrentHash[0] + a;
CurrentHash[1]:= CurrentHash[1] + b; CurrentHash[1]:= CurrentHash[1] + b;
CurrentHash[2]:= CurrentHash[2] + c; CurrentHash[2]:= CurrentHash[2] + c;
CurrentHash[3]:= CurrentHash[3] + d; CurrentHash[3]:= CurrentHash[3] + d;
CurrentHash[4]:= CurrentHash[4] + e; CurrentHash[4]:= CurrentHash[4] + e;
CurrentHash[5]:= CurrentHash[5] + f; CurrentHash[5]:= CurrentHash[5] + f;
CurrentHash[6]:= CurrentHash[6] + g; CurrentHash[6]:= CurrentHash[6] + g;
CurrentHash[7]:= CurrentHash[7] + h; CurrentHash[7]:= CurrentHash[7] + h;
FillChar(W,Sizeof(W),0); FillChar(W,Sizeof(W),0);
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_sha256.GetAlgorithm: string; class function TDCP_sha256.GetAlgorithm: string;
begin begin
Result:= 'SHA256'; Result:= 'SHA256';
end; end;
class function TDCP_sha256.GetId: integer; class function TDCP_sha256.GetId: integer;
begin begin
Result:= DCP_sha256; Result:= DCP_sha256;
end; end;
class function TDCP_sha256.GetHashSize: integer; class function TDCP_sha256.GetHashSize: integer;
begin begin
Result:= 256; Result:= 256;
end; end;
class function TDCP_sha256.SelfTest: boolean; class function TDCP_sha256.SelfTest: boolean;
const const
Test1Out: array[0..31] of byte= Test1Out: array[0..31] of byte=
($ba,$78,$16,$bf,$8f,$01,$cf,$ea,$41,$41,$40,$de,$5d,$ae,$22,$23, ($ba,$78,$16,$bf,$8f,$01,$cf,$ea,$41,$41,$40,$de,$5d,$ae,$22,$23,
$b0,$03,$61,$a3,$96,$17,$7a,$9c,$b4,$10,$ff,$61,$f2,$00,$15,$ad); $b0,$03,$61,$a3,$96,$17,$7a,$9c,$b4,$10,$ff,$61,$f2,$00,$15,$ad);
Test2Out: array[0..31] of byte= Test2Out: array[0..31] of byte=
($24,$8d,$6a,$61,$d2,$06,$38,$b8,$e5,$c0,$26,$93,$0c,$3e,$60,$39, ($24,$8d,$6a,$61,$d2,$06,$38,$b8,$e5,$c0,$26,$93,$0c,$3e,$60,$39,
$a3,$3c,$e4,$59,$64,$ff,$21,$67,$f6,$ec,$ed,$d4,$19,$db,$06,$c1); $a3,$3c,$e4,$59,$64,$ff,$21,$67,$f6,$ec,$ed,$d4,$19,$db,$06,$c1);
var var
TestHash: TDCP_sha256; TestHash: TDCP_sha256;
TestOut: array[0..31] of byte; TestOut: array[0..31] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_sha256.Create(nil); TestHash:= TDCP_sha256.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out))); Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'); TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result; Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_sha256.Init; procedure TDCP_sha256.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $6a09e667; CurrentHash[0]:= $6a09e667;
CurrentHash[1]:= $bb67ae85; CurrentHash[1]:= $bb67ae85;
CurrentHash[2]:= $3c6ef372; CurrentHash[2]:= $3c6ef372;
CurrentHash[3]:= $a54ff53a; CurrentHash[3]:= $a54ff53a;
CurrentHash[4]:= $510e527f; CurrentHash[4]:= $510e527f;
CurrentHash[5]:= $9b05688c; CurrentHash[5]:= $9b05688c;
CurrentHash[6]:= $1f83d9ab; CurrentHash[6]:= $1f83d9ab;
CurrentHash[7]:= $5be0cd19; CurrentHash[7]:= $5be0cd19;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_sha256.Burn; procedure TDCP_sha256.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_sha256.Update(const Buffer; Size: longword); procedure TDCP_sha256.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29); Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_sha256.Final(var Digest); procedure TDCP_sha256.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
PDWord(@HashBuffer[56])^:= SwapDWord(LenHi); PDWord(@HashBuffer[56])^:= SwapDWord(LenHi);
PDWord(@HashBuffer[60])^:= SwapDWord(LenLo); PDWord(@HashBuffer[60])^:= SwapDWord(LenLo);
Compress; Compress;
CurrentHash[0]:= SwapDWord(CurrentHash[0]); CurrentHash[0]:= SwapDWord(CurrentHash[0]);
CurrentHash[1]:= SwapDWord(CurrentHash[1]); CurrentHash[1]:= SwapDWord(CurrentHash[1]);
CurrentHash[2]:= SwapDWord(CurrentHash[2]); CurrentHash[2]:= SwapDWord(CurrentHash[2]);
CurrentHash[3]:= SwapDWord(CurrentHash[3]); CurrentHash[3]:= SwapDWord(CurrentHash[3]);
CurrentHash[4]:= SwapDWord(CurrentHash[4]); CurrentHash[4]:= SwapDWord(CurrentHash[4]);
CurrentHash[5]:= SwapDWord(CurrentHash[5]); CurrentHash[5]:= SwapDWord(CurrentHash[5]);
CurrentHash[6]:= SwapDWord(CurrentHash[6]); CurrentHash[6]:= SwapDWord(CurrentHash[6]);
CurrentHash[7]:= SwapDWord(CurrentHash[7]); CurrentHash[7]:= SwapDWord(CurrentHash[7]);
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,397 +1,397 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of SHA512 *******************************} {* A binary compatible implementation of SHA512 *******************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPsha512; unit DCPsha512;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_sha512base= class(TDCP_hash) TDCP_sha512base= class(TDCP_hash)
protected protected
LenHi, LenLo: int64; LenHi, LenLo: int64;
Index: DWord; Index: DWord;
CurrentHash: array[0..7] of int64; CurrentHash: array[0..7] of int64;
HashBuffer: array[0..127] of byte; HashBuffer: array[0..127] of byte;
procedure Compress; procedure Compress;
public public
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
procedure Burn; override; procedure Burn; override;
end; end;
TDCP_sha384= class(TDCP_sha512base) TDCP_sha384= class(TDCP_sha512base)
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
TDCP_sha512= class(TDCP_sha512base) TDCP_sha512= class(TDCP_sha512base)
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
function SwapDWord(a: int64): int64; function SwapDWord(a: int64): int64;
begin begin
Result:= ((a and $FF) shl 56) or ((a and $FF00) shl 40) or ((a and $FF0000) shl 24) or ((a and $FF000000) shl 8) or Result:= ((a and $FF) shl 56) or ((a and $FF00) shl 40) or ((a and $FF0000) shl 24) or ((a and $FF000000) shl 8) or
((a and $FF00000000) shr 8) or ((a and $FF0000000000) shr 24) or ((a and $FF000000000000) shr 40) or ((a and $FF00000000000000) shr 56); ((a and $FF00000000) shr 8) or ((a and $FF0000000000) shr 24) or ((a and $FF000000000000) shr 40) or ((a and $FF00000000000000) shr 56);
end; end;
procedure TDCP_sha512base.Compress; procedure TDCP_sha512base.Compress;
var var
a, b, c, d, e, f, g, h, t1, t2: int64; a, b, c, d, e, f, g, h, t1, t2: int64;
W: array[0..79] of int64; W: array[0..79] of int64;
i: longword; i: longword;
begin begin
Index:= 0; Index:= 0;
dcpFillChar(W, SizeOf(W), 0); dcpFillChar(W, SizeOf(W), 0);
a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3]; a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3];
e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7]; e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7];
Move(HashBuffer,W,Sizeof(HashBuffer)); Move(HashBuffer,W,Sizeof(HashBuffer));
for i:= 0 to 15 do for i:= 0 to 15 do
W[i]:= SwapDWord(W[i]); W[i]:= SwapDWord(W[i]);
for i:= 16 to 79 do for i:= 16 to 79 do
W[i]:= (((W[i-2] shr 19) or (W[i-2] shl 45)) xor ((W[i-2] shr 61) or (W[i-2] shl 3)) xor W[i]:= (((W[i-2] shr 19) or (W[i-2] shl 45)) xor ((W[i-2] shr 61) or (W[i-2] shl 3)) xor
(W[i-2] shr 6)) + W[i-7] + (((W[i-15] shr 1) or (W[i-15] shl 63)) xor ((W[i-15] shr 8) or (W[i-2] shr 6)) + W[i-7] + (((W[i-15] shr 1) or (W[i-15] shl 63)) xor ((W[i-15] shr 8) or
(W[i-15] shl 56)) xor (W[i-15] shr 7)) + W[i-16]; (W[i-15] shl 56)) xor (W[i-15] shr 7)) + W[i-16];
{ {
Non-optimised version Non-optimised version
for i:= 0 to 79 do for i:= 0 to 79 do
begin begin
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) +
((e and f) xor (not e and g)) + K[i] + W[i]; ((e and f) xor (not e and g)) + K[i] + W[i];
t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) +
((a and b) xor (a and c) xor (b and c)); ((a and b) xor (a and c) xor (b and c));
h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2; h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2;
end; end;
} }
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $428a2f98d728ae22 + W[0]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $428a2f98d728ae22 + W[0]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $7137449123ef65cd + W[1]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $7137449123ef65cd + W[1]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b5c0fbcfec4d3b2f + W[2]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b5c0fbcfec4d3b2f + W[2]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $e9b5dba58189dbbc + W[3]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $e9b5dba58189dbbc + W[3]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $3956c25bf348b538 + W[4]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $3956c25bf348b538 + W[4]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $59f111f1b605d019 + W[5]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $59f111f1b605d019 + W[5]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $923f82a4af194f9b + W[6]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $923f82a4af194f9b + W[6]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $ab1c5ed5da6d8118 + W[7]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $ab1c5ed5da6d8118 + W[7]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $d807aa98a3030242 + W[8]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $d807aa98a3030242 + W[8]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $12835b0145706fbe + W[9]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $12835b0145706fbe + W[9]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $243185be4ee4b28c + W[10]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $243185be4ee4b28c + W[10]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $550c7dc3d5ffb4e2 + W[11]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $550c7dc3d5ffb4e2 + W[11]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $72be5d74f27b896f + W[12]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $72be5d74f27b896f + W[12]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $80deb1fe3b1696b1 + W[13]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $80deb1fe3b1696b1 + W[13]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $9bdc06a725c71235 + W[14]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $9bdc06a725c71235 + W[14]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c19bf174cf692694 + W[15]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c19bf174cf692694 + W[15]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $e49b69c19ef14ad2 + W[16]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $e49b69c19ef14ad2 + W[16]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $efbe4786384f25e3 + W[17]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $efbe4786384f25e3 + W[17]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $0fc19dc68b8cd5b5 + W[18]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $0fc19dc68b8cd5b5 + W[18]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $240ca1cc77ac9c65 + W[19]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $240ca1cc77ac9c65 + W[19]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $2de92c6f592b0275 + W[20]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $2de92c6f592b0275 + W[20]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4a7484aa6ea6e483 + W[21]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4a7484aa6ea6e483 + W[21]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5cb0a9dcbd41fbd4 + W[22]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5cb0a9dcbd41fbd4 + W[22]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $76f988da831153b5 + W[23]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $76f988da831153b5 + W[23]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $983e5152ee66dfab + W[24]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $983e5152ee66dfab + W[24]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a831c66d2db43210 + W[25]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a831c66d2db43210 + W[25]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b00327c898fb213f + W[26]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b00327c898fb213f + W[26]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $bf597fc7beef0ee4 + W[27]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $bf597fc7beef0ee4 + W[27]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $c6e00bf33da88fc2 + W[28]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $c6e00bf33da88fc2 + W[28]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d5a79147930aa725 + W[29]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d5a79147930aa725 + W[29]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $06ca6351e003826f + W[30]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $06ca6351e003826f + W[30]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $142929670a0e6e70 + W[31]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $142929670a0e6e70 + W[31]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $27b70a8546d22ffc + W[32]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $27b70a8546d22ffc + W[32]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $2e1b21385c26c926 + W[33]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $2e1b21385c26c926 + W[33]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $4d2c6dfc5ac42aed + W[34]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $4d2c6dfc5ac42aed + W[34]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $53380d139d95b3df + W[35]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $53380d139d95b3df + W[35]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $650a73548baf63de + W[36]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $650a73548baf63de + W[36]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $766a0abb3c77b2a8 + W[37]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $766a0abb3c77b2a8 + W[37]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $81c2c92e47edaee6 + W[38]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $81c2c92e47edaee6 + W[38]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $92722c851482353b + W[39]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $92722c851482353b + W[39]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $a2bfe8a14cf10364 + W[40]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $a2bfe8a14cf10364 + W[40]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a81a664bbc423001 + W[41]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a81a664bbc423001 + W[41]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $c24b8b70d0f89791 + W[42]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $c24b8b70d0f89791 + W[42]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $c76c51a30654be30 + W[43]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $c76c51a30654be30 + W[43]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $d192e819d6ef5218 + W[44]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $d192e819d6ef5218 + W[44]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d69906245565a910 + W[45]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d69906245565a910 + W[45]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $f40e35855771202a + W[46]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $f40e35855771202a + W[46]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $106aa07032bbd1b8 + W[47]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $106aa07032bbd1b8 + W[47]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $19a4c116b8d2d0c8 + W[48]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $19a4c116b8d2d0c8 + W[48]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $1e376c085141ab53 + W[49]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $1e376c085141ab53 + W[49]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $2748774cdf8eeb99 + W[50]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $2748774cdf8eeb99 + W[50]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $34b0bcb5e19b48a8 + W[51]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $34b0bcb5e19b48a8 + W[51]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $391c0cb3c5c95a63 + W[52]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $391c0cb3c5c95a63 + W[52]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4ed8aa4ae3418acb + W[53]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4ed8aa4ae3418acb + W[53]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5b9cca4f7763e373 + W[54]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5b9cca4f7763e373 + W[54]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $682e6ff3d6b2b8a3 + W[55]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $682e6ff3d6b2b8a3 + W[55]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $748f82ee5defb2fc + W[56]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $748f82ee5defb2fc + W[56]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $78a5636f43172f60 + W[57]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $78a5636f43172f60 + W[57]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $84c87814a1f0ab72 + W[58]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $84c87814a1f0ab72 + W[58]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $8cc702081a6439ec + W[59]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $8cc702081a6439ec + W[59]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $90befffa23631e28 + W[60]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $90befffa23631e28 + W[60]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $a4506cebde82bde9 + W[61]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $a4506cebde82bde9 + W[61]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $bef9a3f7b2c67915 + W[62]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $bef9a3f7b2c67915 + W[62]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c67178f2e372532b + W[63]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c67178f2e372532b + W[63]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $ca273eceea26619c + W[64]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $ca273eceea26619c + W[64]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $d186b8c721c0c207 + W[65]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $d186b8c721c0c207 + W[65]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $eada7dd6cde0eb1e + W[66]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $eada7dd6cde0eb1e + W[66]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $f57d4f7fee6ed178 + W[67]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $f57d4f7fee6ed178 + W[67]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $06f067aa72176fba + W[68]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $06f067aa72176fba + W[68]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $0a637dc5a2c898a6 + W[69]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $0a637dc5a2c898a6 + W[69]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $113f9804bef90dae + W[70]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $113f9804bef90dae + W[70]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $1b710b35131c471b + W[71]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $1b710b35131c471b + W[71]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $28db77f523047d84 + W[72]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2; t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $28db77f523047d84 + W[72]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $32caab7b40c72493 + W[73]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2; t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $32caab7b40c72493 + W[73]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $3c9ebe0a15c9bebc + W[74]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2; t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $3c9ebe0a15c9bebc + W[74]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $431d67c49c100d4c + W[75]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2; t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $431d67c49c100d4c + W[75]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $4cc5d4becb3e42b6 + W[76]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2; t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $4cc5d4becb3e42b6 + W[76]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $597f299cfc657e2a + W[77]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2; t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $597f299cfc657e2a + W[77]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5fcb6fab3ad6faec + W[78]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2; t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5fcb6fab3ad6faec + W[78]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $6c44198c4a475817 + W[79]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2; t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $6c44198c4a475817 + W[79]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
CurrentHash[0]:= CurrentHash[0] + a; CurrentHash[0]:= CurrentHash[0] + a;
CurrentHash[1]:= CurrentHash[1] + b; CurrentHash[1]:= CurrentHash[1] + b;
CurrentHash[2]:= CurrentHash[2] + c; CurrentHash[2]:= CurrentHash[2] + c;
CurrentHash[3]:= CurrentHash[3] + d; CurrentHash[3]:= CurrentHash[3] + d;
CurrentHash[4]:= CurrentHash[4] + e; CurrentHash[4]:= CurrentHash[4] + e;
CurrentHash[5]:= CurrentHash[5] + f; CurrentHash[5]:= CurrentHash[5] + f;
CurrentHash[6]:= CurrentHash[6] + g; CurrentHash[6]:= CurrentHash[6] + g;
CurrentHash[7]:= CurrentHash[7] + h; CurrentHash[7]:= CurrentHash[7] + h;
FillChar(W,Sizeof(W),0); FillChar(W,Sizeof(W),0);
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
procedure TDCP_sha512base.Burn; procedure TDCP_sha512base.Burn;
begin begin
LenHi:= 0; LenLo:= 0; LenHi:= 0; LenLo:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_sha512base.Update(const Buffer; Size: longword); procedure TDCP_sha512base.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(LenLo,Size*8); Inc(LenLo,Size*8);
if LenLo< (Size*8) then if LenLo< (Size*8) then
Inc(LenHi); Inc(LenHi);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_sha384.GetAlgorithm: string; class function TDCP_sha384.GetAlgorithm: string;
begin begin
Result:= 'SHA384'; Result:= 'SHA384';
end; end;
class function TDCP_sha384.GetId: integer; class function TDCP_sha384.GetId: integer;
begin begin
Result:= DCP_sha384; Result:= DCP_sha384;
end; end;
class function TDCP_sha384.GetHashSize: integer; class function TDCP_sha384.GetHashSize: integer;
begin begin
Result:= 384; Result:= 384;
end; end;
class function TDCP_sha384.SelfTest: boolean; class function TDCP_sha384.SelfTest: boolean;
const const
Test1Out: array[0..47] of byte= Test1Out: array[0..47] of byte=
($cb,$00,$75,$3f,$45,$a3,$5e,$8b,$b5,$a0,$3d,$69,$9a,$c6,$50,$07, ($cb,$00,$75,$3f,$45,$a3,$5e,$8b,$b5,$a0,$3d,$69,$9a,$c6,$50,$07,
$27,$2c,$32,$ab,$0e,$de,$d1,$63,$1a,$8b,$60,$5a,$43,$ff,$5b,$ed, $27,$2c,$32,$ab,$0e,$de,$d1,$63,$1a,$8b,$60,$5a,$43,$ff,$5b,$ed,
$80,$86,$07,$2b,$a1,$e7,$cc,$23,$58,$ba,$ec,$a1,$34,$c8,$25,$a7); $80,$86,$07,$2b,$a1,$e7,$cc,$23,$58,$ba,$ec,$a1,$34,$c8,$25,$a7);
Test2Out: array[0..47] of byte= Test2Out: array[0..47] of byte=
($09,$33,$0c,$33,$f7,$11,$47,$e8,$3d,$19,$2f,$c7,$82,$cd,$1b,$47, ($09,$33,$0c,$33,$f7,$11,$47,$e8,$3d,$19,$2f,$c7,$82,$cd,$1b,$47,
$53,$11,$1b,$17,$3b,$3b,$05,$d2,$2f,$a0,$80,$86,$e3,$b0,$f7,$12, $53,$11,$1b,$17,$3b,$3b,$05,$d2,$2f,$a0,$80,$86,$e3,$b0,$f7,$12,
$fc,$c7,$c7,$1a,$55,$7e,$2d,$b9,$66,$c3,$e9,$fa,$91,$74,$60,$39); $fc,$c7,$c7,$1a,$55,$7e,$2d,$b9,$66,$c3,$e9,$fa,$91,$74,$60,$39);
var var
TestHash: TDCP_sha384; TestHash: TDCP_sha384;
TestOut: array[0..47] of byte; TestOut: array[0..47] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_sha384.Create(nil); TestHash:= TDCP_sha384.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out))); Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'); TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result; Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_sha384.Init; procedure TDCP_sha384.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $cbbb9d5dc1059ed8; CurrentHash[0]:= $cbbb9d5dc1059ed8;
CurrentHash[1]:= $629a292a367cd507; CurrentHash[1]:= $629a292a367cd507;
CurrentHash[2]:= $9159015a3070dd17; CurrentHash[2]:= $9159015a3070dd17;
CurrentHash[3]:= $152fecd8f70e5939; CurrentHash[3]:= $152fecd8f70e5939;
CurrentHash[4]:= $67332667ffc00b31; CurrentHash[4]:= $67332667ffc00b31;
CurrentHash[5]:= $8eb44a8768581511; CurrentHash[5]:= $8eb44a8768581511;
CurrentHash[6]:= $db0c2e0d64f98fa7; CurrentHash[6]:= $db0c2e0d64f98fa7;
CurrentHash[7]:= $47b5481dbefa4fa4; CurrentHash[7]:= $47b5481dbefa4fa4;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_sha384.Final(var Digest); procedure TDCP_sha384.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 112 then if Index>= 112 then
Compress; Compress;
Pint64(@HashBuffer[112])^:= SwapDWord(LenHi); Pint64(@HashBuffer[112])^:= SwapDWord(LenHi);
Pint64(@HashBuffer[120])^:= SwapDWord(LenLo); Pint64(@HashBuffer[120])^:= SwapDWord(LenLo);
Compress; Compress;
CurrentHash[0]:= SwapDWord(CurrentHash[0]); CurrentHash[0]:= SwapDWord(CurrentHash[0]);
CurrentHash[1]:= SwapDWord(CurrentHash[1]); CurrentHash[1]:= SwapDWord(CurrentHash[1]);
CurrentHash[2]:= SwapDWord(CurrentHash[2]); CurrentHash[2]:= SwapDWord(CurrentHash[2]);
CurrentHash[3]:= SwapDWord(CurrentHash[3]); CurrentHash[3]:= SwapDWord(CurrentHash[3]);
CurrentHash[4]:= SwapDWord(CurrentHash[4]); CurrentHash[4]:= SwapDWord(CurrentHash[4]);
CurrentHash[5]:= SwapDWord(CurrentHash[5]); CurrentHash[5]:= SwapDWord(CurrentHash[5]);
Move(CurrentHash,Digest,384 div 8); Move(CurrentHash,Digest,384 div 8);
Burn; Burn;
end; end;
{******************************************************************************} {******************************************************************************}
class function TDCP_sha512.GetAlgorithm: string; class function TDCP_sha512.GetAlgorithm: string;
begin begin
Result:= 'SHA512'; Result:= 'SHA512';
end; end;
class function TDCP_sha512.GetId: integer; class function TDCP_sha512.GetId: integer;
begin begin
Result:= DCP_sha512; Result:= DCP_sha512;
end; end;
class function TDCP_sha512.GetHashSize: integer; class function TDCP_sha512.GetHashSize: integer;
begin begin
Result:= 512; Result:= 512;
end; end;
class function TDCP_sha512.SelfTest: boolean; class function TDCP_sha512.SelfTest: boolean;
const const
Test1Out: array[0..63] of byte= Test1Out: array[0..63] of byte=
($dd,$af,$35,$a1,$93,$61,$7a,$ba,$cc,$41,$73,$49,$ae,$20,$41,$31, ($dd,$af,$35,$a1,$93,$61,$7a,$ba,$cc,$41,$73,$49,$ae,$20,$41,$31,
$12,$e6,$fa,$4e,$89,$a9,$7e,$a2,$0a,$9e,$ee,$e6,$4b,$55,$d3,$9a, $12,$e6,$fa,$4e,$89,$a9,$7e,$a2,$0a,$9e,$ee,$e6,$4b,$55,$d3,$9a,
$21,$92,$99,$2a,$27,$4f,$c1,$a8,$36,$ba,$3c,$23,$a3,$fe,$eb,$bd, $21,$92,$99,$2a,$27,$4f,$c1,$a8,$36,$ba,$3c,$23,$a3,$fe,$eb,$bd,
$45,$4d,$44,$23,$64,$3c,$e8,$0e,$2a,$9a,$c9,$4f,$a5,$4c,$a4,$9f); $45,$4d,$44,$23,$64,$3c,$e8,$0e,$2a,$9a,$c9,$4f,$a5,$4c,$a4,$9f);
Test2Out: array[0..63] of byte= Test2Out: array[0..63] of byte=
($8e,$95,$9b,$75,$da,$e3,$13,$da,$8c,$f4,$f7,$28,$14,$fc,$14,$3f, ($8e,$95,$9b,$75,$da,$e3,$13,$da,$8c,$f4,$f7,$28,$14,$fc,$14,$3f,
$8f,$77,$79,$c6,$eb,$9f,$7f,$a1,$72,$99,$ae,$ad,$b6,$88,$90,$18, $8f,$77,$79,$c6,$eb,$9f,$7f,$a1,$72,$99,$ae,$ad,$b6,$88,$90,$18,
$50,$1d,$28,$9e,$49,$00,$f7,$e4,$33,$1b,$99,$de,$c4,$b5,$43,$3a, $50,$1d,$28,$9e,$49,$00,$f7,$e4,$33,$1b,$99,$de,$c4,$b5,$43,$3a,
$c7,$d3,$29,$ee,$b6,$dd,$26,$54,$5e,$96,$e5,$5b,$87,$4b,$e9,$09); $c7,$d3,$29,$ee,$b6,$dd,$26,$54,$5e,$96,$e5,$5b,$87,$4b,$e9,$09);
var var
TestHash: TDCP_sha512; TestHash: TDCP_sha512;
TestOut: array[0..63] of byte; TestOut: array[0..63] of byte;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_sha512.Create(nil); TestHash:= TDCP_sha512.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abc'); TestHash.UpdateStr('abc');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out))); Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'); TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result; Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_sha512.Init; procedure TDCP_sha512.Init;
begin begin
Burn; Burn;
CurrentHash[0]:= $6a09e667f3bcc908; CurrentHash[0]:= $6a09e667f3bcc908;
CurrentHash[1]:= $bb67ae8584caa73b; CurrentHash[1]:= $bb67ae8584caa73b;
CurrentHash[2]:= $3c6ef372fe94f82b; CurrentHash[2]:= $3c6ef372fe94f82b;
CurrentHash[3]:= $a54ff53a5f1d36f1; CurrentHash[3]:= $a54ff53a5f1d36f1;
CurrentHash[4]:= $510e527fade682d1; CurrentHash[4]:= $510e527fade682d1;
CurrentHash[5]:= $9b05688c2b3e6c1f; CurrentHash[5]:= $9b05688c2b3e6c1f;
CurrentHash[6]:= $1f83d9abfb41bd6b; CurrentHash[6]:= $1f83d9abfb41bd6b;
CurrentHash[7]:= $5be0cd19137e2179; CurrentHash[7]:= $5be0cd19137e2179;
fInitialized:= true; fInitialized:= true;
end; end;
procedure TDCP_sha512.Final(var Digest); procedure TDCP_sha512.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80; HashBuffer[Index]:= $80;
if Index>= 112 then if Index>= 112 then
Compress; Compress;
Pint64(@HashBuffer[112])^:= SwapDWord(LenHi); Pint64(@HashBuffer[112])^:= SwapDWord(LenHi);
Pint64(@HashBuffer[120])^:= SwapDWord(LenLo); Pint64(@HashBuffer[120])^:= SwapDWord(LenLo);
Compress; Compress;
CurrentHash[0]:= SwapDWord(CurrentHash[0]); CurrentHash[0]:= SwapDWord(CurrentHash[0]);
CurrentHash[1]:= SwapDWord(CurrentHash[1]); CurrentHash[1]:= SwapDWord(CurrentHash[1]);
CurrentHash[2]:= SwapDWord(CurrentHash[2]); CurrentHash[2]:= SwapDWord(CurrentHash[2]);
CurrentHash[3]:= SwapDWord(CurrentHash[3]); CurrentHash[3]:= SwapDWord(CurrentHash[3]);
CurrentHash[4]:= SwapDWord(CurrentHash[4]); CurrentHash[4]:= SwapDWord(CurrentHash[4]);
CurrentHash[5]:= SwapDWord(CurrentHash[5]); CurrentHash[5]:= SwapDWord(CurrentHash[5]);
CurrentHash[6]:= SwapDWord(CurrentHash[6]); CurrentHash[6]:= SwapDWord(CurrentHash[6]);
CurrentHash[7]:= SwapDWord(CurrentHash[7]); CurrentHash[7]:= SwapDWord(CurrentHash[7]);
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,304 +1,304 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A binary compatible implementation of Tiger ********************************} {* A binary compatible implementation of Tiger ********************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 2002 David Barton *} {* Copyright (c) 2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPtiger; unit DCPtiger;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
Classes, Sysutils, DCPcrypt2, DCPconst; Classes, Sysutils, DCPcrypt2, DCPconst;
type type
TDCP_tiger= class(TDCP_hash) TDCP_tiger= class(TDCP_hash)
protected protected
Len: int64; Len: int64;
Index: DWord; Index: DWord;
CurrentHash: array[0..2] of int64; CurrentHash: array[0..2] of int64;
HashBuffer: array[0..63] of byte; HashBuffer: array[0..63] of byte;
procedure Compress; procedure Compress;
public public
class function GetId: integer; override; class function GetId: integer; override;
class function GetAlgorithm: string; override; class function GetAlgorithm: string; override;
class function GetHashSize: integer; override; class function GetHashSize: integer; override;
class function SelfTest: boolean; override; class function SelfTest: boolean; override;
procedure Init; override; procedure Init; override;
procedure Burn; override; procedure Burn; override;
procedure Update(const Buffer; Size: longword); override; procedure Update(const Buffer; Size: longword); override;
procedure Final(var Digest); override; procedure Final(var Digest); override;
end; end;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$R-}{$Q-} {$R-}{$Q-}
{$INCLUDE DCPtiger.inc} {$INCLUDE DCPtiger.inc}
procedure TDCP_tiger.Compress; procedure TDCP_tiger.Compress;
var var
a, b, c, aa, bb, cc: int64; a, b, c, aa, bb, cc: int64;
x: array[0..7] of int64; x: array[0..7] of int64;
begin begin
dcpFillChar(x, SizeOf(x), 0); dcpFillChar(x, SizeOf(x), 0);
a:= CurrentHash[0]; aa:= a; a:= CurrentHash[0]; aa:= a;
b:= CurrentHash[1]; bb:= b; b:= CurrentHash[1]; bb:= b;
c:= CurrentHash[2]; cc:= c; c:= CurrentHash[2]; cc:= c;
Move(HashBuffer,x,Sizeof(x)); Move(HashBuffer,x,Sizeof(x));
c:= c xor x[0]; c:= c xor x[0];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 5; b:= b * 5;
a:= a xor x[1]; a:= a xor x[1];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 5; c:= c * 5;
b:= b xor x[2]; b:= b xor x[2];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 5; a:= a * 5;
c:= c xor x[3]; c:= c xor x[3];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 5; b:= b * 5;
a:= a xor x[4]; a:= a xor x[4];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 5; c:= c * 5;
b:= b xor x[5]; b:= b xor x[5];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 5; a:= a * 5;
c:= c xor x[6]; c:= c xor x[6];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 5; b:= b * 5;
a:= a xor x[7]; a:= a xor x[7];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 5; c:= c * 5;
x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5); x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5);
x[1]:= x[1] xor x[0]; x[1]:= x[1] xor x[0];
x[2]:= x[2] + x[1]; x[2]:= x[2] + x[1];
x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19)); x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19));
x[4]:= x[4] xor x[3]; x[4]:= x[4] xor x[3];
x[5]:= x[5] + x[4]; x[5]:= x[5] + x[4];
x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23)); x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23));
x[7]:= x[7] xor x[6]; x[7]:= x[7] xor x[6];
x[0]:= x[0] + x[7]; x[0]:= x[0] + x[7];
x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19)); x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19));
x[2]:= x[2] xor x[1]; x[2]:= x[2] xor x[1];
x[3]:= x[3] + x[2]; x[3]:= x[3] + x[2];
x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23)); x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23));
x[5]:= x[5] xor x[4]; x[5]:= x[5] xor x[4];
x[6]:= x[6] + x[5]; x[6]:= x[6] + x[5];
x[7]:= x[7] - (x[6] xor $0123456789ABCDEF); x[7]:= x[7] - (x[6] xor $0123456789ABCDEF);
b:= b xor x[0]; b:= b xor x[0];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 7; a:= a * 7;
c:= c xor x[1]; c:= c xor x[1];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 7; b:= b * 7;
a:= a xor x[2]; a:= a xor x[2];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 7; c:= c * 7;
b:= b xor x[3]; b:= b xor x[3];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 7; a:= a * 7;
c:= c xor x[4]; c:= c xor x[4];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 7; b:= b * 7;
a:= a xor x[5]; a:= a xor x[5];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 7; c:= c * 7;
b:= b xor x[6]; b:= b xor x[6];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 7; a:= a * 7;
c:= c xor x[7]; c:= c xor x[7];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 7; b:= b * 7;
x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5); x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5);
x[1]:= x[1] xor x[0]; x[1]:= x[1] xor x[0];
x[2]:= x[2] + x[1]; x[2]:= x[2] + x[1];
x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19)); x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19));
x[4]:= x[4] xor x[3]; x[4]:= x[4] xor x[3];
x[5]:= x[5] + x[4]; x[5]:= x[5] + x[4];
x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23)); x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23));
x[7]:= x[7] xor x[6]; x[7]:= x[7] xor x[6];
x[0]:= x[0] + x[7]; x[0]:= x[0] + x[7];
x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19)); x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19));
x[2]:= x[2] xor x[1]; x[2]:= x[2] xor x[1];
x[3]:= x[3] + x[2]; x[3]:= x[3] + x[2];
x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23)); x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23));
x[5]:= x[5] xor x[4]; x[5]:= x[5] xor x[4];
x[6]:= x[6] + x[5]; x[6]:= x[6] + x[5];
x[7]:= x[7] - (x[6] xor $0123456789ABCDEF); x[7]:= x[7] - (x[6] xor $0123456789ABCDEF);
a:= a xor x[0]; a:= a xor x[0];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 9; c:= c * 9;
b:= b xor x[1]; b:= b xor x[1];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 9; a:= a * 9;
c:= c xor x[2]; c:= c xor x[2];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 9; b:= b * 9;
a:= a xor x[3]; a:= a xor x[3];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 9; c:= c * 9;
b:= b xor x[4]; b:= b xor x[4];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 9; a:= a * 9;
c:= c xor x[5]; c:= c xor x[5];
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]); a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]); b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
b:= b * 9; b:= b * 9;
a:= a xor x[6]; a:= a xor x[6];
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]); b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]); c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
c:= c * 9; c:= c * 9;
b:= b xor x[7]; b:= b xor x[7];
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]); c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]); a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
a:= a * 9; a:= a * 9;
CurrentHash[0]:= a xor aa; CurrentHash[0]:= a xor aa;
CurrentHash[1]:= b - bb; CurrentHash[1]:= b - bb;
CurrentHash[2]:= c + cc; CurrentHash[2]:= c + cc;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
end; end;
class function TDCP_tiger.GetHashSize: integer; class function TDCP_tiger.GetHashSize: integer;
begin begin
Result:= 192; Result:= 192;
end; end;
class function TDCP_tiger.GetId: integer; class function TDCP_tiger.GetId: integer;
begin begin
Result:= DCP_tiger; Result:= DCP_tiger;
end; end;
class function TDCP_tiger.GetAlgorithm: string; class function TDCP_tiger.GetAlgorithm: string;
begin begin
Result:= 'Tiger'; Result:= 'Tiger';
end; end;
class function TDCP_tiger.SelfTest: boolean; class function TDCP_tiger.SelfTest: boolean;
const const
Test1Out: array[0..2] of int64= Test1Out: array[0..2] of int64=
($87FB2A9083851CF7,$470D2CF810E6DF9E,$B586445034A5A386); ($87FB2A9083851CF7,$470D2CF810E6DF9E,$B586445034A5A386);
Test2Out: array[0..2] of int64= Test2Out: array[0..2] of int64=
($0C410A042968868A,$1671DA5A3FD29A72,$5EC1E457D3CDB303); ($0C410A042968868A,$1671DA5A3FD29A72,$5EC1E457D3CDB303);
var var
TestHash: TDCP_tiger; TestHash: TDCP_tiger;
TestOut: array[0..2] of int64; TestOut: array[0..2] of int64;
begin begin
dcpFillChar(TestOut, SizeOf(TestOut), 0); dcpFillChar(TestOut, SizeOf(TestOut), 0);
TestHash:= TDCP_tiger.Create(nil); TestHash:= TDCP_tiger.Create(nil);
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-'); TestHash.UpdateStr('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)); Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
TestHash.Init; TestHash.Init;
TestHash.UpdateStr('Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham'); TestHash.UpdateStr('Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham');
TestHash.Final(TestOut); TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result; Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
TestHash.Free; TestHash.Free;
end; end;
procedure TDCP_tiger.Init; procedure TDCP_tiger.Init;
begin begin
Burn; Burn;
fInitialized:= true; fInitialized:= true;
CurrentHash[0]:= $0123456789ABCDEF; CurrentHash[0]:= $0123456789ABCDEF;
CurrentHash[1]:= $FEDCBA9876543210; CurrentHash[1]:= $FEDCBA9876543210;
CurrentHash[2]:= $F096A5B4C3B2E187; CurrentHash[2]:= $F096A5B4C3B2E187;
end; end;
procedure TDCP_tiger.Burn; procedure TDCP_tiger.Burn;
begin begin
Len:= 0; Len:= 0;
Index:= 0; Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0); FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0); FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false; fInitialized:= false;
end; end;
procedure TDCP_tiger.Update(const Buffer; Size: longword); procedure TDCP_tiger.Update(const Buffer; Size: longword);
var var
PBuf: ^byte; PBuf: ^byte;
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
Inc(Len,Size*8); Inc(Len,Size*8);
PBuf:= @Buffer; PBuf:= @Buffer;
while Size> 0 do while Size> 0 do
begin begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index); Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index); Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index); Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress; Compress;
end end
else else
begin begin
Move(PBuf^,HashBuffer[Index],Size); Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size); Inc(Index,Size);
Size:= 0; Size:= 0;
end; end;
end; end;
end; end;
procedure TDCP_tiger.Final(var Digest); procedure TDCP_tiger.Final(var Digest);
begin begin
if not fInitialized then if not fInitialized then
raise EDCP_hash.Create('Hash not initialized'); raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $01; HashBuffer[Index]:= $01;
if Index>= 56 then if Index>= 56 then
Compress; Compress;
Pint64(@HashBuffer[56])^:= Len; Pint64(@HashBuffer[56])^:= Len;
Compress; Compress;
Move(CurrentHash,Digest,Sizeof(CurrentHash)); Move(CurrentHash,Digest,Sizeof(CurrentHash));
Burn; Burn;
end; end;
end. end.

View File

@ -1,130 +1,130 @@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
= DCPcrypt Cryptographic Component Library v2 Beta 3 = = DCPcrypt Cryptographic Component Library v2 Beta 3 =
= Copyright (c) 1999-2003 David Barton = = Copyright (c) 1999-2003 David Barton =
= http://www.cityinthesky.co.uk/ = = http://www.cityinthesky.co.uk/ =
= crypto@cityinthesky.co.uk = = crypto@cityinthesky.co.uk =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Introduction: Introduction:
DCPcrypt is a collection of cryptographic components for the Borland DCPcrypt is a collection of cryptographic components for the Borland
Delphi(tm), C++ Builder(tm) and Kylix(tm) programming languages. The Delphi(tm), C++ Builder(tm) and Kylix(tm) programming languages. The
supported versions are Delphi 4, 5, 6, 7, 2005, C++ Builder (3?), 4, supported versions are Delphi 4, 5, 6, 7, 2005, C++ Builder (3?), 4,
5, (6?) and Kylix 1 (untested), 2 and 3 (untested). 5, (6?) and Kylix 1 (untested), 2 and 3 (untested).
Thanks to Manuel C. for the modifications to make DCPcrypt work under Thanks to Manuel C. for the modifications to make DCPcrypt work under
Delphi 2005! Delphi 2005!
The idea behind DCPcrypt is that it should be possible to "drop in" The idea behind DCPcrypt is that it should be possible to "drop in"
any algorithm implementation to replace another with minimum or no any algorithm implementation to replace another with minimum or no
code changes. To aid in this goal all cryptographic components are code changes. To aid in this goal all cryptographic components are
descended from one of several base classes, TDCP_cipher for encryption descended from one of several base classes, TDCP_cipher for encryption
algorithms and TDCP_hash for message digest algorithms. algorithms and TDCP_hash for message digest algorithms.
DCPcrypt is open source software (released under the MIT license) and DCPcrypt is open source software (released under the MIT license) and
as such there is no charge for inclusion in other software. However, I as such there is no charge for inclusion in other software. However, I
am currently a student and if you are making money from my software I am currently a student and if you are making money from my software I
would really appreciate a donation of some sort, whether financial or would really appreciate a donation of some sort, whether financial or
a license for the software you develop (or if anyone wants to sponsor a license for the software you develop (or if anyone wants to sponsor
a Mathematical Modelling (Masters) student for their final year...). a Mathematical Modelling (Masters) student for their final year...).
Please note THIS IS NOT COMPULSORY IN ANY WAY. See Please note THIS IS NOT COMPULSORY IN ANY WAY. See
http://www.cityinthesky.co.uk/cryptography.html for details on http://www.cityinthesky.co.uk/cryptography.html for details on
financial donations. financial donations.
This software is OSI Certified Open Source Software. This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative. OSI Certified is a certification mark of the Open Source Initiative.
If you maintain a website then a link to my page at If you maintain a website then a link to my page at
http://www.cityinthesky.co.uk/ would be great! http://www.cityinthesky.co.uk/ would be great!
What's New: What's New:
Changes since DCPcrypt v2 Beta 2 include Changes since DCPcrypt v2 Beta 2 include
* Corrected C++ Builder compilation problem. * Corrected C++ Builder compilation problem.
Changes since DCPcrypt v2 Beta 1 include Changes since DCPcrypt v2 Beta 1 include
* Renamed source code files for hashes and ciphers to DCPxxx.pas * Renamed source code files for hashes and ciphers to DCPxxx.pas
* Change the format of Cipher.InitStr so that the hash algorithm * Change the format of Cipher.InitStr so that the hash algorithm
used to generate the key is explicitly specified. In order to used to generate the key is explicitly specified. In order to
get the same functionality as before, use TDCP_sha1. get the same functionality as before, use TDCP_sha1.
e.g. Cipher.InitStr('Hello World',TDCP_sha1); e.g. Cipher.InitStr('Hello World',TDCP_sha1);
* Block ciphers are now inherited from an intermediate component * Block ciphers are now inherited from an intermediate component
that implements the block size specific chaining mode encryption that implements the block size specific chaining mode encryption
routines. routines.
* Remove the internal component registration, it was more hassle * Remove the internal component registration, it was more hassle
than it was worth. If there is a demand for this to be put back than it was worth. If there is a demand for this to be put back
then I might... then I might...
* Added the full range of operation modes for Haval. By changing * Added the full range of operation modes for Haval. By changing
the defines at the top of DCPhaval.pas you can specify the the defines at the top of DCPhaval.pas you can specify the
number of passes and the output hash size. number of passes and the output hash size.
* Added the Tiger hash algorithm (192bit digest). * Added the Tiger hash algorithm (192bit digest).
* Changed the name of the file containing TDCP_ripemd160 for * Changed the name of the file containing TDCP_ripemd160 for
consistency to DCPripemd160 from DCPrmd160. consistency to DCPripemd160 from DCPrmd160.
* GOST no longer appears on the component palette pending verifying * GOST no longer appears on the component palette pending verifying
what the actual standard is (the code is still included however). what the actual standard is (the code is still included however).
* Added the RipeMD-128 hash algorithm (128bit digest). * Added the RipeMD-128 hash algorithm (128bit digest).
* Added the Serpent block cipher (AES finalist). * Added the Serpent block cipher (AES finalist).
* Added the SHA-256,384,512 hash algorithms (256, 384, 512bit digest * Added the SHA-256,384,512 hash algorithms (256, 384, 512bit digest
respectively). respectively).
* Added CTR chaining mode to all block ciphers. * Added CTR chaining mode to all block ciphers.
Installation: Installation:
Delphi: Open the appropriate package, DCPdelphiX.dpk where X is Delphi: Open the appropriate package, DCPdelphiX.dpk where X is
your version of Delphi (either 4, 5 or 6). Then press the your version of Delphi (either 4, 5 or 6). Then press the
install button. install button.
C++ Builder: Create a new design time package and add all the .pas C++ Builder: Create a new design time package and add all the .pas
files from the DCPcrypt2.zip archive including all those files from the DCPcrypt2.zip archive including all those
in the Ciphers and Hashes subdirectories. Then press the in the Ciphers and Hashes subdirectories. Then press the
install button. install button.
Kylix: Open the DCPkylix.dpk package and then press the install Kylix: Open the DCPkylix.dpk package and then press the install
button (note: Kylix 1 users may need to create a new button (note: Kylix 1 users may need to create a new
package as with C++ Builder as this is a Kylix 2 package). package as with C++ Builder as this is a Kylix 2 package).
You may need to add the directory containing DCPcrypt (and the Ciphers You may need to add the directory containing DCPcrypt (and the Ciphers
and Hashes subdirectories) to your library search path (found under and Hashes subdirectories) to your library search path (found under
Environment Options). Environment Options).
Once installed you will find two extra pages of components on your Once installed you will find two extra pages of components on your
component palette, namely DCPciphers and DCPhashes. You can now place component palette, namely DCPciphers and DCPhashes. You can now place
these components onto the form of your application to start using the these components onto the form of your application to start using the
algorithms. algorithms.
Usage: Usage:
See the main html documentation in the Docs subdirectory. See the main html documentation in the Docs subdirectory.
Contact: Contact:
I appreciate knowing what DCPcrypt is being used for and also if you I appreciate knowing what DCPcrypt is being used for and also if you
have any queries or bug reports please email me at crypto@cityinthesky.co.uk. have any queries or bug reports please email me at crypto@cityinthesky.co.uk.
DCPcrypt is copyrighted (c) 1999-2003 David Barton. DCPcrypt is copyrighted (c) 1999-2003 David Barton.
All trademarks are property of their respective owners. All trademarks are property of their respective owners.

View File

@ -1,139 +1,139 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* A Base64 encoding/decoding unit ********************************************} {* A Base64 encoding/decoding unit ********************************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPbase64; unit DCPbase64;
interface interface
uses uses
Sysutils; Sysutils;
function Base64EncodeStr(const Value: string): string; function Base64EncodeStr(const Value: string): string;
{ Encode a string into Base64 format } { Encode a string into Base64 format }
function Base64DecodeStr(const Value: string): string; function Base64DecodeStr(const Value: string): string;
{ Decode a Base64 format string } { Decode a Base64 format string }
function Base64Encode(pInput: pointer; pOutput: pointer; Size: longint): longint; function Base64Encode(pInput: pointer; pOutput: pointer; Size: longint): longint;
{ Encode a lump of raw data (output is (4/3) times bigger than input) } { Encode a lump of raw data (output is (4/3) times bigger than input) }
function Base64Decode(pInput: pointer; pOutput: pointer; Size: longint): longint; function Base64Decode(pInput: pointer; pOutput: pointer; Size: longint): longint;
{ Decode a lump of raw data } { Decode a lump of raw data }
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
{$Q-}{$R-} {$Q-}{$R-}
const const
B64: array[0..63] of byte= (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, B64: array[0..63] of byte= (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108, 81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,
109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53, 109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,
54,55,56,57,43,47); 54,55,56,57,43,47);
function Base64Encode(pInput: pointer; pOutput: pointer; Size: longint): longint; function Base64Encode(pInput: pointer; pOutput: pointer; Size: longint): longint;
var var
i, iptr, optr: integer; i, iptr, optr: integer;
Input, Output: PByteArray; Input, Output: PByteArray;
begin begin
Input:= PByteArray(pInput); Output:= PByteArray(pOutput); Input:= PByteArray(pInput); Output:= PByteArray(pOutput);
iptr:= 0; optr:= 0; iptr:= 0; optr:= 0;
for i:= 1 to (Size div 3) do for i:= 1 to (Size div 3) do
begin begin
Output^[optr+0]:= B64[Input^[iptr] shr 2]; Output^[optr+0]:= B64[Input^[iptr] shr 2];
Output^[optr+1]:= B64[((Input^[iptr] and 3) shl 4) + (Input^[iptr+1] shr 4)]; Output^[optr+1]:= B64[((Input^[iptr] and 3) shl 4) + (Input^[iptr+1] shr 4)];
Output^[optr+2]:= B64[((Input^[iptr+1] and 15) shl 2) + (Input^[iptr+2] shr 6)]; Output^[optr+2]:= B64[((Input^[iptr+1] and 15) shl 2) + (Input^[iptr+2] shr 6)];
Output^[optr+3]:= B64[Input^[iptr+2] and 63]; Output^[optr+3]:= B64[Input^[iptr+2] and 63];
Inc(optr,4); Inc(iptr,3); Inc(optr,4); Inc(iptr,3);
end; end;
case (Size mod 3) of case (Size mod 3) of
1: begin 1: begin
Output^[optr+0]:= B64[Input^[iptr] shr 2]; Output^[optr+0]:= B64[Input^[iptr] shr 2];
Output^[optr+1]:= B64[(Input^[iptr] and 3) shl 4]; Output^[optr+1]:= B64[(Input^[iptr] and 3) shl 4];
Output^[optr+2]:= byte('='); Output^[optr+2]:= byte('=');
Output^[optr+3]:= byte('='); Output^[optr+3]:= byte('=');
end; end;
2: begin 2: begin
Output^[optr+0]:= B64[Input^[iptr] shr 2]; Output^[optr+0]:= B64[Input^[iptr] shr 2];
Output^[optr+1]:= B64[((Input^[iptr] and 3) shl 4) + (Input^[iptr+1] shr 4)]; Output^[optr+1]:= B64[((Input^[iptr] and 3) shl 4) + (Input^[iptr+1] shr 4)];
Output^[optr+2]:= B64[(Input^[iptr+1] and 15) shl 2]; Output^[optr+2]:= B64[(Input^[iptr+1] and 15) shl 2];
Output^[optr+3]:= byte('='); Output^[optr+3]:= byte('=');
end; end;
end; end;
Result:= ((Size+2) div 3) * 4; Result:= ((Size+2) div 3) * 4;
end; end;
function Base64EncodeStr(const Value: string): string; function Base64EncodeStr(const Value: string): string;
begin begin
SetLength(Result,((Length(Value)+2) div 3) * 4); SetLength(Result,((Length(Value)+2) div 3) * 4);
Base64Encode(@Value[1],@Result[1],Length(Value)); Base64Encode(@Value[1],@Result[1],Length(Value));
end; end;
function Base64Decode(pInput: pointer; pOutput: pointer; Size: longint): longint; function Base64Decode(pInput: pointer; pOutput: pointer; Size: longint): longint;
var var
i, j, iptr, optr: integer; i, j, iptr, optr: integer;
Temp: array[0..3] of byte; Temp: array[0..3] of byte;
Input, Output: PByteArray; Input, Output: PByteArray;
begin begin
Input:= PByteArray(pInput); Output:= PByteArray(pOutput); Input:= PByteArray(pInput); Output:= PByteArray(pOutput);
iptr:= 0; optr:= 0; iptr:= 0; optr:= 0;
Result:= 0; Result:= 0;
for i:= 1 to (Size div 4) do for i:= 1 to (Size div 4) do
begin begin
for j:= 0 to 3 do for j:= 0 to 3 do
begin begin
case Input^[iptr] of case Input^[iptr] of
65..90 : Temp[j]:= Input^[iptr] - Ord('A'); 65..90 : Temp[j]:= Input^[iptr] - Ord('A');
97..122: Temp[j]:= Input^[iptr] - Ord('a') + 26; 97..122: Temp[j]:= Input^[iptr] - Ord('a') + 26;
48..57 : Temp[j]:= Input^[iptr] - Ord('0') + 52; 48..57 : Temp[j]:= Input^[iptr] - Ord('0') + 52;
43 : Temp[j]:= 62; 43 : Temp[j]:= 62;
47 : Temp[j]:= 63; 47 : Temp[j]:= 63;
61 : Temp[j]:= $FF; 61 : Temp[j]:= $FF;
end; end;
Inc(iptr); Inc(iptr);
end; end;
Output^[optr]:= (Temp[0] shl 2) or (Temp[1] shr 4); Output^[optr]:= (Temp[0] shl 2) or (Temp[1] shr 4);
Result:= optr+1; Result:= optr+1;
if (Temp[2]<> $FF) and (Temp[3]= $FF) then if (Temp[2]<> $FF) and (Temp[3]= $FF) then
begin begin
Output^[optr+1]:= (Temp[1] shl 4) or (Temp[2] shr 2); Output^[optr+1]:= (Temp[1] shl 4) or (Temp[2] shr 2);
Result:= optr+2; Result:= optr+2;
Inc(optr) Inc(optr)
end end
else if (Temp[2]<> $FF) then else if (Temp[2]<> $FF) then
begin begin
Output^[optr+1]:= (Temp[1] shl 4) or (Temp[2] shr 2); Output^[optr+1]:= (Temp[1] shl 4) or (Temp[2] shr 2);
Output^[optr+2]:= (Temp[2] shl 6) or Temp[3]; Output^[optr+2]:= (Temp[2] shl 6) or Temp[3];
Result:= optr+3; Result:= optr+3;
Inc(optr,2); Inc(optr,2);
end; end;
Inc(optr); Inc(optr);
end; end;
end; end;
function Base64DecodeStr(const Value: string): string; function Base64DecodeStr(const Value: string): string;
begin begin
SetLength(Result,(Length(Value) div 4) * 3); SetLength(Result,(Length(Value) div 4) * 3);
SetLength(Result,Base64Decode(@Value[1],@Result[1],Length(Value))); SetLength(Result,Base64Decode(@Value[1],@Result[1],Length(Value)));
end; end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -1,72 +1,72 @@
{******************************************************************************} {******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********} {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************} {******************************************************************************}
{* Constants for use with DCPcrypt ********************************************} {* Constants for use with DCPcrypt ********************************************}
{******************************************************************************} {******************************************************************************}
{* Copyright (c) 1999-2002 David Barton *} {* Copyright (c) 1999-2002 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *} {* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *} {* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *} {* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *} {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *} {* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *} {* Software is furnished to do so, subject to the following conditions: *}
{* *} {* *}
{* The above copyright notice and this permission notice shall be included in *} {* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *} {* all copies or substantial portions of the Software. *}
{* *} {* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *} {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *} {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *} {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *} {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *} {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *} {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *} {* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************} {******************************************************************************}
unit DCPconst; unit DCPconst;
interface interface
{******************************************************************************} {******************************************************************************}
const const
{ Component registration } { Component registration }
DCPcipherpage = 'DCPciphers'; DCPcipherpage = 'DCPciphers';
DCPhashpage = 'DCPhashes'; DCPhashpage = 'DCPhashes';
{ ID values } { ID values }
DCP_rc2 = 1; DCP_rc2 = 1;
DCP_sha1 = 2; DCP_sha1 = 2;
DCP_rc5 = 3; DCP_rc5 = 3;
DCP_rc6 = 4; DCP_rc6 = 4;
DCP_blowfish = 5; DCP_blowfish = 5;
DCP_twofish = 6; DCP_twofish = 6;
DCP_cast128 = 7; DCP_cast128 = 7;
DCP_gost = 8; DCP_gost = 8;
DCP_rijndael = 9; DCP_rijndael = 9;
DCP_ripemd160 = 10; DCP_ripemd160 = 10;
DCP_misty1 = 11; DCP_misty1 = 11;
DCP_idea = 12; DCP_idea = 12;
DCP_mars = 13; DCP_mars = 13;
DCP_haval = 14; DCP_haval = 14;
DCP_cast256 = 15; DCP_cast256 = 15;
DCP_md5 = 16; DCP_md5 = 16;
DCP_md4 = 17; DCP_md4 = 17;
DCP_tiger = 18; DCP_tiger = 18;
DCP_rc4 = 19; DCP_rc4 = 19;
DCP_ice = 20; DCP_ice = 20;
DCP_thinice = 21; DCP_thinice = 21;
DCP_ice2 = 22; DCP_ice2 = 22;
DCP_des = 23; DCP_des = 23;
DCP_3des = 24; DCP_3des = 24;
DCP_tea = 25; DCP_tea = 25;
DCP_serpent = 26; DCP_serpent = 26;
DCP_ripemd128 = 27; DCP_ripemd128 = 27;
DCP_sha256 = 28; DCP_sha256 = 28;
DCP_sha384 = 29; DCP_sha384 = 29;
DCP_sha512 = 30; DCP_sha512 = 30;
{******************************************************************************} {******************************************************************************}
{******************************************************************************} {******************************************************************************}
implementation implementation
end. end.

File diff suppressed because it is too large Load Diff