| 1160 | }; |
| 1161 | |
| 1162 | bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &valdata, unsigned int tuples = 0xffff) |
| 1163 | { |
| 1164 | HexEncoder output(new FileSink(cout)); |
| 1165 | SecByteBlock plain(cg.BlockSize()), cipher(cg.BlockSize()), out(cg.BlockSize()), outplain(cg.BlockSize()); |
| 1166 | SecByteBlock key(cg.KeyLength()); |
| 1167 | bool pass=true, fail; |
| 1168 | |
| 1169 | while (valdata.MaxRetrievable() && tuples--) |
| 1170 | { |
| 1171 | valdata.Get(key, cg.KeyLength()); |
| 1172 | valdata.Get(plain, cg.BlockSize()); |
| 1173 | valdata.Get(cipher, cg.BlockSize()); |
| 1174 | |
| 1175 | member_ptr<BlockTransformation> transE(cg.NewEncryption(key)); |
| 1176 | transE->ProcessBlock(plain, out); |
| 1177 | fail = memcmp(out, cipher, cg.BlockSize()) != 0; |
| 1178 | |
| 1179 | member_ptr<BlockTransformation> transD(cg.NewDecryption(key)); |
| 1180 | transD->ProcessBlock(out, outplain); |
| 1181 | fail=fail || memcmp(outplain, plain, cg.BlockSize()); |
| 1182 | |
| 1183 | pass = pass && !fail; |
| 1184 | |
| 1185 | cout << (fail ? "FAILED " : "passed "); |
| 1186 | output.Put(key, cg.KeyLength()); |
| 1187 | cout << " "; |
| 1188 | output.Put(outplain, cg.BlockSize()); |
| 1189 | cout << " "; |
| 1190 | output.Put(out, cg.BlockSize()); |
| 1191 | cout << endl; |
| 1192 | } |
| 1193 | return pass; |
| 1194 | } |
| 1195 | |
| 1196 | class FilterTester : public Unflushable<Sink> |
| 1197 | { |
no test coverage detected