diff options
author | miod <> | 2023-02-01 20:45:04 +0000 |
---|---|---|
committer | miod <> | 2023-02-01 20:45:04 +0000 |
commit | dc4b2cf3e0979364f14ff89a07ffafc47435e2e7 (patch) | |
tree | 58219f5c6538172b9d00f33bf48c9a61419ec7a0 /src/lib/libcrypto/aes | |
parent | 86f42338b2994b620482c37e3d0d9fc3ba1f523b (diff) | |
download | openbsd-dc4b2cf3e0979364f14ff89a07ffafc47435e2e7.tar.gz openbsd-dc4b2cf3e0979364f14ff89a07ffafc47435e2e7.tar.bz2 openbsd-dc4b2cf3e0979364f14ff89a07ffafc47435e2e7.zip |
Move all data blocks from .text to .rodata and cleanup up and homogeneize code
responsible from getting the proper address of those blocks.
ok tb@ jsing@
Diffstat (limited to 'src/lib/libcrypto/aes')
-rw-r--r-- | src/lib/libcrypto/aes/asm/aes-586.pl | 45 | ||||
-rw-r--r-- | src/lib/libcrypto/aes/asm/aesni-x86.pl | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/aes/asm/vpaes-x86.pl | 34 |
3 files changed, 42 insertions, 38 deletions
diff --git a/src/lib/libcrypto/aes/asm/aes-586.pl b/src/lib/libcrypto/aes/asm/aes-586.pl index c5ae3f6903..4e0f34cba3 100644 --- a/src/lib/libcrypto/aes/asm/aes-586.pl +++ b/src/lib/libcrypto/aes/asm/aes-586.pl | |||
@@ -950,8 +950,10 @@ sub enclast() | |||
950 | &xor ($s3,&DWP(12,$key)); | 950 | &xor ($s3,&DWP(12,$key)); |
951 | 951 | ||
952 | &ret (); | 952 | &ret (); |
953 | &function_end_B("_x86_AES_encrypt"); | ||
953 | 954 | ||
954 | &set_label("AES_Te",64); # Yes! I keep it in the code segment! | 955 | &rodataseg(); |
956 | &set_label("AES_Te",64); | ||
955 | &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6); | 957 | &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6); |
956 | &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591); | 958 | &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591); |
957 | &_data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56); | 959 | &_data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56); |
@@ -1154,7 +1156,7 @@ sub enclast() | |||
1154 | &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080); | 1156 | &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080); |
1155 | &data_word(0x0000001b, 0x00000036, 0x00000000, 0x00000000); | 1157 | &data_word(0x0000001b, 0x00000036, 0x00000000, 0x00000000); |
1156 | &data_word(0x00000000, 0x00000000, 0x00000000, 0x00000000); | 1158 | &data_word(0x00000000, 0x00000000, 0x00000000, 0x00000000); |
1157 | &function_end_B("_x86_AES_encrypt"); | 1159 | &previous(); |
1158 | 1160 | ||
1159 | # void AES_encrypt (const void *inp,void *out,const AES_KEY *key); | 1161 | # void AES_encrypt (const void *inp,void *out,const AES_KEY *key); |
1160 | &function_begin("AES_encrypt"); | 1162 | &function_begin("AES_encrypt"); |
@@ -1174,11 +1176,9 @@ sub enclast() | |||
1174 | &add ("esp",4); # 4 is reserved for caller's return address | 1176 | &add ("esp",4); # 4 is reserved for caller's return address |
1175 | &mov ($_esp,$s0); # save stack pointer | 1177 | &mov ($_esp,$s0); # save stack pointer |
1176 | 1178 | ||
1177 | &call (&label("pic_point")); # make it PIC! | 1179 | &picsetup($tbl); |
1178 | &set_label("pic_point"); | 1180 | &picsymbol($s0, "OPENSSL_ia32cap_P", $tbl); |
1179 | &blindpop($tbl); | 1181 | &picsymbol($tbl, &label("AES_Te"), $tbl); |
1180 | &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if (!$x86only); | ||
1181 | &lea ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl)); | ||
1182 | 1182 | ||
1183 | # pick Te4 copy which can't "overlap" with stack frame or key schedule | 1183 | # pick Te4 copy which can't "overlap" with stack frame or key schedule |
1184 | &lea ($s1,&DWP(768-4,"esp")); | 1184 | &lea ($s1,&DWP(768-4,"esp")); |
@@ -1744,8 +1744,10 @@ sub declast() | |||
1744 | &xor ($s3,&DWP(12,$key)); | 1744 | &xor ($s3,&DWP(12,$key)); |
1745 | 1745 | ||
1746 | &ret (); | 1746 | &ret (); |
1747 | &function_end_B("_x86_AES_decrypt"); | ||
1747 | 1748 | ||
1748 | &set_label("AES_Td",64); # Yes! I keep it in the code segment! | 1749 | &rodataseg(); |
1750 | &set_label("AES_Td",64); | ||
1749 | &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a); | 1751 | &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a); |
1750 | &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b); | 1752 | &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b); |
1751 | &_data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5); | 1753 | &_data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5); |
@@ -1943,7 +1945,7 @@ sub declast() | |||
1943 | &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61); | 1945 | &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61); |
1944 | &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26); | 1946 | &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26); |
1945 | &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d); | 1947 | &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d); |
1946 | &function_end_B("_x86_AES_decrypt"); | 1948 | &previous(); |
1947 | 1949 | ||
1948 | # void AES_decrypt (const void *inp,void *out,const AES_KEY *key); | 1950 | # void AES_decrypt (const void *inp,void *out,const AES_KEY *key); |
1949 | &function_begin("AES_decrypt"); | 1951 | &function_begin("AES_decrypt"); |
@@ -1963,11 +1965,9 @@ sub declast() | |||
1963 | &add ("esp",4); # 4 is reserved for caller's return address | 1965 | &add ("esp",4); # 4 is reserved for caller's return address |
1964 | &mov ($_esp,$s0); # save stack pointer | 1966 | &mov ($_esp,$s0); # save stack pointer |
1965 | 1967 | ||
1966 | &call (&label("pic_point")); # make it PIC! | 1968 | &picsetup($tbl); |
1967 | &set_label("pic_point"); | 1969 | &picsymbol($s0, "OPENSSL_ia32cap_P", $tbl); |
1968 | &blindpop($tbl); | 1970 | &picsymbol($tbl, &label("AES_Td"), $tbl); |
1969 | &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if(!$x86only); | ||
1970 | &lea ($tbl,&DWP(&label("AES_Td")."-".&label("pic_point"),$tbl)); | ||
1971 | 1971 | ||
1972 | # pick Td4 copy which can't "overlap" with stack frame or key schedule | 1972 | # pick Td4 copy which can't "overlap" with stack frame or key schedule |
1973 | &lea ($s1,&DWP(768-4,"esp")); | 1973 | &lea ($s1,&DWP(768-4,"esp")); |
@@ -2034,13 +2034,10 @@ my $mark=&DWP(76+240,"esp"); # copy of aes_key->rounds | |||
2034 | &cmp ($s2,0); | 2034 | &cmp ($s2,0); |
2035 | &je (&label("drop_out")); | 2035 | &je (&label("drop_out")); |
2036 | 2036 | ||
2037 | &call (&label("pic_point")); # make it PIC! | 2037 | &picsetup($tbl); |
2038 | &set_label("pic_point"); | 2038 | &picsymbol($s0, "OPENSSL_ia32cap_P", $tbl); |
2039 | &blindpop($tbl); | 2039 | &picsymbol($tbl, &label("AES_Te"), $tbl); |
2040 | &picmeup($s0,"OPENSSL_ia32cap_P",$tbl,&label("pic_point")) if(!$x86only); | ||
2041 | |||
2042 | &cmp (&wparam(5),0); | 2040 | &cmp (&wparam(5),0); |
2043 | &lea ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl)); | ||
2044 | &jne (&label("picked_te")); | 2041 | &jne (&label("picked_te")); |
2045 | &lea ($tbl,&DWP(&label("AES_Td")."-".&label("AES_Te"),$tbl)); | 2042 | &lea ($tbl,&DWP(&label("AES_Td")."-".&label("AES_Te"),$tbl)); |
2046 | &set_label("picked_te"); | 2043 | &set_label("picked_te"); |
@@ -2659,10 +2656,9 @@ sub enckey() | |||
2659 | &test ("edi",-1); | 2656 | &test ("edi",-1); |
2660 | &jz (&label("badpointer")); | 2657 | &jz (&label("badpointer")); |
2661 | 2658 | ||
2662 | &call (&label("pic_point")); | 2659 | &picsetup($tbl); |
2663 | &set_label("pic_point"); | 2660 | &picsymbol($tbl, &label("AES_Te"), $tbl); |
2664 | &blindpop($tbl); | 2661 | |
2665 | &lea ($tbl,&DWP(&label("AES_Te")."-".&label("pic_point"),$tbl)); | ||
2666 | &lea ($tbl,&DWP(2048+128,$tbl)); | 2662 | &lea ($tbl,&DWP(2048+128,$tbl)); |
2667 | 2663 | ||
2668 | # prefetch Te4 | 2664 | # prefetch Te4 |
@@ -2975,6 +2971,5 @@ sub deckey() | |||
2975 | 2971 | ||
2976 | &xor ("eax","eax"); # return success | 2972 | &xor ("eax","eax"); # return success |
2977 | &function_end("AES_set_decrypt_key"); | 2973 | &function_end("AES_set_decrypt_key"); |
2978 | &asciz("AES for x86, CRYPTOGAMS by <appro\@openssl.org>"); | ||
2979 | 2974 | ||
2980 | &asm_finish(); | 2975 | &asm_finish(); |
diff --git a/src/lib/libcrypto/aes/asm/aesni-x86.pl b/src/lib/libcrypto/aes/asm/aesni-x86.pl index 8c1d0b5bed..ff44415611 100644 --- a/src/lib/libcrypto/aes/asm/aesni-x86.pl +++ b/src/lib/libcrypto/aes/asm/aesni-x86.pl | |||
@@ -2184,6 +2184,5 @@ if ($PREFIX eq "aesni") { | |||
2184 | &set_label("dec_key_ret"); | 2184 | &set_label("dec_key_ret"); |
2185 | &ret (); | 2185 | &ret (); |
2186 | &function_end_B("${PREFIX}_set_decrypt_key"); | 2186 | &function_end_B("${PREFIX}_set_decrypt_key"); |
2187 | &asciz("AES for Intel AES-NI, CRYPTOGAMS by <appro\@openssl.org>"); | ||
2188 | 2187 | ||
2189 | &asm_finish(); | 2188 | &asm_finish(); |
diff --git a/src/lib/libcrypto/aes/asm/vpaes-x86.pl b/src/lib/libcrypto/aes/asm/vpaes-x86.pl index 1533e2c304..38cef61733 100644 --- a/src/lib/libcrypto/aes/asm/vpaes-x86.pl +++ b/src/lib/libcrypto/aes/asm/vpaes-x86.pl | |||
@@ -57,6 +57,7 @@ $PREFIX="vpaes"; | |||
57 | my ($round, $base, $magic, $key, $const, $inp, $out)= | 57 | my ($round, $base, $magic, $key, $const, $inp, $out)= |
58 | ("eax", "ebx", "ecx", "edx","ebp", "esi","edi"); | 58 | ("eax", "ebx", "ecx", "edx","ebp", "esi","edi"); |
59 | 59 | ||
60 | &rodataseg(); | ||
60 | &static_label("_vpaes_consts"); | 61 | &static_label("_vpaes_consts"); |
61 | &static_label("_vpaes_schedule_low_round"); | 62 | &static_label("_vpaes_schedule_low_round"); |
62 | 63 | ||
@@ -153,8 +154,7 @@ $k_dsbe=0x2a0; # decryption sbox output *E*u, *E*t | |||
153 | $k_dsbo=0x2c0; # decryption sbox final output | 154 | $k_dsbo=0x2c0; # decryption sbox final output |
154 | &data_word(0x7EF94000,0x1387EA53,0xD4943E2D,0xC7AA6DB9); | 155 | &data_word(0x7EF94000,0x1387EA53,0xD4943E2D,0xC7AA6DB9); |
155 | &data_word(0x93441D00,0x12D7560F,0xD8C58E9C,0xCA4B8159); | 156 | &data_word(0x93441D00,0x12D7560F,0xD8C58E9C,0xCA4B8159); |
156 | &asciz ("Vector Permutation AES for x86/SSSE3, Mike Hamburg (Stanford University)"); | 157 | &previous(); |
157 | &align (64); | ||
158 | 158 | ||
159 | &function_begin_B("_vpaes_preheat"); | 159 | &function_begin_B("_vpaes_preheat"); |
160 | &add ($const,&DWP(0,"esp")); | 160 | &add ($const,&DWP(0,"esp")); |
@@ -762,9 +762,11 @@ $k_dsbo=0x2c0; # decryption sbox final output | |||
762 | &mov ($magic,0x30); | 762 | &mov ($magic,0x30); |
763 | &mov ($out,0); | 763 | &mov ($out,0); |
764 | 764 | ||
765 | &lea ($const,&DWP(&label("_vpaes_consts")."+0x30-".&label("pic_point"))); | 765 | &picsetup($const); |
766 | &picsymbol($const, &label("_vpaes_consts"), $const); | ||
767 | &lea ($const,&DWP(0x30,$const)) | ||
768 | |||
766 | &call ("_vpaes_schedule_core"); | 769 | &call ("_vpaes_schedule_core"); |
767 | &set_label("pic_point"); | ||
768 | 770 | ||
769 | &mov ("esp",&DWP(48,"esp")); | 771 | &mov ("esp",&DWP(48,"esp")); |
770 | &xor ("eax","eax"); | 772 | &xor ("eax","eax"); |
@@ -792,18 +794,22 @@ $k_dsbo=0x2c0; # decryption sbox final output | |||
792 | &and ($magic,32); | 794 | &and ($magic,32); |
793 | &xor ($magic,32); # nbist==192?0:32; | 795 | &xor ($magic,32); # nbist==192?0:32; |
794 | 796 | ||
795 | &lea ($const,&DWP(&label("_vpaes_consts")."+0x30-".&label("pic_point"))); | 797 | &picsetup($const); |
798 | &picsymbol($const, &label("_vpaes_consts"), $const); | ||
799 | &lea ($const,&DWP(0x30,$const)) | ||
800 | |||
796 | &call ("_vpaes_schedule_core"); | 801 | &call ("_vpaes_schedule_core"); |
797 | &set_label("pic_point"); | ||
798 | 802 | ||
799 | &mov ("esp",&DWP(48,"esp")); | 803 | &mov ("esp",&DWP(48,"esp")); |
800 | &xor ("eax","eax"); | 804 | &xor ("eax","eax"); |
801 | &function_end("${PREFIX}_set_decrypt_key"); | 805 | &function_end("${PREFIX}_set_decrypt_key"); |
802 | 806 | ||
803 | &function_begin("${PREFIX}_encrypt"); | 807 | &function_begin("${PREFIX}_encrypt"); |
804 | &lea ($const,&DWP(&label("_vpaes_consts")."+0x30-".&label("pic_point"))); | 808 | &picsetup($const); |
809 | &picsymbol($const, &label("_vpaes_consts"), $const); | ||
810 | &lea ($const,&DWP(0x30,$const)) | ||
811 | |||
805 | &call ("_vpaes_preheat"); | 812 | &call ("_vpaes_preheat"); |
806 | &set_label("pic_point"); | ||
807 | &mov ($inp,&wparam(0)); # inp | 813 | &mov ($inp,&wparam(0)); # inp |
808 | &lea ($base,&DWP(-56,"esp")); | 814 | &lea ($base,&DWP(-56,"esp")); |
809 | &mov ($out,&wparam(1)); # out | 815 | &mov ($out,&wparam(1)); # out |
@@ -820,9 +826,11 @@ $k_dsbo=0x2c0; # decryption sbox final output | |||
820 | &function_end("${PREFIX}_encrypt"); | 826 | &function_end("${PREFIX}_encrypt"); |
821 | 827 | ||
822 | &function_begin("${PREFIX}_decrypt"); | 828 | &function_begin("${PREFIX}_decrypt"); |
823 | &lea ($const,&DWP(&label("_vpaes_consts")."+0x30-".&label("pic_point"))); | 829 | &picsetup($const); |
830 | &picsymbol($const, &label("_vpaes_consts"), $const); | ||
831 | &lea ($const,&DWP(0x30,$const)) | ||
832 | |||
824 | &call ("_vpaes_preheat"); | 833 | &call ("_vpaes_preheat"); |
825 | &set_label("pic_point"); | ||
826 | &mov ($inp,&wparam(0)); # inp | 834 | &mov ($inp,&wparam(0)); # inp |
827 | &lea ($base,&DWP(-56,"esp")); | 835 | &lea ($base,&DWP(-56,"esp")); |
828 | &mov ($out,&wparam(1)); # out | 836 | &mov ($out,&wparam(1)); # out |
@@ -859,9 +867,11 @@ $k_dsbo=0x2c0; # decryption sbox final output | |||
859 | &mov (&DWP(8,"esp"),$const); # save ivp | 867 | &mov (&DWP(8,"esp"),$const); # save ivp |
860 | &mov ($out,$round); # $out works as $len | 868 | &mov ($out,$round); # $out works as $len |
861 | 869 | ||
862 | &lea ($const,&DWP(&label("_vpaes_consts")."+0x30-".&label("pic_point"))); | 870 | &picsetup($const); |
871 | &picsymbol($const, &label("_vpaes_consts"), $const); | ||
872 | &lea ($const,&DWP(0x30,$const)) | ||
873 | |||
863 | &call ("_vpaes_preheat"); | 874 | &call ("_vpaes_preheat"); |
864 | &set_label("pic_point"); | ||
865 | &cmp ($magic,0); | 875 | &cmp ($magic,0); |
866 | &je (&label("cbc_dec_loop")); | 876 | &je (&label("cbc_dec_loop")); |
867 | &jmp (&label("cbc_enc_loop")); | 877 | &jmp (&label("cbc_enc_loop")); |