aboutsummaryrefslogtreecommitdiff
path: root/crypto/bn/bn_ctx.c
diff options
context:
space:
mode:
authorGeoff Thorpe <geoff@openssl.org>2003-10-30 01:07:56 +0000
committerGeoff Thorpe <geoff@openssl.org>2003-10-30 01:07:56 +0000
commit5f747c7f4bfb7dc97179a1bbe746e083ca38d1e3 (patch)
treee2966c4ca1a40056d49c7d60fa804d889d65fc53 /crypto/bn/bn_ctx.c
parentc4db1a8b5c2d72b765614b2115f36ae5ac8d22bd (diff)
downloadopenssl-5f747c7f4bfb7dc97179a1bbe746e083ca38d1e3.zip
openssl-5f747c7f4bfb7dc97179a1bbe746e083ca38d1e3.tar.gz
openssl-5f747c7f4bfb7dc97179a1bbe746e083ca38d1e3.tar.bz2
When a BN_CTX is used for temporary workspace, the variables are sometimes
left in an inconsistent state when they are released for later reuse. This change resets the BIGNUMs when they are released back to the context.
Diffstat (limited to 'crypto/bn/bn_ctx.c')
-rw-r--r--crypto/bn/bn_ctx.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c
index 34cc75c..a0e7915 100644
--- a/crypto/bn/bn_ctx.c
+++ b/crypto/bn/bn_ctx.c
@@ -167,6 +167,19 @@ void BN_CTX_end(BN_CTX *ctx)
ctx->too_many = 0;
ctx->depth--;
+ /* It appears some "scrapbook" uses of BN_CTX result in BIGNUMs being
+ * left in an inconsistent state when they are released (eg. BN_div).
+ * These can trip us up when they get reused, so the safest fix is to
+ * make sure the BIGNUMs are made sane when the context usage is
+ * releasing them. */
if (ctx->depth < BN_CTX_NUM_POS)
+#if 0
ctx->tos = ctx->pos[ctx->depth];
+#else
+ {
+ while(ctx->tos > ctx->pos[ctx->depth])
+ /* This ensures the BIGNUM is sane(r) for reuse. */
+ ctx->bn[--(ctx->tos)].top = 0;
+ }
+#endif
}