diff options
author | Jeffrey Walton <noloader@gmail.com> | 2019-10-12 07:14:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-12 07:14:38 -0400 |
commit | 76c29eadafc2a4df656a6505b58293ef4cfa3288 (patch) | |
tree | e7131043045caecc7aa6ece37ec2befdfcb8df52 /cmac.cpp | |
parent | 85ecff46093ff8f3da4efd8b5d840b8bb7d681ce (diff) | |
download | cryptopp-git-76c29eadafc2a4df656a6505b58293ef4cfa3288.tar.gz |
Add XTS block cipher mode of operation (GH #891, PR #892)
Diffstat (limited to 'cmac.cpp')
-rw-r--r-- | cmac.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -5,14 +5,17 @@ #ifndef CRYPTOPP_IMPORTS
#include "cmac.h"
+#include "misc.h"
-NAMESPACE_BEGIN(CryptoPP)
+ANONYMOUS_NAMESPACE_BEGIN
+
+using CryptoPP::byte;
+using CryptoPP::IsPowerOf2;
-static void MulU(byte *k, unsigned int length)
+void MulU(byte *k, unsigned int len)
{
byte carry = 0;
-
- for (int i=length-1; i>=1; i-=2)
+ for (int i=len-1; i>=1; i-=2)
{
byte carry2 = k[i] >> 7;
k[i] += k[i] + carry;
@@ -20,9 +23,22 @@ static void MulU(byte *k, unsigned int length) k[i-1] += k[i-1] + carry2;
}
+#ifndef CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS
+ CRYPTOPP_ASSERT(len == 16);
+
+ if (carry)
+ {
+ k[15] ^= 0x87;
+ return;
+ }
+#else
+ CRYPTOPP_ASSERT(IsPowerOf2(len));
+ CRYPTOPP_ASSERT(len >= 8);
+ CRYPTOPP_ASSERT(len <= 128);
+
if (carry)
{
- switch (length)
+ switch (len)
{
case 8:
k[7] ^= 0x1b;
@@ -50,11 +66,16 @@ static void MulU(byte *k, unsigned int length) k[127] ^= 0x43;
break;
default:
- throw InvalidArgument("CMAC: " + IntToString(length) + " is not a supported cipher block size");
+ CRYPTOPP_ASSERT(0);
}
}
+#endif // CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS
}
+ANONYMOUS_NAMESPACE_END
+
+NAMESPACE_BEGIN(CryptoPP)
+
void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
{
BlockCipher &cipher = AccessCipher();
|