remove Sapphire

pull/2/head
weidai 2002-10-18 19:48:45 +00:00
parent deea52fd3b
commit 55fe26233e
5 changed files with 5 additions and 300 deletions

View File

@ -18,7 +18,7 @@ Joan Daemen - 3way.cpp
Leonard Janke - cast.cpp, seal.cpp Leonard Janke - cast.cpp, seal.cpp
Steve Reid - cast.cpp Steve Reid - cast.cpp
Phil Karn - des.cpp Phil Karn - des.cpp
Michael Paul Johnson - diamond.cpp, sapphire.cpp Michael Paul Johnson - diamond.cpp
Andrew M. Kuchling - md2.cpp, md4.cpp Andrew M. Kuchling - md2.cpp, md4.cpp
Colin Plumb - md5.cpp, md5mac.cpp Colin Plumb - md5.cpp, md5mac.cpp
Seal Woods - rc6.cpp Seal Woods - rc6.cpp

View File

@ -11,8 +11,7 @@ This library includes:
3-WAY, GOST, SHARK, CAST-128, Square, Skipjack 3-WAY, GOST, SHARK, CAST-128, Square, Skipjack
- generic block cipher modes: ECB, CBC, CBC ciphertext stealing (CTS), - generic block cipher modes: ECB, CBC, CBC ciphertext stealing (CTS),
CFB, OFB, counter (CTR) mode CFB, OFB, counter (CTR) mode
- stream ciphers: Panama, ARC4, SEAL, WAKE, WAKE-OFB, Sapphire II, - stream ciphers: Panama, ARC4, SEAL, WAKE, WAKE-OFB, BlumBlumShub
BlumBlumShub
- public key cryptography: RSA, DSA, ElGamal, Nyberg-Rueppel (NR), Rabin, - public key cryptography: RSA, DSA, ElGamal, Nyberg-Rueppel (NR), Rabin,
Rabin-Williams (RW), LUC, LUCELG, DLIES (variants of DHAES), ESIGN Rabin-Williams (RW), LUC, LUCELG, DLIES (variants of DHAES), ESIGN
- padding schemes for public-key systems: PKCS#1 v2.0, OAEP, PSSR, IEEE - padding schemes for public-key systems: PKCS#1 v2.0, OAEP, PSSR, IEEE
@ -247,3 +246,4 @@ History
5.1 (in development) 5.1 (in development)
- fixed a bug in CBC and ECB modes with processing non-aligned data - fixed a bug in CBC and ECB modes with processing non-aligned data
- removed Sapphire

View File

@ -54,7 +54,6 @@
#include "modes.h" #include "modes.h"
#include "mdc.h" #include "mdc.h"
#include "lubyrack.h" #include "lubyrack.h"
#include "sapphire.h"
#include "tea.h" #include "tea.h"
#include "dh.h" #include "dh.h"
#include "mqv.h" #include "mqv.h"

View File

@ -1,179 +0,0 @@
// sapphire.cpp -- modified by Wei Dai from:
/* sapphire.cpp -- the Saphire II stream cipher class.
Dedicated to the Public Domain the author and inventor:
(Michael Paul Johnson). This code comes with no warranty.
Use it at your own risk.
Ported from the Pascal implementation of the Sapphire Stream
Cipher 9 December 1994.
Added hash pre- and post-processing 27 December 1994.
Modified initialization to make index variables key dependent,
made the output function more resistant to cryptanalysis,
and renamed to Sapphire II 2 January 1995
*/
#include "pch.h"
#include "sapphire.h"
NAMESPACE_BEGIN(CryptoPP)
byte SapphireBase::keyrand(unsigned int limit,
const byte *user_key,
byte keysize,
byte *rsum,
unsigned *keypos)
{
unsigned u, // Value from 0 to limit to return.
retry_limiter, // No infinite loops allowed.
mask; // Select just enough bits.
retry_limiter = 0;
mask = 1; // Fill mask with enough bits to cover
while (mask < limit) // the desired range.
mask = (mask << 1) + 1;
do
{
*rsum = cards[*rsum] + user_key[(*keypos)++];
if (*keypos >= keysize)
{
*keypos = 0; // Recycle the user key.
*rsum += keysize; // key "aaaa" != key "aaaaaaaa"
}
u = mask & *rsum;
if (++retry_limiter > 11)
u %= limit; // Prevent very rare long loops.
}
while (u > limit);
return u;
}
SapphireBase::SapphireBase()
: cards(256)
{
}
SapphireBase::SapphireBase(const byte *key, unsigned int keysize)
: cards(256)
{
assert(keysize < 256);
// Key size may be up to 256 bytes.
// Pass phrases may be used directly, with longer length
// compensating for the low entropy expected in such keys.
// Alternatively, shorter keys hashed from a pass phrase or
// generated randomly may be used. For random keys, lengths
// of from 4 to 16 bytes are recommended, depending on how
// secure you want this to be.
int i;
byte rsum;
unsigned keypos;
// Start with cards all in order, one of each.
for (i=0;i<256;i++)
cards[i] = i;
// Swap the card at each position with some other card.
keypos = 0; // Start with first byte of user key.
rsum = 0;
for (i=255;i;i--)
std::swap(cards[i], cards[keyrand(i, key, keysize, &rsum, &keypos)]);
// Initialize the indices and data dependencies.
// Indices are set to different values instead of all 0
// to reduce what is known about the state of the cards
// when the first byte is emitted.
rotor = cards[1];
ratchet = cards[3];
avalanche = cards[5];
last_plain = cards[7];
last_cipher = cards[rsum];
rsum = 0;
keypos = 0;
}
SapphireBase::~SapphireBase()
{
rotor = ratchet = avalanche = last_plain = last_cipher = 0;
}
void SapphireEncryption::ProcessString(byte *outString, const byte *inString, unsigned int length)
{
while(length--)
*outString++ = SapphireEncryption::ProcessByte(*inString++);
}
void SapphireEncryption::ProcessString(byte *inoutString, unsigned int length)
{
while(length--)
{
*inoutString = SapphireEncryption::ProcessByte(*inoutString);
inoutString++;
}
}
void SapphireDecryption::ProcessString(byte *outString, const byte *inString, unsigned int length)
{
while(length--)
*outString++ = SapphireDecryption::ProcessByte(*inString++);
}
void SapphireDecryption::ProcessString(byte *inoutString, unsigned int length)
{
while(length--)
{
*inoutString = SapphireDecryption::ProcessByte(*inoutString);
inoutString++;
}
}
SapphireHash::SapphireHash(unsigned int hashLength)
: hashLength(hashLength)
{
Init();
}
void SapphireHash::Init()
{
// This function is used to initialize non-keyed hash
// computation.
int i, j;
// Initialize the indices and data dependencies.
rotor = 1;
ratchet = 3;
avalanche = 5;
last_plain = 7;
last_cipher = 11;
// Start with cards all in inverse order.
for (i=0, j=255;i<256;i++,j--)
cards[i] = (byte) j;
}
void SapphireHash::Update(const byte *input, unsigned int length)
{
while(length--)
SapphireEncryption::ProcessByte(*input++);
}
void SapphireHash::TruncatedFinal(byte *hash, unsigned int size)
{
ThrowIfInvalidTruncatedSize(size);
for (int i=255; i>=0; i--)
ProcessByte((byte) i);
for (unsigned int j=0; j<size; j++)
hash[j] = ProcessByte(0);
Init();
}
NAMESPACE_END

View File

@ -1,115 +0,0 @@
#ifndef CRYPTOPP_SAPPHIRE_H
#define CRYPTOPP_SAPPHIRE_H
#include "seckey.h"
#include "secblock.h"
NAMESPACE_BEGIN(CryptoPP)
/// base class, do not use directly
class SapphireBase : public VariableKeyLength<16, 1, 255>
{
protected:
SapphireBase();
SapphireBase(const byte *userKey, unsigned int keyLength);
~SapphireBase();
inline void ShuffleCards()
{
ratchet += cards[rotor++];
byte swaptemp = cards[last_cipher];
cards[last_cipher] = cards[ratchet];
cards[ratchet] = cards[last_plain];
cards[last_plain] = cards[rotor];
cards[rotor] = swaptemp;
avalanche += cards[swaptemp];
}
// These variables comprise the state of the state machine.
SecByteBlock cards; // A permutation of 0-255.
byte rotor, // Index that rotates smoothly
ratchet, // Index that moves erratically
avalanche, // Index heavily data dependent
last_plain, // Last plain text byte
last_cipher; // Last cipher text byte
private:
byte keyrand(unsigned int limit, const byte *user_key, byte keysize, byte *rsum, unsigned *keypos);
};
/// <a href="http://www.weidai.com/scan-mirror/cs.html#Sapphire-II">Sapphire-II Cipher</a>
class SapphireEncryption : public StreamTransformation, public SapphireBase
{
public:
SapphireEncryption(const byte *userKey, unsigned int keyLength=DEFAULT_KEYLENGTH)
: SapphireBase(userKey, keyLength) {}
inline byte ProcessByte(byte b)
{
ShuffleCards();
last_cipher = b^cards[(cards[ratchet] + cards[rotor]) & 0xFF] ^
cards[cards[(cards[last_plain] +
cards[last_cipher] +
cards[avalanche])&0xFF]];
last_plain = b;
return last_cipher;
}
void ProcessString(byte *outString, const byte *inString, unsigned int length);
void ProcessString(byte *inoutString, unsigned int length);
protected:
SapphireEncryption() {} // for SapphireHash
};
/// <a href="http://www.weidai.com/scan-mirror/cs.html#Sapphire-II">Sapphire-II cipher</a>
class SapphireDecryption : public StreamTransformation, public SapphireBase
{
public:
SapphireDecryption(const byte *userKey, unsigned int keyLength=DEFAULT_KEYLENGTH)
: SapphireBase(userKey, keyLength) {}
inline byte ProcessByte(byte b)
{
ShuffleCards();
last_plain = b^cards[(cards[ratchet] + cards[rotor]) & 0xFF] ^
cards[cards[(cards[last_plain] +
cards[last_cipher] +
cards[avalanche])&0xFF]];
last_cipher = b;
return last_plain;
}
void ProcessString(byte *outString, const byte *inString, unsigned int length);
void ProcessString(byte *inoutString, unsigned int length);
};
/// Sapphire Random Number Generator
class SapphireRNG : public RandomNumberGenerator, private SapphireEncryption
{
public:
SapphireRNG(const byte *seed, unsigned int seedLength)
: SapphireEncryption(seed, seedLength) {}
inline byte GetByte() {return SapphireEncryption::ProcessByte(0);}
};
//! Sapphire Hash
/*! Digest Length = 160 bits */
class SapphireHash : public HashTransformation, private SapphireEncryption
{
public:
SapphireHash(unsigned int hashLength=20);
void Update(const byte *input, unsigned int length);
void TruncatedFinal(byte *hash, unsigned int size);
unsigned int DigestSize() const {return hashLength;}
private:
void Init();
const unsigned int hashLength;
};
NAMESPACE_END
#endif