3 #include <threefishApi.h>
7 void threefishSetKey(ThreefishKey_t* keyCtx, ThreefishSize_t stateSize,
8 uint64_t* keyData, uint64_t* tweak)
10 int keyWords = stateSize / 64;
12 uint64_t parity = KeyScheduleConst;
14 keyCtx->tweak[0] = tweak[0];
15 keyCtx->tweak[1] = tweak[1];
16 keyCtx->tweak[2] = tweak[0] ^ tweak[1];
18 for (i = 0; i < keyWords; i++) {
19 keyCtx->key[i] = keyData[i];
22 keyCtx->key[i] = parity;
23 keyCtx->stateSize = stateSize;
26 void threefishEncryptBlockBytes(ThreefishKey_t* keyCtx, uint8_t* in,
29 u64b_t plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
30 u64b_t cipher[SKEIN_MAX_STATE_WORDS];
32 Skein_Get64_LSB_First(plain, in, keyCtx->stateSize / 64); /* bytes to words */
33 threefishEncryptBlockWords(keyCtx, plain, cipher);
34 Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8); /* words to bytes */
37 void threefishEncryptBlockWords(ThreefishKey_t* keyCtx, uint64_t* in,
40 switch (keyCtx->stateSize) {
42 threefishEncrypt256(keyCtx, in, out);
45 threefishEncrypt512(keyCtx, in, out);
48 threefishEncrypt1024(keyCtx, in, out);
53 void threefishDecryptBlockBytes(ThreefishKey_t* keyCtx, uint8_t* in,
56 u64b_t plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
57 u64b_t cipher[SKEIN_MAX_STATE_WORDS];
59 Skein_Get64_LSB_First(cipher, in, keyCtx->stateSize / 64); /* bytes to words */
60 threefishDecryptBlockWords(keyCtx, cipher, plain);
61 Skein_Put64_LSB_First(out, plain, keyCtx->stateSize / 8); /* words to bytes */
64 void threefishDecryptBlockWords(ThreefishKey_t* keyCtx, uint64_t* in,
67 switch (keyCtx->stateSize) {
69 threefishDecrypt256(keyCtx, in, out);
72 threefishDecrypt512(keyCtx, in, out);
75 threefishDecrypt1024(keyCtx, in, out);