I want to use libhydrogen in PureBasic to sign and verify messages.
I got a problem with importing functions with fixed arrays, PureBasic does not support it. What would be the correct definition for the function in PureBasic?
;ImportC "hydrolib.lib" : EndImport
;needed types
!#define uint8_t unsigned char
!#define size_t long long
!#define hydro_random_SEEDBYTES 32
;!void hydro_random_buf_deterministic(void *out, size_t out_len,const uint8_t seed[hydro_random_SEEDBYTES]);
;simulate calling the function
!void hydro_random_buf_deterministic(void *out, size_t out_len, const uint8_t seed[hydro_random_SEEDBYTES])
!{
For a = 0 To 31
xx.a
!v_xx = seed[v_a];
Debug xx
Next
!};
;strucutre to use
Structure m256
a.a[32]
EndStructure
*x.m256 = AllocateMemory(32)
For a = 0 To 31
*x\a[a] = a
Next
;call the function
!hydro_random_buf_deterministic(0,0,p_x);
;according to this post http://forums.purebasic.com/english/viewtopic.php?p=582637,
;size_t is 8 bytes on windows and 4/8 on other os.
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Structure size_t
size_t.q
EndStructure
CompilerElse
CompilerIf #PB_Compiler_64Bit
Structure size_t
size_t.q
EndStructure
CompilerElse
Structure size_t
size_t.l
EndStructure
CompilerEndIf
CompilerEndIf
Define out
Define out_len.size_t
; Debug SizeOf(out_len)
out_len\size_t=10
#hydro_random_SEEDBYTES=32
Dim seed.a(#hydro_random_SEEDBYTES);normally, you can use dynamic array in procedure in place or static array
For i=0 To #hydro_random_SEEDBYTES-1
seed(i)=i
Next i
Procedure hydro_random_buf_deterministic(*out.INTEGER, *outlen.size_t, Array arrayseed.a(1))
*out\I=2
Debug arrayseed(12)
ProcedureReturn *outlen\size_t
EndProcedure
Debug hydro_random_buf_deterministic(@out, @out_len, seed()):Debug out
Debug ""
;== With static array ==============================================================
Structure sta
sta.a[#hydro_random_SEEDBYTES]
EndStructure
Define seedsta.sta
For i=0 To #hydro_random_SEEDBYTES-1
seedsta\sta[i]=i
Next i
Procedure hydro_random_buf_deterministic2(*out, *outlen.size_t, *seedsta.sta)
PokeI(*out,2)
ProcedureReturn *seedsta\sta[10]
EndProcedure
Define *out = AllocateMemory(SizeOf(integer))
Debug *out
Debug hydro_random_buf_deterministic2(@*out, @out_len, @seedsta)
Debug PeekI(@*out)
After some testing, the arrays can just be passed as pointers.
I use the sign/verify and hash functions of the lib.
If anyone needs compiled version of the lib and/or PureBasic headers for it. You can request them from me. Since it's not completely tested, i don't want to post them just yet.
Thorium wrote: Fri Jul 19, 2024 3:05 pm
After some testing, the arrays can just be passed as pointers.
I use the sign/verify and hash functions of the lib.
If anyone needs compiled version of the lib and/or PureBasic headers for it. You can request them from me. Since it's not completely tested, i don't want to post them just yet.