From 554b464b34cd5df2beb51952302e86edf184e480 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Thu, 27 Jun 2024 01:42:04 +0300 Subject: [PATCH] Fix gcc-14 issues part 2. (#61) * Fix recently discovered nim-2.0 gcc-14 issues. * One more place to fix. --- bearssl/abi/bearssl_ec.nim | 6 +++++- bearssl/abi/bearssl_rand.nim | 3 ++- bearssl/abi/brssl.nim | 5 ++++- bearssl/rand.nim | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bearssl/abi/bearssl_ec.nim b/bearssl/abi/bearssl_ec.nim index add5aed..11336e4 100644 --- a/bearssl/abi/bearssl_ec.nim +++ b/bearssl/abi/bearssl_ec.nim @@ -325,10 +325,14 @@ const EC_KBUF_PUB_MAX_SIZE* = 145 -proc ecKeygen*(rngCtx: ptr ptr PrngClass; impl: ptr EcImpl; sk: ptr EcPrivateKey; +proc ecKeygen*(rngCtx: PrngClassPointerConst; impl: ptr EcImpl; sk: ptr EcPrivateKey; kbuf: pointer; curve: cint): uint {.importcFunc, importc: "br_ec_keygen", header: "bearssl_ec.h".} +proc ecKeygen*(rngCtx: ptr ptr PrngClass; impl: ptr EcImpl; sk: ptr EcPrivateKey; + kbuf: pointer; curve: cint): uint = + ecKeygen(PrngClassPointerConst(rngCtx), impl, sk, kbuf, curve) + proc ecComputePub*(impl: ptr EcImpl; pk: ptr EcPublicKey; kbuf: pointer; sk: ptr EcPrivateKey): uint {.importcFunc, importc: "br_ec_compute_pub", header: "bearssl_ec.h".} diff --git a/bearssl/abi/bearssl_rand.nim b/bearssl/abi/bearssl_rand.nim index d296d1a..63c8c7e 100644 --- a/bearssl/abi/bearssl_rand.nim +++ b/bearssl/abi/bearssl_rand.nim @@ -21,6 +21,7 @@ type update* {.importc: "update".}: proc (ctx: ptr ptr PrngClass; seed: pointer; seedLen: uint) {.importcFunc.} + PrngClassPointerConst* {.importc: "const br_prng_class**", header: "bearssl_rand.h", bycopy.} = pointer type @@ -51,7 +52,7 @@ proc hmacDrbgGetHash*(ctx: var HmacDrbgContext): ptr HashClass {.inline.} = type - PrngSeeder* {.importc: "br_prng_seeder".} = proc (ctx: ptr ptr PrngClass): cint {.importcFunc.} + PrngSeeder* {.importc: "br_prng_seeder".} = proc (ctx: PrngClassPointerConst): cint {.importcFunc.} constCstringArray* {.importc: "const char**", nodecl.} = pointer proc prngSeederSystem*(name: constCstringArray): PrngSeeder {.importcFunc, diff --git a/bearssl/abi/brssl.nim b/bearssl/abi/brssl.nim index c3231a0..ee94e05 100644 --- a/bearssl/abi/brssl.nim +++ b/bearssl/abi/brssl.nim @@ -18,8 +18,11 @@ type vtable* {.importc: "vtable".}: ptr X509Class inner* {.importc: "inner".}: ptr ptr X509Class -proc x509NoanchorInit*(xwc: var X509NoanchorContext; inner: ptr ptr X509Class) {.importcFunc, +proc x509NoanchorInit*(xwc: var X509NoanchorContext; inner: X509ClassPointerConst) {.importcFunc, importc: "x509_noanchor_init", header: "brssl_cpp.h".} +proc x509NoanchorInit*(xwc: var X509NoanchorContext; inner: ptr ptr X509Class) = + x509NoanchorInit(xwc, X509ClassPointerConst(inner)) + proc initNoAnchor*(xwc: var X509NoanchorContext, inner: ptr ptr X509Class) {. importcFunc, importc: "x509_noanchor_init", header: "brssl_cpp.h", deprecated: "x509NoanchorInit".} diff --git a/bearssl/rand.nim b/bearssl/rand.nim index a12ee94..81f383b 100644 --- a/bearssl/rand.nim +++ b/bearssl/rand.nim @@ -39,7 +39,7 @@ proc new*(T: type HmacDrbgContext): ref HmacDrbgContext = let rng = (ref HmacDrbgContext)() hmacDrbgInit(rng[], addr sha256Vtable, nil, 0) - if seeder(addr rng.vtable) == 0: + if seeder(PrngClassPointerConst(addr rng.vtable)) == 0: return nil rng