diff options
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/eax_test.cpp | 249 | ||||
-rw-r--r-- | doc/examples/eax_vecs.txt | 461 | ||||
-rw-r--r-- | doc/examples/row_encryptor.cpp | 171 |
3 files changed, 0 insertions, 881 deletions
diff --git a/doc/examples/eax_test.cpp b/doc/examples/eax_test.cpp deleted file mode 100644 index 228ece286..000000000 --- a/doc/examples/eax_test.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <fstream> -#include <iostream> -#include <sstream> -#include <boost/regex.hpp> - -#include <botan/botan.h> -#include <botan/eax.h> - -using namespace Botan; - -namespace { - -unsigned from_string(const std::string& s) - { - std::istringstream stream(s); - unsigned n; - stream >> n; - return n; - } - -std::string seq(unsigned n) - { - std::string s; - - for(unsigned i = 0; i != n; ++i) - { - unsigned char b = (i & 0xFF); - - const char bin2hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - - s += bin2hex[(b >> 4)]; - s += bin2hex[(b & 0x0f)]; - } - - return s; - } - -void eax_test(const std::string& algo, - const std::string& key_str, - const std::string& nonce_str, - const std::string& header_str, - const std::string& tag_str, - const std::string& plaintext_str, - const std::string& ciphertext) - { - /* - printf("EAX(algo=%s key=%s nonce=%s header=%s tag=%s pt=%s ct=%s)\n", - algo.c_str(), key_str.c_str(), nonce_str.c_str(), header_str.c_str(), tag_str.c_str(), - plaintext_str.c_str(), ciphertext.c_str()); - */ - - SymmetricKey key(key_str); - InitializationVector iv(nonce_str); - - EAX_Encryption* enc; - - Pipe pipe(new Hex_Decoder, - enc = new EAX_Encryption(get_block_cipher(algo)), - new Hex_Encoder); - - enc->set_key(key); - enc->set_iv(iv); - - OctetString header(header_str); - - enc->set_header(header.begin(), header.length()); - - pipe.start_msg(); - pipe.write(plaintext_str); - pipe.end_msg(); - - std::string out = pipe.read_all_as_string(); - - if(out != ciphertext + tag_str) - { - printf("BAD enc %s '%s' != '%s%s'\n", algo.c_str(), - out.c_str(), ciphertext.c_str(), tag_str.c_str()); - } - else - printf("OK enc %s\n", algo.c_str()); - - try - { - EAX_Decryption* dec; - Pipe pipe2(new Hex_Decoder, - dec = new EAX_Decryption(get_block_cipher(algo)), - new Hex_Encoder); - - dec->set_key(key); - dec->set_iv(iv); - - dec->set_header(header.begin(), header.length()); - - pipe2.start_msg(); - pipe2.write(ciphertext); - pipe2.write(tag_str); - pipe2.end_msg(); - - std::string out2 = pipe2.read_all_as_string(); - - if(out2 != plaintext_str) - { - printf("BAD decrypt %s '%s'\n", algo.c_str(), out2.c_str()); - } - else - printf("OK decrypt %s\n", algo.c_str()); - } - catch(std::exception& e) - { - printf("%s\n", e.what()); - } - - } - -std::pair<std::string, int> translate_algo(const std::string& in) - { - if(in == "aes (16 byte key)") - return std::make_pair("AES-128", 16); - - if(in == "blowfish (8 byte key)") - return std::make_pair("Blowfish", 8); - - if(in == "rc2 (8 byte key)") - return std::make_pair("RC2", 8); - - if(in == "rc5 (8 byte key)") - return std::make_pair("RC5", 8); - - if(in == "rc6 (16 byte key)") - return std::make_pair("RC6", 16); - - if(in == "safer-sk128 (16 byte key)") - return std::make_pair("SAFER-SK(10)", 16); - - if(in == "twofish (16 byte key)") - return std::make_pair("Twofish", 16); - - if(in == "des (8 byte key)") - return std::make_pair("DES", 8); - - if(in == "3des (24 byte key)") - return std::make_pair("TripleDES", 24); - - // These 3 are disabled due to differences in base algorithm. - -#if 0 - // XTEA: LTC uses little endian, Botan (and Crypto++) use big-endian - // I swapped to LE in XTEA and the vectors did match - if(in == "xtea (16 byte key)") - return std::make_pair("XTEA", 16); - - // Skipjack: LTC uses big-endian, Botan (and Crypto++) use - // little-endian I am not sure if that was the full difference - // though, was unable to replicate LTC's EAX vectors with Skipjack - if(in == "skipjack (10 byte key)") - return std::make_pair("Skipjack", 10); - - // Noekeon: uses direct keying instead of indirect - if(in == "noekeon (16 byte key)") - return std::make_pair("Noekeon", 16); - -#endif - - return std::make_pair("", 0); - } - -std::string rep(const std::string& s_in, unsigned n) - { - std::string s_out; - - for(unsigned i = 0; i != n; ++i) - s_out += s_in[i % s_in.size()]; - - return s_out; - } - -void run_tests(std::istream& in) - { - std::string algo; - std::string key; - - while(in.good()) - { - std::string line; - - std::getline(in, line); - - if(line == "") - continue; - - if(line.size() > 5 && line.substr(0, 4) == "EAX-") - { - std::pair<std::string, int> name_and_keylen = - translate_algo(line.substr(4)); - - algo = name_and_keylen.first; - key = seq(name_and_keylen.second); - } - else if(algo != "") - { - boost::regex vec_regex("^([ 0-9]{3}): (.*), (.*)$"); - - boost::smatch what; - - if(boost::regex_match(line, what, vec_regex, boost::match_extra)) - { - unsigned n = from_string(what[1]); - std::string ciphertext = what[2]; - std::string tag = what[3]; - - std::string plaintext = seq(n); - std::string header = seq(n); - std::string nonce = seq(n); - - eax_test(algo, key, nonce, header, tag, - plaintext, ciphertext); - - key = rep(tag, key.size()); // repeat as needed - } - } - } - - - } - -} - -int main() - { - std::ifstream in("eax_vecs.txt"); - - Botan::LibraryInitializer init; - - if(!in) - { - std::cerr << "Couldn't read input file\n"; - return 1; - } - - run_tests(in); - - } diff --git a/doc/examples/eax_vecs.txt b/doc/examples/eax_vecs.txt deleted file mode 100644 index 95cd7c1ab..000000000 --- a/doc/examples/eax_vecs.txt +++ /dev/null @@ -1,461 +0,0 @@ -EAX Test Vectors. Uses the 00010203...NN-1 pattern for header/nonce/plaintext/key. The outputs -are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous -step repeated sufficiently. - -EAX-aes (16 byte key) - 0: , 9AD07E7DBFF301F505DE596B9615DFFF - 1: 47, 57C4AC75A42D05260AFA093ACD4499ED - 2: C4E2, 26C5AB00325306772E6F6E4C8093F3D2 - 3: 16177B, 852260F91F27898D4FC176E311F6E1D1 - 4: F09F68BE, 700766CA231643B5D60C3B91B1B700C1 - 5: 8472705EDF, AC4C3359326EEA4CF71FC03E0E0292F2 - 6: 14C25EB5FD0D, 8DBD749CA79CCF11C1B370F8C975858C - 7: F6A37F60670A85, AFBD1D5921557187504ADE61014C9622 - 8: 1AACFEAE8FBAD833, 82F477325D6F76BB81940AE25F9801C2 - 9: 069414324EC293697C, B980E21C09CA129B69E9032D980A9DC5 - 10: D8174DE9A2FC92B7DA9C, 1E42CC58BA2C8BFD83806444EA29DB61 - 11: 2C087DEA30F8B7EE510990, 83DB400A080C4D43CAA6EC3F1085A923 - 12: F36B93C272A703D3422C6A11, 1370C3AF2F3392916364BBBCC2C62EC1 - 13: A0F33477BAE2E28E6747AA3193, B626DC719528CAC65DB0EF94E35422CE - 14: FCF5193506052E8BFA095C1A5205, F5BD02E0B3C91CC7D6FAAA8A9A76CE6A - 15: 3797D7F8599B8EEAB39C56241880DC, 0B70003E77146B903F06EF294FECD517 - 16: C4BAD0E0356FFD369110C048D45D81BE, DE7C2B1D83BE2CC8EA402ABE1038BB79 - 17: AF5C358BD31CDCAC2F0EA5252F1C3BE1E4, 2D700986F93B22DFE6695C2A243B4E42 - 18: 7DEF9056FBDAF491D7206B26B19DEF617AA1, E71A7D00BE972D85C77931D7591B2151 - 19: 6E9B2C0A90BF9D38A6EA3B5D2B9B2D97F938EB, 5B483D7F15C39602C2918181E57DA341 - 20: 7C5F68DEE9BBA3B04F11D5FC7C9C7FE6E8B5025C, 0AE6A12D37A9C10BB1A494E16705DC05 - 21: AF0A886BF673BC72045FC074F06A0176C96105E2E6, 06B2DC9A2868C23F86D710E01E37E07B - 22: 5F228A986DFE4301EDBAF07A02E114F1B30932995CD1, 74EBF68627C78B1FD024A59B56B2A8FA - 23: 911322F60555118CBECD8DD82F186AC19514316E8D48BA, B6A8BAF2F175CD0C71B63B1EF37E185E - 24: E7F52730CFB808EFDB376A5D5DF31A7EF8292DC5FC37E9BC, BA2AD158A2D2E5CE01296402B592E1DB - 25: B3F8D7CA47D8D86E94D670AFBAFA3B8D9E186C97DC029D4705, 709D2D2B9975D4729C19D4EAC430E65E - 26: 7178FEC027AFADDC2C03518E75CF34D207CAC2EB1537A0DBA520, A315F034CE5E66601444402520F55DE2 - 27: FC230B2B8522F53459D0B968421469BBA7E683ACB0190393B2870F, 48679A78E470E175CF3D3E9B46CEDFCE - 28: 35A641127C78C721ECDC50866C21637FDC9515E41CE60F09015EA713, 0062987222F6412B7AAF8A9ABF6FBF98 - 29: 3D42D6C113421743C08A6F682CFA0E517D5531BB66241C02EC4DCC26F7, B1AAFE11FA2D6E0C870177DDD7F98FF0 - 30: DAD065B4669B7C59C8392D8E7BD7E64BC01CEFFF27E335B25A328D356F0E, 8973B9B9ECF26DAB58CCF0787EE928E5 - 31: EBE626F9E241FD233D9781C359430C982667AA26921B62E98FAEC502C01B0B, 2AC0D7052A2CDCCE8E26FEA7595198AA - 32: 64D842B66796A797C2B4C6905742FDF2148FFC445E192F9E03B53810C082F788, 9778B345EC12D222DCC6DBABD2651750 - -EAX-blowfish (8 byte key) - 0: , D8C4C23A6AC0B7B7 - 1: 2A, 5E0E4BDDB60772FB - 2: 7695, 7581B16CCC9C45F1 - 3: EB14C8, 6223A121CFA216C7 - 4: 5A5C809C, 4A47658796337D6A - 5: 8BC2041181, E1FBA8DBA00571FC - 6: 89C666F015FA, 2B4A76A0E699FCFE - 7: 86C1FA92484AF6, 31B3B738A261D6F5 - 8: D1F401C145C9328B, 4C4A045EB489F59C - 9: 70C9C7753698324A73, AB298B5B20567EB4 - 10: A50D9D88DC101B6DC8D2, 529DFCBFD13B8E6C - 11: 7CC2885C2BE79C44F28FF2, 566255022B40C81C - 12: 6902D58347C29250EE07981C, 34619AF18E14C690 - 13: AB6C3C4AD3EC45143392B642DA, E6D2DD323DA175BB - 14: 7065B28BA8AB67B2FB7B6D5E3FAF, AEDCAA54F4B0772F - 15: CBBA14A74AD4ADC0EF036EDAE42D51, F2BFFA4D81BAC034 - 16: 60A315193F58144F5701D547C79FEEED, 912FDBDB05467DF5 - -EAX-xtea (16 byte key) - 0: , 86881D824E3BC561 - 1: EE, 4C3505F04611D9C2 - 2: 80C8, 6A3428BEEAD60738 - 3: BF88E7, 04F1E99E9F5906C2 - 4: E06574B7, 33B0153AAEF9776F - 5: 42D950AF63, 4A0F415640322FDF - 6: C30F6AD46EC9, 9646FE909D2B95CB - 7: A0049FCA856A14, A0257289C6BBF278 - 8: 2814B0C1358440E0, C4B0A2354925E887 - 9: BF4F062B52C1E489CF, B56442A3CA57A041 - 10: 63DF433956831B8780FC, ADF9ED0B46DCA19E - 11: C317FD079817F50E0E8A16, 2EA0EC993FC603AE - 12: 2BD12FDDD81EB11660346D2A, FBC6F69125BBA88D - 13: 85D356536FE2843C6BBE60EDBC, BB2FEFD04F230E79 - 14: 22493009DB01B4746F4927A8C4FB, 64CC08471D93C9AC - 15: C0F3C0DB08DC93FBA725D1E02DE084, 77B762213DDCCFFE - 16: 568B66D3112556BD98FF9339E9C002E5, C8355F508219FE0C - -EAX-rc5 (8 byte key) - 0: , 169C7954341EF44D - 1: 22, DABFDA9A0B0BA067 - 2: 2E54, 6A3D6D9AA5877C5A - 3: 2A6ECF, 2A34A3AF5DE8919E - 4: 9CC5F84F, D3F673EDAF75E3B5 - 5: FF5611756C, CC647FAAC8D49BF1 - 6: 74C939BEB31C, C335999CCFE8F5FA - 7: 7976B6F7709B5F, 2A7969C5FD063A88 - 8: 421EEC5022276174, 2C9BFB1EAC3C54A2 - 9: 6A4761CD266B1C0ECB, 3EA3CCEBC85FAC4E - 10: 7C09201098E764239A2E, 8043ABA9BF4D5AEE - 11: 8CE26277562F646DE33C88, D72AED48895E3B40 - 12: 52150F44D37D121560DA87F6, 58E865E22B485906 - 13: BA0A73B45F93ECFBFC3AB3D8D0, 683D52FA47FB1A52 - 14: 96546CBE01054AD24CC95DB54724, D80D0D530E5D1DDE - 15: 61E654BB18CD26FC36C09F874DC2C7, C65884CB9D9FEC1E - 16: 1D77B8BF02CDEAB4A707C07628826D5B, F18D1730C3D64701 - -EAX-rc6 (16 byte key) - 0: , 1DF8B0B92A3F0C951C425AF4830E63FD - 1: 1A, 8A2959EBBE90180999994DEB7036DB85 - 2: 435D, 7EF00CB57DB7B4155DB530D75CE6B025 - 3: 08A6CF, 2ED6AF0F2D5BAB05F623D389480A01F2 - 4: A86E54D3, FC69547C8BD922A5BF2F7B26C4D20F98 - 5: ED0822E439, 0007A3C6DEFC6C912C0E5B853B520368 - 6: 7BEFC7FD4054, D32C43A4D1086D57C5BCFAEE04EBC600 - 7: 5235E58E79287C, A27E9C781327C0FC7C55410EB0C828A9 - 8: CEB5EE99BE521F4D, 547F46383987F2A3582A81A3BCF9B280 - 9: 0358B063D5F99C3770, C0A73730512CDA6AD49599775D59EDA1 - 10: 434B9AEE07DFADD0A332, 499BD88881E558E09A8E822BE27D2496 - 11: D47849E650F350BB622D74, 638E37A84E7FAAF8F5D77F1B061773DC - 12: 814592F568284085E79A024B, 9EB1405E8422FE50BC0D88D837A2C650 - 13: 6F2B55EC91B591082053AF692E, C48F91EF01AA43A1EE3B36D233DDD48B - 14: 506CBDD2901838EE2F178B6953DA, 03778957F536509BFCA577B23A18F726 - 15: 446EE435D3D1848B51BB8C5F7BE4A1, 1129EAEAADE534940546D43242A4C839 - 16: FB9D2B150C42465B1685D8F069CC06DB, 41E2940F5DC63CB4E2FBEC25ED8A31E6 - 17: 9684F683260107BE8FEBBEE1D3EEDAA7BD, BAE7C116F7FF96631F4ACEE95C65CEF3 - 18: 5082B1FE48CD3AB58F63C2DCFDD4069AC736, 19AC7B8EE315CBB7131A283851B32266 - 19: 8C72AE495B6F003A3C784D144E84E88885F78E, FA4CEC023740A8D670E351FBCF62C1CB - 20: 815D6361C7AE34C9D796ADF9C71ABC46AEF88BC9, 9A1F7288C61A6623B9A82748137ED7CC - 21: 904A853E2E96BD2B85AAB3F5DFB900E9B3642EE667, 9AA90DBDD461CAD20495DCFBCB513DD2 - 22: 79D738A462F727B3D3C529ED999B6FDCCD991D1C5A4D, BF0987BEDDE650D73CAE7D380FED3431 - 23: B2DEFDB7D503A84E83155A04B8DE8C8DBB68C2FC475007, B7CE900CF43CD518024123C76F6DA328 - 24: 9E723E15439E12F6C46DF8A309AE1E97B6FD18436259CFB0, DF8B6E1E23512CC4CF5FF531A1908F69 - 25: A7F0AD03CEBCC9202718AA164886E1026975306A664C5AC7A9, 4A771BF8B9A4325705C85E5499FD98E9 - 26: A53A92AD1C6835F28E04EF591E783D36F3D76E489B31B87BEB7A, AA263B52A6E6A043DE4D7029D4DC73F5 - 27: 79BE3C38291A7F77E932C8A9DEAC08DE6442EA9B3895B101A14E7B, 33B84DE06342E675E019CD0237292ED0 - 28: FA108123C5A69571CFDFE8C3D00535121FDE3096DDC0D700F8F26A5A, 764025D7CA1A3F2C54D28956423B0C77 - 29: 36EC2D67FD977BD2B73DB6D8EB756B3EADA13690E1B6DFC12A4781B34B, 4BC6B38DE3B02283D92F4DF19A5C48C5 - 30: 96D3243C945905C9732B5927E46F00886D511463B38C86002FC26B65AB8C, 5B5511CDEC35687AB8425AB22D58B4F1 - 31: 9CF83B87BEA3374AF7722E999863E3DABB858B0383383EAC7757F5B80FD44B, 1E0CBC961940FDA93B73A92DACFD67F3 - 32: CE3BC3C9FA5EF4AFE5272B3EDD24B1B003FED2C2E501528CFF44D3FABFF52CB4, DC94FDDC78AAB2B7CAA1E1EF149AC355 - -EAX-safer+ (16 byte key) - 0: , B120C7B37450C46189712E4DFD1F0C44 - 1: CA, 82BA1869C5FF1EF2A4F6ADC1E7DC1F1D - 2: DD20, 6BD5601B16C9943A84AC1F99A176E6D1 - 3: C1C09F, 0911DC63AA414C004E2BD825BECDC93B - 4: 27E43F59, BD858F084B082F76814DC385E1FB20D1 - 5: 2A9A92F246, 5ADC4A32491934AC0BD00FCE686B26F1 - 6: 52C78C0CD6F4, F35886F46C03EDCA10B3D01CF07B1E0A - 7: 23E0D3CED3795F, FE33D96FC98B78A30C0A412C60E93992 - 8: CD3FC9961559F239, 9982364A61609FC41068260267231EE9 - 9: 6EA46CB7AD7505C1BC, BB15053EF0F78B9091B3064118F3E9BF - 10: 05D9BA230A56CCA0703A, 1338E68E3DC992B6EB2685C668E75869 - 11: 7AAD6049DFDCA6771AE42B, 35267E431051E1812495615324C4CBE6 - 12: 8695091532B83B23C296F620, 7B2EEA861E9A91E6B6A911E10FC3FDD1 - 13: D909DA4BC7372ACAEA78E6A0EE, EA6C1CD16180DF0B07F4E204A4B4FACB - 14: 7DEC8443600D0563AEFE87A2064F, DA454728069B3B409889664783588189 - 15: C042FE656742CD2FE5D9C212D18C6C, 5929E4AECC2CA047BAE948E7023FE4D0 - 16: 0B84D3CF59EEF7319633F4A397D47CF8, 31F892FFDB7535DF5D9143456E404163 - 17: 8C9E57AAFA7969B142742B63AB73286600, C418231C44F96660DDBA8C26B3BB3681 - 18: E9EED66D370A3A6A39C7E0E570D96F807EAC, A4AFE8D1D3C31B956A3BDBD043E7A665 - 19: 1A5D47992DA5597D1449B4C8DD47B7404C7657, F3ECEE5182014FC3365FDBC4C33CC06A - 20: E7C7945FD1AFD3F5DCE666D8A5A2E8A3C11A7A5F, 86D78B2FBA7597B8806BED505B52BDF6 - 21: 9E2165B47B29CBC4ACD50660E011D691F061209969, E9B1E860BD02085177E1A94E1EE6F3F0 - 22: 48EA2945C8DD3FE09407BAC8973A861DB15B788C8FFD, 502926712EDB1B3DD13806052C6C75D7 - 23: F37D46B35B60819EA52B00457D79155C04B55972D0DFA9, BB2B7D210BF0570F422640BF81F39B9E - 24: 12E85C0C78227205CC682360C79E35BF58EC6551CF8FE2D0, 042990D7A58D458C570A15DD375DB4E7 - 25: 4F6C15109DE980DD14A7F4C27F48671E4787C53A564232F427, B097A5990D8067DD89C21473150C070F - 26: AAC472E49DB101B564A8A01E2C80C0C6AE9065D332C2DE79FAB6, ACDD587A7DB86542E195DF73AF1C1CBC - 27: B9912CE18019C31692A1F7E11D9CCB20297ACCB9DC62C47C01D2C2, B0ACBF028CA5B15E0035D2EB8CA916BE - 28: B4F2B1FE14A1ECDC9C8EA1A0120395E6ED1E69D3FC85DD0F3F90F350, 9A561EBC769369B95B9CB74FC6AC27D3 - 29: 3FE397C8AD02689B7437A37861F0907AF1F6014A293B46419348771C5A, 6B7BEB9BD5018FECD71BE5081C7C2544 - 30: 5019089142199F7207E1B7731B8B247A18A685B231499DF12A73F5D67D37, 307E93446777005BA1B088F178A0DB6E - 31: EAE8F9F02F8DB3D70B78B08CFB0949D99F1A86C958A8E3823736BCEAB86BE1, 6C94F48591C18BF9C450515B73379973 - 32: B9C795F7A87305B4AD36DBA10B3B1C70B329D29E49C8C6A932D96A74334AEE4A, D18E6E233FEFD6E5C7148BDC1504299C - -EAX-twofish (16 byte key) - 0: , DB0C02CB069E3773296D3BD4A87A381B - 1: 99, 7D21D19E9C440F68E99F1F2EA2668694 - 2: 0696, EA590EC417C88E23FD23917F9ECFB0C6 - 3: B9B082, 82D4C9B68DDB02C906496413E13A2D68 - 4: D6B29D74, 5BCE5CA4F662E883BF7FCAAE5FB2CE01 - 5: A59C9CB009, CBFB04226D1029A7EC9D64A48A6729BE - 6: F4924FE3E355, 3D85B3900DECA0528C815F1447A1F209 - 7: 679C88D52FB519, 931C7A863C3701D8015FDBD8696C6C30 - 8: 26DA41C0D115375E, 7627E23E791A4DCB0FA5ED71B1ED2288 - 9: 8FEC6EB7016AD2B178, F65ED0286A724F0CB2EA317D5022B0D8 - 10: B5F22415B1334133C531, 87C4F3A8991BBB85984BC4D3305A5CF1 - 11: 23E1D0ED2E820AFE7DA2FE, 100499F1093FAB2ECF73B643594E98E3 - 12: 79519ABA91F46B8DAD6D5335, FBDCD1FCDB20AB99135F28A714C6992F - 13: 5968D0B4198A0AAD3D0395018F, 781F22E2DA98F83398FCF911B2010057 - 14: 4E55B14432B601E3EF2EF567CB15, 8BF6E53D7657E56EA3DA1BFD9C9EC06E - 15: 6ED89651CE19B3DD1EE5C8780B5015, 131CFD657D32D4E1B35140ADDCA0E13A - 16: 2295A968B4D072D12757756247554850, F35FAC95C2AA4155450EAAA6E2E789B5 - 17: F9B2AA2AA502EA79BBA0C5EAD932B8E1EE, 0ED81AA40B9BF39A9AAEDDDB7A04BEA6 - 18: 385055F1C1C26C0472A504B4CD225DCA55FE, 24831680B56368231AC54227D737F582 - 19: 771529585C741A3F8B1C973709892F255A99EE, 2A132B4BF96FD5109DB04459103F5E84 - 20: E7A2197D9FAA8AB8B303B5EC71AE34AD5EC5DD66, CCAB6518371EC8E0A9E9EE4F7CA5878B - 21: 279E54F755EAC6B57375B9EC4406E43DB3139D740C, 7B6F26F2C0ECC9F2DF4EDD7513E6E0B7 - 22: 27816AA94CBA2BF98E49E595AF5B3FAD12BF1D6F1AC6, D04876C5492D275F15C834E3CF794F0E - 23: B5658DC148855F68B282211D879F688F3C142FE555CF81, 4539CDA8A65DB9047AAD76B421B81120 - 24: 72F0BD4F939C2C9B4FA734DCB0AE4FB9BD342BC8459ED2FE, CEA8469BC0457EBF3418C1114288C904 - 25: 70568245E6E6BD5D11AD0C74030D7AE08BA05057DEA0FBF4AD, 71554FDE6B87477A51EE4499D78783D2 - 26: 8702D35BE07D7ADF70684046CC6C72FBBBF821E0BBCCBC973601, 33CC6FBFDA15E306919E0C3BB2E22BB6 - 27: 0BA23F4A6174165D4A8BA80B7C875340B0F8B2A6967D34E106BC22, 00E6679496714236EECEC84B9AF3072E - 28: B9E25ABA84C6BD95B5149E7616FE2E1D6FAACEAAD77A636C60279176, 8D8AD0B9D4C709E1DA370EE01611482A - 29: 74759711F6D542581F9F83498FB616638D092732BA07109BF4B5BE045C, 71A40DC777BD09F75362F7B20E0B7576 - 30: ADBF7E98926484BA2C7F6CD7CD9734FC19265F68AF3BFCAEB025F6296E37, 8DF15B5F69B67F7DABE44E3666B55047 - 31: 2DC26D449379997D110309B2A0DC2760FCE8CADB4B14ED580F86C70F69C9BA, EFCB60EB2B25737E256BC76700B198EF - 32: 2B1890EB9FC0B8293E45D42D2126F4072754AA54E220C853C5F20FBA86BE0795, 1A1B15BBC287372FB9AF035FB124B6A1 - -EAX-safer-k64 (8 byte key) - 0: , 9065118C8F6F7842 - 1: A1, 1926B3F5112C33BA - 2: 2E9A, 5FA6078A0AA7B7C8 - 3: 56FCE2, 984E385F9441FEC8 - 4: C33ACE8A, 24AC1CBBCCD0D00A - 5: 24307E196B, DD2D52EFCA571B68 - 6: 31471EAA5155, EB41C2B36FAAA774 - 7: 03D397F6CFFF62, 7DFBC8485C8B169B - 8: 8FA39E282C21B5B2, 2C7EC769966B36D7 - 9: FEA5402D9A8BE34946, A058E165B5FFB556 - 10: 6CDEF76554CA845193F0, FED516001FFE039A - 11: DC50D19E98463543D94820, 8F9CCF32394498A1 - 12: 42D8DC34F1974FB4EB2535D7, 77F648526BCBB5AF - 13: B75F1299EF6211A6318F6A8EAA, C5086AEA1BE7640B - 14: 1E28D68373330829DD1FFC5D083E, 33EDA06A7B5929A2 - 15: 85529CF87C4706751B0D47CC89CEA6, D031905D6141CBED - 16: FE5CB61BAF93B30ED3C296EE85F51864, CC484888F0ABD922 - -EAX-safer-sk64 (8 byte key) - 0: , 5254AB3079CDCB78 - 1: 75, 798DCF14FEF8F4D1 - 2: 0300, D5FCA75DAC97849C - 3: 520F98, 10E357957CE20898 - 4: 80E2764D, 5C7F46656C6A46EA - 5: C48960CDAA, 3CCF44BD41F01CA8 - 6: E0E60BD9AA2C, EBB493983FCEE79D - 7: D13D8804906A1B, 6EDDCA919978F0B6 - 8: B7AE14C37A343BFB, 2369E38A9B686747 - 9: 5DE326BBCC7D0D35E9, 041E5EE8568E941C - 10: 13494F5B0635BA3D6E53, EAEEA8AFA55141DD - 11: A9BB35B14C831FDA0D83F7, 4002A696F1363987 - 12: E242043A1C355409819FABFC, 63A085B8886C5FDC - 13: 204598B889272C6FE694BDBB4D, 194A1530138EFECE - 14: EE3F39E0823A82615679C664DEBF, 1EFF8134C8BEFB3A - 15: 8579D87FD3B5E2780BC229665F1D1B, A832CD3E1C1C2289 - 16: 74D7290D72DA67C4A9EAD434AE3A0A85, 96BAA615A5253CB5 - -EAX-safer-k128 (16 byte key) - 0: , 7E32E3F943777EE7 - 1: D1, BA00336F561731A7 - 2: F6D7, 8E3862846CD1F482 - 3: 5323B5, BD1B8C27B061969B - 4: A3EC3416, 170BBB9CE17D1D62 - 5: 0C74D66716, 7BD024B890C5CE01 - 6: 6158A630EB37, B5C5BD0652ACB712 - 7: 17F2D0E019947D, F9FF81E2638EC21C - 8: 68E135CC154509C8, AA9EAEF8426886AA - 9: EDB1ABE0B486749C21, 355C99E4651C0400 - 10: DB0C30E9367A72E8F5B2, 631B5671B8A1DB9A - 11: D4E5453D9A4C9DB5170FCE, 75A2DF0042E14D82 - 12: 3F429CC9A550CBDA44107AA7, 2C2977EA13FEBD45 - 13: A7CA22A97C2361171B415E7083, BFE81185F31727A8 - 14: 170F79D8B0E3F77299C44208C5B1, D5ED9F9459DF9C22 - 15: 2E24312D2AE5D5F09D5410900A4BBA, 2FC865CA96EA5A7E - 16: 8F3C49A316BA27067FF2C6D99EC8C846, 9D840F40CDB62E4B - -EAX-safer-sk128 (16 byte key) - 0: , 22D90A75BBA5F298 - 1: 3F, 98C31AB2DE61DE82 - 2: 584D, F4701D4A1A09928C - 3: B9DEAD, 6E221A98505153DA - 4: 06D4A6EB, 0E57C51B96BA13B6 - 5: 7B58B441CA, E28CCF271F5D0A29 - 6: 7950E0D1EC24, 2ACDDE6E38180C07 - 7: 65A4F4E098D7C6, 7DC1C9E9602BACF2 - 8: FEBE4E72BAA0848F, C4607EA3F138BAD9 - 9: 9B7BD6D6D655985AA3, 8B2C58A9530EA6AC - 10: 60C92F925D1478470203, 51E6F5F6DC996F84 - 11: 7B40769370E651F64AA654, 74F1F8A8D3F4B9AF - 12: 7215832C2FB9C54DF7A9C686, 9BF9AEF14F9151D1 - 13: AD0F9C79008572AB8AE2466EFF, F375D0583D921B69 - 14: C05076E2C330A0D25D7CEC80597F, 843C12F84B00A8E0 - 15: D18F0563AB0278140B0CD9A9B07B34, 262B1688E16A171E - 16: 650747091F5C532EE37D2D78EE1EC605, 1BAC36144F9A0E8D - -EAX-rc2 (8 byte key) - 0: , D6CC8632EEE0F46B - 1: 4C, EA19572CB8970CB4 - 2: 5537, 3EDD3253F6D0C1A8 - 3: 206FA6, 20FA88F03F240D31 - 4: 17EE8B40, 702E8194F1FCBFDE - 5: 2A89287136, 31C5534786E15FB3 - 6: 3A6AEDC7066B, 3C663A4081E1D243 - 7: 8BC5203947A644, 6AAC806C92BFBD6E - 8: 2E0274BBE14D21A3, CEB0E0CB73C3664C - 9: 9C4B292B0CF17E3A29, F23CD535559023EC - 10: 8E322734308F85662877, 46363D7EFC322821 - 11: C413C405767FF5F98E3667, E7BA35D8F3678E7E - 12: D77806B7A218098B1569EADC, BA67C306E5C0181B - 13: 4BE5EF74F9E9799A4D636FEA9F, 4C511C44ADBA4030 - 14: 7E19969170C2C8D8AEBA8C7FBC2C, 54CC6D466A2DF6DA - 15: 2EF1CEDC1DD3403CF440FC5561BE33, 61C6FB277E93701F - 16: DE052719153EBACE9D7B19F52AC4282F, 4AC2A96F2FA8634C - -EAX-des (8 byte key) - 0: , 44048B7F240B6F5F - 1: 0A, 37009B7D4E09953A - 2: 03BA, BFD2FD7758961728 - 3: 37EE10, 16A6AF96DE888A19 - 4: 07F44290, 100CA84AA0EDAA1D - 5: 389EF0023B, 9614FB800A533268 - 6: 3F4DBA8AA01C, EFA6B55B7ED5E40F - 7: 8C7B837896EAE7, C113CE8F664CE3D4 - 8: 7011D993D8EDB0C7, B4C370A919F60497 - 9: 0DEB30A31351B13D7B, 00ABC82DC5F3A1AF - 10: 8D3897B2CBE323D6EE1C, 7A2D15627CA1441B - 11: DBC002C817DEBFB419F94B, D8EB87F86D6ACDEF - 12: 17048E2976FA85AA849E9A80, 229FCD1C9D1E3B9C - 13: 30B989EF646544885A478AC198, C1B7EB4F799105C8 - 14: 5C2E12A7F118A08D6FD585F9C839, C358679FEE6FE7D7 - 15: 8D1A1E888BBB8648E638C4E74E11B8, 685E006C441448B8 - 16: 93AE906B8BE4EAC8ED6D8F48F04A7AFF, 71DD7AF752FE28FB - -EAX-3des (24 byte key) - 0: , 8914311BB990B725 - 1: D8, 2094EDC5D03E54B1 - 2: FEE5, 781CFB0EBE3895CA - 3: DECF5E, 59918E8A5C4B459B - 4: BD583AAD, 2013BEEBEEA795A1 - 5: 2BC01C6C78, 0B1134DBBEAB5D3F - 6: 4D5EAF01A895, AB4D17516ECBA50A - 7: AF229F90614480, D3113C0A9D133CD4 - 8: BCA6F375DF4568E0, 8E9EAEC8E77786BC - 9: 575F34219E6DD8DB4C, B40C75139E5D1860 - 10: A199B8AC433B615EC96F, 774AF803698ADE3D - 11: 718A2975DD9A872A68AE10, 3B9460F849CBA7FB - 12: AB38E148180F6E2FFBB96F91, E3EE3B8FC50DADBC - 13: EB10E0233507459D4A6C29EE80, 8D90B46BB1EAB27E - 14: EB48559C320DFB056C37458E19B5, 9315F0C4AF8500EB - 15: 9E8C73EADA105749B5D8D97392EDC3, 2E749EE66C1E6A16 - 16: 600FA4149AF252C87B828C780AEFF8BC, 33D7D11DCDC19936 - -EAX-cast5 (8 byte key) - 0: , 382FB8F7E9F69FDC - 1: 99, 20DA959849B3F7AB - 2: C54B, D05547C6AFA3484A - 3: 579836, AAA92B2321FC50C5 - 4: FEB7AE55, 639EDF01C4FB965D - 5: EA8A6023FA, 01274B3ED5CE102C - 6: B7C4E995121F, 712BFE27CAFF6DDE - 7: F44236660B0004, FAC51D1DF8EC7093 - 8: 01CD7E3D0BF29E8A, 049C47A45D868D0B - 9: DAB170493DFD6E0365, 6F3AEDD9A3ECF4FD - 10: 82C9EEC4803D9CD11FA8, 32683C0A9128C6EA - 11: 324AC59E87B244ECE0F32F, F6B095AAB49353CF - 12: DBDDAB11D02C9CA5843C406E, EA728FC46DDD3B04 - 13: D67376C2A4AD92E7DD80E39303, CAF72B7E7C237EB3 - 14: F2B9BBEF08036C2982C6DDD06918, 70A29D780C22752C - 15: 96E3D9141F8EBF520540C2BC9A9C23, CEFC86A1CD48203D - 16: 70CABBA983179106AE7FCD5F1F31D5C3, BF7F9168F4F82F56 - -EAX-noekeon (16 byte key) - 0: , 556805EEA595CFB9A30FAD196103D7FD - 1: F5, 0A7DAEDFB656526CEF4DDBA8087A227A - 2: 7B8C, 249895D79962D5B4D18FE07366281B72 - 3: ACFF15, DCC489D24832EB106F576AE6B6EB957A - 4: 08ADE7DB, 0D3215999E9960EDAB29B78744C7F139 - 5: 66139213F6, 505E1E7141D043E903C26EE0959EEECD - 6: 078B79F880A8, 35B7EB326A55E50332866EEDB682EC20 - 7: 2809E34D9667D4, FFDEC555F68524A09A6ABACA372077D9 - 8: 93D267DE1EC635D3, 4FF3561990A56E4B374618722EF850FF - 9: F377A4D93FF32F4A51, 91D4070423A90FC54D305169C03F49ED - 10: 6244B717E082993EB7A1, 2E3A8A354AFA9473667ED7FDD46BE9FC - 11: E917559625D25E6E5F2EDA, 19295C37A70314CC9A1D11FDE8D23C92 - 12: 1E6DF2EE112A893AB14DFA92, 12C4A89D4CD65F8116A03A135AFD3701 - 13: 47B18CD762E011770E203CF605, 434909A97E118B20D3AEDC79AFE33A9E - 14: 72D9A1A7DA6F33D5E0B927F9F32C, 779C23714FCAA2B2321EC7FB5B03E222 - 15: DA8B830FFCB3DB274807F780D33240, EDC2F1C8A401F328A53392597730B007 - 16: B53DD2BB840AD933D36A7B5FFDCCFBBB, 4EC0E6D1F916BF633869239B672B37A1 - 17: 42936BB9A936C30408660855F4F47F3314, F0DAA6DDA15585E1697ABBB4790B15B5 - 18: 00372E47F5BA016F1B2A1E680B76AB02052A, CDBF3D241BF7FF96D3DFBEDDB872E901 - 19: 8AA236B0C8BEF6F67A97C2DF90628F6E5838FF, 731DCD61F7F26004C03519F9500EA824 - 20: 55338647812FC9D86CBDDCED7120268A4D43F8BA, 0E61B3C835CAD95FD49FEF002C014E72 - 21: 435820B28E52154B47A04D5E635D8FE37FA47FC985, F6A96DCE4917E8D7C610923627E80970 - 22: 0D30C15B6FEB4A48B14DD15D41A4B25D442AA677B25C, 28E15CCB74AE992C68BDDC8D87802050 - 23: D9D701F9AD6B0E13D2CDDA15A5194E7CE8BD2C02137391, 2DB9A15884E9C996C3D6B5BDA44B9598 - 24: E2390AC5CE10CCFBC72106A52C7F180CB477E3C193CBACA8, 22D3F7DCD6947EA4E78DF57A8E1A9A59 - 25: ADEFB7D9500658D34996AF6BE6336CD78891064EA1DB8E9785, F239D67D039A15C620A7CD4BE4796B3F - 26: 89964C90ABF54A6DF9F13C3681E70C702D80A17BE79F8160F30E, 6336F729ECE1ED7368669D75B7E2DCBA - 27: 576B2813CECDA4F905BD5D58349EF070FF41B7EB6BB2B01B061B0B, 125324CBF2ACF1011A44A99A11EC8AFC - 28: 430B957481748519A60494F0B5F698F34B1A8235B00AC0D1F0A4442E, 1E80A7FCEBBB8E1E12D6831906154485 - 29: E781BFE5FCDE0BFC056CC86C4A0B9DD3B815BE8CA678204CF47289B5B5, 190D5AAA9EC1CB4CC86FACE53BF1201B - 30: 78BFAC07A9B7B2AE9329BF9F9BF18A1A49DD9587001EFCA00E9AD9752764, 4FB5ECBEEB0995C150EBC66508FA19C1 - 31: 7D6C20694109DE21F7955855A8FF832347518DD496C2A114DF142C68ACDEAA, B25D4BB34056DC091A7A3950D46C32EC - 32: 3E1E4395DEC1AFEA9212B95F37E679B6E2D14DF23C5DE49018C2C8038CC4AD45, 9A6DE7BD41A21918AD504490EF4E581D - -EAX-skipjack (10 byte key) - 0: , 85F74B6AFFB10ACD - 1: 3F, 604DF8BDD98A0B3F - 2: EA87, 792374FE07588BF9 - 3: 0169CA, 489AB8AF69DA3306 - 4: A7AC3EB1, 428DAF508E24B583 - 5: AA9028D5B3, C0A44EDA71FB2C86 - 6: DA97BA88A061, DA2EC34077F42585 - 7: 7E25FAA41CEBC8, 36D4987551E06D5B - 8: F662DA6C9001CBFE, B7DEF76680C316A9 - 9: 6D3F73EC716E1DA897, 5F0F83BAE4D3513B - 10: 2A300F585BEE9C889743, F4756C24DEB72A9C - 11: 80518B010DD77C82D19106, 50FF5CAA365F4A70 - 12: 6E579A2173C861B6F37B4CD3, 81E3E5ABBA8F0292 - 13: 5B04829880A72C38871C7021F3, 6B26F463708A3294 - 14: 934177878E9A9A9FB4DEB3895922, EBC1C32F0A2A3E96 - 15: 07AF486D1C458AAB2DBF13C3243FAD, 87288E41A9E64089 - 16: 84059283DF9A2A8563E7AF69235F26DF, 351652A0DBCE9D6E - -EAX-anubis (16 byte key) - 0: , 8E20F19D9BA22ABA09FB86FDE6B9EF38 - 1: 3B, F4201E546A9160F989191942EC8FD1D3 - 2: 9F38, 4E3CEAE3E1CB954E021A10E814B71732 - 3: 4F4769, 3E8F35A6A5B11200E9F1AA38590066CD - 4: AB41F5FC, EC4C97A8892AAF5433106D4AC8A49843 - 5: 414F95D61B, BF831E34D1E3FECB973A8C730ECA2E6D - 6: 4798322F06D1, 005BBC30BFEDBE6463536C4F80D1A071 - 7: F256B6CD1BF4F5, 468A28F0661884B846B191B530C8D064 - 8: 90906F27A633ADDE, 6D9200A37A7F6A456CB103673184C2E5 - 9: 16CD3C17C9B4EAB135, 6D716E23D7B35109F55B036EDFA7742E - 10: 7AD1C22F1F06298DFB25, B076990F8193543C8F3185D3792BCE56 - 11: 0476F2ABCD057FE6FEE39D, BB2876DB18C00038FADBBD9B264ACC3C - 12: B69EDE336407DBC2EE735857, AB63E5906116A8BE22C52B5DA31B1839 - 13: C3864C1354065A56470669E602, C72BFD3A0BC73BFF051C9AB2F0DFED93 - 14: 296D8F183A59020D33890420DD7B, C9D90B9EB42C32EDCF6223587D1598A6 - 15: 256ED8E9D982616680559979BDF2E9, 179FE4E7BA7E966050D35900317E9916 - 16: D4ED8F30FF9C0470D75B3B16750A3AE4, 5D50F05BB270A292DFF9F67A3BA84675 - 17: 40CDEB6388274143CA3C4F6020BD9A4875, B27C7DFB1BFBB3FCCEE0171852C7924E - 18: 54EF262EC1801D505C7629D038654EBA0594, 9D2060FCD0A2C577511C7752ADE60BBE - 19: F39EE54A37F16DD38B624D7AB8F0D9CBD4B981, BC056C7D2C09D813703CDD63C1C69F44 - 20: F4E7AD474FCA153ABD670E43081ED09EB2C4CC1A, F244BD4D630272F0D98FCA04226C04F1 - 21: 039ECC36A0A16273E7246CA1FF19D213AC87B53F29, 3056DB6916C925DF220B6C9980EE141A - 22: 7DE1DCDEF01447CA2FE83375A48DD84E4A7CB7C01992, 79AFEA4816EAF8DAC8A5E93960F1594F - 23: A886C4B914BF0983003272F226F9B2197EF2DC05ACDDE0, B59D85A0FDA5FA4422F7203C055B97A9 - 24: 00B3E1E91448E250AAFB695C0643A6577AB453EFECFABF53, 4A7EFF1CBC1AB535122A017203616D85 - 25: 85E972E774D66D0531E40B8FE9E264A77B50FA883AB0943080, B18E164BF89B7E7AB0DC256DFEC7C72F - 26: 004849E39334969B392CB0CF3FDEFB3D792DCBBC15F8328C7EDC, 3C51295711F5F878DE8F0B2B5A26A227 - 27: A0BAD6C2264AB1578993BA49E59D4598822FFED20A57D88F756FF1, 2EB9D525697A419A10DB2A84AEEA5FBC - 28: C34DD806EAB5AD823D78BCA78A7709A705FC94ECC521A367D76C9588, 3C57580C7903039D645C06DBAF07B477 - 29: C447EC77512938CF7862388C32AF22ACE6B5E4CBAA998BE4F5CBC4D215, 43425D09B7ACFD90371C08953946A955 - 30: 2C16993AAE624CBA4CDAF34FE3D368559E6BE548292B281439866375013B, 3B7360C3FA8FB1C15D19F567153CB46C - 31: 538E5DFAF14854A786851E4165F2E01CDDA963E318FCE4FB58E31A6B5CFC33, 2F8EA13B7A6873FE556CA535ABA0968B - 32: 5E29CDB7D9695A110043E9C260104BDF020A3A2A139D4112E918AB584BDD7EDA, 9133213AA7BCF062D2BD37F866683D3F - -EAX-khazad (16 byte key) - 0: , 75968E54452F6781 - 1: 95, ADAF5949F09B5A22 - 2: 6B8F, A06B201947424A11 - 3: 5BE668, 3251416625DF347A - 4: 5A92E82B, 33E25772427D9786 - 5: 62F9F2ABCC, DE714F5F5D17D6D0 - 6: 0E3CD825BD8D, A7991C8CB8975ED9 - 7: 4AD0D999503AAD, 53A827D7886F7227 - 8: BB08E6FAED1DAEE8, 91A118749B7AB9F3 - 9: 16E30CB12E20D18495, F8F8B8C1280158F9 - 10: 616DBCC6346959D89E4A, 506BF35A70297D53 - 11: F86B022D4B28FDB1F0B7D3, EA42220C805FD759 - 12: 9B8A3D9CDBADD9BBCCCD2B28, BB478D3CE9A229C9 - 13: CDC4AB4EF2D5B46E87827241F0, 658EDB9497A91823 - 14: 1A113D96B21B4AEBDB13E34C381A, 63AD0C4084AC84B0 - 15: 14DA751E5AF7E01F35B3CE74EE1ACF, 3C76AB64E1724DCE - 16: A13BBC7E408D2C550634CBC64690B8FE, 3D4BBC0C76536730 - diff --git a/doc/examples/row_encryptor.cpp b/doc/examples/row_encryptor.cpp deleted file mode 100644 index b512025b6..000000000 --- a/doc/examples/row_encryptor.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <string> -#include <memory> -#include <sstream> -#include <iostream> -#include <stdexcept> - -#include <botan/botan.h> -#include <botan/filters.h> -#include <botan/eax.h> - -using namespace Botan; - -/* -* Encrypt and decrypt small rows -*/ -class Row_Encryptor - { - public: - Row_Encryptor(const std::string& passphrase, - RandomNumberGenerator& rng); - - Row_Encryptor(const std::string& passphrase, - const std::vector<byte>& salt); - - std::string encrypt(const std::string& input, - const std::vector<byte>& salt); - - std::string decrypt(const std::string& input, - const std::vector<byte>& salt); - - std::vector<byte> get_pbkdf_salt() const { return pbkdf_salt; } - private: - void init(const std::string& passphrase); - - Row_Encryptor(const Row_Encryptor&) {} - Row_Encryptor& operator=(const Row_Encryptor&) { return (*this); } - - std::vector<byte> pbkdf_salt; - Pipe enc_pipe, dec_pipe; - EAX_Encryption* eax_enc; // owned by enc_pipe - EAX_Decryption* eax_dec; // owned by dec_pipe; - }; - -Row_Encryptor::Row_Encryptor(const std::string& passphrase, - RandomNumberGenerator& rng) - { - pbkdf_salt.resize(10); // 80 bits - rng.randomize(&pbkdf_salt[0], pbkdf_salt.size()); - init(passphrase); - } - -Row_Encryptor::Row_Encryptor(const std::string& passphrase, - const std::vector<byte>& salt) - { - pbkdf_salt = salt; - init(passphrase); - } - -void Row_Encryptor::init(const std::string& passphrase) - { - std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-160)")); - - secure_vector<byte> key = pbkdf->derive_key(32, passphrase, - &pbkdf_salt[0], pbkdf_salt.size(), - 10000).bits_of(); - - /* - Save pointers to the EAX objects so we can change the IV as needed - */ - - Algorithm_Factory& af = global_state().algorithm_factory(); - - const BlockCipher* proto = af.prototype_block_cipher("Serpent"); - - if(!proto) - throw std::runtime_error("Could not get a Serpent proto object"); - - enc_pipe.append(eax_enc = new EAX_Encryption(proto->clone())); - dec_pipe.append(eax_dec = new EAX_Decryption(proto->clone())); - - eax_enc->set_key(key); - eax_dec->set_key(key); - } - -std::string Row_Encryptor::encrypt(const std::string& input, - const std::vector<byte>& salt) - { - eax_enc->set_iv(salt); - enc_pipe.process_msg(input); - return enc_pipe.read_all_as_string(Pipe::LAST_MESSAGE); - } - -std::string Row_Encryptor::decrypt(const std::string& input, - const std::vector<byte>& salt) - { - eax_dec->set_iv(salt); - dec_pipe.process_msg(input); - return dec_pipe.read_all_as_string(Pipe::LAST_MESSAGE); - } - -/* -* Test code follows: -*/ - -int main() - { - Botan::LibraryInitializer init; - - AutoSeeded_RNG rng; - - const std::string secret_passphrase = "secret passphrase"; - - Row_Encryptor encryptor("secret passphrase", rng); - - std::vector<std::string> original_inputs; - - for(u32bit i = 0; i != 50000; ++i) - { - std::ostringstream out; - - u32bit output_bytes = rng.next_byte(); - - for(u32bit j = 0; j != output_bytes; ++j) - out << std::hex << (int)rng.next_byte(); - - original_inputs.push_back(out.str()); - } - - std::vector<std::string> encrypted_values; - std::vector<byte> salt(4); - - for(u32bit i = 0; i != original_inputs.size(); ++i) - { - std::string input = original_inputs[i]; - - for(u32bit j = 0; j != 4; ++j) - salt[j] = (i >> 8) & 0xFF; - - encrypted_values.push_back(encryptor.encrypt(input, salt)); - } - - for(u32bit i = 0; i != encrypted_values.size(); ++i) - { - std::string ciphertext = encrypted_values[i]; - - // NOTE: same salt value as previous loop (index value) - for(u32bit j = 0; j != 4; ++j) - salt[j] = (i >> 8) & 0xFF; - - std::string output = encryptor.decrypt(ciphertext, salt); - - if(output != original_inputs[i]) - std::cout << "BOOM " << i << "\n"; - } - - Row_Encryptor test_pbkdf_salt_copy(secret_passphrase, - encryptor.get_pbkdf_salt()); - - zeroise(salt); - std::string test = test_pbkdf_salt_copy.decrypt(encrypted_values[0], salt); - if(test != original_inputs[0]) - std::cout << "PBKDF salt copy failed to decrypt properly\n"; - - return 0; - } |