kmdcodec.h
/*
Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL)
version 2 as published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992.
RSA Data Security, Inc. Created 1991. All rights reserved.
The KMD5 class is based on a C++ implementation of
"RSA Data Security, Inc. MD5 Message-Digest Algorithm" by
Mordechai T. Abzug, Copyright (c) 1995. This implementation
passes the test-suite as defined in RFC 1321.
The encoding and decoding utilities in KCodecs with the exception of
quoted-printable are based on the java implementation in HTTPClient
package by Ronald Tschalär Copyright (C) 1996-1999.
The quoted-printable codec as described in RFC 2045, section 6.7. is by
Rik Hemsley (C) 2001.
*/
#ifndef _KMDBASE_H
#define _KMDBASE_H
#define KBase64 KCodecs
#include <qglobal.h>
#include <qstring.h>
#include <qiodevice.h>
#include "kdelibs_export.h"
class KDECORE_EXPORT KCodecs
{
public:
static QCString quotedPrintableEncode(const QByteArray & in,
bool useCRLF = true);
static QCString quotedPrintableEncode(const QCString & str,
bool useCRLF = true);
static void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
bool useCRLF);
static QCString quotedPrintableDecode(const QByteArray & in);
static QCString quotedPrintableDecode(const QCString & str);
static void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
static QCString uuencode( const QByteArray& in );
static QCString uuencode( const QCString& str );
static void uuencode( const QByteArray& in, QByteArray& out );
static QCString uudecode( const QByteArray& in );
static QCString uudecode( const QCString& str );
static void uudecode( const QByteArray& in, QByteArray& out );
static QCString base64Encode( const QByteArray& in, bool insertLFs = false);
static QCString base64Encode( const QCString& str, bool insertLFs = false );
static void base64Encode( const QByteArray& in, QByteArray& out,
bool insertLFs = false );
static QCString base64Decode( const QByteArray& in );
static QCString base64Decode( const QCString& str );
static void base64Decode( const QByteArray& in, QByteArray& out );
private:
KCodecs();
private:
static const char UUEncMap[64];
static const char UUDecMap[128];
static const char Base64EncMap[64];
static const char Base64DecMap[128];
static const char hexChars[16];
static const unsigned int maxQPLineLength;
};
class KMD5Private;
class KDECORE_EXPORT KMD5
{
public:
typedef unsigned char Digest[16];
KMD5();
KMD5(const char* in, int len = -1);
KMD5(const QByteArray& a );
KMD5(const QCString& a );
void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
void update(const unsigned char* in, int len = -1);
void update(const QByteArray& in );
void update(const QCString& in );
bool update(QIODevice& file);
void reset();
const Digest& rawDigest ();
void rawDigest( KMD5::Digest& bin );
QCString hexDigest ();
void hexDigest(QCString&);
QCString base64Digest ();
bool verify( const KMD5::Digest& digest);
bool verify(const QCString&);
protected:
void transform( const unsigned char buffer[64] );
void finalize();
private:
KMD5(const KMD5& u);
KMD5& operator=(const KMD5& md);
void init();
void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len );
void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len );
Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s, Q_UINT32 ac );
void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s, Q_UINT32 ac );
void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s, Q_UINT32 ac );
void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s, Q_UINT32 ac );
private:
Q_UINT32 m_state[4];
Q_UINT32 m_count[2];
Q_UINT8 m_buffer[64];
Digest m_digest;
bool m_finalized;
KMD5Private* d;
};
class KDECORE_EXPORT KMD4
{
public:
typedef unsigned char Digest[16];
KMD4();
KMD4(const char* in, int len = -1);
KMD4(const QByteArray& a );
KMD4(const QCString& a );
void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
void update(const unsigned char* in, int len = -1);
void update(const QByteArray& in );
void update(const QCString& in );
bool update(QIODevice& file);
void reset();
const Digest& rawDigest ();
void rawDigest( KMD4::Digest& bin );
QCString hexDigest ();
void hexDigest(QCString&);
QCString base64Digest ();
bool verify( const KMD4::Digest& digest);
bool verify(const QCString&);
protected:
void transform( Q_UINT32 buf[4], Q_UINT32 const in[16] );
void finalize();
private:
KMD4(const KMD4& u);
KMD4& operator=(const KMD4& md);
void init();
void byteReverse( unsigned char *buf, Q_UINT32 len );
Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s );
void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s );
void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
Q_UINT32 s );
private:
Q_UINT32 m_state[4];
Q_UINT32 m_count[2];
Q_UINT8 m_buffer[64];
Digest m_digest;
bool m_finalized;
class KMD4Private;
KMD4Private* d;
};
#endif
KMD5::update
void update(const char *in, int len=-1)
Updates the message to be digested.
Definition: kmdcodec.h:442
KMD5
An adapted C++ implementation of RSA Data Securities MD5 algorithm.
Definition: kmdcodec.h:402
KMD4::update
void update(const char *in, int len=-1)
Updates the message to be digested.
Definition: kmdcodec.h:617
KCodecs
A wrapper class for the most commonly used encoding and decoding algorithms.
Definition: kmdcodec.h:74
KMD4
An adapted C++ implementation of the MD4 Message-Digest algorithm.
Definition: kmdcodec.h:577

KDE Home | KDE Accessibility Home | Description of Access Keys