XU XUv0.16.0

#crypto/subtle

导入方式: #crypto/subtle

公开 API: 5 函数, 0 方法, 0 类型, 0 常量, 0 方法集

常时比较外形的工具;后端不保证常时。

constant_time_compare

XuAPI
pub fn constant_time_compare(x &string, y &string) int

用途

恒定时间比较。

参数

x &string
值(只读借用,调用方仍持有原值;类型 &string)
y &string
值(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

constant_time_byte_eq

XuAPI
pub fn constant_time_byte_eq(x int, y int) int

用途

以固定恒定时间比较两字节是否相等,防范时序侧信道攻击。

参数

x int
值(int)
y int
值(int)

返回值

int — 该类型的值

constant_time_eq

XuAPI
pub fn constant_time_eq(x int, y int) int

用途

以固定恒定时间比较两个整数切片或数据,防范时序侧信道攻击。

参数

x int
值(int)
y int
值(int)

返回值

int — 该类型的值

constant_time_select

XuAPI
pub fn constant_time_select(v int, x int, y int) int

用途

以恒定时间根据标志选择返回两个值之一(v=1 返回 x,v=0 返回 y)。

参数

v int
值(int)
x int
值(int)
y int
值(int)

返回值

int — 该类型的值

xor_bytes

XuAPI
pub fn xor_bytes(x &string, y &string) string

用途

执行 xor bytes 操作。失败时抛出错误,调用方需处理或继续传播。

参数

x &string
值(只读借用,调用方仍持有原值;类型 &string)
y &string
值(只读借用,调用方仍持有原值;类型 &string)

返回值

string — 结果字符串