richter 01/09/04 12:24:14 Modified: crypto epcrypto_config.h Added: crypto epcrypto.c Log: source crypto Revision Changes Path 1.2 +141 -133 embperl/crypto/epcrypto_config.h Index: epcrypto_config.h =================================================================== RCS file: /home/cvs/embperl/crypto/epcrypto_config.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- epcrypto_config.h 2001/09/04 08:34:34 1.1 +++ epcrypto_config.h 2001/09/04 19:24:13 1.2 @@ -1,133 +1,141 @@ -/*################################################################################### -# -# Embperl - Copyright (c) 1997-2001 Gerald Richter / ECOS -# -# You may distribute under the terms of either the GNU General Public -# License or the Artistic License, as specified in the Perl README file. -# For use with Apache httpd and mod_perl, see also Apache copyright. -# -# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. -# -# $Id: epcrypto_config.h,v 1.1 2001/09/04 08:34:34 richter Exp $ -# -###################################################################################*/ - -/* -* Configuration for Embperl source code encrytion, -* you need to set the correct values for -* -* EPC_ENABLE -* EPC_CHIPER -* EPC_KEY -* EPC_UNENCYRPTED -* -* before you can use it. -*/ - -/* ---------------------------------------------------------------------------- -* -* Enable source code encryption -* -* Set to 1 for yes and to 0 for no -* -* -------------------------------------------------------------------------- */ - -#define EPC_ENABLE 0 - - -/* ---------------------------------------------------------------------------- - -Possible Chipers, an up to date list can be found at - -http://www.openssl.org/docs/crypto/EVP_EncryptInit.html#CIPHER_LISTING - -------------------------------------------------------------------------------- - -CIPHER LISTING -============== - -All algorithms have a fixed key length unless otherwise stated. - -EVP_enc_null() -Null cipher: does nothing. - -EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void) -DES in CBC, ECB, CFB and OFB modes respectively. - -EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), EVP_des_ede_cfb(void) -Two key triple DES in CBC, ECB, CFB and OFB modes respectively. - -EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), EVP_des_ede3_cfb(void) -Three key triple DES in CBC, ECB, CFB and OFB modes respectively. - -EVP_desx_cbc(void) -DESX algorithm in CBC mode. - -EVP_rc4(void) -RC4 stream cipher. This is a variable key length cipher with default key length 128 bits. - -EVP_rc4_40(void) -RC4 stream cipher with 40 bit key length. This is obsolete and new code should -use EVP_rc4() and the EVP_CIPHER_CTX_set_key_length() function. - -EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), EVP_idea_ofb(void), EVP_idea_cbc(void) -IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. - -EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void) -RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a -variable key length cipher with an additional parameter called ``effective key -bits'' or ``effective key length''. By default both are set to 128 bits. - -EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void) -RC2 algorithm in CBC mode with a default key length and effective key length of -40 and 64 bits. These are obsolete and new code should use EVP_rc2_cbc(), -EVP_CIPHER_CTX_set_key_length() and EVP_CIPHER_CTX_ctrl() to set the key length and effective key length. - -EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void); -Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. -This is a variable key length cipher. - -EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), EVP_cast5_ofb(void) -CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. -This is a variable key length cipher. - -EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void) -RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. -This is a variable key length cipher with an additional ``number of rounds'' -parameter. By default the key length is set to 128 bits and 12 rounds. - ----------------------------------------------------------------------------- */ - -/* ---------------------------------------------------------------------------- -* -* Chiper to use, choose one of the above -* -* -------------------------------------------------------------------------- */ - -#define EPC_CHIPER EVP_rc4 - - -/* ---------------------------------------------------------------------------- -* -* Key -* -* !!!!!!!! Make sure to change to key below and make it length fit to used chiper !!!!!!!! -* -* -------------------------------------------------------------------------- */ - -#define EPC_KEY { 0x88, 0x56, 0xff, 0x78, 0xbc, 0xaa, 0x94, 0x1a, 0xfe } - - -/* ---------------------------------------------------------------------------- -* -* Allow unencrypted files to be served by Embperl ? -* -* Set to 1 for yes and to 0 for no -* -* -------------------------------------------------------------------------- */ - -#define EPC_UNENCYRPTED 1 - - +/*################################################################################### +# +# Embperl - Copyright (c) 1997-2001 Gerald Richter / ECOS +# +# You may distribute under the terms of either the GNU General Public +# License or the Artistic License, as specified in the Perl README file. +# For use with Apache httpd and mod_perl, see also Apache copyright. +# +# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# +# $Id: epcrypto_config.h,v 1.2 2001/09/04 19:24:13 richter Exp $ +# +###################################################################################*/ + +/* +* Configuration for Embperl source code encrytion, +* you need to set the correct values for +* +* EPC_ENABLE +* EPC_CHIPER +* EPC_KEY +* EPC_KEYLEN +* EPC_UNENCYRPTED +* +* before you can use it. +*/ + +/* ---------------------------------------------------------------------------- +* +* Enable source code encryption +* +* Set to 1 for yes and to 0 for no +* +* -------------------------------------------------------------------------- */ + +#define EPC_ENABLE 0 + + +/* ---------------------------------------------------------------------------- + +Possible Chipers, an up to date list can be found at + +http://www.openssl.org/docs/crypto/EVP_EncryptInit.html#CIPHER_LISTING + +------------------------------------------------------------------------------- + +CIPHER LISTING +============== + +All algorithms have a fixed key length unless otherwise stated. + +EVP_enc_null() +Null cipher: does nothing. + +EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void) +DES in CBC, ECB, CFB and OFB modes respectively. + +EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), EVP_des_ede_cfb(void) +Two key triple DES in CBC, ECB, CFB and OFB modes respectively. + +EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), EVP_des_ede3_cfb(void) +Three key triple DES in CBC, ECB, CFB and OFB modes respectively. + +EVP_desx_cbc(void) +DESX algorithm in CBC mode. + +EVP_rc4(void) +RC4 stream cipher. This is a variable key length cipher with default key length 128 bits. + +EVP_rc4_40(void) +RC4 stream cipher with 40 bit key length. This is obsolete and new code should +use EVP_rc4() and the EVP_CIPHER_CTX_set_key_length() function. + +EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), EVP_idea_ofb(void), EVP_idea_cbc(void) +IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively. + +EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void) +RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a +variable key length cipher with an additional parameter called ``effective key +bits'' or ``effective key length''. By default both are set to 128 bits. + +EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void) +RC2 algorithm in CBC mode with a default key length and effective key length of +40 and 64 bits. These are obsolete and new code should use EVP_rc2_cbc(), +EVP_CIPHER_CTX_set_key_length() and EVP_CIPHER_CTX_ctrl() to set the key length and effective key length. + +EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void); +Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. +This is a variable key length cipher. + +EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), EVP_cast5_ofb(void) +CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. +This is a variable key length cipher. + +EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void) +RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. +This is a variable key length cipher with an additional ``number of rounds'' +parameter. By default the key length is set to 128 bits and 12 rounds. + +---------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------------- +* +* Chiper to use, choose one of the above +* or any function that returns a valid EVP_CIPHER structure. +* +* -------------------------------------------------------------------------- */ + +#define EPC_CHIPER EVP_rc4() + + +/* ---------------------------------------------------------------------------- +* +* Key and it's length +* +* the below value must be suitable to use a initializer for an char pointer. +* either specify an constant or any function that returns a pointer a string +* +* !!!!!!!! Make sure to change to key below and make it length fit to used chiper !!!!!!!! +* !!!!!!!! Keep this file secret, anybody who has access to this and therefore !!!!!!!! +* !!!!!!!! to the key value can easy decrypt anything !!!!!!!! +* +* -------------------------------------------------------------------------- */ + +#define EPC_KEY "\0x88\0x56\0xff\0x78\0xbc\0xaa\0x94\0x1a\0xfe" +#define EPC_KEYLEN (sizeof (EPC_KEY) - 1) + + +/* ---------------------------------------------------------------------------- +* +* Allow unencrypted files to be served by Embperl ? +* +* Set to 1 for yes and to 0 for no +* +* -------------------------------------------------------------------------- */ + +#define EPC_UNENCYRPTED 1 + + 1.1 embperl/crypto/epcrypto.c Index: epcrypto.c =================================================================== #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <openssl/evp.h> #include "epcrypto_config.h" int do_crypt_file(FILE *in, FILE *out, int do_encrypt) { char inbuf[1024], outbuf[1024 + 8192]; /*EVP_MAX_BLOCK_LENGTH*/ int inlen, outlen; unsigned char * key = EPC_KEY ; unsigned char * iv = "12345678"; EVP_CIPHER_CTX ctx ; EVP_CipherInit(&ctx, EPC_CHIPER, NULL, NULL, do_encrypt); EVP_CIPHER_CTX_set_key_length(&ctx, EPC_KEYLEN); EVP_CipherInit(&ctx, NULL, key, iv, do_encrypt); for(;;) { inlen = fread(inbuf, 1, 1024, in); if(inlen <= 0) break; if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen)) { return 0; } fwrite(outbuf, 1, outlen, out); } if(!EVP_CipherFinal(&ctx, outbuf, &outlen)) { return 0; } fwrite(outbuf, 1, outlen, out); EVP_CIPHER_CTX_cleanup(&ctx); return 1; } int do_crypt_mem(char * inbuf, int inlen, char * outbuf, int do_encrypt, int type) { /* inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; */ int outlen; unsigned char * key = EPC_KEY ; unsigned char * iv = "12345678"; EVP_CIPHER_CTX ctx ; if(inlen <= 0) return 0; if (type > 0) { EVP_CipherInit(&ctx, EPC_CHIPER, NULL, NULL, do_encrypt); EVP_CIPHER_CTX_set_key_length(&ctx, EPC_KEYLEN); EVP_CipherInit(&ctx, NULL, key, iv, do_encrypt); } if (type < 2) { if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen)) { return 0; } } else { if(!EVP_CipherFinal(&ctx, outbuf, &outlen)) { return 0; } EVP_CIPHER_CTX_cleanup(&ctx); } return outlen ; } #ifndef XS_VERSION int main (int argc, char *argv[]) { FILE * ifd ; FILE * ofd ; puts ("Embperl encryption tool / Vers. 1.0 / (c) 2001 G.Richter ecos gmbh\n") ; OpenSSL_add_all_algorithums () ; if (argc < 3) { puts ("Usage: epcrypto <inputfile> <outputfile> [<syntax>] [<decrypt>]\n") ; puts (" syntax defaults to 'Embperl'\n") ; puts (" decrypt defaults to false\n") ; exit (1) ; } if (!(ifd = fopen (argv[1], "r"))) { printf ("Cannot open %s for reading (%s)\n", argv[1], strerror( errno ) ) ; exit (1) ; } if (!(ofd = fopen (argv[1], "w"))) { printf ("Cannot open %s for writing (%s)\n", argv[1], strerror( errno ) ) ; exit (1) ; } if (!do_crypt_file (ifd, ofd, argc > 3 && argv[4][0] != '\0' && argv[4][0] != '0'?0:1)) { printf ("Error while processing (%s)\n", argv[1], strerror( errno ) ) ; exit (1) ; } return 0 ; } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
