XU XUv0.13.1
中文

#crypto/hkdf

import: #crypto/hkdf

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

HKDF (RFC 5869): HMAC-based Extract-and-Expand Key Derivation Function using SHA-256. Aligned with `.org/x/crypto/hkdf`. Key derivation proceeds in two steps 1. Extract: PRK = HMAC-Hash(salt, IKM) to extract a pseudorandom key. 2. Expand: OKM = HKDF-Expand(PRK, info, L) to expand to desired length.

extract

XuAPI
pub fn extract(secret &string, salt &string) string

Purpose

extract extracts a pseudorandom key PRK of 32 bytes from input key material. If salt is empty, a string of 32 zero bytes is used per RFC 5869 §2.2.

Parameters

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

Returns

string — result string

expand

XuAPI
pub fn expand(prk &string, info &string, length int) string

Purpose

expand expands a pseudorandom key (PRK) with optional context info to length bytes. Maximum length is 255 * 32 = 8160 bytes per RFC 5869 §2.3. 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)
length int
length (int)

Returns

string — result string

key

XuAPI
pub fn key(secret &string, salt &string, info &string, length int) string

Purpose

key derives length bytes from secret, salt, and info in a single call. Throws on failure; handle the error or propagate it to the caller.

Parameters

secret &string
secret (read-only borrow; caller keeps the original; type &string)
salt &string
salt (read-only borrow; caller keeps the original; type &string)
info &string
info (read-only borrow; caller keeps the original; type &string)
length int
length (int)

Returns

string — result string