crypto

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package crypto holds the password hashing and the random source a script cannot write for itself.

PHP's password_hash() is one of the few standard functions with no implementation in the language: it needs a key derivation function and a CSPRNG, and phpscript exposes neither. Everything else the family does (parsing options, choosing an algorithm) is arithmetic a script could do, so the binding is deliberately narrow: the password functions here, and the CSPRNG pair in random.go that hands the same entropy to scripts directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rt *runner.Runtime)

Register installs the password hashing functions and their constants on rt.

func RegisterHash added in v0.4.0

func RegisterHash(rt *runner.Runtime)

RegisterHash installs PHP's message-digest pair. Like the CSPRNG, a digest is something a script cannot write for itself at any usable speed, which is what qualifies it for this package; the algorithm-agnostic hash() family is deliberately absent until something needs more than these two names.

Both return string, not []byte: a PHP string is a Go string in this runtime, and a []byte would reach scripts as a foreign Go value that strlen and concatenation do not recognise.

func RegisterIdentifiers added in v0.4.0

func RegisterIdentifiers(rt *runner.Runtime)

RegisterIdentifiers installs the id generators. Neither is a PHP name: PHP's own library mints no unique ids, so ports reach for composer packages (ramsey/uuid, symfony/ulid) whose value is exactly the entropy source this package already owns. Both are implemented here rather than through a Go dependency, because each is a format over crypto/rand and nothing more.

The two share one layout — a 48-bit millisecond timestamp followed by randomness — so both sort by creation time. ulid() renders it in Crockford base32; uuid() renders it as a version 7 UUID, the hexadecimal spelling of the same idea.

func RegisterRandom added in v0.4.0

func RegisterRandom(rt *runner.Runtime)

RegisterRandom installs the random functions on rt. random_bytes and random_int are the PHP 7+ core pair (paragonie/random_compat existed solely to polyfill them), read from crypto/rand, the same source Session\Manager mints session ids from. rand reads the same source: it exists because the PHP written against it is everywhere, but it takes no seed, so the seeded reproducibility of srand/mt_srand stays absent and those two with it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL