From f47fb628f0996b1a6ffa6ca9a5693e82b8e0dde5 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Fri, 14 Feb 2020 12:16:21 +0900 Subject: [PATCH] Fix curve mulgen iterate/derive --- libp2p/crypto/curve25519.nim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libp2p/crypto/curve25519.nim b/libp2p/crypto/curve25519.nim index a9a18c2..83b8404 100644 --- a/libp2p/crypto/curve25519.nim +++ b/libp2p/crypto/curve25519.nim @@ -58,18 +58,20 @@ proc mul*(_: type[Curve25519], dst: var Curve25519Key, scalar: Curve25519Key, po assert res == 1 proc mulgen*(_: type[Curve25519], dst: var Curve25519Key, scalar: Curve25519Key) = - while true: - let - size = defaultBrEc.mulgen( - cast[pcuchar](addr dst[0]), - cast[pcuchar](unsafeAddr scalar[0]), - Curve25519KeySize, - EC_curve25519.cint) - assert size == Curve25519KeySize - for forbid in ForbiddenCurveValues: - if dst == forbid: - continue - break + block iterate: + while true: + block derive: + let + size = defaultBrEc.mulgen( + cast[pcuchar](addr dst[0]), + cast[pcuchar](unsafeAddr scalar[0]), + Curve25519KeySize, + EC_curve25519.cint) + assert size == Curve25519KeySize + for forbid in ForbiddenCurveValues: + if dst == forbid: + break derive + break iterate when isMainModule: var