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