X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbn%2Fbn_gf2m.c;h=24906c9c32ec5452f154734b47137ae2d4616fb4;hp=c969685c87467a0b18d4c2580009f1fa77bd72e6;hb=6c950e0dc97a84cab70bd004142cfa59f3eb46a4;hpb=d28735a05bbd20ab628a775e2877e1666b2eb865 diff --git a/crypto/bn/bn_gf2m.c b/crypto/bn/bn_gf2m.c index c969685c87..24906c9c32 100644 --- a/crypto/bn/bn_gf2m.c +++ b/crypto/bn/bn_gf2m.c @@ -27,6 +27,13 @@ * */ +/* NOTE: This file is licensed pursuant to the OpenSSL license below + * and may be modified; but after modifications, the above covenant + * may no longer apply! In such cases, the corresponding paragraph + * ["In addition, Sun covenants ... causes the infringement."] and + * this note can be edited out; but please keep the Sun copyright + * notice and attribution. */ + /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -316,10 +323,10 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) int n, dN, d0, d1; BN_ULONG zz, *z; - /* Since the algorithm does reduction in place, if a == r, copy the + /* Since the algorithm does reduction in the r value, if a != r, copy the * contents of a into r so we can do reduction in r. */ - if ((a != NULL) && (a->d != r->d)) + if (a != r) { if (!bn_wexpand(r, a->top)) return 0; for (j = 0; j < a->top; j++) @@ -370,12 +377,16 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) for (k = 1; p[k] > 0; k++) { + BN_ULONG tmp_ulong; + /* reducing component t^p[k]*/ n = p[k] / BN_BITS2; d0 = p[k] % BN_BITS2; d1 = BN_BITS2 - d0; z[n] ^= (zz << d0); - if (d0) z[n+1] ^= (zz >> d1); + tmp_ulong = zz >> d1; + if (d0 && tmp_ulong) + z[n+1] ^= tmp_ulong; } @@ -427,7 +438,7 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig BN_CTX_start(ctx); if ((s = BN_CTX_get(ctx)) == NULL) goto err; - zlen = a->top + b->top; + zlen = a->top + b->top + 4; if (!bn_wexpand(s, zlen)) goto err; s->top = zlen;