1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Remove all the Digest stuff from pnUtCrypt.

This commit is contained in:
Darryl Pogue
2012-02-12 15:23:31 -08:00
parent 7a5d61f7c8
commit 39e8dd1b3c
4 changed files with 48 additions and 172 deletions

View File

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtStr.h"
#include "pnUtTime.h"
#include <openssl/sha.h>
#include <openssl/rc4.h>
/*****************************************************************************
@ -72,8 +71,6 @@ struct CryptKey {
namespace Crypt {
ShaDigest s_shaSeed;
/*****************************************************************************
*
@ -81,26 +78,6 @@ ShaDigest s_shaSeed;
*
***/
//============================================================================
void ShaProcess (
void * dest,
unsigned sourceCount,
const unsigned sourceBytes[],
const void * sourcePtrs[]
) {
// initialize digest
SHA_CTX sha;
SHA_Init(&sha);
// hash data streams
for (unsigned index = 0; index < sourceCount; ++index)
SHA_Update(&sha, sourcePtrs[index], sourceBytes[index]);
// complete hashing
SHA_Final((unsigned char *)dest, &sha);
}
/*****************************************************************************
*
* RC4
@ -144,39 +121,6 @@ static void Rc4Codec (
*
***/
//============================================================================
void CryptDigest (
ECryptAlgorithm algorithm,
void * dest, // must be sized to the algorithm's digest size
const unsigned sourceBytes,
const void * sourceData
) {
CryptDigest(
algorithm,
dest,
1,
&sourceBytes,
&sourceData
);
}
//============================================================================
void CryptDigest (
ECryptAlgorithm algorithm,
void * dest, // must be sized to the algorithm's digest size
unsigned sourceCount,
const unsigned sourceBytes[], // [sourceCount]
const void * sourcePtrs[] // [sourceCount]
) {
switch (algorithm) {
case kCryptSha:
ShaProcess(dest, sourceCount, sourceBytes, sourcePtrs);
break;
DEFAULT_FATAL(algorithm);
}
}
//============================================================================
CryptKey * CryptKeyCreate (
ECryptAlgorithm algorithm,
@ -231,78 +175,6 @@ unsigned CryptKeyGetBlockSize (
}
}
//============================================================================
void CryptCreateRandomSeed (
unsigned bytes,
uint8_t * data
) {
COMPILER_ASSERT(SHA_DIGEST_LENGTH == 20);
// Combine seed with input data
{
unsigned seedIndex = 0;
unsigned dataIndex = 0;
unsigned cur = 0;
unsigned end = max(bytes, sizeof(s_shaSeed));
for (; cur < end; ++cur) {
s_shaSeed[seedIndex] ^= data[dataIndex];
if (++seedIndex >= sizeof(s_shaSeed))
seedIndex = 0;
if (++dataIndex >= bytes)
dataIndex = 0;
}
((uint32_t*)s_shaSeed)[2] ^= (uint32_t) &bytes;
((uint32_t*)s_shaSeed)[3] ^= (uint32_t) bytes;
((uint32_t*)s_shaSeed)[4] ^= (uint32_t) data;
}
// Hash seed
ShaDigest digest;
CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), s_shaSeed);
// Update output with contents of digest
{
unsigned src = 0;
unsigned dst = 0;
unsigned cur = 0;
unsigned end = max(bytes, sizeof(digest));
for (; cur < end; ++cur) {
data[dst] ^= ((const uint8_t *) &digest)[src];
if (++src >= sizeof(digest))
src = 0;
if (++dst >= bytes)
dst = 0;
}
}
// Combine seed with digest
for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) {
s_shaSeed[i] ^= digest[i];
}
}
//============================================================================
void CryptCreateFastWeakChallenge (
unsigned * challenge,
unsigned val1,
unsigned val2
) {
s_shaSeed.data[0] ^= TimeGetMs(); // looping time
s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1);
s_shaSeed.data[0] ^= (unsigned) TimeGetTime(); // global time
s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1);
s_shaSeed.data[0] ^= *challenge; // unknown
s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1);
s_shaSeed.data[0] ^= (unsigned) challenge; // variable address
s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1);
s_shaSeed.data[0] ^= val1;
s_shaSeed.data[0] ^= _rotl(s_shaSeed.data[0], 1);
s_shaSeed.data[0] ^= val2;
*challenge = s_shaSeed.data[0];
}
//============================================================================
void CryptEncrypt (
CryptKey * key,

View File

@ -61,35 +61,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
struct CryptKey;
enum ECryptAlgorithm {
kCryptSha,
kCryptRc4,
kCryptRsa,
kNumCryptAlgorithms
};
/*****************************************************************************
*
* Digest functions
*
***/
void CryptDigest (
ECryptAlgorithm algorithm,
void * dest, // must be sized to the algorithm's digest size
const unsigned sourceBytes,
const void * sourceData
);
void CryptDigest (
ECryptAlgorithm algorithm,
void * dest, // must be sized to the algorithm's digest size
unsigned sourceCount,
const unsigned sourceBytes[], // [sourceCount]
const void * sourcePtrs[] // [sourceCount]
);
/*****************************************************************************
*
* Key generation
@ -119,18 +96,6 @@ unsigned CryptKeyGetBlockSize (
CryptKey * key
);
void CryptCreateRandomSeed (
unsigned bytes,
uint8_t * data
);
void CryptCreateFastWeakChallenge (
unsigned * challenge,
unsigned val1,
unsigned val2
);
/*****************************************************************************
*
* Encryption and Decryption