diff options
| author | beck <> | 2000-12-15 02:58:47 +0000 |
|---|---|---|
| committer | beck <> | 2000-12-15 02:58:47 +0000 |
| commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
| tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/bn/bn_lib.c | |
| parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
| download | openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2 openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip | |
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/bn/bn_lib.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 0e6b12d9c3..b6b0ce4b3c 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
| @@ -56,6 +56,12 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef BN_DEBUG | ||
| 60 | # undef NDEBUG /* avoid conflicting definitions */ | ||
| 61 | # define NDEBUG | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #include <assert.h> | ||
| 59 | #include <stdio.h> | 65 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 66 | #include "cryptlib.h" |
| 61 | #include "bn_lcl.h" | 67 | #include "bn_lcl.h" |
| @@ -244,14 +250,8 @@ int BN_num_bits(const BIGNUM *a) | |||
| 244 | 250 | ||
| 245 | if (a->top == 0) return(0); | 251 | if (a->top == 0) return(0); |
| 246 | l=a->d[a->top-1]; | 252 | l=a->d[a->top-1]; |
| 253 | assert(l != 0); | ||
| 247 | i=(a->top-1)*BN_BITS2; | 254 | i=(a->top-1)*BN_BITS2; |
| 248 | if (l == 0) | ||
| 249 | { | ||
| 250 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 251 | fprintf(stderr,"BAD TOP VALUE\n"); | ||
| 252 | #endif | ||
| 253 | abort(); | ||
| 254 | } | ||
| 255 | return(i+BN_num_bits_word(l)); | 255 | return(i+BN_num_bits_word(l)); |
| 256 | } | 256 | } |
| 257 | 257 | ||
| @@ -262,24 +262,24 @@ void BN_clear_free(BIGNUM *a) | |||
| 262 | if (a == NULL) return; | 262 | if (a == NULL) return; |
| 263 | if (a->d != NULL) | 263 | if (a->d != NULL) |
| 264 | { | 264 | { |
| 265 | memset(a->d,0,a->max*sizeof(a->d[0])); | 265 | memset(a->d,0,a->dmax*sizeof(a->d[0])); |
| 266 | if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) | 266 | if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) |
| 267 | Free(a->d); | 267 | OPENSSL_free(a->d); |
| 268 | } | 268 | } |
| 269 | i=BN_get_flags(a,BN_FLG_MALLOCED); | 269 | i=BN_get_flags(a,BN_FLG_MALLOCED); |
| 270 | memset(a,0,sizeof(BIGNUM)); | 270 | memset(a,0,sizeof(BIGNUM)); |
| 271 | if (i) | 271 | if (i) |
| 272 | Free(a); | 272 | OPENSSL_free(a); |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | void BN_free(BIGNUM *a) | 275 | void BN_free(BIGNUM *a) |
| 276 | { | 276 | { |
| 277 | if (a == NULL) return; | 277 | if (a == NULL) return; |
| 278 | if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) | 278 | if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) |
| 279 | Free(a->d); | 279 | OPENSSL_free(a->d); |
| 280 | a->flags|=BN_FLG_FREE; /* REMOVE? */ | 280 | a->flags|=BN_FLG_FREE; /* REMOVE? */ |
| 281 | if (a->flags & BN_FLG_MALLOCED) | 281 | if (a->flags & BN_FLG_MALLOCED) |
| 282 | Free(a); | 282 | OPENSSL_free(a); |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | void BN_init(BIGNUM *a) | 285 | void BN_init(BIGNUM *a) |
| @@ -291,7 +291,7 @@ BIGNUM *BN_new(void) | |||
| 291 | { | 291 | { |
| 292 | BIGNUM *ret; | 292 | BIGNUM *ret; |
| 293 | 293 | ||
| 294 | if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL) | 294 | if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL) |
| 295 | { | 295 | { |
| 296 | BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); | 296 | BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); |
| 297 | return(NULL); | 297 | return(NULL); |
| @@ -299,7 +299,7 @@ BIGNUM *BN_new(void) | |||
| 299 | ret->flags=BN_FLG_MALLOCED; | 299 | ret->flags=BN_FLG_MALLOCED; |
| 300 | ret->top=0; | 300 | ret->top=0; |
| 301 | ret->neg=0; | 301 | ret->neg=0; |
| 302 | ret->max=0; | 302 | ret->dmax=0; |
| 303 | ret->d=NULL; | 303 | ret->d=NULL; |
| 304 | return(ret); | 304 | return(ret); |
| 305 | } | 305 | } |
| @@ -317,7 +317,7 @@ BIGNUM *bn_expand2(BIGNUM *b, int words) | |||
| 317 | 317 | ||
| 318 | bn_check_top(b); | 318 | bn_check_top(b); |
| 319 | 319 | ||
| 320 | if (words > b->max) | 320 | if (words > b->dmax) |
| 321 | { | 321 | { |
| 322 | bn_check_top(b); | 322 | bn_check_top(b); |
| 323 | if (BN_get_flags(b,BN_FLG_STATIC_DATA)) | 323 | if (BN_get_flags(b,BN_FLG_STATIC_DATA)) |
| @@ -325,7 +325,7 @@ BIGNUM *bn_expand2(BIGNUM *b, int words) | |||
| 325 | BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); | 325 | BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); |
| 326 | return(NULL); | 326 | return(NULL); |
| 327 | } | 327 | } |
| 328 | a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); | 328 | a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*(words+1)); |
| 329 | if (A == NULL) | 329 | if (A == NULL) |
| 330 | { | 330 | { |
| 331 | BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); | 331 | BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); |
| @@ -423,21 +423,21 @@ BIGNUM *bn_expand2(BIGNUM *b, int words) | |||
| 423 | case 0: ; /* ultrix cc workaround, see above */ | 423 | case 0: ; /* ultrix cc workaround, see above */ |
| 424 | } | 424 | } |
| 425 | #endif | 425 | #endif |
| 426 | Free(b->d); | 426 | OPENSSL_free(b->d); |
| 427 | } | 427 | } |
| 428 | 428 | ||
| 429 | b->d=a; | 429 | b->d=a; |
| 430 | b->max=words; | 430 | b->dmax=words; |
| 431 | 431 | ||
| 432 | /* Now need to zero any data between b->top and b->max */ | 432 | /* Now need to zero any data between b->top and b->max */ |
| 433 | 433 | ||
| 434 | A= &(b->d[b->top]); | 434 | A= &(b->d[b->top]); |
| 435 | for (i=(b->max - b->top)>>3; i>0; i--,A+=8) | 435 | for (i=(b->dmax - b->top)>>3; i>0; i--,A+=8) |
| 436 | { | 436 | { |
| 437 | A[0]=0; A[1]=0; A[2]=0; A[3]=0; | 437 | A[0]=0; A[1]=0; A[2]=0; A[3]=0; |
| 438 | A[4]=0; A[5]=0; A[6]=0; A[7]=0; | 438 | A[4]=0; A[5]=0; A[6]=0; A[7]=0; |
| 439 | } | 439 | } |
| 440 | for (i=(b->max - b->top)&7; i>0; i--,A++) | 440 | for (i=(b->dmax - b->top)&7; i>0; i--,A++) |
| 441 | A[0]=0; | 441 | A[0]=0; |
| 442 | #else | 442 | #else |
| 443 | memset(A,0,sizeof(BN_ULONG)*(words+1)); | 443 | memset(A,0,sizeof(BN_ULONG)*(words+1)); |
| @@ -508,7 +508,7 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) | |||
| 508 | void BN_clear(BIGNUM *a) | 508 | void BN_clear(BIGNUM *a) |
| 509 | { | 509 | { |
| 510 | if (a->d != NULL) | 510 | if (a->d != NULL) |
| 511 | memset(a->d,0,a->max*sizeof(a->d[0])); | 511 | memset(a->d,0,a->dmax*sizeof(a->d[0])); |
| 512 | a->top=0; | 512 | a->top=0; |
| 513 | a->neg=0; | 513 | a->neg=0; |
| 514 | } | 514 | } |
