Author

Topic: Help - Any OpenSSL Gurus? (Read 2132 times)

legendary
Activity: 1890
Merit: 1072
Ian Knowles - CIYAM Lead Developer
January 16, 2012, 03:23:05 AM
#2
Solved by instead using the EVP_Encrypt functions as used in Bitcoin.

Smiley
legendary
Activity: 1890
Merit: 1072
Ian Knowles - CIYAM Lead Developer
January 15, 2012, 09:53:02 PM
#1
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. Sad

Code was compiled as follows:
cl.exe /nologo /MD /GR /EHa /W3 /wd4068 test.cpp kernel32.lib user32.lib ssleay32.lib libeay32.lib /link

[test.cpp]
#include
#include
#include
#include
//#include

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_KEY key;
   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 )
         break;
   }
}

If anyone can see any obvious problems with this code or the compiler options I'd really appreciate a heads up.


Regards,

Ian.
Jump to: