X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_conf.c;h=15a79ed77059f3f13046626de0589e7aeba14f2f;hb=13cc886eb2edfe7be4e65067be6df01e2f08436a;hp=bd2b112ecc045b8ff7b9615aae42c13d17e68bdc;hpb=8b7f1839b1981554979af1aa2e5e8b58ad63fe77;p=tfcrypt.git diff --git a/tfc_conf.c b/tfc_conf.c index bd2b112..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")) { @@ -94,9 +94,45 @@ _nspc: || macbits > TF_MAX_BITS || macbits % 8) xerror(NO, YES, YES, "[%s] macbits=%s: invalid MAC bits setting", path, d); } + else if (!strcmp(s, "do_full_key")) { + if (!strcasecmp(d, "yes")) do_full_key = YES; + else if (!strcasecmp(d, "no")) do_full_key = NO; + } else xerror(NO, YES, YES, "[%s] %s: unknown keyword", path, s); } 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); +}