diff options
author | lloyd <[email protected]> | 2009-04-16 22:48:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-04-16 22:48:52 +0000 |
commit | 967bf93208e061eb794ec0e368dec3c33a80615c (patch) | |
tree | 760919fe7f84c5f048d1de580b5228f35800918e | |
parent | 07ffeeee0e4fd3cd2ccf4b3267fabef20eee2964 (diff) |
Add XTS mode, from IEEE P1619
-rw-r--r-- | checks/algos.cpp | 3 | ||||
-rw-r--r-- | checks/validate.dat | 367 | ||||
-rw-r--r-- | src/engine/def_engine/def_mode.cpp | 14 | ||||
-rw-r--r-- | src/modes/xts/info.txt | 15 | ||||
-rw-r--r-- | src/modes/xts/xts.cpp | 344 | ||||
-rw-r--r-- | src/modes/xts/xts.h | 76 |
6 files changed, 818 insertions, 1 deletions
diff --git a/checks/algos.cpp b/checks/algos.cpp index 79a609dda..d106d1479 100644 --- a/checks/algos.cpp +++ b/checks/algos.cpp @@ -24,7 +24,7 @@ std::vector<algorithm> get_algos() algos.push_back(algorithm("Block Cipher", "KASUMI", "KASUMI/ECB", 16)); algos.push_back(algorithm("Block Cipher", - "Lion(SHA-256,Turing)", + "Lion", "Lion(SHA-256,Turing,8192)/ECB", 32)); algos.push_back(algorithm("Block Cipher", "Luby-Rackoff(SHA-512)", @@ -61,6 +61,7 @@ std::vector<algorithm> get_algos() algos.push_back(algorithm("Cipher Mode", "AES-128/CTR", "AES-128/CTR-BE", 16, 16)); algos.push_back(algorithm("Cipher Mode", "AES-128/EAX", 16, 16)); + algos.push_back(algorithm("Cipher Mode", "AES-128/XTS", 32, 16)); algos.push_back(algorithm("Stream Cipher", "ARC4", 16)); algos.push_back(algorithm("Stream Cipher", "Salsa20", 32)); diff --git a/checks/validate.dat b/checks/validate.dat index eaa288b15..652c5b2ee 100644 --- a/checks/validate.dat +++ b/checks/validate.dat @@ -23888,6 +23888,332 @@ C61A0851AB4E515D11525B92E2B9D850:C825FC7C4D539DC74887CECC70884F37 60:710DABD24D400F3B6B:\ F956B879EC7F807F1FCB482B53623671:E64F90B4619D93137E6237929EABF297 +[AES/XTS] +# Vectors are from IEEE P1619 D11 + +0000000000000000000000000000000000000000000000000000000000000000:\ +917CF69EBD68B2EC9B9FE9A3EADDA692CD43D2F59598ED858C02C2652FBF922E:\ +0000000000000000000000000000000000000000000000000000000000000000:\ +00000000000000000000000000000000 + +4444444444444444444444444444444444444444444444444444444444444444:\ +C454185E6A16936E39334038ACEF838BFB186FFF7480ADC4289382ECD6D394F0:\ +1111111111111111111111111111111122222222222222222222222222222222:\ +33333333330000000000000000000000 + +4444444444444444444444444444444444444444444444444444444444444444:\ +B01F86F8EDC1863706FA8A4253E34F28AF319DE38334870F4DD1F94CBE9832F1:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\ +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF:\ +27A7479BEFA1D476489F308CD4CFA6E2A96E4BBE3208FF25287DD3819616E89C\ +C78CF7F5E543445F8333D8FA7F56000005279FA5D8B5E4AD40E736DDB4D35412\ +328063FD2AAB53E5EA1E0A9F332500A5DF9487D07A5C92CC512C8866C7E860CE\ +93FDF166A24912B422976146AE20CE846BB7DC9BA94A767AAEF20C0D61AD0265\ +5EA92DC4C4E41A8952C651D33174BE51A10C421110E6D81588EDE82103A252D8\ +A750E8768DEFFFED9122810AAEB99F9172AF82B604DC4B8E51BCB08235A6F434\ +1332E4CA60482A4BA1A03B3E65008FC5DA76B70BF1690DB4EAE29C5F1BADD03C\ +5CCF2A55D705DDCD86D449511CEB7EC30BF12B1FA35B913F9F747A8AFD1B130E\ +94BFF94EFFD01A91735CA1726ACD0B197C4E5B03393697E126826FB6BBDE8ECC\ +1E08298516E2C9ED03FF3C1B7860F6DE76D4CECD94C8119855EF5297CA67E9F3\ +E7FF72B1E99785CA0A7E7720C5B36DC6D72CAC9574C8CBBC2F801E23E56FD344\ +B07F22154BEBA0F08CE8891E643ED995C94D9A69C9F1B5F499027A78572AEEBD\ +74D20CC39881C213EE770B1010E4BEA718846977AE119F7A023AB58CCA0AD752\ +AFE656BB3C17256A9F6E9BF19FDD5A38FC82BBE872C5539EDB609EF4F79C203E\ +BB140F2E583CB2AD15B4AA5B655016A8449277DBD477EF2C8D6C017DB738B18D\ +EB4A427D1923CE3FF262735779A418F20A282DF920147BEABE421EE5319D0568:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +00000000000000000000000000000000 + +27A7479BEFA1D476489F308CD4CFA6E2A96E4BBE3208FF25287DD3819616E89C\ +C78CF7F5E543445F8333D8FA7F56000005279FA5D8B5E4AD40E736DDB4D35412\ +328063FD2AAB53E5EA1E0A9F332500A5DF9487D07A5C92CC512C8866C7E860CE\ +93FDF166A24912B422976146AE20CE846BB7DC9BA94A767AAEF20C0D61AD0265\ +5EA92DC4C4E41A8952C651D33174BE51A10C421110E6D81588EDE82103A252D8\ +A750E8768DEFFFED9122810AAEB99F9172AF82B604DC4B8E51BCB08235A6F434\ +1332E4CA60482A4BA1A03B3E65008FC5DA76B70BF1690DB4EAE29C5F1BADD03C\ +5CCF2A55D705DDCD86D449511CEB7EC30BF12B1FA35B913F9F747A8AFD1B130E\ +94BFF94EFFD01A91735CA1726ACD0B197C4E5B03393697E126826FB6BBDE8ECC\ +1E08298516E2C9ED03FF3C1B7860F6DE76D4CECD94C8119855EF5297CA67E9F3\ +E7FF72B1E99785CA0A7E7720C5B36DC6D72CAC9574C8CBBC2F801E23E56FD344\ +B07F22154BEBA0F08CE8891E643ED995C94D9A69C9F1B5F499027A78572AEEBD\ +74D20CC39881C213EE770B1010E4BEA718846977AE119F7A023AB58CCA0AD752\ +AFE656BB3C17256A9F6E9BF19FDD5A38FC82BBE872C5539EDB609EF4F79C203E\ +BB140F2E583CB2AD15B4AA5B655016A8449277DBD477EF2C8D6C017DB738B18D\ +EB4A427D1923CE3FF262735779A418F20A282DF920147BEABE421EE5319D0568:\ +264D3CA8512194FEC312C8C9891F279FEFDD608D0C027B60483A3FA811D65EE5\ +9D52D9E40EC5672D81532B38B6B089CE951F0F9C35590B8B978D175213F329BB\ +1C2FD30F2F7F30492A61A532A79F51D36F5E31A7C9A12C286082FF7D2394D18F\ +783E1A8E72C722CAAAA52D8F065657D2631FD25BFD8E5BAAD6E527D763517501\ +C68C5EDC3CDD55435C532D7125C8614DEED9ADAA3ACADE5888B87BEF641C4C99\ +4C8091B5BCD387F3963FB5BC37AA922FBFE3DF4E5B915E6EB514717BDD2A7407\ +9A5073F5C4BFD46ADF7D282E7A393A52579D11A028DA4D9CD9C77124F9648EE3\ +83B1AC763930E7162A8D37F350B2F74B8472CF09902063C6B32E8C2D9290CEFB\ +D7346D1C779A0DF50EDCDE4531DA07B099C638E83A755944DF2AEF1AA31752FD\ +323DCB710FB4BFBB9D22B925BC3577E1B8949E729A90BBAFEACF7F7879E7B114\ +7E28BA0BAE940DB795A61B15ECF4DF8DB07B824BB062802CC98A9545BB2AAEED\ +77CB3FC6DB15DCD7D80D7D5BC406C4970A3478ADA8899B329198EB61C193FB62\ +75AA8CA340344A75A862AEBE92EEE1CE032FD950B47D7704A3876923B4AD6284\ +4BF4A09C4DBE8B4397184B7471360C9564880AEDDDB9BAA4AF2E75394B08CD32\ +FF479C57A07D3EAB5D54DE5F9738B8D27F27A9F0AB11799D7B7FFEFB2704C95C\ +6AD12C39F1E867A4B7B1D7818A4B753DFD2A89CCB45E001A03A867B187F225DD:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +01000000000000000000000000000000 + +264D3CA8512194FEC312C8C9891F279FEFDD608D0C027B60483A3FA811D65EE5\ +9D52D9E40EC5672D81532B38B6B089CE951F0F9C35590B8B978D175213F329BB\ +1C2FD30F2F7F30492A61A532A79F51D36F5E31A7C9A12C286082FF7D2394D18F\ +783E1A8E72C722CAAAA52D8F065657D2631FD25BFD8E5BAAD6E527D763517501\ +C68C5EDC3CDD55435C532D7125C8614DEED9ADAA3ACADE5888B87BEF641C4C99\ +4C8091B5BCD387F3963FB5BC37AA922FBFE3DF4E5B915E6EB514717BDD2A7407\ +9A5073F5C4BFD46ADF7D282E7A393A52579D11A028DA4D9CD9C77124F9648EE3\ +83B1AC763930E7162A8D37F350B2F74B8472CF09902063C6B32E8C2D9290CEFB\ +D7346D1C779A0DF50EDCDE4531DA07B099C638E83A755944DF2AEF1AA31752FD\ +323DCB710FB4BFBB9D22B925BC3577E1B8949E729A90BBAFEACF7F7879E7B114\ +7E28BA0BAE940DB795A61B15ECF4DF8DB07B824BB062802CC98A9545BB2AAEED\ +77CB3FC6DB15DCD7D80D7D5BC406C4970A3478ADA8899B329198EB61C193FB62\ +75AA8CA340344A75A862AEBE92EEE1CE032FD950B47D7704A3876923B4AD6284\ +4BF4A09C4DBE8B4397184B7471360C9564880AEDDDB9BAA4AF2E75394B08CD32\ +FF479C57A07D3EAB5D54DE5F9738B8D27F27A9F0AB11799D7B7FFEFB2704C95C\ +6AD12C39F1E867A4B7B1D7818A4B753DFD2A89CCB45E001A03A867B187F225DD:\ +FA762A3680B76007928ED4A4F49A9456031B704782E65E16CECB54ED7D017B5E\ +18ABD67B338E81078F21EDB7868D901EBE9C731A7C18B5E6DEC1D6A72E078AC9\ +A4262F860BEEFA14F4E821018272E411A951502B6E79066E84252C3346F3AA62\ +344351A291D4BEDC7A07618BDEA2AF63145CC7A4B8D4070691AE890CD65733E7\ +946E9021A1DFFC4C59F159425EE6D50CA9B135FA6162CEA18A939838DC000FB3\ +86FAD086ACCE5AC07CB2ECE7FD580B00CFA5E98589631DC25E8E2A3DAF2FFDEC\ +26531659912C9D8F7A15E5865EA8FB5816D6207052BD7128CD743C12C8118791\ +A4736811935EB982A532349E31DD401E0B660A568CB1A4711F552F55DED59F1F\ +15BF7196B3CA12A91E488EF59D64F3A02BF45239499AC6176AE321C4A211EC54\ +5365971C5D3F4F09D4EB139BFDF2073D33180B21002B65CC9865E76CB24CD92C\ +874C24C18350399A936AB3637079295D76C417776B94EFCE3A0EF7206B151105\ +19655C956CBD8B2489405EE2B09A6B6EEBE0C53790A12A8998378B33A5B71159\ +625F4BA49D2A2FDBA59FBF0897BC7AABD8D707DC140A80F0F309F835D3DA54AB\ +584E501DFA0EE977FEC543F74186A802B9A37ADB3E8291ECA04D66520D229E60\ +401E7282BEF486AE059AA70696E0E305D777140A7A883ECDCB69B9FF938E8A42\ +31864C69CA2C2043BED007FF3E605E014BCF518138DC3A25C5E236171A2D01D6:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +02000000000000000000000000000000 + +8E41B78C390B5AF9D758BB214A67E9F6BF7727B09AC6124084C37611398FA45D\ +AAD94868600ED391FB1ACD4857A95B466E62EF9F4B377244D1C152E7B30D731A\ +AD30C716D214B707AED99EB5B5E580B3E887CF7497465651D4B60E6042051DA3\ +693C3B78C14489543BE8B6AD0BA629565BBA202313BA7B0D0C94A3252B676F46\ +CC02CE0F8A7D34C0ED229129673C1F61AED579D08A9203A25AAC3A77E9DB6026\ +7996DB38DF637356D9DCD1632E369939F2A29D89345C66E05066F1A3677AEF18\ +DEA4113FAEB629E46721A66D0A7E785D3E29AF2594EB67DFA982AFFE0AAC058F\ +6E15864269B135418261FC3AFB089472CF68C45DD7F231C6249BA0255E1E0338\ +33FC4D00A3FE02132D7BC3873614B8AEE34273581EA0325C81F0270AFFA13641\ +D052D36F0757D484014354D02D6883CA15C24D8C3956B1BD027BCF41F151FD80\ +23C5340E5606F37E90FDB87C86FB4FA634B3718A30BACE06A66EAF8F63C4AA3B\ +637826A87FE8CFA44282E92CB1615AF3A28E53BC74C7CBA1A0977BE9065D0C1A\ +5DEC6C54AE38D37F37AA35283E048E5530A85C4E7A29D7B92EC0C3169CDF2A80\ +5C7604BCE60049B9FB7B8EAAC10F51AE23794CEBA68BB58112E293B9B692CA72\ +1B37C662F8574ED4DBA6F88E170881C82CDDC1034A0CA7E284BF0962B6B26292\ +D836FA9F73C1AC770EEF0F2D3A1EAF61D3E03555FD424EEDD67E18A18094F888:\ +D55F684F81F4426E9FDE92A5FF02DF2AC896AF63962888A97910C1379E20B0A3\ +B1DB613FB7FE2E07004329EA5C22BFD33E3DBE4CF58CC608C2C26C19A2E2FE22\ +F98732C2B5CB844CC6C0702D91E1D50FC4382A7EBA5635CD602432A2306AC4CE\ +82F8D70C8D9BC15F918FE71E74C622D5CF71178BF6E0B9CC9F2B41DD8DBE441C\ +41CD0C73A6DC47A348F6702F9D0E9B1B1431E948E299B9EC2272AB2C5F0C7BE8\ +6AFFA5DEC87A0BEE81D3D50007EDAA2BCFCCB35605155FF36ED8EDD4A40DCD4B\ +243ACD11B2B987BDBFAF91A7CAC27E9C5AEA525EE53DE7B2D3332C8644402B82\ +3E94A7DB26276D2D23AA07180F76B4FD29B9C0823099C9D62C519880AEE7E969\ +7617C1497D47BF3E571950311421B6B734D38B0DB91EB85331B91EA9F61530F5\ +4512A5A52A4BAD589EB69781D537F23297BB459BDAD2948A29E1550BF4787E0B\ +E95BB173CF5FAB17DAB7A13A052A63453D97CCEC1A321954886B7A1299FAAEEC\ +AE35C6EAACA753B041B5E5F093BF83397FD21DD6B3012066FCC058CC32C3B09D\ +7562DEE29509B5839392C9FF05F51F3166AAAC4AC5F238038A3045E6F72E48EF\ +0FE8BC675E82C318A268E43970271BF119B81BF6A982746554F84E72B9F00280\ +A320A08142923C23C883423FF949827F29BBACDC1CCDB04938CE6098C95BA6B3\ +2528F4EF78EED778B2E122DDFD1CBDD11D1C0A6783E011FC536D63D053260637:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +FD000000000000000000000000000000 + +D55F684F81F4426E9FDE92A5FF02DF2AC896AF63962888A97910C1379E20B0A3\ +B1DB613FB7FE2E07004329EA5C22BFD33E3DBE4CF58CC608C2C26C19A2E2FE22\ +F98732C2B5CB844CC6C0702D91E1D50FC4382A7EBA5635CD602432A2306AC4CE\ +82F8D70C8D9BC15F918FE71E74C622D5CF71178BF6E0B9CC9F2B41DD8DBE441C\ +41CD0C73A6DC47A348F6702F9D0E9B1B1431E948E299B9EC2272AB2C5F0C7BE8\ +6AFFA5DEC87A0BEE81D3D50007EDAA2BCFCCB35605155FF36ED8EDD4A40DCD4B\ +243ACD11B2B987BDBFAF91A7CAC27E9C5AEA525EE53DE7B2D3332C8644402B82\ +3E94A7DB26276D2D23AA07180F76B4FD29B9C0823099C9D62C519880AEE7E969\ +7617C1497D47BF3E571950311421B6B734D38B0DB91EB85331B91EA9F61530F5\ +4512A5A52A4BAD589EB69781D537F23297BB459BDAD2948A29E1550BF4787E0B\ +E95BB173CF5FAB17DAB7A13A052A63453D97CCEC1A321954886B7A1299FAAEEC\ +AE35C6EAACA753B041B5E5F093BF83397FD21DD6B3012066FCC058CC32C3B09D\ +7562DEE29509B5839392C9FF05F51F3166AAAC4AC5F238038A3045E6F72E48EF\ +0FE8BC675E82C318A268E43970271BF119B81BF6A982746554F84E72B9F00280\ +A320A08142923C23C883423FF949827F29BBACDC1CCDB04938CE6098C95BA6B3\ +2528F4EF78EED778B2E122DDFD1CBDD11D1C0A6783E011FC536D63D053260637:\ +72EFC1EBFE1EE25975A6EB3AA8589DDA2B261F1C85BDAB442A9E5B2DD1D7C395\ +7A16FC08E526D4B1223F1B1232A11AF274C3D70DAC57F83E0983C498F1A6F1AE\ +CB021C3E70085A1E527F1CE41EE5911A82020161529CD82773762DAF5459DE94\ +A0A82ADAE7E1703C808543C29ED6FB32D9E004327C1355180C995A07741493A0\ +9C21BA01A387882DA4F62534B87BB15D60D197201C0FD3BF30C1500A3ECFECDD\ +66D8721F90BCC4C17EE925C61B0A03727A9C0D5F5CA462FBFA0AF1C2513A9D9D\ +4B5345BD27A5F6E653F751693E6B6A2B8EAD57D511E00E58C45B7B8D005AF792\ +88F5C7C22FD4F1BF7A898B03A5634C6A1AE3F9FAE5DE4F296A2896B23E7ED43E\ +D14FA5A2803F4D28F0D3FFCF24757677AEBDB47BB388378708948A8D4126ED18\ +39E0DA29A537A8C198B3C66AB00712DD261674BF45A73D67F76914F830CA014B\ +65596F27E4CF62DE66125A5566DF9975155628B400FBFB3A29040ED50FAFFDBB\ +18AECE7C5C44693260AAB386C0A37B11B114F1C415AEBB653BE468179428D43A\ +4D8BC3EC38813ECA30A13CF1BB18D524F1992D44D8B1A42EA30B22E6C95B199D\ +8D182F8840B09D059585C31AD691FA0619FF038ACA2C39A943421157361717C4\ +9D322028A74648113BD8C9D7EC77CF3C89C1EC8718CEFF8516D96B34C3C614F1\ +0699C9ABC4ED0411506223BEA16AF35C883ACCDBE1104EEF0CFDB54E12FB230A:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +FE000000000000000000000000000000 + +72EFC1EBFE1EE25975A6EB3AA8589DDA2B261F1C85BDAB442A9E5B2DD1D7C395\ +7A16FC08E526D4B1223F1B1232A11AF274C3D70DAC57F83E0983C498F1A6F1AE\ +CB021C3E70085A1E527F1CE41EE5911A82020161529CD82773762DAF5459DE94\ +A0A82ADAE7E1703C808543C29ED6FB32D9E004327C1355180C995A07741493A0\ +9C21BA01A387882DA4F62534B87BB15D60D197201C0FD3BF30C1500A3ECFECDD\ +66D8721F90BCC4C17EE925C61B0A03727A9C0D5F5CA462FBFA0AF1C2513A9D9D\ +4B5345BD27A5F6E653F751693E6B6A2B8EAD57D511E00E58C45B7B8D005AF792\ +88F5C7C22FD4F1BF7A898B03A5634C6A1AE3F9FAE5DE4F296A2896B23E7ED43E\ +D14FA5A2803F4D28F0D3FFCF24757677AEBDB47BB388378708948A8D4126ED18\ +39E0DA29A537A8C198B3C66AB00712DD261674BF45A73D67F76914F830CA014B\ +65596F27E4CF62DE66125A5566DF9975155628B400FBFB3A29040ED50FAFFDBB\ +18AECE7C5C44693260AAB386C0A37B11B114F1C415AEBB653BE468179428D43A\ +4D8BC3EC38813ECA30A13CF1BB18D524F1992D44D8B1A42EA30B22E6C95B199D\ +8D182F8840B09D059585C31AD691FA0619FF038ACA2C39A943421157361717C4\ +9D322028A74648113BD8C9D7EC77CF3C89C1EC8718CEFF8516D96B34C3C614F1\ +0699C9ABC4ED0411506223BEA16AF35C883ACCDBE1104EEF0CFDB54E12FB230A:\ +3260AE8DAD1F4A32C5CAFE3AB0EB95549D461A67CEB9E5AA2D3AFB62DECE0553\ +193BA50C75BE251E08D1D08F1088576C7EFDFAAF3F459559571E12511753B07A\ +F073F35DA06AF0CE0BBF6B8F5CCC5CEA500EC1B211BD51F63B606BF6528796CA\ +12173BA39B8935EE44CCCE646F90A45BF9CCC567F0ACE13DC2D53EBEEDC81F58\ +B2E41179DDDF0D5A5C42F5D8506C1A5D2F8F59F3EA873CBCD0EEC19ACBF32542\ +3BD3DCB8C2B1BF1D1EAED0EBA7F0698E4314FBEB2F1566D1B9253008CBCCF45A\ +2B0D9C5C9C21474F4076E02BE26050B99DEE4FD68A4CF890E496E4FCAE7B70F9\ +4EA5A9062DA0DAEBA1993D2CCD1DD3C244B8428801495A58B216547E7E847C46\ +D1D756377B6242D2E5FB83BF752B54E0DF71E889F3A2BB0F4C10805BF3C59037\ +6E3C24E22FF57F7FA965577375325CEA5D920DB94B9C336B455F6E894C01866F\ +E9FBB8C8D3F70A2957285F6DFB5DCD8CBF54782F8FE7766D4723819913AC7734\ +21E3A31095866BAD22C86A6036B2518B2059B4229D18C8C2CCBDF906C6CC6E82\ +464EE57BDDB0BEBCB1DC645325BFB3E665EF7251082C88EBB1CF203BD779FDD3\ +8675713C8DAADD17E1CABEE432B09787B6DDF3304E38B731B45DF5DF51B78FCF\ +B3D32466028D0BA36555E7E11AB0EE0666061D1645D962444BC47A38188930A8\ +4B4D561395C73C087021927CA638B7AFC8A8679CCB84C26555440EC7F10445CD:\ +2718281828459045235360287471352631415926535897932384626433832795:\ +FF000000000000000000000000000000 + +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\ +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF:\ +1C3B3A102F770386E4836C99E370CF9BEA00803F5E482357A4AE12D414A3E63B\ +5D31E276F8FE4A8D66B317F9AC683F44680A86AC35ADFC3345BEFECB4BB188FD\ +5776926C49A3095EB108FD1098BAEC70AAA66999A72A82F27D848B21D4A741B0\ +C5CD4D5FFF9DAC89AEBA122961D03A757123E9870F8ACF1000020887891429CA\ +2A3E7A7D7DF7B10355165C8B9A6D0A7DE8B062C4500DC4CD120C0F7418DAE3D0\ +B5781C34803FA75421C790DFE1DE1834F280D7667B327F6C8CD7557E12AC3A0F\ +93EC05C52E0493EF31A12D3D9260F79A289D6A379BC70C50841473D1A8CC81EC\ +583E9645E07B8D9670655BA5BBCFECC6DC3966380AD8FECB17B6BA02469A020A\ +84E18E8F84252070C13E9F1F289BE54FBC481457778F616015E1327A02B140F1\ +505EB309326D68378F8374595C849D84F4C333EC4423885143CB47BD71C5EDAE\ +9BE69A2FFECEB1BEC9DE244FBE15992B11B77C040F12BD8F6A975A44A0F90C29\ +A9ABC3D4D893927284C58754CCE294529F8614DCD2ABA991925FEDC4AE74FFAC\ +6E333B93EB4AFF0479DA9A410E4450E0DD7AE4C6E2910900575DA401FC07059F\ +645E8B7E9BFDEF33943054FF84011493C27B3429EAEDB4ED5376441A77ED4385\ +1AD77F16F541DFD269D50D6A5F14FB0AAB1CBB4C1550BE97F7AB4066193C4CAA\ +773DAD38014BD2092FA755C824BB5E54C4F36FFDA9FCEA70B9C6E693E148C151:\ +2718281828459045235360287471352662497757247093699959574966967627\ +3141592653589793238462643383279502884197169399375105820974944592:\ +FF000000000000000000000000000000 + +000102030405060708090A0B0C0D0E0F10:\ +6C1625DB4671522D3D7599601DE7CA09ED:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +000102030405060708090A0B0C0D0E0F1011:\ +D069444B7A7E0CAB09E24447D24DEB1FEDBF:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +000102030405060708090A0B0C0D0E0F101112:\ +E5DF1351C0544BA1350B3363CD8EF4BEEDBF9D:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +000102030405060708090A0B0C0D0E0F10111213:\ +9D84C813F719AA2C7BE3F66171C7C5C2EDBF9DAC:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\ +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F\ +202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F\ +404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F\ +606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F\ +808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F\ +A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF\ +C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF:\ +38B45812EF43A05BD957E545907E223B954AB4AAF088303AD910EADF14B42BE6\ +8B2461149D8C8BA85F992BE970BC621F1B06573F63E867BF5875ACAFA04E42CC\ +BD7BD3C2A0FB1FFF791EC5EC36C66AE4AC1E806D81FBF709DBE29E471FAD3854\ +9C8E66F5345D7C1EB94F405D1EC785CC6F6A68F6254DD8339F9D84057E01A177\ +41990482999516B5611A38F41BB6478E6F173F320805DD71B1932FC333CB9EE3\ +9936BEEA9AD96FA10FB4112B901734DDAD40BC1878995F8E11AEE7D141A2F5D4\ +8B7A4E1E7F0B2C04830E69A4FD1378411C2F287EDF48C6C4E5C247A19680F7FE\ +41CEFBD49B582106E3616CBBE4DFB2344B2AE9519391F3E0FB4922254B1D6D2D\ +19C6D4D537B3A26F3BCC51588B32F3ECA0829B6A5AC72578FB814FB43CF80D64\ +A233E3F997A3F02683342F2B33D25B492536B93BECB2F5E1A8B82F5B88334272\ +9E8AE09D16938841A21A97FB543EEA3BBFF59F13C1A18449E398701C1AD51648\ +346CBC04C27BB2DA3B93A1372CCAE548FB53BEE476F9E9C91773B1BB19828394\ +D55D3E1A20ED69113A860B6829FFA847224604435070221B257E8DFF783615D2\ +CAE4803A93AA4334AB482A0AFAC9C0AEDA70B45A481DF5DEC5DF8CC0F423C77A\ +5FD46CD312021D4B438862419A791BE03BB4D97C0E59578542531BA466A83BAF\ +92CEFC151B5CC1611A167893819B63FB8A6B18E86DE60290FA72B797B0CE59F3:\ +E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECF:\ +21436587A90000000000000000000000 + +# Generated by Botan + +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E:\ +D05BC090A8E04F1B3D3ECDD5BAEC0FD4EDBF9DACE45D6F6A7306E64BE5DD82:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + # MARKER: Cipher Modes (Decryption) # Cipher mode format is plaintext:ciphertext:key:iv @@ -24891,6 +25217,47 @@ C61A0851AB4E515D11525B92E2B9D850:C825FC7C4D539DC74887CECC70884F37 710DABD24D400F3B6B:60:\ F956B879EC7F807F1FCB482B53623671:E64F90B4619D93137E6237929EABF297 +[AES/XTS] +917CF69EBD68B2EC9B9FE9A3EADDA692CD43D2F59598ED858C02C2652FBF922E:\ +0000000000000000000000000000000000000000000000000000000000000000:\ +0000000000000000000000000000000000000000000000000000000000000000:\ +00000000000000000000000000000000 + +C454185E6A16936E39334038ACEF838BFB186FFF7480ADC4289382ECD6D394F0:\ +4444444444444444444444444444444444444444444444444444444444444444:\ +1111111111111111111111111111111122222222222222222222222222222222:\ +33333333330000000000000000000000 + +B01F86F8EDC1863706FA8A4253E34F28AF319DE38334870F4DD1F94CBE9832F1:\ +4444444444444444444444444444444444444444444444444444444444444444:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +6C1625DB4671522D3D7599601DE7CA09ED:\ +000102030405060708090A0B0C0D0E0F10:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +D069444B7A7E0CAB09E24447D24DEB1FEDBF:\ +000102030405060708090A0B0C0D0E0F1011:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +E5DF1351C0544BA1350B3363CD8EF4BEEDBF9D:\ +000102030405060708090A0B0C0D0E0F101112:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +9D84C813F719AA2C7BE3F66171C7C5C2EDBF9DAC:\ +000102030405060708090A0B0C0D0E0F10111213:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + +D05BC090A8E04F1B3D3ECDD5BAEC0FD4EDBF9DACE45D6F6A7306E64BE5DD82:\ +000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E:\ +FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0:\ +9A785634120000000000000000000000 + # MARKER: Stream Ciphers # Stream cipher format is plaintext:ciphertext:key diff --git a/src/engine/def_engine/def_mode.cpp b/src/engine/def_engine/def_mode.cpp index a61683f93..2b093a0a3 100644 --- a/src/engine/def_engine/def_mode.cpp +++ b/src/engine/def_engine/def_mode.cpp @@ -40,6 +40,10 @@ #include <botan/eax.h> #endif +#if defined(BOTAN_HAS_XTS) + #include <botan/xts.h> +#endif + namespace Botan { namespace { @@ -188,6 +192,16 @@ Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, } #endif +#if defined(BOTAN_HAS_XTS) + if(mode == "XTS") + { + if(direction == ENCRYPTION) + return new XTS_Encryption(block_cipher->clone()); + else + return new XTS_Decryption(block_cipher->clone()); + } +#endif + throw Algorithm_Not_Found("get_mode: " + cipher_name + "/" + mode + "/" + padding); } diff --git a/src/modes/xts/info.txt b/src/modes/xts/info.txt new file mode 100644 index 000000000..30d8f3496 --- /dev/null +++ b/src/modes/xts/info.txt @@ -0,0 +1,15 @@ +realname "XTS block cipher mode" + +define XTS + +load_on auto + +<add> +xts.cpp +xts.h +</add> + +<requires> +modes +</requires> + diff --git a/src/modes/xts/xts.cpp b/src/modes/xts/xts.cpp new file mode 100644 index 000000000..8819c85dc --- /dev/null +++ b/src/modes/xts/xts.cpp @@ -0,0 +1,344 @@ +/* +* XTS Mode +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/xts.h> +#include <botan/xor_buf.h> +#include <algorithm> +#include <stdexcept> + +namespace Botan { + +namespace { + +void poly_double(byte tweak[], u32bit size) + { + const byte polynomial = 0x87; // for 128 bit ciphers + + byte carry = 0; + for(u32bit i = 0; i != size; ++i) + { + byte carry2 = (tweak[i] >> 7); + tweak[i] = (tweak[i] << 1) | carry; + carry = carry2; + } + + if(carry) + tweak[0] ^= polynomial; + } + +} + +/* +* XTS_Encryption constructor +*/ +XTS_Encryption::XTS_Encryption(BlockCipher* ciph) : cipher(ciph) + { + if(cipher->BLOCK_SIZE != 16) + throw std::invalid_argument("Bad cipher for XTS: " + cipher->name()); + + cipher2 = cipher->clone(); + buffer.create(cipher->BLOCK_SIZE); + tweak.create(cipher->BLOCK_SIZE); + buffer.create(2 * cipher->BLOCK_SIZE); + position = 0; + } + +/* +* XTS_Encryption constructor +*/ +XTS_Encryption::XTS_Encryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv) : cipher(ciph) + { + if(cipher->BLOCK_SIZE != 16) + throw std::invalid_argument("Bad cipher for XTS: " + cipher->name()); + + cipher2 = cipher->clone(); + buffer.create(cipher->BLOCK_SIZE); + tweak.create(cipher->BLOCK_SIZE); + buffer.create(2 * cipher->BLOCK_SIZE); + position = 0; + + set_key(key); + set_iv(iv); + } + +/* +* Return the name +*/ +std::string XTS_Encryption::name() const + { + return (cipher->name() + "/XTS"); + } + +/* +* Set new tweak +*/ +void XTS_Encryption::set_iv(const InitializationVector& iv) + { + if(iv.length() != tweak.size()) + throw Invalid_IV_Length(name(), iv.length()); + + tweak = iv.bits_of(); + cipher2->encrypt(tweak); + } + +void XTS_Encryption::set_key(const SymmetricKey& key) + { + u32bit key_half = key.length() / 2; + + if(key.length() % 2 == 1 || !cipher->valid_keylength(key_half)) + throw Invalid_Key_Length(name(), key.length()); + + cipher->set_key(key.begin(), key_half); + cipher2->set_key(key.begin() + key_half, key_half); + } + +void XTS_Encryption::encrypt(const byte block[]) + { + /* + * We can always use the first 16 bytes of buffer as temp space, + * since either the input block is buffer (in which case this is + * just buffer ^= tweak) or it not, in which case we already read + * and used the data there and are processing new input. Kind of + * subtle/nasty, but saves allocating a distinct temp buf. + */ + + xor_buf(buffer, block, tweak, cipher->BLOCK_SIZE); + cipher->encrypt(buffer); + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + + poly_double(tweak, cipher->BLOCK_SIZE); + + send(buffer, cipher->BLOCK_SIZE); + } + +/* +* Encrypt in XTS mode +*/ +void XTS_Encryption::write(const byte input[], u32bit length) + { + const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; + + u32bit copied = std::min(buffer.size() - position, length); + buffer.copy(position, input, copied); + length -= copied; + input += copied; + position += copied; + + if(length == 0) return; + + encrypt(buffer); + if(length > BLOCK_SIZE) + { + encrypt(buffer + BLOCK_SIZE); + while(length > buffer.size()) + { + encrypt(input); + length -= BLOCK_SIZE; + input += BLOCK_SIZE; + } + position = 0; + } + else + { + copy_mem(buffer.begin(), buffer + BLOCK_SIZE, BLOCK_SIZE); + position = BLOCK_SIZE; + } + buffer.copy(position, input, length); + position += length; + } + +/* +* Finish encrypting in XTS mode +*/ +void XTS_Encryption::end_msg() + { + const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; + + if(position < BLOCK_SIZE) + throw Exception("XTS_Encryption: insufficient data to encrypt"); + else if(position == BLOCK_SIZE) + { + encrypt(buffer); + } + else if(position == 2*BLOCK_SIZE) + { + encrypt(buffer); + encrypt(buffer + BLOCK_SIZE); + } + else + { // steal ciphertext + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + cipher->encrypt(buffer); + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + + poly_double(tweak, cipher->BLOCK_SIZE); + + for(u32bit i = 0; i != position - cipher->BLOCK_SIZE; ++i) + std::swap(buffer[i], buffer[i + cipher->BLOCK_SIZE]); + + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + cipher->encrypt(buffer); + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + + send(buffer, position); + } + } + +/* +* XTS_Decryption constructor +*/ +XTS_Decryption::XTS_Decryption(BlockCipher* ciph) + { + cipher = ciph; + cipher2 = ciph->clone(); + buffer.create(cipher->BLOCK_SIZE); + tweak.create(cipher->BLOCK_SIZE); + buffer.create(2 * cipher->BLOCK_SIZE); + position = 0; + } + +/* +* XTS_Decryption constructor +*/ +XTS_Decryption::XTS_Decryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv) + { + cipher = ciph; + cipher2 = ciph->clone(); + buffer.create(cipher->BLOCK_SIZE); + tweak.create(cipher->BLOCK_SIZE); + buffer.create(2 * cipher->BLOCK_SIZE); + position = 0; + + set_key(key); + set_iv(iv); + } + +/* +* Return the name +*/ +std::string XTS_Decryption::name() const + { + return (cipher->name() + "/XTS"); + } + +/* +* Set new tweak +*/ +void XTS_Decryption::set_iv(const InitializationVector& iv) + { + if(iv.length() != tweak.size()) + throw Invalid_IV_Length(name(), iv.length()); + + tweak = iv.bits_of(); + cipher2->encrypt(tweak); + } + +void XTS_Decryption::set_key(const SymmetricKey& key) + { + u32bit key_half = key.length() / 2; + + if(key.length() % 2 == 1 || !cipher->valid_keylength(key_half)) + throw Invalid_Key_Length(name(), key.length()); + + cipher->set_key(key.begin(), key_half); + cipher2->set_key(key.begin() + key_half, key_half); + } + +/* +* Decrypt a block +*/ +void XTS_Decryption::decrypt(const byte block[]) + { + xor_buf(buffer, block, tweak, cipher->BLOCK_SIZE); + cipher->decrypt(buffer); + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + + poly_double(tweak, cipher->BLOCK_SIZE); + + send(buffer, cipher->BLOCK_SIZE); + } + +/* +* Decrypt in XTS mode +*/ +void XTS_Decryption::write(const byte input[], u32bit length) + { + const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; + + u32bit copied = std::min(buffer.size() - position, length); + buffer.copy(position, input, copied); + length -= copied; + input += copied; + position += copied; + + if(length == 0) return; + + decrypt(buffer); + if(length > BLOCK_SIZE) + { + decrypt(buffer + BLOCK_SIZE); + while(length > 2*BLOCK_SIZE) + { + decrypt(input); + length -= BLOCK_SIZE; + input += BLOCK_SIZE; + } + position = 0; + } + else + { + copy_mem(buffer.begin(), buffer + BLOCK_SIZE, BLOCK_SIZE); + position = BLOCK_SIZE; + } + buffer.copy(position, input, length); + position += length; + } + +/* +* Finish decrypting in XTS mode +*/ +void XTS_Decryption::end_msg() + { + const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; + + if(position < BLOCK_SIZE) + throw Exception("XTS_Decryption: insufficient data to decrypt"); + else if(position == BLOCK_SIZE) + { + decrypt(buffer); + } + else if(position == 2*BLOCK_SIZE) + { + decrypt(buffer); + decrypt(buffer + BLOCK_SIZE); + } + else + { + SecureVector<byte> tweak2 = tweak; + + poly_double(tweak2, cipher->BLOCK_SIZE); + + xor_buf(buffer, tweak2, cipher->BLOCK_SIZE); + cipher->decrypt(buffer); + xor_buf(buffer, tweak2, cipher->BLOCK_SIZE); + + for(u32bit i = 0; i != position - cipher->BLOCK_SIZE; ++i) + std::swap(buffer[i], buffer[i + cipher->BLOCK_SIZE]); + + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + cipher->decrypt(buffer); + xor_buf(buffer, tweak, cipher->BLOCK_SIZE); + + send(buffer, position); + } + } + +} diff --git a/src/modes/xts/xts.h b/src/modes/xts/xts.h new file mode 100644 index 000000000..01558175b --- /dev/null +++ b/src/modes/xts/xts.h @@ -0,0 +1,76 @@ +/* +* XTS mode, from IEEE P1619 +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_XTS_H__ +#define BOTAN_XTS_H__ + +#include <botan/basefilt.h> +#include <botan/block_cipher.h> + +namespace Botan { + +/* +* XTS Encryption +*/ +class BOTAN_DLL XTS_Encryption : public Keyed_Filter + { + public: + void set_key(const SymmetricKey& key); + void set_iv(const InitializationVector& iv); + + std::string name() const; + + XTS_Encryption(BlockCipher* ciph); + + XTS_Encryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv); + + ~XTS_Encryption() { delete cipher; delete cipher2; } + private: + void write(const byte[], u32bit); + void end_msg(); + void encrypt(const byte block[]); + + BlockCipher* cipher; + BlockCipher* cipher2; + SecureVector<byte> tweak; + SecureVector<byte> buffer; + u32bit position; + }; + +/* +* XTS Decryption +*/ +class BOTAN_DLL XTS_Decryption : public Keyed_Filter + { + public: + void set_key(const SymmetricKey& key); + void set_iv(const InitializationVector& iv); + + std::string name() const; + + XTS_Decryption(BlockCipher* ciph); + + XTS_Decryption(BlockCipher* ciph, + const SymmetricKey& key, + const InitializationVector& iv); + private: + void write(const byte[], u32bit); + void end_msg(); + void decrypt(const byte[]); + + BlockCipher* cipher; + BlockCipher* cipher2; + SecureVector<byte> tweak; + SecureVector<byte> buffer; + u32bit position; + }; + +} + +#endif |