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 Merge netpgpverify(1) and libnetp...



details:   https://anonhg.NetBSD.org/src/rev/a9d2e35b3d07
branches:  trunk
changeset: 782778:a9d2e35b3d07
user:      agc <agc%NetBSD.org@localhost>
date:      Tue Nov 20 05:26:24 2012 +0000

description:
Merge netpgpverify(1) and libnetpgpverify(3) from the
agc-netpgp-standalone branch.

Rewrite the netpgpverify(1) functionality from RFC4880 up.  This is a
completely new implementation, and uses its own bignum library derived
from libtommath.  Apart from libz and libbz2, it just uses its own
library and is self-contained - this makes it easier to embed, and to
use from scripting languages.

netpgpverify(1) now verifies all the signed files i've thrown at it,
and the added bonus of using no functionality from libcrypto - all of
its bignum functionality comes from its own libnetpgpverify.so.
netpgpverify(1) now verifies not only signatures on binary files, but
also signatures on text documents.  This fixes PR/46930.  Please don't
start me on the hoops I had to jump through to calculate the digests
on text files; trust me, you will regret it.

% supersize `which netpgpverify`
   text    data     bss     dec     hex filename
   4452     860      72    5384    1508 /usr/bin/netpgpverify
  79542    1408       0   80950   13c36 /usr/lib/libz.so.1
  43994     984     488   45466    b19a /usr/lib/libgcc_s.so.1
1318116   49644   69272 1437032  15ed68 /usr/lib/libc.so.12
  57253    4184       0   61437    effd /usr/lib/libbz2.so.1
 108726    1712       0  110438   1af66 /usr/lib/libnetpgpverify.so.4
  1612083    58792   69832   1740707   0x1a8fa3   total
%

% make t
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -c verify b.gpg > output16
diff expected16 output16
rm -f output16
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -c verify a.gpg > output17
diff expected17 output17
rm -f output17
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -c verify gpgsigned-a.gpg > output18
diff expected18 output18
rm -f output18
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -c verify NetBSD-6.0_RC2_hashes.asc > output19
diff expected19 output19
rm -f output19
...
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -k dsa-pubring.gpg in2.asc > output45
diff expected45 output45
rm -f output45
env LD_LIBRARY_PATH=/usr/src/crypto/external/bsd/netpgp-standalone/lib/verify ./netpgpverify -k problem-pubring.gpg NetBSD-6.0_hashes.asc > output46
diff expected46 output46
rm -f output46
cd tests/netpgpverify && make && atf-run
atf2kyua: I: Removing stale Kyuafiles from /tmp/.XXXXXX.004966aa
atf2kyua: I: Converting /usr/src/crypto/external/bsd/netpgp-standalone/tests/netpgpverify/Atffile -> /tmp/.XXXXXX.004966aa/Kyuafile
t_netpgpverify:netpgpverify_rsa  ->  passed  [0.221s]
t_netpgpverify:netpgpverify_dsa  ->  passed  [0.117s]

2/2 passed (0 failed)
Committed action 19
%

diffstat:

 crypto/external/bsd/netpgp/Makefile                             |     5 +-
 crypto/external/bsd/netpgp/bin/Makefile                         |     5 +
 crypto/external/bsd/netpgp/bin/netpgpverify/Makefile            |   119 +
 crypto/external/bsd/netpgp/dist/src/libbn/Makefile              |    13 +
 crypto/external/bsd/netpgp/dist/src/libbn/bignum.c              |  5635 ++++++++++
 crypto/external/bsd/netpgp/dist/src/libbn/bn.h                  |   145 +
 crypto/external/bsd/netpgp/dist/src/libbn/libnetpgpbn.3         |   304 +
 crypto/external/bsd/netpgp/dist/src/libbn/misc.c                |    82 +
 crypto/external/bsd/netpgp/dist/src/libbn/misc.h                |    53 +
 crypto/external/bsd/netpgp/dist/src/libbn/rand.c                |    60 +
 crypto/external/bsd/netpgp/dist/src/libbn/rand.h                |    44 +
 crypto/external/bsd/netpgp/dist/src/libbn/stubs.c               |   217 +
 crypto/external/bsd/netpgp/dist/src/libbn/stubs.h               |    94 +
 crypto/external/bsd/netpgp/dist/src/libdigest/Makefile          |    16 +
 crypto/external/bsd/netpgp/dist/src/libdigest/digest.c          |   383 +
 crypto/external/bsd/netpgp/dist/src/libdigest/digest.h          |   109 +
 crypto/external/bsd/netpgp/dist/src/libdigest/tiger.3           |   219 +
 crypto/external/bsd/netpgp/dist/src/libdigest/tiger.c           |   906 +
 crypto/external/bsd/netpgp/dist/src/libdigest/tiger.h           |    65 +
 crypto/external/bsd/netpgp/dist/src/librsa/Makefile             |    10 +
 crypto/external/bsd/netpgp/dist/src/librsa/libnetpgprsa.3       |   114 +
 crypto/external/bsd/netpgp/dist/src/librsa/rsa.c                |   696 +
 crypto/external/bsd/netpgp/dist/src/librsa/rsa.h                |   155 +
 crypto/external/bsd/netpgp/dist/src/librsa/rsastubs.c           |    83 +
 crypto/external/bsd/netpgp/dist/src/librsa/rsastubs.h           |    25 +
 crypto/external/bsd/netpgp/dist/src/libverify/Makefile          |    71 +
 crypto/external/bsd/netpgp/dist/src/libverify/array.h           |    82 +
 crypto/external/bsd/netpgp/dist/src/libverify/b64.c             |   355 +
 crypto/external/bsd/netpgp/dist/src/libverify/b64.h             |    32 +
 crypto/external/bsd/netpgp/dist/src/libverify/dump.c            |    88 +
 crypto/external/bsd/netpgp/dist/src/libverify/libnetpgpverify.3 |   139 +
 crypto/external/bsd/netpgp/dist/src/libverify/libverify.c       |  2366 ++++
 crypto/external/bsd/netpgp/dist/src/libverify/pgpsum.c          |   187 +
 crypto/external/bsd/netpgp/dist/src/libverify/pgpsum.h          |    35 +
 crypto/external/bsd/netpgp/dist/src/libverify/verify.h          |   292 +
 crypto/external/bsd/netpgp/dist/src/netpgpverify/main.c         |   165 +
 crypto/external/bsd/netpgp/lib/verify/Makefile                  |    19 +
 crypto/external/bsd/netpgp/lib/verify/shlib_version             |     2 +
 38 files changed, 13388 insertions(+), 2 deletions(-)

diffs (truncated from 13548 to 300 lines):

diff -r 5390c96778b4 -r a9d2e35b3d07 crypto/external/bsd/netpgp/Makefile
--- a/crypto/external/bsd/netpgp/Makefile       Mon Nov 19 23:43:08 2012 +0000
+++ b/crypto/external/bsd/netpgp/Makefile       Tue Nov 20 05:26:24 2012 +0000
@@ -1,8 +1,9 @@
-#      $NetBSD: Makefile,v 1.5 2010/09/02 06:00:11 agc Exp $
+#      $NetBSD: Makefile,v 1.6 2012/11/20 05:26:24 agc Exp $
 
 SUBDIR=                libmj .WAIT
+SUBDIR+=       lib/verify .WAIT
 SUBDIR+=       lib .WAIT
-SUBDIR+=       netpgp netpgpkeys netpgpverify
+SUBDIR+=       netpgp netpgpkeys bin
 #SUBDIR+=      hkpc hkpd
 
 .include <bsd.subdir.mk>
diff -r 5390c96778b4 -r a9d2e35b3d07 crypto/external/bsd/netpgp/bin/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/bin/Makefile   Tue Nov 20 05:26:24 2012 +0000
@@ -0,0 +1,5 @@
+#      $NetBSD: Makefile,v 1.4 2012/11/20 05:26:25 agc Exp $
+
+SUBDIR+=       netpgpverify
+
+.include <bsd.subdir.mk>
diff -r 5390c96778b4 -r a9d2e35b3d07 crypto/external/bsd/netpgp/bin/netpgpverify/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/bin/netpgpverify/Makefile      Tue Nov 20 05:26:24 2012 +0000
@@ -0,0 +1,119 @@
+# $NetBSD: Makefile,v 1.2 2012/11/20 05:26:25 agc Exp $
+
+.include <bsd.own.mk>
+
+PROG=netpgpverify
+SRCS+=main.c
+BINDIR=/usr/bin
+
+WARNS=5
+MAN=netpgpverify.1
+
+CPPFLAGS+=-I${EXTDIST}/libverify
+
+LIBNETPGPVERIFYDIR!=   cd ${.CURDIR}/../../lib/verify && ${PRINTOBJDIR}
+LDADD+=         -L${LIBNETPGPVERIFYDIR} -lnetpgpverify
+DPADD+=         ${LIBNETPGPVERIFYDIR}/libnetpgpverify.a
+
+LDADD+=         -lz -lbz2
+DPADD+=         ${LIBZ} ${LIBBZ2}
+
+EXTDIST= ${.CURDIR}/../../dist/src
+.PATH: ${EXTDIST}/netpgpverify
+
+.include <bsd.prog.mk>
+
+t: ${PROG}
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c verify b.gpg > output16
+       diff expected16 output16
+       rm -f output16
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c verify a.gpg > output17
+       diff expected17 output17
+       rm -f output17
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c verify gpgsigned-a.gpg > output18
+       diff expected18 output18
+       rm -f output18
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c verify NetBSD-6.0_RC2_hashes.asc > output19
+       diff expected19 output19
+       rm -f output19
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c cat jj.asc > output20
+       diff expected20 output20
+       rm -f output20
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < a.gpg > output21
+       diff expected21 output21
+       rm -f output21
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < jj.asc > output22
+       diff expected22 output22
+       rm -f output22
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < NetBSD-6.0_RC2_hashes.asc > output23
+       diff expected23 output23
+       rm -f output23
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < b.gpg > output24
+       diff expected24 output24
+       rm -f output24
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} NetBSD-6.0_RC1_hashes.gpg > output25
+       diff expected25 output25
+       rm -f output25
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < NetBSD-6.0_RC1_hashes.gpg > output26
+       diff expected26 output26
+       rm -f output26
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < NetBSD-6.0_hashes.asc > output27
+       diff expected27 output27
+       rm -f output27
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} NetBSD-6.0_hashes.asc > output28
+       diff expected28 output28
+       rm -f output28
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} NetBSD-6.0_RC1_hashes_ascii.gpg > output29
+       diff expected29 output29
+       rm -f output29
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} < NetBSD-6.0_RC1_hashes_ascii.gpg > output30
+       diff expected30 output30
+       rm -f output30
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c cat b.gpg b.gpg b.gpg > output31
+       diff expected31 output31
+       rm -f output31
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} b.gpg b.gpg b.gpg > output32
+       diff expected32 output32
+       rm -f output32
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c cat b.gpg jj.asc b.gpg > output33
+       diff expected33 output33
+       rm -f output33
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} det.sig > output34
+       diff expected34 output34
+       rm -f output34
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -c cat det.sig > output35
+       diff expected35 output35
+       rm -f output35
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg in1.gpg > output36
+       diff expected36 output36
+       rm -f output36
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg < in1.gpg > output37
+       diff expected37 output37
+       rm -f output37
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg in1.asc > output38
+       diff expected38 output38
+       rm -f output38
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg < in1.asc > output39
+       diff expected39 output39
+       rm -f output39
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg -c cat in1.gpg > output40
+       diff expected40 output40
+       rm -f output40
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg -c cat < in1.gpg > output41
+       diff expected41 output41
+       rm -f output41
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg -c cat in1.asc > output42
+       diff expected42 output42
+       rm -f output42
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg -c cat < in1.asc > output43
+       diff expected43 output43
+       rm -f output43
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg in2.gpg > output44
+       diff expected44 output44
+       rm -f output44
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k dsa-pubring.gpg in2.asc > output45
+       diff expected45 output45
+       rm -f output45
+       env LD_LIBRARY_PATH=${LIBNETPGPVERIFYDIR} ./${PROG} -k problem-pubring.gpg NetBSD-6.0_hashes.asc > output46
+       diff expected46 output46
+       rm -f output46
diff -r 5390c96778b4 -r a9d2e35b3d07 crypto/external/bsd/netpgp/dist/src/libbn/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libbn/Makefile        Tue Nov 20 05:26:24 2012 +0000
@@ -0,0 +1,13 @@
+LIB=netbn
+SRCS= bignum.c digest.c misc.c rand.c
+SRCS+= stubs.c
+MKMAN=no
+WARNS=4
+CPPFLAGS+=-I${EXTDIST}
+
+INCS=bn.h digest.h
+INCSDIR=/usr/include/netpgp
+
+EXTDIST=       ${.CURDIR}/../cipher
+
+.include <bsd.lib.mk>
diff -r 5390c96778b4 -r a9d2e35b3d07 crypto/external/bsd/netpgp/dist/src/libbn/bignum.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/libbn/bignum.c        Tue Nov 20 05:26:24 2012 +0000
@@ -0,0 +1,5635 @@
+/*-
+ * Copyright (c) 2012 Alistair Crooks <agc%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * 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 above 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis%gmail.com@localhost, http://libtom.org
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#ifdef _KERNEL
+# include <sys/kmem.h>
+#else
+# include <arpa/inet.h>
+# include <ctype.h>
+# include <inttypes.h>
+# include <stdarg.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+# include <time.h>
+# include <unistd.h>
+#endif
+
+#include "misc.h"
+#include "bn.h"
+#include "digest.h"
+
+/**************************************************************************/
+
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis%gmail.com@localhost, http://libtom.org
+ */
+
+#define MP_PREC                32
+#define DIGIT_BIT      60
+#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)))
+
+#define MP_NO          0
+#define MP_YES         1
+
+#ifndef USE_ARG
+#define USE_ARG(x)     /*LINTED*/(void)&(x)
+#endif
+
+#ifndef __arraycount
+#define        __arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))
+#endif
+
+#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
+
+#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
+
+typedef int           mp_err;
+
+static int mp_mul(mp_int * a, mp_int * b, mp_int * c);
+static int mp_sqr(mp_int * a, mp_int * b);
+
+static int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
+
+/* set to zero */
+static void
+mp_zero(mp_int *a)
+{
+  int       n;
+  mp_digit *tmp;
+
+  a->sign = MP_ZPOS;
+  a->used = 0;
+
+  tmp = a->dp;
+  /* XXX - memset */
+  for (n = 0; n < a->alloc; n++) {
+     *tmp++ = 0;
+  }
+}
+
+/* grow as required */
+static int
+mp_grow(mp_int *a, int size)
+{
+  int     i;
+  mp_digit *tmp;
+
+  /* if the alloc size is smaller alloc more ram */
+  if (a->alloc < size) {
+    /* ensure there are always at least MP_PREC digits extra on top */



Home | Main Index | Thread Index | Old Index