github.com/insolar/x-crypto@v0.0.0-20191031140942-75fab8a325f6/sha256/sha256block_arm64.s (about) 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 HASHUPDATE \ 8 SHA256H V9.S4, V3, V2 \ 9 SHA256H2 V9.S4, V8, V3 \ 10 VMOV V2.B16, V8.B16 11 12 // func sha256block(h []uint32, p []byte, k []uint32) 13 TEXT ·sha256block(SB),NOSPLIT,$0 14 MOVD h_base+0(FP), R0 // Hash value first address 15 MOVD p_base+24(FP), R1 // message first address 16 MOVD k_base+48(FP), R2 // k constants first address 17 MOVD p_len+32(FP), R3 // message length 18 VLD1 (R0), [V0.S4, V1.S4] // load h(a,b,c,d,e,f,g,h) 19 VLD1.P 64(R2), [V16.S4, V17.S4, V18.S4, V19.S4] 20 VLD1.P 64(R2), [V20.S4, V21.S4, V22.S4, V23.S4] 21 VLD1.P 64(R2), [V24.S4, V25.S4, V26.S4, V27.S4] 22 VLD1 (R2), [V28.S4, V29.S4, V30.S4, V31.S4] //load 64*4bytes K constant(K0-K63) 23 24 blockloop: 25 26 VLD1.P 16(R1), [V4.B16] // load 16bytes message 27 VLD1.P 16(R1), [V5.B16] // load 16bytes message 28 VLD1.P 16(R1), [V6.B16] // load 16bytes message 29 VLD1.P 16(R1), [V7.B16] // load 16bytes message 30 VMOV V0.B16, V2.B16 // backup: VO h(dcba) 31 VMOV V1.B16, V3.B16 // backup: V1 h(hgfe) 32 VMOV V2.B16, V8.B16 33 VREV32 V4.B16, V4.B16 // prepare for using message in Byte format 34 VREV32 V5.B16, V5.B16 35 VREV32 V6.B16, V6.B16 36 VREV32 V7.B16, V7.B16 37 38 VADD V16.S4, V4.S4, V9.S4 // V18(W0+K0...W3+K3) 39 SHA256SU0 V5.S4, V4.S4 // V4: (su0(W1)+W0,...,su0(W4)+W3) 40 HASHUPDATE // H4 41 42 VADD V17.S4, V5.S4, V9.S4 // V18(W4+K4...W7+K7) 43 SHA256SU0 V6.S4, V5.S4 // V5: (su0(W5)+W4,...,su0(W8)+W7) 44 SHA256SU1 V7.S4, V6.S4, V4.S4 // V4: W16-W19 45 HASHUPDATE // H8 46 47 VADD V18.S4, V6.S4, V9.S4 // V18(W8+K8...W11+K11) 48 SHA256SU0 V7.S4, V6.S4 // V6: (su0(W9)+W8,...,su0(W12)+W11) 49 SHA256SU1 V4.S4, V7.S4, V5.S4 // V5: W20-W23 50 HASHUPDATE // H12 51 52 VADD V19.S4, V7.S4, V9.S4 // V18(W12+K12...W15+K15) 53 SHA256SU0 V4.S4, V7.S4 // V7: (su0(W13)+W12,...,su0(W16)+W15) 54 SHA256SU1 V5.S4, V4.S4, V6.S4 // V6: W24-W27 55 HASHUPDATE // H16 56 57 VADD V20.S4, V4.S4, V9.S4 // V18(W16+K16...W19+K19) 58 SHA256SU0 V5.S4, V4.S4 // V4: (su0(W17)+W16,...,su0(W20)+W19) 59 SHA256SU1 V6.S4, V5.S4, V7.S4 // V7: W28-W31 60 HASHUPDATE // H20 61 62 VADD V21.S4, V5.S4, V9.S4 // V18(W20+K20...W23+K23) 63 SHA256SU0 V6.S4, V5.S4 // V5: (su0(W21)+W20,...,su0(W24)+W23) 64 SHA256SU1 V7.S4, V6.S4, V4.S4 // V4: W32-W35 65 HASHUPDATE // H24 66 67 VADD V22.S4, V6.S4, V9.S4 // V18(W24+K24...W27+K27) 68 SHA256SU0 V7.S4, V6.S4 // V6: (su0(W25)+W24,...,su0(W28)+W27) 69 SHA256SU1 V4.S4, V7.S4, V5.S4 // V5: W36-W39 70 HASHUPDATE // H28 71 72 VADD V23.S4, V7.S4, V9.S4 // V18(W28+K28...W31+K31) 73 SHA256SU0 V4.S4, V7.S4 // V7: (su0(W29)+W28,...,su0(W32)+W31) 74 SHA256SU1 V5.S4, V4.S4, V6.S4 // V6: W40-W43 75 HASHUPDATE // H32 76 77 VADD V24.S4, V4.S4, V9.S4 // V18(W32+K32...W35+K35) 78 SHA256SU0 V5.S4, V4.S4 // V4: (su0(W33)+W32,...,su0(W36)+W35) 79 SHA256SU1 V6.S4, V5.S4, V7.S4 // V7: W44-W47 80 HASHUPDATE // H36 81 82 VADD V25.S4, V5.S4, V9.S4 // V18(W36+K36...W39+K39) 83 SHA256SU0 V6.S4, V5.S4 // V5: (su0(W37)+W36,...,su0(W40)+W39) 84 SHA256SU1 V7.S4, V6.S4, V4.S4 // V4: W48-W51 85 HASHUPDATE // H40 86 87 VADD V26.S4, V6.S4, V9.S4 // V18(W40+K40...W43+K43) 88 SHA256SU0 V7.S4, V6.S4 // V6: (su0(W41)+W40,...,su0(W44)+W43) 89 SHA256SU1 V4.S4, V7.S4, V5.S4 // V5: W52-W55 90 HASHUPDATE // H44 91 92 VADD V27.S4, V7.S4, V9.S4 // V18(W44+K44...W47+K47) 93 SHA256SU0 V4.S4, V7.S4 // V7: (su0(W45)+W44,...,su0(W48)+W47) 94 SHA256SU1 V5.S4, V4.S4, V6.S4 // V6: W56-W59 95 HASHUPDATE // H48 96 97 VADD V28.S4, V4.S4, V9.S4 // V18(W48+K48,...,W51+K51) 98 HASHUPDATE // H52 99 SHA256SU1 V6.S4, V5.S4, V7.S4 // V7: W60-W63 100 101 VADD V29.S4, V5.S4, V9.S4 // V18(W52+K52,...,W55+K55) 102 HASHUPDATE // H56 103 104 VADD V30.S4, V6.S4, V9.S4 // V18(W59+K59,...,W59+K59) 105 HASHUPDATE // H60 106 107 VADD V31.S4, V7.S4, V9.S4 // V18(W60+K60,...,W63+K63) 108 HASHUPDATE // H64 109 110 SUB $64, R3, R3 // message length - 64bytes, then compare with 64bytes 111 VADD V2.S4, V0.S4, V0.S4 112 VADD V3.S4, V1.S4, V1.S4 113 CBNZ R3, blockloop 114 115 sha256ret: 116 117 VST1 [V0.S4, V1.S4], (R0) // store hash value H 118 RET 119