Commit fffd68f1 authored by Brian Wellington's avatar Brian Wellington
Browse files

update to openssl-0.9.4, remove compile-time warnings

parent 94167262
......@@ -46,7 +46,7 @@ OPENSSLOBJS = sec/openssl/bn_add.@O@ sec/openssl/bn_asm.@O@ \
sec/openssl/bn_comba.@O@ sec/openssl/bn_div.@O@ \
sec/openssl/bn_err.@O@ sec/openssl/bn_exp.@O@ \
sec/openssl/bn_exp2.@O@ sec/openssl/bn_gcd.@O@ \
sec/openssl/bn_lib.@O@ sec/openssl/bn_m.@O@ \
sec/openssl/bn_lib.@O@ \
sec/openssl/bn_mont.@O@ sec/openssl/bn_mul.@O@ \
sec/openssl/bn_prime.@O@ sec/openssl/bn_rand.@O@ \
sec/openssl/bn_recp.@O@ sec/openssl/bn_shift.@O@ \
......
......@@ -38,7 +38,7 @@ LIBS = @LIBS@
# Alphabetically
OBJS = bn_add.@O@ bn_asm.@O@ bn_comba.@O@ bn_div.@O@ \
bn_err.@O@ bn_exp.@O@ bn_exp2.@O@ bn_gcd.@O@ \
bn_lib.@O@ bn_m.@O@ bn_mont.@O@ bn_mul.@O@ \
bn_lib.@O@ bn_mont.@O@ bn_mul.@O@ \
bn_prime.@O@ bn_rand.@O@ bn_recp.@O@ \
bn_shift.@O@ bn_sqr.@O@ bn_word.@O@ buffer.@O@ \
cryptlib.@O@ dsa_asn1.@O@ dsa_err.@O@ dsa_gen.@O@ \
......@@ -49,7 +49,7 @@ OBJS = bn_add.@O@ bn_asm.@O@ bn_comba.@O@ bn_div.@O@ \
SRCS = bn_add.c bn_asm.c bn_comba.c bn_div.c \
bn_err.c bn_exp.c bn_exp2.c bn_gcd.c \
bn_lib.c bn_m.c bn_mont.c bn_mul.c \
bn_lib.c bn_mont.c bn_mul.c \
bn_prime.c bn_rand.c bn_recp.c \
bn_shift.c bn_sqr.c bn_word.c buffer.c \
cryptlib.c dsa_asn1.c dsa_err.c dsa_gen.c \
......
......@@ -104,12 +104,12 @@ int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b)
}
/* unsigned add of b to a, r must be large enough */
int BN_uadd(BIGNUM *r, BIGNUM *a, BIGNUM *b)
int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
register int i;
int max,min;
BN_ULONG *ap,*bp,*rp,carry,t1;
BIGNUM *tmp;
const BIGNUM *tmp;
bn_check_top(a);
bn_check_top(b);
......@@ -164,7 +164,7 @@ int BN_uadd(BIGNUM *r, BIGNUM *a, BIGNUM *b)
}
/* unsigned subtraction of b from a, a must be larger than b. */
int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b)
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max,min;
register BN_ULONG t1,t2,*ap,*bp,*rp;
......@@ -255,11 +255,11 @@ int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b)
return(1);
}
int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b)
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max;
int add=0,neg=0;
BIGNUM *tmp;
const BIGNUM *tmp;
bn_check_top(a);
bn_check_top(b);
......
......@@ -264,18 +264,20 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
else
q=h/dh;
th=q*dh;
tl=dl*q;
for (;;)
{
t=(h-q*dh);
t=h-th;
if ((t&BN_MASK2h) ||
((dl*q) <= (
(t<<BN_BITS4)+
((tl) <= (
(t<<BN_BITS4)|
((l&BN_MASK2h)>>BN_BITS4))))
break;
q--;
th-=dh;
tl-=dl;
}
th=q*dh;
tl=q*dl;
t=(tl>>BN_BITS4);
tl=(tl<<BN_BITS4)&BN_MASK2h;
th+=t;
......
......@@ -57,6 +57,7 @@
*/
#include <stdio.h>
#include <openssl/bn.h>
#include "cryptlib.h"
#include "bn_lcl.h"
......@@ -117,8 +118,8 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
#else
int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,
BN_CTX *ctx)
int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
BN_CTX *ctx)
{
int norm_shift,i,j,loop;
BIGNUM *tmp,wnum,*snum,*sdiv,*res;
......@@ -199,56 +200,98 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,
for (i=0; i<loop-1; i++)
{
BN_ULONG q,n0,n1;
BN_ULONG l0;
BN_ULONG q,l0;
#ifdef BN_DIV3W
q=bn_div_3_words(wnump,d0,d1);
#else
#if !defined(NO_ASM) && !defined(PEDANTIC)
# if defined(__GNUC__) && __GNUC__>=2
# if defined(__i386)
/*
* There were two reasons for implementing this template:
* - GNU C generates a call to a function (__udivdi3 to be exact)
* in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
* understand why...);
* - divl doesn't only calculate quotient, but also leaves
* remainder in %edx which we can definitely use here:-)
*
* <appro@fy.chalmers.se>
*/
# define bn_div_words(n0,n1,d0) \
({ asm volatile ( \
"divl %4" \
: "=a"(q), "=d"(rem) \
: "a"(n1), "d"(n0), "g"(d0) \
: "cc"); \
q; \
})
# define REMINDER_IS_ALREADY_CALCULATED
# endif /* __<cpu> */
# endif /* __GNUC__ */
#endif /* NO_ASM */
BN_ULONG n0,n1,rem=0;
wnum.d--; wnum.top++;
n0=wnump[0];
n1=wnump[-1];
if (n0 == d0)
q=BN_MASK2;
else
#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0;
#else
q=bn_div_words(n0,n1,d0);
#endif
{
#ifdef BN_LLONG
BN_ULLONG t1,t2,rem;
t1=((BN_ULLONG)n0<<BN_BITS2)|n1;
BN_ULLONG t2;
#ifndef REMINDER_IS_ALREADY_CALCULATED
/*
* rem doesn't have to be BN_ULLONG. The least we
* know it's less that d0, isn't it?
*/
rem=(n1-q*d0)&BN_MASK2;
#endif
t2=(BN_ULLONG)d1*q;
for (;;)
{
t2=(BN_ULLONG)d1*q;
rem=t1-(BN_ULLONG)q*d0;
if ((rem>>BN_BITS2) ||
(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))
if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
break;
q--;
rem += d0;
if (rem < d0) break; /* don't let rem overflow */
t2 -= d1;
}
#else
BN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;
t1h=n0;
t1l=n1;
BN_ULONG t2l,t2h,ql,qh;
#ifndef REMINDER_IS_ALREADY_CALCULATED
/*
* It's more than enough with the only multiplication.
* See the comment above in BN_LLONG section...
*/
rem=(n1-q*d0)&BN_MASK2;
#endif
t2l=LBITS(d1); t2h=HBITS(d1);
ql =LBITS(q); qh =HBITS(q);
mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
for (;;)
{
t2l=LBITS(d1); t2h=HBITS(d1);
ql =LBITS(q); qh =HBITS(q);
mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
t3t=LBITS(d0); t3h=HBITS(d0);
mul64(t3t,t3h,ql,qh); /* t3=t1-(BN_ULLONG)q*d0; */
t3l=(t1l-t3t)&BN_MASK2;
if (t3l > t1l) t3h++;
t3h=(t1h-t3h)&BN_MASK2;
/*if ((t3>>BN_BITS2) ||
(t2 <= ((t3<<BN_BITS2)+wnump[-2])))
break; */
if (t3h) break;
if (t2h < t3l) break;
if ((t2h == t3l) && (t2l <= wnump[-2])) break;
if ((t2h < rem) ||
((t2h == rem) && (t2l <= wnump[-2])))
break;
q--;
rem += d0;
if (rem < d0) break; /* don't let rem overflow */
if (t2l < d1) t2h--; t2l -= d1;
}
#endif
}
#endif /* !BN_DIV3W */
wnum.d--; wnum.top++;
l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
tmp->d[div_n]=l0;
for (j=div_n+1; j>0; j--)
......@@ -283,7 +326,7 @@ err:
#endif
/* rem != m */
int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
{
#if 0 /* The old slow way */
int i,nm,nd;
......
......@@ -63,7 +63,7 @@
#define TABLE_SIZE 16
/* slow but works */
int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, BN_CTX *ctx)
int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
{
BIGNUM *t;
int r=0;
......@@ -154,7 +154,8 @@ err:
return(ret);
}
int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
BN_CTX *ctx)
{
int ret;
......@@ -183,7 +184,8 @@ int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
}
/* #ifdef RECP_MUL_MOD */
int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx)
{
int i,j,bits,ret=0,wstart,wend,window,wvalue;
int start=1,ts=0;
......@@ -296,12 +298,13 @@ err:
/* #endif */
/* #ifdef MONT_MUL_MOD */
int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *in_mont)
int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
{
int i,j,bits,ret=0,wstart,wend,window,wvalue;
int start=1,ts=0;
BIGNUM *d,*aa,*r;
BIGNUM *d,*r;
BIGNUM *aa;
BIGNUM val[TABLE_SIZE];
BN_MONT_CTX *mont=NULL;
......
......@@ -140,7 +140,7 @@ err:
}
/* solves ax == 1 (mod n) */
BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, BIGNUM *n, BN_CTX *ctx)
BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
{
BIGNUM *A,*B,*X,*Y,*M,*D,*R;
BIGNUM *T,*ret=NULL;
......
......@@ -84,28 +84,28 @@ void BN_set_params(int mult, int high, int low, int mont)
{
if (mult >= 0)
{
if (mult > (sizeof(int)*8)-1)
if ((unsigned int)mult > (sizeof(int)*8)-1)
mult=sizeof(int)*8-1;
bn_limit_bits=mult;
bn_limit_num=1<<mult;
}
if (high >= 0)
{
if (high > (sizeof(int)*8)-1)
if ((unsigned int)high > (sizeof(int)*8)-1)
high=sizeof(int)*8-1;
bn_limit_bits_high=high;
bn_limit_num_high=1<<high;
}
if (low >= 0)
{
if (low > (sizeof(int)*8)-1)
if ((unsigned int)low > (sizeof(int)*8)-1)
low=sizeof(int)*8-1;
bn_limit_bits_low=low;
bn_limit_num_low=1<<low;
}
if (mont >= 0)
{
if (mont > (sizeof(int)*8)-1)
if ((unsigned int)mont > (sizeof(int)*8)-1)
mont=sizeof(int)*8-1;
bn_limit_bits_mont=mont;
bn_limit_num_mont=1<<mont;
......@@ -235,7 +235,7 @@ int BN_num_bits_word(BN_ULONG l)
}
}
int BN_num_bits(BIGNUM *a)
int BN_num_bits(const BIGNUM *a)
{
BN_ULONG l;
int i;
......@@ -485,10 +485,12 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
return(b);
}
BIGNUM *BN_dup(BIGNUM *a)
BIGNUM *BN_dup(const BIGNUM *a)
{
BIGNUM *r;
if (a == NULL) return NULL;
bn_check_top(a);
r=BN_new();
......@@ -496,7 +498,7 @@ BIGNUM *BN_dup(BIGNUM *a)
return((BIGNUM *)BN_copy(r,a));
}
BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
int i;
BN_ULONG *A;
......@@ -549,7 +551,7 @@ BN_ULONG BN_get_word(BIGNUM *a)
BN_ULONG ret=0;
n=BN_num_bytes(a);
if (n > sizeof(BN_ULONG))
if ((unsigned int)n > sizeof(BN_ULONG))
return(BN_MASK2);
for (i=a->top-1; i>=0; i--)
{
......@@ -567,7 +569,7 @@ BN_ULONG BN_get_word(BIGNUM *a)
int BN_set_word(BIGNUM *a, BN_ULONG w)
{
int i,n;
if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
if (bn_expand(a,(int)sizeof(BN_ULONG)*8) == NULL) return(0);
n=sizeof(BN_ULONG)/BN_BYTES;
a->neg=0;
......@@ -629,7 +631,7 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
}
/* ignore negative */
int BN_bn2bin(BIGNUM *a, unsigned char *to)
int BN_bn2bin(const BIGNUM *a, unsigned char *to)
{
int n,i;
BN_ULONG l;
......@@ -643,7 +645,7 @@ int BN_bn2bin(BIGNUM *a, unsigned char *to)
return(n);
}
int BN_ucmp(BIGNUM *a, BIGNUM *b)
int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
{
int i;
BN_ULONG t1,t2,*ap,*bp;
......@@ -665,7 +667,7 @@ int BN_ucmp(BIGNUM *a, BIGNUM *b)
return(0);
}
int BN_cmp(BIGNUM *a, BIGNUM *b)
int BN_cmp(const BIGNUM *a, const BIGNUM *b)
{
int i;
int gt,lt;
......@@ -737,7 +739,7 @@ int BN_clear_bit(BIGNUM *a, int n)
return(1);
}
int BN_is_bit_set(BIGNUM *a, int n)
int BN_is_bit_set(const BIGNUM *a, int n)
{
int i,j;
......
/* crypto/bn/bn_m.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include "bn_lcl.h"
#include <openssl/stack.h>
int limit=16;
typedef struct bn_pool_st
{
int used;
int tos;
STACK *sk;
} BN_POOL;
BIGNUM *BN_POOL_push(BN_POOL *bp)
{
BIGNUM *ret;
if (bp->used >= bp->tos)
{
ret=BN_new();
sk_push(bp->sk,(char *)ret);
bp->tos++;
bp->used++;
}
else
{
ret=(BIGNUM *)sk_value(bp->sk,bp->used);
bp->used++;
}
return(ret);
}
void BN_POOL_pop(BN_POOL *bp, int num)
{
bp->used-=num;
}
int BN_m(BIGNUM *r, BIGNUM *a, BIGNUM *b)
{
static BN_POOL bp;
static init=1;
if (init)
{
bp.used=0;
bp.tos=0;
bp.sk=sk_new_null();
init=0;
}
return(BN_mm(r,a,b,&bp));
}
/* r must be different to a and b */
int BN_mm(BIGNUM *m, BIGNUM *A, BIGNUM *B, BN_POOL *bp)
{
int i,num;
int an,bn;
BIGNUM *a,*b,*c,*d,*ac,*bd;
an=A->top;
bn=B->top;
if ((an <= limit) || (bn <= limit))
{
/* BEW */
BN_CTX ctx;
return(BN_mul(m,A,B, &ctx));
}
a=BN_POOL_push(bp);
b=BN_POOL_push(bp);
c=BN_POOL_push(bp);
d=BN_POOL_push(bp);
ac=BN_POOL_push(bp);
bd=BN_POOL_push(bp);
num=(an <= bn)?an:bn;
num=1<<(BN_num_bits_word(num-1)-1);
/* Are going to now chop things into 'num' word chunks. */
num*=BN_BITS2;
BN_copy(a,A);
BN_mask_bits(a,num);
BN_rshift(b,A,num);
BN_copy(c,B);
BN_mask_bits(c,num);
BN_rshift(d,B,num);
BN_sub(ac ,b,a);
BN_sub(bd,c,d);
BN_mm(m,ac,bd,bp);
BN_mm(ac,a,c,bp);
BN_mm(bd,b,d,bp);
BN_add(m,m,ac);
BN_add(m,m,bd);
BN_lshift(m,m,num);
BN_lshift(bd,bd,num*2);
BN_add(m,m,ac);
BN_add(m,m,bd);
BN_POOL_pop(bp,6);
return(1);
}
......@@ -68,8 +68,8 @@
#define MONT_WORD
int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *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;
......@@ -298,7 +298,7 @@ void BN_MONT_CTX_free(BN_MONT_CTX *mont)
Free(mont);
}
int BN_MONT_CTX_set(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;
......
......@@ -597,14 +597,14 @@ printf("BN_mul %d * %d\n",a->top,b->top);
/* if (al == 4)
{
if (bn_wexpand(rr,8) == NULL) return(0);
r->top=8;
rr->top=8;
bn_mul_comba4(rr->d,a->d,b->d);
goto end;