From 7a983d569fcebc2d9b9629309ab7efc00da72f6b Mon Sep 17 00:00:00 2001 From: onesecure Date: Wed, 25 May 2016 01:37:02 +0800 Subject: [PATCH 1/4] Qt Project file. --- SMP/config.h | 4 + SMP/gcrypt.pro | 213 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 SMP/gcrypt.pro diff --git a/SMP/config.h b/SMP/config.h index cef65fd7d..3f875555b 100644 --- a/SMP/config.h +++ b/SMP/config.h @@ -507,5 +507,9 @@ properly prefixed. */ #define CAMELLIA_EXT_SYM_PREFIX _gcry_ +#ifdef _MSC_VER +#include "compat.h" +#endif + #endif /*_GCRYPT_CONFIG_H_INCLUDED*/ diff --git a/SMP/gcrypt.pro b/SMP/gcrypt.pro new file mode 100644 index 000000000..bcb489a24 --- /dev/null +++ b/SMP/gcrypt.pro @@ -0,0 +1,213 @@ +TEMPLATE = lib +TARGET = gcrypt +CONFIG += qt warn_off + +DESTDIR = $$PWD/lib + +LIBGPG_ERROR_DIR = ../../libgpg-error/SMP/lib + +LIBS += -L$$LIBGPG_ERROR_DIR -lgpg-error + +INCLUDEPATH += . ../src ./mpi ../mpi ./cipher $$LIBGPG_ERROR_DIR +DEFINES += HAVE_CONFIG_H + +win32 { + LIBS += -lUser32 -lAdvapi32 + DEFINES += __builtin_bswap32=_byteswap_ulong __builtin_bswap64=_byteswap_uint64 asm=__asm__ __i386__ + DEF_FILE = ../src/libgcrypt.def + CONFIG += shared dll #CONFIG += staticlib +} + +HEADERS = \ + ../cipher/bithelp.h \ + ../cipher/bufhelp.h \ + ../cipher/camellia.h \ + ../cipher/cipher-internal.h \ + ../cipher/cipher-selftest.h \ + ../cipher/ecc-common.h \ + ../cipher/gost.h \ + ../cipher/hash-common.h \ + ../cipher/kdf-internal.h \ + ../cipher/keccak_permute_32.h \ + ../cipher/keccak_permute_64.h \ + ../cipher/mac-internal.h \ + ../cipher/poly1305-internal.h \ + ../cipher/pubkey-internal.h \ + ../cipher/rijndael-internal.h \ + ../cipher/rijndael-tables.h \ + ../cipher/sha1.h \ + ../compat/libcompat.h \ + ../mpi/ec-internal.h \ + ../mpi/generic/mpi-asm-defs.h \ + ../mpi/longlong.h \ + ../mpi/mpi-inline.h \ + ../mpi/mpi-internal.h \ + ../random/rand-internal.h \ + ../random/random.h \ + ../src/cipher-proto.h \ + ../src/cipher.h \ + ../src/context.h \ + ../src/ec-context.h \ + ../src/g10lib.h \ + ../src/gcrypt-int.h \ + ../src/hmac256.h \ + ../src/hwf-common.h \ + ../src/mpi.h \ + ../src/secmem.h \ + ../src/stdmem.h \ + ../src/types.h \ + ../src/visibility.h \ + ./config.h \ + ./gcrypt.h \ + ./mpi/asm-syntax.h \ + ./mpi/mod-source-info.h \ + ./mpi/mpi-asm-defs.h \ + ./mpi/sysdep.h \ + ./version.h \ + ./compat.h + +SOURCES = \ + ../cipher/arcfour.c \ + ../cipher/blowfish.c \ + ../cipher/camellia-glue.c \ + ../cipher/camellia.c \ + ../cipher/cast5.c \ + ../cipher/chacha20.c \ + ../cipher/cipher-aeswrap.c \ + ../cipher/cipher-cbc.c \ + ../cipher/cipher-ccm.c \ + ../cipher/cipher-cfb.c \ + ../cipher/cipher-cmac.c \ + ../cipher/cipher-ctr.c \ + ../cipher/cipher-gcm-intel-pclmul.c \ + ../cipher/cipher-gcm.c \ + ../cipher/cipher-ocb.c \ + ../cipher/cipher-ofb.c \ + ../cipher/cipher-poly1305.c \ + ../cipher/cipher-selftest.c \ + ../cipher/cipher.c \ + ../cipher/crc-intel-pclmul.c \ + ../cipher/crc.c \ + ../cipher/des.c \ + ../cipher/dsa-common.c \ + ../cipher/dsa.c \ + ../cipher/ecc-curves.c \ + ../cipher/ecc-ecdsa.c \ + ../cipher/ecc-eddsa.c \ + ../cipher/ecc-gost.c \ + ../cipher/ecc-misc.c \ + ../cipher/ecc.c \ + ../cipher/elgamal.c \ + ../cipher/gost28147.c \ + ../cipher/gostr3411-94.c \ + ../cipher/hash-common.c \ + ../cipher/hmac-tests.c \ + ../cipher/idea.c \ + ../cipher/kdf.c \ + ../cipher/keccak.c \ + ../cipher/mac-cmac.c \ + ../cipher/mac-gmac.c \ + ../cipher/mac-hmac.c \ + ../cipher/mac-poly1305.c \ + ../cipher/mac.c \ + ../cipher/md.c \ + ../cipher/md4.c \ + ../cipher/md5.c \ + ../cipher/poly1305.c \ + ../cipher/primegen.c \ + ../cipher/pubkey-util.c \ + ../cipher/pubkey.c \ + ../cipher/rfc2268.c \ + ../cipher/rijndael-aesni.c \ + ../cipher/rijndael-padlock.c \ + ../cipher/rijndael.c \ + ../cipher/rmd160.c \ + ../cipher/rsa-common.c \ + ../cipher/rsa.c \ + ../cipher/salsa20.c \ + ../cipher/scrypt.c \ + ../cipher/seed.c \ + ../cipher/serpent.c \ + ../cipher/sha1.c \ + ../cipher/sha256.c \ + ../cipher/sha512.c \ + ../cipher/stribog.c \ + ../cipher/tiger.c \ + ../cipher/twofish.c \ + ../cipher/whirlpool.c \ + ../compat/compat.c \ + ../mpi/ec-ed25519.c \ + ../mpi/ec.c \ + ../mpi/generic/mpih-add1.c \ + ../mpi/generic/mpih-lshift.c \ + ../mpi/generic/mpih-mul1.c \ + ../mpi/generic/mpih-mul2.c \ + ../mpi/generic/mpih-mul3.c \ + ../mpi/generic/mpih-rshift.c \ + ../mpi/generic/mpih-sub1.c \ + ../mpi/mpi-add.c \ + ../mpi/mpi-bit.c \ + ../mpi/mpi-cmp.c \ + ../mpi/mpi-div.c \ + ../mpi/mpi-gcd.c \ + ../mpi/mpi-inline.c \ + ../mpi/mpi-inv.c \ + ../mpi/mpi-mod.c \ + ../mpi/mpi-mpow.c \ + ../mpi/mpi-mul.c \ + ../mpi/mpi-pow.c \ + ../mpi/mpi-scan.c \ + ../mpi/mpicoder.c \ + ../mpi/mpih-div.c \ + ../mpi/mpih-mul.c \ + ../mpi/mpiutil.c \ + ../random/random-csprng.c \ + ../random/random-drbg.c \ + ../random/random-system.c \ + ../random/random.c \ + ../random/rndhw.c \ + ../src/context.c \ + ../src/fips.c \ + ../src/global.c \ + ../src/hmac256.c \ + ../src/hwf-x86.c \ + ../src/hwfeatures.c \ + ../src/misc.c \ + ../src/missing-string.c \ + ../src/secmem.c \ + ../src/sexp.c \ + ../src/stdmem.c \ + ../src/visibility.c + +win32 { + HEADERS += \ + + SOURCES += \ + ../cipher/rijndael-ssse3-amd64.c \ + ../random/rndw32.c +} else { + SOURCES += \ + ../random/rndlinux.c +} + +# +# Copies the given files to the destination directory +# http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output +# +defineTest(copyToDestdir) { + files = $$1 + + for(FILE, files) { + DDIR = $$DESTDIR + + # Replace slashes in paths with backslashes for Windows + win32:FILE ~= s,/,\\,g + win32:DDIR ~= s,/,\\,g + + QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t) + } + + export(QMAKE_POST_LINK) +} + +copyToDestdir($$PWD/gcrypt.h) From 10d56722998001f7fd2d04f2d99f3405f40a3025 Mon Sep 17 00:00:00 2001 From: onesecure Date: Wed, 25 May 2016 01:49:15 +0800 Subject: [PATCH 2/4] minor changes. --- .gitignore | 1 + SMP/gcrypt.pro | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3cd83a2cb..18b361299 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.o .deps/ .libs/ +build-*/ po/*.gmo po/messages.mo /aclocal.m4 diff --git a/SMP/gcrypt.pro b/SMP/gcrypt.pro index bcb489a24..efd98f5c0 100644 --- a/SMP/gcrypt.pro +++ b/SMP/gcrypt.pro @@ -2,9 +2,9 @@ TEMPLATE = lib TARGET = gcrypt CONFIG += qt warn_off -DESTDIR = $$PWD/lib +DESTDIR = $$PWD/../../bin -LIBGPG_ERROR_DIR = ../../libgpg-error/SMP/lib +LIBGPG_ERROR_DIR = $$PWD/../../bin LIBS += -L$$LIBGPG_ERROR_DIR -lgpg-error From 68d65f80a60a1cc98bdbbb70a4b582df905a3a8e Mon Sep 17 00:00:00 2001 From: Ralph Shane Date: Thu, 26 May 2016 01:24:11 +0800 Subject: [PATCH 3/4] iOS, Android, MacOSX, adopter. --- .gitignore | 1 + SMP/config.h | 24 +++++++++++++++++++++--- SMP/gcrypt.pro | 23 +++++++++++++++++++---- random/rndunix.c | 4 +++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 18b361299..735d9b1ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.lo *.o +.DS_Store .deps/ .libs/ build-*/ diff --git a/SMP/config.h b/SMP/config.h index 3f875555b..e391903dc 100644 --- a/SMP/config.h +++ b/SMP/config.h @@ -101,8 +101,10 @@ /* Defined for SPARC platforms */ /* #undef HAVE_CPU_ARCH_SPARC */ +#if (defined(__i386__) || defined(__x86_64__)) /* Defined for the x86 platforms */ #define HAVE_CPU_ARCH_X86 1 +#endif /* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you don't. */ @@ -117,9 +119,11 @@ /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ /* #undef HAVE_DOPRNT */ +#if defined(WIN32) /* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) with special properties like no file modes */ #define HAVE_DOSISH_SYSTEM 1 +#endif /* defined if we must run on a stupid file system */ #define HAVE_DRIVE_LETTERS 1 @@ -231,8 +235,10 @@ /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 +#if !defined(WIN32) && !defined(ANDROID) /* Define to 1 if you have the `stpcpy' function. */ -/* #undef HAVE_STPCPY */ +#define HAVE_STPCPY 1 +#endif /* Define to 1 if you have the `strcasecmp' function. */ #define HAVE_STRCASECMP 1 @@ -240,8 +246,10 @@ /* Define to 1 if you have the `strerror' function. */ #define HAVE_STRERROR 1 +#if defined(WIN32) /* Define to 1 if you have the `stricmp' function. */ #define HAVE_STRICMP 1 +#endif /* Define to 1 if you have the header file. */ /* #undef HAVE_STRINGS_H */ @@ -312,8 +320,10 @@ /* Define to 1 if you have the `wait4' function. */ /* #undef HAVE_WAIT4 */ +#if !defined(WIN32) /* Define to 1 if you have the `waitpid' function. */ -/* #undef HAVE_WAITPID */ +#define HAVE_WAITPID 1 +#endif /* Define to 1 if you have the header file. */ #define HAVE_WINSOCK2_H 1 @@ -444,14 +454,22 @@ /* Defined if the EGD based RNG should be used. */ /* #undef USE_RNDEGD */ +#if defined(__linux__) /* Defined if the /dev/random RNG should be used. */ -/* #undef USE_RNDLINUX */ +#define USE_RNDLINUX 1 + +#define NAME_OF_DEV_RANDOM "/dev/random" +#define NAME_OF_DEV_URANDOM "/dev/urandom" + +#endif /* Defined if the default Unix RNG should be used. */ /* #undef USE_RNDUNIX */ +#if defined(WIN32) /* Defined if the Windows specific RNG should be used. */ #define USE_RNDW32 1 +#endif /* Defined if the WindowsCE specific RNG should be used. */ /* #undef USE_RNDW32CE */ diff --git a/SMP/gcrypt.pro b/SMP/gcrypt.pro index efd98f5c0..008a46020 100644 --- a/SMP/gcrypt.pro +++ b/SMP/gcrypt.pro @@ -1,6 +1,8 @@ TEMPLATE = lib TARGET = gcrypt -CONFIG += qt warn_off +CONFIG += warn_off + +message("App Binary architecture: $$QT_ARCH") DESTDIR = $$PWD/../../bin @@ -15,7 +17,9 @@ win32 { LIBS += -lUser32 -lAdvapi32 DEFINES += __builtin_bswap32=_byteswap_ulong __builtin_bswap64=_byteswap_uint64 asm=__asm__ __i386__ DEF_FILE = ../src/libgcrypt.def - CONFIG += shared dll #CONFIG += staticlib + CONFIG += shared dll +} else { + CONFIG += staticlib } HEADERS = \ @@ -170,7 +174,6 @@ SOURCES = \ ../src/fips.c \ ../src/global.c \ ../src/hmac256.c \ - ../src/hwf-x86.c \ ../src/hwfeatures.c \ ../src/misc.c \ ../src/missing-string.c \ @@ -185,11 +188,23 @@ win32 { SOURCES += \ ../cipher/rijndael-ssse3-amd64.c \ ../random/rndw32.c -} else { +} + +linux { SOURCES += \ ../random/rndlinux.c } +unix { + SOURCES += \ + ../random/rndunix.c \ + ../random/random-fips.c +} + +equals(QT_ARCH, "i386") | equals(QT_ARCH, "x86_64") { + SOURCES += ../src/hwf-x86.c +} + # # Copies the given files to the destination directory # http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output diff --git a/random/rndunix.c b/random/rndunix.c index 2e1329852..24cbfe3e4 100644 --- a/random/rndunix.c +++ b/random/rndunix.c @@ -117,9 +117,11 @@ #include #endif /* _AIX */ #ifndef __QNX__ -#include #include +#if !defined(ANDROID) +#include #include +#endif #endif /* __QNX__ */ #include #include /* Verschiedene komische Typen */ From c1b0ab428473925df02035dbe0eb755ed7ad5494 Mon Sep 17 00:00:00 2001 From: Ralph Shane Date: Thu, 26 May 2016 11:44:19 +0800 Subject: [PATCH 4/4] random lock initialize issue. --- random/random-csprng.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/random/random-csprng.c b/random/random-csprng.c index a0bfc783b..a9ab23ba9 100644 --- a/random/random-csprng.c +++ b/random/random-csprng.c @@ -249,7 +249,7 @@ static void read_random_source (enum random_origins origin, static void initialize_basics(void) { - static int initialized; + static int initialized = 0; if (!initialized) { @@ -264,6 +264,10 @@ initialize_basics(void) gcry_assert (GCRY_WEAK_RANDOM == 0 && GCRY_STRONG_RANDOM == 1 && GCRY_VERY_STRONG_RANDOM == 2); + + int err = gpgrt_lock_init(&pool_lock); + if (err) + log_fatal ("failed to initialize the pool lock: %s\n", gpg_strerror (err)); } }