Added pronounceable password generator

Improved RNG seeding on Windows
Updated AES implementation
Removed SHA1 implementation, replaced by QCryptographicHash
Replaced ARC4 implementation by the one from KeePass 1.11
Some cleanup

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@216 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent 455e68ff60
commit 636f3b8af6
  1. 2
      src/Database.h
  2. 58
      src/Kdb3Database.cpp
  3. 6
      src/Kdb3Database.h
  4. 4
      src/KpxConfig.h
  5. 404
      src/apg/convert.c
  6. 43
      src/apg/convert.h
  7. 49
      src/apg/owntypes.h
  8. 2289
      src/apg/pronpass.c
  9. 92
      src/apg/pronpass.h
  10. 162
      src/apg/randpass.c
  11. 70
      src/apg/randpass.h
  12. 51
      src/apg/smbl.h
  13. 139
      src/crypto/aes.h
  14. 161
      src/crypto/aes_edefs.h
  15. 280
      src/crypto/aes_modes.c
  16. 286
      src/crypto/aes_tdefs.h
  17. 106
      src/crypto/aescpp.h
  18. 61
      src/crypto/aescrypt.c
  19. 209
      src/crypto/aeskey.c
  20. 532
      src/crypto/aesopt.h
  21. 73
      src/crypto/aestab.c
  22. 75
      src/crypto/aestab.h
  23. 114
      src/crypto/arcfour.cpp
  24. 60
      src/crypto/arcfour.h
  25. 258
      src/crypto/sha1.cpp
  26. 119
      src/crypto/sha1.h
  27. 2
      src/crypto/yarrow.cpp
  28. 14
      src/dialogs/PasswordDlg.cpp
  29. 1
      src/dialogs/PasswordDlg.h
  30. 342
      src/dialogs/PasswordGenDlg.cpp
  31. 23
      src/dialogs/PasswordGenDlg.h
  32. 513
      src/forms/PasswordGenDlg.ui
  33. 28
      src/import/Import_PwManager.cpp
  34. 8
      src/keepassx.h
  35. 3
      src/lib/GroupView.cpp
  36. 488
      src/lib/IniReader.cpp
  37. 182
      src/lib/IniReader.h
  38. 29
      src/lib/SecString.cpp
  39. 4
      src/lib/SecString.h
  40. 68
      src/lib/random.cpp
  41. 22
      src/lib/random.h
  42. 16
      src/lib/tools.cpp
  43. 1
      src/lib/tools.h
  44. 1
      src/main_macx.cpp
  45. 2
      src/mainwindow.cpp
  46. 356
      src/src.pro

@ -110,7 +110,6 @@ The IEntryHandle interface provides access to Entry data structures without usin
class IEntryHandle{
public:
virtual void setImage(const quint32& ImageID)=0;
virtual void setOldImage(const quint32& OldImgID)=0;
virtual void setTitle(const QString& Title)=0;
virtual void setUrl(const QString& URL)=0;
virtual void setUsername(const QString& Username)=0;
@ -126,7 +125,6 @@ public:
virtual KpxUuid uuid()=0;
virtual IGroupHandle* group()=0;
virtual quint32 image()=0;
virtual quint32 oldImage()=0;
virtual QString title()=0;
virtual QString url()=0;
virtual QString username()=0;

@ -64,13 +64,13 @@ void Kdb3Database::removeIcon(int id){
CustomIcons.removeAt(id); // .isNull()==true
for(int i=0;i<Entries.size();i++){
if(Entries[i].Image == id+builtinIcons())
Entries[i].Image=Entries[i].OldImage;
Entries[i].Image=0;
if(Entries[i].Image>id+builtinIcons())
Entries[i].Image--;
}
for(int i=0;i<Groups.size();i++){
if(Groups[i].Image == id+builtinIcons())
Groups[i].Image=Groups[i].OldImage;
Groups[i].Image=0;
if(Groups[i].Image>id+builtinIcons())
Groups[i].Image--;
}
@ -165,10 +165,8 @@ void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
memcpyFromLEnd32(&Icon,dta.data()+offset);
offset+=4;
StdEntry* entry=getEntry(EntryUuid);
if(entry){
entry->OldImage=entry->Image;
if(entry)
entry->Image=Icon+BUILTIN_ICONS;
}
}
for(int i=0;i<NumGroups;i++){
quint32 GroupId,Icon;
@ -177,10 +175,8 @@ void Kdb3Database::parseCustomIconsMetaStream(const QByteArray& dta){
memcpyFromLEnd32(&Icon,dta.data()+offset);
offset+=4;
StdGroup* Group=getGroup(GroupId);
if(Group){
Group->OldImage=Group->Image;
if(Group)
Group->Image=Icon+BUILTIN_ICONS;
}
}
return;
}
@ -224,7 +220,6 @@ void Kdb3Database::parseCustomIconsMetaStreamV3(const QByteArray& dta){
offset+=4;
StdEntry* entry=getEntry(EntryUuid);
if(entry){
entry->OldImage=entry->Image;
if (Icon>=65)
entry->Image=Icon+4; // Since v0.3.2 the BUILTIN_ICONS number has increased by 4
else
@ -239,8 +234,6 @@ void Kdb3Database::parseCustomIconsMetaStreamV3(const QByteArray& dta){
offset+=4;
StdGroup* Group=getGroup(GroupId);
if(Group){
Group->OldImage=Group->Image;
Group->Image=Icon;
if (Group->Image>=65)
Group->Image=Icon+4; // Since v0.3.2 the BUILTIN_ICONS number has increased by 4
else
@ -272,7 +265,6 @@ void Kdb3Database::createGroupTreeStateMetaStream(StdEntry* e){
e->Username="SYSTEM";
e->Comment="KPX_GROUP_TREE_STATE";
e->Url="$";
e->OldImage=0;
e->Image=0;
if(Groups.size())e->GroupId=Groups[0].Id;
QByteArray bin;
@ -317,7 +309,6 @@ switch(FieldType)
break;
case 0x0003:
memcpyFromLEnd32(&entry->Image, (char*)pData);
entry->OldImage=entry->Image;
break;
case 0x0004:
entry->Title=QString::fromUtf8((char*)pData);
@ -388,7 +379,6 @@ bool Kdb3Database::readGroupField(StdGroup* group,QList<quint32>& Levels,quint16
break;
case 0x0007:
memcpyFromLEnd32(&group->Image, (char*)pData);
group->OldImage=group->Image;
break;
case 0x0008:
quint16 Level;
@ -558,8 +548,10 @@ if(Algorithm == Rijndael_Cipher){
}
else if(Algorithm == Twofish_Cipher){
CTwofish twofish;
if (twofish.init(FinalKey, 32, EncryptionIV) != true)
if (twofish.init(FinalKey, 32, EncryptionIV) != true){
error=tr("Unable to initalize the twofish algorithm.");
LOAD_RETURN_CLEANUP
}
crypto_size = (unsigned long)twofish.padDecrypt((quint8 *)buffer + DB_HEADER_SIZE,
total_size - DB_HEADER_SIZE, (quint8 *)buffer + DB_HEADER_SIZE);
}
@ -1014,7 +1006,6 @@ IGroupHandle* Kdb3Database::addGroup(const CGroup* group,IGroupHandle* ParentHan
}
Kdb3Database::StdGroup::StdGroup(const CGroup& other){
OldImage=0;
Index=0;
Id=other.Id;
Image=other.Image;
@ -1033,11 +1024,9 @@ void Kdb3Database::EntryHandle::setBinaryDesc(const QString& s){Entry->BinaryDes
void Kdb3Database::EntryHandle::setComment(const QString& s){Entry->Comment=s;}
void Kdb3Database::EntryHandle::setBinary(const QByteArray& s){Entry->Binary=s;}
void Kdb3Database::EntryHandle::setImage(const quint32& s){Entry->Image=s;}
void Kdb3Database::EntryHandle::setOldImage(const quint32& s){Entry->OldImage=s;}
KpxUuid Kdb3Database::EntryHandle::uuid(){return Entry->Uuid;}
IGroupHandle* Kdb3Database::EntryHandle::group(){return Entry->Group->Handle;}
quint32 Kdb3Database::EntryHandle::image(){return Entry->Image;}
quint32 Kdb3Database::EntryHandle::oldImage(){return Entry->OldImage;}
QString Kdb3Database::EntryHandle::title(){return Entry->Title;}
QString Kdb3Database::EntryHandle::url(){return Entry->Url;}
QString Kdb3Database::EntryHandle::username(){return Entry->Username;}
@ -1106,24 +1095,13 @@ Kdb3Database::EntryHandle::EntryHandle(Kdb3Database* db){
bool Kdb3Database::GroupHandle::isValid(){return valid;}
void Kdb3Database::GroupHandle::setOldImage(const quint32& s){Group->OldImage=s;}
QString Kdb3Database::GroupHandle::title(){return Group->Title;}
quint32 Kdb3Database::GroupHandle::oldImage(){return Group->OldImage;}
quint32 Kdb3Database::GroupHandle::image(){return Group->Image;}
int Kdb3Database::GroupHandle::index(){return Group->Index;}
void Kdb3Database::GroupHandle::setTitle(const QString& Title){Group->Title=Title;}
void Kdb3Database::GroupHandle::setExpanded(bool IsExpanded){Group->IsExpanded=IsExpanded;}
bool Kdb3Database::GroupHandle::expanded(){return Group->IsExpanded;}
void Kdb3Database::GroupHandle::setImage(const quint32& New)
{
if(Group->Image < pDB->builtinIcons() && New >= pDB->builtinIcons())
Group->OldImage=Group->Image;
if(New < pDB->builtinIcons())
Group->OldImage=New;
Group->Image=New;
}
void Kdb3Database::GroupHandle::setImage(const quint32& New){Group->Image=New;}
Kdb3Database::GroupHandle::GroupHandle(Kdb3Database* db){
@ -1220,21 +1198,6 @@ bool Kdb3Database::save(){
}
}
/* This is only a fix for a bug in the implementation of the metastream creation
in KeePassX 0.2.1. to restore lost icons.
It should be removed after a while.
-----------------------------------------------------------------------------------*/
for(int i=0;i<Groups.size();i++){
if(Groups[i].Image<builtinIcons())
Groups[i].OldImage=Groups[i].Image;
}
for(int i=0;i<Entries.size();i++){
if(Entries[i].Image<builtinIcons())
Entries[i].OldImage=Entries[i].Image;
}
/* ----------------------------------------------------------------------------------*/
unsigned int FileSize;
QList<StdEntry> MetaStreams;
@ -1376,7 +1339,6 @@ void Kdb3Database::createCustomIconsMetaStream(StdEntry* e){
e->Username="SYSTEM";
e->Comment="KPX_CUSTOM_ICONS_4";
e->Url="$";
e->OldImage=0;
if(Groups.size())e->GroupId=Groups[0].Id;
int Size=12;
quint32 NumEntries=0;
@ -1505,7 +1467,7 @@ void Kdb3Database::serializeGroups(QList<StdGroup>& GroupList,char* buffer,unsig
FieldType = 0x0007; FieldSize = 4;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
memcpyToLEnd32(buffer+pos, &SortedGroups[i]->OldImage); pos += 4;
memcpyToLEnd32(buffer+pos, &SortedGroups[i]->Image); pos += 4;
FieldType = 0x0008; FieldSize = 2;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
@ -1542,7 +1504,7 @@ void Kdb3Database::serializeEntries(QList<StdEntry>& EntryList,char* buffer,unsi
FieldType = 0x0003; FieldSize = 4;
memcpyToLEnd16(buffer+pos, &FieldType); pos += 2;
memcpyToLEnd32(buffer+pos, &FieldSize); pos += 4;
memcpyToLEnd32(buffer+pos,&EntryList[i].OldImage); pos += 4;
memcpyToLEnd32(buffer+pos,&EntryList[i].Image); pos += 4;
FieldType = 0x0004;

@ -49,7 +49,6 @@ public:
public:
EntryHandle(Kdb3Database* db);
virtual void setImage(const quint32& ImageID);
void setOldImage(const quint32& OldImgID);
virtual void setTitle(const QString& Title);
virtual void setUrl(const QString& URL);
virtual void setUsername(const QString& Username);
@ -67,7 +66,6 @@ public:
virtual int visualIndex() const;
virtual void setVisualIndex(int i);
virtual void setVisualIndexDirectly(int i);
quint32 oldImage();
virtual QString title();
virtual QString url();
virtual QString username();
@ -96,10 +94,8 @@ public:
public:
virtual void setTitle(const QString& Title);
virtual void setImage(const quint32& ImageId);
void setOldImage(const quint32& ImageId);
virtual QString title();
virtual quint32 image();
quint32 oldImage();
virtual bool isValid();
virtual IGroupHandle* parent();
virtual QList<IGroupHandle*> childs();
@ -120,7 +116,6 @@ public:
class StdEntry:public CEntry{
public:
quint32 OldImage;
quint16 Index;
EntryHandle* Handle;
StdGroup* Group;
@ -130,7 +125,6 @@ public:
public:
StdGroup():CGroup(){};
StdGroup(const CGroup&);
quint32 OldImage;
quint16 Index;
StdGroup* Parent;
GroupHandle* Handle;

@ -72,9 +72,10 @@ public:
QString mountDir(){return settings.value("Options/MountDir",DEFAULT_MOUNT_DIR).toString();}
bool openLastFile(){return settings.value("Options/OpenLastFile",true).toBool();}
bool autoSave(){return settings.value("Options/AutoSave",false).toBool();}
int pwGenCategory(){return settings.value("Options/PwGenCategory",0).toInt();}
QString pwGenCharList(){return settings.value("Options/PwGenCharList").toString();}
int pwGenLength(){return settings.value("Options/PwGenLength",25).toInt();}
QBitArray pwGenOptions(){return stringToBitArray(settings.value("Options/PwGenOptions","1111100001").toString(),10);}
QBitArray pwGenOptions(){return stringToBitArray(settings.value("Options/PwGenOptions","11111000011110").toString(),14);}
bool rememberLastKey(){return settings.value("Options/RememberLastKey",true).toBool();}
bool saveFileDlgHistory(){return settings.value("Options/SaveFileDlgHistory",true).toBool();}
bool saveRelativePaths(){return settings.value("Options/SaveRelativePaths",true).toBool();}
@ -131,6 +132,7 @@ public:
void setMountDir(const QString& value){settings.setValue("Options/MountDir",value);}
void setOpenLastFile(bool value){settings.setValue("Options/OpenLastFile",value);}
void setAutoSave(bool value){settings.setValue("Options/AutoSave",value);}
void setPwGenCategory(int value){settings.setValue("Options/PwGenCategory",value);}
void setPwGenCharList(const QString& value){settings.setValue("Options/PwGenCharList",value);}
void setPwGenLength(int value){settings.setValue("Options/PwGenLength",value);}
void setPwGenOptions(const QBitArray& value){settings.setValue("Options/PwGenOptions",bitArrayToString(value));}

@ -0,0 +1,404 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "random.h"
#include "randpass.h"
#include "convert.h"
/*
** GLOBALS
*/
/* small letters */
char let[26] =
{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'w', 'z'
};
/* capital letters */
char clet[26] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'W', 'Z'
};
/*
** FUNCTIONS
*/
/*
** decapitalize() - This routine replaces all capital letters
** to small letters in the word:
** INPUT:
** char * - word.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
decapitalize (char *word)
{
int i = 0; /* counter */
int j = 0; /* counter */
int str_len = strlen(word);
for(j = 0; j < str_len; j++)
for(i=0; i < 26; i++)
if(word[j] == clet[i])
word[j] = let[i];
}
#ifndef APGBFM
/*
** capitalize() - This routine designed to modify sullable like this:
** adel ----> Adel
** dot ----> Dot
** etc.
** INPUT:
** char * - syllable.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
capitalize (char *syllable)
{
char tmp = 0x00;
int i = 0;
if ( randint(2) == TRUE)
{
(void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp));
for(i=0; i < 26; i++)
if ( let[i] == tmp )
if (is_restricted_symbol(clet[i]) != TRUE)
(void)memcpy ((void *)syllable, (void *)&clet[i], 1);
}
}
/*
** numerize() - This routine designed to modify single-letter
** syllable like this:
** a ----> 1 or 2 or 3 etc.
** u ----> 1 or 2 or 3 etc.
** etc.
** INPUT:
** char * - single-letter syllable
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
numerize (char *syllable)
{
char *tmp;
if ( (tmp = (char *)calloc(1, 4)) == NULL)
perror("calloc");
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_NB);
(void)memcpy ((void *)syllable, (void *)tmp, 1);
}
free ((void *)tmp);
}
/*
** specialize() - This routine designed to modify single-letter syllable
** like this:
** a ----> # or $ or % etc.
** u ----> # or $ or % etc.
** etc.
** INPUT:
** char * - single-letter syllable.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
specialize (char *syllable)
{
char *tmp;
if ( (tmp = (char *)calloc(1, 4)) == NULL)
perror("calloc");
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_SS);
(void)memcpy ((void *)syllable, (void *)tmp, 1);
}
free ((void *)tmp);
}
/*
** symb2name - convert symbol to it's name
** INPUT:
** char * - one symbol syllable
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
symb2name(char * syllable, char * h_syllable)
{
struct ssymb_names
{
char symbol;
char *name;
};
static struct ssymb_names ssn[42] =
{
{'1',"ONE"},
{'2',"TWO"},
{'3',"THREE"},
{'4',"FOUR"},
{'5',"FIVE"},
{'6',"SIX"},
{'7',"SEVEN"},
{'8',"EIGHT"},
{'9',"NINE"},
{'0',"ZERO"},
{33, "EXCLAMATION_POINT"},
{34, "QUOTATION_MARK"},
{35, "CROSSHATCH"},
{36, "DOLLAR_SIGN"},
{37, "PERCENT_SIGN"},
{38, "AMPERSAND"},
{39, "APOSTROPHE"},
{40, "LEFT_PARENTHESIS"},
{41, "RIGHT_PARENTHESIS"},
{42, "ASTERISK"},
{43, "PLUS_SIGN"},
{44, "COMMA"},
{45, "HYPHEN"},
{46, "PERIOD"},
{47, "SLASH"},
{58, "COLON"},
{59, "SEMICOLON"},
{60, "LESS_THAN"},
{61, "EQUAL_SIGN"},
{62, "GREATER_THAN"},
{63, "QUESTION_MARK"},
{64, "AT_SIGN"},
{91, "LEFT_BRACKET"},
{92, "BACKSLASH"},
{93, "RIGHT_BRACKET"},
{94, "CIRCUMFLEX"},
{95, "UNDERSCORE"},
{96, "GRAVE"},
{123, "LEFT_BRACE"},
{124, "VERTICAL_BAR"},
{125, "RIGHT_BRACE"},
{126, "TILDE"}
};
int i = 0;
int flag = FALSE;
if (strlen(syllable) == 1)
{
for (i = 0; i < 42; i++)
{
if(*syllable == ssn[i].symbol)
{
(void)memcpy((void*)h_syllable, (void*)ssn[i].name, strlen(ssn[i].name));
flag = TRUE;
}
}
if (flag != TRUE)
(void)memcpy((void*)h_syllable, (void*)syllable, strlen(syllable));
}
}
/*
** spell_word - spell the word
** INPUT:
** char * - pointer to the word
** char * - pointer to the spelled word
** OUTPUT:
** char * - pointer to the spelled word
** NULL - something is wrong
** NOTES:
** You should free() memory pointed by spelled_word after each use of spell_word
*/
char *
spell_word(char * word, char * spelled_word)
{
struct char_spell
{
char symbol;
char *name;
};
static struct char_spell cs[94] =
{
{'1',"ONE" },
{'2',"TWO" },
{'3',"THREE" },
{'4',"FOUR" },
{'5',"FIVE" },
{'6',"SIX" },
{'7',"SEVEN" },
{'8',"EIGHT" },
{'9',"NINE" },
{'0',"ZERO" },
{'A', "Alfa" },
{'B', "Bravo" },
{'C', "Charlie" },
{'D', "Delta" },
{'E', "Echo" },
{'F', "Foxtrot" },
{'G', "Golf" },
{'H', "Hotel" },
{'I', "India" },
{'J', "Juliett" },
{'K', "Kilo" },
{'L', "Lima" },
{'M', "Mike" },
{'N', "November" },
{'O', "Oscar" },
{'P', "Papa" },
{'Q', "Quebec" },
{'R', "Romeo" },
{'S', "Sierra" },
{'T', "Tango" },
{'U', "Uniform" },
{'V', "Victor" },
{'W', "Whiskey" },
{'X', "X_ray" },
{'Y', "Yankee" },
{'Z', "Zulu" },
{'a', "alfa" },
{'b', "bravo" },
{'c', "charlie" },
{'d', "delta" },
{'e', "echo" },
{'f', "foxtrot" },
{'g', "golf" },
{'h', "hotel" },
{'i', "india" },
{'j', "juliett" },
{'k', "kilo" },
{'l', "lima" },
{'m', "mike" },
{'n', "november" },
{'o', "oscar" },
{'p', "papa" },
{'q', "quebec" },
{'r', "romeo" },
{'s', "sierra" },
{'t', "tango" },
{'u', "uniform" },
{'v', "victor" },
{'w', "whiskey" },
{'x', "x_ray" },
{'y', "yankee" },
{'z', "zulu" },
{33, "EXCLAMATION_POINT"},
{34, "QUOTATION_MARK" },
{35, "CROSSHATCH" },
{36, "DOLLAR_SIGN" },
{37, "PERCENT_SIGN" },
{38, "AMPERSAND" },
{39, "APOSTROPHE" },
{40, "LEFT_PARENTHESIS" },
{41, "RIGHT_PARENTHESIS"},
{42, "ASTERISK" },
{43, "PLUS_SIGN" },
{44, "COMMA" },
{45, "HYPHEN" },
{46, "PERIOD" },
{47, "SLASH" },
{58, "COLON" },
{59, "SEMICOLON" },
{60, "LESS_THAN" },
{61, "EQUAL_SIGN" },
{62, "GREATER_THAN" },
{63, "QUESTION_MARK" },
{64, "AT_SIGN" },
{91, "LEFT_BRACKET" },
{92, "BACKSLASH" },
{93, "RIGHT_BRACKET" },
{94, "CIRCUMFLEX" },
{95, "UNDERSCORE" },
{96, "GRAVE" },
{123, "LEFT_BRACE" },
{124, "VERTICAL_BAR" },
{125, "RIGHT_BRACE" },
{126, "TILDE" }
};
int s_length = 0;
int i = 0;
int j = 0;
int word_len = strlen(word);
char * tmp_ptr;
char hyphen = '-';
char zero = 0x00;
/* Count the length of the spelled word */
for (i=0; i <= word_len; i++)
for (j=0; j < 94; j++)
if (word[i] == cs[j].symbol)
{
s_length = s_length + strlen(cs[j].name) + 1;
continue;
}
/* Allocate memory for spelled word */
if ( (spelled_word = (char *)calloc(1, (size_t)s_length)) == NULL)
return(NULL);
/* Construct spelled word */
tmp_ptr = spelled_word;
for (i=0; i < word_len; i++)
for (j=0; j < 94; j++)
if (word[i] == cs[j].symbol)
{
(void) memcpy((void *)tmp_ptr, (void *)cs[j].name, strlen(cs[j].name));
tmp_ptr = tmp_ptr + strlen(cs[j].name);
/* Place the hyphen after each symbol */
(void) memcpy((void *)(tmp_ptr), (void *)&hyphen, 1);
tmp_ptr = tmp_ptr + 1;
continue;
}
/* Remove hyphen at the end of the word */
tmp_ptr = tmp_ptr - 1;
(void) memcpy((void *)(tmp_ptr), (void *)&zero, 1);
return (spelled_word);
}
#endif /* APGBFM */

@ -0,0 +1,43 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef APG_CONVERT_H
#define APG_CONVERT_H 1
void decapitalize (char *word);
#ifndef APGBFM
void capitalize (char *syllable);
void numerize (char *syllable);
void specialize (char *syllable);
void symb2name(char * syllable, char * h_syllable);
char* spell_word(char * word, char * spelled_word);
#endif /* APGBFM */
#endif /* APG_CONVERT_H */

@ -0,0 +1,49 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef APG_OWN_TYPES_H
#define APG_OWN_TYPES_H 1
typedef unsigned int UINT;
typedef unsigned short USHORT;
typedef short int SHORT;
typedef int boolean;
typedef unsigned long int UINT32;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define APG_MAX_PASSWORD_LENGTH 255
#endif /* APG_OWN_TYPES_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,92 @@
/*
** This module uses code from the NIST implementation of FIPS-181,
** but the algorythm is CHANGED and I think that I CAN
** copyright it. See copiright notes below.
*/
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef APG_PRONPASS_H
#define APG_PRONPASS_H 1
#ifndef APG_OWN_TYPES_H
#include "owntypes.h"
#endif /* APG_OWN_TYPES_H */
//#ifndef APG_RND_H
//#include "rnd.h"
//#endif /* APG_RND_H */
#define RULE_SIZE (sizeof(rules)/sizeof(struct unit))
#define ALLOWED(flag) (digram[units_in_syllable[current_unit -1]][unit] & (flag))
#define MAX_UNACCEPTABLE 20
#define MAX_RETRIES (4 * (int) pwlen + RULE_SIZE)
#define NOT_BEGIN_SYLLABLE 010
#define NO_FINAL_SPLIT 04
#define VOWEL 02
#define ALTERNATE_VOWEL 01
#define NO_SPECIAL_RULE 0
#define BEGIN 0200
#define NOT_BEGIN 0100
#define BREAK 040
#define PREFIX 020
#define ILLEGAL_PAIR 010
#define SUFFIX 04
#define END 02
#define NOT_END 01
#define ANY_COMBINATION 0
#ifdef __cplusplus
extern "C" {
#endif
extern int gen_pron_pass (char *word, char *hyphenated_word, USHORT minlen,
USHORT maxlen, unsigned int pass_mode);
USHORT random_unit (USHORT type);
USHORT get_random (USHORT minlen, USHORT maxlen);
boolean have_initial_y (USHORT *units, USHORT unit_size);
boolean illegal_placement (USHORT *units, USHORT pwlen);
boolean improper_word (USHORT *units, USHORT word_size);
boolean have_final_split (USHORT *units, USHORT unit_size);
int gen_word (char *word, char *hyphenated_word, USHORT pwlen,
unsigned int pass_mode);
char *gen_syllable(char *syllable, USHORT pwlen, USHORT *units_in_syllable,
USHORT *syllable_length);
#ifdef __cplusplus
}
#endif
#endif /* APG_PRONPASS_H */

@ -0,0 +1,162 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
** randpass.c - Random password generation module of PWGEN program
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "random.h"
#include "randpass.h"
#include "owntypes.h"
#include "smbl.h"
/*
** gen_rand_pass - generates random password of specified type
** INPUT:
** char * - password string.
** int - minimum password length.
** int - maximum password length.
** unsigned int - password generation mode.
** OUTPUT:
** int - password length or -1 on error.
** NOTES:
** none.
*/
int
gen_rand_pass (char *password_string, int minl, int maxl, unsigned int pass_mode)
{
int i = 0;
int j = 0;
int length = 0;
char *str_pointer;
int random_weight[94];
int max_weight = 0;
int max_weight_element_number = 0;
if (minl > APG_MAX_PASSWORD_LENGTH || maxl > APG_MAX_PASSWORD_LENGTH ||
minl < 1 || maxl < 1 || minl > maxl)
return (-1);
for (i = 0; i <= 93; i++) random_weight[i] = 0;
length = minl + randint(maxl-minl+1);
str_pointer = password_string;
for (i = 0; i < length; i++)
{
/* Asign random weight in weight array if mode is present*/
for (j = 0; j <= 93 ; j++)
if ( ( (pass_mode & smbl[j].type) > 0) &&
!( (S_RS & smbl[j].type) > 0))
random_weight[j] = 1 + randint(20000);
j = 0;
/* Find an element with maximum weight */
for (j = 0; j <= 93; j++)
if (random_weight[j] > max_weight)
{
max_weight = random_weight[j];
max_weight_element_number = j;
}
/* Get password symbol */
*str_pointer = smbl[max_weight_element_number].ch;
str_pointer++;
max_weight = 0;
max_weight_element_number = 0;
for (j = 0; j <= 93; j++) random_weight[j] = 0;
}
*str_pointer = 0;
return (length);
}
/*
** gen_rand_symbol - generates random password of specified type
** INPUT:
** char * - symbol.
** unsigned int - symbol type.
** OUTPUT:
** int - password length or -1 on error.
** NOTES:
** none.
*/
int
gen_rand_symbol (char *symbol, unsigned int mode)
{
int j = 0;
char *str_pointer;
int random_weight[94];
int max_weight = 0;
int max_weight_element_number = 0;
for (j = 0; j <= 93; j++) random_weight[j] = 0;
str_pointer = symbol;
j = 0;
/* Asign random weight in weight array if mode is present*/
for (j = 0; j <= 93 ; j++)
if ( ( (mode & smbl[j].type) > 0) &&
!( (S_RS & smbl[j].type) > 0))
random_weight[j] = 1 + randint(20000);
j = 0;
/* Find an element with maximum weight */
for (j = 0; j <= 93; j++)
if (random_weight[j] > max_weight)
{
max_weight = random_weight[j];
max_weight_element_number = j;
}
/* Get password symbol */
*str_pointer = smbl[max_weight_element_number].ch;
max_weight = 0;
max_weight_element_number = 0;
return (0);
}
/*
** is_restricted_symbol - detcts if symbol is restricted rigt now
** INPUT:
** char - symbol.
** OUTPUT:
** int - 0 - not restricted
** 1 - restricted
** NOTES:
** none.
*/
int
is_restricted_symbol (char symbol)
{
int j = 0;
for (j = 0; j <= 93 ; j++)
if (symbol == smbl[j].ch)
if ((S_RS & smbl[j].type) > 0)
return(1);
return(0);
}

@ -0,0 +1,70 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
** randpass.h
*/
#ifndef APG_RANDPASS_H
#define APG_RANDPASS_H 1
/*#ifndef APG_RND_H
#include "rnd.h"
#endif*/
#ifndef APG_OWN_TYPES_H
#include "owntypes.h"
#endif
#define S_NB 0x01 /* Numeric */
#define S_SS 0x02 /* Special */
#define S_CL 0x04 /* Capital */
#define S_SL 0x08 /* Small */
#define S_RS 0x10 /* Restricted Symbol*/
struct sym
{
char ch;
USHORT type;
};
#ifdef __cplusplus
extern "C" {
#endif
/* char gen_symbol(unsigned short int symbol_class); */
extern int gen_rand_pass(char* password_string, int minl,
int maxl, unsigned int pass_mode);
extern int gen_rand_symbol (char *symbol, unsigned int mode);
extern int is_restricted_symbol (char symbol);
#ifdef __cplusplus
}
#endif
#endif /* RANDPASS_H */

@ -0,0 +1,51 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef APG_SMBL_H
#define APG_SMBL_H 1
struct sym smbl[94] =
{
{'a', S_SL}, {'b', S_SL}, {'c', S_SL}, {'d', S_SL}, {'e', S_SL}, {'f', S_SL},
{'g', S_SL}, {'h', S_SL}, {'i', S_SL}, {'j', S_SL}, {'k', S_SL}, {'l', S_SL},
{'m', S_SL}, {'n', S_SL}, {'o', S_SL}, {'p', S_SL}, {'q', S_SL}, {'r', S_SL},
{'s', S_SL}, {'t', S_SL}, {'u', S_SL}, {'v', S_SL}, {'w', S_SL}, {'x', S_SL},
{'y', S_SL}, {'z', S_SL}, {'A', S_CL}, {'B', S_CL}, {'C', S_CL}, {'D', S_CL},
{'E', S_CL}, {'F', S_CL}, {'G', S_CL}, {'H', S_CL}, {'I', S_CL}, {'J', S_CL},
{'K', S_CL}, {'L', S_CL}, {'M', S_CL}, {'N', S_CL}, {'O', S_CL}, {'P', S_CL},
{'Q', S_CL}, {'R', S_CL}, {'S', S_CL}, {'T', S_CL}, {'U', S_CL}, {'V', S_CL},
{'W', S_CL}, {'X', S_CL}, {'Y', S_CL}, {'Z', S_CL}, {'1', S_NB}, {'2', S_NB},
{'3', S_NB}, {'4', S_NB}, {'5', S_NB}, {'6', S_NB}, {'7', S_NB}, {'8', S_NB},
{'9', S_NB}, {'0', S_NB}, {33 , S_SS}, {34 , S_SS}, {35 , S_SS}, {36 , S_SS},
{37 , S_SS}, {38 , S_SS}, {39 , S_SS}, {40 , S_SS}, {41 , S_SS}, {42 , S_SS},
{43 , S_SS}, {44 , S_SS}, {45 , S_SS}, {46 , S_SS}, {47 , S_SS}, {58 , S_SS},
{59 , S_SS}, {60 , S_SS}, {61 , S_SS}, {62 , S_SS}, {63 , S_SS}, {64 , S_SS},
{91 , S_SS}, {92 , S_SS}, {93 , S_SS}, {94 , S_SS}, {95 , S_SS}, {96 , S_SS},
{123, S_SS}, {124, S_SS}, {125, S_SS}, {126, S_SS}
};
#endif /* APG_SMBL_H */

@ -1,24 +1,28 @@
/**************************************************************************
* *
* Copyright (C) 2007 by Tarek Saidi <tarek.saidi@arcor.de> *
* Copyright (c) 2003 Dr Brian Gladman, Worcester, UK *
* *
* 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; version 2 of the License. *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/*