summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_ctx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_ctx.c')
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
index 46132fd180..7daf19eb84 100644
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -61,15 +61,16 @@
61 61
62#include <stdio.h> 62#include <stdio.h>
63#include <assert.h> 63#include <assert.h>
64
64#include "cryptlib.h" 65#include "cryptlib.h"
65#include <openssl/bn.h> 66#include "bn_lcl.h"
66 67
67 68
68BN_CTX *BN_CTX_new(void) 69BN_CTX *BN_CTX_new(void)
69 { 70 {
70 BN_CTX *ret; 71 BN_CTX *ret;
71 72
72 ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); 73 ret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));
73 if (ret == NULL) 74 if (ret == NULL)
74 { 75 {
75 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); 76 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
@@ -83,6 +84,7 @@ BN_CTX *BN_CTX_new(void)
83 84
84void BN_CTX_init(BN_CTX *ctx) 85void BN_CTX_init(BN_CTX *ctx)
85 { 86 {
87#if 0 /* explicit version */
86 int i; 88 int i;
87 ctx->tos = 0; 89 ctx->tos = 0;
88 ctx->flags = 0; 90 ctx->flags = 0;
@@ -90,6 +92,9 @@ void BN_CTX_init(BN_CTX *ctx)
90 ctx->too_many = 0; 92 ctx->too_many = 0;
91 for (i = 0; i < BN_CTX_NUM; i++) 93 for (i = 0; i < BN_CTX_NUM; i++)
92 BN_init(&(ctx->bn[i])); 94 BN_init(&(ctx->bn[i]));
95#else
96 memset(ctx, 0, sizeof *ctx);
97#endif
93 } 98 }
94 99
95void BN_CTX_free(BN_CTX *ctx) 100void BN_CTX_free(BN_CTX *ctx)
@@ -102,7 +107,7 @@ void BN_CTX_free(BN_CTX *ctx)
102 for (i=0; i < BN_CTX_NUM; i++) 107 for (i=0; i < BN_CTX_NUM; i++)
103 BN_clear_free(&(ctx->bn[i])); 108 BN_clear_free(&(ctx->bn[i]));
104 if (ctx->flags & BN_FLG_MALLOCED) 109 if (ctx->flags & BN_FLG_MALLOCED)
105 Free(ctx); 110 OPENSSL_free(ctx);
106 } 111 }
107 112
108void BN_CTX_start(BN_CTX *ctx) 113void BN_CTX_start(BN_CTX *ctx)
@@ -112,8 +117,14 @@ void BN_CTX_start(BN_CTX *ctx)
112 ctx->depth++; 117 ctx->depth++;
113 } 118 }
114 119
120
115BIGNUM *BN_CTX_get(BN_CTX *ctx) 121BIGNUM *BN_CTX_get(BN_CTX *ctx)
116 { 122 {
123 /* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,
124 * make sure that if BN_CTX_get fails once it will return NULL again
125 * until BN_CTX_end is called. (This is so that callers have to check
126 * only the last return value.)
127 */
117 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM) 128 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
118 { 129 {
119 if (!ctx->too_many) 130 if (!ctx->too_many)