OpenVAS Libraries  9.0.3
genrand.c File Reference

Random number generation. More...

#include <pwd.h>
#include <unistd.h>
#include "byteorder.h"
#include "smb.h"
#include <time.h>
#include "md4.h"
#include "proto.h"
#include <fcntl.h>
Include dependency graph for genrand.c:

Go to the source code of this file.

Macros

#define uint32   uint32_t
 
#define False   0
 
#define True   1
 
#define ZERO_STRUCT(x)   memset((char *)&(x), 0, sizeof(x))
 

Typedefs

typedef unsigned int bool
 

Functions

void generate_random_buffer_ntlmssp (unsigned char *out, int len)
 

Detailed Description

Random number generation.

Definition in file genrand.c.

Macro Definition Documentation

◆ False

#define False   0

Definition at line 53 of file genrand.c.

◆ True

#define True   1

Definition at line 54 of file genrand.c.

◆ uint32

#define uint32   uint32_t

Definition at line 49 of file genrand.c.

◆ ZERO_STRUCT

#define ZERO_STRUCT (   x)    memset((char *)&(x), 0, sizeof(x))

Definition at line 65 of file genrand.c.

Typedef Documentation

◆ bool

typedef unsigned int bool

Definition at line 52 of file genrand.c.

Function Documentation

◆ generate_random_buffer_ntlmssp()

void generate_random_buffer_ntlmssp ( unsigned char *  out,
int  len 
)

Definition at line 167 of file genrand.c.

168 {
169  static int urand_fd = -1;
170  unsigned char md4_buf[64];
171  unsigned char tmp_buf[16];
172  unsigned char *p;
173 
174  if(!done_reseed_ntlmssp) {
175  urand_fd = do_reseed_ntlmssp(True, urand_fd);
176  done_reseed_ntlmssp = True;
177  }
178 
179  if (urand_fd != -1 && len > 0) {
180 
181  if (read(urand_fd, out, len) == len)
182  return; /* len bytes of random data read from urandom. */
183 
184  /* Read of urand error, drop back to non urand method. */
185  close(urand_fd);
186  urand_fd = -1;
187  do_reseed_ntlmssp(False, -1);
188  done_reseed_ntlmssp = True;
189  }
190 
191  /*
192  * Generate random numbers in chunks of 64 bytes,
193  * then md4 them & copy to the output buffer.
194  * This way the raw state of the stream is never externally
195  * seen.
196  */
197 
198  p = out;
199  while(len > 0) {
200  int copy_len = len > 16 ? 16 : len;
201 
202  smb_arc4_crypt_ntlmssp(smb_arc4_state, md4_buf, sizeof(md4_buf));
203  mdfour_ntlmssp(tmp_buf, md4_buf, sizeof(md4_buf));
204  memcpy(p, tmp_buf, copy_len);
205  p += copy_len;
206  len -= copy_len;
207  }
208 }
#define True
Definition: genrand.c:54
void mdfour_ntlmssp(unsigned char *out, const unsigned char *in, int n)
Definition: md4.c:125
void smb_arc4_crypt_ntlmssp(unsigned char arc4_state_inout[258], unsigned char *data, size_t len)
Definition: arc4.c:57
#define False
Definition: genrand.c:53

Referenced by LMv2_generate_response_ntlmssp(), ntlmssp_genauth_keyexchg(), ntlmssp_genauth_ntlm2(), and NTLMv2_generate_client_data_ntlmssp().

Here is the caller graph for this function: