+ /* This is how HMAC is done in InspIRCd 1.2:
+ *
+ * sha256( (pass xor 0x5c) + sha256((pass xor 0x36) + m) )
+ *
+ * 5c and 36 were chosen as part of the HMAC standard, because they
+ * flip the bits in a way likely to strengthen the function.
+ */
+ std::string hmac1, hmac2;
+
+ for (size_t n = 0; n < password.length(); n++)
+ {
+ hmac1.push_back(static_cast<char>(password[n] ^ 0x5C));
+ hmac2.push_back(static_cast<char>(password[n] ^ 0x36));
+ }
+
+ hmac2.append(challenge);
+ hmac2 = sha256->hexsum(hmac2);
+
+ std::string hmac = hmac1 + hmac2;
+ hmac = sha256->hexsum(hmac);
+
+ return "HMAC-SHA256:"+ hmac;
+ }
+ else
+ {
+ return "AUTH:" + BinToBase64(sha256->hmac(password, challenge));