1/* SPDX-License-Identifier: BSD-2-Clause */ 2/* 3 * Copyright (c) 2014-2020, Linaro Limited 4 */ 5 6/* SHA-256 secure hash using ARMv8 Crypto Extensions */ 7 8#include <asm.S> 9 10 .fpu crypto-neon-fp-armv8 11 12 k0 .req q7 13 k1 .req q8 14 15 ta0 .req q9 16 ta1 .req q10 17 tb0 .req q10 18 tb1 .req q9 19 20 dga .req q11 21 dgb .req q12 22 23 dg0 .req q13 24 dg1 .req q14 25 dg2 .req q15 26 27 .macro add_only, ev, s0 28 vmov dg2, dg0 29 .ifnb \s0 30 vld1.32 {k\ev}, [r3]! 31 .endif 32 sha256h.32 dg0, dg1, tb\ev 33 sha256h2.32 dg1, dg2, tb\ev 34 .ifnb \s0 35 vadd.u32 ta\ev, q\s0, k\ev 36 .endif 37 .endm 38 39 .macro add_update, ev, s0, s1, s2, s3 40 sha256su0.32 q\s0, q\s1 41 add_only \ev, \s1 42 sha256su1.32 q\s0, q\s2, q\s3 43 .endm 44 45 46FUNC sha256_ce_transform , : 47 /* load state */ 48 vld1.8 {dga-dgb}, [r0] 49 50 /* load input */ 510: vld1.8 {q0-q1}, [r1]! 52 vrev32.8 q0, q0 53 vrev32.8 q1, q1 54 vld1.8 {q2-q3}, [r1]! 55 vrev32.8 q2, q2 56 vrev32.8 q3, q3 57 subs r2, r2, #1 58 59 /* load round constants */ 60 adr r3, .Lsha256_rcon 61 vld1.32 {k0}, [r3]! 62 63 vadd.u32 ta0, q0, k0 64 vmov dg0, dga 65 vmov dg1, dgb 66 67 add_update 1, 0, 1, 2, 3 68 add_update 0, 1, 2, 3, 0 69 add_update 1, 2, 3, 0, 1 70 add_update 0, 3, 0, 1, 2 71 add_update 1, 0, 1, 2, 3 72 add_update 0, 1, 2, 3, 0 73 add_update 1, 2, 3, 0, 1 74 add_update 0, 3, 0, 1, 2 75 add_update 1, 0, 1, 2, 3 76 add_update 0, 1, 2, 3, 0 77 add_update 1, 2, 3, 0, 1 78 add_update 0, 3, 0, 1, 2 79 80 add_only 1, 1 81 add_only 0, 2 82 add_only 1, 3 83 add_only 0 84 85 /* update state */ 86 vadd.u32 dga, dga, dg0 87 vadd.u32 dgb, dgb, dg1 88 bne 0b 89 90 /* store new state */ 91 vst1.8 {dga-dgb}, [r0] 92 bx lr 93 94 .align 6 95.Lsha256_rcon: 96 .word 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5 97 .word 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5 98 .word 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3 99 .word 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174 100 .word 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc 101 .word 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da 102 .word 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7 103 .word 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967 104 .word 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13 105 .word 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85 106 .word 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3 107 .word 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070 108 .word 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5 109 .word 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3 110 .word 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208 111 .word 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 112END_FUNC sha256_ce_transform 113