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 RegisterHash ¶ added in v0.4.0
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
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
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.