diff options
Diffstat (limited to 'security/nss/lib/fortcrypt/swfort/pkcs11')
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/.cvsignore | 15 | ||||
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/Makefile | 179 | ||||
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/config.mk | 43 | ||||
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/inst.js | 189 | ||||
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/manifest.mn | 63 | ||||
-rwxr-xr-x | security/nss/lib/fortcrypt/swfort/pkcs11/pk11inst | 49 | ||||
-rw-r--r-- | security/nss/lib/fortcrypt/swfort/pkcs11/stub.c | 350 |
7 files changed, 888 insertions, 0 deletions
diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/.cvsignore b/security/nss/lib/fortcrypt/swfort/pkcs11/.cvsignore new file mode 100644 index 000000000..6532d294d --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/.cvsignore @@ -0,0 +1,15 @@ +forsock.c +cryptint.h +fmutex.h +fortsock.h +fpkcs11.h +fpkcs11f.h +fpkcs11i.h +fpkcs11t.h +fpkmem.h +fpkstrs.h +genci.h +maci.h +fortpk11.c +fmutex.c + diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/Makefile b/security/nss/lib/fortcrypt/swfort/pkcs11/Makefile new file mode 100644 index 000000000..00c911bc6 --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/Makefile @@ -0,0 +1,179 @@ +#! gmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Netscape security libraries. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1994-2000 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. If you wish to allow use of your +# version of this file only under the terms of the GPL and not to +# allow others to use your version of this file under the MPL, +# indicate your decision by deleting the provisions above and +# replace them with the notice and other provisions required by +# the GPL. If you do not delete the provisions above, a recipient +# may use your version of this file under either the MPL or the +# GPL. +# + +include manifest.mn +include $(CORE_DEPTH)/coreconf/config.mk +include config.mk + + +#SWCILIB = ../$(OBJDIR)/$(LIB_PREFIX)swfci.$(LIB_SUFFIX) +# can't do this in manifest.mn because OS_ARCH isn't defined there. +ifeq ($(OS_ARCH), WINNT) + +CRYPTO_LIB = $(DIST)/lib/freebl.lib + +ifdef MOZILLA_SECURITY_BUILD +CRYPTO_LIB = $(DIST)/lib/crypto.lib +endif +ifdef MOZILLA_BSAFE_BUILD +CRYPTO_LIB += $(DIST)/lib/bsafe$(BSAFEVER).lib +CRYPTO_LIB += $(DIST)/lib/freebl.lib +endif + +# $(DIST)/lib/dbm.lib +# $(DIST)/lib/$(NSPR31_LIB_PREFIX)nspr4.lib +EXTRA_LIBS = \ + $(DIST)/lib/swfci.lib \ + $(DIST)/lib/softoken.lib \ + $(CRYPTO_LIB) \ + $(DIST)/lib/secutil.lib \ + $(DIST)/lib/$(NSPR31_LIB_PREFIX)plc4_s.lib \ + $(DIST)/lib/$(NSPR31_LIB_PREFIX)plds4_s.lib \ + wsock32.lib \ + winmm.lib \ + $(NULL) + +else + +# $(DIST)/lib/libdbm.a +# $(DIST)/lib/libnspr3.a +# +CRYPTO_LIB = $(DIST)/lib/libfreebl.$(LIB_SUFFIX) + +ifdef MOZILLA_SECURITY_BUILD +CRYPTO_LIB = $(DIST)/lib/libcrypto.$(LIB_SUFFIX) +endif +ifdef MOZILLA_BSAFE_BUILD +CRYPTO_LIB += $(DIST)/lib/libbsafe.$(LIB_SUFFIX) +CRYPTO_LIB += $(DIST)/lib/libfreebl.$(LIB_SUFFIX) +endif + +ifeq ($(OS_ARCH), OS2) +PLC_STATIC_LIB = $(DIST)/lib/plc4.$(LIB_SUFFIX) +PLDS_STATIC_LIB = $(DIST)/lib/plds4.$(LIB_SUFFIX) +else +PLC_STATIC_LIB = $(DIST)/lib/libplc4.$(LIB_SUFFIX) +PLDS_STATIC_LIB = $(DIST)/lib/libplds4.$(LIB_SUFFIX) +endif + +EXTRA_LIBS += \ + $(DIST)/lib/libswfci.$(LIB_SUFFIX) \ + $(DIST)/lib/libsoftoken.$(LIB_SUFFIX) \ + $(CRYPTO_LIB) \ + $(DIST)/lib/libsecutil.$(LIB_SUFFIX) \ + $(PLC_STATIC_LIB) \ + $(PLDS_STATIC_LIB) \ + $(NULL) + +endif + +#ifeq ($(OS_TARGET), WIN16) +#W16LIBS += $(SWCILIB) +#else +#OBJS += $(SWCILIB) +#endif + +INST_JS = inst.js +LIBCI_JAR = $(OBJDIR)/lib$(LIBRARY_NAME).jar +LIBCI_JAR_SRC = $(INST_JS) pk11inst $(SHARED_LIBRARY) + +ifneq ($(OS_TARGET), WIN16) +TARGETS : $(LIBCI_JAR) +endif + +ifeq ($(OS_TARGET), WIN16) +# note that rules.mk is not included below for WIN16 +all: + @echo Skipping fortcrypt directory for 16-bit windows builds + +all_platforms alltags clean clobber clobber_all realclean: all + +boot export install libs program release: all + +endif + +#$(SHARED_LIBRARY): $(SWCILIB) + +# +# The following rules packages the shared library into a JAR, +# ready to be signed +# +$(OBJDIR)/replace: replace.c + $(CC) -o $@ $< + +# ZIP options: +# -5 means medium compression +# -q means quiet +# -j means do not store tree structure, all files go into one dir +# +$(LIBCI_JAR): $(LIBCI_JAR_SRC) + @echo +++ building $@ from $(LIBCI_JAR_SRC) + @rm -f $@ + zip -5qj $@ $(LIBCI_JAR_SRC) + +$(LIBSWCI_JAR): $(LIBSWCI_JAR_SRC) + @echo +++ building $@ from $(LIBSWCI_JAR_SRC) + @rm -f $@ + zip -5qj $@ $(LIBSWCI_JAR_SRC) + + +MD_FILES += $(LIBCI_JAR) $(LIBSWCI_JAR) + +# coreconf doesn't build the AIX shared library for FORTEZZA, +# so I'm going to override their shared library command and build the shared +# library the way config used to. +# + + +ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1) +DSO_LDOPTS = -bM:SRE -bh:4 -bnoentry +EXTRA_DSO_LDOPTS = -lc +MKSHLIB = xlC $(DSO_LDOPTS) + +$(SHARED_LIBRARY): $(OBJS) + @$(MAKE_OBJDIR) + rm -f $@ + $(MKSHLIB) -o $@ $(OBJS) $(EXTRA_LIBS) $(EXTRA_DSO_LDOPTS) + chmod +x $@ + +endif + +ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.2) +LD += -G +endif + +ifneq ($(OS_TARGET), WIN16) +include $(CORE_DEPTH)/coreconf/rules.mk +endif + diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/config.mk b/security/nss/lib/fortcrypt/swfort/pkcs11/config.mk new file mode 100644 index 000000000..960774691 --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/config.mk @@ -0,0 +1,43 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Netscape security libraries. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1994-2000 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. If you wish to allow use of your +# version of this file only under the terms of the GPL and not to +# allow others to use your version of this file under the MPL, +# indicate your decision by deleting the provisions above and +# replace them with the notice and other provisions required by +# the GPL. If you do not delete the provisions above, a recipient +# may use your version of this file under either the MPL or the +# GPL. +# + +# +# Override TARGETS variable so that only shared libraries +# are specifed as dependencies within rules.mk. +# + +TARGETS = $(SHARED_LIBRARY) $(SHARED_SW_LIBRARY) $(LIBCI_JAR) $(LIBCI_SW_JAR) +LIBRARY = +IMPORT_LIBRARY = +PROGRAM = + diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/inst.js b/security/nss/lib/fortcrypt/swfort/pkcs11/inst.js new file mode 100644 index 000000000..2f7574717 --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/inst.js @@ -0,0 +1,189 @@ +// +// The contents of this file are subject to the Mozilla Public +// License Version 1.1 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of +// the License at http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS +// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +// implied. See the License for the specific language governing +// rights and limitations under the License. +// +// The Original Code is the Netscape security libraries. +// +// The Initial Developer of the Original Code is Netscape +// Communications Corporation. Portions created by Netscape are +// Copyright (C) 1994-2000 Netscape Communications Corporation. All +// Rights Reserved. +// +// Contributor(s): +// +// Alternatively, the contents of this file may be used under the +// terms of the GNU General Public License Version 2 or later (the +// "GPL"), in which case the provisions of the GPL are applicable +// instead of those above. If you wish to allow use of your +// version of this file only under the terms of the GPL and not to +// allow others to use your version of this file under the MPL, +// indicate your decision by deleting the provisions above and +// replace them with the notice and other provisions required by +// the GPL. If you do not delete the provisions above, a recipient +// may use your version of this file under either the MPL or the +// GPL. +// +//////////////////////////////////////////////////////////////////////////////////////// +// Crypto Mechanism Flags +PKCS11_MECH_RSA_FLAG = 0x1<<0; +PKCS11_MECH_DSA_FLAG = 0x1<<1; +PKCS11_MECH_RC2_FLAG = 0x1<<2; +PKCS11_MECH_RC4_FLAG = 0x1<<3; +PKCS11_MECH_DES_FLAG = 0x1<<4; +PKCS11_MECH_DH_FLAG = 0x1<<5; //Diffie-Hellman +PKCS11_MECH_SKIPJACK_FLAG = 0x1<<6; //SKIPJACK algorithm as in Fortezza cards +PKCS11_MECH_RC5_FLAG = 0x1<<7; +PKCS11_MECH_SHA1_FLAG = 0x1<<8; +PKCS11_MECH_MD5_FLAG = 0x1<<9; +PKCS11_MECH_MD2_FLAG = 0x1<<10; +PKCS11_MECH_RANDOM_FLAG = 0x1<<27; //Random number generator +PKCS11_PUB_READABLE_CERT_FLAG = 0x1<<28; //Stored certs can be read off the token w/o logging in +PKCS11_DISABLE_FLAG = 0x1<<30; //tell Navigator to disable this slot by default + +// Important: +// 0x1<<11, 0x1<<12, ... , 0x1<<26, 0x1<<29, and 0x1<<31 are reserved +// for internal use in Navigator. +// Therefore, these bits should always be set to 0; otherwise, +// Navigator might exhibit unpredictable behavior. + +// These flags indicate which mechanisms should be turned on by +var pkcs11MechanismFlags = 0; + +//////////////////////////////////////////////////////////////////////////////////////// +// Ciphers that support SSL or S/MIME +PKCS11_CIPHER_FORTEZZA_FLAG = 0x1<<0; + +// Important: +// 0x1<<1, 0x1<<2, ... , 0x1<<31 are reserved +// for internal use in Navigator. +// Therefore, these bits should ALWAYS be set to 0; otherwise, +// Navigator might exhibit unpredictable behavior. + +// These flags indicate which SSL ciphers are supported +var pkcs11CipherFlags = PKCS11_CIPHER_FORTEZZA_FLAG; + +//////////////////////////////////////////////////////////////////////////////////////// +// Return values of pkcs11.addmodule() & pkcs11.delmodule() +// success codes +JS_OK_ADD_MODULE = 3; // Successfully added a module +JS_OK_DEL_EXTERNAL_MODULE = 2; // Successfully deleted ext. module +JS_OK_DEL_INTERNAL_MODULE = 1; // Successfully deleted int. module + +// failure codes +JS_ERR_OTHER = -1; // Other errors than the followings +JS_ERR_USER_CANCEL_ACTION = -2; // User abort an action +JS_ERR_INCORRECT_NUM_OF_ARGUMENTS= -3; // Calling a method w/ incorrect # of arguments +JS_ERR_DEL_MODULE = -4; // Error deleting a module +JS_ERR_ADD_MODULE = -5; // Error adding a module +JS_ERR_BAD_MODULE_NAME = -6; // The module name is invalid +JS_ERR_BAD_DLL_NAME = -7; // The DLL name is bad +JS_ERR_BAD_MECHANISM_FLAGS = -8; // The mechanism flags are invalid +JS_ERR_BAD_CIPHER_ENABLE_FLAGS = -9; // The SSL, S/MIME cipher flags are invalid + + +//////////////////////////////////////////////////////////////////////////////////////// +// Find out which library is to be installed depending on the platform + +// pathname seperator is platform specific +var sep = "/"; +var vendor = "netscape"; +var moduleName = "not_supported"; + +// platform-independent relative path +var dir = "pkcs11/" + vendor + "/"; + +var plat = navigator.platform; + +bAbort = false; +progName = "instinit"; +if (plat == "Win32") { + moduleName = "swft32.dll"; + // progName = "instinit.exe"; + sep = "\\"; +} else if (plat == "AIX4.1") { + moduleName = "libswft.so"; +} else if (plat == "SunOS4.1.3_U1") { + moduleName = "libswft.so.1.0"; +} else if ((plat == "SunOS5.4") || (plat == "SunOS5.5.1")){ + moduleName = "libswft.so"; +} else if ((plat == "HP-UXA.09") || (plat == "HP-UXB.10")){ + moduleName = "libswft.sl"; +} else { + window.alert("Sorry, platform "+plat+" is not supported."); + bAbort = true; +} + +//////////////////////////////////////////////////////////////////////////////////////// +// Installation Begins... +if (!bAbort) { +if (confirm("This script will install and configure a security module, do you want to continue?")) { + // Step 1. Create a version object and a software update object + vi = new netscape.softupdate.VersionInfo(1, 5, 0, 0); + su = new netscape.softupdate.SoftwareUpdate(this, "Fortezza Card PKCS#11 Module"); + // "Fortezza ... Module" is the logical name of the bundle + + //////////////////////////////////////// + // Step 2. Start the install process + bAbort = false; + err = su.StartInstall("NSfortezza", // NSfortezza is the component folder (logical) + vi, + netscape.softupdate.SoftwareUpdate.FULL_INSTALL); + + bAbort = bAbort || (err !=0); + + if (err == 0) { + //////////////////////////////////////// + // Step 3. Find out the physical location of the Program dir + Folder = su.GetFolder("Program"); + + //////////////////////////////////////// + // Step 4. Install the files. Unpack them and list where they go + err = su.AddSubcomponent("FortezzaLibrary", //component name (logical) + vi, // version info + moduleName, // source file in JAR (physical) + Folder, // target folder (physical) + dir + moduleName, // target path & filename (physical) + this.force); // forces update + bAbort = bAbort || (err !=0); + if (err != 0) window.alert("Add sub err= "+ err); + } + + if (err == 0) { + /// Try installing the init program + err = su.AddSubcomponent("FortezzaInitProg", vi, progName, Folder, progName, this.force); + // don't fail because it didn't install, may just not be part of the package +} + + //////////////////////////////////////// + // Step 5. Unless there was a problem, move files to final location + // and update the Client Version Registry + if (bAbort) { + window.alert("Aborting, Folder="+Folder+" module="+dir+moduleName); + su.AbortInstall(); + } else { + err = su.FinalizeInstall(); + // Platform specific full path + fullpath = Folder + "pkcs11" + sep + vendor + sep + moduleName; + + //////////////////////////////////////// + // Step 6: Call pkcs11.addmodule() to register the newly downloaded module + result = pkcs11.addmodule("Netscape Software FORTEZZA Module", + fullpath, + pkcs11MechanismFlags, + pkcs11CipherFlags); + + if ( result < 0) { + window.alert("New module setup failed. Error code: " + result); + } else { + window.alert("New module setup completed."); + } + } +} +} diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/manifest.mn b/security/nss/lib/fortcrypt/swfort/pkcs11/manifest.mn new file mode 100644 index 000000000..7ef8c2009 --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/manifest.mn @@ -0,0 +1,63 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Netscape security libraries. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1994-2000 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. If you wish to allow use of your +# version of this file only under the terms of the GPL and not to +# allow others to use your version of this file under the MPL, +# indicate your decision by deleting the provisions above and +# replace them with the notice and other provisions required by +# the GPL. If you do not delete the provisions above, a recipient +# may use your version of this file under either the MPL or the +# GPL. +# + +CORE_DEPTH = ../../../../.. + +MODULE = security +LIBRARY_NAME = swft +#LIBRARY_VERSION = 32 + +COPIED_CSRCS = forsock.c \ + fortpk11.c \ + fmutex.c \ + $(NULL) + +CSRCS = \ + $(COPIED_CSRCS) \ + stub.c \ + $(NULL) + +vpath %.c ../../ +INCLUDES = -I../.. + +EXPORTS = + +REQUIRES = security dbm + + +DEFINES = -DSWFORT + +GARBAGE = $(COPIED_CSRCS) cryptint.h fmutex.h fortsock.h fpkcs11.h \ + fpkcs11f.h fpkcs11i.h fpkcs11t.h fpkmem.h fpkstrs.h genci.h maci.h + + diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/pk11inst b/security/nss/lib/fortcrypt/swfort/pkcs11/pk11inst new file mode 100755 index 000000000..31d73eb4a --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/pk11inst @@ -0,0 +1,49 @@ +ForwardCompatible { HPUX:10:hppa1.1 Solaris:5.5.1:sparc AIX:4.1:rs6000 } + Platforms { + WINNT::x86 { + ModuleName { "Netscape Software FORTEZZA Module" } + ModuleFile { %root%/pkcs11/netscape/swft32.dll } + DefaultMechanismFlags{0x0000} + DefaultCipherFlags{0x0001} + Files { + swft32.dll { + RelativePath { %root%/pkcs11/netscape/swft32.dll } + } + } + WIN95::x86 { + EquivalentPlatform {WINNT::x86} + } + Solaris:5.5.1:sparc { + ModuleName { "Netscape Software FORTEZZA Module" } + ModuleFile { %root%/pkcs11/netscape/libswft.so } + DefaultMechanismFlags{0x0000} + DefaultCipherFlags{0x0001} + Files { + libswft.so { + RelativePath { %root%/pkcs11/netscape/libswft.so } + } + } + } + AIX:4.1:rs6000 { + ModuleName { "Netscape Software FORTEZZA Module" } + ModuleFile { %root%/pkcs11/netscape/libswft.so } + DefaultMechanismFlags{0x0000} + DefaultCipherFlags{0x0001} + Files { + libswft.so { + RelativePath { %root%/pkcs11/netscape/libswft.so } + } + } + } + HPUX:10:hppa1.1 { + ModuleName { "Netscape Software FORTEZZA Module" } + ModuleFile { %root%/pkcs11/netscape/libswft.sl } + DefaultMechanismFlags{0x0000} + DefaultCipherFlags{0x0001} + Files { + libswft.so { + RelativePath { %root%/pkcs11/netscape/libswft.sl } + } + } + } + } diff --git a/security/nss/lib/fortcrypt/swfort/pkcs11/stub.c b/security/nss/lib/fortcrypt/swfort/pkcs11/stub.c new file mode 100644 index 000000000..3767547f8 --- /dev/null +++ b/security/nss/lib/fortcrypt/swfort/pkcs11/stub.c @@ -0,0 +1,350 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the Netscape security libraries. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1994-2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License Version 2 or later (the + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. If you wish to allow use of your + * version of this file only under the terms of the GPL and not to + * allow others to use your version of this file under the MPL, + * indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by + * the GPL. If you do not delete the provisions above, a recipient + * may use your version of this file under either the MPL or the + * GPL. + */ +/* + * secport.c - portability interfaces for security libraries + * + * This file abstracts out libc functionality that libsec depends on + * + * NOTE - These are not public interfaces. These stubs are to allow the + * SW FORTEZZA to link with some low level security functions without dragging + * in NSPR. + * + * $Id$ + */ + +#include "seccomon.h" +#include "prmem.h" +#include "prerror.h" +#include "plarena.h" +#include "secerr.h" +#include "prmon.h" +#include "prbit.h" + +unsigned long port_allocFailures; + +/* locations for registering Unicode conversion functions. + * Is this the appropriate location? or should they be + * moved to client/server specific locations? + */ +PORTCharConversionFunc ucs4Utf8ConvertFunc; +PORTCharConversionFunc ucs2Utf8ConvertFunc; +PORTCharConversionWSwapFunc ucs2AsciiConvertFunc; + +void * +PORT_Alloc(size_t bytes) +{ + void *rv; + + /* Always allocate a non-zero amount of bytes */ + rv = (void *)malloc(bytes ? bytes : 1); + if (!rv) { + ++port_allocFailures; + } + return rv; +} + +void * +PORT_Realloc(void *oldptr, size_t bytes) +{ + void *rv; + + rv = (void *)realloc(oldptr, bytes); + if (!rv) { + ++port_allocFailures; + } + return rv; +} + +void * +PORT_ZAlloc(size_t bytes) +{ + void *rv; + + /* Always allocate a non-zero amount of bytes */ + rv = (void *)calloc(1, bytes ? bytes : 1); + if (!rv) { + ++port_allocFailures; + } + return rv; +} + +void +PORT_Free(void *ptr) +{ + if (ptr) { + free(ptr); + } +} + +void +PORT_ZFree(void *ptr, size_t len) +{ + if (ptr) { + memset(ptr, 0, len); + free(ptr); + } +} + +void +PORT_SetError(int value) +{ + return; +} + +int +PORT_GetError(void) +{ + return(1); +} + +/********************* Arena code follows *****************************/ + + +PLArenaPool * +PORT_NewArena(unsigned long chunksize) +{ + PLArenaPool *arena; + + arena = (PLArenaPool*)PORT_ZAlloc(sizeof(PLArenaPool)); + if ( arena != NULL ) { + PR_InitArenaPool(arena, "security", chunksize, sizeof(double)); + } + return(arena); +} + +void * +PORT_ArenaAlloc(PLArenaPool *arena, size_t size) +{ + void *p; + + PL_ARENA_ALLOCATE(p, arena, size); + if (p == NULL) { + ++port_allocFailures; + } + + return(p); +} + +void * +PORT_ArenaZAlloc(PLArenaPool *arena, size_t size) +{ + void *p; + + PL_ARENA_ALLOCATE(p, arena, size); + if (p == NULL) { + ++port_allocFailures; + } else { + PORT_Memset(p, 0, size); + } + + return(p); +} + +/* need to zeroize!! */ +void +PORT_FreeArena(PLArenaPool *arena, PRBool zero) +{ + PR_FinishArenaPool(arena); + PORT_Free(arena); +} + +void * +PORT_ArenaGrow(PLArenaPool *arena, void *ptr, size_t oldsize, size_t newsize) +{ + PORT_Assert(newsize >= oldsize); + + PL_ARENA_GROW(ptr, arena, oldsize, ( newsize - oldsize ) ); + + return(ptr); +} + +void * +PORT_ArenaMark(PLArenaPool *arena) +{ + void * result; + + result = PL_ARENA_MARK(arena); + return result; +} + +void +PORT_ArenaRelease(PLArenaPool *arena, void *mark) +{ + PL_ARENA_RELEASE(arena, mark); +} + +void +PORT_ArenaUnmark(PLArenaPool *arena, void *mark) +{ + /* do nothing */ +} + +char * +PORT_ArenaStrdup(PLArenaPool *arena,char *str) { + int len = PORT_Strlen(str)+1; + char *newstr; + + newstr = (char*)PORT_ArenaAlloc(arena,len); + if (newstr) { + PORT_Memcpy(newstr,str,len); + } + return newstr; +} + +PR_IMPLEMENT(void) +PR_Assert(const char *expr, const char *file, int line) { + return; +} + +PR_IMPLEMENT(void *) +PR_Alloc(PRUint32 bytes) { return malloc(bytes); } + +PR_IMPLEMENT(void *) +PR_Malloc(PRUint32 bytes) { return malloc(bytes); } + +PR_IMPLEMENT(void *) +PR_Calloc(PRUint32 blocks, PRUint32 bytes) { return calloc(blocks,bytes); } + +PR_IMPLEMENT(void) +PR_Free(void *ptr) { free(ptr); } + +PR_IMPLEMENT(void) +PR_SetError(PRErrorCode errorCode, PRInt32 oserr) { return; } + +PR_IMPLEMENT(void) +PR_SetErrorText(PRIntn textLength, const char *text) { return; } + + +/* Old template; want to expunge it eventually. */ +#include "secasn1.h" +#include "secoid.h" + +const SEC_ASN1Template SECOID_AlgorithmIDTemplate[] = { + { SEC_ASN1_SEQUENCE, + 0, NULL, sizeof(SECAlgorithmID) }, + { SEC_ASN1_OBJECT_ID, + offsetof(SECAlgorithmID,algorithm), }, + { SEC_ASN1_OPTIONAL | SEC_ASN1_ANY, + offsetof(SECAlgorithmID,parameters), }, + { 0, } +}; + +/* now make the RNG happy */ /* This is not atomic! */ +PR_IMPLEMENT(PRInt32) PR_AtomicIncrement(PRInt32 *val) { return ++(*val); } +/* This is not atomic! */ +PR_IMPLEMENT(PRInt32) PR_AtomicDecrement(PRInt32 *val) { return --(*val); } + +PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime ticks) { return PR_SUCCESS; } + +#include "nssilock.h" +#include "fmutex.h" +PR_IMPLEMENT(PRLock *) +PR_NewLock(void) { + PRLock *lock = NULL; + + FMUTEX_Create(&lock); + + /* if we don't have a lock, FMUTEX can deal with things */ + if (lock == NULL) lock=(PRLock *) 1; + return lock; +} + +PR_IMPLEMENT(void) +PR_DestroyLock(PRLock *lock) { + FMUTEX_Destroy(lock); +} + +PR_IMPLEMENT(void) +PR_Lock(PRLock *lock) { + FMUTEX_Lock(lock); +} + +PR_IMPLEMENT(PRStatus) +PR_Unlock(PRLock *lock) { + FMUTEX_Unlock(lock); + return PR_SUCCESS; +} + +/* this implementation is here to satisfy the PRMonitor use in plarena.c. +** It appears that it doesn't need re-entrant locks. It could have used +** PRLock instead of PRMonitor. So, this implementation just uses +** PRLock for a PRMonitor. +*/ +PR_IMPLEMENT(PRMonitor*) +PR_NewMonitor(void) +{ + return (PRMonitor *) PR_NewLock(); +} + + +PR_IMPLEMENT(void) +PR_EnterMonitor(PRMonitor *mon) +{ + PR_Lock( (PRLock *)mon ); +} + +PR_IMPLEMENT(PRStatus) +PR_ExitMonitor(PRMonitor *mon) +{ + return PR_Unlock( (PRLock *)mon ); +} + +#include "prinit.h" + +/* This is NOT threadsafe. It is merely a pseudo-functional stub. +*/ +PR_IMPLEMENT(PRStatus) PR_CallOnce( + PRCallOnceType *once, + PRCallOnceFN func) +{ + /* This is not really atomic! */ + if (1 == PR_AtomicIncrement(&once->initialized)) { + once->status = (*func)(); + } else { + /* Should wait to be sure that func has finished before returning. */ + } + return once->status; +} + + +/* +** Compute the log of the least power of 2 greater than or equal to n +*/ +PRIntn PR_CeilingLog2(PRUint32 i) { + PRIntn log2; + PR_CEILING_LOG2(log2,i); + return log2; +} + +/********************** end of arena functions ***********************/ + |