Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Trying to get a cryptography shader working

  1. #1
    Newbie Newbie
    Join Date
    Dec 2013

    Trying to get a cryptography shader working

    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
    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

    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)

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    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).

  3. #3
    Newbie Newbie
    Join Date
    Dec 2013
    most current Shader :

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

    and most current doDataEncrypt() :
    Last edited by Dark Photon; 12-13-2013 at 07:06 PM. Reason: update to pastebin code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts