X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tftweakapi.c;fp=tftweakapi.c;h=5f68fe591c6a2fea22ddc8713f01e8a21219505d;hb=f402e6aa2dd18138ec26e9bfb340dae294637aec;hp=0000000000000000000000000000000000000000;hpb=0b911d4a813fe164d62ef6ef132c5a4f9a441d57;p=tfcrypt.git diff --git a/tftweakapi.c b/tftweakapi.c new file mode 100644 index 0000000..5f68fe5 --- /dev/null +++ b/tftweakapi.c @@ -0,0 +1,23 @@ +#include +#include "tfdef.h" +#include "tfcore.h" + +void tf_tweak_set(void *key, const void *tweak) +{ + TF_UNIT_TYPE *ukey = key; + TF_UNIT_TYPE *twe = ukey+TF_TWEAK_WORD1; + TF_UNIT_TYPE c = THREEFISH_CONST; + size_t x; + + for (x = 0; x < TF_NR_BLOCK_UNITS; x++) c ^= ukey[x]; + ukey[x] = c; + + if (!tweak) { + memset(twe, 0, (TF_NR_TWEAK_UNITS+1)*TF_SIZE_UNIT); + return; + } + + memcpy(twe, tweak, TF_NR_TWEAK_UNITS*TF_SIZE_UNIT); + data_to_words(twe, TF_NR_TWEAK_UNITS*TF_SIZE_UNIT); + ukey[TF_TWEAK_WORD3] = ukey[TF_TWEAK_WORD1] ^ ukey[TF_TWEAK_WORD2]; +}