void derive_key_ripemd160(const uint8 *key, int keyLength, const uint8 *salt, int saltLength, int iterations, uint8 *diskKey, int diskKeyLength) { uint8 u[RIPEMD160_DIGESTSIZE]; int b, l, r; if (diskKeyLength % RIPEMD160_DIGESTSIZE) l = 1 + diskKeyLength / RIPEMD160_DIGESTSIZE; else l = diskKeyLength / RIPEMD160_DIGESTSIZE; r = diskKeyLength - (l - 1) * RIPEMD160_DIGESTSIZE; /* first l - 1 blocks */ for (b = 1; b < l; b++) { derive_u_ripemd160(key, keyLength, salt, saltLength, iterations, u, b); memcpy(diskKey, u, RIPEMD160_DIGESTSIZE); diskKey += RIPEMD160_DIGESTSIZE; } /* last block */ derive_u_ripemd160(key, keyLength, salt, saltLength, iterations, u, b); memcpy(diskKey, u, r); /* Prevent possible leaks. */ memset(u, 0, sizeof(u)); }
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen) { char u[RIPEMD160_DIGESTSIZE]; int b, l, r; if (dklen % RIPEMD160_DIGESTSIZE) { l = 1 + dklen / RIPEMD160_DIGESTSIZE; } else { l = dklen / RIPEMD160_DIGESTSIZE; } r = dklen - (l - 1) * RIPEMD160_DIGESTSIZE; /* first l - 1 blocks */ for (b = 1; b < l; b++) { derive_u_ripemd160 (pwd, pwd_len, salt, salt_len, iterations, u, b); memcpy (dk, u, RIPEMD160_DIGESTSIZE); dk += RIPEMD160_DIGESTSIZE; } /* last block */ derive_u_ripemd160 (pwd, pwd_len, salt, salt_len, iterations, u, b); memcpy (dk, u, r); /* Prevent possible leaks. */ burn (u, sizeof(u)); }
void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, uint32 iterations, char *dk, int dklen) { int b, l, r; hmac_ripemd160_ctx hmac; #ifndef TC_WINDOWS_BOOT unsigned char tk[RIPEMD160_DIGESTSIZE]; /* If the password is longer than the hash algorithm block size, let password = ripemd160(password), as per HMAC specifications. */ if (pwd_len > RIPEMD160_BLOCKSIZE) { RMD160_CTX tctx; RMD160Init(&tctx); RMD160Update(&tctx, (const unsigned char *) pwd, pwd_len); RMD160Final(tk, &tctx); pwd = (char *) tk; pwd_len = RIPEMD160_DIGESTSIZE; burn (&tctx, sizeof(tctx)); // Prevent leaks } #endif if (dklen % RIPEMD160_DIGESTSIZE) { l = 1 + dklen / RIPEMD160_DIGESTSIZE; } else { l = dklen / RIPEMD160_DIGESTSIZE; } r = dklen - (l - 1) * RIPEMD160_DIGESTSIZE; /* first l - 1 blocks */ for (b = 1; b < l; b++) { derive_u_ripemd160 (pwd, pwd_len, salt, salt_len, iterations, b, &hmac); memcpy (dk, hmac.u, RIPEMD160_DIGESTSIZE); dk += RIPEMD160_DIGESTSIZE; } /* last block */ derive_u_ripemd160 (pwd, pwd_len, salt, salt_len, iterations, b, &hmac); memcpy (dk, hmac.u, r); /* Prevent possible leaks. */ burn (&hmac, sizeof(hmac)); #ifndef TC_WINDOWS_BOOT burn (tk, sizeof(tk)); #endif }