0e3136
diff --git a/configure.in b/configure.in
0e3136
index cb43246..0bb6b0d 100644
0e3136
--- httpd-2.4.43/configure.in.r1861793+
0e3136
+++ httpd-2.4.43/configure.in
0e3136
@@ -465,6 +465,28 @@
0e3136
 AC_SEARCH_LIBS(crypt, crypt)
0e3136
 CRYPT_LIBS="$LIBS"
0e3136
 APACHE_SUBST(CRYPT_LIBS)
0e3136
+
0e3136
+if test "$ac_cv_search_crypt" != "no"; then
0e3136
+   # Test crypt() with the SHA-512 test vector from https://akkadia.org/drepper/SHA-crypt.txt
0e3136
+   AC_CACHE_CHECK([whether crypt() supports SHA-2], [ap_cv_crypt_sha2], [
0e3136
+    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
0e3136
+#include <crypt.h>
0e3136
+#include <stdlib.h>
0e3136
+#include <string.h>
0e3136
+
0e3136
+#define PASSWD_0 "Hello world!"
0e3136
+#define SALT_0 "\$6\$saltstring"
0e3136
+#define EXPECT_0 "\$6\$saltstring\$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu" \
0e3136
+               "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"
0e3136
+]], [char *result = crypt(PASSWD_0, SALT_0);
0e3136
+     if (!result) return 1;
0e3136
+     if (strcmp(result, EXPECT_0)) return 2;
0e3136
+])], [ap_cv_crypt_sha2=yes], [ap_cv_crypt_sha2=no])])
0e3136
+   if test "$ap_cv_crypt_sha2" = yes; then
0e3136
+     AC_DEFINE([HAVE_CRYPT_SHA2], 1, [Define if crypt() supports SHA-2 hashes])
0e3136
+   fi
0e3136
+fi
0e3136
+
0e3136
 LIBS="$saved_LIBS"
0e3136
 
0e3136
 dnl See Comment #Spoon
0e3136
--- httpd-2.4.43/docs/man/htpasswd.1.r1861793+
0e3136
+++ httpd-2.4.43/docs/man/htpasswd.1
0e3136
@@ -27,16 +27,16 @@
0e3136
 .SH "SYNOPSIS"
0e3136
  
0e3136
 .PP
0e3136
-\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
0e3136
+\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
0e3136
  
0e3136
 .PP
0e3136
-\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
0e3136
+\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
0e3136
  
0e3136
 .PP
0e3136
-\fB\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR\fR
0e3136
+\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
0e3136
  
0e3136
 .PP
0e3136
-\fB\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR\fR
0e3136
+\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
0e3136
  
0e3136
 
0e3136
 .SH "SUMMARY"
0e3136
@@ -48,7 +48,7 @@
0e3136
 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\&.
0e3136
  
0e3136
 .PP
0e3136
-\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\&.
0e3136
+\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\&.
0e3136
  
0e3136
 .PP
0e3136
 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/\&.
0e3136
@@ -73,17 +73,26 @@
0e3136
 \fB-m\fR
0e3136
 Use MD5 encryption for passwords\&. This is the default (since version 2\&.2\&.18)\&.  
0e3136
 .TP
0e3136
+\fB-2\fR
0e3136
+Use SHA-256 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
0e3136
+.TP
0e3136
+\fB-5\fR
0e3136
+Use SHA-512 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
0e3136
+.TP
0e3136
 \fB-B\fR
0e3136
 Use bcrypt encryption for passwords\&. This is currently considered to be very secure\&.  
0e3136
 .TP
0e3136
 \fB-C\fR
0e3136
 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)\&.  
0e3136
 .TP
0e3136
+\fB-r\fR
0e3136
+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)\&.  
0e3136
+.TP
0e3136
 \fB-d\fR
0e3136
 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\&.  
0e3136
 .TP
0e3136
 \fB-s\fR
0e3136
-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\&.  
0e3136
+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\&.  
0e3136
 .TP
0e3136
 \fB-p\fR
0e3136
 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\&.  
0e3136
@@ -152,10 +161,13 @@
0e3136
 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\&.
0e3136
  
0e3136
 .PP
0e3136
-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\&.
0e3136
+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\&.
0e3136
+ 
0e3136
+.PP
0e3136
+The SHA-1 and \fBcrypt()\fR formats are insecure by today's standards\&.
0e3136
  
0e3136
 .PP
0e3136
-The SHA and \fBcrypt()\fR formats are insecure by today's standards\&.
0e3136
+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\&.
0e3136
  
0e3136
 .SH "RESTRICTIONS"
0e3136
  
0e3136
--- httpd-2.4.43/support/htpasswd.c.r1861793+
0e3136
+++ httpd-2.4.43/support/htpasswd.c
0e3136
@@ -109,17 +109,21 @@
0e3136
             "for it." NL
0e3136
         " -i  Read password from stdin without verification (for script usage)." NL
0e3136
         " -m  Force MD5 encryption of the password (default)." NL
0e3136
-        " -B  Force bcrypt encryption of the password (very secure)." NL
0e3136
+        " -2  Force SHA-256 crypt() hash of the password (very secure)." NL
0e3136
+        " -5  Force SHA-512 crypt() hash of the password (very secure)." NL
0e3136
+        " -B  Force bcrypt encryption of the password (very secure)." NL
0e3136
         " -C  Set the computing time used for the bcrypt algorithm" NL
0e3136
         "     (higher is more secure but slower, default: %d, valid: 4 to 17)." NL
0e3136
+        " -r  Set the number of rounds used for the SHA-256, SHA-512 algorithms" NL
0e3136
+        "     (higher is more secure but slower, default: 5000)." NL
0e3136
         " -d  Force CRYPT encryption of the password (8 chars max, insecure)." NL
0e3136
-        " -s  Force SHA encryption of the password (insecure)." NL
0e3136
+        " -s  Force SHA-1 encryption of the password (insecure)." NL
0e3136
         " -p  Do not encrypt the password (plaintext, insecure)." NL
0e3136
         " -D  Delete the specified user." NL
0e3136
         " -v  Verify password for the specified user." NL
0e3136
         "On other systems than Windows and NetWare the '-p' flag will "
0e3136
             "probably not work." NL
0e3136
-        "The SHA algorithm does not use a salt and is less secure than the "
0e3136
+        "The SHA-1 algorithm does not use a salt and is less secure than the "
0e3136
             "MD5 algorithm." NL,
0e3136
         BCRYPT_DEFAULT_COST
0e3136
     );
0e3136
@@ -178,7 +182,7 @@
0e3136
     if (rv != APR_SUCCESS)
0e3136
         exit(ERR_SYNTAX);
0e3136
 
0e3136
-    while ((rv = apr_getopt(state, "cnmspdBbDiC:v", &opt, &opt_arg)) == APR_SUCCESS) {
0e3136
+    while ((rv = apr_getopt(state, "cnmspdBbDi25C:r:v", &opt, &opt_arg)) == APR_SUCCESS) {
0e3136
         switch (opt) {
0e3136
         case 'c':
0e3136
             *mask |= APHTP_NEWFILE;
0e3136
--- httpd-2.4.43/support/passwd_common.c.r1861793+
0e3136
+++ httpd-2.4.43/support/passwd_common.c
0e3136
@@ -179,16 +179,21 @@
0e3136
 int mkhash(struct passwd_ctx *ctx)
0e3136
 {
0e3136
     char *pw;
0e3136
-    char salt[16];
0e3136
+    char salt[17];
0e3136
     apr_status_t rv;
0e3136
     int ret = 0;
0e3136
 #if CRYPT_ALGO_SUPPORTED
0e3136
     char *cbuf;
0e3136
 #endif
0e3136
+#ifdef HAVE_CRYPT_SHA2
0e3136
+    const char *setting;
0e3136
+    char method;
0e3136
+#endif
0e3136
 
0e3136
-    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT) {
0e3136
+    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT
0e3136
+        && ctx->alg != ALG_CRYPT_SHA256 && ctx->alg != ALG_CRYPT_SHA512 ) {
0e3136
         apr_file_printf(errfile,
0e3136
-                        "Warning: Ignoring -C argument for this algorithm." NL);
0e3136
+                        "Warning: Ignoring -C/-r argument for this algorithm." NL);
0e3136
     }
0e3136
 
0e3136
     if (ctx->passwd == NULL) {
0e3136
@@ -246,6 +251,34 @@
0e3136
         break;
0e3136
 #endif /* CRYPT_ALGO_SUPPORTED */
0e3136
 
0e3136
+#ifdef HAVE_CRYPT_SHA2
0e3136
+    case ALG_CRYPT_SHA256:
0e3136
+    case ALG_CRYPT_SHA512:
0e3136
+        ret = generate_salt(salt, 16, &ctx->errstr, ctx->pool);
0e3136
+        if (ret != 0)
0e3136
+            break;
0e3136
+
0e3136
+        method = ctx->alg == ALG_CRYPT_SHA256 ? '5': '6';
0e3136
+
0e3136
+        if (ctx->cost) 
0e3136
+            setting = apr_psprintf(ctx->pool, "$%c$rounds=%d$%s",
0e3136
+                                   method, ctx->cost, salt);
0e3136
+        else
0e3136
+            setting = apr_psprintf(ctx->pool, "$%c$%s",
0e3136
+                                   method, salt);
0e3136
+
0e3136
+        cbuf = crypt(pw, setting);
0e3136
+        if (cbuf == NULL) {
0e3136
+            rv = APR_FROM_OS_ERROR(errno);
0e3136
+            ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv;;
0e3136
+            ret = ERR_PWMISMATCH;
0e3136
+            break;
0e3136
+        }
0e3136
+
0e3136
+        apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
0e3136
+        break;
0e3136
+#endif /* HAVE_CRYPT_SHA2 */
0e3136
+
0e3136
 #if BCRYPT_ALGO_SUPPORTED
0e3136
     case ALG_BCRYPT:
0e3136
         rv = apr_generate_random_bytes((unsigned char*)salt, 16);
0e3136
@@ -294,6 +327,19 @@
0e3136
     case 's':
0e3136
         ctx->alg = ALG_APSHA;
0e3136
         break;
0e3136
+#ifdef HAVE_CRYPT_SHA2
0e3136
+    case '2':
0e3136
+        ctx->alg = ALG_CRYPT_SHA256;
0e3136
+        break;
0e3136
+    case '5':
0e3136
+        ctx->alg = ALG_CRYPT_SHA512;
0e3136
+        break;
0e3136
+#else
0e3136
+    case '2':
0e3136
+    case '5':
0e3136
+        ctx->errstr = "SHA-2 crypt() algorithms are not supported on this platform.";
0e3136
+        return ERR_ALG_NOT_SUPP;
0e3136
+#endif
0e3136
     case 'p':
0e3136
         ctx->alg = ALG_PLAIN;
0e3136
 #if !PLAIN_ALGO_SUPPORTED
0e3136
@@ -324,11 +370,12 @@
0e3136
         return ERR_ALG_NOT_SUPP;
0e3136
 #endif
0e3136
         break;
0e3136
-    case 'C': {
0e3136
+    case 'C':
0e3136
+    case 'r': {
0e3136
             char *endptr;
0e3136
             long num = strtol(opt_arg, &endptr, 10);
0e3136
             if (*endptr != '\0' || num <= 0) {
0e3136
-                ctx->errstr = "argument to -C must be a positive integer";
0e3136
+                ctx->errstr = "argument to -C/-r must be a positive integer";
0e3136
                 return ERR_SYNTAX;
0e3136
             }
0e3136
             ctx->cost = num;
0e3136
--- httpd-2.4.43/support/passwd_common.h.r1861793+
0e3136
+++ httpd-2.4.43/support/passwd_common.h
0e3136
@@ -28,6 +28,8 @@
0e3136
 #include "apu_version.h"
0e3136
 #endif
0e3136
 
0e3136
+#include "ap_config_auto.h"
0e3136
+
0e3136
 #define MAX_STRING_LEN 256
0e3136
 
0e3136
 #define ALG_PLAIN 0
0e3136
@@ -35,6 +37,8 @@
0e3136
 #define ALG_APMD5 2
0e3136
 #define ALG_APSHA 3
0e3136
 #define ALG_BCRYPT 4
0e3136
+#define ALG_CRYPT_SHA256 5
0e3136
+#define ALG_CRYPT_SHA512 6
0e3136
 
0e3136
 #define BCRYPT_DEFAULT_COST 5
0e3136
 
0e3136
@@ -84,7 +88,7 @@
0e3136
     apr_size_t      out_len;
0e3136
     char            *passwd;
0e3136
     int             alg;
0e3136
-    int             cost;
0e3136
+    int             cost; /* cost for bcrypt, rounds for SHA-2 */
0e3136
     enum {
0e3136
         PW_PROMPT = 0,
0e3136
         PW_ARG,