VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/GfMul.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/GfMul.c')
-rw-r--r--src/Common/GfMul.c110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/Common/GfMul.c b/src/Common/GfMul.c
index 7e170bc1..7cc36ec1 100644
--- a/src/Common/GfMul.c
+++ b/src/Common/GfMul.c
@@ -634,137 +634,70 @@ int Gf128Tab64Init (unsigned __int8 *a, GfCtx *ctx)
{
for (j = 0; j < 16; j++)
{
int jm = 0;
jm |= (j & 0x1) << 3;
jm |= (j & 0x2) << 1;
jm |= (j & 0x4) >> 1;
jm |= (j & 0x8) >> 3;
memcpy (&ctx->gf_t128[i-16][jm], (unsigned char *)&ctx8k->gf_t8k[31-i][j], 16);
MirrorBits128 ((unsigned char *)&ctx->gf_t128[i-16][jm]);
}
}
burn (ctx8k ,sizeof (*ctx8k));
burn (am, sizeof (am));
TCfree (ctx8k);
return TRUE;
}
-int Gf64TabInit (unsigned __int8 *a, GfCtx *ctx)
-{
- /* Deprecated/legacy */
-
- GfCtx4k64 *ctx4k;
- unsigned __int8 am[8];
- int i, j;
-
- ctx4k = (GfCtx4k64 *) TCalloc (sizeof (GfCtx4k64));
- if (!ctx4k)
- return FALSE;
-
- memcpy (am, a, 8);
- MirrorBits64 (am);
- compile_4k_table64 (am, ctx4k);
-
- /* Convert LSB-first table to MSB-first */
- for (i = 0; i < 16; i++)
- {
- for (j = 0; j < 16; j++)
- {
- int jm = 0;
- jm |= (j & 0x1) << 3;
- jm |= (j & 0x2) << 1;
- jm |= (j & 0x4) >> 1;
- jm |= (j & 0x8) >> 3;
-
- memcpy (&ctx->gf_t64[i][jm], (unsigned char *)&ctx4k->gf_t4k[15-i][j], 8);
- MirrorBits64 ((unsigned char *)&ctx->gf_t64[i][jm]);
- }
- }
-
- burn (ctx4k,sizeof (*ctx4k));
- burn (am, sizeof (am));
- TCfree (ctx4k);
- return TRUE;
-}
#define xor_8kt64(i) \
xor_block_aligned(r, ctx->gf_t128[i + i][a[i] & 15]); \
xor_block_aligned(r, ctx->gf_t128[i + i + 1][a[i] >> 4])
/* Multiply a 128-bit number by a 64-bit number in the finite field GF(2^128) */
void Gf128MulBy64Tab (unsigned __int8 a[8], unsigned __int8 p[16], GfCtx *ctx)
{
unsigned __int32 r[CBLK_LEN >> 2];
move_block_aligned(r, ctx->gf_t128[7*2][a[7] & 15]);
xor_block_aligned(r, ctx->gf_t128[7*2+1][a[7] >> 4]);
if (*(unsigned __int16 *)a)
{
xor_8kt64(0);
xor_8kt64(1);
}
if (a[2])
{
xor_8kt64(2);
}
xor_8kt64(3);
xor_8kt64(4);
xor_8kt64(5);
xor_8kt64(6);
move_block_aligned(p, r);
}
-#define xor_8k64(i) \
- xor_block_aligned64(r, ctx->gf_t64[i + i][a[i] & 15]); \
- xor_block_aligned64(r, ctx->gf_t64[i + i + 1][a[i] >> 4])
-
-/* Multiply two 64-bit numbers in the finite field GF(2^64) */
-void Gf64MulTab (unsigned char a[8], unsigned char p[8], GfCtx *ctx)
-{
- /* Deprecated/legacy */
-
- unsigned __int32 r[CBLK_LEN8 >> 2];
-
- move_block_aligned64(r, ctx->gf_t64[7*2][a[7] & 15]);
- xor_block_aligned64(r, ctx->gf_t64[7*2+1][a[7] >> 4]);
-
- if (*(unsigned __int16 *)a)
- {
- xor_8k64(0);
- xor_8k64(1);
- }
- if (a[2])
- {
- xor_8k64(2);
- }
- xor_8k64(3);
- xor_8k64(4);
- xor_8k64(5);
- xor_8k64(6);
-
- move_block_aligned64(p, r);
-}
/* Basic algorithms for testing of optimized algorithms */
static void xor128 (uint64 *a, uint64 *b)
{
*a++ ^= *b++;
*a ^= *b;
}
static void shl128 (unsigned __int8 *a)
{
int i, x = 0, xx;
for (i = 15; i >= 0; i--)
{
xx = (a[i] & 0x80) >> 7;
a[i] = (char) ((a[i] << 1) | x);
x = xx;
}
}
@@ -792,97 +725,54 @@ static void GfMul128Basic (unsigned __int8 *a, unsigned __int8 *b, unsigned __in
}
}
}
static void xor64 (uint64 *a, uint64 *b)
{
*a ^= *b;
}
static void shl64 (unsigned __int8 *a)
{
int i, x = 0, xx;
for (i = 7; i >= 0; i--)
{
xx = (a[i] & 0x80) >> 7;
a[i] = (char) ((a[i] << 1) | x);
x = xx;
}
}
-static void GfMul64Basic (unsigned __int8 *a, unsigned __int8 *b, unsigned __int8* p)
-{
- /* Deprecated/legacy */
-
- int i;
- unsigned __int8 la[8];
- memcpy (la, a, 8);
- memset (p, 0, 8);
-
- for (i = 0; i < 64; i++)
- {
- if (IsBitSet64 (i, b))
- xor64 ((uint64 *)p, (uint64 *)la);
-
- if (la[0] & 0x80)
- {
- shl64 (la);
- la[7] ^= 0x1b;
- }
- else
- {
- shl64 (la);
- }
- }
-}
-
BOOL GfMulSelfTest ()
{
BOOL result = TRUE;
unsigned __int8 a[16];
unsigned __int8 b[16];
unsigned __int8 p1[16];
unsigned __int8 p2[16];
GfCtx *gfCtx = (GfCtx *) TCalloc (sizeof (GfCtx));
int i, j;
if (!gfCtx)
return FALSE;
- /* GF(2^64) - deprecated/legacy */
- for (i = 0; i < 0x100; i++)
- {
- for (j = 0; j < 8; j++)
- {
- a[j] = (unsigned __int8) i;
- b[j] = a[j] ^ 0xff;
- }
-
- GfMul64Basic (a, b, p1);
-
- Gf64TabInit (a, gfCtx);
- Gf64MulTab (b, p2, gfCtx);
-
- if (memcmp (p1, p2, 8) != 0)
- result = FALSE;
- }
/* GF(2^128) */
for (i = 0; i < 0x100; i++)
{
for (j = 0; j < 16; j++)
{
a[j] = (unsigned __int8) i;
b[j] = j < 8 ? 0 : a[j] ^ 0xff;
}
GfMul128Basic (a, b, p1);
Gf128Tab64Init (a, gfCtx);
Gf128MulBy64Tab (b + 8, p2, gfCtx);
if (memcmp (p1, p2, 16) != 0)
result = FALSE;
}
TCfree (gfCtx);