Skip to content

Commit 9d5cc62

Browse files
committed
rustg 6.0.0
1 parent 85bfc11 commit 9d5cc62

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

code/__DEFINES/__rust_g.dm

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,70 @@
203203

204204
#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
205205
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, fname)
206-
#define rustg_hash_generate_totp(seed) RUSTG_CALL(RUST_G, "generate_totp")(seed)
207-
#define rustg_hash_generate_totp_tolerance(seed, tolerance) RUSTG_CALL(RUST_G, "generate_totp_tolerance")(seed, tolerance)
206+
207+
/// Supported algorithms: RUSTG_HASH_SHA1, RUSTG_HASH_SHA256, RUSTG_HASH_SHA512
208+
/// Seed must be between 10 bytes to 64 bytes (padded or unpadded) of base32. 20 bytes is recommended. Use a CSPRNG.
209+
/// Refresh rate is fixed at 30sec and digit count is fixed at 6
210+
#define rustg_hash_generate_totp(algorithm, seed) RUSTG_CALL(RUST_G, "generate_totp")(algorithm, seed)
211+
/// Supported algorithms: RUSTG_HASH_SHA1, RUSTG_HASH_SHA256, RUSTG_HASH_SHA512
212+
/// Seed must be between 10 bytes to 64 bytes (padded or unpadded) of base32. 20 bytes is recommended. Use a CSPRNG.
213+
/// Refresh rate is fixed at 30sec and digit count is fixed at 6
214+
/// Tolerance is the number of codes +-30sec from the current one that are allowed.
215+
#define rustg_hash_generate_totp_tolerance(algorithm, seed, tolerance) RUSTG_CALL(RUST_G, "generate_totp_tolerance")(algorithm, seed, tolerance)
216+
217+
/// Creates a cryptographically-secure pseudorandom number generator using the OS-level PRNG as a seed
218+
/// n_bytes is the number of bytes provided to the RNG, the length of the string output varies by format
219+
/// The output string length and characters contained in each format is as follows:
220+
/// RUSTG_RNG_FORMAT_HEX: n_bytes * 2, [a-z0-9]
221+
/// RUSTG_RNG_FORMAT_ALPHANUMERIC: n_bytes, [A-Za-z0-9]
222+
/// RUSTG_RNG_FORMAT_BASE32: ceil(n_bytes / 5 * 8) [A-Z2-7]
223+
/// RUSTG_RNG_FORMAT_BASE32_PADDED: ceil(n_bytes / 5) * 8 [A-Z2-7=]
224+
/// RUSTG_RNG_FORMAT_BASE64: 4 * ceil(n_bytes/3), [A-Za-z0-9+/=]
225+
/// Outputs "ERROR: [reason]" if the format string provided is invalid, or n_bytes is not a positive non-zero integer
226+
#define rustg_csprng_chacha20(format, n_bytes) RUSTG_CALL(RUST_G, "csprng_chacha20")(format, "[n_bytes]")
227+
228+
/// Creates a seeded pseudorandom number generator using the SHA256 hash output bytes of the seed string
229+
/// Note that this function is NOT suitable for use in cryptography and is intended for high-quality **predictable** RNG
230+
/// Use rustg_csprng_chacha20 for a cryptographically-secure PRNG.
231+
/// n_bytes is the number of bytes provided to the RNG, the length of the string output varies by format
232+
/// The output string length and characters contained in each format is as follows:
233+
/// RUSTG_RNG_FORMAT_HEX: n_bytes * 2, [a-z0-9]
234+
/// RUSTG_RNG_FORMAT_ALPHANUMERIC: n_bytes, [A-Za-z0-9]
235+
/// RUSTG_RNG_FORMAT_BASE32: ceil(n_bytes / 5 * 8) [A-Z2-7]
236+
/// RUSTG_RNG_FORMAT_BASE32_PADDED: ceil(n_bytes / 5) * 8 [A-Z2-7=]
237+
/// RUSTG_RNG_FORMAT_BASE64: 4 * ceil(n_bytes/3), [A-Za-z0-9+/=]
238+
/// Outputs "ERROR: [reason]" if the format string provided is invalid, or n_bytes is not a positive non-zero integer
239+
#define rustg_prng_chacha20_seeded(format, n_bytes, seed) RUSTG_CALL(RUST_G, "prng_chacha20_seeded")(format, "[n_bytes]", seed)
240+
241+
#define RUSTG_RNG_FORMAT_HEX "hex"
242+
#define RUSTG_RNG_FORMAT_ALPHANUMERIC "alphanumeric"
243+
#define RUSTG_RNG_FORMAT_BASE32 "base32_rfc4648"
244+
#define RUSTG_RNG_FORMAT_BASE32_PADDED "base32_rfc4648_pad"
245+
#define RUSTG_RNG_FORMAT_BASE64 "base64"
208246

209247
#define RUSTG_HASH_MD5 "md5"
210248
#define RUSTG_HASH_SHA1 "sha1"
211249
#define RUSTG_HASH_SHA256 "sha256"
212250
#define RUSTG_HASH_SHA512 "sha512"
213251
#define RUSTG_HASH_XXH64 "xxh64"
252+
#define RUSTG_HASH_BASE32 "base32_rfc4648"
253+
#define RUSTG_HASH_BASE32_PADDED "base32_rfc4648_pad"
214254
#define RUSTG_HASH_BASE64 "base64"
215255

216256
/// Encode a given string into base64
217257
#define rustg_encode_base64(str) rustg_hash_string(RUSTG_HASH_BASE64, str)
218-
/// Decode a given base64 string
258+
/// Decode a given base64 string. This expects padding.
259+
/// Returns a blank string if the string is not valid base64.
219260
#define rustg_decode_base64(str) RUSTG_CALL(RUST_G, "decode_base64")(str)
220261

262+
/// Encode a given string into base32 (RFC4648)
263+
/// If padding set to FALSE, will not output padding characters.
264+
#define rustg_encode_base32(str, padding) rustg_hash_string(padding ? RUSTG_HASH_BASE32_PADDED : RUSTG_HASH_BASE32, str)
265+
/// Decode a given base32 (RFC4648) string
266+
/// If padding set to FALSE, decoding will not support padding characters.
267+
/// Returns a blank string if the string is not valid base32.
268+
#define rustg_decode_base32(str, padding) RUSTG_CALL(RUST_G, "decode_base32")(str, "[padding ? 1 : 0]")
269+
221270
#ifdef RUSTG_OVERRIDE_BUILTINS
222271
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
223272
#endif

dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export BYOND_MAJOR=516
88
export BYOND_MINOR=1661
99

1010
#rust_g git tag
11-
export RUST_G_VERSION=4.2.0
11+
export RUST_G_VERSION=6.0.0
1212

1313
#node version
1414
export NODE_VERSION_LTS=22.14.0

rust_g.dll

-13.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)