From 61b13629ae44b9ae98a4396ebe23fa65fba5150a Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Sun, 30 Dec 2012 18:41:32 +0600 Subject: [PATCH 1/9] new mcryptography ferite module --- mcrypto_ferite_module/farm.yard | 28 ++++++ mcrypto_ferite_module/mcrypt.fec | 144 ++++++++++++++++++++++++++++++ mcrypto_ferite_module/mcrypt.fec~ | 142 +++++++++++++++++++++++++++++ mcrypto_ferite_module/mcrypt.feh | 46 ++++++++++ mcrypto_ferite_module/mcrypt.feh~ | 44 +++++++++ mcrypto_ferite_module/test.fe | 12 +++ 6 files changed, 416 insertions(+) create mode 100644 mcrypto_ferite_module/farm.yard create mode 100644 mcrypto_ferite_module/mcrypt.fec create mode 100644 mcrypto_ferite_module/mcrypt.fec~ create mode 100644 mcrypto_ferite_module/mcrypt.feh create mode 100644 mcrypto_ferite_module/mcrypt.feh~ create mode 100644 mcrypto_ferite_module/test.fe diff --git a/mcrypto_ferite_module/farm.yard b/mcrypto_ferite_module/farm.yard new file mode 100644 index 0000000..95f34fa --- /dev/null +++ b/mcrypto_ferite_module/farm.yard @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mcrypto_ferite_module/mcrypt.fec b/mcrypto_ferite_module/mcrypt.fec new file mode 100644 index 0000000..1f74c48 --- /dev/null +++ b/mcrypto_ferite_module/mcrypt.fec @@ -0,0 +1,144 @@ +// developed by ashish ghosh. email:ashish_ghosh@cention.se + +uses "mcrypt.lib"; + +module-header { + +#include +#include +#include +#include + +} + + +namespace mcrypt{ + +class mcrypt{ + +native function encode( string string1) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + int cryptsize; + char *target; + char* result; + + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + + if (i < 0) { + // mcrypt_perror( i ); + // exit(1); + FE_RETURN_FALSE; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + cryptsize = ( ( string1->length + blocksize - 1 ) / blocksize ) * blocksize; + target = calloc( 1, cryptsize ); + + memcpy( target, string1->data, string1->length ); + + if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { + fprintf( stderr, "Code failing" ); + } + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + FE_RETURN_CSTR( target, FE_TRUE ); + +} + + + +native function decode( string string2 ) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + char *target; + char *block_buffer; + int decryptlength; + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + if ( i < 0 ) { + // mcrypt_perror( i ); + //exit(1); + FE_RETURN_FALSE ; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + block_buffer = calloc( 1, blocksize ); + decryptlength = (string2->length + blocksize - 1) / blocksize * blocksize; + target = calloc( 1, decryptlength ); + + memcpy(target, string2->data , string2->length); + mdecrypt_generic( td, target, decryptlength ); + + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + free(block_buffer); + FE_RETURN_CSTR( target, FE_TRUE ); + +} + +} + +} \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt.fec~ b/mcrypto_ferite_module/mcrypt.fec~ new file mode 100644 index 0000000..bf1cd72 --- /dev/null +++ b/mcrypto_ferite_module/mcrypt.fec~ @@ -0,0 +1,142 @@ +uses "mcrypt.lib"; + +module-header { + +#include +#include +#include +#include + +} + + +namespace mcrypt{ + +class mcrypt{ + +native function encode( string string1) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + int cryptsize; + char *target; + char* result; + + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + + if (i < 0) { + // mcrypt_perror( i ); + // exit(1); + FE_RETURN_FALSE; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + cryptsize = ( ( string1->length + blocksize - 1 ) / blocksize ) * blocksize; + target = calloc( 1, cryptsize ); + + memcpy( target, string1->data, string1->length ); + + if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { + fprintf( stderr, "Code failing" ); + } + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + FE_RETURN_CSTR( target, FE_TRUE ); + +} + + + +native function decode( string string2 ) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + char *target; + char *block_buffer; + int decryptlength; + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + if ( i < 0 ) { + // mcrypt_perror( i ); + //exit(1); + FE_RETURN_FALSE ; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + block_buffer = calloc( 1, blocksize ); + decryptlength = (string2->length + blocksize - 1) / blocksize * blocksize; + target = calloc( 1, decryptlength ); + + memcpy(target, string2->data , string2->length); + mdecrypt_generic( td, target, decryptlength ); + + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + free(block_buffer); + FE_RETURN_CSTR( target, FE_TRUE ); + +} + +} + +} \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt.feh b/mcrypto_ferite_module/mcrypt.feh new file mode 100644 index 0000000..4e23c03 --- /dev/null +++ b/mcrypto_ferite_module/mcrypt.feh @@ -0,0 +1,46 @@ +// developed by ashish ghosh. email:ashish_ghosh@cention.se + +uses "mcrypt.fec"; +uses "string","number","console","array"; +uses "MHash.fec"; + +namespace mCrypt{ + + + function encryptMcryptography(string password) { + + object mcryptObj = new mcrypt.mcrypt(); + string mcryptPassword; + string encodedPassword; + + monitor { + mcryptPassword = mcryptObj.encode(password); + encodedPassword = String.base64encode(mcryptPassword); + return encodedPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } + + + function decryptMcryptography(string password) { + + object mcryptObj = new mcrypt.mcrypt(); + string decodedPassword; + string mcryptPassword; + + monitor { + decodedPassword = String.base64decode(password); + mcryptPassword = mcryptObj.decode(decodedPassword); + return mcryptPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } + + + + +} \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt.feh~ b/mcrypto_ferite_module/mcrypt.feh~ new file mode 100644 index 0000000..a6ce99c --- /dev/null +++ b/mcrypto_ferite_module/mcrypt.feh~ @@ -0,0 +1,44 @@ +uses "mcrypt.fec"; +uses "string","number","console","array"; +uses "MHash.fec"; + +namespace mCrypt{ + + + function encryptMcryptography(string password) { + + object mcryptObj = new mcrypt.mcrypt(); + string mcryptPassword; + string encodedPassword; + + monitor { + mcryptPassword = mcryptObj.encode(password); + encodedPassword = String.base64encode(mcryptPassword); + return encodedPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } + + + function decryptMcryptography(string password) { + + object mcryptObj = new mcrypt.mcrypt(); + string decodedPassword; + string mcryptPassword; + + monitor { + decodedPassword = String.base64decode(password); + mcryptPassword = mcryptObj.decode(decodedPassword); + return mcryptPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } + + + + +} \ No newline at end of file diff --git a/mcrypto_ferite_module/test.fe b/mcrypto_ferite_module/test.fe new file mode 100644 index 0000000..fd49e84 --- /dev/null +++ b/mcrypto_ferite_module/test.fe @@ -0,0 +1,12 @@ + uses "mcrypt.feh"; + + + string password = "ashish ghosh"; + string encryptedPassword; + string decryptedPassword; + encryptedPassword = mCrypt.encryptMcryptography(password); + Console.println("encrypt:" + "${encryptedPassword}"); + decryptedPassword = mCrypt.decryptMcryptography(encryptedPassword); + Console.println("decrypt:" + "${decryptedPassword}"); + + From 4351033192fbbf784d762fc749eab0b6b68c5c8b Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Sun, 30 Dec 2012 18:54:21 +0600 Subject: [PATCH 2/9] edit farm --- mcrypto_ferite_module/farm.yard | 1 + 1 file changed, 1 insertion(+) diff --git a/mcrypto_ferite_module/farm.yard b/mcrypto_ferite_module/farm.yard index 95f34fa..60ff823 100644 --- a/mcrypto_ferite_module/farm.yard +++ b/mcrypto_ferite_module/farm.yard @@ -21,6 +21,7 @@ + From 4936ad3e310c3757e792f0fe09b0745aabbfcacf Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Mon, 31 Dec 2012 10:56:54 +0600 Subject: [PATCH 3/9] some modifies --- mcrypto_ferite_module/farm.yard | 7 +- mcrypto_ferite_module/mcrypt.feh | 2 +- mcrypto_ferite_module/mcrypt_module.fec | 144 ++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 mcrypto_ferite_module/mcrypt_module.fec diff --git a/mcrypto_ferite_module/farm.yard b/mcrypto_ferite_module/farm.yard index 60ff823..1b3553f 100644 --- a/mcrypto_ferite_module/farm.yard +++ b/mcrypto_ferite_module/farm.yard @@ -6,7 +6,10 @@ - + + + + @@ -20,7 +23,7 @@ - + diff --git a/mcrypto_ferite_module/mcrypt.feh b/mcrypto_ferite_module/mcrypt.feh index 4e23c03..36a6083 100644 --- a/mcrypto_ferite_module/mcrypt.feh +++ b/mcrypto_ferite_module/mcrypt.feh @@ -1,6 +1,6 @@ // developed by ashish ghosh. email:ashish_ghosh@cention.se -uses "mcrypt.fec"; +uses "mcrypt_module.fec"; uses "string","number","console","array"; uses "MHash.fec"; diff --git a/mcrypto_ferite_module/mcrypt_module.fec b/mcrypto_ferite_module/mcrypt_module.fec new file mode 100644 index 0000000..5019913 --- /dev/null +++ b/mcrypto_ferite_module/mcrypt_module.fec @@ -0,0 +1,144 @@ +// developed by ashish ghosh. email:ashish_ghosh@cention.se + +uses "mcrypt.lib"; + +module-header { + +#include +#include +#include +#include + +} + + +namespace mcrypt{ + +class mcrypt{ + +native function encode( string password) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + int cryptsize; + char *target; + char* result; + + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + + if (i < 0) { + // mcrypt_perror( i ); + // exit(1); + FE_RETURN_FALSE; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + cryptsize = ( ( password->length + blocksize - 1 ) / blocksize ) * blocksize; + target = calloc( 1, cryptsize ); + + memcpy( target, password->data, password->length ); + + if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { + fprintf( stderr, "Code failing" ); + } + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + FE_RETURN_CSTR( target, FE_TRUE ); + +} + + + +native function decode( string password ) : string { + + int i; + char *IV; + int iv_size; + int keysize; + char *key; + int blocksize; + char *target; + char *block_buffer; + int decryptlength; + + MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); + + if ( td == MCRYPT_FAILED ) { + FE_RETURN_FALSE ; + } + + if ( mcrypt_enc_self_test( td ) != 0 ) { + FE_RETURN_FALSE ; + } + + iv_size = mcrypt_enc_get_iv_size( td ); + + if ( iv_size != 0 ) { + IV = calloc( 1, iv_size ); + for ( i = 0; i < iv_size; i++ ) { + IV[ i ] = rand(); + } + } + + keysize = mcrypt_enc_get_key_size( td ); + key = calloc( 1, keysize ); + memcpy(key, "12345678", keysize); + + i = mcrypt_generic_init ( td, key, keysize, IV ); + if ( i < 0 ) { + // mcrypt_perror( i ); + //exit(1); + FE_RETURN_FALSE ; + } + + + blocksize = mcrypt_enc_get_block_size( td ); + block_buffer = calloc( 1, blocksize ); + decryptlength = (password->length + blocksize - 1) / blocksize * blocksize; + target = calloc( 1, decryptlength ); + + memcpy(target, password->data , password->length); + mdecrypt_generic( td, target, decryptlength ); + + + mcrypt_generic_deinit( td ); + mcrypt_module_close( td ); + + free(block_buffer); + FE_RETURN_CSTR( target, FE_TRUE ); + +} + +} + +} \ No newline at end of file From 44ff983798e4d7020ad00f1a0f1043349c4fc7fb Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Mon, 31 Dec 2012 10:57:53 +0600 Subject: [PATCH 4/9] delete garbage file --- mcrypto_ferite_module/mcrypt.fec | 144 ------------------------------ mcrypto_ferite_module/mcrypt.fec~ | 142 ----------------------------- mcrypto_ferite_module/mcrypt.feh~ | 44 --------- 3 files changed, 330 deletions(-) delete mode 100644 mcrypto_ferite_module/mcrypt.fec delete mode 100644 mcrypto_ferite_module/mcrypt.fec~ delete mode 100644 mcrypto_ferite_module/mcrypt.feh~ diff --git a/mcrypto_ferite_module/mcrypt.fec b/mcrypto_ferite_module/mcrypt.fec deleted file mode 100644 index 1f74c48..0000000 --- a/mcrypto_ferite_module/mcrypt.fec +++ /dev/null @@ -1,144 +0,0 @@ -// developed by ashish ghosh. email:ashish_ghosh@cention.se - -uses "mcrypt.lib"; - -module-header { - -#include -#include -#include -#include - -} - - -namespace mcrypt{ - -class mcrypt{ - -native function encode( string string1) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - int cryptsize; - char *target; - char* result; - - - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; - } - - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } - - iv_size = mcrypt_enc_get_iv_size( td ); - - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); - } - } - - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); - - i = mcrypt_generic_init ( td, key, keysize, IV ); - - if (i < 0) { - // mcrypt_perror( i ); - // exit(1); - FE_RETURN_FALSE; - } - - - blocksize = mcrypt_enc_get_block_size( td ); - cryptsize = ( ( string1->length + blocksize - 1 ) / blocksize ) * blocksize; - target = calloc( 1, cryptsize ); - - memcpy( target, string1->data, string1->length ); - - if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { - fprintf( stderr, "Code failing" ); - } - - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - - FE_RETURN_CSTR( target, FE_TRUE ); - -} - - - -native function decode( string string2 ) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - char *target; - char *block_buffer; - int decryptlength; - - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; - } - - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } - - iv_size = mcrypt_enc_get_iv_size( td ); - - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); - } - } - - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); - - i = mcrypt_generic_init ( td, key, keysize, IV ); - if ( i < 0 ) { - // mcrypt_perror( i ); - //exit(1); - FE_RETURN_FALSE ; - } - - - blocksize = mcrypt_enc_get_block_size( td ); - block_buffer = calloc( 1, blocksize ); - decryptlength = (string2->length + blocksize - 1) / blocksize * blocksize; - target = calloc( 1, decryptlength ); - - memcpy(target, string2->data , string2->length); - mdecrypt_generic( td, target, decryptlength ); - - - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - - free(block_buffer); - FE_RETURN_CSTR( target, FE_TRUE ); - -} - -} - -} \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt.fec~ b/mcrypto_ferite_module/mcrypt.fec~ deleted file mode 100644 index bf1cd72..0000000 --- a/mcrypto_ferite_module/mcrypt.fec~ +++ /dev/null @@ -1,142 +0,0 @@ -uses "mcrypt.lib"; - -module-header { - -#include -#include -#include -#include - -} - - -namespace mcrypt{ - -class mcrypt{ - -native function encode( string string1) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - int cryptsize; - char *target; - char* result; - - - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; - } - - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } - - iv_size = mcrypt_enc_get_iv_size( td ); - - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); - } - } - - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); - - i = mcrypt_generic_init ( td, key, keysize, IV ); - - if (i < 0) { - // mcrypt_perror( i ); - // exit(1); - FE_RETURN_FALSE; - } - - - blocksize = mcrypt_enc_get_block_size( td ); - cryptsize = ( ( string1->length + blocksize - 1 ) / blocksize ) * blocksize; - target = calloc( 1, cryptsize ); - - memcpy( target, string1->data, string1->length ); - - if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { - fprintf( stderr, "Code failing" ); - } - - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - - FE_RETURN_CSTR( target, FE_TRUE ); - -} - - - -native function decode( string string2 ) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - char *target; - char *block_buffer; - int decryptlength; - - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; - } - - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } - - iv_size = mcrypt_enc_get_iv_size( td ); - - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); - } - } - - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); - - i = mcrypt_generic_init ( td, key, keysize, IV ); - if ( i < 0 ) { - // mcrypt_perror( i ); - //exit(1); - FE_RETURN_FALSE ; - } - - - blocksize = mcrypt_enc_get_block_size( td ); - block_buffer = calloc( 1, blocksize ); - decryptlength = (string2->length + blocksize - 1) / blocksize * blocksize; - target = calloc( 1, decryptlength ); - - memcpy(target, string2->data , string2->length); - mdecrypt_generic( td, target, decryptlength ); - - - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - - free(block_buffer); - FE_RETURN_CSTR( target, FE_TRUE ); - -} - -} - -} \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt.feh~ b/mcrypto_ferite_module/mcrypt.feh~ deleted file mode 100644 index a6ce99c..0000000 --- a/mcrypto_ferite_module/mcrypt.feh~ +++ /dev/null @@ -1,44 +0,0 @@ -uses "mcrypt.fec"; -uses "string","number","console","array"; -uses "MHash.fec"; - -namespace mCrypt{ - - - function encryptMcryptography(string password) { - - object mcryptObj = new mcrypt.mcrypt(); - string mcryptPassword; - string encodedPassword; - - monitor { - mcryptPassword = mcryptObj.encode(password); - encodedPassword = String.base64encode(mcryptPassword); - return encodedPassword; - }handle{ - return "!!! Error to connect in mcrypt"; - } - - } - - - function decryptMcryptography(string password) { - - object mcryptObj = new mcrypt.mcrypt(); - string decodedPassword; - string mcryptPassword; - - monitor { - decodedPassword = String.base64decode(password); - mcryptPassword = mcryptObj.decode(decodedPassword); - return mcryptPassword; - }handle{ - return "!!! Error to connect in mcrypt"; - } - - } - - - - -} \ No newline at end of file From 028a8057ce580b5b0c542d2d9bdd7f561d9cc94a Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Mon, 31 Dec 2012 12:13:33 +0600 Subject: [PATCH 5/9] document --- mcrypto_ferite_module/install_document.txt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 mcrypto_ferite_module/install_document.txt diff --git a/mcrypto_ferite_module/install_document.txt b/mcrypto_ferite_module/install_document.txt new file mode 100644 index 0000000..fe770eb --- /dev/null +++ b/mcrypto_ferite_module/install_document.txt @@ -0,0 +1,31 @@ +## mcrypt install + +wget http://easynews.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz + +tar -xvzf libmcrypt-2.5.8.tar.gz + +cd libmcrypt-2.5.8 + +./configure --prefix=/cention --disable-posix-threads + +make + +sudo make install + + + +##Installing libltdl (optional) + +cd libltdl + +./configure --prefix=/cention --enable-ltdl-install + +make + +make install # As root + + +##farm install + + +LD_LIBRARY_PATH=/cention/lib PATH=/cention/bin:$PATH farm clean then PATH=/cention/bin:$PATH farm install \ No newline at end of file From 102a9c831cc24ce6743e5e3cbf968c5a908284b4 Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Wed, 2 Jan 2013 18:55:56 +0600 Subject: [PATCH 6/9] update mcrypt ferite module --- mcrypto_ferite_module/farm.yard | 3 + mcrypto_ferite_module/mcrypt.feh | 70 ++++---- mcrypto_ferite_module/mcrypt_module.fec | 210 ++++++++++++------------ mcrypto_ferite_module/test.fe | 11 +- 4 files changed, 144 insertions(+), 150 deletions(-) diff --git a/mcrypto_ferite_module/farm.yard b/mcrypto_ferite_module/farm.yard index 1b3553f..f4035ed 100644 --- a/mcrypto_ferite_module/farm.yard +++ b/mcrypto_ferite_module/farm.yard @@ -10,6 +10,8 @@ + + @@ -18,6 +20,7 @@ + diff --git a/mcrypto_ferite_module/mcrypt.feh b/mcrypto_ferite_module/mcrypt.feh index 36a6083..cd5a3b6 100644 --- a/mcrypto_ferite_module/mcrypt.feh +++ b/mcrypto_ferite_module/mcrypt.feh @@ -1,46 +1,40 @@ // developed by ashish ghosh. email:ashish_ghosh@cention.se -uses "mcrypt_module.fec"; -uses "string","number","console","array"; -uses "MHash.fec"; +uses "mcrypt_module"; namespace mCrypt{ - function encryptMcryptography(string password) { - - object mcryptObj = new mcrypt.mcrypt(); - string mcryptPassword; - string encodedPassword; - - monitor { - mcryptPassword = mcryptObj.encode(password); - encodedPassword = String.base64encode(mcryptPassword); - return encodedPassword; - }handle{ - return "!!! Error to connect in mcrypt"; - } - - } - - - function decryptMcryptography(string password) { - - object mcryptObj = new mcrypt.mcrypt(); - string decodedPassword; - string mcryptPassword; - - monitor { - decodedPassword = String.base64decode(password); - mcryptPassword = mcryptObj.decode(decodedPassword); - return mcryptPassword; - }handle{ - return "!!! Error to connect in mcrypt"; - } - - } - + function encryptMcryptography(string password , string passphrase ) { + + object mcryptObj = new mcrypt.mcrypt("des", "ecb"); + string mcryptPassword; + string encodedPassword; + + monitor { + mcryptObj.keygenarate(passphrase); + mcryptPassword = mcryptObj.encode(password); + return mcryptPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } + + function decryptMcryptography(string password , string passphrase ) { + + object mcryptObj = new mcrypt.mcrypt("des", "ecb"); + string decodedPassword; + string mcryptPassword; + + monitor { + mcryptObj.keygenarate(passphrase); + mcryptPassword = mcryptObj.decode(password); + return mcryptPassword; + }handle{ + return "!!! Error to connect in mcrypt"; + } + + } - - } \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt_module.fec b/mcrypto_ferite_module/mcrypt_module.fec index 5019913..6e52d8c 100644 --- a/mcrypto_ferite_module/mcrypt_module.fec +++ b/mcrypto_ferite_module/mcrypt_module.fec @@ -3,142 +3,138 @@ uses "mcrypt.lib"; module-header { - #include #include #include #include - +#include +#define selfCrypt ((MCRYPT)(self->odata)) } namespace mcrypt{ -class mcrypt{ - -native function encode( string password) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - int cryptsize; - char *target; - char* result; - - - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; - } - - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } - - iv_size = mcrypt_enc_get_iv_size( td ); - - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); + class mcrypt{ + + /** + * @function mcrypt constructor. + * @param string algo - The algorithm to use. + * @param string mode - The encryption mode. + */ + + native function constructor(string algo, string mode) { + self->odata = mcrypt_module_open(algo->data, NULL,mode->data, NULL); + if( selfCrypt == MCRYPT_FAILED ) { + ferite_error(script, 0, "Error, couldn't initialize crypt module\n"); + FE_RETURN_NULL_OBJECT; } } - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); - - i = mcrypt_generic_init ( td, key, keysize, IV ); + /** + * @function mcrypt Key genarate function. + * @param string passphrase - Use for key generation. + */ - if (i < 0) { - // mcrypt_perror( i ); - // exit(1); - FE_RETURN_FALSE; - } + native function keygenarate( string passphrase ){ + int i; + char *key; + int iv_size, err, flag; + int key_len = 0; + char *iv; + KEYGEN keygen; + + key_len /= 8; + if( key_len <= 0) + key_len = mcrypt_enc_get_key_size( selfCrypt ); + key=calloc(1,key_len*sizeof(char)); + keygen.count = 0; + keygen.salt= NULL; + keygen.hash_algorithm[0] = MHASH_MD5; + keygen.salt_size = mhash_get_keygen_salt_size(MHASH_MD5); + + if( key == NULL ){ + FE_RETURN_FALSE; + } + mhash_keygen_ext( KEYGEN_MCRYPT ,keygen, key, key_len, passphrase->data , strlen(passphrase->data)); + + + if(flag = mcrypt_enc_mode_has_iv( selfCrypt )){ + + iv_size = mcrypt_enc_get_iv_size( selfCrypt ); + iv = malloc(iv_size*sizeof(char)); + + if( iv == NULL ){ + FE_RETURN_FALSE; + }else { + for(i=0;ilength + blocksize - 1 ) / blocksize ) * blocksize; - target = calloc( 1, cryptsize ); - - memcpy( target, password->data, password->length ); - - if ( mcrypt_generic( td, target, cryptsize ) != 0 ) { - fprintf( stderr, "Code failing" ); } - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - - FE_RETURN_CSTR( target, FE_TRUE ); - -} - - - -native function decode( string password ) : string { - - int i; - char *IV; - int iv_size; - int keysize; - char *key; - int blocksize; - char *target; - char *block_buffer; - int decryptlength; + /** + * @function mcrypt password encode function. + * @param string password - Use for psaaword encryption. + */ + + native function encode( string password ) { + + int err; + FeriteVariable *ret_str; + ret_str = fe_new_str( "crypt_str", password->data,password->length,FE_CHARSET_DEFAULT ); + err = mcrypt_generic (selfCrypt, VAS(ret_str)->data, VAS( ret_str)->length ); + if( err ) { + ferite_variable_destroy( script , ret_str ); + mcrypt_perror( err ); + ferite_error( script, 0, "error\n" ); + FE_RETURN_FALSE; + } + FE_RETURN_VAR( ret_str ); - MCRYPT td = mcrypt_module_open( "des", NULL, "ecb", NULL ); - if ( td == MCRYPT_FAILED ) { - FE_RETURN_FALSE ; } - if ( mcrypt_enc_self_test( td ) != 0 ) { - FE_RETURN_FALSE ; - } + /** + * @function mcrypt password deencode function. + * @param string password - Use for psaaword decryption. + */ - iv_size = mcrypt_enc_get_iv_size( td ); + native function decode( string password ) { - if ( iv_size != 0 ) { - IV = calloc( 1, iv_size ); - for ( i = 0; i < iv_size; i++ ) { - IV[ i ] = rand(); - } + FeriteVariable *ret_str; + + ret_str = fe_new_str("new_str",password->data,password->length ,FE_CHARSET_DEFAULT); + mdecrypt_generic (selfCrypt, VAS(ret_str)->data , VAS(ret_str)->length ); + FE_RETURN_VAR(ret_str); + } - keysize = mcrypt_enc_get_key_size( td ); - key = calloc( 1, keysize ); - memcpy(key, "12345678", keysize); + /** + * @function mcrypt constructor. + */ - i = mcrypt_generic_init ( td, key, keysize, IV ); - if ( i < 0 ) { - // mcrypt_perror( i ); - //exit(1); - FE_RETURN_FALSE ; + native function destructor() + { + if( selfCrypt == NULL ) { + ferite_error( script, 0, "Internal error\n"); + FE_RETURN_FALSE; + } + mcrypt_generic_deinit(selfCrypt); + mcrypt_module_close(selfCrypt); } - blocksize = mcrypt_enc_get_block_size( td ); - block_buffer = calloc( 1, blocksize ); - decryptlength = (password->length + blocksize - 1) / blocksize * blocksize; - target = calloc( 1, decryptlength ); - - memcpy(target, password->data , password->length); - mdecrypt_generic( td, target, decryptlength ); - - - mcrypt_generic_deinit( td ); - mcrypt_module_close( td ); - free(block_buffer); - FE_RETURN_CSTR( target, FE_TRUE ); - -} - -} + } } \ No newline at end of file diff --git a/mcrypto_ferite_module/test.fe b/mcrypto_ferite_module/test.fe index fd49e84..03f6f08 100644 --- a/mcrypto_ferite_module/test.fe +++ b/mcrypto_ferite_module/test.fe @@ -1,12 +1,13 @@ - uses "mcrypt.feh"; + uses "mcrypt.feh","string","console"; - - string password = "ashish ghosh"; + string passphrase = ""; + string password; string encryptedPassword; string decryptedPassword; - encryptedPassword = mCrypt.encryptMcryptography(password); + password = String.escape(argv[0]); + encryptedPassword = mCrypt.encryptMcryptography(password , passphrase); Console.println("encrypt:" + "${encryptedPassword}"); - decryptedPassword = mCrypt.decryptMcryptography(encryptedPassword); + decryptedPassword = mCrypt.decryptMcryptography(encryptedPassword , passphrase); Console.println("decrypt:" + "${decryptedPassword}"); From 6b30b26bcbd0fec5d6fb06a7489d3c6066cb58cb Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Thu, 3 Jan 2013 19:50:04 +0600 Subject: [PATCH 7/9] mcrypt ferite module --- mcrypto_ferite_module/mcrypt.feh | 45 +++++++++++++++---------- mcrypto_ferite_module/mcrypt_module.fec | 2 +- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/mcrypto_ferite_module/mcrypt.feh b/mcrypto_ferite_module/mcrypt.feh index cd5a3b6..bd68f4f 100644 --- a/mcrypto_ferite_module/mcrypt.feh +++ b/mcrypto_ferite_module/mcrypt.feh @@ -1,6 +1,6 @@ // developed by ashish ghosh. email:ashish_ghosh@cention.se -uses "mcrypt_module"; +uses "mcrypt_module","string"; namespace mCrypt{ @@ -8,31 +8,40 @@ namespace mCrypt{ function encryptMcryptography(string password , string passphrase ) { object mcryptObj = new mcrypt.mcrypt("des", "ecb"); - string mcryptPassword; - string encodedPassword; - - monitor { - mcryptObj.keygenarate(passphrase); - mcryptPassword = mcryptObj.encode(password); - return mcryptPassword; - }handle{ - return "!!! Error to connect in mcrypt"; + string encryptedPassword; + number length; + length = String.length( password ); + + if( length >= 8 ){ + + monitor { + mcryptObj.keygenarate(passphrase); + encryptedPassword = mcryptObj.encode(password); + return encryptedPassword; + } + handle { + raise new Error("Encryption error to connect in mcrypt ."); + } } - + else { + raise new Error("Error string length must be greater than 7 ."); + } } function decryptMcryptography(string password , string passphrase ) { object mcryptObj = new mcrypt.mcrypt("des", "ecb"); - string decodedPassword; - string mcryptPassword; - + string decryptedPassword; + monitor { - mcryptObj.keygenarate(passphrase); - mcryptPassword = mcryptObj.decode(password); - return mcryptPassword; + if( password ){ + + mcryptObj.keygenarate(passphrase); + decryptedPassword = mcryptObj.decode(password); + return decryptedPassword; + } }handle{ - return "!!! Error to connect in mcrypt"; + raise new Error(" Decryption error to connect in mcrypt ."); } } diff --git a/mcrypto_ferite_module/mcrypt_module.fec b/mcrypto_ferite_module/mcrypt_module.fec index 6e52d8c..478c817 100644 --- a/mcrypto_ferite_module/mcrypt_module.fec +++ b/mcrypto_ferite_module/mcrypt_module.fec @@ -79,7 +79,7 @@ namespace mcrypt{ ferite_error(script, 0,""); FE_RETURN_FALSE; } - + FE_RETURN_TRUE; } /** From 44f63aa6ee1a20363d16681555f5999dcde0e760 Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Sun, 6 Jan 2013 11:38:48 +0600 Subject: [PATCH 8/9] mcrypt ferite module --- mcrypto_ferite_module/install_document.txt | 16 +++++++--------- mcrypto_ferite_module/mcrypt_module.fec | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/mcrypto_ferite_module/install_document.txt b/mcrypto_ferite_module/install_document.txt index fe770eb..ff7e506 100644 --- a/mcrypto_ferite_module/install_document.txt +++ b/mcrypto_ferite_module/install_document.txt @@ -1,31 +1,29 @@ + + ## mcrypt install wget http://easynews.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz - tar -xvzf libmcrypt-2.5.8.tar.gz - cd libmcrypt-2.5.8 - ./configure --prefix=/cention --disable-posix-threads - make - sudo make install + + ##Installing libltdl (optional) cd libltdl - ./configure --prefix=/cention --enable-ltdl-install - make - make install # As root -##farm install + +##farm install + LD_LIBRARY_PATH=/cention/lib PATH=/cention/bin:$PATH farm clean then PATH=/cention/bin:$PATH farm install \ No newline at end of file diff --git a/mcrypto_ferite_module/mcrypt_module.fec b/mcrypto_ferite_module/mcrypt_module.fec index 478c817..8f6563b 100644 --- a/mcrypto_ferite_module/mcrypt_module.fec +++ b/mcrypto_ferite_module/mcrypt_module.fec @@ -8,7 +8,7 @@ module-header { #include #include #include -#define selfCrypt ((MCRYPT)(self->odata)) +#define td ((MCRYPT)(self->odata)) } @@ -24,7 +24,7 @@ namespace mcrypt{ native function constructor(string algo, string mode) { self->odata = mcrypt_module_open(algo->data, NULL,mode->data, NULL); - if( selfCrypt == MCRYPT_FAILED ) { + if( td == MCRYPT_FAILED ) { ferite_error(script, 0, "Error, couldn't initialize crypt module\n"); FE_RETURN_NULL_OBJECT; } @@ -46,7 +46,7 @@ namespace mcrypt{ key_len /= 8; if( key_len <= 0) - key_len = mcrypt_enc_get_key_size( selfCrypt ); + key_len = mcrypt_enc_get_key_size( td ); key=calloc(1,key_len*sizeof(char)); keygen.count = 0; keygen.salt= NULL; @@ -59,9 +59,9 @@ namespace mcrypt{ mhash_keygen_ext( KEYGEN_MCRYPT ,keygen, key, key_len, passphrase->data , strlen(passphrase->data)); - if(flag = mcrypt_enc_mode_has_iv( selfCrypt )){ + if(flag = mcrypt_enc_mode_has_iv( td )){ - iv_size = mcrypt_enc_get_iv_size( selfCrypt ); + iv_size = mcrypt_enc_get_iv_size( td ); iv = malloc(iv_size*sizeof(char)); if( iv == NULL ){ @@ -73,7 +73,7 @@ namespace mcrypt{ } - err = mcrypt_generic_init( selfCrypt, key, key_len, iv); + err = mcrypt_generic_init( td, key, key_len, iv); if( err < 0 ) { mcrypt_perror(err); ferite_error(script, 0,""); @@ -92,7 +92,7 @@ namespace mcrypt{ int err; FeriteVariable *ret_str; ret_str = fe_new_str( "crypt_str", password->data,password->length,FE_CHARSET_DEFAULT ); - err = mcrypt_generic (selfCrypt, VAS(ret_str)->data, VAS( ret_str)->length ); + err = mcrypt_generic (td, VAS(ret_str)->data, VAS( ret_str)->length ); if( err ) { ferite_variable_destroy( script , ret_str ); mcrypt_perror( err ); @@ -114,7 +114,7 @@ namespace mcrypt{ FeriteVariable *ret_str; ret_str = fe_new_str("new_str",password->data,password->length ,FE_CHARSET_DEFAULT); - mdecrypt_generic (selfCrypt, VAS(ret_str)->data , VAS(ret_str)->length ); + mdecrypt_generic (td, VAS(ret_str)->data , VAS(ret_str)->length ); FE_RETURN_VAR(ret_str); } @@ -125,12 +125,12 @@ namespace mcrypt{ native function destructor() { - if( selfCrypt == NULL ) { + if( td == NULL ) { ferite_error( script, 0, "Internal error\n"); FE_RETURN_FALSE; } - mcrypt_generic_deinit(selfCrypt); - mcrypt_module_close(selfCrypt); + mcrypt_generic_deinit(td); + mcrypt_module_close(td); } From c6858b6ff1dfd607fb799260bb3969a2b47f8e61 Mon Sep 17 00:00:00 2001 From: ashish ghosh Date: Wed, 16 Jan 2013 17:35:55 +0600 Subject: [PATCH 9/9] fixed the issue of too short string --- mcrypto_ferite_module/mcrypt.feh | 23 +++----- mcrypto_ferite_module/mcrypt_module.fec | 77 ++++++++++++++++--------- mcrypto_ferite_module/test.fe | 6 +- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/mcrypto_ferite_module/mcrypt.feh b/mcrypto_ferite_module/mcrypt.feh index bd68f4f..726561a 100644 --- a/mcrypto_ferite_module/mcrypt.feh +++ b/mcrypto_ferite_module/mcrypt.feh @@ -9,23 +9,14 @@ namespace mCrypt{ object mcryptObj = new mcrypt.mcrypt("des", "ecb"); string encryptedPassword; - number length; - length = String.length( password ); - - if( length >= 8 ){ - - monitor { - mcryptObj.keygenarate(passphrase); - encryptedPassword = mcryptObj.encode(password); - return encryptedPassword; - } - handle { - raise new Error("Encryption error to connect in mcrypt ."); + monitor { + mcryptObj.keygenarate(passphrase); + encryptedPassword = mcryptObj.encode(password); + return encryptedPassword; } - } - else { - raise new Error("Error string length must be greater than 7 ."); - } + handle { + raise new Error("Encryption error to connect in mcrypt ."); + } } function decryptMcryptography(string password , string passphrase ) { diff --git a/mcrypto_ferite_module/mcrypt_module.fec b/mcrypto_ferite_module/mcrypt_module.fec index 8f6563b..d3e5583 100644 --- a/mcrypto_ferite_module/mcrypt_module.fec +++ b/mcrypto_ferite_module/mcrypt_module.fec @@ -40,45 +40,46 @@ namespace mcrypt{ int i; char *key; int iv_size, err, flag; - int key_len = 0; + int key_len; char *iv; KEYGEN keygen; - + + key_len = strlen(passphrase->data); key_len /= 8; if( key_len <= 0) - key_len = mcrypt_enc_get_key_size( td ); - key=calloc(1,key_len*sizeof(char)); + key_len = mcrypt_enc_get_key_size( td ); + key = calloc(1,key_len*sizeof(char)); + keygen.count = 0; keygen.salt= NULL; keygen.hash_algorithm[0] = MHASH_MD5; keygen.salt_size = mhash_get_keygen_salt_size(MHASH_MD5); if( key == NULL ){ + ferite_error(script, 0,"error\n"); FE_RETURN_FALSE; } mhash_keygen_ext( KEYGEN_MCRYPT ,keygen, key, key_len, passphrase->data , strlen(passphrase->data)); - - - if(flag = mcrypt_enc_mode_has_iv( td )){ - + + if(mcrypt_enc_mode_has_iv( td )){ + iv_size = mcrypt_enc_get_iv_size( td ); iv = malloc(iv_size*sizeof(char)); - + if( iv == NULL ){ - FE_RETURN_FALSE; + ferite_error(script, 0,"error\n"); + FE_RETURN_FALSE; }else { for(i=0;idata,password->length,FE_CHARSET_DEFAULT ); - err = mcrypt_generic (td, VAS(ret_str)->data, VAS( ret_str)->length ); + char *target; + + ret_str = fe_new_str( "encrypt_str", password->data,password->length,FE_CHARSET_DEFAULT ); + + blocksize = mcrypt_enc_get_block_size( td ); + cryptsize = ( ( VAS( ret_str)->length + blocksize - 1 ) / blocksize ) * blocksize; + target = calloc( 1, cryptsize ); + + memcpy( target, VAS(ret_str)->data, VAS(ret_str)->length ); + err = mcrypt_generic(td, target, cryptsize); if( err ) { ferite_variable_destroy( script , ret_str ); mcrypt_perror( err ); ferite_error( script, 0, "error\n" ); FE_RETURN_FALSE; } - FE_RETURN_VAR( ret_str ); - - + + FE_RETURN_CSTR(target , free); } /** @@ -110,12 +119,24 @@ namespace mcrypt{ */ native function decode( string password ) { - - FeriteVariable *ret_str; - - ret_str = fe_new_str("new_str",password->data,password->length ,FE_CHARSET_DEFAULT); - mdecrypt_generic (td, VAS(ret_str)->data , VAS(ret_str)->length ); - FE_RETURN_VAR(ret_str); + + int blocksize , cryptsize; + char *block_buffer; + char *target; + FeriteVariable *ret_str; + + ret_str = fe_new_str("decrypt_str",password->data,password->length ,FE_CHARSET_DEFAULT); + + blocksize = mcrypt_enc_get_block_size( td ); + block_buffer = calloc( 1, blocksize ); + cryptsize = ( ( VAS( ret_str)->length + blocksize - 1 ) / blocksize ) * blocksize; + target = calloc( 1, cryptsize ); + + memcpy(target, VAS(ret_str)->data, VAS( ret_str)->length); + mdecrypt_generic (td, target , cryptsize ); + + free(block_buffer); + FE_RETURN_CSTR(target , free); } diff --git a/mcrypto_ferite_module/test.fe b/mcrypto_ferite_module/test.fe index 03f6f08..345cd89 100644 --- a/mcrypto_ferite_module/test.fe +++ b/mcrypto_ferite_module/test.fe @@ -1,10 +1,10 @@ uses "mcrypt.feh","string","console"; - string passphrase = ""; - string password; + string passphrase = "cention"; + string password = "ashish"; string encryptedPassword; string decryptedPassword; - password = String.escape(argv[0]); + encryptedPassword = mCrypt.encryptMcryptography(password , passphrase); Console.println("encrypt:" + "${encryptedPassword}"); decryptedPassword = mCrypt.decryptMcryptography(encryptedPassword , passphrase);