michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifdef FREEBL_NO_DEPEND michael@0: #include "stubs.h" michael@0: #endif michael@0: michael@0: #include "nspr.h" michael@0: #include "hasht.h" michael@0: #include "blapi.h" /* below the line */ michael@0: #include "secerr.h" michael@0: michael@0: static void * michael@0: null_hash_new_context(void) michael@0: { michael@0: return NULL; michael@0: } michael@0: michael@0: static void * michael@0: null_hash_clone_context(void *v) michael@0: { michael@0: PORT_Assert(v == NULL); michael@0: return NULL; michael@0: } michael@0: michael@0: static void michael@0: null_hash_begin(void *v) michael@0: { michael@0: } michael@0: michael@0: static void michael@0: null_hash_update(void *v, const unsigned char *input, unsigned int length) michael@0: { michael@0: } michael@0: michael@0: static void michael@0: null_hash_end(void *v, unsigned char *output, unsigned int *outLen, michael@0: unsigned int maxOut) michael@0: { michael@0: *outLen = 0; michael@0: } michael@0: michael@0: static void michael@0: null_hash_destroy_context(void *v, PRBool b) michael@0: { michael@0: PORT_Assert(v == NULL); michael@0: } michael@0: michael@0: michael@0: const SECHashObject SECRawHashObjects[] = { michael@0: { 0, michael@0: (void * (*)(void)) null_hash_new_context, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) null_hash_destroy_context, michael@0: (void (*)(void *)) null_hash_begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) null_hash_update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) null_hash_end, michael@0: 0, michael@0: HASH_AlgNULL, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) null_hash_end michael@0: }, michael@0: { MD2_LENGTH, michael@0: (void * (*)(void)) MD2_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) MD2_DestroyContext, michael@0: (void (*)(void *)) MD2_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) MD2_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD2_End, michael@0: MD2_BLOCK_LENGTH, michael@0: HASH_AlgMD2, michael@0: NULL /* end_raw */ michael@0: }, michael@0: { MD5_LENGTH, michael@0: (void * (*)(void)) MD5_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) MD5_DestroyContext, michael@0: (void (*)(void *)) MD5_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) MD5_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD5_End, michael@0: MD5_BLOCK_LENGTH, michael@0: HASH_AlgMD5, michael@0: (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD5_EndRaw michael@0: }, michael@0: { SHA1_LENGTH, michael@0: (void * (*)(void)) SHA1_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) SHA1_DestroyContext, michael@0: (void (*)(void *)) SHA1_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) SHA1_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) SHA1_End, michael@0: SHA1_BLOCK_LENGTH, michael@0: HASH_AlgSHA1, michael@0: (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) michael@0: SHA1_EndRaw michael@0: }, michael@0: { SHA256_LENGTH, michael@0: (void * (*)(void)) SHA256_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) SHA256_DestroyContext, michael@0: (void (*)(void *)) SHA256_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) SHA256_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA256_End, michael@0: SHA256_BLOCK_LENGTH, michael@0: HASH_AlgSHA256, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA256_EndRaw michael@0: }, michael@0: { SHA384_LENGTH, michael@0: (void * (*)(void)) SHA384_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) SHA384_DestroyContext, michael@0: (void (*)(void *)) SHA384_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) SHA384_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA384_End, michael@0: SHA384_BLOCK_LENGTH, michael@0: HASH_AlgSHA384, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA384_EndRaw michael@0: }, michael@0: { SHA512_LENGTH, michael@0: (void * (*)(void)) SHA512_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) SHA512_DestroyContext, michael@0: (void (*)(void *)) SHA512_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) SHA512_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA512_End, michael@0: SHA512_BLOCK_LENGTH, michael@0: HASH_AlgSHA512, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA512_EndRaw michael@0: }, michael@0: { SHA224_LENGTH, michael@0: (void * (*)(void)) SHA224_NewContext, michael@0: (void * (*)(void *)) null_hash_clone_context, michael@0: (void (*)(void *, PRBool)) SHA224_DestroyContext, michael@0: (void (*)(void *)) SHA224_Begin, michael@0: (void (*)(void *, const unsigned char *, unsigned int)) SHA224_Update, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA224_End, michael@0: SHA224_BLOCK_LENGTH, michael@0: HASH_AlgSHA224, michael@0: (void (*)(void *, unsigned char *, unsigned int *, michael@0: unsigned int)) SHA224_EndRaw michael@0: }, michael@0: }; michael@0: michael@0: const SECHashObject * michael@0: HASH_GetRawHashObject(HASH_HashType hashType) michael@0: { michael@0: if (hashType < HASH_AlgNULL || hashType >= HASH_AlgTOTAL) { michael@0: PORT_SetError(SEC_ERROR_INVALID_ARGS); michael@0: return NULL; michael@0: } michael@0: return &SECRawHashObjects[hashType]; michael@0: }