Module sha2

This module implements SHA2 (Secure Hash Algorithm 2) set of cryptographic hash functions designed by National Security Agency, version FIPS-180-4. []

Tests made according to official test vectors [].


Sha2Context[bits; bsize; T] = object
  count: array[2, T]
  state: array[8, T]
  buffer: array[bsize, byte]
sha224 = Sha2Context[224, 64, uint32]
sha256 = Sha2Context[256, 64, uint32]
sha384 = Sha2Context[384, 128, uint64]
sha512 = Sha2Context[512, 128, uint64]
sha512_224 = Sha2Context[224, 128, uint64]
sha512_256 = Sha2Context[256, 128, uint64]
sha2 = sha224 | sha256 | sha384 | sha512 | sha512_224 | sha512_256


proc init(ctx: var Sha2Context)
proc clear(ctx: var Sha2Context) {...}{.inline.}
proc update(ctx: var Sha2Context; data: ptr byte; inlen: uint)
"is greater" operator. This is the same as y < x.
proc update[T: bchar](ctx: var Sha2Context; data: openArray[T])
proc finish(ctx: var Sha2Context; pBytes: ptr byte; nBytes: uint): uint
"is greater or equals" operator. This is the same as y <= x.
proc finish(ctx: var Sha2Context): MDigest[ctx.bits]
proc finish[T: bchar](ctx: var Sha2Context; data: var openArray[T])
"is greater or equals" operator. This is the same as y <= x.


template sizeDigest(ctx: Sha2Context): uint
template sizeBlock(ctx: Sha2Context): uint
template sizeDigest(r: typedesc[sha2]): int
template sizeBlock(r: typedesc[sha2]): int