The Trunk: WebClient-Core-ul.113.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: WebClient-Core-ul.113.mcz

commits-2
Levente Uzonyi uploaded a new version of WebClient-Core to project The Trunk:
http://source.squeak.org/trunk/WebClient-Core-ul.113.mcz

==================== Summary ====================

Name: WebClient-Core-ul.113
Author: ul
Time: 5 February 2018, 11:43:25.863479 pm
UUID: 10da8ea8-848d-4d99-92e0-105d99a25dda
Ancestors: WebClient-Core-topa.112

- fix: #md5HashStream: will properly process an empty stream
- simplified #hmacSha1:key:

=============== Diff against WebClient-Core-topa.112 ===============

Item was changed:
  ----- Method: WebUtils class>>hmacSha1:key: (in category 'oauth') -----
  hmacSha1: message key: signKey
  "Compute the SHA1 HMAC for the given message"
 
+ | blockSize key |
- | blockSize key ipad opad |
  blockSize := 64. "SHA1 block size"
  key := signKey asByteArray.
  key size > blockSize ifTrue:[key := self sha1Hash: key].
+ key size < blockSize ifTrue:[key := key grownBy: blockSize - key size ].
- key size < blockSize ifTrue:[key := key, (ByteArray new: blockSize - key size)].
- ipad := ByteArray new: blockSize withAll: 16r36.
- opad := ByteArray new: blockSize withAll: 16r5c.
  ^self sha1Hash:
+ (key collect: [ :byte | byte bitXor: 16r5c "opad byte" ]),
+ (self sha1Hash: (key collect: [ :byte | byte bitXor: 16r36 "ipad byte" ]), message)!
- (key with: opad collect:[:b1 :b2| b1 bitXor: b2]),
- (self sha1Hash: (key with: ipad collect:[:b1 :b2| b1 bitXor: b2]), message)!

Item was changed:
  ----- Method: WebUtils class>>md5HashStream: (in category 'md5') -----
  md5HashStream: aStream
  "self md5HashStream: (ReadStream on: 'foo')"
 
+ | start buffer chunkSize n words hash |
- | start buffer bytes sz n words hash |
  hash := WordArray
  with: 16r67452301
  with: 16rEFCDAB89
  with: 16r98BADCFE
  with: 16r10325476.
  words := WordArray new: 16.
  buffer := ByteArray new: 64.
  start := aStream position.
+ [
+ chunkSize := (aStream nextInto: buffer) size.
+ chunkSize < 64 or: [ aStream atEnd ] ]
+ whileFalse: [
+ 1 to: 16 do:[:i| words at: i put: (buffer unsignedLongAt: i*4-3 bigEndian: false)].
+ self md5Transform: words hash: hash ].
+ buffer from: chunkSize +1 to: buffer size put: 0.
+ chunkSize < 56 ifTrue: [
+ buffer at: chunkSize + 1 put: 128. "trailing bit"
+ ] ifFalse:[
+ "not enough room for the length, so just pad this one, then..."
+ chunkSize < 64 ifTrue:[buffer at: chunkSize + 1 put: 128].
- [aStream atEnd] whileFalse: [
- bytes := aStream nextInto: buffer.
- (bytes size < 64 or:[aStream atEnd]) ifTrue:[
- sz := bytes size.
- buffer replaceFrom: 1 to: sz with: bytes startingAt: 1.
- buffer from: sz+1 to: buffer size put: 0.
- sz < 56 ifTrue:[
- buffer at: sz + 1 put: 128. "trailing bit"
- ] ifFalse:[
- "not enough room for the length, so just pad this one, then..."
- sz < 64 ifTrue:[buffer at: sz + 1 put: 128].
- 1 to: 16 do:[:i| words at: i put: (buffer unsignedLongAt: i*4-3 bigEndian: false)].
- self md5Transform: words hash: hash.
- "process one additional block of padding ending with the length"
- buffer atAllPut: 0.
- sz = 64 ifTrue: [buffer at: 1 put: 128].
- ].
- "Fill in the final 8 bytes with the 64-bit length in bits."
- n := (aStream position - start) * 8.
- 7 to: 0 by: -1 do:[:i| buffer at: (buffer size - i) put: ((n bitShift: 7 - i * -8) bitAnd: 255)].
- ].
  1 to: 16 do:[:i| words at: i put: (buffer unsignedLongAt: i*4-3 bigEndian: false)].
  self md5Transform: words hash: hash.
+ "process one additional block of padding ending with the length"
+ buffer atAllPut: 0.
+ chunkSize = 64 ifTrue: [buffer at: 1 put: 128].
  ].
+ "Fill in the final 8 bytes with the 64-bit length in bits."
+ n := (aStream position - start) * 8.
+ 7 to: 0 by: -1 do:[:i| buffer at: (buffer size - i) put: ((n bitShift: 7 - i * -8) bitAnd: 255)].
+ "Final round"
+ 1 to: 16 do:[:i| words at: i put: (buffer unsignedLongAt: i*4-3 bigEndian: false)].
+ self md5Transform: words hash: hash.
+
+ ^(ByteArray new: 16)
+ unsignedLongAt: 1 put: (hash at: 4) bigEndian: true;
+ unsignedLongAt: 5 put: (hash at: 3) bigEndian: true;
+ unsignedLongAt: 9 put: (hash at: 2) bigEndian: true;
+ unsignedLongAt: 13 put: (hash at: 1) bigEndian: true;
+ yourself!
- bytes := ByteArray new: 16.
- bytes unsignedLongAt: 1 put: (hash at: 4) bigEndian: true.
- bytes unsignedLongAt: 5 put: (hash at: 3) bigEndian: true.
- bytes unsignedLongAt: 9 put: (hash at: 2) bigEndian: true.
- bytes unsignedLongAt: 13 put: (hash at: 1) bigEndian: true.
- ^bytes
- !