nsslowhash.c (2871B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifdef FREEBL_NO_DEPEND 6 #include "stubs.h" 7 #endif 8 #include "prtypes.h" 9 #include "prenv.h" 10 #include "secerr.h" 11 #include "blapi.h" 12 #include "hasht.h" 13 #include "plhash.h" 14 #include "nsslowhash.h" 15 #include "blapii.h" 16 17 struct NSSLOWInitContextStr { 18 int count; 19 }; 20 21 struct NSSLOWHASHContextStr { 22 const SECHashObject *hashObj; 23 void *hashCtxt; 24 }; 25 26 static NSSLOWInitContext dummyContext = { 0 }; 27 static PRBool post_failed = PR_TRUE; 28 29 NSSLOWInitContext * 30 NSSLOW_Init(void) 31 { 32 #ifdef FREEBL_NO_DEPEND 33 (void)FREEBL_InitStubs(); 34 #endif 35 36 #ifndef NSS_FIPS_DISABLED 37 /* make sure the FIPS product is installed if we are trying to 38 * go into FIPS mode */ 39 if (NSS_GetSystemFIPSEnabled()) { 40 if (BL_FIPSEntryOK(PR_TRUE, PR_FALSE) != SECSuccess) { 41 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); 42 post_failed = PR_TRUE; 43 return NULL; 44 } 45 } 46 #endif 47 post_failed = PR_FALSE; 48 49 return &dummyContext; 50 } 51 52 void 53 NSSLOW_Shutdown(NSSLOWInitContext *context) 54 { 55 PORT_Assert(context == &dummyContext); 56 return; 57 } 58 59 void 60 NSSLOW_Reset(NSSLOWInitContext *context) 61 { 62 PORT_Assert(context == &dummyContext); 63 return; 64 } 65 66 NSSLOWHASHContext * 67 NSSLOWHASH_NewContext(NSSLOWInitContext *initContext, 68 HASH_HashType hashType) 69 { 70 NSSLOWHASHContext *context; 71 72 if (post_failed) { 73 PORT_SetError(SEC_ERROR_PKCS11_DEVICE_ERROR); 74 return NULL; 75 } 76 77 if (initContext != &dummyContext) { 78 PORT_SetError(SEC_ERROR_INVALID_ARGS); 79 return (NULL); 80 } 81 82 context = PORT_ZNew(NSSLOWHASHContext); 83 if (!context) { 84 return NULL; 85 } 86 context->hashObj = HASH_GetRawHashObject(hashType); 87 if (!context->hashObj) { 88 PORT_Free(context); 89 return NULL; 90 } 91 context->hashCtxt = context->hashObj->create(); 92 if (!context->hashCtxt) { 93 PORT_Free(context); 94 return NULL; 95 } 96 97 return context; 98 } 99 100 void 101 NSSLOWHASH_Begin(NSSLOWHASHContext *context) 102 { 103 return context->hashObj->begin(context->hashCtxt); 104 } 105 106 void 107 NSSLOWHASH_Update(NSSLOWHASHContext *context, const unsigned char *buf, 108 unsigned int len) 109 { 110 return context->hashObj->update(context->hashCtxt, buf, len); 111 } 112 113 void 114 NSSLOWHASH_End(NSSLOWHASHContext *context, unsigned char *buf, 115 unsigned int *ret, unsigned int len) 116 { 117 return context->hashObj->end(context->hashCtxt, buf, ret, len); 118 } 119 120 void 121 NSSLOWHASH_Destroy(NSSLOWHASHContext *context) 122 { 123 context->hashObj->destroy(context->hashCtxt, PR_TRUE); 124 PORT_Free(context); 125 } 126 127 unsigned int 128 NSSLOWHASH_Length(NSSLOWHASHContext *context) 129 { 130 return context->hashObj->length; 131 }