~ehmry/nim_sphincs

6a66c7b1c63553fddf3293b7072833a3d6ebb7df — Emery Hemingway 3 years ago adb3c75 master v0.1.1
Support for seq[byte] input
M sphincs.nimble => sphincs.nimble +1 -1
@@ 1,6 1,6 @@
# Package

version       = "0.1.0"
version       = "0.1.1"
author        = "Emery Hemingway"
description   = "SPHINCS⁺ stateless hash-based signature scheme"
license       = "MIT"

M src/sphincs/private/sphincs_shake256.nim => src/sphincs/private/sphincs_shake256.nim +2 -2
@@ 92,7 92,7 @@ proc T_len(pk: PK; adrs: Address; M: array[wotsLen, Nbytes]): Nbytes =
    # hash again with bitmasked message
  sha3_final(ctx, result)

proc PRFmsg(sk: SK; optRand: Nbytes; M: string|openArray[byte]): Nbytes =
proc PRFmsg(sk: SK; optRand: Nbytes; M: string|openArray[byte]|seq[byte]): Nbytes =
  ## Pseudorandom function to generate randomness for message compression.
  var ctx: SHA3
  sha3_init(ctx, SHA3_SHAKE256, n)


@@ 101,7 101,7 @@ proc PRFmsg(sk: SK; optRand: Nbytes; M: string|openArray[byte]): Nbytes =
  sha3_update(ctx, M, M.len)
  sha3_final(ctx, result)

proc Hmsg(R: Nbytes; pk: PK; M: string|openArray[byte]): (array[partialDigestBytes,byte], int64, int32) =
proc Hmsg(R: Nbytes; pk: PK; M: string|openArray[byte]|seq[byte]): (array[partialDigestBytes,byte], int64, int32) =
  ## Keyed hash funcion for compression messages to be signed.
  var
    digest: array[m, byte]

M src/sphincs/private/sphincsinstantiate.nim => src/sphincs/private/sphincsinstantiate.nim +3 -3
@@ 303,7 303,7 @@ type

{.pop.} # allow runtime checks

proc sign*(pair: KeyPair; M: string|openArray[byte]; optRand: Nbytes): string {.noSideEffect.} =
proc sign*(pair: KeyPair; M: string|openArray[byte]|seq[byte]; optRand: Nbytes): string {.noSideEffect.} =
  ## Generate a SPHINCS⁺ signature.
  ## The signature will be deterministic unless `optRand` is randomized.
  let msgOff = sizeof(SpxSignature)


@@ 341,11 341,11 @@ proc sign*(pair: KeyPair; M: string|openArray[byte]; optRand: Nbytes): string {.
      idxLeaf = (int32)idxTree and ((1 shl spxTreeHeight) - 1)
      idxTree = idxTree shr spxTreeHeight
        # update the indices for the next layer
  for i in 0..M.len:
  for i in 0..<M.len:
    result[msgOff+i] = (char)M[i]
    # append signature with message

proc sign*(pair: KeyPair; M: string|openArray[byte]; rand: RandomBytes): string {.noSideEffect.} =
proc sign*(pair: KeyPair; M: string|openArray[byte]|seq[byte]; rand: RandomBytes): string {.noSideEffect.} =
  ## Generate a SPHINCS⁺ signature. The passed `rand` procedure is used to
  ## create non-deterministic signatures which are generally recommended.
  var optRand: Nbytes