Markopy
Utilizing Markov Models for brute forcing attacks
Markov::API::CUDA Namespace Reference

Namespace for objects requiring CUDA libraries. More...

Namespaces

 Random
 Namespace for Random engines operable under device space.
 

Classes

class  CUDADeviceController
 Controller class for CUDA device. More...
 
class  CUDAModelMatrix
 Extension of Markov::API::ModelMatrix which is modified to run on GPU devices. More...
 

Functions

__global__ void FastRandomWalkCUDAKernel (unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
 CUDA kernel for the FastRandomWalk operation. More...
 
__device__ char * strchr (char *p, char c, int s_len)
 srtchr implementation on device space More...
 

Detailed Description

Namespace for objects requiring CUDA libraries.

Function Documentation

◆ FastRandomWalkCUDAKernel()

__global__ void Markov::API::CUDA::FastRandomWalkCUDAKernel ( unsigned long int  n,
int  minLen,
int  maxLen,
char *  outputBuffer,
char *  matrixIndex,
long int *  totalEdgeWeights,
long int *  valueMatrix,
char *  edgeMatrix,
int  matrixSize,
int  memoryPerKernelGrid,
unsigned long *  seed 
)

CUDA kernel for the FastRandomWalk operation.

Will be initiated by CPU and continued by GPU (global tag)

Parameters
n- Number of passwords to generate.
minlen- minimum string length for a single generation
maxLen- maximum string length for a single generation
outputBuffer- VRAM ptr to the output buffer
matrixIndex- VRAM ptr to the matrix indices
totalEdgeWeights- VRAM ptr to the totalEdgeWeights array
valueMatrix- VRAM ptr to the edge weights array
edgeMatrix- VRAM ptr to the edge representations array
matrixSize- Size of the matrix dimensions
memoryPerKernelGrid- Maximum memory usage per kernel grid
seed- seed chunk to generate the random from (generated & used by Marsaglia)

Definition at line 194 of file cudaModelMatrix.cu.

195  {
196 
197  int kernelWorkerIndex = threadIdx.x + blockIdx.x * blockDim.x;
198 
199  if(n==0) return;
200 
201  char* e;
202  int index = 0;
203  char next;
204  int len=0;
205  long int selection;
206  char cur;
207  long int bufferctr = 0;
208  unsigned long int *x,*y,*z,t;
209  char* res = &outputBuffer[kernelWorkerIndex*memoryPerKernelGrid];
210  x=&seed[kernelWorkerIndex*3];
211  y=&seed[kernelWorkerIndex*3+1];
212  z=&seed[kernelWorkerIndex*3+2];
213  for (int i = 0; i < n; i++) {
214  cur=199;
215  len=0;
216  while (true) {
217  e = strchr(matrixIndex, cur, matrixSize);
218  index = e - matrixIndex;
219  /*selection = Markov::API::CUDA::Random::devrandom(
220  seed[kernelWorkerIndex*3],
221  seed[kernelWorkerIndex*3+1],
222  seed[kernelWorkerIndex*3+2]) % totalEdgeWeights[index];*/
223  *x ^= *x << 16;
224  *x ^= *x >> 5;
225  *x ^= *x << 1;
226 
227  t = *x;
228  *x = *y;
229  *y = *z;
230  *z = t ^ *x ^ *y;
231  selection = *z % totalEdgeWeights[index];
232  for(int j=0;j<matrixSize-1;j++){
233  selection -= valueMatrix[index*matrixSize + j];
234  if (selection < 0){
235  next = edgeMatrix[index*sizeof(char)*matrixSize + j];
236  break;
237  }
238  }
239 
240  if (len >= maxLen) break;
241  else if ((next < 0) && (len < minLen)) continue;
242  else if (next < 0) break;
243  cur = next;
244  res[bufferctr + len++] = cur;
245  }
246  res[bufferctr + len++] = '\n';
247  bufferctr+=len;
248  }
249  res[bufferctr] = '\0';
250  }
__device__ char * strchr(char *p, char c, int s_len)
srtchr implementation on device space

◆ strchr()

__device__ char * Markov::API::CUDA::strchr ( char *  p,
char  c,
int  s_len 
)

srtchr implementation on device space

Fint the first matching index of a string

Parameters
p- string to check
c- character to match
s_len- maximum string length
Returns
pointer to the match

Definition at line 252 of file cudaModelMatrix.cu.

252  {
253  for (;; ++p, s_len--) {
254  if (*p == c)
255  return((char *)p);
256  if (!*p)
257  return((char *)NULL);
258  }
259  }