#include "uniqueID.h" #include "minorGems/crypto/hashes/sha1.h" #include "minorGems/util/log/AppLog.h" #include #include uniqueID defaultID = { { 0, 0, 0, 0, 0, 0 } }; uniqueID makeUniqueID( unsigned char *inData, int inLength ) { uniqueID returnValue; unsigned char *hash = computeRawSHA1Digest( inData, inLength ); // only first U bytes of hash used memcpy( returnValue.bytes, hash, U ); delete [] hash; return returnValue; } partialUniqueID startUniqueID() { SHA_CTX ctx; SHA1_Init( &ctx ); return ctx; } partialUniqueID addToUniqueID( partialUniqueID inPartial, unsigned char *inData, int inLength ) { // update overwites data unsigned char *buffer = new unsigned char[inLength]; memcpy( buffer, inData, inLength ); SHA1_Update( &inPartial, buffer, inLength ); delete [] buffer; return inPartial; } uniqueID makeUniqueID( partialUniqueID inPartial ) { uniqueID returnValue; unsigned char resultBuffer[ SHA1_DIGEST_LENGTH ]; SHA1_Final( resultBuffer, &inPartial ); memcpy( returnValue.bytes, resultBuffer, U ); return returnValue; } uniqueID readUniqueID( unsigned char *inBytes, int inLength, int *outNumUsed ) { uniqueID returnValue; if( inLength >= U ) { memcpy( returnValue.bytes, inBytes, U ); *outNumUsed = U; } else { AppLog::error( "ERROR: not enough bytes in data string for a uniqueID\n" ); *outNumUsed = -1; } return returnValue; } char readUniqueIDs( uniqueID *outDest, int inNumToRead, unsigned char *inBytes, int inLength, int *outNumUsed ) { *outNumUsed = 0; for( int i=0; ibytes, raw, U ); delete [] raw; return true; }