41 #ifndef HAVE_UCBINCLUDE 45 #include "/usr/ucbinclude/fcntl.h" 49 #define uint32 uint32_t 56 static unsigned char smb_arc4_state[258];
65 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 67 static bool done_reseed_ntlmssp =
False;
68 static void (*reseed_callback_ntlmssp)(
int *newseed);
74 static void get_rand_reseed_data_ntlmssp(
int *reseed_data)
76 if (reseed_callback_ntlmssp) {
77 reseed_callback_ntlmssp(reseed_data);
88 static void do_filehash_ntlmssp(
const char *fname,
unsigned char *the_hash)
90 unsigned char buf[1011];
91 unsigned char tmp_md4[16];
94 fd = open(fname,O_RDONLY,0);
98 while ((n = read(fd, (
char *)buf,
sizeof(buf))) > 0) {
101 the_hash[n] ^= tmp_md4[n];
118 static int do_reseed_ntlmssp(
bool use_fd,
int fd)
120 unsigned char seed_inbuf[40];
127 fd = open(
"/dev/urandom", O_RDONLY,0);
134 do_filehash_ntlmssp(
"/etc/shadow", &seed_inbuf[0]);
141 v1 = (counter++) + mypid + tval.tv_sec;
142 v2 = (counter++) * mypid + tval.tv_usec;
144 SIVAL(seed_inbuf, 32, v1 ^
IVAL(seed_inbuf, 32));
145 SIVAL(seed_inbuf, 36, v2 ^
IVAL(seed_inbuf, 36));
151 get_rand_reseed_data_ntlmssp(&reseed_data);
154 for (i = 0; i <
sizeof(seed_inbuf); i++)
155 seed_inbuf[i] ^= ((
char *)(&reseed_data))[i %
sizeof(reseed_data)];
169 static int urand_fd = -1;
170 unsigned char md4_buf[64];
171 unsigned char tmp_buf[16];
174 if(!done_reseed_ntlmssp) {
175 urand_fd = do_reseed_ntlmssp(
True, urand_fd);
176 done_reseed_ntlmssp =
True;
179 if (urand_fd != -1 && len > 0) {
181 if (read(urand_fd, out, len) == len)
187 do_reseed_ntlmssp(
False, -1);
188 done_reseed_ntlmssp =
True;
200 int copy_len = len > 16 ? 16 : len;
204 memcpy(p, tmp_buf, copy_len);
void GetTimeOfDay_ntlmssp(struct timeval *tval)
#define SIVAL(buf, pos, val)
void mdfour_ntlmssp(unsigned char *out, const unsigned char *in, int n)
void generate_random_buffer_ntlmssp(unsigned char *out, int len)
void smb_arc4_crypt_ntlmssp(unsigned char arc4_state_inout[258], unsigned char *data, size_t len)
struct timeval timeval(unsigned long val)
void smb_arc4_init_ntlmssp(unsigned char arc4_state_out[258], const unsigned char *key, size_t keylen)