okidokey, the code is attached.
The encryption/decryption function is in do_crypt.c
thanks
Stella
On Mon, May 27, 2002 at 06:03:46PM +0200, Aleix Conchillo wrote:
> hi stella,
>
> could you please post your sample code?
>
> best regards,
>
> aleix
>
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing List[EMAIL PROTECTED]
> Automated List Manager [EMAIL PROTECTED]
OPENSSLDIR=/usr/local/ssl
LIBS = -lm -L$(OPENSSLDIR) -lssl -lcrypto -lefence
oflags = -c
CFLAGS = -pedantic -ansi -W -Wall -g
CC = gcc
exec = crypt
default: main.o do_crypt.o parse_keyfile.o
$(CC) -o ${exec} main.o do_crypt.o parse_keyfile.o -o crypt ${LIBS}
main.o: main.c do_crypt.c parse_keyfile.c header.h
${CC} -c ${CFLAGS} ${INCDIR} main.c do_crypt.c parse_keyfile.c
clean:
rm -f core *.o
#include "header.h"
#define EVP_MAX_BLOCK_LENGTH 6
FILE *out;
char* do_crypt(char *i_p, int docrypt) {
unsigned char outbuf[1024+EVP_MAX_BLOCK_LENGTH];
unsigned char outbuf_final[1024];
int outlen, inlen;
unsigned char iv[] = "12345678";
EVP_CIPHER_CTX ctx;
inlen = strlen(i_p);
EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit(&ctx, EVP_des_ede3(), NULL, NULL, docrypt);
EVP_CIPHER_CTX_set_key_length(&ctx, key_length);
EVP_CipherInit(&ctx, NULL, key, iv, docrypt);
if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, (unsigned char *)i_p, inlen)) {
fprintf(stderr, "Error crypting in EVP_CipherUpdate\n");
exit(10);
}
if(!EVP_CipherFinal(&ctx, outbuf_final, &outlen)) {
fprintf(stderr, "Error crypting in EVP_CipherFinal\n");
exit(11);
}
sprintf(return_out,"%s%s", outbuf, outbuf_final);
fwrite(return_out,1,outlen, stdout);
fwrite("\n",1,1,stdout);
EVP_CIPHER_CTX_cleanup(&ctx);
return return_out;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BUFSIZE 1024
struct stat tmp;
int f_map_encrypt_p;
FILE *f_session_key_p;
char *session_key_filename;
char *current_line;
char *edata_a, *edata_b;
char *data_a, *data_b;
int docrypt;
int key_length;
char *session_key;
unsigned char key[BUFSIZE];
char *return_out;
char* parse_keyfile(char *current_line);
char* do_crypt(char *i_p, int docrypt);
key : 64556564446546465546546444555665
#include "header.h"
int main(int argc, char** argv) {
int opt, i=0, j=0;
char *temp2;
/* COMMAND LINE OPTION HANDLING */
while((opt = getopt(argc, argv, "k:a:b:"))!=-1)
switch (opt) {
case 'k':
if(optarg) {
session_key_filename = malloc(64);
strncpy(session_key_filename, optarg, 64);
if((stat(optarg, &tmp)!=0)) {
fprintf(stderr,"Error: Illegal
filename for keyfile\n");
exit(1);
}
}
break;
case 'a':
if(optarg) {
edata_a = malloc(64);
strncpy(edata_a, optarg, 64);
}
break;
case 'b':
if(optarg) {
edata_b = malloc(64);
strncpy(edata_b, optarg, 64);
}
break;
case '?':
default:
printf("Usage: -k session_key_file\n");
exit(2);
}
printf("0: %s\t1: %s\n", edata_a, edata_b);
if (!session_key_filename) {
fprintf(stderr, "Error: Missing option -k\n");
printf("Usage: -k session_key_file\n");
exit(4);
}
if((return_out =(char *)malloc((BUFSIZE)*sizeof(char)))==NULL) {
fprintf(stderr, "Error: malloc error\n");
exit(8);
}
/* IN HERE GOES DECRYPTION