Changes to have OpenSSL compile on OS/2.
authorRichard Levitte <levitte@openssl.org>
Sun, 1 Jul 2001 22:39:46 +0000 (22:39 +0000)
committerRichard Levitte <levitte@openssl.org>
Sun, 1 Jul 2001 22:39:46 +0000 (22:39 +0000)
Contributed by "Brian Havard" <brianh@kheldar.apana.org.au>

Configure
INSTALL.OS2 [new file with mode: 0644]
crypto/bio/bss_file.c
crypto/bio/bss_log.c
crypto/o_time.c
crypto/rand/rand_os2.c [new file with mode: 0644]
crypto/rand/rand_unix.c
e_os2.h
os2/OS2-EMX.cmd [new file with mode: 0644]
util/mk1mf.pl
util/pl/OS2-EMX.pl [new file with mode: 0644]

index d852c6b4c4083f2fa2a78d6e9aaaa93cf64e9690..a76f7060d6f61a1c6614f424f4d83c73b1140eb0 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -453,10 +453,13 @@ my %table=(
 ##### GNU Hurd
 "hurd-x86",  "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -m486 -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC",
 
+##### OS/2 EMX
+"OS2-EMX", "gcc::::::::",
+
 );
 
 my @WinTargets=qw(VC-NT VC-WIN32 VC-WIN16 VC-W31-16 VC-W31-32 VC-MSDOS BC-32
-       BC-16 Mingw32);
+       BC-16 Mingw32 OS2-EMX);
 
 my $prefix="";
 my $openssldir="";
diff --git a/INSTALL.OS2 b/INSTALL.OS2
new file mode 100644 (file)
index 0000000..d4cc0e3
--- /dev/null
@@ -0,0 +1,22 @@
+ Installation on OS/2
+ --------------------
+
+ You need to have the following tools installed:
+
+  * EMX GCC
+  * PERL
+  * GNU make
+
+
+ To build the makefile, run
+
+ > os2\os2-emx
+
+ This will configure OpenSSL and create OS2-EMX.mak which you then use to 
+ build the OpenSSL libraries & programs by running
+
+ > make -f os2-emx.mak
+
+ If that finishes successfully you will find the libraries and programs in the
+ "out" directory.
index f31e0a50ee170d97073a6d84493fbcc88972a0e7..0dee7fa34874c7decb755b15c66403d4572f5452 100644 (file)
@@ -210,6 +210,11 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
                        _setmode(fileno((FILE *)ptr),_O_TEXT);
                else
                        _setmode(fileno((FILE *)ptr),_O_BINARY);
+#elif defined(OPENSSL_SYS_OS2)
+               if (num & BIO_FP_TEXT)
+                       setmode(fileno((FILE *)ptr), O_TEXT);
+               else
+                       setmode(fileno((FILE *)ptr), O_BINARY);
 #endif
                break;
        case BIO_C_SET_FILENAME:
index 13fb517c18ee025f86c5e3110690e13bd3b6d527..bdcbf30480d5023567a029b8c38c3f8415184f63 100644 (file)
@@ -77,7 +77,7 @@
 #  include <starlet.h>
 #elif defined(__ultrix)
 #  include <sys/syslog.h>
-#elif !defined(MSDOS) /* Unix */
+#elif !defined(MSDOS) && !defined(NO_SYSLOG) /* Unix */
 #  include <syslog.h>
 #endif
 
index 136ea567b7819d502996df3812a1a3985f3dc6fb..61f30315cf1e3626728c352a0c2fec74068542ff 100644 (file)
@@ -72,7 +72,7 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
        {
        struct tm *ts = NULL;
 
-#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r))
+#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r))
        /* should return &data, but doesn't on some systems,
           so we don't even look at the return value */
        gmtime_r(timer,result);
diff --git a/crypto/rand/rand_os2.c b/crypto/rand/rand_os2.c
new file mode 100644 (file)
index 0000000..c3e36d4
--- /dev/null
@@ -0,0 +1,147 @@
+/* crypto/rand/rand_os2.c */
+/* ====================================================================
+ * Copyright (c) 1998-2000 The OpenSSL Project.  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.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED 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 OpenSSL PROJECT OR
+ * ITS 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 product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "cryptlib.h"
+#include <openssl/rand.h>
+#include "rand_lcl.h"
+
+#ifdef OPENSSL_SYS_OS2
+
+#define INCL_DOSPROCESS
+#define INCL_DOSPROFILE
+#define INCL_DOSMISC
+#define INCL_DOSMODULEMGR
+#include <os2.h>
+
+#define   CMD_KI_RDCNT    (0x63)
+
+typedef struct _CPUUTIL {
+    ULONG ulTimeLow;            /* Low 32 bits of time stamp      */
+    ULONG ulTimeHigh;           /* High 32 bits of time stamp     */
+    ULONG ulIdleLow;            /* Low 32 bits of idle time       */
+    ULONG ulIdleHigh;           /* High 32 bits of idle time      */
+    ULONG ulBusyLow;            /* Low 32 bits of busy time       */
+    ULONG ulBusyHigh;           /* High 32 bits of busy time      */
+    ULONG ulIntrLow;            /* Low 32 bits of interrupt time  */
+    ULONG ulIntrHigh;           /* High 32 bits of interrupt time */
+} CPUUTIL;
+
+APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
+APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
+HMODULE hDoscalls = 0;
+
+int RAND_poll(void)
+{
+    char failed_module[20];
+    QWORD qwTime;
+    ULONG SysVars[QSV_FOREGROUND_PROCESS];
+
+    if (hDoscalls == 0) {
+        ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls);
+
+        if (rc == 0) {
+            rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall);
+
+            if (rc)
+                DosPerfSysCall = NULL;
+
+            rc = DosQueryProcAddr(hDoscalls, 368, NULL, (PFN *)&DosQuerySysState);
+
+            if (rc)
+                DosQuerySysState = NULL;
+        }
+    }
+
+    /* Sample the hi-res timer, runs at around 1.1 MHz */
+    DosTmrQueryTime(&qwTime);
+    RAND_add(&qwTime, sizeof(qwTime), 2);
+
+    /* Sample a bunch of system variables, includes various process & memory statistics */
+    DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
+    RAND_add(SysVars, sizeof(SysVars), 4);
+
+    /* If available, sample CPU registers that count at CPU MHz
+     * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
+     */
+    if (DosPerfSysCall) {
+        CPUUTIL util;
+
+        if (DosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) {
+            RAND_add(&util, sizeof(util), 10);
+        }
+        else {
+            DosPerfSysCall = NULL;
+        }
+    }
+
+    /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
+    if (DosQuerySysState) {
+        char *buffer = OPENSSL_malloc(256 * 1024);
+
+        if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) {
+            /* First 4 bytes in buffer is a pointer to the thread count
+             * there should be at least 1 byte of entropy per thread
+             */
+            RAND_add(buffer, 256 * 1024, **(ULONG **)buffer);
+        }
+
+        OPENSSL_free(buffer);
+        return 1;
+    }
+
+    return 0;
+}
+
+#endif /* OPENSSL_SYS_OS2 */
index c491280b1f0d1137d4a52675af408190409c407e..5a78009e9aa4b9e9bf7cfef164007971ea1b2834 100644 (file)
 #include <openssl/rand.h>
 #include "rand_lcl.h"
 
-#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS))
+#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2))
 
 #include <sys/types.h>
 #include <sys/time.h>
diff --git a/e_os2.h b/e_os2.h
index 5ebd7481ee7260123cb57c64cb3084ccf55aff7c..18b68527afb4600c78e93a407af4115e7fb50929 100644 (file)
--- a/e_os2.h
+++ b/e_os2.h
@@ -136,6 +136,12 @@ extern "C" {
 # endif
 #endif
 
+/* --------------------------------- OS/2 ---------------------------------- */
+#if defined(__EMX__) || defined(__OS2__)
+# undef OPENSSL_SYS_UNIX
+# define OPENSSL_SYS_OS2
+#endif
+
 /* --------------------------------- Unix ---------------------------------- */
 #ifdef OPENSSL_SYS_UNIX
 # if defined(linux) || defined(OPENSSL_SYSNAME_LINUX)
diff --git a/os2/OS2-EMX.cmd b/os2/OS2-EMX.cmd
new file mode 100644 (file)
index 0000000..8b2a092
--- /dev/null
@@ -0,0 +1,61 @@
+@echo off
+
+perl Configure OS2-EMX
+perl util\mkfiles.pl > MINFO
+
+@rem create make file
+perl util\mk1mf.pl OS2-EMX > OS2-EMX.mak
+
+echo Generating x86 for GNU assember
+
+echo Bignum
+cd crypto\bn\asm
+rem perl x86.pl a.out > bn-os2.asm
+perl bn-586.pl a.out > bn-os2.asm 
+perl co-586.pl a.out > co-os2.asm 
+cd ..\..\..
+
+echo DES
+cd crypto\des\asm
+perl des-586.pl a.out > d-os2.asm
+cd ..\..\..
+
+echo crypt(3)
+cd crypto\des\asm
+perl crypt586.pl a.out > y-os2.asm
+cd ..\..\..
+
+echo Blowfish
+cd crypto\bf\asm
+perl bf-586.pl a.out > b-os2.asm
+cd ..\..\..
+
+echo CAST5
+cd crypto\cast\asm
+perl cast-586.pl a.out > c-os2.asm
+cd ..\..\..
+
+echo RC4
+cd crypto\rc4\asm
+perl rc4-586.pl a.out > r4-os2.asm
+cd ..\..\..
+
+echo MD5
+cd crypto\md5\asm
+perl md5-586.pl a.out > m5-os2.asm
+cd ..\..\..
+
+echo SHA1
+cd crypto\sha\asm
+perl sha1-586.pl a.out > s1-os2.asm
+cd ..\..\..
+
+echo RIPEMD160
+cd crypto\ripemd\asm
+perl rmd-586.pl a.out > rm-os2.asm
+cd ..\..\..
+
+echo RC5\32
+cd crypto\rc5\asm
+perl rc5-586.pl a.out > r5-os2.asm
+cd ..\..\..
index e6aa5c45c0dbbe9533dde23d5f39738905c6520d..014c4df0b20bd550ddf636db36216efe56affe62 100755 (executable)
@@ -37,6 +37,7 @@ $infile="MINFO";
        "linux-elf","Linux elf",
        "ultrix-mips","DEC mips ultrix",
        "FreeBSD","FreeBSD distribution",
+       "OS2-EMX", "EMX GCC OS/2",
        "default","cc under unix",
        );
 
@@ -182,6 +183,11 @@ elsif ($platform eq "ultrix-mips")
        require "ultrix.pl";
        $unix=1;
        }
+elsif ($platform eq "OS2-EMX")
+       {
+       $wc=1;
+       require 'OS2-EMX.pl';
+       }
 else
        {
        require "unix.pl";
diff --git a/util/pl/OS2-EMX.pl b/util/pl/OS2-EMX.pl
new file mode 100644 (file)
index 0000000..5718055
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/local/bin/perl
+#
+# OS2-EMX.pl - for EMX GCC on OS/2
+#
+
+$o='\\';
+$cp='copy';
+$rm='rm -f';
+
+# C compiler stuff
+
+$cc='gcc';
+$cflags="-DL_ENDIAN -O3 -fomit-frame-pointer -m486 -Zmt -Wall ";
+
+if ($debug) { 
+       $cflags.="-g "; 
+}
+
+$obj='.o';
+$ofile='-o ';
+
+# EXE linking stuff
+$link='${CC}';
+$lflags='${CFLAGS} -Zbsd-signals';
+$efile='-o ';
+$exep='.exe';
+$ex_libs="-lsocket";
+
+# static library stuff
+$mklib='ar r';
+$mlflags='';
+$ranlib="ar s";
+$plib='lib';
+$libp=".a";
+$shlibp=".a";
+$lfile='';
+
+$asm='as';
+$afile='-o ';
+$bn_asm_obj="";
+$bn_asm_src="";
+$des_enc_obj="";
+$des_enc_src="";
+$bf_enc_obj="";
+$bf_enc_src="";
+
+if (!$no_asm)
+       {
+       $bn_asm_obj='crypto\bn\asm\bn-os2.o crypto\bn\asm\co-os2.o';
+       $bn_asm_src='crypto\bn\asm\bn-os2.asm crypto\bn\asm\co-os2.asm';
+       $des_enc_obj='crypto\des\asm\d-os2.o crypto\des\asm\y-os2.o';
+       $des_enc_src='crypto\des\asm\d-os2.asm crypto\des\asm\y-os2.asm';
+       $bf_enc_obj='crypto\bf\asm\b-os2.o';
+       $bf_enc_src='crypto\bf\asm\b-os2.asm';
+       $cast_enc_obj='crypto\cast\asm\c-os2.o';
+       $cast_enc_src='crypto\cast\asm\c-os2.asm';
+       $rc4_enc_obj='crypto\rc4\asm\r4-os2.o';
+       $rc4_enc_src='crypto\rc4\asm\r4-os2.asm';
+       $rc5_enc_obj='crypto\rc5\asm\r5-os2.o';
+       $rc5_enc_src='crypto\rc5\asm\r5-os2.asm';
+       $md5_asm_obj='crypto\md5\asm\m5-os2.o';
+       $md5_asm_src='crypto\md5\asm\m5-os2.asm';
+       $sha1_asm_obj='crypto\sha\asm\s1-os2.o';
+       $sha1_asm_src='crypto\sha\asm\s1-os2.asm';
+       $rmd160_asm_obj='crypto\ripemd\asm\rm-os2.o';
+       $rmd160_asm_src='crypto\ripemd\asm\rm-os2.asm';
+       }
+
+sub do_lib_rule
+       {
+       local($obj,$target,$name,$shlib)=@_;
+       local($ret,$_,$Name);
+
+       $target =~ s/\//$o/g if $o ne '/';
+       $target="$target";
+       ($Name=$name) =~ tr/a-z/A-Z/;
+
+       $ret.="$target: \$(${Name}OBJ)\n";
+       $ret.="\t\$(RM) $target\n";
+       $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
+       $ret.="\t\$(RANLIB) $target\n\n";
+       }
+
+sub do_link_rule
+       {
+       local($target,$files,$dep_libs,$libs)=@_;
+       local($ret,$_);
+       
+       $file =~ s/\//$o/g if $o ne '/';
+       $n=&bname($target);
+       $ret.="$target: $files $dep_libs\n";
+       $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
+       return($ret);
+       }
+
+1;