@@ -207,7 +207,7 @@ pg_be_scram_init(const char *username, const char *shadow_pass)
207207 */
208208char * verifier ;
209209
210- verifier = scram_build_verifier ( username , shadow_pass , 0 );
210+ verifier = pg_be_scram_build_verifier ( shadow_pass );
211211
212212(void )parse_scram_verifier (verifier ,& state -> iterations ,& state -> salt ,
213213state -> StoredKey ,state -> ServerKey );
@@ -387,22 +387,14 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
387387/*
388388 * Construct a verifier string for SCRAM, stored in pg_authid.rolpassword.
389389 *
390- * If iterations is 0, default number of iterations is used. The result is
391- * palloc'd, so caller is responsible for freeing it.
390+ * The result is palloc'd, so caller is responsible for freeing it.
392391 */
393392char *
394- scram_build_verifier (const char * username ,const char * password ,
395- int iterations )
393+ pg_be_scram_build_verifier (const char * password )
396394{
397395char * prep_password = NULL ;
398396pg_saslprep_rc rc ;
399397char saltbuf [SCRAM_DEFAULT_SALT_LEN ];
400- uint8 salted_password [SCRAM_KEY_LEN ];
401- uint8 keybuf [SCRAM_KEY_LEN ];
402- char * encoded_salt ;
403- char * encoded_storedkey ;
404- char * encoded_serverkey ;
405- int encoded_len ;
406398char * result ;
407399
408400/*
@@ -414,10 +406,7 @@ scram_build_verifier(const char *username, const char *password,
414406if (rc == SASLPREP_SUCCESS )
415407password = (const char * )prep_password ;
416408
417- if (iterations <=0 )
418- iterations = SCRAM_DEFAULT_ITERATIONS ;
419-
420- /* Generate salt, and encode it in base64 */
409+ /* Generate random salt */
421410if (!pg_backend_random (saltbuf ,SCRAM_DEFAULT_SALT_LEN ))
422411{
423412ereport (LOG ,
@@ -426,37 +415,11 @@ scram_build_verifier(const char *username, const char *password,
426415return NULL ;
427416}
428417
429- encoded_salt = palloc (pg_b64_enc_len (SCRAM_DEFAULT_SALT_LEN )+ 1 );
430- encoded_len = pg_b64_encode (saltbuf ,SCRAM_DEFAULT_SALT_LEN ,encoded_salt );
431- encoded_salt [encoded_len ]= '\0' ;
432-
433- /* Calculate StoredKey, and encode it in base64 */
434- scram_SaltedPassword (password ,saltbuf ,SCRAM_DEFAULT_SALT_LEN ,
435- iterations ,salted_password );
436- scram_ClientKey (salted_password ,keybuf );
437- scram_H (keybuf ,SCRAM_KEY_LEN ,keybuf );/* StoredKey */
438-
439- encoded_storedkey = palloc (pg_b64_enc_len (SCRAM_KEY_LEN )+ 1 );
440- encoded_len = pg_b64_encode ((const char * )keybuf ,SCRAM_KEY_LEN ,
441- encoded_storedkey );
442- encoded_storedkey [encoded_len ]= '\0' ;
443-
444- /* And same for ServerKey */
445- scram_ServerKey (salted_password ,keybuf );
446-
447- encoded_serverkey = palloc (pg_b64_enc_len (SCRAM_KEY_LEN )+ 1 );
448- encoded_len = pg_b64_encode ((const char * )keybuf ,SCRAM_KEY_LEN ,
449- encoded_serverkey );
450- encoded_serverkey [encoded_len ]= '\0' ;
451-
452- result = psprintf ("SCRAM-SHA-256$%d:%s$%s:%s" ,iterations ,encoded_salt ,
453- encoded_storedkey ,encoded_serverkey );
418+ result = scram_build_verifier (saltbuf ,SCRAM_DEFAULT_SALT_LEN ,
419+ SCRAM_DEFAULT_ITERATIONS ,password );
454420
455421if (prep_password )
456422pfree (prep_password );
457- pfree (encoded_salt );
458- pfree (encoded_storedkey );
459- pfree (encoded_serverkey );
460423
461424return result ;
462425}
@@ -1194,7 +1157,7 @@ scram_MockSalt(const char *username)
11941157 * Generate salt using a SHA256 hash of the username and the cluster's
11951158 * mock authentication nonce. (This works as long as the salt length is
11961159 * not larger the SHA256 digest length. If the salt is smaller, the caller
1197- * will just ignore the extra data) )
1160+ * will just ignore the extra data. )
11981161 */
11991162StaticAssertStmt (PG_SHA256_DIGEST_LENGTH >=SCRAM_DEFAULT_SALT_LEN ,
12001163"salt length greater than SHA256 digest length" );