github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/crypto/subtle/constant_time.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package subtleは、暗号化コードでよく使用される関数を実装しますが、正しく使用するために注意深い考慮が必要です。
     6  package subtle
     7  
     8  // ConstantTimeCompareは、2つのスライスxとyが同じ内容を持つ場合は1を返し、そうでない場合は0を返します。実行時間はスライスの長さに依存し、内容には独立しています。xとyの長さが一致しない場合は、即座に0を返します。
     9  func ConstantTimeCompare(x, y []byte) int
    10  
    11  // ConstantTimeSelectは、vが1の場合はxを返し、vが0の場合はyを返します。
    12  // vが他の値を取る場合、動作は未定義です。
    13  func ConstantTimeSelect(v, x, y int) int
    14  
    15  // ConstantTimeByteEq は、x が y と等しい場合は1を、そうでない場合は0を返します。
    16  func ConstantTimeByteEq(x, y uint8) int
    17  
    18  // ConstantTimeEqは、x == yの場合は1を返し、それ以外の場合は0を返します。
    19  func ConstantTimeEq(x, y int32) int
    20  
    21  // ConstantTimeCopyは、v == 1の場合、yの内容(長さが等しいスライス)をxにコピーします。
    22  // v == 0の場合、xは変更されません。vが他の値を取る場合の動作は未定義です。
    23  func ConstantTimeCopy(v int, x, y []byte)
    24  
    25  // ConstantTimeLessOrEq は、x ≤ y の場合は1を返し、そうでない場合は0を返します。
    26  // ただし、xまたはyが負数または2**31 - 1より大きい場合、動作は未定義です。
    27  func ConstantTimeLessOrEq(x, y int) int