CryptoTestCiphers.Mod 18 KB

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