Digital Bitbox01
#2
I've pulled the code for the hardware itself, and was able some of the encryption logic as well. I'm not too sure how to make sense of all this as I'm unfamiliar with C, as well as cryptography in general. Any advice is greatly appreciated here.

int wallet_generate_node(const char *passphrase, const char *entropy, HDNode *node)
{
    int ret;
    uint8_t seed[PBKDF2_HMACLEN];
    char salt[8 + strlens(passphrase+ 1];
    snprintf(saltsizeof(salt), "%s%s""mnemonic"passphrase);
    pbkdf2_hmac_sha512((const uint8_t *)entropystrlens(entropy), saltseed,
                       sizeof(seed));

    if (hdnode_from_seed(seedsizeof(seed), node== DBB_ERROR) {
        ret = DBB_ERROR;
    } else {
        ret = DBB_OK;
    }

    utils_zero(seedsizeof(seed));
    utils_zero(saltsizeof(salt));
    return ret;
}


void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const char *salt, uint8_t *key,
                        int keylen)
{
    uint32_t ijk;
    uint8_t f[PBKDF2_HMACLEN], g[PBKDF2_HMACLEN];
    uint32_t blocks = keylen / PBKDF2_HMACLEN;
    int saltlen = strlens(salt);
    uint8_t salt_pbkdf2[saltlen + 4];
    memset(salt_pbkdf20sizeof(salt_pbkdf2));
    memcpy(salt_pbkdf2saltsaltlen);

    if (keylen & (PBKDF2_HMACLEN - 1)) {
        blocks++;
    }
    for (i = 1i <= blocksi++) {
        salt_pbkdf2[saltlen    ] = (i >> 24& 0xFF;
        salt_pbkdf2[saltlen + 1= (i >> 16& 0xFF;
        salt_pbkdf2[saltlen + 2= (i >> 8& 0xFF;
        salt_pbkdf2[saltlen + 3= i & 0xFF;
        hmac_sha512(passpasslensalt_pbkdf2saltlen + 4g);
        memcpy(fgPBKDF2_HMACLEN);
        for (j = 1j < PBKDF2_ROUNDSj++) {
            hmac_sha512(passpasslengPBKDF2_HMACLENg);
            for (k = 0k < PBKDF2_HMACLENk++) {
                f[k^= g[k];
            }
        }
        if (i == blocks && (keylen & (PBKDF2_HMACLEN - 1))) {
            memcpy(key + PBKDF2_HMACLEN * (i - 1), fkeylen & (PBKDF2_HMACLEN - 1));
        } else {
            memcpy(key + PBKDF2_HMACLEN * (i - 1), fPBKDF2_HMACLEN);
        }
    }
    utils_zero(fsizeof(f));
    utils_zero(gsizeof(g));
}
Reply


Messages In This Thread
Digital Bitbox01 - by dtmle - 01-25-2021, 07:27 AM
RE: Digital Bitbox01 - by dtmle - 01-25-2021, 08:03 AM
RE: Digital Bitbox01 - by undeath - 01-25-2021, 06:44 PM
RE: Digital Bitbox01 - by dtmle - 01-25-2021, 11:09 PM
RE: Digital Bitbox01 - by undeath - 01-26-2021, 12:30 AM
RE: Digital Bitbox01 - by dtmle - 01-26-2021, 04:51 AM
RE: Digital Bitbox01 - by undeath - 01-26-2021, 04:58 PM