Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn, if pbkdf2 took longer than 100ms #1428

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/mod/pbkdf2.mod/pbkdf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ static char *pbkdf2_hash(const char *pass, const char *digest_name,
char *out2;
unsigned char *buf;
struct rusage ru1, ru2;
double utime, stime;
/* log only once as long as rounds aint changed */
michaelortmann marked this conversation as resolved.
Show resolved Hide resolved
static int rounds_last, responsiveness;

digest = EVP_get_digestbyname(digest_name);
if (!digest) {
Expand Down Expand Up @@ -114,12 +117,21 @@ static char *pbkdf2_hash(const char *pass, const char *digest_name,
return NULL;
}
if (!ret && !getrusage(RUSAGE_SELF, &ru2)) {
utime = (double) (ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec) / 1000 +
(double) (ru2.ru_utime.tv_sec - ru1.ru_utime.tv_sec ) * 1000;
stime = (double) (ru2.ru_stime.tv_usec - ru1.ru_stime.tv_usec) / 1000 +
(double) (ru2.ru_stime.tv_sec - ru1.ru_stime.tv_sec ) * 1000;
debug4("pbkdf2 method %s rounds %i, user %.3fms sys %.3fms", digest_name,
rounds,
(double) (ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec) / 1000 +
(double) (ru2.ru_utime.tv_sec - ru1.ru_utime.tv_sec ) * 1000,
(double) (ru2.ru_stime.tv_usec - ru1.ru_stime.tv_usec) / 1000 +
(double) (ru2.ru_stime.tv_sec - ru1.ru_stime.tv_sec ) * 1000);
rounds, utime, stime);
if (rounds != rounds_last) {
rounds_last = rounds;
responsiveness = 0;
}
if (((utime + stime) > 100.0) && !responsiveness) {
putlog(LOG_MISC, "*", "PBKDF2 warning: pbkdf2 method %s rounds %i took more than 100ms (user %.3fms sys %.3fms). Consider lowering pbkdf2-rounds for eggdrops responsiveness.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eggdrop's

digest_name, rounds, utime, stime);
responsiveness = 1;
}
}
else {
debug1("PBKDF2 error: getrusage(): %s", strerror(errno));
Expand Down