fixed libtools portability bug, fixed arc4random() portability,

fixed htobe32 and be32toh portability, fixed error handling in main(),
fixed invalid type parameter for randomart image in pcppubkey_printshortinfo(),
fixed configure search for libsodium.
This commit is contained in:
TLINDEN
2013-10-29 22:14:34 +01:00
parent f029d9fec4
commit 08ce1c1b8e
20 changed files with 1354 additions and 675 deletions

View File

@@ -2,7 +2,7 @@ AM_CFLAGS = -I../libpcp -Wall -g
lib_LTLIBRARIES = libpcp1.la
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c warn.c \
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \
z85.c zmq_z85.c key.c randomart.c \
vault.c fatal.c jenhash.c digital_crc32.c \
crypto.c

View File

@@ -97,7 +97,7 @@ am__uninstall_files_from_dir = { \
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libpcp1_la_LIBADD =
am_libpcp1_la_OBJECTS = mac.lo mem.lo pad.lo version.lo warn.lo z85.lo \
am_libpcp1_la_OBJECTS = mac.lo mem.lo pad.lo version.lo z85.lo \
zmq_z85.lo key.lo randomart.lo vault.lo fatal.lo jenhash.lo \
digital_crc32.lo crypto.lo
libpcp1_la_OBJECTS = $(am_libpcp1_la_OBJECTS)
@@ -240,7 +240,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AM_CFLAGS = -I../libpcp -Wall -g
lib_LTLIBRARIES = libpcp1.la
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c warn.c \
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \
z85.c zmq_z85.c key.c randomart.c \
vault.c fatal.c jenhash.c digital_crc32.c \
crypto.c
@@ -350,7 +350,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/randomart.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vault.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/version.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/warn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/z85.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zmq_z85.Plo@am__quote@

View File

@@ -3,9 +3,18 @@
/* Define to 1 if you have the `arc4random_buf' function. */
#undef HAVE_ARC4RANDOM_BUF
/* Define to 1 if you have the `be32toh' function. */
#undef HAVE_BE32TOH
/* Define to 1 if you have the `bzero' function. */
#undef HAVE_BZERO
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <endian.h> header file. */
#undef HAVE_ENDIAN_H
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
@@ -36,6 +45,9 @@
/* Define to 1 if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H
/* Define to 1 if you have the `htobe32' function. */
#undef HAVE_HTOBE32
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
@@ -93,6 +105,9 @@
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL
/* Define to 1 if you have the <sys/endian.h> header file. */
#undef HAVE_SYS_ENDIAN_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H

View File

@@ -9,9 +9,9 @@ extern "C" {
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/endian.h> // FIXME: put portable thing from scrypt here
#include "defines.h"
#include "platform.h"
#include "mem.h"
#include "mac.h"
#include "randomart.h"

View File

@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <errno.h>
#include <err.h>
#include "platform.h"
// simple malloc() wrapper
// behaves like calloc(), which

View File

@@ -9,5 +9,71 @@
#error Need either CONFIG_H_FILE or HAVE_CONFIG_H defined.
#endif
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#else
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#else
#ifdef HAVE_BETOH32
// openbsd, use aliases
#define be32toh betoh32
#define htobe32 hto32be
#else
#if __BYTE_ORDER == __BIG_ENDIAN
// Copyright (c) 1999 Joseph Samuel Myers. bsd-games
#define be32toh(x) ((void)0)
#define htobe32(x) ((void)0)
#else
#define be32toh(x) ((u_int32_t)ntohl((u_int32_t)(x)))
#define htobe32(x) ((u_int32_t)htonl((u_int32_t)(x)))
#endif
#endif // HAVE_BETOH32
#endif // HAVE_SYS_ENDIAN_H
#endif // HAVE_ENDIAN_H
#ifndef HAVE_ARC4RANDOM_BUF
// shitty OS. we've got to use other stuff
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
static inline FILE *__getranddev() {
FILE *R;
if((R = fopen("/dev/urandom", "rb")) == NULL) {
// not even this is here! what a shame
if((R = fopen("/dev/random", "rb")) == NULL) {
// not available or depleted. that's too bad
fprintf(stderr, "ERROR: /dev/urandom not available, /dev/random is depleted.\n");
fprintf(stderr, "That's horrible for you but a nightmare for me. I die. Bye.\n");
exit(2);
}
}
return R;
}
static inline u_int32_t arc4random() {
uint32_t x;
FILE *R = __getranddev();
fread(&x, sizeof(uint32_t), 1, R);
fclose(R);
return x;
}
static inline void arc4random_buf(void *buf, size_t nbytes) {
FILE *R = __getranddev();
fread(buf, nbytes, 1, R);
fclose(R);
}
#endif
#endif /* !_HAVE_PCP_PLATFORM_H */

View File

@@ -1,140 +0,0 @@
/*-
* Copyright 2007-2009 Colin Percival
* 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 AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file was originally written by Colin Percival as part of the Tarsnap
* online backup system.
*/
#ifndef _SYSENDIAN_H_
#define _SYSENDIAN_H_
#include "platform.h"
/* If we don't have be64enc, the <sys/endian.h> we have isn't usable. */
#if !HAVE_DECL_BE64ENC
#undef HAVE_SYS_ENDIAN_H
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#else
#include <stdint.h>
static inline uint32_t
be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
static inline void
be32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
static inline uint64_t
be64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
}
static inline void
be64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;
p[7] = x & 0xff;
p[6] = (x >> 8) & 0xff;
p[5] = (x >> 16) & 0xff;
p[4] = (x >> 24) & 0xff;
p[3] = (x >> 32) & 0xff;
p[2] = (x >> 40) & 0xff;
p[1] = (x >> 48) & 0xff;
p[0] = (x >> 56) & 0xff;
}
static inline uint32_t
le32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
}
static inline void
le32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
p[0] = x & 0xff;
p[1] = (x >> 8) & 0xff;
p[2] = (x >> 16) & 0xff;
p[3] = (x >> 24) & 0xff;
}
static inline uint64_t
le64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
}
static inline void
le64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;
p[0] = x & 0xff;
p[1] = (x >> 8) & 0xff;
p[2] = (x >> 16) & 0xff;
p[3] = (x >> 24) & 0xff;
p[4] = (x >> 32) & 0xff;
p[5] = (x >> 40) & 0xff;
p[6] = (x >> 48) & 0xff;
p[7] = (x >> 56) & 0xff;
}
#endif /* !HAVE_SYS_ENDIAN_H */
#endif /* !_SYSENDIAN_H_ */

View File

@@ -8,6 +8,7 @@
#include <unistd.h>
#include "defines.h"
#include "platform.h"
#include "mem.h"
#include "key.h"
#include "uthash.h"

View File

@@ -1,75 +0,0 @@
/*-
* Copyright 2009 Colin Percival
* 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 AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file was originally written by Colin Percival as part of the Tarsnap
* online backup system.
*/
#include "platform.h"
#ifdef HAVE_ERR_H
/*
* Everything is provided through err.h and the associated library, so we
* don't need to do anything here.
*/
#else
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "warn.h"
const char * warn_progname = "(null)";
void
warn(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "%s", warn_progname);
if (fmt != NULL) {
fprintf(stderr, ": ");
vfprintf(stderr, fmt, ap);
}
fprintf(stderr, ": %s\n", strerror(errno));
va_end(ap);
}
void
warnx(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "%s", warn_progname);
if (fmt != NULL) {
fprintf(stderr, ": ");
vfprintf(stderr, fmt, ap);
}
fprintf(stderr, "\n");
va_end(ap);
}
#endif

View File

@@ -1,13 +0,0 @@
#ifndef _HAVE_PCP_WARN_H
#define _HAVE_PCP_WARN_H
#ifdef HAVE_ERR_H
#include <err.h>
#else
#define NEED_WARN_PROGNAME
const char * warn_progname;
void warn(const char *, ...);
void warnx(const char *, ...);
#endif
#endif /* !_HAVE_WARN_H */