Back to index

lightning-sunbird  0.9+nobinonly
rawhash.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nspr.h"
00038 #include "sechash.h"
00039 #include "blapi.h"   /* below the line */
00040 #include "secerr.h"
00041 
00042 static void *
00043 null_hash_new_context(void)
00044 {
00045     return NULL;
00046 }
00047 
00048 static void *
00049 null_hash_clone_context(void *v)
00050 {
00051     PORT_Assert(v == NULL);
00052     return NULL;
00053 }
00054 
00055 static void
00056 null_hash_begin(void *v)
00057 {
00058 }
00059 
00060 static void
00061 null_hash_update(void *v, const unsigned char *input, unsigned int length)
00062 {
00063 }
00064 
00065 static void
00066 null_hash_end(void *v, unsigned char *output, unsigned int *outLen,
00067              unsigned int maxOut)
00068 {
00069     *outLen = 0;
00070 }
00071 
00072 static void
00073 null_hash_destroy_context(void *v, PRBool b)
00074 {
00075     PORT_Assert(v == NULL);
00076 }
00077 
00078 
00079 const SECHashObject SECRawHashObjects[] = {
00080   { 0,
00081     (void * (*)(void)) null_hash_new_context,
00082     (void * (*)(void *)) null_hash_clone_context,
00083     (void (*)(void *, PRBool)) null_hash_destroy_context,
00084     (void (*)(void *)) null_hash_begin,
00085     (void (*)(void *, const unsigned char *, unsigned int)) null_hash_update,
00086     (void (*)(void *, unsigned char *, unsigned int *,
00087              unsigned int)) null_hash_end,
00088     0,
00089     HASH_AlgNULL
00090   },
00091   { MD2_LENGTH,
00092     (void * (*)(void)) MD2_NewContext,
00093     (void * (*)(void *)) null_hash_clone_context,
00094     (void (*)(void *, PRBool)) MD2_DestroyContext,
00095     (void (*)(void *)) MD2_Begin,
00096     (void (*)(void *, const unsigned char *, unsigned int)) MD2_Update,
00097     (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD2_End,
00098     MD2_BLOCK_LENGTH,
00099     HASH_AlgMD2
00100   },
00101   { MD5_LENGTH,
00102     (void * (*)(void)) MD5_NewContext,
00103     (void * (*)(void *)) null_hash_clone_context,
00104     (void (*)(void *, PRBool)) MD5_DestroyContext,
00105     (void (*)(void *)) MD5_Begin,
00106     (void (*)(void *, const unsigned char *, unsigned int)) MD5_Update,
00107     (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) MD5_End,
00108     MD5_BLOCK_LENGTH,
00109     HASH_AlgMD5
00110   },
00111   { SHA1_LENGTH,
00112     (void * (*)(void)) SHA1_NewContext,
00113     (void * (*)(void *)) null_hash_clone_context,
00114     (void (*)(void *, PRBool)) SHA1_DestroyContext,
00115     (void (*)(void *)) SHA1_Begin,
00116     (void (*)(void *, const unsigned char *, unsigned int)) SHA1_Update,
00117     (void (*)(void *, unsigned char *, unsigned int *, unsigned int)) SHA1_End,
00118     SHA1_BLOCK_LENGTH,
00119     HASH_AlgSHA1
00120   },
00121   { SHA256_LENGTH,
00122     (void * (*)(void)) SHA256_NewContext,
00123     (void * (*)(void *)) null_hash_clone_context,
00124     (void (*)(void *, PRBool)) SHA256_DestroyContext,
00125     (void (*)(void *)) SHA256_Begin,
00126     (void (*)(void *, const unsigned char *, unsigned int)) SHA256_Update,
00127     (void (*)(void *, unsigned char *, unsigned int *,
00128              unsigned int)) SHA256_End,
00129     SHA256_BLOCK_LENGTH,
00130     HASH_AlgSHA256
00131   },
00132   { SHA384_LENGTH,
00133     (void * (*)(void)) SHA384_NewContext,
00134     (void * (*)(void *)) null_hash_clone_context,
00135     (void (*)(void *, PRBool)) SHA384_DestroyContext,
00136     (void (*)(void *)) SHA384_Begin,
00137     (void (*)(void *, const unsigned char *, unsigned int)) SHA384_Update,
00138     (void (*)(void *, unsigned char *, unsigned int *,
00139              unsigned int)) SHA384_End,
00140     SHA384_BLOCK_LENGTH,
00141     HASH_AlgSHA384
00142   },
00143   { SHA512_LENGTH,
00144     (void * (*)(void)) SHA512_NewContext,
00145     (void * (*)(void *)) null_hash_clone_context,
00146     (void (*)(void *, PRBool)) SHA512_DestroyContext,
00147     (void (*)(void *)) SHA512_Begin,
00148     (void (*)(void *, const unsigned char *, unsigned int)) SHA512_Update,
00149     (void (*)(void *, unsigned char *, unsigned int *,
00150              unsigned int)) SHA512_End,
00151     SHA512_BLOCK_LENGTH,
00152     HASH_AlgSHA512
00153   },
00154 };
00155 
00156 const SECHashObject *
00157 HASH_GetRawHashObject(HASH_HashType hashType)
00158 {
00159     if (hashType < HASH_AlgNULL || hashType >= HASH_AlgTOTAL) {
00160        PORT_SetError(SEC_ERROR_INVALID_ARGS);
00161        return NULL;
00162     }
00163     return &SECRawHashObjects[hashType];
00164 }