⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hmac.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/hmac.c,v 1.3 2003/01/16 18:18:55 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: hmac.c,v $ * Revision 1.3  2003/01/16 18:18:55  josh * directory structure shifting * * Revision 1.2  2001/11/06 22:15:51  tneale * Fixed for newest file layout * * Revision 1.1.1.1  2001/11/05 17:48:39  tneale * Tornado shuffle * * Revision 1.6  2001/01/19 22:21:30  paul * Update copyright. * * Revision 1.5  2000/03/17 00:16:53  meister * Update copyright message * * Revision 1.4  1998/09/04 14:02:28  sar * Convert some ints to unsigned ints to make some compliers happier * * Revision 1.3  1998/06/21 21:40:55  sar * More type checking stuff to keep compilers happy * * Revision 1.2  1998/06/18 04:11:23  sar * clean u psome type info, make the lengths be bits32_t * * Revision 1.1  1998/05/22 18:03:07  sar * HMAC functions, this code is arranged so that the user can insert their * own digest functions such as MD5 or SHA * *//* [clearcase]modification history-------------------01b,20apr05,job  update copyright notices01a,11dec03,job  fix copyright statements*/#ifndef EPILOGUE_INSTALL_H#include <wrn/wm/common/install.h>#endif /* EPILOGUE_INSTALL_H */#ifndef	EPILOGUE_TYPES_H#include <wrn/wm/common/types.h>#endif /* EPILOGUE_TYPES_H */#ifndef COMMON_CONFIG_H#include <wrn/wm/common/config.h>#endif /* COMMON_CONFIG_H */#ifndef COMMON_GLUE_H#include <wrn/wm/common/glue.h>#endif /* COMMON_GLUE_H */#include <wrn/wm/common/hmac.h>/* initialize an HMAC context */void InitHmacCTX (HMAC_CTX         *ctx,                   hashfcn_init_t    init,		  hashfcn_update_t  update,                   hashfcn_final_t   final,		  bits32_t          hashsiz){    ctx->hmac_hashinit    = init;    ctx->hmac_hashupdate  = update;    ctx->hmac_hashfinal   = final;    ctx->hmac_hashlen     = hashsiz;}void hmac_init (HMAC_CTX *ctx,		bits8_t  *key,		bits32_t  keylen){    bits8_t xk [64];    unsigned int i;    /*      * if we have more than 64 bytes of key, hash that first using the      * given hash algorithm.      */    if (keylen > 64)     {         (*(ctx->hmac_hashinit))(ctx->hmac_state);        (*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);        (*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);        /*  K XOR input pad of 0x36's */        for (i = 0 ; i < ctx->hmac_hashlen; i++)             xk [i] ^= ((bits8_t) 0x36);        MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x36,		64 - (unsigned int)ctx->hmac_hashlen);    }    else    {      /*  K XOR input pad of 0x36's */      for (i = 0 ; i < keylen; i++)           xk [i] = key [i] ^ ((bits8_t) 0x36);      MEMSET (xk + (unsigned int)keylen, 0x36, 64 - (unsigned int)keylen);    }    (*(ctx->hmac_hashinit))(ctx->hmac_state);    (*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);}void hmac_update (HMAC_CTX *ctx,		  bits8_t  *data,		  bits32_t  len){     (*(ctx->hmac_hashupdate))(ctx->hmac_state, data, len);}void hmac_final (HMAC_CTX *ctx,		 bits8_t  *key,		 bits32_t  keylen,		 bits8_t  *output){    bits8_t xk [64];    unsigned int i;    (*(ctx->hmac_hashfinal))(ctx->hmac_state, ctx->hmac_tmp);    /*      * if we have more than 64 bytes of key, hash that first using the      * given hash algorithm.      */    if (keylen > 64)     {         (*(ctx->hmac_hashinit))(ctx->hmac_state);        (*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);        (*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);        /*  K XOR output pad of 0x5c's */        for (i = 0 ; i < ctx->hmac_hashlen; i++)             xk [i] ^= ((bits8_t) 0x5c);        MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x5c,		64 - (unsigned int)ctx->hmac_hashlen);    }    else    {      /*  K XOR output pad of 0x5c's */      for (i = 0 ; i < keylen; i++)           xk [i] = key [i] ^ ((bits8_t) 0x5c);      MEMSET (xk + (unsigned int)keylen, 0x5c, 64 - (unsigned int)keylen);    }    (*(ctx->hmac_hashinit))(ctx->hmac_state);    (*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);    (*(ctx->hmac_hashupdate))(ctx->hmac_state, ctx->hmac_tmp,                               ctx->hmac_hashlen);    (*(ctx->hmac_hashfinal))(ctx->hmac_state, output);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -