projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Swap to using _longjmp/_setjmp instead of longjmp/setjmp
[oweals/openssl.git]
/
crypto
/
bn
/
bn_mont.c
diff --git
a/crypto/bn/bn_mont.c
b/crypto/bn/bn_mont.c
index 175145e7b757901cd1211efd26d19ddc12fceb81..bda2157aa5dd9f8b3aee9f468447bcf4b1f74192 100644
(file)
--- a/
crypto/bn/bn_mont.c
+++ b/
crypto/bn/bn_mont.c
@@
-116,7
+116,7
@@
* sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf
*/
* sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf
*/
-#include "cryptlib.h"
+#include "
internal/
cryptlib.h"
#include "bn_lcl.h"
#define MONT_WORD /* use the faster word-based algorithm */
#include "bn_lcl.h"
#define MONT_WORD /* use the faster word-based algorithm */
@@
-196,12
+196,9
@@
static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
rp = r->d;
/* clear the top words of T */
rp = r->d;
/* clear the top words of T */
-# if 1
- for (i = r->top; i < max; i++) /* memset? XXX */
- rp[i] = 0;
-# else
- memset(&(rp[r->top]), 0, (max - r->top) * sizeof(BN_ULONG));
-# endif
+ i = max - r->top;
+ if (i)
+ memset(&rp[r->top], 0, sizeof(*rp) * i);
r->top = max;
n0 = mont->n0[0];
r->top = max;
n0 = mont->n0[0];
@@
-319,7
+316,7
@@
BN_MONT_CTX *BN_MONT_CTX_new(void)
{
BN_MONT_CTX *ret;
{
BN_MONT_CTX *ret;
- if ((ret =
(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX
))) == NULL)
+ if ((ret =
OPENSSL_malloc(sizeof(*ret
))) == NULL)
return (NULL);
BN_MONT_CTX_init(ret);
return (NULL);
BN_MONT_CTX_init(ret);
@@
-342,9
+339,9
@@
void BN_MONT_CTX_free(BN_MONT_CTX *mont)
if (mont == NULL)
return;
if (mont == NULL)
return;
- BN_free(&(mont->RR));
- BN_free(&(mont->N));
- BN_free(&(mont->Ni));
+ BN_
clear_
free(&(mont->RR));
+ BN_
clear_
free(&(mont->N));
+ BN_
clear_
free(&(mont->Ni));
if (mont->flags & BN_FLG_MALLOCED)
OPENSSL_free(mont);
}
if (mont->flags & BN_FLG_MALLOCED)
OPENSSL_free(mont);
}
@@
-354,6
+351,9
@@
int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
int ret = 0;
BIGNUM *Ri, *R;
int ret = 0;
BIGNUM *Ri, *R;
+ if (BN_is_zero(mod))
+ return 0;
+
BN_CTX_start(ctx);
if ((Ri = BN_CTX_get(ctx)) == NULL)
goto err;
BN_CTX_start(ctx);
if ((Ri = BN_CTX_get(ctx)) == NULL)
goto err;
@@
-517,7
+517,7
@@
BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
* (the losers throw away the work they've done).
*/
ret = BN_MONT_CTX_new();
* (the losers throw away the work they've done).
*/
ret = BN_MONT_CTX_new();
- if (
!ret
)
+ if (
ret == NULL
)
return NULL;
if (!BN_MONT_CTX_set(ret, mod, ctx)) {
BN_MONT_CTX_free(ret);
return NULL;
if (!BN_MONT_CTX_set(ret, mod, ctx)) {
BN_MONT_CTX_free(ret);