diff -up ./nss/lib/freebl/blname.c.freebl-dyload ./nss/lib/freebl/blname.c --- ./nss/lib/freebl/blname.c.freebl-dyload 2014-11-17 15:50:32.580158978 -0800 +++ ./nss/lib/freebl/blname.c 2014-11-17 15:50:32.736161778 -0800 @@ -5,8 +5,13 @@ * * License, v. 2.0. If a copy of the MPL was not distributed with this * * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#if defined(FREEBL_LOWHASH) +static const char* default_name = + SHLIB_PREFIX"freeblpriv"SHLIB_VERSION"."SHLIB_SUFFIX; +#else static const char* default_name = SHLIB_PREFIX"freebl"SHLIB_VERSION"."SHLIB_SUFFIX; +#endif /* getLibName() returns the name of the library to load. */ diff -up ./nss/lib/freebl/freebl_hash_vector.def.freebl-dyload ./nss/lib/freebl/freebl_hash_vector.def --- ./nss/lib/freebl/freebl_hash_vector.def.freebl-dyload 2014-11-17 15:50:32.737161796 -0800 +++ ./nss/lib/freebl/freebl_hash_vector.def 2014-11-17 15:50:32.737161796 -0800 @@ -0,0 +1,34 @@ +;+# +;+# This Source Code Form is subject to the terms of the Mozilla Public +;+# License, v. 2.0. If a copy of the MPL was not distributed with this +;+# file, You can obtain one at http://mozilla.org/MPL/2.0/. +;+# +;+# OK, this file is meant to support SUN, LINUX, AIX and WINDOWS +;+# 1. For all unix platforms, the string ";-" means "remove this line" +;+# 2. For all unix platforms, the string " DATA " will be removed from any +;+# line on which it occurs. +;+# 3. Lines containing ";+" will have ";+" removed on SUN and LINUX. +;+# On AIX, lines containing ";+" will be removed. +;+# 4. For all unix platforms, the string ";;" will thave the ";;" removed. +;+# 5. For all unix platforms, after the above processing has taken place, +;+# all characters after the first ";" on the line will be removed. +;+# And for AIX, the first ";" will also be removed. +;+# This file is passed directly to windows. Since ';' is a comment, all UNIX +;+# directives are hidden behind ";", ";+", and ";-" +;+ +;+NSSprivate_3.11 { # NSS 3.11 release +;+ global: +LIBRARY freebl3 ;- +EXPORTS ;- +FREEBL_GetVector; +;+ local: +;+ *; +;+}; +;+NSSprivate_3.16 { # NSS 3.11 release +;+ global: +LIBRARY freebl3 ;- +EXPORTS ;- +NSSLOW_GetVector; +;+ local: +;+ *; +;+}; diff -up ./nss/lib/freebl/ldvector.c.freebl-dyload ./nss/lib/freebl/ldvector.c --- ./nss/lib/freebl/ldvector.c.freebl-dyload 2014-11-17 15:50:32.583159032 -0800 +++ ./nss/lib/freebl/ldvector.c 2014-11-17 15:50:32.737161796 -0800 @@ -14,7 +14,6 @@ extern int FREEBL_InitStubs(void); #include "hmacct.h" #include "blapii.h" - static const struct FREEBLVectorStr vector = { @@ -292,6 +291,8 @@ static const struct FREEBLVectorStr vect /* End of Version 3.017 */ }; + + const FREEBLVector * FREEBL_GetVector(void) { @@ -317,3 +318,31 @@ FREEBL_GetVector(void) return &vector; } + +#ifdef FREEBL_LOWHASH +static const struct NSSLOWVectorStr nssvector = +{ + sizeof nssvector, + NSSLOW_VERSION, + FREEBL_GetVector, + NSSLOW_Init, + NSSLOW_Shutdown, + NSSLOW_Reset, + NSSLOWHASH_NewContext, + NSSLOWHASH_Begin, + NSSLOWHASH_Update, + NSSLOWHASH_End, + NSSLOWHASH_Destroy, + NSSLOWHASH_Length +}; + +const NSSLOWVector * +NSSLOW_GetVector(void) +{ + SECStatus rv; + + /* POST check and stub init happens in FREEBL_GetVector() and + * NSSLOW_Init() respectively */ + return &nssvector; +} +#endif diff -up ./nss/lib/freebl/loader.h.freebl-dyload ./nss/lib/freebl/loader.h --- ./nss/lib/freebl/loader.h.freebl-dyload 2014-06-24 13:45:27.000000000 -0700 +++ ./nss/lib/freebl/loader.h 2014-11-17 15:50:32.738161814 -0800 @@ -10,6 +10,7 @@ #include "blapi.h" + #define FREEBL_VERSION 0x0311 struct FREEBLVectorStr { @@ -713,8 +714,43 @@ struct FREEBLVectorStr { typedef struct FREEBLVectorStr FREEBLVector; +#ifdef FREEBL_LOWHASH +#include "nsslowhash.h" + +#define NSSLOW_VERSION 0x0300 + +struct NSSLOWVectorStr { + unsigned short length; /* of this struct in bytes */ + unsigned short version; /* of this struct. */ + const FREEBLVector *(*p_FREEBL_GetVector)(void); + NSSLOWInitContext *(*p_NSSLOW_Init)(void); + void (*p_NSSLOW_Shutdown)(NSSLOWInitContext *context); + void (*p_NSSLOW_Reset)(NSSLOWInitContext *context); + NSSLOWHASHContext *(*p_NSSLOWHASH_NewContext)( + NSSLOWInitContext *initContext, + HASH_HashType hashType); + void (*p_NSSLOWHASH_Begin)(NSSLOWHASHContext *context); + void (*p_NSSLOWHASH_Update)(NSSLOWHASHContext *context, + const unsigned char *buf, + unsigned int len); + void (*p_NSSLOWHASH_End)(NSSLOWHASHContext *context, + unsigned char *buf, + unsigned int *ret, unsigned int len); + void (*p_NSSLOWHASH_Destroy)(NSSLOWHASHContext *context); + unsigned int (*p_NSSLOWHASH_Length)(NSSLOWHASHContext *context); +}; + +typedef struct NSSLOWVectorStr NSSLOWVector; +#endif + SEC_BEGIN_PROTOS +#ifdef FREEBL_LOWHASH +typedef const NSSLOWVector * NSSLOWGetVectorFn(void); + +extern NSSLOWGetVectorFn NSSLOW_GetVector; +#endif + typedef const FREEBLVector * FREEBLGetVectorFn(void); extern FREEBLGetVectorFn FREEBL_GetVector; diff -up ./nss/lib/freebl/lowhash_vector.c.freebl-dyload ./nss/lib/freebl/lowhash_vector.c --- ./nss/lib/freebl/lowhash_vector.c.freebl-dyload 2014-11-17 15:50:32.739161832 -0800 +++ ./nss/lib/freebl/lowhash_vector.c 2014-11-17 16:56:14.683766156 -0800 @@ -0,0 +1,213 @@ +/* + * loader.c - load platform dependent DSO containing freebl implementation. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#define _GNU_SOURCE 1 +#include "loader.h" +#include "prmem.h" +#include "prerror.h" +#include "prinit.h" +#include "prenv.h" +#include "blname.c" + +#include "prio.h" +#include "prprf.h" +#include +#include "prsystem.h" +#include "nsslowhash.h" +#include +#include "pratom.h" + +static const char *NameOfThisSharedLib = + SHLIB_PREFIX"freebl"SHLIB_VERSION"."SHLIB_SUFFIX; + +static PRLibrary* blLib; + +#define LSB(x) ((x)&0xff) +#define MSB(x) ((x)>>8) + +static const NSSLOWVector *vector; +static const char *libraryName = NULL; + +/* pretty much only glibc uses this, make sure we don't have any depenencies + * on nspr.. */ +#undef PORT_Alloc +#undef PORT_Free +#define PORT_Alloc malloc +#define PR_Malloc malloc +#define PORT_Free free +#define PR_Free free +#define PR_GetDirectorySeparator() '/' +#define PR_LoadLibraryWithFlags(libspec,flags) \ + (PRLibrary*)dlopen(libSpec.value.pathname,RTLD_NOW|RTLD_LOCAL) +#define PR_GetLibraryFilePathname(name,addr) \ + freebl_lowhash_getLibraryFilePath(addr) + +static char * +freebl_lowhash_getLibraryFilePath(void *addr) +{ + Dl_info dli; + if (dladdr(addr, &dli) == 0) { + return NULL; + } + return strdup(dli.dli_fname); +} +#include "genload.c" + + +/* This function must be run only once. */ +/* determine if hybrid platform, then actually load the DSO. */ +static PRStatus +freebl_LoadDSO( void ) +{ + PRLibrary * handle; + const char * name = getLibName(); + + if (!name) { + PR_SetError(PR_LOAD_LIBRARY_ERROR, 0); + return PR_FAILURE; + } + handle = loader_LoadLibrary(name); + if (handle) { + void *address = dlsym(handle, "NSSLOW_GetVector"); + PRStatus status; + if (address) { + NSSLOWGetVectorFn * getVector = (NSSLOWGetVectorFn *)address; + const NSSLOWVector * dsoVector = getVector(); + if (dsoVector) { + unsigned short dsoVersion = dsoVector->version; + unsigned short myVersion = NSSLOW_VERSION; + if (MSB(dsoVersion) == MSB(myVersion) && + LSB(dsoVersion) >= LSB(myVersion) && + dsoVector->length >= sizeof(NSSLOWVector)) { + vector = dsoVector; + libraryName = name; + blLib = handle; + return PR_SUCCESS; + } + } + } + status = dlclose(handle); + PORT_Assert(PR_SUCCESS == status); + } + return PR_FAILURE; +} + +static PRCallOnceType loadFreeBLOnce; +/* remove when NSPR pratom.h is updated. s390 has atomic intrinsics, + * but nspr doesn't know it. */ +#if defined(__s390__) || defined(__s390x__) +#undef PR_ATOMIC_SET +#define PR_ATOMIC_SET(val, newval) __sync_lock_test_and_set(val, newval) +#endif + +static PRStatus +freebl_RunLoaderOnce( void ) +{ + PRStatus status; + + /* Don't have NSPR, so can use the real PR_CallOnce, implement a stripped + * down version. */ + if (loadFreeBLOnce.initialized) { + return loadFreeBLOnce.status; + } + /* PR_ATOMIC_SET macro is implemented with compiler intrinsics, if we don't + * have the intrinsic, it will be set to an NSPR PR_Atomic function, which + * will show up as missing at build time. If we get that missing function, + * Then we'll need to implement a PR_AtomicSet() function for that platform + */ + if (PR_ATOMIC_SET(&loadFreeBLOnce.inProgress,1) == 0) { + loadFreeBLOnce.status = freebl_LoadDSO(); + loadFreeBLOnce.initialized = 1; + } else { + /* shouldn't have a lot of takers on the else clause, which is good + * since we don't have condition variables yet. + * 'initialized' only ever gets set (not cleared) so we don't + * need the traditional locks. */ + while (!loadFreeBLOnce.initialized) { + sleep(1); /* don't have condition variables, just give up the CPU */ + } + } + + return loadFreeBLOnce.status; +} + +const FREEBLVector *FREEBL_GetVector(void) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return NULL; + return (vector->p_FREEBL_GetVector)(); +} + +NSSLOWInitContext *NSSLOW_Init(void) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return NULL; + return (vector->p_NSSLOW_Init)(); +} + +void NSSLOW_Shutdown(NSSLOWInitContext *context) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOW_Shutdown)(context); +} + +void NSSLOW_Reset(NSSLOWInitContext *context) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOW_Reset)(context); +} + +NSSLOWHASHContext *NSSLOWHASH_NewContext( + NSSLOWInitContext *initContext, + HASH_HashType hashType) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return NULL; + return (vector->p_NSSLOWHASH_NewContext)(initContext, hashType); +} + +void NSSLOWHASH_Begin(NSSLOWHASHContext *context) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOWHASH_Begin)(context); +} + +void NSSLOWHASH_Update(NSSLOWHASHContext *context, + const unsigned char *buf, + unsigned int len) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOWHASH_Update)(context, buf, len); +} + +void NSSLOWHASH_End(NSSLOWHASHContext *context, + unsigned char *buf, + unsigned int *ret, unsigned int len) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOWHASH_End)(context, buf, ret, len); +} + +void NSSLOWHASH_Destroy(NSSLOWHASHContext *context) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return; + (vector->p_NSSLOWHASH_Destroy)(context); +} + +unsigned int NSSLOWHASH_Length(NSSLOWHASHContext *context) +{ + if (!vector && PR_SUCCESS != freebl_RunLoaderOnce()) + return -1; + return (vector->p_NSSLOWHASH_Length)(context); +} + diff -up ./nss/lib/freebl/Makefile.freebl-dyload ./nss/lib/freebl/Makefile --- ./nss/lib/freebl/Makefile.freebl-dyload 2014-11-17 15:50:32.684160845 -0800 +++ ./nss/lib/freebl/Makefile 2014-11-17 15:50:32.739161832 -0800 @@ -46,13 +46,24 @@ ifeq ($(FREEBL_NO_DEPEND),1) endif ifeq ($(FREEBL_LOWHASH),1) + DEFINES += -DFREEBL_LOWHASH LOWHASH_SRCS = nsslowhash.c LOWHASH_EXPORTS = nsslowhash.h - MAPFILE_SOURCE = freebl_hash.def + MAPFILE_SOURCE = freebl_hash_vector.def + FREEBL_BUILD_LOWHASH = 1 else MAPFILE_SOURCE = freebl.def endif +ifdef FREEBL_LOWHASH_BUILD + CSRCS = lowhash_vector.c + SIMPLE_OBJS = $(CSRCS:.c=$(OBJ_SUFFIX)) + OBJS = $(addprefix $(OBJDIR)/$(PROG_PREFIX), $(SIMPLE_OBJS)) + ALL_TRASH := $(TARGETS) $(OBJS) $(OBJDIR) LOGS TAGS $(GARBAGE) \ + $(NOSUCHFILE) so_locations + MAPFILE_SOURCE = freebl_hash.def +endif + # FREEBL_USE_PRELINK # # Most modern version of Linux support a speed optimization scheme where an @@ -574,6 +585,17 @@ release_md libs:: $(SINGLE_SHLIB_DIR) endif +ifdef FREEBL_BUILD_LOWHASH +SINGLE_SHLIB_DIR = $(OBJDIR)/$(OS_TARGET)_SINGLE_SHLIB +ALL_TRASH += $(SINGLE_SHLIB_DIR) +$(SINGLE_SHLIB_DIR): + -mkdir $(SINGLE_SHLIB_DIR) + +release_md libs:: $(SINGLE_SHLIB_DIR) + $(MAKE) FREEBL_LOWHASH_BUILD=1 FREEBL_CHILD_BUILD=1 \ + OBJDIR=$(SINGLE_SHLIB_DIR) $@ +endif + # multiple shared libraries ######################## ABI32_FPU stuff ######################### diff -up ./nss/lib/freebl/manifest.mn.freebl-dyload ./nss/lib/freebl/manifest.mn --- ./nss/lib/freebl/manifest.mn.freebl-dyload 2014-11-17 15:50:32.583159032 -0800 +++ ./nss/lib/freebl/manifest.mn 2014-11-17 15:50:32.739161832 -0800 @@ -29,6 +29,12 @@ ifdef FREEBL_CHILD_BUILD ifdef USE_ABI64_FPU LIBRARY_NAME = freebl_64fpu endif + ifdef FREEBL_LOWHASH + LIBRARY_NAME = freeblpriv + endif + ifdef FREEBL_LOWHASH_BUILD + LIBRARY_NAME = freebl + endif endif # if the library name contains _, we prefix the version with _