First commit for 0.2.3, some old functions still need to be ported to the new back-end api, i.e. import and export.
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@104 b624d157-de02-0410-bad0-e51aec6abb33master
parent
0286b87a41
commit
21f0fea56a
Before Width: | Height: | Size: 806 B After Width: | Height: | Size: 898 B |
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
File diff suppressed because it is too large
Load Diff
@ -1,125 +0,0 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2005-2006 by Tarek Saidi * |
||||
* tarek.saidi@arcor.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., * |
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef _PW_MANAGER_H_ |
||||
#define _PW_MANAGER_H_ |
||||
#define DB_HEADER_SIZE 124 |
||||
#define PWM_DBSIG_1 0x9AA2D903 |
||||
#define PWM_DBSIG_2 0xB54BFB65 |
||||
#define PWM_DBVER_DW 0x00030002 |
||||
#define PWM_FLAG_SHA2 1 |
||||
#define PWM_FLAG_RIJNDAEL 2 |
||||
#define PWM_FLAG_ARCFOUR 4 |
||||
#define PWM_FLAG_TWOFISH 8 |
||||
#define PWM_STD_KEYENCROUNDS 6000 |
||||
|
||||
#include <qcolor.h> |
||||
#include <qobject.h> |
||||
#include <QDateTime> |
||||
#include <QDate> |
||||
#include <QTime> |
||||
#include <QStringList> |
||||
#include <QPixmap> |
||||
#include "lib/SecString.h" |
||||
#include "Database.h" |
||||
|
||||
|
||||
class PwDatabase:public Database{ |
||||
Q_OBJECT |
||||
public: |
||||
PwDatabase(); |
||||
bool openDatabase(QString filename, QString& err); |
||||
bool saveDatabase(); |
||||
bool closeDatabase(); |
||||
void newDatabase(); |
||||
bool CalcMasterKeyByPassword(QString& password); |
||||
bool CalcMasterKeyByFile(QString filename); |
||||
bool CalcMasterKeyByFileAndPw(QString filename, QString& password); |
||||
bool createKeyFile(const QString& filename); |
||||
|
||||
CGroup& group(unsigned long index); |
||||
void setGroup(unsigned long index,CGroup& group); |
||||
int numGroups(); |
||||
CGroup* addGroup(CGroup* parent); |
||||
void deleteGroup(CGroup* pGroup); |
||||
void deleteGroup(unsigned long ID); |
||||
void moveGroup(CGroup* group, CGroup* DstGroup, int pos=-1); |
||||
void moveGroupDirectly(CGroup* group, CGroup* DstGroup); //inserts group directly behind DstGroup on the same level
|
||||
int getGroupIndex(CGroup* group); |
||||
int getGroupIndex(unsigned long ID); |
||||
int getNumberOfChilds(CGroup* pGroup); |
||||
QList<int> getChildIds(CGroup* pGroup); |
||||
|
||||
CEntry& entry(unsigned long index); |
||||
CEntry* getEntry(const KpxUuid& uuid); |
||||
void setEntry(unsigned long index,CEntry& Entry); |
||||
int numEntries(); |
||||
CEntry* cloneEntry(CEntry* pEntry); |
||||
void deleteEntry(CEntry* pEntry); |
||||
void moveEntry(CEntry* pEntry,CGroup* pDstGroup); |
||||
CEntry* addEntry(); |
||||
CEntry* addEntry(CEntry* NewEntry); |
||||
void merge(Database* db2); |
||||
bool isParentGroup(CGroup* Group,CGroup* PotenialParent); |
||||
|
||||
QString getError(); //get first error
|
||||
QString getErrors(); //get all errors in a \n seperated String
|
||||
QPixmap& icon(int index); |
||||
int numIcons(); |
||||
void addIcon(const QPixmap& icon); |
||||
void removeIcon(int Id); |
||||
void replaceIcon(int Id,const QPixmap& icon); |
||||
|
||||
QList<CGroup>Groups; |
||||
QList<CEntry>Entries; |
||||
private: |
||||
bool IsMetaStream(CEntry& Entry); |
||||
bool parseMetaStream(const CEntry& Entry); |
||||
bool parseCustomIconsMetaStream(const QByteArray& data); |
||||
bool parseCustomIconsMetaStreamV1(const QByteArray& data); |
||||
void createCustomIconsMetaStream(CEntry* dst); |
||||
void transformKey(quint8* src,quint8* dst,quint8* seed,int rounds); |
||||
bool readHeader(char* raw); |
||||
bool isGroupIdInUse(quint32 GroupID); |
||||
bool isEntrySidInUse(quint32 sID); |
||||
quint32 getNewGroupId(); |
||||
quint32 getNewEntrySid(); |
||||
bool convHexToBinaryKey(char* HexKey, char* dst); |
||||
QStringList Errors; |
||||
QList<QPixmap> CustomIcons; |
||||
QList<CEntry> UnkownMetaStreams; |
||||
|
||||
signals: |
||||
void iconsModified(); |
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
void memcpyFromLEnd32(quint32* dst,const char* src); |
||||
void memcpyFromLEnd16(quint16* dst,const char* src); |
||||
void memcpyToLEnd32(char* src,const quint32* dst); |
||||
void memcpyToLEnd16(char* src,const quint16* dst); |
||||
QDateTime dateFromPackedStruct5(const unsigned char* pBytes); |
||||
void dateToPackedStruct5(const QDateTime& datetime, unsigned char* dst); |
||||
|
||||
bool testDatabase(); |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,233 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2005-2006 by Tarek Saidi * |
||||
* keepassx@gmail.com * |
||||
* * |
||||
* 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., * |
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef _STD_DATABASE_H_ |
||||
#define _STD_DATABASE_H_ |
||||
|
||||
#define DB_HEADER_SIZE 124 |
||||
#define PWM_DBSIG_1 0x9AA2D903 |
||||
#define PWM_DBSIG_2 0xB54BFB65 |
||||
#define PWM_DBVER_DW 0x00030002 |
||||
#define PWM_FLAG_SHA2 1 |
||||
#define PWM_FLAG_RIJNDAEL 2 |
||||
#define PWM_FLAG_ARCFOUR 4 |
||||
#define PWM_FLAG_TWOFISH 8 |
||||
#define PWM_STD_KEYENCROUNDS 6000 |
||||
|
||||
#include <qcolor.h> |
||||
#include <qobject.h> |
||||
#include <QDateTime> |
||||
#include <QDate> |
||||
#include <QTime> |
||||
#include <QStringList> |
||||
#include <QPixmap> |
||||
#include "lib/SecString.h" |
||||
#include "Database.h" |
||||
|
||||
|
||||
void memcpyFromLEnd32(quint32* dst,const char* src); |
||||
void memcpyFromLEnd16(quint16* dst,const char* src); |
||||
void memcpyToLEnd32(char* src,const quint32* dst); |
||||
void memcpyToLEnd16(char* src,const quint16* dst); |
||||
|
||||
//! Implementation of the standard KeePassX database.
|
||||
class StandardDatabase:public ICustomIcons,public IDatabase, public IFilePasswordAuth{ |
||||
Q_OBJECT |
||||
public: |
||||
class StdGroup; |
||||
class StdEntry; |
||||
class EntryHandle:public IEntryHandle{ |
||||
friend class StandardDatabase; |
||||
public: |
||||
EntryHandle(StandardDatabase* 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); |
||||
virtual void setPassword(const SecString& Password); |
||||
virtual void setComment(const QString& Comment); |
||||
virtual void setBinaryDesc(const QString& BinaryDesc); |
||||
virtual void setCreation(const KpxDateTime& Creation); |
||||
virtual void setLastMod(const KpxDateTime& LastMod); |
||||
virtual void setLastAccess(const KpxDateTime& LastAccess); |
||||
virtual void setExpire(const KpxDateTime& Expire); |
||||
virtual void setBinary(const QByteArray& BinaryData); |
||||
virtual KpxUuid uuid(); |
||||
virtual IGroupHandle* group(); |
||||
virtual quint32 image(); |
||||
virtual int index() const; |
||||
quint32 oldImage(); |
||||
virtual QString title(); |
||||
virtual QString url(); |
||||
virtual QString username(); |
||||
virtual SecString password(); |
||||
virtual QString comment(); |
||||
virtual QString binaryDesc(); |
||||
virtual KpxDateTime creation(); |
||||
virtual KpxDateTime lastMod(); |
||||
virtual KpxDateTime lastAccess(); |
||||
virtual KpxDateTime expire(); |
||||
virtual QByteArray binary(); |
||||
virtual quint32 binarySize(); |
||||
virtual bool isValid() const; |
||||
virtual bool operator<(const IEntryHandle*& other); |
||||
private: |
||||
void invalidate(){valid=false;} |
||||
bool valid; |
||||
unsigned int ListIndex; |
||||
KpxUuid Uuid; |
||||
StandardDatabase* pDB; |
||||
StdEntry* Entry; |
||||
}; |
||||
class GroupHandle:public IGroupHandle{ |
||||
friend class StandardDatabase; |
||||
GroupHandle(StandardDatabase* db); |
||||
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(); |
||||
virtual int index(); |
||||
virtual void setIndex(int index); |
||||
virtual int level(); |
||||
private: |
||||
void invalidate(){valid=false;} |
||||
bool valid; |
||||
StdGroup* Group; |
||||
StandardDatabase* pDB; |
||||
}; |
||||
friend class EntryHandle; |
||||
friend class GroupHandle; |
||||
class StdEntry:public CEntry{ |
||||
public: |
||||
quint32 OldImage; |
||||
quint16 Index; |
||||
EntryHandle* Handle; |
||||
StdGroup* Group; |
||||
}; |
||||
class StdGroup:public CGroup{ |
||||
public: |
||||
StdGroup():CGroup(){}; |
||||
StdGroup(const CGroup&); |
||||
quint32 OldImage; |
||||
quint16 Index; |
||||
StdGroup* Parent; |
||||
GroupHandle* Handle; |
||||
QList<StdGroup*> Childs; |
||||
QList<StdEntry*> Entries; |
||||
}; |
||||
virtual bool load(QString identifier); |
||||
virtual bool save(); |
||||
virtual bool close(); |
||||
virtual void create(); |
||||
virtual int numEntries(); |
||||
virtual int numGroups(); |
||||
virtual QString getError(); |
||||
virtual void cleanUpHandles(); |
||||
virtual QPixmap& icon(int index); |
||||
virtual int numIcons(); |
||||
virtual void addIcon(const QPixmap& icon); |
||||
virtual void removeIcon(int index); |
||||
virtual void replaceIcon(int index,const QPixmap& icon); |
||||
virtual int builtinIcons(){return 62;}; |
||||
virtual void authByPwd(QString& password); |
||||
virtual bool authByFile(QFile& file); |
||||
virtual bool authByFileAndPwd(QString& password, QFile& file); |
||||
virtual bool createKeyFile(const QString& filename,int length=32, bool Hex=false); |
||||
virtual QList<IEntryHandle*> search(IGroupHandle* Group,const QString& SearchString, bool CaseSensitve, bool RegExp,bool Recursive,bool* Fields); |
||||
virtual QFile* file(){return File;} |
||||
virtual bool changeFile(const QString& filename); |
||||
|
||||
virtual QList<IEntryHandle*> entries(); |
||||
virtual QList<IEntryHandle*> entries(IGroupHandle* Group); |
||||
virtual IEntryHandle* cloneEntry(const IEntryHandle* entry); |
||||
virtual void deleteEntry(IEntryHandle* entry); |
||||
virtual void deleteEntries(QList<IEntryHandle*> entries); |
||||
virtual IEntryHandle* newEntry(IGroupHandle* group); |
||||
virtual IEntryHandle* addEntry(const CEntry* NewEntry, IGroupHandle* group); |
||||
virtual void moveEntry(IEntryHandle* entry, IGroupHandle* group); |
||||
virtual void deleteLastEntry(); |
||||
|
||||
|
||||
virtual QList<IGroupHandle*> groups(); |
||||
virtual QList<IGroupHandle*> sortedGroups(); |
||||
virtual void deleteGroup(IGroupHandle* group); |
||||
virtual void moveGroup(IGroupHandle* Group,IGroupHandle* NewParent,int Position); |
||||
virtual IGroupHandle* addGroup(const CGroup* Group,IGroupHandle* Parent); |
||||
virtual bool isParent(IGroupHandle* parent, IGroupHandle* child); |
||||
|
||||
|
||||
|
||||
|
||||
private: |
||||
QDateTime dateFromPackedStruct5(const unsigned char* pBytes); |
||||
void dateToPackedStruct5(const QDateTime& datetime, unsigned char* dst); |
||||
bool isMetaStream(StdEntry& Entry); |
||||
bool parseMetaStream(const StdEntry& Entry); |
||||
bool parseCustomIconsMetaStream(const QByteArray& data); |
||||
bool parseCustomIconsMetaStreamV1(const QByteArray& data); |
||||
bool parseCustomIconsMetaStreamV2(const QByteArray& data); |
||||
bool readEntryField(StdEntry* entry, quint16 FieldType, quint32 FieldSize, quint8 *pData); |
||||
bool readGroupField(StdGroup* group,QList<quint32>& Levels,quint16 FieldType, quint32 FieldSize, quint8 *pData); |
||||
bool createGroupTree(QList<quint32>& Levels); |
||||
void createHandles(); |
||||
bool transformKey(quint8* src,quint8* dst,quint8* KeySeed,int rounds); |
||||
void invalidateHandle(StdEntry* entry); |
||||
bool convHexToBinaryKey(char* HexKey, char* dst); |
||||
quint32 getNewGroupId(); |
||||
void serializeEntries(QList<StdEntry>& EntryList,char* buffer,unsigned int& pos); |
||||
void serializeGroups(QList<StdGroup>& GroupList,char* buffer,unsigned int& pos); |
||||
void createCustomIconsMetaStream(StdEntry* e); |
||||
void appendChildsToGroupList(QList<StdGroup*>& list,StdGroup& group); |
||||
void appendChildsToGroupList(QList<IGroupHandle*>& list,StdGroup& group); |
||||
bool searchStringContains(const QString& search, const QString& string,bool Cs, bool RegExp); |
||||
void getEntriesRecursive(IGroupHandle* Group, QList<IEntryHandle*>& EntryList); |
||||
void rebuildIndices(QList<StdGroup*>& list); |
||||
|
||||
StdEntry* getEntry(const KpxUuid& uuid); |
||||
StdEntry* getEntry(EntryHandle* handle); |
||||
int getEntryListIndex(EntryHandle* handle); |
||||
EntryHandle* getHandle(StdEntry* entry); |
||||
|
||||
StdGroup* getGroup(quint32 Id); |
||||
void deleteGroup(StdGroup* group); |
||||
|
||||
QList<EntryHandle> EntryHandles; |
||||
QList<GroupHandle> GroupHandles; |
||||
QList<StdEntry> Entries; |
||||
QList<StdGroup> Groups; |
||||
StdGroup RootGroup; |
||||
QList<QPixmap>CustomIcons; |
||||
QFile* File; |
||||
QString error; |
||||
QList<StdEntry> UnknownMetaStreams; |
||||
unsigned int KeyTransfRounds; |
||||
CryptAlgorithm Algorithm; |
||||
quint8 RawMasterKey[32]; |
||||
quint8 MasterKey[32]; |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,197 @@ |
||||
/*
|
||||
--------------------------------------------------------------------------- |
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. |
||||
|
||||
LICENSE TERMS |
||||
|
||||
The free distribution and use of this software in both source and binary |
||||
form is allowed (with or without changes) provided that: |
||||
|
||||
1. distributions of this source code include the above copyright |
||||
notice, this list of conditions and the following disclaimer; |
||||
|
||||
2. distributions in binary form include the above copyright |
||||
notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other associated materials; |
||||
|
||||
3. the copyright holder's name is not used to endorse products |
||||
built using this software without specific written permission. |
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product |
||||
may be distributed under the terms of the GNU General Public License (GPL), |
||||
in which case the provisions of the GPL apply INSTEAD OF those given above. |
||||
|
||||
DISCLAIMER |
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties |
||||
in respect of its properties, including, but not limited to, correctness |
||||
and/or fitness for purpose. |
||||
--------------------------------------------------------------------------- |
||||
Issue 31/01/2006 |
||||
|
||||
This file contains the definitions required to use AES in C. See aesopt.h |
||||
for optimisation details. |
||||
*/ |
||||
|
||||
#ifndef _AES_H |
||||
#define _AES_H |
||||
|
||||
#include <stdlib.h> |
||||
|
||||
/* This include is used to find 8 & 32 bit unsigned integer types */ |
||||
#include "aes_tdefs.h" |
||||
|
||||
#if defined(__cplusplus) |
||||
extern "C" |
||||
{ |
||||
#endif |
||||
|
||||
#define AES_128 /* define if AES with 128 bit keys is needed */ |
||||
#define AES_192 /* define if AES with 192 bit keys is needed */ |
||||
#define AES_256 /* define if AES with 256 bit keys is needed */ |
||||
#define AES_VAR /* define if a variable key size is needed */ |
||||
#define AES_MODES /* define if support is needed for modes */ |
||||
|
||||
/* The following must also be set in assembler files if being used */ |
||||
|
||||
#define AES_ENCRYPT /* if support for encryption is needed */ |
||||
#define AES_DECRYPT /* if support for decryption is needed */ |
||||
#define AES_ERR_CHK /* for parameter checks & error return codes */ |
||||
#define AES_REV_DKS /* define to reverse decryption key schedule */ |
||||
|
||||
#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ |
||||
#define N_COLS 4 /* the number of columns in the state */ |
||||
|
||||
/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ |
||||
/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ |
||||
/* or 44, 52 or 60 32-bit words. */ |
||||
|
||||
#if defined( AES_VAR ) || defined( AES_256 ) |
||||
#define KS_LENGTH 60 |
||||
#elif defined( AES_192 ) |
||||
#define KS_LENGTH 52 |
||||
#else |
||||
#define KS_LENGTH 44 |
||||
#endif |
||||
|
||||
#if defined( AES_ERR_CHK ) |
||||
#define aes_rval int_ret |
||||
#else |
||||
#define aes_rval void_ret |
||||
#endif |
||||
|
||||
/* the character array 'inf' in the following structures is used */ |
||||
/* to hold AES context information. This AES code uses cx->inf.b[0] */ |
||||
/* to hold the number of rounds multiplied by 16. The other three */ |
||||
/* elements can be used by code that implements additional modes */ |
||||
|
||||
typedef union |
||||
{ uint_32t l; |
||||
uint_8t b[4]; |
||||
} aes_inf; |
||||
|
||||
typedef struct |
||||
{ uint_32t ks[KS_LENGTH]; |
||||
aes_inf inf; |
||||
} aes_encrypt_ctx; |
||||
|
||||
typedef struct |
||||
{ uint_32t ks[KS_LENGTH]; |
||||
aes_inf inf; |
||||
} aes_decrypt_ctx; |
||||
|
||||
/* This routine must be called before first use if non-static */ |
||||
/* tables are being used */ |
||||
|
||||
aes_rval gen_tabs(void); |
||||
|
||||
/* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */ |
||||
/* those in the range 128 <= key_len <= 256 are given in bits */ |
||||
|
||||
#if defined( AES_ENCRYPT ) |
||||
|
||||
#if defined(AES_128) || defined(AES_VAR) |
||||
aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_192) || defined(AES_VAR) |
||||
aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_256) || defined(AES_VAR) |
||||
aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_VAR) |
||||
aes_rval aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
aes_rval aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); |
||||
|
||||
#endif |
||||
|
||||
#if defined( AES_DECRYPT ) |
||||
|
||||
#if defined(AES_128) || defined(AES_VAR) |
||||
aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_192) || defined(AES_VAR) |
||||
aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_256) || defined(AES_VAR) |
||||
aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
#if defined(AES_VAR) |
||||
aes_rval aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]); |
||||
#endif |
||||
|
||||
aes_rval aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); |
||||
|
||||
#endif |
||||
|
||||
#if defined(AES_MODES) |
||||
|
||||
aes_rval aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, const aes_encrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, const aes_decrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *iv, const aes_encrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *iv, const aes_decrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_mode_reset(aes_encrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]); |
||||
|
||||
aes_rval aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]); |
||||
|
||||
#define aes_ofb_encrypt aes_ofb_crypt |
||||
#define aes_ofb_decrypt aes_ofb_crypt |
||||
|
||||
aes_rval aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *iv, aes_encrypt_ctx cx[1]); |
||||
|
||||
typedef void cbuf_inc(unsigned char *cbuf); |
||||
|
||||
#define aes_ctr_encrypt aes_ctr_crypt |
||||
#define aes_ctr_decrypt aes_ctr_crypt |
||||
|
||||
aes_rval aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, |
||||
int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]); |
||||
|
||||
#endif |
||||
|
||||
#if defined(__cplusplus) |
||||
} |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,130 @@ |
||||
/*
|
||||
--------------------------------------------------------------------------- |
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. |
||||
|
||||
LICENSE TERMS |
||||
|
||||
The free distribution and use of this software in both source and binary |
||||
form is allowed (with or without changes) provided that: |
||||
|
||||
1. distributions of this source code include the above copyright |
||||
notice, this list of conditions and the following disclaimer; |
||||
|
||||
2. distributions in binary form include the above copyright |
||||
notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other associated materials; |
||||
|
||||
3. the copyright holder's name is not used to endorse products |
||||
built using this software without specific written permission. |
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product |
||||
may be distributed under the terms of the GNU General Public License (GPL), |
||||
in which case the provisions of the GPL apply INSTEAD OF those given above. |
||||
|
||||
DISCLAIMER |
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties |
||||
in respect of its properties, including, but not limited to, correctness |
||||
and/or fitness for purpose. |
||||
--------------------------------------------------------------------------- |
||||
Issue 31/01/2006 |
||||
*/ |
||||
|
||||
#ifndef EDEFS_H |
||||
#define EDEFS_H |
||||
#if defined(__cplusplus) |
||||
extern "C" |
||||
{ |
||||
#endif |
||||
|
||||
#define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ |
||||
#define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ |
||||
|
||||
#if defined(__GNUC__) || defined(__GNU_LIBRARY__) |
||||
# if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) |
||||
# include <sys/endian.h> |
||||
# elif defined( BSD ) && ( BSD >= 199103 ) || defined( __DJGPP__ ) || defined( __CYGWIN32__ ) |
||||
# include <machine/endian.h> |
||||
# elif defined(__APPLE__) |
||||
# if defined(__BIG_ENDIAN__) && !defined( BIG_ENDIAN ) |
||||
# define BIG_ENDIAN |
||||
# elif defined(__LITTLE_ENDIAN__) && !defined( LITTLE_ENDIAN ) |
||||
# define LITTLE_ENDIAN |
||||
# endif |
||||
# elif !defined( __MINGW32__ ) |
||||
# include <endian.h> |
||||
# if !defined(__BEOS__) |
||||
# include <byteswap.h> |
||||
# endif |
||||
# endif |
||||
#endif |
||||
|
||||
#if !defined(PLATFORM_BYTE_ORDER) |
||||
# if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN) |
||||
# if defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# endif |
||||
# elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN) |
||||
# if defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# endif |
||||
# elif defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__) |
||||
# if defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif !defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
# endif |
||||
# endif |
||||
#endif |
||||
|
||||
/* if the platform is still unknown, try to find its byte order */ |
||||
/* from commonly used machine defines */ |
||||
|
||||
#if !defined(PLATFORM_BYTE_ORDER) |
||||
|
||||
#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ |
||||
defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
|
||||
defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
|
||||
defined( vax ) || defined( vms ) || defined( VMS ) || \
|
||||
defined( __VMS ) || defined( _M_X64 ) |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
|
||||
#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ |
||||
defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
|
||||
defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
|
||||
defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
|
||||
defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
|
||||
defined( __TANDEM ) || defined( THINK_C ) || defined( __VMCMS__ ) || \
|
||||
defined( __VOS__ ) |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
|
||||
#elif 0 /* **** EDIT HERE IF NECESSARY **** */ |
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
||||
#elif 0 /* **** EDIT HERE IF NECESSARY **** */ |
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
||||
#else |
||||
# error Please edit edefs.h (lines 117 or 119) to set the platform byte order |
||||
#endif |
||||
|
||||
#endif |
||||
|
||||
#if defined(__cplusplus) |
||||
} |
||||
#endif |
||||
#endif |
@ -0,0 +1,891 @@ |
||||
/*
|
||||
--------------------------------------------------------------------------- |
||||
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. |
||||
|
||||
LICENSE TERMS |
||||
|
||||
The free distribution and use of this software in both source and binary |
||||
form is allowed (with or without changes) provided that: |
||||
|
||||
1. distributions of this source code include the above copyright |
||||
notice, this list of conditions and the following disclaimer; |
||||
|
||||
2. distributions in binary form include the above copyright |
||||
notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other associated materials; |
||||
|
||||
3. the copyright holder's name is not used to endorse products |
||||
built using this software without specific written permission. |
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product |
||||
may be distributed under the terms of the GNU General Public License (GPL), |
||||
in which case the provisions of the GPL apply INSTEAD OF those given above. |
||||
|
||||
DISCLAIMER |
||||