Markopy
Utilizing Markov Models for brute forcing attacks
cudaModelMatrix.h
Go to the documentation of this file.
1
/** @file cudaModelMatrix.h
2
* @brief CUDA accelerated extension of Markov::API::ModelMatrix
3
* @authors Ata Hakçıl
4
*
5
* @copydoc Markov::API::CUDA::CUDAModelMatrix
6
*/
7
8
#
include
"MarkovAPI/src/modelMatrix.h"
9
#
include
"cudaDeviceController.h"
10
11
/** @brief Namespace for objects requiring CUDA libraries.
12
*/
13
namespace
Markov
::
API
::
CUDA
{
14
/** @brief Extension of Markov::API::ModelMatrix which is modified to run on GPU devices.
15
*
16
* This implementation only supports Nvidia devices.
17
* @copydoc Markov::API::ModelMatrix
18
*/
19
class
CUDAModelMatrix
:
public
Markov
::
API
::
ModelMatrix
,
public
CUDADeviceController
{
20
public
:
21
22
/** @brief Migrate the class members to the VRAM
23
*
24
* Cannot be used without calling Markov::API::ModelMatrix::ConstructMatrix at least once.
25
* This function will manage the memory allocation and data transfer from CPU RAM to GPU VRAM.
26
*
27
* Newly allocated VRAM pointers are set in the class member variables.
28
*
29
*/
30
__host__
void
MigrateMatrix
();
31
32
/** @brief Flatten migrated matrix from 2d to 1d
33
*
34
*
35
*/
36
__host__
void
FlattenMatrix
();
37
38
/** @brief Random walk on the Matrix-reduced Markov::Model
39
*
40
* TODO
41
*
42
*
43
* @param n - Number of passwords to generate.
44
* @param wordlistFileName - Filename to write to
45
* @param minLen - Minimum password length to generate
46
* @param maxLen - Maximum password length to generate
47
* @param threads - number of OS threads to spawn
48
* @param bFileIO - If false, filename will be ignored and will output to stdout.
49
*
50
*
51
* @code{.cpp}
52
* Markov::API::ModelMatrix mp;
53
* mp.Import("models/finished.mdl");
54
* mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
55
* @endcode
56
*
57
*/
58
__host__
void
FastRandomWalk
(
unsigned
long
int
n
,
const
char
*
wordlistFileName
,
int
minLen
,
int
maxLen
,
bool
bFileIO
,
bool
bInfinite
);
59
60
protected
:
61
62
/** @brief Allocate the output buffer for kernel operation
63
*
64
* TODO
65
*
66
*
67
* @param n - Number of passwords to generate.
68
* @param singleGenMaxLen - maximum string length for a single generation
69
* @param CUDAKernelGridSize - Total number of grid members in CUDA kernel
70
* @param sizePerGrid - Size to allocate per grid member
71
* @return pointer to the allocation on VRAM
72
*
73
*
74
*/
75
__host__
char
*
AllocVRAMOutputBuffer
(
long
int
n
,
long
int
singleGenMaxLen
,
long
int
CUDAKernelGridSize
,
long
int
sizePerGrid
);
76
77
__host__
void
LaunchAsyncKernel
(
int
kernelID
,
int
minLen
,
int
maxLen
);
78
79
__host__
void
prepKernelMemoryChannel
(
int
numberOfStreams
);
80
81
__host__
void
GatherAsyncKernelOutput
(
int
kernelID
,
bool
bFileIO
,
std
::
ofstream
&
wordlist
);
82
83
private
:
84
85
/**
86
@brief VRAM Address pointer of edge matrix (from modelMatrix.h)
87
*/
88
char
*
device_edgeMatrix
;
89
90
/**
91
@brief VRAM Address pointer of value matrix (from modelMatrix.h)
92
*/
93
long
int
*
device_valueMatrix
;
94
95
/**
96
@brief VRAM Address pointer of matrixIndex (from modelMatrix.h)
97
*/
98
char
*
device_matrixIndex
;
99
100
/**
101
@brief VRAM Address pointer of total edge weights (from modelMatrix.h)
102
*/
103
long
int
*
device_totalEdgeWeights
;
104
105
/**
106
@brief RandomWalk results in device
107
*/
108
char
**
device_outputBuffer
;
109
110
/**
111
@brief RandomWalk results in host
112
*/
113
char
**
outputBuffer
;
114
115
/**
116
@brief Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing
117
*/
118
char
*
flatEdgeMatrix
;
119
120
/**
121
@brief Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing
122
*/
123
long
int
*
flatValueMatrix
;
124
125
int
cudaBlocks
;
126
int
cudaThreads
;
127
int
iterationsPerKernelThread
;
128
long
int
totalOutputPerSync
;
129
long
int
totalOutputPerKernel
;
130
int
numberOfPartitions
;
131
int
cudaGridSize
;
132
int
cudaMemPerGrid
;
133
long
int
cudaPerKernelAllocationSize
;
134
135
int
alternatingKernels
;
136
137
unsigned
long
**
device_seeds
;
138
139
cudaStream_t
*
cudastreams
;
140
141
};
142
143
/** @brief CUDA kernel for the FastRandomWalk operation
144
*
145
* Will be initiated by CPU and continued by GPU (__global__ tag)
146
*
147
*
148
* @param n - Number of passwords to generate.
149
* @param minlen - minimum string length for a single generation
150
* @param maxLen - maximum string length for a single generation
151
* @param outputBuffer - VRAM ptr to the output buffer
152
* @param matrixIndex - VRAM ptr to the matrix indices
153
* @param totalEdgeWeights - VRAM ptr to the totalEdgeWeights array
154
* @param valueMatrix - VRAM ptr to the edge weights array
155
* @param edgeMatrix - VRAM ptr to the edge representations array
156
* @param matrixSize - Size of the matrix dimensions
157
* @param memoryPerKernelGrid - Maximum memory usage per kernel grid
158
* @param seed - seed chunk to generate the random from (generated & used by Marsaglia)
159
*
160
*
161
*
162
*/
163
__global__
void
FastRandomWalkCUDAKernel
(
unsigned
long
int
n
,
int
minLen
,
int
maxLen
,
char
*
outputBuffer
,
164
char
*
matrixIndex
,
long
int
*
totalEdgeWeights
,
long
int
*
valueMatrix
,
char
*
edgeMatrix
,
165
int
matrixSize
,
int
memoryPerKernelGrid
,
unsigned
long
*
seed
);
//, unsigned long mex, unsigned long mey, unsigned long mez);
166
167
168
/** @brief srtchr implementation on __device__ space
169
*
170
* Fint the first matching index of a string
171
*
172
*
173
* @param p - string to check
174
* @param c - character to match
175
* @param s_len - maximum string length
176
* @returns pointer to the match
177
*/
178
__device__
char
*
strchr
(
char
*
p
,
char
c
,
int
s_len
);
179
180
};
Markopy
CudaMarkovAPI
src
cudaModelMatrix.h
Generated by
1.9.0