~samiam/MaraDNS

81c1429f0307609a3b9544deabf45b3a69ead9f2 — Sam Trenholme 2 months ago 1996cac
Rollback: Deadwood in Windows was crashing in startup.
I am now figuring out where the issue is to fix things.
This is for https://github.com/samboy/MaraDNS/issues/59
1 files changed, 11 insertions(+), 27 deletions(-)

M deadwood-github/src/DwHash.c
M deadwood-github/src/DwHash.c => deadwood-github/src/DwHash.c +11 -27
@@ 1,4 1,4 @@
/* Copyright (c) 2007-2020 Sam Trenholme
/* Copyright (c) 2007-2014 Sam Trenholme
 *
 * TERMS
 *


@@ 24,9 24,6 @@
#include <stdint.h>
#include <stdio.h> /* For reading and writing the hash to a file */
#include <time.h>
#ifdef MINGW
#include <wincrypt.h> /* Windows only; *NIX has /dev/random */
#endif

#include "DwHash.h"
/* The default value for the multiply constant is a 31-bit random prime


@@ 49,47 46,34 @@ extern int64_t the_time;
 * information in a table */

/* Called before reading dwood3rc, this sets add_constant based on
 * CryptGenRandom in Windows and /dev/urandom in Unix */
 * secret.txt in Windows and /dev/urandom in Unix */
void set_add_constant() {
        FILE *in = 0;
        dwr_rg *quick_n_dirty = 0;
        dw_str *seedit = 0;
        int counter = 0;
        time_t timestamp = 0;
#ifdef MINGW
        HCRYPTPROV CryptContext;
        int b;
#endif

        seedit = dw_create(14);
#ifdef MINGW
        in = fopen("secret.txt","rb");
#else
        in = fopen("/dev/urandom","rb");
#endif /* MINGW */

        if(seedit == 0) {
        if(in == 0) {
                goto catch_set_add_constant;
        }

        seedit->len = 11;
        seedit = dw_create(14);

#ifdef MINGW
        b = CryptAcquireContext(&CryptContext, NULL, NULL, PROV_RSA_FULL,
                CRYPT_VERIFYCONTEXT);
        if(b != 1) {
                goto catch_set_add_constant;
        }
        b = CryptGenRandom(CryptContext, 8, seedit->str);
        if(b != 1) {
        if(seedit == 0) {
                goto catch_set_add_constant;
        }
        CryptReleaseContext(CryptContext,0);
#else
        in = fopen("/dev/urandom","rb");

        if(in == 0) {
                goto catch_set_add_constant;
        }
        seedit->len = 11;
        for(counter = 0; counter < 8; counter++) {
                *(seedit->str + counter) = getc(in);
        }
#endif /* MINGW */
        timestamp = time(0);
        *(seedit->str + 8) = (timestamp & 0xff);
        *(seedit->str + 9) = (timestamp & 0xff00) >> 8;