System-Hashing

HMAC
HMAC is a mechanism for message authentication using cryptographic hash functions. HMAC can be used with any iterative cryptographic hash function, e.g., MD5, SHA-1, in combination with a secret shared key. The cryptographic strength of HMAC depends on the properties of the underlying hash function.
See RFC 2114.
destroy
digestMessage:
digestSize
key:
on:
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
setHash:
HashFunction
A HashFunction is xxxxxxxxx.
Instance Variables
blockSize
doubleHashMessage:
SHA1 new doubleHashMessage: 'foo'
doubleHashStream:
hashMessage:
MD5 new hashMessage: 'foo'
hashSize
hashStream:
hmac
MD5
This class implements the MD5 128-bit one-way hash function. It uses the MD5Plugin for better performance. Some methods are taken from the original version of MD5NonPrimitive.
blockSize
finalValue
hashSize
hashStream:
initialize
Some magic numbers to get the process started
isPluginAvailable
new
primProcessBuffer:withState:
processBuffer:
processFinalBuffer:bitLength:
Pad the buffer until we have an even 64 bytes, then transform
storeLength:in:
Fill in the final 8 bytes of the given ByteArray with a 64-bit
little-endian representation of the original message length in bits.
MD5NonPrimitive
This class implements the MD5 128-bit one-way hash function. It relies on
the ThirtyTwoBitRegister class supplied as part of the "Digital Signatures"
functionality included in Squeak 2.7. As of this date (1/20/2000), the
U.S. Government has lifted many of the previous restrictions on the export
of encryption software, but you should check before exporting anything
including this code. MD5 is commonly used for some secure Internet
protocols, including authentication in HTTP, which is why I wrote it.
Submitted by Duane Maxwell
fX:Y:Z:
compute 'xy or (not x)z'
ffA:B:C:D:M:S:T:
compute a = b + ((a + f(b,c,d) + m + t) <<< s)
finalValue
Concatenate the state values to produce the 128-bite result
gX:Y:Z:
compute 'xz or y(not z)'
ggA:B:C:D:M:S:T:
compute a = b + ((a + g(b,c,d) + m + t) <<< s)
hX:Y:Z:
compute 'x xor y xor z'
hhA:B:C:D:M:S:T:
compute a = b + ((a + h(b,c,d) + m + t) <<< s)
iX:Y:Z:
compute 'y xor (x or (not z))'
iiA:B:C:D:M:S:T:
compute a = b + ((a + i(b,c,d) + m + t) <<< s)
initialize
Some magic numbers to get the process started
processBuffer:
Process a 64-byte buffer
round:selector:round:
Do one round with the given function
rounds:
Perform the four rounds with different functions
step:template:selector:
Perform one step in the round
SHA1
This class implements the Secure Hash Algorithm (SHA) described in the U.S. government's Secure Hash Standard (SHS). This standard is described in FIPS PUB 180-1, "SECURE HASH STANDARD", April 17, 1995.
The Secure Hash Algorithm is also described on p. 442 of 'Applied Cryptography: Protocols, Algorithms, and Source Code in C' by Bruce Scheier, Wiley, 1996.
See the comment in class DigitalSignatureAlgorithm for details on its use.
Implementation notes:
The secure hash standard was created with 32-bit hardware in mind. All arithmetic in the hash computation must be done modulo 2^32. This implementation uses ThirtyTwoBitRegister objects to simulate hardware registers; this implementation is about six times faster than using LargePositiveIntegers (measured on a Macintosh G3 Powerbook). Implementing a primitive to process each 64-byte buffer would probably speed up the computation by a factor of 20 or more.
blockSize
constantForStep:
Answer the constant for the i-th step of the block hash loop. We number our steps 1-80, versus the 0-79 of the standard.
expandedBlock:
Convert the given 64 byte buffer into 80 32-bit registers and answer the result.
finalHash
Concatenate the final totals to build the 160-bit integer result.
hashFunction:of:with:with:
Compute the hash function for the i-th step of the block hash loop. We number our steps 1-80, versus the 0-79 of the standard.
hashInteger:
Hash the given positive integer. The integer to be hashed should have 512 or fewer bits. This entry point is used in key generation.
hashInteger:seed:
Hash the given positive integer. The integer to be hashed should have 512 or fewer bits. This entry point is used in the production of random numbers
hashSize
hashStream:
Hash the contents of the given stream from the current position to the end using the Secure Hash Algorithm. The SHA algorithm is defined in FIPS PUB 180-1. It is also described on p. 442 of 'Applied Cryptography: Protocols, Algorithms, and Source Code in C' by Bruce Scheier, Wiley, 1996.
initialize
Subclasses should redefine this method to perform initializations on instance creation
initializeTotals
Initialize totalA through totalE to their seed values.
initializeTotalsArray
Initialize the totals array from the registers for use with the primitives.
primExpandBlock:into:
Expand the given 64-byte buffer into the given Bitmap of length 80.
primHasSecureHashPrimitive
Answer true if this platform has primitive support for the Secure Hash Algorithm.
primHashBlock:using:
Hash the given block (a Bitmap) of 80 32-bit words, using the given workingTotals.
processBuffer:
Process given 64-byte buffer, accumulating the results in totalA through totalE.
processBufferUsingPrimitives:
Process given 64-byte buffer using the primitives, accumulating the results in totals.
processFinalBuffer:bitLength:
Process given buffer, whose length may be <= 64 bytes, accumulating the results in totalA through totalE. Also process the final padding bits and length.
storeLength:in:
Fill in the final 8 bytes of the given ByteArray with a 64-bit big-endian representation of the original message length in bits.