Click here to Skip to main content
15,896,445 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 257.4K   7.4K   111  
Yet another password manager.
/********************************************************************
	Created:	21/3/2004, 11:15
	File name: 	D:\Projects\Exile\RC5\RC5.h
	File path:	D:\Projects\Exile\RC5
	File base:	RC5
	File ext:	h
	Author:		Gogolev Anton
*********************************************************************/

#ifndef __RC5_H__
#define __RC5_H__

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the RC5_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// RC5_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.

#ifdef RC5_EXPORTS
#define RC5_API extern "C" __declspec(dllexport)
#else
#define RC5_API extern "C" __declspec(dllimport)
#endif

BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved);

//////////////////////////////////////////////////////////////////////////
// RC5 Types

// RC5 Word
typedef unsigned long int RC5_WORD;

// RC5 Crypt Context Handle
typedef unsigned long int HRC5CONTEXT;

// RC5 CBC Crypt Context
typedef struct tagRC5CBCCONTEXT {
	BYTE cCbcMode;
	BYTE *pbInitVector; // CBC Initialization Vector
	BYTE *pbChainBlock; // Chaining block
	BYTE *pbBuffer;
	UINT nBuffer; // Buffer index
} RC5CBCCONTEXT, *LPRC5CBCCONTEXT;

// RC5 Crypt Context
typedef struct tagRC5CONTEXT {
	long lVersion; // Big-Endian
	BYTE cWordSize; // Bits
	BYTE cRounds;
	BYTE cKeyBytes; // Bytes in private key
	BYTE cKeyWords; // = ceil(8 * cKeyBytes / cWordSize)
	UINT nExpandedSize; // = 2 * (cRounds + 1)
	RC5_WORD *pwExpanded;
	LPRC5CBCCONTEXT *pRc5Cbc; // Optional (null for Block Cipher)
} RC5CONTEXT, *LPRC5CONTEXT;

// CBC Modes
static const BYTE RC5_CBC = 0x01; // Usual Chain Block Cipher
static const BYTE RC5_CBC_PAD = 0x02; // Padded CBC

//////////////////////////////////////////////////////////////////////////
// RC5 Block Cipher API Functions

// Acquire RC5 Crypt context with cKeyBytes bytes in private key and
// cRounds rounds of encryption.
RC5_API BOOL Rc5AcquireContext(HRC5CONTEXT &hRc5, BYTE cKeyBytes, BYTE cRounds);

// Release context previously acquired with Rc5AcquireContext().
RC5_API BOOL Rc5ReleaseContext(HRC5CONTEXT &hRc5);

// Resets RC5 context so a new private key can be supplied.
// In order to change crypt settings, previous context must be
// released and a new context acquired.
RC5_API BOOL Rc5ResetContext(HRC5CONTEXT hRc5);

// Determines whether hRc5 is a valid context
RC5_API BOOL Rc5ValidContext(HRC5CONTEXT hRc5);

// Assigns a text private key. It can be deleted later since it becomes
// mixed into RC5CONTEXT internal structures.
RC5_API BOOL Rc5SetPrivateKey(HRC5CONTEXT hRc5, TCHAR *pszKey);

// Assigns a binary private key. It must be cKeyBytes long.
RC5_API BOOL Rc5SetBinaryPrivateKey(HRC5CONTEXT hRc5, BYTE *pKey);

// Encrypts two 32-bit words from pwPlain to pwCipher
RC5_API BOOL Rc5Encrypt(HRC5CONTEXT hRc5, RC5_WORD *pwPlain, RC5_WORD *pwCipher);

// Decrypts two 32-bit words from pwCipher to pwPlain
RC5_API BOOL Rc5Decrypt(HRC5CONTEXT hRc5, RC5_WORD *pwCipher, RC5_WORD *pwPlain);

// Encrypts a block of nBlock * 2 RC5_WORDs (i.e nBlock 64-bit blocks)
RC5_API BOOL Rc5EncryptBlock(HRC5CONTEXT hRc5, RC5_WORD *pwPlain, RC5_WORD *pwCipher, UINT nBlocks);

// Decrypts a block of nBlock * 2 RC5_WORDs (i.e nBlock 64-bit blocks)
RC5_API BOOL Rc5DecryptBlock(HRC5CONTEXT hRc5, RC5_WORD *pwCipher, RC5_WORD *pwPlain, UINT nBlocks);

// Recrypts block by decrypting it in the source context and encrypting in a new one
RC5_API BOOL Rc5Recrypt(HRC5CONTEXT hRc5Src, HRC5CONTEXT hRc5Dest, RC5_WORD *pwCipherSrc, RC5_WORD *pwCipherDest);

// Recrypts block of nBlock * 2 RC5_WORDs (i.e nBlock 64-bit blocks) by decrypting it in the source 
// context and encrypting in a new one.
RC5_API BOOL Rc5RecryptBlock(HRC5CONTEXT hRc5Src, HRC5CONTEXT hRc5Dest, RC5_WORD *pwCipherSrc, 
							 RC5_WORD *pwCipherDest, UINT nBlocks);

//////////////////////////////////////////////////////////////////////////
// RC5 CBC API Functions

// Acquires RC5 CBC crypting context.
RC5_API BOOL Rc5CbcAcquireContext(HRC5CONTEXT &hRc5, BYTE cKeyBytes, BYTE cRounds, BYTE cCbcMode);

// Releases
RC5_API BOOL Rc5CbcReleaseContext(HRC5CONTEXT &hRc5);

// Resets context
RC5_API BOOL Rc5CbcResetContext(HRC5CONTEXT &hRc5);

// Assigns a binary private key
RC5_API BOOL Rc5CbcSetBinaryPrivateKey(HRC5CONTEXT hRc5, BYTE *pbKey);

#endif // __RC5H_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions