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

Error C (from H file to V : warning: implicit declaration of function 'sha3_finalize' /tmp/v_1000/SHA3.01HYG2REZ8HW9F433E3J5B37XR.tmp.c:13117: error: '{' expected (got ";") #21546

Closed
b-bruno opened this issue May 22, 2024 · 1 comment

Comments

@b-bruno
Copy link

b-bruno commented May 22, 2024

V doctor:

**Prequiste SHA3 C Lib** : https://github.com/brainhub/SHA3IUF/blob/master/sha3.h

V full version: V 0.4.6 0be5377.7a36b44
OS: linux, "Arch Linux"
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

getwd: /home/bruno/Documents/Dev/SHA3
vexe: /home/bruno/Téléchargements/v/v
vexe mtime: 2024-05-22 05:59:15

vroot: OK, value: /home/bruno/Téléchargements/v
VMODULES: OK, value: /home/bruno/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.45.1
Git vroot status: 0.4.6-13-g7a36b44c
.git/config present: true

CC version: cc (GCC) 14.1.1 20240507
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

What did you do?
v -g -o vdbg cmd/v && vdbg sha3.v

module main

#flag -I/home/bruno/Documents/Dev/SHA3/include/
#flag -L/home/bruno/Documents/Dev/SHA3/lib/
#flag -lsha3
//#flag -llibsha3
#include "sha3.h"

const (
    //sha3_keccak_sponge_words = (1600 / 8) / int(sizeof(u64))
    sha3_keccak_sponge_words = 25 // = (1600 / 8) / int(sizeof(u64))
)

enum Sha3Flags as u8 {
	sha3_flags_none = 0
	sha3_flags_keccak = 1
}

enum Sha3Return {   
	sha3_return_ok = 0    
	sha3_return_bad_params = 1
}

struct Sha3Context {
    saved         u64                  // the portion of the input message that we didn't consume yet
    s             [sha3_keccak_sponge_words]u64  // Keccak's state
    sb            [sha3_keccak_sponge_words * 8]u8  // Keccak's state
    byte_index    u32                  // 0..7--the next byte after the set one (starts from 0; 0--none are buffered)
    word_index    u32                  // 0..24--the next word to integrate input (starts from 0)
    capacity_words u32                 // the double size of the hash output in words (e.g. 16 for Keccak 512)
}

fn C.sha3_init256(context &Sha3Context)
fn C.sha3_init384(context &Sha3Context)
fn C.sha3_init512(context &Sha3Context)

fn C.sha3_set_flags(context &Sha3Context, flag Sha3Flags) Sha3Flags

fn C.sha3_update(context &Sha3Context, buf_in []u8, len u64)
fn C.sha3_finalize(context &Sha3Context) []u8

fn main() {
	mut c := Sha3Context{}
	sha3_flags_keccak := Sha3Flags.sha3_flags_keccak
	println('SHA3 test C implementation')
	mut i := 16777216
  C.sha3_init256(&c)
  C.sha3_set_flags(&c, sha3_flags_keccak)
  for i > 0 {
    C.sha3_update(&c, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".bytes(), 64)
    i--
  }
  hash := C.sha3_finalize(&c)
	println('hash SHA256 $hash.str()')

}
[sha3.zip](https://github.com/vlang/v/files/15402848/sha3.zip)


What did you expect to see?

hash SHA3_256 result

What did you see instead?

Compilation with unknown C compiler
==================
/tmp/v_1000/sha3.01HYG2RMT1WP8CX020BV13RC6N.tmp.c:13117: warning: implicit declaration of function 'sha3_finalize'
/tmp/v_1000/sha3.01HYG2RMT1WP8CX020BV13RC6N.tmp.c:13117: error: '{' expected (got ";")
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@felipensp
Copy link
Member

Take a look at the function names on .h file, they are not lowercased.

E.g.

void sha3_Update(void *priv, void const *bufIn, size_t len);
void const *sha3_Finalize(void *priv);

Not a bug here.

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

2 participants