subtle

package
v1.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

subtleパッケージは、暗号化コードでよく使用される関数を実装しますが、正しく使用するために注意深い考慮が必要です。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstantTimeByteEq

func ConstantTimeByteEq(x, y uint8) int

ConstantTimeByteEq は、x が y と等しい場合は1を、そうでない場合は0を返します。

func ConstantTimeCompare

func ConstantTimeCompare(x, y []byte) int

ConstantTimeCompareは、2つのスライスxとyが同じ内容を持つ場合は1を返し、そうでない場合は0を返します。実行時間はスライスの長さに依存し、内容には独立しています。xとyの長さが一致しない場合は、即座に0を返します。

func ConstantTimeCopy

func ConstantTimeCopy(v int, x, y []byte)

ConstantTimeCopyは、v == 1の場合、yの内容(長さが等しいスライス)をxにコピーします。 v == 0の場合、xは変更されません。vが他の値を取る場合の動作は未定義です。

func ConstantTimeEq

func ConstantTimeEq(x, y int32) int

ConstantTimeEqは、x == yの場合は1を返し、それ以外の場合は0を返します。

func ConstantTimeLessOrEq added in v1.2.0

func ConstantTimeLessOrEq(x, y int) int

ConstantTimeLessOrEq は、x ≤ y の場合は1を返し、そうでない場合は0を返します。 ただし、xまたはyが負数または2**31 - 1より大きい場合、動作は未定義です。

func ConstantTimeSelect

func ConstantTimeSelect(v, x, y int) int

ConstantTimeSelectは、vが1の場合はxを返し、vが0の場合はyを返します。 vが他の値を取る場合、動作は未定義です。

func WithDataIndependentTiming added in v1.25.0

func WithDataIndependentTiming(f func())

WithDataIndependentTiming enables architecture specific features which ensure that the timing of specific instructions is independent of their inputs before executing f. On f returning it disables these features.

WithDataIndependentTiming should only be used when f is written to make use of constant-time operations. WithDataIndependentTiming does not make variable-time code constant-time.

WithDataIndependentTiming may lock the current goroutine to the OS thread for the duration of f. Calls to WithDataIndependentTiming may be nested.

On Arm64 processors with FEAT_DIT, WithDataIndependentTiming enables PSTATE.DIT. See https://developer.arm.com/documentation/ka005181/1-0/?lang=en.

Currently, on all other architectures WithDataIndependentTiming executes f immediately with no other side-effects.

func XORBytes added in v1.20.0

func XORBytes(dst, x, y []byte) int

XORBytesはすべてのi < n = min(len(x), len(y))に対してdst[i] = x[i] ^ y[i]を設定し、 dstに書き込まれたバイト数nを返します。

dstの長さが少なくともnでない場合、 XORBytesはdstに何も書き込まずにパニックします。

dstとxまたはyは完全に重複するか全く重複しないかのいずれかである必要があり、 そうでない場合XORBytesはパニックすることがあります。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL