Home > Software > libObfuscate Cryptography


libObfuscate
ISO C / open-source / system independent


Modern 256bit cryptography / scrambling
references and links (*)




How to: Link to your C project


  • go to \libObfuscateRedist\

  • add libObfuscateDef\*.h to your source

  • add libObfuscateDef.h to your source

  • add libObfuscate.h to your source

  • add #include "libObfuscate.h" to your files

  • link using libObfuscate.lib

  • add libObfuscate.dll (no dependencies) to your release

  • add full licensing license.txt to your release


CSPRNG - Based on AES: Seed


Manual Seed : Seed = { Key , CTR } = Hash ( passw , nonce )


CSPRNG_DATA csprng;
BYTE passw [32];
DWORD nonce;
ENUM_HASH hash; // hash = SHA512_HASH / ...

CSPRNG_set_seed( &csprng , hash , passw , nonce );

typedef enum {
SHA512_HASH=0,
GROSTL512_HASH,
KECCAK512_HASH,
SKEIN512_HASH
} ENUM_HASH;

HW AutoSeed : Seed = { Key , CTR } = RaceCondition ( )


CSPRNG_DATA csprng;

anyType pDesc; // progress descriptor

// pCall = NULL && pDesc = NULL → no progress callback
CSPRNG_autoseed( &csprng , pCall , pDesc );

Architecture


csprng1_little.jpg

Enlarge

User interaction callback


// progress callback
void pCall( void *desc , BYTE perc )
{
anyType1 desc' = ( anyType1 ) desc;

// show perc = 0..100 %
...
}

HW AutoSeed


csprng2_little.jpg

Enlarge


CSPRNG - Based on AES: Functions


Functions


BYTE bValue = CSPRNG_get_byte( &csprng );
WORD wValue = CSPRNG_get_word( &csprng );
DWORD dValue = CSPRNG_get_dword( &csprng );
...

BYTE *array; // BYTE array [len]

// fill array with a random permutation of { 0..len }
// simple implementation - slow - keep len little
CSPRNG_array_init( &csprng , len , array );
...

BYTE *buf; // BYTE buf [len]

anyType1 pDesc; // progress descriptor
anyType2 sDesc; // stopTest descriptor

// pCall = NULL && pDesc = NULL → no progress callback
// sCall = NULL && sDesc = NULL → no stopTest callBack
switch( CSPRNG_randomize( &csprng , len , buf , pCall , pDesc , sCall , sDesc ) )
{
case OBFUNC_STOP: // stopped
case OBFUNC_OK: // ok
}

User interaction callbacks


// progress callback
void pCall( void *desc , BYTE perc )
{
anyType1 desc' = ( anyType1 ) desc;

// show perc = 0..100 %
...
}

// stopTest callback
BOOL sCall( void *desc )
{
anyType2 desc' = ( anyType2 ) desc;

// Test? Stop task!
return( TRUE );

// Test ? Continue task!
return( FALSE );
}


Hashing - 512bit: Grostl


Hashing : hash [64] = Grostl ( inBuf [len] )


GROSTL512_DATA grostl;
BYTE hash [64];
BYTE *inBuf; // BYTE inBuf [len]

Grostl512_init( &grostl );
Grostl512_data( &grostl , inBuf , len );
Grostl512_finalize( &grostl , hash );


Hashing - 512bit: Keccak


Hashing : hash [64] = Keccak ( inBuf [len] )


KECCAK512_DATA keccak;
BYTE hash [64];
BYTE *inBuf; // BYTE inBuf [len]

Keccak512_init( &keccak );
Keccak512_data( &keccak , inBuf , len );
Keccak512_finalize( &keccak , hash );


Hashing - 512bit: SHA2


Hashing : hash [64] = SHA2 ( inBuf [len] )


SHA512_DATA sha;
BYTE hash [64];
BYTE *inBuf; // BYTE inBuf [len]

Sha512_init( &sha );
Sha512_data( &sha , inBuf , len );
Sha512_finalize( &sha , hash );


Hashing - 512bit: Skein


Hashing : hash [64] = Skein ( inBuf [len] )


SKEIN512_DATA skein;
BYTE hash [64];
BYTE *inBuf; // BYTE inBuf [len]

Skein512_init( &skein );
Skein512_data( &skein , inBuf , len );
Skein512_finalize( &skein , hash );


Cryptography - 256bit - ECB - 128bit block: AES


Encrypt : outBuf [16] = AES ECB ( inBuf [16] )


RIJNDAEL_STATIC_DATA rijndael;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &rijndael , 0 , sizeof( RIJNDAEL_STATIC_DATA ) );
rijndael.nrounds = Rijndael_set_key_encrypt( rijndael.key , passw , 256 );

Rijndael_encrypt( rijndael.key , rijndael.nrounds , inBuf , outBuf );

Decrypt : outBuf [16] = AES ECB -1( inBuf [16] )


RIJNDAEL_STATIC_DATA rijndael;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &rijndael , 0 , sizeof( RIJNDAEL_STATIC_DATA ) );
rijndael.nrounds = Rijndael_set_key_decrypt( rijndael.key , passw , 256 );

Rijndael_decrypt( rijndael.key , rijndael.nrounds , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Anubis


Encrypt : outBuf [16] = Anubis ECB ( inBuf [16] )


ANUBIS_STATIC_DATA anubis;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &anubis , 0 , sizeof( ANUBIS_STATIC_DATA ) );
Anubis_set_key( &anubis.key , passw );

Anubis_encrypt( &anubis.key , inBuf , outBuf );

Decrypt : outBuf [16] = Anubis ECB -1( inBuf [16] )


ANUBIS_STATIC_DATA anubis;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &anubis , 0 , sizeof( ANUBIS_STATIC_DATA ) );
Anubis_set_key( &anubis.key , passw );

Anubis_decrypt( &anubis.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Camellia


Encrypt : outBuf [16] = Camellia ECB ( inBuf [16] )


CAMELLIA_STATIC_DATA camellia;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &camellia , 0 , sizeof( CAMELLIA_STATIC_DATA ) );
Camellia_set_key( camellia.key , 256 , passw );

Camellia_encrypt( camellia.key , 256 , inBuf , outBuf );

Decrypt : outBuf [16] = Camellia ECB -1( inBuf [16] )


CAMELLIA_STATIC_DATA camellia;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &camellia , 0 , sizeof( CAMELLIA_STATIC_DATA ) );
Camellia_set_key( camellia.key , 256 , passw );

Camellia_decrypt( camellia.key , 256 , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Cast-256


Encrypt : outBuf [16] = Cast-256 ECB ( inBuf [16] )


CAST256_STATIC_DATA cast256;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &cast256 , 0 , sizeof( CAST256_STATIC_DATA ) );
Cast256_set_key( cast256.key , ( DWORD * ) passw , 256 );

Cast256_encrypt( cast256.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = Cast-256 ECB -1( inBuf [16] )


CAST256_STATIC_DATA cast256;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &cast256 , 0 , sizeof( CAST256_STATIC_DATA ) );
Cast256_set_key( cast256.key , ( DWORD * ) passw , 256 );

Cast256_decrypt( cast256.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Clefia


Encrypt : outBuf [16] = Clefia ECB ( inBuf [16] )


CLEFIA_STATIC_DATA clefia;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &clefia , 0 , sizeof( CLEFIA_STATIC_DATA ) );
Clefia_set_key( &clefia.key , passw , 256 );

Clefia_encrypt( &clefia.key , inBuf , outBuf );

Decrypt : outBuf [16] = Clefia ECB -1( inBuf [16] )


CLEFIA_STATIC_DATA clefia;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &clefia , 0 , sizeof( CLEFIA_STATIC_DATA ) );
Clefia_set_key( &clefia.key , passw , 256 );

Clefia_decrypt( &clefia.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: FROG


Encrypt : outBuf [16] = FROG ECB ( inBuf [16] )


FROG_STATIC_DATA frog;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &frog , 0 , sizeof( FROG_STATIC_DATA ) );
Frog_set_key( &frog.key , ( DWORD * ) passw , 256 );

Frog_encrypt( &frog.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = FROG ECB -1( inBuf [16] )


FROG_STATIC_DATA frog;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &frog , 0 , sizeof( FROG_STATIC_DATA ) );
Frog_set_key( &frog.key , ( DWORD * ) passw , 256 );

Frog_decrypt( &frog.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Hierocrypt3


Encrypt : outBuf [16] = Hierocrypt3 ECB ( inBuf [16] )


HIEROCRYPT3_STATIC_DATA hierocrypt3;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &hierocrypt3 , 0 , sizeof( HIEROCRYPT3_STATIC_DATA ) );
Hierocrypt3_set_key( &hierocrypt3.key , passw );

Hierocrypt3_encrypt( &hierocrypt3.key , inBuf , outBuf );

Decrypt : outBuf [16] = Hierocrypt3 ECB -1( inBuf [16] )


HIEROCRYPT3_STATIC_DATA hierocrypt3;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &hierocrypt3 , 0 , sizeof( HIEROCRYPT3_STATIC_DATA ) );
Hierocrypt3_set_key( &hierocrypt3.key , passw );

Hierocrypt3_decrypt( &hierocrypt3.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Idea-NXT


Encrypt : outBuf [16] = Idea-NXT ECB ( inBuf [16] )


IDEANXT128_STATIC_DATA ideanxt;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &ideanxt , 0 , sizeof( IDEANXT128_STATIC_DATA ) );
Ideanxt128_set_key( &ideanxt.key , passw , 256 );

Ideanxt128_encrypt( &ideanxt.key , inBuf , outBuf );

Decrypt : outBuf [16] = Idea-NXT ECB -1( inBuf [16] )


IDEANXT128_STATIC_DATA ideanxt;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &ideanxt , 0 , sizeof( IDEANXT128_STATIC_DATA ) );
Ideanxt128_set_key( &ideanxt.key , passw , 256 );

Ideanxt128_decrypt( &ideanxt.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: MARS


Encrypt : outBuf [16] = MARS ECB ( inBuf [16] )


MARS_STATIC_DATA mars;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &mars , 0 , sizeof( MARS_STATIC_DATA ) );
mars.vk[0]=0x09d0c479;
mars.vk[1]=0x28c8ffe0;
mars.vk[2]=0x84aa6c39;
mars.vk[3]=0x9dad7287;
mars.vk[4]=0x7dff9be3;
mars.vk[5]=0xd4268361;
mars.vk[6]=0xc96da1d4;
Mars_set_key( mars.key , mars.vk , ( DWORD * ) passw , 256 );

Mars_encrypt( mars.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = MARS ECB -1( inBuf [16] )


MARS_STATIC_DATA mars;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &mars , 0 , sizeof( MARS_STATIC_DATA ) );
mars.vk[0]=0x09d0c479;
mars.vk[1]=0x28c8ffe0;
mars.vk[2]=0x84aa6c39;
mars.vk[3]=0x9dad7287;
mars.vk[4]=0x7dff9be3;
mars.vk[5]=0xd4268361;
mars.vk[6]=0xc96da1d4;
Mars_set_key( mars.key , mars.vk , ( DWORD * ) passw , 256 );

Mars_decrypt( mars.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: RC6


Encrypt : outBuf [16] = RC6 ECB ( inBuf [16] )


RC6_STATIC_DATA rc6;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &rc6 , 0 , sizeof( RC6_STATIC_DATA ) );
Rc6_set_key( rc6.key , ( DWORD * ) passw , 256 );

Rc6_encrypt( rc6.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = RC6 ECB -1( inBuf [16] )


RC6_STATIC_DATA rc6;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &rc6 , 0 , sizeof( RC6_STATIC_DATA ) );
Rc6_set_key( rc6.key , ( DWORD * ) passw , 256 );

Rc6_decrypt( rc6.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Safer+


Encrypt : outBuf [16] = Safer+ ECB ( inBuf [16] )


SAFERP_STATIC_DATA saferp;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &saferp , 0 , sizeof( SAFERP_STATIC_DATA ) );
Saferp_set_key( &saferp.key , ( DWORD * ) passw , 256 );

Saferp_encrypt( &saferp.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = Safer+ ECB -1( inBuf [16] )


SAFERP_STATIC_DATA saferp;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &saferp , 0 , sizeof( SAFERP_STATIC_DATA ) );
Saferp_set_key( &saferp.key , ( DWORD * ) passw , 256 );

Saferp_decrypt( &saferp.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: SC2000


Encrypt : outBuf [16] = SC2000 ECB ( inBuf [16] )


SC2000_STATIC_DATA sc2000;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &sc2000 , 0 , sizeof( SC2000_STATIC_DATA ) );
Sc2000_set_key( sc2000.key , ( DWORD * ) passw );

Sc2000_encrypt( sc2000.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = SC2000 ECB -1( inBuf [16] )


SC2000_STATIC_DATA sc2000;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &sc2000 , 0 , sizeof( SC2000_STATIC_DATA ) );
Sc2000_set_key( sc2000.key , ( DWORD * ) passw );

Sc2000_decrypt( sc2000.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Serpent


Encrypt : outBuf [16] = Serpent ECB ( inBuf [16] )


SERPENT_STATIC_DATA serpent;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &serpent , 0 , sizeof( SERPENT_STATIC_DATA ) );
Serpent_set_key( serpent.key , ( DWORD * ) passw , 256 );

Serpent_encrypt( serpent.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = Serpent ECB -1( inBuf [16] )


SERPENT_STATIC_DATA serpent;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &serpent , 0 , sizeof( SERPENT_STATIC_DATA ) );
Serpent_set_key( serpent.key , ( DWORD * ) passw , 256 );

Serpent_decrypt( serpent.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Speed


Encrypt : outBuf [16] = Speed ECB ( inBuf [16] )


SPEED_STATIC_DATA speed;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &speed , 0 , sizeof( SPEED_STATIC_DATA ) );
Speed_set_key( speed.key , passw );

Speed_encrypt( speed.key , inBuf , outBuf );

Decrypt : outBuf [16] = Speed ECB -1( inBuf [16] )


SPEED_STATIC_DATA speed;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &speed , 0 , sizeof( SPEED_STATIC_DATA ) );
Speed_set_key( speed.key , passw );

Speed_decrypt( speed.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Twofish


Encrypt : outBuf [16] = Twofish ECB ( inBuf [16] )


TWOFISH_STATIC_DATA twofish;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &twofish , 0 , sizeof( TWOFISH_STATIC_DATA ) );
Twofish_set_key( &twofish.key , ( DWORD * ) passw , 256 );

Twofish_encrypt( &twofish.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );

Decrypt : outBuf [16] = Twofish ECB -1( inBuf [16] )


TWOFISH_STATIC_DATA twofish;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &twofish , 0 , sizeof( TWOFISH_STATIC_DATA ) );
Twofish_set_key( &twofish.key , ( DWORD * ) passw , 256 );

Twofish_decrypt( &twofish.key , ( DWORD * ) inBuf , ( DWORD * ) outBuf );


Cryptography - 256bit - ECB - 128bit block: Unicorn-A


Encrypt : outBuf [16] = Unicorn-A ECB ( inBuf [16] )


UNICORNA_STATIC_DATA unicorn;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &unicorn , 0 , sizeof( UNICORNA_STATIC_DATA ) );
Unicorn_set_key( unicorn.key , passw );

Unicorn_encrypt( unicorn.key , inBuf , outBuf );

Decrypt : outBuf [16] = Unicorn-A ECB -1( inBuf [16] )


UNICORNA_STATIC_DATA unicorn;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];

memset( &unicorn , 0 , sizeof( UNICORNA_STATIC_DATA ) );
Unicorn_set_key( unicorn.key , passw );

Unicorn_decrypt( unicorn.key , inBuf , outBuf );


Cryptography - 256bit - ECB - 128bit block: Wrapper


Encrypt : outBuf [16] = Cipher ECB ( inBuf [16] )


MULTI_STATIC_DATA multi;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];
ENUM_ALG cipher; // cipher = ANUBIS_ALG / ...

Multi_single_setkey( &multi , cipher , passw );

Multi_ECB_single_encrypt( &multi , cipher , inBuf , outBuf );


Decrypt : outBuf [16] = Cipher ECB -1( inBuf [16] )


MULTI_STATIC_DATA multi;
BYTE passw [32];
BYTE inBuf [16] , outBuf [16];
ENUM_ALG cipher; // cipher = ANUBIS_ALG / ...

Multi_single_setkey( &multi , cipher , passw );

Multi_ECB_single_decrypt( &multi , cipher , inBuf , outBuf );

typedef enum {
ANUBIS_ALG=0,
CAMELLIA_ALG,
CAST256_ALG,
CLEFIA_ALG,
FROG_ALG,
HIEROCRYPT3_ALG,
IDEANXT128_ALG,
MARS_ALG,
RC6_ALG,
RIJNDAEL_ALG,
SAFERP_ALG,
SC2000_ALG,
SERPENT_ALG,
SPEED_ALG,
TWOFISH_ALG,
UNICORNA_ALG
} ENUM_ALG;


Multi-cryptography - 256 + 256bit - CBC - Segment


Encrypt : buf ' [k * 16] = Multi-cipher CBC ( buf [k * 16] )


MULTI_DATA multi;
BYTE iv [16 * 16];
BYTE passw1 [32] , passw2 [32];
DWORD nonce;
BYTE *buf; // BYTE buf [len = k * 16]

anyType1 pDesc; // progress descriptor
anyType2 sDesc; // stopTest descriptor

Multi_setkey( &multi , iv , passw1 , passw2 , nonce );

// pCall = NULL && pDesc = NULL → no progress callback
// sCall = NULL && sDesc = NULL → no stopTest callBack
switch( Multi_CBC_encrypt( &multi , len , buf , pCall , pDesc , sCall , sDesc ) )
{
case OBFUNC_STOP: // stopped
case OBFUNC_OK: // ok
}

Architecture


multi_cr1_little.jpg

Enlarge

Decrypt : buf [k * 16] = Multi-cipher CBC -1( buf ' [k * 16] )


MULTI_DATA multi;
BYTE iv [16 * 16];
BYTE passw1 [32] , passw2 [32];
DWORD nonce;
BYTE *buf; // BYTE buf [len = k * 16]

anyType1 pDesc; // progress descriptor
anyType2 sDesc; // stopTest descriptor

Multi_setkey( &multi , iv , passw1 , passw2 , nonce );

// pCall = NULL && pDesc = NULL → no progress callback
// sCall = NULL && sDesc = NULL → no stopTest callBack
switch( Multi_CBC_decrypt( &multi , len , buf , pCall , pDesc , sCall , sDesc ) )
{
case OBFUNC_STOP: // stopped
case OBFUNC_OK: // ok
}

Cipher selection


multi_cr2_little.jpg

Enlarge

User interaction callbacks


// progress callback
void pCall( void *desc , BYTE perc )
{
anyType1 desc' = ( anyType1 ) desc;

// show perc = 0..100 %
...
}

// stopTest callback
BOOL sCall( void *desc )
{
anyType2 desc' = ( anyType2 ) desc;

// Test? Stop task!
return( TRUE );

// Test ? Continue task!
return( FALSE );
}

Example


multi_cr3_little.jpg

Enlarge