File: wephash.cpp

package info (click to toggle)
plasma-widget-networkmanagement 0.1~svn1141976-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,812 kB
  • ctags: 3,700
  • sloc: cpp: 28,962; xml: 471; makefile: 21; sh: 16; python: 9
file content (45 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*  This file is part of the KDE project
    Copyright (C) 2008 Christopher Blauvelt <cblauvelt@gmail.com>

    Based on code from Dan Williams <dcbw@redhat.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include <QByteArray>
#include <QCryptographicHash>

#include "wephash.h"

QByteArray wep128PassphraseHash(QByteArray input)
{
    QByteArray md5_data, digest;

    if (input.isEmpty()) {
        return QByteArray();
    }

    md5_data.reserve(65);
    digest.reserve(16);

    // Get at least 64 bytes
    for (int i = 0; i < 64; i++)
        md5_data[i] = input[i % input.length()];

    digest = QCryptographicHash::hash(md5_data, QCryptographicHash::Md5);
    //convert to hex and only pass the first 26 chars for 128-bit encryption
    return digest.toHex().left(26);
}