...

Source file src/vendor/golang.org/x/crypto/internal/poly1305/bits_compat.go

Documentation: vendor/golang.org/x/crypto/internal/poly1305

     1  // Copyright 2019 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  //go:build !go1.13
     6  
     7  package poly1305
     8  
     9  // Generic fallbacks for the math/bits intrinsics, copied from
    10  // src/math/bits/bits.go. They were added in Go 1.12, but Add64 and Sum64 had
    11  // variable time fallbacks until Go 1.13.
    12  
    13  func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
    14  	sum = x + y + carry
    15  	carryOut = ((x & y) | ((x | y) &^ sum)) >> 63
    16  	return
    17  }
    18  
    19  func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
    20  	diff = x - y - borrow
    21  	borrowOut = ((^x & y) | (^(x ^ y) & diff)) >> 63
    22  	return
    23  }
    24  
    25  func bitsMul64(x, y uint64) (hi, lo uint64) {
    26  	const mask32 = 1<<32 - 1
    27  	x0 := x & mask32
    28  	x1 := x >> 32
    29  	y0 := y & mask32
    30  	y1 := y >> 32
    31  	w0 := x0 * y0
    32  	t := x1*y0 + w0>>32
    33  	w1 := t & mask32
    34  	w2 := t >> 32
    35  	w1 += x0 * y1
    36  	hi = x1*y1 + w2 + w1>>32
    37  	lo = x * y
    38  	return
    39  }
    40  

View as plain text