Skip to content

crypto.subtle #

Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. Use of this source code is governed by an MIT license that can be found in the LICENSE file. Package subtle implements functions that are often useful in cryptographic code but require careful thought to use correctly.

fn any_overlap #

fn any_overlap(x []u8, y []u8) bool

Note: require unsafe in futureany_overlap reports whether x and y share memory at any (not necessarily corresponding) index. The memory beyond the slice length is ignored.

fn constant_time_byte_eq #

fn constant_time_byte_eq(x u8, y u8) int

constant_time_byte_eq returns 1 when x == y.

fn constant_time_compare #

fn constant_time_compare(x []u8, y []u8) int

constant_time_compare returns 1 when x and y have equal contents. The runtime of this function is proportional of the length of x and y. It is NOT dependent on their content.

fn constant_time_copy #

fn constant_time_copy(v int, mut x []u8, y []u8)

constant_time_copy copies the contents of y into x, when v == 1. When v == 0, x is left unchanged. this function is undefined, when v takes any other value

fn constant_time_eq #

fn constant_time_eq(x int, y int) int

constant_time_eq returns 1 when x == y.

fn constant_time_less_or_eq #

fn constant_time_less_or_eq(x int, y int) int

constant_time_less_or_eq returns 1 if x <= y, and 0 otherwise. it is undefined when x or y are negative, or > (2^32 - 1)

fn constant_time_select #

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

constant_time_select returns x when v == 1, and y when v == 0. it is undefined when v is any other value

fn inexact_overlap #

fn inexact_overlap(x []u8, y []u8) bool

inexact_overlap reports whether x and y share memory at any non-corresponding index. The memory beyond the slice length is ignored. Note that x and y can have different lengths and still not have any inexact overlap.

inexact_overlap can be used to implement the requirements of the crypto/cipher AEAD, Block, BlockMode and Stream interfaces.