Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifdef FREEBL_NO_DEPEND |
michael@0 | 6 | #include "stubs.h" |
michael@0 | 7 | #endif |
michael@0 | 8 | |
michael@0 | 9 | #include "nspr.h" |
michael@0 | 10 | #include "hasht.h" |
michael@0 | 11 | #include "blapi.h" /* below the line */ |
michael@0 | 12 | #include "secerr.h" |
michael@0 | 13 | |
michael@0 | 14 | static void * |
michael@0 | 15 | null_hash_new_context(void) |
michael@0 | 16 | { |
michael@0 | 17 | return NULL; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | static void * |
michael@0 | 21 | null_hash_clone_context(void *v) |
michael@0 | 22 | { |
michael@0 | 23 | PORT_Assert(v == NULL); |
michael@0 | 24 | return NULL; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | static void |
michael@0 | 28 | null_hash_begin(void *v) |
michael@0 | 29 | { |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | static void |
michael@0 | 33 | null_hash_update(void *v, const unsigned char *input, unsigned int length) |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | static void |
michael@0 | 38 | null_hash_end(void *v, unsigned char *output, unsigned int *outLen, |
michael@0 | 39 | unsigned int maxOut) |
michael@0 | 40 | { |
michael@0 | 41 | *outLen = 0; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | static void |
michael@0 | 45 | null_hash_destroy_context(void *v, PRBool b) |
michael@0 | 46 | { |
michael@0 | 47 | PORT_Assert(v == NULL); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | const SECHashObject SECRawHashObjects[] = { |
michael@0 | 52 | { 0, |
michael@0 | 53 | (void * (*)(void)) null_hash_new_context, |
michael@0 | 54 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 55 | (void (*)(void *, PRBool)) null_hash_destroy_context, |
michael@0 | 56 | (void (*)(void *)) null_hash_begin, |
michael@0 | 57 | (void (*)(void *, const unsigned char *, unsigned int)) null_hash_update, |
michael@0 | 58 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 59 | unsigned int)) null_hash_end, |
michael@0 | 60 | 0, |
michael@0 | 61 | HASH_AlgNULL, |
michael@0 | 62 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 63 | unsigned int)) null_hash_end |
michael@0 | 64 | }, |
michael@0 | 65 | { MD2_LENGTH, |
michael@0 | 66 | (void * (*)(void)) MD2_NewContext, |
michael@0 | 67 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 68 | (void (*)(void *, PRBool)) MD2_DestroyContext, |
michael@0 | 69 | (void (*)(void *)) MD2_Begin, |
michael@0 | 70 | (void (*)(void *, const unsigned char *, unsigned int)) MD2_Update, |
michael@0 | 71 | (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD2_End, |
michael@0 | 72 | MD2_BLOCK_LENGTH, |
michael@0 | 73 | HASH_AlgMD2, |
michael@0 | 74 | NULL /* end_raw */ |
michael@0 | 75 | }, |
michael@0 | 76 | { MD5_LENGTH, |
michael@0 | 77 | (void * (*)(void)) MD5_NewContext, |
michael@0 | 78 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 79 | (void (*)(void *, PRBool)) MD5_DestroyContext, |
michael@0 | 80 | (void (*)(void *)) MD5_Begin, |
michael@0 | 81 | (void (*)(void *, const unsigned char *, unsigned int)) MD5_Update, |
michael@0 | 82 | (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD5_End, |
michael@0 | 83 | MD5_BLOCK_LENGTH, |
michael@0 | 84 | HASH_AlgMD5, |
michael@0 | 85 | (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD5_EndRaw |
michael@0 | 86 | }, |
michael@0 | 87 | { SHA1_LENGTH, |
michael@0 | 88 | (void * (*)(void)) SHA1_NewContext, |
michael@0 | 89 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 90 | (void (*)(void *, PRBool)) SHA1_DestroyContext, |
michael@0 | 91 | (void (*)(void *)) SHA1_Begin, |
michael@0 | 92 | (void (*)(void *, const unsigned char *, unsigned int)) SHA1_Update, |
michael@0 | 93 | (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) SHA1_End, |
michael@0 | 94 | SHA1_BLOCK_LENGTH, |
michael@0 | 95 | HASH_AlgSHA1, |
michael@0 | 96 | (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) |
michael@0 | 97 | SHA1_EndRaw |
michael@0 | 98 | }, |
michael@0 | 99 | { SHA256_LENGTH, |
michael@0 | 100 | (void * (*)(void)) SHA256_NewContext, |
michael@0 | 101 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 102 | (void (*)(void *, PRBool)) SHA256_DestroyContext, |
michael@0 | 103 | (void (*)(void *)) SHA256_Begin, |
michael@0 | 104 | (void (*)(void *, const unsigned char *, unsigned int)) SHA256_Update, |
michael@0 | 105 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 106 | unsigned int)) SHA256_End, |
michael@0 | 107 | SHA256_BLOCK_LENGTH, |
michael@0 | 108 | HASH_AlgSHA256, |
michael@0 | 109 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 110 | unsigned int)) SHA256_EndRaw |
michael@0 | 111 | }, |
michael@0 | 112 | { SHA384_LENGTH, |
michael@0 | 113 | (void * (*)(void)) SHA384_NewContext, |
michael@0 | 114 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 115 | (void (*)(void *, PRBool)) SHA384_DestroyContext, |
michael@0 | 116 | (void (*)(void *)) SHA384_Begin, |
michael@0 | 117 | (void (*)(void *, const unsigned char *, unsigned int)) SHA384_Update, |
michael@0 | 118 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 119 | unsigned int)) SHA384_End, |
michael@0 | 120 | SHA384_BLOCK_LENGTH, |
michael@0 | 121 | HASH_AlgSHA384, |
michael@0 | 122 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 123 | unsigned int)) SHA384_EndRaw |
michael@0 | 124 | }, |
michael@0 | 125 | { SHA512_LENGTH, |
michael@0 | 126 | (void * (*)(void)) SHA512_NewContext, |
michael@0 | 127 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 128 | (void (*)(void *, PRBool)) SHA512_DestroyContext, |
michael@0 | 129 | (void (*)(void *)) SHA512_Begin, |
michael@0 | 130 | (void (*)(void *, const unsigned char *, unsigned int)) SHA512_Update, |
michael@0 | 131 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 132 | unsigned int)) SHA512_End, |
michael@0 | 133 | SHA512_BLOCK_LENGTH, |
michael@0 | 134 | HASH_AlgSHA512, |
michael@0 | 135 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 136 | unsigned int)) SHA512_EndRaw |
michael@0 | 137 | }, |
michael@0 | 138 | { SHA224_LENGTH, |
michael@0 | 139 | (void * (*)(void)) SHA224_NewContext, |
michael@0 | 140 | (void * (*)(void *)) null_hash_clone_context, |
michael@0 | 141 | (void (*)(void *, PRBool)) SHA224_DestroyContext, |
michael@0 | 142 | (void (*)(void *)) SHA224_Begin, |
michael@0 | 143 | (void (*)(void *, const unsigned char *, unsigned int)) SHA224_Update, |
michael@0 | 144 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 145 | unsigned int)) SHA224_End, |
michael@0 | 146 | SHA224_BLOCK_LENGTH, |
michael@0 | 147 | HASH_AlgSHA224, |
michael@0 | 148 | (void (*)(void *, unsigned char *, unsigned int *, |
michael@0 | 149 | unsigned int)) SHA224_EndRaw |
michael@0 | 150 | }, |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | const SECHashObject * |
michael@0 | 154 | HASH_GetRawHashObject(HASH_HashType hashType) |
michael@0 | 155 | { |
michael@0 | 156 | if (hashType < HASH_AlgNULL || hashType >= HASH_AlgTOTAL) { |
michael@0 | 157 | PORT_SetError(SEC_ERROR_INVALID_ARGS); |
michael@0 | 158 | return NULL; |
michael@0 | 159 | } |
michael@0 | 160 | return &SECRawHashObjects[hashType]; |
michael@0 | 161 | } |