1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Reorder SM4-based cascade ciphers: apply SM4 as the final stage following external review.

The cascade order has been updated so that SM4 is applied after the other cipher(s) (e.g., Serpent). This change reflects standard cryptanalytic guidance, which shows that the overall strength of a cascade is limited by the first encryption stage. Given that SM4 uses a 128-bit key, its post-quantum brute-force resistance is lower than ciphers with a 256-bit key (such as Serpent). By placing SM4 last, we ensure that any potential weakness in SM4 cannot reduce the security margin provided by the stronger cipher.
This commit is contained in:
Mounir IDRASSI
2025-05-16 15:37:32 +09:00
parent b0311f7a86
commit 982fffe4db
13 changed files with 108 additions and 108 deletions

View File

@@ -98,13 +98,13 @@ static EncryptionAlgorithm EncryptionAlgorithms[] =
{ { SERPENT, TWOFISH, 0 }, { XTS, 0 }, 1, 1 },
{ { KUZNYECHIK, CAMELLIA, 0 }, { XTS, 0 }, 0, 1 },
{ { TWOFISH, KUZNYECHIK, 0 }, { XTS, 0 }, 0, 1 },
{ { SM4, KUZNYECHIK, 0 }, { XTS, 0 }, 0, 1 },
{ { SM4, SERPENT, 0 }, { XTS, 0 }, 0, 1 },
{ { KUZNYECHIK, SM4, 0 }, { XTS, 0 }, 0, 1 },
{ { SERPENT, SM4, 0 }, { XTS, 0 }, 0, 1 },
{ { TWOFISH, SM4, 0 }, { XTS, 0 }, 0, 1 },
{ { SERPENT, CAMELLIA, 0 }, { XTS, 0 }, 0, 1 },
{ { AES, KUZNYECHIK, 0 }, { XTS, 0 }, 0, 1 },
{ { CAMELLIA, SERPENT, KUZNYECHIK, 0 }, { XTS, 0 }, 0, 1 },
{ { SM4, SERPENT, TWOFISH, 0 }, { XTS, 0 }, 0, 1 },
{ { SERPENT, TWOFISH, SM4, 0 }, { XTS, 0 }, 0, 1 },
#endif
{ { 0, 0 }, { 0, 0}, 0, 0 } // Must be all-zero

View File

@@ -1202,53 +1202,53 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
else if (wcscmp (name, L"Kuznyechik-SM4") == 0)
else if (wcscmp (name, L"SM4-Kuznyechik") == 0)
{
switch (testCase)
{
case 0:
if (crc != 0xb126b7f8)
if (crc != 0xa8179f71)
return FALSE;
nTestsPerformed++;
break;
case 1:
if (crc != 0xa117004a)
if (crc != 0xaa372193)
return FALSE;
nTestsPerformed++;
break;
case 2:
if (crc != 0xc561be46)
if (crc != 0x49b78057)
return FALSE;
nTestsPerformed++;
break;
case 3:
if (crc != 0x47106ce3)
if (crc != 0x80718fd2)
return FALSE;
nTestsPerformed++;
break;
}
}
else if (wcscmp (name, L"Serpent-SM4") == 0)
else if (wcscmp (name, L"SM4-Serpent") == 0)
{
switch (testCase)
{
case 0:
if (crc != 0x40a9eaa5)
if (crc != 0x77cd332a)
return FALSE;
nTestsPerformed++;
break;
case 1:
if (crc != 0xce6873f1)
if (crc != 0x3a2be34b)
return FALSE;
nTestsPerformed++;
break;
case 2:
if (crc != 0x92cafcad)
if (crc != 0xfc1a6d4c)
return FALSE;
nTestsPerformed++;
break;
case 3:
if (crc != 0x7e1463ca)
if (crc != 0xf9b54baf)
return FALSE;
nTestsPerformed++;
break;
@@ -1306,27 +1306,27 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
else if (wcscmp (name, L"Twofish-Serpent-SM4") == 0)
else if (wcscmp (name, L"SM4-Twofish-Serpent") == 0)
{
switch (testCase)
{
case 0:
if (crc != 0x881b6e3d)
if (crc != 0x3ef6c86f)
return FALSE;
nTestsPerformed++;
break;
case 1:
if (crc != 0x37ed1418)
if (crc != 0xe5202d6c)
return FALSE;
nTestsPerformed++;
break;
case 2:
if (crc != 0x8e563eef)
if (crc != 0xa3acb43b)
return FALSE;
nTestsPerformed++;
break;
case 3:
if (crc != 0xdcbc41ac)
if (crc != 0xe9d64477)
return FALSE;
nTestsPerformed++;
break;
@@ -1469,15 +1469,15 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
return FALSE;
nTestsPerformed++;
}
else if (wcscmp (name, L"Kuznyechik-SM4") == 0)
else if (wcscmp (name, L"SM4-Kuznyechik") == 0)
{
if (crc != 0x8190551b)
if (crc != 0x23039a99)
return FALSE;
nTestsPerformed++;
}
else if (wcscmp (name, L"Serpent-SM4") == 0)
else if (wcscmp (name, L"SM4-Serpent") == 0)
{
if (crc != 0x31408c47)
if (crc != 0xa7c3155b)
return FALSE;
nTestsPerformed++;
}
@@ -1493,9 +1493,9 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
return FALSE;
nTestsPerformed++;
}
else if (wcscmp (name, L"Twofish-Serpent-SM4") == 0)
else if (wcscmp (name, L"SM4-Twofish-Serpent") == 0)
{
if (crc != 0x033093e5)
if (crc != 0x9723753f)
return FALSE;
nTestsPerformed++;
}

View File

@@ -316,10 +316,10 @@ namespace VeraCrypt
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (CamelliaKuznyechik))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (KuznyechikTwofish))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (KuznyechikAES))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (KuznyechikSM4))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (SerpentSM4))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (SM4Kuznyechik))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (SM4Serpent))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (SM4Twofish))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (TwofishSerpentSM4))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (SM4TwofishSerpent))
|| (typeid (*volume->GetEncryptionAlgorithm()) == typeid (KuznyechikSerpentCamellia));
if (options.NoKernelCrypto

View File

@@ -81,10 +81,10 @@ namespace VeraCrypt
l.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentTwofishAES ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpent ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new KuznyechikSM4 ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentSM4 ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Kuznyechik ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Serpent ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Twofish ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpentSM4 ()));
l.push_back (shared_ptr <EncryptionAlgorithm> (new SM4TwofishSerpent ()));
#endif
return l;
}
@@ -394,20 +394,20 @@ namespace VeraCrypt
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
}
// Kuznyechik-SM4
KuznyechikSM4::KuznyechikSM4 ()
// SM4-Kuznyechik
SM4Kuznyechik::SM4Kuznyechik ()
{
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherKuznyechik ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
}
// Serpent-SM4
SerpentSM4::SerpentSM4 ()
// SM4-Serpent
SM4Serpent::SM4Serpent ()
{
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherSerpent ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
}
@@ -421,12 +421,12 @@ namespace VeraCrypt
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
}
// Twofish-Serpent-SM4
TwofishSerpentSM4::TwofishSerpentSM4 ()
// SM4-Twofish-Serpent
SM4TwofishSerpent::SM4TwofishSerpent ()
{
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherSerpent ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherTwofish ()));
Ciphers.push_back (shared_ptr <Cipher> (new CipherSM4 ()));
SupportedModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
}

View File

@@ -96,10 +96,10 @@ namespace VeraCrypt
TC_ENCRYPTION_ALGORITHM (CamelliaKuznyechik);
TC_ENCRYPTION_ALGORITHM (CamelliaSerpent);
TC_ENCRYPTION_ALGORITHM (SM4);
TC_ENCRYPTION_ALGORITHM (KuznyechikSM4);
TC_ENCRYPTION_ALGORITHM (SerpentSM4);
TC_ENCRYPTION_ALGORITHM (SM4Kuznyechik);
TC_ENCRYPTION_ALGORITHM (SM4Serpent);
TC_ENCRYPTION_ALGORITHM (SM4Twofish);
TC_ENCRYPTION_ALGORITHM (TwofishSerpentSM4);
TC_ENCRYPTION_ALGORITHM (SM4TwofishSerpent);
#undef TC_ENCRYPTION_ALGORITHM

View File

@@ -1076,53 +1076,53 @@ namespace VeraCrypt
break;
}
}
else if (typeid (ea) == typeid (KuznyechikSM4))
else if (typeid (ea) == typeid (SM4Kuznyechik))
{
switch (testCase)
{
case 0:
if (crc != 0xb126b7f8)
if (crc != 0xa8179f71)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 1:
if (crc != 0xa117004a)
if (crc != 0xaa372193)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 2:
if (crc != 0xc561be46)
if (crc != 0x49b78057)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 3:
if (crc != 0x47106ce3)
if (crc != 0x80718fd2)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
}
}
else if (typeid (ea) == typeid (SerpentSM4))
else if (typeid (ea) == typeid (SM4Serpent))
{
switch (testCase)
{
case 0:
if (crc != 0x40a9eaa5)
if (crc != 0x77cd332a)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 1:
if (crc != 0xce6873f1)
if (crc != 0x3a2be34b)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 2:
if (crc != 0x92cafcad)
if (crc != 0xfc1a6d4c)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 3:
if (crc != 0x7e1463ca)
if (crc != 0xf9b54baf)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
@@ -1154,27 +1154,27 @@ namespace VeraCrypt
break;
}
}
else if (typeid (ea) == typeid (TwofishSerpentSM4))
else if (typeid (ea) == typeid (SM4TwofishSerpent))
{
switch (testCase)
{
case 0:
if (crc != 0x881b6e3d)
if (crc != 0x3ef6c86f)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 1:
if (crc != 0x37ed1418)
if (crc != 0xe5202d6c)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 2:
if (crc != 0x8e563eef)
if (crc != 0xa3acb43b)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
case 3:
if (crc != 0xdcbc41ac)
if (crc != 0xe9d64477)
throw TestFailed (SRC_POS);
nTestsPerformed++;
break;
@@ -1333,15 +1333,15 @@ namespace VeraCrypt
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
else if (typeid (ea) == typeid (KuznyechikSM4))
else if (typeid (ea) == typeid (SM4Kuznyechik))
{
if (crc != 0x8190551b)
if (crc != 0x23039a99)
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
else if (typeid (ea) == typeid (SerpentSM4))
else if (typeid (ea) == typeid (SM4Serpent))
{
if (crc != 0x31408c47)
if (crc != 0xa7c3155b)
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
@@ -1351,9 +1351,9 @@ namespace VeraCrypt
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
else if (typeid (ea) == typeid (TwofishSerpentSM4))
else if (typeid (ea) == typeid (SM4TwofishSerpent))
{
if (crc != 0x033093e5)
if (crc != 0x9723753f)
throw TestFailed (SRC_POS);
nTestsPerformed++;
}

View File

@@ -120,10 +120,10 @@ namespace VeraCrypt
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentTwofishAES ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpent ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new KuznyechikSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Kuznyechik ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Serpent ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Twofish ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpentSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4TwofishSerpent ()));
SupportedEncryptionModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
#else
SupportedEncryptionModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeWolfCryptXTS ()));
@@ -174,10 +174,10 @@ namespace VeraCrypt
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentAES ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentTwofishAES ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpent ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new KuznyechikSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SerpentSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Kuznyechik ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Serpent ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4Twofish ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new TwofishSerpentSM4 ()));
SupportedEncryptionAlgorithms.push_back (shared_ptr <EncryptionAlgorithm> (new SM4TwofishSerpent ()));
SupportedEncryptionModes.push_back (shared_ptr <EncryptionMode> (new EncryptionModeXTS ()));
#else