The following program (using OpenSSL 1.0.0a) is attempting to use AES to encrypt the contents of file "x" and output to "y" but under Win32 I get an AV in SEED_ofb128_encrypt upon calling AES_cfb128_encrypt.
I read the OpenSSL FAQ and did try adding the code calling the init functions and/or including applink.c (commented out below) but all to no avail.
Code was compiled as follows:
cl.exe /nologo /MD /GR /EHa /W3 /wd4068 test.cpp kernel32.lib user32.lib ssleay32.lib libeay32.lib /link
using namespace std;
int main( int argc, char* argv[ ] )
// SSL_library_init( );
// CRYPTO_malloc_init( );
int num, bytes_read, bytes_written;
unsigned char indata[ AES_BLOCK_SIZE ];
unsigned char outdata[ AES_BLOCK_SIZE ];
unsigned char ckey[ ] = "thiskeyisverybad";
unsigned char ivec[ ] = "dontusethisinput";
AES_set_encrypt_key( ckey, 128, &key );
ifstream inpf( "x", ios::in | ios::binary );
ofstream outf( "y", ios::out | ios::binary );
while( true )
bytes_read = inpf.rdbuf( )->sgetn( ( char* )indata, AES_BLOCK_SIZE );
AES_cfb128_encrypt( indata, outdata, bytes_read, &key, ivec, &num, AES_ENCRYPT );
bytes_written = outf.rdbuf( )->sputn( ( char* )outdata, bytes_read );
if( bytes_read < AES_BLOCK_SIZE )
If anyone can see any obvious problems with this code or the compiler options I'd really appreciate a heads up.