Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/netpgpverify Sync with p...



details:   https://anonhg.NetBSD.org/src/rev/d908b1ad0460
branches:  trunk
changeset: 345900:d908b1ad0460
user:      agc <agc%NetBSD.org@localhost>
date:      Tue Jun 14 20:47:08 2016 +0000

description:
Sync with pkgsrc sources as of version 20160614

+ pick up renaming changes to internal routines
+ fix for issue verifying signatures created by gpg --no-emit-version
+ add test for same

diffstat:

 crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.bsd |    4 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.in  |   23 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/bignum.c     |  347 ++++++---
 crypto/external/bsd/netpgp/dist/src/netpgpverify/bn.h         |  174 +++-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/bzlib.c      |   14 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/digest.c     |   46 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/digest.h     |   12 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/libverify.c  |  360 ++++++---
 crypto/external/bsd/netpgp/dist/src/netpgpverify/md5.h        |   26 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/md5c.c       |   15 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/misc.c       |    1 -
 crypto/external/bsd/netpgp/dist/src/netpgpverify/pgpsum.c     |    3 +
 crypto/external/bsd/netpgp/dist/src/netpgpverify/rmd160.c     |   29 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/rmd160.h     |   31 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/rsa.c        |  205 ++--
 crypto/external/bsd/netpgp/dist/src/netpgpverify/rsa.h        |   48 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/sha1.c       |   22 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/sha1.h       |   31 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.c       |   90 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/sha2.h       |   80 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/tiger.c      |   38 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/tiger.h      |   18 +-
 crypto/external/bsd/netpgp/dist/src/netpgpverify/verify.h     |    4 +-
 23 files changed, 981 insertions(+), 640 deletions(-)

diffs (truncated from 3591 to 300 lines):

diff -r dacdc8e80f83 -r d908b1ad0460 crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.bsd
--- a/crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.bsd     Tue Jun 14 18:16:06 2016 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.bsd     Tue Jun 14 20:47:08 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.bsd,v 1.4 2015/02/05 01:26:54 agc Exp $
+# $NetBSD: Makefile.bsd,v 1.5 2016/06/14 20:47:08 agc Exp $
 
 PROG=netpgpverify
 
@@ -43,3 +43,5 @@
        rm -f 1keytest.gpg
        @echo "testing signing with a subkey"
        ./chk.sh -k joyent-pubring.gpg digest-20121220.tgz
+       @echo "testing signatures with no version"
+       ./${PROG} -k pubring.gpg noversion.asc
diff -r dacdc8e80f83 -r d908b1ad0460 crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.in
--- a/crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.in      Tue Jun 14 18:16:06 2016 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/netpgpverify/Makefile.in      Tue Jun 14 20:47:08 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.8 2014/03/09 00:15:45 agc Exp $
+# $NetBSD: Makefile.in,v 1.9 2016/06/14 20:47:08 agc Exp $
 
 PROG=netpgpverify
 
@@ -26,8 +26,25 @@
        ./${PROG} -k pubring.gpg NetBSD-6.0_RC1_hashes.asc
        ./${PROG} -k pubring.gpg NetBSD-6.0_RC1_hashes.gpg
        ./${PROG} -v
-       ./${PROG} -S testkey.pub data.gpg
-       ./${PROG} -S testkey.pub data.sig
+       ./${PROG} -S sshtest-20140202.pub data.gpg
+       ./${PROG} -S sshtest-20140202.pub data.sig
+       @echo "expected failure, to check bad signatures fail to verify"
+       -sed -e 's|A|B|' data.gpg | ./${PROG} -S sshtest-20140202.pub
+       @echo ""
+       @echo "expected failure, no valid key for verification"
+       -./${PROG} -k /dev/null NetBSD-6.0_RC1_hashes.gpg
+       @echo "dumping now"
+       ./${PROG} -c dump -k pubring.gpg NetBSD-6.0_RC1_hashes.asc > /dev/null
+       @echo "dumping ssh now"
+       ./${PROG} -c dump -S sshtest-20140202.pub data.gpg
+       @echo "testing pubring with one key"
+       uudecode 1keytest.gpg.uu
+       ./${PROG} -k 1keypubring.gpg 1keytest.gpg
+       rm -f 1keytest.gpg
+       @echo "testing signing with a subkey"
+       ./chk.sh -k joyent-pubring.gpg digest-20121220.tgz
+       @echo "testing signatures with no version"
+       ./${PROG} -k pubring.gpg noversion.asc
 
 clean:
        rm -rf *.core ${OBJS} ${PROG}
diff -r dacdc8e80f83 -r d908b1ad0460 crypto/external/bsd/netpgp/dist/src/netpgpverify/bignum.c
--- a/crypto/external/bsd/netpgp/dist/src/netpgpverify/bignum.c Tue Jun 14 18:16:06 2016 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/netpgpverify/bignum.c Tue Jun 14 20:47:08 2016 +0000
@@ -45,6 +45,7 @@
 # include <sys/kmem.h>
 #else
 # include <arpa/inet.h>
+# include <limits.h>
 # include <stdarg.h>
 # include <stdio.h>
 # include <stdlib.h>
@@ -88,6 +89,10 @@
 #define        __arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))
 #endif
 
+#ifndef MIN
+#define MIN(a,b)       (((a)<(b))?(a):(b))
+#endif
+
 #define MP_ISZERO(a) (((a)->used == 0) ? MP_YES : MP_NO)
 
 typedef int           mp_err;
@@ -216,7 +221,7 @@
 
 /* copy, b = a */
 static int
-mp_copy(BIGNUM *a, BIGNUM *b)
+mp_copy(PGPV_BIGNUM *a, PGPV_BIGNUM *b)
 {
        int     res;
 
@@ -1333,13 +1338,13 @@
 
 top:
        /* 4.  while u is even do */
-       while (BN_is_even(&u) == 1) {
+       while (PGPV_BN_is_even(&u) == 1) {
                /* 4.1 u = u/2 */
                if ((res = half(&u, &u)) != MP_OKAY) {
                        goto LBL_ERR;
                }
                /* 4.2 if B is odd then */
-               if (BN_is_odd(&B) == 1) {
+               if (PGPV_BN_is_odd(&B) == 1) {
                        if ((res = signed_subtract(&B, &x, &B)) != MP_OKAY) {
                                goto LBL_ERR;
                        }
@@ -1351,13 +1356,13 @@
        }
 
        /* 5.  while v is even do */
-       while (BN_is_even(&v) == 1) {
+       while (PGPV_BN_is_even(&v) == 1) {
                /* 5.1 v = v/2 */
                if ((res = half(&v, &v)) != MP_OKAY) {
                        goto LBL_ERR;
                }
                /* 5.2 if D is odd then */
-               if (BN_is_odd(&D) == 1) {
+               if (PGPV_BN_is_odd(&D) == 1) {
                        /* D = (D-x)/2 */
                        if ((res = signed_subtract(&D, &x, &D)) != MP_OKAY) {
                                goto LBL_ERR;
@@ -1446,7 +1451,7 @@
        }
 
        /* 2. [modified] if x,y are both even then return an error! */
-       if (BN_is_even(&x) == 1 && BN_is_even(&y) == 1) {
+       if (PGPV_BN_is_even(&x) == 1 && PGPV_BN_is_even(&y) == 1) {
                res = MP_VAL;
                goto LBL_ERR;
        }
@@ -1463,13 +1468,13 @@
 
 top:
        /* 4.  while u is even do */
-       while (BN_is_even(&u) == 1) {
+       while (PGPV_BN_is_even(&u) == 1) {
                /* 4.1 u = u/2 */
                if ((res = half(&u, &u)) != MP_OKAY) {
                        goto LBL_ERR;
                }
                /* 4.2 if A or B is odd then */
-               if (BN_is_odd(&A) == 1 || BN_is_odd(&B) == 1) {
+               if (PGPV_BN_is_odd(&A) == 1 || PGPV_BN_is_odd(&B) == 1) {
                        /* A = (A+y)/2, B = (B-x)/2 */
                        if ((res = signed_add(&A, &y, &A)) != MP_OKAY) {
                                 goto LBL_ERR;
@@ -1488,13 +1493,13 @@
        }
 
        /* 5.  while v is even do */
-       while (BN_is_even(&v) == 1) {
+       while (PGPV_BN_is_even(&v) == 1) {
                /* 5.1 v = v/2 */
                if ((res = half(&v, &v)) != MP_OKAY) {
                        goto LBL_ERR;
                }
                /* 5.2 if C or D is odd then */
-               if (BN_is_odd(&C) == 1 || BN_is_odd(&D) == 1) {
+               if (PGPV_BN_is_odd(&C) == 1 || PGPV_BN_is_odd(&D) == 1) {
                        /* C = (C+y)/2, D = (D-x)/2 */
                        if ((res = signed_add(&C, &y, &C)) != MP_OKAY) {
                                 goto LBL_ERR;
@@ -1542,7 +1547,7 @@
        }
 
        /* if not zero goto step 4 */
-       if (BN_is_zero(&u) == 0) {
+       if (PGPV_BN_is_zero(&u) == 0) {
                goto top;
        }
        /* now a = C, b = D, gcd == g*v */
@@ -1584,7 +1589,7 @@
        }
 
        /* if the modulus is odd we can use a faster routine instead */
-       if (BN_is_odd(b) == 1) {
+       if (PGPV_BN_is_odd(b) == 1) {
                return fast_modular_inverse(a, b, c);
        }
        return slow_modular_inverse(a, b, c);
@@ -4351,7 +4356,7 @@
        }
 
        /* if the modulus is odd or diminished_radix, use the montgomery method */
-       if (BN_is_odd(P) == 1 || diminished_radix) {
+       if (PGPV_BN_is_odd(P) == 1 || diminished_radix) {
                return fast_exponent_modulo(G, X, P, Y, diminished_radix);
        }
        /* otherwise use the generic Barrett reduction technique */
@@ -5019,7 +5024,7 @@
 }
 
 static char *
-formatbn(const BIGNUM *a, const int radix)
+formatbn(const PGPV_BIGNUM *a, const int radix)
 {
        char    *s;
        int      len;
@@ -5081,11 +5086,11 @@
 }
 
 static int
-getbn(BIGNUM **a, const char *str, int radix)
+getbn(PGPV_BIGNUM **a, const char *str, int radix)
 {
        int     len;
 
-       if (a == NULL || str == NULL || (*a = BN_new()) == NULL) {
+       if (a == NULL || str == NULL || (*a = PGPV_BN_new()) == NULL) {
                return 0;
        }
        if (mp_getradix_num(*a, radix, __UNCONST(str)) != MP_OKAY) {
@@ -5116,32 +5121,120 @@
        return res;
 }
 
+/* bn_mp_gcd.c */
+/* Greatest Common Divisor using the binary method */
+static int
+mp_gcd(mp_int *a, mp_int *b, mp_int *c)
+{
+       mp_int  u, v;
+       int     k, u_lsb, v_lsb, res;
+
+       /* either zero than gcd is the largest */
+       if (PGPV_BN_is_zero(a) == MP_YES) {
+               return absolute(b, c);
+       }
+       if (PGPV_BN_is_zero(b) == MP_YES) {
+               return absolute(a, c);
+       }
+
+       /* get copies of a and b we can modify */
+       if ((res = mp_init_copy(&u, a)) != MP_OKAY) {
+               return res;
+       }
+
+       if ((res = mp_init_copy(&v, b)) != MP_OKAY) {
+               goto LBL_U;
+       }
+
+       /* must be positive for the remainder of the algorithm */
+       u.sign = v.sign = MP_ZPOS;
+
+       /* B1.  Find the common power of two for u and v */
+       u_lsb = mp_cnt_lsb(&u);
+       v_lsb = mp_cnt_lsb(&v);
+       k = MIN(u_lsb, v_lsb);
+
+       if (k > 0) {
+               /* divide the power of two out */
+               if ((res = rshift_bits(&u, k, &u, NULL)) != MP_OKAY) {
+                       goto LBL_V;
+               }
+
+               if ((res = rshift_bits(&v, k, &v, NULL)) != MP_OKAY) {
+                       goto LBL_V;
+               }
+       }
+
+       /* divide any remaining factors of two out */
+       if (u_lsb != k) {
+               if ((res = rshift_bits(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
+                       goto LBL_V;
+               }
+       }
+
+       if (v_lsb != k) {
+               if ((res = rshift_bits(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
+                       goto LBL_V;
+               }
+       }
+
+       while (PGPV_BN_is_zero(&v) == 0) {
+               /* make sure v is the largest */
+               if (compare_magnitude(&u, &v) == MP_GT) {
+                       /* swap u and v to make sure v is >= u */
+                       mp_exch(&u, &v);
+               }
+
+               /* subtract smallest from largest */
+               if ((res = signed_subtract(&v, &u, &v)) != MP_OKAY) {
+                       goto LBL_V;
+               }
+
+               /* Divide out all factors of two */
+               if ((res = rshift_bits(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
+                       goto LBL_V;
+               } 
+       } 
+
+       /* multiply by 2**k which we divided out at the beginning */
+       if ((res = lshift_bits(&u, k, c)) != MP_OKAY) {
+               goto LBL_V;
+       }
+       c->sign = MP_ZPOS;
+       res = MP_OKAY;
+LBL_V:
+       mp_clear (&u);
+LBL_U:
+       mp_clear (&v);
+       return res;
+}
+
 /**************************************************************************/
 



Home | Main Index | Thread Index | Old Index