bn_print.c (59191) | bn_print.c (68651) |
---|---|
1/* crypto/bn/bn_print.c */ 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * --- 50 unchanged lines hidden (view full) --- 59#include <stdio.h> 60#include <ctype.h> 61#include "cryptlib.h" 62#include <openssl/buffer.h> 63#include "bn_lcl.h" 64 65static const char *Hex="0123456789ABCDEF"; 66 | 1/* crypto/bn/bn_print.c */ 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * --- 50 unchanged lines hidden (view full) --- 59#include <stdio.h> 60#include <ctype.h> 61#include "cryptlib.h" 62#include <openssl/buffer.h> 63#include "bn_lcl.h" 64 65static const char *Hex="0123456789ABCDEF"; 66 |
67/* Must 'Free' the returned data */ | 67/* Must 'OPENSSL_free' the returned data */ |
68char *BN_bn2hex(const BIGNUM *a) 69 { 70 int i,j,v,z=0; 71 char *buf; 72 char *p; 73 | 68char *BN_bn2hex(const BIGNUM *a) 69 { 70 int i,j,v,z=0; 71 char *buf; 72 char *p; 73 |
74 buf=(char *)Malloc(a->top*BN_BYTES*2+2); | 74 buf=(char *)OPENSSL_malloc(a->top*BN_BYTES*2+2); |
75 if (buf == NULL) 76 { 77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); 78 goto err; 79 } 80 p=buf; 81 if (a->neg) *(p++)='-'; 82 if (a->top == 0) *(p++)='0'; --- 11 unchanged lines hidden (view full) --- 94 } 95 } 96 } 97 *p='\0'; 98err: 99 return(buf); 100 } 101 | 75 if (buf == NULL) 76 { 77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); 78 goto err; 79 } 80 p=buf; 81 if (a->neg) *(p++)='-'; 82 if (a->top == 0) *(p++)='0'; --- 11 unchanged lines hidden (view full) --- 94 } 95 } 96 } 97 *p='\0'; 98err: 99 return(buf); 100 } 101 |
102/* Must 'Free' the returned data */ | 102/* Must 'OPENSSL_free' the returned data */ |
103char *BN_bn2dec(const BIGNUM *a) 104 { 105 int i=0,num; 106 char *buf=NULL; 107 char *p; 108 BIGNUM *t=NULL; 109 BN_ULONG *bn_data=NULL,*lp; 110 111 i=BN_num_bits(a)*3; 112 num=(i/10+i/1000+3)+1; | 103char *BN_bn2dec(const BIGNUM *a) 104 { 105 int i=0,num; 106 char *buf=NULL; 107 char *p; 108 BIGNUM *t=NULL; 109 BN_ULONG *bn_data=NULL,*lp; 110 111 i=BN_num_bits(a)*3; 112 num=(i/10+i/1000+3)+1; |
113 bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); 114 buf=(char *)Malloc(num+3); | 113 bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); 114 buf=(char *)OPENSSL_malloc(num+3); |
115 if ((buf == NULL) || (bn_data == NULL)) 116 { 117 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); 118 goto err; 119 } 120 if ((t=BN_dup(a)) == NULL) goto err; 121 122 p=buf; --- 21 unchanged lines hidden (view full) --- 144 while (lp != bn_data) 145 { 146 lp--; 147 sprintf(p,BN_DEC_FMT2,*lp); 148 while (*p) p++; 149 } 150 } 151err: | 115 if ((buf == NULL) || (bn_data == NULL)) 116 { 117 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); 118 goto err; 119 } 120 if ((t=BN_dup(a)) == NULL) goto err; 121 122 p=buf; --- 21 unchanged lines hidden (view full) --- 144 while (lp != bn_data) 145 { 146 lp--; 147 sprintf(p,BN_DEC_FMT2,*lp); 148 while (*p) p++; 149 } 150 } 151err: |
152 if (bn_data != NULL) Free(bn_data); | 152 if (bn_data != NULL) OPENSSL_free(bn_data); |
153 if (t != NULL) BN_free(t); 154 return(buf); 155 } 156 157int BN_hex2bn(BIGNUM **bn, const char *a) 158 { 159 BIGNUM *ret=NULL; 160 BN_ULONG l=0; --- 172 unchanged lines hidden --- | 153 if (t != NULL) BN_free(t); 154 return(buf); 155 } 156 157int BN_hex2bn(BIGNUM **bn, const char *a) 158 { 159 BIGNUM *ret=NULL; 160 BN_ULONG l=0; --- 172 unchanged lines hidden --- |