YosysHQ / picorv32

PicoRV32 - A Size-Optimized RISC-V CPU
ISC License
2.86k stars 715 forks source link

Executing C code for PQC in PicoRV32 and verilator, openSSL/config.h not found #254

Closed SyedFahimuddinAlavi closed 3 months ago

SyedFahimuddinAlavi commented 3 months ago

Bonjour, A naive question, I am porting and benchmark the AES and PQC algorithm on picoRV32. Easiest way I could find to execute with verilator is to modify the hello.c and different files from there. AES encryption decryption works fine but I noticed that openSSL/config.h not found but I have installed the toolchain that should have crypto library(I updated make file with -lcrypto option but no use) and also verilator is simulating executable that build with nostdlib option. Anything I am missing that causing the crypto library not being linked or somebody faced similar issue?


> `~/workspace/picorv32_forked$ make
> iverilog -o testbench.vvp -DCOMPRESSED_ISA testbench.v picorv32.v
> chmod -x testbench.vvp
> /opt/riscv32i/bin/riscv32-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imc -o firmware/start.o firmware/start.S
> 
> .
> .
> .
> 
> /opt/riscv32i/bin/riscv32-unknown-elf-gcc -c -mabi=ilp32 -march=rv32ic --std=c99 -Werror -Wall -Wextra -Wshadow -Wundef -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes -pedantic  -ffreestanding -nostdlib -fno-lto -o firmware/kyber512/rng.o firmware/kyber512/rng.c
> firmware/kyber512/rng.c:10:10: fatal error: openssl/conf.h: No such file or directory
>  #include <openssl/conf.h>
> `
secworks commented 3 months ago

You could take a look at the PQC Dilithium3 PoC we have done for TKey1, which use the PicoRV32 CPU core: https://github.com/tillitis/pqsigner

SyedFahimuddinAlavi commented 3 months ago

Thanks @secworks , exactly it is what I was looking for. It worked on host but on Tkey I got build error -opaque-pointers mode (Producer: LLVM15.0.7 Reader: LLVM 14.0.6) even I removed LLVM/Clang 14 completely

`clang-15 -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf -fno-builtin-putchar -nostdlib -mno-relax -flto -g -Wall -Werror=implicit-function-declaration -Wextra -Wpedantic -Werror -Wmissing-prototypes -Wredundant-decls -std=c99 -I ../../../tkey-libs/include -std=c99 -I../.. -DTKEY -c -o symmetric-shake.o symmetric-shake.c llvm-ar-15 -r libdilithium3_clean.a ntt.o packing.o poly.o polyvec.o reduce.o rounding.o sign.o symmetric-shake.o

llvm-ar-15: warning: creating libdilithium3_clean.a

make[1]: Leaving directory /home/alavis/workspace/cryptography_codes/pqsigner/pqclean/dilithium3/clean

clang-15 -target riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf -fno-builtin-putchar -nostdlib -mno-relax -flto -g -Wall -Werror=implicit-function-declaration -I ../pqclean/dilithium3/clean/ -I /home/alavis/workspace/cryptography_codes/pqsigner/pqsigner/../tkey-libs/include -I . -DTKEY -o pqsigner.elf main.o stdlib.o malloc.o ../pqclean/fips202.o io.o hex.o static-keys.o -L ../pqclean/dilithium3/clean/ -ldilithium3_clean -T /home/alavis/workspace/cryptography_codes/pqsigner/pqsigner/../tkey-libs/app.lds -L /home/alavis/workspace/cryptography_codes/pqsigner/pqsigner/../tkey-libs -lcommon -lcrt0

ld.lld: error: main.o: Opaque pointers are only supported in -opaque-pointers mode (Producer: LLVM15.0.7 Reader: LLVM 14.0.6)

clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)

make: *** [Makefile:28: pqsigner.elf] Error 1`

SyedFahimuddinAlavi commented 3 months ago

Thanks