1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtCrypto module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
26 #include "qxthash_p.h"
29 \class QxtHash QxtHash
33 \brief Hashing funcions
36 qDebug()<<QxtHash(QxtHash::Md5,"foo").hash();
40 \fn QxtHash::QxtHash (Algorithm algo)
41 constructs a new hash with Algorithm \p algo
43 QxtHash::QxtHash (Algorithm algo)
45 QXT_INIT_PRIVATE(QxtHash);
50 \fn QxtHash::QxtHash (Algorithm algo, const QByteArray & data)
51 constructs a new hash with Algorithm \p algo and reads the data \p data
53 QxtHash::QxtHash (Algorithm algo, const QByteArray & data)
55 QXT_INIT_PRIVATE(QxtHash);
61 \fn void QxtHash::append ( const QByteArray & dt)
62 appends the data \p dt to the current data
65 void QxtHash::append ( const QByteArray & dt)
67 if (qxt_d().algo==Md5)
69 MD5Update(&qxt_d().md5ctx, (const unsigned char *)dt.constData(), dt.length());
71 else if (qxt_d().algo==Md4)
73 md4_update(&qxt_d().md4ctx, (const unsigned char *)dt.constData(), dt.length());
78 \fn void QxtHash::operator+= ( const QByteArray & dt)
79 appends the data \p dt to the current data
81 void QxtHash::operator+= ( const QByteArray & dt)
86 \fn void QxtHash::reset()
87 resets teh hash, deletes all data
91 if (qxt_d().algo==Md5)
93 MD5Init(&qxt_d().md5ctx);
95 else if (qxt_d().algo==Md4)
97 md4_init(&qxt_d().md4ctx);
101 \fn QByteArray QxtHash::hash()
102 returns the resulting hash
105 QByteArray QxtHash::hash()
109 if (qxt_d().algo==Md5)
112 MD5Final(&qxt_d().md5ctx, (unsigned char *)hs.data());
114 else if (qxt_d().algo==Md4)
116 hs.resize(MD4_RESULTLEN);
117 md4_final(&qxt_d().md4ctx, (unsigned char *)hs.data());
125 #include "thirdparty/md5.cpp"
126 #include "thirdparty/md4.cpp"