ON_SHA1 is a small class for calculating the SHA-1 hash of a sequence of bytes. It may be use incrementally (the bytes do not have to be in a contiguous array in memory at one time). More...

#include <opennurbs_sha1.h>

Public Member Functions

 ON_SHA1 ()=default
 
 ON_SHA1 (const ON_SHA1 &)=default
 
 ~ON_SHA1 ()=default
 
void Accumulate2dPoint (const class ON_2dPoint &point)
 
void Accumulate2dVector (const class ON_2dVector &vector)
 
void Accumulate3dPoint (const class ON_3dPoint &point)
 
void Accumulate3dVector (const class ON_3dVector &vector)
 
void Accumulate4dPoint (const class ON_4dPoint &point)
 
void AccumulateBool (bool b)
 
void AccumulateBoundingBox (const class ON_BoundingBox &bbox)
 
void AccumulateBytes (const void *buffer, ON__UINT64 sizeof_buffer)
 Make one or more calls to AccumulateBytes() as the sequenence of bytes is available. More...
 
void AccumulateDouble (double x)
 Add the double value to the SHA1 in a manner that -0.0 and +0.0 will generate identical SHA-1 values and the result is independent of endian byte order. More...
 
void AccumulateDoubleArray (size_t count, const double *a)
 Add the double value to the SHA1 in a manner that -0.0 and +0.0 will generate identical SHA-1 values and the result is independent of endian byte order. More...
 
void AccumulateFileReference (const class ON_FileReference &file_reference)
 Accumuates the full and relative path names. More...
 
void AccumulateId (const ON_UUID &id)
 
void AccumulateInteger16 (ON__INT16 i)
 
void AccumulateInteger32 (ON__INT32 i)
 
void AccumulateInteger64 (ON__INT64 i)
 
void AccumulateInteger8 (ON__INT8 i)
 
void AccumulateLengthUnitSystem (const ON::LengthUnitSystem length_unit_system)
 
void AccumulateString (const class ON_String &str)
 
void AccumulateString (const class ON_wString &str)
 
void AccumulateString (const char *sUTF8, int element_count, ON_StringMapOrdinalType mapping)
 
void AccumulateString (const wchar_t *sUTF8, int element_count, ON_StringMapOrdinalType mapping)
 
void AccumulateString (const class ON_String &str, ON_StringMapOrdinalType mapping)
 
void AccumulateString (const class ON_wString &str, ON_StringMapOrdinalType mapping)
 
void AccumulateSubHash (const class ON_SHA1_Hash &sub_hash)
 
void AccumulateTransformation (const class ON_Xform &xform)
 
void AccumulateUnitSystem (const class ON_UnitSystem &unit_system)
 
void AccumulateUnsigned16 (ON__UINT16 u)
 
void AccumulateUnsigned32 (ON__UINT32 u)
 
void AccumulateUnsigned64 (ON__UINT64 u)
 
void AccumulateUnsigned8 (ON__UINT8 u)
 
ON__UINT64 ByteCount () const
 
ON_SHA1_Hash Hash () const
 
ON_SHA1operator= (const ON_SHA1 &)=default
 
void Reset ()
 Reset this ON_SHA1 class so it can be reused. More...
 

Static Public Member Functions

static bool Validate ()
 This is a static function that uses ON_SHA1 to compute SHA-1 hash values of sequences of bytes with known SHA-1 hash values and compares the results from ON_SHA1 with the known SHA-1 hash values. More...
 

Detailed Description

ON_SHA1 is a small class for calculating the SHA-1 hash of a sequence of bytes. It may be use incrementally (the bytes do not have to be in a contiguous array in memory at one time).

The ON_SHA1 class cannot be used for cryptographic or security applications. The SHA-1 hash algorithm is not suitable for cryptographic or security applications. The ON_SHA1 class does not "wipe" intermediate results.

If you have two different seqences of N bytes storing information (lower entropy than a random sequence) are you are not intentionally calculating the information to create a SHA-1 hash collision, then the probability that the sequences have the same SHA-1 hash is approximately 2^-80 ~ 10^-24.

Constructor & Destructor Documentation

◆ ON_SHA1() [1/2]

ON_SHA1::ON_SHA1 ( )
default

◆ ~ON_SHA1()

ON_SHA1::~ON_SHA1 ( )
default

◆ ON_SHA1() [2/2]

ON_SHA1::ON_SHA1 ( const ON_SHA1 )
default

Member Function Documentation

◆ Accumulate2dPoint()

void ON_SHA1::Accumulate2dPoint ( const class ON_2dPoint point)

◆ Accumulate2dVector()

void ON_SHA1::Accumulate2dVector ( const class ON_2dVector vector)

◆ Accumulate3dPoint()

void ON_SHA1::Accumulate3dPoint ( const class ON_3dPoint point)

◆ Accumulate3dVector()

void ON_SHA1::Accumulate3dVector ( const class ON_3dVector vector)

◆ Accumulate4dPoint()

void ON_SHA1::Accumulate4dPoint ( const class ON_4dPoint point)

◆ AccumulateBool()

void ON_SHA1::AccumulateBool ( bool  b)

◆ AccumulateBoundingBox()

void ON_SHA1::AccumulateBoundingBox ( const class ON_BoundingBox bbox)

◆ AccumulateBytes()

void ON_SHA1::AccumulateBytes ( const void *  buffer,
ON__UINT64  sizeof_buffer 
)

Make one or more calls to AccumulateBytes() as the sequenence of bytes is available.

Parameters
buffer[in]
sizeof_buffer[in] number of bytes in buffer

◆ AccumulateDouble()

void ON_SHA1::AccumulateDouble ( double  x)

Add the double value to the SHA1 in a manner that -0.0 and +0.0 will generate identical SHA-1 values and the result is independent of endian byte order.

◆ AccumulateDoubleArray()

void ON_SHA1::AccumulateDoubleArray ( size_t  count,
const double *  a 
)

Add the double value to the SHA1 in a manner that -0.0 and +0.0 will generate identical SHA-1 values and the result is independent of endian byte order.

◆ AccumulateFileReference()

void ON_SHA1::AccumulateFileReference ( const class ON_FileReference file_reference)

Accumuates the full and relative path names.

◆ AccumulateId()

void ON_SHA1::AccumulateId ( const ON_UUID id)

◆ AccumulateInteger16()

void ON_SHA1::AccumulateInteger16 ( ON__INT16  i)

◆ AccumulateInteger32()

void ON_SHA1::AccumulateInteger32 ( ON__INT32  i)

◆ AccumulateInteger64()

void ON_SHA1::AccumulateInteger64 ( ON__INT64  i)

◆ AccumulateInteger8()

void ON_SHA1::AccumulateInteger8 ( ON__INT8  i)

◆ AccumulateLengthUnitSystem()

void ON_SHA1::AccumulateLengthUnitSystem ( const ON::LengthUnitSystem  length_unit_system)

◆ AccumulateString() [1/6]

void ON_SHA1::AccumulateString ( const class ON_String str)

◆ AccumulateString() [2/6]

void ON_SHA1::AccumulateString ( const class ON_wString str)

◆ AccumulateString() [3/6]

void ON_SHA1::AccumulateString ( const char *  sUTF8,
int  element_count,
ON_StringMapOrdinalType  mapping 
)

◆ AccumulateString() [4/6]

void ON_SHA1::AccumulateString ( const wchar_t *  sUTF8,
int  element_count,
ON_StringMapOrdinalType  mapping 
)

◆ AccumulateString() [5/6]

void ON_SHA1::AccumulateString ( const class ON_String str,
ON_StringMapOrdinalType  mapping 
)

◆ AccumulateString() [6/6]

void ON_SHA1::AccumulateString ( const class ON_wString str,
ON_StringMapOrdinalType  mapping 
)

◆ AccumulateSubHash()

void ON_SHA1::AccumulateSubHash ( const class ON_SHA1_Hash sub_hash)

◆ AccumulateTransformation()

void ON_SHA1::AccumulateTransformation ( const class ON_Xform xform)

◆ AccumulateUnitSystem()

void ON_SHA1::AccumulateUnitSystem ( const class ON_UnitSystem unit_system)

◆ AccumulateUnsigned16()

void ON_SHA1::AccumulateUnsigned16 ( ON__UINT16  u)

◆ AccumulateUnsigned32()

void ON_SHA1::AccumulateUnsigned32 ( ON__UINT32  u)

◆ AccumulateUnsigned64()

void ON_SHA1::AccumulateUnsigned64 ( ON__UINT64  u)

◆ AccumulateUnsigned8()

void ON_SHA1::AccumulateUnsigned8 ( ON__UINT8  u)

◆ ByteCount()

ON__UINT64 ON_SHA1::ByteCount ( ) const
Returns
Total number of bytes passed to Update().

◆ Hash()

ON_SHA1_Hash ON_SHA1::Hash ( ) const
Returns
SHA-1 hash value of the sequenence of ByteCount() bytes that have been passed to this ON_SHA1 classe's Update() function since construction or the last call to Reset().

You may use Hash() to compute intermediate SHA-1 hash values.

Put another way, you may call Update() zero or more times passing in N1 bytes, call Digest() to get the SHA-1 hash of those N1 bytes, make zero or more additional calls to Update() passing in N2 additional bytes, call digest to get the SHA-1 hash of the seqence of (N1 + N2) bytes, and so on.

◆ operator=()

ON_SHA1& ON_SHA1::operator= ( const ON_SHA1 )
default

◆ Reset()

void ON_SHA1::Reset ( )

Reset this ON_SHA1 class so it can be reused.

◆ Validate()

static bool ON_SHA1::Validate ( )
static

This is a static function that uses ON_SHA1 to compute SHA-1 hash values of sequences of bytes with known SHA-1 hash values and compares the results from ON_SHA1 with the known SHA-1 hash values.

This function can be used to validate the ON_SHA1 class compiled correctly.

Returns
true All validation tests passed. false At least one validation test failed.