How to use crypt() on freeBSD with sha512?

698 views Asked by At

Currently my code looks like this:

if (iInit == 1)
{
    if (crypt_set_format("sha512") == 0)
        return -1;

    iInit = !iInit;
}

res = crypt(szPWhash, "ABCDEFGH");

The resulting hash is € v

I tryed already

res = crypt(szPWhash, "$6$QX$");

or even this notation:

res = crypt(szPWhash, "$6$QX");

But doesn't matter which salt I choose Or whats the entered password is.

The resulting hash is every time unchanged € v.

What doesn't even look like a sha512 hash.

So what I'm doing wrong?

EDIT

I figured out, that if I change the encrypton mehtod, the hash changes but, it keeps similiar doesn't matter what i choose as key and/or salt.

1

There are 1 answers

1
Grady Player On

I don't know about crypt, but with openssl it would look like:

SHA512_CTX * ctx = calloc(sizeof ctx,1); // or stack allocate / not as a pointer
SHA512_Init(ctx);
char * str = "blahblah";
SHA512_Update(context, str, strlen(str));
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512_Final(hash, context);