906948
diff --git a/configure.in b/configure.in
906948
index cb43246..0bb6b0d 100644
906948
--- httpd-2.4.43/configure.in.r1861793+
906948
+++ httpd-2.4.43/configure.in
906948
@@ -465,6 +465,28 @@
906948
 AC_SEARCH_LIBS(crypt, crypt)
906948
 CRYPT_LIBS="$LIBS"
906948
 APACHE_SUBST(CRYPT_LIBS)
906948
+
906948
+if test "$ac_cv_search_crypt" != "no"; then
906948
+   # Test crypt() with the SHA-512 test vector from https://akkadia.org/drepper/SHA-crypt.txt
906948
+   AC_CACHE_CHECK([whether crypt() supports SHA-2], [ap_cv_crypt_sha2], [
906948
+    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
906948
+#include <crypt.h>
906948
+#include <stdlib.h>
906948
+#include <string.h>
906948
+
906948
+#define PASSWD_0 "Hello world!"
906948
+#define SALT_0 "\$6\$saltstring"
906948
+#define EXPECT_0 "\$6\$saltstring\$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu" \
906948
+               "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"
906948
+]], [char *result = crypt(PASSWD_0, SALT_0);
906948
+     if (!result) return 1;
906948
+     if (strcmp(result, EXPECT_0)) return 2;
906948
+])], [ap_cv_crypt_sha2=yes], [ap_cv_crypt_sha2=no])])
906948
+   if test "$ap_cv_crypt_sha2" = yes; then
906948
+     AC_DEFINE([HAVE_CRYPT_SHA2], 1, [Define if crypt() supports SHA-2 hashes])
906948
+   fi
906948
+fi
906948
+
906948
 LIBS="$saved_LIBS"
906948
 
906948
 dnl See Comment #Spoon
906948
--- httpd-2.4.43/docs/man/htpasswd.1.r1861793+
906948
+++ httpd-2.4.43/docs/man/htpasswd.1
906948
@@ -27,16 +27,16 @@
906948
 .SH "SYNOPSIS"
906948
  
906948
 .PP
906948
-\fB\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR\fR
906948
+\fB\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fB2\fR | -\fB5\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR\fR
906948
  
906948
 .PP
906948
-\fB\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR\fR
906948
+\fB\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBB\fR | -\fB2\fR | -\fB5\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR\fR
906948
  
906948
 .PP
906948
-\fB\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR\fR
906948
+\fB\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fB2\fR | -\fB5\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR\fR
906948
  
906948
 .PP
906948
-\fB\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR\fR
906948
+\fB\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fB2\fR | -\fB5\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR\fR
906948
  
906948
 
906948
 .SH "SUMMARY"
906948
@@ -48,7 +48,7 @@
906948
 Resources available from the Apache HTTP server can be restricted to just the users listed in the files created by \fBhtpasswd\fR\&. This program can only manage usernames and passwords stored in a flat-file\&. It can encrypt and display password information for use in other types of data stores, though\&. To use a DBM database see dbmmanage or htdbm\&.
906948
  
906948
 .PP
906948
-\fBhtpasswd\fR encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's \fBcrypt()\fR routine\&. Files managed by \fBhtpasswd\fR may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with \fBcrypt()\fR\&.
906948
+\fBhtpasswd\fR encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA-1, or the system's \fBcrypt()\fR routine\&. SHA-2-based hashes (SHA-256 and SHA-512) are supported for \fBcrypt()\fR\&. Files managed by \fBhtpasswd\fR may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with \fBcrypt()\fR\&.
906948
  
906948
 .PP
906948
 This manual page only lists the command line arguments\&. For details of the directives necessary to configure user authentication in httpd see the Apache manual, which is part of the Apache distribution or can be found at http://httpd\&.apache\&.org/\&.
906948
@@ -73,17 +73,26 @@
906948
 \fB-m\fR
906948
 Use MD5 encryption for passwords\&. This is the default (since version 2\&.2\&.18)\&.  
906948
 .TP
906948
+\fB-2\fR
906948
+Use SHA-256 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
906948
+.TP
906948
+\fB-5\fR
906948
+Use SHA-512 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
906948
+.TP
906948
 \fB-B\fR
906948
 Use bcrypt encryption for passwords\&. This is currently considered to be very secure\&.  
906948
 .TP
906948
 \fB-C\fR
906948
 This flag is only allowed in combination with \fB-B\fR (bcrypt encryption)\&. It sets the computing time used for the bcrypt algorithm (higher is more secure but slower, default: 5, valid: 4 to 17)\&.  
906948
 .TP
906948
+\fB-r\fR
906948
+This flag is only allowed in combination with \fB-2\fR or \fB-5\fR\&. It sets the number of hash rounds used for the SHA-2 algorithms (higher is more secure but slower; the default is 5,000)\&.  
906948
+.TP
906948
 \fB-d\fR
906948
 Use \fBcrypt()\fR encryption for passwords\&. This is not supported by the httpd server on Windows and Netware\&. This algorithm limits the password length to 8 characters\&. This algorithm is \fBinsecure\fR by today's standards\&. It used to be the default algorithm until version 2\&.2\&.17\&.  
906948
 .TP
906948
 \fB-s\fR
906948
-Use SHA encryption for passwords\&. Facilitates migration from/to Netscape servers using the LDAP Directory Interchange Format (ldif)\&. This algorithm is \fBinsecure\fR by today's standards\&.  
906948
+Use SHA-1 (160-bit) encryption for passwords\&. Facilitates migration from/to Netscape servers using the LDAP Directory Interchange Format (ldif)\&. This algorithm is \fBinsecure\fR by today's standards\&.  
906948
 .TP
906948
 \fB-p\fR
906948
 Use plaintext passwords\&. Though \fBhtpasswd\fR will support creation on all platforms, the httpd daemon will only accept plain text passwords on Windows and Netware\&.  
906948
@@ -152,10 +161,13 @@
906948
 When using the \fBcrypt()\fR algorithm, note that only the first 8 characters of the password are used to form the password\&. If the supplied password is longer, the extra characters will be silently discarded\&.
906948
  
906948
 .PP
906948
-The SHA encryption format does not use salting: for a given password, there is only one encrypted representation\&. The \fBcrypt()\fR and MD5 formats permute the representation by prepending a random salt string, to make dictionary attacks against the passwords more difficult\&.
906948
+The SHA-1 encryption format does not use salting: for a given password, there is only one encrypted representation\&. The \fBcrypt()\fR and MD5 formats permute the representation by prepending a random salt string, to make dictionary attacks against the passwords more difficult\&.
906948
+ 
906948
+.PP
906948
+The SHA-1 and \fBcrypt()\fR formats are insecure by today's standards\&.
906948
  
906948
 .PP
906948
-The SHA and \fBcrypt()\fR formats are insecure by today's standards\&.
906948
+The SHA-2-based \fBcrypt()\fR formats (SHA-256 and SHA-512) are supported on most modern Unix systems, and follow the specification at https://www\&.akkadia\&.org/drepper/SHA-crypt\&.txt\&.
906948
  
906948
 .SH "RESTRICTIONS"
906948
  
906948
--- httpd-2.4.43/support/htpasswd.c.r1861793+
906948
+++ httpd-2.4.43/support/htpasswd.c
906948
@@ -109,17 +109,21 @@
906948
             "for it." NL
906948
         " -i  Read password from stdin without verification (for script usage)." NL
906948
         " -m  Force MD5 encryption of the password (default)." NL
906948
-        " -B  Force bcrypt encryption of the password (very secure)." NL
906948
+        " -2  Force SHA-256 crypt() hash of the password (very secure)." NL
906948
+        " -5  Force SHA-512 crypt() hash of the password (very secure)." NL
906948
+        " -B  Force bcrypt encryption of the password (very secure)." NL
906948
         " -C  Set the computing time used for the bcrypt algorithm" NL
906948
         "     (higher is more secure but slower, default: %d, valid: 4 to 17)." NL
906948
+        " -r  Set the number of rounds used for the SHA-256, SHA-512 algorithms" NL
906948
+        "     (higher is more secure but slower, default: 5000)." NL
906948
         " -d  Force CRYPT encryption of the password (8 chars max, insecure)." NL
906948
-        " -s  Force SHA encryption of the password (insecure)." NL
906948
+        " -s  Force SHA-1 encryption of the password (insecure)." NL
906948
         " -p  Do not encrypt the password (plaintext, insecure)." NL
906948
         " -D  Delete the specified user." NL
906948
         " -v  Verify password for the specified user." NL
906948
         "On other systems than Windows and NetWare the '-p' flag will "
906948
             "probably not work." NL
906948
-        "The SHA algorithm does not use a salt and is less secure than the "
906948
+        "The SHA-1 algorithm does not use a salt and is less secure than the "
906948
             "MD5 algorithm." NL,
906948
         BCRYPT_DEFAULT_COST
906948
     );
906948
@@ -178,7 +182,7 @@
906948
     if (rv != APR_SUCCESS)
906948
         exit(ERR_SYNTAX);
906948
 
906948
-    while ((rv = apr_getopt(state, "cnmspdBbDiC:v", &opt, &opt_arg)) == APR_SUCCESS) {
906948
+    while ((rv = apr_getopt(state, "cnmspdBbDi25C:r:v", &opt, &opt_arg)) == APR_SUCCESS) {
906948
         switch (opt) {
906948
         case 'c':
906948
             *mask |= APHTP_NEWFILE;
906948
--- httpd-2.4.43/support/passwd_common.c.r1861793+
906948
+++ httpd-2.4.43/support/passwd_common.c
906948
@@ -179,16 +179,21 @@
906948
 int mkhash(struct passwd_ctx *ctx)
906948
 {
906948
     char *pw;
906948
-    char salt[16];
906948
+    char salt[17];
906948
     apr_status_t rv;
906948
     int ret = 0;
906948
 #if CRYPT_ALGO_SUPPORTED
906948
     char *cbuf;
906948
 #endif
906948
+#ifdef HAVE_CRYPT_SHA2
906948
+    const char *setting;
906948
+    char method;
906948
+#endif
906948
 
906948
-    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT) {
906948
+    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT
906948
+        && ctx->alg != ALG_CRYPT_SHA256 && ctx->alg != ALG_CRYPT_SHA512 ) {
906948
         apr_file_printf(errfile,
906948
-                        "Warning: Ignoring -C argument for this algorithm." NL);
906948
+                        "Warning: Ignoring -C/-r argument for this algorithm." NL);
906948
     }
906948
 
906948
     if (ctx->passwd == NULL) {
906948
@@ -246,6 +251,34 @@
906948
         break;
906948
 #endif /* CRYPT_ALGO_SUPPORTED */
906948
 
906948
+#ifdef HAVE_CRYPT_SHA2
906948
+    case ALG_CRYPT_SHA256:
906948
+    case ALG_CRYPT_SHA512:
906948
+        ret = generate_salt(salt, 16, &ctx->errstr, ctx->pool);
906948
+        if (ret != 0)
906948
+            break;
906948
+
906948
+        method = ctx->alg == ALG_CRYPT_SHA256 ? '5': '6';
906948
+
906948
+        if (ctx->cost) 
906948
+            setting = apr_psprintf(ctx->pool, "$%c$rounds=%d$%s",
906948
+                                   method, ctx->cost, salt);
906948
+        else
906948
+            setting = apr_psprintf(ctx->pool, "$%c$%s",
906948
+                                   method, salt);
906948
+
906948
+        cbuf = crypt(pw, setting);
906948
+        if (cbuf == NULL) {
906948
+            rv = APR_FROM_OS_ERROR(errno);
906948
+            ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv;;
906948
+            ret = ERR_PWMISMATCH;
906948
+            break;
906948
+        }
906948
+
906948
+        apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
906948
+        break;
906948
+#endif /* HAVE_CRYPT_SHA2 */
906948
+
906948
 #if BCRYPT_ALGO_SUPPORTED
906948
     case ALG_BCRYPT:
906948
         rv = apr_generate_random_bytes((unsigned char*)salt, 16);
906948
@@ -294,6 +327,19 @@
906948
     case 's':
906948
         ctx->alg = ALG_APSHA;
906948
         break;
906948
+#ifdef HAVE_CRYPT_SHA2
906948
+    case '2':
906948
+        ctx->alg = ALG_CRYPT_SHA256;
906948
+        break;
906948
+    case '5':
906948
+        ctx->alg = ALG_CRYPT_SHA512;
906948
+        break;
906948
+#else
906948
+    case '2':
906948
+    case '5':
906948
+        ctx->errstr = "SHA-2 crypt() algorithms are not supported on this platform.";
906948
+        return ERR_ALG_NOT_SUPP;
906948
+#endif
906948
     case 'p':
906948
         ctx->alg = ALG_PLAIN;
906948
 #if !PLAIN_ALGO_SUPPORTED
906948
@@ -324,11 +370,12 @@
906948
         return ERR_ALG_NOT_SUPP;
906948
 #endif
906948
         break;
906948
-    case 'C': {
906948
+    case 'C':
906948
+    case 'r': {
906948
             char *endptr;
906948
             long num = strtol(opt_arg, &endptr, 10);
906948
             if (*endptr != '\0' || num <= 0) {
906948
-                ctx->errstr = "argument to -C must be a positive integer";
906948
+                ctx->errstr = "argument to -C/-r must be a positive integer";
906948
                 return ERR_SYNTAX;
906948
             }
906948
             ctx->cost = num;
906948
--- httpd-2.4.43/support/passwd_common.h.r1861793+
906948
+++ httpd-2.4.43/support/passwd_common.h
906948
@@ -28,6 +28,8 @@
906948
 #include "apu_version.h"
906948
 #endif
906948
 
906948
+#include "ap_config_auto.h"
906948
+
906948
 #define MAX_STRING_LEN 256
906948
 
906948
 #define ALG_PLAIN 0
906948
@@ -35,6 +37,8 @@
906948
 #define ALG_APMD5 2
906948
 #define ALG_APSHA 3
906948
 #define ALG_BCRYPT 4
906948
+#define ALG_CRYPT_SHA256 5
906948
+#define ALG_CRYPT_SHA512 6
906948
 
906948
 #define BCRYPT_DEFAULT_COST 5
906948
 
906948
@@ -84,7 +88,7 @@
906948
     apr_size_t      out_len;
906948
     char            *passwd;
906948
     int             alg;
906948
-    int             cost;
906948
+    int             cost; /* cost for bcrypt, rounds for SHA-2 */
906948
     enum {
906948
         PW_PROMPT = 0,
906948
         PW_ARG,