Skip to content

Commit

Permalink
Fix [CastSizes] warnings in twofish.nim and utils.nim. (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatfate committed Jan 9, 2023
1 parent 5bbf708 commit 4014ef9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions nimcrypto/twofish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ template b3(x: uint32): byte =
cast[byte](x shr 24)

template BYTEARRAY_TO_U32(arr): uint32 =
((cast[uint32](arr[0]) shl 24) xor (cast[uint32](arr[1]) shl 16) xor
(cast[uint32](arr[2]) shl 8) xor (cast[uint32](arr[3])))
((uint32(arr[0]) shl 24) xor (uint32(arr[1]) shl 16) xor
(uint32(arr[2]) shl 8) xor (uint32(arr[3])))
template BYTES_TO_U32(r0, r1, r2, r3): uint32 =
((cast[uint32](r0) shl 24) xor (cast[uint32](r1) shl 16) xor
(cast[uint32](r2) shl 8) xor (cast[uint32](r3)))
((uint32(r0) shl 24) xor (uint32(r1) shl 16) xor
(uint32(r2) shl 8) xor (uint32(r3)))

proc polyMult(a, b: uint32): uint32 =
result = 0'u32
Expand Down
12 changes: 4 additions & 8 deletions nimcrypto/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,10 @@ proc big64ToCpu*(p: ptr byte, offset: int): uint64 {.deprecated, inline.} =
result = cast[ptr uint64](cast[uint](p) + cast[uint](offset))[]
else:
var pp = cast[ptr UncheckedArray[byte]](p)
result = cast[uint64](pp[offset + 0] shl 56) or
cast[uint64](pp[offset + 1] shl 48) or
cast[uint64](pp[offset + 2] shl 40) or
cast[uint64](pp[offset + 3] shl 32) or
cast[uint64](pp[offset + 4] shl 24) or
cast[uint64](pp[offset + 5] shl 16) or
cast[uint64](pp[offset + 6] shl 8) or
cast[uint64](pp[offset + 7])
(uint64(pp[offset + 0]) shl 56) or (uint64(pp[offset + 1]) shl 48) or
(uint64(pp[offset + 2]) shl 40) or (uint64(pp[offset + 3]) shl 32) or
(uint64(pp[offset + 4]) shl 24) or (uint64(pp[offset + 5]) shl 16) or
(uint64(pp[offset + 6]) shl 8) or uint64(pp[offset + 7])

proc cpuToLit64*(p: ptr byte, offset: int, v: uint64) {.deprecated, inline.} =
## Store uint64 integer ``v`` to pointer ``p`` and offset ``o`` in
Expand Down

0 comments on commit 4014ef9

Please sign in to comment.