| 1 |
# Copyright 2021- IBM Inc. All rights reserved |
| 2 |
# |
| 3 |
# This file is part of Libgcrypt. |
| 4 |
# |
| 5 |
# Libgcrypt is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as |
| 7 |
# published by the Free Software Foundation; either version 2.1 of |
| 8 |
# the License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# Libgcrypt is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public |
| 16 |
# License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
#=================================================================================== |
| 19 |
# Written by Danny Tsen <[email protected]> |
| 20 |
# |
| 21 |
# GHASH is based on the Karatsuba multiplication method. |
| 22 |
# |
| 23 |
# Xi xor X1 |
| 24 |
# |
| 25 |
# X1 * H^4 + X2 * H^3 + x3 * H^2 + X4 * H = |
| 26 |
# (X1.h * H4.h + xX.l * H4.l + X1 * H4) + |
| 27 |
# (X2.h * H3.h + X2.l * H3.l + X2 * H3) + |
| 28 |
# (X3.h * H2.h + X3.l * H2.l + X3 * H2) + |
| 29 |
# (X4.h * H.h + X4.l * H.l + X4 * H) |
| 30 |
# |
| 31 |
# Xi = v0 |
| 32 |
# H Poly = v2 |
| 33 |
# Hash keys = v3 - v14 |
| 34 |
# ( H.l, H, H.h) |
| 35 |
# ( H^2.l, H^2, H^2.h) |
| 36 |
# ( H^3.l, H^3, H^3.h) |
| 37 |
# ( H^4.l, H^4, H^4.h) |
| 38 |
# |
| 39 |
# v30 is IV |
| 40 |
# v31 - counter 1 |
| 41 |
# |
| 42 |
# AES used, |
| 43 |
# vs0 - vs14 for round keys |
| 44 |
# v15, v16, v17, v18, v19, v20, v21, v22 for 8 blocks (encrypted) |
| 45 |
# |
| 46 |
# This implementation uses stitched AES-GCM approach to improve overall performance. |
| 47 |
# AES is implemented with 8x blocks and GHASH is using 2 4x blocks. |
| 48 |
# |
| 49 |
# Current performance with 128 bit key using bench-slope on Power10[le] (3.89GHz): |
| 50 |
# |
| 51 |
# AES | nanosecs/byte mebibytes/sec cycles/byte |
| 52 |
# GCM enc | 0.169 ns/B 5643 MiB/s - c/B |
| 53 |
# GCM dec | 0.171 ns/B 5585 MiB/s - c/B |
| 54 |
# |
| 55 |
# =================================================================================== |
| 56 |
# |
| 57 |
|
| 58 |
.machine "any" |
| 59 |
.abiversion 2 |
| 60 |
.text |
| 61 |
|
| 62 |
# 4x loops |
| 63 |
# v15 - v18 - input states |
| 64 |
# vs1 - vs9 - round keys |
| 65 |
# |
| 66 |
.macro Loop_aes_middle4x |
| 67 |
xxlor 19+32, 1, 1 |
| 68 |
xxlor 20+32, 2, 2 |
| 69 |
xxlor 21+32, 3, 3 |
| 70 |
xxlor 22+32, 4, 4 |
| 71 |
|
| 72 |
vcipher 15, 15, 19 |
| 73 |
vcipher 16, 16, 19 |
| 74 |
vcipher 17, 17, 19 |
| 75 |
vcipher 18, 18, 19 |
| 76 |
|
| 77 |
vcipher 15, 15, 20 |
| 78 |
vcipher 16, 16, 20 |
| 79 |
vcipher 17, 17, 20 |
| 80 |
vcipher 18, 18, 20 |
| 81 |
|
| 82 |
vcipher 15, 15, 21 |
| 83 |
vcipher 16, 16, 21 |
| 84 |
vcipher 17, 17, 21 |
| 85 |
vcipher 18, 18, 21 |
| 86 |
|
| 87 |
vcipher 15, 15, 22 |
| 88 |
vcipher 16, 16, 22 |
| 89 |
vcipher 17, 17, 22 |
| 90 |
vcipher 18, 18, 22 |
| 91 |
|
| 92 |
xxlor 19+32, 5, 5 |
| 93 |
xxlor 20+32, 6, 6 |
| 94 |
xxlor 21+32, 7, 7 |
| 95 |
xxlor 22+32, 8, 8 |
| 96 |
|
| 97 |
vcipher 15, 15, 19 |
| 98 |
vcipher 16, 16, 19 |
| 99 |
vcipher 17, 17, 19 |
| 100 |
vcipher 18, 18, 19 |
| 101 |
|
| 102 |
vcipher 15, 15, 20 |
| 103 |
vcipher 16, 16, 20 |
| 104 |
vcipher 17, 17, 20 |
| 105 |
vcipher 18, 18, 20 |
| 106 |
|
| 107 |
vcipher 15, 15, 21 |
| 108 |
vcipher 16, 16, 21 |
| 109 |
vcipher 17, 17, 21 |
| 110 |
vcipher 18, 18, 21 |
| 111 |
|
| 112 |
vcipher 15, 15, 22 |
| 113 |
vcipher 16, 16, 22 |
| 114 |
vcipher 17, 17, 22 |
| 115 |
vcipher 18, 18, 22 |
| 116 |
|
| 117 |
xxlor 23+32, 9, 9 |
| 118 |
vcipher 15, 15, 23 |
| 119 |
vcipher 16, 16, 23 |
| 120 |
vcipher 17, 17, 23 |
| 121 |
vcipher 18, 18, 23 |
| 122 |
.endm |
| 123 |
|
| 124 |
# 8x loops |
| 125 |
# v15 - v22 - input states |
| 126 |
# vs1 - vs9 - round keys |
| 127 |
# |
| 128 |
.macro Loop_aes_middle8x |
| 129 |
xxlor 23+32, 1, 1 |
| 130 |
xxlor 24+32, 2, 2 |
| 131 |
xxlor 25+32, 3, 3 |
| 132 |
xxlor 26+32, 4, 4 |
| 133 |
|
| 134 |
vcipher 15, 15, 23 |
| 135 |
vcipher 16, 16, 23 |
| 136 |
vcipher 17, 17, 23 |
| 137 |
vcipher 18, 18, 23 |
| 138 |
vcipher 19, 19, 23 |
| 139 |
vcipher 20, 20, 23 |
| 140 |
vcipher 21, 21, 23 |
| 141 |
vcipher 22, 22, 23 |
| 142 |
|
| 143 |
vcipher 15, 15, 24 |
| 144 |
vcipher 16, 16, 24 |
| 145 |
vcipher 17, 17, 24 |
| 146 |
vcipher 18, 18, 24 |
| 147 |
vcipher 19, 19, 24 |
| 148 |
vcipher 20, 20, 24 |
| 149 |
vcipher 21, 21, 24 |
| 150 |
vcipher 22, 22, 24 |
| 151 |
|
| 152 |
vcipher 15, 15, 25 |
| 153 |
vcipher 16, 16, 25 |
| 154 |
vcipher 17, 17, 25 |
| 155 |
vcipher 18, 18, 25 |
| 156 |
vcipher 19, 19, 25 |
| 157 |
vcipher 20, 20, 25 |
| 158 |
vcipher 21, 21, 25 |
| 159 |
vcipher 22, 22, 25 |
| 160 |
|
| 161 |
vcipher 15, 15, 26 |
| 162 |
vcipher 16, 16, 26 |
| 163 |
vcipher 17, 17, 26 |
| 164 |
vcipher 18, 18, 26 |
| 165 |
vcipher 19, 19, 26 |
| 166 |
vcipher 20, 20, 26 |
| 167 |
vcipher 21, 21, 26 |
| 168 |
vcipher 22, 22, 26 |
| 169 |
|
| 170 |
xxlor 23+32, 5, 5 |
| 171 |
xxlor 24+32, 6, 6 |
| 172 |
xxlor 25+32, 7, 7 |
| 173 |
xxlor 26+32, 8, 8 |
| 174 |
|
| 175 |
vcipher 15, 15, 23 |
| 176 |
vcipher 16, 16, 23 |
| 177 |
vcipher 17, 17, 23 |
| 178 |
vcipher 18, 18, 23 |
| 179 |
vcipher 19, 19, 23 |
| 180 |
vcipher 20, 20, 23 |
| 181 |
vcipher 21, 21, 23 |
| 182 |
vcipher 22, 22, 23 |
| 183 |
|
| 184 |
vcipher 15, 15, 24 |
| 185 |
vcipher 16, 16, 24 |
| 186 |
vcipher 17, 17, 24 |
| 187 |
vcipher 18, 18, 24 |
| 188 |
vcipher 19, 19, 24 |
| 189 |
vcipher 20, 20, 24 |
| 190 |
vcipher 21, 21, 24 |
| 191 |
vcipher 22, 22, 24 |
| 192 |
|
| 193 |
vcipher 15, 15, 25 |
| 194 |
vcipher 16, 16, 25 |
| 195 |
vcipher 17, 17, 25 |
| 196 |
vcipher 18, 18, 25 |
| 197 |
vcipher 19, 19, 25 |
| 198 |
vcipher 20, 20, 25 |
| 199 |
vcipher 21, 21, 25 |
| 200 |
vcipher 22, 22, 25 |
| 201 |
|
| 202 |
vcipher 15, 15, 26 |
| 203 |
vcipher 16, 16, 26 |
| 204 |
vcipher 17, 17, 26 |
| 205 |
vcipher 18, 18, 26 |
| 206 |
vcipher 19, 19, 26 |
| 207 |
vcipher 20, 20, 26 |
| 208 |
vcipher 21, 21, 26 |
| 209 |
vcipher 22, 22, 26 |
| 210 |
|
| 211 |
xxlor 23+32, 9, 9 |
| 212 |
vcipher 15, 15, 23 |
| 213 |
vcipher 16, 16, 23 |
| 214 |
vcipher 17, 17, 23 |
| 215 |
vcipher 18, 18, 23 |
| 216 |
vcipher 19, 19, 23 |
| 217 |
vcipher 20, 20, 23 |
| 218 |
vcipher 21, 21, 23 |
| 219 |
vcipher 22, 22, 23 |
| 220 |
.endm |
| 221 |
|
| 222 |
# |
| 223 |
# Compute 4x hash values based on Karatsuba method. |
| 224 |
# |
| 225 |
ppc_aes_gcm_ghash: |
| 226 |
vxor 15, 15, 0 |
| 227 |
|
| 228 |
xxlxor 29, 29, 29 |
| 229 |
|
| 230 |
vpmsumd 23, 12, 15 # H4.L * X.L |
| 231 |
vpmsumd 24, 9, 16 |
| 232 |
vpmsumd 25, 6, 17 |
| 233 |
vpmsumd 26, 3, 18 |
| 234 |
|
| 235 |
vxor 23, 23, 24 |
| 236 |
vxor 23, 23, 25 |
| 237 |
vxor 23, 23, 26 # L |
| 238 |
|
| 239 |
vpmsumd 24, 13, 15 # H4.L * X.H + H4.H * X.L |
| 240 |
vpmsumd 25, 10, 16 # H3.L * X1.H + H3.H * X1.L |
| 241 |
vpmsumd 26, 7, 17 |
| 242 |
vpmsumd 27, 4, 18 |
| 243 |
|
| 244 |
vxor 24, 24, 25 |
| 245 |
vxor 24, 24, 26 |
| 246 |
vxor 24, 24, 27 # M |
| 247 |
|
| 248 |
# sum hash and reduction with H Poly |
| 249 |
vpmsumd 28, 23, 2 # reduction |
| 250 |
|
| 251 |
xxlor 29+32, 29, 29 |
| 252 |
vsldoi 26, 24, 29, 8 # mL |
| 253 |
vsldoi 29, 29, 24, 8 # mH |
| 254 |
vxor 23, 23, 26 # mL + L |
| 255 |
|
| 256 |
vsldoi 23, 23, 23, 8 # swap |
| 257 |
vxor 23, 23, 28 |
| 258 |
|
| 259 |
vpmsumd 24, 14, 15 # H4.H * X.H |
| 260 |
vpmsumd 25, 11, 16 |
| 261 |
vpmsumd 26, 8, 17 |
| 262 |
vpmsumd 27, 5, 18 |
| 263 |
|
| 264 |
vxor 24, 24, 25 |
| 265 |
vxor 24, 24, 26 |
| 266 |
vxor 24, 24, 27 |
| 267 |
|
| 268 |
vxor 24, 24, 29 |
| 269 |
|
| 270 |
# sum hash and reduction with H Poly |
| 271 |
vsldoi 27, 23, 23, 8 # swap |
| 272 |
vpmsumd 23, 23, 2 |
| 273 |
vxor 27, 27, 24 |
| 274 |
vxor 23, 23, 27 |
| 275 |
|
| 276 |
xxlor 32, 23+32, 23+32 # update hash |
| 277 |
|
| 278 |
blr |
| 279 |
|
| 280 |
# |
| 281 |
# Combine two 4x ghash |
| 282 |
# v15 - v22 - input blocks |
| 283 |
# |
| 284 |
.macro ppc_aes_gcm_ghash2_4x |
| 285 |
# first 4x hash |
| 286 |
vxor 15, 15, 0 # Xi + X |
| 287 |
|
| 288 |
xxlxor 29, 29, 29 |
| 289 |
|
| 290 |
vpmsumd 23, 12, 15 # H4.L * X.L |
| 291 |
vpmsumd 24, 9, 16 |
| 292 |
vpmsumd 25, 6, 17 |
| 293 |
vpmsumd 26, 3, 18 |
| 294 |
|
| 295 |
vxor 23, 23, 24 |
| 296 |
vxor 23, 23, 25 |
| 297 |
vxor 23, 23, 26 # L |
| 298 |
|
| 299 |
vpmsumd 24, 13, 15 # H4.L * X.H + H4.H * X.L |
| 300 |
vpmsumd 25, 10, 16 # H3.L * X1.H + H3.H * X1.L |
| 301 |
vpmsumd 26, 7, 17 |
| 302 |
vpmsumd 27, 4, 18 |
| 303 |
|
| 304 |
vxor 24, 24, 25 |
| 305 |
vxor 24, 24, 26 |
| 306 |
|
| 307 |
# sum hash and reduction with H Poly |
| 308 |
vpmsumd 28, 23, 2 # reduction |
| 309 |
|
| 310 |
xxlor 29+32, 29, 29 |
| 311 |
|
| 312 |
vxor 24, 24, 27 # M |
| 313 |
vsldoi 26, 24, 29, 8 # mL |
| 314 |
vsldoi 29, 29, 24, 8 # mH |
| 315 |
vxor 23, 23, 26 # mL + L |
| 316 |
|
| 317 |
vsldoi 23, 23, 23, 8 # swap |
| 318 |
vxor 23, 23, 28 |
| 319 |
|
| 320 |
vpmsumd 24, 14, 15 # H4.H * X.H |
| 321 |
vpmsumd 25, 11, 16 |
| 322 |
vpmsumd 26, 8, 17 |
| 323 |
vpmsumd 27, 5, 18 |
| 324 |
|
| 325 |
vxor 24, 24, 25 |
| 326 |
vxor 24, 24, 26 |
| 327 |
vxor 24, 24, 27 # H |
| 328 |
|
| 329 |
vxor 24, 24, 29 # H + mH |
| 330 |
|
| 331 |
# sum hash and reduction with H Poly |
| 332 |
vsldoi 27, 23, 23, 8 # swap |
| 333 |
vpmsumd 23, 23, 2 |
| 334 |
vxor 27, 27, 24 |
| 335 |
vxor 27, 23, 27 # 1st Xi |
| 336 |
|
| 337 |
# 2nd 4x hash |
| 338 |
vpmsumd 24, 9, 20 |
| 339 |
vpmsumd 25, 6, 21 |
| 340 |
vpmsumd 26, 3, 22 |
| 341 |
vxor 19, 19, 27 # Xi + X |
| 342 |
vpmsumd 23, 12, 19 # H4.L * X.L |
| 343 |
|
| 344 |
vxor 23, 23, 24 |
| 345 |
vxor 23, 23, 25 |
| 346 |
vxor 23, 23, 26 # L |
| 347 |
|
| 348 |
vpmsumd 24, 13, 19 # H4.L * X.H + H4.H * X.L |
| 349 |
vpmsumd 25, 10, 20 # H3.L * X1.H + H3.H * X1.L |
| 350 |
vpmsumd 26, 7, 21 |
| 351 |
vpmsumd 27, 4, 22 |
| 352 |
|
| 353 |
vxor 24, 24, 25 |
| 354 |
vxor 24, 24, 26 |
| 355 |
|
| 356 |
# sum hash and reduction with H Poly |
| 357 |
vpmsumd 28, 23, 2 # reduction |
| 358 |
|
| 359 |
xxlor 29+32, 29, 29 |
| 360 |
|
| 361 |
vxor 24, 24, 27 # M |
| 362 |
vsldoi 26, 24, 29, 8 # mL |
| 363 |
vsldoi 29, 29, 24, 8 # mH |
| 364 |
vxor 23, 23, 26 # mL + L |
| 365 |
|
| 366 |
vsldoi 23, 23, 23, 8 # swap |
| 367 |
vxor 23, 23, 28 |
| 368 |
|
| 369 |
vpmsumd 24, 14, 19 # H4.H * X.H |
| 370 |
vpmsumd 25, 11, 20 |
| 371 |
vpmsumd 26, 8, 21 |
| 372 |
vpmsumd 27, 5, 22 |
| 373 |
|
| 374 |
vxor 24, 24, 25 |
| 375 |
vxor 24, 24, 26 |
| 376 |
vxor 24, 24, 27 # H |
| 377 |
|
| 378 |
vxor 24, 24, 29 # H + mH |
| 379 |
|
| 380 |
# sum hash and reduction with H Poly |
| 381 |
vsldoi 27, 23, 23, 8 # swap |
| 382 |
vpmsumd 23, 23, 2 |
| 383 |
vxor 27, 27, 24 |
| 384 |
vxor 23, 23, 27 |
| 385 |
|
| 386 |
xxlor 32, 23+32, 23+32 # update hash |
| 387 |
|
| 388 |
.endm |
| 389 |
|
| 390 |
# |
| 391 |
# Compute update single hash |
| 392 |
# |
| 393 |
.macro ppc_update_hash_1x |
| 394 |
vxor 28, 28, 0 |
| 395 |
|
| 396 |
vxor 19, 19, 19 |
| 397 |
|
| 398 |
vpmsumd 22, 3, 28 # L |
| 399 |
vpmsumd 23, 4, 28 # M |
| 400 |
vpmsumd 24, 5, 28 # H |
| 401 |
|
| 402 |
vpmsumd 27, 22, 2 # reduction |
| 403 |
|
| 404 |
vsldoi 25, 23, 19, 8 # mL |
| 405 |
vsldoi 26, 19, 23, 8 # mH |
| 406 |
vxor 22, 22, 25 # LL + LL |
| 407 |
vxor 24, 24, 26 # HH + HH |
| 408 |
|
| 409 |
vsldoi 22, 22, 22, 8 # swap |
| 410 |
vxor 22, 22, 27 |
| 411 |
|
| 412 |
vsldoi 20, 22, 22, 8 # swap |
| 413 |
vpmsumd 22, 22, 2 # reduction |
| 414 |
vxor 20, 20, 24 |
| 415 |
vxor 22, 22, 20 |
| 416 |
|
| 417 |
vmr 0, 22 # update hash |
| 418 |
|
| 419 |
.endm |
| 420 |
|
| 421 |
# |
| 422 |
# libgcrypt: |
| 423 |
# _gcry_ppc10_aes_gcm_encrypt (const void *inp, void *out, size_t len, |
| 424 |
# const char *rk, unsigned char iv[16], void *Xip); |
| 425 |
# |
| 426 |
# r3 - inp |
| 427 |
# r4 - out |
| 428 |
# r5 - len |
| 429 |
# r6 - AES round keys |
| 430 |
# r7 - iv |
| 431 |
# r8 - HPoli, hash keys, Xi |
| 432 |
# |
| 433 |
# rounds is at offset 480 in rk |
| 434 |
# Xi is at 256 in gcm_table (Xip). |
| 435 |
# |
| 436 |
.global _gcry_ppc10_aes_gcm_encrypt |
| 437 |
.align 5 |
| 438 |
_gcry_ppc10_aes_gcm_encrypt: |
| 439 |
_gcry_ppc_aes_gcm_encrypt: |
| 440 |
|
| 441 |
stdu 1,-512(1) |
| 442 |
mflr 0 |
| 443 |
|
| 444 |
std 14,112(1) |
| 445 |
std 15,120(1) |
| 446 |
std 16,128(1) |
| 447 |
std 17,136(1) |
| 448 |
std 18,144(1) |
| 449 |
std 19,152(1) |
| 450 |
std 20,160(1) |
| 451 |
std 21,168(1) |
| 452 |
li 9, 256 |
| 453 |
stvx 20, 9, 1 |
| 454 |
addi 9, 9, 16 |
| 455 |
stvx 21, 9, 1 |
| 456 |
addi 9, 9, 16 |
| 457 |
stvx 22, 9, 1 |
| 458 |
addi 9, 9, 16 |
| 459 |
stvx 23, 9, 1 |
| 460 |
addi 9, 9, 16 |
| 461 |
stvx 24, 9, 1 |
| 462 |
addi 9, 9, 16 |
| 463 |
stvx 25, 9, 1 |
| 464 |
addi 9, 9, 16 |
| 465 |
stvx 26, 9, 1 |
| 466 |
addi 9, 9, 16 |
| 467 |
stvx 27, 9, 1 |
| 468 |
addi 9, 9, 16 |
| 469 |
stvx 28, 9, 1 |
| 470 |
addi 9, 9, 16 |
| 471 |
stvx 29, 9, 1 |
| 472 |
addi 9, 9, 16 |
| 473 |
stvx 30, 9, 1 |
| 474 |
addi 9, 9, 16 |
| 475 |
stvx 31, 9, 1 |
| 476 |
std 0, 528(1) |
| 477 |
|
| 478 |
# Load Xi |
| 479 |
li 10, 256 |
| 480 |
lxvb16x 32, 10, 8 # load Xi |
| 481 |
|
| 482 |
# load Hash - h^4, h^3, h^2, h |
| 483 |
lxvd2x 2+32, 0, 8 # H Poli |
| 484 |
li 10, 16 |
| 485 |
lxvd2x 3+32, 10, 8 # Hl |
| 486 |
li 10, 32 |
| 487 |
lxvd2x 4+32, 10, 8 # H |
| 488 |
li 10, 48 |
| 489 |
lxvd2x 5+32, 10, 8 # Hh |
| 490 |
|
| 491 |
li 10, 64 |
| 492 |
lxvd2x 6+32, 10, 8 # H^2l |
| 493 |
li 10, 80 |
| 494 |
lxvd2x 7+32, 10, 8 # H^2 |
| 495 |
li 10, 96 |
| 496 |
lxvd2x 8+32, 10, 8 # H^2h |
| 497 |
|
| 498 |
li 10, 112 |
| 499 |
lxvd2x 9+32, 10, 8 # H^3l |
| 500 |
li 10, 128 |
| 501 |
lxvd2x 10+32, 10, 8 # H^3 |
| 502 |
li 10, 144 |
| 503 |
lxvd2x 11+32, 10, 8 # H^3h |
| 504 |
|
| 505 |
li 10, 160 |
| 506 |
lxvd2x 12+32, 10, 8 # H^4l |
| 507 |
li 10, 176 |
| 508 |
lxvd2x 13+32, 10, 8 # H^4 |
| 509 |
li 10, 192 |
| 510 |
lxvd2x 14+32, 10, 8 # H^4h |
| 511 |
|
| 512 |
# initialize ICB: GHASH( IV ), IV - r7 |
| 513 |
lxvb16x 30+32, 0, 7 # load IV - v30 |
| 514 |
|
| 515 |
mr 12, 5 # length |
| 516 |
li 11, 0 # block index |
| 517 |
|
| 518 |
# counter 1 |
| 519 |
vxor 31, 31, 31 |
| 520 |
vspltisb 22, 1 |
| 521 |
vsldoi 31, 31, 22,1 # counter 1 |
| 522 |
|
| 523 |
# load round key to VSR |
| 524 |
lxv 0, 0(6) |
| 525 |
lxv 1, 0x10(6) |
| 526 |
lxv 2, 0x20(6) |
| 527 |
lxv 3, 0x30(6) |
| 528 |
lxv 4, 0x40(6) |
| 529 |
lxv 5, 0x50(6) |
| 530 |
lxv 6, 0x60(6) |
| 531 |
lxv 7, 0x70(6) |
| 532 |
lxv 8, 0x80(6) |
| 533 |
lxv 9, 0x90(6) |
| 534 |
lxv 10, 0xa0(6) |
| 535 |
|
| 536 |
# load rounds - 10 (128), 12 (192), 14 (256) |
| 537 |
lwz 9,480(6) |
| 538 |
|
| 539 |
# |
| 540 |
# vxor state, state, w # addroundkey |
| 541 |
xxlor 32+29, 0, 0 |
| 542 |
vxor 15, 30, 29 # IV + round key - add round key 0 |
| 543 |
|
| 544 |
cmpdi 9, 10 |
| 545 |
beq Loop_aes_gcm_8x |
| 546 |
|
| 547 |
# load 2 more round keys (v11, v12) |
| 548 |
lxv 11, 0xb0(6) |
| 549 |
lxv 12, 0xc0(6) |
| 550 |
|
| 551 |
cmpdi 9, 12 |
| 552 |
beq Loop_aes_gcm_8x |
| 553 |
|
| 554 |
# load 2 more round keys (v11, v12, v13, v14) |
| 555 |
lxv 13, 0xd0(6) |
| 556 |
lxv 14, 0xe0(6) |
| 557 |
cmpdi 9, 14 |
| 558 |
beq Loop_aes_gcm_8x |
| 559 |
|
| 560 |
b aes_gcm_out |
| 561 |
|
| 562 |
.align 5 |
| 563 |
Loop_aes_gcm_8x: |
| 564 |
mr 14, 3 |
| 565 |
mr 9, 4 |
| 566 |
|
| 567 |
# n blcoks |
| 568 |
li 10, 128 |
| 569 |
divdu 10, 5, 10 # n 128 bytes-blocks |
| 570 |
cmpdi 10, 0 |
| 571 |
beq Loop_last_block |
| 572 |
|
| 573 |
vaddudm 30, 30, 31 # IV + counter |
| 574 |
vxor 16, 30, 29 |
| 575 |
vaddudm 30, 30, 31 |
| 576 |
vxor 17, 30, 29 |
| 577 |
vaddudm 30, 30, 31 |
| 578 |
vxor 18, 30, 29 |
| 579 |
vaddudm 30, 30, 31 |
| 580 |
vxor 19, 30, 29 |
| 581 |
vaddudm 30, 30, 31 |
| 582 |
vxor 20, 30, 29 |
| 583 |
vaddudm 30, 30, 31 |
| 584 |
vxor 21, 30, 29 |
| 585 |
vaddudm 30, 30, 31 |
| 586 |
vxor 22, 30, 29 |
| 587 |
|
| 588 |
mtctr 10 |
| 589 |
|
| 590 |
li 15, 16 |
| 591 |
li 16, 32 |
| 592 |
li 17, 48 |
| 593 |
li 18, 64 |
| 594 |
li 19, 80 |
| 595 |
li 20, 96 |
| 596 |
li 21, 112 |
| 597 |
|
| 598 |
lwz 10, 480(6) |
| 599 |
|
| 600 |
Loop_8x_block: |
| 601 |
|
| 602 |
lxvb16x 15, 0, 14 # load block |
| 603 |
lxvb16x 16, 15, 14 # load block |
| 604 |
lxvb16x 17, 16, 14 # load block |
| 605 |
lxvb16x 18, 17, 14 # load block |
| 606 |
lxvb16x 19, 18, 14 # load block |
| 607 |
lxvb16x 20, 19, 14 # load block |
| 608 |
lxvb16x 21, 20, 14 # load block |
| 609 |
lxvb16x 22, 21, 14 # load block |
| 610 |
addi 14, 14, 128 |
| 611 |
|
| 612 |
Loop_aes_middle8x |
| 613 |
|
| 614 |
xxlor 23+32, 10, 10 |
| 615 |
|
| 616 |
cmpdi 10, 10 |
| 617 |
beq Do_next_ghash |
| 618 |
|
| 619 |
# 192 bits |
| 620 |
xxlor 24+32, 11, 11 |
| 621 |
|
| 622 |
vcipher 15, 15, 23 |
| 623 |
vcipher 16, 16, 23 |
| 624 |
vcipher 17, 17, 23 |
| 625 |
vcipher 18, 18, 23 |
| 626 |
vcipher 19, 19, 23 |
| 627 |
vcipher 20, 20, 23 |
| 628 |
vcipher 21, 21, 23 |
| 629 |
vcipher 22, 22, 23 |
| 630 |
|
| 631 |
vcipher 15, 15, 24 |
| 632 |
vcipher 16, 16, 24 |
| 633 |
vcipher 17, 17, 24 |
| 634 |
vcipher 18, 18, 24 |
| 635 |
vcipher 19, 19, 24 |
| 636 |
vcipher 20, 20, 24 |
| 637 |
vcipher 21, 21, 24 |
| 638 |
vcipher 22, 22, 24 |
| 639 |
|
| 640 |
xxlor 23+32, 12, 12 |
| 641 |
|
| 642 |
cmpdi 10, 12 |
| 643 |
beq Do_next_ghash |
| 644 |
|
| 645 |
# 256 bits |
| 646 |
xxlor 24+32, 13, 13 |
| 647 |
|
| 648 |
vcipher 15, 15, 23 |
| 649 |
vcipher 16, 16, 23 |
| 650 |
vcipher 17, 17, 23 |
| 651 |
vcipher 18, 18, 23 |
| 652 |
vcipher 19, 19, 23 |
| 653 |
vcipher 20, 20, 23 |
| 654 |
vcipher 21, 21, 23 |
| 655 |
vcipher 22, 22, 23 |
| 656 |
|
| 657 |
vcipher 15, 15, 24 |
| 658 |
vcipher 16, 16, 24 |
| 659 |
vcipher 17, 17, 24 |
| 660 |
vcipher 18, 18, 24 |
| 661 |
vcipher 19, 19, 24 |
| 662 |
vcipher 20, 20, 24 |
| 663 |
vcipher 21, 21, 24 |
| 664 |
vcipher 22, 22, 24 |
| 665 |
|
| 666 |
xxlor 23+32, 14, 14 |
| 667 |
|
| 668 |
cmpdi 10, 14 |
| 669 |
beq Do_next_ghash |
| 670 |
b aes_gcm_out |
| 671 |
|
| 672 |
Do_next_ghash: |
| 673 |
|
| 674 |
# |
| 675 |
# last round |
| 676 |
vcipherlast 15, 15, 23 |
| 677 |
vcipherlast 16, 16, 23 |
| 678 |
|
| 679 |
xxlxor 47, 47, 15 |
| 680 |
stxvb16x 47, 0, 9 # store output |
| 681 |
xxlxor 48, 48, 16 |
| 682 |
stxvb16x 48, 15, 9 # store output |
| 683 |
|
| 684 |
vcipherlast 17, 17, 23 |
| 685 |
vcipherlast 18, 18, 23 |
| 686 |
|
| 687 |
xxlxor 49, 49, 17 |
| 688 |
stxvb16x 49, 16, 9 # store output |
| 689 |
xxlxor 50, 50, 18 |
| 690 |
stxvb16x 50, 17, 9 # store output |
| 691 |
|
| 692 |
vcipherlast 19, 19, 23 |
| 693 |
vcipherlast 20, 20, 23 |
| 694 |
|
| 695 |
xxlxor 51, 51, 19 |
| 696 |
stxvb16x 51, 18, 9 # store output |
| 697 |
xxlxor 52, 52, 20 |
| 698 |
stxvb16x 52, 19, 9 # store output |
| 699 |
|
| 700 |
vcipherlast 21, 21, 23 |
| 701 |
vcipherlast 22, 22, 23 |
| 702 |
|
| 703 |
xxlxor 53, 53, 21 |
| 704 |
stxvb16x 53, 20, 9 # store output |
| 705 |
xxlxor 54, 54, 22 |
| 706 |
stxvb16x 54, 21, 9 # store output |
| 707 |
|
| 708 |
addi 9, 9, 128 |
| 709 |
|
| 710 |
# ghash here |
| 711 |
ppc_aes_gcm_ghash2_4x |
| 712 |
|
| 713 |
xxlor 27+32, 0, 0 |
| 714 |
vaddudm 30, 30, 31 # IV + counter |
| 715 |
vmr 29, 30 |
| 716 |
vxor 15, 30, 27 # add round key |
| 717 |
vaddudm 30, 30, 31 |
| 718 |
vxor 16, 30, 27 |
| 719 |
vaddudm 30, 30, 31 |
| 720 |
vxor 17, 30, 27 |
| 721 |
vaddudm 30, 30, 31 |
| 722 |
vxor 18, 30, 27 |
| 723 |
vaddudm 30, 30, 31 |
| 724 |
vxor 19, 30, 27 |
| 725 |
vaddudm 30, 30, 31 |
| 726 |
vxor 20, 30, 27 |
| 727 |
vaddudm 30, 30, 31 |
| 728 |
vxor 21, 30, 27 |
| 729 |
vaddudm 30, 30, 31 |
| 730 |
vxor 22, 30, 27 |
| 731 |
|
| 732 |
addi 12, 12, -128 |
| 733 |
addi 11, 11, 128 |
| 734 |
|
| 735 |
bdnz Loop_8x_block |
| 736 |
|
| 737 |
vmr 30, 29 |
| 738 |
|
| 739 |
Loop_last_block: |
| 740 |
cmpdi 12, 0 |
| 741 |
beq aes_gcm_out |
| 742 |
|
| 743 |
# loop last few blocks |
| 744 |
li 10, 16 |
| 745 |
divdu 10, 12, 10 |
| 746 |
|
| 747 |
mtctr 10 |
| 748 |
|
| 749 |
lwz 10, 480(6) |
| 750 |
|
| 751 |
cmpdi 12, 16 |
| 752 |
blt Final_block |
| 753 |
|
| 754 |
.macro Loop_aes_middle_1x |
| 755 |
xxlor 19+32, 1, 1 |
| 756 |
xxlor 20+32, 2, 2 |
| 757 |
xxlor 21+32, 3, 3 |
| 758 |
xxlor 22+32, 4, 4 |
| 759 |
|
| 760 |
vcipher 15, 15, 19 |
| 761 |
vcipher 15, 15, 20 |
| 762 |
vcipher 15, 15, 21 |
| 763 |
vcipher 15, 15, 22 |
| 764 |
|
| 765 |
xxlor 19+32, 5, 5 |
| 766 |
xxlor 20+32, 6, 6 |
| 767 |
xxlor 21+32, 7, 7 |
| 768 |
xxlor 22+32, 8, 8 |
| 769 |
|
| 770 |
vcipher 15, 15, 19 |
| 771 |
vcipher 15, 15, 20 |
| 772 |
vcipher 15, 15, 21 |
| 773 |
vcipher 15, 15, 22 |
| 774 |
|
| 775 |
xxlor 19+32, 9, 9 |
| 776 |
vcipher 15, 15, 19 |
| 777 |
.endm |
| 778 |
|
| 779 |
Next_rem_block: |
| 780 |
lxvb16x 15, 0, 14 # load block |
| 781 |
|
| 782 |
Loop_aes_middle_1x |
| 783 |
|
| 784 |
xxlor 23+32, 10, 10 |
| 785 |
|
| 786 |
cmpdi 10, 10 |
| 787 |
beq Do_next_1x |
| 788 |
|
| 789 |
# 192 bits |
| 790 |
xxlor 24+32, 11, 11 |
| 791 |
|
| 792 |
vcipher 15, 15, 23 |
| 793 |
vcipher 15, 15, 24 |
| 794 |
|
| 795 |
xxlor 23+32, 12, 12 |
| 796 |
|
| 797 |
cmpdi 10, 12 |
| 798 |
beq Do_next_1x |
| 799 |
|
| 800 |
# 256 bits |
| 801 |
xxlor 24+32, 13, 13 |
| 802 |
|
| 803 |
vcipher 15, 15, 23 |
| 804 |
vcipher 15, 15, 24 |
| 805 |
|
| 806 |
xxlor 23+32, 14, 14 |
| 807 |
|
| 808 |
cmpdi 10, 14 |
| 809 |
beq Do_next_1x |
| 810 |
|
| 811 |
Do_next_1x: |
| 812 |
vcipherlast 15, 15, 23 |
| 813 |
|
| 814 |
xxlxor 47, 47, 15 |
| 815 |
stxvb16x 47, 0, 9 # store output |
| 816 |
addi 14, 14, 16 |
| 817 |
addi 9, 9, 16 |
| 818 |
|
| 819 |
vmr 28, 15 |
| 820 |
ppc_update_hash_1x |
| 821 |
|
| 822 |
addi 12, 12, -16 |
| 823 |
addi 11, 11, 16 |
| 824 |
xxlor 19+32, 0, 0 |
| 825 |
vaddudm 30, 30, 31 # IV + counter |
| 826 |
vxor 15, 30, 19 # add round key |
| 827 |
|
| 828 |
bdnz Next_rem_block |
| 829 |
|
| 830 |
cmpdi 12, 0 |
| 831 |
beq aes_gcm_out |
| 832 |
|
| 833 |
Final_block: |
| 834 |
Loop_aes_middle_1x |
| 835 |
|
| 836 |
xxlor 23+32, 10, 10 |
| 837 |
|
| 838 |
cmpdi 10, 10 |
| 839 |
beq Do_final_1x |
| 840 |
|
| 841 |
# 192 bits |
| 842 |
xxlor 24+32, 11, 11 |
| 843 |
|
| 844 |
vcipher 15, 15, 23 |
| 845 |
vcipher 15, 15, 24 |
| 846 |
|
| 847 |
xxlor 23+32, 12, 12 |
| 848 |
|
| 849 |
cmpdi 10, 12 |
| 850 |
beq Do_final_1x |
| 851 |
|
| 852 |
# 256 bits |
| 853 |
xxlor 24+32, 13, 13 |
| 854 |
|
| 855 |
vcipher 15, 15, 23 |
| 856 |
vcipher 15, 15, 24 |
| 857 |
|
| 858 |
xxlor 23+32, 14, 14 |
| 859 |
|
| 860 |
cmpdi 10, 14 |
| 861 |
beq Do_final_1x |
| 862 |
|
| 863 |
Do_final_1x: |
| 864 |
vcipherlast 15, 15, 23 |
| 865 |
|
| 866 |
lxvb16x 15, 0, 14 # load last block |
| 867 |
xxlxor 47, 47, 15 |
| 868 |
|
| 869 |
# create partial block mask |
| 870 |
li 15, 16 |
| 871 |
sub 15, 15, 12 # index to the mask |
| 872 |
|
| 873 |
vspltisb 16, -1 # first 16 bytes - 0xffff...ff |
| 874 |
vspltisb 17, 0 # second 16 bytes - 0x0000...00 |
| 875 |
li 10, 192 |
| 876 |
stvx 16, 10, 1 |
| 877 |
addi 10, 10, 16 |
| 878 |
stvx 17, 10, 1 |
| 879 |
|
| 880 |
addi 10, 1, 192 |
| 881 |
lxvb16x 16, 15, 10 # load partial block mask |
| 882 |
xxland 47, 47, 16 |
| 883 |
|
| 884 |
vmr 28, 15 |
| 885 |
ppc_update_hash_1x |
| 886 |
|
| 887 |
# * should store only the remaining bytes. |
| 888 |
bl Write_partial_block |
| 889 |
|
| 890 |
b aes_gcm_out |
| 891 |
|
| 892 |
# |
| 893 |
# Write partial block |
| 894 |
# r9 - output |
| 895 |
# r12 - remaining bytes |
| 896 |
# v15 - partial input data |
| 897 |
# |
| 898 |
Write_partial_block: |
| 899 |
li 10, 192 |
| 900 |
stxvb16x 15+32, 10, 1 # last block |
| 901 |
|
| 902 |
#add 10, 9, 11 # Output |
| 903 |
addi 10, 9, -1 |
| 904 |
addi 16, 1, 191 |
| 905 |
|
| 906 |
mtctr 12 # remaining bytes |
| 907 |
li 15, 0 |
| 908 |
|
| 909 |
Write_last_byte: |
| 910 |
lbzu 14, 1(16) |
| 911 |
stbu 14, 1(10) |
| 912 |
bdnz Write_last_byte |
| 913 |
blr |
| 914 |
|
| 915 |
aes_gcm_out: |
| 916 |
# out = state |
| 917 |
li 10, 256 |
| 918 |
stxvb16x 32, 10, 8 # write out Xi |
| 919 |
add 3, 11, 12 # return count |
| 920 |
|
| 921 |
li 9, 256 |
| 922 |
lvx 20, 9, 1 |
| 923 |
addi 9, 9, 16 |
| 924 |
lvx 21, 9, 1 |
| 925 |
addi 9, 9, 16 |
| 926 |
lvx 22, 9, 1 |
| 927 |
addi 9, 9, 16 |
| 928 |
lvx 23, 9, 1 |
| 929 |
addi 9, 9, 16 |
| 930 |
lvx 24, 9, 1 |
| 931 |
addi 9, 9, 16 |
| 932 |
lvx 25, 9, 1 |
| 933 |
addi 9, 9, 16 |
| 934 |
lvx 26, 9, 1 |
| 935 |
addi 9, 9, 16 |
| 936 |
lvx 27, 9, 1 |
| 937 |
addi 9, 9, 16 |
| 938 |
lvx 28, 9, 1 |
| 939 |
addi 9, 9, 16 |
| 940 |
lvx 29, 9, 1 |
| 941 |
addi 9, 9, 16 |
| 942 |
lvx 30, 9, 1 |
| 943 |
addi 9, 9, 16 |
| 944 |
lvx 31, 9, 1 |
| 945 |
|
| 946 |
ld 0, 528(1) |
| 947 |
ld 14,112(1) |
| 948 |
ld 15,120(1) |
| 949 |
ld 16,128(1) |
| 950 |
ld 17,136(1) |
| 951 |
ld 18,144(1) |
| 952 |
ld 19,152(1) |
| 953 |
ld 20,160(1) |
| 954 |
ld 21,168(1) |
| 955 |
|
| 956 |
mtlr 0 |
| 957 |
addi 1, 1, 512 |
| 958 |
blr |
| 959 |
|
| 960 |
# |
| 961 |
# 8x Decrypt |
| 962 |
# |
| 963 |
.global _gcry_ppc10_aes_gcm_decrypt |
| 964 |
.align 5 |
| 965 |
_gcry_ppc10_aes_gcm_decrypt: |
| 966 |
_gcry_ppc_aes_gcm_decrypt: |
| 967 |
|
| 968 |
stdu 1,-512(1) |
| 969 |
mflr 0 |
| 970 |
|
| 971 |
std 14,112(1) |
| 972 |
std 15,120(1) |
| 973 |
std 16,128(1) |
| 974 |
std 17,136(1) |
| 975 |
std 18,144(1) |
| 976 |
std 19,152(1) |
| 977 |
std 20,160(1) |
| 978 |
std 21,168(1) |
| 979 |
li 9, 256 |
| 980 |
stvx 20, 9, 1 |
| 981 |
addi 9, 9, 16 |
| 982 |
stvx 21, 9, 1 |
| 983 |
addi 9, 9, 16 |
| 984 |
stvx 22, 9, 1 |
| 985 |
addi 9, 9, 16 |
| 986 |
stvx 23, 9, 1 |
| 987 |
addi 9, 9, 16 |
| 988 |
stvx 24, 9, 1 |
| 989 |
addi 9, 9, 16 |
| 990 |
stvx 25, 9, 1 |
| 991 |
addi 9, 9, 16 |
| 992 |
stvx 26, 9, 1 |
| 993 |
addi 9, 9, 16 |
| 994 |
stvx 27, 9, 1 |
| 995 |
addi 9, 9, 16 |
| 996 |
stvx 28, 9, 1 |
| 997 |
addi 9, 9, 16 |
| 998 |
stvx 29, 9, 1 |
| 999 |
addi 9, 9, 16 |
| 1000 |
stvx 30, 9, 1 |
| 1001 |
addi 9, 9, 16 |
| 1002 |
stvx 31, 9, 1 |
| 1003 |
std 0, 528(1) |
| 1004 |
|
| 1005 |
# Load Xi |
| 1006 |
li 10, 256 |
| 1007 |
lxvb16x 32, 10, 8 # load Xi |
| 1008 |
|
| 1009 |
# load Hash - h^4, h^3, h^2, h |
| 1010 |
lxvd2x 2+32, 0, 8 # H Poli |
| 1011 |
li 10, 16 |
| 1012 |
lxvd2x 3+32, 10, 8 # Hl |
| 1013 |
li 10, 32 |
| 1014 |
lxvd2x 4+32, 10, 8 # H |
| 1015 |
li 10, 48 |
| 1016 |
lxvd2x 5+32, 10, 8 # Hh |
| 1017 |
|
| 1018 |
li 10, 64 |
| 1019 |
lxvd2x 6+32, 10, 8 # H^2l |
| 1020 |
li 10, 80 |
| 1021 |
lxvd2x 7+32, 10, 8 # H^2 |
| 1022 |
li 10, 96 |
| 1023 |
lxvd2x 8+32, 10, 8 # H^2h |
| 1024 |
|
| 1025 |
li 10, 112 |
| 1026 |
lxvd2x 9+32, 10, 8 # H^3l |
| 1027 |
li 10, 128 |
| 1028 |
lxvd2x 10+32, 10, 8 # H^3 |
| 1029 |
li 10, 144 |
| 1030 |
lxvd2x 11+32, 10, 8 # H^3h |
| 1031 |
|
| 1032 |
li 10, 160 |
| 1033 |
lxvd2x 12+32, 10, 8 # H^4l |
| 1034 |
li 10, 176 |
| 1035 |
lxvd2x 13+32, 10, 8 # H^4 |
| 1036 |
li 10, 192 |
| 1037 |
lxvd2x 14+32, 10, 8 # H^4h |
| 1038 |
|
| 1039 |
# initialize ICB: GHASH( IV ), IV - r7 |
| 1040 |
lxvb16x 30+32, 0, 7 # load IV - v30 |
| 1041 |
|
| 1042 |
mr 12, 5 # length |
| 1043 |
li 11, 0 # block index |
| 1044 |
|
| 1045 |
# counter 1 |
| 1046 |
vxor 31, 31, 31 |
| 1047 |
vspltisb 22, 1 |
| 1048 |
vsldoi 31, 31, 22,1 # counter 1 |
| 1049 |
|
| 1050 |
# load round key to VSR |
| 1051 |
lxv 0, 0(6) |
| 1052 |
lxv 1, 0x10(6) |
| 1053 |
lxv 2, 0x20(6) |
| 1054 |
lxv 3, 0x30(6) |
| 1055 |
lxv 4, 0x40(6) |
| 1056 |
lxv 5, 0x50(6) |
| 1057 |
lxv 6, 0x60(6) |
| 1058 |
lxv 7, 0x70(6) |
| 1059 |
lxv 8, 0x80(6) |
| 1060 |
lxv 9, 0x90(6) |
| 1061 |
lxv 10, 0xa0(6) |
| 1062 |
|
| 1063 |
# load rounds - 10 (128), 12 (192), 14 (256) |
| 1064 |
lwz 9,480(6) |
| 1065 |
|
| 1066 |
# |
| 1067 |
# vxor state, state, w # addroundkey |
| 1068 |
xxlor 32+29, 0, 0 |
| 1069 |
vxor 15, 30, 29 # IV + round key - add round key 0 |
| 1070 |
|
| 1071 |
cmpdi 9, 10 |
| 1072 |
beq Loop_aes_gcm_8x_dec |
| 1073 |
|
| 1074 |
# load 2 more round keys (v11, v12) |
| 1075 |
lxv 11, 0xb0(6) |
| 1076 |
lxv 12, 0xc0(6) |
| 1077 |
|
| 1078 |
cmpdi 9, 12 |
| 1079 |
beq Loop_aes_gcm_8x_dec |
| 1080 |
|
| 1081 |
# load 2 more round keys (v11, v12, v13, v14) |
| 1082 |
lxv 13, 0xd0(6) |
| 1083 |
lxv 14, 0xe0(6) |
| 1084 |
cmpdi 9, 14 |
| 1085 |
beq Loop_aes_gcm_8x_dec |
| 1086 |
|
| 1087 |
b aes_gcm_out |
| 1088 |
|
| 1089 |
.align 5 |
| 1090 |
Loop_aes_gcm_8x_dec: |
| 1091 |
mr 14, 3 |
| 1092 |
mr 9, 4 |
| 1093 |
|
| 1094 |
# n blcoks |
| 1095 |
li 10, 128 |
| 1096 |
divdu 10, 5, 10 # n 128 bytes-blocks |
| 1097 |
cmpdi 10, 0 |
| 1098 |
beq Loop_last_block_dec |
| 1099 |
|
| 1100 |
vaddudm 30, 30, 31 # IV + counter |
| 1101 |
vxor 16, 30, 29 |
| 1102 |
vaddudm 30, 30, 31 |
| 1103 |
vxor 17, 30, 29 |
| 1104 |
vaddudm 30, 30, 31 |
| 1105 |
vxor 18, 30, 29 |
| 1106 |
vaddudm 30, 30, 31 |
| 1107 |
vxor 19, 30, 29 |
| 1108 |
vaddudm 30, 30, 31 |
| 1109 |
vxor 20, 30, 29 |
| 1110 |
vaddudm 30, 30, 31 |
| 1111 |
vxor 21, 30, 29 |
| 1112 |
vaddudm 30, 30, 31 |
| 1113 |
vxor 22, 30, 29 |
| 1114 |
|
| 1115 |
mtctr 10 |
| 1116 |
|
| 1117 |
li 15, 16 |
| 1118 |
li 16, 32 |
| 1119 |
li 17, 48 |
| 1120 |
li 18, 64 |
| 1121 |
li 19, 80 |
| 1122 |
li 20, 96 |
| 1123 |
li 21, 112 |
| 1124 |
|
| 1125 |
lwz 10, 480(6) |
| 1126 |
|
| 1127 |
Loop_8x_block_dec: |
| 1128 |
|
| 1129 |
lxvb16x 15, 0, 14 # load block |
| 1130 |
lxvb16x 16, 15, 14 # load block |
| 1131 |
lxvb16x 17, 16, 14 # load block |
| 1132 |
lxvb16x 18, 17, 14 # load block |
| 1133 |
lxvb16x 19, 18, 14 # load block |
| 1134 |
lxvb16x 20, 19, 14 # load block |
| 1135 |
lxvb16x 21, 20, 14 # load block |
| 1136 |
lxvb16x 22, 21, 14 # load block |
| 1137 |
addi 14, 14, 128 |
| 1138 |
|
| 1139 |
Loop_aes_middle8x |
| 1140 |
|
| 1141 |
xxlor 23+32, 10, 10 |
| 1142 |
|
| 1143 |
cmpdi 10, 10 |
| 1144 |
beq Do_last_aes_dec |
| 1145 |
|
| 1146 |
# 192 bits |
| 1147 |
xxlor 24+32, 11, 11 |
| 1148 |
|
| 1149 |
vcipher 15, 15, 23 |
| 1150 |
vcipher 16, 16, 23 |
| 1151 |
vcipher 17, 17, 23 |
| 1152 |
vcipher 18, 18, 23 |
| 1153 |
vcipher 19, 19, 23 |
| 1154 |
vcipher 20, 20, 23 |
| 1155 |
vcipher 21, 21, 23 |
| 1156 |
vcipher 22, 22, 23 |
| 1157 |
|
| 1158 |
vcipher 15, 15, 24 |
| 1159 |
vcipher 16, 16, 24 |
| 1160 |
vcipher 17, 17, 24 |
| 1161 |
vcipher 18, 18, 24 |
| 1162 |
vcipher 19, 19, 24 |
| 1163 |
vcipher 20, 20, 24 |
| 1164 |
vcipher 21, 21, 24 |
| 1165 |
vcipher 22, 22, 24 |
| 1166 |
|
| 1167 |
xxlor 23+32, 12, 12 |
| 1168 |
|
| 1169 |
cmpdi 10, 12 |
| 1170 |
beq Do_last_aes_dec |
| 1171 |
|
| 1172 |
# 256 bits |
| 1173 |
xxlor 24+32, 13, 13 |
| 1174 |
|
| 1175 |
vcipher 15, 15, 23 |
| 1176 |
vcipher 16, 16, 23 |
| 1177 |
vcipher 17, 17, 23 |
| 1178 |
vcipher 18, 18, 23 |
| 1179 |
vcipher 19, 19, 23 |
| 1180 |
vcipher 20, 20, 23 |
| 1181 |
vcipher 21, 21, 23 |
| 1182 |
vcipher 22, 22, 23 |
| 1183 |
|
| 1184 |
vcipher 15, 15, 24 |
| 1185 |
vcipher 16, 16, 24 |
| 1186 |
vcipher 17, 17, 24 |
| 1187 |
vcipher 18, 18, 24 |
| 1188 |
vcipher 19, 19, 24 |
| 1189 |
vcipher 20, 20, 24 |
| 1190 |
vcipher 21, 21, 24 |
| 1191 |
vcipher 22, 22, 24 |
| 1192 |
|
| 1193 |
xxlor 23+32, 14, 14 |
| 1194 |
|
| 1195 |
cmpdi 10, 14 |
| 1196 |
beq Do_last_aes_dec |
| 1197 |
b aes_gcm_out |
| 1198 |
|
| 1199 |
Do_last_aes_dec: |
| 1200 |
|
| 1201 |
# |
| 1202 |
# last round |
| 1203 |
vcipherlast 15, 15, 23 |
| 1204 |
vcipherlast 16, 16, 23 |
| 1205 |
|
| 1206 |
xxlxor 47, 47, 15 |
| 1207 |
stxvb16x 47, 0, 9 # store output |
| 1208 |
xxlxor 48, 48, 16 |
| 1209 |
stxvb16x 48, 15, 9 # store output |
| 1210 |
|
| 1211 |
vcipherlast 17, 17, 23 |
| 1212 |
vcipherlast 18, 18, 23 |
| 1213 |
|
| 1214 |
xxlxor 49, 49, 17 |
| 1215 |
stxvb16x 49, 16, 9 # store output |
| 1216 |
xxlxor 50, 50, 18 |
| 1217 |
stxvb16x 50, 17, 9 # store output |
| 1218 |
|
| 1219 |
vcipherlast 19, 19, 23 |
| 1220 |
vcipherlast 20, 20, 23 |
| 1221 |
|
| 1222 |
xxlxor 51, 51, 19 |
| 1223 |
stxvb16x 51, 18, 9 # store output |
| 1224 |
xxlxor 52, 52, 20 |
| 1225 |
stxvb16x 52, 19, 9 # store output |
| 1226 |
|
| 1227 |
vcipherlast 21, 21, 23 |
| 1228 |
vcipherlast 22, 22, 23 |
| 1229 |
|
| 1230 |
xxlxor 53, 53, 21 |
| 1231 |
stxvb16x 53, 20, 9 # store output |
| 1232 |
xxlxor 54, 54, 22 |
| 1233 |
stxvb16x 54, 21, 9 # store output |
| 1234 |
|
| 1235 |
addi 9, 9, 128 |
| 1236 |
|
| 1237 |
xxlor 15+32, 15, 15 |
| 1238 |
xxlor 16+32, 16, 16 |
| 1239 |
xxlor 17+32, 17, 17 |
| 1240 |
xxlor 18+32, 18, 18 |
| 1241 |
xxlor 19+32, 19, 19 |
| 1242 |
xxlor 20+32, 20, 20 |
| 1243 |
xxlor 21+32, 21, 21 |
| 1244 |
xxlor 22+32, 22, 22 |
| 1245 |
|
| 1246 |
# ghash here |
| 1247 |
ppc_aes_gcm_ghash2_4x |
| 1248 |
|
| 1249 |
xxlor 27+32, 0, 0 |
| 1250 |
vaddudm 30, 30, 31 # IV + counter |
| 1251 |
vmr 29, 30 |
| 1252 |
vxor 15, 30, 27 # add round key |
| 1253 |
vaddudm 30, 30, 31 |
| 1254 |
vxor 16, 30, 27 |
| 1255 |
vaddudm 30, 30, 31 |
| 1256 |
vxor 17, 30, 27 |
| 1257 |
vaddudm 30, 30, 31 |
| 1258 |
vxor 18, 30, 27 |
| 1259 |
vaddudm 30, 30, 31 |
| 1260 |
vxor 19, 30, 27 |
| 1261 |
vaddudm 30, 30, 31 |
| 1262 |
vxor 20, 30, 27 |
| 1263 |
vaddudm 30, 30, 31 |
| 1264 |
vxor 21, 30, 27 |
| 1265 |
vaddudm 30, 30, 31 |
| 1266 |
vxor 22, 30, 27 |
| 1267 |
addi 12, 12, -128 |
| 1268 |
addi 11, 11, 128 |
| 1269 |
|
| 1270 |
bdnz Loop_8x_block_dec |
| 1271 |
|
| 1272 |
vmr 30, 29 |
| 1273 |
|
| 1274 |
Loop_last_block_dec: |
| 1275 |
cmpdi 12, 0 |
| 1276 |
beq aes_gcm_out |
| 1277 |
|
| 1278 |
# loop last few blocks |
| 1279 |
li 10, 16 |
| 1280 |
divdu 10, 12, 10 |
| 1281 |
|
| 1282 |
mtctr 10 |
| 1283 |
|
| 1284 |
lwz 10,480(6) |
| 1285 |
|
| 1286 |
cmpdi 12, 16 |
| 1287 |
blt Final_block_dec |
| 1288 |
|
| 1289 |
Next_rem_block_dec: |
| 1290 |
lxvb16x 15, 0, 14 # load block |
| 1291 |
|
| 1292 |
Loop_aes_middle_1x |
| 1293 |
|
| 1294 |
xxlor 23+32, 10, 10 |
| 1295 |
|
| 1296 |
cmpdi 10, 10 |
| 1297 |
beq Do_next_1x_dec |
| 1298 |
|
| 1299 |
# 192 bits |
| 1300 |
xxlor 24+32, 11, 11 |
| 1301 |
|
| 1302 |
vcipher 15, 15, 23 |
| 1303 |
vcipher 15, 15, 24 |
| 1304 |
|
| 1305 |
xxlor 23+32, 12, 12 |
| 1306 |
|
| 1307 |
cmpdi 10, 12 |
| 1308 |
beq Do_next_1x_dec |
| 1309 |
|
| 1310 |
# 256 bits |
| 1311 |
xxlor 24+32, 13, 13 |
| 1312 |
|
| 1313 |
vcipher 15, 15, 23 |
| 1314 |
vcipher 15, 15, 24 |
| 1315 |
|
| 1316 |
xxlor 23+32, 14, 14 |
| 1317 |
|
| 1318 |
cmpdi 10, 14 |
| 1319 |
beq Do_next_1x_dec |
| 1320 |
|
| 1321 |
Do_next_1x_dec: |
| 1322 |
vcipherlast 15, 15, 23 |
| 1323 |
|
| 1324 |
xxlxor 47, 47, 15 |
| 1325 |
stxvb16x 47, 0, 9 # store output |
| 1326 |
addi 14, 14, 16 |
| 1327 |
addi 9, 9, 16 |
| 1328 |
|
| 1329 |
xxlor 28+32, 15, 15 |
| 1330 |
ppc_update_hash_1x |
| 1331 |
|
| 1332 |
addi 12, 12, -16 |
| 1333 |
addi 11, 11, 16 |
| 1334 |
xxlor 19+32, 0, 0 |
| 1335 |
vaddudm 30, 30, 31 # IV + counter |
| 1336 |
vxor 15, 30, 19 # add round key |
| 1337 |
|
| 1338 |
bdnz Next_rem_block_dec |
| 1339 |
|
| 1340 |
cmpdi 12, 0 |
| 1341 |
beq aes_gcm_out |
| 1342 |
|
| 1343 |
Final_block_dec: |
| 1344 |
Loop_aes_middle_1x |
| 1345 |
|
| 1346 |
xxlor 23+32, 10, 10 |
| 1347 |
|
| 1348 |
cmpdi 10, 10 |
| 1349 |
beq Do_final_1x_dec |
| 1350 |
|
| 1351 |
# 192 bits |
| 1352 |
xxlor 24+32, 11, 11 |
| 1353 |
|
| 1354 |
vcipher 15, 15, 23 |
| 1355 |
vcipher 15, 15, 24 |
| 1356 |
|
| 1357 |
xxlor 23+32, 12, 12 |
| 1358 |
|
| 1359 |
cmpdi 10, 12 |
| 1360 |
beq Do_final_1x_dec |
| 1361 |
|
| 1362 |
# 256 bits |
| 1363 |
xxlor 24+32, 13, 13 |
| 1364 |
|
| 1365 |
vcipher 15, 15, 23 |
| 1366 |
vcipher 15, 15, 24 |
| 1367 |
|
| 1368 |
xxlor 23+32, 14, 14 |
| 1369 |
|
| 1370 |
cmpdi 10, 14 |
| 1371 |
beq Do_final_1x_dec |
| 1372 |
|
| 1373 |
Do_final_1x_dec: |
| 1374 |
vcipherlast 15, 15, 23 |
| 1375 |
|
| 1376 |
lxvb16x 15, 0, 14 # load block |
| 1377 |
xxlxor 47, 47, 15 |
| 1378 |
|
| 1379 |
# create partial block mask |
| 1380 |
li 15, 16 |
| 1381 |
sub 15, 15, 12 # index to the mask |
| 1382 |
|
| 1383 |
vspltisb 16, -1 # first 16 bytes - 0xffff...ff |
| 1384 |
vspltisb 17, 0 # second 16 bytes - 0x0000...00 |
| 1385 |
li 10, 192 |
| 1386 |
stvx 16, 10, 1 |
| 1387 |
addi 10, 10, 16 |
| 1388 |
stvx 17, 10, 1 |
| 1389 |
|
| 1390 |
addi 10, 1, 192 |
| 1391 |
lxvb16x 16, 15, 10 # load block mask |
| 1392 |
xxland 47, 47, 16 |
| 1393 |
|
| 1394 |
xxlor 28+32, 15, 15 |
| 1395 |
ppc_update_hash_1x |
| 1396 |
|
| 1397 |
# * should store only the remaining bytes. |
| 1398 |
bl Write_partial_block |
| 1399 |
|
| 1400 |
b aes_gcm_out |
| 1401 |
# |