-rw-r--r-- | pwmanager/libcrypt/cipher/serpent.c | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/binentrygen.cpp | 5 | ||||
-rw-r--r-- | pwmanager/pwmanager/binentrygen.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/blowfish.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/blowfish.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/genpasswd.cpp | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/libgcryptif.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmexception.h | 3 | ||||
-rw-r--r-- | pwmanager/pwmanager/randomizer.h | 1 |
9 files changed, 17 insertions, 9 deletions
diff --git a/pwmanager/libcrypt/cipher/serpent.c b/pwmanager/libcrypt/cipher/serpent.c index d606d9f..fb5df20 100644 --- a/pwmanager/libcrypt/cipher/serpent.c +++ b/pwmanager/libcrypt/cipher/serpent.c @@ -612,143 +612,143 @@ serpent_subkeys_generate (serpent_key_t key, serpent_subkeys_t subkeys) u32_t k[132]; u32_t *w = &w_real[8]; int i, j; /* Initialize with key values. */ for (i = 0; i < 8; i++) w[i - 8] = key[i]; /* Expand to intermediate key using the affine recurrence. */ for (i = 0; i < 132; i++) w[i] = rol (w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i, 11); /* Calculate subkeys via S-Boxes, in bitslice mode. */ SBOX (3, w, k, 0); SBOX (2, w, k, 4); SBOX (1, w, k, 8); SBOX (0, w, k, 12); SBOX (7, w, k, 16); SBOX (6, w, k, 20); SBOX (5, w, k, 24); SBOX (4, w, k, 28); SBOX (3, w, k, 32); SBOX (2, w, k, 36); SBOX (1, w, k, 40); SBOX (0, w, k, 44); SBOX (7, w, k, 48); SBOX (6, w, k, 52); SBOX (5, w, k, 56); SBOX (4, w, k, 60); SBOX (3, w, k, 64); SBOX (2, w, k, 68); SBOX (1, w, k, 72); SBOX (0, w, k, 76); SBOX (7, w, k, 80); SBOX (6, w, k, 84); SBOX (5, w, k, 88); SBOX (4, w, k, 92); SBOX (3, w, k, 96); SBOX (2, w, k, 100); SBOX (1, w, k, 104); SBOX (0, w, k, 108); SBOX (7, w, k, 112); SBOX (6, w, k, 116); SBOX (5, w, k, 120); SBOX (4, w, k, 124); SBOX (3, w, k, 128); /* Renumber subkeys. */ for (i = 0; i < ROUNDS + 1; i++) for (j = 0; j < 4; j++) subkeys[i][j] = k[4 * i + j]; } /* Initialize CONTEXT with the key KEY of KEY_LENGTH bits. */ static void serpent_setkey_internal (serpent_context_t *context, const byte_t *key, unsigned int key_length) { serpent_key_t key_prepared; serpent_key_prepare (key, key_length, key_prepared); serpent_subkeys_generate (key_prepared, context->keys); _gcry_burn_stack (272 * sizeof (u32_t)); } - + static const char *serpent_test (void); /* Initialize CTX with the key KEY of KEY_LENGTH bytes. */ static gcry_err_code_t serpent_setkey (void *ctx, const byte_t *key, unsigned int key_length) { serpent_context_t *context = ctx; static const char *serpent_test_ret; static int serpent_init_done; gcry_err_code_t ret = GPG_ERR_NO_ERROR; if (! serpent_init_done) { /* Execute a self-test the first time, Serpent is used. */ - static const char *serpent_test (void); + serpent_test_ret = serpent_test (); if (serpent_test_ret) log_error ("Serpent test failure: %s\n", serpent_test_ret); serpent_init_done = 1; } if (serpent_test_ret) ret = GPG_ERR_SELFTEST_FAILED; else { serpent_setkey_internal (context, key, key_length); _gcry_burn_stack (sizeof (serpent_key_t)); } return ret; } static void serpent_encrypt_internal (serpent_context_t *context, const serpent_block_t input, serpent_block_t output) { serpent_block_t b, b_next; int round = 0; #ifdef WORDS_BIGENDIAN b[0] = byte_swap_32 (input[0]); b[1] = byte_swap_32 (input[1]); b[2] = byte_swap_32 (input[2]); b[3] = byte_swap_32 (input[3]); #else b[0] = input[0]; b[1] = input[1]; b[2] = input[2]; b[3] = input[3]; #endif ROUND (0, context->keys, b, b_next); ROUND (1, context->keys, b, b_next); ROUND (2, context->keys, b, b_next); ROUND (3, context->keys, b, b_next); ROUND (4, context->keys, b, b_next); ROUND (5, context->keys, b, b_next); ROUND (6, context->keys, b, b_next); ROUND (7, context->keys, b, b_next); ROUND (0, context->keys, b, b_next); ROUND (1, context->keys, b, b_next); ROUND (2, context->keys, b, b_next); ROUND (3, context->keys, b, b_next); ROUND (4, context->keys, b, b_next); ROUND (5, context->keys, b, b_next); ROUND (6, context->keys, b, b_next); ROUND (7, context->keys, b, b_next); ROUND (0, context->keys, b, b_next); ROUND (1, context->keys, b, b_next); ROUND (2, context->keys, b, b_next); ROUND (3, context->keys, b, b_next); ROUND (4, context->keys, b, b_next); ROUND (5, context->keys, b, b_next); ROUND (6, context->keys, b, b_next); ROUND (7, context->keys, b, b_next); ROUND (0, context->keys, b, b_next); ROUND (1, context->keys, b, b_next); ROUND (2, context->keys, b, b_next); diff --git a/pwmanager/pwmanager/binentrygen.cpp b/pwmanager/pwmanager/binentrygen.cpp index 7d5ae45..f156a5e 100644 --- a/pwmanager/pwmanager/binentrygen.cpp +++ b/pwmanager/pwmanager/binentrygen.cpp @@ -1,71 +1,72 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ - #include "binentrygen.h" #include "base64.h" -#include "pwmexception.h" +#include "pwmexception.h" +#include "globalstuff.h" void BinEntryGen::encode(const QByteArray &data, PwMDataItem *ret, DataType type) { ret->clear(); ret->name = tostr(static_cast<int>(type)); ret->binary = true; if (data.size() == 0) return; Base64 b64; string d(data.data(), data.size()); ret->pw = b64.encode(d); } void BinEntryGen::decode(const PwMDataItem &data, QByteArray *ret, DataType *type) { BUG_ON(!data.binary); int t = strtol(data.name.c_str(), 0, 10); *type = static_cast<DataType>(t); switch (*type) { case None: case KWalletMap: case KWalletStream: break; default: *type = None; } if (data.pw == "") { ret->fill(0); ret->resize(0); return; } Base64 b64; string d(b64.decode(data.pw)); ret->duplicate(d.c_str(), d.length()); } BinEntryGen::DataType BinEntryGen::binType(const PwMDataItem &data) { if (!data.binary) return None; int type = strtol(data.name.c_str(), 0, 10); return (static_cast<DataType>(type)); } + diff --git a/pwmanager/pwmanager/binentrygen.h b/pwmanager/pwmanager/binentrygen.h index a58cd42..49288aa 100644 --- a/pwmanager/pwmanager/binentrygen.h +++ b/pwmanager/pwmanager/binentrygen.h @@ -1,65 +1,65 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __BINENTRYGEN_H #define __BINENTRYGEN_H -#include "pwmdoc.h" #include <qcstring.h> +#include "pwmdoc.h" /** Binary entry generator. * This generator generates a normal struct PwMDataItem * from binary data (using base64 encoding). * This mechanism is used to support the binary interface functions * of the KWallet emulation, for example. * * The format of the encoded binary data as a PwMDataItem is as follows: * * PwMDataItem::desc contains the normal description string for * this entry. Nothing surprising. * PwMDataItem::name contains the "DataType" number in ascii format. * PwMDataItem::pw contains the base64 encoded data stream. * PwMDataItem::binary is always true for binary entries. * All other PwMDataItems are currently unused by BinEntryGen. */ class BinEntryGen { public: enum DataType { None = 0, KWalletMap, KWalletStream }; public: BinEntryGen() { } /** Encode the binary "data" and return it in "ret" */ void encode(const QByteArray &data, PwMDataItem *ret, DataType type); /** Decode the "data" and return it as binary "ret" */ void decode(const PwMDataItem &data, QByteArray *ret, DataType *type); /** Return the data type for this binary data item */ DataType binType(const PwMDataItem &data); }; #endif // __BINENTRYGEN_H diff --git a/pwmanager/pwmanager/blowfish.cpp b/pwmanager/pwmanager/blowfish.cpp index 2ca58ce..ee29756 100644 --- a/pwmanager/pwmanager/blowfish.cpp +++ b/pwmanager/pwmanager/blowfish.cpp @@ -1,112 +1,112 @@ /* 2003.05.02: Derived from libgcrypt-1.1.12 by Michael Buesch */ /* blowfish.c - Blowfish encryption * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser general Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * Libgcrypt 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * For a description of the algorithm, see: * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. * ISBN 0-471-11709-9. Pages 336 ff. */ /* Test values: * key "abcdefghijklmnopqrstuvwxyz"; * plain "BLOWFISH" * cipher 32 4E D0 FE F4 13 A2 03 * */ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include <string.h> #include <stdlib.h> -#include "blowfish.h" #include "globalstuff.h" +#include "blowfish.h" /* precomputed S boxes */ static const uint32_t ks0[256] = { 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A, 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239, 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3, 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE, 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7, 0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463, 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09, 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3, 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8, 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82, 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB, 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573, 0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B, 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8, 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4, 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C, 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299, 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9, 0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF, 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF, 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA, 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915, 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400, 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664, 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A }; static const uint32_t ks1[256] = { 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1, 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1, 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1, 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737, 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD, 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41, 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331, 0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF, 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87, 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C, 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908, diff --git a/pwmanager/pwmanager/blowfish.h b/pwmanager/pwmanager/blowfish.h index 5129eab..862cccb 100644 --- a/pwmanager/pwmanager/blowfish.h +++ b/pwmanager/pwmanager/blowfish.h @@ -1,110 +1,112 @@ /*************************************************************************** * * * copyright (C) 2003, 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * blowfish.c - Blowfish encryption * * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef BLOWFISH_H #define BLOWFISH_H -#include "pwmexception.h" +//#include "pwmexception.h" #ifndef _WIN32_ #include <stdint.h> #else #endif #include <string> using std::string; #define BLOWFISH_BLOCKSIZE 8 #define BLOWFISH_ROUNDS 16 #define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */ #ifndef _WIN32_ typedef uint8_t byte; #else #define uint8_t Q_UINT8 #define byte Q_UINT8 #define uint32_t Q_UINT32 #endif +//#include "pwmexception.h" + /** blowfish encryption algorithm. * Derived from libgcrypt-1.1.12 */ class Blowfish { struct BLOWFISH_context { uint32_t s0[256]; uint32_t s1[256]; uint32_t s2[256]; uint32_t s3[256]; uint32_t p[BLOWFISH_ROUNDS+2]; }; public: Blowfish() {} static bool selfTest(); /** set key to encrypt. if return == 1, it is a weak key. */ int bf_setkey( byte *key, unsigned int keylen ); /** encrypt inbuf and return it in outbuf. * inbuf and outbuf have to be: buf % 8 == 0 * You may check this with getPaddedLen() and pad with NULL. */ int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); /** decrypt inbuf and return it in outbuf. * inbuf and outbuf have to be: buf % 8 == 0 * You may check this with getPaddedLen() and pad with NULL. */ int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); /** returns the length, the sting has to be padded to */ static unsigned int getPaddedLen(unsigned int inLen) { return ((8 - (inLen % 8)) + inLen); } /** pad up to 8 bytes. */ static void padNull(string *buf); /** remove padded data */ static bool unpadNull(string *buf); protected: #if BLOWFISH_ROUNDS != 16 uint32_t function_F( uint32_t x) { uint16_t a, b, c, d; #ifdef BIG_ENDIAN_HOST a = ((byte *) & x)[0]; b = ((byte *) & x)[1]; c = ((byte *) & x)[2]; d = ((byte *) & x)[3]; #else a = ((byte *) & x)[3]; b = ((byte *) & x)[2]; c = ((byte *) & x)[1]; d = ((byte *) & x)[0]; #endif return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d]; } #endif void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p, uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3) { l ^= p[i]; #ifdef BIG_ENDIAN_HOST r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]]) ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]]; diff --git a/pwmanager/pwmanager/genpasswd.cpp b/pwmanager/pwmanager/genpasswd.cpp index b0cceff..41078b3 100644 --- a/pwmanager/pwmanager/genpasswd.cpp +++ b/pwmanager/pwmanager/genpasswd.cpp @@ -1,86 +1,87 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include "genpasswd.h" #include "pwmexception.h" #include "randomizer.h" +#include "globalstuff.h" /* how often can a char of the same charset be reused in order */ #define FILTER_MAX_CHARSET_REUSE 3 /* re-randomize all charsets on every iteration (0/1) */ #define RERAND_CHARSET 0 struct staticCharsetStruct { const char *lower; const char *upper; const char *num; const char *special; const char *blank; }; static struct staticCharsetStruct staticCharset = { "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "!\"§$%&/()=?,.-;:_+", " " }; GenPasswd::GenPasswd() : length (8) , useFilter (true) { dynCharset.setAutoDelete(true); } void GenPasswd::setCharset(bool lower, bool upper, bool num, bool special, bool blank, QString user) { unsigned int sanityCheck = 0; dynCharset_element *tmpElement; dynCharset.clear(); if (lower) { tmpElement = new dynCharset_element; tmpElement->refCnt = 0; tmpElement->data = staticCharset.lower; dynCharset.append(tmpElement); ++sanityCheck; } if (upper) { tmpElement = new dynCharset_element; tmpElement->refCnt = 0; tmpElement->data = staticCharset.upper; dynCharset.append(tmpElement); ++sanityCheck; } if (num) { tmpElement = new dynCharset_element; tmpElement->refCnt = 0; tmpElement->data = staticCharset.num; dynCharset.append(tmpElement); ++sanityCheck; } diff --git a/pwmanager/pwmanager/libgcryptif.h b/pwmanager/pwmanager/libgcryptif.h index 9a987a2..a08d678 100644 --- a/pwmanager/pwmanager/libgcryptif.h +++ b/pwmanager/pwmanager/libgcryptif.h @@ -1,106 +1,108 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * hashPassphrase() is derived from GnuPG and is * * Copyright (C) 1998, 1999, 2000, 2001, 2003 * * Free Software Foundation, Inc. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __LIBGCRYPTIF_H #define __LIBGCRYPTIF_H -#include "pwmexception.h" //#undef CONFIG_PWMANAGER_GCRY // for debugging only. #ifdef CONFIG_PWMANAGER_GCRY #include <stddef.h> #include <sys/types.h> #ifndef _WIN32_ #include <stdint.h> #else #define uint8_t Q_UINT8 #define byte Q_UINT8 #define uint32_t Q_UINT32 #endif #define STRING2KEY_SALTLEN 8 +#include "pwmexception.h" + + /** interface class for the libgcrypt cipher and hash algorithms * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding) */ class LibGCryptIf { protected: struct STRING2KEY { int mode; int hash_algo; uint8_t salt[STRING2KEY_SALTLEN]; uint32_t count; }; struct DEK { size_t keylen; uint8_t key[32]; // this is the largest used keylen (256 bit) }; public: LibGCryptIf() { } /** is libgcrypt available? */ static bool available() { return true; } /** encrypt data. _algo is the PWM_CRYPT_* ID * of the algorithm. */ PwMerror encrypt(unsigned char **outBuf, size_t *outBufLen, unsigned char *inBuf, size_t inBufLen, const unsigned char *key, size_t keylen, char _algo, char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase ); /** decrypt data. _algo is the PWM_CRYPT_* ID * of the algorithm. */ PwMerror decrypt(unsigned char **outBuf, size_t *outBufLen, const unsigned char *inBuf, size_t inBufLen, const unsigned char *key, size_t keylen, char _algo, char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase ); /** hash data. _algo is the PWM_HASH_* ID of the hash */ PwMerror hash(unsigned char **outBuf, size_t *outBufLen, const unsigned char *inBuf, size_t inBufLen, char _algo); /** returns the length of the hash. _algo is the PWM_HASH_* * id of the hash. returns 0 on error. */ unsigned int hashLength(char _algo); protected: /** returns the total buffer length */ size_t getBufLen(size_t inBufLen, size_t boundary) { return ((boundary - (inBufLen % boundary)) + inBufLen); diff --git a/pwmanager/pwmanager/pwmexception.h b/pwmanager/pwmanager/pwmexception.h index 301ebd7..7f5a3a6 100644 --- a/pwmanager/pwmanager/pwmexception.h +++ b/pwmanager/pwmanager/pwmexception.h @@ -1,87 +1,87 @@ /*************************************************************************** * * * copyright (C) 2003, 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __PWMEXCEPTION_H #define __PWMEXCEPTION_H -#include "globalstuff.h" +//#include "globalstuff.h" #include <iostream> #include <string> using std::string; using std::cerr; using std::cout; using std::endl; /* This is an internal function to reduce code-overhead * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use * these macros instead of calling this function directly. */ void pwmFatal(const char *id, const char *file, int line); /** Use PWM_ASSERT(condition) for debugging assertions. * "condition" is eaten up and replaced with a NOP * when debugging is disabled. * * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition), * but it does _not_ eat up "condition" and ensures that * condition is always evaluated. */ #ifdef PWM_ASSERT # undef PWM_ASSERT #endif #ifdef PWM_ASSERT_NOEAT # undef PWM_ASSERT_NOEAT #endif #ifdef PWM_DEBUG # define PWM_ASSERT(x) do { \ if (unlikely(!(x))) { \ cerr << "PWM_ASSERT failed: (" << #x \ << ") in " << __FILE__ \ << ":" << __LINE__ \ << endl; \ } \ } while (0) # define PWM_ASSERT_NOEAT(x) do { PWM_ASSERT(x); } while (0) #else // PWM_DEBUG # define PWM_ASSERT(x) do { } while (0) # define PWM_ASSERT_NOEAT(x) do { if (x) ; } while (0) #endif // PWM_DEBUG /** Insert a BUG() into code paths which clearly show * a bug in the code and which should, under normal * circumstances, never execute. */ #ifdef BUG # undef BUG #endif #define BUG() do { pwmFatal("BUG", __FILE__, __LINE__); } while (0) /** Use BUG_ON(condition) to print a bug-message if "condition" * is true. This is also enabled in non-debugging code. */ #ifdef BUG_ON # undef BUG_ON #endif #define BUG_ON(x) do { if (unlikely(x)) BUG(); } while (0) /** Insert a WARN() into code-paths which should not * execute normally, but if they do it's non-fatal. @@ -153,65 +153,66 @@ enum PwMerror { e_entryExists, e_categoryExists, e_maxAllowedEntr, // no more entries can be added. e_outOfMem, e_lock, // error while (un)locking e_docNotSaved, // doc wasn't saved to a file, yet. e_docIsEmpty, e_binEntry, e_normalEntry, e_syncError, e_generic }; /** can be used for general exception faults */ class PwMException { public: enum exceptionId { EX_GENERIC = 0, EX_OPEN, EX_CLOSE, EX_READ, EX_WRITE, EX_LOAD_MODULE, EX_PARSE }; public: PwMException(exceptionId id = EX_GENERIC, const char *message = "") { exId = id; exMsg = message; } exceptionId getId() { return exId; } const char* getMessage() { return exMsg; } protected: /** ID of this exception */ exceptionId exId; /** additional error-message for this exception */ const char *exMsg; }; void __printInfo(const string &msg); void __printWarn(const string &msg); void __printError(const string &msg); #ifdef PWM_DEBUG void __printDebug(const string &msg); # define printDebug(x) __printDebug(x) #else # define printDebug(x) do { } while (0) #endif #define printInfo(x) __printInfo(x) #define printWarn(x) __printWarn(x) #define printError(x) __printError(x) +#include "globalstuff.h" #endif // __PWMEXCEPTION_H diff --git a/pwmanager/pwmanager/randomizer.h b/pwmanager/pwmanager/randomizer.h index f2a6015..44cc28e 100644 --- a/pwmanager/pwmanager/randomizer.h +++ b/pwmanager/pwmanager/randomizer.h @@ -1,86 +1,87 @@ /*************************************************************************** * * * copyright (C) 2003, 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __RANDOMIZER_H #define __RANDOMIZER_H #include "pwmexception.h" +#include "globalstuff.h" #ifndef PWM_EMBEDDED #include <qmutex.h> #endif #include <string> using std::string; class QFile; /** Randomizer to get random values. * This class is thread-safe. * You should always use the instance returned by * obj() to use it. */ class Randomizer { public: Randomizer(); ~Randomizer(); static Randomizer * obj() { PWM_ASSERT(rndObj); return rndObj; } static void init() { PWM_ASSERT(!rndObj); rndObj = new Randomizer; } static void cleanup() { delete_ifnot_null(rndObj); } /** generate random char */ char genRndChar(); /** generate random int */ int genRndInt(); /** generate a random unsigned int */ unsigned int genRndUInt(); /** returns a buffer with random data */ string genRndBuf(size_t len); /** returns a buffer with random data */ void genRndBuf(unsigned char *buf, size_t len); protected: /** random-device-node (if available. Otherwise NULL) */ QFile *rndDev; #ifndef PWM_EMBEDDED /** mutex for accessing the public functions thread-save */ QMutex mutex; #endif /** seed value for fallback - rand_r() */ unsigned int seed; /** static Randomizer object returned by obj() */ static Randomizer *rndObj; }; #endif // __RANDOMIZER_H |