gcc 14 support (#62)

* rsaKeygenGetDefault test

* add ubuntu 24 and gcc 14 to ci

* use PrngClassPointerConst for rsa keygen

* fix test_brssl

* add comment about ubuntu 24

* define and use ConstPtrPtrHashClass

* remove previous ecKeygen

* remove previous x509NoanchorInit

* improve test

* add ecKeygen test

* add x509NoanchorInit test

* remove commented code

* rename target to linux-gcc-14

* test already exists

* fix tests
This commit is contained in:
diegomrsantos 2024-07-18 17:50:24 +02:00 committed by GitHub
parent 646fa2152b
commit d4e2f555c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 88 additions and 11 deletions

View File

@ -18,6 +18,8 @@ jobs:
target:
- os: linux
cpu: amd64
- os: linux-gcc-14 # this is to use ubuntu 24 and install gcc 14. Must be removed when ubuntu-latest is 24.04
cpu: amd64
- os: linux
cpu: i386
- os: macos
@ -31,6 +33,9 @@ jobs:
- target:
os: linux
builder: ubuntu-latest
- target:
os: linux-gcc-14 # this is to use ubuntu 24 and install gcc 14. Must be removed when ubuntu-latest is 24.04
builder: ubuntu-24.04
- target:
os: macos
cpu: amd64
@ -163,10 +168,20 @@ jobs:
bash build_nim.sh nim csources dist/nimble NimBinaries
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
- name: Use gcc 14
if : ${{ matrix.target.os == 'linux-gcc-14' }}
run: |
# Add GCC-14 to alternatives
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14
# Set GCC-14 as the default
sudo update-alternatives --set gcc /usr/bin/gcc-14
- name: Run tests
run: |
nim --version
nimble --version
gcc --version
nimble install -y --depsOnly
env NIMLANG=c nimble test
# C++ support requires fixing const pointer proc assignments

View File

@ -23,19 +23,20 @@ const
{.compile: bearHashPath & "sha2small.c".}
type
ConstPtrPtrHashClass* {.importc: "const br_hash_class**", header: "bearssl_hash.h", bycopy.} = pointer
HashClass* {.importc: "br_hash_class", header: "bearssl_hash.h", bycopy.} = object
contextSize* {.importc: "context_size".}: uint
desc* {.importc: "desc".}: uint32
init* {.importc: "init".}: proc (ctx: ptr ptr HashClass) {.importcFunc.}
update* {.importc: "update".}: proc (ctx: ptr ptr HashClass; data: pointer;
init* {.importc: "init".}: proc (ctx: ConstPtrPtrHashClass) {.importcFunc.}
update* {.importc: "update".}: proc (ctx: ConstPtrPtrHashClass; data: pointer;
len: uint) {.importcFunc.}
`out`* {.importc: "out".}: proc (ctx: ptr ptr HashClass; dst: pointer) {.importcFunc.}
state* {.importc: "state".}: proc (ctx: ptr ptr HashClass; dst: pointer): uint64 {.
`out`* {.importc: "out".}: proc (ctx: ConstPtrPtrHashClass; dst: pointer) {.importcFunc.}
state* {.importc: "state".}: proc (ctx: ConstPtrPtrHashClass; dst: pointer): uint64 {.
importcFunc.}
setState* {.importc: "set_state".}: proc (ctx: ptr ptr HashClass; stb: pointer;
setState* {.importc: "set_state".}: proc (ctx: ConstPtrPtrHashClass; stb: pointer;
count: uint64) {.importcFunc.}
template hashdesc_Id*(id: untyped): untyped =
((uint32)(id) shl hashdesc_Id_Off)

View File

@ -357,20 +357,20 @@ template rsaKbufPubSize*(size: untyped): untyped =
type
RsaKeygen* {.importc: "br_rsa_keygen".} = proc (rngCtx: ptr ptr PrngClass; sk: ptr RsaPrivateKey; kbufPriv: pointer;
RsaKeygen* {.importc: "br_rsa_keygen".} = proc (rngCtx: PrngClassPointerConst; sk: ptr RsaPrivateKey; kbufPriv: pointer;
pk: ptr RsaPublicKey; kbufPub: pointer; size: cuint; pubexp: uint32): uint32 {.
importcFunc.}
proc rsaI15Keygen*(rngCtx: ptr ptr PrngClass; sk: ptr RsaPrivateKey; kbufPriv: pointer;
proc rsaI15Keygen*(rngCtx: PrngClassPointerConst; sk: ptr RsaPrivateKey; kbufPriv: pointer;
pk: ptr RsaPublicKey; kbufPub: pointer; size: cuint; pubexp: uint32): uint32 {.
importcFunc, importc: "br_rsa_i15_keygen", header: "bearssl_rsa.h".}
proc rsaI31Keygen*(rngCtx: ptr ptr PrngClass; sk: ptr RsaPrivateKey; kbufPriv: pointer;
proc rsaI31Keygen*(rngCtx: PrngClassPointerConst; sk: ptr RsaPrivateKey; kbufPriv: pointer;
pk: ptr RsaPublicKey; kbufPub: pointer; size: cuint; pubexp: uint32): uint32 {.
importcFunc, importc: "br_rsa_i31_keygen", header: "bearssl_rsa.h".}
proc rsaI62Keygen*(rngCtx: ptr ptr PrngClass; sk: ptr RsaPrivateKey; kbufPriv: pointer;
proc rsaI62Keygen*(rngCtx: PrngClassPointerConst; sk: ptr RsaPrivateKey; kbufPriv: pointer;
pk: ptr RsaPublicKey; kbufPub: pointer; size: cuint; pubexp: uint32): uint32 {.
importcFunc, importc: "br_rsa_i62_keygen", header: "bearssl_rsa.h".}

View File

@ -9,4 +9,4 @@ suite "x509":
var x509: X509MinimalContext
x509MinimalInit(x509, nil, nil, 0)
x509NoanchorInit(xwc, addr x509.vtable)
x509NoanchorInit(xwc, X509ClassPointerConst(addr x509.vtable))

20
tests/test_ec.nim Normal file
View File

@ -0,0 +1,20 @@
import
unittest2,
../bearssl/[rand, ec]
{.used.}
type
EcPrivateKey* = ref object
buffer*: array[EC_KBUF_PRIV_MAX_SIZE, byte]
key*: ec.EcPrivateKey
suite "ec":
test "test ecKeygen interface":
let rng = HmacDrbgContext.new()
var ecimp = ecGetDefault()
var res = new EcPrivateKey
check ecKeygen(
PrngClassPointerConst(addr rng.vtable), ecimp, addr res.key, addr res.buffer[0], cint(EC_secp256r1)
) != 0

41
tests/test_rsa.nim Normal file
View File

@ -0,0 +1,41 @@
import
unittest2,
../bearssl/[rand, rsa]
{.used.}
const
DefaultKeySize* = 3072 ## Default RSA key size in bits.
DefaultPublicExponent* = 65537'u32
type
RsaPrivateKey* = ref object
buffer*: seq[byte]
seck*: rsa.RsaPrivateKey
pubk*: rsa.RsaPublicKey
pexp*: ptr byte
pexplen*: uint
suite "rsa":
test "test rsaKeygenGetDefault interface":
let rng = HmacDrbgContext.new()
let
sko = 0
pko = rsaKbufPrivSize(DefaultKeySize)
eko = pko + rsaKbufPubSize(DefaultKeySize)
length = eko + ((DefaultKeySize + 7) shr 3)
let res = new RsaPrivateKey
res.buffer = newSeq[byte](length)
var keygen = rsaKeygenGetDefault()
check keygen(
addr rng.vtable,
addr res.seck,
addr res.buffer[sko],
addr res.pubk,
addr res.buffer[pko],
cuint(DefaultKeySize),
DefaultPublicExponent,
) != 0