Black Lives Matter. Support the Equal Justice Initiative.

Text file src/crypto/sha1/sha1block_arm64.s

Documentation: crypto/sha1

     1// Copyright 2017 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#include "textflag.h"
     6
     7#define HASHUPDATECHOOSE \
     8	SHA1C	V16.S4, V1, V2 \
     9	SHA1H	V3, V1 \
    10	VMOV	V2.B16, V3.B16
    11
    12#define HASHUPDATEPARITY \
    13	SHA1P	V16.S4, V1, V2 \
    14	SHA1H	V3, V1 \
    15	VMOV	V2.B16, V3.B16
    16
    17#define HASHUPDATEMAJ \
    18	SHA1M	V16.S4, V1, V2 \
    19	SHA1H	V3, V1 \
    20	VMOV	V2.B16, V3.B16
    21
    22// func sha1block(h []uint32, p []byte, k []uint32)
    23TEXT ·sha1block(SB),NOSPLIT,$0
    24	MOVD	h_base+0(FP), R0                             // hash value first address
    25	MOVD	p_base+24(FP), R1                            // message first address
    26	MOVD	k_base+48(FP), R2                            // k constants first address
    27	MOVD	p_len+32(FP), R3                             // message length
    28	VLD1.P	16(R0), [V0.S4]
    29	FMOVS	(R0), F20
    30	SUB	$16, R0, R0
    31
    32blockloop:
    33
    34	VLD1.P	16(R1), [V4.B16]                             // load message
    35	VLD1.P	16(R1), [V5.B16]
    36	VLD1.P	16(R1), [V6.B16]
    37	VLD1.P	16(R1), [V7.B16]
    38	VLD1	(R2), [V19.S4]                               // load constant k0-k79
    39	VMOV	V0.B16, V2.B16
    40	VMOV	V20.S[0], V1
    41	VMOV	V2.B16, V3.B16
    42	VDUP	V19.S[0], V17.S4
    43	VREV32	V4.B16, V4.B16                               // prepare for using message in Byte format
    44	VREV32	V5.B16, V5.B16
    45	VREV32	V6.B16, V6.B16
    46	VREV32	V7.B16, V7.B16
    47
    48
    49	VDUP	V19.S[1], V18.S4
    50	VADD	V17.S4, V4.S4, V16.S4
    51	SHA1SU0	V6.S4, V5.S4, V4.S4
    52	HASHUPDATECHOOSE
    53	SHA1SU1	V7.S4, V4.S4
    54
    55	VADD	V17.S4, V5.S4, V16.S4
    56	SHA1SU0	V7.S4, V6.S4, V5.S4
    57	HASHUPDATECHOOSE
    58	SHA1SU1	V4.S4, V5.S4
    59	VADD	V17.S4, V6.S4, V16.S4
    60	SHA1SU0	V4.S4, V7.S4, V6.S4
    61	HASHUPDATECHOOSE
    62	SHA1SU1	V5.S4, V6.S4
    63
    64	VADD	V17.S4, V7.S4, V16.S4
    65	SHA1SU0	V5.S4, V4.S4, V7.S4
    66	HASHUPDATECHOOSE
    67	SHA1SU1	V6.S4, V7.S4
    68
    69	VADD	V17.S4, V4.S4, V16.S4
    70	SHA1SU0	V6.S4, V5.S4, V4.S4
    71	HASHUPDATECHOOSE
    72	SHA1SU1	V7.S4, V4.S4
    73
    74	VDUP	V19.S[2], V17.S4
    75	VADD	V18.S4, V5.S4, V16.S4
    76	SHA1SU0	V7.S4, V6.S4, V5.S4
    77	HASHUPDATEPARITY
    78	SHA1SU1	V4.S4, V5.S4
    79
    80	VADD	V18.S4, V6.S4, V16.S4
    81	SHA1SU0	V4.S4, V7.S4, V6.S4
    82	HASHUPDATEPARITY
    83	SHA1SU1	V5.S4, V6.S4
    84
    85	VADD	V18.S4, V7.S4, V16.S4
    86	SHA1SU0	V5.S4, V4.S4, V7.S4
    87	HASHUPDATEPARITY
    88	SHA1SU1	V6.S4, V7.S4
    89
    90	VADD	V18.S4, V4.S4, V16.S4
    91	SHA1SU0	V6.S4, V5.S4, V4.S4
    92	HASHUPDATEPARITY
    93	SHA1SU1	V7.S4, V4.S4
    94
    95	VADD	V18.S4, V5.S4, V16.S4
    96	SHA1SU0	V7.S4, V6.S4, V5.S4
    97	HASHUPDATEPARITY
    98	SHA1SU1	V4.S4, V5.S4
    99
   100	VDUP	V19.S[3], V18.S4
   101	VADD	V17.S4, V6.S4, V16.S4
   102	SHA1SU0	V4.S4, V7.S4, V6.S4
   103	HASHUPDATEMAJ
   104	SHA1SU1	V5.S4, V6.S4
   105
   106	VADD	V17.S4, V7.S4, V16.S4
   107	SHA1SU0	V5.S4, V4.S4, V7.S4
   108	HASHUPDATEMAJ
   109	SHA1SU1	V6.S4, V7.S4
   110
   111	VADD	V17.S4, V4.S4, V16.S4
   112	SHA1SU0	V6.S4, V5.S4, V4.S4
   113	HASHUPDATEMAJ
   114	SHA1SU1	V7.S4, V4.S4
   115
   116	VADD	V17.S4, V5.S4, V16.S4
   117	SHA1SU0	V7.S4, V6.S4, V5.S4
   118	HASHUPDATEMAJ
   119	SHA1SU1	V4.S4, V5.S4
   120
   121	VADD	V17.S4, V6.S4, V16.S4
   122	SHA1SU0	V4.S4, V7.S4, V6.S4
   123	HASHUPDATEMAJ
   124	SHA1SU1	V5.S4, V6.S4
   125
   126	VADD	V18.S4, V7.S4, V16.S4
   127	SHA1SU0	V5.S4, V4.S4, V7.S4
   128	HASHUPDATEPARITY
   129	SHA1SU1	V6.S4, V7.S4
   130
   131	VADD	V18.S4, V4.S4, V16.S4
   132	HASHUPDATEPARITY
   133
   134	VADD	V18.S4, V5.S4, V16.S4
   135	HASHUPDATEPARITY
   136
   137	VADD	V18.S4, V6.S4, V16.S4
   138	HASHUPDATEPARITY
   139
   140	VADD	V18.S4, V7.S4, V16.S4
   141	HASHUPDATEPARITY
   142
   143	SUB	$64, R3, R3                                  // message length - 64bytes, then compare with 64bytes
   144	VADD	V2.S4, V0.S4, V0.S4
   145	VADD	V1.S4, V20.S4, V20.S4
   146	CBNZ	R3, blockloop
   147
   148sha1ret:
   149
   150	VST1.P	[V0.S4], 16(R0)                               // store hash value H(dcba)
   151	FMOVS	F20, (R0)                                     // store hash value H(e)
   152	RET

View as plain text