Constify DH-related code.
[openssl.git] / crypto / asn1 / t_pkey.c
index 7bf470e8ddb2083c16b4ce46293dcca5cad157b1..62bc704d322133b04cb530ee49fae0b11fe79ef7 100644 (file)
 #include <openssl/dsa.h>
 #endif
 
-/* DHerr(DH_F_DHPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
- * DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
- */
-
-#ifndef NOPROTO
 static int print(BIO *fp,const char *str,BIGNUM *num,
                unsigned char *buf,int off);
-#else
-static int print();
-#endif
-
 #ifndef NO_RSA
 #ifndef NO_FP_API
-int RSA_print_fp(FILE *fp, RSA *x, int off)
+int RSA_print_fp(FILE *fp, const RSA *x, int off)
         {
         BIO *b;
         int ret;
@@ -100,7 +91,7 @@ int RSA_print_fp(FILE *fp, RSA *x, int off)
         }
 #endif
 
-int RSA_print(BIO *bp, RSA *x, int off)
+int RSA_print(BIO *bp, const RSA *x, int off)
        {
        char str[128];
        const char *s;
@@ -108,7 +99,7 @@ int RSA_print(BIO *bp, RSA *x, int off)
        int i,ret=0;
 
        i=RSA_size(x);
-       m=(unsigned char *)Malloc((unsigned int)i+10);
+       m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
        if (m == NULL)
                {
                RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
@@ -142,14 +133,14 @@ int RSA_print(BIO *bp, RSA *x, int off)
        if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
        ret=1;
 err:
-       if (m != NULL) Free((char *)m);
+       if (m != NULL) OPENSSL_free(m);
        return(ret);
        }
 #endif /* NO_RSA */
 
 #ifndef NO_DSA
 #ifndef NO_FP_API
-int DSA_print_fp(FILE *fp, DSA *x, int off)
+int DSA_print_fp(FILE *fp, const DSA *x, int off)
        {
        BIO *b;
        int ret;
@@ -166,7 +157,7 @@ int DSA_print_fp(FILE *fp, DSA *x, int off)
        }
 #endif
 
-int DSA_print(BIO *bp, DSA *x, int off)
+int DSA_print(BIO *bp, const DSA *x, int off)
        {
        char str[128];
        unsigned char *m=NULL;
@@ -185,7 +176,7 @@ int DSA_print(BIO *bp, DSA *x, int off)
                i=BN_num_bytes(bn)*2;
        else
                i=256;
-       m=(unsigned char *)Malloc((unsigned int)i+10);
+       m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
        if (m == NULL)
                {
                DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
@@ -213,7 +204,7 @@ int DSA_print(BIO *bp, DSA *x, int off)
        if ((x->g != NULL) && !print(bp,"G:   ",x->g,m,off)) goto err;
        ret=1;
 err:
-       if (m != NULL) Free((char *)m);
+       if (m != NULL) OPENSSL_free(m);
        return(ret);
        }
 #endif /* !NO_DSA */
@@ -270,7 +261,7 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
 
 #ifndef NO_DH
 #ifndef NO_FP_API
-int DHparams_print_fp(FILE *fp, DH *x)
+int DHparams_print_fp(FILE *fp, const DH *x)
         {
         BIO *b;
         int ret;
@@ -287,13 +278,13 @@ int DHparams_print_fp(FILE *fp, DH *x)
         }
 #endif
 
-int DHparams_print(BIO *bp, DH *x)
+int DHparams_print(BIO *bp, const DH *x)
        {
        unsigned char *m=NULL;
        int reason=ERR_R_BUF_LIB,i,ret=0;
 
        i=BN_num_bytes(x->p);
-       m=(unsigned char *)Malloc((unsigned int)i+10);
+       m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
        if (m == NULL)
                {
                reason=ERR_R_MALLOC_FAILURE;
@@ -307,7 +298,7 @@ int DHparams_print(BIO *bp, DH *x)
        if (!print(bp,"generator:",x->g,m,4)) goto err;
        if (x->length != 0)
                {
-               if (BIO_printf(bp,"    recomented-private-length: %d bits\n",
+               if (BIO_printf(bp,"    recommended-private-length: %d bits\n",
                        (int)x->length) <= 0) goto err;
                }
        ret=1;
@@ -316,14 +307,14 @@ int DHparams_print(BIO *bp, DH *x)
 err:
                DHerr(DH_F_DHPARAMS_PRINT,reason);
                }
-       if (m != NULL) Free((char *)m);
+       if (m != NULL) OPENSSL_free(m);
        return(ret);
        }
 #endif
 
 #ifndef NO_DSA
 #ifndef NO_FP_API
-int DSAparams_print_fp(FILE *fp, DSA *x)
+int DSAparams_print_fp(FILE *fp, const DSA *x)
         {
         BIO *b;
         int ret;
@@ -340,13 +331,13 @@ int DSAparams_print_fp(FILE *fp, DSA *x)
         }
 #endif
 
-int DSAparams_print(BIO *bp, DSA *x)
+int DSAparams_print(BIO *bp, const DSA *x)
        {
        unsigned char *m=NULL;
        int reason=ERR_R_BUF_LIB,i,ret=0;
 
        i=BN_num_bytes(x->p);
-       m=(unsigned char *)Malloc((unsigned int)i+10);
+       m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
        if (m == NULL)
                {
                reason=ERR_R_MALLOC_FAILURE;
@@ -361,7 +352,7 @@ int DSAparams_print(BIO *bp, DSA *x)
        if (!print(bp,"g:",x->g,m,4)) goto err;
        ret=1;
 err:
-       if (m != NULL) Free((char *)m);
+       if (m != NULL) OPENSSL_free(m);
        DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
        return(ret);
        }