mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Crypto: Add support for Japanese encryption standard Camellia, including for system encryption.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "Crypto/Aes.h"
|
||||
#include "Crypto/Serpent.h"
|
||||
#include "Crypto/Twofish.h"
|
||||
#include "Crypto/Camellia.h"
|
||||
|
||||
#ifdef TC_AES_HW_CPU
|
||||
# include "Crypto/Aes_hw_cpu.h"
|
||||
@@ -77,6 +78,7 @@ namespace VeraCrypt
|
||||
l.push_back (shared_ptr <Cipher> (new CipherAES ()));
|
||||
l.push_back (shared_ptr <Cipher> (new CipherSerpent ()));
|
||||
l.push_back (shared_ptr <Cipher> (new CipherTwofish ()));
|
||||
l.push_back (shared_ptr <Cipher> (new CipherCamellia ()));
|
||||
|
||||
return l;
|
||||
}
|
||||
@@ -239,6 +241,27 @@ namespace VeraCrypt
|
||||
{
|
||||
twofish_set_key ((TwofishInstance *) ScheduledKey.Ptr(), (unsigned int *) key);
|
||||
}
|
||||
|
||||
// Camellia
|
||||
void CipherCamellia::Decrypt (byte *data) const
|
||||
{
|
||||
camellia_decrypt (data, data, (uint64 *) ScheduledKey.Ptr());
|
||||
}
|
||||
|
||||
void CipherCamellia::Encrypt (byte *data) const
|
||||
{
|
||||
camellia_encrypt (data, data, (uint64 *) ScheduledKey.Ptr());
|
||||
}
|
||||
|
||||
size_t CipherCamellia::GetScheduledKeySize () const
|
||||
{
|
||||
return CAMELLIA_KS;
|
||||
}
|
||||
|
||||
void CipherCamellia::SetCipherKey (const byte *key)
|
||||
{
|
||||
camellia_set_key (key, (uint64 *) ScheduledKey.Ptr());
|
||||
}
|
||||
|
||||
|
||||
bool Cipher::HwSupportEnabled = true;
|
||||
|
||||
@@ -106,6 +106,7 @@ namespace VeraCrypt
|
||||
|
||||
TC_CIPHER (Serpent, 16, 32);
|
||||
TC_CIPHER (Twofish, 16, 32);
|
||||
TC_CIPHER (Camellia, 16, 32);
|
||||
|
||||
#undef TC_CIPHER
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace VeraCrypt
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new AES ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new Serpent ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new Twofish ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new Camellia ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofish ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofishSerpent ()));
|
||||
l.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
|
||||
@@ -284,4 +285,12 @@ namespace VeraCrypt
|
||||
|
||||
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
|
||||
}
|
||||
|
||||
// Camellia
|
||||
Camellia::Camellia ()
|
||||
{
|
||||
Ciphers.push_back (shared_ptr <Cipher> (new CipherCamellia()));
|
||||
|
||||
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ namespace VeraCrypt
|
||||
TC_ENCRYPTION_ALGORITHM (Twofish);
|
||||
TC_ENCRYPTION_ALGORITHM (TwofishSerpent);
|
||||
TC_ENCRYPTION_ALGORITHM (SerpentTwofishAES);
|
||||
TC_ENCRYPTION_ALGORITHM (Camellia);
|
||||
|
||||
#undef TC_ENCRYPTION_ALGORITHM
|
||||
}
|
||||
|
||||
@@ -95,6 +95,34 @@ namespace VeraCrypt
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const CipherTestVector CamelliaTestVectors[] =
|
||||
{
|
||||
{
|
||||
{
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
|
||||
},
|
||||
{
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
|
||||
},
|
||||
{
|
||||
0x9A, 0xCC, 0x23, 0x7D, 0xFF, 0x16, 0xD7, 0x6C, 0x20, 0xEF, 0x7C, 0x91, 0x9E, 0x3A, 0x75, 0x09
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00, 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48,
|
||||
0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00, 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48
|
||||
},
|
||||
{
|
||||
0xE6, 0x84, 0x42, 0x17, 0x16, 0xFC, 0x0B, 0x01, 0xAE, 0xB5, 0xC6, 0x76, 0x51, 0x20, 0xF9, 0x5F
|
||||
},
|
||||
{
|
||||
0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84, 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void TestCipher (Cipher &cipher, const CipherTestVector *testVector, size_t testVectorCount)
|
||||
{
|
||||
@@ -139,6 +167,9 @@ namespace VeraCrypt
|
||||
|
||||
CipherTwofish twofish;
|
||||
TestCipher (twofish, TwofishTestVectors, array_capacity (TwofishTestVectors));
|
||||
|
||||
CipherCamellia camellia;
|
||||
TestCipher (camellia, CamelliaTestVectors, array_capacity (CamelliaTestVectors));
|
||||
}
|
||||
|
||||
const EncryptionTest::XtsTestVector EncryptionTest::XtsTestVectors[] =
|
||||
@@ -546,6 +577,32 @@ namespace VeraCrypt
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (typeid (ea) == typeid (Camellia))
|
||||
{
|
||||
switch (testCase)
|
||||
{
|
||||
case 0:
|
||||
if (crc != 0x2436badb)
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
break;
|
||||
case 1:
|
||||
if (crc != 0x247d2272)
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
break;
|
||||
case 2:
|
||||
if (crc != 0x72b49cde)
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
break;
|
||||
case 3:
|
||||
if (crc != 0xb838d2c1)
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (typeid (ea) == typeid (AESTwofish))
|
||||
{
|
||||
switch (testCase)
|
||||
@@ -742,6 +799,12 @@ namespace VeraCrypt
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
}
|
||||
else if (typeid (ea) == typeid (Camellia))
|
||||
{
|
||||
if (crc != 0x8176b223)
|
||||
throw TestFailed (SRC_POS);
|
||||
nTestsPerformed++;
|
||||
}
|
||||
else if (typeid (ea) == typeid (AESTwofish))
|
||||
{
|
||||
if (crc != 0x14ce7385)
|
||||
@@ -784,7 +847,7 @@ namespace VeraCrypt
|
||||
nTestsPerformed++;
|
||||
}
|
||||
|
||||
if (nTestsPerformed != 80)
|
||||
if (nTestsPerformed != 90)
|
||||
throw TestFailed (SRC_POS);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace VeraCrypt
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AES ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Serpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Twofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Camellia ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofishSerpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
|
||||
@@ -98,6 +99,7 @@ namespace VeraCrypt
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AES ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Serpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Twofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Camellia ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofishSerpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
|
||||
@@ -136,6 +138,7 @@ namespace VeraCrypt
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AES ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Serpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Twofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Camellia ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofishSerpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
|
||||
@@ -181,6 +184,7 @@ namespace VeraCrypt
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AES ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Serpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Twofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new Camellia ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofish ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new AESTwofishSerpent ()));
|
||||
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
|
||||
|
||||
Reference in New Issue
Block a user