Bitcoin Forum
May 27, 2024, 01:56:20 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help - Any OpenSSL Gurus?  (Read 2132 times)
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1078


Ian Knowles - CIYAM Lead Developer


View Profile WWW
January 16, 2012, 01:53:02 AM
 #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 <fstream>
#include <iostream>
#include <openssl/aes.h>
#include <openssl/ssl.h>
//#include <openssl/applink.c>

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.

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1078


Ian Knowles - CIYAM Lead Developer


View Profile WWW
January 16, 2012, 07:23:05 AM
 #2

Solved by instead using the EVP_Encrypt functions as used in Bitcoin.

Smiley

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!