Skip to content

Commit 1aeef2f

Browse files
committed
use std/sha1 to avoid issue on 32bit system
1 parent c07f386 commit 1aeef2f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

hmac.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
## This module implements HMAC-SHA1 and HMC-MD5 hashing methods
1010

11-
import md5, strutils, sha1
11+
import std/[sha1, md5, strutils]
1212
import nimSHA2 except toHex
1313
import nimcrypto
1414

1515
type
1616
Keccak512Digest* = array[0..63, char]
1717

18-
proc hash_sha1*(s: string): Sha1Digest {.procvar.} = sha1.compute(s)
18+
proc hash_sha1*(s: string): Sha1Digest {.procvar.} = sha1.secureHash(s).Sha1Digest
1919

2020
proc hash_sha224*(s: string): SHA224Digest {.procvar.} = computeSHA224(s)
2121

@@ -31,7 +31,7 @@ proc hash_md5*(s: string): MD5Digest {.procvar.} = toMD5(s)
3131
3232
proc toHex*[T](x: T): string {.inline.} =
3333
when x is Sha1Digest:
34-
result = toLowerAscii($x)
34+
result = toLowerAscii($x.SecureHash)
3535
elif x is MD5Digest:
3636
result = toLowerAscii($x)
3737
else:
@@ -116,4 +116,3 @@ when isMainModule:
116116
117117
result = toHex(hmac_keccak512(longKey, "In cryptography, a keyed-hash message authentication code (HMAC) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Any cryptographic hash function, such as MD5 or SHA-1, may be used in the calculation of an HMAC"))
118118
echo result
119-

hmac.nimble

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version = "0.2.0"
1+
version = "0.3.0"
22
author = "Huy Doan"
33
description = "HMAC hashing in Nim"
44
license = "MIT"
55

6-
requires "nim", "nimSHA2", "sha1", "nimcrypto >= 0.5.4"
6+
requires "nim >= 2.0.0", "nimSHA2", "nimcrypto >= 0.5.4"

0 commit comments

Comments
 (0)