From 76d3bc631eff60841026f2526d69f6d661d218a3 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 2 Jun 2016 00:10:39 +0200 Subject: Crypto: Add support for Japanese encryption standard Camellia, including for system encryption. --- src/Volume/Cipher.cpp | 23 ++++++++++++++ src/Volume/Cipher.h | 1 + src/Volume/EncryptionAlgorithm.cpp | 9 ++++++ src/Volume/EncryptionAlgorithm.h | 1 + src/Volume/EncryptionTest.cpp | 65 +++++++++++++++++++++++++++++++++++++- src/Volume/VolumeLayout.cpp | 4 +++ 6 files changed, 102 insertions(+), 1 deletion(-) (limited to 'src/Volume') diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp index 4acea91e..2f3594ab 100644 --- a/src/Volume/Cipher.cpp +++ b/src/Volume/Cipher.cpp @@ -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 (new CipherAES ())); l.push_back (shared_ptr (new CipherSerpent ())); l.push_back (shared_ptr (new CipherTwofish ())); + l.push_back (shared_ptr (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; diff --git a/src/Volume/Cipher.h b/src/Volume/Cipher.h index 866a2c2c..522142b5 100644 --- a/src/Volume/Cipher.h +++ b/src/Volume/Cipher.h @@ -106,6 +106,7 @@ namespace VeraCrypt TC_CIPHER (Serpent, 16, 32); TC_CIPHER (Twofish, 16, 32); + TC_CIPHER (Camellia, 16, 32); #undef TC_CIPHER diff --git a/src/Volume/EncryptionAlgorithm.cpp b/src/Volume/EncryptionAlgorithm.cpp index 77ed8807..589db9b8 100644 --- a/src/Volume/EncryptionAlgorithm.cpp +++ b/src/Volume/EncryptionAlgorithm.cpp @@ -64,6 +64,7 @@ namespace VeraCrypt l.push_back (shared_ptr (new AES ())); l.push_back (shared_ptr (new Serpent ())); l.push_back (shared_ptr (new Twofish ())); + l.push_back (shared_ptr (new Camellia ())); l.push_back (shared_ptr (new AESTwofish ())); l.push_back (shared_ptr (new AESTwofishSerpent ())); l.push_back (shared_ptr (new SerpentAES ())); @@ -284,4 +285,12 @@ namespace VeraCrypt SupportedModes.push_back (shared_ptr (new EncryptionModeXTS ())); } + + // Camellia + Camellia::Camellia () + { + Ciphers.push_back (shared_ptr (new CipherCamellia())); + + SupportedModes.push_back (shared_ptr (new EncryptionModeXTS ())); + } } diff --git a/src/Volume/EncryptionAlgorithm.h b/src/Volume/EncryptionAlgorithm.h index f61358a2..8ebbea29 100644 --- a/src/Volume/EncryptionAlgorithm.h +++ b/src/Volume/EncryptionAlgorithm.h @@ -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 } diff --git a/src/Volume/EncryptionTest.cpp b/src/Volume/EncryptionTest.cpp index 26b5deab..f874de8e 100644 --- a/src/Volume/EncryptionTest.cpp +++ b/src/Volume/EncryptionTest.cpp @@ -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); } diff --git a/src/Volume/VolumeLayout.cpp b/src/Volume/VolumeLayout.cpp index 065045b9..623d2b82 100644 --- a/src/Volume/VolumeLayout.cpp +++ b/src/Volume/VolumeLayout.cpp @@ -68,6 +68,7 @@ namespace VeraCrypt SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); + SupportedEncryptionAlgorithms.push_back (shared_ptr (new Camellia ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); @@ -98,6 +99,7 @@ namespace VeraCrypt SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); + SupportedEncryptionAlgorithms.push_back (shared_ptr (new Camellia ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); @@ -136,6 +138,7 @@ namespace VeraCrypt SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); + SupportedEncryptionAlgorithms.push_back (shared_ptr (new Camellia ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); @@ -181,6 +184,7 @@ namespace VeraCrypt SupportedEncryptionAlgorithms.push_back (shared_ptr (new AES ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Serpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new Twofish ())); + SupportedEncryptionAlgorithms.push_back (shared_ptr (new Camellia ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofish ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new AESTwofishSerpent ())); SupportedEncryptionAlgorithms.push_back (shared_ptr (new SerpentAES ())); -- cgit v1.2.3