get rid of compiler warnings
[tprouty/samba.git] / source / libsmb / smbencrypt.c
index e7ebd4c00027e3150ea6bcaea802ac4d6ffec0e8..b6273dedfc6322e807c8465038e34eb9c30e14e8 100644 (file)
@@ -53,56 +53,6 @@ void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
 #endif
 }
 
-/* Routines for Windows NT MD4 Hash functions. */
-static int _my_wcslen(int16 *str)
-{
-       int len = 0;
-       while(*str++ != 0)
-               len++;
-       return len;
-}
-
-/*
- * Convert a string into an NT UNICODE string.
- * Note that regardless of processor type 
- * this must be in intel (little-endian)
- * format.
- */
-static int _my_mbstowcs(int16 *dst, uchar *src, int len)
-{
-       int i;
-       int16 val;
-       for(i = 0; i < len; i++) {
-               val = *src;
-               SSVAL(dst,0,val);
-               dst++;
-               src++;
-               if(val == 0)
-                       break;
-       }
-       return i;
-}
-
-static int _my_mbstowcsupper(int16 * dst, const uchar * src, int len)
-{
-       int i;
-       int16 val;
-
-       for (i = 0; i < len; i++)
-       {
-               val = toupper(*src);
-               SSVAL(dst, 0, val);
-               dst++;
-               src++;
-               if (val == 0)
-                       break;
-       }
-       return i;
-}
-
-
 /* 
  * Creates the MD4 Hash of the users password in NT UNICODE.
  */
@@ -110,17 +60,16 @@ static int _my_mbstowcsupper(int16 * dst, const uchar * src, int len)
 void E_md4hash(uchar *passwd, uchar *p16)
 {
        int len;
-       int16 wpwd[129];
+       smb_ucs2_t wpwd[129];
        
        /* Password cannot be longer than 128 characters */
        len = strlen((char *)passwd);
        if(len > 128)
                len = 128;
-       /* Password must be converted to NT unicode */
-       _my_mbstowcs(wpwd, passwd, len);
-       wpwd[len] = 0; /* Ensure string is null terminated */
+       /* Password must be converted to NT unicode - null terminated. */
+       push_ucs2(NULL, wpwd, (const char *)passwd, 256, STR_UNICODE|STR_NOALIGN|STR_TERMINATE);
        /* Calculate length in bytes */
-       len = _my_wcslen(wpwd) * sizeof(int16);
+       len = strlen_w(wpwd) * sizeof(int16);
 
        mdfour(p16, (unsigned char *)wpwd, len);
 }
@@ -172,12 +121,12 @@ void ntv2_owf_gen(const uchar owf[16],
        int user_l = strlen(user_n);
        int domain_l = strlen(domain_n);
 
-       _my_mbstowcsupper((int16 *) user_u, user_n, user_l * 2);
-       _my_mbstowcsupper((int16 *) dom_u, domain_n, domain_l * 2);
+       push_ucs2(NULL, user_u, user_n, (user_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER);
+       push_ucs2(NULL, dom_u, domain_n, (domain_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER);
 
        hmac_md5_init_limK_to_64(owf, 16, &ctx);
-       hmac_md5_update(user_u, user_l * 2, &ctx);
-       hmac_md5_update(dom_u, domain_l * 2, &ctx);
+       hmac_md5_update((const unsigned char *)user_u, user_l * 2, &ctx);
+       hmac_md5_update((const unsigned char *)dom_u, domain_l * 2, &ctx);
        hmac_md5_final(kr_buf, &ctx);
 
 #ifdef DEBUG_PASSWORD
@@ -279,7 +228,7 @@ void SMBOWFencrypt_ntv2(const uchar kr[16],
        hmac_md5_init_limK_to_64(kr, 16, &ctx);
        hmac_md5_update(srv_chal, srv_chal_len, &ctx);
        hmac_md5_update(cli_chal, cli_chal_len, &ctx);
-       hmac_md5_final(resp_buf, &ctx);
+       hmac_md5_final((unsigned char *)resp_buf, &ctx);
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100, ("SMBOWFencrypt_ntv2: srv_chal, cli_chal, resp_buf\n"));
@@ -296,7 +245,7 @@ void SMBsesskeygen_ntv2(const uchar kr[16],
 
        hmac_md5_init_limK_to_64(kr, 16, &ctx);
        hmac_md5_update(nt_resp, 16, &ctx);
-       hmac_md5_final(sess_key, &ctx);
+       hmac_md5_final((unsigned char *)sess_key, &ctx);
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100, ("SMBsesskeygen_ntv2:\n"));
@@ -307,7 +256,7 @@ void SMBsesskeygen_ntv2(const uchar kr[16],
 void SMBsesskeygen_ntv1(const uchar kr[16],
                        const uchar * nt_resp, char sess_key[16])
 {
-       mdfour(sess_key, kr, 16);
+       mdfour((unsigned char *)sess_key, kr, 16);
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100, ("SMBsesskeygen_ntv1:\n"));
@@ -321,7 +270,7 @@ void SMBsesskeygen_ntv1(const uchar kr[16],
 BOOL encode_pw_buffer(char buffer[516], const char *new_pass,
                      int new_pw_len, BOOL nt_pass_set)
 {
-       generate_random_buffer(buffer, 516, True);
+       generate_random_buffer((unsigned char *)buffer, 516, True);
 
        if (nt_pass_set) {
                new_pw_len *= 2;
@@ -439,7 +388,7 @@ void nt_owf_genW(const UNISTR2 *pwd, uchar nt_p16[16])
                SIVAL(buf, i * 2, pwd->buffer[i]);
        }
        /* Calculate the MD4 hash (NT compatible) of the password */
-       mdfour(nt_p16, buf, pwd->uni_str_len * 2);
+       mdfour(nt_p16, (const unsigned char *)buf, pwd->uni_str_len * 2);
 
        /* clear out local copy of user's password (just being paranoid). */
        ZERO_STRUCT(buf);