alghmac.h (2255B)
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 #ifndef _ALGHMAC_H_ 6 #define _ALGHMAC_H_ 7 8 typedef struct HMACContextStr HMACContext; 9 10 SEC_BEGIN_PROTOS 11 12 /* destroy HMAC context */ 13 extern void 14 HMAC_Destroy(HMACContext *cx, PRBool freeit); 15 16 /* create HMAC context 17 * hash_obj hash object from SECRawHashObjects[] 18 * secret the secret with which the HMAC is performed. 19 * secret_len the length of the secret. 20 * isFIPS true if conforming to FIPS 198. 21 * 22 * NULL is returned if an error occurs. 23 */ 24 extern HMACContext * 25 HMAC_Create(const SECHashObject *hash_obj, const unsigned char *secret, 26 unsigned int secret_len, PRBool isFIPS); 27 28 /* like HMAC_Create, except caller allocates HMACContext. */ 29 SECStatus 30 HMAC_Init(HMACContext *cx, const SECHashObject *hash_obj, 31 const unsigned char *secret, unsigned int secret_len, PRBool isFIPS); 32 33 /* like HMAC_Init, except caller passes in an existing context 34 * previously used by either HMAC_Create or HMAC_Init. */ 35 SECStatus 36 HMAC_ReInit(HMACContext *cx, const SECHashObject *hash_obj, 37 const unsigned char *secret, unsigned int secret_len, PRBool isFIPS); 38 39 /* reset HMAC for a fresh round */ 40 extern void 41 HMAC_Begin(HMACContext *cx); 42 43 /* update HMAC 44 * cx HMAC Context 45 * data the data to perform HMAC on 46 * data_len the length of the data to process 47 */ 48 extern void 49 HMAC_Update(HMACContext *cx, const unsigned char *data, unsigned int data_len); 50 51 /* Finish HMAC -- place the results within result 52 * cx HMAC context 53 * result buffer for resulting hmac'd data 54 * result_len where the resultant hmac length is stored 55 * max_result_len maximum possible length that can be stored in result 56 */ 57 extern SECStatus 58 HMAC_Finish(HMACContext *cx, unsigned char *result, unsigned int *result_len, 59 unsigned int max_result_len); 60 61 /* clone a copy of the HMAC state. this is usefult when you would 62 * need to keep a running hmac but also need to extract portions 63 * partway through the process. 64 */ 65 extern HMACContext * 66 HMAC_Clone(HMACContext *cx); 67 68 SEC_END_PROTOS 69 70 #endif