4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Unified version for both position independent and non position independent
28 * for both v8plus and v9.
31 * cc -c -xarch=v8plus aes_crypt_asm.S or
32 * cc -c -arch=v9 aes_crypt_asm.S
33 * for kernel use (no -KPIC).
37 * cc -c -xarch=v8plus -KPIC -DPIC aes_crypt_asm.S or
38 * cc -c -arch=v9 -KPIC -DPIC aes_crypt_asm.S
42 * The tables were generated by a C program, compiled into the C version
43 * of this function, from which a .s was generated by the C compiler and
44 * that .s was used as a starting point for this one, in particular for
45 * the data definitions. It is important, though that the tables and
46 * the code both remain in the text section and in this order, otherwise,
47 * at least on UltraSparc-II processors, collisions in the E-cache are
48 * highly probable between the code and the data it is using which can
49 * result in up to 40% performance loss.
51 * For a description of the AES algorithm (a.k.a. Rijndael), see NIST
52 * publication FIPS PUB 197.
56 #include <sys/stack.h>
59 .section ".text",#alloc,#execinstr
60 .file "aes_crypt_asm.s"
62 .register %g2,#scratch
63 .register %g3,#scratch
65 .section ".text",#alloc
2406 .section ".data",#alloc,#write
2412 ! for v8plus
, the addresses are
64-bit long so we should use
.xword
2427 #else /* __sparcv9 */
2430 ! for v8plus
, the addresses are
32-bit long
, we use filler
0's so that
2431 ! we can use ldx to load the addresses just like in the v9 version
2454 #endif /* __sparcv9 */
2456 .type aes_const,#object
2459 .section ".text",#alloc,#execinstr
2461 ! SUBROUTINE aes_encrypt_impl
2463 ! void aes_encrypt_impl(const uint32_t rk[], int Nr, const uint32_t pt[4],
2466 ! OFFSET SOURCE LINE LABEL INSTRUCTION
2468 .global aes_encrypt_impl
2473 save %sp, -SA(MINFRAME), %sp
2476 sethi %hi(aes_const), %l0
2480 sethi %hi(_GLOBAL_OFFSET_TABLE_-(.L1-.)), %l1
2481 or %l0, %lo(aes_const), %l0
2484 or %l1, %lo(_GLOBAL_OFFSET_TABLE_-(.L1-.)), %l1
2485 sethi %hi(0xff000000), %i5
2488 sethi %hi(0x7fff8), %l6
2491 or %l6, %lo(0x7ff8), %l6
2496 sethi %hh(aes_const), %l0
2497 sethi %lm(aes_const), %l7
2499 or %l0, %hm(aes_const), %l0
2500 or %l7, %lo(aes_const), %l7
2503 sethi %hi(0xff000000), %i5
2506 sethi %hi(0x7fff8), %l6
2510 or %l6, %lo(0x7ff8), %l6
2515 #else /* __sparcv9 */
2517 save %sp, -SA(MINFRAME), %sp
2518 sethi %hi(aes_const), %l0
2524 sethi %hi(_GLOBAL_OFFSET_TABLE_-(.L1-.)), %l1
2525 or %l0, %lo(aes_const), %l0
2528 or %l1, %lo(_GLOBAL_OFFSET_TABLE_-(.L1-.)), %l1
2529 sethi %hi(0xff000000), %i5
2532 sethi %hi(0x7fff8), %l6
2535 or %l6, %lo(0x7ff8), %l6
2540 or %l0, %lo(aes_const), %l7
2541 sethi %hi(0xff000000), %i5
2544 sethi %hi(0x7fff8), %l6
2547 or %l6, %lo(0x7ff8), %l6
2552 #endif /* __sparcv9 */
2620 ldx [%l0 + %l4], %o0
2624 ldx [%l1 + %l5], %o5
2628 ldx [%l2 + %l6], %g5
2632 ldx [%l3 + %l7], %o0
2640 ldx [%l0 + %l4], %o0
2644 ldx [%l1 + %l5], %o5
2647 ldx [%l2 + %l6], %g5
2651 ldx [%l3 + %l7], %o0
2659 ldx [%l0 + %l4], %o0
2663 ldx [%l1 + %l5], %o5
2666 ldx [%l2 + %l6], %g5
2670 ldx [%l3 + %l7], %o0
2678 ldx [%l0 + %l4], %o0
2682 ldx [%l1 + %l5], %o5
2685 ldx [%l2 + %l6], %g5
2690 ldx [%l3 + %l7], %o0
2699 ldx [%l0 + %l4], %o0
2703 ldx [%l1 + %l5], %o5
2707 ldx [%l2 + %l6], %g5
2711 ldx [%l3 + %l7], %o0
2719 ldx [%l0 + %l4], %o0
2723 ldx [%l1 + %l5], %o5
2726 ldx [%l2 + %l6], %g5
2730 ldx [%l3 + %l7], %o0
2738 ldx [%l0 + %l4], %o0
2742 ldx [%l1 + %l5], %o5
2745 ldx [%l2 + %l6], %g5
2749 ldx [%l3 + %l7], %o0
2757 ldx [%l0 + %l4], %o0
2761 ldx [%l1 + %l5], %o5
2764 ldx [%l2 + %l6], %g5
2768 ldx [%l3 + %l7], %o0
2777 ldx [%l0 + %l4], %o0
2781 ldx [%l1 + %l5], %o5
2785 ldx [%l2 + %l6], %g5
2789 ldx [%l3 + %l7], %o0
2797 ldx [%l0 + %l4], %o0
2801 ldx [%l1 + %l5], %o5
2804 ldx [%l2 + %l6], %g5
2808 ldx [%l3 + %l7], %o0
2816 ldx [%l0 + %l4], %o0
2820 ldx [%l1 + %l5], %o5
2823 ldx [%l2 + %l6], %g5
2827 ldx [%l3 + %l7], %o0
2835 ldx [%l0 + %l4], %o0
2839 ldx [%l1 + %l5], %o5
2842 ldx [%l2 + %l6], %g5
2847 ldx [%l3 + %l7], %o0
2856 srl %l4, 1, %l4 !***** should be removed after
2857 srl %l5, 1, %l5 !***** unrolling the loop and correcting
2858 add %i0, 32, %i0 !***** the last iteration
2975 .type aes_encrypt_impl,2
2976 .size aes_encrypt_impl,(.-aes_encrypt_impl)
2979 .section ".text",#alloc,#execinstr
2982 ! SUBROUTINE aes_decrypt_impl
2984 ! void aes_decrypt_impl(const uint32_t rk[], int Nr, const uint32_t ct[4],
2987 ! OFFSET SOURCE LINE LABEL INSTRUCTION
2989 .global aes_decrypt_impl
2994 save %sp, -SA(MINFRAME), %sp
2997 sethi %hi(aes_const), %l0
3001 sethi %hi(_GLOBAL_OFFSET_TABLE_-(.L1d-.)), %l1
3002 or %l0, %lo(aes_const), %l0
3005 or %l1, %lo(_GLOBAL_OFFSET_TABLE_-(.L1d-.)), %l1
3006 sethi %hi(0xff000000), %i5
3009 sethi %hi(0x7fff8), %l6
3012 or %l6, %lo(0x7ff8), %l6
3017 sethi %hh(aes_const), %l0
3018 sethi %lm(aes_const), %l7
3020 or %l0, %hm(aes_const), %l0
3021 or %l7, %lo(aes_const), %l7
3024 sethi %hi(0xff000000), %i5
3027 sethi %hi(0x7fff8), %l6
3031 or %l6, %lo(0x7ff8), %l6
3036 #else /* __sparcv9 */
3038 save %sp, -SA(MINFRAME), %sp
3039 sethi %hi(aes_const), %l0
3045 sethi %hi(_GLOBAL_OFFSET_TABLE_-(.L1d-.)), %l1
3046 or %l0, %lo(aes_const), %l0
3049 or %l1, %lo(_GLOBAL_OFFSET_TABLE_-(.L1d-.)), %l1
3050 sethi %hi(0xff000000), %i5
3053 sethi %hi(0x7fff8), %l6
3056 or %l6, %lo(0x7ff8), %l6
3061 or %l0, %lo(aes_const), %l7
3062 sethi %hi(0xff000000), %i5
3065 sethi %hi(0x7fff8), %l6
3068 or %l6, %lo(0x7ff8), %l6
3073 #endif /* __sparcv9 */
3141 ldx [%l0 + %l4], %o0
3145 ldx [%l1 + %l5], %o5
3149 ldx [%l2 + %l6], %g5
3153 ldx [%l3 + %l7], %o0
3161 ldx [%l0 + %l4], %o0
3165 ldx [%l1 + %l5], %o5
3168 ldx [%l2 + %l6], %g5
3172 ldx [%l3 + %l7], %o0
3180 ldx [%l0 + %l4], %o0
3184 ldx [%l1 + %l5], %o5
3187 ldx [%l2 + %l6], %g5
3191 ldx [%l3 + %l7], %o0
3199 ldx [%l0 + %l4], %o0
3203 ldx [%l1 + %l5], %o5
3206 ldx [%l2 + %l6], %g5
3211 ldx [%l3 + %l7], %o0
3220 ldx [%l0 + %l4], %o0
3224 ldx [%l1 + %l5], %o5
3228 ldx [%l2 + %l6], %g5
3232 ldx [%l3 + %l7], %o0
3240 ldx [%l0 + %l4], %o0
3244 ldx [%l1 + %l5], %o5
3247 ldx [%l2 + %l6], %g5
3251 ldx [%l3 + %l7], %o0
3259 ldx [%l0 + %l4], %o0
3263 ldx [%l1 + %l5], %o5
3266 ldx [%l2 + %l6], %g5
3270 ldx [%l3 + %l7], %o0
3278 ldx [%l0 + %l4], %o0
3282 ldx [%l1 + %l5], %o5
3285 ldx [%l2 + %l6], %g5
3289 ldx [%l3 + %l7], %o0
3298 ldx [%l0 + %l4], %o0
3302 ldx [%l1 + %l5], %o5
3306 ldx [%l2 + %l6], %g5
3310 ldx [%l3 + %l7], %o0
3318 ldx [%l0 + %l4], %o0
3322 ldx [%l1 + %l5], %o5
3325 ldx [%l2 + %l6], %g5
3329 ldx [%l3 + %l7], %o0
3337 ldx [%l0 + %l4], %o0
3341 ldx [%l1 + %l5], %o5
3344 ldx [%l2 + %l6], %g5
3348 ldx [%l3 + %l7], %o0
3356 ldx [%l0 + %l4], %o0
3360 ldx [%l1 + %l5], %o5
3363 ldx [%l2 + %l6], %g5
3368 ldx [%l3 + %l7], %o0
3377 srl %l4, 1, %l4 !***** should be removed after
3378 srl %l5, 1, %l5 !***** unrolling the loop and correcting
3379 add %i0, 32, %i0 !***** the last iteration
3496 .type aes_decrypt_impl,2
3497 .size aes_decrypt_impl,(.-aes_decrypt_impl)
3500 .section ".text",#alloc
5855 ! Begin Disassembling Stabs
5856 .xstabs ".stab.index","Xa ; O ; P ; V=3.1 ; R=WorkShop Compilers 5.0 99/02/25 C 5.0 patch 107289-01",60,0,0,0 ! (/tmp/acompAAA5jaWsZ:1)
5857 ! End Disassembling Stabs
5859 ! Begin Disassembling Ident
5860 .ident "cg: WorkShop Compilers 5.0 99/04/15 Compiler Common 5.0 Patch 107357-02" ! (NO SOURCE LINE)
5861 .ident "acomp: WorkShop Compilers 5.0 99/02/25 C 5.0 patch 107289-01" ! (/tmp/acompAAA5jaWsZ:4675)
5862 ! End Disassembling Ident