]> jfr.im git - irc/atheme/atheme.git/commitdiff
pbkdf2v2: Save CPU cycles in the verifying case
authorAaron Jones <redacted>
Tue, 5 May 2015 17:25:42 +0000 (17:25 +0000)
committerAaron Jones <redacted>
Tue, 5 May 2015 17:25:42 +0000 (17:25 +0000)
libathemecore has been verified to handle NULL return from crypt
providers correctly - so start returning NULL in pbkdf2v2 in the
case of trying to verify hashes that were not produced by itself

modules/crypto/pbkdf2v2.c

index 557f33554ed4a4e890dabf4bb014f4a236371af7..940281d54b55a26f4666cb8cecae48a88031bc52 100644 (file)
@@ -134,20 +134,14 @@ static const char *pbkdf2v2_crypt(const char *pass, const char *crypt_str)
        char            digest_b64[(EVP_MAX_MD_SIZE * 2) + 5];
        static char     result[PASSLEN];
 
-       /* Attempt to extract the PRF, iteration count and salt */
-       if (sscanf(crypt_str, PBKDF2_F_SCAN, &prf, &iter, salt) < 3) {
-
-               /*
-                * Didn't get all of the parameters we wanted, the crypt
-                * string must not be for a hash produced by this module.
-                * But we can't just return NULL or an empty string incase
-                * we're being asked to generate a new password hash for a
-                * new user registration (rather than for verification) or
-                * something along those lines. Therefore, generate params.
-                */
-               (void) sscanf(pbkdf2v2_make_salt(), PBKDF2_F_SCAN,
-                             &prf, &iter, salt);
-       }
+       /*
+        * Attempt to extract the PRF, iteration count and salt
+        *
+        * If this fails, we're trying to verify a hash not produced by
+        * this module - just bail out, libathemecore can handle NULL
+        */
+       if (sscanf(crypt_str, PBKDF2_F_SCAN, &prf, &iter, salt) < 3)
+               return NULL;
 
        /* Look up the digest method corresponding to the PRF */
        switch (prf) {
@@ -161,10 +155,11 @@ static const char *pbkdf2v2_crypt(const char *pass, const char *crypt_str)
                break;
 
        default:
-               /* This should match the default PRF */
-               prf = PBKDF2_PRF_DEF;
-               md = EVP_sha512();
-               break;
+               /*
+                * Similar to above, trying to verify a password
+                * that we cannot ever verify - bail out here
+                */
+               return NULL;
        }
 
        /* Compute the PBKDF2 digest */