Skip to content

Commit

Permalink
syscall: libc_wasip2: arc4random_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski committed Mar 2, 2024
1 parent 156ecb0 commit 67beb70
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/syscall/libc_wasip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ydnar/wasm-tools-go/wasi/filesystem/types"
ioerror "github.com/ydnar/wasm-tools-go/wasi/io/error"
"github.com/ydnar/wasm-tools-go/wasi/io/streams"
"github.com/ydnar/wasm-tools-go/wasi/random/random"
)

func goString(cstr *byte) string {
Expand Down Expand Up @@ -1014,3 +1015,12 @@ func unsetenv(key *byte) int {
delete(libc_envs, k)
return 0
}

// void arc4random_buf (void *, size_t);
//
//go:export arc4random_buf
func arc4random_buf(p unsafe.Pointer, l uint) {
result := random.GetRandomBytes(uint64(l))
s := result.Slice()
memcpy(unsafe.Pointer(p), unsafe.Pointer(unsafe.SliceData(s)), uintptr(l))
}

0 comments on commit 67beb70

Please sign in to comment.