CVS commit: src/crypto/external/bsd/netpgp/dist/src/libbn

2018-08-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 13 09:53:51 UTC 2018

Modified Files:
src/crypto/external/bsd/netpgp/dist/src/libbn: bignum.c

Log Message:
sprinke const


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.5 src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.6
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.5	Mon Mar 18 21:00:16 2013
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c	Mon Aug 13 05:53:51 2018
@@ -575,7 +575,7 @@ mp_init_size (mp_int * a, int size)
 }
 
 /* creates "a" then copies b into it */
-static int mp_init_copy (mp_int * a, mp_int * b)
+static int mp_init_copy (mp_int * a, const mp_int * b)
 {
   int res;
 
@@ -587,9 +587,9 @@ static int mp_init_copy (mp_int * a, mp_
 
 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
 static int
-s_mp_add (mp_int * a, mp_int * b, mp_int * c)
+s_mp_add (const mp_int * a, const mp_int * b, mp_int * c)
 {
-  mp_int *x;
+  const mp_int *x;
   int olduse, res, min, max;
 
   /* find sizes, we let |a| <= |b| which means we have to sort
@@ -617,7 +617,8 @@ s_mp_add (mp_int * a, mp_int * b, mp_int
   c->used = max + 1;
 
   {
-mp_digit u, *tmpa, *tmpb, *tmpc;
+const mp_digit *tmpa, *tmpb;
+mp_digit u, *tmpc;
 int i;
 
 /* alias for digit pointers */
@@ -675,7 +676,7 @@ s_mp_add (mp_int * a, mp_int * b, mp_int
 
 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
 static int
-s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
+s_mp_sub (const mp_int * a, const mp_int * b, mp_int * c)
 {
   int olduse, res, min, max;
 
@@ -693,7 +694,8 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int
   c->used = max;
 
   {
-mp_digit u, *tmpa, *tmpb, *tmpc;
+const mp_digit *tmpa, *tmpb;
+mp_digit u, *tmpc;
 int i;
 
 /* alias for digit pointers */
@@ -742,7 +744,7 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int
 
 /* high level subtraction (handles signs) */
 static int
-mp_sub (mp_int * a, mp_int * b, mp_int * c)
+mp_sub (const mp_int * a, const mp_int * b, mp_int * c)
 {
   int sa, sb, res;
 
@@ -831,9 +833,10 @@ static int mp_rshd (mp_int * a, int b)
 
 /* multiply by a digit */
 static int
-mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
+mp_mul_d (const mp_int * a, mp_digit b, mp_int * c)
 {
-  mp_digit u, *tmpa, *tmpc;
+  const mp_digit *tmpa;
+  mp_digit u, *tmpc;
   mp_word  r;
   int  ix, res, olduse;
 
@@ -888,7 +891,7 @@ mp_mul_d (mp_int * a, mp_digit b, mp_int
 }
 
 /* high level addition (handles signs) */
-static int mp_add (mp_int * a, mp_int * b, mp_int * c)
+static int mp_add (const mp_int * a, const mp_int * b, mp_int * c)
 {
   int sa, sb, res;
 
@@ -933,7 +936,7 @@ mp_exch(mp_int *a, mp_int *b)
 
 /* calc a value mod 2**b */
 static int
-mp_mod_2d (mp_int * a, int b, mp_int * c)
+mp_mod_2d (const mp_int * a, int b, mp_int * c)
 {
   int x, res;
 
@@ -966,7 +969,7 @@ mp_mod_2d (mp_int * a, int b, mp_int * c
 }
 
 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
-static int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
+static int mp_div_2d (const mp_int * a, int b, mp_int * c, mp_int * d)
 {
   mp_digit D, r, rr;
   int x, res;
@@ -1055,7 +1058,7 @@ static int mp_div_2d (mp_int * a, int b,
  * 14.20 from HAC but fixed to treat these cases.
 */
 static int
-mp_div(mp_int *c, mp_int *d, mp_int *a, mp_int *b)
+mp_div(mp_int *c, mp_int *d, const mp_int *a, const mp_int *b)
 {
   mp_int  q, x, y, t1, t2;
   int res, n, t, i, norm, neg;
@@ -1240,7 +1243,7 @@ LBL_Q:mp_clear ();
 
 /* c = a mod b, 0 <= c < b */
 static int
-mp_mod (mp_int * a, mp_int * b, mp_int * c)
+mp_mod (const mp_int * a, const mp_int * b, mp_int * c)
 {
   mp_int  t;
   int res;
@@ -1274,7 +1277,7 @@ static void mp_set (mp_int * a, mp_digit
 }
 
 /* b = a/2 */
-static int mp_div_2(mp_int * a, mp_int * b)
+static int mp_div_2(const mp_int * a, mp_int * b)
 {
   int x, res, oldused;
 
@@ -1321,7 +1324,7 @@ static int mp_div_2(mp_int * a, mp_int *
 }
 
 /* compare a digit */
-static int mp_cmp_d(mp_int * a, mp_digit b)
+static int mp_cmp_d(const mp_int * a, mp_digit b)
 {
   /* compare based on sign */
   if (a->sign == MP_NEG) {
@@ -1362,7 +1365,7 @@ static void mp_clear_multi(mp_int *mp, .
  * odd as per HAC Note 14.64 on pp. 610
  */
 static int
-fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
+fast_mp_invmod (const mp_int * a, const mp_int * b, mp_int * c)
 {
   mp_int  x, y, u, v, B, D;
   int res, neg;
@@ -1485,7 +1488,7 @@ LBL_ERR:mp_clear_multi (, , , , 
 
 /* hac 14.61, pp608 */
 static int
-mp_invmod_slow (mp_int * a, mp_int * b, 

CVS commit: src/crypto/external/bsd/netpgp/dist/src/libbn

2013-03-18 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Tue Mar 19 01:00:17 UTC 2013

Modified Files:
src/crypto/external/bsd/netpgp/dist/src/libbn: bignum.c

Log Message:
fix some lint on i386, noticed by Greg Troxel, thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.4 src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.5
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.4	Thu Nov 22 00:37:55 2012
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c	Tue Mar 19 01:00:16 2013
@@ -1394,7 +1394,7 @@ fast_mp_invmod (mp_int * a, mp_int * b, 
   if ((res = mp_copy (y, v)) != MP_OKAY) {
 goto LBL_ERR;
   }
-  mp_set (D, 1);
+  mp_set (D, (unsigned long)1);
 
 top:
   /* 4.  while u is even do */
@@ -1463,7 +1463,7 @@ top:
   /* now a = C, b = D, gcd == g*v */
 
   /* if v != 1 then there is no inverse */
-  if (mp_cmp_d (v, 1) != MP_EQ) {
+  if (mp_cmp_d (v, (unsigned long)1) != MP_EQ) {
 res = MP_VAL;
 goto LBL_ERR;
   }
@@ -1522,8 +1522,8 @@ mp_invmod_slow (mp_int * a, mp_int * b, 
   if ((res = mp_copy (y, v)) != MP_OKAY) {
 goto LBL_ERR;
   }
-  mp_set (A, 1);
-  mp_set (D, 1);
+  mp_set (A, (unsigned long)1);
+  mp_set (D, (unsigned long)1);
 
 top:
   /* 4.  while u is even do */



CVS commit: src/crypto/external/bsd/netpgp/dist/src/libbn

2012-12-03 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Mon Dec  3 18:02:22 UTC 2012

Modified Files:
src/crypto/external/bsd/netpgp/dist/src/libbn: bn.h

Log Message:
Make the mp_digit type an unsigned long so that it works for ILP32 and
LP64.

Fixes problems showing up on regression tests on i386 (which work fine on
amd64) i.e. turn:

t_netpgpverify (1/1): 2 test cases
netpgpverify_dsa: [0.309746s] Failed: atf-check failed; see the 
output of the test for details
netpgpverify_rsa: [0.183148s] Passed.
[0.495102s]

Failed test cases:
t_netpgpverify:netpgpverify_dsa

Summary for 1 test programs:
1 passed test cases.
1 failed test cases.
0 expected failed test cases.
0 skipped test cases.

into:

t_netpgpverify (1/1): 2 test cases
netpgpverify_dsa: [0.236076s] Passed.
netpgpverify_rsa: [0.154680s] Passed.
[0.393034s]

Summary for 1 test programs:
2 passed test cases.
0 failed test cases.
0 expected failed test cases.
0 skipped test cases.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.3 src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.4
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.3	Tue Nov 20 17:57:40 2012
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h	Mon Dec  3 18:02:22 2012
@@ -44,7 +44,8 @@
 
 __BEGIN_DECLS
 
-typedef uint64_t	mp_digit;
+/* should be 32bit on ILP32, 64bit on LP64 */
+typedef unsigned long	mp_digit;
 typedef uint64_t	mp_word;
 
 /* multi-precision integer */



CVS commit: src/crypto/external/bsd/netpgp/dist/src/libbn

2012-11-21 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Thu Nov 22 00:37:56 UTC 2012

Modified Files:
src/crypto/external/bsd/netpgp/dist/src/libbn: bignum.c

Log Message:
Fix some lint - from Havard Eidnes


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.3 src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.4
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.3	Tue Nov 20 17:57:40 2012
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c	Thu Nov 22 00:37:55 2012
@@ -500,7 +500,7 @@ mp_clear (mp_int * a)
 }
 
 /* free ram */
-netpgp_deallocate(a-dp, a-alloc);
+netpgp_deallocate(a-dp, (size_t)a-alloc);
 
 /* reset members to make debugging easier */
 a-dp= NULL;
@@ -4789,6 +4789,7 @@ mp_cnt_lsb(mp_int *a)
if ((q  1) == 0) {
   do {
  qq  = q  15;
+	 /* LINTED previous op ensures range of qq */
  x  += lnz[qq];
  q = 4;
   } while (qq == 0);
@@ -5064,6 +5065,7 @@ mp_toradix_n(mp_int * a, char *str, int 
   mp_clear (t);
   return res;
 }
+/* LINTED -- radix' range is checked above, limits d's range */
 *str++ = mp_s_rmap[d];
 ++digs;
   }
@@ -5089,9 +5091,9 @@ formatbn(const BIGNUM *a, const int radi
 	if (mp_radix_size(__UNCONST(a), radix, len) != MP_OKAY) {
 		return NULL;
 	}
-	if ((s = netpgp_allocate(1, len)) != NULL) {
+	if ((s = netpgp_allocate(1, (size_t)len)) != NULL) {
 		if (mp_toradix_n(__UNCONST(a), s, radix, len) != MP_OKAY) {
-			netpgp_deallocate(s, len);
+			netpgp_deallocate(s, (size_t)len);
 			return NULL;
 		}
 	}



CVS commit: src/crypto/external/bsd/netpgp/dist/src/libbn

2012-11-20 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Tue Nov 20 17:57:41 UTC 2012

Modified Files:
src/crypto/external/bsd/netpgp/dist/src/libbn: bignum.c bn.h

Log Message:
don't assume every platform is 64-bit - just use standard integer arithmetic


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c \
src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.2 src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.3
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c:1.2	Tue Nov 20 05:26:25 2012
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c	Tue Nov 20 17:57:40 2012
@@ -76,7 +76,7 @@
  */
 
 #define MP_PREC		32
-#define DIGIT_BIT	60
+#define DIGIT_BIT	28
 #define MP_MASK  mp_digit)1)((mp_digit)DIGIT_BIT))-((mp_digit)1))
 
 #define MP_WARRAY	/*LINTED*/(1U  (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT) + 1)))
Index: src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h
diff -u src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.2 src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.3
--- src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h:1.2	Tue Nov 20 05:26:25 2012
+++ src/crypto/external/bsd/netpgp/dist/src/libbn/bn.h	Tue Nov 20 17:57:40 2012
@@ -44,8 +44,8 @@
 
 __BEGIN_DECLS
 
-typedef unsigned long	mp_digit;
-typedef unsigned long	mp_word __attribute__ ((mode(TI)));
+typedef uint64_t	mp_digit;
+typedef uint64_t	mp_word;
 
 /* multi-precision integer */
 typedef struct mp_int {