Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler regression with Nim > 1.2.0 #51

Closed
mratsim opened this issue Apr 27, 2020 · 1 comment
Closed

Compiler regression with Nim > 1.2.0 #51

mratsim opened this issue Apr 27, 2020 · 1 comment

Comments

@mratsim
Copy link
Contributor

mratsim commented Apr 27, 2020

Upstream nim-lang/Nim#14136

The following does not work on latest Nim devel:

type
  MDigest*[bits: static[int]] = object
    ## Message digest type
    data*: array[bits div 8, byte]

  Sha2Context*[bits: static[int],
               bsize: static[int],
               T: uint32|uint64] = object
    count: array[2, T]
    state: array[8, T]
    buffer: array[bsize, byte]

  sha256* = Sha2Context[256, 64, uint32]

template hmacSizeBlock*(h: typedesc): int =
  when (h is Sha2Context):
    int(h.bsize)
  else:
    {.fatal: "Choosen hash primitive is not yet supported!".}

type
  HMAC*[HashType] = object
    ## HMAC context object.
    mdctx: HashType
    opadctx: HashType
    ipad: array[HashType.hmacSizeBlock, byte]
    opad: array[HashType.hmacSizeBlock, byte]

func hkdfExtract*[T;S,I: char|byte](ctx: var HMAC[T],
                     prk: var MDigest[T.bits], # <------- error here "Error: type expected"
                     salt: openArray[S],
                     ikm: openArray[I]
                    ) =
  discard

var ctx: HMAC[sha256]
var prk: MDigest[sha256.bits]
let salt = [byte 0x00, 0x01, 0x02]
let ikm = "CompletelyRandomInput"

ctx.hkdfExtract(prk, salt, ikm)

This was not detected because due to #39 nim-blscurve was temporarily removed from testing important packages.

Note: The IETF Hash-To-Curve draft 6 and 7 will remove HKDF needs though we use it in nim-eth and nim-libp2p as well.

@mratsim
Copy link
Contributor Author

mratsim commented Jul 22, 2020

Fixed upstream

@mratsim mratsim closed this as completed Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant