projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add prototypes for new DSA functions Steve added recently.
[oweals/openssl.git]
/
crypto
/
bn
/
bn_mont.c
diff --git
a/crypto/bn/bn_mont.c
b/crypto/bn/bn_mont.c
index e0aa3c769d227dc5f58e9052627b6edb070819d4..ee0f410c22a2eabfbff7967523f06906b1d011fe 100644
(file)
--- a/
crypto/bn/bn_mont.c
+++ b/
crypto/bn/bn_mont.c
@@
-56,16
+56,20
@@
* [including the GNU Public Licence.]
*/
* [including the GNU Public Licence.]
*/
+/*
+ * Details about Montgomery multiplication algorithms can be found at:
+ * http://www.ece.orst.edu/ISL/Publications.html
+ * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf
+ */
+
#include <stdio.h>
#include "cryptlib.h"
#include "bn_lcl.h"
#define MONT_WORD
#include <stdio.h>
#include "cryptlib.h"
#include "bn_lcl.h"
#define MONT_WORD
-int BN_mod_mul_montgomery(r,a,b,mont,ctx)
-BIGNUM *r,*a,*b;
-BN_MONT_CTX *mont;
-BN_CTX *ctx;
+int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+ BN_MONT_CTX *mont, BN_CTX *ctx)
{
BIGNUM *tmp,*tmp2;
{
BIGNUM *tmp,*tmp2;
@@
-101,13
+105,10
@@
err:
return(0);
}
return(0);
}
-int BN_from_montgomery(ret,a,mont,ctx)
-BIGNUM *ret;
-BIGNUM *a;
-BN_MONT_CTX *mont;
-BN_CTX *ctx;
+int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
+ BN_CTX *ctx)
{
{
-#ifdef BN_RECURSION
+#ifdef BN_RECURSION
_MONT
if (mont->use_word)
#endif
{
if (mont->use_word)
#endif
{
@@
-206,7
+207,7
@@
printf("word BN_from_montgomery %d * %d\n",nl,nl);
err1:
return(retn);
}
err1:
return(retn);
}
-#ifdef BN_RECURSION
+#ifdef BN_RECURSION
_MONT
else /* bignum version */
{
BIGNUM *t1,*t2,*t3;
else /* bignum version */
{
BIGNUM *t1,*t2,*t3;
@@
-235,7
+236,7
@@
printf("number BN_from_montgomery\n");
/* hmm... if a is between i and 2*i, things are bad */
if (a->top > i)
{
/* hmm... if a is between i and 2*i, things are bad */
if (a->top > i)
{
- j=
bn_add_words(ret->d,ret->d,&(a->d[i]),i
);
+ j=
(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i)
);
if (j) /* overflow */
bn_sub_words(ret->d,ret->d,mont->N.d,i);
}
if (j) /* overflow */
bn_sub_words(ret->d,ret->d,mont->N.d,i);
}
@@
-263,7
+264,7
@@
printf("number BN_from_montgomery\n");
#endif
}
#endif
}
-BN_MONT_CTX *BN_MONT_CTX_new()
+BN_MONT_CTX *BN_MONT_CTX_new(
void
)
{
BN_MONT_CTX *ret;
{
BN_MONT_CTX *ret;
@@
-275,8
+276,7
@@
BN_MONT_CTX *BN_MONT_CTX_new()
return(ret);
}
return(ret);
}
-void BN_MONT_CTX_init(ctx)
-BN_MONT_CTX *ctx;
+void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
{
ctx->use_word=0;
ctx->ri=0;
{
ctx->use_word=0;
ctx->ri=0;
@@
-286,9
+286,11
@@
BN_MONT_CTX *ctx;
ctx->flags=0;
}
ctx->flags=0;
}
-void BN_MONT_CTX_free(mont)
-BN_MONT_CTX *mont;
+void BN_MONT_CTX_free(BN_MONT_CTX *mont)
{
{
+ if(mont == NULL)
+ return;
+
BN_free(&(mont->RR));
BN_free(&(mont->N));
BN_free(&(mont->Ni));
BN_free(&(mont->RR));
BN_free(&(mont->N));
BN_free(&(mont->Ni));
@@
-296,10
+298,7
@@
BN_MONT_CTX *mont;
Free(mont);
}
Free(mont);
}
-int BN_MONT_CTX_set(mont,mod,ctx)
-BN_MONT_CTX *mont;
-BIGNUM *mod;
-BN_CTX *ctx;
+int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
{
BIGNUM Ri,*R;
{
BIGNUM Ri,*R;
@@
-307,7
+306,7
@@
BN_CTX *ctx;
R= &(mont->RR); /* grab RR as a temp */
BN_copy(&(mont->N),mod); /* Set N */
R= &(mont->RR); /* grab RR as a temp */
BN_copy(&(mont->N),mod); /* Set N */
-#ifdef BN_RECURSION
+#ifdef BN_RECURSION
_MONT
if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)
#endif
{
if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)
#endif
{
@@
-355,7
+354,7
@@
BN_CTX *ctx;
BN_free(&Ri);
/* mod->top=z; */
}
BN_free(&Ri);
/* mod->top=z; */
}
-#ifdef BN_RECURSION
+#ifdef BN_RECURSION
_MONT
else
{
mont->use_word=0;
else
{
mont->use_word=0;
@@
-393,8
+392,7
@@
err:
return(0);
}
return(0);
}
-BN_MONT_CTX *BN_MONT_CTX_copy(to, from)
-BN_MONT_CTX *to, *from;
+BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
{
if (to == from) return(to);
{
if (to == from) return(to);