> But it
> would appear that
> this is the hard way to do it and have heard
> numerous recommendations to
> instead use the EVP API, but I have found minimal
> examples on how to do
> this. Does anyone have some sample code?? And also I
I had sent one few days ago. I am sending it again.

HTH,
Girish
> did find one
> example on the web from a project call cfengine that
> uses EVP but when
> compiling gives me LOTS of linker errors (linking
> against libeay32MD.lib
> or ssleay32MD.lib) which I acquired via the
> precompiled binaries from
> Shining Light Productions
> http://www.slproweb.com/products/Win32OpenSSL.html
> which is version
> 0.9.8b are there any known issues with these, they
> linked fine when I
> was going with the AES_encrypt/decrypt aes.h
> approach.
> 
> Thanks in Advance,
> 
> AJ
>
______________________________________________________________________
> OpenSSL Project                                
> http://www.openssl.org
> User Support Mailing List                   
> openssl-users@openssl.org
> Automated List Manager                          
> [EMAIL PROTECTED]
> 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
#include <fcntl.h>
#include <unistd.h>
#include <openssl/evp.h>

#define IV "0xdeadbeefdeadbeef"

int main(int argc, char **argv) {
	EVP_CIPHER_CTX ctx;
	unsigned char key[1024],iv[1024],ibuf[1024],obuf[1024];
	int rfd, wfd,keyfd,ilen,olen,tlen;
	int l = 0;

	if(argc < 3) {
		printf("Usage: %s infile outfile\n",argv[0]);
		exit(128);
	}


	memcpy(iv,IV,sizeof(IV));
	key[0] = 0;

	/* Let us derive a random 256 bit key */
	while(l < 32) {
		char b[128];
		sprintf(b,"%lu",arc4random());
		strcat(key,b);
		l = strlen(key);
	}


 	keyfd =	creat(".key",0644);
	write(keyfd,key,256);
	close(keyfd);

	EVP_CIPHER_CTX_init(&ctx);
	if(!EVP_CipherInit_ex(&ctx, EVP_aes_256_cbc(),NULL,key, iv,1) ) {
	printf("Couldnt initialize cipher\n");
	return 1;
}
/* 1 for encrypt, 0 for decrypt */

	if((rfd = open(argv[1],O_RDONLY) ) == -1) {
		printf("Couldnt open input file\n");
		exit(128);
	}
	if((wfd = creat(argv[2],0644) ) == -1) {
		printf("Couldn't open output file for writing\n");
		exit(128);
	}

	while((ilen = read(rfd,ibuf,1024) ) > 0) {
		if(EVP_CipherUpdate(&ctx,obuf,&olen,ibuf,ilen)){
			write(wfd,obuf,olen);
		}
		else {
			printf("Encryption error\n");
			return 1;
		}

	}
	if(!EVP_CipherFinal_ex(&ctx,obuf+olen,&tlen)) {
		printf("Trouble with padding the last block\n");
		return 1;
	}
	write(wfd,obuf+olen,tlen);
	EVP_CIPHER_CTX_cleanup(&ctx);
	close(rfd);
	close(wfd);

	printf("AES 256 CBC encryption complete\n");
	printf("Secret key is saved to file .key\n");

	return 0;
}
  • Re: EVP? Girish Venkatachalam
    • RE: EVP? Mayorga, Armando CTR NIOC Norfolk N361

Reply via email to