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 %
This commit is contained in:
parent
a48b4338aa
commit
640eb22bcb
|
@ -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>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# $NetBSD: Makefile,v 1.4 2012/11/20 05:26:25 agc Exp $
|
||||
|
||||
SUBDIR+= netpgpverify
|
||||
|
||||
.include <bsd.subdir.mk>
|
|
@ -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
|
|
@ -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>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,145 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef FAUXBN_H_
|
||||
#define FAUXBN_H_ 20100108
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef _KERNEL
|
||||
# include <inttypes.h>
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef unsigned long mp_digit;
|
||||
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
||||
|
||||
/* multi-precision integer */
|
||||
typedef struct mp_int {
|
||||
mp_digit *dp; /* array of digits */
|
||||
int used; /* # of digits used */
|
||||
int alloc; /* # of digits allocated */
|
||||
int sign; /* non-zero if negative */
|
||||
} mp_int;
|
||||
|
||||
#define BIGNUM mp_int
|
||||
#define BN_ULONG mp_digit
|
||||
|
||||
/* a "context" of mp integers - never really used */
|
||||
typedef struct bn_ctx_t {
|
||||
size_t count;
|
||||
size_t arraysize;
|
||||
BIGNUM **v;
|
||||
} BN_CTX;
|
||||
|
||||
#define MP_LT -1
|
||||
#define MP_EQ 0
|
||||
#define MP_GT 1
|
||||
|
||||
#define MP_ZPOS 0
|
||||
#define MP_NEG 1
|
||||
|
||||
#define MP_OKAY 0
|
||||
#define MP_MEM -2
|
||||
#define MP_VAL -3
|
||||
#define MP_RANGE MP_VAL
|
||||
|
||||
/*********************************/
|
||||
|
||||
#define BN_is_negative(x) ((x)->sign == MP_NEG)
|
||||
#define BN_is_zero(a) (((a)->used == 0) ? 1 : 0)
|
||||
#define BN_is_odd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? 1 : 0)
|
||||
#define BN_is_even(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? 1 : 0)
|
||||
|
||||
BIGNUM *BN_new(void);
|
||||
BIGNUM *BN_dup(const BIGNUM */*a*/);
|
||||
int BN_copy(BIGNUM */*b*/, const BIGNUM */*a*/);
|
||||
|
||||
void BN_init(BIGNUM */*a*/);
|
||||
void BN_free(BIGNUM */*a*/);
|
||||
void BN_clear(BIGNUM */*a*/);
|
||||
void BN_clear_free(BIGNUM */*a*/);
|
||||
|
||||
int BN_cmp(BIGNUM */*a*/, BIGNUM */*b*/);
|
||||
|
||||
BIGNUM *BN_bin2bn(const uint8_t */*buf*/, int /*size*/, BIGNUM */*bn*/);
|
||||
int BN_bn2bin(const BIGNUM */*a*/, unsigned char */*b*/);
|
||||
char *BN_bn2hex(const BIGNUM */*a*/);
|
||||
char *BN_bn2dec(const BIGNUM */*a*/);
|
||||
int BN_hex2bn(BIGNUM **/*a*/, const char */*str*/);
|
||||
int BN_dec2bn(BIGNUM **/*a*/, const char */*str*/);
|
||||
#ifndef _KERNEL
|
||||
int BN_print_fp(FILE */*fp*/, const BIGNUM */*a*/);
|
||||
#endif
|
||||
|
||||
int BN_add(BIGNUM */*r*/, const BIGNUM */*a*/, const BIGNUM */*b*/);
|
||||
int BN_sub(BIGNUM */*r*/, const BIGNUM */*a*/, const BIGNUM */*b*/);
|
||||
int BN_mul(BIGNUM */*r*/, const BIGNUM */*a*/, const BIGNUM */*b*/, BN_CTX */*ctx*/);
|
||||
int BN_div(BIGNUM */*q*/, BIGNUM */*r*/, const BIGNUM */*a*/, const BIGNUM */*b*/, BN_CTX */*ctx*/);
|
||||
void BN_swap(BIGNUM */*a*/, BIGNUM */*b*/);
|
||||
int BN_lshift(BIGNUM */*r*/, const BIGNUM */*a*/, int /*n*/);
|
||||
int BN_lshift1(BIGNUM */*r*/, BIGNUM */*a*/);
|
||||
int BN_rshift(BIGNUM */*r*/, const BIGNUM */*a*/, int /*n*/);
|
||||
int BN_rshift1(BIGNUM */*r*/, BIGNUM */*a*/);
|
||||
int BN_set_word(BIGNUM */*a*/, BN_ULONG /*w*/);
|
||||
void BN_set_negative(BIGNUM */*a*/, int /*n*/);
|
||||
|
||||
int BN_num_bytes(const BIGNUM */*a*/);
|
||||
int BN_num_bits(const BIGNUM */*a*/);
|
||||
|
||||
int BN_mod_exp(BIGNUM */*r*/, BIGNUM */*a*/, BIGNUM */*p*/, BIGNUM */*m*/, BN_CTX */*ctx*/);
|
||||
BIGNUM *BN_mod_inverse(BIGNUM */*ret*/, BIGNUM */*a*/, const BIGNUM */*n*/, BN_CTX */*ctx*/);
|
||||
int BN_mod_mul(BIGNUM */*ret*/, BIGNUM */*a*/, BIGNUM */*b*/, const BIGNUM */*m*/, BN_CTX */*ctx*/);
|
||||
int BN_mod_sub(BIGNUM */*r*/, BIGNUM */*a*/, BIGNUM */*b*/, const BIGNUM */*m*/, BN_CTX */*ctx*/);
|
||||
|
||||
BN_CTX *BN_CTX_new(void);
|
||||
BIGNUM *BN_CTX_get(BN_CTX */*ctx*/);
|
||||
void BN_CTX_start(BN_CTX */*ctx*/);
|
||||
void BN_CTX_end(BN_CTX */*ctx*/);
|
||||
void BN_CTX_init(BN_CTX */*c*/);
|
||||
void BN_CTX_free(BN_CTX */*c*/);
|
||||
|
||||
int BN_rand(BIGNUM */*rnd*/, int /*bits*/, int /*top*/, int /*bottom*/);
|
||||
int BN_rand_range(BIGNUM */*rnd*/, BIGNUM */*range*/);
|
||||
|
||||
int BN_is_prime(const BIGNUM */*a*/, int /*checks*/, void (*callback)(int, int, void *), BN_CTX */*ctx*/, void */*cb_arg*/);
|
||||
|
||||
const BIGNUM *BN_value_one(void);
|
||||
int BN_is_bit_set(const BIGNUM */*a*/, int /*n*/);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,304 @@
|
|||
.\" $NetBSD: libnetpgpbn.3,v 1.2 2012/11/20 05:26:25 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2010 Alistair Crooks <agc@NetBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.Dd April 13, 2012
|
||||
.Dt LIBNETPGPBN 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libnetpgpbn
|
||||
.Nd BIGNUM library of multi-precision integers
|
||||
.Sh LIBRARY
|
||||
.Lb libnetpgpbn
|
||||
.Sh SYNOPSIS
|
||||
.In netpgp/bn.h
|
||||
.Ft BIGNUM *
|
||||
.Fo BN_new
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft BIGNUM *
|
||||
.Fo BN_dup
|
||||
.Fa "const BIGNUM *orig"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_copy
|
||||
.Fa "BIGNUM *to" "const BIGNUM *from"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_swap
|
||||
.Fa "BIGNUM *a" "BIGNUM *b"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft void
|
||||
.Fo BN_init
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_free
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_clear
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_clear_free
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft void
|
||||
.Fo BN_clear_free
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_cmp
|
||||
.Fa "BIGNUM *lhs" "BIGNUM *rhs"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_negative
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_zero
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_odd
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_even
|
||||
.Fa "BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft BIGNUM *
|
||||
.Fo BN_bin2bn
|
||||
.Fa "const uint8_t *buf" "int size" "BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_bn2bin
|
||||
.Fa "BIGNUM *bn" "uint8_t *buf"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_bn2bin
|
||||
.Fa "BIGNUM *bn" "uint8_t *buf"
|
||||
.Fc
|
||||
.Ft char *
|
||||
.Fo BN_bn2hex
|
||||
.Fa "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft char *
|
||||
.Fo BN_bn2dec
|
||||
.Fa "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_hex2bn
|
||||
.Fa "BIGNUM **bn" "const char *str"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_dec2bn
|
||||
.Fa "BIGNUM **bn" "const char *str"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_print_fp
|
||||
.Fa "FILE *fp" "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_add
|
||||
.Fa "BIGNUM *sum" "const BIGNUM *a" "const BIGNUM *b"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_sub
|
||||
.Fa "BIGNUM *sum" "const BIGNUM *a" "const BIGNUM *b"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_mul
|
||||
.Fa "BIGNUM *product" "const BIGNUM *a" "const BIGNUM *b" "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_div
|
||||
.Fa "BIGNUM *quotient" "BIGNUM *remainder" "const BIGNUM *a" "const BIGNUM *b" "BN_CTX *context"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_lshift
|
||||
.Fa "BIGNUM *result" "const BIGNUM *bn" "int n"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_lshift1
|
||||
.Fa "BIGNUM *result" "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_rshift
|
||||
.Fa "BIGNUM *result" "const BIGNUM *bn" "int n"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_rshift1
|
||||
.Fa "BIGNUM *result" "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_set_word
|
||||
.Fa "BIGNUM *result" "unsigned long val"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_set_negative
|
||||
.Fa "BIGNUM *result" "int val"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_num_bytes
|
||||
.Fa "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_num_bits
|
||||
.Fa "const BIGNUM *bn"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fo BN_mod_exp
|
||||
.Fa "BIGNUM *result" "BIGNUM *a" "BIGNUM *p" "BIGNUM *m" "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft BIGNUM *
|
||||
.Fo BN_mod_inverse
|
||||
.Fa "BIGNUM *result" "BIGNUM *a" "BIGNUM *n" "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_mod_mul
|
||||
.Fa "BIGNUM *result" "BIGNUM *a" "BIGNUM *b" "BIGNUM *m" "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_mod_sub
|
||||
.Fa "BIGNUM *result" "BIGNUM *a" "BIGNUM *b" "BIGNUM *m" "BN_CTX *context"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft BN_CTX *
|
||||
.Fo BN_CTX_new
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft BIGNUM *
|
||||
.Fo BN_CTX_get
|
||||
.Fa "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_CTX_start
|
||||
.Fa "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_CTX_end
|
||||
.Fa "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_CTX_init
|
||||
.Fa "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo BN_CTX_free
|
||||
.Fa "BN_CTX *context"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_rand
|
||||
.Fa "BIGNUM *result" "int bits" "int top" "int bottom"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_rand_range
|
||||
.Fa "BIGNUM *result" "BIGNUM *range"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_prime
|
||||
.Fa "const BIGNUM *bn" "int checks" "void (*callback)(int int void)"
|
||||
.Fa "BN_CTX *context" "void *callbackarg"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft const BIGNUM *
|
||||
.Fo BN_value_one
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo BN_is_bit_set
|
||||
.Fa "const BIGNUM *bn" "int n"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
emulates the API of the openssl
|
||||
.Xr bn 3
|
||||
library.
|
||||
It is implemented using Tom St Denis
|
||||
.Dq libtommath
|
||||
library.
|
||||
.Sh EXAMPLES
|
||||
The follow code fragment will make a JSON object
|
||||
out of the string
|
||||
.Dq Hello <USERNAME>\en
|
||||
in the
|
||||
buffer called
|
||||
.Dq buf
|
||||
where
|
||||
.Dq USERNAME
|
||||
is the name of the user taken from the runtime environment.
|
||||
The encoded text will be in an allocated buffer called
|
||||
.Dq s
|
||||
.Bd -literal -offset indent
|
||||
mj_t atom;
|
||||
char buf[BUFSIZ];
|
||||
char *s;
|
||||
int cc;
|
||||
|
||||
(void) memset(\*[Am]atom, 0x0, sizeof(atom));
|
||||
cc = snprintf(buf, sizeof(buf), "Hello %s\en", getenv("USER"));
|
||||
mj_create(\*[Am]atom, "string", buf, cc);
|
||||
cc = mj_asprint(\*[Am]s, \*[Am]atom, MJ_JSON_ENCODE);
|
||||
.Ed
|
||||
.Pp
|
||||
and the following example will take the (binary) text which has been encoded into
|
||||
JSON and is in the buffer
|
||||
.Dq buf ,
|
||||
such as in the previous example, and re-create the original text:
|
||||
.Bd -literal -offset indent
|
||||
int from, to, tok, cc;
|
||||
char *s;
|
||||
mj_t atom;
|
||||
|
||||
(void) memset(\*[Am]atom, 0x0, sizeof(atom));
|
||||
from = to = tok = 0;
|
||||
mj_parse(\*[Am]atom, buf, \*[Am]from, \*[Am]to, \*[Am]tok);
|
||||
cc = mj_asprint(\*[Am]s, \*[Am]atom, MJ_HUMAN);
|
||||
printf("%.*s", cc, s);
|
||||
.Ed
|
||||
.Pp
|
||||
The
|
||||
.Dv s
|
||||
pointer points to allocated storage with the original NUL-terminated string
|
||||
in it.
|
||||
.Sh SEE ALSO
|
||||
.Xr bn 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
library first appeared in
|
||||
.Nx 7.0 .
|
||||
.Sh AUTHORS
|
||||
.An Alistair Crooks Aq agc@NetBSD.org
|
|
@ -0,0 +1,82 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
# include <sys/kmem.h>
|
||||
#else
|
||||
# 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"
|
||||
|
||||
#ifndef USE_ARG
|
||||
#define USE_ARG(x) /*LINTED*/(void)&(x)
|
||||
#endif
|
||||
|
||||
void *
|
||||
netpgp_allocate(size_t n, size_t nels)
|
||||
{
|
||||
#ifdef _KERNEL
|
||||
return kmem_zalloc(n * nels, KM_SLEEP);
|
||||
#else
|
||||
return calloc(n, nels);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
netpgp_deallocate(void *ptr, size_t size)
|
||||
{
|
||||
#ifdef _KERNEL
|
||||
kmem_free(ptr, size);
|
||||
#else
|
||||
USE_ARG(size);
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _KERNEL
|
||||
void
|
||||
logmessage(const int level, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
USE_ARG(level);
|
||||
if (fmt != NULL) {
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MISC_H_
|
||||
#define MISC_H_ 20110705
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void *netpgp_allocate(size_t /*n*/, size_t /*nels*/);
|
||||
void netpgp_deallocate(void */*ptr*/, size_t /*size*/);
|
||||
|
||||
#ifndef _KERNEL
|
||||
void logmessage(const int /*level*/, const char */*fmt*/, ...);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,60 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.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 "rand.h"
|
||||
|
||||
int
|
||||
RAND_bytes(unsigned char *buf, int num)
|
||||
{
|
||||
uint32_t r;
|
||||
size_t cc;
|
||||
int i;
|
||||
|
||||
if (buf == NULL || num < 0) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0 ; i < num ; i += sizeof(r)) {
|
||||
r = arc4random();
|
||||
cc = MIN(sizeof(r), (size_t)(num - i));
|
||||
(void) memcpy(&buf[i], &r, cc);
|
||||
}
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef RAND_H_
|
||||
#define RAND_H_ 20120327
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int RAND_bytes(unsigned char */*buf*/, int /*len*/);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,217 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.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 "stubs.h"
|
||||
|
||||
#ifndef USE_ARG
|
||||
#define USE_ARG(x) /*LINTED*/(void)&(x)
|
||||
#endif
|
||||
|
||||
void
|
||||
OpenSSL_add_all_algorithms(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OPENSSL_add_all_algorithms_noconf(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CRYPTO_cleanup_all_ex_data(void)
|
||||
{
|
||||
}
|
||||
|
||||
BIO *
|
||||
BIO_new_fd(int fd, int close_flag)
|
||||
{
|
||||
USE_ARG(fd);
|
||||
USE_ARG(close_flag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ERR_get_error(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
ERR_error_string(unsigned long e, char *buf)
|
||||
{
|
||||
static char staticbuf[120];
|
||||
|
||||
if (buf == NULL) {
|
||||
buf = staticbuf;
|
||||
}
|
||||
snprintf(buf, 120, "error:%lu:netssl:[unknown function]:[unknown error]", e);
|
||||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
ERR_remove_state(unsigned long pid)
|
||||
{
|
||||
USE_ARG(pid);
|
||||
}
|
||||
|
||||
void
|
||||
ERR_print_errors(BIO *bp)
|
||||
{
|
||||
USE_ARG(bp);
|
||||
}
|
||||
|
||||
void
|
||||
idea_set_encrypt_key(uint8_t *key, IDEA_KEY_SCHEDULE *ks)
|
||||
{
|
||||
printf("idea_set_encrypt_key stubbed\n");
|
||||
USE_ARG(key);
|
||||
USE_ARG(ks);
|
||||
}
|
||||
|
||||
void
|
||||
idea_set_decrypt_key(IDEA_KEY_SCHEDULE *encrypt_ks, IDEA_KEY_SCHEDULE *decrypt_ks)
|
||||
{
|
||||
printf("idea_set_decrypt_key stubbed\n");
|
||||
USE_ARG(encrypt_ks);
|
||||
USE_ARG(decrypt_ks);
|
||||
}
|
||||
|
||||
void
|
||||
idea_cfb64_encrypt(uint8_t *in, uint8_t *out, long length, des_key_schedule *ks, des_cblock *ivec, int *num, int enc)
|
||||
{
|
||||
printf("idea_cfb64_encrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(length);
|
||||
USE_ARG(ks);
|
||||
USE_ARG(ivec);
|
||||
USE_ARG(num);
|
||||
USE_ARG(enc);
|
||||
}
|
||||
|
||||
void
|
||||
idea_ecb_encrypt(uint8_t *in, uint8_t *out, IDEA_KEY_SCHEDULE *ks)
|
||||
{
|
||||
printf("idea_cfb64_decrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(ks);
|
||||
}
|
||||
|
||||
int
|
||||
Camellia_set_key(const unsigned char *userKey, const int bits, CAMELLIA_KEY *key)
|
||||
{
|
||||
printf("Camellia_set_key stubbed\n");
|
||||
USE_ARG(userKey);
|
||||
USE_ARG(bits);
|
||||
USE_ARG(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Camellia_encrypt(const unsigned char *in, unsigned char *out, const CAMELLIA_KEY *key)
|
||||
{
|
||||
printf("Camellia_encrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(key);
|
||||
}
|
||||
|
||||
void
|
||||
Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc)
|
||||
{
|
||||
printf("Camellia_cfb128_encrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(length);
|
||||
USE_ARG(key);
|
||||
USE_ARG(ivec);
|
||||
USE_ARG(num);
|
||||
USE_ARG(enc);
|
||||
}
|
||||
|
||||
void
|
||||
Camellia_decrypt(const unsigned char *in, unsigned char *out, const CAMELLIA_KEY *key)
|
||||
{
|
||||
printf("Camellia_decrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(key);
|
||||
}
|
||||
|
||||
int
|
||||
DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
|
||||
{
|
||||
printf("DES_set_key stubbed\n");
|
||||
USE_ARG(key);
|
||||
USE_ARG(schedule);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, DES_key_schedule *ks1,DES_key_schedule *ks2, DES_key_schedule *ks3, int enc)
|
||||
{
|
||||
printf("DES_ecb3_encrypt stubbed\n");
|
||||
USE_ARG(input);
|
||||
USE_ARG(output);
|
||||
USE_ARG(ks1);
|
||||
USE_ARG(ks2);
|
||||
USE_ARG(ks3);
|
||||
USE_ARG(enc);
|
||||
}
|
||||
|
||||
void
|
||||
DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, long length,DES_key_schedule *ks1, DES_key_schedule *ks2,DES_key_schedule *ks3, DES_cblock *ivec,int *num,int enc)
|
||||
{
|
||||
printf("DES_ede3_cfb64_encrypt stubbed\n");
|
||||
USE_ARG(in);
|
||||
USE_ARG(out);
|
||||
USE_ARG(length);
|
||||
USE_ARG(ks1);
|
||||
USE_ARG(ks2);
|
||||
USE_ARG(ks3);
|
||||
USE_ARG(ivec);
|
||||
USE_ARG(num);
|
||||
USE_ARG(enc);
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef STUBS_H_
|
||||
#define STUBS_H_ 20120327
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*********************************/
|
||||
/* stubs */
|
||||
/*********************************/
|
||||
|
||||
void OpenSSL_add_all_algorithms(void);
|
||||
void OPENSSL_add_all_algorithms_noconf(void);
|
||||
void CRYPTO_cleanup_all_ex_data(void);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BIO FILE
|
||||
|
||||
BIO *BIO_new_fd(int /*fd*/, int /*close_flag*/);
|
||||
|
||||
unsigned long ERR_get_error(void);
|
||||
char *ERR_error_string(unsigned long /*e*/, char */*buf*/);
|
||||
void ERR_remove_state(unsigned long /*pid*/);
|
||||
void ERR_print_errors(BIO */*bp*/);
|
||||
|
||||
#define IDEA_KEY_SCHEDULE void
|
||||
#define des_key_schedule void
|
||||
#define des_cblock void
|
||||
#define IDEA_DECRYPT 0
|
||||
#define IDEA_ENCRYPT 1
|
||||
#define IDEA_BLOCK 8
|
||||
#define IDEA_KEY_LENGTH 16
|
||||
|
||||
void idea_set_encrypt_key(uint8_t *key, IDEA_KEY_SCHEDULE *ks);
|
||||
void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *encrypt_ks, IDEA_KEY_SCHEDULE *decrypt_ks);
|
||||
void idea_cfb64_encrypt(uint8_t *in, uint8_t *out, long length, des_key_schedule *ks, des_cblock *ivec, int *num, int enc);
|
||||
void idea_ecb_encrypt(uint8_t *in, uint8_t *out, IDEA_KEY_SCHEDULE *ks);
|
||||
|
||||
#define CAMELLIA_KEY void
|
||||
#define CAMELLIA_DECRYPT 0
|
||||
#define CAMELLIA_ENCRYPT 1
|
||||
#define CAMELLIA_BLOCK_SIZE 16
|
||||
|
||||
int Camellia_set_key(const unsigned char *userKey, const int bits, CAMELLIA_KEY *key);
|
||||
void Camellia_encrypt(const unsigned char *in, unsigned char *out, const CAMELLIA_KEY *key);
|
||||
void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc);
|
||||
void Camellia_decrypt(const unsigned char *in, unsigned char *out, const CAMELLIA_KEY *key);
|
||||
|
||||
#define const_DES_cblock void
|
||||
#define DES_cblock void
|
||||
#define DES_key_schedule void
|
||||
#define DES_DECRYPT 0
|
||||
#define DES_ENCRYPT 1
|
||||
|
||||
int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
|
||||
void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, DES_key_schedule *ks1,DES_key_schedule *ks2, DES_key_schedule *ks3, int enc);
|
||||
void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, long length,DES_key_schedule *ks1, DES_key_schedule *ks2,DES_key_schedule *ks3, DES_cblock *ivec,int *num,int enc);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,16 @@
|
|||
LIB=netdigest
|
||||
SRCS= tiger.c digest.c
|
||||
MKMAN=no
|
||||
WARNS=4
|
||||
CPPFLAGS+=-I${EXTDIST}
|
||||
|
||||
INCS=digest.h tiger.h
|
||||
INCSDIR=/usr/include/netpgp
|
||||
EXTDIST=${.CURDIR}
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
||||
.if ${HAVE_GCC} >= 45
|
||||
#COPTS.isns_pdu.c+= -fno-strict-aliasing
|
||||
CPPFLAGS+= -fno-strict-aliasing
|
||||
.endif
|
|
@ -0,0 +1,383 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
# include <sys/md5.h>
|
||||
# include <sys/sha1.h>
|
||||
# include <sys/sha2.h>
|
||||
# include <sys/rmd160.h>
|
||||
# include <sys/kmem.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <ctype.h>
|
||||
# include <inttypes.h>
|
||||
# include <md5.h>
|
||||
# include <rmd160.h>
|
||||
# include <sha1.h>
|
||||
# include <sha2.h>
|
||||
# include <stdarg.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "digest.h"
|
||||
|
||||
static uint8_t prefix_md5[] = {
|
||||
0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86,
|
||||
0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10
|
||||
};
|
||||
|
||||
static uint8_t prefix_sha1[] = {
|
||||
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 0x03, 0x02,
|
||||
0x1A, 0x05, 0x00, 0x04, 0x14
|
||||
};
|
||||
|
||||
static uint8_t prefix_sha256[] = {
|
||||
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
|
||||
0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20
|
||||
};
|
||||
|
||||
static uint64_t prefix_tiger[] = {
|
||||
0x0123456789ABCDEFLL,
|
||||
0xFEDCBA9876543210LL,
|
||||
0xF096A5B4C3B2E187LL
|
||||
};
|
||||
|
||||
static uint8_t prefix_rmd160[] = {
|
||||
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24,
|
||||
0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14
|
||||
};
|
||||
|
||||
static uint8_t prefix_sha512[] = {
|
||||
0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
|
||||
0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40
|
||||
};
|
||||
|
||||
#define V4_SIGNATURE 4
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void
|
||||
MD5_Init(MD5_CTX *context)
|
||||
{
|
||||
if (context) {
|
||||
MD5Init(context);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MD5_Update(MD5_CTX *context, const unsigned char *data, unsigned int len)
|
||||
{
|
||||
if (context && data) {
|
||||
MD5Update(context, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MD5_Final(unsigned char digest[16], MD5_CTX *context)
|
||||
{
|
||||
if (digest && context) {
|
||||
MD5Final(digest, context);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SHA1_Init(SHA1_CTX *context)
|
||||
{
|
||||
if (context) {
|
||||
SHA1Init(context);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
|
||||
{
|
||||
if (context && data) {
|
||||
SHA1Update(context, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
|
||||
{
|
||||
if (digest && context) {
|
||||
SHA1Final(digest, context);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RMD160_Init(RMD160_CTX *context)
|
||||
{
|
||||
if (context) {
|
||||
RMD160Init(context);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RMD160_Update(RMD160_CTX *context, const unsigned char *data, unsigned int len)
|
||||
{
|
||||
if (context && data) {
|
||||
RMD160Update(context, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RMD160_Final(unsigned char digest[20], RMD160_CTX *context)
|
||||
{
|
||||
if (context && digest) {
|
||||
RMD160Final(digest, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* algorithm size (raw) */
|
||||
int
|
||||
digest_alg_size(unsigned alg)
|
||||
{
|
||||
switch(alg) {
|
||||
case MD5_HASH_ALG:
|
||||
return 16;
|
||||
case SHA1_HASH_ALG:
|
||||
return 20;
|
||||
case RIPEMD_HASH_ALG:
|
||||
return RMD160_DIGEST_LENGTH;
|
||||
case SHA256_HASH_ALG:
|
||||
return 32;
|
||||
case SHA512_HASH_ALG:
|
||||
return 64;
|
||||
case TIGER_HASH_ALG:
|
||||
case TIGER2_HASH_ALG:
|
||||
return TIGER_DIGEST_LENGTH;
|
||||
default:
|
||||
printf("hash_any: bad algorithm\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* initialise the hash structure */
|
||||
int
|
||||
digest_init(digest_t *hash, const uint32_t hashalg)
|
||||
{
|
||||
if (hash == NULL) {
|
||||
return 0;
|
||||
}
|
||||
switch(hash->alg = hashalg) {
|
||||
case MD5_HASH_ALG:
|
||||
MD5Init(&hash->u.md5ctx);
|
||||
hash->size = 16;
|
||||
hash->prefix = prefix_md5;
|
||||
hash->len = sizeof(prefix_md5);
|
||||
hash->ctx = &hash->u.md5ctx;
|
||||
return 1;
|
||||
case SHA1_HASH_ALG:
|
||||
SHA1Init(&hash->u.sha1ctx);
|
||||
hash->size = 20;
|
||||
hash->prefix = prefix_sha1;
|
||||
hash->len = sizeof(prefix_sha1);
|
||||
hash->ctx = &hash->u.sha1ctx;
|
||||
return 1;
|
||||
case RIPEMD_HASH_ALG:
|
||||
RMD160Init(&hash->u.rmd160ctx);
|
||||
hash->size = 20;
|
||||
hash->prefix = prefix_rmd160;
|
||||
hash->len = sizeof(prefix_rmd160);
|
||||
hash->ctx = &hash->u.rmd160ctx;
|
||||
return 1;
|
||||
case SHA256_HASH_ALG:
|
||||
SHA256_Init(&hash->u.sha256ctx);
|
||||
hash->size = 32;
|
||||
hash->prefix = prefix_sha256;
|
||||
hash->len = sizeof(prefix_sha256);
|
||||
hash->ctx = &hash->u.sha256ctx;
|
||||
return 1;
|
||||
case SHA512_HASH_ALG:
|
||||
SHA512_Init(&hash->u.sha512ctx);
|
||||
hash->size = 64;
|
||||
hash->prefix = prefix_sha512;
|
||||
hash->len = sizeof(prefix_sha512);
|
||||
hash->ctx = &hash->u.sha512ctx;
|
||||
return 1;
|
||||
case TIGER_HASH_ALG:
|
||||
TIGER_Init(&hash->u.tigerctx);
|
||||
hash->size = TIGER_DIGEST_LENGTH;
|
||||
hash->prefix = prefix_tiger;
|
||||
hash->len = sizeof(prefix_tiger);
|
||||
hash->ctx = &hash->u.tigerctx;
|
||||
return 1;
|
||||
case TIGER2_HASH_ALG:
|
||||
TIGER2_Init(&hash->u.tigerctx);
|
||||
hash->size = TIGER_DIGEST_LENGTH;
|
||||
hash->prefix = prefix_tiger;
|
||||
hash->len = sizeof(prefix_tiger);
|
||||
hash->ctx = &hash->u.tigerctx;
|
||||
return 1;
|
||||
default:
|
||||
printf("hash_any: bad algorithm\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct rec_t {
|
||||
const char *s;
|
||||
const unsigned alg;
|
||||
} rec_t;
|
||||
|
||||
static rec_t hashalgs[] = {
|
||||
{ "md5", MD5_HASH_ALG },
|
||||
{ "sha1", SHA1_HASH_ALG },
|
||||
{ "ripemd", RIPEMD_HASH_ALG },
|
||||
{ "sha256", SHA256_HASH_ALG },
|
||||
{ "sha512", SHA512_HASH_ALG },
|
||||
{ "tiger", TIGER_HASH_ALG },
|
||||
{ "tiger2", TIGER2_HASH_ALG },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
/* initialise by string alg name */
|
||||
unsigned
|
||||
digest_get_alg(const char *hashalg)
|
||||
{
|
||||
rec_t *r;
|
||||
|
||||
for (r = hashalgs ; hashalg && r->s ; r++) {
|
||||
if (strcasecmp(r->s, hashalg) == 0) {
|
||||
return r->alg;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
digest_update(digest_t *hash, const uint8_t *data, size_t length)
|
||||
{
|
||||
if (hash == NULL || data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
switch(hash->alg) {
|
||||
case MD5_HASH_ALG:
|
||||
MD5Update(hash->ctx, data, (unsigned)length);
|
||||
return 1;
|
||||
case SHA1_HASH_ALG:
|
||||
SHA1Update(hash->ctx, data, (unsigned)length);
|
||||
return 1;
|
||||
case RIPEMD_HASH_ALG:
|
||||
RMD160Update(hash->ctx, data, (unsigned)length);
|
||||
return 1;
|
||||
case SHA256_HASH_ALG:
|
||||
SHA256_Update(hash->ctx, data, length);
|
||||
return 1;
|
||||
case SHA512_HASH_ALG:
|
||||
SHA512_Update(hash->ctx, data, length);
|
||||
return 1;
|
||||
case TIGER_HASH_ALG:
|
||||
case TIGER2_HASH_ALG:
|
||||
TIGER_Update(hash->ctx, data, length);
|
||||
return 1;
|
||||
default:
|
||||
printf("hash_any: bad algorithm\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
digest_final(uint8_t *out, digest_t *hash)
|
||||
{
|
||||
if (hash == NULL || out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
switch(hash->alg) {
|
||||
case MD5_HASH_ALG:
|
||||
MD5Final(out, hash->ctx);
|
||||
break;
|
||||
case SHA1_HASH_ALG:
|
||||
SHA1Final(out, hash->ctx);
|
||||
break;
|
||||
case RIPEMD_HASH_ALG:
|
||||
RMD160Final(out, hash->ctx);
|
||||
break;
|
||||
case SHA256_HASH_ALG:
|
||||
SHA256_Final(out, hash->ctx);
|
||||
break;
|
||||
case SHA512_HASH_ALG:
|
||||
SHA512_Final(out, hash->ctx);
|
||||
break;
|
||||
case TIGER_HASH_ALG:
|
||||
TIGER_Final(out, hash->ctx);
|
||||
break;
|
||||
default:
|
||||
printf("hash_any: bad algorithm\n");
|
||||
return 0;
|
||||
}
|
||||
(void) memset(hash->ctx, 0x0, hash->size);
|
||||
return (unsigned)hash->size;
|
||||
}
|
||||
|
||||
int
|
||||
digest_length(digest_t *hash, unsigned hashedlen)
|
||||
{
|
||||
uint8_t trailer[6];
|
||||
|
||||
if (hash == NULL) {
|
||||
return 0;
|
||||
}
|
||||
trailer[0] = V4_SIGNATURE;
|
||||
trailer[1] = 0xFF;
|
||||
trailer[2] = (uint8_t)((hashedlen >> 24) & 0xff);
|
||||
trailer[3] = (uint8_t)((hashedlen >> 16) & 0xff);
|
||||
trailer[4] = (uint8_t)((hashedlen >> 8) & 0xff);
|
||||
trailer[5] = (uint8_t)(hashedlen & 0xff);
|
||||
digest_update(hash, trailer, sizeof(trailer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned
|
||||
digest_get_prefix(unsigned hashalg, uint8_t *prefix, size_t size)
|
||||
{
|
||||
if (prefix == NULL) {
|
||||
return 0;
|
||||
}
|
||||
switch (hashalg) {
|
||||
case MD5_HASH_ALG:
|
||||
memcpy(prefix, prefix_md5, sizeof(prefix_md5));
|
||||
return sizeof(prefix_md5);
|
||||
case SHA1_HASH_ALG:
|
||||
memcpy(prefix, prefix_sha1, sizeof(prefix_sha1));
|
||||
return sizeof(prefix_sha1);
|
||||
case SHA256_HASH_ALG:
|
||||
memcpy(prefix, prefix_sha256, sizeof(prefix_sha256));
|
||||
return sizeof(prefix_sha256);
|
||||
default:
|
||||
printf("digest_get_prefix: unknown hash algorithm: %d\n", hashalg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef DIGEST_H_
|
||||
#define DIGEST_H_ 20100108
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
# include <sys/md5.h>
|
||||
# include <sys/sha1.h>
|
||||
# include <sys/sha2.h>
|
||||
# include <sys/rmd160.h>
|
||||
#else
|
||||
# include <md5.h>
|
||||
# include <sha1.h>
|
||||
# include <sha2.h>
|
||||
# include <rmd160.h>
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include "tiger.h"
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define MD5_HASH_ALG 1
|
||||
#define SHA1_HASH_ALG 2
|
||||
#define RIPEMD_HASH_ALG 3
|
||||
#define TIGER_HASH_ALG 6 /* from rfc2440 */
|
||||
#define SHA256_HASH_ALG 8
|
||||
#define SHA384_HASH_ALG 9
|
||||
#define SHA512_HASH_ALG 10
|
||||
#define SHA224_HASH_ALG 11
|
||||
#define TIGER2_HASH_ALG 100 /* private/experimental from rfc4880 */
|
||||
|
||||
/* structure to describe digest methods */
|
||||
typedef struct digest_t {
|
||||
uint32_t alg; /* algorithm */
|
||||
size_t size; /* size */
|
||||
union {
|
||||
MD5_CTX md5ctx; /* MD5 */
|
||||
SHA1_CTX sha1ctx; /* SHA1 */
|
||||
RMD160_CTX rmd160ctx; /* RIPEMD */
|
||||
SHA256_CTX sha256ctx; /* SHA256 */
|
||||
SHA512_CTX sha512ctx; /* SHA512 */
|
||||
TIGER_CTX tigerctx; /* TIGER/TIGER2 */
|
||||
} u;
|
||||
void *prefix; /* points to specific prefix */
|
||||
uint32_t len; /* prefix length */
|
||||
void *ctx; /* pointer to context array */
|
||||
} digest_t;
|
||||
|
||||
unsigned digest_get_alg(const char */*hashalg*/);
|
||||
|
||||
int digest_init(digest_t */*digest*/, const uint32_t /*hashalg*/);
|
||||
|
||||
int digest_update(digest_t */*digest*/, const uint8_t */*data*/, size_t /*size*/);
|
||||
unsigned digest_final(uint8_t */*out*/, digest_t */*digest*/);
|
||||
int digest_alg_size(unsigned /*alg*/);
|
||||
int digest_length(digest_t */*hash*/, unsigned /*hashedlen*/);
|
||||
|
||||
void MD5_Init(MD5_CTX */*context*/);
|
||||
void MD5_Update(MD5_CTX */*context*/, const unsigned char */*data*/, unsigned int /*len*/);
|
||||
void MD5_Final(unsigned char /*digest*/[16], MD5_CTX */*context*/);
|
||||
|
||||
void SHA1_Init(SHA1_CTX */*context*/);
|
||||
void SHA1_Update(SHA1_CTX */*context*/, const unsigned char */*data*/, unsigned int /*len*/);
|
||||
void SHA1_Final(unsigned char /*digest*/[20], SHA1_CTX */*context*/);
|
||||
|
||||
void RMD160_Init(RMD160_CTX */*ctx*/);
|
||||
void RMD160_Update(RMD160_CTX */*ctx*/, const unsigned char */*data*/, uint32_t /*len*/);
|
||||
void RMD160_Final(unsigned char /*digest*/[RMD160_DIGEST_LENGTH], RMD160_CTX */*ctx*/);
|
||||
|
||||
unsigned digest_get_prefix(unsigned /*hashalg*/, uint8_t */*prefix*/, size_t /*size*/);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,219 @@
|
|||
.\" $NetBSD: tiger.3,v 1.2 2012/11/20 05:26:25 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2011 Alistair Crooks <agc@NetBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.Dd May 30, 2011
|
||||
.Dt TIGER 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm TIGER_Init ,
|
||||
.Nm TIGER_Update ,
|
||||
.Nm TIGER_Final ,
|
||||
.Nm TIGER_End ,
|
||||
.Nm TIGER_File ,
|
||||
.Nm TIGER_Data
|
||||
.Nd calculate TIGER message digests
|
||||
.Sh SYNOPSIS
|
||||
.In tiger.h
|
||||
.Ft void
|
||||
.Fo TIGER_Init
|
||||
.Fa "TIGER_CTX *context"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo TIGER_Update
|
||||
.Fa "TIGER_CTX *context" "const uint8_t *data" "u_int len"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo TIGER_Final
|
||||
.Fa "uint8_t digest[20]" "TIGER_CTX *context"
|
||||
.Fc
|
||||
.Ft "char *"
|
||||
.Fo TIGER_End
|
||||
.Fa "TIGER_CTX *context" "char *buf"
|
||||
.Fc
|
||||
.Ft "char *"
|
||||
.Fo TIGER_File
|
||||
.Fa "char *filename" "char *buf"
|
||||
.Fc
|
||||
.Ft "char *"
|
||||
.Fo TIGER_Data
|
||||
.Fa "uint8_t *data" "size_t len" "char *buf"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
The TIGER functions calculate TIGER message digest functions,
|
||||
as defined by Ross Anderson and Eli Biham.
|
||||
The algorithm takes a
|
||||
message less than 2^64 bits as input and produces a 192-bit digest
|
||||
suitable for use as a digital signature.
|
||||
.Pp
|
||||
At the time of writing,
|
||||
May 2011,
|
||||
no attacks or pre-imaging have been discovered against the
|
||||
.Nm
|
||||
message digests, whilst the same cannot be said of
|
||||
.Xr md5 3
|
||||
or
|
||||
.Xr sha1 3 .
|
||||
.Pp
|
||||
The
|
||||
.Fn TIGER_Init
|
||||
function initializes a TIGER_CTX
|
||||
.Ar context
|
||||
for use with
|
||||
.Fn TIGER_Update ,
|
||||
and
|
||||
.Fn TIGER_Final .
|
||||
The
|
||||
.Fn TIGER_Update
|
||||
function adds
|
||||
.Ar data
|
||||
of length
|
||||
.Ar len
|
||||
to the TIGER_CTX specified by
|
||||
.Ar context .
|
||||
.Fn TIGER_Final
|
||||
is called when all data has been added via
|
||||
.Fn TIGER_Update
|
||||
and stores a message digest in the
|
||||
.Ar digest
|
||||
parameter.
|
||||
When a
|
||||
.Dv NULL
|
||||
pointer is passed to
|
||||
.Fn TIGER_Final
|
||||
as first argument only the final padding will be applied and the
|
||||
current context can still be used with
|
||||
.Fn TIGER_Update .
|
||||
.Pp
|
||||
The core of the TIGER message digest is performed by
|
||||
.Fn TIGER_Update .
|
||||
Most programs should use the interface provided by
|
||||
.Fn TIGER_Init ,
|
||||
.Fn TIGER_Update ,
|
||||
and
|
||||
.Fn TIGER_Final .
|
||||
.Pp
|
||||
The
|
||||
.Fn TIGER_End
|
||||
function is a front end for
|
||||
.Fn TIGER_Final
|
||||
which converts the digest into an
|
||||
.Tn ASCII
|
||||
representation of the 160 bit digest in hexadecimal.
|
||||
.Pp
|
||||
The
|
||||
.Fn TIGER_File
|
||||
function calculates the digest for a file and returns the result via
|
||||
.Fn TIGER_End .
|
||||
If
|
||||
.Fn TIGER_File
|
||||
is unable to open the file a
|
||||
.Dv NULL
|
||||
pointer is returned.
|
||||
.Pp
|
||||
The
|
||||
.Fn TIGER_Data
|
||||
function
|
||||
calculates the digest of an arbitrary string and returns the result via
|
||||
.Fn TIGER_End .
|
||||
.Pp
|
||||
For each of the
|
||||
.Fn TIGER_End ,
|
||||
.Fn TIGER_File ,
|
||||
and
|
||||
.Fn TIGER_Data
|
||||
functions the
|
||||
.Ar buf
|
||||
parameter should either be a string of at least 41 characters in
|
||||
size or a
|
||||
.Dv NULL
|
||||
pointer.
|
||||
In the latter case, space will be dynamically allocated via
|
||||
.Xr malloc 3
|
||||
and should be freed using
|
||||
.Xr free 3
|
||||
when it is no longer needed.
|
||||
.Sh EXAMPLES
|
||||
The follow code fragment will calculate the digest for the string
|
||||
"The quick brown fox jumps over the lazy dog"
|
||||
which is
|
||||
.Dq 6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075 .
|
||||
.Bd -literal -offset indent
|
||||
TIGER_CTX tiger;
|
||||
uint8_t results[24];
|
||||
char *buf;
|
||||
int n;
|
||||
|
||||
buf = "The quick brown fox jumps over the lazy dog";
|
||||
n = strlen(buf);
|
||||
TIGER_Init(\*[Am]tiger);
|
||||
TIGER_Update(\*[Am]tiger, (uint8_t *)buf, n);
|
||||
TIGER_Final(results, \*[Am]tiger);
|
||||
|
||||
/* Print the digest as one long hex value */
|
||||
printf("0x");
|
||||
for (n = 0; n \*[Lt] 24; n++)
|
||||
printf("%02x", results[n]);
|
||||
putchar('\en');
|
||||
.Ed
|
||||
.Pp
|
||||
Alternately, the helper functions could be used in the following way:
|
||||
.Bd -literal -offset indent
|
||||
TIGER_CTX tiger;
|
||||
uint8_t output[49];
|
||||
char *buf = "The quick brown fox jumps over the lazy dog";
|
||||
|
||||
printf("0x%s", TIGER_Data(buf, strlen(buf), output));
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr md5 3 ,
|
||||
.Xr sha1 3
|
||||
.Pp
|
||||
.Rs
|
||||
.%A Ross Anderson
|
||||
.%A Eli Biham
|
||||
.%T "Tiger - A Fast New Hash Function"
|
||||
.%B Proceedings of Fast Software Encryption 3, Cambridge
|
||||
.%D 1996
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
The TIGER functions appeared in
|
||||
.Nx 6.0 .
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
This implementation of TIGER was adapted by
|
||||
.An Alistair Crooks Aq agc@NetBSD.org
|
||||
from the original reference code.
|
||||
.Pp
|
||||
The
|
||||
.Fn TIGER_End ,
|
||||
.Fn TIGER_File ,
|
||||
and
|
||||
.Fn TIGER_Data
|
||||
helper functions are derived from code written by Poul-Henning Kamp.
|
||||
.Sh BUGS
|
||||
All attempts have bene made to optimise for the underlying hardware,
|
||||
as well as to format the digest properly in an endian-neutral manner.
|
||||
The author has no VAX hardware on which to test, and so it is not known
|
||||
whether that platform is supported.
|
|
@ -0,0 +1,906 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tiger.h"
|
||||
|
||||
#ifndef IS_LITTLE_ENDIAN
|
||||
#define IS_LITTLE_ENDIAN(x) (*(char *)(void *)&x)
|
||||
#define IS_BIG_ENDIAN(x) !(*(char *)(void *)&x)
|
||||
#endif
|
||||
|
||||
#define BSWAP64(x) ((((x) & 0xffULL) << 56) | \
|
||||
(((x) & 0xff00ULL) << 40) | \
|
||||
(((x) & 0xff0000ULL) << 24) | \
|
||||
(((x) & 0xff000000ULL) << 8) | \
|
||||
(((x) & 0xff00000000ULL) >> 8) | \
|
||||
(((x) & 0xff0000000000ULL) >> 24) | \
|
||||
(((x) & 0xff000000000000ULL) >> 40) | \
|
||||
(((x) & 0xff00000000000000ULL) >> 56))
|
||||
|
||||
/* sboxes.c: Tiger S boxes */
|
||||
static uint64_t table[4*256] = {
|
||||
0x02AAB17CF7E90C5ELL /* 0 */, 0xAC424B03E243A8ECLL /* 1 */,
|
||||
0x72CD5BE30DD5FCD3LL /* 2 */, 0x6D019B93F6F97F3ALL /* 3 */,
|
||||
0xCD9978FFD21F9193LL /* 4 */, 0x7573A1C9708029E2LL /* 5 */,
|
||||
0xB164326B922A83C3LL /* 6 */, 0x46883EEE04915870LL /* 7 */,
|
||||
0xEAACE3057103ECE6LL /* 8 */, 0xC54169B808A3535CLL /* 9 */,
|
||||
0x4CE754918DDEC47CLL /* 10 */, 0x0AA2F4DFDC0DF40CLL /* 11 */,
|
||||
0x10B76F18A74DBEFALL /* 12 */, 0xC6CCB6235AD1AB6ALL /* 13 */,
|
||||
0x13726121572FE2FFLL /* 14 */, 0x1A488C6F199D921ELL /* 15 */,
|
||||
0x4BC9F9F4DA0007CALL /* 16 */, 0x26F5E6F6E85241C7LL /* 17 */,
|
||||
0x859079DBEA5947B6LL /* 18 */, 0x4F1885C5C99E8C92LL /* 19 */,
|
||||
0xD78E761EA96F864BLL /* 20 */, 0x8E36428C52B5C17DLL /* 21 */,
|
||||
0x69CF6827373063C1LL /* 22 */, 0xB607C93D9BB4C56ELL /* 23 */,
|
||||
0x7D820E760E76B5EALL /* 24 */, 0x645C9CC6F07FDC42LL /* 25 */,
|
||||
0xBF38A078243342E0LL /* 26 */, 0x5F6B343C9D2E7D04LL /* 27 */,
|
||||
0xF2C28AEB600B0EC6LL /* 28 */, 0x6C0ED85F7254BCACLL /* 29 */,
|
||||
0x71592281A4DB4FE5LL /* 30 */, 0x1967FA69CE0FED9FLL /* 31 */,
|
||||
0xFD5293F8B96545DBLL /* 32 */, 0xC879E9D7F2A7600BLL /* 33 */,
|
||||
0x860248920193194ELL /* 34 */, 0xA4F9533B2D9CC0B3LL /* 35 */,
|
||||
0x9053836C15957613LL /* 36 */, 0xDB6DCF8AFC357BF1LL /* 37 */,
|
||||
0x18BEEA7A7A370F57LL /* 38 */, 0x037117CA50B99066LL /* 39 */,
|
||||
0x6AB30A9774424A35LL /* 40 */, 0xF4E92F02E325249BLL /* 41 */,
|
||||
0x7739DB07061CCAE1LL /* 42 */, 0xD8F3B49CECA42A05LL /* 43 */,
|
||||
0xBD56BE3F51382F73LL /* 44 */, 0x45FAED5843B0BB28LL /* 45 */,
|
||||
0x1C813D5C11BF1F83LL /* 46 */, 0x8AF0E4B6D75FA169LL /* 47 */,
|
||||
0x33EE18A487AD9999LL /* 48 */, 0x3C26E8EAB1C94410LL /* 49 */,
|
||||
0xB510102BC0A822F9LL /* 50 */, 0x141EEF310CE6123BLL /* 51 */,
|
||||
0xFC65B90059DDB154LL /* 52 */, 0xE0158640C5E0E607LL /* 53 */,
|
||||
0x884E079826C3A3CFLL /* 54 */, 0x930D0D9523C535FDLL /* 55 */,
|
||||
0x35638D754E9A2B00LL /* 56 */, 0x4085FCCF40469DD5LL /* 57 */,
|
||||
0xC4B17AD28BE23A4CLL /* 58 */, 0xCAB2F0FC6A3E6A2ELL /* 59 */,
|
||||
0x2860971A6B943FCDLL /* 60 */, 0x3DDE6EE212E30446LL /* 61 */,
|
||||
0x6222F32AE01765AELL /* 62 */, 0x5D550BB5478308FELL /* 63 */,
|
||||
0xA9EFA98DA0EDA22ALL /* 64 */, 0xC351A71686C40DA7LL /* 65 */,
|
||||
0x1105586D9C867C84LL /* 66 */, 0xDCFFEE85FDA22853LL /* 67 */,
|
||||
0xCCFBD0262C5EEF76LL /* 68 */, 0xBAF294CB8990D201LL /* 69 */,
|
||||
0xE69464F52AFAD975LL /* 70 */, 0x94B013AFDF133E14LL /* 71 */,
|
||||
0x06A7D1A32823C958LL /* 72 */, 0x6F95FE5130F61119LL /* 73 */,
|
||||
0xD92AB34E462C06C0LL /* 74 */, 0xED7BDE33887C71D2LL /* 75 */,
|
||||
0x79746D6E6518393ELL /* 76 */, 0x5BA419385D713329LL /* 77 */,
|
||||
0x7C1BA6B948A97564LL /* 78 */, 0x31987C197BFDAC67LL /* 79 */,
|
||||
0xDE6C23C44B053D02LL /* 80 */, 0x581C49FED002D64DLL /* 81 */,
|
||||
0xDD474D6338261571LL /* 82 */, 0xAA4546C3E473D062LL /* 83 */,
|
||||
0x928FCE349455F860LL /* 84 */, 0x48161BBACAAB94D9LL /* 85 */,
|
||||
0x63912430770E6F68LL /* 86 */, 0x6EC8A5E602C6641CLL /* 87 */,
|
||||
0x87282515337DDD2BLL /* 88 */, 0x2CDA6B42034B701BLL /* 89 */,
|
||||
0xB03D37C181CB096DLL /* 90 */, 0xE108438266C71C6FLL /* 91 */,
|
||||
0x2B3180C7EB51B255LL /* 92 */, 0xDF92B82F96C08BBCLL /* 93 */,
|
||||
0x5C68C8C0A632F3BALL /* 94 */, 0x5504CC861C3D0556LL /* 95 */,
|
||||
0xABBFA4E55FB26B8FLL /* 96 */, 0x41848B0AB3BACEB4LL /* 97 */,
|
||||
0xB334A273AA445D32LL /* 98 */, 0xBCA696F0A85AD881LL /* 99 */,
|
||||
0x24F6EC65B528D56CLL /* 100 */, 0x0CE1512E90F4524ALL /* 101 */,
|
||||
0x4E9DD79D5506D35ALL /* 102 */, 0x258905FAC6CE9779LL /* 103 */,
|
||||
0x2019295B3E109B33LL /* 104 */, 0xF8A9478B73A054CCLL /* 105 */,
|
||||
0x2924F2F934417EB0LL /* 106 */, 0x3993357D536D1BC4LL /* 107 */,
|
||||
0x38A81AC21DB6FF8BLL /* 108 */, 0x47C4FBF17D6016BFLL /* 109 */,
|
||||
0x1E0FAADD7667E3F5LL /* 110 */, 0x7ABCFF62938BEB96LL /* 111 */,
|
||||
0xA78DAD948FC179C9LL /* 112 */, 0x8F1F98B72911E50DLL /* 113 */,
|
||||
0x61E48EAE27121A91LL /* 114 */, 0x4D62F7AD31859808LL /* 115 */,
|
||||
0xECEBA345EF5CEAEBLL /* 116 */, 0xF5CEB25EBC9684CELL /* 117 */,
|
||||
0xF633E20CB7F76221LL /* 118 */, 0xA32CDF06AB8293E4LL /* 119 */,
|
||||
0x985A202CA5EE2CA4LL /* 120 */, 0xCF0B8447CC8A8FB1LL /* 121 */,
|
||||
0x9F765244979859A3LL /* 122 */, 0xA8D516B1A1240017LL /* 123 */,
|
||||
0x0BD7BA3EBB5DC726LL /* 124 */, 0xE54BCA55B86ADB39LL /* 125 */,
|
||||
0x1D7A3AFD6C478063LL /* 126 */, 0x519EC608E7669EDDLL /* 127 */,
|
||||
0x0E5715A2D149AA23LL /* 128 */, 0x177D4571848FF194LL /* 129 */,
|
||||
0xEEB55F3241014C22LL /* 130 */, 0x0F5E5CA13A6E2EC2LL /* 131 */,
|
||||
0x8029927B75F5C361LL /* 132 */, 0xAD139FABC3D6E436LL /* 133 */,
|
||||
0x0D5DF1A94CCF402FLL /* 134 */, 0x3E8BD948BEA5DFC8LL /* 135 */,
|
||||
0xA5A0D357BD3FF77ELL /* 136 */, 0xA2D12E251F74F645LL /* 137 */,
|
||||
0x66FD9E525E81A082LL /* 138 */, 0x2E0C90CE7F687A49LL /* 139 */,
|
||||
0xC2E8BCBEBA973BC5LL /* 140 */, 0x000001BCE509745FLL /* 141 */,
|
||||
0x423777BBE6DAB3D6LL /* 142 */, 0xD1661C7EAEF06EB5LL /* 143 */,
|
||||
0xA1781F354DAACFD8LL /* 144 */, 0x2D11284A2B16AFFCLL /* 145 */,
|
||||
0xF1FC4F67FA891D1FLL /* 146 */, 0x73ECC25DCB920ADALL /* 147 */,
|
||||
0xAE610C22C2A12651LL /* 148 */, 0x96E0A810D356B78ALL /* 149 */,
|
||||
0x5A9A381F2FE7870FLL /* 150 */, 0xD5AD62EDE94E5530LL /* 151 */,
|
||||
0xD225E5E8368D1427LL /* 152 */, 0x65977B70C7AF4631LL /* 153 */,
|
||||
0x99F889B2DE39D74FLL /* 154 */, 0x233F30BF54E1D143LL /* 155 */,
|
||||
0x9A9675D3D9A63C97LL /* 156 */, 0x5470554FF334F9A8LL /* 157 */,
|
||||
0x166ACB744A4F5688LL /* 158 */, 0x70C74CAAB2E4AEADLL /* 159 */,
|
||||
0xF0D091646F294D12LL /* 160 */, 0x57B82A89684031D1LL /* 161 */,
|
||||
0xEFD95A5A61BE0B6BLL /* 162 */, 0x2FBD12E969F2F29ALL /* 163 */,
|
||||
0x9BD37013FEFF9FE8LL /* 164 */, 0x3F9B0404D6085A06LL /* 165 */,
|
||||
0x4940C1F3166CFE15LL /* 166 */, 0x09542C4DCDF3DEFBLL /* 167 */,
|
||||
0xB4C5218385CD5CE3LL /* 168 */, 0xC935B7DC4462A641LL /* 169 */,
|
||||
0x3417F8A68ED3B63FLL /* 170 */, 0xB80959295B215B40LL /* 171 */,
|
||||
0xF99CDAEF3B8C8572LL /* 172 */, 0x018C0614F8FCB95DLL /* 173 */,
|
||||
0x1B14ACCD1A3ACDF3LL /* 174 */, 0x84D471F200BB732DLL /* 175 */,
|
||||
0xC1A3110E95E8DA16LL /* 176 */, 0x430A7220BF1A82B8LL /* 177 */,
|
||||
0xB77E090D39DF210ELL /* 178 */, 0x5EF4BD9F3CD05E9DLL /* 179 */,
|
||||
0x9D4FF6DA7E57A444LL /* 180 */, 0xDA1D60E183D4A5F8LL /* 181 */,
|
||||
0xB287C38417998E47LL /* 182 */, 0xFE3EDC121BB31886LL /* 183 */,
|
||||
0xC7FE3CCC980CCBEFLL /* 184 */, 0xE46FB590189BFD03LL /* 185 */,
|
||||
0x3732FD469A4C57DCLL /* 186 */, 0x7EF700A07CF1AD65LL /* 187 */,
|
||||
0x59C64468A31D8859LL /* 188 */, 0x762FB0B4D45B61F6LL /* 189 */,
|
||||
0x155BAED099047718LL /* 190 */, 0x68755E4C3D50BAA6LL /* 191 */,
|
||||
0xE9214E7F22D8B4DFLL /* 192 */, 0x2ADDBF532EAC95F4LL /* 193 */,
|
||||
0x32AE3909B4BD0109LL /* 194 */, 0x834DF537B08E3450LL /* 195 */,
|
||||
0xFA209DA84220728DLL /* 196 */, 0x9E691D9B9EFE23F7LL /* 197 */,
|
||||
0x0446D288C4AE8D7FLL /* 198 */, 0x7B4CC524E169785BLL /* 199 */,
|
||||
0x21D87F0135CA1385LL /* 200 */, 0xCEBB400F137B8AA5LL /* 201 */,
|
||||
0x272E2B66580796BELL /* 202 */, 0x3612264125C2B0DELL /* 203 */,
|
||||
0x057702BDAD1EFBB2LL /* 204 */, 0xD4BABB8EACF84BE9LL /* 205 */,
|
||||
0x91583139641BC67BLL /* 206 */, 0x8BDC2DE08036E024LL /* 207 */,
|
||||
0x603C8156F49F68EDLL /* 208 */, 0xF7D236F7DBEF5111LL /* 209 */,
|
||||
0x9727C4598AD21E80LL /* 210 */, 0xA08A0896670A5FD7LL /* 211 */,
|
||||
0xCB4A8F4309EBA9CBLL /* 212 */, 0x81AF564B0F7036A1LL /* 213 */,
|
||||
0xC0B99AA778199ABDLL /* 214 */, 0x959F1EC83FC8E952LL /* 215 */,
|
||||
0x8C505077794A81B9LL /* 216 */, 0x3ACAAF8F056338F0LL /* 217 */,
|
||||
0x07B43F50627A6778LL /* 218 */, 0x4A44AB49F5ECCC77LL /* 219 */,
|
||||
0x3BC3D6E4B679EE98LL /* 220 */, 0x9CC0D4D1CF14108CLL /* 221 */,
|
||||
0x4406C00B206BC8A0LL /* 222 */, 0x82A18854C8D72D89LL /* 223 */,
|
||||
0x67E366B35C3C432CLL /* 224 */, 0xB923DD61102B37F2LL /* 225 */,
|
||||
0x56AB2779D884271DLL /* 226 */, 0xBE83E1B0FF1525AFLL /* 227 */,
|
||||
0xFB7C65D4217E49A9LL /* 228 */, 0x6BDBE0E76D48E7D4LL /* 229 */,
|
||||
0x08DF828745D9179ELL /* 230 */, 0x22EA6A9ADD53BD34LL /* 231 */,
|
||||
0xE36E141C5622200ALL /* 232 */, 0x7F805D1B8CB750EELL /* 233 */,
|
||||
0xAFE5C7A59F58E837LL /* 234 */, 0xE27F996A4FB1C23CLL /* 235 */,
|
||||
0xD3867DFB0775F0D0LL /* 236 */, 0xD0E673DE6E88891ALL /* 237 */,
|
||||
0x123AEB9EAFB86C25LL /* 238 */, 0x30F1D5D5C145B895LL /* 239 */,
|
||||
0xBB434A2DEE7269E7LL /* 240 */, 0x78CB67ECF931FA38LL /* 241 */,
|
||||
0xF33B0372323BBF9CLL /* 242 */, 0x52D66336FB279C74LL /* 243 */,
|
||||
0x505F33AC0AFB4EAALL /* 244 */, 0xE8A5CD99A2CCE187LL /* 245 */,
|
||||
0x534974801E2D30BBLL /* 246 */, 0x8D2D5711D5876D90LL /* 247 */,
|
||||
0x1F1A412891BC038ELL /* 248 */, 0xD6E2E71D82E56648LL /* 249 */,
|
||||
0x74036C3A497732B7LL /* 250 */, 0x89B67ED96361F5ABLL /* 251 */,
|
||||
0xFFED95D8F1EA02A2LL /* 252 */, 0xE72B3BD61464D43DLL /* 253 */,
|
||||
0xA6300F170BDC4820LL /* 254 */, 0xEBC18760ED78A77ALL /* 255 */,
|
||||
0xE6A6BE5A05A12138LL /* 256 */, 0xB5A122A5B4F87C98LL /* 257 */,
|
||||
0x563C6089140B6990LL /* 258 */, 0x4C46CB2E391F5DD5LL /* 259 */,
|
||||
0xD932ADDBC9B79434LL /* 260 */, 0x08EA70E42015AFF5LL /* 261 */,
|
||||
0xD765A6673E478CF1LL /* 262 */, 0xC4FB757EAB278D99LL /* 263 */,
|
||||
0xDF11C6862D6E0692LL /* 264 */, 0xDDEB84F10D7F3B16LL /* 265 */,
|
||||
0x6F2EF604A665EA04LL /* 266 */, 0x4A8E0F0FF0E0DFB3LL /* 267 */,
|
||||
0xA5EDEEF83DBCBA51LL /* 268 */, 0xFC4F0A2A0EA4371ELL /* 269 */,
|
||||
0xE83E1DA85CB38429LL /* 270 */, 0xDC8FF882BA1B1CE2LL /* 271 */,
|
||||
0xCD45505E8353E80DLL /* 272 */, 0x18D19A00D4DB0717LL /* 273 */,
|
||||
0x34A0CFEDA5F38101LL /* 274 */, 0x0BE77E518887CAF2LL /* 275 */,
|
||||
0x1E341438B3C45136LL /* 276 */, 0xE05797F49089CCF9LL /* 277 */,
|
||||
0xFFD23F9DF2591D14LL /* 278 */, 0x543DDA228595C5CDLL /* 279 */,
|
||||
0x661F81FD99052A33LL /* 280 */, 0x8736E641DB0F7B76LL /* 281 */,
|
||||
0x15227725418E5307LL /* 282 */, 0xE25F7F46162EB2FALL /* 283 */,
|
||||
0x48A8B2126C13D9FELL /* 284 */, 0xAFDC541792E76EEALL /* 285 */,
|
||||
0x03D912BFC6D1898FLL /* 286 */, 0x31B1AAFA1B83F51BLL /* 287 */,
|
||||
0xF1AC2796E42AB7D9LL /* 288 */, 0x40A3A7D7FCD2EBACLL /* 289 */,
|
||||
0x1056136D0AFBBCC5LL /* 290 */, 0x7889E1DD9A6D0C85LL /* 291 */,
|
||||
0xD33525782A7974AALL /* 292 */, 0xA7E25D09078AC09BLL /* 293 */,
|
||||
0xBD4138B3EAC6EDD0LL /* 294 */, 0x920ABFBE71EB9E70LL /* 295 */,
|
||||
0xA2A5D0F54FC2625CLL /* 296 */, 0xC054E36B0B1290A3LL /* 297 */,
|
||||
0xF6DD59FF62FE932BLL /* 298 */, 0x3537354511A8AC7DLL /* 299 */,
|
||||
0xCA845E9172FADCD4LL /* 300 */, 0x84F82B60329D20DCLL /* 301 */,
|
||||
0x79C62CE1CD672F18LL /* 302 */, 0x8B09A2ADD124642CLL /* 303 */,
|
||||
0xD0C1E96A19D9E726LL /* 304 */, 0x5A786A9B4BA9500CLL /* 305 */,
|
||||
0x0E020336634C43F3LL /* 306 */, 0xC17B474AEB66D822LL /* 307 */,
|
||||
0x6A731AE3EC9BAAC2LL /* 308 */, 0x8226667AE0840258LL /* 309 */,
|
||||
0x67D4567691CAECA5LL /* 310 */, 0x1D94155C4875ADB5LL /* 311 */,
|
||||
0x6D00FD985B813FDFLL /* 312 */, 0x51286EFCB774CD06LL /* 313 */,
|
||||
0x5E8834471FA744AFLL /* 314 */, 0xF72CA0AEE761AE2ELL /* 315 */,
|
||||
0xBE40E4CDAEE8E09ALL /* 316 */, 0xE9970BBB5118F665LL /* 317 */,
|
||||
0x726E4BEB33DF1964LL /* 318 */, 0x703B000729199762LL /* 319 */,
|
||||
0x4631D816F5EF30A7LL /* 320 */, 0xB880B5B51504A6BELL /* 321 */,
|
||||
0x641793C37ED84B6CLL /* 322 */, 0x7B21ED77F6E97D96LL /* 323 */,
|
||||
0x776306312EF96B73LL /* 324 */, 0xAE528948E86FF3F4LL /* 325 */,
|
||||
0x53DBD7F286A3F8F8LL /* 326 */, 0x16CADCE74CFC1063LL /* 327 */,
|
||||
0x005C19BDFA52C6DDLL /* 328 */, 0x68868F5D64D46AD3LL /* 329 */,
|
||||
0x3A9D512CCF1E186ALL /* 330 */, 0x367E62C2385660AELL /* 331 */,
|
||||
0xE359E7EA77DCB1D7LL /* 332 */, 0x526C0773749ABE6ELL /* 333 */,
|
||||
0x735AE5F9D09F734BLL /* 334 */, 0x493FC7CC8A558BA8LL /* 335 */,
|
||||
0xB0B9C1533041AB45LL /* 336 */, 0x321958BA470A59BDLL /* 337 */,
|
||||
0x852DB00B5F46C393LL /* 338 */, 0x91209B2BD336B0E5LL /* 339 */,
|
||||
0x6E604F7D659EF19FLL /* 340 */, 0xB99A8AE2782CCB24LL /* 341 */,
|
||||
0xCCF52AB6C814C4C7LL /* 342 */, 0x4727D9AFBE11727BLL /* 343 */,
|
||||
0x7E950D0C0121B34DLL /* 344 */, 0x756F435670AD471FLL /* 345 */,
|
||||
0xF5ADD442615A6849LL /* 346 */, 0x4E87E09980B9957ALL /* 347 */,
|
||||
0x2ACFA1DF50AEE355LL /* 348 */, 0xD898263AFD2FD556LL /* 349 */,
|
||||
0xC8F4924DD80C8FD6LL /* 350 */, 0xCF99CA3D754A173ALL /* 351 */,
|
||||
0xFE477BACAF91BF3CLL /* 352 */, 0xED5371F6D690C12DLL /* 353 */,
|
||||
0x831A5C285E687094LL /* 354 */, 0xC5D3C90A3708A0A4LL /* 355 */,
|
||||
0x0F7F903717D06580LL /* 356 */, 0x19F9BB13B8FDF27FLL /* 357 */,
|
||||
0xB1BD6F1B4D502843LL /* 358 */, 0x1C761BA38FFF4012LL /* 359 */,
|
||||
0x0D1530C4E2E21F3BLL /* 360 */, 0x8943CE69A7372C8ALL /* 361 */,
|
||||
0xE5184E11FEB5CE66LL /* 362 */, 0x618BDB80BD736621LL /* 363 */,
|
||||
0x7D29BAD68B574D0BLL /* 364 */, 0x81BB613E25E6FE5BLL /* 365 */,
|
||||
0x071C9C10BC07913FLL /* 366 */, 0xC7BEEB7909AC2D97LL /* 367 */,
|
||||
0xC3E58D353BC5D757LL /* 368 */, 0xEB017892F38F61E8LL /* 369 */,
|
||||
0xD4EFFB9C9B1CC21ALL /* 370 */, 0x99727D26F494F7ABLL /* 371 */,
|
||||
0xA3E063A2956B3E03LL /* 372 */, 0x9D4A8B9A4AA09C30LL /* 373 */,
|
||||
0x3F6AB7D500090FB4LL /* 374 */, 0x9CC0F2A057268AC0LL /* 375 */,
|
||||
0x3DEE9D2DEDBF42D1LL /* 376 */, 0x330F49C87960A972LL /* 377 */,
|
||||
0xC6B2720287421B41LL /* 378 */, 0x0AC59EC07C00369CLL /* 379 */,
|
||||
0xEF4EAC49CB353425LL /* 380 */, 0xF450244EEF0129D8LL /* 381 */,
|
||||
0x8ACC46E5CAF4DEB6LL /* 382 */, 0x2FFEAB63989263F7LL /* 383 */,
|
||||
0x8F7CB9FE5D7A4578LL /* 384 */, 0x5BD8F7644E634635LL /* 385 */,
|
||||
0x427A7315BF2DC900LL /* 386 */, 0x17D0C4AA2125261CLL /* 387 */,
|
||||
0x3992486C93518E50LL /* 388 */, 0xB4CBFEE0A2D7D4C3LL /* 389 */,
|
||||
0x7C75D6202C5DDD8DLL /* 390 */, 0xDBC295D8E35B6C61LL /* 391 */,
|
||||
0x60B369D302032B19LL /* 392 */, 0xCE42685FDCE44132LL /* 393 */,
|
||||
0x06F3DDB9DDF65610LL /* 394 */, 0x8EA4D21DB5E148F0LL /* 395 */,
|
||||
0x20B0FCE62FCD496FLL /* 396 */, 0x2C1B912358B0EE31LL /* 397 */,
|
||||
0xB28317B818F5A308LL /* 398 */, 0xA89C1E189CA6D2CFLL /* 399 */,
|
||||
0x0C6B18576AAADBC8LL /* 400 */, 0xB65DEAA91299FAE3LL /* 401 */,
|
||||
0xFB2B794B7F1027E7LL /* 402 */, 0x04E4317F443B5BEBLL /* 403 */,
|
||||
0x4B852D325939D0A6LL /* 404 */, 0xD5AE6BEEFB207FFCLL /* 405 */,
|
||||
0x309682B281C7D374LL /* 406 */, 0xBAE309A194C3B475LL /* 407 */,
|
||||
0x8CC3F97B13B49F05LL /* 408 */, 0x98A9422FF8293967LL /* 409 */,
|
||||
0x244B16B01076FF7CLL /* 410 */, 0xF8BF571C663D67EELL /* 411 */,
|
||||
0x1F0D6758EEE30DA1LL /* 412 */, 0xC9B611D97ADEB9B7LL /* 413 */,
|
||||
0xB7AFD5887B6C57A2LL /* 414 */, 0x6290AE846B984FE1LL /* 415 */,
|
||||
0x94DF4CDEACC1A5FDLL /* 416 */, 0x058A5BD1C5483AFFLL /* 417 */,
|
||||
0x63166CC142BA3C37LL /* 418 */, 0x8DB8526EB2F76F40LL /* 419 */,
|
||||
0xE10880036F0D6D4ELL /* 420 */, 0x9E0523C9971D311DLL /* 421 */,
|
||||
0x45EC2824CC7CD691LL /* 422 */, 0x575B8359E62382C9LL /* 423 */,
|
||||
0xFA9E400DC4889995LL /* 424 */, 0xD1823ECB45721568LL /* 425 */,
|
||||
0xDAFD983B8206082FLL /* 426 */, 0xAA7D29082386A8CBLL /* 427 */,
|
||||
0x269FCD4403B87588LL /* 428 */, 0x1B91F5F728BDD1E0LL /* 429 */,
|
||||
0xE4669F39040201F6LL /* 430 */, 0x7A1D7C218CF04ADELL /* 431 */,
|
||||
0x65623C29D79CE5CELL /* 432 */, 0x2368449096C00BB1LL /* 433 */,
|
||||
0xAB9BF1879DA503BALL /* 434 */, 0xBC23ECB1A458058ELL /* 435 */,
|
||||
0x9A58DF01BB401ECCLL /* 436 */, 0xA070E868A85F143DLL /* 437 */,
|
||||
0x4FF188307DF2239ELL /* 438 */, 0x14D565B41A641183LL /* 439 */,
|
||||
0xEE13337452701602LL /* 440 */, 0x950E3DCF3F285E09LL /* 441 */,
|
||||
0x59930254B9C80953LL /* 442 */, 0x3BF299408930DA6DLL /* 443 */,
|
||||
0xA955943F53691387LL /* 444 */, 0xA15EDECAA9CB8784LL /* 445 */,
|
||||
0x29142127352BE9A0LL /* 446 */, 0x76F0371FFF4E7AFBLL /* 447 */,
|
||||
0x0239F450274F2228LL /* 448 */, 0xBB073AF01D5E868BLL /* 449 */,
|
||||
0xBFC80571C10E96C1LL /* 450 */, 0xD267088568222E23LL /* 451 */,
|
||||
0x9671A3D48E80B5B0LL /* 452 */, 0x55B5D38AE193BB81LL /* 453 */,
|
||||
0x693AE2D0A18B04B8LL /* 454 */, 0x5C48B4ECADD5335FLL /* 455 */,
|
||||
0xFD743B194916A1CALL /* 456 */, 0x2577018134BE98C4LL /* 457 */,
|
||||
0xE77987E83C54A4ADLL /* 458 */, 0x28E11014DA33E1B9LL /* 459 */,
|
||||
0x270CC59E226AA213LL /* 460 */, 0x71495F756D1A5F60LL /* 461 */,
|
||||
0x9BE853FB60AFEF77LL /* 462 */, 0xADC786A7F7443DBFLL /* 463 */,
|
||||
0x0904456173B29A82LL /* 464 */, 0x58BC7A66C232BD5ELL /* 465 */,
|
||||
0xF306558C673AC8B2LL /* 466 */, 0x41F639C6B6C9772ALL /* 467 */,
|
||||
0x216DEFE99FDA35DALL /* 468 */, 0x11640CC71C7BE615LL /* 469 */,
|
||||
0x93C43694565C5527LL /* 470 */, 0xEA038E6246777839LL /* 471 */,
|
||||
0xF9ABF3CE5A3E2469LL /* 472 */, 0x741E768D0FD312D2LL /* 473 */,
|
||||
0x0144B883CED652C6LL /* 474 */, 0xC20B5A5BA33F8552LL /* 475 */,
|
||||
0x1AE69633C3435A9DLL /* 476 */, 0x97A28CA4088CFDECLL /* 477 */,
|
||||
0x8824A43C1E96F420LL /* 478 */, 0x37612FA66EEEA746LL /* 479 */,
|
||||
0x6B4CB165F9CF0E5ALL /* 480 */, 0x43AA1C06A0ABFB4ALL /* 481 */,
|
||||
0x7F4DC26FF162796BLL /* 482 */, 0x6CBACC8E54ED9B0FLL /* 483 */,
|
||||
0xA6B7FFEFD2BB253ELL /* 484 */, 0x2E25BC95B0A29D4FLL /* 485 */,
|
||||
0x86D6A58BDEF1388CLL /* 486 */, 0xDED74AC576B6F054LL /* 487 */,
|
||||
0x8030BDBC2B45805DLL /* 488 */, 0x3C81AF70E94D9289LL /* 489 */,
|
||||
0x3EFF6DDA9E3100DBLL /* 490 */, 0xB38DC39FDFCC8847LL /* 491 */,
|
||||
0x123885528D17B87ELL /* 492 */, 0xF2DA0ED240B1B642LL /* 493 */,
|
||||
0x44CEFADCD54BF9A9LL /* 494 */, 0x1312200E433C7EE6LL /* 495 */,
|
||||
0x9FFCC84F3A78C748LL /* 496 */, 0xF0CD1F72248576BBLL /* 497 */,
|
||||
0xEC6974053638CFE4LL /* 498 */, 0x2BA7B67C0CEC4E4CLL /* 499 */,
|
||||
0xAC2F4DF3E5CE32EDLL /* 500 */, 0xCB33D14326EA4C11LL /* 501 */,
|
||||
0xA4E9044CC77E58BCLL /* 502 */, 0x5F513293D934FCEFLL /* 503 */,
|
||||
0x5DC9645506E55444LL /* 504 */, 0x50DE418F317DE40ALL /* 505 */,
|
||||
0x388CB31A69DDE259LL /* 506 */, 0x2DB4A83455820A86LL /* 507 */,
|
||||
0x9010A91E84711AE9LL /* 508 */, 0x4DF7F0B7B1498371LL /* 509 */,
|
||||
0xD62A2EABC0977179LL /* 510 */, 0x22FAC097AA8D5C0ELL /* 511 */,
|
||||
0xF49FCC2FF1DAF39BLL /* 512 */, 0x487FD5C66FF29281LL /* 513 */,
|
||||
0xE8A30667FCDCA83FLL /* 514 */, 0x2C9B4BE3D2FCCE63LL /* 515 */,
|
||||
0xDA3FF74B93FBBBC2LL /* 516 */, 0x2FA165D2FE70BA66LL /* 517 */,
|
||||
0xA103E279970E93D4LL /* 518 */, 0xBECDEC77B0E45E71LL /* 519 */,
|
||||
0xCFB41E723985E497LL /* 520 */, 0xB70AAA025EF75017LL /* 521 */,
|
||||
0xD42309F03840B8E0LL /* 522 */, 0x8EFC1AD035898579LL /* 523 */,
|
||||
0x96C6920BE2B2ABC5LL /* 524 */, 0x66AF4163375A9172LL /* 525 */,
|
||||
0x2174ABDCCA7127FBLL /* 526 */, 0xB33CCEA64A72FF41LL /* 527 */,
|
||||
0xF04A4933083066A5LL /* 528 */, 0x8D970ACDD7289AF5LL /* 529 */,
|
||||
0x8F96E8E031C8C25ELL /* 530 */, 0xF3FEC02276875D47LL /* 531 */,
|
||||
0xEC7BF310056190DDLL /* 532 */, 0xF5ADB0AEBB0F1491LL /* 533 */,
|
||||
0x9B50F8850FD58892LL /* 534 */, 0x4975488358B74DE8LL /* 535 */,
|
||||
0xA3354FF691531C61LL /* 536 */, 0x0702BBE481D2C6EELL /* 537 */,
|
||||
0x89FB24057DEDED98LL /* 538 */, 0xAC3075138596E902LL /* 539 */,
|
||||
0x1D2D3580172772EDLL /* 540 */, 0xEB738FC28E6BC30DLL /* 541 */,
|
||||
0x5854EF8F63044326LL /* 542 */, 0x9E5C52325ADD3BBELL /* 543 */,
|
||||
0x90AA53CF325C4623LL /* 544 */, 0xC1D24D51349DD067LL /* 545 */,
|
||||
0x2051CFEEA69EA624LL /* 546 */, 0x13220F0A862E7E4FLL /* 547 */,
|
||||
0xCE39399404E04864LL /* 548 */, 0xD9C42CA47086FCB7LL /* 549 */,
|
||||
0x685AD2238A03E7CCLL /* 550 */, 0x066484B2AB2FF1DBLL /* 551 */,
|
||||
0xFE9D5D70EFBF79ECLL /* 552 */, 0x5B13B9DD9C481854LL /* 553 */,
|
||||
0x15F0D475ED1509ADLL /* 554 */, 0x0BEBCD060EC79851LL /* 555 */,
|
||||
0xD58C6791183AB7F8LL /* 556 */, 0xD1187C5052F3EEE4LL /* 557 */,
|
||||
0xC95D1192E54E82FFLL /* 558 */, 0x86EEA14CB9AC6CA2LL /* 559 */,
|
||||
0x3485BEB153677D5DLL /* 560 */, 0xDD191D781F8C492ALL /* 561 */,
|
||||
0xF60866BAA784EBF9LL /* 562 */, 0x518F643BA2D08C74LL /* 563 */,
|
||||
0x8852E956E1087C22LL /* 564 */, 0xA768CB8DC410AE8DLL /* 565 */,
|
||||
0x38047726BFEC8E1ALL /* 566 */, 0xA67738B4CD3B45AALL /* 567 */,
|
||||
0xAD16691CEC0DDE19LL /* 568 */, 0xC6D4319380462E07LL /* 569 */,
|
||||
0xC5A5876D0BA61938LL /* 570 */, 0x16B9FA1FA58FD840LL /* 571 */,
|
||||
0x188AB1173CA74F18LL /* 572 */, 0xABDA2F98C99C021FLL /* 573 */,
|
||||
0x3E0580AB134AE816LL /* 574 */, 0x5F3B05B773645ABBLL /* 575 */,
|
||||
0x2501A2BE5575F2F6LL /* 576 */, 0x1B2F74004E7E8BA9LL /* 577 */,
|
||||
0x1CD7580371E8D953LL /* 578 */, 0x7F6ED89562764E30LL /* 579 */,
|
||||
0xB15926FF596F003DLL /* 580 */, 0x9F65293DA8C5D6B9LL /* 581 */,
|
||||
0x6ECEF04DD690F84CLL /* 582 */, 0x4782275FFF33AF88LL /* 583 */,
|
||||
0xE41433083F820801LL /* 584 */, 0xFD0DFE409A1AF9B5LL /* 585 */,
|
||||
0x4325A3342CDB396BLL /* 586 */, 0x8AE77E62B301B252LL /* 587 */,
|
||||
0xC36F9E9F6655615ALL /* 588 */, 0x85455A2D92D32C09LL /* 589 */,
|
||||
0xF2C7DEA949477485LL /* 590 */, 0x63CFB4C133A39EBALL /* 591 */,
|
||||
0x83B040CC6EBC5462LL /* 592 */, 0x3B9454C8FDB326B0LL /* 593 */,
|
||||
0x56F56A9E87FFD78CLL /* 594 */, 0x2DC2940D99F42BC6LL /* 595 */,
|
||||
0x98F7DF096B096E2DLL /* 596 */, 0x19A6E01E3AD852BFLL /* 597 */,
|
||||
0x42A99CCBDBD4B40BLL /* 598 */, 0xA59998AF45E9C559LL /* 599 */,
|
||||
0x366295E807D93186LL /* 600 */, 0x6B48181BFAA1F773LL /* 601 */,
|
||||
0x1FEC57E2157A0A1DLL /* 602 */, 0x4667446AF6201AD5LL /* 603 */,
|
||||
0xE615EBCACFB0F075LL /* 604 */, 0xB8F31F4F68290778LL /* 605 */,
|
||||
0x22713ED6CE22D11ELL /* 606 */, 0x3057C1A72EC3C93BLL /* 607 */,
|
||||
0xCB46ACC37C3F1F2FLL /* 608 */, 0xDBB893FD02AAF50ELL /* 609 */,
|
||||
0x331FD92E600B9FCFLL /* 610 */, 0xA498F96148EA3AD6LL /* 611 */,
|
||||
0xA8D8426E8B6A83EALL /* 612 */, 0xA089B274B7735CDCLL /* 613 */,
|
||||
0x87F6B3731E524A11LL /* 614 */, 0x118808E5CBC96749LL /* 615 */,
|
||||
0x9906E4C7B19BD394LL /* 616 */, 0xAFED7F7E9B24A20CLL /* 617 */,
|
||||
0x6509EADEEB3644A7LL /* 618 */, 0x6C1EF1D3E8EF0EDELL /* 619 */,
|
||||
0xB9C97D43E9798FB4LL /* 620 */, 0xA2F2D784740C28A3LL /* 621 */,
|
||||
0x7B8496476197566FLL /* 622 */, 0x7A5BE3E6B65F069DLL /* 623 */,
|
||||
0xF96330ED78BE6F10LL /* 624 */, 0xEEE60DE77A076A15LL /* 625 */,
|
||||
0x2B4BEE4AA08B9BD0LL /* 626 */, 0x6A56A63EC7B8894ELL /* 627 */,
|
||||
0x02121359BA34FEF4LL /* 628 */, 0x4CBF99F8283703FCLL /* 629 */,
|
||||
0x398071350CAF30C8LL /* 630 */, 0xD0A77A89F017687ALL /* 631 */,
|
||||
0xF1C1A9EB9E423569LL /* 632 */, 0x8C7976282DEE8199LL /* 633 */,
|
||||
0x5D1737A5DD1F7ABDLL /* 634 */, 0x4F53433C09A9FA80LL /* 635 */,
|
||||
0xFA8B0C53DF7CA1D9LL /* 636 */, 0x3FD9DCBC886CCB77LL /* 637 */,
|
||||
0xC040917CA91B4720LL /* 638 */, 0x7DD00142F9D1DCDFLL /* 639 */,
|
||||
0x8476FC1D4F387B58LL /* 640 */, 0x23F8E7C5F3316503LL /* 641 */,
|
||||
0x032A2244E7E37339LL /* 642 */, 0x5C87A5D750F5A74BLL /* 643 */,
|
||||
0x082B4CC43698992ELL /* 644 */, 0xDF917BECB858F63CLL /* 645 */,
|
||||
0x3270B8FC5BF86DDALL /* 646 */, 0x10AE72BB29B5DD76LL /* 647 */,
|
||||
0x576AC94E7700362BLL /* 648 */, 0x1AD112DAC61EFB8FLL /* 649 */,
|
||||
0x691BC30EC5FAA427LL /* 650 */, 0xFF246311CC327143LL /* 651 */,
|
||||
0x3142368E30E53206LL /* 652 */, 0x71380E31E02CA396LL /* 653 */,
|
||||
0x958D5C960AAD76F1LL /* 654 */, 0xF8D6F430C16DA536LL /* 655 */,
|
||||
0xC8FFD13F1BE7E1D2LL /* 656 */, 0x7578AE66004DDBE1LL /* 657 */,
|
||||
0x05833F01067BE646LL /* 658 */, 0xBB34B5AD3BFE586DLL /* 659 */,
|
||||
0x095F34C9A12B97F0LL /* 660 */, 0x247AB64525D60CA8LL /* 661 */,
|
||||
0xDCDBC6F3017477D1LL /* 662 */, 0x4A2E14D4DECAD24DLL /* 663 */,
|
||||
0xBDB5E6D9BE0A1EEBLL /* 664 */, 0x2A7E70F7794301ABLL /* 665 */,
|
||||
0xDEF42D8A270540FDLL /* 666 */, 0x01078EC0A34C22C1LL /* 667 */,
|
||||
0xE5DE511AF4C16387LL /* 668 */, 0x7EBB3A52BD9A330ALL /* 669 */,
|
||||
0x77697857AA7D6435LL /* 670 */, 0x004E831603AE4C32LL /* 671 */,
|
||||
0xE7A21020AD78E312LL /* 672 */, 0x9D41A70C6AB420F2LL /* 673 */,
|
||||
0x28E06C18EA1141E6LL /* 674 */, 0xD2B28CBD984F6B28LL /* 675 */,
|
||||
0x26B75F6C446E9D83LL /* 676 */, 0xBA47568C4D418D7FLL /* 677 */,
|
||||
0xD80BADBFE6183D8ELL /* 678 */, 0x0E206D7F5F166044LL /* 679 */,
|
||||
0xE258A43911CBCA3ELL /* 680 */, 0x723A1746B21DC0BCLL /* 681 */,
|
||||
0xC7CAA854F5D7CDD3LL /* 682 */, 0x7CAC32883D261D9CLL /* 683 */,
|
||||
0x7690C26423BA942CLL /* 684 */, 0x17E55524478042B8LL /* 685 */,
|
||||
0xE0BE477656A2389FLL /* 686 */, 0x4D289B5E67AB2DA0LL /* 687 */,
|
||||
0x44862B9C8FBBFD31LL /* 688 */, 0xB47CC8049D141365LL /* 689 */,
|
||||
0x822C1B362B91C793LL /* 690 */, 0x4EB14655FB13DFD8LL /* 691 */,
|
||||
0x1ECBBA0714E2A97BLL /* 692 */, 0x6143459D5CDE5F14LL /* 693 */,
|
||||
0x53A8FBF1D5F0AC89LL /* 694 */, 0x97EA04D81C5E5B00LL /* 695 */,
|
||||
0x622181A8D4FDB3F3LL /* 696 */, 0xE9BCD341572A1208LL /* 697 */,
|
||||
0x1411258643CCE58ALL /* 698 */, 0x9144C5FEA4C6E0A4LL /* 699 */,
|
||||
0x0D33D06565CF620FLL /* 700 */, 0x54A48D489F219CA1LL /* 701 */,
|
||||
0xC43E5EAC6D63C821LL /* 702 */, 0xA9728B3A72770DAFLL /* 703 */,
|
||||
0xD7934E7B20DF87EFLL /* 704 */, 0xE35503B61A3E86E5LL /* 705 */,
|
||||
0xCAE321FBC819D504LL /* 706 */, 0x129A50B3AC60BFA6LL /* 707 */,
|
||||
0xCD5E68EA7E9FB6C3LL /* 708 */, 0xB01C90199483B1C7LL /* 709 */,
|
||||
0x3DE93CD5C295376CLL /* 710 */, 0xAED52EDF2AB9AD13LL /* 711 */,
|
||||
0x2E60F512C0A07884LL /* 712 */, 0xBC3D86A3E36210C9LL /* 713 */,
|
||||
0x35269D9B163951CELL /* 714 */, 0x0C7D6E2AD0CDB5FALL /* 715 */,
|
||||
0x59E86297D87F5733LL /* 716 */, 0x298EF221898DB0E7LL /* 717 */,
|
||||
0x55000029D1A5AA7ELL /* 718 */, 0x8BC08AE1B5061B45LL /* 719 */,
|
||||
0xC2C31C2B6C92703ALL /* 720 */, 0x94CC596BAF25EF42LL /* 721 */,
|
||||
0x0A1D73DB22540456LL /* 722 */, 0x04B6A0F9D9C4179ALL /* 723 */,
|
||||
0xEFFDAFA2AE3D3C60LL /* 724 */, 0xF7C8075BB49496C4LL /* 725 */,
|
||||
0x9CC5C7141D1CD4E3LL /* 726 */, 0x78BD1638218E5534LL /* 727 */,
|
||||
0xB2F11568F850246ALL /* 728 */, 0xEDFABCFA9502BC29LL /* 729 */,
|
||||
0x796CE5F2DA23051BLL /* 730 */, 0xAAE128B0DC93537CLL /* 731 */,
|
||||
0x3A493DA0EE4B29AELL /* 732 */, 0xB5DF6B2C416895D7LL /* 733 */,
|
||||
0xFCABBD25122D7F37LL /* 734 */, 0x70810B58105DC4B1LL /* 735 */,
|
||||
0xE10FDD37F7882A90LL /* 736 */, 0x524DCAB5518A3F5CLL /* 737 */,
|
||||
0x3C9E85878451255BLL /* 738 */, 0x4029828119BD34E2LL /* 739 */,
|
||||
0x74A05B6F5D3CECCBLL /* 740 */, 0xB610021542E13ECALL /* 741 */,
|
||||
0x0FF979D12F59E2ACLL /* 742 */, 0x6037DA27E4F9CC50LL /* 743 */,
|
||||
0x5E92975A0DF1847DLL /* 744 */, 0xD66DE190D3E623FELL /* 745 */,
|
||||
0x5032D6B87B568048LL /* 746 */, 0x9A36B7CE8235216ELL /* 747 */,
|
||||
0x80272A7A24F64B4ALL /* 748 */, 0x93EFED8B8C6916F7LL /* 749 */,
|
||||
0x37DDBFF44CCE1555LL /* 750 */, 0x4B95DB5D4B99BD25LL /* 751 */,
|
||||
0x92D3FDA169812FC0LL /* 752 */, 0xFB1A4A9A90660BB6LL /* 753 */,
|
||||
0x730C196946A4B9B2LL /* 754 */, 0x81E289AA7F49DA68LL /* 755 */,
|
||||
0x64669A0F83B1A05FLL /* 756 */, 0x27B3FF7D9644F48BLL /* 757 */,
|
||||
0xCC6B615C8DB675B3LL /* 758 */, 0x674F20B9BCEBBE95LL /* 759 */,
|
||||
0x6F31238275655982LL /* 760 */, 0x5AE488713E45CF05LL /* 761 */,
|
||||
0xBF619F9954C21157LL /* 762 */, 0xEABAC46040A8EAE9LL /* 763 */,
|
||||
0x454C6FE9F2C0C1CDLL /* 764 */, 0x419CF6496412691CLL /* 765 */,
|
||||
0xD3DC3BEF265B0F70LL /* 766 */, 0x6D0E60F5C3578A9ELL /* 767 */,
|
||||
0x5B0E608526323C55LL /* 768 */, 0x1A46C1A9FA1B59F5LL /* 769 */,
|
||||
0xA9E245A17C4C8FFALL /* 770 */, 0x65CA5159DB2955D7LL /* 771 */,
|
||||
0x05DB0A76CE35AFC2LL /* 772 */, 0x81EAC77EA9113D45LL /* 773 */,
|
||||
0x528EF88AB6AC0A0DLL /* 774 */, 0xA09EA253597BE3FFLL /* 775 */,
|
||||
0x430DDFB3AC48CD56LL /* 776 */, 0xC4B3A67AF45CE46FLL /* 777 */,
|
||||
0x4ECECFD8FBE2D05ELL /* 778 */, 0x3EF56F10B39935F0LL /* 779 */,
|
||||
0x0B22D6829CD619C6LL /* 780 */, 0x17FD460A74DF2069LL /* 781 */,
|
||||
0x6CF8CC8E8510ED40LL /* 782 */, 0xD6C824BF3A6ECAA7LL /* 783 */,
|
||||
0x61243D581A817049LL /* 784 */, 0x048BACB6BBC163A2LL /* 785 */,
|
||||
0xD9A38AC27D44CC32LL /* 786 */, 0x7FDDFF5BAAF410ABLL /* 787 */,
|
||||
0xAD6D495AA804824BLL /* 788 */, 0xE1A6A74F2D8C9F94LL /* 789 */,
|
||||
0xD4F7851235DEE8E3LL /* 790 */, 0xFD4B7F886540D893LL /* 791 */,
|
||||
0x247C20042AA4BFDALL /* 792 */, 0x096EA1C517D1327CLL /* 793 */,
|
||||
0xD56966B4361A6685LL /* 794 */, 0x277DA5C31221057DLL /* 795 */,
|
||||
0x94D59893A43ACFF7LL /* 796 */, 0x64F0C51CCDC02281LL /* 797 */,
|
||||
0x3D33BCC4FF6189DBLL /* 798 */, 0xE005CB184CE66AF1LL /* 799 */,
|
||||
0xFF5CCD1D1DB99BEALL /* 800 */, 0xB0B854A7FE42980FLL /* 801 */,
|
||||
0x7BD46A6A718D4B9FLL /* 802 */, 0xD10FA8CC22A5FD8CLL /* 803 */,
|
||||
0xD31484952BE4BD31LL /* 804 */, 0xC7FA975FCB243847LL /* 805 */,
|
||||
0x4886ED1E5846C407LL /* 806 */, 0x28CDDB791EB70B04LL /* 807 */,
|
||||
0xC2B00BE2F573417FLL /* 808 */, 0x5C9590452180F877LL /* 809 */,
|
||||
0x7A6BDDFFF370EB00LL /* 810 */, 0xCE509E38D6D9D6A4LL /* 811 */,
|
||||
0xEBEB0F00647FA702LL /* 812 */, 0x1DCC06CF76606F06LL /* 813 */,
|
||||
0xE4D9F28BA286FF0ALL /* 814 */, 0xD85A305DC918C262LL /* 815 */,
|
||||
0x475B1D8732225F54LL /* 816 */, 0x2D4FB51668CCB5FELL /* 817 */,
|
||||
0xA679B9D9D72BBA20LL /* 818 */, 0x53841C0D912D43A5LL /* 819 */,
|
||||
0x3B7EAA48BF12A4E8LL /* 820 */, 0x781E0E47F22F1DDFLL /* 821 */,
|
||||
0xEFF20CE60AB50973LL /* 822 */, 0x20D261D19DFFB742LL /* 823 */,
|
||||
0x16A12B03062A2E39LL /* 824 */, 0x1960EB2239650495LL /* 825 */,
|
||||
0x251C16FED50EB8B8LL /* 826 */, 0x9AC0C330F826016ELL /* 827 */,
|
||||
0xED152665953E7671LL /* 828 */, 0x02D63194A6369570LL /* 829 */,
|
||||
0x5074F08394B1C987LL /* 830 */, 0x70BA598C90B25CE1LL /* 831 */,
|
||||
0x794A15810B9742F6LL /* 832 */, 0x0D5925E9FCAF8C6CLL /* 833 */,
|
||||
0x3067716CD868744ELL /* 834 */, 0x910AB077E8D7731BLL /* 835 */,
|
||||
0x6A61BBDB5AC42F61LL /* 836 */, 0x93513EFBF0851567LL /* 837 */,
|
||||
0xF494724B9E83E9D5LL /* 838 */, 0xE887E1985C09648DLL /* 839 */,
|
||||
0x34B1D3C675370CFDLL /* 840 */, 0xDC35E433BC0D255DLL /* 841 */,
|
||||
0xD0AAB84234131BE0LL /* 842 */, 0x08042A50B48B7EAFLL /* 843 */,
|
||||
0x9997C4EE44A3AB35LL /* 844 */, 0x829A7B49201799D0LL /* 845 */,
|
||||
0x263B8307B7C54441LL /* 846 */, 0x752F95F4FD6A6CA6LL /* 847 */,
|
||||
0x927217402C08C6E5LL /* 848 */, 0x2A8AB754A795D9EELL /* 849 */,
|
||||
0xA442F7552F72943DLL /* 850 */, 0x2C31334E19781208LL /* 851 */,
|
||||
0x4FA98D7CEAEE6291LL /* 852 */, 0x55C3862F665DB309LL /* 853 */,
|
||||
0xBD0610175D53B1F3LL /* 854 */, 0x46FE6CB840413F27LL /* 855 */,
|
||||
0x3FE03792DF0CFA59LL /* 856 */, 0xCFE700372EB85E8FLL /* 857 */,
|
||||
0xA7BE29E7ADBCE118LL /* 858 */, 0xE544EE5CDE8431DDLL /* 859 */,
|
||||
0x8A781B1B41F1873ELL /* 860 */, 0xA5C94C78A0D2F0E7LL /* 861 */,
|
||||
0x39412E2877B60728LL /* 862 */, 0xA1265EF3AFC9A62CLL /* 863 */,
|
||||
0xBCC2770C6A2506C5LL /* 864 */, 0x3AB66DD5DCE1CE12LL /* 865 */,
|
||||
0xE65499D04A675B37LL /* 866 */, 0x7D8F523481BFD216LL /* 867 */,
|
||||
0x0F6F64FCEC15F389LL /* 868 */, 0x74EFBE618B5B13C8LL /* 869 */,
|
||||
0xACDC82B714273E1DLL /* 870 */, 0xDD40BFE003199D17LL /* 871 */,
|
||||
0x37E99257E7E061F8LL /* 872 */, 0xFA52626904775AAALL /* 873 */,
|
||||
0x8BBBF63A463D56F9LL /* 874 */, 0xF0013F1543A26E64LL /* 875 */,
|
||||
0xA8307E9F879EC898LL /* 876 */, 0xCC4C27A4150177CCLL /* 877 */,
|
||||
0x1B432F2CCA1D3348LL /* 878 */, 0xDE1D1F8F9F6FA013LL /* 879 */,
|
||||
0x606602A047A7DDD6LL /* 880 */, 0xD237AB64CC1CB2C7LL /* 881 */,
|
||||
0x9B938E7225FCD1D3LL /* 882 */, 0xEC4E03708E0FF476LL /* 883 */,
|
||||
0xFEB2FBDA3D03C12DLL /* 884 */, 0xAE0BCED2EE43889ALL /* 885 */,
|
||||
0x22CB8923EBFB4F43LL /* 886 */, 0x69360D013CF7396DLL /* 887 */,
|
||||
0x855E3602D2D4E022LL /* 888 */, 0x073805BAD01F784CLL /* 889 */,
|
||||
0x33E17A133852F546LL /* 890 */, 0xDF4874058AC7B638LL /* 891 */,
|
||||
0xBA92B29C678AA14ALL /* 892 */, 0x0CE89FC76CFAADCDLL /* 893 */,
|
||||
0x5F9D4E0908339E34LL /* 894 */, 0xF1AFE9291F5923B9LL /* 895 */,
|
||||
0x6E3480F60F4A265FLL /* 896 */, 0xEEBF3A2AB29B841CLL /* 897 */,
|
||||
0xE21938A88F91B4ADLL /* 898 */, 0x57DFEFF845C6D3C3LL /* 899 */,
|
||||
0x2F006B0BF62CAAF2LL /* 900 */, 0x62F479EF6F75EE78LL /* 901 */,
|
||||
0x11A55AD41C8916A9LL /* 902 */, 0xF229D29084FED453LL /* 903 */,
|
||||
0x42F1C27B16B000E6LL /* 904 */, 0x2B1F76749823C074LL /* 905 */,
|
||||
0x4B76ECA3C2745360LL /* 906 */, 0x8C98F463B91691BDLL /* 907 */,
|
||||
0x14BCC93CF1ADE66ALL /* 908 */, 0x8885213E6D458397LL /* 909 */,
|
||||
0x8E177DF0274D4711LL /* 910 */, 0xB49B73B5503F2951LL /* 911 */,
|
||||
0x10168168C3F96B6BLL /* 912 */, 0x0E3D963B63CAB0AELL /* 913 */,
|
||||
0x8DFC4B5655A1DB14LL /* 914 */, 0xF789F1356E14DE5CLL /* 915 */,
|
||||
0x683E68AF4E51DAC1LL /* 916 */, 0xC9A84F9D8D4B0FD9LL /* 917 */,
|
||||
0x3691E03F52A0F9D1LL /* 918 */, 0x5ED86E46E1878E80LL /* 919 */,
|
||||
0x3C711A0E99D07150LL /* 920 */, 0x5A0865B20C4E9310LL /* 921 */,
|
||||
0x56FBFC1FE4F0682ELL /* 922 */, 0xEA8D5DE3105EDF9BLL /* 923 */,
|
||||
0x71ABFDB12379187ALL /* 924 */, 0x2EB99DE1BEE77B9CLL /* 925 */,
|
||||
0x21ECC0EA33CF4523LL /* 926 */, 0x59A4D7521805C7A1LL /* 927 */,
|
||||
0x3896F5EB56AE7C72LL /* 928 */, 0xAA638F3DB18F75DCLL /* 929 */,
|
||||
0x9F39358DABE9808ELL /* 930 */, 0xB7DEFA91C00B72ACLL /* 931 */,
|
||||
0x6B5541FD62492D92LL /* 932 */, 0x6DC6DEE8F92E4D5BLL /* 933 */,
|
||||
0x353F57ABC4BEEA7ELL /* 934 */, 0x735769D6DA5690CELL /* 935 */,
|
||||
0x0A234AA642391484LL /* 936 */, 0xF6F9508028F80D9DLL /* 937 */,
|
||||
0xB8E319A27AB3F215LL /* 938 */, 0x31AD9C1151341A4DLL /* 939 */,
|
||||
0x773C22A57BEF5805LL /* 940 */, 0x45C7561A07968633LL /* 941 */,
|
||||
0xF913DA9E249DBE36LL /* 942 */, 0xDA652D9B78A64C68LL /* 943 */,
|
||||
0x4C27A97F3BC334EFLL /* 944 */, 0x76621220E66B17F4LL /* 945 */,
|
||||
0x967743899ACD7D0BLL /* 946 */, 0xF3EE5BCAE0ED6782LL /* 947 */,
|
||||
0x409F753600C879FCLL /* 948 */, 0x06D09A39B5926DB6LL /* 949 */,
|
||||
0x6F83AEB0317AC588LL /* 950 */, 0x01E6CA4A86381F21LL /* 951 */,
|
||||
0x66FF3462D19F3025LL /* 952 */, 0x72207C24DDFD3BFBLL /* 953 */,
|
||||
0x4AF6B6D3E2ECE2EBLL /* 954 */, 0x9C994DBEC7EA08DELL /* 955 */,
|
||||
0x49ACE597B09A8BC4LL /* 956 */, 0xB38C4766CF0797BALL /* 957 */,
|
||||
0x131B9373C57C2A75LL /* 958 */, 0xB1822CCE61931E58LL /* 959 */,
|
||||
0x9D7555B909BA1C0CLL /* 960 */, 0x127FAFDD937D11D2LL /* 961 */,
|
||||
0x29DA3BADC66D92E4LL /* 962 */, 0xA2C1D57154C2ECBCLL /* 963 */,
|
||||
0x58C5134D82F6FE24LL /* 964 */, 0x1C3AE3515B62274FLL /* 965 */,
|
||||
0xE907C82E01CB8126LL /* 966 */, 0xF8ED091913E37FCBLL /* 967 */,
|
||||
0x3249D8F9C80046C9LL /* 968 */, 0x80CF9BEDE388FB63LL /* 969 */,
|
||||
0x1881539A116CF19ELL /* 970 */, 0x5103F3F76BD52457LL /* 971 */,
|
||||
0x15B7E6F5AE47F7A8LL /* 972 */, 0xDBD7C6DED47E9CCFLL /* 973 */,
|
||||
0x44E55C410228BB1ALL /* 974 */, 0xB647D4255EDB4E99LL /* 975 */,
|
||||
0x5D11882BB8AAFC30LL /* 976 */, 0xF5098BBB29D3212ALL /* 977 */,
|
||||
0x8FB5EA14E90296B3LL /* 978 */, 0x677B942157DD025ALL /* 979 */,
|
||||
0xFB58E7C0A390ACB5LL /* 980 */, 0x89D3674C83BD4A01LL /* 981 */,
|
||||
0x9E2DA4DF4BF3B93BLL /* 982 */, 0xFCC41E328CAB4829LL /* 983 */,
|
||||
0x03F38C96BA582C52LL /* 984 */, 0xCAD1BDBD7FD85DB2LL /* 985 */,
|
||||
0xBBB442C16082AE83LL /* 986 */, 0xB95FE86BA5DA9AB0LL /* 987 */,
|
||||
0xB22E04673771A93FLL /* 988 */, 0x845358C9493152D8LL /* 989 */,
|
||||
0xBE2A488697B4541ELL /* 990 */, 0x95A2DC2DD38E6966LL /* 991 */,
|
||||
0xC02C11AC923C852BLL /* 992 */, 0x2388B1990DF2A87BLL /* 993 */,
|
||||
0x7C8008FA1B4F37BELL /* 994 */, 0x1F70D0C84D54E503LL /* 995 */,
|
||||
0x5490ADEC7ECE57D4LL /* 996 */, 0x002B3C27D9063A3ALL /* 997 */,
|
||||
0x7EAEA3848030A2BFLL /* 998 */, 0xC602326DED2003C0LL /* 999 */,
|
||||
0x83A7287D69A94086LL /* 1000 */, 0xC57A5FCB30F57A8ALL /* 1001 */,
|
||||
0xB56844E479EBE779LL /* 1002 */, 0xA373B40F05DCBCE9LL /* 1003 */,
|
||||
0xD71A786E88570EE2LL /* 1004 */, 0x879CBACDBDE8F6A0LL /* 1005 */,
|
||||
0x976AD1BCC164A32FLL /* 1006 */, 0xAB21E25E9666D78BLL /* 1007 */,
|
||||
0x901063AAE5E5C33CLL /* 1008 */, 0x9818B34448698D90LL /* 1009 */,
|
||||
0xE36487AE3E1E8ABBLL /* 1010 */, 0xAFBDF931893BDCB4LL /* 1011 */,
|
||||
0x6345A0DC5FBBD519LL /* 1012 */, 0x8628FE269B9465CALL /* 1013 */,
|
||||
0x1E5D01603F9C51ECLL /* 1014 */, 0x4DE44006A15049B7LL /* 1015 */,
|
||||
0xBF6C70E5F776CBB1LL /* 1016 */, 0x411218F2EF552BEDLL /* 1017 */,
|
||||
0xCB0C0708705A36A3LL /* 1018 */, 0xE74D14754F986044LL /* 1019 */,
|
||||
0xCD56D9430EA8280ELL /* 1020 */, 0xC12591D7535F5065LL /* 1021 */,
|
||||
0xC83223F1720AEF96LL /* 1022 */, 0xC3A0396F7363A51FLL /* 1023 */
|
||||
};
|
||||
|
||||
/* The following macro denotes that an optimization */
|
||||
/* for Alpha is required. It is used only for */
|
||||
/* optimization of time. Otherwise it does nothing. */
|
||||
#ifdef _LP64
|
||||
#define OPTIMIZE_FOR_LP64
|
||||
#endif
|
||||
|
||||
/* NOTE that this code is NOT FULLY OPTIMIZED for any */
|
||||
/* machine. Assembly code might be much faster on some */
|
||||
/* machines, especially if the code is compiled with */
|
||||
/* gcc. */
|
||||
|
||||
/* The number of passes of the hash function. */
|
||||
/* Three passes are recommended. */
|
||||
/* Use four passes when you need extra security. */
|
||||
/* Must be at least three. */
|
||||
#define PASSES 3
|
||||
|
||||
#define T1 (table)
|
||||
#define T2 (table+256)
|
||||
#define T3 (table+(256*2))
|
||||
#define T4 (table+(256*3))
|
||||
|
||||
#define SAVE_ABC do { \
|
||||
aa = a; \
|
||||
bb = b; \
|
||||
cc = c; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#ifdef OPTIMIZE_FOR_LP64
|
||||
/* This is the official definition of round */
|
||||
#define ROUND(a,b,c,x,mul) do { \
|
||||
c ^= x; \
|
||||
a -= T1[((c)>>(0*8))&0xFF] ^ T2[((c)>>(2*8))&0xFF] ^ \
|
||||
T3[((c)>>(4*8))&0xFF] ^ T4[((c)>>(6*8))&0xFF] ; \
|
||||
b += T4[((c)>>(1*8))&0xFF] ^ T3[((c)>>(3*8))&0xFF] ^ \
|
||||
T2[((c)>>(5*8))&0xFF] ^ T1[((c)>>(7*8))&0xFF] ; \
|
||||
b *= mul; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
#else
|
||||
/* This code works faster when compiled on 32-bit machines */
|
||||
/* (but works slower on Alpha) */
|
||||
#define ROUND(a,b,c,x,mul) do { \
|
||||
c ^= x; \
|
||||
a -= T1[(uint8_t)(c)] ^ \
|
||||
T2[(const uint8_t)(((uint32_t)(c))>>(2*8))] ^ \
|
||||
T3[(const uint8_t)((c)>>(4*8))] ^ \
|
||||
T4[(const uint8_t)(((uint32_t)((c)>>(4*8)))>>(2*8))] ; \
|
||||
b += T4[(uint8_t)(((uint32_t)(c))>>(1*8))] ^ \
|
||||
T3[(const uint8_t)(((uint32_t)(c))>>(3*8))] ^ \
|
||||
T2[(const uint8_t)(((uint32_t)((c)>>(4*8)))>>(1*8))] ^ \
|
||||
T1[(const uint8_t)(((uint32_t)((c)>>(4*8)))>>(3*8))]; \
|
||||
b *= mul; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
#endif
|
||||
|
||||
#define PASS(a,b,c,mul) do { \
|
||||
ROUND(a,b,c,x0,mul); \
|
||||
ROUND(b,c,a,x1,mul); \
|
||||
ROUND(c,a,b,x2,mul); \
|
||||
ROUND(a,b,c,x3,mul); \
|
||||
ROUND(b,c,a,x4,mul); \
|
||||
ROUND(c,a,b,x5,mul); \
|
||||
ROUND(a,b,c,x6,mul); \
|
||||
ROUND(b,c,a,x7,mul); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define KEY_SCHEDULE do { \
|
||||
x0 -= x7 ^ (uint64_t)0xA5A5A5A5A5A5A5A5LL; \
|
||||
x1 ^= x0; \
|
||||
x2 += x1; \
|
||||
x3 -= x2 ^ ((~x1)<<19); \
|
||||
x4 ^= x3; \
|
||||
x5 += x4; \
|
||||
x6 -= x5 ^ ((~x4)>>23); \
|
||||
x7 ^= x6; \
|
||||
x0 += x7; \
|
||||
x1 -= x0 ^ ((~x7)<<19); \
|
||||
x2 ^= x1; \
|
||||
x3 += x2; \
|
||||
x4 -= x3 ^ ((~x2)>>23); \
|
||||
x5 ^= x4; \
|
||||
x6 += x5; \
|
||||
x7 -= x6 ^ (uint64_t)0x0123456789ABCDEFLL; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define FEEDFORWARD do { \
|
||||
a ^= aa; \
|
||||
b -= bb; \
|
||||
c += cc; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#ifdef OPTIMIZE_FOR_LP64
|
||||
/* The loop is unrolled: works better on Alpha */
|
||||
#define COMPRESS do { \
|
||||
SAVE_ABC; \
|
||||
PASS(a,b,c,5); \
|
||||
KEY_SCHEDULE; \
|
||||
PASS(c,a,b,7); \
|
||||
KEY_SCHEDULE; \
|
||||
PASS(b,c,a,9); \
|
||||
for (pass_no = 3; pass_no < PASSES; pass_no++) { \
|
||||
KEY_SCHEDULE; \
|
||||
PASS(a,b,c,9); \
|
||||
tmpa = a; a = c; c = b; b = tmpa; \
|
||||
} \
|
||||
FEEDFORWARD; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
#else
|
||||
/* loop: works better on PC and Sun (smaller cache?) */
|
||||
#define COMPRESS do { \
|
||||
SAVE_ABC; \
|
||||
for (pass_no = 0; pass_no < PASSES; pass_no++) { \
|
||||
if (pass_no != 0) { \
|
||||
KEY_SCHEDULE; \
|
||||
} \
|
||||
PASS(a,b,c,(pass_no==0?5:pass_no==1?7:9)); \
|
||||
tmpa = a; a = c; c = b; b = tmpa; \
|
||||
} \
|
||||
FEEDFORWARD; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
#endif
|
||||
|
||||
#define TIGER_COMPRESS_MACRO(str, state) do { \
|
||||
uint64_t a, b, c, tmpa; \
|
||||
uint64_t aa, bb, cc; \
|
||||
uint64_t x0, x1, x2, x3, x4, x5, x6, x7; \
|
||||
int pass_no; \
|
||||
\
|
||||
a = state[0]; \
|
||||
b = state[1]; \
|
||||
c = state[2]; \
|
||||
\
|
||||
x0 = str[0]; x1 = str[1]; x2 = str[2]; x3 = str[3]; \
|
||||
x4 = str[4]; x5 = str[5]; x6 = str[6]; x7 = str[7]; \
|
||||
\
|
||||
COMPRESS; \
|
||||
\
|
||||
state[0] = a; \
|
||||
state[1] = b; \
|
||||
state[2] = c; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#ifdef OPTIMIZE_FOR_LP64
|
||||
/* The compress function is inlined: works better on Alpha. */
|
||||
/* Still leaves the function above in the code, in case some other */
|
||||
/* module calls it directly. */
|
||||
#define tiger_compress(str, state) \
|
||||
TIGER_COMPRESS_MACRO(((const uint64_t*)(const void *)str), ((uint64_t*)(void *)state))
|
||||
#else
|
||||
/* The compress function is a function. Requires smaller cache? */
|
||||
static void
|
||||
tiger_compress(const uint64_t *str, uint64_t state[3])
|
||||
{
|
||||
TIGER_COMPRESS_MACRO(((const uint64_t*)str), ((uint64_t*)state));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* weird function to format 8 raw bytes to 16 formatted hex chars */
|
||||
static void
|
||||
sprint_uint64(char *buf, uint64_t val)
|
||||
{
|
||||
static const char hexdigits[] = "0123456789abcdef";
|
||||
int indian = 1;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
if (IS_LITTLE_ENDIAN(indian)) {
|
||||
buf[2 * (7 - i)] = hexdigits[(val >> (56 - 8 * i + 4)) & 15];
|
||||
buf[(2 * (7 - i)) + 1] = hexdigits[(val >> (56 - 8 * i)) & 15];
|
||||
} else {
|
||||
buf[2 * i] = hexdigits[(val >> (56 - 8 * i + 4)) & 15];
|
||||
buf[(2 * i) + 1] = hexdigits[(val >> (56 - 8 * i)) & 15];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* common function to initialise context */
|
||||
static void
|
||||
initcontext(TIGER_CTX *ctx, uint8_t pad)
|
||||
{
|
||||
(void) memset(ctx, 0x0, sizeof(*ctx));
|
||||
ctx->ctx[0] = 0x0123456789ABCDEFLL;
|
||||
ctx->ctx[1] = 0xFEDCBA9876543210LL;
|
||||
ctx->ctx[2] = 0xF096A5B4C3B2E187LL;
|
||||
ctx->init = 1;
|
||||
ctx->pad = pad;
|
||||
}
|
||||
|
||||
/* set the version number (0 is same as 1 for Tiger) */
|
||||
static int
|
||||
setversion(TIGER_CTX *ctx, int version)
|
||||
{
|
||||
switch(version) {
|
||||
case 0:
|
||||
case 1:
|
||||
initcontext(ctx, 0x01);
|
||||
break;
|
||||
case 2:
|
||||
initcontext(ctx, 0x80);
|
||||
break;
|
||||
default:
|
||||
(void) fprintf(stderr, "unknown version %d\n", version);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
TIGER_Init(TIGER_CTX *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
initcontext(ctx, 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TIGER2_Init(TIGER_CTX *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
initcontext(ctx, 0x80);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TIGER_Update(TIGER_CTX *ctx, const void *data, size_t length)
|
||||
{
|
||||
const uint64_t *str = (const uint64_t *)data;
|
||||
uint64_t i;
|
||||
uint64_t j;
|
||||
union {
|
||||
uint8_t temp8[64];
|
||||
uint64_t temp64[8];
|
||||
} u;
|
||||
int indian = 1;
|
||||
|
||||
if (ctx == NULL || data == NULL) {
|
||||
return;
|
||||
}
|
||||
for(i = length; i >= 64; i -= 64) {
|
||||
if (IS_BIG_ENDIAN(indian)) {
|
||||
for (j = 0; j < 64; j++) {
|
||||
u.temp8[j ^ 7] = ((const uint8_t *)(const void *)str)[j];
|
||||
}
|
||||
tiger_compress(u.temp64, ctx->ctx);
|
||||
} else {
|
||||
tiger_compress(str, ctx->ctx);
|
||||
}
|
||||
str += 8;
|
||||
}
|
||||
if (IS_BIG_ENDIAN(indian)) {
|
||||
for (j = 0; j < i; j++) {
|
||||
u.temp8[j ^ 7] = ((const uint8_t*)(const void *)str)[j];
|
||||
}
|
||||
u.temp8[j ^ 7] = ctx->pad;
|
||||
for (j++; j&7; j++) {
|
||||
u.temp8[j ^ 7] = 0;
|
||||
}
|
||||
} else {
|
||||
for (j = 0; j < i; j++) {
|
||||
u.temp8[j] = ((const uint8_t*)(const void *)str)[j];
|
||||
}
|
||||
u.temp8[j++] = ctx->pad;
|
||||
for (; j&7; j++) {
|
||||
u.temp8[j] = 0;
|
||||
}
|
||||
}
|
||||
if (j > 56) {
|
||||
for (; j < 64; j++) {
|
||||
u.temp8[j] = 0;
|
||||
}
|
||||
tiger_compress(u.temp64, ctx->ctx);
|
||||
j = 0;
|
||||
}
|
||||
for (; j < 56; j++) {
|
||||
u.temp8[j] = 0;
|
||||
}
|
||||
((uint64_t *)(void *)(&(u.temp8[56])))[0] = ((uint64_t)length) << 3;
|
||||
tiger_compress(u.temp64, ctx->ctx);
|
||||
}
|
||||
|
||||
void
|
||||
TIGER_Final(uint8_t *digest, TIGER_CTX *ctx)
|
||||
{
|
||||
uint64_t le[3];
|
||||
int indian = 1;
|
||||
int i;
|
||||
|
||||
if (digest == NULL || ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
if (!ctx->init) {
|
||||
TIGER_Init(ctx);
|
||||
TIGER_Update(ctx, NULL, 0);
|
||||
}
|
||||
if (IS_LITTLE_ENDIAN(indian)) {
|
||||
for (i = 0; i < 3; ++i) {
|
||||
le[i] = (uint64_t)BSWAP64(ctx->ctx[i]);
|
||||
}
|
||||
(void) memcpy(digest, le, 3 * sizeof(le[0]));
|
||||
} else {
|
||||
(void) memcpy(digest, ctx->ctx, 3 * sizeof(ctx->ctx[0]));
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
TIGER_End(TIGER_CTX *ctx, char *buf)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (buf == NULL && (buf = calloc(1, 49)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!ctx->init) {
|
||||
TIGER_Init(ctx);
|
||||
TIGER_Update(ctx, NULL, 0);
|
||||
}
|
||||
for (i = 0; i < 3; ++i) {
|
||||
sprint_uint64(buf + i * 16, ctx->ctx[i]);
|
||||
}
|
||||
buf[16 * i] = 0x0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
TIGER_File(char *filename, char *buf, int version)
|
||||
{
|
||||
TIGER_CTX ctx;
|
||||
uint8_t buffer[BUFSIZ];
|
||||
ssize_t num;
|
||||
int fd;
|
||||
int oerrno;
|
||||
|
||||
if (filename == NULL || buf == NULL || !setversion(&ctx, version)) {
|
||||
return NULL;
|
||||
}
|
||||
if ((fd = open(filename, O_RDONLY)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0) {
|
||||
TIGER_Update(&ctx, buffer, (size_t)num);
|
||||
}
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return (num < 0) ? NULL : TIGER_End(&ctx, buf);
|
||||
}
|
||||
|
||||
char *
|
||||
TIGER_Data(const uint8_t *data, size_t len, char *buf, int version)
|
||||
{
|
||||
TIGER_CTX ctx;
|
||||
|
||||
if (data == NULL || buf == NULL || !setversion(&ctx, version)) {
|
||||
return NULL;
|
||||
}
|
||||
TIGER_Update(&ctx, data, len);
|
||||
return TIGER_End(&ctx, buf);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*-
|
||||
* Copyright (c) 2005-2011 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef TIGER_H_
|
||||
#define TIGER_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define TIGER_DIGEST_LENGTH 24
|
||||
#define TIGER_DIGEST_STRING_LENGTH ((TIGER_DIGEST_LENGTH * 2) + 1)
|
||||
|
||||
typedef struct TIGER_CTX {
|
||||
uint64_t ctx[3];
|
||||
int init;
|
||||
uint8_t pad;
|
||||
} TIGER_CTX;
|
||||
|
||||
void TIGER_Init(TIGER_CTX *);
|
||||
void TIGER2_Init(TIGER_CTX *);
|
||||
void TIGER_Update(TIGER_CTX *, const void *, size_t);
|
||||
void TIGER_Final(uint8_t *, TIGER_CTX *);
|
||||
|
||||
char *TIGER_End(TIGER_CTX *, char *);
|
||||
|
||||
char *TIGER_File(char *, char *, int);
|
||||
char *TIGER_Data(const uint8_t *, size_t, char *, int);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,10 @@
|
|||
LIB=netrsa
|
||||
SRCS=rsa.c stubs.c
|
||||
MKMAN=no
|
||||
WARNS=4
|
||||
CPPFLAGS+=-I${.CURDIR}/../bn
|
||||
|
||||
INCS=rsa.h
|
||||
INCSDIR=/usr/include/netpgp
|
||||
|
||||
.include <bsd.lib.mk>
|
|
@ -0,0 +1,114 @@
|
|||
.\" $NetBSD: libnetpgprsa.3,v 1.2 2012/11/20 05:26:25 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.Dd April 13, 2012
|
||||
.Dt LIBNETPGPRSA 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libnetpgprsa
|
||||
.Nd BIGNUM library of multi-precision integers
|
||||
.Sh LIBRARY
|
||||
.Lb libnetpgprsa
|
||||
.Sh SYNOPSIS
|
||||
.In netpgp/rsa.h
|
||||
.Ft RSA *
|
||||
.Fo RSA_new
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo RSA_size
|
||||
.Fa "const RSA *rsa"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo RSA_free
|
||||
.Fa "RSA *rsa"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo RSA_check_key
|
||||
.Fa "RSA *rsa"
|
||||
.Fc
|
||||
.Ft RSA *
|
||||
.Fo RSA_generate_key
|
||||
.Fa "int num" "unsigned long e" "void (*callback)(int, int, void *)" "void *callbackarg"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo RSA_public_encrypt
|
||||
.Fa "int siglen" "const uint8_t *signature" "uint8_t *to" "RSA *rsa" "int padding"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo RSA_private_encrypt
|
||||
.Fa "int siglen" "const uint8_t *signature" "uint8_t *to" "RSA *rsa" "int padding"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo RSA_private_decrypt
|
||||
.Fa "int siglen" "const uint8_t *signature" "uint8_t *to" "RSA *rsa" "int padding"
|
||||
.Fc
|
||||
.Pp
|
||||
.Ft DSA *
|
||||
.Fo DSA_new
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo DSA_size
|
||||
.Fa "const DSA *dsa"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo DSA_free
|
||||
.Fa "DSA *dsa"
|
||||
.Fc
|
||||
.Ft DSA_SIG *
|
||||
.Fo DSA_SIG_new
|
||||
.Fa "void"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fo DSA_SIG_free
|
||||
.Fa "DSA_SIG *sig"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo DSA_do_verify
|
||||
.Fa "const unsigned char *digest" "int digestlen" "DSA_SIG *sig" "DSA *dsa"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo DSA_do_sign
|
||||
.Fa "const unsigned char *digest" "int digestlen" "DSA *dsa"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a small library which provides RSA signing,
|
||||
encryption and decryption, and DSA signing.
|
||||
RSA and DSA verification are provided by the
|
||||
.Xr libnetpgpverify 3
|
||||
library.
|
||||
.Pp
|
||||
.Sh SEE ALSO
|
||||
.Xr libnetpgpbn 3
|
||||
.Xr libnetpgpverify 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
library first appeared in
|
||||
.Nx 7.0 .
|
||||
.Sh AUTHORS
|
||||
.An Alistair Crooks Aq agc@NetBSD.org
|
|
@ -0,0 +1,696 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
# include <sys/kmem.h>
|
||||
# define logmessage log
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
#include "digest.h"
|
||||
#include "rsa.h"
|
||||
|
||||
#ifndef USE_ARG
|
||||
#define USE_ARG(x) /*LINTED*/(void)&(x)
|
||||
#endif
|
||||
|
||||
#define RSA_MAX_MODULUS_BITS 16384
|
||||
#define RSA_SMALL_MODULUS_BITS 3072
|
||||
#define RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "large" modulus only */
|
||||
|
||||
static int
|
||||
rsa_padding_check_none(uint8_t *to, int tlen, const uint8_t *from, int flen, int num)
|
||||
{
|
||||
USE_ARG(num);
|
||||
if (flen > tlen) {
|
||||
printf("r too large\n");
|
||||
return -1;
|
||||
}
|
||||
(void) memset(to, 0x0, tlen - flen);
|
||||
(void) memcpy(to + tlen - flen, from, flen);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static int
|
||||
lowlevel_rsa_private_encrypt(int plainc, const unsigned char *plain, unsigned char *encbuf, RSA *rsa)
|
||||
{
|
||||
BIGNUM *decbn;
|
||||
BIGNUM *signedbn;
|
||||
uint8_t *decbuf;
|
||||
int nbytes;
|
||||
int signc;
|
||||
int signedbytes;
|
||||
int r;
|
||||
|
||||
decbuf = NULL;
|
||||
r = -1;
|
||||
decbn = BN_new();
|
||||
signedbn = BN_new();
|
||||
nbytes = BN_num_bytes(rsa->n);
|
||||
decbuf = netpgp_allocate(1, nbytes);
|
||||
/* add no padding */
|
||||
memcpy(decbuf, plain, plainc);
|
||||
BN_bin2bn(decbuf, nbytes, decbn);
|
||||
if (BN_cmp(decbn, rsa->n) >= 0) {
|
||||
printf("decbn too big\n");
|
||||
goto err;
|
||||
}
|
||||
if (!BN_mod_exp(signedbn, decbn, rsa->d, rsa->n, NULL)) {
|
||||
printf("bad mod_exp\n");
|
||||
goto err;
|
||||
}
|
||||
signedbytes = BN_num_bytes(signedbn);
|
||||
signc = BN_bn2bin(signedbn, &encbuf[nbytes - signedbytes]);
|
||||
memset(encbuf, 0x0, nbytes - signc);
|
||||
r = nbytes;
|
||||
err:
|
||||
netpgp_deallocate(decbuf, nbytes);
|
||||
BN_clear_free(decbn);
|
||||
BN_clear_free(signedbn);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
lowlevel_rsa_public_encrypt(int plainc, const unsigned char *plain, unsigned char *encbuf, RSA *rsa)
|
||||
{
|
||||
BIGNUM *decbn;
|
||||
BIGNUM *encbn;
|
||||
uint8_t *decbuf;
|
||||
int nbytes;
|
||||
int encc;
|
||||
int r;
|
||||
int i;
|
||||
|
||||
r = -1;
|
||||
decbn = BN_new();
|
||||
encbn = BN_new();
|
||||
nbytes = BN_num_bytes(rsa->n);
|
||||
decbuf = netpgp_allocate(1, nbytes);
|
||||
(void) memcpy(decbuf, plain, plainc);
|
||||
if (BN_bin2bn(decbuf, nbytes, decbn) == NULL) {
|
||||
printf("bin2bn failed\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_cmp(decbn, rsa->n) >= 0) {
|
||||
printf("BN_cmp failed\n");
|
||||
goto err;
|
||||
}
|
||||
if (!BN_mod_exp(encbn, decbn, rsa->e, rsa->n, NULL)) {
|
||||
printf("BN_mod_exp failed\n");
|
||||
goto err;
|
||||
}
|
||||
encc = BN_num_bytes(encbn);
|
||||
i = BN_bn2bin(encbn, &encbuf[nbytes - encc]);
|
||||
(void) memset(encbuf, 0x0, nbytes - i);
|
||||
r = nbytes;
|
||||
err:
|
||||
if (decbuf) {
|
||||
memset(decbuf, 0x0, nbytes);
|
||||
netpgp_deallocate(decbuf, nbytes);
|
||||
}
|
||||
BN_clear_free(decbn);
|
||||
BN_clear_free(encbn);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
lowlevel_rsa_private_decrypt(int enclen, const unsigned char *encbuf, unsigned char *to, RSA *rsa)
|
||||
{
|
||||
BIGNUM *encbn;
|
||||
BIGNUM *decbn;
|
||||
uint8_t *buf;
|
||||
int nbytes;
|
||||
int j;
|
||||
int r;
|
||||
|
||||
r = -1;
|
||||
decbn = encbn = NULL;
|
||||
buf = NULL;
|
||||
if (BN_num_bits(rsa->n) > RSA_MAX_MODULUS_BITS) {
|
||||
return -1;
|
||||
}
|
||||
if (BN_cmp(rsa->n, rsa->e) <= 0) {
|
||||
return -1;
|
||||
}
|
||||
encbn = BN_new();
|
||||
decbn = BN_new();
|
||||
nbytes = BN_num_bytes(rsa->n);
|
||||
buf = netpgp_allocate(1, nbytes);
|
||||
if (enclen > nbytes) {
|
||||
printf("bad enclen\n");
|
||||
goto err;
|
||||
}
|
||||
BN_bin2bn(encbuf, enclen, encbn);
|
||||
if (BN_cmp(encbn, rsa->n) >= 0) {
|
||||
printf("bad encbn\n");
|
||||
goto err;
|
||||
}
|
||||
BN_mod_exp(decbn, encbn, rsa->d, rsa->n, NULL);
|
||||
j = BN_bn2bin(decbn, buf);
|
||||
r = rsa_padding_check_none(to, nbytes, buf, j, nbytes);
|
||||
err:
|
||||
BN_clear_free(encbn);
|
||||
BN_clear_free(decbn);
|
||||
netpgp_deallocate(buf, nbytes);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
lowlevel_rsa_public_decrypt(const uint8_t *encbuf, int enclen, uint8_t *dec, const rsa_pubkey_t *rsa)
|
||||
{
|
||||
uint8_t *decbuf;
|
||||
BIGNUM *decbn;
|
||||
BIGNUM *encbn;
|
||||
int decbytes;
|
||||
int nbytes;
|
||||
int r;
|
||||
|
||||
nbytes = 0;
|
||||
r = -1;
|
||||
decbuf = NULL;
|
||||
decbn = encbn = NULL;
|
||||
if (BN_num_bits(rsa->n) > RSA_MAX_MODULUS_BITS) {
|
||||
printf("rsa r modulus too large\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_cmp(rsa->n, rsa->e) <= 0) {
|
||||
printf("rsa r bad n value\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_num_bits(rsa->n) > RSA_SMALL_MODULUS_BITS &&
|
||||
BN_num_bits(rsa->e) > RSA_MAX_PUBEXP_BITS) {
|
||||
printf("rsa r bad exponent limit\n");
|
||||
goto err;
|
||||
}
|
||||
if ((encbn = BN_new()) == NULL ||
|
||||
(decbn = BN_new()) == NULL ||
|
||||
(decbuf = netpgp_allocate(1, nbytes = BN_num_bytes(rsa->n))) == NULL) {
|
||||
printf("allocation failure\n");
|
||||
goto err;
|
||||
}
|
||||
if (enclen > nbytes) {
|
||||
printf("rsa r > mod len\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_bin2bn(encbuf, enclen, encbn) == NULL) {
|
||||
printf("null encrypted BN\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_cmp(encbn, rsa->n) >= 0) {
|
||||
printf("rsa r data too large for modulus\n");
|
||||
goto err;
|
||||
}
|
||||
if (BN_mod_exp(decbn, encbn, rsa->e, rsa->n, NULL) < 0) {
|
||||
printf("BN_mod_exp < 0\n");
|
||||
goto err;
|
||||
}
|
||||
decbytes = BN_num_bytes(decbn);
|
||||
(void) BN_bn2bin(decbn, decbuf);
|
||||
if ((r = rsa_padding_check_none(dec, nbytes, decbuf, decbytes, 0)) < 0) {
|
||||
printf("rsa r padding check failed\n");
|
||||
}
|
||||
err:
|
||||
BN_free(encbn);
|
||||
BN_free(decbn);
|
||||
if (decbuf != NULL) {
|
||||
(void) memset(decbuf, 0x0, nbytes);
|
||||
netpgp_deallocate(decbuf, nbytes);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
@file rsa_make_key.c
|
||||
RSA key generation, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Create an RSA key
|
||||
@param prng An active PRNG state
|
||||
@param wprng The index of the PRNG desired
|
||||
@param size The size of the modulus (key size) desired (octets)
|
||||
@param e The "e" value (public key). e==65537 is a good choice
|
||||
@param key [out] Destination of a newly created private key pair
|
||||
@return CRYPT_OK if successful, upon error all allocated ram is freed
|
||||
*/
|
||||
static int
|
||||
rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key)
|
||||
{
|
||||
void *p, *q, *tmp1, *tmp2, *tmp3;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(ltc_mp.name != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
|
||||
if ((size < (MIN_RSA_SIZE/8)) || (size > (MAX_RSA_SIZE/8))) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
|
||||
if ((e < 3) || ((e & 1) == 0)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = mp_init_multi(&p, &q, &tmp1, &tmp2, &tmp3, NULL)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* make primes p and q (optimization provided by Wayne Scott) */
|
||||
/* tmp3 = e */
|
||||
if ((err = mp_set_int(tmp3, e)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
|
||||
/* make prime "p" */
|
||||
do {
|
||||
if ((err = rand_prime( p, size/2, prng, wprng)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp1 = p-1 */
|
||||
if ((err = mp_sub_d( p, 1, tmp1)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp2 = gcd(p-1, e) */
|
||||
if ((err = mp_gcd( tmp1, tmp3, tmp2)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
} while (mp_cmp_d( tmp2, 1) != 0);
|
||||
/* while e divides p-1 */
|
||||
|
||||
/* make prime "q" */
|
||||
do {
|
||||
if ((err = rand_prime( q, size/2, prng, wprng)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp1 = q-1 */
|
||||
if ((err = mp_sub_d( q, 1, tmp1)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp2 = gcd(q-1, e) */
|
||||
if ((err = mp_gcd( tmp1, tmp3, tmp2)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
} while (mp_cmp_d( tmp2, 1) != 0);
|
||||
/* while e divides q-1 */
|
||||
|
||||
/* tmp1 = lcm(p-1, q-1) */
|
||||
/* tmp2 = p-1 */
|
||||
if ((err = mp_sub_d( p, 1, tmp2)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp1 = q-1 (previous do/while loop) */
|
||||
/* tmp1 = lcm(p-1, q-1) */
|
||||
if ((err = mp_lcm( tmp1, tmp2, tmp1)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
|
||||
/* make key */
|
||||
if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP, &key->p, &key->q, NULL)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
|
||||
/* key->e = e */
|
||||
if ((err = mp_set_int( key->e, e)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* key->d = 1/e mod lcm(p-1,q-1) */
|
||||
if ((err = mp_invmod( key->e, tmp1, key->d)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* key->N = pq */
|
||||
if ((err = mp_mul( p, q, key->N)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
|
||||
/* optimize for CRT now */
|
||||
/* find d mod q-1 and d mod p-1 */
|
||||
/* tmp1 = q-1 */
|
||||
if ((err = mp_sub_d( p, 1, tmp1)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* tmp2 = p-1 */
|
||||
if ((err = mp_sub_d( q, 1, tmp2)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* dP = d mod p-1 */
|
||||
if ((err = mp_mod( key->d, tmp1, key->dP)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* dQ = d mod q-1 */
|
||||
if ((err = mp_mod( key->d, tmp2, key->dQ)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
/* qP = 1/q mod p */
|
||||
if ((err = mp_invmod( q, p, key->qP)) != CRYPT_OK) {
|
||||
got oerrkey;
|
||||
}
|
||||
|
||||
if ((err = mp_copy( p, key->p)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
if ((err = mp_copy( q, key->q)) != CRYPT_OK) {
|
||||
goto errkey;
|
||||
}
|
||||
|
||||
/* set key type (in this case it's CRT optimized) */
|
||||
key->type = PK_PRIVATE;
|
||||
|
||||
/* return ok and free temps */
|
||||
err = CRYPT_OK;
|
||||
goto cleanup;
|
||||
errkey:
|
||||
mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
|
||||
cleanup:
|
||||
mp_clear_multi(tmp3, tmp2, tmp1, p, q, NULL);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define HASHBUF_LEN 512
|
||||
|
||||
#define DSA_MAX_MODULUS_BITS 10000
|
||||
|
||||
static int
|
||||
dsa_do_verify(const unsigned char *calculated, int dgst_len, const dsasig_t *sig, mpi_dsa_t *dsa)
|
||||
{
|
||||
BIGNUM *M;
|
||||
BIGNUM *W;
|
||||
BIGNUM *t1;
|
||||
int ret = -1;
|
||||
int qbits;
|
||||
|
||||
if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) {
|
||||
return 0;
|
||||
}
|
||||
M = W = t1 = NULL;
|
||||
qbits = BN_num_bits(dsa->q);
|
||||
switch(qbits) {
|
||||
case 160:
|
||||
case 224:
|
||||
case 256:
|
||||
/* openssl sources say these are the valid values */
|
||||
/* according to FIPS 186-3 */
|
||||
break;
|
||||
default:
|
||||
printf("dsa: bad # of Q bits\n");
|
||||
return 0;
|
||||
}
|
||||
if (BN_num_bits(dsa->p) > DSA_MAX_MODULUS_BITS) {
|
||||
printf("dsa: p too large\n");
|
||||
return 0;
|
||||
}
|
||||
/* no love for SHA512? */
|
||||
if (dgst_len > SHA256_DIGEST_LENGTH) {
|
||||
printf("dsa: digest too long\n");
|
||||
return 0;
|
||||
}
|
||||
ret = 0;
|
||||
if ((M = BN_new()) == NULL ||
|
||||
(W = BN_new()) == NULL ||
|
||||
(t1 = BN_new()) == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_zero(sig->r) ||
|
||||
BN_is_negative(sig->r) ||
|
||||
BN_cmp(sig->r, dsa->q) >= 0) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_zero(sig->s) ||
|
||||
BN_is_negative(sig->s) ||
|
||||
BN_cmp(sig->s, dsa->q) >= 0) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_mod_inverse(W, sig->s, dsa->q, NULL) != MP_OKAY) {
|
||||
goto err;
|
||||
}
|
||||
if (dgst_len > qbits / 8) {
|
||||
dgst_len = qbits / 8;
|
||||
}
|
||||
if (BN_bin2bn(calculated, dgst_len, M) == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_mod_mul(M, M, W, dsa->q, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_mod_mul(W, sig->r, W, dsa->q, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_mod_exp(dsa->p, t1, dsa->g, M, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_div(NULL, M, t1, dsa->q, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
ret = (BN_cmp(M, sig->r) == 0);
|
||||
err:
|
||||
if (M) {
|
||||
BN_free(M);
|
||||
}
|
||||
if (W) {
|
||||
BN_free(W);
|
||||
}
|
||||
if (t1) {
|
||||
BN_free(t1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
int
|
||||
RSA_size(const RSA *rsa)
|
||||
{
|
||||
return (rsa == NULL) ? 0 : BN_num_bits(rsa->n);
|
||||
}
|
||||
|
||||
int
|
||||
DSA_size(const DSA *dsa)
|
||||
{
|
||||
return (dsa == NULL) ? 0 : BN_num_bits(dsa->p);
|
||||
}
|
||||
|
||||
unsigned
|
||||
dsa_verify(const signature_t *signature, const dsa_pubkey_t *pubdsa, const uint8_t *calculated, size_t hash_length)
|
||||
{
|
||||
mpi_dsa_t odsa;
|
||||
dsasig_t osig;
|
||||
unsigned qlen;
|
||||
int ret;
|
||||
|
||||
if (signature == NULL || pubdsa == NULL || calculated == NULL) {
|
||||
return -1;
|
||||
}
|
||||
(void) memset(&osig, 0x0, sizeof(osig));
|
||||
(void) memset(&odsa, 0x0, sizeof(odsa));
|
||||
BN_copy(osig.r, signature->dsa.r);
|
||||
BN_copy(osig.s, signature->dsa.s);
|
||||
odsa.p = pubdsa->p;
|
||||
odsa.q = pubdsa->q;
|
||||
odsa.g = pubdsa->g;
|
||||
odsa.pub_key = pubdsa->y;
|
||||
if ((qlen = BN_num_bytes(odsa.q)) < hash_length) {
|
||||
hash_length = qlen;
|
||||
}
|
||||
ret = dsa_do_verify(calculated, (int)hash_length, &signature->dsa, &odsa);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
BN_free(odsa.p);
|
||||
BN_free(odsa.q);
|
||||
BN_free(odsa.g);
|
||||
BN_free(odsa.pub_key);
|
||||
odsa.p = odsa.q = odsa.g = odsa.pub_key = NULL;
|
||||
BN_free(osig.r);
|
||||
BN_free(osig.s);
|
||||
osig.r = osig.s = NULL;
|
||||
return (unsigned)ret;
|
||||
}
|
||||
|
||||
RSA *
|
||||
RSA_new(void)
|
||||
{
|
||||
return netpgp_allocate(1, sizeof(RSA));
|
||||
}
|
||||
|
||||
void
|
||||
RSA_free(RSA *rsa)
|
||||
{
|
||||
if (rsa) {
|
||||
netpgp_deallocate(rsa, sizeof(*rsa));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
RSA_check_key(RSA *rsa)
|
||||
{
|
||||
BIGNUM *calcn;
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if (rsa == NULL || rsa->p == NULL || rsa->q == NULL || rsa->n == NULL) {
|
||||
return -1;
|
||||
}
|
||||
/* check that p and q are coprime, and that n = p*q. */
|
||||
if (!BN_is_prime(rsa->p, 1, NULL, NULL, NULL) ||
|
||||
!BN_is_prime(rsa->q, 1, NULL, NULL, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
calcn = BN_new();
|
||||
BN_mul(calcn, rsa->p, rsa->q, NULL);
|
||||
if (BN_cmp(calcn, rsa->n) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
/* XXX - check that d*e = 1 mod (p-1*q-1) */
|
||||
ret = 1;
|
||||
errout:
|
||||
BN_clear_free(calcn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
RSA *
|
||||
RSA_generate_key(int num, unsigned long e, void (*callback)(int,int,void *), void *cb_arg)
|
||||
{
|
||||
/* STUBBED */
|
||||
USE_ARG(num);
|
||||
USE_ARG(e);
|
||||
USE_ARG(callback);
|
||||
USE_ARG(cb_arg);
|
||||
printf("RSA_generate_key stubbed\n");
|
||||
return RSA_new();
|
||||
}
|
||||
|
||||
/* encrypt */
|
||||
int
|
||||
RSA_public_encrypt(int plainc, const unsigned char *plain, unsigned char *encbuf, RSA *rsa, int padding)
|
||||
{
|
||||
USE_ARG(padding);
|
||||
if (plain == NULL || encbuf == NULL || rsa == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return lowlevel_rsa_public_encrypt(plainc, plain, encbuf, rsa);
|
||||
}
|
||||
|
||||
/* decrypt */
|
||||
int
|
||||
RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
|
||||
{
|
||||
USE_ARG(padding);
|
||||
if (from == NULL || to == NULL || rsa == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return lowlevel_rsa_private_decrypt(flen, from, to, rsa);
|
||||
}
|
||||
|
||||
/* sign */
|
||||
int
|
||||
RSA_private_encrypt(int plainc, const unsigned char *plain, unsigned char *encbuf, RSA *rsa, int padding)
|
||||
{
|
||||
USE_ARG(padding);
|
||||
if (plain == NULL || encbuf == NULL || rsa == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return lowlevel_rsa_private_encrypt(plainc, plain, encbuf, rsa);
|
||||
}
|
||||
|
||||
/* verify */
|
||||
int
|
||||
RSA_public_decrypt(int enclen, const unsigned char *enc, unsigned char *dec, RSA *rsa, int padding)
|
||||
{
|
||||
rsa_pubkey_t pub;
|
||||
int ret;
|
||||
|
||||
if (enc == NULL || dec == NULL || rsa == NULL) {
|
||||
return 0;
|
||||
}
|
||||
USE_ARG(padding);
|
||||
(void) memset(&pub, 0x0, sizeof(pub));
|
||||
pub.n = BN_dup(rsa->n);
|
||||
pub.e = BN_dup(rsa->e);
|
||||
ret = lowlevel_rsa_public_decrypt(enc, enclen, dec, &pub);
|
||||
BN_free(pub.n);
|
||||
BN_free(pub.e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
DSA *
|
||||
DSA_new(void)
|
||||
{
|
||||
return netpgp_allocate(1, sizeof(DSA));
|
||||
}
|
||||
|
||||
void
|
||||
DSA_free(DSA *dsa)
|
||||
{
|
||||
if (dsa) {
|
||||
netpgp_deallocate(dsa, sizeof(*dsa));
|
||||
}
|
||||
}
|
||||
|
||||
DSA_SIG *
|
||||
DSA_SIG_new(void)
|
||||
{
|
||||
return netpgp_allocate(1, sizeof(DSA_SIG));
|
||||
}
|
||||
|
||||
void
|
||||
DSA_SIG_free(DSA_SIG *sig)
|
||||
{
|
||||
if (sig) {
|
||||
netpgp_deallocate(sig, sizeof(*sig));
|
||||
}
|
||||
}
|
||||
|
||||
DSA_SIG *
|
||||
DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
|
||||
{
|
||||
/* STUBBED */
|
||||
USE_ARG(dgst);
|
||||
USE_ARG(dlen);
|
||||
USE_ARG(dsa);
|
||||
printf("DSA_do_sign stubbed\n");
|
||||
return DSA_SIG_new();
|
||||
}
|
||||
|
||||
int
|
||||
DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)
|
||||
{
|
||||
if (dgst == NULL || dgst_len == 0 || sig == NULL || dsa == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return dsa_do_verify(dgst, dgst_len, sig, dsa);
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef RSA_H_
|
||||
#define RSA_H_ 20120325
|
||||
|
||||
#include "bn.h"
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef struct rsa_pubkey_t {
|
||||
BIGNUM *n; /* RSA public modulus n */
|
||||
BIGNUM *e; /* RSA public encryption exponent e */
|
||||
} rsa_pubkey_t;
|
||||
|
||||
typedef struct mpi_rsa_t {
|
||||
int f1; /* openssl pad */
|
||||
long f2; /* openssl version */
|
||||
const void *f3; /* openssl method */
|
||||
void *f4; /* openssl engine */
|
||||
BIGNUM *n;
|
||||
BIGNUM *e;
|
||||
BIGNUM *d;
|
||||
BIGNUM *p;
|
||||
BIGNUM *q;
|
||||
BIGNUM *dmp1;
|
||||
BIGNUM *dmq1;
|
||||
BIGNUM *iqmp;
|
||||
} mpi_rsa_t;
|
||||
|
||||
#define RSA mpi_rsa_t
|
||||
|
||||
typedef struct dsa_pubkey_t {
|
||||
BIGNUM *p; /* DSA public modulus n */
|
||||
BIGNUM *q; /* DSA public encryption exponent e */
|
||||
BIGNUM *g;
|
||||
BIGNUM *y;
|
||||
} dsa_pubkey_t;
|
||||
|
||||
typedef struct mpi_dsa_t {
|
||||
BIGNUM *p;
|
||||
BIGNUM *q;
|
||||
BIGNUM *g;
|
||||
BIGNUM *y;
|
||||
BIGNUM *x;
|
||||
BIGNUM *pub_key;
|
||||
BIGNUM *priv_key;
|
||||
} mpi_dsa_t;
|
||||
|
||||
#define DSA mpi_dsa_t
|
||||
|
||||
typedef struct rsasig_t {
|
||||
BIGNUM *sig; /* mpi which is actual signature */
|
||||
} rsasig_t;
|
||||
|
||||
typedef struct dsasig_t {
|
||||
BIGNUM *r; /* mpi which is actual signature */
|
||||
BIGNUM *s; /* mpi which is actual signature */
|
||||
} dsasig_t;
|
||||
|
||||
#define DSA_SIG dsasig_t
|
||||
|
||||
/* misc defs */
|
||||
#define RSA_NO_PADDING 3
|
||||
|
||||
#define SIGNETBSD_ID_SIZE 8
|
||||
#define SIGNETBSD_NAME_SIZE 128
|
||||
|
||||
#define RSA_PUBKEY_ALG 1
|
||||
#define DSA_PUBKEY_ALG 17
|
||||
|
||||
/* the public part of the key */
|
||||
typedef struct pubkey_t {
|
||||
uint32_t version; /* key version - usually 4 */
|
||||
uint8_t id[SIGNETBSD_ID_SIZE]; /* binary id */
|
||||
char name[SIGNETBSD_NAME_SIZE]; /* name of identity - not necessary, but looks better */
|
||||
int64_t birthtime; /* time of creation of key */
|
||||
int64_t expiry; /* expiration time of the key */
|
||||
uint32_t validity; /* validity in days */
|
||||
uint32_t alg; /* pubkey algorithm - rsa/dss etc */
|
||||
rsa_pubkey_t rsa; /* specific RSA keys */
|
||||
dsa_pubkey_t dsa; /* specific DSA keys */
|
||||
} pubkey_t;
|
||||
|
||||
/* signature details (for a specific file) */
|
||||
typedef struct signature_t {
|
||||
uint32_t version; /* signature version number */
|
||||
uint32_t type; /* signature type value */
|
||||
int64_t birthtime; /* creation time of the signature */
|
||||
int64_t expiry; /* expiration time of the signature */
|
||||
uint8_t id[SIGNETBSD_ID_SIZE]; /* binary id */
|
||||
uint32_t key_alg; /* public key algorithm number */
|
||||
uint32_t hash_alg; /* hashing algorithm number */
|
||||
rsasig_t rsa; /* RSA signature */
|
||||
dsasig_t dsa; /* DSA signature */
|
||||
size_t v4_hashlen; /* length of hashed info */
|
||||
uint8_t *v4_hashed; /* hashed info */
|
||||
uint8_t hash2[2]; /* high 2 bytes of hashed value - for quick test */
|
||||
pubkey_t *signer; /* pubkey of signer */
|
||||
} signature_t;
|
||||
|
||||
unsigned dsa_verify(const signature_t */*sig*/, const dsa_pubkey_t */*pubdsa*/, const uint8_t */*calc*/, size_t /*hashlen*/);
|
||||
|
||||
RSA *RSA_new(void);
|
||||
int RSA_size(const RSA */*rsa*/);
|
||||
void RSA_free(RSA */*rsa*/);
|
||||
int RSA_check_key(RSA */*rsa*/);
|
||||
RSA *RSA_generate_key(int /*num*/, unsigned long /*e*/, void (*callback)(int,int,void *), void */*cb_arg*/);
|
||||
int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding);
|
||||
int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding);
|
||||
int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding);
|
||||
int RSA_public_decrypt(int flen, const uint8_t *from, uint8_t *to, RSA *rsa, int padding);
|
||||
|
||||
DSA *DSA_new(void);
|
||||
int DSA_size(const DSA */*rsa*/);
|
||||
void DSA_free(DSA */*dsa*/);
|
||||
DSA_SIG *DSA_SIG_new(void);
|
||||
void DSA_SIG_free(DSA_SIG */*sig*/);
|
||||
int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa);
|
||||
DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,83 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "rsa.h"
|
||||
#include "rsastubs.h"
|
||||
|
||||
#ifndef USE_ARG
|
||||
#define USE_ARG(x) /*LINTED*/(void)&(x)
|
||||
#endif
|
||||
|
||||
static int
|
||||
pass_cb(char *buf, int size, int rwflag, void *u)
|
||||
{
|
||||
char *passphrase;
|
||||
char prompt[128];
|
||||
|
||||
USE_ARG(rwflag);
|
||||
snprintf(prompt, sizeof(prompt), "\"%s\" passphrase: ", (char *)u);
|
||||
if ((passphrase = getpass(prompt)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
(void) memcpy(buf, passphrase, (size_t)size);
|
||||
return (int)strlen(passphrase);
|
||||
}
|
||||
|
||||
RSA *
|
||||
PEM_read_RSAPrivateKey(FILE *fp, RSA **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
char phrase[128 + 1];
|
||||
RSA *rsa;
|
||||
int cc;
|
||||
|
||||
fprintf(stderr, "Stubbed PEM_read_RSAPrivateKey\n");
|
||||
USE_ARG(u);
|
||||
if (cb == NULL) {
|
||||
cb = pass_cb;
|
||||
}
|
||||
cc = (*cb)(phrase, sizeof(phrase), 0, u);
|
||||
rsa = *x = RSA_new();
|
||||
USE_ARG(fp);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
DSA *
|
||||
PEM_read_DSAPrivateKey(FILE *fp, DSA **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
DSA *dsa;
|
||||
|
||||
USE_ARG(u);
|
||||
if (cb == NULL) {
|
||||
cb = pass_cb;
|
||||
}
|
||||
dsa = *x = DSA_new();
|
||||
USE_ARG(fp);
|
||||
return dsa;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef RSASTUBS_H_
|
||||
#define RSASTUBS_H_ 20120412
|
||||
|
||||
#include "rsa.h"
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef int pem_password_cb(char */*buf*/, int /*size*/, int /*rwflag*/, void */*userdata*/);
|
||||
|
||||
RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x, pem_password_cb *cb, void *u);
|
||||
DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,71 @@
|
|||
# $NetBSD: Makefile,v 1.2 2012/11/20 05:26:25 agc Exp $
|
||||
|
||||
PROG=netpgpv
|
||||
SRCS=libverify.c b64.c pgpsum.c
|
||||
SRCS+=digest.c tiger.c
|
||||
SRCS+=bignum.c misc.c
|
||||
SRCS+=rsaglue.c rsa.c
|
||||
SRCS+=main.c
|
||||
WARNS=5
|
||||
MKMAN=no
|
||||
CPPFLAGS+=-I${.CURDIR}/../libbn
|
||||
CPPFLAGS+=-I${.CURDIR}/../librsa
|
||||
LDADD+=-lz
|
||||
LDADD+=-lbz2
|
||||
|
||||
# XXX - debugging
|
||||
#CPPFLAGS+=-g -O0
|
||||
#LDFLAGS+=-g -O0
|
||||
#CPPFLAGS+=-O3
|
||||
#LDFLAGS+=-O3
|
||||
|
||||
.PATH: ${.CURDIR} ${.CURDIR}/../libdigest ${.CURDIR}/../libverify ${.CURDIR}/../libbn ${.CURDIR}/../librsa
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
t: ${PROG}
|
||||
./${PROG} -c verify b.gpg > output16
|
||||
diff expected16 output16
|
||||
rm -f output16
|
||||
./${PROG} -c verify a.gpg > output17
|
||||
diff expected17 output17
|
||||
rm -f output17
|
||||
./${PROG} -c verify gpgsigned-a.gpg > output18
|
||||
diff expected18 output18
|
||||
rm -f output18
|
||||
./${PROG} -c verify NetBSD-6.0_RC2_hashes.asc > output19
|
||||
diff expected19 output19
|
||||
rm -f output19
|
||||
./${PROG} -c cat jj.asc > output20
|
||||
diff expected20 output20
|
||||
rm -f output20
|
||||
./${PROG} < a.gpg > output21
|
||||
diff expected21 output21
|
||||
rm -f output21
|
||||
./${PROG} < jj.asc > output22
|
||||
diff expected22 output22
|
||||
rm -f output22
|
||||
./${PROG} < NetBSD-6.0_RC2_hashes.asc > output23
|
||||
diff expected23 output23
|
||||
rm -f output23
|
||||
./${PROG} < b.gpg > output24
|
||||
diff expected24 output24
|
||||
rm -f output24
|
||||
./${PROG} NetBSD-6.0_RC1_hashes.gpg > output25
|
||||
diff expected25 output25
|
||||
rm -f output25
|
||||
./${PROG} < NetBSD-6.0_RC1_hashes.gpg > output26
|
||||
diff expected26 output26
|
||||
rm -f output26
|
||||
./${PROG} < NetBSD-6.0_hashes.asc > output27
|
||||
diff expected27 output27
|
||||
rm -f output27
|
||||
./${PROG} NetBSD-6.0_hashes.asc > output28
|
||||
diff expected28 output28
|
||||
rm -f output28
|
||||
./${PROG} NetBSD-6.0_RC1_hashes_ascii.gpg > output29
|
||||
diff expected29 output29
|
||||
rm -f output29
|
||||
./${PROG} < NetBSD-6.0_RC1_hashes_ascii.gpg > output30
|
||||
diff expected30 output30
|
||||
rm -f output30
|
|
@ -0,0 +1,82 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef ARRAY_H_
|
||||
#define ARRAY_H_ 20120921
|
||||
|
||||
#ifndef PGPV_ARRAY
|
||||
/* creates 2 unsigned vars called "name"c and "name"size in current scope */
|
||||
/* also creates an array called "name"s in current scope */
|
||||
#define PGPV_ARRAY(type, name) \
|
||||
unsigned name##c; unsigned name##vsize; type *name##s
|
||||
#endif
|
||||
|
||||
/* if this isn't part of a struct, need to specifically initialise things */
|
||||
#define ARRAY_INIT(name) do { \
|
||||
name##c = name##vsize = 0; \
|
||||
name##s = NULL; \
|
||||
} while(/*CONSTCOND*/0)
|
||||
|
||||
/* check the array is big enough - if not, expand it by explicit amount */
|
||||
/* this is clunky, but there are bugs a-lurking */
|
||||
#define ARRAY_EXPAND_SIZED(name, mult, add) do { \
|
||||
if (name##c == name##vsize) { \
|
||||
void *_v; \
|
||||
char *_cv = NULL; \
|
||||
unsigned _ents; \
|
||||
_ents = (name##vsize * (mult)) + (add); \
|
||||
_cv = _v = realloc(name##s, _ents * sizeof(*name##s)); \
|
||||
if (_v == NULL) { \
|
||||
fprintf(stderr, "ARRAY_EXPAND - bad realloc\n"); \
|
||||
} else { \
|
||||
memset(&_cv[name##vsize * sizeof(*name##s)], \
|
||||
0x0, (_ents - name##vsize) * sizeof(*name##s)); \
|
||||
name##s = _v; \
|
||||
name##vsize = _ents; \
|
||||
} \
|
||||
} \
|
||||
} while(/*CONSTCOND*/0)
|
||||
|
||||
/* check the array is big enough - if not, expand it (size * 2) + 10 */
|
||||
#define ARRAY_EXPAND(name) ARRAY_EXPAND_SIZED(name, 2, 10)
|
||||
|
||||
#define ARRAY_ELEMENT(name, num) name##s[num]
|
||||
#define ARRAY_LAST(name) name##s[name##c - 1]
|
||||
#define ARRAY_COUNT(name) name##c
|
||||
#define ARRAY_SIZE(name) name##vsize
|
||||
#define ARRAY_ARRAY(name) name##s
|
||||
|
||||
#define ARRAY_APPEND(name, newel) do { \
|
||||
ARRAY_EXPAND(name); \
|
||||
ARRAY_COUNT(name) += 1; \
|
||||
ARRAY_LAST(name) = newel; \
|
||||
} while(/*CONSTCOND*/0)
|
||||
|
||||
#define ARRAY_DELETE(name, num) do { \
|
||||
ARRAY_COUNT(name) -= 1; \
|
||||
memmove(&ARRAY_ELEMENT(name, num), &ARRAY_ELEMENT(name, num + 1), \
|
||||
(ARRAY_COUNT(name) - (num)) * sizeof(ARRAY_ELEMENT(name, 0))); \
|
||||
} while(/*CONSTCOND*/0)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,355 @@
|
|||
/*********************************************************************\
|
||||
|
||||
MODULE NAME: b64.c
|
||||
|
||||
AUTHOR: Bob Trower 08/04/01
|
||||
|
||||
PROJECT: Crypt Data Packaging
|
||||
|
||||
COPYRIGHT: Copyright (c) Trantor Standard Systems Inc., 2001
|
||||
|
||||
NOTE: This source code may be used as you wish, subject to
|
||||
the MIT license. See the LICENCE section below.
|
||||
|
||||
DESCRIPTION:
|
||||
This little utility implements the Base64
|
||||
Content-Transfer-Encoding standard described in
|
||||
RFC1113 (http://www.faqs.org/rfcs/rfc1113.html).
|
||||
|
||||
This is the coding scheme used by MIME to allow
|
||||
binary data to be transferred by SMTP mail.
|
||||
|
||||
Groups of 3 bytes from a binary stream are coded as
|
||||
groups of 4 bytes in a text stream.
|
||||
|
||||
The input stream is 'padded' with zeros to create
|
||||
an input that is an even multiple of 3.
|
||||
|
||||
A special character ('=') is used to denote padding so
|
||||
that the stream can be decoded back to its exact size.
|
||||
|
||||
Encoded output is formatted in lines which should
|
||||
be a maximum of 72 characters to conform to the
|
||||
specification. This program defaults to 72 characters,
|
||||
but will allow more or less through the use of a
|
||||
switch. The program enforces a minimum line size
|
||||
of 4 characters.
|
||||
|
||||
Example encoding:
|
||||
|
||||
The stream 'ABCD' is 32 bits long. It is mapped as
|
||||
follows:
|
||||
|
||||
ABCD
|
||||
|
||||
A (65) B (66) C (67) D (68) (None) (None)
|
||||
01000001 01000010 01000011 01000100
|
||||
|
||||
16 (Q) 20 (U) 9 (J) 3 (D) 17 (R) 0 (A) NA (=) NA (=)
|
||||
010000 010100 001001 000011 010001 000000 000000 000000
|
||||
|
||||
|
||||
QUJDRA==
|
||||
|
||||
Decoding is the process in reverse. A 'decode' lookup
|
||||
table has been created to avoid string scans.
|
||||
|
||||
DESIGN GOALS: Specifically:
|
||||
Code is a stand-alone utility to perform base64
|
||||
encoding/decoding. It should be genuinely useful
|
||||
when the need arises and it meets a need that is
|
||||
likely to occur for some users.
|
||||
Code acts as sample code to show the author's
|
||||
design and coding style.
|
||||
|
||||
Generally:
|
||||
This program is designed to survive:
|
||||
Everything you need is in a single source file.
|
||||
It compiles cleanly using a vanilla ANSI C compiler.
|
||||
It does its job correctly with a minimum of fuss.
|
||||
The code is not overly clever, not overly simplistic
|
||||
and not overly verbose.
|
||||
Access is 'cut and paste' from a web page.
|
||||
Terms of use are reasonable.
|
||||
|
||||
VALIDATION: Non-trivial code is never without errors. This
|
||||
file likely has some problems, since it has only
|
||||
been tested by the author. It is expected with most
|
||||
source code that there is a period of 'burn-in' when
|
||||
problems are identified and corrected. That being
|
||||
said, it is possible to have 'reasonably correct'
|
||||
code by following a regime of unit test that covers
|
||||
the most likely cases and regression testing prior
|
||||
to release. This has been done with this code and
|
||||
it has a good probability of performing as expected.
|
||||
|
||||
Unit Test Cases:
|
||||
|
||||
case 0:empty file:
|
||||
CASE0.DAT -> ->
|
||||
(Zero length target file created
|
||||
on both encode and decode.)
|
||||
|
||||
case 1:One input character:
|
||||
CASE1.DAT A -> QQ== -> A
|
||||
|
||||
case 2:Two input characters:
|
||||
CASE2.DAT AB -> QUJD -> AB
|
||||
|
||||
case 3:Three input characters:
|
||||
CASE3.DAT ABC -> QUJD -> ABC
|
||||
|
||||
case 4:Four input characters:
|
||||
case4.dat ABCD -> QUJDRA== -> ABCD
|
||||
|
||||
case 5:All chars from 0 to ff, linesize set to 50:
|
||||
|
||||
AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIj
|
||||
JCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZH
|
||||
SElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWpr
|
||||
bG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P
|
||||
kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKz
|
||||
tLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX
|
||||
2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7
|
||||
/P3+/w==
|
||||
|
||||
case 6:Mime Block from e-mail:
|
||||
(Data same as test case 5)
|
||||
|
||||
case 7: Large files:
|
||||
Tested 28 MB file in/out.
|
||||
|
||||
case 8: Random Binary Integrity:
|
||||
This binary program (b64.exe) was encoded to base64,
|
||||
back to binary and then executed.
|
||||
|
||||
case 9 Stress:
|
||||
All files in a working directory encoded/decoded
|
||||
and compared with file comparison utility to
|
||||
ensure that multiple runs do not cause problems
|
||||
such as exhausting file handles, tmp storage, etc.
|
||||
|
||||
-------------
|
||||
|
||||
Syntax, operation and failure:
|
||||
All options/switches tested. Performs as
|
||||
expected.
|
||||
|
||||
case 10:
|
||||
No Args -- Shows Usage Screen
|
||||
Return Code 1 (Invalid Syntax)
|
||||
case 11:
|
||||
One Arg (invalid) -- Shows Usage Screen
|
||||
Return Code 1 (Invalid Syntax)
|
||||
case 12:
|
||||
One Arg Help (-?) -- Shows detailed Usage Screen.
|
||||
Return Code 0 (Success -- help request is valid).
|
||||
case 13:
|
||||
One Arg Help (-h) -- Shows detailed Usage Screen.
|
||||
Return Code 0 (Success -- help request is valid).
|
||||
case 14:
|
||||
One Arg (valid) -- Uses stdin/stdout (filter)
|
||||
Return Code 0 (Sucess)
|
||||
case 15:
|
||||
Two Args (invalid file) -- shows system error.
|
||||
Return Code 2 (File Error)
|
||||
case 16:
|
||||
Encode non-existent file -- shows system error.
|
||||
Return Code 2 (File Error)
|
||||
case 17:
|
||||
Out of disk space -- shows system error.
|
||||
Return Code 3 (File I/O Error)
|
||||
|
||||
-------------
|
||||
|
||||
Compile/Regression test:
|
||||
gcc compiled binary under Cygwin
|
||||
Microsoft Visual Studio under Windows 2000
|
||||
Microsoft Version 6.0 C under Windows 2000
|
||||
|
||||
DEPENDENCIES: None
|
||||
|
||||
LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall
|
||||
be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
||||
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
VERSION HISTORY:
|
||||
Bob Trower 08/04/01 -- Create Version 0.00.00B
|
||||
|
||||
\******************************************************************* */
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "b64.h"
|
||||
|
||||
/*
|
||||
** Translation Table as described in RFC1113
|
||||
*/
|
||||
static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/*
|
||||
** Translation Table to decode (created by author)
|
||||
*/
|
||||
static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
|
||||
|
||||
/*
|
||||
** encodeblock
|
||||
**
|
||||
** encode 3 8-bit binary bytes as 4 '6-bit' characters
|
||||
*/
|
||||
static void
|
||||
encodeblock(uint8_t *wordin, uint8_t *wordout, int wordlen)
|
||||
{
|
||||
wordout[0] = cb64[(unsigned)wordin[0] >> 2];
|
||||
wordout[1] = cb64[((unsigned)(wordin[0] & 0x03) << 4) | ((unsigned)(wordin[1] & 0xf0) >> 4)];
|
||||
wordout[2] = (uint8_t)(wordlen > 1) ?
|
||||
cb64[((unsigned)(wordin[1] & 0x0f) << 2) | ((unsigned)(wordin[2] & 0xc0) >> 6)] : '=';
|
||||
wordout[3] = (uint8_t)(wordlen > 2) ? cb64[wordin[2] & 0x3f] : '=';
|
||||
}
|
||||
|
||||
/*
|
||||
** encode
|
||||
**
|
||||
** base64 encode a stream adding padding and line breaks as per spec.
|
||||
*/
|
||||
int
|
||||
b64encode(const char *in, const size_t insize, void *vp, size_t outsize, int linesize)
|
||||
{
|
||||
const char *inp;
|
||||
unsigned i;
|
||||
uint8_t wordout[4];
|
||||
uint8_t wordin[3];
|
||||
char *out = vp;
|
||||
char *outp;
|
||||
int blocksout;
|
||||
int wordlen;
|
||||
|
||||
if (in == NULL || vp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
wordlen = 0;
|
||||
for (blocksout = 0, inp = in, outp = out; (size_t)(inp - in) < insize && (size_t)(outp - out) < outsize;) {
|
||||
for (wordlen = 0, i = 0; i < sizeof(wordin); i++) {
|
||||
wordin[i] = (uint8_t) *inp++;
|
||||
if ((size_t)(inp - in) <= insize) {
|
||||
wordlen++;
|
||||
} else {
|
||||
wordin[i] = 0x0;
|
||||
}
|
||||
}
|
||||
if (wordlen > 0) {
|
||||
encodeblock(wordin, wordout, wordlen);
|
||||
for (i = 0; i < sizeof(wordout) ; i++) {
|
||||
*outp++ = wordout[i];
|
||||
}
|
||||
blocksout++;
|
||||
}
|
||||
if (linesize > 0) {
|
||||
if (blocksout >= (int)(linesize / sizeof(wordout)) ||
|
||||
(size_t)(inp - in) >= insize) {
|
||||
if (blocksout) {
|
||||
*outp++ = '\r';
|
||||
*outp++ = '\n';
|
||||
}
|
||||
blocksout = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (int)(outp - out);
|
||||
}
|
||||
|
||||
/*
|
||||
** decodeblock
|
||||
**
|
||||
** decode 4 '6-bit' characters into 3 8-bit binary bytes
|
||||
*/
|
||||
static void
|
||||
decodeblock(uint8_t wordin[4], uint8_t wordout[3])
|
||||
{
|
||||
wordout[0] = (uint8_t) ((unsigned)wordin[0] << 2 | (unsigned)wordin[1] >> 4);
|
||||
wordout[1] = (uint8_t) ((unsigned)wordin[1] << 4 | (unsigned)wordin[2] >> 2);
|
||||
wordout[2] = (uint8_t) (((wordin[2] << 6) & 0xc0) | wordin[3]);
|
||||
}
|
||||
|
||||
/*
|
||||
** decode
|
||||
**
|
||||
** decode a base64 encoded stream discarding padding, line breaks and noise
|
||||
*/
|
||||
int
|
||||
b64decode(const char *in, const size_t insize, void *vp, size_t outsize)
|
||||
{
|
||||
const char *inp;
|
||||
unsigned wordlen;
|
||||
unsigned i;
|
||||
uint8_t wordout[3];
|
||||
uint8_t wordin[4];
|
||||
uint8_t v;
|
||||
char *out = vp;
|
||||
char *outp;
|
||||
|
||||
if (in == NULL || vp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
for (inp = in, outp = out ; (size_t)(inp - in) < insize && (size_t)(outp - out) < outsize ; ) {
|
||||
for (wordlen = 0, i = 0 ; i < sizeof(wordin) && (size_t)(inp - in) < insize ; i++) {
|
||||
/* get a single character */
|
||||
for (v = 0; (size_t)(inp - in) <= insize && v == 0 ; ) {
|
||||
if (*inp == '\r' && *(inp + 1) == '\n') {
|
||||
inp += 2;
|
||||
} else {
|
||||
v = (uint8_t) *inp++;
|
||||
v = (uint8_t) ((v < 43 || v > 122) ? 0 : cd64[v - 43]);
|
||||
if (v) {
|
||||
v = (uint8_t) ((v == '$') ? 0 : v - 61);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* perhaps 0x0 pad */
|
||||
if ((size_t)(inp - in) <= insize) {
|
||||
wordlen += 1;
|
||||
if (v) {
|
||||
wordin[i] = (uint8_t) (v - 1);
|
||||
}
|
||||
} else {
|
||||
wordin[i] = 0x0;
|
||||
}
|
||||
}
|
||||
if (wordlen > 0) {
|
||||
decodeblock(wordin, wordout);
|
||||
for (i = 0; i < wordlen - 1 ; i++) {
|
||||
*outp++ = wordout[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return (int)(outp - out);
|
||||
}
|
||||
|
||||
/* return the encoded size for n bytes input */
|
||||
int
|
||||
b64_encsize(unsigned n)
|
||||
{
|
||||
return ((4 * n) / 3) + 4;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*-
|
||||
* Copyright (c) 2010 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef B64_H_
|
||||
#define B64_H_ 20091223
|
||||
|
||||
int b64encode(const char */*in*/, const size_t /*insize*/, void */*vp*/, size_t /*outsize*/, int /*linesize*/);
|
||||
int b64decode(const char */*in*/, const size_t /*insize*/, void */*vp*/, size_t /*outsize*/);
|
||||
int b64_encsize(unsigned /*n*/);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,88 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef isprint
|
||||
#define isprint(x) ((x) >= ' ' && (x) <= '~')
|
||||
#endif
|
||||
|
||||
#define HEXDUMP_LINELEN 16
|
||||
|
||||
#ifndef PRIsize
|
||||
#define PRIsize "z"
|
||||
#endif
|
||||
|
||||
/* show hexadecimal/ascii dump */
|
||||
static ssize_t
|
||||
hexdump(const char *in, const size_t len, void *outvp, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
char line[HEXDUMP_LINELEN + 1];
|
||||
char *out = (char *)outvp;
|
||||
int o;
|
||||
|
||||
for (i = 0, o = 0 ; i < len ; i++) {
|
||||
if (i % HEXDUMP_LINELEN == 0) {
|
||||
o += snprintf(&out[o], size - o,
|
||||
"%.5" PRIsize "u | ", i);
|
||||
}
|
||||
o += snprintf(&out[o], size - o, "%.02x ", (uint8_t)in[i]);
|
||||
line[i % HEXDUMP_LINELEN] =
|
||||
(isprint((uint8_t)in[i])) ? in[i] : '.';
|
||||
if (i % HEXDUMP_LINELEN == HEXDUMP_LINELEN - 1) {
|
||||
line[HEXDUMP_LINELEN] = 0x0;
|
||||
o += snprintf(&out[o], size - o, " | %s\n", line);
|
||||
}
|
||||
}
|
||||
if (i % HEXDUMP_LINELEN != 0) {
|
||||
for ( ; i % HEXDUMP_LINELEN != 0 ; i++) {
|
||||
o += snprintf(&out[o], size - o, " ");
|
||||
line[i % HEXDUMP_LINELEN] = ' ';
|
||||
}
|
||||
line[HEXDUMP_LINELEN] = 0x0;
|
||||
o += snprintf(&out[o], size - o, " | %s\n", line);
|
||||
}
|
||||
return (ssize_t)o;
|
||||
}
|
||||
|
||||
void dumpmem(void */*p*/, size_t /*size*/);
|
||||
|
||||
/* just dump an area of memory to stdout */
|
||||
void
|
||||
dumpmem(void *vp, size_t size)
|
||||
{
|
||||
ssize_t cc;
|
||||
uint8_t *p = (uint8_t *)vp;
|
||||
char *buf;
|
||||
|
||||
buf = calloc(1, size * 5);
|
||||
cc = hexdump((const char *)p, size, buf, size * 5);
|
||||
fprintf(stdout, "%.*s\n", (int)cc, buf);
|
||||
free(buf);
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
.\" $NetBSD: libnetpgpverify.3,v 1.2 2012/11/20 05:26:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.Dd October 21, 2012
|
||||
.Dt LIBNETPGPVERIFY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm libnetpgpverify
|
||||
.Nd library to verify digital signatures
|
||||
.Sh LIBRARY
|
||||
.Lb libnetpgpverify
|
||||
.Sh SYNOPSIS
|
||||
.In netpgp/verify.h
|
||||
.Ft int
|
||||
.Fo pgpv_read_pubring
|
||||
.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size"
|
||||
.Fc
|
||||
.Ft size_t
|
||||
.Fo pgpv_verify
|
||||
.Fa "pgpv_cursor_t *cursor" "pgpv_t *pgp" "const void *ptr" "ssize_t size"
|
||||
.Fc
|
||||
.Ft size_t
|
||||
.Fo pgpv_get_verified
|
||||
.Fa "pgpv_cursor_t *cursor" "size_t cookie " "char **ret"
|
||||
.Fc
|
||||
.Ft size_t
|
||||
.Fo pgpv_get_entry
|
||||
.Fa "pgpv_t *pgp" "unsigned ent" "char **ret"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fo pgpv_close
|
||||
.Fa "pgpv_t *pgp"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a small library which will verify a digital signature on a text or
|
||||
binary document.
|
||||
It has been kept deliberately small and only uses compression libraries
|
||||
to function.
|
||||
.Pp
|
||||
PGP messages, including key rings, are made up of PGP packets, defined
|
||||
in RFC 4880.
|
||||
To match a digital signature, the public key of the signer must be
|
||||
located in a public key ring.
|
||||
This library has enough functionality to parse a pubkey keyring,
|
||||
using
|
||||
.Fn pgpv_read_pubring
|
||||
to read the public keys of trusted identities,
|
||||
and to read files or memory which has already been signed.
|
||||
The
|
||||
.Fn pgpv_verify
|
||||
function is used to verify the signature, either on data, or on memory.
|
||||
To signal to
|
||||
.Fn pgpv_verify
|
||||
to read a file and verify it, the
|
||||
.Dv size
|
||||
argument should be set to
|
||||
.Dv -1
|
||||
whilst a positive size signals that the pointer value should be that
|
||||
of signed memory.
|
||||
.Fn pgpv_verify
|
||||
returns a cookie if the ignature was verified, or 0 if it did not.
|
||||
This cookie can subsequently be used to retrieve the data which
|
||||
was verified.
|
||||
.Pp
|
||||
If the signature does match, then the file or memory can be considered as being
|
||||
verified as being unmodified and unchanged, integrally sound.
|
||||
.Pp
|
||||
Signatures have validity dates on them, and it is possible for a signature to
|
||||
have expired when it is being checked.
|
||||
If for any reason the signature does not match, then the reason for not
|
||||
verifying the signature will be stored in the
|
||||
.Dv why
|
||||
buffer in the
|
||||
.Dv pgpv_cursor_t
|
||||
structure.
|
||||
.Pp
|
||||
Occasionally, the memory or contents of the file which matched the signature
|
||||
will be needed, rather than a boolean value of whether it was verified.
|
||||
To do this, the
|
||||
.Fn pgpv_get_verified
|
||||
function is used.
|
||||
Arguments to
|
||||
.Fn pgpv_get_verified
|
||||
are the cookie returned from the verification, and a buffer
|
||||
allocated for the returned data and its size.
|
||||
If an error occurs, or the signature is not verified, a zero value is returned
|
||||
for the size.
|
||||
.Nm
|
||||
stores the starts of the data of all verified matches, and so the entry
|
||||
number argument is the index of the occurrence of verification.
|
||||
The first match will have an entry number of 0, the second 1, and so on.
|
||||
.Pp
|
||||
The
|
||||
.Fn pgpv_close
|
||||
function is used to clean up after all matching and verification has taken place.
|
||||
It frees and de-allocates all resources used in the verification of the signature.
|
||||
.Pp
|
||||
The program used for signing may encode into base64 encoding, and it may also
|
||||
use embedded compression to make the output smaller than it would otherwise be.
|
||||
This is handled automatically by
|
||||
.Nm
|
||||
.Sh SEE ALSO
|
||||
.Xr bn 3 ,
|
||||
.Xr zlib 3 ,
|
||||
.Xr bzlib2 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is designed to conform to IETF RFC 4880.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
library first appeared in
|
||||
.Nx 7.0 .
|
||||
.Sh AUTHORS
|
||||
.An Alistair Crooks Aq agc@NetBSD.org
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,187 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "digest.h"
|
||||
#include "pgpsum.h"
|
||||
|
||||
/* add the ascii armor line endings (except for last line) */
|
||||
static size_t
|
||||
don_armor(digest_t *hash, uint8_t *in, size_t insize, int doarmor)
|
||||
{
|
||||
uint8_t *from;
|
||||
uint8_t *newp;
|
||||
uint8_t *p;
|
||||
uint8_t dos_line_end[2];
|
||||
|
||||
dos_line_end[0] = '\r';
|
||||
dos_line_end[1] = '\n';
|
||||
for (from = in ; (p = memchr(from, '\n', insize - (size_t)(from - in))) != NULL ; from = p + 1) {
|
||||
for (newp = p ; doarmor == 'w' && newp > from ; --newp) {
|
||||
if (*(newp - 1) != ' ' && *(newp - 1) != '\t') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
digest_update(hash, from, (size_t)(newp - from));
|
||||
digest_update(hash, dos_line_end, sizeof(dos_line_end));
|
||||
}
|
||||
digest_update(hash, from, insize - (size_t)(from - in));
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef NETPGPV_DEBUG
|
||||
/* just for giggles, write what we're about to checksum */
|
||||
static int
|
||||
writefile(uint8_t *mem, size_t insize)
|
||||
{
|
||||
size_t cc;
|
||||
size_t wc;
|
||||
char template[256];
|
||||
int fd;
|
||||
|
||||
snprintf(template, sizeof(template), "netpgpvmd.XXXXXX");
|
||||
if ((fd = mkstemp(template)) < 0) {
|
||||
fprintf(stderr, "can't mkstemp %s\n", template);
|
||||
return 0;
|
||||
}
|
||||
for (cc = 0 ; cc < insize ; cc += wc) {
|
||||
if ((wc = write(fd, &mem[cc], insize - cc)) <= 0) {
|
||||
fprintf(stderr, "short write\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* return non-zero if this is actually an armored piece already */
|
||||
static int
|
||||
already_armored(uint8_t *in, size_t insize)
|
||||
{
|
||||
uint8_t *from;
|
||||
uint8_t *p;
|
||||
|
||||
for (from = in ; (p = memchr(from, '\n', insize - (size_t)(from - in))) != NULL ; from = p + 1) {
|
||||
if (*(p - 1) != '\r') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* calculate the checksum for the data we have */
|
||||
static int
|
||||
calcsum(uint8_t *out, size_t size, const char *name, uint8_t *mem, size_t cc, const uint8_t *hashed, size_t hashsize, int doarmor)
|
||||
{
|
||||
digest_t hash;
|
||||
uint32_t len32;
|
||||
uint16_t len16;
|
||||
uint8_t hashalg;
|
||||
uint8_t trailer[6];
|
||||
|
||||
/* hashed data is non-null (previously checked) */
|
||||
hashalg = hashed[3];
|
||||
memcpy(&len16, &hashed[4], sizeof(len16));
|
||||
len32 = ntohs(len16) + 6;
|
||||
len32 = htonl(len32);
|
||||
trailer[0] = 0x04;
|
||||
trailer[1] = 0xff;
|
||||
memcpy(&trailer[2], &len32, sizeof(len32));
|
||||
#ifdef NETPGPV_DEBUG
|
||||
writefile(mem, cc);
|
||||
#endif
|
||||
digest_init(&hash, hashalg);
|
||||
if (strchr("tw", doarmor) != NULL && !already_armored(mem, cc)) {
|
||||
/* this took me ages to find - something causes gpg to truncate its input */
|
||||
don_armor(&hash, mem, cc - 1, doarmor);
|
||||
} else {
|
||||
digest_update(&hash, mem, cc);
|
||||
}
|
||||
if (hashed) {
|
||||
digest_update(&hash, hashed, hashsize);
|
||||
}
|
||||
digest_update(&hash, trailer, sizeof(trailer));
|
||||
return digest_final(out, &hash);
|
||||
}
|
||||
|
||||
/* open the file, mmap it, and then get the checksum on that */
|
||||
int
|
||||
pgpv_digest_file(uint8_t *data, size_t size, const char *name, const uint8_t *hashed, size_t hashsize, int doarmor)
|
||||
{
|
||||
struct stat st;
|
||||
uint8_t *mem;
|
||||
size_t cc;
|
||||
FILE *fp;
|
||||
int ret;
|
||||
|
||||
if (hashed == NULL || data == NULL || name == NULL) {
|
||||
fprintf(stderr, "no hashed data provided\n");
|
||||
return 0;
|
||||
}
|
||||
ret = 0;
|
||||
mem = NULL;
|
||||
cc = 0;
|
||||
if ((fp = fopen(name, "r")) == NULL) {
|
||||
warn("%s - not found", name);
|
||||
return 0;
|
||||
}
|
||||
if (fstat(fileno(fp), &st) < 0) {
|
||||
warn("%s - can't stat", name);
|
||||
goto done;
|
||||
}
|
||||
cc = (size_t)(st.st_size);
|
||||
if ((mem = mmap(NULL, cc, PROT_READ, MAP_SHARED, fileno(fp), 0)) == MAP_FAILED) {
|
||||
warn("%s - can't mmap", name);
|
||||
goto done;
|
||||
}
|
||||
ret = calcsum(data, size, name, mem, cc, hashed, hashsize, doarmor);
|
||||
done:
|
||||
if (data) {
|
||||
munmap(mem, cc);
|
||||
}
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* calculate the digest over memory too */
|
||||
int
|
||||
pgpv_digest_memory(uint8_t *data, size_t size, void *mem, size_t cc, const uint8_t *hashed, size_t hashsize, int doarmor)
|
||||
{
|
||||
if (hashed == NULL || data == NULL || mem == NULL) {
|
||||
fprintf(stderr, "no hashed data provided\n");
|
||||
return 0;
|
||||
}
|
||||
return calcsum(data, size, "[memory]", mem, cc, hashed, hashsize, doarmor);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef PGPSUM_H_
|
||||
#define PGPSUM_H_ 20121003
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
int pgpv_digest_file(uint8_t */*buf*/, size_t /*size*/, const char */*name*/, const uint8_t */*hashed*/, size_t /*hashsize*/, int /*doarmor*/);
|
||||
int pgpv_digest_memory(uint8_t */*buf*/, size_t /*size*/, void */*memory*/, size_t /*cc*/, const uint8_t */*hashed*/, size_t /*hashsize*/, int /*doarmor*/);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,292 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#ifndef NETPGP_VERIFY_H_
|
||||
#define NETPGP_VERIFY_H_ 20120928
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifndef PGPV_ARRAY
|
||||
/* creates 2 unsigned vars called "name"c and "name"size in current scope */
|
||||
/* also creates an array called "name"s in current scope */
|
||||
#define PGPV_ARRAY(type, name) \
|
||||
unsigned name##c; unsigned name##vsize; type *name##s
|
||||
#endif
|
||||
|
||||
/* 64bit key ids */
|
||||
#define PGPV_KEYID_LEN 8
|
||||
#define PGPV_STR_KEYID_LEN (PGPV_KEYID_LEN + PGPV_KEYID_LEN + 1)
|
||||
|
||||
/* bignum structure */
|
||||
typedef struct pgpv_bignum_t {
|
||||
void *bn; /* hide the implementation details */
|
||||
uint16_t bits; /* cached number of bits */
|
||||
} pgpv_bignum_t;
|
||||
|
||||
/* right now, our max binary digest length is 20 bytes */
|
||||
#define PGPV_MAX_HASH_LEN 20
|
||||
|
||||
/* fingerprint */
|
||||
typedef struct pgpv_fingerprint_t {
|
||||
uint8_t hashalg; /* algorithm for digest */
|
||||
uint8_t v[PGPV_MAX_HASH_LEN]; /* the digest */
|
||||
uint32_t len; /* its length */
|
||||
} pgpv_fingerprint_t;
|
||||
|
||||
/* specify size for array of bignums */
|
||||
#define PGPV_MAX_PUBKEY_BN 4
|
||||
|
||||
/* public key */
|
||||
typedef struct pgpv_pubkey_t {
|
||||
pgpv_fingerprint_t fingerprint; /* key fingerprint i.e. digest */
|
||||
uint8_t keyid[PGPV_KEYID_LEN]; /* last 8 bytes of v4 keys */
|
||||
int64_t birth; /* creation time */
|
||||
int64_t expiry; /* expiry time */
|
||||
pgpv_bignum_t bn[PGPV_MAX_PUBKEY_BN]; /* bignums */
|
||||
uint8_t keyalg; /* key algorithm */
|
||||
uint8_t hashalg; /* hash algorithm */
|
||||
uint8_t version; /* key version */
|
||||
} pgpv_pubkey_t;
|
||||
|
||||
#define PGPV_MAX_SESSKEY_BN 2
|
||||
|
||||
/* a (size, byte array) string */
|
||||
typedef struct pgpv_string_t {
|
||||
size_t size;
|
||||
uint8_t *data;
|
||||
} pgpv_string_t;
|
||||
|
||||
typedef struct pgpv_ref_t {
|
||||
void *vp;
|
||||
size_t offset;
|
||||
unsigned mem;
|
||||
} pgpv_ref_t;
|
||||
|
||||
#define PGPV_MAX_SECKEY_BN 4
|
||||
|
||||
typedef struct pgpv_compress_t {
|
||||
pgpv_string_t s;
|
||||
uint8_t compalg;
|
||||
} pgpv_compress_t;
|
||||
|
||||
/* a packet dealing with trust */
|
||||
typedef struct pgpv_trust_t {
|
||||
uint8_t level;
|
||||
uint8_t amount;
|
||||
} pgpv_trust_t;
|
||||
|
||||
/* a signature sub packet */
|
||||
typedef struct pgpv_sigsubpkt_t {
|
||||
pgpv_string_t s;
|
||||
uint8_t tag;
|
||||
uint8_t critical;
|
||||
} pgpv_sigsubpkt_t;
|
||||
|
||||
#define PGPV_MAX_SIG_BN 2
|
||||
|
||||
typedef struct pgpv_signature_t {
|
||||
uint8_t *signer; /* key id of signer */
|
||||
pgpv_ref_t hashstart;
|
||||
uint8_t *hash2;
|
||||
uint8_t *mpi;
|
||||
int64_t birth;
|
||||
int64_t keyexpiry;
|
||||
int64_t expiry;
|
||||
uint32_t hashlen;
|
||||
uint8_t version;
|
||||
uint8_t type;
|
||||
uint8_t keyalg;
|
||||
uint8_t hashalg;
|
||||
uint8_t trustlevel;
|
||||
uint8_t trustamount;
|
||||
pgpv_bignum_t bn[PGPV_MAX_SIG_BN];
|
||||
char *regexp;
|
||||
char *pref_key_server;
|
||||
char *policy;
|
||||
char *features;
|
||||
char *why_revoked;
|
||||
uint8_t *revoke_fingerprint;
|
||||
uint8_t revoke_alg;
|
||||
uint8_t revoke_sensitive;
|
||||
uint8_t trustsig;
|
||||
uint8_t revocable;
|
||||
uint8_t pref_symm_alg;
|
||||
uint8_t pref_hash_alg;
|
||||
uint8_t pref_compress_alg;
|
||||
uint8_t key_server_modify;
|
||||
uint8_t notation;
|
||||
uint8_t type_key;
|
||||
uint8_t primary_userid;
|
||||
uint8_t revoked; /* subtract 1 to get real reason, 0 == not revoked */
|
||||
} pgpv_signature_t;
|
||||
|
||||
/* a signature packet */
|
||||
typedef struct pgpv_sigpkt_t {
|
||||
pgpv_signature_t sig;
|
||||
uint16_t subslen;
|
||||
uint16_t unhashlen;
|
||||
PGPV_ARRAY(pgpv_sigsubpkt_t, subpkts);
|
||||
} pgpv_sigpkt_t;
|
||||
|
||||
/* a one-pass signature packet */
|
||||
typedef struct pgpv_onepass_t {
|
||||
uint8_t keyid[PGPV_KEYID_LEN];
|
||||
uint8_t version;
|
||||
uint8_t type;
|
||||
uint8_t hashalg;
|
||||
uint8_t keyalg;
|
||||
uint8_t nested;
|
||||
} pgpv_onepass_t;
|
||||
|
||||
/* a literal data packet */
|
||||
typedef struct pgpv_litdata_t {
|
||||
uint8_t *filename;
|
||||
pgpv_string_t s;
|
||||
uint32_t secs;
|
||||
uint8_t namelen;
|
||||
char format;
|
||||
unsigned mem;
|
||||
size_t offset;
|
||||
size_t len;
|
||||
} pgpv_litdata_t;
|
||||
|
||||
/* user attributes - images */
|
||||
typedef struct pgpv_userattr_t {
|
||||
size_t len;
|
||||
PGPV_ARRAY(pgpv_string_t, subattrs);
|
||||
} pgpv_userattr_t;
|
||||
|
||||
/* a general PGP packet */
|
||||
typedef struct pgpv_pkt_t {
|
||||
uint8_t tag;
|
||||
uint8_t newfmt;
|
||||
uint8_t allocated;
|
||||
uint8_t mement;
|
||||
size_t offset;
|
||||
pgpv_string_t s;
|
||||
union {
|
||||
pgpv_sigpkt_t sigpkt;
|
||||
pgpv_onepass_t onepass;
|
||||
pgpv_litdata_t litdata;
|
||||
pgpv_compress_t compressed;
|
||||
pgpv_trust_t trust;
|
||||
pgpv_pubkey_t pubkey;
|
||||
pgpv_string_t userid;
|
||||
pgpv_userattr_t userattr;
|
||||
} u;
|
||||
} pgpv_pkt_t;
|
||||
|
||||
/* a memory structure */
|
||||
typedef struct pgpv_mem_t {
|
||||
size_t size;
|
||||
size_t cc;
|
||||
uint8_t *mem;
|
||||
FILE *fp;
|
||||
uint8_t dealloc;
|
||||
const char *allowed; /* the types of packet that are allowed */
|
||||
} pgpv_mem_t;
|
||||
|
||||
/* packet parser */
|
||||
|
||||
typedef struct pgpv_signed_userid_t {
|
||||
pgpv_string_t userid;
|
||||
PGPV_ARRAY(pgpv_signature_t, sigs);
|
||||
uint8_t primary_userid;
|
||||
uint8_t revoked;
|
||||
} pgpv_signed_userid_t;
|
||||
|
||||
typedef struct pgpv_signed_userattr_t {
|
||||
pgpv_userattr_t userattr;
|
||||
PGPV_ARRAY(pgpv_signature_t, sigs);
|
||||
uint8_t revoked;
|
||||
} pgpv_signed_userattr_t;
|
||||
|
||||
typedef struct pgpv_signed_subkey_t {
|
||||
pgpv_pubkey_t subkey;
|
||||
pgpv_signature_t revoc_self_sig;
|
||||
PGPV_ARRAY(pgpv_signature_t, sigs);
|
||||
} pgpv_signed_subkey_t;
|
||||
|
||||
typedef struct pgpv_primarykey_t {
|
||||
pgpv_pubkey_t primary;
|
||||
pgpv_signature_t revoc_self_sig;
|
||||
PGPV_ARRAY(pgpv_signature_t, direct_sigs);
|
||||
PGPV_ARRAY(pgpv_signed_userid_t, signed_userids);
|
||||
PGPV_ARRAY(pgpv_signed_userattr_t, signed_userattrs);
|
||||
PGPV_ARRAY(pgpv_signed_subkey_t, signed_subkeys);
|
||||
size_t fmtsize;
|
||||
uint8_t primary_userid;
|
||||
} pgpv_primarykey_t;
|
||||
|
||||
/* everything stems from this structure */
|
||||
typedef struct pgpv_t {
|
||||
PGPV_ARRAY(pgpv_pkt_t, pkts); /* packet array */
|
||||
PGPV_ARRAY(pgpv_primarykey_t, primaries); /* array of primary keys */
|
||||
PGPV_ARRAY(pgpv_mem_t, areas); /* areas we read packets from */
|
||||
PGPV_ARRAY(size_t, datastarts); /* starts of data packets */
|
||||
size_t pkt; /* when parsing, current pkt number */
|
||||
const char *op; /* the operation we're doing */
|
||||
} pgpv_t;
|
||||
|
||||
#define PGPV_REASON_LEN 128
|
||||
|
||||
/* when searching, we define a cursor, and fill in an array of subscripts */
|
||||
typedef struct pgpv_cursor_t {
|
||||
pgpv_t *pgp; /* pointer to pgp tree */
|
||||
char *field; /* field we're searching on */
|
||||
char *op; /* operation we're doing */
|
||||
char *value; /* value we're searching for */
|
||||
void *ptr; /* for regexps etc */
|
||||
PGPV_ARRAY(uint32_t, found); /* array of matched subscripts */
|
||||
PGPV_ARRAY(size_t, datacookies); /* cookies to retrieve matched data */
|
||||
int64_t sigtime; /* time of signature */
|
||||
char why[PGPV_REASON_LEN]; /* reason for bad signature */
|
||||
} pgpv_cursor_t;
|
||||
|
||||
#ifndef __BEGIN_DECLS
|
||||
# if defined(__cplusplus)
|
||||
# define __BEGIN_DECLS extern "C" {
|
||||
# define __END_DECLS }
|
||||
# else
|
||||
# define __BEGIN_DECLS
|
||||
# define __END_DECLS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int pgpv_read_pubring(pgpv_t */*pgp*/, const void */*keyringfile/mem*/, ssize_t /*size*/);
|
||||
|
||||
size_t pgpv_verify(pgpv_cursor_t */*cursor*/, pgpv_t */*pgp*/, const void */*mem/file*/, ssize_t /*size*/);
|
||||
size_t pgpv_get_verified(pgpv_cursor_t */*cursor*/, size_t /*cookie*/, char **/*ret*/);
|
||||
|
||||
size_t pgpv_get_entry(pgpv_t */*pgp*/, unsigned /*ent*/, char **/*ret*/);
|
||||
|
||||
int pgpv_close(pgpv_t */*pgp*/);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -0,0 +1,165 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "verify.h"
|
||||
|
||||
#include "array.h"
|
||||
|
||||
/* print the time nicely */
|
||||
static void
|
||||
ptime(int64_t secs)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
t = (time_t)secs;
|
||||
printf("%s", ctime(&t));
|
||||
}
|
||||
|
||||
/* print entry n */
|
||||
static void
|
||||
pentry(pgpv_t *pgp, int n)
|
||||
{
|
||||
char *s;
|
||||
|
||||
pgpv_get_entry(pgp, (unsigned)n, &s);
|
||||
printf("%s", s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
#define MB(x) ((x) * 1024 * 1024)
|
||||
|
||||
/* get stdin into memory so we can verify it */
|
||||
static char *
|
||||
getstdin(ssize_t *cc, size_t *size)
|
||||
{
|
||||
size_t newsize;
|
||||
char *newin;
|
||||
char *in;
|
||||
int rc;
|
||||
|
||||
*cc = 0;
|
||||
*size = 0;
|
||||
in = NULL;
|
||||
do {
|
||||
newsize = *size + MB(1);
|
||||
if ((newin = realloc(in, newsize)) == NULL) {
|
||||
break;
|
||||
}
|
||||
in = newin;
|
||||
*size = newsize;
|
||||
if ((rc = read(STDIN_FILENO, &in[*cc], newsize - *cc)) > 0) {
|
||||
*cc += rc;
|
||||
}
|
||||
} while (rc > 0);
|
||||
return in;
|
||||
}
|
||||
|
||||
/* verify memory or file */
|
||||
static int
|
||||
verify_data(pgpv_t *pgp, const char *cmd, const char *inname, char *in, ssize_t cc)
|
||||
{
|
||||
pgpv_cursor_t cursor;
|
||||
size_t size;
|
||||
size_t cookie;
|
||||
char *data;
|
||||
|
||||
memset(&cursor, 0x0, sizeof(cursor));
|
||||
if (strcasecmp(cmd, "cat") == 0) {
|
||||
if ((cookie = pgpv_verify(&cursor, pgp, in, cc)) != 0) {
|
||||
if ((size = pgpv_get_verified(&cursor, cookie, &data)) > 0) {
|
||||
printf("%.*s", (int)size, data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} else if (strcasecmp(cmd, "verify") == 0) {
|
||||
if (pgpv_verify(&cursor, pgp, in, cc)) {
|
||||
printf("Good signature for %s made ", inname);
|
||||
ptime(cursor.sigtime);
|
||||
pentry(pgp, ARRAY_ELEMENT(cursor.found, 0));
|
||||
return 1;
|
||||
}
|
||||
warnx("Signature did not match contents -- %s", cursor.why);
|
||||
} else {
|
||||
warnx("unrecognised command \"%s\"", cmd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *keyring;
|
||||
const char *cmd;
|
||||
ssize_t cc;
|
||||
size_t size;
|
||||
pgpv_t pgp;
|
||||
char *in;
|
||||
int ok;
|
||||
int i;
|
||||
|
||||
memset(&pgp, 0x0, sizeof(pgp));
|
||||
cmd = NULL;
|
||||
keyring = NULL;
|
||||
ok = 1;
|
||||
while ((i = getopt(argc, argv, "c:k:")) != -1) {
|
||||
switch(i) {
|
||||
case 'c':
|
||||
cmd = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
keyring = optarg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cmd == NULL) {
|
||||
cmd = "verify";
|
||||
}
|
||||
if (!pgpv_read_pubring(&pgp, keyring, -1)) {
|
||||
errx(EXIT_FAILURE, "can't read keyring");
|
||||
}
|
||||
if (optind == argc) {
|
||||
in = getstdin(&cc, &size);
|
||||
ok = verify_data(&pgp, cmd, "[stdin]", in, cc);
|
||||
} else {
|
||||
for (ok = 1, i = optind ; i < argc ; i++) {
|
||||
if (!verify_data(&pgp, cmd, argv[i], argv[i], -1)) {
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
pgpv_close(&pgp);
|
||||
exit((ok) ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
# $NetBSD: Makefile,v 1.2 2012/11/20 05:26:26 agc Exp $
|
||||
|
||||
LIB=netpgpverify
|
||||
SRCS=libverify.c b64.c pgpsum.c
|
||||
SRCS+=digest.c tiger.c
|
||||
SRCS+=bignum.c misc.c
|
||||
CPPFLAGS+=-I${EXTDIST}/src/libbn
|
||||
CPPFLAGS+=-I${EXTDIST}/src/libdigest
|
||||
CPPFLAGS+=-I${EXTDIST}/src/librsa
|
||||
MAN=libnetpgpverify.3
|
||||
WARNS=5
|
||||
|
||||
EXTDIST=${.CURDIR}/../../dist
|
||||
.PATH: ${EXTDIST}/src/libverify ${EXTDIST}/src/libdigest ${EXTDIST}/src/libbn ${EXTDIST}/src/librsa
|
||||
|
||||
INCS=verify.h
|
||||
INCSDIR=/usr/include/netpgp
|
||||
|
||||
.include <bsd.lib.mk>
|
|
@ -0,0 +1,2 @@
|
|||
major=4
|
||||
minor=0
|
Loading…
Reference in New Issue