2019-03-23 22:15:38 +01:00
|
|
|
/**
|
|
|
|
* Author......: See docs/credits.txt
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
2017-01-21 15:37:44 +01:00
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
#include "inc_vendor.h"
|
|
|
|
#include "inc_types.h"
|
|
|
|
#include "inc_common.h"
|
|
|
|
#include "inc_hash_sha256.h"
|
|
|
|
#include "inc_luks_essiv.h"
|
2017-01-21 15:37:44 +01:00
|
|
|
|
2018-02-06 19:12:24 +01:00
|
|
|
DECLSPEC void ESSIV_sha256_init128 (u32 *key, u32 *essivhash)
|
2017-01-21 15:37:44 +01:00
|
|
|
{
|
|
|
|
essivhash[0] = SHA256M_A;
|
|
|
|
essivhash[1] = SHA256M_B;
|
|
|
|
essivhash[2] = SHA256M_C;
|
|
|
|
essivhash[3] = SHA256M_D;
|
|
|
|
essivhash[4] = SHA256M_E;
|
|
|
|
essivhash[5] = SHA256M_F;
|
|
|
|
essivhash[6] = SHA256M_G;
|
|
|
|
essivhash[7] = SHA256M_H;
|
|
|
|
|
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
w0[0] = hc_swap32_S (key[0]);
|
|
|
|
w0[1] = hc_swap32_S (key[1]);
|
|
|
|
w0[2] = hc_swap32_S (key[2]);
|
|
|
|
w0[3] = hc_swap32_S (key[3]);
|
2017-01-21 15:37:44 +01:00
|
|
|
w1[0] = 0x80000000;
|
|
|
|
w1[1] = 0;
|
|
|
|
w1[2] = 0;
|
|
|
|
w1[3] = 0;
|
|
|
|
w2[0] = 0;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
|
|
|
w3[3] = 16 * 8;
|
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
sha256_transform (w0, w1, w2, w3, essivhash);
|
2017-01-21 15:37:44 +01:00
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
essivhash[0] = hc_swap32_S (essivhash[0]);
|
|
|
|
essivhash[1] = hc_swap32_S (essivhash[1]);
|
|
|
|
essivhash[2] = hc_swap32_S (essivhash[2]);
|
|
|
|
essivhash[3] = hc_swap32_S (essivhash[3]);
|
|
|
|
essivhash[4] = hc_swap32_S (essivhash[4]);
|
|
|
|
essivhash[5] = hc_swap32_S (essivhash[5]);
|
|
|
|
essivhash[6] = hc_swap32_S (essivhash[6]);
|
|
|
|
essivhash[7] = hc_swap32_S (essivhash[7]);
|
2017-01-21 15:37:44 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 19:12:24 +01:00
|
|
|
DECLSPEC void ESSIV_sha256_init256 (u32 *key, u32 *essivhash)
|
2017-01-21 15:37:44 +01:00
|
|
|
{
|
|
|
|
essivhash[0] = SHA256M_A;
|
|
|
|
essivhash[1] = SHA256M_B;
|
|
|
|
essivhash[2] = SHA256M_C;
|
|
|
|
essivhash[3] = SHA256M_D;
|
|
|
|
essivhash[4] = SHA256M_E;
|
|
|
|
essivhash[5] = SHA256M_F;
|
|
|
|
essivhash[6] = SHA256M_G;
|
|
|
|
essivhash[7] = SHA256M_H;
|
|
|
|
|
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
w0[0] = hc_swap32_S (key[0]);
|
|
|
|
w0[1] = hc_swap32_S (key[1]);
|
|
|
|
w0[2] = hc_swap32_S (key[2]);
|
|
|
|
w0[3] = hc_swap32_S (key[3]);
|
|
|
|
w1[0] = hc_swap32_S (key[4]);
|
|
|
|
w1[1] = hc_swap32_S (key[5]);
|
|
|
|
w1[2] = hc_swap32_S (key[6]);
|
|
|
|
w1[3] = hc_swap32_S (key[7]);
|
2017-01-21 15:37:44 +01:00
|
|
|
w2[0] = 0x80000000;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
|
|
|
w3[3] = 32 * 8;
|
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
sha256_transform (w0, w1, w2, w3, essivhash);
|
2017-01-21 15:37:44 +01:00
|
|
|
|
2019-03-23 22:15:38 +01:00
|
|
|
essivhash[0] = hc_swap32_S (essivhash[0]);
|
|
|
|
essivhash[1] = hc_swap32_S (essivhash[1]);
|
|
|
|
essivhash[2] = hc_swap32_S (essivhash[2]);
|
|
|
|
essivhash[3] = hc_swap32_S (essivhash[3]);
|
|
|
|
essivhash[4] = hc_swap32_S (essivhash[4]);
|
|
|
|
essivhash[5] = hc_swap32_S (essivhash[5]);
|
|
|
|
essivhash[6] = hc_swap32_S (essivhash[6]);
|
|
|
|
essivhash[7] = hc_swap32_S (essivhash[7]);
|
2017-01-21 15:37:44 +01:00
|
|
|
}
|