| 1 | /* Copyright (c) (2013,2015,2016,2019) Apple Inc. All rights reserved. |
| 2 | * |
| 3 | * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which |
| 4 | * is contained in the License.txt file distributed with corecrypto) and only to |
| 5 | * people who accept that license. IMPORTANT: Any license rights granted to you by |
| 6 | * Apple Inc. (if any) are limited to internal use within your organization only on |
| 7 | * devices and computers you own or control, for the sole purpose of verifying the |
| 8 | * security characteristics and correct functioning of the Apple Software. You may |
| 9 | * not, directly or indirectly, redistribute the Apple Software or any portions thereof. |
| 10 | * |
| 11 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
| 12 | * |
| 13 | * This file contains Original Code and/or Modifications of Original Code |
| 14 | * as defined in and that are subject to the Apple Public Source License |
| 15 | * Version 2.0 (the 'License'). You may not use this file except in |
| 16 | * compliance with the License. The rights granted to you under the License |
| 17 | * may not be used to create, or enable the creation or redistribution of, |
| 18 | * unlawful or unlicensed copies of an Apple operating system, or to |
| 19 | * circumvent, violate, or enable the circumvention or violation of, any |
| 20 | * terms of an Apple operating system software license agreement. |
| 21 | * |
| 22 | * Please obtain a copy of the License at |
| 23 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
| 24 | * |
| 25 | * The Original Code and all software distributed under the License are |
| 26 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 27 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 28 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 29 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 30 | * Please see the License for the specific language governing rights and |
| 31 | * limitations under the License. |
| 32 | * |
| 33 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | // #include <Availability.h> |
| 38 | #include <sys/cdefs.h> |
| 39 | |
| 40 | #if defined(__clang__) && ((defined(__apple_build_version__) && __apple_build_version__ > 5010000)) |
| 41 | #define __USES_V_CRYPTO_INTRINSICS 1 |
| 42 | #else |
| 43 | #define __USES_V_CRYPTO_INTRINSICS 0 |
| 44 | #endif |
| 45 | |
| 46 | |
| 47 | // AES INSTRUCTIONS |
| 48 | // aese.16b v0, v1 |
| 49 | // aesd.16b v0, v1 |
| 50 | // aesmc.16b v0, v1 |
| 51 | // aesimc.16b v0, v1 |
| 52 | |
| 53 | // SHA1 INTRINSICS |
| 54 | // sha1su0.4s v0, v1, v2 |
| 55 | // sha1su1.4s v0, v1 |
| 56 | // sha1c.4s v0, v1, v2 // or q0, s1, v2.4s |
| 57 | // sha1m.4s v0, v1, v2 // or q0, s1, v2.4s |
| 58 | // sha1p.4s v0, v1, v2 // or q0, s1, v2.4s |
| 59 | // sha1h.4s v0, v1 // or s0, s1 |
| 60 | |
| 61 | // SHA256 INTRINSICS |
| 62 | // sha256su0.4s v0, v1 |
| 63 | // sha256su1.4s v0, v1, v2 |
| 64 | // sha256h.4s v0, v1, v2 // or q0, q1, v2.4s |
| 65 | // sha256h2.4s v0, v1, v2 // or q0, q1, v2.4s |
| 66 | |
| 67 | |
| 68 | #if __USES_V_CRYPTO_INTRINSICS == 1 |
| 69 | .macro AESE |
| 70 | aese.16b v$0, v$1 |
| 71 | .endm |
| 72 | |
| 73 | .macro AESD |
| 74 | aesd.16b v$0, v$1 |
| 75 | .endm |
| 76 | |
| 77 | .macro AESMC |
| 78 | aesmc.16b v$0, v$1 |
| 79 | .endm |
| 80 | |
| 81 | .macro AESIMC |
| 82 | aesimc.16b v$0, v$1 |
| 83 | .endm |
| 84 | |
| 85 | |
| 86 | #else |
| 87 | |
| 88 | .macro AESE |
| 89 | aese q$0, q$1 |
| 90 | .endm |
| 91 | |
| 92 | .macro AESD |
| 93 | aesd q$0, q$1 |
| 94 | .endm |
| 95 | |
| 96 | .macro AESMC |
| 97 | aesmc q$0, q$1 |
| 98 | .endm |
| 99 | |
| 100 | .macro AESIMC |
| 101 | aesimc q$0, q$1 |
| 102 | .endm |
| 103 | |
| 104 | #endif |
| 105 | |
| 106 | #if __USES_V_CRYPTO_INTRINSICS == 1 |
| 107 | |
| 108 | .macro SHA1SU0 |
| 109 | sha1su0 v$0.4s, v$1.4s, v$2.4s |
| 110 | .endm |
| 111 | |
| 112 | .macro SHA1SU1 |
| 113 | sha1su1 v$0.4s, v$1.4s |
| 114 | .endm |
| 115 | |
| 116 | .macro SHA1C |
| 117 | sha1c q$0, s$1, v$2.4s |
| 118 | .endm |
| 119 | |
| 120 | .macro SHA1M |
| 121 | sha1m q$0, s$1, v$2.4s |
| 122 | .endm |
| 123 | |
| 124 | .macro SHA1P |
| 125 | sha1p q$0, s$1, v$2.4s |
| 126 | .endm |
| 127 | |
| 128 | .macro SHA1H |
| 129 | sha1h s$0, s$1 |
| 130 | .endm |
| 131 | |
| 132 | .macro SHA256SU0 |
| 133 | sha256su0 v$0.4s, v$1.4s |
| 134 | .endm |
| 135 | |
| 136 | .macro SHA256SU1 |
| 137 | sha256su1 v$0.4s, v$1.4s, v$2.4s |
| 138 | .endm |
| 139 | |
| 140 | .macro SHA256H |
| 141 | sha256h q$0, q$1, v$2.4s |
| 142 | .endm |
| 143 | |
| 144 | .macro SHA256H2 |
| 145 | sha256h2 q$0, q$1, v$2.4s |
| 146 | .endm |
| 147 | |
| 148 | #else |
| 149 | |
| 150 | .macro SHA1SU0 |
| 151 | sha1su0 q$0, q$1, q$2 |
| 152 | .endm |
| 153 | |
| 154 | .macro SHA1SU1 |
| 155 | sha1su1 q$0, q$1 |
| 156 | .endm |
| 157 | |
| 158 | .macro SHA1C |
| 159 | sha1c q$0, q$1, q$2 |
| 160 | .endm |
| 161 | |
| 162 | .macro SHA1M |
| 163 | sha1m q$0, q$1, q$2 |
| 164 | .endm |
| 165 | |
| 166 | .macro SHA1P |
| 167 | sha1p q$0, q$1, q$2 |
| 168 | .endm |
| 169 | |
| 170 | .macro SHA1H |
| 171 | sha1h q$0, q$1 |
| 172 | .endm |
| 173 | |
| 174 | .macro SHA256SU0 |
| 175 | sha256su0 q$0, q$1 |
| 176 | .endm |
| 177 | |
| 178 | .macro SHA256SU1 |
| 179 | sha256su1 q$0, q$1, q$2 |
| 180 | .endm |
| 181 | |
| 182 | .macro SHA256H |
| 183 | sha256h q$0, q$1, q$2 |
| 184 | .endm |
| 185 | |
| 186 | .macro SHA256H2 |
| 187 | sha256h2 q$0, q$1, q$2 |
| 188 | .endm |
| 189 | |
| 190 | #endif |
| 191 | |