diff --git a/lib/scram/Makefile.am b/lib/scram/Makefile.am
index 991a16e..437c381 100644
--- a/lib/scram/Makefile.am
+++ b/lib/scram/Makefile.am
@@ -26,7 +26,8 @@ libgsasl_scram_la_SOURCES = scram.h mechinfo.c \
 	tokens.h tokens.c \
 	validate.h validate.c \
 	parser.h parser.c \
-	printer.h printer.c
+	printer.h printer.c \
+	hex.h hex.c \
 
 if CLIENT
 libgsasl_scram_la_SOURCES += client.c
diff --git a/lib/scram/client.c b/lib/scram/client.c
index 437dfb0..7b787fa 100644
--- a/lib/scram/client.c
+++ b/lib/scram/client.c
@@ -41,6 +41,7 @@
 #include "printer.h"
 #include "gc.h"
 #include "memxor.h"
+#include "hex.h"
 
 #define CNONCE_ENTROPY_BYTES 18
 
@@ -124,46 +125,6 @@ _gsasl_scram_sha1_plus_client_start (Gsasl_session * sctx, void **mech_data)
   return scram_start (sctx, mech_data, 1);
 }
 
-static char
-hexdigit_to_char (char hexdigit)
-{
-  if (hexdigit >= '0' && hexdigit <= '9')
-    return hexdigit - '0';
-  if (hexdigit >= 'a' && hexdigit <= 'f')
-    return hexdigit - 'a' + 10;
-  return 0;
-}
-
-static char
-hex_to_char (char u, char l)
-{
-  return (char) (((unsigned char) hexdigit_to_char (u)) * 16
-		 + hexdigit_to_char (l));
-}
-
-static void
-sha1_hex_to_byte (char *saltedpassword, const char *p)
-{
-  while (*p)
-    {
-      *saltedpassword = hex_to_char (p[0], p[1]);
-      p += 2;
-      saltedpassword++;
-    }
-}
-
-static bool
-hex_p (const char *hexstr)
-{
-  static const char hexalpha[] = "0123456789abcdef";
-
-  for (; *hexstr; hexstr++)
-    if (strchr (hexalpha, *hexstr) == NULL)
-      return false;
-
-  return true;
-}
-
 int
 _gsasl_scram_sha1_client_step (Gsasl_session * sctx,
 			       void *mech_data,
diff --git a/lib/scram/hex.c b/lib/scram/hex.c
new file mode 100644
index 0000000..1021cad
--- /dev/null
+++ b/lib/scram/hex.c
@@ -0,0 +1,45 @@
+/* Get strchr, */
+#include <string.h>
+
+/* Get bool. */
+#include <stdbool.h>
+
+static char
+hexdigit_to_char (char hexdigit)
+{
+  if (hexdigit >= '0' && hexdigit <= '9')
+    return hexdigit - '0';
+  if (hexdigit >= 'a' && hexdigit <= 'f')
+    return hexdigit - 'a' + 10;
+  return 0;
+}
+
+static char
+hex_to_char (char u, char l)
+{
+  return (char) (((unsigned char) hexdigit_to_char (u)) * 16
+		 + hexdigit_to_char (l));
+}
+
+void
+sha1_hex_to_byte (char *saltedpassword, const char *p)
+{
+  while (*p)
+    {
+      *saltedpassword = hex_to_char (p[0], p[1]);
+      p += 2;
+      saltedpassword++;
+    }
+}
+
+bool
+hex_p (const char *hexstr)
+{
+  static const char hexalpha[] = "0123456789abcdef";
+
+  for (; *hexstr; hexstr++)
+    if (strchr (hexalpha, *hexstr) == NULL)
+      return false;
+
+  return true;
+}
diff --git a/lib/scram/hex.h b/lib/scram/hex.h
new file mode 100644
index 0000000..ab0039f
--- /dev/null
+++ b/lib/scram/hex.h
@@ -0,0 +1,33 @@
+/* validate.h --- Convert hex strings to bytes.
+ * Copyright (C) 2009-2012 Simon Josefsson
+ *
+ * This file is part of GNU SASL Library.
+ *
+ * GNU SASL Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GNU SASL Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNU SASL Library; if not, write to the Free
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef HEX_H
+#define HEX_H
+
+/* Get bool. */
+#include <stdbool.h>
+
+void sha1_hex_to_byte (char *saltedpassword, const char *p);
+
+bool hex_p (const char *hexstr);
+
+#endif /* HEX_H */
diff --git a/lib/scram/server.c b/lib/scram/server.c
index d6d7ad5..3f01e76 100644
--- a/lib/scram/server.c
+++ b/lib/scram/server.c
@@ -44,6 +44,7 @@
 #include "printer.h"
 #include "gc.h"
 #include "memxor.h"
+#include "hex.h"
 
 #define DEFAULT_SALT_BYTES 12
 #define SNONCE_ENTROPY_BYTES 18
@@ -313,15 +314,21 @@ _gsasl_scram_sha1_server_step (Gsasl_session * sctx,
 
 	{
 	  const char *p;
+	  char saltedpassword[20];
+
+	  memset(saltedpassword, 0, 20);
 
 	  /* Get StoredKey and ServerKey */
-	  if ((p = gsasl_property_get (sctx, GSASL_PASSWORD)))
+	  p = gsasl_property_get (sctx, GSASL_SCRAM_SALTED_PASSWORD);
+	  if (p && strlen (p) == 40 && hex_p (p))
+	    {
+	      sha1_hex_to_byte (saltedpassword, p);
+	    }
+	  else if ((p = gsasl_property_get (sctx, GSASL_PASSWORD)))
 	    {
 	      Gc_rc err;
 	      char *salt;
 	      size_t saltlen;
-	      char saltedpassword[20];
-	      char *clientkey;
 	      char *preppasswd;
 
 	      rc = gsasl_saslprep (p, 0, &preppasswd, NULL);
@@ -344,31 +351,35 @@ _gsasl_scram_sha1_server_step (Gsasl_session * sctx,
 	      gsasl_free (salt);
 	      if (err != GC_OK)
 		return GSASL_MALLOC_ERROR;
+	    }
+	  else
+	    return GSASL_NO_PASSWORD;  
 
-	      /* ClientKey := HMAC(SaltedPassword, "Client Key") */
+	  {
+	    char *clientkey;
+
+	    /* ClientKey := HMAC(SaltedPassword, "Client Key") */
 #define CLIENT_KEY "Client Key"
-	      rc = gsasl_hmac_sha1 (saltedpassword, 20,
-				    CLIENT_KEY, strlen (CLIENT_KEY),
-				    &clientkey);
-	      if (rc != 0)
-		return rc;
+	    rc = gsasl_hmac_sha1 (saltedpassword, 20,
+				  CLIENT_KEY, strlen (CLIENT_KEY),
+				  &clientkey);
+	    if (rc != 0)
+	      return rc;
 
-	      /* StoredKey := H(ClientKey) */
-	      rc = gsasl_sha1 (clientkey, 20, &state->storedkey);
-	      free (clientkey);
-	      if (rc != 0)
-		return rc;
+	    /* StoredKey := H(ClientKey) */
+	    rc = gsasl_sha1 (clientkey, 20, &state->storedkey);
+	    free (clientkey);
+	    if (rc != 0)
+	      return rc;
 
-	      /* ServerKey := HMAC(SaltedPassword, "Server Key") */
+	    /* ServerKey := HMAC(SaltedPassword, "Server Key") */
 #define SERVER_KEY "Server Key"
-	      rc = gsasl_hmac_sha1 (saltedpassword, 20,
-				    SERVER_KEY, strlen (SERVER_KEY),
-				    &state->serverkey);
-	      if (rc != 0)
-		return rc;
-	    }
-	  else
-	    return GSASL_NO_PASSWORD;
+	    rc = gsasl_hmac_sha1 (saltedpassword, 20,
+				  SERVER_KEY, strlen (SERVER_KEY),
+				  &state->serverkey);
+	    if (rc != 0)
+	      return rc;
+	  }
 
 	  /* Compute AuthMessage */
 	  {
