Kennwortmanager KeePassX Weiterentwicklung der Version 1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
keepassx1/src/crypto/arcfour.cpp

58 lines
1.5 KiB

/*
Copyright (C) 2003-2008 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "arcfour.h"
void CArcFour::setKey(quint8* key, uint length){
RawKey = key;
RawKeyLength = length;
}
void CArcFour::encrypt(const quint8* src, quint8* dst, uint length){
quint8 S[256];
quint32 w;
for(w = 0; w < 256; ++w)
S[w] = static_cast<quint8>(w); // Fill linearly
const quint8 btBufDep = static_cast<quint8>((length & 0xFF) << 1);
quint8 i = 0, j = 0, t;
quint32 k = 0;
for(w = 0; w < 256; ++w) // Key setup
{
j += S[w] + RawKey[k] + btBufDep;
t = S[i]; S[i] = S[j]; S[j] = t; // Swap entries
++k;
if(k == RawKeyLength) k = 0;
}
i = 0; j = 0;
for(w = 0; w < length; ++w) // Encrypt PT
{
++i;
j += S[i];
t = S[i]; S[i] = S[j]; S[j] = t; // Swap entries
t = S[i] + S[j]; // Generate random byte
dst[w] = src[w] ^ S[t]; // XOR with PT
}
}