prepared stdlb for new integer arithmetic rules
This commit is contained in:
parent
e7bcadaf32
commit
12af4a3f8a
2 changed files with 8 additions and 8 deletions
|
|
@ -78,10 +78,10 @@ proc encode(dest: var MD5Block, src: cstring) =
|
||||||
proc decode(dest: var openArray[uint8], src: openArray[uint32]) =
|
proc decode(dest: var openArray[uint8], src: openArray[uint32]) =
|
||||||
var i = 0
|
var i = 0
|
||||||
for j in 0..high(src):
|
for j in 0..high(src):
|
||||||
dest[i] = src[j] and 0xff'u32
|
dest[i] = uint8(src[j] and 0xff'u32)
|
||||||
dest[i+1] = src[j] shr 8 and 0xff'u32
|
dest[i+1] = uint8(src[j] shr 8 and 0xff'u32)
|
||||||
dest[i+2] = src[j] shr 16 and 0xff'u32
|
dest[i+2] = uint8(src[j] shr 16 and 0xff'u32)
|
||||||
dest[i+3] = src[j] shr 24 and 0xff'u32
|
dest[i+3] = uint8(src[j] shr 24 and 0xff'u32)
|
||||||
inc(i, 4)
|
inc(i, 4)
|
||||||
|
|
||||||
proc transform(buffer: pointer, state: var MD5State) =
|
proc transform(buffer: pointer, state: var MD5State) =
|
||||||
|
|
@ -216,8 +216,8 @@ proc `$`*(d: MD5Digest): string =
|
||||||
const digits = "0123456789abcdef"
|
const digits = "0123456789abcdef"
|
||||||
result = ""
|
result = ""
|
||||||
for i in 0..15:
|
for i in 0..15:
|
||||||
add(result, digits[(d[i] shr 4) and 0xF])
|
add(result, digits[(d[i].int shr 4) and 0xF])
|
||||||
add(result, digits[d[i] and 0xF])
|
add(result, digits[d[i].int and 0xF])
|
||||||
|
|
||||||
proc getMD5*(s: string): string =
|
proc getMD5*(s: string): string =
|
||||||
## computes an MD5 value of `s` and returns its string representation
|
## computes an MD5 value of `s` and returns its string representation
|
||||||
|
|
|
||||||
|
|
@ -148,13 +148,13 @@ proc sha1(src: cstring; len: int): Sha1Digest =
|
||||||
while lastBlockBytes < endCurrentBlock:
|
while lastBlockBytes < endCurrentBlock:
|
||||||
|
|
||||||
var value = uint32(src[lastBlockBytes + currentBlock]) shl
|
var value = uint32(src[lastBlockBytes + currentBlock]) shl
|
||||||
((3'u32 - (lastBlockBytes and 3)) shl 3)
|
((3'u32 - uint32(lastBlockBytes and 3)) shl 3)
|
||||||
|
|
||||||
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or value
|
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or value
|
||||||
inc(lastBlockBytes)
|
inc(lastBlockBytes)
|
||||||
|
|
||||||
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or (
|
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or (
|
||||||
0x80'u32 shl ((3'u32 - (lastBlockBytes and 3)) shl 3)
|
0x80'u32 shl ((3'u32 - uint32(lastBlockBytes and 3)) shl 3)
|
||||||
)
|
)
|
||||||
|
|
||||||
if endCurrentBlock >= 56:
|
if endCurrentBlock >= 56:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue