CryptoTestCiphers.Mod 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. MODULE CryptoTestCiphers; (** AUTHOR "F.N."; PURPOSE "Ciphers Test"; *)
  2. IMPORT
  3. U := CryptoUtils, Ciphers := CryptoCiphers, Kernel, Commands, Out := KernelLog;
  4. PROCEDURE Ecb1*(context : Commands.Context);
  5. VAR
  6. hex, bindata, binkey, modname, orig: ARRAY 64 + 1 OF CHAR; cipher: Ciphers.Cipher;
  7. keybits: LONGINT;
  8. BEGIN
  9. (* read in the parameter *)
  10. context.arg.SkipWhitespace; context.arg.String(modname);
  11. context.arg.SkipWhitespace; context.arg.Int(keybits, FALSE);
  12. (* encryption *)
  13. cipher := Ciphers.NewCipher( modname );
  14. hex := "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
  15. U.Hex2Bin( hex, 0, binkey, 0, keybits DIV 8 ); U.Hex2Bin( hex, 0, bindata, 0, cipher.blockSize );
  16. orig := bindata; orig[cipher.blockSize] := 0X;
  17. cipher.InitKey( binkey, keybits );
  18. Out.Ln; Out.String( "*********************************" );
  19. Out.Ln; Out.String( "Encrypt-Decrypt-Test in ECB-mode: " ); Out.String( cipher.name );
  20. Out.Ln; Out.String( "Key: " ); U.PrintHex( binkey, 0, keybits DIV 8 );
  21. Out.Ln; Out.String( "Original: " ); U.PrintHex( bindata, 0, cipher.blockSize );
  22. cipher.Encrypt( bindata, 0, cipher.blockSize );
  23. Out.Ln; Out.String( "Encrypted: " ); U.PrintHex( bindata, 0, cipher.blockSize );
  24. (* decryption *)
  25. cipher.Decrypt( bindata, 0, cipher.blockSize );
  26. Out.Ln; Out.String( "Decrypted: " ); U.PrintHex( bindata, 0, cipher.blockSize );
  27. bindata[cipher.blockSize] := 0X;
  28. Out.Ln;
  29. IF bindata = orig THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  30. Out.Ln
  31. END Ecb1;
  32. PROCEDURE Cbc1*(context : Commands.Context);
  33. VAR
  34. hex, bindata, binkey, modname, iv, orig: ARRAY 2 * 64 + 1 OF CHAR; cipher: Ciphers.Cipher;
  35. keybits: LONGINT;
  36. BEGIN
  37. (* read in the parameter *)
  38. context.arg.SkipWhitespace; context.arg.String(modname);
  39. context.arg.SkipWhitespace; context.arg.Int(keybits, FALSE);
  40. (* encryption *)
  41. cipher := Ciphers.NewCipher( modname );
  42. hex := "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
  43. U.Hex2Bin( hex, 0, binkey, 0, keybits DIV 8 ); U.Hex2Bin( hex, 0, bindata, 0, 2 * cipher.blockSize );
  44. cipher.InitKey( binkey, keybits );
  45. U.RandomBytes( iv, 0, cipher.blockSize );
  46. (*U.RandomBytes( bindata, 0, cipher.blockSize);*)
  47. cipher.SetIV( iv, Ciphers.CBC );
  48. Out.Ln; Out.String( "*********************************" );
  49. Out.Ln; Out.String( "Encrypt-Decrypt-Test in CBC-mode: " ); Out.String( cipher.name );
  50. Out.Ln; Out.String( "Key: " ); U.PrintHex( binkey, 0, keybits DIV 8 );
  51. Out.Ln; Out.String( "IV: "); U.PrintHex( iv, 0, cipher.blockSize );
  52. Out.Ln; Out.String( "Original: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  53. orig := bindata; orig[2 * cipher.blockSize] := 0X;
  54. cipher.Encrypt( bindata, 0, 2 * cipher.blockSize );
  55. Out.Ln; Out.String( "Encrypted: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  56. (* decryption *)
  57. cipher.SetIV( iv, Ciphers.CBC );
  58. cipher.Decrypt( bindata, 0, 2 * cipher.blockSize );
  59. Out.Ln; Out.String( "Decrypted: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  60. bindata[2 * cipher.blockSize] := 0X;
  61. Out.Ln;
  62. IF bindata = orig THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  63. Out.Ln
  64. END Cbc1;
  65. PROCEDURE Ctr1*(context : Commands.Context);
  66. VAR
  67. hex, bindata, binkey, modname, iv, orig: ARRAY 64 OF CHAR; cipher: Ciphers.Cipher;
  68. keybits: LONGINT;
  69. BEGIN
  70. (* read in the parameter *)
  71. context.arg.SkipWhitespace; context.arg.String(modname);
  72. context.arg.SkipWhitespace; context.arg.Int(keybits, FALSE);
  73. (* encryption *)
  74. cipher := Ciphers.NewCipher( modname );
  75. hex := "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
  76. U.Hex2Bin( hex, 0, binkey, 0, 24 ); (*U.Hex2Bin( hex, 0, bindata, 0, 16 );*)
  77. cipher.InitKey( binkey, keybits );
  78. U.RandomBytes( iv, 0, cipher.blockSize );
  79. U.RandomBytes( bindata, 0, cipher.blockSize);
  80. cipher.SetIV( iv, Ciphers.CTR );
  81. Out.Ln; Out.String( "*********************************" );
  82. Out.Ln; Out.String( "Encrypt-Decrypt-Test in CTR-mode: " ); Out.String( cipher.name );
  83. Out.Ln; Out.String( "Key: " ); U.PrintHex( binkey, 0, keybits DIV 8 );
  84. Out.Ln; Out.String( "Original: " ); U.PrintHex( bindata, 0, 16 );
  85. orig := bindata; orig[16] := 0X;
  86. cipher.Encrypt( bindata, 0, 16 );
  87. Out.Ln; Out.String( "Encrypted: " ); U.PrintHex( bindata, 0, 16 );
  88. (* decryption *)
  89. cipher.InitKey( binkey, keybits );
  90. cipher.SetIV( iv, Ciphers.CTR );
  91. cipher.Decrypt( bindata, 0, 16 );
  92. Out.Ln; Out.String( "Decrypted: " ); U.PrintHex( bindata, 0, 16 );
  93. bindata[16] := 0X;
  94. Out.Ln;
  95. IF bindata = orig THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  96. Out.Ln
  97. END Ctr1;
  98. (** encrypt input with key (ebc-mode). output is a testvector *)
  99. PROCEDURE Ecb2*( CONST modname, input, output, key: ARRAY OF CHAR; datalen, keybits: LONGINT );
  100. VAR
  101. cipher: Ciphers.Cipher;
  102. temp1, temp2: ARRAY 256 OF CHAR;
  103. BEGIN
  104. cipher := Ciphers.NewCipher( modname );
  105. U.Hex2Bin( key, 0, temp1, 0, keybits DIV 8 );
  106. cipher.InitKey( temp1, keybits );
  107. Out.Ln; Out.String( "*********************************" );
  108. Out.Ln; Out.String( "Encryption-Test: " ); Out.String( cipher.name );
  109. Out.Ln; Out.String( "Key: " ); U.PrintHex( temp1, 0, keybits DIV 8 );
  110. U.Hex2Bin( input, 0, temp1, 0, datalen );
  111. Out.Ln; Out.String( "plaintext: " ); U.PrintHex( temp1, 0, datalen );
  112. cipher.Encrypt( temp1, 0, datalen );
  113. Out.Ln; Out.String( "encryption: " ); U.PrintHex( temp1, 0, datalen );
  114. U.Hex2Bin( output, 0, temp2, 0, datalen );
  115. Out.Ln; Out.String( "correct encryption: " ); U.PrintHex( temp2, 0, datalen );
  116. Out.Ln;
  117. temp1[datalen] := 0X; temp2[datalen] := 0X;
  118. IF temp1 = temp2 THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  119. Out.Ln
  120. END Ecb2;
  121. (** encrypt input with key (cbc-mode). output is a testvector *)
  122. PROCEDURE Cbc2*( CONST modname, input, output, key, iv: ARRAY OF CHAR; datalen, keybits: LONGINT );
  123. VAR
  124. cipher: Ciphers.Cipher;
  125. temp1, temp2: ARRAY 64 OF CHAR;
  126. BEGIN
  127. cipher := Ciphers.NewCipher( modname );
  128. U.Hex2Bin( key, 0, temp1, 0, keybits DIV 8 );
  129. cipher.InitKey( temp1, keybits );
  130. U.Hex2Bin( iv, 0, temp2, 0, cipher.blockSize );
  131. cipher.SetIV( temp2, Ciphers.CBC );
  132. Out.Ln; Out.String( "*********************************" );
  133. Out.Ln; Out.String( "Encryption-Test: " ); Out.String( cipher.name );
  134. Out.Ln; Out.String( "Key: " ); U.PrintHex( temp1, 0, keybits DIV 8 );
  135. U.Hex2Bin( input, 0, temp1, 0, datalen );
  136. Out.Ln; Out.String( "plaintext: " ); U.PrintHex( temp1, 0, datalen );
  137. cipher.Encrypt( temp1, 0, datalen );
  138. Out.Ln; Out.String( "encryption: " ); U.PrintHex( temp1, 0, datalen );
  139. U.Hex2Bin( output, 0, temp2, 0, datalen );
  140. Out.Ln; Out.String( "correct encryption: " ); U.PrintHex( temp2, 0, datalen );
  141. Out.Ln;
  142. temp1[datalen] := 0X; temp2[datalen] := 0X;
  143. IF temp1 = temp2 THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  144. Out.Ln
  145. END Cbc2;
  146. (** decrypt input with key (cbc-mode). output is a testvector *)
  147. PROCEDURE DecryptCbc2*(CONST modname, input, output, key, iv: ARRAY OF CHAR; datalen, keybits: LONGINT);
  148. VAR
  149. cipher: Ciphers.Cipher;
  150. temp1, temp2: ARRAY 64 OF CHAR;
  151. BEGIN
  152. cipher := Ciphers.NewCipher( modname );
  153. U.Hex2Bin( key, 0, temp1, 0, keybits DIV 8 );
  154. cipher.InitKey( temp1, keybits );
  155. U.Hex2Bin( iv, 0, temp2, 0, cipher.blockSize );
  156. cipher.SetIV( temp2, Ciphers.CBC );
  157. Out.Ln; Out.String( "*********************************" );
  158. Out.Ln; Out.String( "Decryption-Test: " ); Out.String( cipher.name );
  159. Out.Ln; Out.String( "Key: " ); U.PrintHex( temp1, 0, keybits DIV 8 );
  160. U.Hex2Bin( input, 0, temp1, 0, datalen );
  161. Out.Ln; Out.String( "ciphertext: " ); U.PrintHex( temp1, 0, datalen );
  162. cipher.Encrypt( temp1, 0, datalen );
  163. Out.Ln; Out.String( "decryption: " ); U.PrintHex( temp1, 0, datalen );
  164. U.Hex2Bin( output, 0, temp2, 0, datalen );
  165. Out.Ln; Out.String( "correct decryption: " ); U.PrintHex( temp2, 0, datalen );
  166. Out.Ln;
  167. temp1[datalen] := 0X; temp2[datalen] := 0X;
  168. IF temp1 = temp2 THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  169. Out.Ln
  170. END DecryptCbc2;
  171. (** encrypt input with key (counter-mode). output is a testvector *)
  172. PROCEDURE Ctr2*( CONST modname, input, output, key, iv: ARRAY OF CHAR; datalen, keybits: LONGINT );
  173. VAR
  174. cipher: Ciphers.Cipher;
  175. temp1, temp2: ARRAY 64 OF CHAR;
  176. BEGIN
  177. cipher := Ciphers.NewCipher( modname );
  178. U.Hex2Bin( key, 0, temp1, 0, keybits DIV 8 );
  179. cipher.InitKey( temp1, keybits );
  180. U.Hex2Bin( iv, 0, temp2, 0, cipher.blockSize );
  181. cipher.SetIV( temp2, Ciphers.CTR );
  182. Out.Ln; Out.String( "*********************************" );
  183. Out.Ln; Out.String( "Encryption-Test: " ); Out.String( cipher.name );
  184. Out.Ln; Out.String( "Key: " ); U.PrintHex( temp1, 0, keybits DIV 8 );
  185. U.Hex2Bin( input, 0, temp1, 0, datalen );
  186. Out.Ln; Out.String( "plaintext: " ); U.PrintHex( temp1, 0, datalen );
  187. cipher.Encrypt( temp1, 0, datalen );
  188. Out.Ln; Out.String( "encryption: " ); U.PrintHex( temp1, 0, datalen );
  189. U.Hex2Bin( output, 0, temp2, 0, datalen );
  190. Out.Ln; Out.String( "correct encryption: " ); U.PrintHex( temp2, 0, datalen );
  191. Out.Ln;
  192. temp1[datalen] := 0X; temp2[datalen] := 0X;
  193. IF temp1 = temp2 THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  194. Out.Ln
  195. END Ctr2;
  196. PROCEDURE MeasureTime*(context : Commands.Context);
  197. VAR
  198. buf, key: ARRAY 1024 OF CHAR;
  199. milliTimer : Kernel.MilliTimer;
  200. i, j, k, t, keybits: LONGINT;
  201. c: Ciphers.Cipher;
  202. modname, mode, iv: ARRAY 64 OF CHAR;
  203. BEGIN
  204. (* read in the parameter *)
  205. context.arg.SkipWhitespace; context.arg.String(modname);
  206. context.arg.SkipWhitespace; context.arg.String(mode);
  207. context.arg.SkipWhitespace; context.arg.Int(keybits, FALSE);
  208. (* measure time *)
  209. FOR i := 0 TO 1023 DO buf[i] := 'a' END;
  210. c := Ciphers.NewCipher( modname );
  211. c.InitKey( key, keybits );
  212. IF mode = "CBC" THEN c.SetIV( iv, Ciphers.CBC ) END;
  213. Out.Ln; Out.String( "***********************************" );
  214. Out.Ln; Out.String( "Encrypting 100 MB with " ); Out.String( c.name );
  215. Kernel.SetTimer(milliTimer, 0);
  216. FOR k := 0 TO 9 DO
  217. Out.String( "." );
  218. FOR j := 0 TO 9 DO
  219. FOR i := 0 TO 999 DO c.Encrypt( buf, 0, 1024 ) END(* 100 MB data *)
  220. END
  221. END;
  222. t := Kernel.Elapsed(milliTimer);
  223. Out.Int( t, 4 ); Out.String( " ms" ); Out.Ln;
  224. END MeasureTime;
  225. PROCEDURE DesEcb2*;
  226. VAR input, output, key: ARRAY 64 OF CHAR;
  227. BEGIN
  228. key := "0123456789ABCDEF";
  229. input := "4E6F772069732074"; output := "3FA40E8A984D4815";
  230. Ecb2( "CryptoDES", input, output, key, 8, 64 );
  231. END DesEcb2;
  232. PROCEDURE Des3Ecb2*;
  233. VAR input, output, key: ARRAY 64 OF CHAR;
  234. BEGIN
  235. key := "0123456789ABCDEF23456789ABCDEF01456789ABCDEF0123";
  236. input := "4E6F772069732074"; output := "314F8327FA7A09A8";
  237. Ecb2( "CryptoDES3", input, output, key, 8, 192 );
  238. END Des3Ecb2;
  239. PROCEDURE IdeaEcb2*;
  240. VAR input, output, key: ARRAY 64 OF CHAR;
  241. BEGIN
  242. key := "00010002000300040005000600070008";
  243. input := "0000000100020003"; output := "11FBED2B01986DE5";
  244. Ecb2( "CryptoIDEA", input, output, key, 8, 128 );
  245. END IdeaEcb2;
  246. PROCEDURE AesEcb2*;
  247. VAR input, output, key: ARRAY 128 OF CHAR;
  248. BEGIN
  249. key := "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b";
  250. input := "6bc1bee22e409f96e93d7e117393172a";
  251. output := "bd334f1d6e45f25ff712a214571fa5cc";
  252. Ecb2( "CryptoAES", input, output, key, 16, 192 );
  253. key := "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4";
  254. input := "6bc1bee22e409f96e93d7e117393172a";
  255. output := "f3eed1bdb5d2a03c064b5a7e3db181f8";
  256. Ecb2( "CryptoAES", input, output, key, 16, 256 );
  257. END AesEcb2;
  258. PROCEDURE Arc4Ecb2*;
  259. VAR input, output, key: ARRAY 64 OF CHAR;
  260. BEGIN
  261. key := "0123456789abcdef";
  262. input := "0123456789abcdef"; output := "75b7878099e0c596";
  263. Ecb2( "CryptoARC4", input, output, key, 8, 64 );
  264. END Arc4Ecb2;
  265. PROCEDURE CastEcb2*;
  266. VAR input, output, key: ARRAY 64 OF CHAR;
  267. BEGIN
  268. key := "0123456712345678234567893456789A";
  269. input := "0123456789abcdef"; output := "238B4FE5847E44B2";
  270. Ecb2( "CryptoCAST", input, output, key, 8, 128 );
  271. output := "EB6A711A2C02271B";
  272. Ecb2( "CryptoCAST", input, output, key, 8, 80 );
  273. output := "7AC816D16E9B302E";
  274. Ecb2( "CryptoCAST", input, output, key, 8, 40 );
  275. END CastEcb2;
  276. PROCEDURE DesCbc2*;
  277. VAR input, output, key, iv: ARRAY 64 OF CHAR;
  278. BEGIN
  279. key := "0123456789ABCDEF";
  280. iv := "0123456789ABCDEF";
  281. input := "4E6F772069732074"; output := "96C3D4A6DC1C0117";
  282. Cbc2( "CryptoDES", input, output, key, iv, 8, 64 );
  283. END DesCbc2;
  284. PROCEDURE IdeaCbc2*;
  285. VAR input, output, key, iv: ARRAY 64 OF CHAR;
  286. BEGIN
  287. key := "00010002000300040005000600070008";
  288. iv := "0000000000000000";
  289. input := "0000000100020003"; output := "11FBED2B01986DE5";
  290. Cbc2( "CryptoIDEA", input, output, key, iv, 8, 128 );
  291. END IdeaCbc2;
  292. PROCEDURE AesCbc2*;
  293. VAR input, output, key, iv: ARRAY 256 OF CHAR;
  294. BEGIN
  295. key := "2b7e151628aed2a6abf7158809cf4f3c";
  296. iv := "000102030405060708090A0B0C0D0E0F";
  297. input := "6bc1bee22e409f96e93d7e117393172a";
  298. output := "7649abac8119b246cee98e9b12e9197d";
  299. Cbc2( "CryptoAES", input, output, key, iv, 16, 128 );
  300. key := "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4";
  301. iv := "000102030405060708090A0B0C0D0E0F";
  302. input := "6bc1bee22e409f96e93d7e117393172a";
  303. output := "f58c4c04d6e5f1ba779eabfb5f7bfbd6";
  304. Cbc2( "CryptoAES", input, output, key, iv, 16, 256 );
  305. key := "2b7e151628aed2a6abf7158809cf4f3c";
  306. iv := "000102030405060708090A0B0C0D0E0F";
  307. output := "6bc1bee22e409f96e93d7e117393172a";
  308. input := "7649abac8119b246cee98e9b12e9197d";
  309. DecryptCbc2( "CryptoAES", input, output, key, iv, 16, 128 );
  310. key := "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4";
  311. iv := "000102030405060708090A0B0C0D0E0F";
  312. output := "6bc1bee22e409f96e93d7e117393172a";
  313. input := "f58c4c04d6e5f1ba779eabfb5f7bfbd6";
  314. DecryptCbc2( "CryptoAES", input, output, key, iv, 16, 256 );
  315. END AesCbc2;
  316. PROCEDURE AesCtr2*;
  317. VAR input, output, key, iv: ARRAY 256 OF CHAR;
  318. BEGIN
  319. key := "2b7e151628aed2a6abf7158809cf4f3c";
  320. iv := "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
  321. input := "6bc1bee22e409f96e93d7e117393172a";
  322. output := "874d6191b620e3261bef6864990db6ce";
  323. Ctr2( "CryptoAES", input, output, key, iv, 16, 128 );
  324. key := "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4";
  325. iv := "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
  326. input := "6bc1bee22e409f96e93d7e117393172a";
  327. output := "601ec313775789a5b7a7f504bbf3d228";
  328. Ctr2( "CryptoAES", input, output, key, iv, 16, 256 );
  329. END AesCtr2;
  330. PROCEDURE CbcRandom*(context : Commands.Context);
  331. VAR
  332. bindata, binkey, modname, iv, orig: ARRAY 2 * 64 + 1 OF CHAR; cipher: Ciphers.Cipher;
  333. keybits: LONGINT;
  334. BEGIN
  335. (* read in the parameter *)
  336. context.arg.SkipWhitespace; context.arg.String(modname);
  337. context.arg.SkipWhitespace; context.arg.Int(keybits, FALSE);
  338. (* encryption *)
  339. cipher := Ciphers.NewCipher( modname );
  340. U.RandomBytes(binkey, 0, keybits DIV 8);
  341. U.RandomBytes(bindata, 0, 2 * cipher.blockSize); (* test data at least 2 blocks to test CBC *)
  342. cipher.InitKey( binkey, keybits );
  343. U.RandomBytes( iv, 0, cipher.blockSize );
  344. (*U.RandomBytes( bindata, 0, cipher.blockSize);*)
  345. cipher.SetIV( iv, Ciphers.CBC );
  346. Out.Ln; Out.String( "*********************************" );
  347. Out.Ln; Out.String( "Encrypt-Decrypt-Test in CBC-mode: " ); Out.String( cipher.name );
  348. Out.Ln; Out.String( "Key: " ); U.PrintHex( binkey, 0, keybits DIV 8 );
  349. Out.Ln; Out.String( "IV: "); U.PrintHex( iv, 0, cipher.blockSize );
  350. Out.Ln; Out.String( "Original: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  351. orig := bindata; orig[2 * cipher.blockSize] := 0X;
  352. cipher.Encrypt( bindata, 0, 2 * cipher.blockSize );
  353. Out.Ln; Out.String( "Encrypted: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  354. (* decryption *)
  355. cipher.SetIV( iv, Ciphers.CBC );
  356. cipher.Decrypt( bindata, 0, 2 * cipher.blockSize );
  357. Out.Ln; Out.String( "Decrypted: " ); U.PrintHex( bindata, 0, 2 * cipher.blockSize );
  358. bindata[2 * cipher.blockSize] := 0X;
  359. Out.Ln;
  360. IF bindata = orig THEN Out.String( "OK" ) ELSE Out.String( "FAIL" ) END;
  361. Out.Ln
  362. END CbcRandom;
  363. END CryptoTestCiphers.
  364. SystemTools.Free
  365. CryptoTestCiphers CryptoDES3 CryptoDES CryptoIDEA
  366. CryptoARC4 CryptoCAST CryptoAES ~
  367. CryptoTestCiphers.DesEcb2 ~
  368. CryptoTestCiphers.Des3Ecb2 ~
  369. CryptoTestCiphers.IdeaEcb2 ~
  370. CryptoTestCiphers.Arc4Ecb2 ~
  371. CryptoTestCiphers.BlowfishEcb2 ~
  372. CryptoTestCiphers.TwofishEcb2 ~
  373. CryptoTestCiphers.CastEcb2 ~
  374. CryptoTestCiphers.AesEcb2 ~
  375. CryptoTestCiphers.DesCbc2 ~
  376. CryptoTestCiphers.IdeaCbc2 ~
  377. CryptoTestCiphers.AesCbc2 ~
  378. CryptoTestCiphers.AesCtr2 ~
  379. CryptoTestCiphers.Ecb1 CryptoDES 64 ~
  380. CryptoTestCiphers.Ecb1 CryptoDES3 192 ~
  381. CryptoTestCiphers.Ecb1 CryptoIDEA 128 ~
  382. CryptoTestCiphers.Ecb1 CryptoARC4 128 ~
  383. CryptoTestCiphers.Ecb1 CryptoCAST 128 ~
  384. CryptoTestCiphers.Ecb1 CryptoAES 128 ~
  385. CryptoTestCiphers.Ecb1 CryptoAES 256 ~
  386. CryptoTestCiphers.Ecb1 CryptoBlowfish 256 ~
  387. CryptoTestCiphers.Cbc1 CryptoDES 64 ~
  388. CryptoTestCiphers.Cbc1 CryptoDES3 192 ~
  389. CryptoTestCiphers.Cbc1 CryptoIDEA 128 ~
  390. CryptoTestCiphers.Cbc1 CryptoAES 128 ~
  391. CryptoTestCiphers.Cbc1 CryptoAES 256 ~
  392. CryptoTestCiphers.Cbc1 CryptoBlowfish 256 ~
  393. CryptoTestCiphers.CbcRandom CryptoDES 64 ~
  394. CryptoTestCiphers.CbcRandom CryptoDES3 192 ~
  395. CryptoTestCiphers.CbcRandom CryptoIDEA 128 ~
  396. CryptoTestCiphers.CbcRandom CryptoAES 128 ~
  397. CryptoTestCiphers.CbcRandom CryptoAES 256 ~
  398. CryptoTestCiphers.CbcRandom CryptoBlowfish 256 ~
  399. CryptoTestCiphers.Ctr1 CryptoAES 128 ~
  400. CryptoTestCiphers.Ctr1 CryptoAES 256 ~
  401. CryptoTestCiphers.MeasureTime CryptoDES ECB 64 ~
  402. CryptoTestCiphers.MeasureTime CryptoDES CBC 64 ~
  403. CryptoTestCiphers.MeasureTime CryptoDES3 ECB 192 ~
  404. CryptoTestCiphers.MeasureTime CryptoDES3 CBC 192 ~
  405. CryptoTestCiphers.MeasureTime CryptoAES ECB 128 ~
  406. CryptoTestCiphers.MeasureTime CryptoAES CBC 128 ~
  407. CryptoTestCiphers.MeasureTime CryptoIDEA ECB 128 ~
  408. CryptoTestCiphers.MeasureTime CryptoIDEA CBC 128 ~
  409. CryptoTestCiphers.MeasureTime CryptoARC4 ECB 128 ~