From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:31:29 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>SHAHash</name> <environment>Security</environment> <super>Security.Hash</super> <private>false</private> none h0 h1 h2 h3 h4 a b c d e w nlf xnlf <imports></imports> <category>Security-Hashes</category> <attributes> <package>SHA</package> </attributes> </class> <comment> Security.SHAHash
This is an abstract superclass of implementations of SHA hashing algorithm, FIPS PUB 180-2 'Secure Hash Standard', available online from http://csrc.nist.gov/CryptoToolkit/tkhash.html. It maintains common aspects of the various 'clones' of the basic algorithm. Instance variable naming follows the convention in the specification. Instance Variables: h0 <ThirtyTwoBitRegister> digest register h1 <ThirtyTwoBitRegister> digest register h2 <ThirtyTwoBitRegister> digest register h3 <ThirtyTwoBitRegister> digest register h4 <ThirtyTwoBitRegister> digest register a <ThirtyTwoBitRegister> work register A b <ThirtyTwoBitRegister> work register B c <ThirtyTwoBitRegister> work register C d <ThirtyTwoBitRegister> work register D e <ThirtyTwoBitRegister> work register E w <Array of <ThirtyTwoBitRegister>> 80 message schedule registers nlf <ThirtyTwoBitRegister> nonlinear function result register xnlf <ThirtyTwoBitRegister> nonlinear function scratch register
</comment> <class> <name>SHA</name> <environment>Security</environment> <super>Security.SHAHash</super> <private>false</private> none t k <imports></imports> <category>Security-Hashes</category> <attributes> <package>SHA</package> </attributes> </class> <comment> Security.SHA
This is an implementation of SHA-1 hashing algorithm, FIPS PUB 180-2 'Secure Hash Standard', available online from http://csrc.nist.gov/CryptoToolkit/tkhash.html. A less formal description of the algorithm is in Bruce Schneier's Applied Cryptography. Instance variable naming follows the convention in the specification. Instance Variables: t <ThirtyTwoBitRegister> work register T k <ThirtyTwoBitRegister> The constant K as described in the standard. Shared Class Variables: K1 <ThirtyTwoBitRegister> Constant K for rounds 1-20 as described in the standard. K2 <ThirtyTwoBitRegister> Constant K for rounds 21-40 as described in the standard. K3 <ThirtyTwoBitRegister> Constant K for rounds 41-60 as described in the standard. K4 <ThirtyTwoBitRegister> Constant K for rounds 61-80 as described in the standard.
</comment> <class> <name>SHA256</name> <environment>Security</environment> <super>Security.SHAHash</super> <private>false</private> none h5 h6 h7 f g h t1 t2 k <imports></imports> <category>Security-Hashes</category> <attributes> <package>SHA</package> </attributes> </class> <comment> Security.SHA256
This is an implementation of SHA-256 hashing algorithm, FIPS PUB 180-2 'Secure Hash Standard', available online from http://csrc.nist.gov/CryptoToolkit/tkhash.html. This algorithm is a fairly recent extension of the old algorithm. Compared to SHA-1 it attempts to further reduce the chance of 'collisions' by extending the size of the digest to 256 bits. It is however also significantly slower. Instance variable naming follows the convention in the specification. Instance Variables: h5 <ThirtyTwoBitRegister> digest register h6 <ThirtyTwoBitRegister> digest register h7 <ThirtyTwoBitRegister> digest register f <ThirtyTwoBitRegister> work register F g <ThirtyTwoBitRegister> work register G h <ThirtyTwoBitRegister> work register H t1 <ThirtyTwoBitRegister> temp register T1 t2 <ThirtyTwoBitRegister> temp register T2 k <Array of <ThirtyTwoBitRegister>> constant array K as described by the standard. Shared Class Variables: K <Array of: ThirtyTwoBitRegister> constant array K as described by the standard.
</comment> <name>K</name> <environment>Security.SHA256</environment> <private>false</private> <constant>false</constant> <category>constants</category> <initializer>Security.SHA256 prepareK</initializer> <attributes> <package>SHA</package> </attributes> <name>K1</name> <environment>Security.SHA</environment> <private>false</private> <constant>false</constant> <category>constants</category> <initializer>ThirtyTwoBitRegister new load: 16r5A827999</initializer> <attributes> <package>SHA</package> </attributes> <name>K2</name> <environment>Security.SHA</environment> <private>false</private> <constant>false</constant> <category>constants</category> <initializer>ThirtyTwoBitRegister new load: 16r6ED9EBA1</initializer> <attributes> <package>SHA</package> </attributes> <name>K3</name> <environment>Security.SHA</environment> <private>false</private> <constant>false</constant> <category>constants</category> <initializer>ThirtyTwoBitRegister new load: 16r8F1BBCDC</initializer> <attributes> <package>SHA</package> </attributes> <name>K4</name> <environment>Security.SHA</environment> <private>false</private> <constant>false</constant> <category>constants</category> <initializer>ThirtyTwoBitRegister new load: 16rCA62C1D6</initializer> <attributes> <package>SHA</package> </attributes> <methods> Security.SHAHash <category>private-algorithm</category>
chX: x Y: y Z: z "Ch(x,y,z) = (x and y) xor ((not x) and z)" xnlf set: x; bitInvert; bitAnd: z. nlf set: x; bitAnd: y; bitXor: xnlf
doBlock self subclassResponsibility
majX: x Y: y Z: z "Maj(x,y,z) = (x and y) xor (x and z) xor (y and z)" xnlf set: x; bitAnd: z. nlf set: x; bitAnd: y; bitXor: xnlf. xnlf set: y; bitAnd: z. nlf bitXor: xnlf
prepareWorkingRegisters a set: h0. b set: h1. c set: h2. d set: h3. e set: h4
processBlock self readBlock; prepareWorkingRegisters; doBlock; updateDigestRegisters
readBlock "read in the message block" 1 to: 16 do: [ :i | (w at: i) loadFrom: block at: (i - 1) * 4 + 1 ]. 17 to: 20 do: [ :i | self updateWAt: i ]
updateDigestRegisters h0 addIn: a. h1 addIn: b. h2 addIn: c. h3 addIn: d. h4 addIn: e.
</methods> <methods> Security.SHAHash <category>initialize-release</category>
initialize super initialize. h0 := ThirtyTwoBitRegister new. h1 := ThirtyTwoBitRegister new. h2 := ThirtyTwoBitRegister new. h3 := ThirtyTwoBitRegister new. h4 := ThirtyTwoBitRegister new. a := ThirtyTwoBitRegister new. b := ThirtyTwoBitRegister new. c := ThirtyTwoBitRegister new. d := ThirtyTwoBitRegister new. e := ThirtyTwoBitRegister new. nlf := ThirtyTwoBitRegister new. xnlf := ThirtyTwoBitRegister new. w := Array new: 80. 1 to: 20 do: [ :i | w at: i put: ThirtyTwoBitRegister new ]. 21 to: 80 do: [ :i | w at: i put: (w at: i - 20) ]. "just saving 60 register instances, they are not all needed at the same time"
</methods> <methods> Security.SHAHash <category>private-digest</category>
backupRegisters "This has to match with #restoreRegisters:" ^(Array new: 5) at: 1 put: h0 copy; at: 2 put: h1 copy; at: 3 put: h2 copy; at: 4 put: h3 copy; at: 5 put: h4 copy; yourself
restoreRegisters: anArrayOfRegisters "This has to match with #backupRegisters" h0 := anArrayOfRegisters at: 1. h1 := anArrayOfRegisters at: 2. h2 := anArrayOfRegisters at: 3. h3 := anArrayOfRegisters at: 4. h4 := anArrayOfRegisters at: 5
storeLength "big-endian" | bufferSize length | bufferSize := self blockSize. length := self messageLength. bufferSize to: bufferSize -7 by: -1 do: [ :i | block at: i put: (length bitAnd: 255). length := length bitShift: -8 ].
writeDigestInto: aByteArray startingAt: start h0 storeTo: aByteArray at: start. h1 storeTo: aByteArray at: start + 4. h2 storeTo: aByteArray at: start + 8. h3 storeTo: aByteArray at: start + 12. h4 storeTo: aByteArray at: start + 16.
</methods> <methods> Security.SHA <category>private-algorithm</category>
doBlock k := K1. 1 to: 20 do: [ :i | self chX: b Y: c Z: d; updateTRound: i; shuffleRegisters ]. k := K2. 21 to: 40 do: [ :i | self updateWAt: i; parityX: b Y: c Z: d; updateTRound: i; shuffleRegisters ]. k := K3. 41 to: 60 do: [ :i | self updateWAt: i; majX: b Y: c Z: d; updateTRound: i; shuffleRegisters ]. k := K4. 61 to: 80 do: [ :i | self updateWAt: i; parityX: b Y: c Z: d; updateTRound: i; shuffleRegisters ].
parityX: x Y: y Z: z "Parity(x,y,z) = x xor y xor z" nlf set: x; bitXor: y; bitXor: z
shuffleRegisters | temp | temp := e. e := d. d := c. c := b. c leftRotateBy: 30. b := a. a := t. t := temp
updateTRound: i t set: a; leftRotateBy: 5; addIn: nlf; addIn: e; addIn: k; addIn: (w at: i)
updateWAt: i (w at: i) set: (w at: i - 3); bitXor: (w at: i - 8); bitXor: (w at: i - 14); bitXor: (w at: i - 16); leftRotateBy: 1
</methods> <methods> Security.SHA <category>initialize-release</category>
initialize super initialize. t := ThirtyTwoBitRegister new. self reset
</methods> <methods> Security.SHA <category>services-basic</category>
reset super reset. h0 load: 16r67452301. h1 load: 16rEFCDAB89. h2 load: 16r98BADCFE. h3 load: 16r10325476. h4 load: 16rC3D2E1F0.
</methods> <methods> Security.SHA <category>deprecated</category>
hashInteger: aPositiveInteger ^(self hash: aPositiveInteger asBigEndianByteArray) asLargePositiveInteger
</methods> <methods> Security.SHA class <category>accessing</category>
blockSize ^64
digestSize ^20
</methods> <methods> Security.SHA class <category>deprecated</category>
hashInteger: aPositiveInteger ^self new hashInteger: aPositiveInteger
</methods> <methods> Security.SHA256 <category>private-algorithm</category>
doBlock 1 to: 64 do: [ :i || temp | i > 20 ifTrue: [ self updateWAt: i ]. "Compute T1" self Sigma256_1: e. t1 set: h; addIn: nlf. self chX: e Y: f Z: g. t1 addIn: nlf; addIn: (k at: i); addIn: (w at: i). "Compute T2" self Sigma256_0: a. t2 set: nlf. self majX: a Y: b Z: c. t2 addIn: nlf. "Shuffle registers" temp := h. h := g. g := f. f := e. e := d. e addIn: t1. d := c. c := b. b := a. a := t1. a addIn: t2. t1 := temp ]
prepareWorkingRegisters super prepareWorkingRegisters. f set: h5. g set: h6. h set: h7
Sigma256_0: x nlf set: x; rightRotateBy: 2. xnlf set: x; rightRotateBy: 13. nlf bitXor: xnlf. xnlf set: x; rightRotateBy: 22. nlf bitXor: xnlf
sigma256_0: x nlf set: x; rightRotateBy: 7. xnlf set: x; rightRotateBy: 18. nlf bitXor: xnlf. xnlf set: x; >> 3. nlf bitXor: xnlf
Sigma256_1: x nlf set: x; rightRotateBy: 6. xnlf set: x; rightRotateBy: 11. nlf bitXor: xnlf. xnlf set: x; rightRotateBy: 25. nlf bitXor: xnlf
sigma256_1: x nlf set: x; rightRotateBy: 17. xnlf set: x; rightRotateBy: 19. nlf bitXor: xnlf. xnlf set: x; >> 10. nlf bitXor: xnlf
updateDigestRegisters super updateDigestRegisters. h5 addIn: f. h6 addIn: g. h7 addIn: h
updateWAt: i self sigma256_1: (w at: i - 2). (w at: i) set: nlf; addIn: (w at: i - 7). self sigma256_0: (w at: i - 15). (w at: i) addIn: nlf; addIn: (w at: i - 16)
</methods> <methods> Security.SHA256 <category>initialize-release</category>
initialize super initialize. h5 := ThirtyTwoBitRegister new. h6 := ThirtyTwoBitRegister new. h7 := ThirtyTwoBitRegister new. f := ThirtyTwoBitRegister new. g := ThirtyTwoBitRegister new. h := ThirtyTwoBitRegister new. k := K. t1 := ThirtyTwoBitRegister new. t2 := ThirtyTwoBitRegister new. self reset
</methods> <methods> Security.SHA256 <category>services-basic</category>
reset super reset. h0 load: 16r6A09E667. h1 load: 16rBB67AE85. h2 load: 16r3C6EF372. h3 load: 16rA54FF53A. h4 load: 16r510E527F. h5 load: 16r9B05688C. h6 load: 16r1F83D9AB. h7 load: 16r5BE0CD19.
</methods> <methods> Security.SHA256 <category>private-digest</category>
backupRegisters "This has to match with #restoreRegisters:" ^(Array new: 8) at: 1 put: h0 copy; at: 2 put: h1 copy; at: 3 put: h2 copy; at: 4 put: h3 copy; at: 5 put: h4 copy; at: 6 put: h5 copy; at: 7 put: h6 copy; at: 8 put: h7 copy; yourself
restoreRegisters: anArrayOfRegisters "This has to match with #backupRegisters" super restoreRegisters: anArrayOfRegisters. h5 := anArrayOfRegisters at: 6. h6 := anArrayOfRegisters at: 7. h7 := anArrayOfRegisters at: 8
writeDigestInto: aByteArray startingAt: start super writeDigestInto: aByteArray startingAt: start. h5 storeTo: aByteArray at: start + 20. h6 storeTo: aByteArray at: start + 24. h7 storeTo: aByteArray at: start + 28.
</methods> <methods> Security.SHA256 class <category>initialize</category>
prepareK ^#( 16r428A2F98 16r71374491 16rB5C0FBCF 16rE9B5DBA5 16r3956C25B 16r59F111F1 16r923F82A4 16rAB1C5ED5 16rD807AA98 16r12835B01 16r243185BE 16r550C7DC3 16r72BE5D74 16r80DEB1FE 16r9BDC06A7 16rC19BF174 16rE49B69C1 16rEFBE4786 16r0FC19DC6 16r240CA1CC 16r2DE92C6F 16r4A7484AA 16r5CB0A9DC 16r76F988DA 16r983E5152 16rA831C66D 16rB00327C8 16rBF597FC7 16rC6E00BF3 16rD5A79147 16r06CA6351 16r14292967 16r27B70A85 16r2E1B2138 16r4D2C6DFC 16r53380D13 16r650A7354 16r766A0ABB 16r81C2C92E 16r92722C85 16rA2BFE8A1 16rA81A664B 16rC24B8B70 16rC76C51A3 16rD192E819 16rD6990624 16rF40E3585 16r106AA070 16r19A4C116 16r1E376C08 16r2748774C 16r34B0BCB5 16r391C0CB3 16r4ED8AA4A 16r5B9CCA4F 16r682E6FF3 16r748F82EE 16r78A5636F 16r84C87814 16r8CC70208 16r90BEFFFA 16rA4506CEB 16rBEF9A3F7 16rC67178F2 ) collect: [ :int | ThirtyTwoBitRegister new load: int ]
</methods> <methods> Security.SHA256 class <category>accessing</category>
blockSize ^64
digestSize ^32
</methods> <methods> Core.ByteArray <category>security</category>
shaValue ^Security.SHA integerHash: self
</methods> <methods> Security.HMAC class <category>instance creation</category>
SHA ^self hash: SHA new
SHA: keyBytes ^self SHA setKey: keyBytes; yourself
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ByteArray</name> <environment>Core</environment> <super>Core.IntegerArray</super> <private>false</private> bytes <imports></imports> <category>Collections-Arrayed</category> <attributes> <package>Collections-Arrayed</package> </attributes> </class> <class> <name>Hash</name> <environment>Security</environment> <super>Security.MessageDigest</super> <private>false</private> none block position total <imports></imports> <category>Security-Hashes</category> <attributes> <package>HashesBase</package> </attributes> </class>