security/nss/lib/softoken/softoken.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * softoken.h - private data structures and prototypes for the softoken lib
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef _SOFTOKEN_H_
michael@0 9 #define _SOFTOKEN_H_
michael@0 10
michael@0 11 #include "blapi.h"
michael@0 12 #include "lowkeyti.h"
michael@0 13 #include "softoknt.h"
michael@0 14 #include "secoidt.h"
michael@0 15
michael@0 16 #include "pkcs11t.h"
michael@0 17
michael@0 18 SEC_BEGIN_PROTOS
michael@0 19
michael@0 20 /*
michael@0 21 * Convenience wrapper for doing a single PKCS#1 v1.5 RSA operations where the
michael@0 22 * encoded digest info is computed internally, rather than by the caller.
michael@0 23 *
michael@0 24 * The HashSign variants expect as input the value of H, the computed hash
michael@0 25 * from RFC 3447, Section 9.2, Step 1, and will compute the DER-encoded
michael@0 26 * DigestInfo structure internally prior to signing/verifying.
michael@0 27 */
michael@0 28 extern SECStatus
michael@0 29 RSA_HashSign(SECOidTag hashOid, NSSLOWKEYPrivateKey *key,
michael@0 30 unsigned char *sig, unsigned int *sigLen, unsigned int maxLen,
michael@0 31 const unsigned char *hash, unsigned int hashLen);
michael@0 32
michael@0 33 extern SECStatus
michael@0 34 RSA_HashCheckSign(SECOidTag hashOid, NSSLOWKEYPublicKey *key,
michael@0 35 const unsigned char *sig, unsigned int sigLen,
michael@0 36 const unsigned char *hash, unsigned int hashLen);
michael@0 37
michael@0 38 /*
michael@0 39 ** Prepare a buffer for padded CBC encryption, growing to the appropriate
michael@0 40 ** boundary, filling with the appropriate padding.
michael@0 41 **
michael@0 42 ** blockSize must be a power of 2.
michael@0 43 **
michael@0 44 ** We add from 1 to blockSize bytes -- we *always* grow.
michael@0 45 ** The extra bytes contain the value of the length of the padding:
michael@0 46 ** if we have 2 bytes of padding, then the padding is "0x02, 0x02".
michael@0 47 **
michael@0 48 ** NOTE: If arena is non-NULL, we re-allocate from there, otherwise
michael@0 49 ** we assume (and use) PR memory (re)allocation.
michael@0 50 */
michael@0 51 extern unsigned char * CBC_PadBuffer(PLArenaPool *arena, unsigned char *inbuf,
michael@0 52 unsigned int inlen, unsigned int *outlen,
michael@0 53 int blockSize);
michael@0 54
michael@0 55
michael@0 56 /****************************************/
michael@0 57 /*
michael@0 58 ** Power-Up selftests required for FIPS and invoked only
michael@0 59 ** under PKCS #11 FIPS mode.
michael@0 60 */
michael@0 61 extern CK_RV sftk_fipsPowerUpSelfTest( void );
michael@0 62
michael@0 63 /*
michael@0 64 ** make known fixed PKCS #11 key types to their sizes in bytes
michael@0 65 */
michael@0 66 unsigned long sftk_MapKeySize(CK_KEY_TYPE keyType);
michael@0 67
michael@0 68 /*
michael@0 69 ** FIPS 140-2 auditing
michael@0 70 */
michael@0 71 extern PRBool sftk_audit_enabled;
michael@0 72
michael@0 73 extern void sftk_LogAuditMessage(NSSAuditSeverity severity,
michael@0 74 NSSAuditType, const char *msg);
michael@0 75
michael@0 76 extern void sftk_AuditCreateObject(CK_SESSION_HANDLE hSession,
michael@0 77 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
michael@0 78 CK_OBJECT_HANDLE_PTR phObject, CK_RV rv);
michael@0 79
michael@0 80 extern void sftk_AuditCopyObject(CK_SESSION_HANDLE hSession,
michael@0 81 CK_OBJECT_HANDLE hObject,
michael@0 82 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
michael@0 83 CK_OBJECT_HANDLE_PTR phNewObject, CK_RV rv);
michael@0 84
michael@0 85 extern void sftk_AuditDestroyObject(CK_SESSION_HANDLE hSession,
michael@0 86 CK_OBJECT_HANDLE hObject, CK_RV rv);
michael@0 87
michael@0 88 extern void sftk_AuditGetObjectSize(CK_SESSION_HANDLE hSession,
michael@0 89 CK_OBJECT_HANDLE hObject, CK_ULONG_PTR pulSize,
michael@0 90 CK_RV rv);
michael@0 91
michael@0 92 extern void sftk_AuditGetAttributeValue(CK_SESSION_HANDLE hSession,
michael@0 93 CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate,
michael@0 94 CK_ULONG ulCount, CK_RV rv);
michael@0 95
michael@0 96 extern void sftk_AuditSetAttributeValue(CK_SESSION_HANDLE hSession,
michael@0 97 CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate,
michael@0 98 CK_ULONG ulCount, CK_RV rv);
michael@0 99
michael@0 100 extern void sftk_AuditCryptInit(const char *opName,
michael@0 101 CK_SESSION_HANDLE hSession,
michael@0 102 CK_MECHANISM_PTR pMechanism,
michael@0 103 CK_OBJECT_HANDLE hKey, CK_RV rv);
michael@0 104
michael@0 105 extern void sftk_AuditGenerateKey(CK_SESSION_HANDLE hSession,
michael@0 106 CK_MECHANISM_PTR pMechanism,
michael@0 107 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
michael@0 108 CK_OBJECT_HANDLE_PTR phKey, CK_RV rv);
michael@0 109
michael@0 110 extern void sftk_AuditGenerateKeyPair(CK_SESSION_HANDLE hSession,
michael@0 111 CK_MECHANISM_PTR pMechanism,
michael@0 112 CK_ATTRIBUTE_PTR pPublicKeyTemplate,
michael@0 113 CK_ULONG ulPublicKeyAttributeCount,
michael@0 114 CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
michael@0 115 CK_ULONG ulPrivateKeyAttributeCount,
michael@0 116 CK_OBJECT_HANDLE_PTR phPublicKey,
michael@0 117 CK_OBJECT_HANDLE_PTR phPrivateKey, CK_RV rv);
michael@0 118
michael@0 119 extern void sftk_AuditWrapKey(CK_SESSION_HANDLE hSession,
michael@0 120 CK_MECHANISM_PTR pMechanism,
michael@0 121 CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey,
michael@0 122 CK_BYTE_PTR pWrappedKey,
michael@0 123 CK_ULONG_PTR pulWrappedKeyLen, CK_RV rv);
michael@0 124
michael@0 125 extern void sftk_AuditUnwrapKey(CK_SESSION_HANDLE hSession,
michael@0 126 CK_MECHANISM_PTR pMechanism,
michael@0 127 CK_OBJECT_HANDLE hUnwrappingKey,
michael@0 128 CK_BYTE_PTR pWrappedKey, CK_ULONG ulWrappedKeyLen,
michael@0 129 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount,
michael@0 130 CK_OBJECT_HANDLE_PTR phKey, CK_RV rv);
michael@0 131
michael@0 132 extern void sftk_AuditDeriveKey(CK_SESSION_HANDLE hSession,
michael@0 133 CK_MECHANISM_PTR pMechanism,
michael@0 134 CK_OBJECT_HANDLE hBaseKey,
michael@0 135 CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount,
michael@0 136 CK_OBJECT_HANDLE_PTR phKey, CK_RV rv);
michael@0 137
michael@0 138 extern void sftk_AuditDigestKey(CK_SESSION_HANDLE hSession,
michael@0 139 CK_OBJECT_HANDLE hKey, CK_RV rv);
michael@0 140
michael@0 141 /*
michael@0 142 ** FIPS 140-2 Error state
michael@0 143 */
michael@0 144 extern PRBool sftk_fatalError;
michael@0 145
michael@0 146 /*
michael@0 147 ** macros to check for forked child process after C_Initialize
michael@0 148 */
michael@0 149 #if defined(XP_UNIX) && !defined(NO_FORK_CHECK)
michael@0 150
michael@0 151 #ifdef DEBUG
michael@0 152
michael@0 153 #define FORK_ASSERT() \
michael@0 154 { \
michael@0 155 char* forkAssert = getenv("NSS_STRICT_NOFORK"); \
michael@0 156 if ( (!forkAssert) || (0 == strcmp(forkAssert, "1")) ) { \
michael@0 157 PORT_Assert(0); \
michael@0 158 } \
michael@0 159 }
michael@0 160
michael@0 161 #else
michael@0 162
michael@0 163 #define FORK_ASSERT()
michael@0 164
michael@0 165 #endif
michael@0 166
michael@0 167 /* we have 3 methods of implementing the fork checks :
michael@0 168 * - Solaris "mixed" method
michael@0 169 * - pthread_atfork method
michael@0 170 * - getpid method
michael@0 171 */
michael@0 172
michael@0 173 #if !defined (CHECK_FORK_MIXED) && !defined(CHECK_FORK_PTHREAD) && \
michael@0 174 !defined (CHECK_FORK_GETPID)
michael@0 175
michael@0 176 /* Choose fork check method automatically unless specified
michael@0 177 * This section should be updated as more platforms get pthread fixes
michael@0 178 * to unregister fork handlers in dlclose.
michael@0 179 */
michael@0 180
michael@0 181 #ifdef SOLARIS
michael@0 182
michael@0 183 /* Solaris 8, s9 use PID checks, s10 uses pthread_atfork */
michael@0 184
michael@0 185 #define CHECK_FORK_MIXED
michael@0 186
michael@0 187 #elif defined(LINUX)
michael@0 188
michael@0 189 #define CHECK_FORK_PTHREAD
michael@0 190
michael@0 191 #else
michael@0 192
michael@0 193 /* Other Unix platforms use only PID checks. Even if pthread_atfork is
michael@0 194 * available, the behavior of dlclose isn't guaranteed by POSIX to
michael@0 195 * unregister the fork handler. */
michael@0 196
michael@0 197 #define CHECK_FORK_GETPID
michael@0 198
michael@0 199 #endif
michael@0 200
michael@0 201 #endif
michael@0 202
michael@0 203 #if defined(CHECK_FORK_MIXED)
michael@0 204
michael@0 205 extern PRBool usePthread_atfork;
michael@0 206 #include <unistd.h>
michael@0 207 extern pid_t myPid;
michael@0 208 extern PRBool forked;
michael@0 209
michael@0 210 #define PARENT_FORKED() (usePthread_atfork ? forked : (myPid && myPid != getpid()))
michael@0 211
michael@0 212 #elif defined(CHECK_FORK_PTHREAD)
michael@0 213
michael@0 214 extern PRBool forked;
michael@0 215
michael@0 216 #define PARENT_FORKED() forked
michael@0 217
michael@0 218 #elif defined(CHECK_FORK_GETPID)
michael@0 219
michael@0 220 #include <unistd.h>
michael@0 221 extern pid_t myPid;
michael@0 222
michael@0 223 #define PARENT_FORKED() (myPid && myPid != getpid())
michael@0 224
michael@0 225 #endif
michael@0 226
michael@0 227 extern PRBool parentForkedAfterC_Initialize;
michael@0 228 extern PRBool sftkForkCheckDisabled;
michael@0 229
michael@0 230 #define CHECK_FORK() \
michael@0 231 do { \
michael@0 232 if (!sftkForkCheckDisabled && PARENT_FORKED()) { \
michael@0 233 FORK_ASSERT(); \
michael@0 234 return CKR_DEVICE_ERROR; \
michael@0 235 } \
michael@0 236 } while (0)
michael@0 237
michael@0 238 #define SKIP_AFTER_FORK(x) if (!parentForkedAfterC_Initialize) x
michael@0 239
michael@0 240 #define ENABLE_FORK_CHECK() \
michael@0 241 { \
michael@0 242 char* doForkCheck = getenv("NSS_STRICT_NOFORK"); \
michael@0 243 if ( doForkCheck && !strcmp(doForkCheck, "DISABLED") ) { \
michael@0 244 sftkForkCheckDisabled = PR_TRUE; \
michael@0 245 } \
michael@0 246 }
michael@0 247
michael@0 248
michael@0 249 #else
michael@0 250
michael@0 251 /* non-Unix platforms, or fork check disabled */
michael@0 252
michael@0 253 #define CHECK_FORK()
michael@0 254 #define SKIP_AFTER_FORK(x) x
michael@0 255 #define ENABLE_FORK_CHECK()
michael@0 256
michael@0 257 #ifndef NO_FORK_CHECK
michael@0 258 #define NO_FORK_CHECK
michael@0 259 #endif
michael@0 260
michael@0 261 #endif
michael@0 262
michael@0 263
michael@0 264 SEC_END_PROTOS
michael@0 265
michael@0 266 #endif /* _SOFTOKEN_H_ */

mercurial