|
|
|
@ -115,6 +115,65 @@ DECLSPEC void AES_GCM_ghash (const u32 *subkey, const u32 *in, u32 in_len, u32 *
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DECLSPEC void AES_GCM_ghash_global (const u32 *subkey, GLOBAL_AS const u32 *in, u32 in_len, u32 *out)
|
|
|
|
|
{
|
|
|
|
|
u32 m = in_len / 16;
|
|
|
|
|
|
|
|
|
|
GLOBAL_AS const u32 *xpos = in;
|
|
|
|
|
|
|
|
|
|
u32 tmp[4] = { 0 };
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < m; i++)
|
|
|
|
|
{
|
|
|
|
|
u32 t2[4];
|
|
|
|
|
|
|
|
|
|
t2[0] = xpos[0];
|
|
|
|
|
t2[1] = xpos[1];
|
|
|
|
|
t2[2] = xpos[2];
|
|
|
|
|
t2[3] = xpos[3];
|
|
|
|
|
|
|
|
|
|
AES_GCM_xor_block (out, t2);
|
|
|
|
|
|
|
|
|
|
xpos += 4;
|
|
|
|
|
|
|
|
|
|
AES_GCM_gf_mult (out, subkey, tmp);
|
|
|
|
|
|
|
|
|
|
out[0] = tmp[0];
|
|
|
|
|
out[1] = tmp[1];
|
|
|
|
|
out[2] = tmp[2];
|
|
|
|
|
out[3] = tmp[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in + (in_len/4) > xpos)
|
|
|
|
|
{
|
|
|
|
|
u32 last = in + (in_len/4) - xpos;
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < last; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp[i] = xpos[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (u32 i = last; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AES_GCM_xor_block (out, tmp);
|
|
|
|
|
|
|
|
|
|
AES_GCM_gf_mult (out, subkey, tmp);
|
|
|
|
|
|
|
|
|
|
tmp[0] = hc_swap32_S (tmp[0]);
|
|
|
|
|
tmp[1] = hc_swap32_S (tmp[1]);
|
|
|
|
|
tmp[2] = hc_swap32_S (tmp[2]);
|
|
|
|
|
tmp[3] = hc_swap32_S (tmp[3]);
|
|
|
|
|
|
|
|
|
|
out[0] = tmp[0];
|
|
|
|
|
out[1] = tmp[1];
|
|
|
|
|
out[2] = tmp[2];
|
|
|
|
|
out[3] = tmp[3];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DECLSPEC void AES_GCM_Init (const u32 *ukey, u32 key_len, u32 *key, u32 *subkey, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4)
|
|
|
|
|
{
|
|
|
|
|
if (key_len == 128)
|
|
|
|
@ -205,7 +264,7 @@ DECLSPEC void AES_GCM_gctr (const u32 *key, const u32 *iv, const u32 *in, u32 in
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DECLSPEC void AES_GCM_GCTR (u32 *key, u32 *J0, u32 *in, u32 in_len, u32 *out, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4)
|
|
|
|
|
DECLSPEC void AES_GCM_GCTR (u32 *key, u32 *J0, const u32 *in, u32 in_len, u32 *out, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4)
|
|
|
|
|
{
|
|
|
|
|
u32 J0_incr[4];
|
|
|
|
|
|
|
|
|
@ -217,7 +276,7 @@ DECLSPEC void AES_GCM_GCTR (u32 *key, u32 *J0, u32 *in, u32 in_len, u32 *out, SH
|
|
|
|
|
AES_GCM_gctr (key, J0_incr, in, in_len, out, s_te0, s_te1, s_te2, s_te3, s_te4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DECLSPEC void AES_GCM_GHASH (const u32 *subkey, const u32 *aad_buf, u32 aad_len, u32 *enc_buf, u32 enc_len, u32 *out)
|
|
|
|
|
DECLSPEC void AES_GCM_GHASH (const u32 *subkey, const u32 *aad_buf, u32 aad_len, const u32 *enc_buf, u32 enc_len, u32 *out)
|
|
|
|
|
{
|
|
|
|
|
out[0] = 0;
|
|
|
|
|
out[1] = 0;
|
|
|
|
@ -250,3 +309,37 @@ DECLSPEC void AES_GCM_GHASH (const u32 *subkey, const u32 *aad_buf, u32 aad_len,
|
|
|
|
|
|
|
|
|
|
AES_GCM_ghash (subkey, len_buf, 16, out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DECLSPEC void AES_GCM_GHASH_GLOBAL (const u32 *subkey, const u32 *aad_buf, u32 aad_len, GLOBAL_AS const u32 *enc_buf, u32 enc_len, u32 *out)
|
|
|
|
|
{
|
|
|
|
|
out[0] = 0;
|
|
|
|
|
out[1] = 0;
|
|
|
|
|
out[2] = 0;
|
|
|
|
|
out[3] = 0;
|
|
|
|
|
|
|
|
|
|
AES_GCM_ghash (subkey, aad_buf, aad_len, out);
|
|
|
|
|
|
|
|
|
|
// untested swap
|
|
|
|
|
/*
|
|
|
|
|
out[0] = hc_swap32_S (out[0]);
|
|
|
|
|
out[1] = hc_swap32_S (out[1]);
|
|
|
|
|
out[2] = hc_swap32_S (out[2]);
|
|
|
|
|
out[3] = hc_swap32_S (out[3]);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
AES_GCM_ghash_global (subkey, enc_buf, enc_len, out);
|
|
|
|
|
|
|
|
|
|
out[0] = hc_swap32_S (out[0]);
|
|
|
|
|
out[1] = hc_swap32_S (out[1]);
|
|
|
|
|
out[2] = hc_swap32_S (out[2]);
|
|
|
|
|
out[3] = hc_swap32_S (out[3]);
|
|
|
|
|
|
|
|
|
|
u32 len_buf[4];
|
|
|
|
|
|
|
|
|
|
len_buf[0] = aad_len * 8;
|
|
|
|
|
len_buf[1] = 0;
|
|
|
|
|
len_buf[2] = 0;
|
|
|
|
|
len_buf[3] = enc_len * 8;
|
|
|
|
|
|
|
|
|
|
AES_GCM_ghash (subkey, len_buf, 16, out);
|
|
|
|
|
}
|
|
|
|
|