...
Run Format

Source file src/crypto/md5/md5block.go

Documentation: crypto/md5

     1  // Copyright 2013 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  // Code generated by go run gen.go -full -output md5block.go; DO NOT EDIT.
     6  
     7  package md5
     8  
     9  import (
    10  	"runtime"
    11  	"unsafe"
    12  )
    13  
    14  const x86 = runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
    15  
    16  var littleEndian bool
    17  
    18  func init() {
    19  	x := uint32(0x04030201)
    20  	y := [4]byte{0x1, 0x2, 0x3, 0x4}
    21  	littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
    22  }
    23  
    24  func blockGeneric(dig *digest, p []byte) {
    25  	a := dig.s[0]
    26  	b := dig.s[1]
    27  	c := dig.s[2]
    28  	d := dig.s[3]
    29  	var X *[16]uint32
    30  	var xbuf [16]uint32
    31  	for len(p) >= chunk {
    32  		aa, bb, cc, dd := a, b, c, d
    33  
    34  		// This is a constant condition - it is not evaluated on each iteration.
    35  		if x86 {
    36  			// MD5 was designed so that x86 processors can just iterate
    37  			// over the block data directly as uint32s, and we generate
    38  			// less code and run 1.3x faster if we take advantage of that.
    39  			// My apologies.
    40  			X = (*[16]uint32)(unsafe.Pointer(&p[0]))
    41  		} else if littleEndian && uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
    42  			X = (*[16]uint32)(unsafe.Pointer(&p[0]))
    43  		} else {
    44  			X = &xbuf
    45  			j := 0
    46  			for i := 0; i < 16; i++ {
    47  				X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uint32(p[j+2])<<16 | uint32(p[j+3])<<24
    48  				j += 4
    49  			}
    50  		}
    51  
    52  		// Round 1.
    53  
    54  		a += (((c ^ d) & b) ^ d) + X[0] + 3614090360
    55  		a = a<<7 | a>>(32-7) + b
    56  
    57  		d += (((b ^ c) & a) ^ c) + X[1] + 3905402710
    58  		d = d<<12 | d>>(32-12) + a
    59  
    60  		c += (((a ^ b) & d) ^ b) + X[2] + 606105819
    61  		c = c<<17 | c>>(32-17) + d
    62  
    63  		b += (((d ^ a) & c) ^ a) + X[3] + 3250441966
    64  		b = b<<22 | b>>(32-22) + c
    65  
    66  		a += (((c ^ d) & b) ^ d) + X[4] + 4118548399
    67  		a = a<<7 | a>>(32-7) + b
    68  
    69  		d += (((b ^ c) & a) ^ c) + X[5] + 1200080426
    70  		d = d<<12 | d>>(32-12) + a
    71  
    72  		c += (((a ^ b) & d) ^ b) + X[6] + 2821735955
    73  		c = c<<17 | c>>(32-17) + d
    74  
    75  		b += (((d ^ a) & c) ^ a) + X[7] + 4249261313
    76  		b = b<<22 | b>>(32-22) + c
    77  
    78  		a += (((c ^ d) & b) ^ d) + X[8] + 1770035416
    79  		a = a<<7 | a>>(32-7) + b
    80  
    81  		d += (((b ^ c) & a) ^ c) + X[9] + 2336552879
    82  		d = d<<12 | d>>(32-12) + a
    83  
    84  		c += (((a ^ b) & d) ^ b) + X[10] + 4294925233
    85  		c = c<<17 | c>>(32-17) + d
    86  
    87  		b += (((d ^ a) & c) ^ a) + X[11] + 2304563134
    88  		b = b<<22 | b>>(32-22) + c
    89  
    90  		a += (((c ^ d) & b) ^ d) + X[12] + 1804603682
    91  		a = a<<7 | a>>(32-7) + b
    92  
    93  		d += (((b ^ c) & a) ^ c) + X[13] + 4254626195
    94  		d = d<<12 | d>>(32-12) + a
    95  
    96  		c += (((a ^ b) & d) ^ b) + X[14] + 2792965006
    97  		c = c<<17 | c>>(32-17) + d
    98  
    99  		b += (((d ^ a) & c) ^ a) + X[15] + 1236535329
   100  		b = b<<22 | b>>(32-22) + c
   101  
   102  		// Round 2.
   103  
   104  		a += (((b ^ c) & d) ^ c) + X[(1+5*0)&15] + 4129170786
   105  		a = a<<5 | a>>(32-5) + b
   106  
   107  		d += (((a ^ b) & c) ^ b) + X[(1+5*1)&15] + 3225465664
   108  		d = d<<9 | d>>(32-9) + a
   109  
   110  		c += (((d ^ a) & b) ^ a) + X[(1+5*2)&15] + 643717713
   111  		c = c<<14 | c>>(32-14) + d
   112  
   113  		b += (((c ^ d) & a) ^ d) + X[(1+5*3)&15] + 3921069994
   114  		b = b<<20 | b>>(32-20) + c
   115  
   116  		a += (((b ^ c) & d) ^ c) + X[(1+5*4)&15] + 3593408605
   117  		a = a<<5 | a>>(32-5) + b
   118  
   119  		d += (((a ^ b) & c) ^ b) + X[(1+5*5)&15] + 38016083
   120  		d = d<<9 | d>>(32-9) + a
   121  
   122  		c += (((d ^ a) & b) ^ a) + X[(1+5*6)&15] + 3634488961
   123  		c = c<<14 | c>>(32-14) + d
   124  
   125  		b += (((c ^ d) & a) ^ d) + X[(1+5*7)&15] + 3889429448
   126  		b = b<<20 | b>>(32-20) + c
   127  
   128  		a += (((b ^ c) & d) ^ c) + X[(1+5*8)&15] + 568446438
   129  		a = a<<5 | a>>(32-5) + b
   130  
   131  		d += (((a ^ b) & c) ^ b) + X[(1+5*9)&15] + 3275163606
   132  		d = d<<9 | d>>(32-9) + a
   133  
   134  		c += (((d ^ a) & b) ^ a) + X[(1+5*10)&15] + 4107603335
   135  		c = c<<14 | c>>(32-14) + d
   136  
   137  		b += (((c ^ d) & a) ^ d) + X[(1+5*11)&15] + 1163531501
   138  		b = b<<20 | b>>(32-20) + c
   139  
   140  		a += (((b ^ c) & d) ^ c) + X[(1+5*12)&15] + 2850285829
   141  		a = a<<5 | a>>(32-5) + b
   142  
   143  		d += (((a ^ b) & c) ^ b) + X[(1+5*13)&15] + 4243563512
   144  		d = d<<9 | d>>(32-9) + a
   145  
   146  		c += (((d ^ a) & b) ^ a) + X[(1+5*14)&15] + 1735328473
   147  		c = c<<14 | c>>(32-14) + d
   148  
   149  		b += (((c ^ d) & a) ^ d) + X[(1+5*15)&15] + 2368359562
   150  		b = b<<20 | b>>(32-20) + c
   151  
   152  		// Round 3.
   153  
   154  		a += (b ^ c ^ d) + X[(5+3*0)&15] + 4294588738
   155  		a = a<<4 | a>>(32-4) + b
   156  
   157  		d += (a ^ b ^ c) + X[(5+3*1)&15] + 2272392833
   158  		d = d<<11 | d>>(32-11) + a
   159  
   160  		c += (d ^ a ^ b) + X[(5+3*2)&15] + 1839030562
   161  		c = c<<16 | c>>(32-16) + d
   162  
   163  		b += (c ^ d ^ a) + X[(5+3*3)&15] + 4259657740
   164  		b = b<<23 | b>>(32-23) + c
   165  
   166  		a += (b ^ c ^ d) + X[(5+3*4)&15] + 2763975236
   167  		a = a<<4 | a>>(32-4) + b
   168  
   169  		d += (a ^ b ^ c) + X[(5+3*5)&15] + 1272893353
   170  		d = d<<11 | d>>(32-11) + a
   171  
   172  		c += (d ^ a ^ b) + X[(5+3*6)&15] + 4139469664
   173  		c = c<<16 | c>>(32-16) + d
   174  
   175  		b += (c ^ d ^ a) + X[(5+3*7)&15] + 3200236656
   176  		b = b<<23 | b>>(32-23) + c
   177  
   178  		a += (b ^ c ^ d) + X[(5+3*8)&15] + 681279174
   179  		a = a<<4 | a>>(32-4) + b
   180  
   181  		d += (a ^ b ^ c) + X[(5+3*9)&15] + 3936430074
   182  		d = d<<11 | d>>(32-11) + a
   183  
   184  		c += (d ^ a ^ b) + X[(5+3*10)&15] + 3572445317
   185  		c = c<<16 | c>>(32-16) + d
   186  
   187  		b += (c ^ d ^ a) + X[(5+3*11)&15] + 76029189
   188  		b = b<<23 | b>>(32-23) + c
   189  
   190  		a += (b ^ c ^ d) + X[(5+3*12)&15] + 3654602809
   191  		a = a<<4 | a>>(32-4) + b
   192  
   193  		d += (a ^ b ^ c) + X[(5+3*13)&15] + 3873151461
   194  		d = d<<11 | d>>(32-11) + a
   195  
   196  		c += (d ^ a ^ b) + X[(5+3*14)&15] + 530742520
   197  		c = c<<16 | c>>(32-16) + d
   198  
   199  		b += (c ^ d ^ a) + X[(5+3*15)&15] + 3299628645
   200  		b = b<<23 | b>>(32-23) + c
   201  
   202  		// Round 4.
   203  
   204  		a += (c ^ (b | ^d)) + X[(7*0)&15] + 4096336452
   205  		a = a<<6 | a>>(32-6) + b
   206  
   207  		d += (b ^ (a | ^c)) + X[(7*1)&15] + 1126891415
   208  		d = d<<10 | d>>(32-10) + a
   209  
   210  		c += (a ^ (d | ^b)) + X[(7*2)&15] + 2878612391
   211  		c = c<<15 | c>>(32-15) + d
   212  
   213  		b += (d ^ (c | ^a)) + X[(7*3)&15] + 4237533241
   214  		b = b<<21 | b>>(32-21) + c
   215  
   216  		a += (c ^ (b | ^d)) + X[(7*4)&15] + 1700485571
   217  		a = a<<6 | a>>(32-6) + b
   218  
   219  		d += (b ^ (a | ^c)) + X[(7*5)&15] + 2399980690
   220  		d = d<<10 | d>>(32-10) + a
   221  
   222  		c += (a ^ (d | ^b)) + X[(7*6)&15] + 4293915773
   223  		c = c<<15 | c>>(32-15) + d
   224  
   225  		b += (d ^ (c | ^a)) + X[(7*7)&15] + 2240044497
   226  		b = b<<21 | b>>(32-21) + c
   227  
   228  		a += (c ^ (b | ^d)) + X[(7*8)&15] + 1873313359
   229  		a = a<<6 | a>>(32-6) + b
   230  
   231  		d += (b ^ (a | ^c)) + X[(7*9)&15] + 4264355552
   232  		d = d<<10 | d>>(32-10) + a
   233  
   234  		c += (a ^ (d | ^b)) + X[(7*10)&15] + 2734768916
   235  		c = c<<15 | c>>(32-15) + d
   236  
   237  		b += (d ^ (c | ^a)) + X[(7*11)&15] + 1309151649
   238  		b = b<<21 | b>>(32-21) + c
   239  
   240  		a += (c ^ (b | ^d)) + X[(7*12)&15] + 4149444226
   241  		a = a<<6 | a>>(32-6) + b
   242  
   243  		d += (b ^ (a | ^c)) + X[(7*13)&15] + 3174756917
   244  		d = d<<10 | d>>(32-10) + a
   245  
   246  		c += (a ^ (d | ^b)) + X[(7*14)&15] + 718787259
   247  		c = c<<15 | c>>(32-15) + d
   248  
   249  		b += (d ^ (c | ^a)) + X[(7*15)&15] + 3951481745
   250  		b = b<<21 | b>>(32-21) + c
   251  
   252  		a += aa
   253  		b += bb
   254  		c += cc
   255  		d += dd
   256  
   257  		p = p[chunk:]
   258  	}
   259  
   260  	dig.s[0] = a
   261  	dig.s[1] = b
   262  	dig.s[2] = c
   263  	dig.s[3] = d
   264  }
   265  

View as plain text