aboutsummaryrefslogtreecommitdiff
path: root/core/crypto
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2024-03-17 10:29:59 +0900
committerYawning Angel <yawning@schwanenlied.me>2024-04-09 10:23:58 +0900
commitb155fdf8c96d6269fe0f56a3fda76a3df1e5a7c8 (patch)
treec7fec38a6c943882c457f1c368325853e4f4f6b3 /core/crypto
parenta43a5b053c1d1e931eeb56d65e6a40f634a0b94f (diff)
core/crypto: Add `has_rand_bytes`
This allows runtime detection as to if `rand_bytes` is supported or not, and lets us enable the test-case on all of the supported targets.
Diffstat (limited to 'core/crypto')
-rw-r--r--core/crypto/crypto.odin10
-rw-r--r--core/crypto/rand_bsd.odin4
-rw-r--r--core/crypto/rand_darwin.odin4
-rw-r--r--core/crypto/rand_generic.odin4
-rw-r--r--core/crypto/rand_js.odin4
-rw-r--r--core/crypto/rand_linux.odin4
-rw-r--r--core/crypto/rand_windows.odin4
7 files changed, 34 insertions, 0 deletions
diff --git a/core/crypto/crypto.odin b/core/crypto/crypto.odin
index 6cdcacb9c..05f25111a 100644
--- a/core/crypto/crypto.odin
+++ b/core/crypto/crypto.odin
@@ -1,3 +1,7 @@
+/*
+package crypto implements a selection of cryptography algorithms and useful
+helper routines.
+*/
package crypto
import "core:mem"
@@ -51,3 +55,9 @@ rand_bytes :: proc (dst: []byte) {
_rand_bytes(dst)
}
+
+// has_rand_bytes returns true iff the target has support for accessing the
+// system entropty source.
+has_rand_bytes :: proc () -> bool {
+ return _has_rand_bytes()
+}
diff --git a/core/crypto/rand_bsd.odin b/core/crypto/rand_bsd.odin
index 8e2be1d95..61eaf652f 100644
--- a/core/crypto/rand_bsd.odin
+++ b/core/crypto/rand_bsd.odin
@@ -10,3 +10,7 @@ foreign libc {
_rand_bytes :: proc(dst: []byte) {
arc4random_buf(raw_data(dst), len(dst))
}
+
+_has_rand_bytes :: proc () -> bool {
+ return true
+}
diff --git a/core/crypto/rand_darwin.odin b/core/crypto/rand_darwin.odin
index ec44c1491..2864b46dd 100644
--- a/core/crypto/rand_darwin.odin
+++ b/core/crypto/rand_darwin.odin
@@ -10,3 +10,7 @@ _rand_bytes :: proc(dst: []byte) {
panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", res, msg))
}
}
+
+_has_rand_bytes :: proc () -> bool {
+ return true
+}
diff --git a/core/crypto/rand_generic.odin b/core/crypto/rand_generic.odin
index bf7abbbe2..006ca51fe 100644
--- a/core/crypto/rand_generic.odin
+++ b/core/crypto/rand_generic.odin
@@ -9,3 +9,7 @@ package crypto
_rand_bytes :: proc(dst: []byte) {
unimplemented("crypto: rand_bytes not supported on this OS")
}
+
+_has_rand_bytes :: proc () -> bool {
+ return false
+}
diff --git a/core/crypto/rand_js.odin b/core/crypto/rand_js.odin
index 353b1e6b9..cb2711404 100644
--- a/core/crypto/rand_js.odin
+++ b/core/crypto/rand_js.odin
@@ -18,3 +18,7 @@ _rand_bytes :: proc(dst: []byte) {
dst = dst[to_read:]
}
}
+
+_has_rand_bytes :: proc () -> bool {
+ return true
+}
diff --git a/core/crypto/rand_linux.odin b/core/crypto/rand_linux.odin
index 86fc425d6..05c05597d 100644
--- a/core/crypto/rand_linux.odin
+++ b/core/crypto/rand_linux.odin
@@ -34,3 +34,7 @@ _rand_bytes :: proc (dst: []byte) {
dst = dst[n_read:]
}
}
+
+_has_rand_bytes :: proc () -> bool {
+ return true
+}
diff --git a/core/crypto/rand_windows.odin b/core/crypto/rand_windows.odin
index 53b58c776..e1d9f6118 100644
--- a/core/crypto/rand_windows.odin
+++ b/core/crypto/rand_windows.odin
@@ -21,3 +21,7 @@ _rand_bytes :: proc(dst: []byte) {
}
}
}
+
+_has_rand_bytes :: proc () -> bool {
+ return true
+}