diff --git a/nimcrypto.nimble b/nimcrypto.nimble index 017eb40..84f40a3 100644 --- a/nimcrypto.nimble +++ b/nimcrypto.nimble @@ -1,7 +1,7 @@ mode = ScriptMode.Verbose packageName = "nimcrypto" -version = "0.2.0" +version = "0.2.1" author = "Eugene Kabanov" description = "Nim cryptographic library" license = "MIT" diff --git a/nimcrypto/hmac.nim b/nimcrypto/hmac.nim index 5420234..ec2c73a 100644 --- a/nimcrypto/hmac.nim +++ b/nimcrypto/hmac.nim @@ -26,10 +26,11 @@ type opadctx: HashType template sizeBlock*(h: HMAC[Sha2Context]): uint = - uint(h.HashType.bsize) + uint(h.HashType.sizeBlock) + # uint(h.HashType.bsize div 8) template sizeBlock*(h: HMAC[RipemdContext]): uint = - 64'u + uint(h.HashType.sizeBlock) template sizeBlock*(h: HMAC[KeccakContext]): uint = when h.HashType.kind == Keccak or h.HashType.kind == Sha3: @@ -46,9 +47,12 @@ template sizeBlock*(h: HMAC[KeccakContext]): uint = else: {.fatal: "Choosen hash primitive is not yet supported!".} -template sizeDigest*(h: HMAC[Sha2Context]): uint = uint(h.mdctx.bits) -template sizeDigest*(h: HMAC[RipemdContext]): uint = uint(h.mdctx.bits) -template sizeDigest*(h: HMAC[KeccakContext]): uint = uint(h.mdctx.bits) +template sizeDigest*(h: HMAC[Sha2Context]): uint = + uint(h.mdctx.sizeDigest) +template sizeDigest*(h: HMAC[RipemdContext]): uint = + uint(h.mdctx.sizeDigest) +template sizeDigest*(h: HMAC[KeccakContext]): uint = + uint(h.mdctx.sizeDigest) proc init*[T](hmctx: var HMAC[T], key: ptr byte, ulen: uint) = mixin init, update, finish @@ -69,11 +73,9 @@ proc init*[T](hmctx: var HMAC[T], key: ptr byte, ulen: uint) = else: if ulen > 0'u: copyMem(addr k[0], key, ulen) - var i = 0'u - while i < sizeBlock: + for i in 0..