Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Digest Authentication implementation of http Protocol

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Referenc

Http://blog.csdn.net/jszj/article/details/8918967

Https://wenku.baidu.com/view/22be2dcf83d049649b6658ff.html

Http://blog.csdn.net/i_lovefish/article/details/9816783

Md5.h

# ifndef MD5_H

# define MD5_H

Typedef struct

{

Unsigned int count [2]

Unsigned int state [4]

Unsigned char buffer [64]

} MD5_CTX

# define F (x & y) ((x & y) | (~ x & z))

# define G (x & z) ((x & z) | (y & ~ z))

# define H (x ^ y ^ z) (x ^ y ^ z)

# define I (x ~ Z) (y ^ (x | ~ z))

# define ROTATE_LEFT (xQuery n) ((x > (32m)

# define FF (a _ c _

{\\

A + = F (brecrine cpene d) + x + ac;\

A = ROTATE_LEFT (afors);\

A + = b;\

}

# define GG (a _ c _

{\\

A + = G (brecrine cpene d) + x + ac;\

A = ROTATE_LEFT (afors);\

A + = b;\

}

# define HH (a _ c _

{\\

A + = H (brecrine cpene d) + x + ac;\

A = ROTATE_LEFT (afors);\

A + = b;\

}

# define II (a _ c _

{\\

A + = I (brecrine cpene d) + x + ac;\

A = ROTATE_LEFT (afors);\

A + = b;\

}

Void MD5Init (MD5_CTX * context)

Void MD5Update (MD5_CTX * context, unsigned char * input, unsigned int inputlen)

Void MD5Final (MD5_CTX * context, unsigned char digest [16])

Void MD5Transform (unsigned int state [4], unsigned char block [64])

Void MD5Encode (unsigned char * output, unsigned int * input, unsigned int len)

Void MD5Decode (unsigned int * output, unsigned char * input, unsigned int len)

# endif

Md5.cpp

# include

# include "md5.h"

Unsigned char PADDING [] = {0x80pc0re0re0re0re0re0re0pl 0pl 0pl 0pl 0pr 0pl 0pl 0pr 0pl 0pl 0pr 0pr 0pl 0pl 0pr 0pl 0pl 0pl 0pr 0pl 0pl 0pl 0pr 0pr 0pl 0pl 0pl 0pr 0pr 0pl 0pl 0pl 0pr 0pr 0pr 0pl 0pr 0pr 0pr 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}

Void MD5Init (MD5_CTX * context)

{

Context- > count [0] = 0

Context- > count [1] = 0

Context- > state [0] = 0x67452301

Context- > state [1] = 0xEFCDAB89

Context- > state [2] = 0x98BADCFE

Context- > state [3] = 0x10325476

}

Void MD5Update (MD5_CTX * context, unsigned char * input, unsigned int inputlen)

{

Unsigned int i = 0, index = 0, partlen = 0

Index = (context- > count [0] > > 3) & 0x3F

Partlen = 64-index

Context- > count [0] + = inputlen count [0]

< (inputlen count[1]++; context->

Count [1] + = inputlen > > 29

If (inputlen > = partlen)

{

Memcpy (& context- > buffer [index], input, partlen)

MD5Transform (context- > state, context- > buffer)

For (I = partlen; I + 64 state, & input [I])

Index = 0

}

Else

{

I = 0

}

Memcpy (& context- > buffer [index], & input [I], inputlen-I)

}

Void MD5Final (MD5_CTX * context, unsigned char digest [16])

{

Unsigned int index = 0, padlen = 0

Unsigned char bits [8]

Index = (context- > count [0] > > 3) & 0x3F

Padlen = (index

< 56) ? (56 - index) : (120 - index); MD5Encode(bits, context->

Count, 8)

MD5Update (context, PADDING, padlen)

MD5Update (context, bits, 8)

MD5Encode (digest, context- > state, 16)

}

Void MD5Encode (unsigned char * output, unsigned int * input, unsigned int len)

{

Unsigned int i = 0, j = 0

While (j)

< len) { output[j] = input[i] & 0xFF; output[j + 1] = (input[i] >

> 8) & 0xFF

Output [j + 2] = (input [I] > > 16) & 0xFF

Output [j + 3] = (input [I] > > 24) & 0xFF

ITunes +

J + = 4

}

}

Void MD5Decode (unsigned int * output, unsigned char * input, unsigned int len)

{

Unsigned int i = 0, j = 0

While (j < len)

{

Output [I] = (input [j]) |

(input [j + 1]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report