Bitcoin Forum
December 05, 2016, 04:47:30 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Help - Any OpenSSL Gurus?  (Read 1881 times)
CIYAM
Legendary
*
Offline Offline

Activity: 1820


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
1480913250
Hero Member
*
Offline Offline

Posts: 1480913250

View Profile Personal Message (Offline)

Ignore
1480913250
Reply with quote  #2

1480913250
Report to moderator
1480913250
Hero Member
*
Offline Offline

Posts: 1480913250

View Profile Personal Message (Offline)

Ignore
1480913250
Reply with quote  #2

1480913250
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480913250
Hero Member
*
Offline Offline

Posts: 1480913250

View Profile Personal Message (Offline)

Ignore
1480913250
Reply with quote  #2

1480913250
Report to moderator
1480913250
Hero Member
*
Offline Offline

Posts: 1480913250

View Profile Personal Message (Offline)

Ignore
1480913250
Reply with quote  #2

1480913250
Report to moderator
1480913250
Hero Member
*
Offline Offline

Posts: 1480913250

View Profile Personal Message (Offline)

Ignore
1480913250
Reply with quote  #2

1480913250
Report to moderator
CIYAM
Legendary
*
Offline Offline

Activity: 1820


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!