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

📄 pplmd5.c

📁 用于linux环境下的SIP服务器
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  This is the ppl library. It provides a portable interface to usual OS features  Copyright (C) 2002,2003  WellX Telecom   - <partysip@wellx.com>  Copyright (C) 2002,2003  Aymeric MOIZARD - <jack@atosc.org>    The ppl library free software; you can redistribute it and/or modify  it under the terms of the GNU Lesser General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.    The ppl library is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License  along with the ppl library; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//* This code in the file pplmd5.c is taken from the rfc about digest   authentication. It is public code.   "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm"   Changes by Aymeric MOIZARD <jack@atosc.org>*/#include <ppl/ppl_md5.h>PPL_DECLARE (void) ppl_md5_hash_to_hex (HASH Bin, HASHHEX Hex){  unsigned short i;  unsigned char j;  for (i = 0; i < HASHLEN; i++)    {      j = (Bin[i] >> 4) & 0xf;      if (j <= 9)	Hex[i * 2] = (j + '0');      else	Hex[i * 2] = (j + 'a' - 10);      j = Bin[i] & 0xf;      if (j <= 9)	Hex[i * 2 + 1] = (j + '0');      else	Hex[i * 2 + 1] = (j + 'a' - 10);    };  Hex[HASHHEXLEN] = '\0';}/* calculate H(A1) as per spec */PPL_DECLARE (void)ppl_md5_DigestCalcHA1 (IN char *pszAlg,		       IN char *pszUserName,		       IN char *pszRealm,		       IN char *pszPassword,		       IN char *pszNonce,		       IN char *pszCNonce, OUT HASHHEX SessionKey){  MD5_CTX Md5Ctx;  HASH HA1;  ppl_MD5Init (&Md5Ctx);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszUserName,		 strlen (pszUserName));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszRealm, strlen (pszRealm));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszPassword,		 strlen (pszPassword));  ppl_MD5Final ((unsigned char *) HA1, &Md5Ctx);  if ((pszAlg != NULL) && strcasecmp (pszAlg, "md5-sess") == 0)    {      ppl_MD5Init (&Md5Ctx);      ppl_MD5Update (&Md5Ctx, (unsigned char *) HA1, HASHLEN);      ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);      ppl_MD5Update (&Md5Ctx, (unsigned char *) pszNonce, strlen (pszNonce));      ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);      ppl_MD5Update (&Md5Ctx, (unsigned char *) pszCNonce,		     strlen (pszCNonce));      ppl_MD5Final ((unsigned char *) HA1, &Md5Ctx);    };  ppl_md5_hash_to_hex (HA1, SessionKey);}PPL_DECLARE (void)ppl_md5_DigestCalcResponse (IN HASHHEX HA1,	/* H(A1) */			    IN char *pszNonce,	/* nonce from server */			    IN char *pszNonceCount,	/* 8 hex digits */			    IN char *pszCNonce,	/* client nonce */			    IN char *pszQop,	/* qop-value: "", "auth", "auth-						   int" */			    IN char *pszMethod,	/* method from the request */			    IN char *pszDigestUri,	/* requested URL */			    IN HASHHEX HEntity,	/* H(entity body) if qop="auth-i						   nt" */			    OUT HASHHEX Response	/* request-digest or response-di							   gest */  ){  MD5_CTX Md5Ctx;  HASH HA2;  HASH RespHash;  HASHHEX HA2Hex;  /* calculate H(A2) */  ppl_MD5Init (&Md5Ctx);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszMethod, strlen (pszMethod));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszDigestUri,		 strlen (pszDigestUri));  if (pszQop == NULL)    {      goto auth_withoutqop;    }  else if (0 == strcmp (pszQop, "auth-int"))    {      goto auth_withqop;    }  else if (0 == strcmp (pszQop, "auth"))    {      goto auth_withqop;    }auth_withoutqop:  ppl_MD5Final ((unsigned char *) HA2, &Md5Ctx);  ppl_md5_hash_to_hex (HA2, HA2Hex);  /* calculate response */  ppl_MD5Init (&Md5Ctx);  ppl_MD5Update (&Md5Ctx, (unsigned char *) HA1, HASHHEXLEN);  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszNonce, strlen (pszNonce));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  goto end;auth_withqop:  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) HEntity, HASHHEXLEN);  ppl_MD5Final ((unsigned char *) HA2, &Md5Ctx);  ppl_md5_hash_to_hex (HA2, HA2Hex);  /* calculate response */  ppl_MD5Init (&Md5Ctx);  ppl_MD5Update (&Md5Ctx, (unsigned char *) HA1, HASHHEXLEN);  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszNonce, strlen (pszNonce));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszNonceCount,		 strlen (pszNonceCount));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszCNonce, strlen (pszCNonce));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);  ppl_MD5Update (&Md5Ctx, (unsigned char *) pszQop, strlen (pszQop));  ppl_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);end:  ppl_MD5Update (&Md5Ctx, (unsigned char *) HA2Hex, HASHHEXLEN);  ppl_MD5Final ((unsigned char *) RespHash, &Md5Ctx);  ppl_md5_hash_to_hex (RespHash, Response);}/* This is a modified version from Aymeric MOIZARD   of MD5C.C provided by RSA Data Security, Inc.*//* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm *//* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. Allrights reserved.License to copy and use this software is granted provided that itis identified as the "RSA Data Security, Inc. MD5 Message-DigestAlgorithm" in all material mentioning or referencing this softwareor this function.License is also granted to make and use derivative works providedthat such works are identified as "derived from the RSA DataSecurity, Inc. MD5 Message-Digest Algorithm" in all materialmentioning or referencing the derived work.RSA Data Security, Inc. makes no representations concerning eitherthe merchantability of this software or the suitability of thissoftware for any particular purpose. It is provided "as is"without express or implied warranty of any kind.These notices must be retained in any copies of any part of thisdocumentation and/or software. *//* Constants for MD5Transform routine. */#define S11 7#define S12 12#define S13 17#define S14 22#define S21 5#define S22 9#define S23 14#define S24 20#define S31 4#define S32 11#define S33 16#define S34 23#define S41 6#define S42 10#define S43 15#define S44 21static void MD5Transform PROTO_LIST ((UINT4[4], unsigned char[64]));static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));static unsigned char PADDING[64] = {  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};/* F, G, H and I are basic MD5 functions. */#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))#define H(x, y, z) ((x) ^ (y) ^ (z))#define I(x, y, z) ((y) ^ ((x) | (~z)))/* ROTATE_LEFT rotates x left n bits. */#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.Rotation is separate from addition to prevent recomputation. */#define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \  }#define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \  }#define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \

⌨️ 快捷键说明

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