aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/validate.dat272
-rw-r--r--include/cbc_mac.h36
-rw-r--r--src/cbc_mac.cpp108
-rw-r--r--src/def_alg.cpp2
4 files changed, 282 insertions, 136 deletions
diff --git a/checks/validate.dat b/checks/validate.dat
index 99a1b7e1c..a57b3b5ba 100644
--- a/checks/validate.dat
+++ b/checks/validate.dat
@@ -31180,142 +31180,142 @@ D41D8CD98F00B204E9800998ECF8427E
# MAC format is input:mac:key
-#[CBC-MAC(DES)]
-#37363534333231204E6F77206973207468652074696D6520666F7220:\
-#F1D30F6849312CA4:0123456789ABCDEF
-#
-#:0000000000000000:67C6697351FF4AEC
-#
-#29:616FE88F809D55FE:CDBAABF2FBE3467C
-#
-#C254:AED0202A4D19E0E1:F81BE8E78D765A2E
-#
-#63339F:69E2BBE362FFA373:C99A66320DB73158
-#
-#A35A255D:99AF085AE0872883:051758E95ED4ABB2
-#
-#CDC69BB454:346750C009F85AE7:110E827441213DDC
-#
-#8770E93EA141:457FA6D39A704CDB:E1FC673E017E97EA
-#
-#DC6B968F385C2A:725FFF0F41477E42:ECB03BFB32AF3C54
-#
-#EC18DB5C021AFE43:1D119FAEB0BB44C3:FBFAAA3AFB29D1E6
-#
-#053C7C9475D8BE6189:E4DD5474534FE9DA:F95CBBA8990F95B1
-#
-#EBF1B305EFF700E9A13A:BEE63E65CAEFA450:E5CA0BCBD0484764
-#
-#BD1F231EA81C7B64C51473:495FF947F6665F45:5AC55E4B79633B70
-#
-#6424119E09DCAAD4ACF21B10:53C806C8B69CF03C:AF3B33CDE3504847
-#
-#155CBB6F2219BA9B7DF50BE11A:2CFD97F2BD38C7A0:1C7F23F829F8A41B
-#
-#13B5CA4EE8983238E0794D3D34BC:A83C88744DF51267:5F4E77FACB6C05AC
-#
-#86212BAA1A55A2BE70B5733B045CD3:112C46B74BD7D1EC:3694B3AFE2F0E49E
-#
-#4F321549FD824EA90870D4B28A295448:F12831C24A551F5C:9A0ABCD50E18A844
-#
-#AC5BF38E4CD72D9B0942E506C433AFCDA3:0AB4EC81A81F5C6C:847F2DADD47647DE
-#
-#321CEC4AC430F62023856CFBB20704F4EC0B:B2D3297BE75E9505:B920BA86C33E05F1
-#
-#ECD96733B79950A3E314D3D934F75EA0F210A8:0AA5F1B82E138AB3:F6059401BEB4BC44
-#
-#78FA4969E623D01ADA696A7E4C7E5125B3488453:7143592230891CC9:3A94FB3199903257
-#
-#44EE9BBCE9E525CF08F5E9E25E5360AAD2B2D085FA:90E6F543EDA1AC82:54D835E8D4668264
-#
-#98D9A8877565705A8A3F62802944DE7CA5894E5759D3:491310A9E2B8B18C:51ADAC869580EC17
-#
-#E485F18C0C66F17CC07CBB22FCE466DA610B63AF62BC83:302E436ABB2B6193:B4692F3AFFAF2716
-#
-#93AC071FB86D11342D8DEF4F89D4B66335C1C7E4248367D8:\
-#1ED636A10A187609:ED9612EC453902D8
-#
-#E50AF89D7709D1A596C1F41F95AA82CA6C49AE90CD1668BAAC:\
-#2A02740B45449296:7AA6F2B4A8CA99B2
-#
-#C2372ACB08CF61C9C3805E6E0328DA4CD76A19EDD2D3994C798B:\
-#CEA8016EAE33A92B:0022569AD418D1FE
-#
-#E4D9CD45A391C601FFC92AD91501432FEE150287617C13629E69FC:\
-#E584507E7606DD42:7281CD7165A63EAB
-#
-#49CF714BCE3A75A74F76EA7E64FF81EB61FDFEC39B67BF0DE98C7E4E:\
-#5A09D5EF7B21251E:32BDF97C8C6AC75B
-#
-#A43C02F4B2ED7216ECF3014DF000108B67CF99505B179F8ED4980A6103:\
-#3AA4E5750CA579D9:D1BCA70DBE9BBFAB
-#
-#0ED59801D6E5F2D6F67D3EC5168E212E2DAF02C6B963C98A1F7097DE0C56:\
-#FAC262455D9691C6:891A2B211B01070D
-#
-#D8FD8B16C2A1A4E3CFD292D2984B3561D555D16C33DDC2BCF7EDDE13EFE520:\
-#32127540A949B873:C7E2ABDDA44D8188
-#
-#[CBC-MAC(AES-128)]
-#
-#:00000000000000000000000000000000:67C6697351FF4AEC29CDBAABF2FBE346
-#
-#7C:A2F5C113EBEE0F124B649287C7F7986F:C254F81BE8E78D765A2E63339FC99A66
-#
-#320D:5C787D4CDAF3B4D106A7AA09F41BCFCA:B73158A35A255D051758E95ED4ABB2CD
-#
-#C69BB4:B32F25C34E061A972C49E4B0A0678AA5:54110E827441213DDC8770E93EA141E1
-#
-#FC673E01:B5D6A0E8F3202BFF37796DB5EB920B7E:7E97EADC6B968F385C2AECB03BFB32AF
-#
-#3C54EC18DB:F3896484B179F90BE3B62DCE3F748C52:5C021AFE43FBFAAA3AFB29D1E6053C7C
-#
-#9475D8BE6189:100D2CDA97B85428D785D9EECC8D51E2:F95CBBA8990F95B1EBF1B305EFF700E9
-#
-#A13AE5CA0BCBD0:\
-#92A7A024C4F6D8C82C53030545C23C10:484764BD1F231EA81C7B64C514735AC5
-#
-#5E4B79633B706424:\
-#E235CFD4C307E2B3D44199E83E5D83C6:119E09DCAAD4ACF21B10AF3B33CDE350
-#
-#4847155CBB6F2219BA:\
-#2379D24A48EF60E46807E92C1A602AA6:9B7DF50BE11A1C7F23F829F8A41B13B5
-#
-#CA4EE8983238E0794D3D:\
-#D6DA42CAE5C664F3C4D597CF6CE1DDD7:34BC5F4E77FACB6C05AC86212BAA1A55
-#
-#A2BE70B5733B045CD33694:\
-#93990491923BF761B3220C1E45ACD359:B3AFE2F0E49E4F321549FD824EA90870
-#
-#D4B28A2954489A0ABCD50E18:\
-#9B14531370EE1EFFCF5A3BBC2161D25C:A844AC5BF38E4CD72D9B0942E506C433
-#
-#AFCDA3847F2DADD47647DE321C:\
-#EB597AD53F1B208B4FEB5C20D78545AB:EC4AC430F62023856CFBB20704F4EC0B
-#
-#B920BA86C33E05F1ECD96733B799:\
-#91C3626B64EA3B16E15C2F9B32189C68:50A3E314D3D934F75EA0F210A8F60594
-#
-#01BEB4BC4478FA4969E623D01ADA69:\
-#F6251F1A89FE388121DED78B8CA9FD7C:6A7E4C7E5125B34884533A94FB319990
-#
-#325744EE9BBCE9E525CF08F5E9E25E53:\
-#E55A004723589CAA843140BA5AC52119:60AAD2B2D085FA54D835E8D466826498
-#
-#D9A8877565705A8A3F62802944DE7CA589:\
-#53A217151AA961BBF0C7AD4AFDCB9B5F:4E5759D351ADAC869580EC17E485F18C
-#
-#0C66F17CC07CBB22FCE466DA610B63AF62BC:\
-#CE21D27F4D455511CD327D205853EE85:83B4692F3AFFAF271693AC071FB86D11
-#
-#342D8DEF4F89D4B66335C1C7E4248367D8ED96:\
-#4DC9B5ED541B7382F0FCC7CFAB5AAFE0:12EC453902D8E50AF89D7709D1A596C1
-#
-#F41F95AA82CA6C49AE90CD1668BAAC7AA6F2B4A8:\
-#2FB0B595042C8D7AD592583D7E6C76F7:CA99B2C2372ACB08CF61C9C3805E6E03
-#
-#28DA4CD76A19EDD2D3994C798B0022569AD418D1FE:\
-#AC464531064DA66A2F8591AFAB2931D0:E4D9CD45A391C601FFC92AD91501432F
+[CBC-MAC(DES)]
+37363534333231204E6F77206973207468652074696D6520666F7220:\
+F1D30F6849312CA4:0123456789ABCDEF
+
+:0000000000000000:67C6697351FF4AEC
+
+29:616FE88F809D55FE:CDBAABF2FBE3467C
+
+C254:AED0202A4D19E0E1:F81BE8E78D765A2E
+
+63339F:69E2BBE362FFA373:C99A66320DB73158
+
+A35A255D:99AF085AE0872883:051758E95ED4ABB2
+
+CDC69BB454:346750C009F85AE7:110E827441213DDC
+
+8770E93EA141:457FA6D39A704CDB:E1FC673E017E97EA
+
+DC6B968F385C2A:725FFF0F41477E42:ECB03BFB32AF3C54
+
+EC18DB5C021AFE43:1D119FAEB0BB44C3:FBFAAA3AFB29D1E6
+
+053C7C9475D8BE6189:E4DD5474534FE9DA:F95CBBA8990F95B1
+
+EBF1B305EFF700E9A13A:BEE63E65CAEFA450:E5CA0BCBD0484764
+
+BD1F231EA81C7B64C51473:495FF947F6665F45:5AC55E4B79633B70
+
+6424119E09DCAAD4ACF21B10:53C806C8B69CF03C:AF3B33CDE3504847
+
+155CBB6F2219BA9B7DF50BE11A:2CFD97F2BD38C7A0:1C7F23F829F8A41B
+
+13B5CA4EE8983238E0794D3D34BC:A83C88744DF51267:5F4E77FACB6C05AC
+
+86212BAA1A55A2BE70B5733B045CD3:112C46B74BD7D1EC:3694B3AFE2F0E49E
+
+4F321549FD824EA90870D4B28A295448:F12831C24A551F5C:9A0ABCD50E18A844
+
+AC5BF38E4CD72D9B0942E506C433AFCDA3:0AB4EC81A81F5C6C:847F2DADD47647DE
+
+321CEC4AC430F62023856CFBB20704F4EC0B:B2D3297BE75E9505:B920BA86C33E05F1
+
+ECD96733B79950A3E314D3D934F75EA0F210A8:0AA5F1B82E138AB3:F6059401BEB4BC44
+
+78FA4969E623D01ADA696A7E4C7E5125B3488453:7143592230891CC9:3A94FB3199903257
+
+44EE9BBCE9E525CF08F5E9E25E5360AAD2B2D085FA:90E6F543EDA1AC82:54D835E8D4668264
+
+98D9A8877565705A8A3F62802944DE7CA5894E5759D3:491310A9E2B8B18C:51ADAC869580EC17
+
+E485F18C0C66F17CC07CBB22FCE466DA610B63AF62BC83:302E436ABB2B6193:B4692F3AFFAF2716
+
+93AC071FB86D11342D8DEF4F89D4B66335C1C7E4248367D8:\
+1ED636A10A187609:ED9612EC453902D8
+
+E50AF89D7709D1A596C1F41F95AA82CA6C49AE90CD1668BAAC:\
+2A02740B45449296:7AA6F2B4A8CA99B2
+
+C2372ACB08CF61C9C3805E6E0328DA4CD76A19EDD2D3994C798B:\
+CEA8016EAE33A92B:0022569AD418D1FE
+
+E4D9CD45A391C601FFC92AD91501432FEE150287617C13629E69FC:\
+E584507E7606DD42:7281CD7165A63EAB
+
+49CF714BCE3A75A74F76EA7E64FF81EB61FDFEC39B67BF0DE98C7E4E:\
+5A09D5EF7B21251E:32BDF97C8C6AC75B
+
+A43C02F4B2ED7216ECF3014DF000108B67CF99505B179F8ED4980A6103:\
+3AA4E5750CA579D9:D1BCA70DBE9BBFAB
+
+0ED59801D6E5F2D6F67D3EC5168E212E2DAF02C6B963C98A1F7097DE0C56:\
+FAC262455D9691C6:891A2B211B01070D
+
+D8FD8B16C2A1A4E3CFD292D2984B3561D555D16C33DDC2BCF7EDDE13EFE520:\
+32127540A949B873:C7E2ABDDA44D8188
+
+[CBC-MAC(AES-128)]
+
+:00000000000000000000000000000000:67C6697351FF4AEC29CDBAABF2FBE346
+
+7C:A2F5C113EBEE0F124B649287C7F7986F:C254F81BE8E78D765A2E63339FC99A66
+
+320D:5C787D4CDAF3B4D106A7AA09F41BCFCA:B73158A35A255D051758E95ED4ABB2CD
+
+C69BB4:B32F25C34E061A972C49E4B0A0678AA5:54110E827441213DDC8770E93EA141E1
+
+FC673E01:B5D6A0E8F3202BFF37796DB5EB920B7E:7E97EADC6B968F385C2AECB03BFB32AF
+
+3C54EC18DB:F3896484B179F90BE3B62DCE3F748C52:5C021AFE43FBFAAA3AFB29D1E6053C7C
+
+9475D8BE6189:100D2CDA97B85428D785D9EECC8D51E2:F95CBBA8990F95B1EBF1B305EFF700E9
+
+A13AE5CA0BCBD0:\
+92A7A024C4F6D8C82C53030545C23C10:484764BD1F231EA81C7B64C514735AC5
+
+5E4B79633B706424:\
+E235CFD4C307E2B3D44199E83E5D83C6:119E09DCAAD4ACF21B10AF3B33CDE350
+
+4847155CBB6F2219BA:\
+2379D24A48EF60E46807E92C1A602AA6:9B7DF50BE11A1C7F23F829F8A41B13B5
+
+CA4EE8983238E0794D3D:\
+D6DA42CAE5C664F3C4D597CF6CE1DDD7:34BC5F4E77FACB6C05AC86212BAA1A55
+
+A2BE70B5733B045CD33694:\
+93990491923BF761B3220C1E45ACD359:B3AFE2F0E49E4F321549FD824EA90870
+
+D4B28A2954489A0ABCD50E18:\
+9B14531370EE1EFFCF5A3BBC2161D25C:A844AC5BF38E4CD72D9B0942E506C433
+
+AFCDA3847F2DADD47647DE321C:\
+EB597AD53F1B208B4FEB5C20D78545AB:EC4AC430F62023856CFBB20704F4EC0B
+
+B920BA86C33E05F1ECD96733B799:\
+91C3626B64EA3B16E15C2F9B32189C68:50A3E314D3D934F75EA0F210A8F60594
+
+01BEB4BC4478FA4969E623D01ADA69:\
+F6251F1A89FE388121DED78B8CA9FD7C:6A7E4C7E5125B34884533A94FB319990
+
+325744EE9BBCE9E525CF08F5E9E25E53:\
+E55A004723589CAA843140BA5AC52119:60AAD2B2D085FA54D835E8D466826498
+
+D9A8877565705A8A3F62802944DE7CA589:\
+53A217151AA961BBF0C7AD4AFDCB9B5F:4E5759D351ADAC869580EC17E485F18C
+
+0C66F17CC07CBB22FCE466DA610B63AF62BC:\
+CE21D27F4D455511CD327D205853EE85:83B4692F3AFFAF271693AC071FB86D11
+
+342D8DEF4F89D4B66335C1C7E4248367D8ED96:\
+4DC9B5ED541B7382F0FCC7CFAB5AAFE0:12EC453902D8E50AF89D7709D1A596C1
+
+F41F95AA82CA6C49AE90CD1668BAAC7AA6F2B4A8:\
+2FB0B595042C8D7AD592583D7E6C76F7:CA99B2C2372ACB08CF61C9C3805E6E03
+
+28DA4CD76A19EDD2D3994C798B0022569AD418D1FE:\
+AC464531064DA66A2F8591AFAB2931D0:E4D9CD45A391C601FFC92AD91501432F
[CMAC(AES)]
# First twelve vectors come from a paper, they were generated by Eisuke Kuroda
diff --git a/include/cbc_mac.h b/include/cbc_mac.h
new file mode 100644
index 000000000..aec1c42f1
--- /dev/null
+++ b/include/cbc_mac.h
@@ -0,0 +1,36 @@
+/*************************************************
+* CBC-MAC Header File *
+* (C) 1999-2007 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_CBC_MAC__
+#define BOTAN_CBC_MAC__
+
+#include <botan/base.h>
+
+namespace Botan {
+
+/*************************************************
+* CBC-MAC *
+*************************************************/
+class CBC_MAC : public MessageAuthenticationCode
+ {
+ public:
+ void clear() throw();
+ std::string name() const;
+ MessageAuthenticationCode* clone() const;
+ CBC_MAC(const std::string&);
+ ~CBC_MAC();
+ private:
+ void add_data(const byte[], u32bit);
+ void final_result(byte[]);
+ void key(const byte[], u32bit);
+
+ BlockCipher* e;
+ SecureVector<byte> state;
+ u32bit position;
+ };
+
+}
+
+#endif
diff --git a/src/cbc_mac.cpp b/src/cbc_mac.cpp
new file mode 100644
index 000000000..e805c2aa7
--- /dev/null
+++ b/src/cbc_mac.cpp
@@ -0,0 +1,108 @@
+/*************************************************
+* CBC-MAC Source File *
+* (C) 1999-2007 The Botan Project *
+*************************************************/
+
+#include <botan/cbc_mac.h>
+#include <botan/lookup.h>
+#include <botan/bit_ops.h>
+#include <algorithm>
+
+namespace Botan {
+
+/*************************************************
+* Update an CBC-MAC Calculation *
+*************************************************/
+void CBC_MAC::add_data(const byte input[], u32bit length)
+ {
+ u32bit xored = std::min(8 - position, length);
+ xor_buf(state + position, input, xored);
+ position += xored;
+
+ if(position < 8) return;
+
+ e->encrypt(state);
+ input += xored;
+ length -= xored;
+ while(length >= 8)
+ {
+ xor_buf(state, input, 8);
+ e->encrypt(state);
+ input += 8;
+ length -= 8;
+ }
+
+ xor_buf(state, input, length);
+ position = length;
+ }
+
+/*************************************************
+* Finalize an CBC-MAC Calculation *
+*************************************************/
+void CBC_MAC::final_result(byte mac[])
+ {
+ if(position)
+ e->encrypt(state);
+
+ copy_mem(mac, state.begin(), state.size());
+ state.clear();
+ position = 0;
+ }
+
+/*************************************************
+* CBC-MAC Key Schedule *
+*************************************************/
+void CBC_MAC::key(const byte key[], u32bit length)
+ {
+ e->set_key(key, length);
+ }
+
+/*************************************************
+* Clear memory of sensitive data *
+*************************************************/
+void CBC_MAC::clear() throw()
+ {
+ e->clear();
+ state.clear();
+ position = 0;
+ }
+
+/*************************************************
+* Return the name of this type *
+*************************************************/
+std::string CBC_MAC::name() const
+ {
+ return "CBC-MAC(" + e->name() + ")";
+ }
+
+/*************************************************
+* Return a clone of this object *
+*************************************************/
+MessageAuthenticationCode* CBC_MAC::clone() const
+ {
+ return new CBC_MAC(e->name());
+ }
+
+/*************************************************
+* CBC-MAC Constructor *
+*************************************************/
+CBC_MAC::CBC_MAC(const std::string& cipher) :
+ MessageAuthenticationCode(block_size_of(cipher),
+ min_keylength_of(cipher),
+ max_keylength_of(cipher),
+ keylength_multiple_of(cipher)),
+ state(block_size_of(cipher))
+ {
+ e = get_block_cipher(cipher);
+ position = 0;
+ }
+
+/*************************************************
+* CBC-MAC Destructor *
+*************************************************/
+CBC_MAC::~CBC_MAC()
+ {
+ delete e;
+ }
+
+}
diff --git a/src/def_alg.cpp b/src/def_alg.cpp
index 09ae5c978..2dbd30621 100644
--- a/src/def_alg.cpp
+++ b/src/def_alg.cpp
@@ -52,6 +52,7 @@
#include <botan/whrlpool.h>
#include <botan/par_hash.h>
+#include <botan/cbc_mac.h>
#include <botan/cmac.h>
#include <botan/hmac.h>
#include <botan/x919_mac.h>
@@ -219,6 +220,7 @@ Default_Engine::find_mac(const std::string& algo_spec) const
return 0;
const std::string algo_name = deref_alias(name[0]);
+ HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC);
HANDLE_TYPE_ONE_STRING("CMAC", CMAC);
HANDLE_TYPE_ONE_STRING("HMAC", HMAC);
HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC);