Hi,
     I am facing a memory leaks in my program. I am using
BN_new,BN_CTX_new,BN_mod_exp,BN_free and BN_CTX_free  OpenSSL functions in my
program only.  I am using "openssl-0.9.6b" libraries in Solaris 8. I am
attaching my code for your reference. Please let me know how can I come over
from memory leak.


With Regards,
-Pratap

Compilation output :

        (cd ..; make -f Makefile.ssl DIRS=test all)
+ rm -f libcrypto.so.0
+ rm -f libcrypto.so
+ rm -f libcrypto.so.0.9.6
+ rm -f libssl.so.0
+ rm -f libssl.so
+ rm -f libssl.so.0.9.6
making all in test...
cc -I../include -KPIC -DTHREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H
-xtarget=ultra -xarch=v8plus -xO5 -xstrconst -xdepend -Xa -DB_ENDIAN -DBN_DIV2W
-DULTRASPARC -DMD5_ASM  -c  bn_mod_exp.c
cc -o bn_mod_exp -I../include -KPIC -DTHREADS -D_REENTRANT -DDSO_DLFCN
-DHAVE_DLFCN_H -xtarget=ultra -xarch=v8plus -xO5 -xstrconst -xdepend -Xa
-DB_ENDIAN -DBN_DIV2W -DULTRASPARC -DMD5_ASM bn_mod_exp.o  -L.. -lcrypto
-lsocket -lnsl -ldl



Code :

#include <stdio.h>
#include <openssl/bn.h>

void Mont_exp(unsigned char *x,unsigned char *n,unsigned char * m,int
base,unsigned char *A,int *length);

int main(int argc , char *argv[])
{
        unsigned char A[8096];
        int base=16,length;
        unsigned char *x=(unsigned char
*)"400AAAAAAAAABBBBBBBBBCCCCDDDDDDDEEEEEEEEEEEEFFFFFFFFFFAAAAAAAAAAAA62626";
        unsigned char *n=(unsigned char
*)"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8";
        unsigned char *m=(unsigned char
*)"3AFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";

        while (1)
        {
                Mont_exp(x,n,m,base,A,&length);
                printf("A is <%s> of length <%d>\n",A,length);
                memset(A,(char)0,8096);
        }
}

void Mont_exp(unsigned char *x,unsigned char *n,unsigned char * m,int
base,unsigned char *A,int *length)
{
        BIGNUM *a,*b,*c,*d;
        int i;
        BN_CTX *ctx;

        a=(BIGNUM * )BN_new();
        BN_hex2bn(&a,(const char*)&x[0]);

        b=(BIGNUM * )BN_new();
        BN_hex2bn(&b,(const char*)&n[0]);

        c=(BIGNUM * )BN_new();
        BN_hex2bn(&c,(const char*)&m[0]);

        d=(BIGNUM * )BN_new();

        ctx=(BN_CTX *)BN_CTX_new();
        if (ctx == NULL) exit(1);
        if (!BN_mod_exp(d,a,b,c,ctx))
        {
                BN_free(a);
                BN_free(b);
                BN_free(c);
                BN_free(d);
                BN_CTX_free(ctx);
                return;
        }
        strcpy((char *)A,(const char *)BN_bn2hex(d));

        *length = strlen((const char *)A);

        BN_free(a);
        BN_free(b);
        BN_free(c);
        BN_free(d);
        BN_CTX_free(ctx);
        return;
}





"DISCLAIMER: This message is proprietary to Hughes Software Systems Limited
(HSS) and is intended solely for the use of the individual  to whom it is
addressed. It may contain  privileged or confidential information  and should
not be circulated or used for any purpose other than for what it is intended. If
you have received this message in error, please notify the originator
immediately. If you are not the intended recipient, you are notified that you
are strictly prohibited from using, copying, altering, or disclosing the
contents of this message. HSS accepts no responsibility for loss or damage
arising from the use of the information transmitted by this email including
damage from virus."




______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to