XU XUv0.16.0

#crypto/password

import: #crypto/password

counts: 6 functions, 0 methods, 0 types, 0 constants, 0 method sets

Password hashing & Key Derivation (PBKDF2-HMAC-SHA256 + HKDF-SHA256). Self-describing encoded hash for login $pbkdf2-sha256$<iterations>$<salt_b64>$<dk_b64> PBKDF2 work delegates to crypto/pbkdf2.key (precomputed SHA-256 midstates). XU-CT-USE: fixed-shape-only verify compares digests with crypto/subtle. Maximum PBKDF2 derived key length, including verified stored keys.

pbkdf2_hmac_sha256

XuAPI
pub fn pbkdf2_hmac_sha256(password string, salt string, iterations int, key_len int) string

Purpose

pbkdf2_hmac_sha256 returns key_len raw bytes (RFC 2898). Throws on failure; handle the error or propagate it to the caller.

Parameters

password string
password (string)
salt string
salt (string)
iterations int
iterations (int)
key_len int
key_len (int)

Returns

string — result string

hkdf_extract_sha256

XuAPI
pub fn hkdf_extract_sha256(salt &string, ikm &string) string

Purpose

hkdf_extract_sha256 computes a 32-byte pseudorandom key PRK (RFC 5869 §2.2).

Parameters

salt &string
salt (read-only borrow; caller keeps the original; type &string)
ikm &string
ikm (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

hkdf_expand_sha256

XuAPI
pub fn hkdf_expand_sha256(prk &string, info &string, key_len int) string

Purpose

hkdf_expand_sha256 expands PRK to key_len bytes (RFC 5869 §2.3, max 255*32). Throws on failure; handle the error or propagate it to the caller.

Parameters

prk &string
prk (read-only borrow; caller keeps the original; type &string)
info &string
info (read-only borrow; caller keeps the original; type &string)
key_len int
key_len (int)

Returns

string — result string

hash

XuAPI
pub fn hash(password string) string

Purpose

hash returns $pbkdf2-sha256$iter$salt_b64$dk_b64.

Parameters

password string
password (string)

Returns

string — result string

hash_iter

XuAPI
pub fn hash_iter(password string, iterations int) string

Purpose

Hash iter. Throws on failure; handle the error or propagate it to the caller.

Parameters

password string
password (string)
iterations int
iterations (int)

Returns

string — result string

verify

XuAPI
pub fn verify(encoded string, password string) bool

Purpose

verify reports whether password matches an encoded hash.

Parameters

encoded string
encoded (string)
password string
password (string)

Returns

bool — true or false