65 const char KCodecs::Base64EncMap[64] =
67 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
68 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
69 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
70 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
71 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
72 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
73 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
74 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
77 const char KCodecs::Base64DecMap[128] =
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
85 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
86 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
88 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
89 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
90 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
92 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
93 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
94 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
97 const char KCodecs::UUEncMap[64] =
99 0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
100 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
101 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
102 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
103 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
104 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
105 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
106 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
109 const char KCodecs::UUDecMap[128] =
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
116 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
117 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
118 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
119 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
120 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
121 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
122 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
129 const char KCodecs::hexChars[16] =
131 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
132 '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'
135 const unsigned int KCodecs::maxQPLineLength = 70;
140 static int rikFindChar(
const char * _s,
const char c)
146 if ((0 == *s) || (c == *s))
break; ++s;
147 if ((0 == *s) || (c == *s))
break; ++s;
148 if ((0 == *s) || (c == *s))
break; ++s;
149 if ((0 == *s) || (c == *s))
break; ++s;
159 return TQCString (out.data(), out.size()+1);
167 TQByteArray in (str.length());
168 memcpy (in.data(), str.data(), str.length());
180 unsigned int lineLength;
183 const unsigned int length = in.size();
184 const unsigned int end = length - 1;
191 out.resize ((length*12)/10);
197 for (
unsigned int i = 0; i < length; i++)
199 unsigned char c (data[i]);
203 pos = cursor-out.data();
204 if (out.size()-pos < 16) {
205 out.resize(out.size()+4096);
206 cursor = out.data()+pos;
211 if ((c >= 33) && (c <= 126) && (
'=' != c))
225 ((i < end) && ((useCRLF && (
'\r' == data[i + 1]) && (
'\n' == data[i + 2]))
227 (!useCRLF && (
'\n' == data[i + 1]))))
243 else if ((useCRLF && (
'\r' == c) && (i < end) && (
'\n' == data[i + 1])) ||
244 (!useCRLF && (
'\n' == c)))
262 *cursor++ = hexChars[c / 16];
263 *cursor++ = hexChars[c % 16];
270 if ((lineLength > maxQPLineLength) && (i < end))
285 out.truncate(cursor - out.data());
292 return TQCString (out.data(), out.size()+1);
300 TQByteArray in (str.length());
301 memcpy (in.data(), str.data(), str.length());
314 const unsigned int length = in.size();
320 for (
unsigned int i = 0; i < length; i++)
328 char c1 = toupper(in[i + 1]);
329 char c2 = toupper(in[i + 2]);
331 if ((
'\n' == c1) || (
'\r' == c1 &&
'\n' == c2))
343 int hexChar0 = rikFindChar(hexChars, c1);
344 int hexChar1 = rikFindChar(hexChars, c2);
346 if (hexChar0 < 16 && hexChar1 < 16)
348 *cursor++ = char((hexChar0 * 16) | hexChar1);
360 out.truncate(cursor - out.data());
368 TQByteArray in (str.length());
369 memcpy( in.data(), str.data(), str.length() );
377 return TQCString( out.data(), out.size()+1 );
388 unsigned int sidx = 0;
389 unsigned int didx = 0;
390 const char* data = in.data();
391 const unsigned int len = in.size();
393 unsigned int out_len = ((len+2)/3)*4;
398 insertLFs = (insertLFs && out_len > 76);
400 out_len += ((out_len-1)/76);
403 out.resize( out_len );
412 if ( count && (count%76) == 0 )
416 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
417 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
418 (data[sidx] << 4) & 077];
419 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 |
420 (data[sidx+1] << 2) & 077];
421 out[didx++] = Base64EncMap[data[sidx+2] & 077];
428 if ( insertLFs && (count > 0) && (count%76) == 0 )
431 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
434 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
435 (data[sidx] << 4) & 077];
436 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077];
440 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077];
445 while (didx < out.size())
457 TQByteArray in( str.length() );
458 memcpy( in.data(), str.data(), str.length() );
466 return TQCString( out.data(), out.size()+1 );
475 unsigned int count = 0;
476 unsigned int len = in.size(), tail = len;
477 const char* data = in.data();
480 while ( count < len && (data[count] ==
'\n' || data[count] ==
'\r' ||
481 data[count] ==
'\t' || data[count] ==
' ') )
487 if ( strncasecmp(data+count,
"begin", 5) == 0 )
490 while ( count < len && data[count] !=
'\n' && data[count] !=
'\r' )
493 while ( count < len && (data[count] ==
'\n' || data[count] ==
'\r') )
497 tail = (len -= count);
503 && ( data[tail-1] ==
'=' || data[tail-1] ==
'\n' || data[tail-1] ==
'\r' ) )
504 if ( data[--tail] !=
'=' ) len = tail;
506 unsigned int outIdx = 0;
507 out.resize( (count=len) );
508 for (
unsigned int idx = 0; idx < count; idx++)
512 unsigned char ch = data[idx];
513 if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) ||
514 (ch > 96 && ch < 123) || ch ==
'+' || ch ==
'/' || ch ==
'=')
516 out[outIdx++] = Base64DecMap[ch];
528 len = (tail>(len/4)) ? tail-(len/4) : 0;
529 unsigned int sidx = 0, didx = 0;
534 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
535 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
536 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077));
543 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
546 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
549 if ( len == 0 || len < out.size() )
559 in.resize( str.length() );
560 memcpy( in.data(), str.data(), str.length() );
568 return TQCString( out.data(), out.size()+1 );
577 unsigned int sidx = 0;
578 unsigned int didx = 0;
579 unsigned int line_len = 45;
581 const char nl[] =
"\n";
582 const char* data = in.data();
583 const unsigned int nl_len = strlen(nl);
584 const unsigned int len = in.size();
586 out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) );
588 while (sidx+line_len < len)
591 out[didx++] = UUEncMap[line_len];
594 for (
unsigned int end = sidx+line_len; sidx < end; sidx += 3)
596 out[didx++] = UUEncMap[(data[sidx] >> 2) & 077];
597 out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |
598 (data[sidx] << 4) & 077];
599 out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 |
600 (data[sidx+1] << 2) & 077];
601 out[didx++] = UUEncMap[data[sidx+2] & 077];
607 memcpy(out.data()+didx, nl, nl_len);
612 out[didx++] = UUEncMap[len-sidx];
616 out[didx++] = UUEncMap[(data[sidx] >> 2) & 077];
617 out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |
618 (data[sidx] << 4) & 077];
619 out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 |
620 (data[sidx+1] << 2) & 077];
621 out[didx++] = UUEncMap[data[sidx+2] & 077];
627 out[didx++] = UUEncMap[(data[sidx] >> 2) & 077];
628 out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |
629 (data[sidx] << 4) & 077];
630 out[didx++] = UUEncMap[(data[sidx+1] << 2) & 077];
631 out[didx++] = UUEncMap[0];
635 out[didx++] = UUEncMap[(data[sidx] >> 2) & 077];
636 out[didx++] = UUEncMap[(data[sidx] << 4) & 077];
637 out[didx++] = UUEncMap[0];
638 out[didx++] = UUEncMap[0];
642 memcpy(out.data()+didx, nl, nl_len);
646 if ( didx != out.size() )
656 in.resize( str.length() );
657 memcpy( in.data(), str.data(), str.length() );
665 return TQCString( out.data(), out.size()+1 );
674 unsigned int sidx = 0;
675 unsigned int didx = 0;
676 unsigned int len = in.size();
677 unsigned int line_len, end;
678 const char* data = in.data();
681 unsigned int count = 0;
682 while ( count < len && (data[count] ==
'\n' || data[count] ==
'\r' ||
683 data[count] ==
'\t' || data[count] ==
' ') )
687 if ( strncasecmp( data+count,
"begin", 5) == 0 )
690 while ( count < len && data[count] !=
'\n' && data[count] !=
'\r' )
693 while ( count < len && (data[count] ==
'\n' || data[count] ==
'\r') )
701 out.resize( len/4*3 );
705 line_len = UUDecMap[ (
unsigned char) data[sidx++]];
712 A = UUDecMap[(
unsigned char) data[sidx]];
713 B = UUDecMap[(
unsigned char) data[sidx+1]];
714 C = UUDecMap[(
unsigned char) data[sidx+2]];
715 D = UUDecMap[(
unsigned char) data[sidx+3]];
716 out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) );
717 out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) );
718 out[didx++] = ( ((C << 6) & 255) | (D & 077) );
725 A = UUDecMap[(
unsigned char) data[sidx]];
726 B = UUDecMap[(
unsigned char) data[sidx+1]];
727 out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) );
732 B = UUDecMap[(
unsigned char) data[sidx+1]];
733 C = UUDecMap[(
unsigned char) data[sidx+2]];
734 out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) );
738 while (sidx < len && data[sidx] !=
'\n' && data[sidx] !=
'\r')
742 while (sidx < len && (data[sidx] ==
'\n' || data[sidx] ==
'\r'))
746 if ( hasLF && strncasecmp( data+sidx,
"end", 3) == 0 )
750 if ( didx < out.size() )
760 KMD5::KMD5(
const char *in,
int len)
766 KMD5::KMD5(
const TQByteArray& in)
772 KMD5::KMD5(
const TQCString& in)
780 update(in.data(),
int(in.size()));
785 update(in.data(),
int(in.length()));
791 len = tqstrlen(
reinterpret_cast<const char*
>(in));
797 kdWarning() <<
"KMD5::update called after state was finalized!" <<
endl;
802 TQ_UINT32 buffer_index;
803 TQ_UINT32 buffer_space;
804 TQ_UINT32 in_length =
static_cast<TQ_UINT32
>( len );
806 buffer_index =
static_cast<TQ_UINT32
>((m_count[0] >> 3) & 0x3F);
808 if ( (m_count[0] += (in_length << 3))<(in_length << 3) )
811 m_count[1] += (in_length >> 29);
812 buffer_space = 64 - buffer_index;
814 if (in_length >= buffer_space)
816 memcpy (m_buffer + buffer_index, in, buffer_space);
819 for (in_index = buffer_space; in_index + 63 < in_length;
821 transform (
reinterpret_cast<const unsigned char*
>(in+in_index));
828 memcpy(m_buffer+buffer_index, in+in_index, in_length-in_index);
836 while ((len=file.readBlock(
reinterpret_cast<char*
>(buffer),
sizeof(buffer))) > 0)
844 if (m_finalized)
return;
847 TQ_UINT32 index, padLen;
848 static const unsigned char PADDING[64]=
850 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
851 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
852 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
853 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
856 encode (bits, m_count, 8);
860 index =
static_cast<TQ_UINT32
>((m_count[0] >> 3) & 0x3f);
861 padLen = (index < 56) ? (56 - index) : (120 - index);
862 update (
reinterpret_cast<const char*
>(PADDING), padLen);
865 update (
reinterpret_cast<const char*
>(bits), 8);
868 encode (m_digest, m_state, 16);
872 memset ( (
void *)m_buffer, 0,
sizeof(*m_buffer));
881 return (0 == memcmp(
rawDigest(), digest,
sizeof(KMD5::Digest)));
887 return (0 == strcmp(
hexDigest().data(), hexdigest));
899 memcpy( bin, m_digest, 16 );
908 sprintf(s.data(),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
909 m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5],
910 m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11],
911 m_digest[12], m_digest[13], m_digest[14], m_digest[15]);
920 sprintf(s.data(),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
921 m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5],
922 m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11],
923 m_digest[12], m_digest[13], m_digest[14], m_digest[15]);
931 memcpy(ba.data(), m_digest, 16);
949 m_state[0] = 0x67452301;
950 m_state[1] = 0xefcdab89;
951 m_state[2] = 0x98badcfe;
952 m_state[3] = 0x10325476;
954 memset ( m_buffer, 0,
sizeof(*m_buffer));
955 memset ( m_digest, 0,
sizeof(*m_digest));
961 TQ_UINT32 a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], x[16];
963 decode (x, block, 64);
966 Q_ASSERT(!m_finalized);
969 FF (a, b, c, d, x[ 0], KMD5_S11, 0xd76aa478);
970 FF (d, a, b, c, x[ 1], KMD5_S12, 0xe8c7b756);
971 FF (c, d, a, b, x[ 2], KMD5_S13, 0x242070db);
972 FF (b, c, d, a, x[ 3], KMD5_S14, 0xc1bdceee);
973 FF (a, b, c, d, x[ 4], KMD5_S11, 0xf57c0faf);
974 FF (d, a, b, c, x[ 5], KMD5_S12, 0x4787c62a);
975 FF (c, d, a, b, x[ 6], KMD5_S13, 0xa8304613);
976 FF (b, c, d, a, x[ 7], KMD5_S14, 0xfd469501);
977 FF (a, b, c, d, x[ 8], KMD5_S11, 0x698098d8);
978 FF (d, a, b, c, x[ 9], KMD5_S12, 0x8b44f7af);
979 FF (c, d, a, b, x[10], KMD5_S13, 0xffff5bb1);
980 FF (b, c, d, a, x[11], KMD5_S14, 0x895cd7be);
981 FF (a, b, c, d, x[12], KMD5_S11, 0x6b901122);
982 FF (d, a, b, c, x[13], KMD5_S12, 0xfd987193);
983 FF (c, d, a, b, x[14], KMD5_S13, 0xa679438e);
984 FF (b, c, d, a, x[15], KMD5_S14, 0x49b40821);
987 GG (a, b, c, d, x[ 1], KMD5_S21, 0xf61e2562);
988 GG (d, a, b, c, x[ 6], KMD5_S22, 0xc040b340);
989 GG (c, d, a, b, x[11], KMD5_S23, 0x265e5a51);
990 GG (b, c, d, a, x[ 0], KMD5_S24, 0xe9b6c7aa);
991 GG (a, b, c, d, x[ 5], KMD5_S21, 0xd62f105d);
992 GG (d, a, b, c, x[10], KMD5_S22, 0x2441453);
993 GG (c, d, a, b, x[15], KMD5_S23, 0xd8a1e681);
994 GG (b, c, d, a, x[ 4], KMD5_S24, 0xe7d3fbc8);
995 GG (a, b, c, d, x[ 9], KMD5_S21, 0x21e1cde6);
996 GG (d, a, b, c, x[14], KMD5_S22, 0xc33707d6);
997 GG (c, d, a, b, x[ 3], KMD5_S23, 0xf4d50d87);
998 GG (b, c, d, a, x[ 8], KMD5_S24, 0x455a14ed);
999 GG (a, b, c, d, x[13], KMD5_S21, 0xa9e3e905);
1000 GG (d, a, b, c, x[ 2], KMD5_S22, 0xfcefa3f8);
1001 GG (c, d, a, b, x[ 7], KMD5_S23, 0x676f02d9);
1002 GG (b, c, d, a, x[12], KMD5_S24, 0x8d2a4c8a);
1005 HH (a, b, c, d, x[ 5], KMD5_S31, 0xfffa3942);
1006 HH (d, a, b, c, x[ 8], KMD5_S32, 0x8771f681);
1007 HH (c, d, a, b, x[11], KMD5_S33, 0x6d9d6122);
1008 HH (b, c, d, a, x[14], KMD5_S34, 0xfde5380c);
1009 HH (a, b, c, d, x[ 1], KMD5_S31, 0xa4beea44);
1010 HH (d, a, b, c, x[ 4], KMD5_S32, 0x4bdecfa9);
1011 HH (c, d, a, b, x[ 7], KMD5_S33, 0xf6bb4b60);
1012 HH (b, c, d, a, x[10], KMD5_S34, 0xbebfbc70);
1013 HH (a, b, c, d, x[13], KMD5_S31, 0x289b7ec6);
1014 HH (d, a, b, c, x[ 0], KMD5_S32, 0xeaa127fa);
1015 HH (c, d, a, b, x[ 3], KMD5_S33, 0xd4ef3085);
1016 HH (b, c, d, a, x[ 6], KMD5_S34, 0x4881d05);
1017 HH (a, b, c, d, x[ 9], KMD5_S31, 0xd9d4d039);
1018 HH (d, a, b, c, x[12], KMD5_S32, 0xe6db99e5);
1019 HH (c, d, a, b, x[15], KMD5_S33, 0x1fa27cf8);
1020 HH (b, c, d, a, x[ 2], KMD5_S34, 0xc4ac5665);
1023 II (a, b, c, d, x[ 0], KMD5_S41, 0xf4292244);
1024 II (d, a, b, c, x[ 7], KMD5_S42, 0x432aff97);
1025 II (c, d, a, b, x[14], KMD5_S43, 0xab9423a7);
1026 II (b, c, d, a, x[ 5], KMD5_S44, 0xfc93a039);
1027 II (a, b, c, d, x[12], KMD5_S41, 0x655b59c3);
1028 II (d, a, b, c, x[ 3], KMD5_S42, 0x8f0ccc92);
1029 II (c, d, a, b, x[10], KMD5_S43, 0xffeff47d);
1030 II (b, c, d, a, x[ 1], KMD5_S44, 0x85845dd1);
1031 II (a, b, c, d, x[ 8], KMD5_S41, 0x6fa87e4f);
1032 II (d, a, b, c, x[15], KMD5_S42, 0xfe2ce6e0);
1033 II (c, d, a, b, x[ 6], KMD5_S43, 0xa3014314);
1034 II (b, c, d, a, x[13], KMD5_S44, 0x4e0811a1);
1035 II (a, b, c, d, x[ 4], KMD5_S41, 0xf7537e82);
1036 II (d, a, b, c, x[11], KMD5_S42, 0xbd3af235);
1037 II (c, d, a, b, x[ 2], KMD5_S43, 0x2ad7d2bb);
1038 II (b, c, d, a, x[ 9], KMD5_S44, 0xeb86d391);
1045 memset (
static_cast<void *
>(x), 0,
sizeof(x) );
1048 inline TQ_UINT32 KMD5::rotate_left (TQ_UINT32 x, TQ_UINT32 n)
1050 return (x << n) | (x >> (32-n)) ;
1053 inline TQ_UINT32 KMD5::F (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1055 return (x & y) | (~x & z);
1058 inline TQ_UINT32 KMD5::G (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1060 return (x & z) | (y & ~z);
1063 inline TQ_UINT32 KMD5::H (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1068 inline TQ_UINT32 KMD5::I (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1070 return y ^ (x | ~z);
1073 void KMD5::FF ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1074 TQ_UINT32 x, TQ_UINT32 s, TQ_UINT32 ac )
1076 a += F(b, c, d) + x + ac;
1077 a = rotate_left (a, s) +b;
1080 void KMD5::GG ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1081 TQ_UINT32 x, TQ_UINT32 s, TQ_UINT32 ac)
1083 a += G(b, c, d) + x + ac;
1084 a = rotate_left (a, s) +b;
1087 void KMD5::HH ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1088 TQ_UINT32 x, TQ_UINT32 s, TQ_UINT32 ac )
1090 a += H(b, c, d) + x + ac;
1091 a = rotate_left (a, s) +b;
1094 void KMD5::II ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1095 TQ_UINT32 x, TQ_UINT32 s, TQ_UINT32 ac )
1097 a += I(b, c, d) + x + ac;
1098 a = rotate_left (a, s) +b;
1102 void KMD5::encode (
unsigned char* output, TQ_UINT32 *in, TQ_UINT32 len )
1104 #if !defined(WORDS_BIGENDIAN)
1105 memcpy(output, in, len);
1109 for (i = 0, j = 0; j < len; i++, j += 4)
1111 output[j] =
static_cast<TQ_UINT8
>((in[i] & 0xff));
1112 output[j+1] =
static_cast<TQ_UINT8
>(((in[i] >> 8) & 0xff));
1113 output[j+2] =
static_cast<TQ_UINT8
>(((in[i] >> 16) & 0xff));
1114 output[j+3] =
static_cast<TQ_UINT8
>(((in[i] >> 24) & 0xff));
1121 void KMD5::decode (TQ_UINT32 *output,
const unsigned char* in, TQ_UINT32 len)
1123 #if !defined(WORDS_BIGENDIAN)
1124 memcpy(output, in, len);
1128 for (i = 0, j = 0; j < len; i++, j += 4)
1129 output[i] =
static_cast<TQ_UINT32
>(in[j]) |
1130 (
static_cast<TQ_UINT32
>(in[j+1]) << 8) |
1131 (
static_cast<TQ_UINT32
>(in[j+2]) << 16) |
1132 (
static_cast<TQ_UINT32
>(in[j+3]) << 24);
1149 KMD4::KMD4(
const char *in,
int len)
1155 KMD4::KMD4(
const TQByteArray& in)
1161 KMD4::KMD4(
const TQCString& in)
1169 update(in.data(),
int(in.size()));
1174 update(in.data(),
int(in.length()));
1184 len = tqstrlen(
reinterpret_cast<const char*
>(in));
1190 kdWarning() <<
"KMD4::update called after state was finalized!" <<
endl;
1199 if ((m_count[0] = t + ((TQ_UINT32) len << 3)) < t)
1201 m_count[1] += len >> 29;
1203 t = (t >> 3) & 0x3f;
1209 TQ_UINT8 *p = &m_buffer[ t ];
1212 if ((TQ_UINT32)len < t)
1214 memcpy (p, in, len);
1218 byteReverse (m_buffer, 16);
1219 transform (m_state, (TQ_UINT32*) m_buffer);
1227 memcpy (m_buffer, in, 64);
1228 byteReverse (m_buffer, 16);
1229 transform (m_state, (TQ_UINT32 *) m_buffer);
1236 memcpy (m_buffer, in, len);
1244 while ((len=file.readBlock(
reinterpret_cast<char*
>(buffer),
sizeof(buffer))) > 0)
1247 return file.atEnd();
1260 count = (m_count[0] >> 3) & 0x3F;
1264 p = m_buffer + count;
1268 count = 64 - 1 - count;
1274 memset (p, 0, count);
1275 byteReverse (m_buffer, 16);
1276 transform (m_state, (TQ_UINT32*) m_buffer);
1279 memset (m_buffer, 0, 56);
1284 memset (p, 0, count - 8);
1286 byteReverse (m_buffer, 14);
1289 ((TQ_UINT32 *) m_buffer)[14] = m_count[0];
1290 ((TQ_UINT32 *) m_buffer)[15] = m_count[1];
1292 transform (m_state, (TQ_UINT32 *) m_buffer);
1293 byteReverse ((
unsigned char *) m_state, 4);
1295 memcpy (m_digest, m_state, 16);
1296 memset ( (
void *)m_buffer, 0,
sizeof(*m_buffer));
1304 return (0 == memcmp(
rawDigest(), digest,
sizeof(KMD4::Digest)));
1310 return (0 == strcmp(
hexDigest().data(), hexdigest));
1322 memcpy( bin, m_digest, 16 );
1330 sprintf(s.data(),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1331 m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5],
1332 m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11],
1333 m_digest[12], m_digest[13], m_digest[14], m_digest[15]);
1342 sprintf(s.data(),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1343 m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5],
1344 m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11],
1345 m_digest[12], m_digest[13], m_digest[14], m_digest[15]);
1353 memcpy(ba.data(), m_digest, 16);
1370 m_finalized =
false;
1372 m_state[0] = 0x67452301;
1373 m_state[1] = 0xefcdab89;
1374 m_state[2] = 0x98badcfe;
1375 m_state[3] = 0x10325476;
1380 memset ( m_buffer, 0,
sizeof(*m_buffer));
1381 memset ( m_digest, 0,
sizeof(*m_digest));
1386 inline TQ_UINT32 KMD4::rotate_left (TQ_UINT32 x, TQ_UINT32 n)
1388 return (x << n) | (x >> (32-n)) ;
1391 inline TQ_UINT32 KMD4::F (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1393 return (x & y) | (~x & z);
1396 inline TQ_UINT32 KMD4::G (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1398 return ((x) & (y)) | ((x) & (z)) | ((y) & (z));
1401 inline TQ_UINT32 KMD4::H (TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 z)
1406 inline void KMD4::FF ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1407 TQ_UINT32 x, TQ_UINT32 s )
1409 a += F(b, c, d) + x;
1410 a = rotate_left (a, s);
1413 inline void KMD4::GG ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1414 TQ_UINT32 x, TQ_UINT32 s)
1416 a += G(b, c, d) + x + (TQ_UINT32)0x5a827999;
1417 a = rotate_left (a, s);
1420 inline void KMD4::HH ( TQ_UINT32& a, TQ_UINT32 b, TQ_UINT32 c, TQ_UINT32 d,
1421 TQ_UINT32 x, TQ_UINT32 s )
1423 a += H(b, c, d) + x + (TQ_UINT32)0x6ed9eba1;
1424 a = rotate_left (a, s);
1427 void KMD4::byteReverse(
unsigned char *buf, TQ_UINT32 len )
1429 #ifdef WORDS_BIGENDIAN
1430 TQ_UINT32 *b = (TQ_UINT32*) buf;
1432 *b = ((((*b) & 0xff000000) >> 24) | (((*b) & 0x00ff0000) >> 8) |
1433 (((*b) & 0x0000ff00) << 8) | (((*b) & 0x000000ff) << 24));
1448 TQ_UINT32 a, b, c, d;
1455 FF (a, b, c, d, in[0], 3);
1456 FF (d, a, b, c, in[1], 7);
1457 FF (c, d, a, b, in[2], 11);
1458 FF (b, c, d, a, in[3], 19);
1459 FF (a, b, c, d, in[4], 3);
1460 FF (d, a, b, c, in[5], 7);
1461 FF (c, d, a, b, in[6], 11);
1462 FF (b, c, d, a, in[7], 19);
1463 FF (a, b, c, d, in[8], 3);
1464 FF (d, a, b, c, in[9], 7);
1465 FF (c, d, a, b, in[10], 11);
1466 FF (b, c, d, a, in[11], 19);
1467 FF (a, b, c, d, in[12], 3);
1468 FF (d, a, b, c, in[13], 7);
1469 FF (c, d, a, b, in[14], 11);
1470 FF (b, c, d, a, in[15], 19);
1472 GG (a, b, c, d, in[0], 3);
1473 GG (d, a, b, c, in[4], 5);
1474 GG (c, d, a, b, in[8], 9);
1475 GG (b, c, d, a, in[12], 13);
1476 GG (a, b, c, d, in[1], 3);
1477 GG (d, a, b, c, in[5], 5);
1478 GG (c, d, a, b, in[9], 9);
1479 GG (b, c, d, a, in[13], 13);
1480 GG (a, b, c, d, in[2], 3);
1481 GG (d, a, b, c, in[6], 5);
1482 GG (c, d, a, b, in[10], 9);
1483 GG (b, c, d, a, in[14], 13);
1484 GG (a, b, c, d, in[3], 3);
1485 GG (d, a, b, c, in[7], 5);
1486 GG (c, d, a, b, in[11], 9);
1487 GG (b, c, d, a, in[15], 13);
1489 HH (a, b, c, d, in[0], 3);
1490 HH (d, a, b, c, in[8], 9);
1491 HH (c, d, a, b, in[4], 11);
1492 HH (b, c, d, a, in[12], 15);
1493 HH (a, b, c, d, in[2], 3);
1494 HH (d, a, b, c, in[10], 9);
1495 HH (c, d, a, b, in[6], 11);
1496 HH (b, c, d, a, in[14], 15);
1497 HH (a, b, c, d, in[1], 3);
1498 HH (d, a, b, c, in[9], 9);
1499 HH (c, d, a, b, in[5], 11);
1500 HH (b, c, d, a, in[13], 15);
1501 HH (a, b, c, d, in[3], 3);
1502 HH (d, a, b, c, in[11], 9);
1503 HH (c, d, a, b, in[7], 11);
1504 HH (b, c, d, a, in[15], 15);
static TQCString quotedPrintableDecode(const TQByteArray &in)
Decodes a quoted-printable encoded data.
static TQCString base64Decode(const TQByteArray &in)
Decodes the given data that was encoded using the base64 algorithm.
static TQCString uuencode(const TQByteArray &in)
Encodes the given data using the uuencode algorithm.
static TQCString base64Encode(const TQByteArray &in, bool insertLFs=false)
Encodes the given data using the base64 algorithm.
static TQCString quotedPrintableEncode(const TQByteArray &in, bool useCRLF=true)
Encodes the given data using the quoted-printable algorithm.
static TQCString uudecode(const TQByteArray &in)
Decodes the given data using the uudecode algorithm.
void finalize()
finalizes the digest
TQCString hexDigest()
Returns the value of the calculated message digest in a hexadecimal representation.
TQCString base64Digest()
Returns the value of the calculated message digest in a base64-encoded representation.
const Digest & rawDigest()
void reset()
Calling this function will reset the calculated message digest.
bool verify(const KMD4::Digest &digest)
returns true if the calculated digest for the given message matches the given one.
void transform(TQ_UINT32 buf[4], TQ_UINT32 const in[16])
Performs the real update work.
void update(const char *in, int len=-1)
Updates the message to be digested.
void update(const char *in, int len=-1)
Updates the message to be digested.
const Digest & rawDigest()
TQCString base64Digest()
Returns the value of the calculated message digest in a base64-encoded representation.
void transform(const unsigned char buffer[64])
Performs the real update work.
TQCString hexDigest()
Returns the value of the calculated message digest in a hexadecimal representation.
void reset()
Calling this function will reset the calculated message digest.
void finalize()
finalizes the digest
bool verify(const KMD5::Digest &digest)
returns true if the calculated digest for the given message matches the given one.
kndbgstream & endl(kndbgstream &s)
Does nothing.