diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_print.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_print.c | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c index 2bcc11c852..5f46b1826c 100644 --- a/src/lib/libcrypto/bn/bn_print.c +++ b/src/lib/libcrypto/bn/bn_print.c | |||
| @@ -59,20 +59,19 @@ | |||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <ctype.h> | 60 | #include <ctype.h> |
| 61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
| 62 | #include "buffer.h" | 62 | #include <openssl/buffer.h> |
| 63 | #include "bn_lcl.h" | 63 | #include "bn_lcl.h" |
| 64 | 64 | ||
| 65 | static char *Hex="0123456789ABCDEF"; | 65 | static const char *Hex="0123456789ABCDEF"; |
| 66 | 66 | ||
| 67 | /* Must 'Free' the returned data */ | 67 | /* Must 'OPENSSL_free' the returned data */ |
| 68 | char *BN_bn2hex(a) | 68 | char *BN_bn2hex(const BIGNUM *a) |
| 69 | BIGNUM *a; | ||
| 70 | { | 69 | { |
| 71 | int i,j,v,z=0; | 70 | int i,j,v,z=0; |
| 72 | char *buf; | 71 | char *buf; |
| 73 | char *p; | 72 | char *p; |
| 74 | 73 | ||
| 75 | buf=(char *)Malloc(a->top*BN_BYTES*2+2); | 74 | buf=(char *)OPENSSL_malloc(a->top*BN_BYTES*2+2); |
| 76 | if (buf == NULL) | 75 | if (buf == NULL) |
| 77 | { | 76 | { |
| 78 | BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); | 77 | BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); |
| @@ -100,9 +99,8 @@ err: | |||
| 100 | return(buf); | 99 | return(buf); |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | /* Must 'Free' the returned data */ | 102 | /* Must 'OPENSSL_free' the returned data */ |
| 104 | char *BN_bn2dec(a) | 103 | char *BN_bn2dec(const BIGNUM *a) |
| 105 | BIGNUM *a; | ||
| 106 | { | 104 | { |
| 107 | int i=0,num; | 105 | int i=0,num; |
| 108 | char *buf=NULL; | 106 | char *buf=NULL; |
| @@ -112,8 +110,8 @@ BIGNUM *a; | |||
| 112 | 110 | ||
| 113 | i=BN_num_bits(a)*3; | 111 | i=BN_num_bits(a)*3; |
| 114 | num=(i/10+i/1000+3)+1; | 112 | num=(i/10+i/1000+3)+1; |
| 115 | bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); | 113 | bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); |
| 116 | buf=(char *)Malloc(num+3); | 114 | buf=(char *)OPENSSL_malloc(num+3); |
| 117 | if ((buf == NULL) || (bn_data == NULL)) | 115 | if ((buf == NULL) || (bn_data == NULL)) |
| 118 | { | 116 | { |
| 119 | BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); | 117 | BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); |
| @@ -139,7 +137,7 @@ BIGNUM *a; | |||
| 139 | } | 137 | } |
| 140 | lp--; | 138 | lp--; |
| 141 | /* We now have a series of blocks, BN_DEC_NUM chars | 139 | /* We now have a series of blocks, BN_DEC_NUM chars |
| 142 | * in length, where the last one needs trucation. | 140 | * in length, where the last one needs truncation. |
| 143 | * The blocks need to be reversed in order. */ | 141 | * The blocks need to be reversed in order. */ |
| 144 | sprintf(p,BN_DEC_FMT1,*lp); | 142 | sprintf(p,BN_DEC_FMT1,*lp); |
| 145 | while (*p) p++; | 143 | while (*p) p++; |
| @@ -151,14 +149,12 @@ BIGNUM *a; | |||
| 151 | } | 149 | } |
| 152 | } | 150 | } |
| 153 | err: | 151 | err: |
| 154 | if (bn_data != NULL) Free(bn_data); | 152 | if (bn_data != NULL) OPENSSL_free(bn_data); |
| 155 | if (t != NULL) BN_free(t); | 153 | if (t != NULL) BN_free(t); |
| 156 | return(buf); | 154 | return(buf); |
| 157 | } | 155 | } |
| 158 | 156 | ||
| 159 | int BN_hex2bn(bn,a) | 157 | int BN_hex2bn(BIGNUM **bn, const char *a) |
| 160 | BIGNUM **bn; | ||
| 161 | char *a; | ||
| 162 | { | 158 | { |
| 163 | BIGNUM *ret=NULL; | 159 | BIGNUM *ret=NULL; |
| 164 | BN_ULONG l=0; | 160 | BN_ULONG l=0; |
| @@ -169,13 +165,13 @@ char *a; | |||
| 169 | 165 | ||
| 170 | if (*a == '-') { neg=1; a++; } | 166 | if (*a == '-') { neg=1; a++; } |
| 171 | 167 | ||
| 172 | for (i=0; isxdigit(a[i]); i++) | 168 | for (i=0; isxdigit((unsigned char) a[i]); i++) |
| 173 | ; | 169 | ; |
| 174 | 170 | ||
| 175 | num=i+neg; | 171 | num=i+neg; |
| 176 | if (bn == NULL) return(num); | 172 | if (bn == NULL) return(num); |
| 177 | 173 | ||
| 178 | /* a is the start of the hex digets, and it is 'i' long */ | 174 | /* a is the start of the hex digits, and it is 'i' long */ |
| 179 | if (*bn == NULL) | 175 | if (*bn == NULL) |
| 180 | { | 176 | { |
| 181 | if ((ret=BN_new()) == NULL) return(0); | 177 | if ((ret=BN_new()) == NULL) return(0); |
| @@ -189,7 +185,7 @@ char *a; | |||
| 189 | /* i is the number of hex digests; */ | 185 | /* i is the number of hex digests; */ |
| 190 | if (bn_expand(ret,i*4) == NULL) goto err; | 186 | if (bn_expand(ret,i*4) == NULL) goto err; |
| 191 | 187 | ||
| 192 | j=i; /* least significate 'hex' */ | 188 | j=i; /* least significant 'hex' */ |
| 193 | m=0; | 189 | m=0; |
| 194 | h=0; | 190 | h=0; |
| 195 | while (j > 0) | 191 | while (j > 0) |
| @@ -224,9 +220,7 @@ err: | |||
| 224 | return(0); | 220 | return(0); |
| 225 | } | 221 | } |
| 226 | 222 | ||
| 227 | int BN_dec2bn(bn,a) | 223 | int BN_dec2bn(BIGNUM **bn, const char *a) |
| 228 | BIGNUM **bn; | ||
| 229 | char *a; | ||
| 230 | { | 224 | { |
| 231 | BIGNUM *ret=NULL; | 225 | BIGNUM *ret=NULL; |
| 232 | BN_ULONG l=0; | 226 | BN_ULONG l=0; |
| @@ -236,14 +230,14 @@ char *a; | |||
| 236 | if ((a == NULL) || (*a == '\0')) return(0); | 230 | if ((a == NULL) || (*a == '\0')) return(0); |
| 237 | if (*a == '-') { neg=1; a++; } | 231 | if (*a == '-') { neg=1; a++; } |
| 238 | 232 | ||
| 239 | for (i=0; isdigit(a[i]); i++) | 233 | for (i=0; isdigit((unsigned char) a[i]); i++) |
| 240 | ; | 234 | ; |
| 241 | 235 | ||
| 242 | num=i+neg; | 236 | num=i+neg; |
| 243 | if (bn == NULL) return(num); | 237 | if (bn == NULL) return(num); |
| 244 | 238 | ||
| 245 | /* a is the start of the digets, and it is 'i' long. | 239 | /* a is the start of the digits, and it is 'i' long. |
| 246 | * We chop it into BN_DEC_NUM digets at a time */ | 240 | * We chop it into BN_DEC_NUM digits at a time */ |
| 247 | if (*bn == NULL) | 241 | if (*bn == NULL) |
| 248 | { | 242 | { |
| 249 | if ((ret=BN_new()) == NULL) return(0); | 243 | if ((ret=BN_new()) == NULL) return(0); |
| @@ -283,12 +277,9 @@ err: | |||
| 283 | return(0); | 277 | return(0); |
| 284 | } | 278 | } |
| 285 | 279 | ||
| 286 | #ifndef NO_BIO | 280 | #ifndef OPENSSL_NO_BIO |
| 287 | 281 | #ifndef OPENSSL_NO_FP_API | |
| 288 | #ifndef NO_FP_API | 282 | int BN_print_fp(FILE *fp, const BIGNUM *a) |
| 289 | int BN_print_fp(fp, a) | ||
| 290 | FILE *fp; | ||
| 291 | BIGNUM *a; | ||
| 292 | { | 283 | { |
| 293 | BIO *b; | 284 | BIO *b; |
| 294 | int ret; | 285 | int ret; |
| @@ -302,9 +293,7 @@ BIGNUM *a; | |||
| 302 | } | 293 | } |
| 303 | #endif | 294 | #endif |
| 304 | 295 | ||
| 305 | int BN_print(bp, a) | 296 | int BN_print(BIO *bp, const BIGNUM *a) |
| 306 | BIO *bp; | ||
| 307 | BIGNUM *a; | ||
| 308 | { | 297 | { |
| 309 | int i,j,v,z=0; | 298 | int i,j,v,z=0; |
| 310 | int ret=0; | 299 | int ret=0; |
| @@ -329,5 +318,15 @@ BIGNUM *a; | |||
| 329 | end: | 318 | end: |
| 330 | return(ret); | 319 | return(ret); |
| 331 | } | 320 | } |
| 321 | #endif | ||
| 332 | 322 | ||
| 323 | #ifdef BN_DEBUG | ||
| 324 | void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n) | ||
| 325 | { | ||
| 326 | int i; | ||
| 327 | fprintf(o, "%s=", a); | ||
| 328 | for (i=n-1;i>=0;i--) | ||
| 329 | fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */ | ||
| 330 | fprintf(o, "\n"); | ||
| 331 | } | ||
| 333 | #endif | 332 | #endif |
