Source file src/crypto/internal/fips140/sha256/_asm/sha256block_amd64_asm.go

     1  // Copyright 2024 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 main
     6  
     7  import (
     8  	"os"
     9  
    10  	. "github.com/mmcloughlin/avo/build"
    11  )
    12  
    13  //go:generate go run . -out ../sha256block_amd64.s
    14  
    15  // SHA256 block routine. See sha256block.go for Go equivalent.
    16  //
    17  // The algorithm is detailed in FIPS 180-4:
    18  //
    19  //  https://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
    20  
    21  // Wt = Mt; for 0 <= t <= 15
    22  // Wt = SIGMA1(Wt-2) + SIGMA0(Wt-15) + Wt-16; for 16 <= t <= 63
    23  //
    24  // a = H0
    25  // b = H1
    26  // c = H2
    27  // d = H3
    28  // e = H4
    29  // f = H5
    30  // g = H6
    31  // h = H7
    32  //
    33  // for t = 0 to 63 {
    34  //    T1 = h + BIGSIGMA1(e) + Ch(e,f,g) + Kt + Wt
    35  //    T2 = BIGSIGMA0(a) + Maj(a,b,c)
    36  //    h = g
    37  //    g = f
    38  //    f = e
    39  //    e = d + T1
    40  //    d = c
    41  //    c = b
    42  //    b = a
    43  //    a = T1 + T2
    44  // }
    45  //
    46  // H0 = a + H0
    47  // H1 = b + H1
    48  // H2 = c + H2
    49  // H3 = d + H3
    50  // H4 = e + H4
    51  // H5 = f + H5
    52  // H6 = g + H6
    53  // H7 = h + H7
    54  
    55  func main() {
    56  	// https://github.com/mmcloughlin/avo/issues/450
    57  	os.Setenv("GOOS", "linux")
    58  	os.Setenv("GOARCH", "amd64")
    59  
    60  	Package("crypto/internal/fips140/sha256")
    61  	ConstraintExpr("!purego")
    62  	blockAVX2()
    63  	blockSHANI()
    64  	Generate()
    65  }
    66  
    67  var _K = []uint32{
    68  	0x428a2f98,
    69  	0x71374491,
    70  	0xb5c0fbcf,
    71  	0xe9b5dba5,
    72  	0x3956c25b,
    73  	0x59f111f1,
    74  	0x923f82a4,
    75  	0xab1c5ed5,
    76  	0xd807aa98,
    77  	0x12835b01,
    78  	0x243185be,
    79  	0x550c7dc3,
    80  	0x72be5d74,
    81  	0x80deb1fe,
    82  	0x9bdc06a7,
    83  	0xc19bf174,
    84  	0xe49b69c1,
    85  	0xefbe4786,
    86  	0x0fc19dc6,
    87  	0x240ca1cc,
    88  	0x2de92c6f,
    89  	0x4a7484aa,
    90  	0x5cb0a9dc,
    91  	0x76f988da,
    92  	0x983e5152,
    93  	0xa831c66d,
    94  	0xb00327c8,
    95  	0xbf597fc7,
    96  	0xc6e00bf3,
    97  	0xd5a79147,
    98  	0x06ca6351,
    99  	0x14292967,
   100  	0x27b70a85,
   101  	0x2e1b2138,
   102  	0x4d2c6dfc,
   103  	0x53380d13,
   104  	0x650a7354,
   105  	0x766a0abb,
   106  	0x81c2c92e,
   107  	0x92722c85,
   108  	0xa2bfe8a1,
   109  	0xa81a664b,
   110  	0xc24b8b70,
   111  	0xc76c51a3,
   112  	0xd192e819,
   113  	0xd6990624,
   114  	0xf40e3585,
   115  	0x106aa070,
   116  	0x19a4c116,
   117  	0x1e376c08,
   118  	0x2748774c,
   119  	0x34b0bcb5,
   120  	0x391c0cb3,
   121  	0x4ed8aa4a,
   122  	0x5b9cca4f,
   123  	0x682e6ff3,
   124  	0x748f82ee,
   125  	0x78a5636f,
   126  	0x84c87814,
   127  	0x8cc70208,
   128  	0x90befffa,
   129  	0xa4506ceb,
   130  	0xbef9a3f7,
   131  	0xc67178f2,
   132  }
   133  

View as plain text