+static int mschapv1_encode(VALUE_PAIR **request, const char *password)
+{
+ unsigned int i;
+ VALUE_PAIR *challenge, *response;
+ uint8_t nthash[16];
+
+ challenge = paircreate(PW_MSCHAP_CHALLENGE, VENDORPEC_MICROSOFT, PW_TYPE_OCTETS);
+ if (!challenge) {
+ fprintf(stderr, "GOT IT %d!\n", __LINE__);
+ return 0;
+ }
+
+ pairadd(request, challenge);
+ challenge->length = 8;
+ for (i = 0; i < challenge->length; i++) {
+ challenge->vp_octets[i] = fr_rand();
+ }
+
+ response = paircreate(PW_MSCHAP_RESPONSE, VENDORPEC_MICROSOFT, PW_TYPE_OCTETS);
+ if (!response) {
+ fprintf(stderr, "GOT IT %d!\n", __LINE__);
+ return 0;
+ }
+
+ pairadd(request, response);
+ response->length = 50;
+ memset(response->vp_octets, 0, response->length);
+
+ response->vp_octets[1] = 0x01; /* NT hash */
+
+ mschap_ntpwdhash(nthash, password);
+
+ smbdes_mschap(nthash, challenge->vp_octets,
+ response->vp_octets + 26);
+ return 1;
+}
+
+