diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 77f0b1319c..cca5f06124 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,27 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-07-21 15:06 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbssl/Makefile + + contrib/hbssl/evp.c + + contrib/hbssl/evpciph.c + + contrib/hbssl/evpmd.c + * contrib/hbssl/hbssl.ch + + contrib/hbssl/tests/digest.prg + + contrib/hbssl/tests/crypt.prg + + Added almost complete EVP (hashing, encryption, decryption) API. + This means support for a max of 14 hashing methods and + about 90 symmetric encryption methods. + + * contrib/hbssl/ssl.c + * contrib/hbssl/sslctx.c + * Moved two functions between files. + + * bin/postinst.bat + * config/globsh.cf + + Tweaked/fixed to allow building Harbour present on a path + which contains spaces. + 2009-07-21 01:04 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbssl/sslctx.c * contrib/hbssl/ssl.c diff --git a/harbour/bin/postinst.bat b/harbour/bin/postinst.bat index 06e74e5c91..bced12c67a 100644 --- a/harbour/bin/postinst.bat +++ b/harbour/bin/postinst.bat @@ -46,16 +46,16 @@ goto INST_%HB_ARCHITECTURE% if not "%HB_DYNLIB%" == "yes" goto _SKIP_DLL_BIN - call %~dp0hb-mkdyn.bat + call "%~dp0hb-mkdyn.bat" setlocal if "%HB_BIN_COMPILE%" == "" set HB_BIN_COMPILE=%HB_BIN_INSTALL% if exist "%HB_BIN_INSTALL%\*.dll" ( - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -shared -o%HB_BIN_INSTALL%\hbrun-dll %~dp0..\utils\hbrun\hbrun.hbp - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -shared -o%HB_BIN_INSTALL%\hbmk2-dll %~dp0..\utils\hbmk2\hbmk2.hbp - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -shared -o%HB_BIN_INSTALL%\hbtest-dll %~dp0..\utils\hbtest\hbtest.hbp - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -shared -o%HB_BIN_INSTALL%\hbi18n-dll %~dp0..\utils\hbi18n\hbi18n.hbp - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -shared -o%HB_BIN_INSTALL%\hbformat-dll %~dp0..\utils\hbformat\hbformat.hbp + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN -shared "-o%HB_BIN_INSTALL%\hbrun-dll" "%~dp0..\utils\hbrun\hbrun.hbp" + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN -shared "-o%HB_BIN_INSTALL%\hbmk2-dll" "%~dp0..\utils\hbmk2\hbmk2.hbp" + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN -shared "-o%HB_BIN_INSTALL%\hbtest-dll" "%~dp0..\utils\hbtest\hbtest.hbp" + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN -shared "-o%HB_BIN_INSTALL%\hbi18n-dll" "%~dp0..\utils\hbi18n\hbi18n.hbp" + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN -shared "-o%HB_BIN_INSTALL%\hbformat-dll" "%~dp0..\utils\hbformat\hbformat.hbp" ) endlocal @@ -64,10 +64,10 @@ goto INST_%HB_ARCHITECTURE% rem ; We build this here, because GNU Make wouldn't add the icon. setlocal if "%HB_BIN_COMPILE%" == "" set HB_BIN_COMPILE=%HB_BIN_INSTALL% - %HB_BIN_COMPILE%\hbmk2 -q0 -lng=en-EN -o%HB_BIN_INSTALL%\hbrun %~dp0..\utils\hbrun\hbrun.hbp + "%HB_BIN_COMPILE%\hbmk2" -q0 -lng=en-EN "-o%HB_BIN_INSTALL%\hbrun" "%~dp0..\utils\hbrun\hbrun.hbp" endlocal - if "%HB_BUILD_IMPLIB%" == "yes" call %~dp0hb-mkimp.bat + if "%HB_BUILD_IMPLIB%" == "yes" call "%~dp0hb-mkimp.bat" goto END diff --git a/harbour/config/globsh.cf b/harbour/config/globsh.cf index dcbfeafc98..dd544e14ea 100644 --- a/harbour/config/globsh.cf +++ b/harbour/config/globsh.cf @@ -49,7 +49,7 @@ endif ifeq ($(HB_SHELL),nt) -MK = $(subst \,/,$(subst \~,~,$(MAKE))) +MK = "$(subst \,/,$(subst \~,~,$(MAKE)))" RM = del /q /f RDP = rmdir /q /s CP = $(CMDPREF)copy diff --git a/harbour/contrib/hbssl/Makefile b/harbour/contrib/hbssl/Makefile index 4c711c73a8..fb7768e05d 100644 --- a/harbour/contrib/hbssl/Makefile +++ b/harbour/contrib/hbssl/Makefile @@ -27,6 +27,9 @@ HB_USER_CFLAGS += $(foreach d, $(HB_INC_OPENSSL_OK), -I$(d)) C_SOURCES=\ hbssl.c \ + evp.c \ + evpciph.c \ + evpmd.c \ ssl.c \ sslbio.c \ sslciph.c \ diff --git a/harbour/contrib/hbssl/evp.c b/harbour/contrib/hbssl/evp.c new file mode 100644 index 0000000000..18b7167a3e --- /dev/null +++ b/harbour/contrib/hbssl/evp.c @@ -0,0 +1,71 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * OpenSSL API (EVP) - Harbour interface. + * + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" + +#include + +HB_FUNC( OPENSSL_ADD_ALL_ALGORITHMS ) +{ + OpenSSL_add_all_algorithms(); +} + +HB_FUNC( EVP_CLEANUP ) +{ + EVP_cleanup(); +} + +#if 0 + +int EVP_PKEY_size(EVP_PKEY *pkey); + +#endif diff --git a/harbour/contrib/hbssl/evpciph.c b/harbour/contrib/hbssl/evpciph.c new file mode 100644 index 0000000000..5137c2ab93 --- /dev/null +++ b/harbour/contrib/hbssl/evpciph.c @@ -0,0 +1,893 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * OpenSSL API (EVP CIPHER) - Harbour interface. + * + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapierr.h" +#include "hbapiitm.h" + +#include "hbssl.ch" + +#include + +HB_FUNC( OPENSSL_ADD_ALL_CIPHERS ) +{ + OpenSSL_add_all_ciphers(); +} + +static HB_GARBAGE_FUNC( EVP_CIPHER_CTX_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && * ph ) + { + /* Destroy the object */ + hb_xfree( * ph ); + + /* set pointer to NULL just in case */ + * ph = NULL; + } +} + +static void * hb_EVP_CIPHER_CTX_is( int iParam ) +{ + return hb_parptrGC( EVP_CIPHER_CTX_release, iParam ); +} + +static EVP_CIPHER_CTX * hb_EVP_CIPHER_CTX_par( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( EVP_CIPHER_CTX_release, iParam ); + + return ph ? ( EVP_CIPHER_CTX * ) * ph : NULL; +} + +static BOOL hb_EVP_CIPHER_is( int p ) +{ + return HB_ISCHAR( p ) || HB_ISNUM( p ); +} + +static const EVP_CIPHER * hb_EVP_CIPHER_par( int p ) +{ + const EVP_CIPHER * method; + + if( HB_ISCHAR( p ) ) + return EVP_get_cipherbyname( hb_parc( p ) ); + + switch( hb_parni( p ) ) + { + case HB_EVP_CIPHER_ENC_NULL : method = EVP_enc_null(); break; +#ifndef OPENSSL_NO_DES + case HB_EVP_CIPHER_DES_ECB : method = EVP_des_ecb(); break; + case HB_EVP_CIPHER_DES_EDE : method = EVP_des_ede(); break; + case HB_EVP_CIPHER_DES_EDE3 : method = EVP_des_ede3(); break; + case HB_EVP_CIPHER_DES_EDE_ECB : method = EVP_des_ede_ecb(); break; + case HB_EVP_CIPHER_DES_EDE3_ECB : method = EVP_des_ede3_ecb(); break; + case HB_EVP_CIPHER_DES_CFB64 : method = EVP_des_cfb64(); break; + case HB_EVP_CIPHER_DES_CFB : method = EVP_des_cfb(); break; + case HB_EVP_CIPHER_DES_CFB1 : method = EVP_des_cfb1(); break; + case HB_EVP_CIPHER_DES_CFB8 : method = EVP_des_cfb8(); break; + case HB_EVP_CIPHER_DES_EDE_CFB64 : method = EVP_des_ede_cfb64(); break; + case HB_EVP_CIPHER_DES_EDE_CFB : method = EVP_des_ede_cfb(); break; + case HB_EVP_CIPHER_DES_EDE3_CFB64 : method = EVP_des_ede3_cfb64(); break; + case HB_EVP_CIPHER_DES_EDE3_CFB : method = EVP_des_ede3_cfb(); break; + case HB_EVP_CIPHER_DES_EDE3_CFB1 : method = EVP_des_ede3_cfb1(); break; + case HB_EVP_CIPHER_DES_EDE3_CFB8 : method = EVP_des_ede3_cfb8(); break; + case HB_EVP_CIPHER_DES_OFB : method = EVP_des_ofb(); break; + case HB_EVP_CIPHER_DES_EDE_OFB : method = EVP_des_ede_ofb(); break; + case HB_EVP_CIPHER_DES_EDE3_OFB : method = EVP_des_ede3_ofb(); break; + case HB_EVP_CIPHER_DES_CBC : method = EVP_des_cbc(); break; + case HB_EVP_CIPHER_DES_EDE_CBC : method = EVP_des_ede_cbc(); break; + case HB_EVP_CIPHER_DES_EDE3_CBC : method = EVP_des_ede3_cbc(); break; + case HB_EVP_CIPHER_DESX_CBC : method = EVP_desx_cbc(); break; +#endif +#ifndef OPENSSL_NO_RC4 + case HB_EVP_CIPHER_RC4 : method = EVP_rc4(); break; + case HB_EVP_CIPHER_RC4_40 : method = EVP_rc4_40(); break; +#endif +#ifndef OPENSSL_NO_IDEA + case HB_EVP_CIPHER_IDEA_ECB : method = EVP_idea_ecb(); break; + case HB_EVP_CIPHER_IDEA_CFB64 : method = EVP_idea_cfb64(); break; + case HB_EVP_CIPHER_IDEA_CFB : method = EVP_idea_cfb(); break; + case HB_EVP_CIPHER_IDEA_OFB : method = EVP_idea_ofb(); break; + case HB_EVP_CIPHER_IDEA_CBC : method = EVP_idea_cbc(); break; +#endif +#ifndef OPENSSL_NO_RC2 + case HB_EVP_CIPHER_RC2_ECB : method = EVP_rc2_ecb(); break; + case HB_EVP_CIPHER_RC2_CBC : method = EVP_rc2_cbc(); break; + case HB_EVP_CIPHER_RC2_40_CBC : method = EVP_rc2_40_cbc(); break; + case HB_EVP_CIPHER_RC2_64_CBC : method = EVP_rc2_64_cbc(); break; + case HB_EVP_CIPHER_RC2_CFB64 : method = EVP_rc2_cfb64(); break; + case HB_EVP_CIPHER_RC2_CFB : method = EVP_rc2_cfb(); break; + case HB_EVP_CIPHER_RC2_OFB : method = EVP_rc2_ofb(); break; +#endif +#ifndef OPENSSL_NO_BF + case HB_EVP_CIPHER_BF_ECB : method = EVP_bf_ecb(); break; + case HB_EVP_CIPHER_BF_CBC : method = EVP_bf_cbc(); break; + case HB_EVP_CIPHER_BF_CFB64 : method = EVP_bf_cfb64(); break; + case HB_EVP_CIPHER_BF_CFB : method = EVP_bf_cfb(); break; + case HB_EVP_CIPHER_BF_OFB : method = EVP_bf_ofb(); break; +#endif +#ifndef OPENSSL_NO_CAST + case HB_EVP_CIPHER_CAST5_ECB : method = EVP_cast5_ecb(); break; + case HB_EVP_CIPHER_CAST5_CBC : method = EVP_cast5_cbc(); break; + case HB_EVP_CIPHER_CAST5_CFB64 : method = EVP_cast5_cfb64(); break; + case HB_EVP_CIPHER_CAST5_CFB : method = EVP_cast5_cfb(); break; + case HB_EVP_CIPHER_CAST5_OFB : method = EVP_cast5_ofb(); break; +#endif +#ifndef OPENSSL_NO_RC5 + case HB_EVP_CIPHER_RC5_32_12_16_CBC : method = EVP_rc5_32_12_16_cbc(); break; + case HB_EVP_CIPHER_RC5_32_12_16_ECB : method = EVP_rc5_32_12_16_ecb(); break; + case HB_EVP_CIPHER_RC5_32_12_16_CFB64 : method = EVP_rc5_32_12_16_cfb64(); break; + case HB_EVP_CIPHER_RC5_32_12_16_CFB : method = EVP_rc5_32_12_16_cfb(); break; + case HB_EVP_CIPHER_RC5_32_12_16_OFB : method = EVP_rc5_32_12_16_ofb(); break; +#endif +#ifndef OPENSSL_NO_AES + case HB_EVP_CIPHER_AES_128_ECB : method = EVP_aes_128_ecb(); break; + case HB_EVP_CIPHER_AES_128_CBC : method = EVP_aes_128_cbc(); break; + case HB_EVP_CIPHER_AES_128_CFB1 : method = EVP_aes_128_cfb1(); break; + case HB_EVP_CIPHER_AES_128_CFB8 : method = EVP_aes_128_cfb8(); break; + case HB_EVP_CIPHER_AES_128_CFB128 : method = EVP_aes_128_cfb128(); break; + case HB_EVP_CIPHER_AES_128_CFB : method = EVP_aes_128_cfb(); break; + case HB_EVP_CIPHER_AES_128_OFB : method = EVP_aes_128_ofb(); break; + case HB_EVP_CIPHER_AES_192_ECB : method = EVP_aes_192_ecb(); break; + case HB_EVP_CIPHER_AES_192_CBC : method = EVP_aes_192_cbc(); break; + case HB_EVP_CIPHER_AES_192_CFB1 : method = EVP_aes_192_cfb1(); break; + case HB_EVP_CIPHER_AES_192_CFB8 : method = EVP_aes_192_cfb8(); break; + case HB_EVP_CIPHER_AES_192_CFB128 : method = EVP_aes_192_cfb128(); break; + case HB_EVP_CIPHER_AES_192_CFB : method = EVP_aes_192_cfb(); break; + case HB_EVP_CIPHER_AES_192_OFB : method = EVP_aes_192_ofb(); break; + case HB_EVP_CIPHER_AES_256_ECB : method = EVP_aes_256_ecb(); break; + case HB_EVP_CIPHER_AES_256_CBC : method = EVP_aes_256_cbc(); break; + case HB_EVP_CIPHER_AES_256_CFB1 : method = EVP_aes_256_cfb1(); break; + case HB_EVP_CIPHER_AES_256_CFB8 : method = EVP_aes_256_cfb8(); break; + case HB_EVP_CIPHER_AES_256_CFB128 : method = EVP_aes_256_cfb128(); break; + case HB_EVP_CIPHER_AES_256_CFB : method = EVP_aes_256_cfb(); break; + case HB_EVP_CIPHER_AES_256_OFB : method = EVP_aes_256_ofb(); break; +#endif +#ifndef OPENSSL_NO_CAMELLIA + case HB_EVP_CIPHER_CAMELLIA_128_ECB : method = EVP_camellia_128_ecb(); break; + case HB_EVP_CIPHER_CAMELLIA_128_CBC : method = EVP_camellia_128_cbc(); break; + case HB_EVP_CIPHER_CAMELLIA_128_CFB1 : method = EVP_camellia_128_cfb1(); break; + case HB_EVP_CIPHER_CAMELLIA_128_CFB8 : method = EVP_camellia_128_cfb8(); break; + case HB_EVP_CIPHER_CAMELLIA_128_CFB128 : method = EVP_camellia_128_cfb128(); break; + case HB_EVP_CIPHER_CAMELLIA_128_CFB : method = EVP_camellia_128_cfb(); break; + case HB_EVP_CIPHER_CAMELLIA_128_OFB : method = EVP_camellia_128_ofb(); break; + case HB_EVP_CIPHER_CAMELLIA_192_ECB : method = EVP_camellia_192_ecb(); break; + case HB_EVP_CIPHER_CAMELLIA_192_CBC : method = EVP_camellia_192_cbc(); break; + case HB_EVP_CIPHER_CAMELLIA_192_CFB1 : method = EVP_camellia_192_cfb1(); break; + case HB_EVP_CIPHER_CAMELLIA_192_CFB8 : method = EVP_camellia_192_cfb8(); break; + case HB_EVP_CIPHER_CAMELLIA_192_CFB128 : method = EVP_camellia_192_cfb128(); break; + case HB_EVP_CIPHER_CAMELLIA_192_CFB : method = EVP_camellia_192_cfb(); break; + case HB_EVP_CIPHER_CAMELLIA_192_OFB : method = EVP_camellia_192_ofb(); break; + case HB_EVP_CIPHER_CAMELLIA_256_ECB : method = EVP_camellia_256_ecb(); break; + case HB_EVP_CIPHER_CAMELLIA_256_CBC : method = EVP_camellia_256_cbc(); break; + case HB_EVP_CIPHER_CAMELLIA_256_CFB1 : method = EVP_camellia_256_cfb1(); break; + case HB_EVP_CIPHER_CAMELLIA_256_CFB8 : method = EVP_camellia_256_cfb8(); break; + case HB_EVP_CIPHER_CAMELLIA_256_CFB128 : method = EVP_camellia_256_cfb128(); break; + case HB_EVP_CIPHER_CAMELLIA_256_CFB : method = EVP_camellia_256_cfb(); break; + case HB_EVP_CIPHER_CAMELLIA_256_OFB : method = EVP_camellia_256_ofb(); break; +#endif +#ifndef OPENSSL_NO_SEED + case HB_EVP_CIPHER_SEED_ECB : method = EVP_seed_ecb(); break; + case HB_EVP_CIPHER_SEED_CBC : method = EVP_seed_cbc(); break; + case HB_EVP_CIPHER_SEED_CFB128 : method = EVP_seed_cfb128(); break; + case HB_EVP_CIPHER_SEED_CFB : method = EVP_seed_cfb(); break; + case HB_EVP_CIPHER_SEED_OFB : method = EVP_seed_ofb(); break; +#endif + default : method = NULL; + } + + return method; +} + +static int hb_EVP_CIPHER_ptr_to_id( const EVP_CIPHER * method ) +{ + int n; + + if( method == EVP_enc_null() ) n = HB_EVP_CIPHER_ENC_NULL; +#ifndef OPENSSL_NO_DES + else if( method == EVP_des_ecb() ) n = HB_EVP_CIPHER_DES_ECB; + else if( method == EVP_des_ede() ) n = HB_EVP_CIPHER_DES_EDE; + else if( method == EVP_des_ede3() ) n = HB_EVP_CIPHER_DES_EDE3; + else if( method == EVP_des_ede_ecb() ) n = HB_EVP_CIPHER_DES_EDE_ECB; + else if( method == EVP_des_ede3_ecb() ) n = HB_EVP_CIPHER_DES_EDE3_ECB; + else if( method == EVP_des_cfb64() ) n = HB_EVP_CIPHER_DES_CFB64; + else if( method == EVP_des_cfb() ) n = HB_EVP_CIPHER_DES_CFB; + else if( method == EVP_des_cfb1() ) n = HB_EVP_CIPHER_DES_CFB1; + else if( method == EVP_des_cfb8() ) n = HB_EVP_CIPHER_DES_CFB8; + else if( method == EVP_des_ede_cfb64() ) n = HB_EVP_CIPHER_DES_EDE_CFB64; + else if( method == EVP_des_ede_cfb() ) n = HB_EVP_CIPHER_DES_EDE_CFB; + else if( method == EVP_des_ede3_cfb64() ) n = HB_EVP_CIPHER_DES_EDE3_CFB64; + else if( method == EVP_des_ede3_cfb() ) n = HB_EVP_CIPHER_DES_EDE3_CFB; + else if( method == EVP_des_ede3_cfb1() ) n = HB_EVP_CIPHER_DES_EDE3_CFB1; + else if( method == EVP_des_ede3_cfb8() ) n = HB_EVP_CIPHER_DES_EDE3_CFB8; + else if( method == EVP_des_ofb() ) n = HB_EVP_CIPHER_DES_OFB; + else if( method == EVP_des_ede_ofb() ) n = HB_EVP_CIPHER_DES_EDE_OFB; + else if( method == EVP_des_ede3_ofb() ) n = HB_EVP_CIPHER_DES_EDE3_OFB; + else if( method == EVP_des_cbc() ) n = HB_EVP_CIPHER_DES_CBC; + else if( method == EVP_des_ede_cbc() ) n = HB_EVP_CIPHER_DES_EDE_CBC; + else if( method == EVP_des_ede3_cbc() ) n = HB_EVP_CIPHER_DES_EDE3_CBC; + else if( method == EVP_desx_cbc() ) n = HB_EVP_CIPHER_DESX_CBC; +#endif +#ifndef OPENSSL_NO_RC4 + else if( method == EVP_rc4() ) n = HB_EVP_CIPHER_RC4; + else if( method == EVP_rc4_40() ) n = HB_EVP_CIPHER_RC4_40; +#endif +#ifndef OPENSSL_NO_IDEA + else if( method == EVP_idea_ecb() ) n = HB_EVP_CIPHER_IDEA_ECB; + else if( method == EVP_idea_cfb64() ) n = HB_EVP_CIPHER_IDEA_CFB64; + else if( method == EVP_idea_cfb() ) n = HB_EVP_CIPHER_IDEA_CFB; + else if( method == EVP_idea_ofb() ) n = HB_EVP_CIPHER_IDEA_OFB; + else if( method == EVP_idea_cbc() ) n = HB_EVP_CIPHER_IDEA_CBC; +#endif +#ifndef OPENSSL_NO_RC2 + else if( method == EVP_rc2_ecb() ) n = HB_EVP_CIPHER_RC2_ECB; + else if( method == EVP_rc2_cbc() ) n = HB_EVP_CIPHER_RC2_CBC; + else if( method == EVP_rc2_40_cbc() ) n = HB_EVP_CIPHER_RC2_40_CBC; + else if( method == EVP_rc2_64_cbc() ) n = HB_EVP_CIPHER_RC2_64_CBC; + else if( method == EVP_rc2_cfb64() ) n = HB_EVP_CIPHER_RC2_CFB64; + else if( method == EVP_rc2_cfb() ) n = HB_EVP_CIPHER_RC2_CFB; + else if( method == EVP_rc2_ofb() ) n = HB_EVP_CIPHER_RC2_OFB; +#endif +#ifndef OPENSSL_NO_BF + else if( method == EVP_bf_ecb() ) n = HB_EVP_CIPHER_BF_ECB; + else if( method == EVP_bf_cbc() ) n = HB_EVP_CIPHER_BF_CBC; + else if( method == EVP_bf_cfb64() ) n = HB_EVP_CIPHER_BF_CFB64; + else if( method == EVP_bf_cfb() ) n = HB_EVP_CIPHER_BF_CFB; + else if( method == EVP_bf_ofb() ) n = HB_EVP_CIPHER_BF_OFB; +#endif +#ifndef OPENSSL_NO_CAST + else if( method == EVP_cast5_ecb() ) n = HB_EVP_CIPHER_CAST5_ECB; + else if( method == EVP_cast5_cbc() ) n = HB_EVP_CIPHER_CAST5_CBC; + else if( method == EVP_cast5_cfb64() ) n = HB_EVP_CIPHER_CAST5_CFB64; + else if( method == EVP_cast5_cfb() ) n = HB_EVP_CIPHER_CAST5_CFB; + else if( method == EVP_cast5_ofb() ) n = HB_EVP_CIPHER_CAST5_OFB; +#endif +#ifndef OPENSSL_NO_RC5 + else if( method == EVP_rc5_32_12_16_cbc() ) n = HB_EVP_CIPHER_RC5_32_12_16_CBC; + else if( method == EVP_rc5_32_12_16_ecb() ) n = HB_EVP_CIPHER_RC5_32_12_16_ECB; + else if( method == EVP_rc5_32_12_16_cfb64() ) n = HB_EVP_CIPHER_RC5_32_12_16_CFB64; + else if( method == EVP_rc5_32_12_16_cfb() ) n = HB_EVP_CIPHER_RC5_32_12_16_CFB; + else if( method == EVP_rc5_32_12_16_ofb() ) n = HB_EVP_CIPHER_RC5_32_12_16_OFB; +#endif +#ifndef OPENSSL_NO_AES + else if( method == EVP_aes_128_ecb() ) n = HB_EVP_CIPHER_AES_128_ECB; + else if( method == EVP_aes_128_cbc() ) n = HB_EVP_CIPHER_AES_128_CBC; + else if( method == EVP_aes_128_cfb1() ) n = HB_EVP_CIPHER_AES_128_CFB1; + else if( method == EVP_aes_128_cfb8() ) n = HB_EVP_CIPHER_AES_128_CFB8; + else if( method == EVP_aes_128_cfb128() ) n = HB_EVP_CIPHER_AES_128_CFB128; + else if( method == EVP_aes_128_cfb() ) n = HB_EVP_CIPHER_AES_128_CFB; + else if( method == EVP_aes_128_ofb() ) n = HB_EVP_CIPHER_AES_128_OFB; + else if( method == EVP_aes_192_ecb() ) n = HB_EVP_CIPHER_AES_192_ECB; + else if( method == EVP_aes_192_cbc() ) n = HB_EVP_CIPHER_AES_192_CBC; + else if( method == EVP_aes_192_cfb1() ) n = HB_EVP_CIPHER_AES_192_CFB1; + else if( method == EVP_aes_192_cfb8() ) n = HB_EVP_CIPHER_AES_192_CFB8; + else if( method == EVP_aes_192_cfb128() ) n = HB_EVP_CIPHER_AES_192_CFB128; + else if( method == EVP_aes_192_cfb() ) n = HB_EVP_CIPHER_AES_192_CFB; + else if( method == EVP_aes_192_ofb() ) n = HB_EVP_CIPHER_AES_192_OFB; + else if( method == EVP_aes_256_ecb() ) n = HB_EVP_CIPHER_AES_256_ECB; + else if( method == EVP_aes_256_cbc() ) n = HB_EVP_CIPHER_AES_256_CBC; + else if( method == EVP_aes_256_cfb1() ) n = HB_EVP_CIPHER_AES_256_CFB1; + else if( method == EVP_aes_256_cfb8() ) n = HB_EVP_CIPHER_AES_256_CFB8; + else if( method == EVP_aes_256_cfb128() ) n = HB_EVP_CIPHER_AES_256_CFB128; + else if( method == EVP_aes_256_cfb() ) n = HB_EVP_CIPHER_AES_256_CFB; + else if( method == EVP_aes_256_ofb() ) n = HB_EVP_CIPHER_AES_256_OFB; +#endif +#ifndef OPENSSL_NO_CAMELLIA + else if( method == EVP_camellia_128_ecb() ) n = HB_EVP_CIPHER_CAMELLIA_128_ECB; + else if( method == EVP_camellia_128_cbc() ) n = HB_EVP_CIPHER_CAMELLIA_128_CBC; + else if( method == EVP_camellia_128_cfb1() ) n = HB_EVP_CIPHER_CAMELLIA_128_CFB1; + else if( method == EVP_camellia_128_cfb8() ) n = HB_EVP_CIPHER_CAMELLIA_128_CFB8; + else if( method == EVP_camellia_128_cfb128() ) n = HB_EVP_CIPHER_CAMELLIA_128_CFB128; + else if( method == EVP_camellia_128_cfb() ) n = HB_EVP_CIPHER_CAMELLIA_128_CFB; + else if( method == EVP_camellia_128_ofb() ) n = HB_EVP_CIPHER_CAMELLIA_128_OFB; + else if( method == EVP_camellia_192_ecb() ) n = HB_EVP_CIPHER_CAMELLIA_192_ECB; + else if( method == EVP_camellia_192_cbc() ) n = HB_EVP_CIPHER_CAMELLIA_192_CBC; + else if( method == EVP_camellia_192_cfb1() ) n = HB_EVP_CIPHER_CAMELLIA_192_CFB1; + else if( method == EVP_camellia_192_cfb8() ) n = HB_EVP_CIPHER_CAMELLIA_192_CFB8; + else if( method == EVP_camellia_192_cfb128() ) n = HB_EVP_CIPHER_CAMELLIA_192_CFB128; + else if( method == EVP_camellia_192_cfb() ) n = HB_EVP_CIPHER_CAMELLIA_192_CFB; + else if( method == EVP_camellia_192_ofb() ) n = HB_EVP_CIPHER_CAMELLIA_192_OFB; + else if( method == EVP_camellia_256_ecb() ) n = HB_EVP_CIPHER_CAMELLIA_256_ECB; + else if( method == EVP_camellia_256_cbc() ) n = HB_EVP_CIPHER_CAMELLIA_256_CBC; + else if( method == EVP_camellia_256_cfb1() ) n = HB_EVP_CIPHER_CAMELLIA_256_CFB1; + else if( method == EVP_camellia_256_cfb8() ) n = HB_EVP_CIPHER_CAMELLIA_256_CFB8; + else if( method == EVP_camellia_256_cfb128() ) n = HB_EVP_CIPHER_CAMELLIA_256_CFB128; + else if( method == EVP_camellia_256_cfb() ) n = HB_EVP_CIPHER_CAMELLIA_256_CFB; + else if( method == EVP_camellia_256_ofb() ) n = HB_EVP_CIPHER_CAMELLIA_256_OFB; +#endif +#ifndef OPENSSL_NO_SEED + else if( method == EVP_seed_ecb() ) n = HB_EVP_CIPHER_SEED_ECB; + else if( method == EVP_seed_cbc() ) n = HB_EVP_CIPHER_SEED_CBC; + else if( method == EVP_seed_cfb128() ) n = HB_EVP_CIPHER_SEED_CFB128; + else if( method == EVP_seed_cfb() ) n = HB_EVP_CIPHER_SEED_CFB; + else if( method == EVP_seed_ofb() ) n = HB_EVP_CIPHER_SEED_OFB; +#endif + else n = HB_EVP_CIPHER_UNSUPPORTED; + + return n; +} + +HB_FUNC( EVP_GET_CIPHERBYNAME ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retni( hb_EVP_CIPHER_ptr_to_id( EVP_get_cipherbyname( hb_parc( 1 ) ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_GET_CIPHERBYNID ) +{ + if( HB_ISNUM( 1 ) ) + hb_retni( hb_EVP_CIPHER_ptr_to_id( EVP_get_cipherbynid( hb_parni( 1 ) ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_NID ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_nid( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_BLOCK_SIZE ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_block_size( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_KEY_LENGTH ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_key_length( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_KEY_IV_LENGTH ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_iv_length( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_KEY_FLAGS ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retnint( method ? EVP_CIPHER_flags( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_KEY_MODE ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_mode( method ) : 0 ); +} + +HB_FUNC( EVP_CIPHER_TYPE ) +{ + const EVP_CIPHER * method = hb_EVP_CIPHER_par( 1 ); + + hb_retni( method ? EVP_CIPHER_type( method ) : 0 ); +} + +HB_FUNC( HB_EVP_CIPHER_CTX_CREATE ) +{ + void ** ph = ( void ** ) hb_gcAlloc( sizeof( EVP_CIPHER_CTX * ), EVP_CIPHER_CTX_release ); + + EVP_CIPHER_CTX * ctx = ( EVP_CIPHER_CTX * ) hb_xgrab( sizeof( EVP_CIPHER_CTX ) ); + + * ph = ( void * ) ctx; + + hb_retptrGC( ph ); +} + +HB_FUNC( EVP_CIPHER_CTX_INIT ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + EVP_CIPHER_CTX_init( ctx ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_CLEANUP ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CIPHER_CTX_cleanup( ctx ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_SET_PADDING ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CIPHER_CTX_set_padding( ctx, hb_parni( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_KEY_LENGTH ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CIPHER_CTX_key_length( ctx ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_SET_KEY_LENGTH ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CIPHER_CTX_set_key_length( ctx, hb_parni( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_CTRL ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + /* NOTE: 4th param doesn't have a 'const' qualifier. This is a setter + function, so even if we do a copy, what sort of allocation + routines to use? Probably an omission from OpenSSLs part. [vszakats] */ + hb_retni( EVP_CIPHER_CTX_ctrl( ctx, hb_parni( 2 ), hb_parni( 3 ), ( void * ) hb_parc( 4 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHER_CTX_CIPHER ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( hb_EVP_CIPHER_ptr_to_id( EVP_CIPHER_CTX_cipher( ctx ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_ENCRYPTINIT ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_EncryptInit( ctx, + hb_EVP_CIPHER_par( 2 ), + ( const unsigned char * ) hb_parc( 3 ), + ( const unsigned char * ) hb_parc( 4 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_ENCRYPTINIT_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_EncryptInit_ex( ctx, + hb_EVP_CIPHER_par( 2 ), + ( ENGINE * ) hb_parptr( 3 ), + ( const unsigned char * ) hb_parc( 4 ), + ( const unsigned char * ) hb_parc( 5 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_ENCRYPTUPDATE ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( hb_parclen( 3 ) + EVP_CIPHER_CTX_block_size( ctx ) - 1 ); + int size = 0; + + hb_retni( EVP_EncryptUpdate( ctx, + buffer, + &size, + ( const unsigned char * ) hb_parcx( 3 ), + ( size_t ) hb_parclen( 3 ) ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_ENCRYPTFINAL ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_EncryptFinal( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_ENCRYPTFINAL_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_EncryptFinal_ex( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DECRYPTINIT ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_DecryptInit( ctx, + hb_EVP_CIPHER_par( 2 ), + ( const unsigned char * ) hb_parc( 3 ), + ( const unsigned char * ) hb_parc( 4 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DECRYPTINIT_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_DecryptInit_ex( ctx, + hb_EVP_CIPHER_par( 2 ), + ( ENGINE * ) hb_parptr( 3 ), + ( const unsigned char * ) hb_parc( 4 ), + ( const unsigned char * ) hb_parc( 5 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DECRYPTUPDATE ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( hb_parclen( 3 ) + EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_DecryptUpdate( ctx, + buffer, + &size, + ( const unsigned char * ) hb_parcx( 3 ), + ( size_t ) hb_parclen( 3 ) ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DECRYPTFINAL ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_DecryptFinal( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DECRYPTFINAL_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_DecryptFinal_ex( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHERINIT ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CipherInit( ctx, + hb_EVP_CIPHER_par( 2 ), + ( const unsigned char * ) hb_parc( 3 ), + ( const unsigned char * ) hb_parc( 4 ), + hb_parni( 5 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHERINIT_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) && hb_EVP_CIPHER_is( 2 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_CipherInit_ex( ctx, + hb_EVP_CIPHER_par( 2 ), + ( ENGINE * ) hb_parptr( 3 ), + ( const unsigned char * ) hb_parc( 4 ), + ( const unsigned char * ) hb_parc( 5 ), + hb_parni( 6 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHERUPDATE ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( hb_parclen( 3 ) + EVP_CIPHER_CTX_block_size( ctx ) - 1 ); + int size = 0; + + hb_retni( EVP_CipherUpdate( ctx, + buffer, + &size, + ( const unsigned char * ) hb_parcx( 3 ), + ( size_t ) hb_parclen( 3 ) ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHERFINAL ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_CipherFinal( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_CIPHERFINAL_EX ) +{ + if( hb_EVP_CIPHER_CTX_is( 1 ) ) + { + EVP_CIPHER_CTX * ctx = hb_EVP_CIPHER_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_CIPHER_CTX_block_size( ctx ) ); + int size = 0; + + hb_retni( EVP_CipherFinal_ex( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +#if 0 + +#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) +#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) + +int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, int ekl,unsigned char *iv,EVP_PKEY *priv); +int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); +int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk); +int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); +int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +#endif diff --git a/harbour/contrib/hbssl/evpmd.c b/harbour/contrib/hbssl/evpmd.c new file mode 100644 index 0000000000..b623b91f01 --- /dev/null +++ b/harbour/contrib/hbssl/evpmd.c @@ -0,0 +1,487 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * OpenSSL API (EVP MD) - Harbour interface. + * + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapierr.h" +#include "hbapiitm.h" + +#include "hbssl.ch" + +#include + +HB_FUNC( OPENSSL_ADD_ALL_DIGESTS ) +{ + OpenSSL_add_all_digests(); +} + +static HB_GARBAGE_FUNC( EVP_MD_CTX_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && * ph ) + { + /* Destroy the object */ + EVP_MD_CTX_destroy( ( EVP_MD_CTX * ) * ph ); + + /* set pointer to NULL just in case */ + * ph = NULL; + } +} + +static void * hb_EVP_MD_CTX_is( int iParam ) +{ + return hb_parptrGC( EVP_MD_CTX_release, iParam ); +} + +static EVP_MD_CTX * hb_EVP_MD_CTX_par( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( EVP_MD_CTX_release, iParam ); + + return ph ? ( EVP_MD_CTX * ) * ph : NULL; +} + +static BOOL hb_EVP_MD_is( int p ) +{ + return HB_ISCHAR( p ) || HB_ISNUM( p ); +} + +static const EVP_MD * hb_EVP_MD_par( int p ) +{ + const EVP_MD * method; + + if( HB_ISCHAR( p ) ) + return EVP_get_digestbyname( hb_parc( p ) ); + + switch( hb_parni( p ) ) + { + case HB_EVP_MD_MD_NULL : method = EVP_md_null(); break; +#ifndef OPENSSL_NO_MD2 + case HB_EVP_MD_MD2 : method = EVP_md2(); break; +#endif +#ifndef OPENSSL_NO_MD4 + case HB_EVP_MD_MD4 : method = EVP_md4(); break; +#endif +#ifndef OPENSSL_NO_MD5 + case HB_EVP_MD_MD5 : method = EVP_md5(); break; +#endif +#ifndef OPENSSL_NO_SHA + case HB_EVP_MD_SHA : method = EVP_sha(); break; + case HB_EVP_MD_SHA1 : method = EVP_sha1(); break; + case HB_EVP_MD_DSS : method = EVP_dss(); break; + case HB_EVP_MD_DSS1 : method = EVP_dss1(); break; + case HB_EVP_MD_ECDSA : method = EVP_ecdsa(); break; +#endif +#ifndef OPENSSL_NO_SHA256 + case HB_EVP_MD_SHA224 : method = EVP_sha224(); break; + case HB_EVP_MD_SHA256 : method = EVP_sha256(); break; +#endif +#ifndef OPENSSL_NO_SHA512 + case HB_EVP_MD_SHA384 : method = EVP_sha384(); break; + case HB_EVP_MD_SHA512 : method = EVP_sha512(); break; +#endif +#ifndef OPENSSL_NO_MDC2 + case HB_EVP_MD_MDC2 : method = EVP_mdc2(); break; +#endif +#ifndef OPENSSL_NO_RIPEMD + case HB_EVP_MD_RIPEMD160 : method = EVP_ripemd160(); break; +#endif + default : method = NULL; + } + + return method; +} + +static int hb_EVP_MD_ptr_to_id( const EVP_MD * method ) +{ + int n; + + if( method == EVP_md_null() ) n = HB_EVP_MD_MD_NULL; +#ifndef OPENSSL_NO_MD2 + else if( method == EVP_md2() ) n = HB_EVP_MD_MD2; +#endif +#ifndef OPENSSL_NO_MD4 + else if( method == EVP_md4() ) n = HB_EVP_MD_MD4; +#endif +#ifndef OPENSSL_NO_MD5 + else if( method == EVP_md5() ) n = HB_EVP_MD_MD5; +#endif +#ifndef OPENSSL_NO_SHA + else if( method == EVP_sha() ) n = HB_EVP_MD_SHA; + else if( method == EVP_sha1() ) n = HB_EVP_MD_SHA1; + else if( method == EVP_dss() ) n = HB_EVP_MD_DSS; + else if( method == EVP_dss1() ) n = HB_EVP_MD_DSS1; + else if( method == EVP_ecdsa() ) n = HB_EVP_MD_ECDSA; +#endif +#ifndef OPENSSL_NO_SHA256 + else if( method == EVP_sha224() ) n = HB_EVP_MD_SHA224; + else if( method == EVP_sha256() ) n = HB_EVP_MD_SHA256; +#endif +#ifndef OPENSSL_NO_SHA512 + else if( method == EVP_sha384() ) n = HB_EVP_MD_SHA384; + else if( method == EVP_sha512() ) n = HB_EVP_MD_SHA512; +#endif +#ifndef OPENSSL_NO_MDC2 + else if( method == EVP_mdc2() ) n = HB_EVP_MD_MDC2; +#endif +#ifndef OPENSSL_NO_RIPEMD + else if( method == EVP_ripemd160() ) n = HB_EVP_MD_RIPEMD160; +#endif + else n = HB_EVP_MD_UNSUPPORTED; + + return n; +} + +HB_FUNC( EVP_GET_DIGESTBYNAME ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retni( hb_EVP_MD_ptr_to_id( EVP_get_digestbyname( hb_parc( 1 ) ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_GET_DIGESTBYNID ) +{ + if( HB_ISNUM( 1 ) ) + hb_retni( hb_EVP_MD_ptr_to_id( EVP_get_digestbynid( hb_parni( 1 ) ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_MD_TYPE ) +{ + const EVP_MD * method = hb_EVP_MD_par( 1 ); + + hb_retni( method ? EVP_MD_type( method ) : 0 ); +} + +HB_FUNC( EVP_MD_NID ) +{ + const EVP_MD * method = hb_EVP_MD_par( 1 ); + + hb_retni( method ? EVP_MD_nid( method ) : 0 ); +} + +HB_FUNC( EVP_MD_PKEY_TYPE ) +{ + const EVP_MD * method = hb_EVP_MD_par( 1 ); + + hb_retni( method ? EVP_MD_pkey_type( method ) : 0 ); +} + +HB_FUNC( EVP_MD_SIZE ) +{ + const EVP_MD * method = hb_EVP_MD_par( 1 ); + + hb_retni( method ? EVP_MD_size( method ) : 0 ); +} + +HB_FUNC( EVP_MD_BLOCK_SIZE ) +{ + const EVP_MD * method = hb_EVP_MD_par( 1 ); + + hb_retni( method ? EVP_MD_block_size( method ) : 0 ); +} + +HB_FUNC( EVP_MD_CTX_CREATE ) +{ + void ** ph = ( void ** ) hb_gcAlloc( sizeof( EVP_MD_CTX * ), EVP_MD_CTX_release ); + + EVP_MD_CTX * ctx = EVP_MD_CTX_create(); + + * ph = ( void * ) ctx; + + hb_retptrGC( ph ); +} + +HB_FUNC( EVP_MD_CTX_INIT ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + EVP_MD_CTX_init( ctx ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_MD_CTX_CLEANUP ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_MD_CTX_cleanup( ctx ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_MD_CTX_MD ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( hb_EVP_MD_ptr_to_id( EVP_MD_CTX_md( ctx ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_MD_CTX_COPY ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_CTX_is( 2 ) ) + { + EVP_MD_CTX * ctx_out = hb_EVP_MD_CTX_par( 1 ); + EVP_MD_CTX * ctx_in = hb_EVP_MD_CTX_par( 2 ); + + if( ctx_out && ctx_in ) + hb_retni( EVP_MD_CTX_copy( ctx_out, ctx_in ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_MD_CTX_COPY_EX ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_CTX_is( 2 ) ) + { + EVP_MD_CTX * ctx_out = hb_EVP_MD_CTX_par( 1 ); + EVP_MD_CTX * ctx_in = hb_EVP_MD_CTX_par( 2 ); + + if( ctx_out && ctx_in ) + hb_retni( EVP_MD_CTX_copy_ex( ctx_out, ctx_in ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DIGESTINIT ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_DigestInit( ctx, hb_EVP_MD_par( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DIGESTINIT_EX ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_DigestInit_ex( ctx, hb_EVP_MD_par( 2 ), ( ENGINE * ) hb_parptr( 3 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DIGESTUPDATE ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_DigestUpdate( ctx, hb_parcx( 2 ), ( size_t ) hb_parclen( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DIGESTFINAL ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_MAX_MD_SIZE ); + unsigned int size = 0; + + hb_retni( EVP_DigestFinal( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, ( ULONG ) size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_DIGESTFINAL_EX ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + { + unsigned char * buffer = ( unsigned char * ) hb_xgrab( EVP_MAX_MD_SIZE ); + unsigned int size = 0; + + hb_retni( EVP_DigestFinal_ex( ctx, buffer, &size ) ); + + if( size > 0 ) + { + if( ! hb_storclen_buffer( ( char * ) buffer, ( ULONG ) size, 2 ) ) + hb_xfree( buffer ); + } + else + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_SIGNINIT ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + EVP_SignInit( ctx, hb_EVP_MD_par( 2 ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_SIGNINIT_EX ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_SignInit_ex( ctx, hb_EVP_MD_par( 2 ), ( ENGINE * ) hb_parptr( 3 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_SIGNUPDATE ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_SignUpdate( ctx, hb_parcx( 2 ), ( size_t ) hb_parclen( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_VERIFYINIT ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_VerifyInit( ctx, hb_EVP_MD_par( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_VERIFYINIT_EX ) +{ + if( hb_EVP_MD_CTX_is( 1 ) && hb_EVP_MD_is( 2 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_VerifyInit_ex( ctx, hb_EVP_MD_par( 2 ), ( ENGINE * ) hb_parptr( 3 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( EVP_VERIFYUPDATE ) +{ + if( hb_EVP_MD_CTX_is( 1 ) ) + { + EVP_MD_CTX * ctx = hb_EVP_MD_CTX_par( 1 ); + + if( ctx ) + hb_retni( EVP_VerifyUpdate( ctx, hb_parcx( 2 ), ( size_t ) hb_parclen( 2 ) ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +#if 0 + +int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey); +int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey); + +#endif diff --git a/harbour/contrib/hbssl/hbssl.ch b/harbour/contrib/hbssl/hbssl.ch index 3acd30efe7..0733ca074c 100644 --- a/harbour/contrib/hbssl/hbssl.ch +++ b/harbour/contrib/hbssl/hbssl.ch @@ -174,4 +174,122 @@ #define HB_X509_V_ERR_UNNESTED_RESOURCE 44 #define HB_X509_V_ERR_APPLICATION_VERIFICATION 50 +#define HB_EVP_MD_UNSUPPORTED -1 +#define HB_EVP_MD_MD_NULL 0 +#define HB_EVP_MD_MD2 1 +#define HB_EVP_MD_MD4 2 +#define HB_EVP_MD_MD5 3 +#define HB_EVP_MD_SHA 4 +#define HB_EVP_MD_SHA1 5 +#define HB_EVP_MD_DSS 6 +#define HB_EVP_MD_DSS1 7 +#define HB_EVP_MD_ECDSA 8 +#define HB_EVP_MD_SHA224 9 +#define HB_EVP_MD_SHA256 10 +#define HB_EVP_MD_SHA384 11 +#define HB_EVP_MD_SHA512 12 +#define HB_EVP_MD_MDC2 13 +#define HB_EVP_MD_RIPEMD160 14 + +#define HB_EVP_CIPHER_UNSUPPORTED -1 +#define HB_EVP_CIPHER_ENC_NULL 0 +#define HB_EVP_CIPHER_DES_ECB 1 +#define HB_EVP_CIPHER_DES_EDE 2 +#define HB_EVP_CIPHER_DES_EDE3 3 +#define HB_EVP_CIPHER_DES_EDE_ECB 4 +#define HB_EVP_CIPHER_DES_EDE3_ECB 5 +#define HB_EVP_CIPHER_DES_CFB64 6 +#define HB_EVP_CIPHER_DES_CFB 7 +#define HB_EVP_CIPHER_DES_CFB1 8 +#define HB_EVP_CIPHER_DES_CFB8 9 +#define HB_EVP_CIPHER_DES_EDE_CFB64 10 +#define HB_EVP_CIPHER_DES_EDE_CFB 11 +#define HB_EVP_CIPHER_DES_EDE3_CFB64 12 +#define HB_EVP_CIPHER_DES_EDE3_CFB 13 +#define HB_EVP_CIPHER_DES_EDE3_CFB1 14 +#define HB_EVP_CIPHER_DES_EDE3_CFB8 15 +#define HB_EVP_CIPHER_DES_OFB 16 +#define HB_EVP_CIPHER_DES_EDE_OFB 17 +#define HB_EVP_CIPHER_DES_EDE3_OFB 18 +#define HB_EVP_CIPHER_DES_CBC 19 +#define HB_EVP_CIPHER_DES_EDE_CBC 20 +#define HB_EVP_CIPHER_DES_EDE3_CBC 21 +#define HB_EVP_CIPHER_DESX_CBC 22 +#define HB_EVP_CIPHER_RC4 23 +#define HB_EVP_CIPHER_RC4_40 24 +#define HB_EVP_CIPHER_IDEA_ECB 25 +#define HB_EVP_CIPHER_IDEA_CFB64 26 +#define HB_EVP_CIPHER_IDEA_CFB 27 +#define HB_EVP_CIPHER_IDEA_OFB 28 +#define HB_EVP_CIPHER_IDEA_CBC 29 +#define HB_EVP_CIPHER_RC2_ECB 30 +#define HB_EVP_CIPHER_RC2_CBC 31 +#define HB_EVP_CIPHER_RC2_40_CBC 32 +#define HB_EVP_CIPHER_RC2_64_CBC 33 +#define HB_EVP_CIPHER_RC2_CFB64 34 +#define HB_EVP_CIPHER_RC2_CFB 35 +#define HB_EVP_CIPHER_RC2_OFB 36 +#define HB_EVP_CIPHER_BF_ECB 37 +#define HB_EVP_CIPHER_BF_CBC 38 +#define HB_EVP_CIPHER_BF_CFB64 39 +#define HB_EVP_CIPHER_BF_CFB 40 +#define HB_EVP_CIPHER_BF_OFB 41 +#define HB_EVP_CIPHER_CAST5_ECB 42 +#define HB_EVP_CIPHER_CAST5_CBC 43 +#define HB_EVP_CIPHER_CAST5_CFB64 44 +#define HB_EVP_CIPHER_CAST5_CFB 45 +#define HB_EVP_CIPHER_CAST5_OFB 46 +#define HB_EVP_CIPHER_RC5_32_12_16_CBC 47 +#define HB_EVP_CIPHER_RC5_32_12_16_ECB 48 +#define HB_EVP_CIPHER_RC5_32_12_16_CFB64 49 +#define HB_EVP_CIPHER_RC5_32_12_16_CFB 50 +#define HB_EVP_CIPHER_RC5_32_12_16_OFB 51 +#define HB_EVP_CIPHER_AES_128_ECB 52 +#define HB_EVP_CIPHER_AES_128_CBC 53 +#define HB_EVP_CIPHER_AES_128_CFB1 54 +#define HB_EVP_CIPHER_AES_128_CFB8 55 +#define HB_EVP_CIPHER_AES_128_CFB128 56 +#define HB_EVP_CIPHER_AES_128_CFB 57 +#define HB_EVP_CIPHER_AES_128_OFB 58 +#define HB_EVP_CIPHER_AES_192_ECB 59 +#define HB_EVP_CIPHER_AES_192_CBC 60 +#define HB_EVP_CIPHER_AES_192_CFB1 61 +#define HB_EVP_CIPHER_AES_192_CFB8 62 +#define HB_EVP_CIPHER_AES_192_CFB128 63 +#define HB_EVP_CIPHER_AES_192_CFB 64 +#define HB_EVP_CIPHER_AES_192_OFB 65 +#define HB_EVP_CIPHER_AES_256_ECB 66 +#define HB_EVP_CIPHER_AES_256_CBC 67 +#define HB_EVP_CIPHER_AES_256_CFB1 68 +#define HB_EVP_CIPHER_AES_256_CFB8 69 +#define HB_EVP_CIPHER_AES_256_CFB128 70 +#define HB_EVP_CIPHER_AES_256_CFB 71 +#define HB_EVP_CIPHER_AES_256_OFB 72 +#define HB_EVP_CIPHER_CAMELLIA_128_ECB 73 +#define HB_EVP_CIPHER_CAMELLIA_128_CBC 74 +#define HB_EVP_CIPHER_CAMELLIA_128_CFB1 75 +#define HB_EVP_CIPHER_CAMELLIA_128_CFB8 76 +#define HB_EVP_CIPHER_CAMELLIA_128_CFB128 77 +#define HB_EVP_CIPHER_CAMELLIA_128_CFB 78 +#define HB_EVP_CIPHER_CAMELLIA_128_OFB 79 +#define HB_EVP_CIPHER_CAMELLIA_192_ECB 80 +#define HB_EVP_CIPHER_CAMELLIA_192_CBC 81 +#define HB_EVP_CIPHER_CAMELLIA_192_CFB1 82 +#define HB_EVP_CIPHER_CAMELLIA_192_CFB8 83 +#define HB_EVP_CIPHER_CAMELLIA_192_CFB128 84 +#define HB_EVP_CIPHER_CAMELLIA_192_CFB 85 +#define HB_EVP_CIPHER_CAMELLIA_192_OFB 86 +#define HB_EVP_CIPHER_CAMELLIA_256_ECB 87 +#define HB_EVP_CIPHER_CAMELLIA_256_CBC 88 +#define HB_EVP_CIPHER_CAMELLIA_256_CFB1 89 +#define HB_EVP_CIPHER_CAMELLIA_256_CFB8 90 +#define HB_EVP_CIPHER_CAMELLIA_256_CFB128 91 +#define HB_EVP_CIPHER_CAMELLIA_256_CFB 92 +#define HB_EVP_CIPHER_CAMELLIA_256_OFB 93 +#define HB_EVP_CIPHER_SEED_ECB 94 +#define HB_EVP_CIPHER_SEED_CBC 95 +#define HB_EVP_CIPHER_SEED_CFB128 96 +#define HB_EVP_CIPHER_SEED_CFB 97 +#define HB_EVP_CIPHER_SEED_OFB 98 + #endif /* HBSSL_CH_ */ diff --git a/harbour/contrib/hbssl/ssl.c b/harbour/contrib/hbssl/ssl.c index df5143cb56..6c44f17156 100644 --- a/harbour/contrib/hbssl/ssl.c +++ b/harbour/contrib/hbssl/ssl.c @@ -56,6 +56,28 @@ #include "hbssl.h" +HB_FUNC( SSL_INIT ) +{ + SSL_library_init(); + SSL_load_error_strings(); +} + +HB_FUNC( SSLEAY_VERSION ) +{ + int value = hb_parni( 1 ); + + switch( value ) + { + case HB_SSLEAY_VERSION : value = SSLEAY_VERSION; break; + case HB_SSLEAY_CFLAGS : value = SSLEAY_CFLAGS; break; + case HB_SSLEAY_BUILT_ON : value = SSLEAY_BUILT_ON; break; + case HB_SSLEAY_PLATFORM : value = SSLEAY_PLATFORM; break; + case HB_SSLEAY_DIR : value = SSLEAY_DIR; break; + } + + hb_retc( SSLeay_version( value ) ); +} + static HB_GARBAGE_FUNC( SSL_release ) { void ** ph = ( void ** ) Cargo; diff --git a/harbour/contrib/hbssl/sslctx.c b/harbour/contrib/hbssl/sslctx.c index 621baa5641..1ac09aa1d3 100644 --- a/harbour/contrib/hbssl/sslctx.c +++ b/harbour/contrib/hbssl/sslctx.c @@ -56,28 +56,6 @@ #include "hbssl.h" -HB_FUNC( SSL_INIT ) -{ - SSL_library_init(); - SSL_load_error_strings(); -} - -HB_FUNC( SSLEAY_VERSION ) -{ - int value = hb_parni( 1 ); - - switch( value ) - { - case HB_SSLEAY_VERSION : value = SSLEAY_VERSION; break; - case HB_SSLEAY_CFLAGS : value = SSLEAY_CFLAGS; break; - case HB_SSLEAY_BUILT_ON : value = SSLEAY_BUILT_ON; break; - case HB_SSLEAY_PLATFORM : value = SSLEAY_PLATFORM; break; - case HB_SSLEAY_DIR : value = SSLEAY_DIR; break; - } - - hb_retc( SSLeay_version( value ) ); -} - static HB_GARBAGE_FUNC( SSL_CTX_release ) { void ** ph = ( void ** ) Cargo; diff --git a/harbour/contrib/hbssl/tests/crypt.prg b/harbour/contrib/hbssl/tests/crypt.prg new file mode 100644 index 0000000000..e9fe416d62 --- /dev/null +++ b/harbour/contrib/hbssl/tests/crypt.prg @@ -0,0 +1,55 @@ +/* + * $Id$ + */ + +/* + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + */ + +#include "simpleio.ch" + +#include "hbssl.ch" + +PROCEDURE Main() + + LOCAL ctx + LOCAL result + LOCAL encrypted + LOCAL decrypted + + LOCAL cKey := "key" + + OpenSSL_add_all_ciphers() + + ctx := hb_EVP_CIPHER_CTX_create() + EVP_CIPHER_CTX_init( ctx ) + + EVP_EncryptInit( ctx, "AES-192-OFB", cKey ) + ? EVP_CIPHER_CTX_cipher( ctx ) + ? EVP_CIPHER_block_size( EVP_CIPHER_CTX_cipher( ctx ) ) + + encrypted := "" + result := "" + EVP_EncryptUpdate( ctx, @result, "sample text" ) + encrypted += result + EVP_EncryptFinal( ctx, @result ) + encrypted += result + ? "ENCRYTPTED", ">" + hb_StrToHex( encrypted ) + "<" + + EVP_CIPHER_CTX_init( ctx ) + EVP_CIPHER_CTX_cleanup( ctx ) + + EVP_DecryptInit( ctx, "AES-192-OFB", cKey ) + + decrypted := "" + result := "" + EVP_DecryptUpdate( ctx, @result, encrypted ) + decrypted += result + EVP_DecryptFinal( ctx, @result ) + decrypted += result + ? "DECRYTPTED", ">" + decrypted + "<" + + EVP_cleanup() + + RETURN diff --git a/harbour/contrib/hbssl/tests/digest.prg b/harbour/contrib/hbssl/tests/digest.prg new file mode 100644 index 0000000000..b8acce6fee --- /dev/null +++ b/harbour/contrib/hbssl/tests/digest.prg @@ -0,0 +1,40 @@ +/* + * $Id$ + */ + +/* + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + */ + +#include "simpleio.ch" + +#include "hbssl.ch" + +PROCEDURE Main() + + LOCAL ctx + LOCAL digest + + OpenSSL_add_all_digests() + + ctx := EVP_MD_CTX_create() + EVP_MD_CTX_init( ctx ) + + EVP_DigestInit_ex( ctx, HB_EVP_MD_SHA256 ) + EVP_DigestUpdate( ctx, "sample text" ) + digest := "" + EVP_DigestFinal( ctx, @digest ) + ? "SHA256", ">" + hb_StrToHex( digest ) + "<" + + EVP_MD_CTX_cleanup( ctx ) + + EVP_DigestInit_ex( ctx, HB_EVP_MD_RIPEMD160 ) + EVP_DigestUpdate( ctx, "sample text" ) + digest := "" + EVP_DigestFinal( ctx, @digest ) + ? "RIPEMD160", ">" + hb_StrToHex( digest ) + "<" + + EVP_cleanup() + + RETURN