PDA

View Full Version : Trying to get a cryptography shader working



bin1101
12-13-2013, 01:24 PM
I'm trying to use openGL 4.3 and glsl (not clsl) to make a simple compute shader to perform bitwise operations on strings, with the eventual goal of making a block cipher. For now I'd be happy XORing two strings with each other.

It is not going well, I'm fairly sure I can get the buffer to bind, but am unsure how to get glsl to actually manipulate the data. All the examples I've found online assume a vertex or pixel, so working in one dimensional space has proven oddly more difficult. My own efforts have not been able to create even a small change to the data, leading me to suspect I have missed something very basic.

My Shader Code


#version 430 core
#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_storage_buffer_object: enable

//this is the copy saved at above-level


layout( std430, binding=4) buffer bufferKey {
uint KeyString[]; // array of structures
//may need to change to uint for the atomics
};
layout( std430, binding=5) buffer bufferTXT {
uint BufString[]; // array of structures
//may need to change to uint for the atomics
};



/*
//Special Preset variables in the Compute Shader
in uvec3 gl_NumWorkGroups; // same numbers as in the glDispatchCompute call
const uvec3 gl_WorkGroupSize; // same numbers as in the layout local_size_*
in uvec3 gl_WorkGroupID; // which workgroup this thread is in
in uvec3 gl_LocalInvocationID; // where this thread is in the current workgroup
in uvec3 gl_GlobalInvocationID; //where this thread is in all the workitems
in uint gl_LocalInvocationIdenx; //1d representation of the gl_LocalInvocationID (Used for indexing into a shared array)
*/

//uniform GLchar* inputBuffer;// damn TCHAR Conversion
//I think we forced unicode, or wide chars

uniform uint keyByteLength;
layout (local_size_x = 1) in;

uint cryptoXORop(uint left_in, uint right_in){

//atomicXOR(left_in, right_in);
//return left_in;
uint result = left_in ^ right_in;
return result;

//we can still do the null terminator check with some clever modulo
}


void main(void)
{

uint gid = gl_LocalInvocationIndex;

// test, xor first value

uint result = cryptoXORop(BufString[gid], KeyString[gid]);

//BufString[gid] = result+1;
//BufString[ 5 ] = result+2;

BufString[gid+1] += 1;
BufString[ 5 ] += 2;

atomicAdd(BufString[gid], 2);
atomicAdd(BufString[ 5 ], 2);

// keyByteLength--; //cannot modifie uniforms

/*
for( int i = 0; i > -1; i++){
//intended to be a fatal memory error for the gpu
BufString[i] = 56;
//does in fact force the gpu to crash
}
*/


//seems only the CPU needs this
//glMemoryBarrier(GL_ALL_BARRIER_BITS); //keep a wait point for all workgroups
//GroupMemoryBarrier();
}

I would also include a pastebin link of the larger function the shader is called from, but as a new use I cannot link to pastebin. (It's kinda huge to post in an opening post)

Dark Photon
12-13-2013, 02:47 PM
Just put the pastebin url in a message -- omit the http://, add spaces, or whatever you need to do to get it posted. We'll urlify it (you're obviously not a spambot, which is the point behind the no-links for new users restriction).

bin1101
12-13-2013, 03:03 PM
most current Shader : http://pastebin.com/hWp3V0VS

There you go. And actually I've cleaned up the shader some to for what I really want

and most current doDataEncrypt() : http://pastebin.com/jX16PX24