pbkdf1

Doubts, help and support about QuickBMS and other game research tools
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

pbkdf1

Post by chrrox »

python code

Code: Select all

from passlib.utils.pbkdf2 import pbkdf1
key = 'Jr9DW9ksMRv1Lc796mrwv145fXC3L5VcpmKE5VfCuvbrpZGfYwXMpwo9sGkJ54zHse4G7zftpjkhqHHY60O7aQPj4M2ekKMSw094PmXRkN4ftTmDFlYMPmwK8QvhJ20H'.encode('utf-8', 'ignore')
salt = 'Jr9DW9ksMRv1Lc796mrwv145fXC3L5VcpmKE5VfCuvbrpZGfYwXMpwo9sGkJ54zHse4G7zftpjkhqHHY60O7aQPj4M2ekKMSw094PmXRkN4ftTmDFlYMPmwK8QvhJ20H'.encode('utf-8', 'ignore')
bk = pbkdf1(key, salt, 100, keylen=16, hash='sha1')
bk.hex()


produces

Code: Select all

'8e2e1d5a5e3a4a1c7388f6b8d7779d7b'


How would i do this in quickbms?


openssl code

Code: Select all

#include <string.h>
#include <stdlib.h>
#include <openssl/sha.h>

void pbkdf1(const char *password, const char *salt, long iter, unsigned char dk[SHA_DIGEST_LENGTH])
{
    size_t pwlen = strlen(password);
    size_t dlen = pwlen + 8;
    unsigned char *buf;

    if (dlen > SHA_DIGEST_LENGTH)
        buf = malloc(dlen);
    else
        buf = malloc(SHA_DIGEST_LENGTH);

    memcpy(buf, password, pwlen);
    strncpy((char *)buf + pwlen, salt, 8);

    while (iter-- > 0)
    {
        SHA1(buf, dlen, buf);
        dlen = SHA_DIGEST_LENGTH;
    }

    memcpy(dk, buf, SHA_DIGEST_LENGTH);
    free(buf);
}


or

https://github.com/RobertCNelson/bertos ... f/pbkdf1.c
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

Re: pbkdf1

Post by chrrox »

I see this in quickbms source tomcrypt_pkcs.h but no idea how to call it.

Code: Select all

/* ===> LTC_PKCS #5 -- Password Based Cryptography <=== */
#ifdef LTC_PKCS_5

/* Algorithm #1 (old) */
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
                const unsigned char *salt,
                int iteration_count,  int hash_idx,
                unsigned char *out,   unsigned long *outlen);

/* Algorithm #2 (new) */
int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
                const unsigned char *salt,     unsigned long salt_len,
                int iteration_count,           int hash_idx,
                unsigned char *out,            unsigned long *outlen);

#endif  /* LTC_PKCS_5 */
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: pbkdf1

Post by aluigi »

It will be available in the beta.
I added some code in the local one (not on the website yet) but I didn't test it yet.

Other solutions like PKCS5_PBKDF2_HMAC, BytesToKey and Rfc2898DeriveBytes are available but it may be a bit messy to use them since the Encryption command is limited and meant for something different.