X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_conf.c;h=15a79ed77059f3f13046626de0589e7aeba14f2f;hb=cd6f1f9a84c17dbdf6ab320a04eae300502b898d;hp=441d60cb90b7267d5bbce446763e6f0d50932058;hpb=d2e7d8aede7d69caffd59e4b0fa60e0c4b245201;p=tfcrypt.git diff --git a/tfc_conf.c b/tfc_conf.c index 441d60c..15a79ed 100644 --- a/tfc_conf.c +++ b/tfc_conf.c @@ -2,7 +2,7 @@ * tfcrypt -- high security Threefish encryption tool. * * tfcrypt is copyrighted: - * Copyright (C) 2012-2018 Andrey Rys. All rights reserved. + * Copyright (C) 2012-2019 Andrey Rys. All rights reserved. * * tfcrypt is licensed to you under the terms of std. MIT/X11 license: * @@ -66,7 +66,7 @@ _spc2: t = strchr(d, ' '); *t = 0; d = t+1; goto _spc2; _nspc: if (!strcmp(s, "nr_turns")) { - nr_turns = sksum_turns = strtoul(d, &stoi, 10); + nr_turns = strtoul(d, &stoi, 10); if (!str_empty(stoi)) xerror(NO, YES, YES, "[%s] nr_turns=%s: invalid number of turns", path, d); } else if (!strcmp(s, "ctr_mode")) { @@ -104,3 +104,35 @@ _nspc: memset(ln, 0, sizeof(ln)); fclose(f); } + +void hash_defaults(char *uhash, size_t szuhash) +{ + struct skein sk; + char shash[56]; + const char *mode; + tfc_byte hash[TF_FROM_BITS(256)]; + + skein_init(&sk, 256); + + skein_update(&sk, tfc_salt, tfc_saltsz); + + memset(shash, 0, sizeof(shash)); + sprintf(shash, "%zu", nr_turns); + skein_update(&sk, shash, strlen(shash)); + + mode = tfc_modename(ctr_mode); + skein_update(&sk, mode, strlen(mode)); + + memset(shash, 0, sizeof(shash)); + sprintf(shash, "%zu", macbits); + skein_update(&sk, shash, strlen(shash)); + + skein_update(&sk, do_full_key ? "1" : "0", 1); + + skein_final(hash, &sk); + memset(shash, 0, sizeof(shash)); + base64_encode(shash, (const char *)hash, sizeof(hash)); + memset(hash, 0, sizeof(hash)); + + xstrlcpy(uhash, shash, szuhash); +}