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