diff --git a/.github/membrowse-targets.json b/.github/membrowse-targets.json index e0d1595a0c..3fc387f04f 100644 --- a/.github/membrowse-targets.json +++ b/.github/membrowse-targets.json @@ -7,6 +7,7 @@ "build_cmd": "test -f IDE/GCC-ARM/Header/user_settings.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat IDE/GCC-ARM/Header/user_settings.h; printf '#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFCRYPT_ONLY -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", "linker_vars": "" }, { @@ -14,9 +15,10 @@ "port": "gcc-arm", "board": "cortex-m4-min-ecc", "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", - "build_cmd": "test -f examples/configs/user_settings_min_ecc.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_min_ecc.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define USE_WOLF_ARM_STARTUP\\n#define WOLFSSL_USER_CURRTIME\\n#define WOLFSSL_GMTIME\\n#define USER_TICKS\\nextern unsigned long my_time(unsigned long* timer);\\n#define XTIME my_time\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "build_cmd": "test -f examples/configs/user_settings_min_ecc.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_min_ecc.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", "linker_vars": "" }, { @@ -24,9 +26,10 @@ "port": "gcc-arm", "board": "cortex-m4-tls12", "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", - "build_cmd": "test -f examples/configs/user_settings_tls12.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_tls12.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define USE_WOLF_ARM_STARTUP\\n#define WOLFSSL_USER_CURRTIME\\n#define WOLFSSL_GMTIME\\n#define USER_TICKS\\nextern unsigned long my_time(unsigned long* timer);\\n#define XTIME my_time\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "build_cmd": "test -f examples/configs/user_settings_tls12.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_tls12.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", "linker_vars": "" }, { @@ -34,9 +37,185 @@ "port": "gcc-arm", "board": "cortex-m4-baremetal", "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", - "build_cmd": "test -f examples/configs/user_settings_baremetal.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_baremetal.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define USE_WOLF_ARM_STARTUP\\n#define WOLFSSL_USER_CURRTIME\\n#define WOLFSSL_GMTIME\\n#define USER_TICKS\\nextern unsigned long my_time(unsigned long* timer);\\n#define XTIME my_time\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "build_cmd": "test -f examples/configs/user_settings_baremetal.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_baremetal.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m0plus", + "port": "gcc-arm", + "board": "cortex-m0plus", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_min_ecc.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_min_ecc.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen ARCHFLAGS='-mcpu=cortex-m0plus -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP' CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m0plus -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m3", + "port": "gcc-arm", + "board": "cortex-m3", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_tls12.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_tls12.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen ARCHFLAGS='-mcpu=cortex-m3 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP' CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m3 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m7", + "port": "gcc-arm", + "board": "cortex-m7", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f IDE/GCC-ARM/Header/user_settings.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat IDE/GCC-ARM/Header/user_settings.h; printf '#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen ARCHFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP' CFLAGS_EXTRA='-Wno-cpp -DWOLFCRYPT_ONLY -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-tls13", + "port": "gcc-arm", + "board": "cortex-m4-tls13", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_tls13.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_tls13.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-dtls13", + "port": "gcc-arm", + "board": "cortex-m4-dtls13", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_dtls13.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_dtls13.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen SRC_LD=-T./linker_large.ld CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20040000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker_large.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-pq", + "port": "gcc-arm", + "board": "cortex-m4-pq", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_pq.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_pq.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen SRC_LD=-T./linker_large.ld CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20040000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker_large.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-rsa-only", + "port": "gcc-arm", + "board": "cortex-m4-rsa-only", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_rsa_only.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_rsa_only.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen SRC_LD=-T./linker_large.ld CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20040000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker_large.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-pkcs7", + "port": "gcc-arm", + "board": "cortex-m4-pkcs7", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_pkcs7.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_pkcs7.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-openssl-compat", + "port": "gcc-arm", + "board": "cortex-m4-openssl-compat", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_openssl_compat.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_openssl_compat.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define SMALL_SESSION_CACHE\\n#undef HAVE_OCSP\\n#undef HAVE_CERTIFICATE_STATUS_REQUEST\\n#undef HAVE_CERTIFICATE_STATUS_REQUEST_V2\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define USER_TICKS\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen SRC_LD=-T./linker_large.ld CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20040000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker_large.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-sp-math", + "port": "gcc-arm", + "board": "cortex-m4-sp-math", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_min_ecc.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_min_ecc.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n#define WOLFSSL_SP_MATH\\n#define WOLFSSL_SP_NO_ASM\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m4-crypto-only", + "port": "gcc-arm", + "board": "cortex-m4-crypto-only", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "mkdir -p IDE/GCC-ARM/Header-gen && printf '#ifndef WOLFSSL_USER_SETTINGS_H\\n#define WOLFSSL_USER_SETTINGS_H\\n#define WOLFCRYPT_ONLY\\n#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define HAVE_AESGCM\\n#define HAVE_AES_DECRYPT\\n#define HAVE_ECC\\n#define HAVE_CHACHA\\n#define HAVE_POLY1305\\n#define WOLFSSL_SHA512\\n#define WOLFSSL_SHA384\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n#endif\\n' > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK -DWOLFCRYPT_ONLY' LDFLAGS='-mcpu=cortex-m4 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m7-tls13", + "port": "gcc-arm", + "board": "cortex-m7-tls13", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_tls13.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_tls13.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen ARCHFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP' CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20010000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "gcc-arm-cortex-m7-pq", + "port": "gcc-arm", + "board": "cortex-m7-pq", + "apt_packages": "gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib", + "build_cmd": "test -f examples/configs/user_settings_pq.h && mkdir -p IDE/GCC-ARM/Header-gen && { cat examples/configs/user_settings_pq.h; printf '#define WOLFSSL_GENERAL_ALIGNMENT 4\\n#define SINGLE_THREADED\\n#define WOLFSSL_SMALL_STACK\\n#define NO_FILESYSTEM\\n#define NO_WRITEV\\n#define NO_MAIN_DRIVER\\n#define NO_DEV_RANDOM\\n#define BENCH_EMBEDDED\\n#define USE_CERT_BUFFERS_256\\n#define USE_CERT_BUFFERS_2048\\n#define WOLFSSL_IGNORE_FILE_WARN\\n#define WOLFSSL_USER_IO\\n#define WOLFSSL_USER_CURRTIME\\n#define TIME_OVERRIDES\\n#define USER_TICKS\\n#define XTIME my_time\\n#define XGMTIME my_gmtime\\n#define CUSTOM_RAND_TYPE unsigned int\\nextern unsigned int my_rng_seed_gen(void);\\n#undef CUSTOM_RAND_GENERATE\\n#define CUSTOM_RAND_GENERATE my_rng_seed_gen\\n#define HAVE_HASHDRBG\\n#define NO_CRYPT_TEST\\n#define NO_CRYPT_BENCHMARK\\n'; } > IDE/GCC-ARM/Header-gen/user_settings.h && cd IDE/GCC-ARM && make -f Makefile.test TOOLCHAIN=arm-none-eabi- FIPS=0 USER_SETTINGS_DIR=./Header-gen ARCHFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP' SRC_LD=-T./linker_large.ld CFLAGS_EXTRA='-Wno-cpp -DWOLFSSL_NO_SOCK' LDFLAGS='-mcpu=cortex-m7 -mthumb -mabi=aapcs --specs=nosys.specs --specs=nano.specs -Wl,-Map=./Build/WolfCryptTest.map -Wl,-ereset_handler -flto -Wl,--defsym=__stack_process_end__=0x20040000'", + "elf": "IDE/GCC-ARM/Build/WolfCryptTest.elf", + "ld": "IDE/GCC-ARM/linker_large.ld", + "map_file": "IDE/GCC-ARM/Build/WolfCryptTest.map", + "linker_vars": "" + }, + { + "target_name": "stm32-sim-stm32h753", + "port": "stm32-sim", + "board": "stm32h753", + "apt_packages": "build-essential ca-certificates cmake ninja-build python3 git gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib wget unzip", + "build_cmd": "if [ ! -d simulators ]; then git clone --depth 1 https://github.com/wolfSSL/simulators simulators; fi && sudo mkdir -p /opt && if [ ! -d /opt/cmsis-device-h7 ]; then sudo git clone --depth 1 https://github.com/STMicroelectronics/cmsis-device-h7.git /opt/cmsis-device-h7; fi && if [ ! -d /opt/CMSIS_5 ]; then sudo git clone --depth 1 https://github.com/ARM-software/CMSIS_5.git /opt/CMSIS_5; fi && if [ ! -d /opt/STM32CubeH7 ]; then (sudo git clone --depth 1 --branch v1.11.2 --recurse-submodules https://github.com/STMicroelectronics/STM32CubeH7.git /opt/STM32CubeH7 || (sudo git clone --depth 1 --branch v1.11.2 https://github.com/STMicroelectronics/STM32CubeH7.git /opt/STM32CubeH7 && cd /opt/STM32CubeH7 && sudo git submodule update --init --recursive --depth 1)); fi && sudo rm -rf /opt/firmware-stm32sim-h7 /opt/wolfssl-stm32sim && sudo mkdir -p /opt/firmware-stm32sim-h7 && sudo cp -r simulators/STM32Sim/firmware/wolfcrypt-test-h7/. /opt/firmware-stm32sim-h7/ && sudo cp /opt/firmware-stm32sim-h7/stm32h7xx_hal_conf.h /opt/STM32CubeH7/Drivers/STM32H7xx_HAL_Driver/Inc/ && sudo cp -r . /opt/wolfssl-stm32sim && sudo rm -f /opt/wolfssl-stm32sim/config.h && cd /opt/firmware-stm32sim-h7 && sudo cmake -G Ninja -DWOLFSSL_USER_SETTINGS=ON -DUSER_SETTINGS_FILE=/opt/firmware-stm32sim-h7/user_settings.h -DCMAKE_TOOLCHAIN_FILE=/opt/firmware-stm32sim-h7/toolchain-arm-none-eabi.cmake -DCMAKE_BUILD_TYPE=Release -DWOLFSSL_CRYPT_TESTS=OFF -DWOLFSSL_EXAMPLES=OFF -DWOLFSSL_ROOT=/opt/wolfssl-stm32sim -B /opt/firmware-stm32sim-h7/build -S /opt/firmware-stm32sim-h7 && sudo cmake --build /opt/firmware-stm32sim-h7/build && sudo cp /opt/firmware-stm32sim-h7/build/wolfcrypt_test.elf $GITHUB_WORKSPACE/wolfcrypt_test.elf", + "elf": "wolfcrypt_test.elf", + "ld": "simulators/STM32Sim/firmware/wolfcrypt-test-h7/stm32h753.ld", + "linker_vars": "" + }, + { + "target_name": "linuxkm-standard", + "port": "linuxkm", + "board": "linux-kernel-module-standard", + "apt_packages": "build-essential autoconf automake libtool linux-headers-$(uname -r)", + "build_cmd": "./autogen.sh && ./configure --with-linux-source=/lib/modules/$(uname -r)/build EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-lkcapi-register=all --enable-all --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --enable-dual-alg-certs --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-testcert --enable-all-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS='-Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1' --with-max-rsa-bits=16384 && make -j$(nproc) KERNEL_EXTRA_CFLAGS_REMOVE=-pg FORCE_NO_MODULE_SIG=1", + "elf": "linuxkm/libwolfssl.ko", + "ld": "linuxkm/wolfcrypt.lds", + "linker_vars": "", + "apt_cache": "false" + }, + { + "target_name": "linuxkm-pie", + "port": "linuxkm", + "board": "linux-kernel-module-pie", + "apt_packages": "build-essential autoconf automake libtool linux-headers-$(uname -r)", + "build_cmd": "./autogen.sh && ./configure --with-linux-source=/lib/modules/$(uname -r)/build EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-pie --enable-reproducible-build --enable-linuxkm-lkcapi-register=all --enable-all-crypto --enable-cryptonly --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --disable-sp-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS='-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -DDEBUG_LINUXKM_PIE_SUPPORT -Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1' --with-max-rsa-bits=16384 && make -j$(nproc) KERNEL_EXTRA_CFLAGS_REMOVE=-pg FORCE_NO_MODULE_SIG=1", + "elf": "linuxkm/libwolfssl.ko", + "ld": "linuxkm/wolfcrypt.lds", + "linker_vars": "", + "apt_cache": "false" } ] diff --git a/.github/scripts/zephyr-4.x/zephyr-test.sh b/.github/scripts/zephyr-4.x/zephyr-test.sh index c65e6950f7..fa0e827d4d 100755 --- a/.github/scripts/zephyr-4.x/zephyr-test.sh +++ b/.github/scripts/zephyr-4.x/zephyr-test.sh @@ -112,6 +112,9 @@ LOG_DIR="${SCRIPT_DIR}/logs" mkdir -p "${LOG_DIR}" TIMESTAMP=$(date +%Y%m%d_%H%M%S) LOG_FILE="${LOG_DIR}/${BOARD_SLUG}_${TIMESTAMP}.log" +ARTIFACTS_DIR="${SCRIPT_DIR}/artifacts/${BOARD_SLUG}-${SAMPLE_NAME}" +mkdir -p "${ARTIFACTS_DIR}" +chmod 0755 "${ARTIFACTS_DIR}" echo "==> wolfSSL repo: ${WOLFSSL_REPO}" echo "==> wolfSSL branch: ${WOLFSSL_BRANCH}" @@ -256,6 +259,23 @@ else echo "" echo "==> [container] Build succeeded!" + # Stage Membrowse-relevant artifacts on the host-mounted volume. + # /artifacts is bind-mounted by the host wrapper; if it isn't writable + # (e.g. interactive runs without the mount), skip silently. + if [[ -d /artifacts && -w /artifacts ]]; then + BUILD_OUT="${WORKDIR}/zephyrproject/build/zephyr" + if [[ -f "${BUILD_OUT}/zephyr.elf" ]]; then + cp "${BUILD_OUT}/zephyr.elf" /artifacts/zephyr.elf + fi + if [[ -f "${BUILD_OUT}/linker.cmd" ]]; then + cp "${BUILD_OUT}/linker.cmd" /artifacts/linker.cmd + fi + # Map file enables Membrowse library/object attribution + if [[ -f "${BUILD_OUT}/zephyr.map" ]]; then + cp "${BUILD_OUT}/zephyr.map" /artifacts/zephyr.map + fi + fi + # Run the app for emulator targets and watch for completion case "${BOARD_TARGET}" in native_sim*|qemu_*) @@ -342,6 +362,7 @@ docker rm -f "${CONTAINER_NAME}" 2>/dev/null || true DOCKER_ARGS=( --name "${CONTAINER_NAME}" --rm + -v "${ARTIFACTS_DIR}:/artifacts" ) if [[ "$INTERACTIVE" == "1" ]]; then diff --git a/.github/workflows/linuxkm.yml b/.github/workflows/linuxkm.yml index e785cf56cb..c2a7ff9242 100644 --- a/.github/workflows/linuxkm.yml +++ b/.github/workflows/linuxkm.yml @@ -19,7 +19,8 @@ jobs: matrix: config: [ 'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-lkcapi-register=all --enable-all --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --enable-dual-alg-certs --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-testcert --enable-all-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS="-Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1" --with-max-rsa-bits=16384', - 'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-pie --enable-reproducible-build --enable-linuxkm-lkcapi-register=all --enable-all-crypto --enable-cryptonly --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --disable-sp-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -DDEBUG_LINUXKM_PIE_SUPPORT -Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1" --with-max-rsa-bits=16384' + 'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-pie --enable-reproducible-build --enable-linuxkm-lkcapi-register=all --enable-all-crypto --enable-cryptonly --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --disable-sp-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -DDEBUG_LINUXKM_PIE_SUPPORT -Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1" --with-max-rsa-bits=16384', + 'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-tls13 --enable-dtls --enable-dtls13' ] name: build module if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }} @@ -55,3 +56,15 @@ jobs: make -j 4 KERNEL_EXTRA_CFLAGS_REMOVE=-pg FORCE_NO_MODULE_SIG=1 || $(exit 11) ls -l linuxkm/libwolfssl.ko || $(exit 12) echo "Successful linuxkm build." + + - name: Verify DTLS 1.3 symbols are exported (when WOLFSSL_DTLS13 is configured) + run: | + if grep -q '^#define WOLFSSL_DTLS13' wolfssl/options.h; then + echo "WOLFSSL_DTLS13 defined; checking GPL exports in libwolfssl.ko..." + objdump -t linuxkm/libwolfssl.ko \ + | grep -qE '__ksymtab_wolfDTLSv1_3_(client|server)_method$' \ + || { echo "::error::DTLS 1.3 entry points not exported from libwolfssl.ko"; exit 13; } + echo "DTLS 1.3 export check: PASS" + else + echo "WOLFSSL_DTLS13 not defined for this matrix entry; skipping symbol check." + fi diff --git a/.github/workflows/membrowse-comment.yml b/.github/workflows/membrowse-comment.yml new file mode 100644 index 0000000000..1357bca7d9 --- /dev/null +++ b/.github/workflows/membrowse-comment.yml @@ -0,0 +1,32 @@ +name: Membrowse Comment + +on: + workflow_run: + workflows: [Membrowse Memory Report] + types: + - completed + +jobs: + post-comment: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + # Run the comment job even if some of the builds fail + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion != 'cancelled' + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Post Membrowse PR comment + if: ${{ env.MEMBROWSE_API_KEY != '' }} + uses: membrowse/membrowse-action/comment-action@v1 + with: + api_key: ${{ secrets.MEMBROWSE_API_KEY }} + commit: ${{ github.event.workflow_run.head_sha }} + env: + MEMBROWSE_API_KEY: ${{ secrets.MEMBROWSE_API_KEY }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/membrowse-onboard.yml b/.github/workflows/membrowse-onboard.yml index 503942b75f..978a23c132 100644 --- a/.github/workflows/membrowse-onboard.yml +++ b/.github/workflows/membrowse-onboard.yml @@ -11,6 +11,9 @@ on: jobs: load-targets: + # Only run from the wolfssl org to avoid burning forks' CI minutes + # and reporting fork builds to the membrowse backend. + if: github.repository_owner == 'wolfssl' runs-on: ubuntu-24.04 timeout-minutes: 10 outputs: @@ -25,12 +28,13 @@ jobs: onboard: needs: load-targets + if: github.repository_owner == 'wolfssl' runs-on: ubuntu-24.04 - timeout-minutes: 10 + timeout-minutes: 30 strategy: fail-fast: false matrix: - include: ${{ fromJson(needs.load-targets.outputs.matrix) }} + include: ${{ fromJson(needs.load-targets.outputs.matrix || '[]') }} steps: - name: Checkout repository @@ -43,6 +47,7 @@ jobs: uses: ./.github/actions/install-apt-deps with: packages: ${{ matrix.apt_packages }} + cache: ${{ matrix.apt_cache || 'true' }} - name: Run Membrowse Onboard Action uses: membrowse/membrowse-action/onboard-action@v1 diff --git a/.github/workflows/membrowse-report.yml b/.github/workflows/membrowse-report.yml index 40a0885183..201fbed2e8 100644 --- a/.github/workflows/membrowse-report.yml +++ b/.github/workflows/membrowse-report.yml @@ -1,20 +1,21 @@ name: Membrowse Memory Report -# Runs nightly instead of per-PR - the report is for trend tracking, not -# gating individual PRs, and the build matrix is too heavy to run on every -# push. Use workflow_dispatch to trigger an ad-hoc run. - on: - schedule: - - cron: '0 4 * * *' # daily at 04:00 UTC + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + push: + branches: [master] workflow_dispatch: concurrency: - group: ${{ github.workflow }} - cancel-in-progress: false + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} jobs: load-targets: + # Only run from the wolfssl org to avoid burning forks' CI minutes + # and reporting fork builds to the membrowse backend. + if: github.repository_owner == 'wolfssl' && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) runs-on: ubuntu-24.04 timeout-minutes: 10 outputs: @@ -27,28 +28,68 @@ jobs: id: set-matrix run: echo "matrix=$(jq -c '.' .github/membrowse-targets.json)" >> $GITHUB_OUTPUT - analyze: - needs: load-targets + check-changes: + if: github.repository_owner == 'wolfssl' && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) runs-on: ubuntu-24.04 - timeout-minutes: 10 + timeout-minutes: 5 + outputs: + needs_build: ${{ steps.filter.outputs.code == 'true' || github.event_name == 'workflow_dispatch' }} + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Detect binary-affecting changes + id: filter + if: github.event_name == 'pull_request' || github.event_name == 'push' + uses: dorny/paths-filter@v4 + with: + predicate-quantifier: every + filters: | + code: + - '!**.md' + - '!**/README*' + - '!doc/**' + - '!AUTHORS' + - '!COPYING*' + - '!LICENSE*' + - '!LICENSING' + - '!INSTALL' + - '!ChangeLog*' + - '!SCRIPTS-LIST' + - '!.gitignore' + - '!.editorconfig' + - '!.codespellexcludelines' + - '!.cyignore' + - '!.wolfssl_known_macro_extras' + - '!.github/ISSUE_TEMPLATE/**' + - '!.github/PULL_REQUEST_TEMPLATE.md' + + analyze: + needs: [load-targets, check-changes] + if: github.repository_owner == 'wolfssl' && (github.event_name != 'pull_request' || needs.check-changes.outputs.needs_build == 'true') + runs-on: ubuntu-24.04 + timeout-minutes: 30 strategy: fail-fast: false matrix: - include: ${{ fromJson(needs.load-targets.outputs.matrix) }} + include: ${{ fromJson(needs.load-targets.outputs.matrix || '[]') }} steps: - name: Checkout repository uses: actions/checkout@v5 with: - fetch-depth: 0 - submodules: recursive + fetch-depth: 2 + submodules: ${{ needs.check-changes.outputs.needs_build == 'true' && 'recursive' || 'false' }} - name: Install packages + if: needs.check-changes.outputs.needs_build == 'true' uses: ./.github/actions/install-apt-deps with: packages: ${{ matrix.apt_packages }} + cache: ${{ matrix.apt_cache || 'true' }} - name: Build firmware + if: needs.check-changes.outputs.needs_build == 'true' run: ${{ matrix.build_cmd }} - name: Run Membrowse PR Action @@ -56,9 +97,11 @@ jobs: uses: membrowse/membrowse-action@v1 with: target_name: ${{ matrix.target_name }} - elf: ${{ matrix.elf }} - ld: ${{ matrix.ld }} + elf: ${{ needs.check-changes.outputs.needs_build == 'true' && matrix.elf || '' }} + ld: ${{ needs.check-changes.outputs.needs_build == 'true' && matrix.ld || '' }} + map_file: ${{ needs.check-changes.outputs.needs_build == 'true' && matrix.map_file || '' }} linker_vars: ${{ matrix.linker_vars }} api_key: ${{ secrets.MEMBROWSE_API_KEY }} api_url: ${{ vars.MEMBROWSE_API_URL }} + identical: ${{ needs.check-changes.outputs.needs_build != 'true' }} verbose: INFO diff --git a/.github/workflows/membrowse-zephyr.yml b/.github/workflows/membrowse-zephyr.yml new file mode 100644 index 0000000000..993581edc0 --- /dev/null +++ b/.github/workflows/membrowse-zephyr.yml @@ -0,0 +1,115 @@ +name: Membrowse Zephyr Report + +# Triggered after the heavy Zephyr 4.x test workflow completes. Pulls the +# pre-built zephyr.elf, zephyr.map and linker.cmd artifacts staged by +# zephyr-test.sh and feeds them to the Membrowse memory-tracking service. +# This avoids duplicating the (slow) Zephyr build inside the Membrowse +# matrix. + +on: + workflow_run: + workflows: [Zephyr 4.x tests] + types: + - completed + +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_sha }} + cancel-in-progress: true + +jobs: + analyze: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + # Only run from the wolfssl org to avoid burning forks' CI minutes + # and reporting fork builds to the membrowse backend. + if: > + github.event.workflow_run.conclusion == 'success' && + github.repository_owner == 'wolfssl' + permissions: + contents: read + actions: read + strategy: + fail-fast: false + matrix: + include: + - target_name: zephyr-native_sim + artifact: membrowse-zephyr-native_sim + - target_name: zephyr-frdm_rw612 + artifact: membrowse-zephyr-frdm_rw612 + steps: + # Check out the commit the Zephyr workflow actually built so Membrowse + # attributes the report to the right commit. Only the last 2 commits + # are needed (current + parent) to resolve the base for comparison. + - name: Checkout repository + uses: actions/checkout@v5 + with: + ref: ${{ github.event.workflow_run.head_sha }} + fetch-depth: 2 + + - name: Download Zephyr build artifact + id: download + uses: actions/download-artifact@v4 + with: + name: ${{ matrix.artifact }} + path: zephyr-artifacts/${{ matrix.target_name }} + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + continue-on-error: true + + - name: Verify artifact present + id: verify + run: | + ELF="zephyr-artifacts/${{ matrix.target_name }}/zephyr.elf" + LD="zephyr-artifacts/${{ matrix.target_name }}/linker.cmd" + MAP="zephyr-artifacts/${{ matrix.target_name }}/zephyr.map" + if [[ -f "$ELF" && -f "$LD" ]]; then + echo "have_artifacts=true" >> "$GITHUB_OUTPUT" + else + echo "have_artifacts=false" >> "$GITHUB_OUTPUT" + echo "::warning::Membrowse artifact for ${{ matrix.target_name }} not found; the matching cell of zephyr-4.x.yml may have been skipped or excluded." + fi + # The map file is optional; it enables library/object attribution. + if [[ -f "$MAP" ]]; then + echo "map_file=$MAP" >> "$GITHUB_OUTPUT" + else + echo "map_file=" >> "$GITHUB_OUTPUT" + fi + + - name: Run Membrowse PR Action + if: steps.verify.outputs.have_artifacts == 'true' + uses: membrowse/membrowse-action@v1 + with: + target_name: ${{ matrix.target_name }} + elf: zephyr-artifacts/${{ matrix.target_name }}/zephyr.elf + ld: zephyr-artifacts/${{ matrix.target_name }}/linker.cmd + map_file: ${{ steps.verify.outputs.map_file }} + linker_vars: "" + api_key: ${{ secrets.MEMBROWSE_API_KEY }} + api_url: ${{ vars.MEMBROWSE_API_URL }} + verbose: INFO + + # Refresh the consolidated Membrowse PR comment after the Zephyr targets + # have been submitted, mirroring membrowse-comment.yml. + post-comment: + needs: analyze + runs-on: ubuntu-24.04 + timeout-minutes: 10 + if: > + github.event.workflow_run.event == 'pull_request' && + github.repository_owner == 'wolfssl' + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Post Membrowse PR comment + if: ${{ env.MEMBROWSE_API_KEY != '' }} + uses: membrowse/membrowse-action/comment-action@v1 + with: + api_key: ${{ secrets.MEMBROWSE_API_KEY }} + commit: ${{ github.event.workflow_run.head_sha }} + env: + MEMBROWSE_API_KEY: ${{ secrets.MEMBROWSE_API_KEY }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/os-check.yml b/.github/workflows/os-check.yml index 5c1957e4da..1519bd0c88 100644 --- a/.github/workflows/os-check.yml +++ b/.github/workflows/os-check.yml @@ -117,14 +117,14 @@ jobs: # variants of mod_exp__nb / RSA / DH wrappers. '--enable-curve25519=nonblock --enable-ecc=nonblock --enable-rsa=nonblock --enable-dh=nonblock --enable-sp=yes,nonblock CPPFLAGS="-DWOLFSSL_PUBLIC_MP -DWOLFSSL_DEBUG_NONBLOCK -DRSA_LOW_MEM -DSP_WORD_SIZE=32"', '--enable-certreq --enable-certext --enable-certgen --disable-secure-renegotiation-info CPPFLAGS="-DNO_TLS"', - # Minimal DTLS 1.3 client-only build. The SHA-224/384/512/3 - # disables are deliberately omitted: --disable-sha384 alone - # trips a pre-existing wolfSSL bug in - # test_tls13_duplicate_extension (reproducible on clean master). + # Minimal DTLS 1.3 client-only build with the SHA-224/384/512/3 + # hash families disabled. SHA-256 (used by TLS_AES_128_GCM_SHA256) + # and SHA-1 remain enabled. '--enable-dtls13 --disable-tlsv12 --disable-oldtls --disable-rsa --disable-dh --disable-aescbc --disable-aesecb --disable-md5 --disable-chacha --disable-poly1305 --disable-errorstrings --disable-asn-print --disable-eccshamir --disable-base64encode --disable-coding --disable-sni + --disable-sha224 --disable-sha384 --disable-sha512 --disable-sha3 --enable-aesgcm=small --enable-sp-math --enable-sp=smallec256 --disable-sp-asm CPPFLAGS=''-DNO_WOLFSSL_SERVER -DWOLFSSL_NO_TLS12 -DNO_SESSION_CACHE -DWOLFSSL_AES_NO_UNROLL -DUSE_SLOW_SHA256 -DWOLFSSL_NO_ASYNC_IO diff --git a/.github/workflows/pic32mz-sim.yml b/.github/workflows/pic32mz-sim.yml new file mode 100644 index 0000000000..51625cd43a --- /dev/null +++ b/.github/workflows/pic32mz-sim.yml @@ -0,0 +1,86 @@ +name: PIC32MZ simulator test + +# START OF COMMON SECTION +on: + push: + branches: [ 'master', 'main', 'release/**' ] + pull_request: + branches: [ '*' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +# END OF COMMON SECTION + +# Build the PIC32MZ software simulator (https://github.com/wolfSSL/simulators, +# PIC32MZSim/ subdirectory) and run the wolfCrypt test suite on emulated +# PIC32MZ EC (no FPU, CE ignores OUT_SWAP) and EF (FPU + OUT_SWAP) parts, +# through both the direct-register PIC32 port and the MPLAB Harmony 3 driver +# port. +# +# Like stm32-sim.yml, the Dockerfiles read wolfSSL from /opt/wolfssl at +# runtime via a bind mount, so no Dockerfile patching is required - the PR +# checkout is mounted directly. + +jobs: + pic32mz_sim: + name: wolfCrypt on PIC32MZ ${{ matrix.chip_label }} (${{ matrix.port_label }}) + if: github.repository_owner == 'wolfssl' + runs-on: ubuntu-24.04 + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: + - port_label: direct + chip_label: EC + dockerfile: Dockerfile.wolfcrypt-direct + image_tag: pic32mz-wolfcrypt-direct:ci + script: run-wolfcrypt-direct-ec.sh + cache_scope: pic32mz-direct + - port_label: direct + chip_label: EF + dockerfile: Dockerfile.wolfcrypt-direct + image_tag: pic32mz-wolfcrypt-direct:ci + script: run-wolfcrypt-direct-ef.sh + cache_scope: pic32mz-direct + - port_label: harmony + chip_label: EC + dockerfile: Dockerfile.wolfcrypt-harmony + image_tag: pic32mz-wolfcrypt-harmony:ci + script: run-wolfcrypt-harmony-ec.sh + cache_scope: pic32mz-harmony + - port_label: harmony + chip_label: EF + dockerfile: Dockerfile.wolfcrypt-harmony + image_tag: pic32mz-wolfcrypt-harmony:ci + script: run-wolfcrypt-harmony-ef.sh + cache_scope: pic32mz-harmony + steps: + - name: Checkout wolfSSL (PR source) + uses: actions/checkout@v4 + with: + path: wolfssl + + - name: Clone PIC32MZ simulator + run: git clone --depth 1 https://github.com/wolfSSL/simulators simulators + + - uses: docker/setup-buildx-action@v3 + + - name: Build ${{ matrix.image_tag }} image + uses: docker/build-push-action@v5 + with: + context: simulators/PIC32MZSim + file: simulators/PIC32MZSim/${{ matrix.dockerfile }} + push: false + load: true + tags: ${{ matrix.image_tag }} + cache-from: type=gha,scope=${{ matrix.cache_scope }} + cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }} + + - name: Run wolfCrypt tests on PIC32MZ ${{ matrix.chip_label }} (${{ matrix.port_label }}) + run: | + docker run --rm \ + -v "${{ github.workspace }}/wolfssl:/opt/wolfssl:ro" \ + ${{ matrix.image_tag }} \ + /app/scripts/${{ matrix.script }} diff --git a/.github/workflows/zephyr-4.x.yml b/.github/workflows/zephyr-4.x.yml index ac5358dff7..afbbde5ebf 100644 --- a/.github/workflows/zephyr-4.x.yml +++ b/.github/workflows/zephyr-4.x.yml @@ -79,3 +79,22 @@ jobs: path: .github/scripts/zephyr-4.x/logs/ retention-days: 5 if-no-files-found: ignore + + # Stage Membrowse artifacts only for the cells we want to track on the + # Membrowse dashboard. Keep this tight to avoid duplicate target_name + # entries on the dashboard and unnecessary artifact uploads. + - name: Upload Membrowse artifacts (selected cells only) + if: > + success() && + matrix.zephyr-ref == 'v4.3.0' && + matrix.sample == 'wolfssl_test' && + matrix.extra-conf == '' + uses: actions/upload-artifact@v4 + with: + name: membrowse-zephyr-${{ matrix.board == 'native_sim' && 'native_sim' || 'frdm_rw612' }} + path: | + .github/scripts/zephyr-4.x/artifacts/${{ matrix.board == 'native_sim' && 'native_sim' || 'frdm_rw612-rw612' }}-wolfssl_test/zephyr.elf + .github/scripts/zephyr-4.x/artifacts/${{ matrix.board == 'native_sim' && 'native_sim' || 'frdm_rw612-rw612' }}-wolfssl_test/linker.cmd + .github/scripts/zephyr-4.x/artifacts/${{ matrix.board == 'native_sim' && 'native_sim' || 'frdm_rw612-rw612' }}-wolfssl_test/zephyr.map + if-no-files-found: warn + retention-days: 1 diff --git a/.wolfssl_known_macro_extras b/.wolfssl_known_macro_extras index c4a2620543..fe9146dca7 100644 --- a/.wolfssl_known_macro_extras +++ b/.wolfssl_known_macro_extras @@ -741,10 +741,10 @@ WOLFSSL_CONTIKI WOLFSSL_CRL_ALLOW_MISSING_CDP WOLFSSL_DISABLE_EARLY_SANITY_CHECKS WOLFSSL_DRBG_SHA256 +WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID WOLFSSL_DTLS_DISALLOW_FUTURE WOLFSSL_DTLS_RECORDS_CAN_SPAN_DATAGRAMS WOLFSSL_DTLS_RESEND_ONLY_TIMEOUT -WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID WOLFSSL_DUMP_MEMIO_STREAM WOLFSSL_DUP_CERTPOL WOLFSSL_EARLY_DATA_NO_ANTI_REPLAY @@ -869,6 +869,7 @@ WOLFSSL_PASSTHRU_ERR WOLFSSL_PB WOLFSSL_PEER_ADDRESS_CHANGES WOLFSSL_PKCS11_RW_TOKENS +WOLFSSL_PPC64_ASM_AES_NO_HARDEN WOLFSSL_PRCONNECT_PRO WOLFSSL_PREFIX WOLFSSL_PSA_NO_AES @@ -888,6 +889,7 @@ WOLFSSL_RENESAS_RZN2L WOLFSSL_RENESAS_TLS WOLFSSL_RENESAS_TSIP_IAREWRX WOLFSSL_REQUIRE_TCA +WOLFSSL_RISCV_ASM_NO_UNALIGNED WOLFSSL_RNG_USE_FULL_SEED WOLFSSL_RSA_CHECK_D_ON_DECRYPT WOLFSSL_RSA_DECRYPT_TO_0_LEN @@ -976,6 +978,7 @@ XSECURE_CACHE_DISABLE _ABI64 _ABIO64 _ARCH_PPC64 +_ARCH_PWR8 _COMPILER_VERSION _INTPTR_T_DECLARED _LINUX_REFCOUNT_H @@ -1004,6 +1007,7 @@ __32MZ2048ECM144__ __32MZ2048EFM144__ __ANDROID__ __APPLE__ +__ARCH_PWR8 __ARCH_STRCASECMP_NO_REDIRECT __ARCH_STRCMP_NO_REDIRECT __ARCH_STRNCASECMP_NO_REDIRECT diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a2c0e9750..217a9e1574 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2942,11 +2942,14 @@ if(WOLFSSL_EXAMPLES) tests/api/test_mldsa_legacy.c tests/api/test_slhdsa.c tests/api/test_signature.c + tests/api/test_lms_xmss.c tests/api/test_dtls.c + tests/api/test_dtls13.c tests/api/test_ocsp.c tests/api/test_evp.c tests/api/test_tls_ext.c tests/api/test_tls.c + tests/api/test_session.c tests/api/test_x509.c tests/api/test_asn.c tests/api/test_pkcs7.c diff --git a/IDE/GCC-ARM/Header/user_settings.h b/IDE/GCC-ARM/Header/user_settings.h index a3a1561b0e..971180c9bd 100644 --- a/IDE/GCC-ARM/Header/user_settings.h +++ b/IDE/GCC-ARM/Header/user_settings.h @@ -469,10 +469,10 @@ extern "C" { /* Override Current Time */ /* Allows custom "custom_time()" function to be used for benchmark */ #define WOLFSSL_USER_CURRTIME -#define WOLFSSL_GMTIME +#define TIME_OVERRIDES #define USER_TICKS -extern unsigned long my_time(unsigned long* timer); #define XTIME my_time +#define XGMTIME my_gmtime /* ------------------------------------------------------------------------- */ @@ -656,4 +656,3 @@ extern unsigned int my_rng_seed_gen(void); #endif #endif /* WOLFSSL_USER_SETTINGS_H */ - diff --git a/IDE/GCC-ARM/Makefile.common b/IDE/GCC-ARM/Makefile.common index 742b350df7..90603e215b 100644 --- a/IDE/GCC-ARM/Makefile.common +++ b/IDE/GCC-ARM/Makefile.common @@ -89,6 +89,8 @@ SRC_C += ../../src/sniffer.c SRC_C += ../../src/ssl.c SRC_C += ../../src/tls.c SRC_C += ../../src/tls13.c +SRC_C += ../../src/dtls.c +SRC_C += ../../src/dtls13.c SRC_C += ../../src/wolfio.c # wolfCrypt Core (FIPS) @@ -185,6 +187,9 @@ SRC_C += ../../wolfcrypt/src/dsa.c SRC_C += ../../wolfcrypt/src/md2.c SRC_C += ../../wolfcrypt/src/md4.c SRC_C += ../../wolfcrypt/src/ripemd.c +SRC_C += ../../wolfcrypt/src/wc_mldsa.c +SRC_C += ../../wolfcrypt/src/wc_mlkem.c +SRC_C += ../../wolfcrypt/src/wc_mlkem_poly.c FILENAMES_C = $(notdir $(SRC_C)) diff --git a/IDE/GCC-ARM/Source/wolf_main.c b/IDE/GCC-ARM/Source/wolf_main.c index 57e5d224b7..8b6f05da40 100644 --- a/IDE/GCC-ARM/Source/wolf_main.c +++ b/IDE/GCC-ARM/Source/wolf_main.c @@ -27,6 +27,9 @@ #include #include #include +#ifdef NO_ASN_TIME + #include +#endif /* TIME CODE */ @@ -37,21 +40,103 @@ static int hw_get_time_sec(void) { #warning Must implement your own time source if validating certificates - return ++gTimeMs; + return ++gTimeMs; +} + +static int IsLeapYear(int year) +{ + return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)); } /* This is used by wolfCrypt asn.c for cert time checking */ -unsigned long my_time(unsigned long* timer) +time_t my_time(time_t* timer) { - (void)timer; - return hw_get_time_sec(); + time_t curTime = (time_t)hw_get_time_sec(); + + if (timer != NULL) { + *timer = curTime; + } + + return curTime; +} + +struct tm* my_gmtime(const time_t* timer, struct tm* tmp) +{ + static struct tm staticTime; + static const unsigned char daysPerMonth[] = + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + time_t curTime; + long days; + long rem; + int year; + int yearDays; + int month; + int monthDays; + + if (tmp == NULL) { + tmp = &staticTime; + } + + curTime = (timer != NULL) ? *timer : my_time(NULL); + if (curTime < 0) { + curTime = 0; + } + + days = (long)(curTime / 86400); + rem = (long)(curTime % 86400); + + tmp->tm_hour = (int)(rem / 3600); + rem %= 3600; + tmp->tm_min = (int)(rem / 60); + tmp->tm_sec = (int)(rem % 60); + tmp->tm_wday = (int)((days + 4) % 7); + + year = 1970; + while (1) { + yearDays = IsLeapYear(year) ? 366 : 365; + if (days < yearDays) { + break; + } + days -= yearDays; + year++; + } + + tmp->tm_year = year - 1900; + tmp->tm_yday = (int)days; + + for (month = 0; month < 12; month++) { + monthDays = daysPerMonth[month]; + if (month == 1 && IsLeapYear(year)) { + monthDays++; + } + if (days < monthDays) { + break; + } + days -= monthDays; + } + + tmp->tm_mon = month; + tmp->tm_mday = (int)days + 1; + tmp->tm_isdst = 0; + + return tmp; } #ifndef WOLFCRYPT_ONLY /* This is used by TLS only */ -unsigned int LowResTimer(void) +word32 LowResTimer(void) { - return hw_get_time_sec(); + return (word32)hw_get_time_sec(); +} + +/* This is used by TLS 1.3 ticket and PSK timeouts. */ +#ifdef WOLFSSL_32BIT_MILLI_TIME +word32 TimeNowInMilliseconds(void) +#else +sword64 TimeNowInMilliseconds(void) +#endif +{ + return (sword64)my_time(NULL) * 1000; } #endif diff --git a/IDE/GCC-ARM/include.am b/IDE/GCC-ARM/include.am index ca12aca5c2..61d6eeb19a 100644 --- a/IDE/GCC-ARM/include.am +++ b/IDE/GCC-ARM/include.am @@ -10,6 +10,7 @@ EXTRA_DIST+= IDE/GCC-ARM/Source/test_main.c EXTRA_DIST+= IDE/GCC-ARM/Source/tls_client.c EXTRA_DIST+= IDE/GCC-ARM/Source/tls_server.c EXTRA_DIST+= IDE/GCC-ARM/linker.ld +EXTRA_DIST+= IDE/GCC-ARM/linker_large.ld EXTRA_DIST+= IDE/GCC-ARM/linker_fips.ld EXTRA_DIST+= IDE/GCC-ARM/Makefile EXTRA_DIST+= IDE/GCC-ARM/Makefile.bench diff --git a/IDE/GCC-ARM/linker_large.ld b/IDE/GCC-ARM/linker_large.ld new file mode 100644 index 0000000000..c4b3e4b43b --- /dev/null +++ b/IDE/GCC-ARM/linker_large.ld @@ -0,0 +1,30 @@ +MEMORY +{ + FLASH (wx) : ORIGIN = 0x00000000, LENGTH = 1024K + RAM (wx) : ORIGIN = 0x20000000, LENGTH = 256K +} + +SECTIONS +{ + __vectors_start__ = .; + .vectors : { *(.vectors) } > FLASH + __vectors_end__ = __vectors_start__ + 0x400; + .sys : { *(.sys*) } > FLASH + .text : { *(.text*) } > FLASH + .rodata : { *(.rodata*) } > FLASH + + __data_load_start__ = .; + __data_start__ = .; + .data : { *(.data*) } > RAM + __data_end__ = __data_start__ + SIZEOF(.data); + + __bss_start__ = .; + .bss : { *(.bss*) } > RAM + __bss_end__ = __bss_start__ + SIZEOF(.bss); + + __heap_start__ = .; + .heap : { *(.heap*) } > RAM + __heap_end__ = __heap_start__ + SIZEOF(.heap); + + end = .; +} diff --git a/IDE/Renesas/e2studio/RA6M4/README.md b/IDE/Renesas/e2studio/RA6M4/README.md index c576d8c1e2..e74b13b12b 100644 --- a/IDE/Renesas/e2studio/RA6M4/README.md +++ b/IDE/Renesas/e2studio/RA6M4/README.md @@ -85,6 +85,8 @@ The wolfssl Project Summary is listed below and is relevant for every project. + Add `FreeRTOS + TCP` stack to sce_tst_thread from `New Stack` -> `Networking` -> `FreeRTOS+TCP` and set properties + Add Ethernet Driver by clicking `Add Ethernet Driver` element and select `New` -> `Ethernet(r_ether)` + Increase Heap size of `RA Common`. Go to `BSP` tab and inclease `RA Common` -> `Heap size (bytes)` to 0x2000 + + |Property|Value| |:--|:--| |Network Events call vApplicationIPNetworkEventHook|Disable| @@ -130,7 +132,7 @@ The wolfssl Project Summary is listed below and is relevant for every project. SEGGER_RTT_printf.c + To connect RTT block, you can configure RTT viewer configuration based on where RTT block is in a map file. -+ To place RTT block specific area, you can add the following line to `fsp.ld`: ++ To place RTT block specific area, you can add the following line to `fsp_gen.ld`: ``` __ram_from_flash$$ : @@ -161,9 +163,9 @@ SEGGER_RTT_CB _SEGGER_RTT __attribute__((section(".txt.rtt_block"))); 0x20000000 0xa8 ./src/SEGGER_RTT/SEGGER_RTT.o 0x20000000 _SEGGER_RTT ```` - you can specify "RTT control block" to 0x20023648 by Address + you can specify "RTT control block" to 0x20000000 by Address OR - you can specify "RTT control block" to 0x20023000 0x1000 by Search Range + you can specify "RTT control block" to 0x20000000 0x1000 by Search Range ## Run Client 1.) Enable TLS_CLIENT definition in wolfssl_demo.h of test_RA6M4 project @@ -174,7 +176,7 @@ SEGGER_RTT_CB _SEGGER_RTT __attribute__((section(".txt.rtt_block"))); ``` static const byte ucIPAddress[4] = { 192, 168, 11, 241 }; ``` -+ Client IP address can be changed by the following line in wolf_client.c. ++ Server IP address can be changed by the following line in wolfssl_demo.h. ``` #define SERVER_IP "192.168.11.40" ``` diff --git a/IDE/Renesas/e2studio/RA6M4/common/user_settings.h b/IDE/Renesas/e2studio/RA6M4/common/user_settings.h index eea211f233..ba77b8dc0c 100644 --- a/IDE/Renesas/e2studio/RA6M4/common/user_settings.h +++ b/IDE/Renesas/e2studio/RA6M4/common/user_settings.h @@ -115,5 +115,4 @@ #endif #define CUSTOM_RAND_GENERATE_BLOCK wc_fspsm_GenerateRandBlock -/* use original asn parsing */ -#define WOLFSSL_ASN_ORIGINAL + diff --git a/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c b/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c index 2212cbac91..ef297aa53a 100644 --- a/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c +++ b/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c @@ -72,32 +72,32 @@ const st_user_key_block_data_t g_key_block_data = * This is used for Root Certificate verify by SCE */ const unsigned char ca_cert_der_sign[] = { - 0xAF, 0x76, 0x00, 0x5E, 0x2C, 0x9C, 0xCB, 0xAF, 0x96, 0x9F, - 0x7A, 0x0E, 0xA1, 0x41, 0x36, 0xBE, 0x72, 0x8C, 0xED, 0x86, - 0x31, 0xEF, 0x03, 0x19, 0x2D, 0x68, 0xB0, 0x17, 0xD2, 0x3F, - 0x15, 0xAC, 0x51, 0x00, 0x98, 0xE9, 0xE0, 0x07, 0x39, 0x00, - 0x83, 0x63, 0xE3, 0x0F, 0xCA, 0xD5, 0x8A, 0xBD, 0xBB, 0xC5, - 0x5C, 0xC7, 0xE4, 0xE0, 0xCB, 0x2F, 0x9F, 0x4E, 0xE8, 0xB0, - 0xBF, 0xA6, 0x12, 0x95, 0xFF, 0x5C, 0xA8, 0xF7, 0x89, 0xD4, - 0xA0, 0x84, 0x74, 0x50, 0x91, 0x11, 0x16, 0xEA, 0xEC, 0x59, - 0x03, 0x63, 0x2C, 0xBC, 0x7B, 0x16, 0xD5, 0xAB, 0x2F, 0x7A, - 0xF8, 0xC0, 0x51, 0xC2, 0x58, 0x9C, 0x2C, 0x89, 0xFB, 0x26, - 0x88, 0x13, 0x3F, 0x77, 0xD8, 0x2F, 0x3F, 0x52, 0x5C, 0x65, - 0x0F, 0x04, 0xF8, 0xAC, 0x54, 0x4F, 0x9C, 0x36, 0x80, 0x4A, - 0xE7, 0x54, 0x5A, 0x86, 0x6E, 0xD5, 0x34, 0xC9, 0x31, 0x12, - 0x9D, 0x64, 0x8F, 0x3D, 0xA3, 0x9D, 0x07, 0x87, 0xF5, 0xD7, - 0x54, 0x6E, 0xFA, 0x53, 0xF0, 0x09, 0xCE, 0x0A, 0xD3, 0xCA, - 0x63, 0x23, 0x0A, 0x07, 0xF5, 0xA2, 0x28, 0x67, 0xCD, 0xC7, - 0x1E, 0x0C, 0x4F, 0x15, 0x6B, 0xBA, 0x50, 0xDE, 0x08, 0x7B, - 0x56, 0x18, 0x8C, 0xA2, 0xE0, 0x9C, 0x5A, 0x31, 0xBA, 0xAC, - 0xD3, 0x8B, 0xFC, 0x7F, 0xE1, 0x60, 0x26, 0x93, 0x47, 0xA6, - 0x42, 0x67, 0x50, 0x0F, 0x0B, 0x90, 0x27, 0xE3, 0x53, 0x35, - 0xFD, 0x20, 0x2A, 0xEF, 0xB1, 0x68, 0x81, 0xF8, 0x05, 0x19, - 0xB2, 0x37, 0x57, 0xE8, 0x14, 0x5E, 0xD0, 0xC8, 0x10, 0xB0, - 0xAA, 0x15, 0x27, 0xA3, 0xBF, 0x09, 0xC1, 0xC4, 0xAC, 0x5B, - 0xB4, 0xE4, 0x9A, 0xD3, 0x3A, 0x59, 0xF0, 0x2A, 0x05, 0xFE, - 0xA6, 0xA6, 0x86, 0x96, 0x9C, 0xF7, 0x6C, 0xA3, 0x3B, 0x3A, - 0x54, 0xA0, 0x38, 0x6D, 0x84, 0x73 + 0x4D, 0x7E, 0xE5, 0x34, 0x04, 0x8F, 0xA6, 0x81, 0x22, 0x8E, + 0x2A, 0x9E, 0xEA, 0xBE, 0x1D, 0x0A, 0x1C, 0xC3, 0xEC, 0xCD, + 0x99, 0x1D, 0xE0, 0x2E, 0x79, 0x42, 0x8F, 0xEA, 0x79, 0x47, + 0x13, 0xC3, 0x40, 0x47, 0x83, 0xF6, 0xFE, 0x32, 0x42, 0x52, + 0x26, 0xED, 0xC4, 0xCF, 0x2E, 0x86, 0xF4, 0xEC, 0xFE, 0x8F, + 0x6B, 0xF4, 0x3F, 0x0F, 0xA7, 0x1E, 0x9F, 0x09, 0x37, 0xAE, + 0x5E, 0x35, 0x39, 0xCD, 0x35, 0xAC, 0x6F, 0x37, 0x98, 0x01, + 0x6C, 0x8B, 0x01, 0x8A, 0xAE, 0xCC, 0xAF, 0x05, 0x6E, 0x05, + 0x3A, 0x0A, 0x03, 0xA2, 0xEB, 0xD4, 0x4A, 0x63, 0x64, 0x68, + 0xB6, 0xE4, 0xFC, 0xDE, 0xA5, 0x6B, 0xC4, 0x3C, 0x8F, 0xCF, + 0xC2, 0x5A, 0x2F, 0xBB, 0xBE, 0x70, 0xDC, 0x19, 0x07, 0x4D, + 0xC3, 0x5F, 0x3E, 0xD9, 0x1A, 0x8E, 0xB9, 0x36, 0x74, 0xF6, + 0x38, 0xA6, 0x62, 0x7A, 0xBD, 0x53, 0xF5, 0x91, 0xCF, 0xFD, + 0xD2, 0xCA, 0x4A, 0x20, 0x47, 0xD3, 0x78, 0x15, 0x82, 0x75, + 0xDC, 0x3F, 0x2D, 0xAE, 0x18, 0xFE, 0x9F, 0x22, 0x99, 0x12, + 0x4D, 0xF3, 0x3E, 0xE3, 0x47, 0x33, 0xED, 0x06, 0x79, 0x42, + 0x12, 0xBD, 0x07, 0x39, 0x3F, 0x0D, 0x8A, 0x64, 0xA9, 0xDC, + 0xF0, 0xCF, 0x87, 0x85, 0x4F, 0x09, 0x31, 0x26, 0x6D, 0x05, + 0x2B, 0xBD, 0x52, 0xFB, 0x03, 0xD9, 0xD8, 0x0E, 0x34, 0x33, + 0x72, 0xC0, 0x32, 0x69, 0x6F, 0x23, 0x2A, 0xF9, 0xD3, 0xBB, + 0x55, 0xD4, 0xF8, 0x85, 0xF5, 0xF8, 0x5E, 0xAB, 0x57, 0x35, + 0xAC, 0x3A, 0x33, 0x1F, 0xB8, 0x29, 0x1E, 0xFA, 0x30, 0xC1, + 0x32, 0xEB, 0xAB, 0xD3, 0x51, 0x15, 0x6A, 0xAE, 0xE6, 0xD1, + 0x42, 0x6C, 0x93, 0x3C, 0x48, 0xE1, 0xF8, 0xBC, 0x03, 0xFB, + 0x38, 0x25, 0x18, 0x8F, 0x5B, 0x60, 0xE2, 0x86, 0x15, 0x88, + 0xA3, 0x09, 0xFD, 0x29, 0xB7, 0xF5 }; const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign); @@ -108,32 +108,32 @@ const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign); */ const unsigned char ca_ecc_cert_der_sign[] = { - 0x5A, 0x12, 0x05, 0x7F, 0x18, 0x16, 0x41, 0x18, 0x37, 0x11, - 0x67, 0x22, 0xCE, 0x03, 0x92, 0xDB, 0xCB, 0xE2, 0xD2, 0x5B, - 0x35, 0x3A, 0x2E, 0x35, 0xE8, 0x86, 0x6F, 0xB6, 0x3F, 0x86, - 0x99, 0xFB, 0xB7, 0x7A, 0xB1, 0x38, 0xAE, 0x79, 0x7D, 0x98, - 0x2D, 0x81, 0xBD, 0x74, 0xB1, 0x7D, 0xAD, 0xCE, 0x4F, 0x63, - 0xD2, 0xB3, 0x06, 0xDF, 0x00, 0x91, 0x12, 0x21, 0x53, 0xAE, - 0xEB, 0x0E, 0x4E, 0xDA, 0xF1, 0xD7, 0x29, 0x2E, 0xC8, 0xF2, - 0x42, 0xEB, 0x90, 0xDE, 0xE3, 0xF2, 0x4B, 0x9A, 0xC0, 0x16, - 0x51, 0x4C, 0xE3, 0x54, 0xCD, 0xE7, 0x33, 0xE6, 0x0A, 0xD4, - 0x0F, 0x51, 0x6D, 0xA5, 0x69, 0x5E, 0xD7, 0xDD, 0x5A, 0xF9, - 0x95, 0xE7, 0x89, 0x71, 0x56, 0x22, 0x37, 0x24, 0x2D, 0x39, - 0x21, 0xE4, 0xC9, 0x4F, 0x22, 0x2E, 0x01, 0xA0, 0xA1, 0x2F, - 0xDC, 0x75, 0xD9, 0xED, 0x25, 0x37, 0xB6, 0x7E, 0xAB, 0xF7, - 0xFA, 0xCD, 0x68, 0x9B, 0x89, 0x1F, 0x21, 0x43, 0x8C, 0xAC, - 0xE6, 0x55, 0xC2, 0xDE, 0xF5, 0xCE, 0xA9, 0x1B, 0x6D, 0x7E, - 0x64, 0x3D, 0x91, 0x5A, 0x8D, 0x55, 0x8D, 0x32, 0x56, 0x0D, - 0xE2, 0x65, 0x73, 0xBE, 0x21, 0x2E, 0x7D, 0xFF, 0x2C, 0xA4, - 0x28, 0x0F, 0x37, 0x0F, 0xEA, 0xE7, 0xC4, 0xAC, 0x73, 0x7E, - 0x5F, 0x35, 0x35, 0xD2, 0xE1, 0x76, 0x5B, 0xB3, 0x44, 0xA2, - 0xD7, 0x8E, 0x99, 0xE5, 0x7E, 0xD1, 0x61, 0xAB, 0x78, 0xFC, - 0x70, 0x61, 0x34, 0x99, 0x41, 0x1F, 0x83, 0xFF, 0x71, 0x8D, - 0x83, 0xC5, 0x03, 0x3A, 0x64, 0x54, 0xD0, 0x68, 0x83, 0xC7, - 0x3B, 0x75, 0x62, 0x86, 0x7B, 0xF3, 0x4B, 0xFE, 0xAC, 0x4B, - 0x6F, 0x45, 0x70, 0xC4, 0x71, 0x03, 0x9F, 0x90, 0x32, 0x35, - 0xA8, 0x44, 0x63, 0x2B, 0x89, 0xF4, 0xCE, 0x38, 0x40, 0x61, - 0xC4, 0x9A, 0x2E, 0x84, 0xD5, 0x08 + 0x10, 0xDC, 0xA3, 0x0E, 0xD9, 0xA7, 0x3C, 0xBE, 0x37, 0x6E, + 0x34, 0xC1, 0xDB, 0x4E, 0x90, 0x42, 0x05, 0xCC, 0x94, 0x2B, + 0xAF, 0x0D, 0xE0, 0xC9, 0xE3, 0x91, 0x5F, 0x57, 0x58, 0x48, + 0x44, 0x69, 0x96, 0x4A, 0x94, 0x24, 0x17, 0xE6, 0xDC, 0x1F, + 0x6B, 0xCA, 0xC5, 0xD2, 0x66, 0x25, 0xF7, 0x6F, 0x1E, 0x67, + 0xC0, 0x16, 0x7D, 0x59, 0x43, 0x55, 0x52, 0x6F, 0x1C, 0x23, + 0x55, 0xAC, 0x5E, 0x2C, 0x1A, 0x33, 0x9A, 0x3F, 0x8D, 0x2E, + 0xA9, 0x2B, 0x2A, 0x57, 0x90, 0xA9, 0x4B, 0x5F, 0x30, 0xD1, + 0xB5, 0x76, 0x10, 0xAB, 0xDA, 0x0C, 0x6A, 0x0A, 0x42, 0xEF, + 0x5C, 0x4C, 0xFD, 0x4E, 0x5B, 0x4B, 0x68, 0x30, 0x23, 0x11, + 0x53, 0xA8, 0xBE, 0x01, 0x2E, 0x6F, 0xEB, 0x40, 0x60, 0x1D, + 0xBC, 0xE7, 0xCC, 0xCC, 0x89, 0xA0, 0xD1, 0x2E, 0x08, 0x0F, + 0xE5, 0x81, 0xB1, 0xCF, 0x32, 0x95, 0xA0, 0xF6, 0x0E, 0x59, + 0x88, 0x10, 0x2F, 0xB2, 0x60, 0x59, 0xA4, 0x08, 0xBA, 0x81, + 0x1A, 0x6C, 0x24, 0xB8, 0xBE, 0x2B, 0x4A, 0x64, 0x3E, 0x14, + 0x88, 0x46, 0x22, 0xEC, 0xAA, 0x24, 0x6E, 0x1D, 0x5F, 0xA1, + 0x89, 0xA3, 0xD0, 0x5B, 0x26, 0xC1, 0x63, 0xF4, 0xDC, 0x32, + 0x7F, 0xED, 0xDB, 0x0F, 0xE9, 0x0D, 0xBB, 0x24, 0xB9, 0x25, + 0x87, 0x11, 0xE4, 0x90, 0xE3, 0xAE, 0x4B, 0xEE, 0x3C, 0xFB, + 0x49, 0xDD, 0x5E, 0xB0, 0xF3, 0xC9, 0x13, 0xA9, 0x73, 0x78, + 0x23, 0xBB, 0x66, 0x29, 0x53, 0xF2, 0xBF, 0xC6, 0x92, 0xDB, + 0x09, 0x21, 0x18, 0xAF, 0x76, 0x43, 0x4C, 0x7E, 0xD7, 0x4D, + 0xCA, 0xB7, 0xAA, 0x90, 0xEF, 0x6E, 0xF5, 0x3F, 0x66, 0xCA, + 0x40, 0x1A, 0xCE, 0x87, 0x20, 0x9F, 0x39, 0x36, 0x03, 0x53, + 0x8E, 0x2C, 0xFD, 0x31, 0x14, 0xB8, 0x7E, 0x81, 0xC7, 0x84, + 0x69, 0x1B, 0xBD, 0x1A, 0x0F, 0x3A }; static const int sizeof_ca_ecc_cert_der_sign = sizeof(ca_ecc_cert_der_sign); #endif /* USE_CERT_BUFFERS_256 */ diff --git a/IDE/iotsafe-raspberrypi/client-tls13.c b/IDE/iotsafe-raspberrypi/client-tls13.c index ec148bc69d..c68a9e520f 100644 --- a/IDE/iotsafe-raspberrypi/client-tls13.c +++ b/IDE/iotsafe-raspberrypi/client-tls13.c @@ -170,39 +170,31 @@ int client_loop(const char *peer_ip, const char *peer_name, char randombytes[16] = {0}; /* Construct HTTP POST */ - - /* Header */ - strcat(buff, "POST /iot/device HTTP/1.1\r\n"); - strcat(buff, "Content-Type: application/json\r\n"); - strcat(buff, "Content-Length: 1000\r\n"); - strcat(buff, "Accept: */*\r\n"); - strcat(buff, "Host: "); - strcat(buff, peer_name); - strcat(buff, ":"); - strcat(buff, peer_port); - strcat(buff, "\r\n"); - - /* Delimiter */ - strcat(buff, "\r\n"); - - /* Body */ srand(time(NULL)); - int devid = rand() % 100; - char snum[5] = {0}; - snprintf(snum, sizeof(snum), "%d", devid); + int devid = rand() % 100; - strcat(buff, "{"); - strcat(buff, "\"deviceId\": \""); - strcat(buff, snum); - strcat(buff, "\","); - strcat(buff, "\"sensorType\": \"Temperature\","); - strcat(buff, "\"sensorValue\": \""); - strcat(buff, temperature); - strcat(buff, "\","); - strcat(buff, "\"sensorUnit\": \"Celsius\","); - strcat(buff, "\"sensorTime\": 1582181510"); - strcat(buff, "}"); - strcat(buff, "\r\n"); + int n = snprintf(buff, sizeof(buff), + "POST /iot/device HTTP/1.1\r\n" + "Content-Type: application/json\r\n" + "Content-Length: 1000\r\n" + "Accept: */*\r\n" + "Host: %s:%s\r\n" + "\r\n" + "{" + "\"deviceId\": \"%d\"," + "\"sensorType\": \"Temperature\"," + "\"sensorValue\": \"%s\"," + "\"sensorUnit\": \"Celsius\"," + "\"sensorTime\": 1582181510" + "}" + "\r\n", + peer_name, peer_port, devid, temperature); + + if (n < 0 || n >= (int)sizeof(buff)) { + fprintf(stderr, "ERROR: HTTP request too large for buffer\n"); + ret = -1; + goto exit; + } printf("\n\nPOST REQUEST\n\n%s\n\n", buff); diff --git a/IDE/iotsafe-raspberrypi/main.c b/IDE/iotsafe-raspberrypi/main.c index 44042a16f5..873a17c1e5 100644 --- a/IDE/iotsafe-raspberrypi/main.c +++ b/IDE/iotsafe-raspberrypi/main.c @@ -203,27 +203,27 @@ int main(int argc, char** argv) if (argc == 11) { - if (strcmp(argv[1], "-ip") == 0) - strcpy((char*)&ip, argv[2]); + if (strcmp(argv[1], "-ip") == 0 && strlen(argv[2]) < sizeof(ip)) + strcpy((char*)&ip, argv[2]); else show_usage(argv[0]); - if (strcmp(argv[3], "-h") == 0) + if (strcmp(argv[3], "-h") == 0 && strlen(argv[4]) < sizeof(name)) strcpy((char*)&name, argv[4]); else show_usage(argv[0]); - if (strcmp(argv[5], "-p") == 0) + if (strcmp(argv[5], "-p") == 0 && strlen(argv[6]) < sizeof(port)) strcpy((char*)&port, argv[6]); else show_usage(argv[0]); - if (strcmp(argv[7], "-t") == 0) + if (strcmp(argv[7], "-t") == 0 && strlen(argv[8]) < sizeof(temperature)) strcpy((char*)&temperature, argv[8]); else show_usage(argv[0]); - if (strcmp(argv[9], "-d") == 0) + if (strcmp(argv[9], "-d") == 0 && strlen(argv[10]) < sizeof(device)) strcpy((char*)&device, argv[10]); else show_usage(argv[0]); diff --git a/bsdkm/bsdkm_wc_port.h b/bsdkm/bsdkm_wc_port.h index fba3562212..01d564b0cc 100644 --- a/bsdkm/bsdkm_wc_port.h +++ b/bsdkm/bsdkm_wc_port.h @@ -36,6 +36,7 @@ #ifndef CHAR_BIT #include #endif /* !CHAR_BIT*/ +#include #define NO_THREAD_LS #define NO_ATTRIBUTE_CONSTRUCTOR @@ -80,20 +81,22 @@ extern struct malloc_type M_WOLFSSL[1]; #if defined(WOLFSSL_BSDKM_MEMORY_DEBUG) #define XMALLOC(s, h, t) ({ \ (void)(h); (void)(t); \ - void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \ + int _wait_flag = curthread->td_critnest == 0 ? M_WAITOK : M_NOWAIT; \ + void * _ptr = malloc((s), M_WOLFSSL, _wait_flag | M_ZERO); \ printf("info: malloc: %p, M_WOLFSSL, %zu\n", _ptr, (size_t) s); \ (void *)_ptr; \ }) #define XFREE(p, h, t) ({ \ void* _xp; (void)(h); (void)(t); _xp = (p); \ - printf("info: free: %p, M_WOLFSSL\n", p); \ + printf("info: free: %p, M_WOLFSSL\n", _xp); \ if(_xp) free(_xp, M_WOLFSSL); \ }) #else #define XMALLOC(s, h, t) ({ \ (void)(h); (void)(t); \ - void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \ + int _wait_flag = curthread->td_critnest == 0 ? M_WAITOK : M_NOWAIT; \ + void * _ptr = malloc((s), M_WOLFSSL, _wait_flag | M_ZERO); \ (void *)_ptr; \ }) diff --git a/bsdkm/wolfkmod.c b/bsdkm/wolfkmod.c index 84e8a01490..872d68589f 100644 --- a/bsdkm/wolfkmod.c +++ b/bsdkm/wolfkmod.c @@ -249,15 +249,14 @@ static int wolfkmod_load(void) error = wolfkmod_init(); if (error != 0) { - return (ECANCELED); + goto wolfkmod_load_out; } #ifndef NO_CRYPT_TEST error = wolfcrypt_test(NULL); if (error != 0) { printf("error: wolfcrypt test failed: %d\n", error); - (void)wolfkmod_cleanup(); - return (ECANCELED); + goto wolfkmod_load_out; } printf("info: wolfCrypt self-test passed.\n"); #endif /* NO_CRYPT_TEST */ @@ -266,15 +265,19 @@ static int wolfkmod_load(void) error = benchmark_test(NULL); if (error != 0) { printf("error: wolfcrypt benchmark failed: %d\n", error); - (void)wolfkmod_cleanup(); - return (ECANCELED); + goto wolfkmod_load_out; } printf("info: wolfCrypt benchmark passed.\n"); #endif /* WOLFSSL_KERNEL_BENCHMARKS */ - printf("info: libwolfssl loaded\n"); - return (0); +wolfkmod_load_out: + if (error != 0) { + (void)wolfkmod_cleanup(); + error = ECANCELED; + } + + return (error); } static int wolfkmod_unload(void) @@ -435,7 +438,8 @@ static int wolfkdriv_attach(device_t dev) ret = wolfkmod_init(); if (ret != 0) { - return (ECANCELED); + error = ECANCELED; + goto attach_out; } /** @@ -452,7 +456,8 @@ static int wolfkdriv_attach(device_t dev) if (softc->crid < 0) { device_printf(dev, "error: crypto_get_driverid failed: %d\n", softc->crid); - return (ENXIO); + error = ENXIO; + goto attach_out; } /* @@ -487,7 +492,7 @@ static int wolfkdriv_attach(device_t dev) attach_out: if (error) { wolfkdriv_unregister(softc); - error = ENXIO; + (void)wolfkmod_cleanup(); } return (error); diff --git a/bsdkm/x86_vecreg.c b/bsdkm/x86_vecreg.c index 973f17c13e..c96cc0afd1 100644 --- a/bsdkm/x86_vecreg.c +++ b/bsdkm/x86_vecreg.c @@ -29,13 +29,13 @@ #include struct wolfkmod_fpu_state_t { - volatile lwpid_t td_tid; - volatile u_int nest; + volatile lwpid_t td_tid; /* the thread currently using fpu. */ + volatile u_int nest; /* the fpu nesting level. */ }; typedef struct wolfkmod_fpu_state_t wolfkmod_fpu_state_t; -/* fpu_states array tracks thread id and nesting level of save/restore +/* The fpu_states array tracks thread id and nesting level of save/restore * and push/pop vector registers macro calls. It is indexed by raw cpu id, * and only accessed after the thread calls fpu_kern_enter(), and before * calling fpu_kern_leave(), and only indexed by the thread's PCPU_GET(cpuid). diff --git a/configure.ac b/configure.ac index 7cd5cf6671..0c427d4ca7 100644 --- a/configure.ac +++ b/configure.ac @@ -1432,6 +1432,11 @@ then AC_MSG_ERROR([--enable-all-asm is incompatible with --disable-ppc32-asm]) fi + if test "$enable_ppc64_asm" = "no" + then + AC_MSG_ERROR([--enable-all-asm is incompatible with --disable-ppc64-asm]) + fi + case "$host_cpu" in *x86_64*|*amd64*) if test "$enable_intelasm" = "" @@ -1462,6 +1467,10 @@ then fi ;; *powerpc64*) + if test "$enable_ppc64_asm" = "" + then + enable_ppc64_asm=yes + fi ;; *powerpc*) if test "$enable_ppc32_asm" = "" @@ -1513,6 +1522,7 @@ then test "$enable_hkdf" = "" && enable_hkdf=yes test "$enable_eccencrypt" = "" && test "$enable_ecc" != "no" && enable_eccencrypt=yes test "$enable_fpecc" = "" && test "$enable_ecc" != "no" && enable_fpecc=yes + test "$enable_eccsi" = "" && test "$enable_ecc" != "no" && enable_eccsi=yes test "$enable_psk" = "" && enable_psk=yes test "$enable_cmac" = "" && enable_cmac=yes test "$enable_cmac_kdf" = "" && enable_cmac_kdf=yes @@ -1580,13 +1590,12 @@ then test "$enable_aessiv" = "" && enable_aessiv=yes # AFALG lacks AES-EAX test "$enable_aeseax" = "" && test "$enable_afalg" != "yes" && enable_aeseax=yes + test "$enable_sakke" = "" && test "$enable_ecc" != "no" && enable_sakke=yes if test "$KERNEL_MODE_DEFAULTS" != "yes" then test "$enable_cryptocb" = "" && enable_cryptocb=yes test "$enable_pkcallbacks" = "" && enable_pkcallbacks=yes - test "$enable_eccsi" = "" && test "$enable_ecc" != "no" && enable_eccsi=yes - test "$enable_sakke" = "" && test "$enable_ecc" != "no" && enable_sakke=yes fi fi @@ -3859,7 +3868,7 @@ do # FSL, FSR, FSRI, CMOV, CMIX - QEMU doesn't know about these instructions AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION_TERNARY" ;; - zkn|zkned) + zkned) # AES encrypt/decrpyt, SHA-2 ENABLED_RISCV_ASM=yes AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM" @@ -3934,21 +3943,70 @@ then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM" AC_MSG_NOTICE([32-bit PowerPC assembly for SHA-256]) ENABLED_PPC32_ASM=yes + + if test "$ENABLED_PPC32_ASM_INLINE" = "yes" || test "$ENABLED_PPC32_ASM_INLINE_REG" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_INLINE" + else + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM" + fi + if test "$ENABLED_PPC32_ASM_SMALL" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_SMALL" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM_SMALL" + fi + if test "$ENABLED_PPC32_ASM_SPE" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_SPE" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM_SPE" + fi fi -if test "$ENABLED_PPC32_ASM_INLINE" = "yes" || test "$ENABLED_PPC32_ASM_INLINE_REG" = "yes"; then - AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_INLINE" + +# PPC64 Assembly +AC_ARG_ENABLE([ppc64-asm], + [AS_HELP_STRING([--enable-ppc64-asm],[Enable wolfSSL PowerPC 64-bit ASM support (default: disabled).])], + [ ENABLED_PPC64_ASM=$enableval ], + [ ENABLED_PPC64_ASM=no ] + ) + + +if test "$ENABLED_PPC64_ASM" != "no" && test "$ENABLED_ASM" = "yes" +then + ENABLED_PPC64_ASM_OPTS=$ENABLED_PPC64_ASM + for v in `echo $ENABLED_PPC64_ASM_OPTS | tr "," " "` + do + case $v in + yes) + ;; + inline) + ENABLED_PPC64_ASM_INLINE=yes + ;; + inline-reg) + ENABLED_PPC64_ASM_INLINE_REG=yes + ;; + small) + ENABLED_PPC64_ASM_SMALL=yes + ;; + *) + AC_MSG_ERROR([Invalid RISC-V option [yes,inline,small]: $ENABLED_PPC64_ASM.]) + break + ;; + esac + done + + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM" + AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN" + AC_MSG_NOTICE([64-bit PowerPC assembly for AES]) + ENABLED_PPC64_ASM=yes +fi +if test "$ENABLED_PPC64_ASM_INLINE" = "yes" || test "$ENABLED_PPC64_ASM_INLINE_REG" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM_INLINE" else - AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC64_ASM" fi -if test "$ENABLED_PPC32_ASM_SMALL" = "yes"; then - AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_SMALL" - AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM_SMALL" -fi -if test "$ENABLED_PPC32_ASM_SPE" = "yes"; then - AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_SPE" - AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM_SPE" +if test "$ENABLED_PPC64_ASM_SMALL" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM_SMALL" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC64_ASM_SMALL" fi + # Xilinx hardened crypto AC_ARG_ENABLE([xilinx], [AS_HELP_STRING([--enable-xilinx],[Enable wolfSSL support for Xilinx hardened crypto(default: disabled)])], @@ -12219,6 +12277,9 @@ AM_CONDITIONAL([BUILD_RISCV_ASM],[test "x$ENABLED_RISCV_ASM" = "xyes"]) AM_CONDITIONAL([BUILD_PPC32_ASM],[test "x$ENABLED_PPC32_ASM" = "xyes"]) AM_CONDITIONAL([BUILD_PPC32_ASM_INLINE],[test "x$ENABLED_PPC32_ASM_INLINE" = "xyes"]) AM_CONDITIONAL([BUILD_PPC32_ASM_INLINE_REG],[test "x$ENABLED_PPC32_ASM_INLINE_REG" = "xyes"]) +AM_CONDITIONAL([BUILD_PPC64_ASM],[test "x$ENABLED_PPC64_ASM" = "xyes"]) +AM_CONDITIONAL([BUILD_PPC64_ASM_INLINE],[test "x$ENABLED_PPC64_ASM_INLINE" = "xyes"]) +AM_CONDITIONAL([BUILD_PPC64_ASM_INLINE_REG],[test "x$ENABLED_PPC64_ASM_INLINE_REG" = "xyes"]) AM_CONDITIONAL([BUILD_XILINX],[test "x$ENABLED_XILINX" = "xyes"]) AM_CONDITIONAL([BUILD_AESNI],[test "x$ENABLED_AESNI" = "xyes"]) AM_CONDITIONAL([BUILD_INTELASM],[test "x$ENABLED_INTELASM" = "xyes"]) @@ -12925,6 +12986,15 @@ then ENABLED_PPC32_ASM="inline C Reg" fi echo " * PPC32 ASM $ENABLED_PPC32_ASM" +if test "$ENABLED_PPC64_ASM_INLINE" = "yes" +then + ENABLED_PPC64_ASM="inline C" +fi +if test "$ENABLED_PPC64_ASM_INLINE_REG" = "yes" +then + ENABLED_PPC64_ASM="inline C Reg" +fi +echo " * PPC64 ASM $ENABLED_PPC64_ASM" echo " * Write duplicate: $ENABLED_WRITEDUP" echo " * Xilinx Hardware Acc.: $ENABLED_XILINX" echo " * C89: $ENABLED_C89" diff --git a/examples/configs/user_settings_openssl_compat.h b/examples/configs/user_settings_openssl_compat.h index b2557bb293..297e50a2c3 100644 --- a/examples/configs/user_settings_openssl_compat.h +++ b/examples/configs/user_settings_openssl_compat.h @@ -51,6 +51,23 @@ extern "C" { #define HAVE_WOLFSSL_SSL_H #define OPENSSL_COMPATIBLE_DEFAULTS +/* No-socket embedded builds still compile IP SAN helpers through OPENSSL_ALL. + * Provide local address-conversion stubs when the platform has no socket API. */ +#ifdef WOLFSSL_NO_SOCK + #ifndef WOLFSSL_IP4 + #define WOLFSSL_IP4 2 + #endif + #ifndef WOLFSSL_IP6 + #define WOLFSSL_IP6 10 + #endif + #ifndef XINET_PTON + #define XINET_PTON(a,b,c) 0 + #endif + #ifndef XINET_NTOP + #define XINET_NTOP(a,b,c,d) NULL + #endif +#endif + /* Avoid old name conflicts */ #define NO_OLD_RNGNAME #define NO_OLD_WC_NAMES diff --git a/linuxkm/README.md b/linuxkm/README.md index dd65cec87d..43652e3c1c 100644 --- a/linuxkm/README.md +++ b/linuxkm/README.md @@ -57,6 +57,24 @@ $ sudo modprobe libwolfssl | `--enable-intelasm` | x86/amd64 crypto acceleration | | `--enable-cryptonly` | Omit TLS/DTLS implementation (normally recommended) | +### Enabling DTLS 1.3 in the kernel module + +`--enable-linuxkm` does not implicitly enable TLS 1.3 or DTLS, so the DTLS 1.3 +configure check (`configure.ac:5634-5636`) requires all three flags to be +passed explicitly: + +```sh +./configure --enable-linuxkm \ + --enable-tls13 --enable-dtls --enable-dtls13 \ + --with-linux-source=/lib/modules/$(uname -r)/build +make -j$(nproc) module +``` + +The resulting `linuxkm/libwolfssl.ko` exports the DTLS 1.3 entry points +(`wolfDTLSv1_3_client_method`, `wolfDTLSv1_3_server_method`, etc.) as GPL +kernel symbols, available to other in-kernel consumers via +`EXPORT_SYMBOL_GPL`. + ### Additional configuration options for verification, performance evaluation, and troubleshooting | option | description | diff --git a/linuxkm/linuxkm_wc_port.h b/linuxkm/linuxkm_wc_port.h index 892f323a8a..83e35dc692 100644 --- a/linuxkm/linuxkm_wc_port.h +++ b/linuxkm/linuxkm_wc_port.h @@ -167,13 +167,14 @@ #ifndef WC_LINUXKM_INTR_SIGNALS #define WC_LINUXKM_INTR_SIGNALS { SIGKILL, SIGABRT, SIGHUP, SIGINT } #endif - extern int wc_linuxkm_sig_ignore_begin(void); - extern int wc_linuxkm_sig_ignore_end(void); - extern int wc_linuxkm_check_for_intr_signals(void); + WOLFSSL_API int wc_linuxkm_can_block(void); + WOLFSSL_API int wc_linuxkm_sig_ignore_begin(void); + WOLFSSL_API int wc_linuxkm_sig_ignore_end(void); + WOLFSSL_API int wc_linuxkm_check_for_intr_signals(void); #ifndef WC_LINUXKM_MAX_NS_WITHOUT_YIELD #define WC_LINUXKM_MAX_NS_WITHOUT_YIELD 1000000000 #endif - extern void wc_linuxkm_relax_long_loop(void); + WOLFSSL_API void wc_linuxkm_relax_long_loop(void); #ifndef WC_SIG_IGNORE_BEGIN #define WC_SIG_IGNORE_BEGIN() wc_linuxkm_sig_ignore_begin() @@ -1221,6 +1222,7 @@ typeof(wc_lkm_LockMutex) *wc_lkm_LockMutex; #endif + typeof(wc_linuxkm_can_block) *wc_linuxkm_can_block; typeof(wc_linuxkm_sig_ignore_begin) *wc_linuxkm_sig_ignore_begin; typeof(wc_linuxkm_sig_ignore_end) *wc_linuxkm_sig_ignore_end; typeof(wc_linuxkm_check_for_intr_signals) *wc_linuxkm_check_for_intr_signals; @@ -1521,8 +1523,9 @@ wolfssl_spin_unlock_irqrestore_rt((lock), (flags)) #endif - #define wc_linuxkm_sig_ignore_begin WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_begin); - #define wc_linuxkm_sig_ignore_end WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_end); + #define wc_linuxkm_can_block WC_PIE_INDIRECT_SYM(wc_linuxkm_can_block) + #define wc_linuxkm_sig_ignore_begin WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_begin) + #define wc_linuxkm_sig_ignore_end WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_end) #define wc_linuxkm_check_for_intr_signals WC_PIE_INDIRECT_SYM(wc_linuxkm_check_for_intr_signals) #define wc_linuxkm_relax_long_loop WC_PIE_INDIRECT_SYM(wc_linuxkm_relax_long_loop) @@ -1905,21 +1908,21 @@ #endif #else /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ #ifdef USE_KVMALLOC - #define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) + #define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0) - #define free(ptr) (preempt_count() == 0 ? kvfree(ptr) : kvfree_atomic(ptr)) + #define free(ptr) (wc_linuxkm_can_block() ? kvfree(ptr) : kvfree_atomic(ptr)) #else #define free(ptr) kvfree(ptr) #endif #ifdef USE_KVREALLOC - #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) + #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC)) #else #define realloc(ptr, newsize) ((void)(ptr), (void)(newsize), NULL) #endif #else - #define malloc(size) kmalloc(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) + #define malloc(size) kmalloc(WC_LINUXKM_ROUND_UP_P_OF_2(size), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC)) #define free(ptr) kfree(ptr) - #define realloc(ptr, newsize) krealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) + #define realloc(ptr, newsize) krealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC)) #endif #endif /* !WC_LINUXKM_USE_HEAP_WRAPPERS */ diff --git a/linuxkm/lkcapi_dh_glue.c b/linuxkm/lkcapi_dh_glue.c index 6caabf06ac..581776b230 100644 --- a/linuxkm/lkcapi_dh_glue.c +++ b/linuxkm/lkcapi_dh_glue.c @@ -89,37 +89,40 @@ #include #define WOLFKM_DH_NAME ("dh") -#define WOLFKM_DH_DRIVER ("dh" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + +#if defined(WOLFSSL_SP_X86_64_ASM) && !defined(NO_AVX2_SUPPORT) + #define WOLFKM_DH_DRIVER_ISA_EXT "-avx2" +#else + #define WOLFKM_DH_DRIVER_ISA_EXT "" +#endif +#define WOLFKM_DH_DRIVER_SUFFIX WOLFKM_DH_DRIVER_ISA_EXT \ + WOLFKM_DRIVER_SUFFIX_BASE + +#define WOLFKM_DH_DRIVER ("dh" WOLFKM_DH_DRIVER_SUFFIX) #ifdef HAVE_FFDHE_2048 #define WOLFKM_FFDHE2048_NAME ("ffdhe2048(dh)") - #define WOLFKM_FFDHE2048_DRIVER ("ffdhe2048" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + #define WOLFKM_FFDHE2048_DRIVER ("ffdhe2048" WOLFKM_DH_DRIVER_SUFFIX) #endif /* HAVE_FFDHE_2048 */ #ifdef HAVE_FFDHE_3072 #define WOLFKM_FFDHE3072_NAME ("ffdhe3072(dh)") - #define WOLFKM_FFDHE3072_DRIVER ("ffdhe3072" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + #define WOLFKM_FFDHE3072_DRIVER ("ffdhe3072" WOLFKM_DH_DRIVER_SUFFIX) #endif /* HAVE_FFDHE_3072 */ #ifdef HAVE_FFDHE_4096 #define WOLFKM_FFDHE4096_NAME ("ffdhe4096(dh)") - #define WOLFKM_FFDHE4096_DRIVER ("ffdhe4096" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + #define WOLFKM_FFDHE4096_DRIVER ("ffdhe4096" WOLFKM_DH_DRIVER_SUFFIX) #endif /* HAVE_FFDHE_4096 */ #ifdef HAVE_FFDHE_6144 #define WOLFKM_FFDHE6144_NAME ("ffdhe6144(dh)") - #define WOLFKM_FFDHE6144_DRIVER ("ffdhe6144" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + #define WOLFKM_FFDHE6144_DRIVER ("ffdhe6144" WOLFKM_DH_DRIVER_SUFFIX) #endif /* HAVE_FFDHE_6144 */ #ifdef HAVE_FFDHE_8192 #define WOLFKM_FFDHE8192_NAME ("ffdhe8192(dh)") - #define WOLFKM_FFDHE8192_DRIVER ("ffdhe8192" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") + #define WOLFKM_FFDHE8192_DRIVER ("ffdhe8192" WOLFKM_DH_DRIVER_SUFFIX) #endif /* HAVE_FFDHE_8192 */ static int linuxkm_test_kpp_driver(const char * driver, diff --git a/linuxkm/lkcapi_ecdh_glue.c b/linuxkm/lkcapi_ecdh_glue.c index 2f88bd2037..24755917a5 100644 --- a/linuxkm/lkcapi_ecdh_glue.c +++ b/linuxkm/lkcapi_ecdh_glue.c @@ -63,19 +63,24 @@ #include #include -#define WOLFKM_ECDH_DRIVER ("ecdh-wolfcrypt") +#if defined(WOLFSSL_SP_X86_64_ASM) && !defined(NO_AVX2_SUPPORT) + #define WOLFKM_ECDH_DRIVER_ISA_EXT "-avx2" +#else + #define WOLFKM_ECDH_DRIVER_ISA_EXT "" +#endif +#define WOLFKM_ECDH_DRIVER_SUFFIX WOLFKM_ECDH_DRIVER_ISA_EXT \ + WOLFKM_DRIVER_SUFFIX_BASE + +#define WOLFKM_ECDH_DRIVER ("ecdh" WOLFKM_ECDH_DRIVER_SUFFIX) #define WOLFKM_ECDH_P192_NAME ("ecdh-nist-p192") -#define WOLFKM_ECDH_P192_DRIVER ("ecdh-nist-p192" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDH_P192_DRIVER ("ecdh-nist-p192" WOLFKM_ECDH_DRIVER_SUFFIX) #define WOLFKM_ECDH_P256_NAME ("ecdh-nist-p256") -#define WOLFKM_ECDH_P256_DRIVER ("ecdh-nist-p256" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDH_P256_DRIVER ("ecdh-nist-p256" WOLFKM_ECDH_DRIVER_SUFFIX) #define WOLFKM_ECDH_P384_NAME ("ecdh-nist-p384") -#define WOLFKM_ECDH_P384_DRIVER ("ecdh-nist-p384" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDH_P384_DRIVER ("ecdh-nist-p384" WOLFKM_ECDH_DRIVER_SUFFIX) static int linuxkm_test_ecdh_nist_driver(const char * driver, const byte * b_pub, diff --git a/linuxkm/lkcapi_ecdsa_glue.c b/linuxkm/lkcapi_ecdsa_glue.c index 46469131e5..13a0e90be5 100644 --- a/linuxkm/lkcapi_ecdsa_glue.c +++ b/linuxkm/lkcapi_ecdsa_glue.c @@ -82,23 +82,27 @@ #include #include -#define WOLFKM_ECDSA_DRIVER ("ecdsa-wolfcrypt") +#if defined(WOLFSSL_SP_X86_64_ASM) && !defined(NO_AVX2_SUPPORT) + #define WOLFKM_ECDSA_DRIVER_ISA_EXT "-avx2" +#else + #define WOLFKM_ECDSA_DRIVER_ISA_EXT "" +#endif +#define WOLFKM_ECDSA_DRIVER_SUFFIX WOLFKM_ECDSA_DRIVER_ISA_EXT \ + WOLFKM_DRIVER_SUFFIX_BASE + +#define WOLFKM_ECDSA_DRIVER ("ecdsa" WOLFKM_ECDSA_DRIVER_SUFFIX) #define WOLFKM_ECDSA_P192_NAME ("ecdsa-nist-p192") -#define WOLFKM_ECDSA_P192_DRIVER ("ecdsa-nist-p192" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDSA_P192_DRIVER ("ecdsa-nist-p192" WOLFKM_ECDSA_DRIVER_SUFFIX) #define WOLFKM_ECDSA_P256_NAME ("ecdsa-nist-p256") -#define WOLFKM_ECDSA_P256_DRIVER ("ecdsa-nist-p256" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDSA_P256_DRIVER ("ecdsa-nist-p256" WOLFKM_ECDSA_DRIVER_SUFFIX) #define WOLFKM_ECDSA_P384_NAME ("ecdsa-nist-p384") -#define WOLFKM_ECDSA_P384_DRIVER ("ecdsa-nist-p384" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDSA_P384_DRIVER ("ecdsa-nist-p384" WOLFKM_ECDSA_DRIVER_SUFFIX) #define WOLFKM_ECDSA_P521_NAME ("ecdsa-nist-p521") -#define WOLFKM_ECDSA_P521_DRIVER ("ecdsa-nist-p521" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt") +#define WOLFKM_ECDSA_P521_DRIVER ("ecdsa-nist-p521" WOLFKM_ECDSA_DRIVER_SUFFIX) static int linuxkm_test_ecdsa_nist_driver(const char * driver, diff --git a/linuxkm/lkcapi_rsa_glue.c b/linuxkm/lkcapi_rsa_glue.c index e38dfaf28c..ac7f8ff5c7 100644 --- a/linuxkm/lkcapi_rsa_glue.c +++ b/linuxkm/lkcapi_rsa_glue.c @@ -99,45 +99,46 @@ #include #define WOLFKM_RSA_NAME ("rsa") -#define WOLFKM_RSA_DRIVER ("rsa" WOLFKM_DRIVER_FIPS "-wolfcrypt") + +#if defined(WOLFSSL_SP_X86_64_ASM) && !defined(NO_AVX2_SUPPORT) + #define WOLFKM_RSA_DRIVER_ISA_EXT "-avx2" +#else + #define WOLFKM_RSA_DRIVER_ISA_EXT "" +#endif +#define WOLFKM_RSA_DRIVER_SUFFIX WOLFKM_RSA_DRIVER_ISA_EXT \ + WOLFKM_DRIVER_SUFFIX_BASE + +#define WOLFKM_RSA_DRIVER ("rsa" WOLFKM_RSA_DRIVER_SUFFIX) #if defined(LINUXKM_AKCIPHER_NO_SIGNVERIFY) /* the akcipher alg */ - #define WOLFKM_PKCS1PAD_NAME ("pkcs1pad(rsa)") - #define WOLFKM_PKCS1PAD_DRIVER ("pkcs1pad(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt)") + #define WOLFKM_PKCS1PAD_NAME "pkcs1pad(rsa)" + #define WOLFKM_PKCS1PAD_DRIVER "pkcs1pad-rsa" WOLFKM_RSA_DRIVER_SUFFIX #endif /* LINUXKM_AKCIPHER_NO_SIGNVERIFY */ /* * pkcs1 sign verify alg names * */ #define WOLFKM_PKCS1_SHA224_NAME (PKCS1_NAME "(rsa,sha224)") -#define WOLFKM_PKCS1_SHA224_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha224)") +#define WOLFKM_PKCS1_SHA224_DRIVER ("pkcs1pad-rsa-sha224" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA256_NAME (PKCS1_NAME "(rsa,sha256)") -#define WOLFKM_PKCS1_SHA256_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha256)") +#define WOLFKM_PKCS1_SHA256_DRIVER ("pkcs1pad-rsa-sha256" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA384_NAME (PKCS1_NAME "(rsa,sha384)") -#define WOLFKM_PKCS1_SHA384_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha384)") +#define WOLFKM_PKCS1_SHA384_DRIVER ("pkcs1pad-rsa-sha384" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA512_NAME (PKCS1_NAME "(rsa,sha512)") -#define WOLFKM_PKCS1_SHA512_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha512)") +#define WOLFKM_PKCS1_SHA512_DRIVER ("pkcs1pad-rsa-sha512" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA3_256_NAME (PKCS1_NAME "(rsa,sha3-256)") -#define WOLFKM_PKCS1_SHA3_256_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha3-256)") +#define WOLFKM_PKCS1_SHA3_256_DRIVER ("pkcs1pad-rsa-sha3-256" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA3_384_NAME (PKCS1_NAME "(rsa,sha3-384)") -#define WOLFKM_PKCS1_SHA3_384_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha3-384)") +#define WOLFKM_PKCS1_SHA3_384_DRIVER ("pkcs1pad-rsa-sha3-384" WOLFKM_RSA_DRIVER_SUFFIX) #define WOLFKM_PKCS1_SHA3_512_NAME (PKCS1_NAME "(rsa,sha3-512)") -#define WOLFKM_PKCS1_SHA3_512_DRIVER (PKCS1_NAME "(rsa" WOLFKM_DRIVER_FIPS \ - "-wolfcrypt,sha3-512)") +#define WOLFKM_PKCS1_SHA3_512_DRIVER ("pkcs1pad-rsa-sha3-512" WOLFKM_RSA_DRIVER_SUFFIX) #if defined(WOLFSSL_KEY_GEN) #if defined(LINUXKM_DIRECT_RSA) diff --git a/linuxkm/lkcapi_sha_glue.c b/linuxkm/lkcapi_sha_glue.c index 39754a6424..9a80247bc3 100644 --- a/linuxkm/lkcapi_sha_glue.c +++ b/linuxkm/lkcapi_sha_glue.c @@ -1009,7 +1009,7 @@ static volatile int wc_linuxkm_rng_initing_default_bank_flag = 0; static int linuxkm_affinity_lock(void *arg) { (void)arg; - if (preempt_count() != 0) + if (! wc_linuxkm_can_block()) return ALREADY_E; #if defined(CONFIG_SMP) && (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 7, 0)) migrate_disable(); /* this actually makes irq_count() nonzero, so that @@ -1118,7 +1118,7 @@ static struct wc_rng_bank_inst *linuxkm_get_drbg(struct wc_rng_bank *ctx) { WC_RNG_BANK_FLAG_CAN_WAIT | WC_RNG_BANK_FLAG_PREFER_AFFINITY_INST; - if (preempt_count() == 0) + if (wc_linuxkm_can_block()) flags |= WC_RNG_BANK_FLAG_AFFINITY_LOCK; else flags |= WC_RNG_BANK_FLAG_NO_VECTOR_OPS; @@ -1487,7 +1487,7 @@ static int wc_mix_pool_bytes(const void *buf, size_t len) { struct wc_rng_bank *ctx; size_t i; int n; - int can_sleep = (preempt_count() == 0); + int can_sleep = wc_linuxkm_can_block(); if (len == 0) return 0; @@ -1545,7 +1545,7 @@ static int wc_mix_pool_bytes(const void *buf, size_t len) { static int wc_crng_reseed(void) { struct wc_rng_bank *ctx; - int can_sleep = (preempt_count() == 0); + int can_sleep = wc_linuxkm_can_block(); int ret = wc_rng_bank_default_checkout(&ctx); if (ret) { diff --git a/linuxkm/module_exports.c.template b/linuxkm/module_exports.c.template index f37eea1e49..8209c6277f 100644 --- a/linuxkm/module_exports.c.template +++ b/linuxkm/module_exports.c.template @@ -91,6 +91,12 @@ #ifdef HAVE_ECC #include #endif +#ifdef WOLFCRYPT_HAVE_ECCSI + #include +#endif +#ifdef WOLFCRYPT_HAVE_SAKKE + #include +#endif #ifdef HAVE_HPKE #include #endif diff --git a/linuxkm/module_hooks.c b/linuxkm/module_hooks.c index be1fd01d7b..e5b94ba278 100644 --- a/linuxkm/module_hooks.c +++ b/linuxkm/module_hooks.c @@ -316,6 +316,13 @@ MODULE_PARM_DESC(rodata_dump_path, #include "linuxkm/lkcapi_glue.c" #endif +int wc_linuxkm_can_block(void) { + /* We can't use preemptible() for this, because we need an accurate test + * even in !CONFIG_PREEMPT_COUNT configs where preemptible() is always 0. + */ + return (preempt_count() == 0) && (! irqs_disabled()); +} + /* for simplicity, we use a global count to suspend signal processing while any * thread is running fipsEntry(), wolfCrypt_IntegrityTest_fips(), * linuxkm_lkcapi_register(), or linuxkm_lkcapi_unregister(). This only affects @@ -336,7 +343,7 @@ int wc_linuxkm_sig_ignore_end(void) { int wc_linuxkm_check_for_intr_signals(void) { static const int intr_signals[] = WC_LINUXKM_INTR_SIGNALS; - if (preempt_count() != 0) + if (! wc_linuxkm_can_block()) return 0; if (signal_pending(current)) { int i; @@ -365,7 +372,7 @@ int wc_linuxkm_check_for_intr_signals(void) { void wc_linuxkm_relax_long_loop(void) { #if WC_LINUXKM_MAX_NS_WITHOUT_YIELD >= 0 - if (preempt_count() == 0) { + if (wc_linuxkm_can_block()) { #if (WC_LINUXKM_MAX_NS_WITHOUT_YIELD == 0) || !defined(CONFIG_SCHED_INFO) cond_resched(); #else @@ -662,6 +669,11 @@ static int wolfssl_init(void) } #endif +#if defined(WC_LINUXKM_USE_HEAP_WRAPPERS) && defined(CONFIG_HAVE_KPROBES) + /* cache the function pointer to find_vm_area(). */ + (void)wc_linuxkm_malloc_usable_size(NULL); +#endif + #ifdef WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE #ifdef CONFIG_MODULE_SIG if (THIS_MODULE->sig_ok == false) { @@ -1283,13 +1295,13 @@ static const struct wc_reloc_table_segments seg_map = { void *wc_linuxkm_malloc(size_t size) { - return kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE); + return kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE); } void wc_linuxkm_free(void *ptr) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0) - if (preempt_count() == 0) + if (wc_linuxkm_can_block()) kvfree(ptr); else kvfree_atomic(ptr); @@ -1300,12 +1312,41 @@ void wc_linuxkm_free(void *ptr) void *wc_linuxkm_realloc(void *ptr, size_t newsize) { - return kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)); + return kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (wc_linuxkm_can_block() ? GFP_KERNEL : GFP_ATOMIC)); } +#ifdef CONFIG_HAVE_KPROBES +#include +#endif + size_t wc_linuxkm_malloc_usable_size(void *ptr) { - return ksize(ptr); + if ((ptr == NULL) || is_vmalloc_addr(ptr)) { +#ifdef CONFIG_HAVE_KPROBES + static typeof(find_vm_area) *find_vm_area_ptr = NULL; + if (find_vm_area_ptr == NULL) { + if (! wc_linuxkm_can_block()) + return 0; + find_vm_area_ptr = my_kallsyms_lookup_name("find_vm_area"); + } + if (find_vm_area_ptr == NULL) + return 0; + else if (ptr == NULL) + return 0; + else { + struct vm_struct *vm = find_vm_area_ptr(ptr); + if (vm) + return get_vm_area_size(vm); + else + return 0; + } +#else + return 0; +#endif + } + else { + return ksize(ptr); + } } #endif /* WC_LINUXKM_USE_HEAP_WRAPPERS */ @@ -1678,6 +1719,7 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) { #endif #endif + wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_can_block = wc_linuxkm_can_block; wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_sig_ignore_begin = wc_linuxkm_sig_ignore_begin; wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_sig_ignore_end = wc_linuxkm_sig_ignore_end; wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_check_for_intr_signals = wc_linuxkm_check_for_intr_signals; diff --git a/src/include.am b/src/include.am index 563a6fa3e8..df6d59c8f7 100644 --- a/src/include.am +++ b/src/include.am @@ -247,6 +247,14 @@ endif !BUILD_ARMASM_INLINE endif BUILD_ARMASM endif !BUILD_ARMASM_NEON +if BUILD_PPC64_ASM +if BUILD_PPC64_ASM_INLINE +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c +else +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm.S +endif !BUILD_PPC64_ASM_INLINE +endif BUILD_PPC64_ASM + if BUILD_AESNI src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/aes_asm.S if BUILD_X86_ASM @@ -512,6 +520,14 @@ endif BUILD_ARMASM endif !BUILD_ARMASM_NEON endif BUILD_AES +if BUILD_PPC64_ASM +if BUILD_PPC64_ASM_INLINE +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c +else +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm.S +endif !BUILD_PPC64_ASM_INLINE +endif BUILD_PPC64_ASM + if BUILD_AESNI src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/aes_asm.S if BUILD_X86_ASM @@ -1390,6 +1406,14 @@ endif !BUILD_ARMASM_INLINE endif BUILD_ARMASM endif !BUILD_ARMASM_NEON +if BUILD_PPC64_ASM +if BUILD_PPC64_ASM_INLINE +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c +else +src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/ppc64/ppc64-aes-asm.S +endif !BUILD_PPC64_ASM_INLINE +endif BUILD_PPC64_ASM + if BUILD_AFALG src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/af_alg/afalg_aes.c endif BUILD_AFALG diff --git a/src/internal.c b/src/internal.c index 5f09158039..4ca81cfcb2 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1423,7 +1423,9 @@ static int ExportOptions(WOLFSSL* ssl, byte* exp, word32 len, byte ver, exp[idx++] = options->acceptState; exp[idx++] = options->asyncState; - if (type == WOLFSSL_EXPORT_TLS) { + /* Encrypt-Then-MAC state. Historically only serialized for TLS; export + * version 6 and later also serialize it for DTLS. */ + if (type == WOLFSSL_EXPORT_TLS || ver > WOLFSSL_EXPORT_VERSION_5) { #ifdef HAVE_ENCRYPT_THEN_MAC exp[idx++] = options->disallowEncThenMac; exp[idx++] = options->encThenMac; @@ -1502,6 +1504,13 @@ static int ImportOptions(WOLFSSL* ssl, const byte* exp, word32 len, byte ver, } break; + case WOLFSSL_EXPORT_VERSION_5: + if (len < DTLS_EXPORT_OPT_SZ_5) { + WOLFSSL_MSG("Sanity check on buffer size failed"); + return BAD_FUNC_ARG; + } + break; + case WOLFSSL_EXPORT_VERSION_4: if (len < DTLS_EXPORT_OPT_SZ_4) { WOLFSSL_MSG("Sanity check on buffer size failed"); @@ -1628,7 +1637,9 @@ static int ImportOptions(WOLFSSL* ssl, const byte* exp, word32 len, byte ver, options->acceptState = exp[idx++]; options->asyncState = exp[idx++]; - if (type == WOLFSSL_EXPORT_TLS) { + /* Encrypt-Then-MAC state. Historically only serialized for TLS; export + * version 6 and later also serialize it for DTLS. */ + if (type == WOLFSSL_EXPORT_TLS || ver > WOLFSSL_EXPORT_VERSION_5) { #ifdef HAVE_ENCRYPT_THEN_MAC options->disallowEncThenMac = exp[idx++]; options->encThenMac = exp[idx++]; @@ -1723,8 +1734,8 @@ static int ImportPeerInfo(WOLFSSL* ssl, const byte* buf, word32 len, byte ver) word16 port; char ip[MAX_EXPORT_IP]; - if (ver != WOLFSSL_EXPORT_VERSION && ver != WOLFSSL_EXPORT_VERSION_4 && - ver != WOLFSSL_EXPORT_VERSION_3) { + if (ver != WOLFSSL_EXPORT_VERSION && ver != WOLFSSL_EXPORT_VERSION_5 && + ver != WOLFSSL_EXPORT_VERSION_4 && ver != WOLFSSL_EXPORT_VERSION_3) { WOLFSSL_MSG("Export version not supported"); return BAD_FUNC_ARG; } @@ -1982,6 +1993,15 @@ int wolfSSL_session_import_internal(WOLFSSL* ssl, const unsigned char* buf, } break; + case WOLFSSL_EXPORT_VERSION_5: + if (type == WOLFSSL_EXPORT_DTLS) { + optSz = DTLS_EXPORT_OPT_SZ_5; + } + else { + optSz = TLS_EXPORT_OPT_SZ_5; + } + break; + case WOLFSSL_EXPORT_VERSION_4: if (type == WOLFSSL_EXPORT_DTLS) { optSz = DTLS_EXPORT_OPT_SZ_4; @@ -13696,6 +13716,16 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen, continue; } + /* RFC 9525 Sec. 6.3: a DNS-ID reference identifier is matched only + * against dNSName SAN entries, never uniformResourceIdentifier + * (even when the URI value resembles a ostname). URI-ID matching + * requires scheme and host parsing (RFC 9525 Sec. 6.5, Sec. 7.2). */ + if (!isIP && altName->type == ASN_URI_TYPE) { + WOLFSSL_MSG("\tAltName is uniformResourceIdentifier, " + "skipping for DNS hostname"); + continue; + } + if (MatchDomainName(buf, (int)len, domain, domainLen, flags)) { match = 1; if (checkCN != NULL) { diff --git a/src/ocsp.c b/src/ocsp.c index b90fcc8af9..c84eebc5e5 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -776,7 +776,8 @@ int wolfSSL_OCSP_resp_find_status(WOLFSSL_OCSP_BASICRESP *bs, single = bs->single; while (single != NULL) { if (single->status != NULL && id->status != NULL && - (XMEMCMP(single->status->serial, id->status->serial, + (single->status->serialSz == id->status->serialSz) + && (XMEMCMP(single->status->serial, id->status->serial, (size_t)single->status->serialSz) == 0) && (XMEMCMP(single->issuerHash, id->issuerHash, OCSP_DIGEST_SIZE) == 0) && (XMEMCMP(single->issuerKeyHash, id->issuerKeyHash, OCSP_DIGEST_SIZE) == 0)) { @@ -1270,7 +1271,7 @@ OcspResponse* wolfSSL_d2i_OCSP_RESPONSE(OcspResponse** response, int length = 0; int ret; - if (data == NULL) + if (data == NULL || *data == NULL || len <= 0) return NULL; if (response != NULL) @@ -1283,30 +1284,27 @@ OcspResponse* wolfSSL_d2i_OCSP_RESPONSE(OcspResponse** response, XMEMSET(resp, 0, sizeof(OcspResponse)); } + if (resp->source != NULL) + XFREE(resp->source, NULL, DYNAMIC_TYPE_TMP_BUFFER); resp->source = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_TMP_BUFFER); - if (resp->source == NULL) { - XFREE(resp, NULL, DYNAMIC_TYPE_OCSP_REQUEST); - return NULL; + if (resp->source == NULL) + goto error; + + if (resp->single != NULL) { + FreeOcspEntry(resp->single, NULL); + XFREE(resp->single, NULL, DYNAMIC_TYPE_OCSP_ENTRY); } resp->single = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL, DYNAMIC_TYPE_OCSP_ENTRY); - if (resp->single == NULL) { - XFREE(resp->source, NULL, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(resp, NULL, DYNAMIC_TYPE_OCSP_REQUEST); - return NULL; - } + if (resp->single == NULL) + goto error; XMEMSET(resp->single, 0, sizeof(OcspEntry)); resp->single->status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL, DYNAMIC_TYPE_OCSP_STATUS); + if (resp->single->status == NULL) + goto error; resp->single->ownStatus = 1; - if (resp->single->status == NULL) { - XFREE(resp->source, NULL, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(resp->single, NULL, DYNAMIC_TYPE_OCSP_ENTRY); - XFREE(resp, NULL, DYNAMIC_TYPE_OCSP_REQUEST); - return NULL; - } XMEMSET(resp->single->status, 0, sizeof(CertStatus)); - XMEMCPY(resp->source, *data, (size_t)len); resp->maxIdx = (word32)len; @@ -1314,8 +1312,7 @@ OcspResponse* wolfSSL_d2i_OCSP_RESPONSE(OcspResponse** response, if (ret != 0 && ret != WC_NO_ERR_TRACE(ASN_OCSP_CONFIRM_E)) { /* for just converting from a DER to an internal structure the CA may * not yet be known to this function for signature verification */ - wolfSSL_OCSP_RESPONSE_free(resp); - return NULL; + goto error; } if (GetSequence(*data, &idx, &length, (word32)len) >= 0) @@ -1325,6 +1322,12 @@ OcspResponse* wolfSSL_d2i_OCSP_RESPONSE(OcspResponse** response, *response = resp; return resp; + +error: + wolfSSL_OCSP_RESPONSE_free(resp); + if (response != NULL && *response == resp) + *response = NULL; + return NULL; } int wolfSSL_i2d_OCSP_RESPONSE(OcspResponse* response, diff --git a/src/pk.c b/src/pk.c index 410cce3a95..131e1367e0 100644 --- a/src/pk.c +++ b/src/pk.c @@ -292,11 +292,10 @@ static int der_write_to_bio_as_pem(const unsigned char* der, int derSz, #endif #endif -#if defined(OPENSSL_EXTRA) && \ - ((!defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)) || \ - (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || \ - (defined(HAVE_ECC) && defined(WOLFSSL_KEY_GEN))) -#if !defined(NO_FILESYSTEM) +#if !defined(NO_FILESYSTEM) && \ + ((defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN) && \ + !defined(NO_PWDBASED)) || \ + defined(WOLFSSL_DH_EXTRA)) /* Write the DER data as PEM into file pointer. * * @param [in] der Buffer containing DER data. @@ -326,8 +325,9 @@ static int der_write_to_file_as_pem(const unsigned char* der, int derSz, XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER); return ret; } -#endif -#endif +#endif /* !NO_FILESYSTEM && + * ((OPENSSL_EXTRA && !NO_CERTS && !NO_ASN && !NO_PWDBASED) || + * WOLFSSL_DH_EXTRA) */ #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \ defined(WOLFSSL_PEM_TO_DER) @@ -6282,6 +6282,166 @@ int wolfSSL_PEM_write_bio_PrivateKey(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key, } #endif /* !NO_BIO */ +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \ + !defined(NO_ASN) && !defined(NO_PWDBASED) +/* Writes a public key to a file pointer encoded in PEM format. + * + * @param [in] fp File pointer to write to. + * @param [in] key Public key to write in PEM format. + * @return 1 on success. + * @return 0 on failure. + */ +int wolfSSL_PEM_write_PUBKEY(XFILE fp, WOLFSSL_EVP_PKEY* key) +{ + int err = 0; + unsigned char* derBuf = NULL; + int derSz = 0; + + WOLFSSL_ENTER("wolfSSL_PEM_write_PUBKEY"); + + if ((fp == XBADFILE) || (key == NULL)) { + WOLFSSL_MSG("Bad Function Arguments"); + err = 1; + } + + if (!err) { + derSz = wolfSSL_i2d_PUBKEY(key, NULL); + if (derSz <= 0) { + WOLFSSL_MSG("Failed to get DER size for key"); + err = 1; + } + } + + if (!err) { + unsigned char* tmp; + derBuf = (unsigned char*)XMALLOC((size_t)derSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (derBuf == NULL) { + WOLFSSL_MSG("Failed to allocate DER buffer"); + err = 1; + } + else { + tmp = derBuf; + if (wolfSSL_i2d_PUBKEY(key, &tmp) <= 0) { + WOLFSSL_MSG("Failed to convert key to DER"); + err = 1; + } + } + } + + /* Write DER buffer to file as PEM. */ + if ((!err) && (der_write_to_file_as_pem(derBuf, derSz, fp, + PUBLICKEY_TYPE, NULL) != 1)) { + WOLFSSL_MSG("Failed to write DER to file as PEM"); + err = 1; + } + + /* Dispose of the DER encoding. */ + XFREE(derBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + + WOLFSSL_LEAVE("wolfSSL_PEM_write_PUBKEY", err); + return !err; +} + +/* Writes a private key to a file pointer encoded in PEM format. + * + * @param [in] fp File pointer to write to. + * @param [in] key Private key to write in PEM format. + * @param [in] cipher Encryption cipher to use. May be NULL. + * @param [in] passwd Password to use when encrypting. May be NULL. + * @param [in] len Length of password. + * @param [in] cb Password callback. + * @param [in] arg Password callback argument. + * @return 1 on success. + * @return 0 on failure. + */ +int wolfSSL_PEM_write_PrivateKey(XFILE fp, WOLFSSL_EVP_PKEY* key, + const WOLFSSL_EVP_CIPHER* cipher, unsigned char* passwd, int len, + wc_pem_password_cb* cb, void* arg) +{ + int err = 0; + int type = 0; + unsigned char* derBuf = NULL; + int derSz = 0; + + (void)cipher; + (void)passwd; + (void)len; + (void)cb; + (void)arg; + + WOLFSSL_ENTER("wolfSSL_PEM_write_PrivateKey"); + + /* Validate parameters. */ + if ((fp == XBADFILE) || (key == NULL)) { + WOLFSSL_MSG("Bad Function Arguments"); + err = 1; + } + + /* Determine PEM type from key type, mirroring wolfSSL_PEM_read_PrivateKey's + * keyFormat switch. */ + if (!err) { + switch (key->type) { + case WC_EVP_PKEY_RSA: + type = PRIVATEKEY_TYPE; + break; + case WC_EVP_PKEY_DSA: + type = DSA_PRIVATEKEY_TYPE; + break; + case WC_EVP_PKEY_EC: + type = ECC_PRIVATEKEY_TYPE; + break; + case WC_EVP_PKEY_DH: + type = DH_PRIVATEKEY_TYPE; + break; + default: + WOLFSSL_MSG("Unknown key type"); + err = 1; + break; + } + } + + if (!err) { + derSz = wolfSSL_i2d_PrivateKey(key, NULL); + if (derSz <= 0) { + WOLFSSL_MSG("Failed to get DER size for private key"); + err = 1; + } + } + + if (!err) { + unsigned char* tmp; + derBuf = (unsigned char*)XMALLOC((size_t)derSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (derBuf == NULL) { + WOLFSSL_MSG("Failed to allocate DER buffer"); + err = 1; + } + else { + tmp = derBuf; + if (wolfSSL_i2d_PrivateKey(key, &tmp) <= 0) { + WOLFSSL_MSG("Error encoding private key as DER"); + err = 1; + } + } + } + + /* Write DER buffer to file as PEM. */ + if ((!err) && (der_write_to_file_as_pem(derBuf, derSz, fp, type, + NULL) != 1)) { + WOLFSSL_MSG("Error writing DER to file as PEM"); + err = 1; + } + + /* Dispose of the DER encoding. */ + XFREE(derBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + + WOLFSSL_LEAVE("wolfSSL_PEM_write_PrivateKey", err); + return !err; +} +#endif /* !NO_FILESYSTEM && !NO_CERTS && OPENSSL_EXTRA && !NO_ASN && + * !NO_PWDBASED */ + #ifndef NO_BIO /* Create a private key object from the data in the BIO. * diff --git a/src/ssl.c b/src/ssl.c index 2669f37aa1..b7fe52ddde 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -12978,44 +12978,62 @@ int wolfSSL_set_tlsext_max_fragment_length(WOLFSSL *s, unsigned char mode) size_t wolfSSL_get_finished(const WOLFSSL *ssl, void *buf, size_t count) { byte len = 0; + byte const * src; WOLFSSL_ENTER("wolfSSL_get_finished"); - if (!ssl || !buf || count < TLS_FINISHED_SZ) { + if (!ssl || !buf) { WOLFSSL_MSG("Bad parameter"); return WOLFSSL_FAILURE; } if (ssl->options.side == WOLFSSL_SERVER_END) { + src = ssl->serverFinished; len = ssl->serverFinished_len; - XMEMCPY(buf, ssl->serverFinished, len); } else { + src = ssl->clientFinished; len = ssl->clientFinished_len; - XMEMCPY(buf, ssl->clientFinished, len); } + + if (count < len) { + WOLFSSL_MSG("Buffer too small"); + return WOLFSSL_FAILURE; + } + + XMEMCPY(buf, src, len); + return len; } size_t wolfSSL_get_peer_finished(const WOLFSSL *ssl, void *buf, size_t count) { byte len = 0; + byte const * src; + WOLFSSL_ENTER("wolfSSL_get_peer_finished"); - if (!ssl || !buf || count < TLS_FINISHED_SZ) { + if (!ssl || !buf) { WOLFSSL_MSG("Bad parameter"); return WOLFSSL_FAILURE; } if (ssl->options.side == WOLFSSL_CLIENT_END) { + src = ssl->serverFinished; len = ssl->serverFinished_len; - XMEMCPY(buf, ssl->serverFinished, len); } else { + src = ssl->clientFinished; len = ssl->clientFinished_len; - XMEMCPY(buf, ssl->clientFinished, len); } + if (count < len) { + WOLFSSL_MSG("Buffer too small"); + return WOLFSSL_FAILURE; + } + + XMEMCPY(buf, src, len); + return len; } #endif /* WOLFSSL_HAVE_TLS_UNIQUE */ diff --git a/src/x509.c b/src/x509.c index 73f4c3c92e..11b74af7fd 100644 --- a/src/x509.c +++ b/src/x509.c @@ -945,10 +945,20 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc) WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT); return NULL; } - a->length = (int)x509->pathLength; + /* RFC 5280 4.2.1.9: only populate pathLen when the + * pathLenConstraint field was actually present. When it is + * absent no limit is imposed, and pathlen must remain NULL so + * it is distinguishable from a pathLenConstraint of 0. */ + if (x509->basicConstPlSet) { + a->length = (int)x509->pathLength; - /* Save ASN1_INTEGER in x509 extension */ - ext->obj->pathlen = a; + /* Save ASN1_INTEGER in x509 extension */ + ext->obj->pathlen = a; + } + else { + wolfSSL_ASN1_INTEGER_free(a); + ext->obj->pathlen = NULL; + } ext->obj->ca = x509->isCa; break; @@ -1234,6 +1244,136 @@ static int asn1_string_copy_to_buffer(WOLFSSL_ASN1_STRING* str, byte** buf, return WOLFSSL_SUCCESS; } +/* Handle WC_NID_subject_alt_name for wolfSSL_X509_add_ext: iterate the + * GENERAL_NAME stack on the extension and add each entry to x509->altNames. + * Only types whose union member is WOLFSSL_ASN1_STRING* (DNS/RFC822/URI/IP/ + * IA5) are read via gn->d.ia5; ASN_OTHER_TYPE is handled via SetOthername. + * Other types (DIRNAME/RID/X400/EDIPARTY) are rejected to avoid the + * type-confused union access that would XMEMCPY from a wild pointer in + * wolfSSL_X509_add_altname_ex. */ +static int wolfssl_x509_add_subj_alt_name_ext(WOLFSSL_X509 *x509, + WOLFSSL_X509_EXTENSION *ext) +{ + WOLFSSL_GENERAL_NAMES* gns = ext->ext_sk; + while (gns) { + WOLFSSL_GENERAL_NAME* gn = gns->data.gn; + if ((gn != NULL) && (gn->type == ASN_OTHER_TYPE)) { + char *buf = NULL; + int ret = 0; + word32 len = 0; + + len = SetOthername(gn->d.otherName, NULL); + if (len == WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) { + return WOLFSSL_FAILURE; + } + + buf = (char*)XMALLOC(len, x509->heap, DYNAMIC_TYPE_X509_EXT); + if (buf == NULL) { + WOLFSSL_MSG("Couldn't allocate memory for othername"); + return WOLFSSL_FAILURE; + } + + /* SetOthername() cannot fail; already passed above. */ + SetOthername(gn->d.otherName, (byte*)buf); + + ret = wolfSSL_X509_add_altname_ex(x509, buf, len, + ASN_OTHER_TYPE); + XFREE(buf, x509->heap, DYNAMIC_TYPE_X509_EXT); + if (ret == WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) { + WOLFSSL_MSG("wolfSSL_X509_add_altname_ex() failed"); + return WOLFSSL_FAILURE; + } + } + /* Only types whose union member are WOLFSSL_ASN1_STRING. */ + else if (gn == NULL) { + WOLFSSL_MSG("Subject alternative name missing"); + return WOLFSSL_FAILURE; + } + else { + if ((gn->type != ASN_RFC822_TYPE && gn->type != ASN_DNS_TYPE && + gn->type != ASN_URI_TYPE && gn->type != ASN_IP_TYPE && + gn->type != WOLFSSL_GEN_IA5) || (gn->d.ia5 == NULL)) { + WOLFSSL_MSG("Subject alternative name unsupported " + "GeneralName type or missing name"); + return WOLFSSL_FAILURE; + } + if (wolfSSL_X509_add_altname_ex(x509, gn->d.ia5->data, + gn->d.ia5->length, gn->type) != WOLFSSL_SUCCESS) { + WOLFSSL_MSG("Failed to add subject alternative name"); + return WOLFSSL_FAILURE; + } + } + gns = gns->next; + } + x509->subjAltNameSet = 1; + x509->subjAltNameCrit = (byte)ext->crit; + return WOLFSSL_SUCCESS; +} + +#ifdef WOLFSSL_CUSTOM_OID +/* Handle the default (unrecognized NID) case of wolfSSL_X509_add_ext when + * custom-OID extensions are enabled: copy the extension OID text and value + * into the next free slot in x509->custom_exts, taking ownership of the + * allocations on success. */ +static int wolfssl_x509_add_custom_ext(WOLFSSL_X509 *x509, + WOLFSSL_X509_EXTENSION *ext) +{ + char *oid = NULL; + byte *val = NULL; + int err = 0; + + if ((ext->obj == NULL) || (ext->value.length == 0) || + (ext->value.data == NULL)) { + WOLFSSL_MSG("Extension has insufficient information."); + return WOLFSSL_FAILURE; + } + + if ((x509->customExtCount < 0) || + (x509->customExtCount >= NUM_CUSTOM_EXT)) { + WOLFSSL_MSG("Bad value for customExtCount."); + return WOLFSSL_FAILURE; + } + + /* This is a viable custom extension. */ + oid = (char*)XMALLOC(MAX_OID_STRING_SZ, x509->heap, + DYNAMIC_TYPE_X509_EXT); + val = (byte*)XMALLOC(ext->value.length, x509->heap, + DYNAMIC_TYPE_X509_EXT); + if ((oid == NULL) || (val == NULL)) { + WOLFSSL_MSG("Memory allocation failure.\n"); + err = 1; + } + + if (err == 0) { + XMEMCPY(val, ext->value.data, ext->value.length); + if (wolfSSL_OBJ_obj2txt(oid, MAX_OID_STRING_SZ, ext->obj, 1) < 0) { + err = 1; + } + } + + if (err == 1) { + XFREE(val, x509->heap, DYNAMIC_TYPE_X509_EXT); + XFREE(oid, x509->heap, DYNAMIC_TYPE_X509_EXT); + return WOLFSSL_FAILURE; + } + + /* ext->crit is WOLFSSL_ASN1_BOOLEAN */ + if (ext->crit != 0 && ext->crit != -1) { + XFREE(val, x509->heap, DYNAMIC_TYPE_X509_EXT); + XFREE(oid, x509->heap, DYNAMIC_TYPE_X509_EXT); + return WOLFSSL_FAILURE; + } + + /* x509->custom_exts now owns the buffers and they must be managed. */ + x509->custom_exts[x509->customExtCount].oid = oid; + x509->custom_exts[x509->customExtCount].crit = (byte)ext->crit; + x509->custom_exts[x509->customExtCount].val = val; + x509->custom_exts[x509->customExtCount].valSz = ext->value.length; + x509->customExtCount++; + return WOLFSSL_SUCCESS; +} +#endif /* WOLFSSL_CUSTOM_OID */ + int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext, int loc) { @@ -1272,49 +1412,10 @@ int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext, x509->subjKeyIdCrit = (byte)ext->crit; break; case WC_NID_subject_alt_name: - { - WOLFSSL_GENERAL_NAMES* gns = ext->ext_sk; - while (gns) { - WOLFSSL_GENERAL_NAME* gn = gns->data.gn; - if ((gn != NULL) && (gn->type == ASN_OTHER_TYPE)) { - char *buf = NULL; - int ret = 0; - word32 len = 0; - - len = SetOthername(gn->d.otherName, NULL); - if (len == WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) { - return WOLFSSL_FAILURE; - } - - buf = (char*)XMALLOC(len, x509->heap, DYNAMIC_TYPE_X509_EXT); - if (buf == NULL) { - WOLFSSL_MSG("Couldn't allocate memory for othername"); - return WOLFSSL_FAILURE; - } - - /* SetOthername() cannot fail; already passed above. */ - SetOthername(gn->d.otherName, (byte*)buf); - - ret = wolfSSL_X509_add_altname_ex(x509, buf, len, - ASN_OTHER_TYPE); - XFREE(buf, x509->heap, DYNAMIC_TYPE_X509_EXT); - if (ret == WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) { - WOLFSSL_MSG("wolfSSL_X509_add_altname_ex() failed"); - return WOLFSSL_FAILURE; - } - } - else if (!gn || !gn->d.ia5 || - wolfSSL_X509_add_altname_ex(x509, gn->d.ia5->data, - gn->d.ia5->length, gn->type) != WOLFSSL_SUCCESS) { - WOLFSSL_MSG("Subject alternative name missing extension"); - return WOLFSSL_FAILURE; - } - gns = gns->next; + if (wolfssl_x509_add_subj_alt_name_ext(x509, ext) != WOLFSSL_SUCCESS) { + return WOLFSSL_FAILURE; } - x509->subjAltNameSet = 1; - x509->subjAltNameCrit = (byte)ext->crit; break; - } case WC_NID_key_usage: if (ext && ext->value.data) { if (ext->value.length == sizeof(word16)) { @@ -1376,60 +1477,10 @@ int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext, break; default: #ifdef WOLFSSL_CUSTOM_OID - { - char *oid = NULL; - byte *val = NULL; - int err = 0; - - if ((ext->obj == NULL) || (ext->value.length == 0)) { - WOLFSSL_MSG("Extension has insufficient information."); + if (wolfssl_x509_add_custom_ext(x509, ext) != WOLFSSL_SUCCESS) { return WOLFSSL_FAILURE; } - - if ((x509->customExtCount < 0) || - (x509->customExtCount >= NUM_CUSTOM_EXT)) { - WOLFSSL_MSG("Bad value for customExtCount."); - return WOLFSSL_FAILURE; - } - - /* This is a viable custom extension. */ - oid = (char*)XMALLOC(MAX_OID_STRING_SZ, x509->heap, - DYNAMIC_TYPE_X509_EXT); - val = (byte*)XMALLOC(ext->value.length, x509->heap, - DYNAMIC_TYPE_X509_EXT); - if ((oid == NULL) || (val == NULL)) { - WOLFSSL_MSG("Memory allocation failure.\n"); - err = 1; - } - - if (err == 0) { - XMEMCPY(val, ext->value.data, ext->value.length); - if (wolfSSL_OBJ_obj2txt(oid, MAX_OID_STRING_SZ, ext->obj, 1) < 0) { - err = 1; - } - } - - if (err == 1) { - XFREE(val, x509->heap, DYNAMIC_TYPE_X509_EXT); - XFREE(oid, x509->heap, DYNAMIC_TYPE_X509_EXT); - return WOLFSSL_FAILURE; - } - - /* ext->crit is WOLFSSL_ASN1_BOOLEAN */ - if (ext->crit != 0 && ext->crit != -1) { - XFREE(val, x509->heap, DYNAMIC_TYPE_X509_EXT); - XFREE(oid, x509->heap, DYNAMIC_TYPE_X509_EXT); - return WOLFSSL_FAILURE; - } - - /* x509->custom_exts now owns the buffers and they must be managed. */ - x509->custom_exts[x509->customExtCount].oid = oid; - x509->custom_exts[x509->customExtCount].crit = (byte)ext->crit; - x509->custom_exts[x509->customExtCount].val = val; - x509->custom_exts[x509->customExtCount].valSz = ext->value.length; - x509->customExtCount++; break; - } #else WOLFSSL_MSG("Unsupported extension to add"); return WOLFSSL_FAILURE; @@ -1529,9 +1580,9 @@ int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext, WOLFSSL_MSG("Memory error"); return rc; } - valLen = XSNPRINTF(val, (size_t)len, "%*s%s", indent, "", - str->strData); - if ((valLen < 0) || (valLen >= len) + valLen = XSNPRINTF(val, (size_t)len + indent, + "%*s%.*s", indent, "", str->length, str->data); + if ((valLen < 0) || (valLen >= len + indent) || ((tmpLen + valLen) >= tmpSz)) { XFREE(val, NULL, DYNAMIC_TYPE_TMP_BUFFER); return rc; @@ -1549,6 +1600,10 @@ int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext, { char* asn1str; asn1str = wolfSSL_i2s_ASN1_STRING(NULL, str); + if (asn1str == NULL) { + WOLFSSL_MSG("wolfSSL_i2s_ASN1_STRING returned NULL"); + return rc; + } tmpLen = XSNPRINTF(tmp, tmpSz, "%*s%s", indent, "", asn1str); XFREE(asn1str, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmpLen >= tmpSz) @@ -1961,7 +2016,13 @@ void* wolfSSL_X509V3_EXT_d2i(WOLFSSL_X509_EXTENSION* ext) } /* Copy pathlen and CA into BASIC_CONSTRAINTS from object */ bc->ca = object->ca; - if (object->pathlen != NULL && object->pathlen->length > 0) { + /* RFC 5280 4.2.1.9: + * "A pathLenConstraint of zero indicates that no non-self-issued + * intermediate CA certificates may follow in a valid + * certification path." + * Check for length of 0 or greater. + */ + if ((object->pathlen != NULL) && (object->pathlen->length >= 0)) { bc->pathlen = wolfSSL_ASN1_INTEGER_dup(object->pathlen); if (bc->pathlen == NULL) { WOLFSSL_MSG("Failed to duplicate ASN1_INTEGER"); @@ -2433,27 +2494,31 @@ void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509, int nid, int* c, switch (nid) { case BASIC_CA_OID: if (x509->basicConstSet) { - WOLFSSL_ASN1_INTEGER* a; - bc = wolfSSL_BASIC_CONSTRAINTS_new(); if (!bc) { WOLFSSL_MSG("wolfSSL_BASIC_CONSTRAINTS_new error"); return NULL; } - a = wolfSSL_ASN1_INTEGER_new(); - if (!a) { - WOLFSSL_MSG("wolfSSL_ASN1_INTEGER_new error"); - wolfSSL_BASIC_CONSTRAINTS_free(bc); - return NULL; - } - a->length = (int)x509->pathLength; - #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \ defined(WOLFSSL_APACHE_HTTPD) bc->ca = x509->isCa; #endif - bc->pathlen = a; + /* RFC 5280 4.2.1.9: only populate pathLen when the + * pathLenConstraint field was present. When absent, no limit + * is imposed and pathlen must remain NULL so it is + * distinguishable from a pathLenConstraint of 0. */ + if (x509->basicConstPlSet) { + WOLFSSL_ASN1_INTEGER* a = wolfSSL_ASN1_INTEGER_new(); + if (a == NULL) { + WOLFSSL_MSG("wolfSSL_ASN1_INTEGER_new error"); + wolfSSL_BASIC_CONSTRAINTS_free(bc); + return NULL; + } + a->length = (int)x509->pathLength; + bc->pathlen = a; + } + if (c != NULL) { *c = x509->basicConstCrit; } @@ -2648,14 +2713,15 @@ void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509, int nid, int* c, WOLFSSL_MSG("wolfSSL_sk_GENERAL_NAME_push error"); goto err; } + /* gn now owned by stack. */ + gn = NULL; /* push DIST_POINT onto stack */ if (wolfSSL_sk_DIST_POINT_push(sk, dp) <= 0) { WOLFSSL_MSG("Error pushing DIST_POINT onto stack"); goto err; } - - gn = NULL; + /* dp now owned by stack. */ dp = NULL; } @@ -5871,8 +5937,7 @@ int wolfSSL_GENERAL_NAME_print(WOLFSSL_BIO* out, WOLFSSL_GENERAL_NAME* gen) case GEN_EMAIL: ret = wolfSSL_BIO_printf(out, "email:"); ret = (ret > 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE; - if (ret == WOLFSSL_SUCCESS) - { + if (ret == WOLFSSL_SUCCESS) { ret = wolfSSL_ASN1_STRING_print(out, gen->d.rfc822Name); } break; @@ -5881,8 +5946,7 @@ int wolfSSL_GENERAL_NAME_print(WOLFSSL_BIO* out, WOLFSSL_GENERAL_NAME* gen) ret = wolfSSL_BIO_printf(out, "DNS:"); ret = (ret > 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE; if (ret == WOLFSSL_SUCCESS) { - ret = wolfSSL_BIO_printf(out, "%s", gen->d.dNSName->strData); - ret = (ret > 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE; + ret = wolfSSL_ASN1_STRING_print(out, gen->d.dNSName); } break; @@ -5893,6 +5957,7 @@ int wolfSSL_GENERAL_NAME_print(WOLFSSL_BIO* out, WOLFSSL_GENERAL_NAME* gen) case GEN_DIRNAME: ret = wolfSSL_BIO_printf(out, "DirName:"); + ret = (ret > 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE; if (ret == WOLFSSL_SUCCESS) { ret = wolfSSL_X509_NAME_print_ex(out, gen->d.directoryName, 0, XN_FLAG_ONELINE); @@ -7094,7 +7159,8 @@ static int X509PrintExtendedKeyUsage(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, EXTKEYUSE_EMAILPROT, EXTKEYUSE_CODESIGN, EXTKEYUSE_CLIENT_AUTH, - EXTKEYUSE_SERVER_AUTH + EXTKEYUSE_SERVER_AUTH, + EXTKEYUSE_ANY }; const char* usageStrs[] = { "OCSP Signing", @@ -7102,7 +7168,8 @@ static int X509PrintExtendedKeyUsage(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, "E-mail Protection", "Code Signing", "TLS Web Client Authentication", - "TLS Web Server Authentication" + "TLS Web Server Authentication", + "Any Extended Key Usage" }; if (bio == NULL || x509 == NULL) { @@ -7483,12 +7550,22 @@ static int X509PrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent) ret = WOLFSSL_FAILURE; break; } - if ((scratchLen = XSNPRINTF( - scratch, scratchSz, - "%*sCA:%s\n", - indent + 8, "", (x509->isCa)? "TRUE": "FALSE")) - >= scratchSz) - { + /* Match OpenSSL output: print "CA:TRUE"/"CA:FALSE" and append + * ", pathlen:N" only when a pathLenConstraint is present + * (RFC 5280 4.2.1.9). An absent constraint imposes no limit + * and must not be shown as pathlen:0. */ + if (x509->basicConstPlSet) { + scratchLen = XSNPRINTF(scratch, scratchSz, + "%*sCA:%s, pathlen:%u\n", + indent + 8, "", (x509->isCa) ? "TRUE" : "FALSE", + (unsigned int)x509->pathLength); + } + else { + scratchLen = XSNPRINTF(scratch, scratchSz, + "%*sCA:%s\n", + indent + 8, "", (x509->isCa) ? "TRUE" : "FALSE"); + } + if (scratchLen >= scratchSz) { ret = WOLFSSL_FAILURE; break; } diff --git a/tests/api.c b/tests/api.c index 58a9781239..beb1d1b0f5 100644 --- a/tests/api.c +++ b/tests/api.c @@ -234,12 +234,15 @@ #include #include #include +#include #include #include #include #include +#include #include #include +#include #include #include #include @@ -6466,7 +6469,7 @@ done: #if defined(ENABLE_TLS_CALLBACK_TEST) || \ (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)) /* TLS server for API unit testing - generic */ -static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args) +THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args) { callback_functions* callbacks = ((func_args*)args)->callbacks; @@ -6723,7 +6726,7 @@ cleanup: } /* TLS Client for API unit testing - generic */ -static void run_wolfssl_client(void* args) +void run_wolfssl_client(void* args) { callback_functions* callbacks = ((func_args*)args)->callbacks; @@ -7279,1152 +7282,162 @@ static int test_wolfSSL_get_finished(void) return EXPECT_RESULT(); } -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \ - !defined(NO_SESSION_CACHE) - -/* Sessions to restore/store */ -static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess; -static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess; -static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx; - -static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx) -{ - /* Don't store sessions. Lookup is still enabled. */ - AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); -#ifdef OPENSSL_EXTRA - AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); -#endif - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); -} - -static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl) -{ - WOLFSSL_SESSION** sess; -#ifdef WOLFSSL_MUTEX_INITIALIZER - static wolfSSL_Mutex m = WOLFSSL_MUTEX_INITIALIZER(m); - - (void)wc_LockMutex(&m); -#endif - if (wolfSSL_is_server(ssl)) - sess = &test_wolfSSL_CTX_add_session_server_sess; - else - sess = &test_wolfSSL_CTX_add_session_client_sess; - if (*sess == NULL) { -#ifdef NO_SESSION_CACHE_REF - *sess = wolfSSL_get1_session(ssl); - AssertNotNull(*sess); -#else - /* Test for backwards compatibility */ - if (wolfSSL_is_server(ssl)) { - *sess = wolfSSL_get1_session(ssl); - AssertNotNull(*sess); - } - else { - *sess = wolfSSL_get_session(ssl); - AssertNotNull(*sess); - } -#endif - /* Now save the session in the internal store to make it available - * for lookup. For TLS 1.3, we can't save the session without - * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the - * session from cache. */ - if (wolfSSL_is_server(ssl) -#ifndef WOLFSSL_TICKET_HAVE_ID - && wolfSSL_version(ssl) != TLS1_3_VERSION -#endif - ) - AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl), - *sess), WOLFSSL_SUCCESS); - } - else { - /* If we have a session retrieved then remaining connections should be - * resuming on that session */ - AssertIntEQ(wolfSSL_session_reused(ssl), 1); - } -#ifdef WOLFSSL_MUTEX_INITIALIZER - wc_UnLockMutex(&m); -#endif - - /* Save CTX to be able to decrypt tickets */ - if (wolfSSL_is_server(ssl) && - test_wolfSSL_CTX_add_session_server_ctx == NULL) { - test_wolfSSL_CTX_add_session_server_ctx = wolfSSL_get_SSL_CTX(ssl); - AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx); - AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)), - WOLFSSL_SUCCESS); - } -#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) -#ifndef WOLFSSL_TICKET_HAVE_ID - if (wolfSSL_version(ssl) != TLS1_3_VERSION && - wolfSSL_session_reused(ssl)) -#endif - { - /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available - * for all connections. TLS 1.3 only has tickets so if we don't - * include the session id in the ticket then the certificates - * will not be available on resumption. */ - #ifdef KEEP_PEER_CERT - WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl); - AssertNotNull(peer); - wolfSSL_X509_free(peer); - #endif - AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); - #ifdef OPENSSL_EXTRA - AssertNotNull(SSL_SESSION_get0_peer(*sess)); - #endif - } -#endif /* SESSION_CERTS && !WOLFSSL_NO_CLIENT_AUTH */ -} - -static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl) -{ - /* Set the session to reuse for the client */ - AssertIntEQ(wolfSSL_set_session(ssl, - test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS); -} -#endif - -static int test_wolfSSL_CTX_add_session(void) +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_HAVE_TLS_UNIQUE) && defined(WOLFSSL_TLS13) +static int test_wolfSSL_get_finished_overrun_on_handshake(WOLFSSL_CTX* ctx, + WOLFSSL* ssl) { EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \ - !defined(NO_SESSION_CACHE) - tcp_ready ready; - func_args client_args; - func_args server_args; - THREAD_TYPE serverThread; - callback_functions client_cb; - callback_functions server_cb; - method_provider methods[][2] = { -#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ - !defined(NO_DES3)) - /* Without AES there are almost no ciphersuites available. This leads - * to no ciphersuites being available and an error. */ - { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method }, -#endif -#ifndef WOLFSSL_NO_TLS12 - { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method }, -#endif - /* Needs the default ticket callback since it is tied to the - * connection context and this makes it easy to carry over the ticket - * crypto context between connections */ -#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ - defined(HAVE_SESSION_TICKET) - { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method }, -#endif - }; - const size_t methodsLen = sizeof(methods)/sizeof(*methods); - size_t i, j; + /* Destination buffer immediately followed by a guard region. Both are + * byte arrays (alignment 1) so there is no padding between them and the + * guard bytes sit directly after buf. The caller promises only + * TLS_FINISHED_SZ writable bytes via the count argument, so wolfSSL must + * not write past buf[] into the guard region. */ + struct { + byte buf[TLS_FINISHED_SZ]; + byte guard[WC_MAX_DIGEST_SIZE]; + } probe; + byte full[WC_MAX_DIGEST_SIZE]; + size_t msg_len; + word32 i; - for (i = 0; i < methodsLen; i++) { - /* First run creates a connection while the second+ run will attempt - * to resume the connection. The trick is that the internal cache - * is turned off. wolfSSL_CTX_add_session should put the session in - * the cache anyway. */ - test_wolfSSL_CTX_add_session_client_sess = NULL; - test_wolfSSL_CTX_add_session_server_sess = NULL; - test_wolfSSL_CTX_add_session_server_ctx = NULL; - -#ifdef NO_SESSION_CACHE_REF - for (j = 0; j < 4; j++) { -#else - /* The session may be overwritten in this case. Do only one resumption - * to stop this test from failing intermittently. */ - for (j = 0; j < 2; j++) { -#endif -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif - - StartTCP(); - InitTcpReady(&ready); - - XMEMSET(&client_args, 0, sizeof(func_args)); - XMEMSET(&server_args, 0, sizeof(func_args)); - - XMEMSET(&client_cb, 0, sizeof(callback_functions)); - XMEMSET(&server_cb, 0, sizeof(callback_functions)); - client_cb.method = methods[i][0]; - server_cb.method = methods[i][1]; - - server_args.signal = &ready; - server_args.callbacks = &server_cb; - client_args.signal = &ready; - client_args.callbacks = &client_cb; - - if (test_wolfSSL_CTX_add_session_server_ctx != NULL) { - server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx; - server_cb.isSharedCtx = 1; - } - server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready; - client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready; - if (j != 0) - client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready; - server_cb.on_result = test_wolfSSL_CTX_add_session_on_result; - client_cb.on_result = test_wolfSSL_CTX_add_session_on_result; - server_cb.ticNoInit = 1; /* Use default builtin */ - - start_thread(test_server_nofail, &server_args, &serverThread); - wait_tcp_ready(&server_args); - test_client_nofail(&client_args, NULL); - join_thread(serverThread); - - ExpectTrue(client_args.return_code); - ExpectTrue(server_args.return_code); - - FreeTcpReady(&ready); - - if (EXPECT_FAIL()) - break; - } - wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess); - wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess); - wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx); - - if (EXPECT_FAIL()) - break; - } -#endif - - return EXPECT_RESULT(); -} -#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) - -/* twcase - prefix for test_wolfSSL_CTX_add_session_ext */ -/* Sessions to restore/store */ -static WOLFSSL_SESSION* twcase_server_first_session_ptr; -static WOLFSSL_SESSION* twcase_client_first_session_ptr; -static WOLFSSL_CTX* twcase_server_current_ctx_ptr; -static int twcase_new_session_called = 0; -static int twcase_remove_session_called = 0; -static int twcase_get_session_called = 0; - -/* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */ -#define SESSION_CACHE_SIZE 33 - -typedef struct { - const byte* key; /* key, altSessionID, session ID, NULL if empty */ - WOLFSSL_SESSION* value; -} hashTable_entry; - -typedef struct { - hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */ - size_t capacity; /* size of entries */ - size_t length; /* number of items in the hash table */ - wolfSSL_Mutex htLock; /* lock */ -}hashTable; - -static hashTable server_sessionCache; - -static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess) -{ - int i; - unsigned int len; - (void)ssl; - - /* - * This example uses a hash table. - * Steps you should take for a non-demo code: - * - acquire a lock for the file named according to the session id - * - open the file - * - encrypt and write the SSL_SESSION object to the file - * - release the lock - * - * Return: - * 0: The callback does not wish to hold a reference of the sess - * 1: The callback wants to hold a reference of the sess. The callback is - * now also responsible for calling wolfSSL_SESSION_free() on sess. - */ - if (sess == NULL) - return 0; - - if (wc_LockMutex(&server_sessionCache.htLock) != 0) { - return 0; - } - for (i = 0; i < SESSION_CACHE_SIZE; i++) { - if (server_sessionCache.entries[i].value == NULL) { - server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len); - server_sessionCache.entries[i].value = sess; - server_sessionCache.length++; - break; - } - } - ++twcase_new_session_called; - wc_UnLockMutex(&server_sessionCache.htLock); - fprintf(stderr, "\t\ttwcase_new_session_called %d\n", - twcase_new_session_called); - return 1; -} - -static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess) -{ - int i; (void)ctx; - (void)sess; - if (sess == NULL) - return; - /* - * This example uses a hash table. - * Steps you should take for a non-demo code: - * - acquire a lock for the file named according to the session id - * - remove the file - * - release the lock - */ - if (wc_LockMutex(&server_sessionCache.htLock) != 0) { - return; + XMEMSET(&probe, 0, sizeof(probe)); + XMEMSET(probe.guard, 0x5A, sizeof(probe.guard)); + + /* For a TLS 1.3 connection the Finished message is the handshake hash + * size (32 bytes for SHA-256, 48 for SHA-384), which is larger than the + * count of TLS_FINISHED_SZ (12) we pass here. The buffer is too small to + * hold the Finished message, so the call must fail and write nothing + * rather than copying the full length and overrunning buf[]. */ + msg_len = wolfSSL_get_finished(ssl, probe.buf, TLS_FINISHED_SZ); + ExpectIntEQ(msg_len, WOLFSSL_FAILURE); + + /* Nothing must have been written: buf[] stays zero and the guard bytes + * that follow it stay 0x5A. */ + for (i = 0; i < (word32)sizeof(probe.buf); i++) { + ExpectIntEQ(probe.buf[i], 0x00); } - for (i = 0; i < SESSION_CACHE_SIZE; i++) { - if (server_sessionCache.entries[i].key != NULL && - XMEMCMP(server_sessionCache.entries[i].key, - sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { - wolfSSL_SESSION_free(server_sessionCache.entries[i].value); - server_sessionCache.entries[i].value = NULL; - server_sessionCache.entries[i].key = NULL; - server_sessionCache.length--; - break; - } - } - ++twcase_remove_session_called; - wc_UnLockMutex(&server_sessionCache.htLock); - fprintf(stderr, "\t\ttwcase_remove_session_called %d\n", - twcase_remove_session_called); -} - -static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl, - const unsigned char *id, int len, int *ref) -{ - int i; - (void)ssl; - (void)id; - (void)len; - - /* - * This example uses a hash table. - * Steps you should take for a non-demo code: - * - acquire a lock for the file named according to the session id in the - * 2nd arg - * - read and decrypt contents of file and create a new SSL_SESSION - * - object release the lock - * - return the new session object - */ - fprintf(stderr, "\t\ttwcase_get_session_called %d\n", - ++twcase_get_session_called); - /* This callback want to retain a copy of the object. If we want wolfSSL to - * be responsible for the pointer then set to 0. */ - *ref = 1; - - for (i = 0; i < SESSION_CACHE_SIZE; i++) { - if (server_sessionCache.entries[i].key != NULL && - XMEMCMP(server_sessionCache.entries[i].key, id, - SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { - return server_sessionCache.entries[i].value; - } - } - return NULL; -} -static int twcase_get_sessionCb_cleanup(void) -{ - int i; - int cnt = 0; - - /* If twcase_get_sessionCb sets *ref = 1, the application is responsible - * for freeing sessions */ - - for (i = 0; i < SESSION_CACHE_SIZE; i++) { - if (server_sessionCache.entries[i].value != NULL) { - wolfSSL_SESSION_free(server_sessionCache.entries[i].value); - cnt++; - } + for (i = 0; i < (word32)sizeof(probe.guard); i++) { + ExpectIntEQ(probe.guard[i], 0x5A); } - fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n", - cnt); - - return TEST_SUCCESS; -} - -static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx) -{ - EXPECT_DECLS; - /* off - Disable internal cache */ - ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); -#ifdef OPENSSL_EXTRA - ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); -#endif - /* off - Do not setup external cache */ - - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); - return EXPECT_RESULT(); -} - -static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx) -{ - /* on - internal cache is on by default */ - /* off - Do not setup external cache */ - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); - return TEST_SUCCESS; -} - -static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx) -{ - EXPECT_DECLS; - /* off - Disable internal cache */ - ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); -#ifdef OPENSSL_EXTRA - ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, - WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); -#endif - /* on - Enable external cache */ - wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); - wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); - wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); - - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); - return EXPECT_RESULT(); -} - -static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx) -{ - /* on - internal cache is on by default */ - /* on - Enable external cache */ - wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); - wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); - wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); - - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); - return TEST_SUCCESS; -} -static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx) -{ - /* on - internal cache is on by default */ - /* on - Enable external cache */ - wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); - wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); - wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); - - wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET); - /* Require both peers to provide certs */ - wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); - return TEST_SUCCESS; -} -static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl) -{ - EXPECT_DECLS; - WOLFSSL_SESSION** sess; - if (wolfSSL_is_server(ssl)) - sess = &twcase_server_first_session_ptr; - else - return TEST_SUCCESS; - - if (*sess == NULL) { - ExpectNotNull(*sess = wolfSSL_get1_session(ssl)); - /* Now save the session in the internal store to make it available - * for lookup. For TLS 1.3, we can't save the session without - * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the - * session from cache. */ - if (wolfSSL_is_server(ssl) -#ifndef WOLFSSL_TICKET_HAVE_ID - && wolfSSL_version(ssl) != TLS1_3_VERSION - && wolfSSL_version(ssl) != DTLS1_3_VERSION -#endif - ) { - ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl), - *sess), WOLFSSL_SUCCESS); - } - } - /* Save CTX to be able to decrypt tickets */ - if (twcase_server_current_ctx_ptr == NULL) { - ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl)); - ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)), - WOLFSSL_SUCCESS); - } -#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) -#ifndef WOLFSSL_TICKET_HAVE_ID - if (wolfSSL_version(ssl) != TLS1_3_VERSION && - wolfSSL_session_reused(ssl)) -#endif - { - /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available - * for all connections. TLS 1.3 only has tickets so if we don't - * include the session id in the ticket then the certificates - * will not be available on resumption. */ - #ifdef KEEP_PEER_CERT - WOLFSSL_X509* peer = NULL; - ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl)); - wolfSSL_X509_free(peer); - #endif - ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); - } -#endif - return EXPECT_RESULT(); -} - -static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl) -{ - EXPECT_DECLS; - WOLFSSL_SESSION** sess; - sess = &twcase_client_first_session_ptr; - if (*sess == NULL) { - ExpectNotNull(*sess = wolfSSL_get1_session(ssl)); - } - else { - /* If we have a session retrieved then remaining connections should be - * resuming on that session */ - ExpectIntEQ(wolfSSL_session_reused(ssl), 1); - } - -#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) -#ifndef WOLFSSL_TICKET_HAVE_ID - if (wolfSSL_version(ssl) != TLS1_3_VERSION && - wolfSSL_session_reused(ssl)) -#endif - { - #ifdef KEEP_PEER_CERT - WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl); - ExpectNotNull(peer); - wolfSSL_X509_free(peer); - #endif - ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); -#ifdef OPENSSL_EXTRA - ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess)); -#endif - } -#endif - return EXPECT_RESULT(); -} -static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl) -{ - EXPECT_DECLS; - /* Set the session to reuse for the client */ - ExpectNotNull(ssl); - ExpectNotNull(twcase_client_first_session_ptr); - ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr), - WOLFSSL_SUCCESS); - return EXPECT_RESULT(); -} - -struct test_add_session_ext_params { - method_provider client_meth; - method_provider server_meth; - const char* tls_version; -}; - -static int test_wolfSSL_CTX_add_session_ext( - struct test_add_session_ext_params* param) -{ - EXPECT_DECLS; - /* Test the default 33 sessions */ - int j; - - /* Clear cache before starting */ - wolfSSL_CTX_flush_sessions(NULL, -1); - - XMEMSET(&server_sessionCache, 0, sizeof(hashTable)); - if (wc_InitMutex(&server_sessionCache.htLock) != 0) - return BAD_MUTEX_E; - server_sessionCache.capacity = SESSION_CACHE_SIZE; - - fprintf(stderr, "\tBegin %s\n", param->tls_version); - for (j = 0; j < 5; j++) { - int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL; - int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL; - test_ssl_cbf client_cb; - test_ssl_cbf server_cb; - - (void)dtls; - - /* Test five cache configurations */ - twcase_client_first_session_ptr = NULL; - twcase_server_first_session_ptr = NULL; - twcase_server_current_ctx_ptr = NULL; - twcase_new_session_called = 0; - twcase_remove_session_called = 0; - twcase_get_session_called = 0; - - /* connection 1 - first connection */ - fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j); - - XMEMSET(&client_cb, 0, sizeof(client_cb)); - XMEMSET(&server_cb, 0, sizeof(server_cb)); - client_cb.method = param->client_meth; - server_cb.method = param->server_meth; - - if (dtls) - client_cb.doUdp = server_cb.doUdp = 1; - - /* Setup internal and external cache */ - switch (j) { - case 0: - /* SSL_OP_NO_TICKET stateful ticket case */ - server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket; - break; - case 1: - server_cb.ctx_ready = twcase_cache_intOn_extOn; - break; - case 2: - server_cb.ctx_ready = twcase_cache_intOff_extOn; - break; - case 3: - server_cb.ctx_ready = twcase_cache_intOn_extOff; - break; - case 4: - server_cb.ctx_ready = twcase_cache_intOff_extOff; - break; - } - client_cb.ctx_ready = twcase_cache_intOff_extOff; - - /* Add session to internal cache and save SSL session for testing */ - server_cb.on_result = twcase_server_sess_ctx_pre_shutdown; - /* Save client SSL session for testing */ - client_cb.on_result = twcase_client_sess_ctx_pre_shutdown; - server_cb.ticNoInit = 1; /* Use default builtin */ - /* Don't free/release ctx */ - server_cb.ctx = twcase_server_current_ctx_ptr; - server_cb.isSharedCtx = 1; - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, - &server_cb, NULL), TEST_SUCCESS); - - ExpectIntEQ(twcase_get_session_called, 0); - if (EXPECT_FAIL()) { - wolfSSL_SESSION_free(twcase_client_first_session_ptr); - wolfSSL_SESSION_free(twcase_server_first_session_ptr); - wolfSSL_CTX_free(twcase_server_current_ctx_ptr); - break; - } - - switch (j) { - case 0: - case 1: - case 2: - /* cache cannot be searched with out a connection */ - /* Add a new session */ - ExpectIntEQ(twcase_new_session_called, 1); - /* In twcase_server_sess_ctx_pre_shutdown - * wolfSSL_CTX_add_session which evicts the existing session - * in cache and adds it back in */ - ExpectIntLE(twcase_remove_session_called, 1); - break; - case 3: - case 4: - /* no external cache */ - ExpectIntEQ(twcase_new_session_called, 0); - ExpectIntEQ(twcase_remove_session_called, 0); - break; - } - - /* connection 2 - session resume */ - fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j); - twcase_new_session_called = 0; - twcase_remove_session_called = 0; - twcase_get_session_called = 0; - server_cb.on_result = 0; - client_cb.on_result = 0; - server_cb.ticNoInit = 1; /* Use default builtin */ - - server_cb.ctx = twcase_server_current_ctx_ptr; - - /* try session resumption */ - client_cb.ssl_ready = twcase_client_set_sess_ssl_ready; - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, - &server_cb, NULL), TEST_SUCCESS); - - /* Clear cache before checking */ - wolfSSL_CTX_flush_sessions(NULL, -1); - - switch (j) { - case 0: - if (tls13) { - /* (D)TLSv1.3 stateful case */ - /* cache hit */ - /* DTLS accesses cache once for stateless parsing and - * once for stateful parsing */ - ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); - - /* (D)TLSv1.3 creates a new ticket, - * updates both internal and external cache */ - ExpectIntEQ(twcase_new_session_called, 1); - /* A new session ID is created for a new ticket */ - ExpectIntEQ(twcase_remove_session_called, 2); - - } - else { - /* non (D)TLSv1.3 case, no update */ - /* DTLS accesses cache once for stateless parsing and - * once for stateful parsing */ -#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME - ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); -#else - ExpectIntEQ(twcase_get_session_called, 1); -#endif - ExpectIntEQ(twcase_new_session_called, 0); - /* Called on session added in - * twcase_server_sess_ctx_pre_shutdown */ - ExpectIntEQ(twcase_remove_session_called, 1); - } - break; - case 1: - if (tls13) { - /* (D)TLSv1.3 case */ - /* cache hit */ - ExpectIntEQ(twcase_get_session_called, 1); - /* (D)TLSv1.3 creates a new ticket, - * updates both internal and external cache */ - ExpectIntEQ(twcase_new_session_called, 1); - /* Called on session added in - * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */ - ExpectIntEQ(twcase_remove_session_called, 1); - } - else { - /* non (D)TLSv1.3 case */ - /* cache hit */ - /* DTLS accesses cache once for stateless parsing and - * once for stateful parsing */ -#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME - ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); -#else - ExpectIntEQ(twcase_get_session_called, 1); -#endif - ExpectIntEQ(twcase_new_session_called, 0); - /* Called on session added in - * twcase_server_sess_ctx_pre_shutdown */ - ExpectIntEQ(twcase_remove_session_called, 1); - } - break; - case 2: - if (tls13) { - /* (D)TLSv1.3 case */ - /* cache hit */ - ExpectIntEQ(twcase_get_session_called, 1); - /* (D)TLSv1.3 creates a new ticket, - * updates both internal and external cache */ - ExpectIntEQ(twcase_new_session_called, 1); - /* Called on session added in - * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */ - ExpectIntEQ(twcase_remove_session_called, 1); - } - else { - /* non (D)TLSv1.3 case */ - /* cache hit */ - /* DTLS accesses cache once for stateless parsing and - * once for stateful parsing */ -#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME - ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); -#else - ExpectIntEQ(twcase_get_session_called, 1); -#endif - ExpectIntEQ(twcase_new_session_called, 0); - /* Called on session added in - * twcase_server_sess_ctx_pre_shutdown */ - ExpectIntEQ(twcase_remove_session_called, 1); - } - break; - case 3: - case 4: - /* no external cache */ - ExpectIntEQ(twcase_get_session_called, 0); - ExpectIntEQ(twcase_new_session_called, 0); - ExpectIntEQ(twcase_remove_session_called, 0); - break; - } - wolfSSL_SESSION_free(twcase_client_first_session_ptr); - wolfSSL_SESSION_free(twcase_server_first_session_ptr); - wolfSSL_CTX_free(twcase_server_current_ctx_ptr); - - if (EXPECT_FAIL()) - break; - } - twcase_get_sessionCb_cleanup(); - XMEMSET(&server_sessionCache.entries, 0, - sizeof(server_sessionCache.entries)); - fprintf(stderr, "\tEnd %s\n", param->tls_version); - - wc_FreeMutex(&server_sessionCache.htLock); + /* A sufficiently large buffer must still succeed and report the actual + * Finished length, which is between TLS_FINISHED_SZ and the max digest + * size. */ + XMEMSET(full, 0, sizeof(full)); + msg_len = wolfSSL_get_finished(ssl, full, sizeof(full)); + ExpectIntGE(msg_len, TLS_FINISHED_SZ); + ExpectIntLE(msg_len, WC_MAX_DIGEST_SIZE); return EXPECT_RESULT(); } -#endif +#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE && + * WOLFSSL_TLS13 */ -static int test_wolfSSL_CTX_add_session_ext_tls13(void) +static int test_wolfSSL_get_finished_overrun(void) { EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ - defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) - struct test_add_session_ext_params param[1] = { - { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif - return EXPECT_RESULT(); -} -static int test_wolfSSL_CTX_add_session_ext_dtls13(void) -{ - EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ - defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) -#ifdef WOLFSSL_DTLS13 - struct test_add_session_ext_params param[1] = { - { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif -#endif - return EXPECT_RESULT(); -} -static int test_wolfSSL_CTX_add_session_ext_tls12(void) -{ - EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#ifndef WOLFSSL_NO_TLS12 - struct test_add_session_ext_params param[1] = { - { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif - return EXPECT_RESULT(); -} -static int test_wolfSSL_CTX_add_session_ext_dtls12(void) -{ - EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#ifndef WOLFSSL_NO_TLS12 -#ifdef WOLFSSL_DTLS - struct test_add_session_ext_params param[1] = { - { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif -#endif - return EXPECT_RESULT(); -} -static int test_wolfSSL_CTX_add_session_ext_tls11(void) -{ - EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ - !defined(NO_DES3)) - struct test_add_session_ext_params param[1] = { - { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif - return EXPECT_RESULT(); -} -static int test_wolfSSL_CTX_add_session_ext_dtls1(void) -{ - EXPECT_DECLS; -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ - defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ - defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ - defined(HAVE_SESSION_TICKET) && \ - !defined(TITAN_SESSION_CACHE) && \ - !defined(HUGE_SESSION_CACHE) && \ - !defined(BIG_SESSION_CACHE) && \ - !defined(MEDIUM_SESSION_CACHE) -#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ - !defined(NO_DES3)) -#ifdef WOLFSSL_DTLS - struct test_add_session_ext_params param[1] = { - { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" } - }; - ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); -#endif -#endif -#endif +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_HAVE_TLS_UNIQUE) && defined(WOLFSSL_TLS13) + test_ssl_cbf client_cbf; + test_ssl_cbf server_cbf; + + XMEMSET(&client_cbf, 0, sizeof(client_cbf)); + XMEMSET(&server_cbf, 0, sizeof(server_cbf)); + + /* Force TLS 1.3 so the stored Finished length exceeds TLS_FINISHED_SZ. */ + client_cbf.method = wolfTLSv1_3_client_method; + server_cbf.method = wolfTLSv1_3_server_method; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, + &server_cbf, test_wolfSSL_get_finished_overrun_on_handshake), + TEST_SUCCESS); +#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE && + * WOLFSSL_TLS13 */ + return EXPECT_RESULT(); } -#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) -/* canned export of a session using older version 3 */ -static unsigned char version_3[] = { - 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, - 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05, - 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, - 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01, - 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05, - 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D, - 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B, - 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98, - 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0, - 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74, - 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26, - 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9, - 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04, - 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D, - 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00, - 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01, - 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00, - 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, - 0x2E, 0x31, 0xED, 0x4F -}; -#endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */ - -static int test_wolfSSL_dtls_export(void) +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_HAVE_TLS_UNIQUE) && defined(WOLFSSL_TLS13) +static int test_wolfSSL_get_peer_finished_overrun_on_handshake(WOLFSSL_CTX* ctx, + WOLFSSL* ssl) { EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) - tcp_ready ready; - func_args client_args; - func_args server_args; - THREAD_TYPE serverThread; - callback_functions server_cbf; - callback_functions client_cbf; -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif + /* Destination buffer immediately followed by a guard region. Both are + * byte arrays (alignment 1) so there is no padding between them and the + * guard bytes sit directly after buf. The caller promises only + * TLS_FINISHED_SZ writable bytes via the count argument, so wolfSSL must + * not write past buf[] into the guard region. */ + struct { + byte buf[TLS_FINISHED_SZ]; + byte guard[WC_MAX_DIGEST_SIZE]; + } probe; + byte full[WC_MAX_DIGEST_SIZE]; + size_t msg_len; + word32 i; - InitTcpReady(&ready); + (void)ctx; - /* set using dtls */ - XMEMSET(&client_args, 0, sizeof(func_args)); - XMEMSET(&server_args, 0, sizeof(func_args)); - XMEMSET(&server_cbf, 0, sizeof(callback_functions)); - XMEMSET(&client_cbf, 0, sizeof(callback_functions)); - server_cbf.method = wolfDTLSv1_2_server_method; - client_cbf.method = wolfDTLSv1_2_client_method; - server_args.callbacks = &server_cbf; - client_args.callbacks = &client_cbf; + XMEMSET(&probe, 0, sizeof(probe)); + XMEMSET(probe.guard, 0x5A, sizeof(probe.guard)); - server_args.signal = &ready; - client_args.signal = &ready; + /* For a TLS 1.3 connection the peer Finished message is the handshake + * hash size (32 bytes for SHA-256, 48 for SHA-384), which is larger than + * the count of TLS_FINISHED_SZ (12) we pass here. The buffer is too small + * to hold the Finished message, so the call must fail and write nothing + * rather than copying the full length and overrunning buf[]. */ + msg_len = wolfSSL_get_peer_finished(ssl, probe.buf, TLS_FINISHED_SZ); + ExpectIntEQ(msg_len, WOLFSSL_FAILURE); - start_thread(run_wolfssl_server, &server_args, &serverThread); - wait_tcp_ready(&server_args); - run_wolfssl_client(&client_args); - join_thread(serverThread); - - ExpectTrue(client_args.return_code); - ExpectTrue(server_args.return_code); - - FreeTcpReady(&ready); - -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif - - if (EXPECT_SUCCESS()) { - SOCKET_T sockfd = 0; - WOLFSSL_CTX* ctx = NULL; - WOLFSSL* ssl = NULL; - char msg[64] = "hello wolfssl!"; - char reply[1024]; - int msgSz = (int)XSTRLEN(msg); - byte *session, *window; - unsigned int sessionSz = 0; - unsigned int windowSz = 0; - -#ifndef TEST_IPV6 - struct sockaddr_in peerAddr; -#else - struct sockaddr_in6 peerAddr; -#endif /* TEST_IPV6 */ - - int i; - - - /* Set ctx to DTLS 1.2 */ - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); - ExpectNotNull(ssl = wolfSSL_new(ctx)); - - /* test importing version 3 */ - ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); - - /* test importing bad length and bad version */ - version_3[2]++; - ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); - version_3[2]--; version_3[1] = 0XA0; - ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); - wolfSSL_free(ssl); - wolfSSL_CTX_free(ctx); - - - /* check storing client state after connection and storing window only */ -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif - - InitTcpReady(&ready); - - /* set using dtls */ - XMEMSET(&server_args, 0, sizeof(func_args)); - XMEMSET(&server_cbf, 0, sizeof(callback_functions)); - server_cbf.method = wolfDTLSv1_2_server_method; - server_cbf.doUdp = 1; - server_args.callbacks = &server_cbf; - server_args.argc = 3; /* set loop_count to 3 */ - - - server_args.signal = &ready; - start_thread(test_server_nofail, &server_args, &serverThread); - wait_tcp_ready(&server_args); - - /* create and connect with client */ - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method())); - ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0)); - ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM)); - ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM)); - tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL); - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); - - /* store server information connected too */ - XMEMSET(&peerAddr, 0, sizeof(peerAddr)); -#ifndef TEST_IPV6 - peerAddr.sin_family = AF_INET; - ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1); - peerAddr.sin_port = XHTONS(server_args.signal->port); -#else - peerAddr.sin6_family = AF_INET6; - ExpectIntEQ( - XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1); - peerAddr.sin6_port = XHTONS(server_args.signal->port); -#endif - - ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)), - WOLFSSL_SUCCESS); - - ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0); - session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0); - ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz); - ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0); - ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0); - window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0); - wolfSSL_free(ssl); - - for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) { - /* restore state */ - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0); - ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0); - ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz); - ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0); - ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0); - wolfSSL_free(ssl); + /* Nothing must have been written: buf[] stays zero and the guard bytes + * that follow it stay 0x5A. */ + for (i = 0; i < (word32)sizeof(probe.buf); i++) { + ExpectIntEQ(probe.buf[i], 0x00); } - XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wolfSSL_CTX_free(ctx); - - fprintf(stderr, "done and waiting for server\n"); - join_thread(serverThread); - ExpectIntEQ(server_args.return_code, TEST_SUCCESS); - - FreeTcpReady(&ready); - -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif + for (i = 0; i < (word32)sizeof(probe.guard); i++) { + ExpectIntEQ(probe.guard[i], 0x5A); } -#endif + + /* A sufficiently large buffer must still succeed and report the actual + * Finished length, which is between TLS_FINISHED_SZ and the max digest + * size. */ + XMEMSET(full, 0, sizeof(full)); + msg_len = wolfSSL_get_peer_finished(ssl, full, sizeof(full)); + ExpectIntGE(msg_len, TLS_FINISHED_SZ); + ExpectIntLE(msg_len, WC_MAX_DIGEST_SIZE); return EXPECT_RESULT(); } +#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE && + * WOLFSSL_TLS13 */ + +static int test_wolfSSL_get_peer_finished_overrun(void) +{ + EXPECT_DECLS; +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_HAVE_TLS_UNIQUE) && defined(WOLFSSL_TLS13) + test_ssl_cbf client_cbf; + test_ssl_cbf server_cbf; + + XMEMSET(&client_cbf, 0, sizeof(client_cbf)); + XMEMSET(&server_cbf, 0, sizeof(server_cbf)); + + /* Force TLS 1.3 so the stored Finished length exceeds TLS_FINISHED_SZ. */ + client_cbf.method = wolfTLSv1_3_client_method; + server_cbf.method = wolfTLSv1_3_server_method; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, + &server_cbf, test_wolfSSL_get_peer_finished_overrun_on_handshake), + TEST_SUCCESS); +#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE && + * WOLFSSL_TLS13 */ + + return EXPECT_RESULT(); +} + #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12) #ifdef WOLFSSL_TLS13 @@ -9353,223 +8366,6 @@ static int test_wolfSSL_SNI_GetFromBuffer(void) #endif /* HAVE_IO_TESTS_DEPENDENCIES */ -#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \ - defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) -/* Dummy peer functions to satisfy the exporter/importer */ -static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip, - int* ipSz, unsigned short* port, int* fam) -{ - (void)ssl; - ip[0] = -1; - *ipSz = 1; - *port = 1; - *fam = 2; - return 1; -} - -static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip, - int ipSz, unsigned short port, int fam) -{ - (void)ssl; - if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2) - return 0; - return 1; -} - -static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx, - WOLFSSL **ssl) -{ - EXPECT_DECLS; - unsigned char* sessionBuf = NULL; - unsigned int sessionSz = 0; - void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl); - void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl); - - wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer); - wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer); - ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0); - ExpectNotNull(sessionBuf = - (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)); - ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0); - wolfSSL_free(*ssl); - *ssl = NULL; - ExpectNotNull(*ssl = wolfSSL_new(*ctx)); - ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0); - wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx); - wolfSSL_SetIOReadCtx(*ssl, ioReadCtx); - - XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return EXPECT_RESULT(); -} -#endif - -static int test_wolfSSL_dtls_export_peers(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \ - defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) - test_ssl_cbf client_cbf; - test_ssl_cbf server_cbf; - size_t i, j; - struct test_params { - method_provider client_meth; - method_provider server_meth; - const char* dtls_version; - } params[] = { -#ifndef NO_OLD_TLS - {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"}, -#endif - {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"}, - /* TODO DTLS 1.3 exporting not supported -#ifdef WOLFSSL_DTLS13 - {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"}, -#endif - */ - }; - - for (i = 0; i < sizeof(params)/sizeof(*params); i++) { - for (j = 0; j <= 3; j++) { - XMEMSET(&client_cbf, 0, sizeof(client_cbf)); - XMEMSET(&server_cbf, 0, sizeof(server_cbf)); - - printf("\n\tTesting DTLS %s connection;", params[i].dtls_version); - - client_cbf.method = params[i].client_meth; - server_cbf.method = params[i].server_meth; - - if (j & 0x1) { - client_cbf.on_handshake = - test_wolfSSL_dtls_export_peers_on_handshake; - printf(" With client export;"); - } - if (j & 0x2) { - server_cbf.on_handshake = - test_wolfSSL_dtls_export_peers_on_handshake; - printf(" With server export;"); - } - - printf("\n"); - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, - &server_cbf, NULL), TEST_SUCCESS); - if (!EXPECT_SUCCESS()) - break; - } - } -#endif - return EXPECT_RESULT(); -} - -/* Test that ImportKeyState correctly skips extra window words when importing - * state from a peer compiled with a larger WOLFSSL_DTLS_WINDOW_WORDS. */ -static int test_wolfSSL_dtls_import_state_extra_window_words(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) - WOLFSSL_CTX* ctx = NULL; - WOLFSSL* ssl = NULL; - unsigned int stateSz = 0; - byte* state = NULL; - byte* modified = NULL; - unsigned int modifiedSz; - word16 origKeyLen; - word16 origTotalLen; - /* Offset from start of key state data to the first wordCount field. - * Layout: 4 sequence numbers (16 bytes) + DTLS-specific fields (42 bytes) + - * encryptSz(4) + padSz(4) + encryptionOn(1) + decryptedCur(1) = 68 */ - const int keyStateWindowOffset = 68; - /* Buffer header: 2 proto + 2 total_len + 2 key_len = 6 */ - const int headerSz = 6; - int idx, modIdx; - int extraPerWindow = 2 * (int)sizeof(word32); /* 8 bytes extra per window */ - int totalExtra = extraPerWindow * 2; /* 16 bytes extra total */ - - /* Create DTLS context and SSL object */ - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); - ExpectNotNull(ssl = wolfSSL_new(ctx)); - - /* Get required buffer size and export state-only */ - ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &stateSz), 0); - ExpectIntGT((int)stateSz, 0); - state = (byte*)XMALLOC(stateSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ExpectNotNull(state); - ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, state, &stateSz), 0); - - /* Build a modified buffer that simulates a peer with - * WOLFSSL_DTLS_WINDOW_WORDS = WOLFSSL_DTLS_WINDOW_WORDS + 2. - * Each window section gets 2 extra word32 values (8 bytes). - * Two windows => 16 extra bytes total. */ - modifiedSz = stateSz + totalExtra; - modified = (byte*)XMALLOC(modifiedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ExpectNotNull(modified); - - if (EXPECT_SUCCESS()) { - int windowWords = WOLFSSL_DTLS_WINDOW_WORDS; - int windowDataSz = windowWords * (int)sizeof(word32); - - XMEMSET(modified, 0, modifiedSz); - - /* Copy protocol/version bytes (first 2 bytes) */ - XMEMCPY(modified, state, 2); - - /* Read original total length and key state length */ - ato16(state + 2, &origTotalLen); - ato16(state + 4, &origKeyLen); - - /* Write updated total length and key state length */ - c16toa((word16)(origTotalLen + totalExtra), modified + 2); - c16toa((word16)(origKeyLen + totalExtra), modified + 4); - - /* Copy key state data up to first window section */ - idx = headerSz; - modIdx = headerSz; - XMEMCPY(modified + modIdx, state + idx, keyStateWindowOffset); - idx += keyStateWindowOffset; - modIdx += keyStateWindowOffset; - - /* First window: write increased wordCount */ - c16toa((word16)(windowWords + 2), modified + modIdx); - idx += OPAQUE16_LEN; - modIdx += OPAQUE16_LEN; - - /* Copy original window data */ - XMEMCPY(modified + modIdx, state + idx, windowDataSz); - idx += windowDataSz; - modIdx += windowDataSz; - - /* Insert 2 extra word32 padding values */ - XMEMSET(modified + modIdx, 0, extraPerWindow); - modIdx += extraPerWindow; - - /* Second window (prevWindow): same transformation */ - c16toa((word16)(windowWords + 2), modified + modIdx); - idx += OPAQUE16_LEN; - modIdx += OPAQUE16_LEN; - - XMEMCPY(modified + modIdx, state + idx, windowDataSz); - idx += windowDataSz; - modIdx += windowDataSz; - - XMEMSET(modified + modIdx, 0, extraPerWindow); - modIdx += extraPerWindow; - - /* Copy remainder of key state (after both windows) */ - XMEMCPY(modified + modIdx, state + idx, stateSz - idx); - } - - /* Import the modified state - should succeed with the fix */ - wolfSSL_free(ssl); - ssl = NULL; - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntGT(wolfSSL_dtls_import(ssl, modified, modifiedSz), 0); - - XFREE(state, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(modified, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wolfSSL_free(ssl); - wolfSSL_CTX_free(ctx); -#endif - return EXPECT_RESULT(); -} static int test_wolfSSL_UseTrustedCA(void) { @@ -11469,8 +10265,7 @@ static int test_wolfSSL_URI(void) wolfSSL_FreeX509(x509); x509 = NULL; -#if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \ - && !defined(WOLFSSL_FPKI) +#if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri, WOLFSSL_FILETYPE_PEM)); #else @@ -17050,61 +15845,6 @@ static int test_wolfSSL_either_side(void) return EXPECT_RESULT(); } -static int test_wolfSSL_DTLS_either_side(void) -{ - EXPECT_DECLS; -#if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \ - defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) - test_ssl_cbf client_cb; - test_ssl_cbf server_cb; - - XMEMSET(&client_cb, 0, sizeof(client_cb)); - XMEMSET(&server_cb, 0, sizeof(server_cb)); - - /* Use different CTX for client and server */ - client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); - ExpectNotNull(client_cb.ctx); - server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); - ExpectNotNull(server_cb.ctx); - /* we are responsible for free'ing WOLFSSL_CTX */ - server_cb.isSharedCtx = client_cb.isSharedCtx = 1; - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, - &server_cb, NULL), TEST_SUCCESS); - - wolfSSL_CTX_free(client_cb.ctx); - wolfSSL_CTX_free(server_cb.ctx); -#endif - return EXPECT_RESULT(); -} - -static int test_generate_cookie(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO) - SSL_CTX* ctx = NULL; - SSL* ssl = NULL; - byte buf[FOURK_BUF] = {0}; - - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method())); - ExpectNotNull(ssl = SSL_new(ctx)); - - /* Test unconnected */ - ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E)); - - wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie); - - wolfSSL_SetCookieCtx(ssl, ctx); - - ExpectNotNull(wolfSSL_GetCookieCtx(ssl)); - - ExpectNull(wolfSSL_GetCookieCtx(NULL)); - - SSL_free(ssl); - SSL_CTX_free(ctx); -#endif - return EXPECT_RESULT(); -} static int test_wolfSSL_set_options(void) { @@ -19469,563 +18209,6 @@ static int test_wolfSSL_d2i_SSL_SESSION_bounds_check(void) return EXPECT_RESULT(); } -static int test_wolfSSL_SESSION(void) -{ - EXPECT_DECLS; -#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ - !defined(NO_RSA) && !defined(NO_SHA256) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE) - WOLFSSL* ssl = NULL; - WOLFSSL_CTX* ctx = NULL; - WOLFSSL_SESSION* sess = NULL; - WOLFSSL_SESSION* sess_copy = NULL; -#ifdef OPENSSL_EXTRA -#ifdef HAVE_EXT_CACHE - unsigned char* sessDer = NULL; - unsigned char* ptr = NULL; - int sz = 0; -#endif - const unsigned char context[] = "user app context"; - unsigned int contextSz = (unsigned int)sizeof(context); -#endif - int ret = 0, err = 0; - SOCKET_T sockfd; - tcp_ready ready; - func_args server_args; - THREAD_TYPE serverThread; - char msg[80]; - const char* sendGET = "GET"; - - /* TLS v1.3 requires session tickets */ - /* CHACHA and POLY1305 required for myTicketEncCb */ -#if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \ - !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \ - defined(HAVE_POLY1305)) || defined(HAVE_AESGCM)))) - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())); -#else - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); -#endif - - ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, - CERT_FILETYPE)); - ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, - CERT_FILETYPE)); - ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), - WOLFSSL_SUCCESS); -#ifdef WOLFSSL_ENCRYPTED_KEYS - wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack); -#endif -#ifdef HAVE_SESSION_TICKET - /* Use session tickets, for ticket tests below */ - ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS); -#endif - - XMEMSET(&server_args, 0, sizeof(func_args)); -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif - - StartTCP(); - InitTcpReady(&ready); - - server_args.signal = &ready; - start_thread(test_server_nofail, &server_args, &serverThread); - wait_tcp_ready(&server_args); - - /* client connection */ - ExpectNotNull(ssl = wolfSSL_new(ctx)); - tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl); - ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); - - WOLFSSL_ASYNC_WHILE_PENDING(ret = wolfSSL_connect(ssl), - ret != WOLFSSL_SUCCESS); - ExpectIntEQ(ret, WOLFSSL_SUCCESS); - - WOLFSSL_ASYNC_WHILE_PENDING( - ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET)), - ret <= 0); - ExpectIntEQ(ret, (int)XSTRLEN(sendGET)); - - WOLFSSL_ASYNC_WHILE_PENDING(ret = wolfSSL_read(ssl, msg, sizeof(msg)), - ret != 23); - ExpectIntEQ(ret, 23); - - ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */ - ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */ - ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1); -#ifdef HAVE_EXT_CACHE - ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without - * HAVE_EXT_CACHE we get new objects each time */ -#endif - wolfSSL_SESSION_free(sess_copy); sess_copy = NULL; - wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */ - - sess = wolfSSL_get_session(ssl); - -#ifdef OPENSSL_EXTRA - ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0); - ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1); - - ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0); - ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0); - #ifdef HAVE_SESSION_TICKET - ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1); - ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess), - SESSION_TICKET_HINT_DEFAULT); - #else - ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0); - #endif -#else - (void)sess; -#endif /* OPENSSL_EXTRA */ - - /* Retain copy of the session for later testing */ - ExpectNotNull(sess = wolfSSL_get1_session(ssl)); - - wolfSSL_shutdown(ssl); - wolfSSL_free(ssl); ssl = NULL; - - CloseSocket(sockfd); - - join_thread(serverThread); - - FreeTcpReady(&ready); - -#ifdef WOLFSSL_TIRTOS - fdOpenSession(Task_self()); -#endif - -#if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA) - { - X509 *x509 = NULL; - char buf[30]; - int bufSz = 0; - - ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess)); - ExpectIntGT((bufSz = X509_NAME_get_text_by_NID( - X509_get_subject_name(x509), NID_organizationalUnitName, buf, - sizeof(buf))), 0); - ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/ - if (bufSz == 7) { - ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0); - } - if (bufSz == 16) { - ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0); - } - } -#endif - -#ifdef HAVE_EXT_CACHE - ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess)); - wolfSSL_SESSION_free(sess_copy); sess_copy = NULL; - sess_copy = NULL; -#endif - -#if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE) - /* get session from DER and update the timeout */ - ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0); - wolfSSL_SESSION_free(sess); sess = NULL; - sess = NULL; - ptr = sessDer; - ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz)); - ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, - (const unsigned char**)&ptr, sz)); - XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL); - sessDer = NULL; - - ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0); - ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS); -#endif - - /* successful set session test */ - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS); - -#ifdef HAVE_SESSION_TICKET - /* Test set/get session ticket */ - { - const char* ticket = "This is a session ticket"; - char buf[64] = {0}; - word32 bufSz = (word32)sizeof(buf); - word32 retSz = 0; - - ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_set_SessionTicket(ssl, (byte *)ticket, - (word32)XSTRLEN(ticket))); - ExpectIntEQ(WOLFSSL_SUCCESS, - wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz)); - ExpectStrEQ(ticket, buf); - - /* return ticket length if buffer parameter is null */ - wolfSSL_get_SessionTicket(ssl, NULL, &retSz); - ExpectIntEQ(bufSz, retSz); - } -#endif - -#ifdef OPENSSL_EXTRA - /* session timeout case */ - /* make the session to be expired */ - ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS); - XSLEEP_MS(1200); - - /* SSL_set_session should reject specified session but return success - * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility. - */ -#if defined(WOLFSSL_ERROR_CODE_OPENSSL) - ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS); -#else - ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); -#endif - ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS); - -#ifdef WOLFSSL_SESSION_ID_CTX - /* fail case with miss match session context IDs (use compatibility API) */ - ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz), - SSL_SUCCESS); - ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - wolfSSL_free(ssl); ssl = NULL; - - ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz), - SSL_SUCCESS); - ExpectNotNull(ssl = wolfSSL_new(ctx)); - ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); -#endif -#endif /* OPENSSL_EXTRA */ - - wolfSSL_free(ssl); - wolfSSL_SESSION_free(sess); - wolfSSL_CTX_free(ctx); -#endif - return EXPECT_RESULT(); -} - -#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ - !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \ - !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \ - !defined(WOLFSSL_NO_TLS12) -static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL; - -static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx) -{ - #ifdef WOLFSSL_ERROR_CODE_OPENSSL - /* returns previous timeout value */ - AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500); - #else - AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS); - #endif -} - - -/* set the session to timeout in a second */ -static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl) -{ - AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1); -} - - -/* store the client side session from the first successful connection */ -static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl) -{ - AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)), - NULL); /* ref count 1 */ -} - - -/* wait till session is expired then set it in the WOLFSSL struct for use */ -static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl) -{ - AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1); - AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), - WOLFSSL_SUCCESS); - XSLEEP_MS(2000); /* wait 2 seconds for session to expire */ -} - - -/* set expired session in the WOLFSSL struct for use */ -static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl) -{ - XSLEEP_MS(1200); /* wait a second for session to expire */ - - /* set the expired session, call to set session fails but continuing on - after failure should be handled here */ -#if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) - AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), - WOLFSSL_SUCCESS); -#else - AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), - WOLFSSL_SUCCESS); -#endif -} - - -/* check that the expired session was not reused */ -static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl) -{ - /* since the session has expired it should not have been reused */ - AssertIntEQ(wolfSSL_session_reused(ssl), 0); -} -#endif - -static int test_wolfSSL_SESSION_expire_downgrade(void) -{ - EXPECT_DECLS; -#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ - !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \ - !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \ - !defined(WOLFSSL_NO_TLS12) - callback_functions server_cbf, client_cbf; - - XMEMSET(&server_cbf, 0, sizeof(callback_functions)); - XMEMSET(&client_cbf, 0, sizeof(callback_functions)); - - /* force server side to use TLS 1.2 */ - server_cbf.method = wolfTLSv1_2_server_method; - - client_cbf.method = wolfSSLv23_client_method; - server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; - client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready; - client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result; - - test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); - ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); - ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); - - client_cbf.method = wolfSSLv23_client_method; - server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; - client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait; - client_cbf.on_result = - test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse; - - test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); - ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); - ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); - - client_cbf.method = wolfSSLv23_client_method; - server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; - client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set; - client_cbf.on_result = - test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse; - - test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); - ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); - ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); - - wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess); -#endif - return EXPECT_RESULT(); -} - -#if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE) -#ifdef WOLFSSL_ATOMIC_OPS - typedef wolfSSL_Atomic_Int SessRemCounter_t; -#else - typedef int SessRemCounter_t; -#endif -static SessRemCounter_t clientSessRemCountMalloc; -static SessRemCounter_t serverSessRemCountMalloc; -static SessRemCounter_t clientSessRemCountFree; -static SessRemCounter_t serverSessRemCountFree; - -static WOLFSSL_CTX* serverSessCtx = NULL; -static WOLFSSL_SESSION* serverSess = NULL; -#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ - !defined(NO_SESSION_CACHE_REF) -static WOLFSSL_CTX* clientSessCtx = NULL; -static WOLFSSL_SESSION* clientSess = NULL; -#endif -static int serverSessRemIdx = 3; -static int sessRemCtx_Server = WOLFSSL_SERVER_END; -static int sessRemCtx_Client = WOLFSSL_CLIENT_END; - -static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess) -{ - int* side; - - (void)ctx; - - side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx); - if (side != NULL) { - if (*side == WOLFSSL_CLIENT_END) - (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1); - else - (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1); - - SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL); - } -} - -static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx) -{ - SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb); -#if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \ - !defined(NO_SESSION_CACHE_REF) - { - EXPECT_DECLS; - /* Allow downgrade, set min version, and disable TLS 1.3. - * Do this because without NO_SESSION_CACHE_REF we will want to return a - * reference to the session cache. But with WOLFSSL_TLS13 and without - * HAVE_SESSION_TICKET we won't have a session ID to be able to place - * the session in the cache. In this case we need to downgrade to - * previous versions to just use the legacy session ID field. */ - ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION), - SSL_SUCCESS); - ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION), - SSL_SUCCESS); - return EXPECT_RESULT(); - } -#else - return TEST_SUCCESS; -#endif -} - -static int SessRemSslSetupCb(WOLFSSL* ssl) -{ - EXPECT_DECLS; - int* side; - - if (SSL_is_server(ssl)) { - side = &sessRemCtx_Server; - (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1); - ExpectNotNull(serverSess = SSL_get1_session(ssl)); - ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)), - SSL_SUCCESS); - } - else { - side = &sessRemCtx_Client; - (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1); -#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ - !defined(NO_SESSION_CACHE_REF) - ExpectNotNull(clientSess = SSL_get1_session(ssl)); - ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)), - SSL_SUCCESS); -#endif - } - ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl), - serverSessRemIdx, side), SSL_SUCCESS); - - return EXPECT_RESULT(); -} -#endif - -static int test_wolfSSL_CTX_sess_set_remove_cb(void) -{ - EXPECT_DECLS; -#if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE) - /* Check that the remove callback gets called for external data in a - * session object */ - test_ssl_cbf func_cb; - - wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0); - wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0); - wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0); - wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0); - - XMEMSET(&func_cb, 0, sizeof(func_cb)); - func_cb.ctx_ready = SessRemCtxSetupCb; - func_cb.on_result = SessRemSslSetupCb; - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb, - NULL), TEST_SUCCESS); - - /* Both should have been allocated */ - ExpectIntEQ(clientSessRemCountMalloc, 1); - ExpectIntEQ(serverSessRemCountMalloc, 1); - - /* This should not be called yet. Session wasn't evicted from cache yet. */ - ExpectIntEQ(clientSessRemCountFree, 0); -#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ - !defined(NO_SESSION_CACHE_REF) - /* Force a cache lookup */ - ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx)); - /* Force a cache update */ - ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0)); - /* This should set the timeout to 0 and call the remove callback from within - * the session cache. Returns 1 per OpenSSL semantics (session was - * present in the cache and removed). */ - ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 1); - ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx)); - ExpectIntEQ(clientSessRemCountFree, 1); -#endif - /* Server session is in the cache so ex_data isn't free'd with the SSL - * object */ - ExpectIntEQ(serverSessRemCountFree, 0); - /* Force a cache lookup */ - ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx)); - /* Force a cache update */ - ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0)); - /* This should set the timeout to 0 and call the remove callback from within - * the session cache. Returns 1 per OpenSSL semantics (session was - * present in the cache and removed). */ - ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 1); - ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx)); - ExpectIntEQ(serverSessRemCountFree, 1); - /* Need to free the references that we kept */ - SSL_CTX_free(serverSessCtx); - SSL_SESSION_free(serverSess); -#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ - !defined(NO_SESSION_CACHE_REF) - SSL_CTX_free(clientSessCtx); - SSL_SESSION_free(clientSess); -#endif -#endif - return EXPECT_RESULT(); -} - -static int test_wolfSSL_ticket_keys(void) -{ - EXPECT_DECLS; -#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ - !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) - WOLFSSL_CTX* ctx = NULL; - byte keys[WOLFSSL_TICKET_KEYS_SZ]; - - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); - - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)), - WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - - ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)), - WOLFSSL_SUCCESS); - - wolfSSL_CTX_free(ctx); -#endif - return EXPECT_RESULT(); -} - #ifndef NO_BIO #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_HAVE_MLDSA) @@ -20650,6 +18833,7 @@ static int test_wolfSSL_GENERAL_NAME_print(void) ACCESS_DESCRIPTION* ad = NULL; ASN1_IA5STRING *dnsname = NULL; ASN1_OBJECT* ridObj = NULL; + X509_NAME* dirName = NULL; const unsigned char v4Addr[] = {192,168,53,1}; const unsigned char v6Addr[] = @@ -20904,22 +19088,35 @@ static int test_wolfSSL_GENERAL_NAME_print(void) /* test for GEN_DIRNAME */ ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new()); + /* Build a real directoryName (X509_NAME) so the print path exercises + * wolfSSL_X509_NAME_print_ex on a valid object. Forcing the type without + * setting d.directoryName would leave it aliasing the default IA5 string + * and cause an out-of-bounds read when printed. */ + ExpectNotNull(dirName = X509_NAME_new()); + ExpectIntEQ(X509_NAME_add_entry_by_NID(dirName, NID_commonName, + MBSTRING_UTF8, (unsigned char*)"wolfSSLDirNameTest", -1, -1, 0), 1); if (gn != NULL) { + /* Replace the default IA5 string allocated by GENERAL_NAME_new with + * the directoryName and take ownership of it. */ + wolfSSL_ASN1_STRING_free(gn->d.ia5); gn->type = GEN_DIRNAME; + gn->d.directoryName = dirName; + dirName = NULL; /* gn owns it now; freed by GENERAL_NAME_free */ } ExpectIntEQ(GENERAL_NAME_print(out, gn), 1); XMEMSET(outbuf,0,sizeof(outbuf)); ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0); + /* Output must start with the label and contain the directory name. */ ExpectIntEQ(XSTRNCMP((const char*)outbuf, dirNameStr, XSTRLEN(dirNameStr)), 0); + ExpectNotNull(XSTRSTR((const char*)outbuf, "wolfSSLDirNameTest")); /* Duplicating GEN_DIRNAME not supported. */ ExpectNull(dup_gn = GENERAL_NAME_dup(gn)); - /* Restore to GEN_IA5 (default) to avoid memory leak. */ - if (gn != NULL) { - gn->type = GEN_IA5; - } GENERAL_NAME_free(gn); gn = NULL; + /* Only freed here if ownership was not transferred (e.g. gn alloc failed). */ + X509_NAME_free(dirName); + dirName = NULL; /* test for GEN_RID */ p = ridData; @@ -24563,6 +22760,172 @@ static int test_NameConstraints_OtherName(void) return EXPECT_RESULT(); } +#if defined(WOLFSSL_ASN_TEMPLATE) && \ + defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \ + defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \ + defined(WOLFSSL_CERT_EXT) && !defined(NO_CERTS) && \ + defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_CUSTOM_OID) && \ + defined(HAVE_OID_ENCODING) && !defined(IGNORE_NAME_CONSTRAINTS) +/* Build a SubjectAltName extension value with a single GeneralName of the + * given context tag (0x82 dnsName, 0x86 URI) carrying `val`. */ +static word32 build_simple_san(byte* out, word32 outSz, byte gnTag, + const char* val) +{ + word32 vlen = (word32)XSTRLEN(val); + if (vlen > 0x7F || outSz < vlen + 4) + return 0; + out[0] = 0x30; /* SEQUENCE */ + out[1] = (byte)(vlen + 2); + out[2] = gnTag; /* [tag] GeneralName */ + out[3] = (byte)vlen; + XMEMCPY(out + 4, val, vlen); + return vlen + 4; +} + +/* Build a NameConstraints extension value with a single subtree ([0] + * permitted or [1] excluded) carrying a GeneralName of context tag `gnTag` + * with value `val`. */ +static word32 build_simple_nameConstraints(byte* out, word32 outSz, + int excluded, byte gnTag, const char* val) +{ + word32 vlen = (word32)XSTRLEN(val); + word32 n3 = vlen + 2; /* GeneralSubtree content: the base GN */ + word32 n2 = n3 + 2; /* subtrees list content: one GeneralSubtree */ + word32 n1 = n2 + 2; /* SEQUENCE content: the subtrees list */ + if (vlen > 0x7F || outSz < n1 + 2) + return 0; + out[0] = 0x30; /* SEQUENCE */ + out[1] = (byte)n1; + out[2] = excluded ? 0xA1 : 0xA0; /* [1] excluded / [0] permitted */ + out[3] = (byte)n2; + out[4] = 0x30; /* GeneralSubtree */ + out[5] = (byte)n3; + out[6] = gnTag; /* base GeneralName */ + out[7] = (byte)vlen; + XMEMCPY(out + 8, val, vlen); + return n1 + 2; +} +#endif + +/* End-to-end enforcement of DNS and URI nameConstraints against wildcard and + * sub-host leaf SANs, exercised through the real chain-verification path. + * + * DNS subtree semantics (RFC 5280 4.2.1.10) plus wildcard reasoning: + * - excluded DNS:foo.example.com must reject a leaf SAN *.example.com, + * because the wildcard can expand to the excluded host (security gap). + * - permitted DNS:example.com must accept *.example.com (contained), while + * permitted DNS:foo.example.com must reject it (the wildcard can escape). + * URI semantics: a constraint without a leading dot is an EXACT host match, + * not a subtree, so permitted URI:host.com must reject https://www.host.com/. + */ +static int test_NameConstraints_DnsUriWildcard(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_ASN_TEMPLATE) && \ + defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \ + defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \ + defined(WOLFSSL_CERT_EXT) && !defined(NO_CERTS) && \ + defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_CUSTOM_OID) && \ + defined(HAVE_OID_ENCODING) && !defined(IGNORE_NAME_CONSTRAINTS) + byte nc[64]; + byte san[64]; + word32 ncSz, sanSz; + const byte DNS = 0x82; /* [2] dnsName */ + const byte URI = 0x86; /* [6] uniformResourceIdentifier */ + + /* --- DNS, excluded subtree --- */ + + /* (1) Excluded foo.example.com vs wildcard SAN that can reach it: the + * pre-fix byte-length guard let this through. Must reject. */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 1, DNS, + "foo.example.com"); + sanSz = build_simple_san(san, sizeof(san), DNS, "*.example.com"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + /* (2) Positive control: same exclusion, wildcard in a different domain + * cannot reach foo.example.com -> accept. */ + sanSz = build_simple_san(san, sizeof(san), DNS, "*.other.com"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); + + /* (3) Regression: literal SAN inside the excluded subtree still rejects. */ + sanSz = build_simple_san(san, sizeof(san), DNS, "foo.example.com"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + /* (4) Regression: literal SAN outside the excluded subtree accepts. */ + sanSz = build_simple_san(san, sizeof(san), DNS, "bar.other.com"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); + + /* --- DNS, permitted subtree --- */ + + /* (5) Permitted example.com accepts *.example.com (fully contained). */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 0, DNS, "example.com"); + sanSz = build_simple_san(san, sizeof(san), DNS, "*.example.com"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); + + /* (6) Permitted foo.example.com rejects *.example.com (the wildcard can + * expand outside the permitted subtree). */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 0, DNS, + "foo.example.com"); + sanSz = build_simple_san(san, sizeof(san), DNS, "*.example.com"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + /* --- URI, exact-host vs subtree semantics --- */ + + /* (7) Permitted URI host.com (no leading dot) is an EXACT host match: + * a sub-host URI is NOT contained -> reject. Pre-fix this wrongly + * subtree-matched and accepted. */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 0, URI, "host.com"); + sanSz = build_simple_san(san, sizeof(san), URI, "https://www.host.com/"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + /* (8) Permitted URI host.com accepts the exact host. */ + sanSz = build_simple_san(san, sizeof(san), URI, "https://host.com/path"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); + + /* (9) Permitted URI .host.com (leading dot) is a subtree: the sub-host is + * accepted but the bare host is not. */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 0, URI, ".host.com"); + sanSz = build_simple_san(san, sizeof(san), URI, "https://www.host.com/"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); + + sanSz = build_simple_san(san, sizeof(san), URI, "https://host.com/"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + /* (10) Excluded URI host.com (exact): bare host excluded, sub-host not. */ + ncSz = build_simple_nameConstraints(nc, sizeof(nc), 1, URI, "host.com"); + sanSz = build_simple_san(san, sizeof(san), URI, "https://host.com/"); + ExpectIntGT((int)ncSz, 0); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), + WC_NO_ERR_TRACE(ASN_NAME_INVALID_E)); + + sanSz = build_simple_san(san, sizeof(san), URI, "https://www.host.com/"); + ExpectIntGT((int)sanSz, 0); + ExpectIntEQ(verify_with_otherName_chain(nc, ncSz, 1, san, sanSz), 0); +#endif + return EXPECT_RESULT(); +} + static int test_MakeCertWithCaFalse(void) { EXPECT_DECLS; @@ -27058,6 +25421,111 @@ static int test_wolfSSL_X509_print(void) return EXPECT_RESULT(); } +static int test_wolfSSL_X509_print_basic_constraints(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \ + !defined(NO_RSA) && defined(XSNPRINTF) && !defined(WC_DISABLE_RADIX_ZERO_PAD) + /* X509_print must match OpenSSL's Basic Constraints output: "CA:TRUE" + * alone when no pathLenConstraint is present, and "CA:TRUE, pathlen:N" + * when one is (including the meaningful value 0). */ + struct { + const char* file; + const char* expect; /* substring that must be present */ + const char* absent; /* substring that must be absent, or NULL */ + } cases[] = { + { "./certs/ca-cert.pem", "CA:TRUE", "pathlen" }, + { "./certs/intermediate/ca-int-cert.pem", "CA:TRUE, pathlen:1", NULL }, + { "./certs/test-pathlen/chainG-ICA1-pathlen0.pem", + "CA:TRUE, pathlen:0", NULL }, + }; + size_t i; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + X509* x509 = NULL; + BIO* bio = NULL; + char* data = NULL; + int len = 0; + char buf[8192]; + + ExpectNotNull(x509 = X509_load_certificate_file(cases[i].file, + WOLFSSL_FILETYPE_PEM)); + ExpectNotNull(bio = BIO_new(BIO_s_mem())); + ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS); + /* Memory BIO data is not NUL-terminated; copy into a bounded buffer. */ + ExpectIntGT((len = BIO_get_mem_data(bio, &data)), 0); + ExpectIntLT(len, (int)sizeof(buf)); + if ((data != NULL) && (len > 0) && (len < (int)sizeof(buf))) { + XMEMCPY(buf, data, (size_t)len); + buf[len] = '\0'; + ExpectNotNull(XSTRSTR(buf, cases[i].expect)); + if (cases[i].absent != NULL) { + ExpectNull(XSTRSTR(buf, cases[i].absent)); + } + } + BIO_free(bio); + X509_free(x509); + } +#endif + return EXPECT_RESULT(); +} + +static int test_wolfSSL_X509_print_ext_key_usage(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \ + !defined(NO_RSA) && defined(XSNPRINTF) && !defined(WC_DISABLE_RADIX_ZERO_PAD) + /* Self-signed RSA cert (CN="wolfSSL anyEKU test", valid until 2126) whose + * only Extended Key Usage is anyExtendedKeyUsage (OID 2.5.29.37.0). + * X509_print must render it as "Any Extended Key Usage" to match OpenSSL, + * rather than omitting it. */ + static const char anyEkuCertPem[] = + "-----BEGIN CERTIFICATE-----\n" + "MIIDMDCCAhigAwIBAgIUGFipYIiuuQZHNjsi0R8t6nZrFVowDQYJKoZIhvcNAQEL\n" + "BQAwHjEcMBoGA1UEAwwTd29sZlNTTCBhbnlFS1UgdGVzdDAgFw0yNjA1MjgwMTI5\n" + "MjBaGA8yMTI2MDUwNDAxMjkyMFowHjEcMBoGA1UEAwwTd29sZlNTTCBhbnlFS1Ug\n" + "dGVzdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKIXS15QjpWlqpqk\n" + "sUTD/mgm7akIZfp2DVoweJsf8BC/tnwMX1noWUFjBC8SLOHyhx4bmWxVBzFXv/uu\n" + "ICoUCq63pgnxj3rQbPAa1pwAX4UsYS1PS/2mO2o7lRLRdDLIaBXuUClVHGjti9x5\n" + "x5++4FFhOhKNt7CkYVAfXasTFKdZqSnKdlYX2rM8LoCjP3YHIC5jEIgjyNUEqzup\n" + "Ls02dIaAly5O8yzasUtULwE76E/UpyhE+o2dkhxnc6ukqU5CBLeHNOUJgvThW1lS\n" + "SlGXl8Kd5uvBvDflXb6y3TQBEY/hb40JzYeH+hHf4YIqCtvfy6PMA+Rcu2CKlDpP\n" + "FVf85pUCAwEAAaNkMGIwHQYDVR0OBBYEFAkmMlYp9K3sbeQ8/RluOviXZ3JcMB8G\n" + "A1UdIwQYMBaAFAkmMlYp9K3sbeQ8/RluOviXZ3JcMA8GA1UdEwEB/wQFMAMBAf8w\n" + "DwYDVR0lBAgwBgYEVR0lADANBgkqhkiG9w0BAQsFAAOCAQEAHX5wAZDAyFSmmsn4\n" + "Mu7TayCx+VbcBgvL4ZdxxJYXexslzI8OviKSgpC56LaVB5JpNqZtFS4pZZikG7nv\n" + "kYCoiU33XN82/gggq1bv8rKO740V6kGev3gfEeJuTX30fCPZ18znE1fU8+VQba1L\n" + "bPn0h746Ivom47/1VMg6y7CbTJg90+lloPWcTWujYfm5jWychqWurhfZmAYcUlBH\n" + "Ksk0l4kiEJA6lSnPp3MqBS0GzwsCixSqYc1W1TlwNGNg38cLP2Z5jerJZlazuVws\n" + "SeEbYO6TIhsy6QJy0Pd7hu9DUOKRxp+OQubL6WgWpjrGl1LUzH5sI5pyWueEAEBu\n" + "e74xbw==\n" + "-----END CERTIFICATE-----\n"; + X509* x509 = NULL; + BIO* bio = NULL; + char* data = NULL; + int len = 0; + char buf[8192]; + + ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer( + (const unsigned char*)anyEkuCertPem, (int)XSTRLEN(anyEkuCertPem), + WOLFSSL_FILETYPE_PEM)); + ExpectNotNull(bio = BIO_new(BIO_s_mem())); + ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS); + /* Memory BIO data is not NUL-terminated; copy into a bounded buffer. */ + ExpectIntGT((len = BIO_get_mem_data(bio, &data)), 0); + ExpectIntLT(len, (int)sizeof(buf)); + if ((data != NULL) && (len > 0) && (len < (int)sizeof(buf))) { + XMEMCPY(buf, data, (size_t)len); + buf[len] = '\0'; + ExpectNotNull(XSTRSTR(buf, "X509v3 Extended Key Usage")); + ExpectNotNull(XSTRSTR(buf, "Any Extended Key Usage")); + } + BIO_free(bio); + X509_free(x509); +#endif + return EXPECT_RESULT(); +} + static int test_wolfSSL_X509_CRL_print(void) { EXPECT_DECLS; @@ -27669,1188 +26137,6 @@ static int test_wolfSSL_CTX_get0_privatekey(void) return EXPECT_RESULT(); } -static int test_wolfSSL_dtls_set_mtu(void) -{ - EXPECT_DECLS; -#if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \ - !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \ - !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX* ctx = NULL; - WOLFSSL* ssl = NULL; - const char* testCertFile; - const char* testKeyFile; - - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); -#ifndef NO_RSA - testCertFile = svrCertFile; - testKeyFile = svrKeyFile; -#elif defined(HAVE_ECC) - testCertFile = eccCertFile; - testKeyFile = eccKeyFile; -#endif - if (testCertFile != NULL && testKeyFile != NULL) { - ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile, - WOLFSSL_FILETYPE_PEM)); - ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile, - WOLFSSL_FILETYPE_PEM)); - } - ExpectNotNull(ssl = wolfSSL_new(ctx)); - - ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); - ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS); - -#ifdef OPENSSL_EXTRA - ExpectIntEQ(SSL_set_mtu(ssl, 1488), WOLFSSL_SUCCESS); -#endif - - wolfSSL_free(ssl); - wolfSSL_CTX_free(ctx); -#endif - - return EXPECT_RESULT(); -} - -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ - defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) - -static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq, - enum HandShakeType hsType, word16 length) -{ - size_t idx = 0; - byte* l; - - /* record layer */ - /* handshake type */ - out[idx++] = handshake; - /* protocol version */ - out[idx++] = 0xfe; - out[idx++] = 0xfd; /* DTLS 1.2 */ - /* epoch 0 */ - XMEMSET(out + idx, 0, 2); - idx += 2; - /* sequence number */ - XMEMSET(out + idx, 0, 6); - c32toa(seq, out + idx + 2); - idx += 6; - /* length in BE */ - if (length) - c16toa(length, out + idx); - else - c16toa(outSz - idx - 2, out + idx); - idx += 2; - - /* handshake layer */ - /* handshake type */ - out[idx++] = (byte)hsType; - /* length */ - l = out + idx; - idx += 3; - /* message seq */ - c16toa(0, out + idx); - idx += 2; - /* frag offset */ - c32to24(0, out + idx); - idx += 3; - /* frag length */ - c32to24((word32)outSz - (word32)idx - 3, l); - c32to24((word32)outSz - (word32)idx - 3, out + idx); - idx += 3; - XMEMSET(out + idx, 0, outSz - idx); -} - -static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl) -{ - byte msg[] = "This is a msg for the client"; - byte reply[40]; - AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0); - reply[sizeof(reply) - 1] = '\0'; - fprintf(stderr, "Client message: %s\n", reply); - AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg)); -} - -static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl) -{ - byte ch[50]; - int fd = wolfSSL_get_wfd(ssl); - byte msg[] = "This is a msg for the server"; - byte reply[40]; - - AssertIntGE(fd, 0); - generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0); - /* Server should ignore this datagram */ - AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch)); - generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000); - /* Server should ignore this datagram */ - AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch)); - - AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg)); - AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0); - reply[sizeof(reply) - 1] = '\0'; - fprintf(stderr, "Server response: %s\n", reply); -} - -static int test_wolfSSL_dtls_plaintext(void) -{ - callback_functions func_cb_client; - callback_functions func_cb_server; - size_t i; - struct test_params { - method_provider client_meth; - method_provider server_meth; - ssl_callback on_result_server; - ssl_callback on_result_client; - } params[] = { - {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, - test_wolfSSL_dtls_plaintext_server, - test_wolfSSL_dtls_plaintext_client}, - }; - - for (i = 0; i < sizeof(params)/sizeof(*params); i++) { - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_server.method = params[i].server_meth; - func_cb_client.method = params[i].client_meth; - func_cb_client.on_result = params[i].on_result_client; - func_cb_server.on_result = params[i].on_result_server; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - if (!func_cb_client.return_code) - return TEST_FAIL; - if (!func_cb_server.return_code) - return TEST_FAIL; - } - - return TEST_RES_CHECK(1); -} -#else -static int test_wolfSSL_dtls_plaintext(void) -{ - return TEST_SKIPPED; -} -#endif - -#if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ - defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) - -static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl) -{ - byte b[1100]; /* buffer for the messages to send */ - size_t idx = 0; - size_t seq_offset = 0; - size_t msg_offset = 0; - int i; - int fd = wolfSSL_get_wfd(ssl); - int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */ - word32 seq_number = 100; /* start high so server definitely reads this */ - word16 msg_number = 50; /* start high so server has to buffer this */ - AssertIntEQ(ret, 1); - /* Now let's start spamming the peer with fragments it needs to store */ - XMEMSET(b, -1, sizeof(b)); - - /* record layer */ - /* handshake type */ - b[idx++] = 22; - /* protocol version */ - b[idx++] = 0xfe; - b[idx++] = 0xfd; /* DTLS 1.2 */ - /* epoch 0 */ - XMEMSET(b + idx, 0, 2); - idx += 2; - /* sequence number */ - XMEMSET(b + idx, 0, 6); - seq_offset = idx + 2; /* increment only the low 32 bits */ - idx += 6; - /* static length in BE */ - c16toa(42, b + idx); - idx += 2; - - /* handshake layer */ - /* cert type */ - b[idx++] = 11; - /* length */ - c32to24(1000, b + idx); - idx += 3; - /* message seq */ - c16toa(0, b + idx); - msg_offset = idx; - idx += 2; - /* frag offset */ - c32to24(500, b + idx); - idx += 3; - /* frag length */ - c32to24(30, b + idx); - idx += 3; - (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */ - - for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0; - seq_number++, msg_number++, i++) { - struct timespec delay; - XMEMSET(&delay, 0, sizeof(delay)); - delay.tv_nsec = 10000000; /* wait 0.01 seconds */ - c32toa(seq_number, b + seq_offset); - c16toa(msg_number, b + msg_offset); - ret = (int)send(fd, (MESSAGE_TYPE_CAST)b, 55, 0); - nanosleep(&delay, NULL); - } -} - -#ifdef WOLFSSL_DTLS13 -static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl) -{ - const word16 sendCountMax = 100; - byte b[150]; /* buffer for the messages to send */ - size_t idx = 0; - size_t msg_offset = 0; - int fd = wolfSSL_get_wfd(ssl); - word16 msg_number = 10; /* start high so server has to buffer this */ - int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */ - AssertIntEQ(ret, 1); - /* Now let's start spamming the peer with fragments it needs to store */ - XMEMSET(b, -1, sizeof(b)); - - /* handshake type */ - b[idx++] = 11; - /* length */ - c32to24(10000, b + idx); - idx += 3; - /* message_seq */ - msg_offset = idx; - idx += 2; - /* fragment_offset */ - c32to24(5000, b + idx); - idx += 3; - /* fragment_length */ - c32to24(100, b + idx); - idx += 3; - /* fragment contents */ - idx += 100; - - for (; ret > 0 && msg_number < sendCountMax; msg_number++) { - byte sendBuf[150]; - int sendSz = sizeof(sendBuf); - struct timespec delay; - XMEMSET(&delay, 0, sizeof(delay)); - delay.tv_nsec = 10000000; /* wait 0.01 seconds */ - c16toa(msg_number, b + msg_offset); - ret = sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b, - (int)idx, handshake, 0, 0, 0); - if (sendSz > 0) - ret = (int)send(fd, (MESSAGE_TYPE_CAST)sendBuf, (size_t)sendSz, 0); - nanosleep(&delay, NULL); - } -} -#endif - -static int test_wolfSSL_dtls_fragments(void) -{ - EXPECT_DECLS; - callback_functions func_cb_client; - callback_functions func_cb_server; - size_t i; - struct test_params { - method_provider client_meth; - method_provider server_meth; - ssl_callback spammer; - } params[] = { -#if !defined(WOLFSSL_NO_TLS12) - {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, - test_wolfSSL_dtls12_fragments_spammer}, -#endif -#ifdef WOLFSSL_DTLS13 - {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, - test_wolfSSL_dtls13_fragments_spammer}, -#endif - }; - - for (i = 0; i < sizeof(params)/sizeof(*params); i++) { - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_server.method = params[i].server_meth; - func_cb_client.method = params[i].client_meth; - func_cb_client.ssl_ready = params[i].spammer; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - /* If the client failed, check that the error it encountered was from - * the server aborting, resulting in a socket error, fatal error or - * reading a close notify alert. - * - * Under slow execution (e.g. valgrind + noasm), the server may - * still be processing fragments when the client completes its - * handshake and write, so the client may succeed -- in that - * case return_code is TEST_SUCCESS and these checks don't apply. - */ - if (func_cb_client.return_code == TEST_FAIL) { - if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) && - func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN && - func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) { - ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); - } - } - /* Check the server returned an error indicating the msg buffer - * was full. - * - * Under slow execution (e.g. valgrind + noasm), the real handshake - * from wolfSSL_negotiate() may complete before enough spam fragments - * accumulate to trigger DTLS_TOO_MANY_FRAGMENTS_E. Accept both - * outcomes: server hit the fragment limit, or completed normally. - */ - if (func_cb_server.return_code == TEST_FAIL) { - ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E)); - } - - if (EXPECT_FAIL()) - break; - } - - return EXPECT_RESULT(); -} - -static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl) -{ - int fd, ret; - byte alert_msg[] = { - 0x15, /* alert type */ - 0xfe, 0xfd, /* version */ - 0x00, 0x00, /* epoch */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */ - 0x00, 0x02, /* length */ - 0x02, /* level: fatal */ - 0x46 /* protocol version */ - }; - - fd = wolfSSL_get_wfd(ssl); - AssertIntGE(fd, 0); - ret = (int)send(fd, (MESSAGE_TYPE_CAST)alert_msg, sizeof(alert_msg), 0); - AssertIntGT(ret, 0); -} - -static int _test_wolfSSL_ignore_alert_before_cookie(byte version12) -{ - callback_functions client_cbs, server_cbs; - - XMEMSET(&client_cbs, 0, sizeof(client_cbs)); - XMEMSET(&server_cbs, 0, sizeof(server_cbs)); - client_cbs.doUdp = server_cbs.doUdp = 1; - if (version12) { -#if !defined(WOLFSSL_NO_TLS12) - client_cbs.method = wolfDTLSv1_2_client_method; - server_cbs.method = wolfDTLSv1_2_server_method; -#else - return TEST_SKIPPED; -#endif - } - else - { -#ifdef WOLFSSL_DTLS13 - client_cbs.method = wolfDTLSv1_3_client_method; - server_cbs.method = wolfDTLSv1_3_server_method; -#else - return TEST_SKIPPED; -#endif /* WOLFSSL_DTLS13 */ - } - - client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert; - test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); - - if (!client_cbs.return_code) - return TEST_FAIL; - if (!server_cbs.return_code) - return TEST_FAIL; - - return TEST_SUCCESS; -} - -static int test_wolfSSL_ignore_alert_before_cookie(void) -{ - int ret; - ret =_test_wolfSSL_ignore_alert_before_cookie(0); - if (ret != 0) - return ret; - ret =_test_wolfSSL_ignore_alert_before_cookie(1); - if (ret != 0) - return ret; - return 0; -} - -static void test_wolfSSL_send_bad_record(WOLFSSL* ssl) -{ - int ret; - int fd; - - byte bad_msg[] = { - 0x17, /* app data */ - 0xaa, 0xfd, /* bad version */ - 0x00, 0x01, /* epoch 1 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */ - 0x00, 0x26, /* length: 38 bytes */ - 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57, - 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1, - 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f, - 0x03, 0x18, 0x72 - }; - - fd = wolfSSL_get_wfd(ssl); - AssertIntGE(fd, 0); - ret = (int)send(fd, (MESSAGE_TYPE_CAST)bad_msg, sizeof(bad_msg), 0); - AssertIntEQ(ret, sizeof(bad_msg)); - ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest")); - AssertIntEQ(ret, sizeof("badrecordtest")); -} - -static void test_wolfSSL_read_string(WOLFSSL* ssl) -{ - byte buf[100]; - int ret; - - ret = wolfSSL_read(ssl, buf, sizeof(buf)); - AssertIntGT(ret, 0); - AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0); -} - -static int _test_wolfSSL_dtls_bad_record( - method_provider client_method, method_provider server_method) -{ - callback_functions client_cbs, server_cbs; - - XMEMSET(&client_cbs, 0, sizeof(client_cbs)); - XMEMSET(&server_cbs, 0, sizeof(server_cbs)); - client_cbs.doUdp = server_cbs.doUdp = 1; - client_cbs.method = client_method; - server_cbs.method = server_method; - - client_cbs.on_result = test_wolfSSL_send_bad_record; - server_cbs.on_result = test_wolfSSL_read_string; - - test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); - - if (!client_cbs.return_code) - return TEST_FAIL; - if (!server_cbs.return_code) - return TEST_FAIL; - - return TEST_SUCCESS; -} - -static int test_wolfSSL_dtls_bad_record(void) -{ - int ret = TEST_SUCCESS; -#if !defined(WOLFSSL_NO_TLS12) - ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method, - wolfDTLSv1_2_server_method); -#endif -#ifdef WOLFSSL_DTLS13 - if (ret == TEST_SUCCESS) { - ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method, - wolfDTLSv1_3_server_method); - } -#endif /* WOLFSSL_DTLS13 */ - return ret; - -} - -#else -static int test_wolfSSL_dtls_fragments(void) -{ - return TEST_SKIPPED; -} -static int test_wolfSSL_ignore_alert_before_cookie(void) -{ - return TEST_SKIPPED; -} -static int test_wolfSSL_dtls_bad_record(void) -{ - return TEST_SKIPPED; -} -#endif - -#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) -static volatile int test_AEAD_seq_num = 0; -#ifdef WOLFSSL_NO_ATOMICS -static volatile int test_AEAD_done = 0; -#else -wolfSSL_Atomic_Int test_AEAD_done = WOLFSSL_ATOMIC_INITIALIZER(0); -#endif -#ifdef WOLFSSL_MUTEX_INITIALIZER -static wolfSSL_Mutex test_AEAD_mutex = WOLFSSL_MUTEX_INITIALIZER(test_AEAD_mutex); -#endif - -static int test_AEAD_fail_decryption = 0; -static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx) -{ - int fd = wolfSSL_get_fd(ssl); - int ret = -1; - if (fd >= 0 && (ret = (int)recv(fd, buf, sz, 0)) > 0) { - if (test_AEAD_fail_decryption) { - /* Modify the packet to trigger a decryption failure */ - buf[ret/2] ^= 0xFF; - if (test_AEAD_fail_decryption == 1) - test_AEAD_fail_decryption = 0; - } - } - (void)ctx; - return ret; -} - -static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit, - w64wrapper* keyUpdateLimit, w64wrapper* sendLimit) -{ - if (sendLimit) - w64Zero(sendLimit); - switch (ssl->specs.bulk_cipher_algorithm) { - case wolfssl_aes_gcm: - if (sendLimit) - *sendLimit = AEAD_AES_LIMIT; - FALL_THROUGH; - case wolfssl_chacha: - if (hardLimit) - *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT; - if (keyUpdateLimit) - *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT; - break; - case wolfssl_aes_ccm: - if (sendLimit) - *sendLimit = DTLS_AEAD_AES_CCM_LIMIT; - if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) { - if (hardLimit) - *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT; - if (keyUpdateLimit) - *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT; - } - else { - if (hardLimit) - *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT; - if (keyUpdateLimit) - *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT; - } - break; - default: - fprintf(stderr, "Unrecognized bulk cipher"); - AssertFalse(1); - break; - } -} - -static void test_AEAD_limit_client(WOLFSSL* ssl) -{ - int ret; - int i; - int didReKey = 0; - char msgBuf[20]; - w64wrapper hardLimit; - w64wrapper keyUpdateLimit; - w64wrapper counter; - w64wrapper sendLimit; - - test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit); - - w64Zero(&counter); - AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)); - - wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv); - - for (i = 0; i < 10; i++) { - /* Test some failed decryptions */ - test_AEAD_fail_decryption = 1; - w64Increment(&counter); - ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); - /* Should succeed since decryption failures are dropped */ - AssertIntGT(ret, 0); - AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)); - } - - test_AEAD_fail_decryption = 1; - Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit; - w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount); - /* 100 read calls should be enough to complete the key update */ - w64Zero(&counter); - for (i = 0; i < 100; i++) { - /* Key update should be sent and negotiated */ - ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); - AssertIntGT(ret, 0); - /* Epoch after one key update is 4 */ - if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) && - w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) { - didReKey = 1; - break; - } - } - AssertTrue(didReKey); - - if (!w64IsZero(sendLimit)) { - /* Test the sending limit for AEAD ciphers */ -#ifdef WOLFSSL_MUTEX_INITIALIZER - (void)wc_LockMutex(&test_AEAD_mutex); -#endif - Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit; - test_AEAD_seq_num = 1; - XMEMSET(msgBuf, 0, sizeof(msgBuf)); - ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf)); - AssertIntGT(ret, 0); - didReKey = 0; - w64Zero(&counter); -#ifdef WOLFSSL_MUTEX_INITIALIZER - wc_UnLockMutex(&test_AEAD_mutex); -#endif - /* 100 read calls should be enough to complete the key update */ - for (i = 0; i < 100; i++) { - /* Key update should be sent and negotiated */ - ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); - AssertIntGT(ret, 0); - /* Epoch after another key update is 5 */ - if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) && - w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) { - didReKey = 1; - break; - } - } - AssertTrue(didReKey); - } - - test_AEAD_fail_decryption = 2; - Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit; - w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount); - /* Connection should fail with a DECRYPT_ERROR */ - ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); - AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); - AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR)); - -#ifdef WOLFSSL_ATOMIC_INITIALIZER - WOLFSSL_ATOMIC_STORE(test_AEAD_done, 1); -#else - test_AEAD_done = 1; -#endif -} - -int counter = 0; -static void test_AEAD_limit_server(WOLFSSL* ssl) -{ - char msgBuf[] = "Sending data"; - int ret = WOLFSSL_SUCCESS; - w64wrapper sendLimit; - SOCKET_T fd = wolfSSL_get_fd(ssl); - struct timespec delay; - XMEMSET(&delay, 0, sizeof(delay)); - delay.tv_nsec = 100000000; /* wait 0.1 seconds */ - tcp_set_nonblocking(&fd); /* So that read doesn't block */ - wolfSSL_dtls_set_using_nonblock(ssl, 1); - test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit); - while (! - #ifdef WOLFSSL_ATOMIC_INITIALIZER - WOLFSSL_ATOMIC_LOAD(test_AEAD_done) - #else - test_AEAD_done - #endif - && ret > 0) - { - counter++; -#ifdef WOLFSSL_MUTEX_INITIALIZER - (void)wc_LockMutex(&test_AEAD_mutex); -#endif - if (test_AEAD_seq_num) { - /* We need to update the seq number so that we can understand the - * peer. Otherwise we will incorrectly interpret the seq number. */ - Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch); - AssertNotNull(e); - e->nextPeerSeqNumber = sendLimit; - test_AEAD_seq_num = 0; - } -#ifdef WOLFSSL_MUTEX_INITIALIZER - wc_UnLockMutex(&test_AEAD_mutex); -#endif - (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); - ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf)); - nanosleep(&delay, NULL); - } -} - -static int test_wolfSSL_dtls_AEAD_limit(void) -{ - callback_functions func_cb_client; - callback_functions func_cb_server; - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_server.method = wolfDTLSv1_3_server_method; - func_cb_client.method = wolfDTLSv1_3_client_method; - func_cb_server.on_result = test_AEAD_limit_server; - func_cb_client.on_result = test_AEAD_limit_client; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - if (!func_cb_client.return_code) - return TEST_FAIL; - if (!func_cb_server.return_code) - return TEST_FAIL; - - return TEST_SUCCESS; -} -#else -static int test_wolfSSL_dtls_AEAD_limit(void) -{ - return TEST_SKIPPED; -} -#endif - -#if defined(WOLFSSL_DTLS) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ - !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING) -static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl) -{ - int fd, ret; - byte ch_msg[] = { - 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a, - 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29, - 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00, - 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, - 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, - 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, - 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, - 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01, - 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, - 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, - 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, - 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c, - 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, - 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, - 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3, - 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6, - 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a, - 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43, - 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3, - 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d, - 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7, - 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e, - 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59, - 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0, - 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c, - 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6, - 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef, - 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45, - 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b, - 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83, - 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7, - 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2, - 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98, - 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a, - 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8, - 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d, - 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02, - 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33, - 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f, - 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3, - 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20, - 0x31, 0x68, 0x4c - }; - - fd = wolfSSL_get_wfd(ssl); - AssertIntGE(fd, 0); - ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0); - AssertIntGT(ret, 0); - /* consume the HRR otherwise handshake will fail */ - ret = (int)recv(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0); - AssertIntGT(ret, 0); -} - -#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) -static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl) -{ - int fd, ret; - byte ch_msh_invalid_cookie[] = { - 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, - 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60, - 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6, - 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00, - 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, - 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, - 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, - 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, - 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01, - 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, - 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, - 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, - 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45, - 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, - 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19, - 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00, - 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c, - 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02, - 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee, - 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f, - 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a, - 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27, - 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf, - 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1, - 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86, - 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d, - 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6, - 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7, - 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd, - 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4, - 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b, - 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0, - 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd, - 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51, - 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92, - 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e, - 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e, - 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc, - 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31, - 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d, - 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b, - 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad, - 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c, - 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00, - 0x23, 0x00, 0x00 - }; - byte alert_reply[50]; - byte expected_alert_reply[] = { - 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x02, 0x02, 0x2f - }; - - fd = wolfSSL_get_wfd(ssl); - if (fd >= 0) { - ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msh_invalid_cookie, - sizeof(ch_msh_invalid_cookie), 0); - AssertIntGT(ret, 0); - /* should reply with an illegal_parameter reply */ - ret = (int)recv(fd, (MESSAGE_TYPE_CAST)alert_reply, sizeof(alert_reply), 0); - AssertIntEQ(ret, sizeof(expected_alert_reply)); - AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, - sizeof(expected_alert_reply)), 0); - } -} -#endif - -static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl) -{ -#ifndef NO_MD5 - enum wc_HashType hashType = WC_HASH_TYPE_MD5; -#elif !defined(NO_SHA) - enum wc_HashType hashType = WC_HASH_TYPE_SHA; -#elif !defined(NO_SHA256) - enum wc_HashType hashType = WC_HASH_TYPE_SHA256; -#else - #error "We need a digest to hash the WOLFSSL object" -#endif - byte hashBuf[WC_MAX_DIGEST_SIZE]; - wc_HashAlg hash; - const TLSX* exts = ssl->extensions; - WOLFSSL sslCopy; /* Use a copy to omit certain fields */ -#ifndef WOLFSSL_SMALL_STACK_CACHE - HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in - * InitHandshakeHashes */ -#endif - - XMEMCPY(&sslCopy, ssl, sizeof(*ssl)); - XMEMSET(hashBuf, 0, sizeof(hashBuf)); - - /* Following fields are not important to compare */ - XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN); - sslCopy.buffers.inputBuffer.buffer = NULL; - sslCopy.buffers.inputBuffer.bufferSize = 0; - sslCopy.buffers.inputBuffer.dynamicFlag = 0; - sslCopy.buffers.inputBuffer.offset = 0; - XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN); - sslCopy.buffers.outputBuffer.buffer = NULL; - sslCopy.buffers.outputBuffer.bufferSize = 0; - sslCopy.buffers.outputBuffer.dynamicFlag = 0; - sslCopy.buffers.outputBuffer.offset = 0; - sslCopy.error = 0; - sslCopy.curSize = 0; - sslCopy.curStartIdx = 0; - sslCopy.keys.curSeq_lo = 0; - XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL)); -#ifdef WOLFSSL_DTLS13 - XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq)); - sslCopy.dtls13FastTimeout = 0; -#endif - sslCopy.keys.dtls_peer_handshake_number = 0; - XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history)); - sslCopy.hsHashes = NULL; -#if !defined(WOLFSSL_NO_CLIENT_AUTH) && \ - ((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \ - (defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \ - (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH))) - sslCopy.options.cacheMessages = 0; -#endif -#ifdef WOLFSSL_ASYNC_IO -#ifdef WOLFSSL_ASYNC_CRYPT - sslCopy.asyncDev = NULL; -#endif - sslCopy.async = NULL; -#endif - - AssertIntEQ(wc_HashInit(&hash, hashType), 0); - AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0); - /* hash extension list */ - while (exts != NULL) { - AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0); - exts = exts->next; - } - /* Hash suites */ - if (sslCopy.suites != NULL) { - AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites, - sizeof(struct Suites)), 0); - } - -#ifdef WOLFSSL_SMALL_STACK_CACHE - /* with WOLFSSL_SMALL_STACK_CACHE, the SHA-2 objects always differ after - * initialization because of cached W and (for SHA512) X buffers. - */ -#else - /* Hash hsHashes */ - AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes, - sizeof(*hsHashes)), 0); -#endif - - AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0); - AssertIntEQ(wc_HashFree(&hash, hashType), 0); - - return MakeWordFromHash(hashBuf); -} - -static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb; -static int test_wolfSSL_dtls_compare_stateless_cb_call_once; -static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl, - char *buf, int sz, void *ctx) -{ - if (test_wolfSSL_dtls_compare_stateless_cb_call_once) { - test_wolfSSL_dtls_compare_stateless_cb_call_once = 0; - return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx); - } - else { - return WOLFSSL_CBIO_ERR_WANT_READ; - } -} - -static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl) -{ - /* Compare the ssl object before and after one ClientHello msg */ - SOCKET_T fd = wolfSSL_get_fd(ssl); - int res; - int err; - word32 initHash; - - test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv; - test_wolfSSL_dtls_compare_stateless_cb_call_once = 1; - wolfSSL_dtls_set_using_nonblock(ssl, 1); - ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once; - - initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl); - (void)initHash; - - res = tcp_select(fd, 5); - /* We are expecting a msg. A timeout indicates failure. */ - AssertIntEQ(res, TEST_RECV_READY); - - res = wolfSSL_accept(ssl); - err = wolfSSL_get_error(ssl, res); - AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); - AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ); - - AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl)); - - wolfSSL_dtls_set_using_nonblock(ssl, 0); - ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb; - -} - -#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) -static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl) -{ - int ret; - ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0); - AssertIntEQ(ret, WOLFSSL_SUCCESS); - test_wolfSSL_dtls_compare_stateless(ssl); -} -#endif - -static int test_wolfSSL_dtls_stateless(void) -{ - callback_functions client_cbs, server_cbs; - size_t i; - struct { - method_provider client_meth; - method_provider server_meth; - ssl_callback client_ssl_ready; - ssl_callback server_ssl_ready; - } test_params[] = { -#if !defined(WOLFSSL_NO_TLS12) - {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, - test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless}, -#endif -#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) - {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, - test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie}, - {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, - test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie}, -#endif - }; - - if (0 == sizeof(test_params)){ - return TEST_SKIPPED; - } - - for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) { - XMEMSET(&client_cbs, 0, sizeof(client_cbs)); - XMEMSET(&server_cbs, 0, sizeof(server_cbs)); - client_cbs.doUdp = server_cbs.doUdp = 1; - client_cbs.method = test_params[i].client_meth; - server_cbs.method = test_params[i].server_meth; - - client_cbs.ssl_ready = test_params[i].client_ssl_ready; - server_cbs.ssl_ready = test_params[i].server_ssl_ready; - test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); - - if (!client_cbs.return_code) - return TEST_FAIL; - if (!server_cbs.return_code) - return TEST_FAIL; - } - - return TEST_SUCCESS; -} - -/* DTLS stateless API handling multiple CHs with different HRR groups */ -static int test_wolfSSL_dtls_stateless_hrr_group(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_SEND_HRR_COOKIE) - size_t i; - word32 initHash; - struct { - method_provider client_meth; - method_provider server_meth; - } params[] = { -#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) - { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method }, -#endif -#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS) - { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method }, -#endif - }; - for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) { - WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL; - WOLFSSL *ssl_s = NULL, *ssl_c = NULL, *ssl_c2 = NULL; - struct test_memio_ctx test_ctx; - int groups_1[] = { - WOLFSSL_ECC_SECP256R1, - WOLFSSL_ECC_SECP384R1, - WOLFSSL_ECC_SECP521R1 - }; - int groups_2[] = { - WOLFSSL_ECC_SECP384R1, - WOLFSSL_ECC_SECP521R1 - }; - char hrrBuf[1000]; - int hrrSz = sizeof(hrrBuf); - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - params[i].client_meth, params[i].server_meth), 0); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL, - params[i].client_meth, params[i].server_meth), 0); - - - wolfSSL_SetLoggingPrefix("server"); - wolfSSL_dtls_set_using_nonblock(ssl_s, 1); - - initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s); - - /* Set groups and disable key shares. This ensures that only the given - * groups are in the SupportedGroups extension and that an empty key - * share extension is sent in the initial ClientHello of each session. - * This triggers the server to send a HelloRetryRequest with the first - * group in the SupportedGroups extension selected. */ - wolfSSL_SetLoggingPrefix("client1"); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups_1, 3), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); - - wolfSSL_SetLoggingPrefix("client2"); - ExpectIntEQ(wolfSSL_set_groups(ssl_c2, groups_2, 2), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c2), WOLFSSL_SUCCESS); - - /* Start handshake, send first ClientHello */ - wolfSSL_SetLoggingPrefix("client1"); - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* Read first ClientHello, send HRR with WOLFSSL_ECC_SECP256R1 */ - wolfSSL_SetLoggingPrefix("server"); - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0); - ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrrBuf, &hrrSz, 0), 0); - ExpectIntGT(hrrSz, 0); - ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s)); - test_memio_clear_buffer(&test_ctx, 1); - - /* Send second ClientHello */ - wolfSSL_SetLoggingPrefix("client2"); - ExpectIntEQ(wolfSSL_connect(ssl_c2), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c2, -1), WOLFSSL_ERROR_WANT_READ); - - /* Read second ClientHello, send HRR now with WOLFSSL_ECC_SECP384R1 */ - wolfSSL_SetLoggingPrefix("server"); - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0); - ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s)); - test_memio_clear_buffer(&test_ctx, 1); - - /* Complete first handshake with WOLFSSL_ECC_SECP256R1 */ - wolfSSL_SetLoggingPrefix("client1"); - ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrrBuf, hrrSz), 0); - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - wolfSSL_SetLoggingPrefix("server"); - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_s); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_c2); - wolfSSL_CTX_free(ctx_s); - wolfSSL_CTX_free(ctx_c); - } -#endif /* WOLFSSL_SEND_HRR_COOKIE */ - return EXPECT_RESULT(); -} -#else -static int test_wolfSSL_dtls_stateless(void) -{ - return TEST_SKIPPED; -} - -static int test_wolfSSL_dtls_stateless_hrr_group(void) -{ - return TEST_SKIPPED; -} -#endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE && - * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */ #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl) @@ -30447,92 +27733,6 @@ static int test_wolfSSL_CRYPTO_get_ex_new_index(void) return EXPECT_RESULT(); } -#if defined(HAVE_EX_DATA_CRYPTO) && defined(OPENSSL_EXTRA) - -#define SESSION_NEW_IDX_LONG 0xDEADBEEF -#define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD) -#define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE) -#define SESSION_NEW_IDX_PTR "Testing" - -static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr, - CRYPTO_EX_DATA* a, int idx, long argValue, void* arg) -{ - AssertNotNull(p); - AssertNull(ptr); - AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS); - AssertIntEQ(argValue, SESSION_NEW_IDX_LONG); - AssertStrEQ(arg, SESSION_NEW_IDX_PTR); -} - -static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out, - const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV, - void* arg) -{ - EXPECT_DECLS; - - ExpectNotNull(out); - ExpectNotNull(in); - ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL); - ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL); - ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL); - ExpectIntEQ(argV, SESSION_NEW_IDX_LONG); - ExpectStrEQ(arg, SESSION_NEW_IDX_PTR); - *(void**)inPtr = SESSION_DUP_IDX_VAL; - if (EXPECT_SUCCESS()) { - return SSL_SUCCESS; - } - else { - return SSL_FAILURE; - } -} - -static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0; -static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr, - CRYPTO_EX_DATA* a, int idx, long argValue, void* arg) -{ - EXPECT_DECLS; - - ExpectNotNull(p); - ExpectNull(ptr); - ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0); - ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG); - ExpectStrEQ(arg, SESSION_NEW_IDX_PTR); - if (EXPECT_SUCCESS()) { - test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++; - } -} - -static int test_wolfSSL_SESSION_get_ex_new_index(void) -{ - EXPECT_DECLS; - int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG, - (void*)SESSION_NEW_IDX_PTR, - test_wolfSSL_SESSION_get_ex_new_index_new_cb, - test_wolfSSL_SESSION_get_ex_new_index_dup_cb, - test_wolfSSL_SESSION_get_ex_new_index_free_cb); - SSL_SESSION* s = SSL_SESSION_new(); - SSL_SESSION* d = NULL; - - ExpectNotNull(s); - ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL); - ExpectNotNull(d = SSL_SESSION_dup(s)); - ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL); - SSL_SESSION_free(s); - ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1); - SSL_SESSION_free(d); - ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2); - - crypto_ex_cb_free(crypto_ex_cb_ctx_session); - crypto_ex_cb_ctx_session = NULL; - return EXPECT_RESULT(); -} -#else -static int test_wolfSSL_SESSION_get_ex_new_index(void) -{ - return TEST_SKIPPED; -} -#endif - static int test_wolfSSL_set_psk_use_session_callback(void) { EXPECT_DECLS; @@ -32179,560 +29379,6 @@ static int test_wolfSSL_FIPS_mode(void) return EXPECT_RESULT(); } -#ifdef WOLFSSL_DTLS - -/* Prints out the current window */ -static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) { -#ifdef WOLFSSL_DEBUG_DTLS_WINDOW - int i; - for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) { - word32 b = w[i]; - int j; - /* Prints out a 32 bit binary number in big endian order */ - for (j = 0; j < 32; j++, b <<= 1) { - if (b & (((word32)1) << 31)) - fprintf(stderr, "1"); - else - fprintf(stderr, "0"); - } - fprintf(stderr, " "); - } - fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l); -#else - (void)h; - (void)l; - (void)w; -#endif -} - -/* a - cur_hi - * b - cur_lo - * c - next_hi - * d - next_lo - * e - window - * f - expected next_hi - * g - expected next_lo - * h - expected window[1] - * i - expected window[0] - */ -#define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \ - ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \ - DUW_TEST_print_window_binary((a), (b), (e)); \ - ExpectIntEQ((c), (f)); \ - ExpectIntEQ((d), (g)); \ - ExpectIntEQ((e)[1], (h)); \ - ExpectIntEQ((e)[0], (i)); \ -} while (0) - -static int test_wolfSSL_DtlsUpdateWindow(void) -{ - EXPECT_DECLS; - word32 window[WOLFSSL_DTLS_WINDOW_WORDS]; - word32 next_lo = 0; - word16 next_hi = 0; - -#ifdef WOLFSSL_DEBUG_DTLS_WINDOW - fprintf(stderr, "\n"); -#endif - - XMEMSET(window, 0, sizeof window); - DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01); - DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03); - DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31); - DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33); - DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01); - DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03); - DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01); - DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01); - DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01); - DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01); - DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05); - DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07); - DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71); - DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79); - DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01); - DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11); - DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19); - DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001); - DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005); - DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015); - DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151); - DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001); - DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001); - DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01); - DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11); - DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01); - DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01); - DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01); - DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01); - DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01); - DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01); - DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01); - - return EXPECT_RESULT(); -} -#endif /* WOLFSSL_DTLS */ - -#ifdef WOLFSSL_DTLS -static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset, - word32 f_len, word32 f_count, byte ready, word32 bytesReceived) -{ - EXPECT_DECLS; - DtlsMsg* cur = NULL; - static byte msg[100]; - static byte msgInit = 0; - - if (!msgInit) { - int i; - for (i = 0; i < 100; i++) - msg[i] = i + 1; - msgInit = 1; - } - - /* Sanitize test parameters */ - ExpectIntLE(len, sizeof(msg)); - ExpectIntLE(f_offset + f_len, sizeof(msg)); - - if (EXPECT_SUCCESS()) - DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL); - - ExpectNotNull(ssl->dtls_rx_msg_list); - - ExpectNotNull(cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)); - ExpectIntEQ(cur->fragBucketListCount, f_count); - ExpectIntEQ(cur->ready, ready); - ExpectIntEQ(cur->bytesReceived, bytesReceived); - if (ready) { - ExpectNull(cur->fragBucketList); - ExpectBufEQ(cur->fullMsg, msg, cur->sz); - } - else { - DtlsFragBucket* fb; - ExpectNotNull(cur->fragBucketList); - for (fb = cur != NULL ? cur->fragBucketList : NULL; - EXPECT_SUCCESS() && fb != NULL; fb = fb->m.m.next) - ExpectBufEQ(fb->buf, msg + fb->m.m.offset, fb->m.m.sz); - } - if (EXPECT_FAIL()) { - printf("Test parameters: seq %u len %u f_offset %u f_len %u f_count %u ready %u bytesReceived %u\n", - seq, len, f_offset, f_len, f_count, ready, bytesReceived); - } - return EXPECT_RESULT(); -} - -static int test_wolfSSL_DTLS_fragment_buckets(void) -{ - EXPECT_DECLS; - WOLFSSL ssl[1]; - - XMEMSET(ssl, 0, sizeof(*ssl)); - - EXPECT_TEST(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100)); /* 0-100 */ - - EXPECT_TEST(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20)); /* 0-20 */ - EXPECT_TEST(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40)); /* 20-40 */ - EXPECT_TEST(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60)); /* 40-60 */ - EXPECT_TEST(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80)); /* 60-80 */ - EXPECT_TEST(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100)); /* 80-100 */ - - /* Test all permutations of 3 regions */ - /* 1 2 3 */ - EXPECT_TEST(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60)); /* 30-60 */ - EXPECT_TEST(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100)); /* 60-100 */ - /* 1 3 2 */ - EXPECT_TEST(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70)); /* 60-100 */ - EXPECT_TEST(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100)); /* 30-60 */ - /* 2 1 3 */ - EXPECT_TEST(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30)); /* 30-60 */ - EXPECT_TEST(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100)); /* 60-100 */ - /* 2 3 1 */ - EXPECT_TEST(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30)); /* 30-60 */ - EXPECT_TEST(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70)); /* 60-100 */ - EXPECT_TEST(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100)); /* 0-30 */ - /* 3 1 2 */ - EXPECT_TEST(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40)); /* 60-100 */ - EXPECT_TEST(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100)); /* 30-60 */ - /* 3 2 1 */ - EXPECT_TEST(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40)); /* 60-100 */ - EXPECT_TEST(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70)); /* 30-60 */ - EXPECT_TEST(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100)); /* 0-30 */ - - /* Test overlapping regions */ - EXPECT_TEST(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30)); /* 20-30 */ - EXPECT_TEST(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40)); /* 70-80 */ - EXPECT_TEST(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60)); /* 20-50 */ - EXPECT_TEST(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100)); /* 40-100 */ - - /* Test overlapping multiple regions */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20)); /* 0-20 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25)); /* 30-35 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30)); /* 40-45 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35)); /* 50-55 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40)); /* 60-65 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45)); /* 70-75 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55)); /* 30-55 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65)); /* 55-70 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90)); /* 75-100 */ - EXPECT_TEST(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100)); /* 10-35 */ - - EXPECT_TEST(DFB_TEST(ssl,10, 100, 0, 20, 1, 0, 20)); /* 0-20 */ - EXPECT_TEST(DFB_TEST(ssl,10, 100, 30, 20, 2, 0, 40)); /* 30-50 */ - EXPECT_TEST(DFB_TEST(ssl,10, 100, 0, 40, 1, 0, 50)); /* 0-40 */ - EXPECT_TEST(DFB_TEST(ssl,10, 100, 50, 50, 0, 1, 100)); /* 50-100 */ - - /* Test region between other regions */ - EXPECT_TEST(DFB_TEST(ssl,11, 100, 0, 20, 1, 0, 20)); /* 0-20 */ - EXPECT_TEST(DFB_TEST(ssl,11, 100, 80, 20, 2, 0, 40)); /* 80-100 */ - EXPECT_TEST(DFB_TEST(ssl,11, 100, 40, 20, 3, 0, 60)); /* 40-60 */ - EXPECT_TEST(DFB_TEST(ssl,11, 100, 20, 20, 2, 0, 80)); /* 20-40 */ - EXPECT_TEST(DFB_TEST(ssl,11, 100, 60, 20, 0, 1, 100)); /* 60-80 */ - - /* Test gap before first bucket (prev==NULL in gap-before branch) */ - EXPECT_TEST(DFB_TEST(ssl,12, 100, 50, 20, 1, 0, 20)); /* 50-70 */ - EXPECT_TEST(DFB_TEST(ssl,12, 100, 0, 20, 2, 0, 40)); /* 0-20 gap before first */ - EXPECT_TEST(DFB_TEST(ssl,12, 100, 20, 30, 1, 0, 70)); /* 20-50 bridges gap */ - EXPECT_TEST(DFB_TEST(ssl,12, 100, 70, 30, 0, 1, 100)); /* 70-100 */ - - /* Test fragment after message is already complete (ready early return) */ - EXPECT_TEST(DFB_TEST(ssl,13, 100, 0,100, 0, 1, 100)); /* 0-100 complete */ - EXPECT_TEST(DFB_TEST(ssl,13, 100, 0, 50, 0, 1, 100)); /* 0-50 dup on ready */ - - /* Test combine where next bucket is larger than cur (chosenBucket=&next) */ - EXPECT_TEST(DFB_TEST(ssl,14, 100, 0, 10, 1, 0, 10)); /* 0-10 */ - EXPECT_TEST(DFB_TEST(ssl,14, 100, 30, 50, 2, 0, 60)); /* 30-80 */ - EXPECT_TEST(DFB_TEST(ssl,14, 100, 5, 30, 1, 0, 80)); /* 5-35 next>cur */ - EXPECT_TEST(DFB_TEST(ssl,14, 100, 80, 20, 0, 1, 100)); /* 80-100 */ - - /* Test super fragment covering all existing buckets */ - EXPECT_TEST(DFB_TEST(ssl,15, 100, 10, 10, 1, 0, 10)); /* 10-20 */ - EXPECT_TEST(DFB_TEST(ssl,15, 100, 30, 10, 2, 0, 20)); /* 30-40 */ - EXPECT_TEST(DFB_TEST(ssl,15, 100, 60, 10, 3, 0, 30)); /* 60-70 */ - EXPECT_TEST(DFB_TEST(ssl,15, 100, 0,100, 0, 1, 100)); /* 0-100 super frag */ - - /* Test exact duplicate fragment */ - EXPECT_TEST(DFB_TEST(ssl,16, 100, 20, 40, 1, 0, 40)); /* 20-60 */ - EXPECT_TEST(DFB_TEST(ssl,16, 100, 20, 40, 1, 0, 40)); /* 20-60 exact dup */ - EXPECT_TEST(DFB_TEST(ssl,16, 100, 0, 20, 1, 0, 60)); /* 0-20 */ - EXPECT_TEST(DFB_TEST(ssl,16, 100, 60, 40, 0, 1, 100)); /* 60-100 */ - - /* Test combine bridging two buckets (combineNext, cur->data) */ - EXPECT_TEST(DFB_TEST(ssl,17, 100, 0, 30, 1, 0, 30)); /* 0-30 */ - EXPECT_TEST(DFB_TEST(ssl,17, 100, 60, 20, 2, 0, 50)); /* 60-80 */ - EXPECT_TEST(DFB_TEST(ssl,17, 100, 20, 45, 1, 0, 80)); /* 20-65 bridge */ - EXPECT_TEST(DFB_TEST(ssl,17, 100, 80, 20, 0, 1, 100)); /* 80-100 */ - - /* Test progressive left-extension with partial overlaps */ - EXPECT_TEST(DFB_TEST(ssl,18, 100, 70, 30, 1, 0, 30)); /* 70-100 */ - EXPECT_TEST(DFB_TEST(ssl,18, 100, 50, 30, 1, 0, 50)); /* 50-80 extend left */ - EXPECT_TEST(DFB_TEST(ssl,18, 100, 30, 30, 1, 0, 70)); /* 30-60 extend left */ - EXPECT_TEST(DFB_TEST(ssl,18, 100, 0, 40, 0, 1, 100)); /* 0-40 complete left */ - - DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap); - ssl->dtls_rx_msg_list = NULL; - ssl->dtls_rx_msg_list_sz = 0; - return EXPECT_RESULT(); -} - -#endif - - -#if !defined(NO_FILESYSTEM) && \ - defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) - -static int test_wolfSSL_dtls_stateless2(void) -{ - EXPECT_DECLS; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_c2 = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL, - wolfDTLSv1_2_client_method, NULL), 0); - ExpectFalse(wolfSSL_is_stateful(ssl_s)); - /* send CH */ - ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_FAILURE); - ExpectFalse(wolfSSL_is_stateful(ssl_s)); - ExpectIntNE(test_ctx.c_len, 0); - /* consume HRR */ - test_memio_clear_buffer(&test_ctx, 1); - /* send CH1 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); - ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); - /* send HRR */ - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_FAILURE); - /* send CH2 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); - ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), - WOLFSSL_ERROR_WANT_READ); - /* send HRR */ - ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - ExpectTrue(wolfSSL_is_stateful(ssl_s)); - - wolfSSL_free(ssl_c2); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - return EXPECT_RESULT(); -} - -#ifdef HAVE_MAX_FRAGMENT -static int test_wolfSSL_dtls_stateless_maxfrag(void) -{ - EXPECT_DECLS; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_c2 = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - word16 max_fragment = 0; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - ExpectNotNull(ssl_s); - ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c)); - ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8), - WOLFSSL_SUCCESS); - wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx); - wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx); - if (EXPECT_SUCCESS()) { - max_fragment = ssl_s->max_fragment; - } - /* send CH */ - ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); - /* CH without cookie shouldn't change state */ - ExpectIntEQ(ssl_s->max_fragment, max_fragment); - ExpectIntNE(test_ctx.c_len, 0); - - /* consume HRR from buffer */ - test_memio_clear_buffer(&test_ctx, 1); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c2); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - return EXPECT_RESULT(); -} -#endif /* HAVE_MAX_FRAGMENT */ - -#if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME) -#define ROUNDS_WITH_HVR 4 -#define ROUNDS_WITHOUT_HVR 2 -#define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ -static int buf_is_hvr(const byte *data, int len) -{ - if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ) - return 0; - return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request; -} - -static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad) -{ - EXPECT_DECLS; - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - WOLFSSL_SESSION *sess = NULL; - int round_trips; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, - &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); -#ifdef HAVE_SESSION_TICKET - if (useticket) { - ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS); - } -#endif - round_trips = ROUNDS_WITH_HVR; - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips, - &round_trips), 0); - ExpectIntEQ(round_trips, ROUNDS_WITH_HVR); - ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); - wolfSSL_shutdown(ssl_c); - wolfSSL_shutdown(ssl_s); - wolfSSL_free(ssl_c); - ssl_c = NULL; - wolfSSL_free(ssl_s); - ssl_s = NULL; - - test_memio_clear_buffer(&test_ctx, 1); - test_memio_clear_buffer(&test_ctx, 0); - /* make resumption invalid */ - if (bad && (sess != NULL)) { - if (useticket) { -#ifdef HAVE_SESSION_TICKET - if (sess->ticket != NULL) { - sess->ticket[0] = !sess->ticket[0]; - } -#endif /* HAVE_SESSION_TICKET */ - } - else { - sess->sessionID[0] = !sess->sessionID[0]; - } - } - ExpectNotNull(ssl_c = wolfSSL_new(ctx_c)); - ExpectNotNull(ssl_s = wolfSSL_new(ctx_s)); - wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx); - wolfSSL_SetIOReadCtx(ssl_c, &test_ctx); - wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx); - wolfSSL_SetIOReadCtx(ssl_s, &test_ctx); - ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); - ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len)); - ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len)); - if (!useticket) { - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0); - ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1); - ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1); - } - wolfSSL_SESSION_free(sess); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - return EXPECT_RESULT(); -} - -static int test_wolfSSL_dtls_stateless_resume(void) -{ - EXPECT_DECLS; -#ifdef HAVE_SESSION_TICKET - ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS); - ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS); -#endif /* HAVE_SESION_TICKET */ - ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS); - ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS); - return EXPECT_RESULT(); -} -#endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */ - -#if !defined(NO_OLD_TLS) -static int test_wolfSSL_dtls_stateless_downgrade(void) -{ - EXPECT_DECLS; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_c2 = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_c2 = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1), - WOLFSSL_SUCCESS); - ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method())); - wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb); - wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb); - ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2)); - wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx); - wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx); - /* send CH */ - ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); - ExpectIntNE(test_ctx.c_len, 0); - /* consume HRR */ - test_memio_clear_buffer(&test_ctx, 1); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c2); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_c2); - wolfSSL_CTX_free(ctx_s); - - return EXPECT_RESULT(); -} -#endif /* !defined(NO_OLD_TLS) */ - -#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/ - -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) -static int test_WOLFSSL_dtls_version_alert(void) -{ - EXPECT_DECLS; - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0); - - /* client hello */ - ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); - /* hrr */ - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); - /* client hello 1 */ - ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); - /* server hello */ - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); - /* should fail */ - ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR))); - /* shuould fail */ - ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && - (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR))); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - - return EXPECT_RESULT(); -} -#else -static int test_WOLFSSL_dtls_version_alert(void) -{ - return TEST_SKIPPED; -} -#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && - * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && - * !defined(NO_OLD_TLS) && !defined(NO_RSA) - */ #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \ @@ -33557,7 +30203,8 @@ static int test_extra_alerts_wrong_cs(void) #endif #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \ - defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_AES_256) + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_AES_256) && \ + defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384" @@ -34358,71 +31005,6 @@ static int test_rpk_set_xxx_cert_type(void) return EXPECT_RESULT(); } -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - - -static int test_dtls13_bad_epoch_ch(void) -{ - EXPECT_DECLS; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const int EPOCH_OFF = 3; - int groups[] = { - WOLFSSL_ECC_SECP256R1, - WOLFSSL_ECC_SECP384R1, - }; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - /* disable hrr cookie so we can later check msgsReceived.got_client_hello - * with just one message */ - ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); - - /* Set client groups to traditional only to avoid CH fragmentation */ - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 2), WOLFSSL_SUCCESS); - - ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WOLFSSL_ERROR_WANT_READ); - - ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2); - - /* first CH should use epoch 0x0 */ - ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) && - (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0)); - - /* change epoch to 2 */ - test_ctx.s_buff[EPOCH_OFF + 1] = 0x2; - - ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), - WOLFSSL_ERROR_WANT_READ); - - ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1); - - /* resend the CH */ - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); - - return EXPECT_RESULT(); -} -#else -static int test_dtls13_bad_epoch_ch(void) -{ - return TEST_SKIPPED; -} -#endif #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \ @@ -34511,232 +31093,6 @@ static int test_short_session_id(void) } #endif -#if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \ - && defined(WOLFSSL_DTLS13) -static byte* test_find_string(const char *string, - byte *buf, int buf_size) -{ - int string_size, i; - - string_size = (int)XSTRLEN(string); - for (i = 0; i < buf_size - string_size - 1; i++) { - if (XSTRCMP((char*)&buf[i], string) == 0) - return &buf[i]; - } - return NULL; -} - -static int test_wolfSSL_dtls13_null_cipher(void) -{ - EXPECT_DECLS; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char *test_str = "test"; - int test_str_size; - byte buf[255], *ptr = NULL; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256"; - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - test_str_size = XSTRLEN("test") + 1; - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); - ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size); - ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0); - - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); - - /* check that the packet was sent cleartext */ - ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff, - test_ctx.s_len)); - if (ptr != NULL) { - /* modify the message */ - *ptr = 'H'; - /* bad messages should be ignored in DTLS */ - ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1); - ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ)); - } - - ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE); - ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE); - ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1); - ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - return TEST_SUCCESS; -} -#else -static int test_wolfSSL_dtls13_null_cipher(void) -{ - return TEST_SKIPPED; -} -#endif -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ - !defined(SINGLE_THREADED) && !defined(NO_RSA) - -static int test_dtls_msg_get_connected_port(int fd, word16 *port) -{ - SOCKADDR_S peer; - XSOCKLENT len; - int ret; - - XMEMSET((byte*)&peer, 0, sizeof(peer)); - len = sizeof(peer); - ret = getpeername(fd, (SOCKADDR*)&peer, &len); - if (ret != 0 || len > (XSOCKLENT)sizeof(peer)) - return -1; - switch (peer.ss_family) { -#ifdef WOLFSSL_IPV6 - case WOLFSSL_IP6: { - *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port); - break; - } -#endif /* WOLFSSL_IPV6 */ - case WOLFSSL_IP4: - *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port); - break; - default: - return -1; - } - return 0; -} - -static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl) -{ - char buf[1] = {'t'}; - SOCKADDR_IN_T addr; - int sock_fd; - word16 port; - int err; - - (void)ssl; - (void)ctx; - - if (ssl == NULL) - return -1; - - err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port); - if (err != 0) - return -1; - - sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0); - if (sock_fd == -1) - return -1; - build_addr(&addr, wolfSSLIP, port, 1, 0); - - /* send a packet to the server. Being another socket, the kernel will ensure - * the source port will be different. */ - err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr, - sizeof(addr)); - - close(sock_fd); - if (err == -1) - return -1; - - return 0; -} - -/* setup a SSL session but just after the handshake send a packet to the server - * with a source address different than the one of the connected client. The I/O - * callback EmbedRecvFrom should just ignore the packet. Sending of the packet - * is done in test_dtls_msg_from_other_peer_cb */ -static int test_dtls_msg_from_other_peer(void) -{ - EXPECT_DECLS; - callback_functions client_cbs; - callback_functions server_cbs; - - XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs)); - XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs)); - - client_cbs.method = wolfDTLSv1_2_client_method; - server_cbs.method = wolfDTLSv1_2_server_method; - client_cbs.doUdp = 1; - server_cbs.doUdp = 1; - - test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs, - test_dtls_msg_from_other_peer_cb); - - ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS); - ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS); - - return EXPECT_RESULT(); -} -#else -static int test_dtls_msg_from_other_peer(void) -{ - return TEST_SKIPPED; -} -#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ - * !defined(SINGLE_THREADED) && !defined(NO_RSA) */ -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \ - !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) \ - && !defined(USE_WINDOWS_API) -static int test_dtls_ipv6_check(void) -{ - EXPECT_DECLS; - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - SOCKADDR_IN fake_addr6; - int sockfd = -1; - - ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method())); - ExpectNotNull(ssl_c = wolfSSL_new(ctx_c)); - ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); - ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile, - WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); - ExpectNotNull(ssl_s = wolfSSL_new(ctx_s)); - XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6)); - /* mimic a sockaddr_in6 struct, this way we can't test without - * WOLFSSL_IPV6 */ - fake_addr6.sin_family = WOLFSSL_IP6; - ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1); - ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS); - /* can't return error here, as the peer is opaque for wolfssl library at - * this point */ - ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)), - WOLFSSL_SUCCESS); - ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1); - wolfSSL_dtls_set_using_nonblock(ssl_c, 1); - ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); - - ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)), - WOLFSSL_SUCCESS); - /* reuse the socket */ - ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS); - wolfSSL_dtls_set_using_nonblock(ssl_s, 1); - ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS); - ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); - if (sockfd != -1) - close(sockfd); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); - return EXPECT_RESULT(); -} -#else -static int test_dtls_ipv6_check(void) -{ - return TEST_SKIPPED; -} -#endif #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION) @@ -34830,96 +31186,6 @@ static int test_wolfSSL_configure_args(void) return EXPECT_RESULT(); } -static int test_dtls_no_extensions(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - !defined(WOLFSSL_NO_TLS12) - WOLFSSL *ssl_s = NULL; - WOLFSSL_CTX *ctx_s = NULL; - struct test_memio_ctx test_ctx; - const byte chNoExtensions[] = { - /* Handshake type */ - 0x16, - /* Version */ - 0xfe, 0xff, - /* Epoch */ - 0x00, 0x00, - /* Seq number */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - /* Length */ - 0x00, 0x40, - /* CH type */ - 0x01, - /* Length */ - 0x00, 0x00, 0x34, - /* Msg Seq */ - 0x00, 0x00, - /* Frag offset */ - 0x00, 0x00, 0x00, - /* Frag length */ - 0x00, 0x00, 0x34, - /* Version */ - 0xfe, 0xff, - /* Random */ - 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37, - 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b, - 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d, - /* Session Length */ - 0x00, - /* Cookie Length */ - 0x00, - /* CS Length */ - 0x00, 0x0c, - /* CS */ - 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33, - /* Comp Meths Length */ - 0x01, - /* Comp Meths */ - 0x00 - /* And finally... no extensions */ - }; - int i; -#ifdef OPENSSL_EXTRA - int repeats = 2; -#else - int repeats = 1; -#endif - - for (i = 0; i < repeats; i++) { - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ssl_s = NULL; - ctx_s = NULL; - - ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s, - NULL, wolfDTLS_server_method), 0); - - test_memio_clear_buffer(&test_ctx, 0); - ExpectIntEQ( - test_memio_inject_message(&test_ctx, 1, - (const char *)chNoExtensions, sizeof(chNoExtensions)), 0); - - -#ifdef OPENSSL_EXTRA - if (i > 0) { - ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION), - WOLFSSL_SUCCESS); - } -#endif - - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Expecting a handshake msg. Either HVR or SH. */ - ExpectIntGT(test_ctx.c_len, 0); - ExpectIntEQ(test_ctx.c_buff[0], 0x16); - - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); - } -#endif - return EXPECT_RESULT(); -} static int test_tls_alert_no_server_hello(void) { @@ -35044,42 +31310,6 @@ static int test_TLSX_CA_NAMES_bad_extension(void) return EXPECT_RESULT(); } -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) -static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx) -{ - AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), - WOLFSSL_SUCCESS); -} - -static int test_dtls_1_0_hvr_downgrade(void) -{ - EXPECT_DECLS; - callback_functions func_cb_client; - callback_functions func_cb_server; - - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_client.method = wolfDTLS_client_method; - func_cb_server.method = wolfDTLSv1_2_server_method; - func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); - ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); - - return EXPECT_RESULT(); -} -#else -static int test_dtls_1_0_hvr_downgrade(void) -{ - EXPECT_DECLS; - return EXPECT_RESULT(); -} -#endif #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \ defined(HAVE_SESSION_TICKET) @@ -35236,499 +31466,12 @@ static int test_session_ticket_hs_update(void) return EXPECT_RESULT(); } -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION) -static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx) -{ - AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), - WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); -} -static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx) -{ - AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); -} -static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl) -{ - char testMsg[] = "Message after SCR"; - char msgBuf[sizeof(testMsg)]; - if (wolfSSL_is_server(ssl)) { - AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); - AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY)); - AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); - AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), - sizeof(testMsg)); - } - else { - AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), - sizeof(testMsg)); - AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); - } -} -static int test_dtls_downgrade_scr_server(void) -{ - EXPECT_DECLS; - callback_functions func_cb_client; - callback_functions func_cb_server; - - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_client.method = wolfDTLSv1_2_client_method; - func_cb_server.method = wolfDTLS_server_method; - func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready; - func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server; - func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result; - func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); - ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); - - return EXPECT_RESULT(); -} -#else -static int test_dtls_downgrade_scr_server(void) -{ - EXPECT_DECLS; - return EXPECT_RESULT(); -} -#endif - -#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ - defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION) -static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx) -{ - AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), - WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); -} - -static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl) -{ - char testMsg[] = "Message after SCR"; - char msgBuf[sizeof(testMsg)]; - if (wolfSSL_is_server(ssl)) { - AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); - AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY)); - AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); - AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), - sizeof(testMsg)); - } - else { - AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), - sizeof(testMsg)); - AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); - } -} - -static int test_dtls_downgrade_scr(void) -{ - EXPECT_DECLS; - callback_functions func_cb_client; - callback_functions func_cb_server; - - XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); - XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); - - func_cb_client.doUdp = func_cb_server.doUdp = 1; - func_cb_client.method = wolfDTLS_client_method; - func_cb_server.method = wolfDTLSv1_2_server_method; - func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready; - func_cb_client.on_result = test_dtls_downgrade_scr_on_result; - func_cb_server.on_result = test_dtls_downgrade_scr_on_result; - - test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); - - ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); - ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); - - return EXPECT_RESULT(); -} -#else -static int test_dtls_downgrade_scr(void) -{ - EXPECT_DECLS; - return EXPECT_RESULT(); -} -#endif - -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && !defined(WOLFSSL_NO_TLS12) - -static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl, - char *data, int sz, void *ctx) -{ - static int call_counter = 0; - call_counter++; - (void)ssl; - (void)data; - (void)sz; - (void)ctx; - switch (call_counter) { - case 1: - case 2: - return WOLFSSL_CBIO_ERR_TIMEOUT; - case 3: - return WOLFSSL_CBIO_ERR_WANT_READ; - default: - AssertIntLE(call_counter, 3); - return -1; - } -} -#endif - -/* Make sure we don't send acks before getting a server hello */ -static int test_dtls_client_hello_timeout_downgrade(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && !defined(WOLFSSL_NO_TLS12) - - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - DtlsRecordLayerHeader* dtlsRH; - size_t len; - byte sequence_number[8]; - int i; - - for (i = 0; i < 2; i++) { - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0); - - if (i == 0) { - /* First time simulate timeout in IO layer */ - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* SH flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Drop the SH */ - if (EXPECT_SUCCESS()) { - ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); - } - /* Read the remainder of the flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - wolfSSL_SSLSetIORecv(ssl_c, - test_dtls_client_hello_timeout_downgrade_read_cb); - /* CH3 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb); - } - else { - /* Second time call wolfSSL_dtls_got_timeout */ - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* SH flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Drop the SH */ - if (EXPECT_SUCCESS()) { - ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); - } - /* Read the remainder of the flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Quick timeout should be set as we received at least one msg */ - ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - /* Quick timeout should be cleared after a quick timeout */ - /* CH3 */ - ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - } - - /* Parse out to make sure we got exactly one ClientHello message */ - XMEMSET(&sequence_number, 0, sizeof(sequence_number)); - /* Second ClientHello after HVR */ - sequence_number[7] = 2; - dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff; - ExpectIntEQ(dtlsRH->type, handshake); - ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); - ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); - ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, - sizeof(sequence_number)), 0); - len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); - ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); - - /* Connection should be able to continue */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - ssl_c = NULL; - ssl_s = NULL; - ctx_c = NULL; - ctx_s = NULL; - if (!EXPECT_SUCCESS()) - break; - } - -#endif - return EXPECT_RESULT(); -} - -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) -static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data, - int sz, void *ctx) -{ - static int call_counter = 0; - call_counter++; - (void)ssl; - (void)data; - (void)sz; - (void)ctx; - switch (call_counter) { - case 1: - return WOLFSSL_CBIO_ERR_TIMEOUT; - case 2: - return WOLFSSL_CBIO_ERR_WANT_READ; - default: - AssertIntLE(call_counter, 2); - return -1; - } -} -#endif - -/* Make sure we don't send acks before getting a server hello */ -static int test_dtls_client_hello_timeout(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL *ssl_c = NULL; - WOLFSSL_CTX *ctx_c = NULL; - struct test_memio_ctx test_ctx; - DtlsRecordLayerHeader* dtlsRH; - size_t idx; - size_t len; - byte sequence_number[8]; - int i; - - for (i = 0; i < 2; i++) { - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL, - wolfDTLSv1_3_client_method, NULL), 0); - - if (i == 0) { - /* First time simulate timeout in IO layer */ - wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb); - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - } - else { - /* Second time call wolfSSL_dtls_got_timeout */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - } - - /* Parse out to make sure we got exactly two ClientHello messages */ - idx = 0; - XMEMSET(&sequence_number, 0, sizeof(sequence_number)); - /* First ClientHello */ - dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx); - ExpectIntEQ(dtlsRH->type, handshake); - ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); - ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); - ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, - sizeof(sequence_number)), 0); - len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); - ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); - idx += sizeof(DtlsRecordLayerHeader) + len; - /* Second ClientHello */ - sequence_number[7] = 1; - dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx); - ExpectIntEQ(dtlsRH->type, handshake); - ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); - ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); - ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, - sizeof(sequence_number)), 0); - len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); - ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - ssl_c = NULL; - ctx_c = NULL; - if (!EXPECT_SUCCESS()) - break; - } - -#endif - return EXPECT_RESULT(); -} /* DTLS test when dropping the changed cipher spec message */ -static int test_dtls_dropped_ccs(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ - && !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - DtlsRecordLayerHeader* dtlsRH; - size_t len; - byte data[1]; - - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server ccs + finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); - - /* Drop the ccs */ - dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff; - len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); - ExpectIntEQ(len, 1); - ExpectIntEQ(dtlsRH->type, change_cipher_spec); - if (EXPECT_SUCCESS()) { - ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); - } - - /* Client rtx flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - /* Server ccs + finished rtx */ - ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client processes finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ - && !defined(WOLFSSL_NO_TLS12) -static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen, - byte seq_num) -{ - EXPECT_DECLS; - DtlsRecordLayerHeader* dtlsRH; - byte sequence_number[8]; - - XMEMSET(&sequence_number, 0, sizeof(sequence_number)); - - ExpectIntGE(ioBufLen, sizeof(*dtlsRH)); - dtlsRH = (DtlsRecordLayerHeader*)ioBuf; - ExpectIntEQ(dtlsRH->type, handshake); - ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); - ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); - sequence_number[7] = seq_num; - ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, - sizeof(sequence_number)), 0); - - return EXPECT_RESULT(); -} -#endif - -/* - * Make sure that we send the correct sequence number after a HelloVerifyRequest - * and after a HelloRetryRequest. This is testing the server side as it is - * operating statelessly and should copy the sequence number of the ClientHello. - */ -static int test_dtls_seq_num_downgrade(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ - && !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff, - test_ctx.s_len, 0), TEST_SUCCESS); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff, - test_ctx.c_len, 0), TEST_SUCCESS); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff, - test_ctx.s_len, 1), TEST_SUCCESS); - /* Server first flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff, - test_ctx.c_len, 1), TEST_SUCCESS); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} /** * Make sure we don't send RSA Signature Hash Algorithms in the @@ -35956,626 +31699,13 @@ static int test_revoked_loaded_int_cert(void) return EXPECT_RESULT(); } -static int test_dtls13_frag_ch_pq(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && defined(WOLFSSL_DTLS_CH_FRAG) && defined(WOLFSSL_HAVE_MLKEM) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char *test_str = "test"; - int test_str_size; - byte buf[255]; -#if defined(WOLFSSL_MLKEM_KYBER) - #if !defined(WOLFSSL_NO_KYBER1024) - int group = WOLFSSL_KYBER_LEVEL5; - const char *group_name = "KYBER_LEVEL5"; - #elif !defined(WOLFSSL_NO_KYBER768) - int group = WOLFSSL_KYBER_LEVEL3; - const char *group_name = "KYBER_LEVEL3"; - #else - int group = WOLFSSL_KYBER_LEVEL1; - const char *group_name = "KYBER_LEVEL1"; - #endif -#elif !defined(WOLFSSL_NO_ML_KEM) && !defined(WOLFSSL_TLS_NO_MLKEM_STANDALONE) - #if !defined(WOLFSSL_NO_ML_KEM_1024) - int group = WOLFSSL_ML_KEM_1024; - const char *group_name = "ML_KEM_1024"; - #elif !defined(WOLFSSL_NO_ML_KEM_768) - int group = WOLFSSL_ML_KEM_768; - const char *group_name = "ML_KEM_768"; - #else - int group = WOLFSSL_ML_KEM_512; - const char *group_name = "ML_KEM_512"; - #endif -#elif defined(WOLFSSL_PQC_HYBRIDS) - #if defined(HAVE_CURVE25519) && !defined(WOLFSSL_NO_ML_KEM_768) - int group = WOLFSSL_X25519MLKEM768; - const char *group_name = "X25519MLKEM768"; - #elif !defined(WOLFSSL_NO_ML_KEM_768) - int group = WOLFSSL_SECP256R1MLKEM768; - const char *group_name = "SecP256r1MLKEM768"; - #else - int group = WOLFSSL_SECP384R1MLKEM1024; - const char *group_name = "SecP384r1MLKEM1024"; - #endif -#endif - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - /* Add in a large post-quantum key share to make the CH long. */ - ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), group_name); - ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), group_name); - test_str_size = XSTRLEN("test") + 1; - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); - ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size); - ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0); - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ - && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ - defined(WOLFSSL_AES_256) -static int test_dtls_frag_ch_count_records(byte* b, int len) -{ - DtlsRecordLayerHeader* dtlsRH; - int records = 0; - size_t recordLen; - while (len > 0) { - records++; - dtlsRH = (DtlsRecordLayerHeader*)b; - recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1]; - if (recordLen > (size_t)len) - break; - b += sizeof(DtlsRecordLayerHeader) + recordLen; - len -= sizeof(DtlsRecordLayerHeader) + recordLen; - } - return records; -} -#endif -static int test_dtls_frag_ch(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ - defined(WOLFSSL_AES_256) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - static unsigned int DUMMY_MTU = 256; - unsigned int len; - unsigned char four_frag_CH[] = { - 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1, - 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85, - 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00, - 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, - 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, - 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, - 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, - 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02, - 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, - 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, - 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, - 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c, - 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, - 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17, - 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1, - 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19, - 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9, - 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, - 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f, - 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e, - 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61, - 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6, - 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b, - 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2, - 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b, - 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28, - 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86, - 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf, - 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c, - 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f, - 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06, - 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78, - 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8, - 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b, - 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6, - 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, - 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46, - 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96, - 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50, - 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80, - 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7, - 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5, - 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4, - 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d, - 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3, - 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e, - 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc, - 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72, - 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4, - 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4, - 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb, - 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17, - 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b, - 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00, - 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66, - 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c, - 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50, - 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4, - 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99, - 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3, - 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43, - 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13, - 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb, - 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87, - 0xa5, 0xcb, 0x68, 0xf3 - }; - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - /* Fragment msgs */ - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS); - /* Add in some key shares to make the CH long */ - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1), - WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1), - WOLFSSL_SUCCESS); -#ifdef HAVE_FFDHE_2048 - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048), - WOLFSSL_SUCCESS); -#endif -#ifdef HAVE_FFDHE_3072 - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_3072), - WOLFSSL_SUCCESS); -#endif -#ifdef HAVE_FFDHE_4096 - ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_4096), - WOLFSSL_SUCCESS); -#endif - ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); - - /* Reject fragmented first CH */ - ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH, - sizeof(four_frag_CH)), 4); - len = sizeof(four_frag_CH); - test_memio_clear_buffer(&test_ctx, 0); - while (len > 0 && EXPECT_SUCCESS()) { - unsigned int inj_len = len > DUMMY_MTU ? DUMMY_MTU : len; - unsigned char *idx = four_frag_CH + sizeof(four_frag_CH) - len; - ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, (const char *)idx, - inj_len), 0); - len -= inj_len; - } - ExpectIntEQ(test_ctx.s_len, sizeof(four_frag_CH)); - while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) { - int s_len = test_ctx.s_len; - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Fail if we didn't advance the buffer to avoid infinite loops */ - ExpectIntLT(test_ctx.s_len, s_len); - } - /* Expect all fragments read */ - ExpectIntEQ(test_ctx.s_len, 0); - /* Expect quietly dropping fragmented first CH */ - ExpectIntEQ(test_ctx.c_len, 0); - -#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) - /* Disable ECH as it pushes it over our MTU */ - wolfSSL_SetEchEnable(ssl_c, 0); -#endif - - /* Limit options to make the CH a fixed length */ - /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2 - * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */ -#ifdef OPENSSL_EXTRA - ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384" - ":DHE-RSA-AES256-GCM-SHA384")); -#else - ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384")); -#endif - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Count records. Expect 1 unfragmented CH */ - ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff, - test_ctx.s_len), 1); - /* HRR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Count records. Expect fragmented CH */ - ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff, - test_ctx.s_len), 1); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); - ssl_c = ssl_s = NULL; - ctx_c = ctx_s = NULL; -#endif - return EXPECT_RESULT(); -} - -static int test_dtls_empty_keyshare_with_cookie(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - unsigned char ch_empty_keyshare_with_cookie[] = { - 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3, - 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9, - 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00, - 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, - 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, - 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, - 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, - 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00, - 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47, - 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf, - 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f, - 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13, - 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d, - 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5, - 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00, - 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, - 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08, - 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, - 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, - 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, - 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f, - 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00 - }; - DtlsRecordLayerHeader* dtlsRH; - byte sequence_number[8]; - - XMEMSET(&sequence_number, 0, sizeof(sequence_number)); - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s, - NULL, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, - (const char *)ch_empty_keyshare_with_cookie, - sizeof(ch_empty_keyshare_with_cookie)), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Expect an alert. A plaintext alert should be exactly 15 bytes. */ - ExpectIntEQ(test_ctx.c_len, 15); - dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff; - ExpectIntEQ(dtlsRH->type, alert); - ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); - ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); - sequence_number[7] = 1; - ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, - sizeof(sequence_number)), 0); - ExpectIntEQ(dtlsRH->length[0], 0); - ExpectIntEQ(dtlsRH->length[1], 2); - ExpectIntEQ(test_ctx.c_buff[13], alert_fatal); - ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter); - - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -static int test_dtls_old_seq_number(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ - !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client second flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Modify the sequence number */ - { - DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff; - XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number)); - } - /* Server second flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Server should not do anything as a pkt was dropped */ - ExpectIntEQ(test_ctx.c_len, 0); - ExpectIntEQ(test_ctx.s_len, 0); - /* Trigger rtx */ - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - - /* Complete connection */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -static int test_dtls12_missing_finished(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ - !defined(WOLFSSL_NO_TLS12) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char test_str[] = "test string"; - char test_buf[sizeof(test_str)]; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HVR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); - /* Let's clear the output */ - test_memio_clear_buffer(&test_ctx, 1); - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), - sizeof(test_str)); - /* Client should not error out on a missing finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server rtx second flight with finished */ - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1); - /* Client process rest of handshake */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); - - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), - sizeof(test_str)); - ExpectIntEQ(wolfSSL_read(ssl_c, test_buf, sizeof(test_buf)), - sizeof(test_str)); - ExpectBufEQ(test_buf, test_str, sizeof(test_str)); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -static int test_dtls13_missing_finished_client(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char test_str[] = "test string"; - char test_buf[sizeof(test_str)]; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HRR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Let's clear the output */ - test_memio_clear_buffer(&test_ctx, 1); - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), - sizeof(test_str)); - /* Client second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server should not error out on a missing finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client rtx second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); - /* Client */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), - sizeof(test_str)); - ExpectIntEQ(wolfSSL_read(ssl_c, test_buf, sizeof(test_buf)), - sizeof(test_str)); - ExpectBufEQ(test_buf, test_str, sizeof(test_str)); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -static int test_dtls13_missing_finished_server(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char test_str[] = "test string"; - char test_buf[sizeof(test_str)]; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HRR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Let's clear the output */ - test_memio_clear_buffer(&test_ctx, 0); - ExpectFalse(wolfSSL_is_init_finished(ssl_c)); - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, sizeof(test_str)), - sizeof(test_str)); - /* Server should not error out on a missing finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client rtx second flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); - /* Let's send some app data */ - ExpectIntEQ(wolfSSL_write(ssl_c, test_str, sizeof(test_str)), - sizeof(test_str)); - ExpectIntEQ(wolfSSL_read(ssl_s, test_buf, sizeof(test_buf)), - sizeof(test_str)); - ExpectBufEQ(test_buf, test_str, sizeof(test_str)); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -static int test_dtls13_finished_send_error_propagation(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL; - WOLFSSL_CTX *ctx_s = NULL; - WOLFSSL *ssl_c = NULL; - WOLFSSL *ssl_s = NULL; - struct test_memio_ctx test_ctx; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* HRR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - /* Server first flight with finished */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - /* Client second flight with finished - block sends to force error */ - test_ctx.s_len = TEST_MEMIO_BUF_SZ; - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - /* Verify the error is propagated, not silently swallowed as success */ - ExpectIntNE(wolfSSL_get_error(ssl_c, -1), 0); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) @@ -38110,909 +33240,6 @@ static int test_wolfSSL_inject(void) int testAll = 1; int stopOnFail = 0; -/*----------------------------------------------------------------------------*/ -/* LMS tests */ -/*----------------------------------------------------------------------------*/ -int test_wc_LmsKey_sign_verify(void); -int test_wc_LmsKey_reload_cache(void); -int test_rfc9802_lms_x509_verify(void); -int test_rfc9802_xmss_x509_verify(void); - -#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) - -#include - -#define LMS_TEST_PRIV_KEY_FILE "/tmp/wolfssl_test_lms.key" - -static int test_lms_write_key(const byte* priv, word32 privSz, void* context) -{ - FILE* f = fopen((const char*)context, "wb"); - int ret = WC_LMS_RC_SAVED_TO_NV_MEMORY; - if (f == NULL) - return -1; - if (fwrite(priv, 1, privSz, f) != privSz) - ret = -1; - fclose(f); - return ret; -} - -static int test_lms_read_key(byte* priv, word32 privSz, void* context) -{ - FILE* f = fopen((const char*)context, "rb"); - if (f == NULL) - return -1; - if (fread(priv, 1, privSz, f) == 0) { - fclose(f); - return -1; - } - fclose(f); - return WC_LMS_RC_READ_TO_MEMORY; -} - -/* Helper: init an LMS key with callbacks and L1-H10-W8 params */ -static int test_lms_init_key(LmsKey* key, WC_RNG* rng) -{ - int ret; - - ret = wc_LmsKey_Init(key, NULL, INVALID_DEVID); - if (ret != 0) return ret; - -#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) - ret = wc_LmsKey_SetParameters(key, 1, 10, 8); -#else - ret = wc_LmsKey_SetParameters(key, 1, 5, 8); -#endif - if (ret != 0) return ret; - - ret = wc_LmsKey_SetWriteCb(key, test_lms_write_key); - if (ret != 0) return ret; - - ret = wc_LmsKey_SetReadCb(key, test_lms_read_key); - if (ret != 0) return ret; - - ret = wc_LmsKey_SetContext(key, (void*)LMS_TEST_PRIV_KEY_FILE); - if (ret != 0) return ret; - - (void)rng; - return 0; -} - -#endif /* WOLFSSL_HAVE_LMS && !WOLFSSL_LMS_VERIFY_ONLY */ - -/* - * Test basic LMS sign/verify with multiple signings. - * Uses L1-H10-W8 (1024 total signatures, 32-entry leaf cache). - */ -int test_wc_LmsKey_sign_verify(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) - LmsKey key; - WC_RNG rng; - byte msg[] = "test message for LMS signing"; - byte sig[2048]; - word32 sigSz; - int i; - int numSigs = 5; - - ExpectIntEQ(wc_InitRng(&rng), 0); - - remove(LMS_TEST_PRIV_KEY_FILE); - ExpectIntEQ(test_lms_init_key(&key, &rng), 0); - ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), 0); - - for (i = 0; i < numSigs; i++) { - sigSz = sizeof(sig); - ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); - ExpectIntEQ(wc_LmsKey_Verify(&key, sig, sigSz, msg, sizeof(msg)), 0); - } - - wc_LmsKey_Free(&key); - wc_FreeRng(&rng); - remove(LMS_TEST_PRIV_KEY_FILE); -#endif - return EXPECT_RESULT(); -} - -/* - * Test LMS key reload after advancing past the leaf cache window. - * - * Reproduces a heap-buffer-overflow bug in wc_lms_treehash_init() where the - * leaf cache write uses (i * hash_len) instead of ((i - leaf->idx) * hash_len). - * When q > max_cb (default 32), wc_LmsKey_Reload calls wc_hss_init_auth_path - * which calls wc_lms_treehash_init with q > 0, causing writes past the end of - * the leaf cache buffer. - * - * Reproduction steps: - * 1. Generate L1-H10-W8 key (cacheBits=5, max_cb=32) - * 2. Sign 33 times to advance q past the cache window - * 3. Free the key and reload from persisted state - * 4. Sign and verify after reload - * - * Without the fix: heap-buffer-overflow at wc_lms_impl.c:1965 - * With the fix: all operations succeed, signatures verify - */ -int test_wc_LmsKey_reload_cache(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) && \ - (!defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10)) - LmsKey key; - LmsKey vkey; - WC_RNG rng; - byte msg[] = "test message for LMS signing"; - byte sig[2048]; - word32 sigSz; - byte pub[64]; - word32 pubSz = sizeof(pub); - int i; - /* Sign 33 times to advance q past the 32-entry cache window. */ - int preSigs = 33; - - ExpectIntEQ(wc_InitRng(&rng), 0); - - /* Phase 1: Generate key and sign past cache window */ - remove(LMS_TEST_PRIV_KEY_FILE); - ExpectIntEQ(test_lms_init_key(&key, &rng), 0); - ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), 0); - - for (i = 0; i < preSigs; i++) { - sigSz = sizeof(sig); - ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); - } - - /* Save public key for verification after reload */ - ExpectIntEQ(wc_LmsKey_ExportPubRaw(&key, pub, &pubSz), 0); - - wc_LmsKey_Free(&key); - - /* Phase 2: Reload key. Triggers wc_lms_treehash_init with q=33 */ - ExpectIntEQ(test_lms_init_key(&key, &rng), 0); - ExpectIntEQ(wc_LmsKey_Reload(&key), 0); - - /* Phase 3: Sign after reload and verify with separate verify-only key */ - sigSz = sizeof(sig); - ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); - - ExpectIntEQ(wc_LmsKey_Init(&vkey, NULL, INVALID_DEVID), 0); -#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) - ExpectIntEQ(wc_LmsKey_SetParameters(&vkey, 1, 10, 8), 0); -#else - ExpectIntEQ(wc_LmsKey_SetParameters(&vkey, 1, 5, 8), 0); -#endif - ExpectIntEQ(wc_LmsKey_ImportPubRaw(&vkey, pub, pubSz), 0); - ExpectIntEQ(wc_LmsKey_Verify(&vkey, sig, sigSz, msg, sizeof(msg)), 0); - - wc_LmsKey_Free(&vkey); - wc_LmsKey_Free(&key); - wc_FreeRng(&rng); - remove(LMS_TEST_PRIV_KEY_FILE); -#endif - return EXPECT_RESULT(); -} - -/*----------------------------------------------------------------------------*/ -/* RFC 9802 (HSS/LMS and XMSS/XMSS^MT in X.509) tests */ -/*----------------------------------------------------------------------------*/ - -/* For every committed self-signed test certificate confirm: - * - wc_ParseCert succeeds on the RFC 9802 AlgorithmIdentifier encoding - * (OID-only SEQUENCE, no NULL parameters) - * - keyOID and signatureOID are set to the expected values - * - loading as a trust anchor and verifying the same bytes through - * wolfSSL_CertManagerVerifyBuffer exercises the ConfirmSignature - * path and succeeds on a valid cert - * - flipping a byte in the signature AND flipping a byte in the - * TBSCertificate both cause verification to fail. - * - * Test vectors are in certs/lms/ and certs/xmss/, generated with Bouncy - * Castle 1.81. BC's default XMSS / XMSS^MT X.509 encoding uses pre- - * standard ISARA OIDs and wraps the raw RFC 8391 pub key in an OCTET - * STRING, so the fixtures were produced with a small generator that - * overrides the AlgorithmIdentifier and SPKI to match RFC 9802. */ -#if (defined(WOLFSSL_HAVE_LMS) || defined(WOLFSSL_HAVE_XMSS)) && \ - !defined(NO_FILESYSTEM) && !defined(NO_CERTS) -/* Sanity bound on a test fixture cert. The largest BC-generated - * fixture we ship (XMSS^MT 40/8) is ~19 KiB; 1 MiB is well above - * any realistic RFC 9802 cert and catches a wild XFTELL. Typed as - * long to match XFTELL's return so the size comparison below isn't - * a mixed long-vs-int compare. */ -#define RFC9802_TEST_MAX_CERT_SIZE ((long)(1L << 20)) - -/* Load a whole file into a freshly-allocated buffer. Caller frees. */ -static int rfc9802_load_file(const char* path, byte** out, int* outLen) -{ - EXPECT_DECLS; - XFILE f = XBADFILE; - long sz = 0; - size_t got = 0; - byte* buf = NULL; - - *out = NULL; - *outLen = 0; - ExpectTrue((f = XFOPEN(path, "rb")) != XBADFILE); - if (f == XBADFILE) - return TEST_FAIL; - if (XFSEEK(f, 0, XSEEK_END) == 0) - sz = XFTELL(f); - (void)XFSEEK(f, 0, XSEEK_SET); - ExpectIntGT(sz, 0); - ExpectIntLT(sz, RFC9802_TEST_MAX_CERT_SIZE); - /* Hard-fail before XMALLOC if XFSEEK / XFTELL produced an unusable - * size: ExpectInt* records the failure but doesn't short-circuit, - * so without this guard a -1 from XFTELL would cast to a multi-GiB - * (size_t) allocation, and a 0 would request a zero-byte malloc. */ - if (sz <= 0 || sz >= RFC9802_TEST_MAX_CERT_SIZE) { - XFCLOSE(f); - return TEST_FAIL; - } - ExpectNotNull(buf = (byte*)XMALLOC((size_t)sz, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); - if (buf != NULL) { - got = XFREAD(buf, 1, (size_t)sz, f); - ExpectIntEQ(got, (size_t)sz); - /* On a short read the caller would otherwise proceed with a - * partially-initialized buffer and produce cascading parse - * failures driven by the uninitialized tail. Free here so the - * caller's `if (buf == NULL) return TEST_FAIL;` short-circuits - * cleanly with a single recorded failure. */ - if (got != (size_t)sz) { - XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - buf = NULL; - sz = 0; - } - } - XFCLOSE(f); - *out = buf; - *outLen = (int)sz; - return EXPECT_RESULT(); -} - -static int rfc9802_verify_one_cert(const char* path, word32 expectedKeyOID, - word32 expectedSigOID) -{ - EXPECT_DECLS; - byte* buf = NULL; - byte* tampered = NULL; - int bytes = 0; - DecodedCert cert; - WOLFSSL_CERT_MANAGER* cm = NULL; - word32 certBegin = 0; - word32 sigIndex = 0; - - ExpectIntEQ(rfc9802_load_file(path, &buf, &bytes), TEST_SUCCESS); - if (buf == NULL) - return TEST_FAIL; - - /* Parse + check OIDs, capture certBegin and sigIndex for later tamper. */ - wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); - ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); - ExpectIntEQ((int)cert.keyOID, (int)expectedKeyOID); - ExpectIntEQ((int)cert.signatureOID, (int)expectedSigOID); - certBegin = cert.certBegin; - sigIndex = cert.sigIndex; - wc_FreeDecodedCert(&cert); - - /* Full verify against a self-installed trust anchor. */ - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, buf, (long)bytes, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - - ExpectNotNull(tampered = (byte*)XMALLOC((size_t)bytes, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); - - /* Negative 1: flip a byte inside the signatureValue BIT STRING. - * Everything after sigIndex is the signatureAlgorithm + the BIT - * STRING payload, so flipping the last byte is always inside the - * signature content. */ - if (tampered != NULL) { - XMEMCPY(tampered, buf, (size_t)bytes); - tampered[bytes - 1] ^= 0x01; - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, tampered, - (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - } - - /* Negative 2: flip a byte at the midpoint of the TBSCertificate. The - * TBS is the first element of the outer Certificate SEQUENCE and - * its bytes lie between (certBegin + outerSeqHeader) and sigIndex. - * Picking the midpoint ensures we're inside TBS regardless of the - * fixture's DN / extensions layout. */ - if (tampered != NULL && sigIndex > certBegin + 8U) { - word32 midTbs = certBegin + 8 + ((sigIndex - (certBegin + 8)) / 2); - XMEMCPY(tampered, buf, (size_t)bytes); - tampered[midTbs] ^= 0x01; - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, tampered, - (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - } - - /* The fixtures MUST carry a KeyUsage extension with at least one of - * digitalSignature / nonRepudiation / keyCertSign / cRLSign set per - * RFC 9802 sec 3. Re-parse and assert that wolfSSL recorded a non- - * empty set of KeyUsage bits from one of those values. */ - wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); - ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); - ExpectIntEQ(cert.extKeyUsageSet, 1); - ExpectIntNE(cert.extKeyUsage & (KEYUSE_DIGITAL_SIG | KEYUSE_CONTENT_COMMIT | - KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN), 0); - wc_FreeDecodedCert(&cert); - - XFREE(tampered, NULL, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - return EXPECT_RESULT(); -} -#endif - -/* Direct wolfCrypt-level negative tests for the parameter-derivation - * helpers used by the RFC 9802 parse path. These exercise failure modes - * (unknown algorithm bytes, truncated inputs, mismatches) that a real - * cert body wouldn't easily reach. */ -#if defined(WOLFSSL_HAVE_LMS) -static int rfc9802_lms_import_negative(void) -{ - EXPECT_DECLS; - LmsKey key; - /* 60-byte buffer matches HSS_PUBLIC_KEY_LEN(32), just like a valid - * SHA-256/M32/H5 key; the algorithm-type bytes are junk so param - * derivation must fail cleanly. */ - byte junk[60]; - - XMEMSET(junk, 0, sizeof(junk)); - /* levels=1, lmsType=0xFFFFFFFF, lmOtsType=0xFFFFFFFF. */ - junk[3] = 1; - XMEMSET(junk + 4, 0xFF, 4); - XMEMSET(junk + 8, 0xFF, 4); - - /* Unknown algorithm types must be rejected. */ - ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, sizeof(junk)), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); - wc_LmsKey_Free(&key); - - /* Too-short buffer: only L + lmsType, no lmOtsType. */ - ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, 8), - WC_NO_ERR_TRACE(BUFFER_E)); - wc_LmsKey_Free(&key); - -#if !defined(WOLFSSL_NO_LMS_SHA256_256) - /* The two cases below pin specific SHA-256/M32 parameter codes - * (L1_H5_W8, L1_H5_W4, L1_H10_W2). Skip them in builds where the - * SHA-256/M32 family is disabled -- the family-agnostic checks - * above (junk algorithm types, too-short buffer, GetSigLen on - * unconfigured key) still cover the universal invariants. */ - - /* Pre-set params that disagree with the raw key's algorithm bytes: - * configure H=5/W=8 but feed buffer that claims H=10 / W=2. */ - XMEMSET(junk, 0, sizeof(junk)); - junk[3] = 1; /* levels=1 */ - junk[7] = 6; /* lmsType = LMS_SHA256_M32_H10 = 6 */ - junk[11] = 2; /* lmOtsType = LMOTS_SHA256_N32_W2 = 2 */ - ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_LmsKey_SetParameters(&key, 1, 5, 8), 0); - ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, sizeof(junk)), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_LmsKey_Free(&key); -#endif /* !WOLFSSL_NO_LMS_SHA256_256 */ - - /* GetSigLen on a key with no params set must not NULL-deref the - * params pointer; it must return BAD_FUNC_ARG instead. */ - { - word32 sigLen = 0; - ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_LmsKey_GetSigLen(&key, &sigLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_LmsKey_Free(&key); - } - -#if !defined(WOLFSSL_NO_LMS_SHA256_256) - /* Partial-write invariant: a length mismatch after a successful - * auto-derive must leave key->params NULL. Build a buffer whose - * leading u32str(L) || lmsType || lmOtsType identifies a known - * parameter set, but truncate to one byte less than the real pub - * key length so the post-derive length check fails. */ - { - byte truncated[59]; /* HSS_PUBLIC_KEY_LEN(32) is 60 */ - XMEMSET(truncated, 0, sizeof(truncated)); - truncated[3] = 1; /* L = 1 */ - truncated[7] = 5; /* lmsType = LMS_SHA256_M32_H5 */ - truncated[11] = 4; /* lmOtsType = LMOTS_SHA256_N32_W4 */ - ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectNull(key.params); - ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, truncated, - sizeof(truncated)), WC_NO_ERR_TRACE(BUFFER_E)); - ExpectNull(key.params); - wc_LmsKey_Free(&key); - } -#endif /* !WOLFSSL_NO_LMS_SHA256_256 */ - - return EXPECT_RESULT(); -} -#endif - -#if defined(WOLFSSL_HAVE_XMSS) -static int rfc9802_xmss_import_negative(void) -{ - EXPECT_DECLS; - XmssKey key; - byte junk[8]; - - XMEMSET(junk, 0, sizeof(junk)); - - /* Too-short buffer. */ - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, 2, 0), - WC_NO_ERR_TRACE(BUFFER_E)); - wc_XmssKey_Free(&key); - - /* Unknown OID (all-zero) for both XMSS and XMSS^MT. */ - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, sizeof(junk), 0), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); - wc_XmssKey_Free(&key); - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, sizeof(junk), 1), - WC_NO_ERR_TRACE(NOT_COMPILED_IN)); - wc_XmssKey_Free(&key); - - /* NULL key / input. */ - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(NULL, junk, sizeof(junk), 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, NULL, 8, 0), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_XmssKey_Free(&key); - - /* GetSigLen on a key with no params set must not NULL-deref the - * params pointer; it must return BAD_FUNC_ARG instead. */ - { - word32 sigLen = 0; - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_GetSigLen(&key, &sigLen), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_XmssKey_Free(&key); - } - - /* Once params have been configured (state != INITED), the OID - * prefix in the raw key MUST match key->oid and is_xmssmt MUST - * match key->is_xmssmt. Set XMSS-SHA2_10_256 and feed a valid- - * sized buffer whose 4-byte OID prefix is bogus -> BAD_FUNC_ARG. */ - { - byte mismatch[XMSS_SHA256_PUBLEN]; - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0); - XMEMSET(mismatch, 0, sizeof(mismatch)); - mismatch[3] = 0x77; /* nonsense OID */ - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, mismatch, - sizeof(mismatch), 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - /* Same buffer with the correct OID, but is_xmssmt hint - * contradicts the configured family -> BAD_FUNC_ARG. */ - mismatch[3] = 0x01; /* WC_XMSS_OID_SHA2_10_256 */ - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, mismatch, - sizeof(mismatch), 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - wc_XmssKey_Free(&key); - } - - /* Partial-write invariant: a length mismatch after a successful - * auto-derive must leave the key in its INITED state, with - * key->params NULL. */ - { - byte truncated[XMSS_SHA256_PUBLEN - 1]; - XMEMSET(truncated, 0, sizeof(truncated)); - truncated[3] = 0x01; - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectNull(key.params); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, truncated, - sizeof(truncated), 0), WC_NO_ERR_TRACE(BUFFER_E)); - ExpectNull(key.params); - wc_XmssKey_Free(&key); - } - - /* is_xmssmt disambiguation: XMSS oid=1 and XMSS^MT oid=1 share - * the wire-numeric value but resolve to different parameter sets. - * Importing the same 68-byte buffer with hint=0 vs hint=1 must - * land in different tables and produce distinct is_xmssmt. */ - { - byte buf[XMSS_SHA256_PUBLEN]; - XMEMSET(buf, 0, sizeof(buf)); - buf[3] = 0x01; - - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); - ExpectIntEQ((int)key.is_xmssmt, 0); - wc_XmssKey_Free(&key); - - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 1), 0); - ExpectIntEQ((int)key.is_xmssmt, 1); - wc_XmssKey_Free(&key); - } - - /* Lenient state: re-importing the same pub key into a VERIFYONLY - * key (params set, no private material) succeeds. The second - * call exercises the lenient-state branch. */ - { - byte buf[XMSS_SHA256_PUBLEN]; - XMEMSET(buf, 0, sizeof(buf)); - buf[3] = 0x01; - - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); - ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); - ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); - wc_XmssKey_Free(&key); - } - - /* Strict signature-length check: wc_XmssKey_Verify rejects any - * sigLen != key->params->sig_len. This guards every consumer - * (RFC 9802 X.509, PKCS#7, CMS, ...) against a longer wrapper that - * happens to start with a valid signature. Construct a key in - * VERIFYONLY state, then verify with sig_len + 1 and sig_len - 1 - * byte buffers; both must fail with BUFFER_E before any crypto - * runs. The buffer contents are irrelevant since the length check - * fires first. */ - { - byte pub[XMSS_SHA256_PUBLEN]; - byte* sigBuf = NULL; - word32 sigLen = 0; - const byte msg[1] = { 0 }; - - XMEMSET(pub, 0, sizeof(pub)); - pub[3] = 0x01; - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, pub, sizeof(pub), 0), 0); - ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); - ExpectIntEQ(wc_XmssKey_GetSigLen(&key, &sigLen), 0); - ExpectIntGT(sigLen, 0); - ExpectNotNull(sigBuf = (byte*)XMALLOC((size_t)sigLen + 1, NULL, - DYNAMIC_TYPE_TMP_BUFFER)); - if (sigBuf != NULL) { - XMEMSET(sigBuf, 0, (size_t)sigLen + 1); - ExpectIntEQ(wc_XmssKey_Verify(&key, sigBuf, sigLen + 1, - msg, (int)sizeof(msg)), WC_NO_ERR_TRACE(BUFFER_E)); - ExpectIntEQ(wc_XmssKey_Verify(&key, sigBuf, sigLen - 1, - msg, (int)sizeof(msg)), WC_NO_ERR_TRACE(BUFFER_E)); - XFREE(sigBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - } - wc_XmssKey_Free(&key); - } - - /* BAD_STATE_E branch: WC_XMSS_STATE_OK must be rejected. Reaching - * OK normally requires a successful private-key Reload / sign, - * which is unavailable in WOLFSSL_XMSS_VERIFY_ONLY builds. Force - * the state directly to exercise the rejection without coupling - * this helper to the signing test fixture; sk stays NULL so Free - * is still safe. */ - { - byte pub[XMSS_SHA256_PUBLEN]; - - XMEMSET(pub, 0, sizeof(pub)); - pub[3] = 0x01; - ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); - ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0); - key.state = WC_XMSS_STATE_OK; - ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, pub, sizeof(pub), 0), - WC_NO_ERR_TRACE(BAD_STATE_E)); - wc_XmssKey_Free(&key); - } - - return EXPECT_RESULT(); -} -#endif - -/* Walk the AlgorithmIdentifier SEQUENCE that begins at sigIndex and - * locate the byte offset of the last byte of its OID content. Handles - * both short-form (length < 128) and long-form DER length encodings, - * so a future fixture-regenerator that emits longer OIDs / SEQUENCEs - * still drives this test rather than tripping the loud-fail branch. - * - * Returns 0 on success with *oidLastByte set; returns -1 on any DER - * shape mismatch. */ -#if defined(WOLFSSL_HAVE_XMSS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) -static int rfc9802_find_sig_alg_oid_last_byte(const byte* buf, word32 bufLen, - word32 sigIndex, word32* oidLastByte) -{ - word32 idx = sigIndex; - word32 oidContentLen = 0; - - /* AlgorithmIdentifier ::= SEQUENCE { algorithm OID, ... } */ - if (idx >= bufLen || buf[idx] != 0x30) - return -1; - idx++; - /* Skip SEQUENCE length (short or long form). */ - if (idx >= bufLen) - return -1; - if (buf[idx] < 0x80) { - idx++; - } - else { - word32 nbytes = (word32)(buf[idx] & 0x7F); - if (nbytes == 0 || nbytes > 4 || idx + 1 + nbytes > bufLen) - return -1; - idx += 1 + nbytes; - } - /* algorithm OID tag. */ - if (idx >= bufLen || buf[idx] != 0x06) - return -1; - idx++; - /* OID length (short or long form). */ - if (idx >= bufLen) - return -1; - if (buf[idx] < 0x80) { - oidContentLen = buf[idx]; - idx++; - } - else { - word32 nbytes = (word32)(buf[idx] & 0x7F); - word32 i; - if (nbytes == 0 || nbytes > 4 || idx + 1 + nbytes > bufLen) - return -1; - for (i = 0; i < nbytes; i++) - oidContentLen = (oidContentLen << 8) | buf[idx + 1 + i]; - idx += 1 + nbytes; - } - if (oidContentLen == 0 || idx + oidContentLen > bufLen) - return -1; - *oidLastByte = idx + oidContentLen - 1; - return 0; -} - -/* Helper: load fixture, locate last byte of outer signatureAlgorithm - * OID, patch it from `expected` to `swap`, and assert that verifying - * the patched cert against itself as a trust anchor fails. */ -static int rfc9802_assert_oid_patch_breaks_verify(const char* path, - byte expectedLastByte, byte patchedLastByte) -{ - EXPECT_DECLS; - byte* buf = NULL; - int bytes = 0; - DecodedCert cert; - WOLFSSL_CERT_MANAGER* cm = NULL; - word32 sigIndex = 0; - word32 lastOidByte = 0; - - ExpectIntEQ(rfc9802_load_file(path, &buf, &bytes), TEST_SUCCESS); - if (buf == NULL) - return TEST_FAIL; - - wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); - ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); - sigIndex = cert.sigIndex; - wc_FreeDecodedCert(&cert); - - ExpectIntEQ(rfc9802_find_sig_alg_oid_last_byte(buf, (word32)bytes, - sigIndex, &lastOidByte), 0); - /* Sanity-check the fixture matches the family the caller asserted, - * so a future regenerator swapping fixtures fails loudly here - * rather than silently testing the wrong direction. */ - ExpectIntEQ((int)buf[lastOidByte], (int)expectedLastByte); - - if (lastOidByte < (word32)bytes && - buf[lastOidByte] == expectedLastByte) { - buf[lastOidByte] = patchedLastByte; - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - /* After the patch the cert's outer signatureAlgorithm and SPKI - * disagree. Verification must fail somewhere (at parse, at - * load, or at ConfirmSignature). The load is best-effort - - * some shape changes get caught there, others only at verify. */ - (void)wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, - WOLFSSL_FILETYPE_ASN1); - ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, buf, - (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - } - - XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - return EXPECT_RESULT(); -} - -/* X.509-level negative: swap the outer signatureAlgorithm OID byte so - * the cert declares XMSS where the SPKI is XMSS^MT, and vice versa. - * SigOidMatchesKeyOid must reject both directions before any crypto. */ -static int rfc9802_xmss_sig_oid_mismatch(void) -{ - EXPECT_DECLS; - /* XMSS sigOID ends 0x22; XMSS^MT sigOID ends 0x23. Patch each - * direction so the asymmetric-key path is exercised both ways - - * a regression that only stripped the check from one branch of - * SigOidMatchesKeyOid would otherwise be missed. */ - ExpectIntEQ(rfc9802_assert_oid_patch_breaks_verify( - "./certs/xmss/bc_xmss_sha2_10_256_root.der", - /* expected XMSS */ 0x22, /* patched to XMSS^MT */ 0x23), - TEST_SUCCESS); - ExpectIntEQ(rfc9802_assert_oid_patch_breaks_verify( - "./certs/xmss/bc_xmssmt_sha2_20_2_256_root.der", - /* expected XMSS^MT */ 0x23, /* patched to XMSS */ 0x22), - TEST_SUCCESS); - return EXPECT_RESULT(); -} -#endif - -/* Exercise a real CA -> leaf certificate chain, not just self-signed. - * Loads the CA as a trust anchor and verifies the leaf against it. */ -#if defined(WOLFSSL_HAVE_LMS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) -static int rfc9802_lms_chain_verify(void) -{ - EXPECT_DECLS; - byte* caBuf = NULL; - byte* leafBuf = NULL; - int caLen = 0; - int leafLen = 0; - WOLFSSL_CERT_MANAGER* cm = NULL; - - ExpectIntEQ(rfc9802_load_file("./certs/lms/bc_lms_chain_ca.der", - &caBuf, &caLen), TEST_SUCCESS); - ExpectIntEQ(rfc9802_load_file("./certs/lms/bc_lms_chain_leaf.der", - &leafBuf, &leafLen), TEST_SUCCESS); - - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - /* Only the CA is a trust anchor; the leaf is verified against it. */ - ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, caBuf, (long)caLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - - /* Without loading the CA the leaf must NOT verify. */ - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - - XFREE(leafBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(caBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - return EXPECT_RESULT(); -} -#endif - -/* Mirror of rfc9802_lms_chain_verify but for an XMSS CA -> leaf pair. */ -#if defined(WOLFSSL_HAVE_XMSS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) -static int rfc9802_xmss_chain_verify(void) -{ - EXPECT_DECLS; - byte* caBuf = NULL; - byte* leafBuf = NULL; - int caLen = 0; - int leafLen = 0; - WOLFSSL_CERT_MANAGER* cm = NULL; - - ExpectIntEQ(rfc9802_load_file("./certs/xmss/bc_xmss_chain_ca.der", - &caBuf, &caLen), TEST_SUCCESS); - ExpectIntEQ(rfc9802_load_file("./certs/xmss/bc_xmss_chain_leaf.der", - &leafBuf, &leafLen), TEST_SUCCESS); - - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, caBuf, (long)caLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - ExpectNotNull(cm = wolfSSL_CertManagerNew()); - ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, - WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); - if (cm != NULL) { - wolfSSL_CertManagerFree(cm); - cm = NULL; - } - - XFREE(leafBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(caBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); - return EXPECT_RESULT(); -} -#endif - -int test_rfc9802_lms_x509_verify(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_LMS) -#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ - !defined(WOLFSSL_NO_LMS_SHA256_256) - /* Mixed single-level LMS and multi-level HSS fixtures. The HSS - * public key carries only the top-level LMS/LM-OTS types, so - * wc_LmsKey_ImportPubRaw's auto-derive path searches the map - * by (levels, lmsType, lmOtsType). The bc_lms_native_bc_root - * fixture is generated through Bouncy Castle's stock - * JcaContentSignerBuilder("LMS") + JcaX509v3CertificateBuilder - * with no overrides; including it here is the cross-impl interop - * gate (BC's native LMS X.509 path is RFC 9802-compliant for HSS/ - * LMS, so wolfSSL must accept it end-to-end). - * - * All fixtures use the SHA-256/M32 family, so the whole block - * is gated on that family being compiled in. Truncated SHA-256/192 - * or SHAKE-only builds skip this block. */ - static const char* const lmsFiles[] = { - "./certs/lms/bc_lms_sha256_h5_w4_root.der", -#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) - "./certs/lms/bc_lms_sha256_h10_w8_root.der", -#endif -#if !defined(WOLFSSL_LMS_MAX_LEVELS) || (WOLFSSL_LMS_MAX_LEVELS >= 2) - "./certs/lms/bc_hss_L2_H5_W8_root.der", -#endif -#if !defined(WOLFSSL_LMS_MAX_LEVELS) || (WOLFSSL_LMS_MAX_LEVELS >= 3) - "./certs/lms/bc_hss_L3_H5_W4_root.der", -#endif - "./certs/lms/bc_lms_native_bc_root.der", - }; - size_t i; - for (i = 0; i < sizeof(lmsFiles) / sizeof(lmsFiles[0]); i++) { - ExpectIntEQ(rfc9802_verify_one_cert(lmsFiles[i], - HSS_LMSk, CTC_HSS_LMS), TEST_SUCCESS); - } - ExpectIntEQ(rfc9802_lms_chain_verify(), TEST_SUCCESS); -#endif /* !NO_FILESYSTEM && !NO_CERTS && !WOLFSSL_NO_LMS_SHA256_256 */ - /* Pure wolfCrypt-level negative tests don't need filesystem or cert - * support, so they run for any LMS-enabled build. */ - ExpectIntEQ(rfc9802_lms_import_negative(), TEST_SUCCESS); -#endif - return EXPECT_RESULT(); -} - -int test_rfc9802_xmss_x509_verify(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_XMSS) -#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) - static const char* const xmssFiles[] = { - "./certs/xmss/bc_xmss_sha2_10_256_root.der", - "./certs/xmss/bc_xmss_sha2_16_256_root.der", - }; - static const char* const xmssmtFiles[] = { - "./certs/xmss/bc_xmssmt_sha2_20_2_256_root.der", - "./certs/xmss/bc_xmssmt_sha2_20_4_256_root.der", - "./certs/xmss/bc_xmssmt_sha2_40_8_256_root.der", - }; - size_t i; - for (i = 0; i < sizeof(xmssFiles) / sizeof(xmssFiles[0]); i++) { - ExpectIntEQ(rfc9802_verify_one_cert(xmssFiles[i], - XMSSk, CTC_XMSS), TEST_SUCCESS); - } - for (i = 0; i < sizeof(xmssmtFiles) / sizeof(xmssmtFiles[0]); i++) { - ExpectIntEQ(rfc9802_verify_one_cert(xmssmtFiles[i], - XMSSMTk, CTC_XMSSMT), TEST_SUCCESS); - } - ExpectIntEQ(rfc9802_xmss_sig_oid_mismatch(), TEST_SUCCESS); - ExpectIntEQ(rfc9802_xmss_chain_verify(), TEST_SUCCESS); -#endif /* !NO_FILESYSTEM && !NO_CERTS */ - /* Pure wolfCrypt-level negative tests don't need filesystem or cert - * support, so they run for any XMSS-enabled build. */ - ExpectIntEQ(rfc9802_xmss_import_negative(), TEST_SUCCESS); -#endif - return EXPECT_RESULT(); -} - #if defined(WOLFSSL_SNIFFER) && defined(WOLFSSL_SNIFFER_CHAIN_INPUT) static int test_sniffer_chain_input_overflow(void) { @@ -39128,47 +33355,6 @@ static int test_DhAgree_rejects_p_minus_1(void) return EXPECT_RESULT(); } - -/* ML-DSA HashML-DSA verify must reject hashLen > WC_MAX_DIGEST_SIZE */ -static int test_mldsa_verify_hash(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_MLDSA) && \ - !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ - !defined(WOLFSSL_MLDSA_NO_VERIFY) - wc_MlDsaKey key; - WC_RNG rng; - int res = 0; - byte sig[4000]; - byte hash[4096]; /* larger than WC_MAX_DIGEST_SIZE */ - - XMEMSET(&key, 0, sizeof(key)); - XMEMSET(&rng, 0, sizeof(rng)); - XMEMSET(sig, 0x41, sizeof(sig)); - XMEMSET(hash, 'A', sizeof(hash)); - - ExpectIntEQ(wc_InitRng(&rng), 0); - ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); -#ifndef WOLFSSL_NO_ML_DSA_65 - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_65), 0); -#elif !defined(WOLFSSL_NO_ML_DSA_44) - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); -#else - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_87), 0); -#endif - ExpectIntEQ(wc_MlDsaKey_MakeKey(&key, &rng), 0); - - /* hashLen=4096 must be rejected, not overflow the stack */ - ExpectIntEQ(wc_MlDsaKey_VerifyCtxHash(&key, sig, sizeof(sig), NULL, 0, - hash, sizeof(hash), WC_HASH_TYPE_SHA256, &res), - WC_NO_ERR_TRACE(BAD_LENGTH_E)); - - wc_MlDsaKey_Free(&key); - DoExpectIntEQ(wc_FreeRng(&rng), 0); -#endif - return EXPECT_RESULT(); -} - /* Test: Ed448 must reject identity public key (0,1) */ static int test_ed448_rejects_identity_key(void) { @@ -40047,44 +34233,6 @@ static int test_pkcs7_enveloped_content_size_overflow(void) return EXPECT_RESULT(); } -/* Dilithium verify_ctx_msg must reject absurdly large msgLen */ -static int test_dilithium_hash(void) -{ - EXPECT_DECLS; -#if defined(WOLFSSL_HAVE_MLDSA) && \ - !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ - !defined(WOLFSSL_MLDSA_NO_VERIFY) - wc_MlDsaKey key; - WC_RNG rng; - int res = 0; - byte sig[4000]; - byte msg[64]; - - XMEMSET(&key, 0, sizeof(key)); - XMEMSET(&rng, 0, sizeof(rng)); - XMEMSET(sig, 0, sizeof(sig)); - XMEMSET(msg, 'A', sizeof(msg)); - - ExpectIntEQ(wc_InitRng(&rng), 0); - ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); -#ifndef WOLFSSL_NO_ML_DSA_65 - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_65), 0); -#elif !defined(WOLFSSL_NO_ML_DSA_44) - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); -#else - ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_87), 0); -#endif - ExpectIntEQ(wc_MlDsaKey_MakeKey(&key, &rng), 0); - - ExpectIntEQ(wc_MlDsaKey_VerifyCtx(&key, sig, sizeof(sig), NULL, 0, - msg, 0xFFFFFFC0, &res), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - - wc_MlDsaKey_Free(&key); - DoExpectIntEQ(wc_FreeRng(&rng), 0); -#endif - return EXPECT_RESULT(); -} - /* PKCS7 CBC must validate all padding bytes */ static int test_pkcs7_padding(void) { @@ -40283,13 +34431,8 @@ TEST_CASE testCases[] = { /* ASN */ TEST_ASN_DECLS, - /* LMS */ - TEST_DECL_GROUP("lms", test_wc_LmsKey_sign_verify), - TEST_DECL_GROUP("lms", test_wc_LmsKey_reload_cache), - - /* RFC 9802 (HSS/LMS and XMSS/XMSS^MT in X.509) */ - TEST_DECL_GROUP("lms", test_rfc9802_lms_x509_verify), - TEST_DECL_GROUP("xmss", test_rfc9802_xmss_x509_verify), + /* LMS, and RFC 9802 (HSS/LMS and XMSS/XMSS^MT in X.509) */ + TEST_LMS_XMSS_DECLS, /* PEM and DER APIs. */ TEST_DECL(test_wc_PemToDer), @@ -40323,6 +34466,7 @@ TEST_CASE testCases[] = { TEST_DECL(test_PathLenSelfIssuedAllowed), TEST_DECL(test_PathLenNoKeyUsage), TEST_DECL(test_NameConstraints_OtherName), + TEST_DECL(test_NameConstraints_DnsUriWildcard), TEST_DECL(test_ParseSerial0FixtureMatrix), TEST_DECL(test_MakeCertWithCaFalse), #ifdef WOLFSSL_CERT_SIGN_CB @@ -40454,6 +34598,8 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_X509_CRL), #ifndef NO_BIO TEST_DECL(test_wolfSSL_X509_print), + TEST_DECL(test_wolfSSL_X509_print_basic_constraints), + TEST_DECL(test_wolfSSL_X509_print_ext_key_usage), TEST_DECL(test_wolfSSL_X509_CRL_print), #endif @@ -40531,10 +34677,6 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_sigalg_info), /* Can't memory test as tcp_connect aborts. */ TEST_DECL(test_wolfSSL_d2i_SSL_SESSION_bounds_check), - TEST_DECL(test_wolfSSL_SESSION), - TEST_DECL(test_wolfSSL_SESSION_expire_downgrade), - TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb), - TEST_DECL(test_wolfSSL_ticket_keys), TEST_DECL(test_wolfSSL_sk_GENERAL_NAME), TEST_DECL(test_wolfSSL_GENERAL_NAME_print), TEST_DECL(test_wolfSSL_sk_DIST_POINT), @@ -40572,7 +34714,6 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_CRYPTO_memcmp), TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index), - TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index), TEST_DECL(test_CRYPTO_set_dynlock_xxx), TEST_DECL(test_CRYPTO_THREADID_xxx), TEST_DECL(test_ENGINE_cleanup), @@ -40685,20 +34826,8 @@ TEST_CASE testCases[] = { #ifdef HAVE_IO_TESTS_DEPENDENCIES TEST_DECL(test_wolfSSL_get_finished), - /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_CTX_add_session), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11), - /* Large number of memory allocations. */ - TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1), + TEST_DECL(test_wolfSSL_get_finished_overrun), + TEST_DECL(test_wolfSSL_get_peer_finished_overrun), #endif TEST_DECL(test_SSL_CIPHER_get_xxx), TEST_DECL(test_wolfSSL_ERR_strings), @@ -40751,12 +34880,8 @@ TEST_CASE testCases[] = { TEST_DECL(test_SetTmpEC_DHE_Sz), TEST_DECL(test_wolfSSL_CTX_get0_privatekey), #ifdef WOLFSSL_DTLS - TEST_DECL(test_wolfSSL_DtlsUpdateWindow), - TEST_DECL(test_wolfSSL_DTLS_fragment_buckets), #endif - TEST_DECL(test_wolfSSL_dtls_set_mtu), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_dtls_plaintext), #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ defined(HAVE_IO_TESTS_DEPENDENCIES) TEST_DECL(test_wolfSSL_read_write), @@ -40769,12 +34894,9 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3), TEST_DECL(test_wolfSSL_CTX_set_cipher_list), /* Can't memory test as server hangs. */ - TEST_DECL(test_wolfSSL_dtls_export), /* Uses Assert in handshake callback. */ TEST_DECL(test_wolfSSL_tls_export), #endif - TEST_DECL(test_wolfSSL_dtls_export_peers), - TEST_DECL(test_wolfSSL_dtls_import_state_extra_window_words), TEST_DECL(test_wolfSSL_SetMinVersion), TEST_DECL(test_wolfSSL_CTX_SetMinVersion), @@ -40896,19 +35018,11 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_msgCb), TEST_DECL(test_wolfSSL_either_side), - TEST_DECL(test_wolfSSL_DTLS_either_side), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_dtls_fragments), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_dtls_AEAD_limit), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_ignore_alert_before_cookie), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_dtls_bad_record), /* Uses Assert in handshake callback. */ - TEST_DECL(test_wolfSSL_dtls_stateless), - TEST_DECL(test_wolfSSL_dtls_stateless_hrr_group), - TEST_DECL(test_generate_cookie), #ifndef NO_BIO TEST_OSSL_BIO_TLS_DECLS, @@ -40935,15 +35049,11 @@ TEST_CASE testCases[] = { defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME - TEST_DECL(test_wolfSSL_dtls_stateless_resume), #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */ #ifdef HAVE_MAX_FRAGMENT - TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag), #endif /* HAVE_MAX_FRAGMENT */ #ifndef NO_RSA - TEST_DECL(test_wolfSSL_dtls_stateless2), #if !defined(NO_OLD_TLS) - TEST_DECL(test_wolfSSL_dtls_stateless_downgrade), #endif /* !defined(NO_OLD_TLS) */ #endif /* ! NO_RSA */ #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ @@ -40951,7 +35061,6 @@ TEST_CASE testCases[] = { TEST_DECL(test_wolfSSL_CTX_set_ciphersuites), TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert), TEST_DECL(test_TLS_13_ticket_different_ciphers), - TEST_DECL(test_WOLFSSL_dtls_version_alert), #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \ && defined(WOLFSSL_TLS13) && \ @@ -40970,36 +35079,17 @@ TEST_CASE testCases[] = { TEST_DECL(test_harden_no_secure_renegotiation), TEST_DECL(test_override_alt_cert_chain), TEST_DECL(test_rpk_set_xxx_cert_type), - TEST_DECL(test_dtls13_bad_epoch_ch), TEST_DECL(test_short_session_id), - TEST_DECL(test_wolfSSL_dtls13_null_cipher), /* Can't memory test as client/server hangs. */ - TEST_DECL(test_dtls_msg_from_other_peer), - TEST_DECL(test_dtls_ipv6_check), TEST_DECL(test_wolfSSL_SCR_after_resumption), - TEST_DECL(test_dtls_no_extensions), TEST_DECL(test_tls_alert_no_server_hello), TEST_DECL(test_TLSX_CA_NAMES_bad_extension), - TEST_DECL(test_dtls_1_0_hvr_downgrade), TEST_DECL(test_session_ticket_no_id), TEST_DECL(test_session_ticket_hs_update), - TEST_DECL(test_dtls_downgrade_scr_server), - TEST_DECL(test_dtls_downgrade_scr), - TEST_DECL(test_dtls_client_hello_timeout_downgrade), - TEST_DECL(test_dtls_client_hello_timeout), - TEST_DECL(test_dtls_dropped_ccs), - TEST_DECL(test_dtls_seq_num_downgrade), TEST_DECL(test_certreq_sighash_algos), TEST_DECL(test_revoked_loaded_int_cert), - TEST_DECL(test_dtls_frag_ch), - TEST_DECL(test_dtls13_frag_ch_pq), - TEST_DECL(test_dtls_empty_keyshare_with_cookie), - TEST_DECL(test_dtls_old_seq_number), - TEST_DECL(test_dtls12_missing_finished), - TEST_DECL(test_dtls13_missing_finished_client), - TEST_DECL(test_dtls13_missing_finished_server), - TEST_DECL(test_dtls13_finished_send_error_propagation), TEST_DTLS_DECLS, + TEST_DTLS13_DECLS, TEST_DECL(test_tls_multi_handshakes_one_record), TEST_DECL(test_write_dup), TEST_DECL(test_write_dup_want_write), @@ -41019,12 +35109,14 @@ TEST_CASE testCases[] = { TEST_DECL(test_ocsp_response_parsing), TEST_DECL(test_ocsp_certid_enc_dec), TEST_DECL(test_ocsp_certid_dup), + TEST_DECL(test_ocsp_resp_find_status_serial_prefix), TEST_DECL(test_ocsp_tls_cert_cb), TEST_DECL(test_ocsp_cert_unknown_crl_fallback), TEST_DECL(test_ocsp_cert_unknown_crl_fallback_nonleaf), TEST_DECL(test_tls13_nonblock_ocsp_low_mfl), TEST_DECL(test_ocsp_responder), TEST_TLS_DECLS, + TEST_SESSION_DECLS, TEST_DECL(test_wc_DhSetNamedKey), TEST_DECL(test_DhAgree_rejects_p_minus_1), TEST_DECL(test_ed448_rejects_identity_key), @@ -41043,8 +35135,6 @@ TEST_CASE testCases[] = { TEST_DECL(test_sniffer_chain_input_overflow), #endif - TEST_DECL(test_mldsa_verify_hash), - TEST_DECL(test_dilithium_hash), /* This test needs to stay at the end to clean up any caches allocated. */ TEST_DECL(test_wolfSSL_Cleanup) }; diff --git a/tests/api/include.am b/tests/api/include.am index f9d4dfe3f1..7ad64d3e63 100644 --- a/tests/api/include.am +++ b/tests/api/include.am @@ -51,13 +51,16 @@ tests_unit_test_SOURCES += tests/api/test_mldsa.c tests_unit_test_SOURCES += tests/api/test_mldsa_legacy.c tests_unit_test_SOURCES += tests/api/test_slhdsa.c tests_unit_test_SOURCES += tests/api/test_signature.c +tests_unit_test_SOURCES += tests/api/test_lms_xmss.c # TLS Protocol tests_unit_test_SOURCES += tests/api/test_dtls.c +tests_unit_test_SOURCES += tests/api/test_dtls13.c # TLS Feature tests_unit_test_SOURCES += tests/api/test_ocsp.c tests_unit_test_SOURCES += tests/api/test_evp.c tests_unit_test_SOURCES += tests/api/test_tls_ext.c tests_unit_test_SOURCES += tests/api/test_tls.c +tests_unit_test_SOURCES += tests/api/test_session.c # Certs tests_unit_test_SOURCES += tests/api/test_x509.c # ASN @@ -157,13 +160,16 @@ EXTRA_DIST += tests/api/test_mlkem.h EXTRA_DIST += tests/api/test_mldsa.h EXTRA_DIST += tests/api/test_slhdsa.h EXTRA_DIST += tests/api/test_signature.h +EXTRA_DIST += tests/api/test_lms_xmss.h EXTRA_DIST += tests/api/test_dtls.h +EXTRA_DIST += tests/api/test_dtls13.h EXTRA_DIST += tests/api/test_ocsp.h EXTRA_DIST += tests/api/test_ocsp_test_blobs.h EXTRA_DIST += tests/api/create_ocsp_test_blobs.py EXTRA_DIST += tests/api/test_evp.h EXTRA_DIST += tests/api/test_tls_ext.h EXTRA_DIST += tests/api/test_tls.h +EXTRA_DIST += tests/api/test_session.h EXTRA_DIST += tests/api/test_x509.h EXTRA_DIST += tests/api/test_asn.h EXTRA_DIST += tests/api/test_pkcs7.h diff --git a/tests/api/test_asn.c b/tests/api/test_asn.c index 23f391c938..ce4eea1487 100644 --- a/tests/api/test_asn.c +++ b/tests/api/test_asn.c @@ -31,6 +31,12 @@ #ifdef HAVE_ED25519 #include #endif +#ifdef HAVE_ED448 + #include +#endif +#ifdef HAVE_DILITHIUM + #include +#endif #if defined(WC_ENABLE_ASYM_KEY_EXPORT) && defined(HAVE_ED25519) static int test_SetAsymKeyDer_once(byte* privKey, word32 privKeySz, byte* pubKey, @@ -843,6 +849,19 @@ int test_wolfssl_local_MatchBaseName(void) "sub.domain.com", 14, ".domain.com", 11), 1); ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, "a.b.domain.com", 14, ".domain.com", 11), 1); + /* Trailing-dot normalization: absolute DNS form is equivalent. */ + ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, + "domain.com.", (int)XSTRLEN("domain.com."), + "domain.com", (int)XSTRLEN("domain.com")), 1); + ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, + "domain.com", (int)XSTRLEN("domain.com"), + "domain.com.", (int)XSTRLEN("domain.com.")), 1); + ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, + "domain.com.", (int)XSTRLEN("domain.com."), + "domain.com.", (int)XSTRLEN("domain.com.")), 1); + ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, + "sub.domain.com.", (int)XSTRLEN("sub.domain.com."), + ".domain.com.", (int)XSTRLEN(".domain.com.")), 1); /* Negative tests - should NOT match */ /* Bug #3: fakedomain.com should NOT match domain.com (no dot boundary) */ @@ -864,6 +883,10 @@ int test_wolfssl_local_MatchBaseName(void) /* Name starting with dot */ ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, ".domain.com", 11, "domain.com", 10), 0); + /* More than one trailing dot leaves an empty label after normalization. */ + ExpectIntEQ(wolfssl_local_MatchBaseName(ASN_DNS_TYPE, + "domain.com..", (int)XSTRLEN("domain.com.."), + "domain.com", (int)XSTRLEN("domain.com")), 0); /* * Tests for email type (ASN_RFC822_TYPE = 0x01) @@ -963,6 +986,210 @@ int test_wolfssl_local_MatchBaseName(void) return EXPECT_RESULT(); } +#if !defined(NO_CERTS) && !defined(NO_ASN) && !defined(IGNORE_NAME_CONSTRAINTS) +/* Convenience wrappers so the cases below read as (name, base) pairs and the + * string lengths can't drift out of sync with the literals. */ +static int dnsWildPermitted(const char* name, const char* base) +{ + return wolfssl_local_MatchDnsConstraintWildcard(name, (int)XSTRLEN(name), + base, (int)XSTRLEN(base), 1); +} +static int dnsWildExcluded(const char* name, const char* base) +{ + return wolfssl_local_MatchDnsConstraintWildcard(name, (int)XSTRLEN(name), + base, (int)XSTRLEN(base), 0); +} +static int uriNC(const char* uri, const char* base) +{ + return wolfssl_local_MatchUriNameConstraint(uri, (int)XSTRLEN(uri), base, + (int)XSTRLEN(base)); +} +#endif + +/* + * Tests label-aware matching of a wildcard DNS SAN against a name-constraint + * subtree. The permitted variant must prove containment (every expansion of + * the wildcard stays inside the subtree); the excluded variant must detect + * intersection (some expansion falls inside the subtree). A '*' never crosses + * a label boundary, so the comparison is by label from the right. + */ +int test_wolfssl_local_MatchDnsConstraintWildcard(void) +{ + EXPECT_DECLS; + +#if !defined(NO_CERTS) && !defined(NO_ASN) && !defined(IGNORE_NAME_CONSTRAINTS) + /* + * PERMITTED subtree -- containment. Accept only when EVERY expansion of + * the wildcard is inside the base subtree. + */ + + /* Wildcard is an extra label to the left of the base: always contained. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", "example.com"), 1); + ExpectIntEQ(dnsWildPermitted("*.sub.example.com", "example.com"), 1); + ExpectIntEQ(dnsWildPermitted("foo*.example.com", "example.com"), 1); + ExpectIntEQ(dnsWildPermitted("a*b.example.com", "example.com"), 1); + /* Case-insensitive on the literal tail labels. */ + ExpectIntEQ(dnsWildPermitted("*.EXAMPLE.CoM", "example.com"), 1); + /* Single-label base; the matched tail "com" is literal. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", "com"), 1); + /* Leading-dot base requires at least one label before it -- the wildcard + * label satisfies that. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", ".example.com"), 1); + ExpectIntEQ(dnsWildPermitted("*.sub.example.com", ".example.com"), 1); + /* Trailing-dot normalization: absolute DNS form is equivalent. */ + ExpectIntEQ(dnsWildPermitted("*.example.com.", "example.com"), 1); + ExpectIntEQ(dnsWildPermitted("*.example.com", "example.com."), 1); + ExpectIntEQ(dnsWildPermitted("*.example.com.", "example.com."), 1); + ExpectIntEQ(dnsWildPermitted("*.example.com.", ".example.com."), 1); + + /* Wildcard lands on a label that must equal the base: NOT provably + * contained, because the label can expand to something else. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", "foo.example.com"), 0); + ExpectIntEQ(dnsWildPermitted("*.example.com.", "foo.example.com"), 0); + ExpectIntEQ(dnsWildPermitted("*.example.com", "foo.example.com."), 0); + ExpectIntEQ(dnsWildPermitted("ex*.com", "example.com"), 0); + ExpectIntEQ(dnsWildPermitted("foo.exa*ple.com", "example.com"), 0); + /* Tail labels do not match the base at all. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", "example.org"), 0); + ExpectIntEQ(dnsWildPermitted("*.evil.com", "example.com"), 0); + /* Leading-dot base, but wildcard would have to equal an interior base + * label. */ + ExpectIntEQ(dnsWildPermitted("*.example.com", ".sub.example.com"), 0); + /* A bare '*' cannot be proven inside any multi-label-or-single subtree. */ + ExpectIntEQ(dnsWildPermitted("*", "com"), 0); + + /* + * EXCLUDED subtree -- intersection. Reject when SOME expansion of the + * wildcard falls inside the base subtree. A wildcard label is + * conservatively treated as able to match any single base label. + */ + + ExpectIntEQ(dnsWildExcluded("*.example.com", "foo.example.com"), 1); + ExpectIntEQ(dnsWildExcluded("*.example.com.", "foo.example.com"), 1); + ExpectIntEQ(dnsWildExcluded("*.example.com", "foo.example.com."), 1); + ExpectIntEQ(dnsWildExcluded("*.example.com.", "foo.example.com."), 1); + /* Wildcard adds a label on top of the excluded subtree. */ + ExpectIntEQ(dnsWildExcluded("*.example.com", "example.com"), 1); + ExpectIntEQ(dnsWildExcluded("*.example.com", "com"), 1); + ExpectIntEQ(dnsWildExcluded("*.example.com", ".example.com"), 1); + /* Wildcard in a non-left label still intersects. */ + ExpectIntEQ(dnsWildExcluded("foo.*.example.com", "bar.example.com"), 1); + /* Partial-label wildcard: conservatively excluded even though "ex*" + * cannot actually expand to "foo" (over-rejection, safe). */ + ExpectIntEQ(dnsWildExcluded("ex*.example.com", "foo.example.com"), 1); + /* A bare '*' can expand to the apex label of a single-label subtree. */ + ExpectIntEQ(dnsWildExcluded("*", "com"), 1); + + /* No intersection: literal tail labels differ from the base. */ + ExpectIntEQ(dnsWildExcluded("*.example.com", "foo.other.com"), 0); + ExpectIntEQ(dnsWildExcluded("*.other.com", "example.com"), 0); + ExpectIntEQ(dnsWildExcluded("*.example.com", "example.org"), 0); + /* Leading-dot excluded base needs a label before it; the wildcard SAN has + * no room for one, so no expansion reaches the proper subtree. */ + ExpectIntEQ(dnsWildExcluded("*.example.com", ".foo.example.com"), 0); + /* Same arity: '*' can expand to the apex label of the base, so the + * wildcard intersects (*.com can be example.com, which is excluded). */ + ExpectIntEQ(dnsWildExcluded("*.com", "example.com"), 1); + /* But a base with MORE labels than the name cannot be reached. */ + ExpectIntEQ(dnsWildExcluded("*.com", "a.example.com"), 0); + + /* + * Error / degenerate inputs (both flags reject). + */ + ExpectIntEQ(wolfssl_local_MatchDnsConstraintWildcard(NULL, 5, + "com", 3, 1), 0); + ExpectIntEQ(wolfssl_local_MatchDnsConstraintWildcard("*.com", 5, + NULL, 3, 1), 0); + ExpectIntEQ(wolfssl_local_MatchDnsConstraintWildcard("*.com", 0, + "com", 3, 1), 0); + ExpectIntEQ(wolfssl_local_MatchDnsConstraintWildcard("*.com", 5, + "com", 0, 1), 0); + /* Name beginning with a dot is invalid. */ + ExpectIntEQ(dnsWildPermitted(".x.com", "com"), 0); + ExpectIntEQ(dnsWildExcluded(".x.com", "com"), 0); + /* Base that is only dots collapses to nothing. */ + ExpectIntEQ(dnsWildExcluded("*.example.com", "."), 0); + ExpectIntEQ(dnsWildExcluded("*.example.com", ".."), 0); + /* SAN has an empty interior label ("*..com"), but only the right-most + * "com" label overlaps the base "com" -- the empty label sits outside the + * compared suffix, and '*' can expand to any label, so the matcher + * conservatively reports intersection. */ + ExpectIntEQ(dnsWildExcluded("*..com", "com"), 1); + +#endif /* !NO_CERTS && !NO_ASN && !IGNORE_NAME_CONSTRAINTS */ + + return EXPECT_RESULT(); +} + +/* + * Tests URI name-constraint matching (RFC 5280 4.2.1.10): the constraint + * applies to the host portion of the URI. A constraint that does NOT begin + * with a dot is an exact host match; one that begins with a dot matches any + * host with one or more additional leading labels (the bare host is excluded). + */ +int test_wolfssl_local_MatchUriNameConstraint(void) +{ + EXPECT_DECLS; + +#if !defined(NO_CERTS) && !defined(NO_ASN) && !defined(IGNORE_NAME_CONSTRAINTS) + /* + * Exact host match (no leading dot in the constraint). + */ + ExpectIntEQ(uriNC("https://host.com/path", "host.com"), 1); + ExpectIntEQ(uriNC("https://host.com", "host.com"), 1); + ExpectIntEQ(uriNC("https://host.com:8443/x", "host.com"), 1); + ExpectIntEQ(uriNC("ftp://user@host.com/x", "host.com"), 1); + ExpectIntEQ(uriNC("https://HOST.COM", "host.com"), 1); + ExpectIntEQ(uriNC("https://host.com?q=1", "host.com"), 1); + ExpectIntEQ(uriNC("https://host.com#frag", "host.com"), 1); + + /* The bug this fix closes: an exact-host constraint must NOT subtree-match + * a sub-host. */ + ExpectIntEQ(uriNC("https://www.host.com/", "host.com"), 0); + ExpectIntEQ(uriNC("https://a.b.host.com", "host.com"), 0); + /* Suffix that does not respect a label boundary. */ + ExpectIntEQ(uriNC("https://xhost.com", "host.com"), 0); + /* host.com is a prefix of the URI host but not the whole host. */ + ExpectIntEQ(uriNC("https://host.com.evil.com", "host.com"), 0); + ExpectIntEQ(uriNC("https://other.com", "host.com"), 0); + + /* + * Leading-dot constraint: proper subtree of hosts (apex excluded). + */ + ExpectIntEQ(uriNC("https://www.host.com/", ".host.com"), 1); + ExpectIntEQ(uriNC("https://a.b.host.com", ".host.com"), 1); + ExpectIntEQ(uriNC("https://www.host.com:443", ".host.com"), 1); + /* The bare host is NOT in the leading-dot subtree. */ + ExpectIntEQ(uriNC("https://host.com", ".host.com"), 0); + ExpectIntEQ(uriNC("https://evilhost.com", ".host.com"), 0); + + /* + * IPv6 literal host extraction ([..]) then exact match. + */ + ExpectIntEQ(uriNC("https://[2001:db8::1]:443/x", "2001:db8::1"), 1); + ExpectIntEQ(uriNC("https://[2001:db8::1]", "2001:db8::2"), 0); + + /* + * Malformed / degenerate URIs and inputs (reject). + */ + ExpectIntEQ(uriNC("no-scheme-host.com", "host.com"), 0); + ExpectIntEQ(uriNC("https://", "host.com"), 0); + /* double literal to abide source-check thinking it's a c++ comment */ + ExpectIntEQ(uriNC("https://" "/path", "host.com"), 0); + ExpectIntEQ(wolfssl_local_MatchUriNameConstraint(NULL, 10, + "host.com", 8), 0); + ExpectIntEQ(wolfssl_local_MatchUriNameConstraint("https://host.com", 16, + NULL, 8), 0); + ExpectIntEQ(wolfssl_local_MatchUriNameConstraint("https://host.com", 0, + "host.com", 8), 0); + ExpectIntEQ(wolfssl_local_MatchUriNameConstraint("https://host.com", 16, + "host.com", 0), 0); + +#endif /* !NO_CERTS && !NO_ASN && !IGNORE_NAME_CONSTRAINTS */ + + return EXPECT_RESULT(); +} + /* * Testing wc_DecodeRsaPssParams with known DER byte arrays. * Exercises both WOLFSSL_ASN_TEMPLATE and non-template paths. @@ -1363,3 +1590,440 @@ int test_wc_DecodeObjectId(void) return EXPECT_RESULT(); } + +#if defined(HAVE_PKCS8) && !defined(NO_ASN) && \ + (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \ + defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_PUBLIC_ASN)) && \ + (defined(HAVE_ED25519) || \ + (defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \ + defined(WOLFSSL_KEY_GEN)) || \ + (defined(HAVE_DILITHIUM) && \ + !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \ + !defined(WOLFSSL_DILITHIUM_NO_ASN1))) +/* Run ToTraditional_ex() on a copy of der and assert the algId, returned + * length, and the inner OCTET STRING tag/length at the start of the + * (in-place rewritten) buffer. */ +static int test_ToTraditional_ex_once(const byte* der, word32 derSz, + word32 expectAlgId, word32 expectPrivKeySz) +{ + EXPECT_DECLS; + byte* copy = NULL; + word32 algId = 0; + int ret; + + copy = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(copy); + if (copy != NULL) { + XMEMCPY(copy, der, derSz); + ret = ToTraditional_ex(copy, derSz, &algId); + ExpectIntGT(ret, 0); + ExpectIntEQ(algId, expectAlgId); + if (ret > 0) { + /* wolfSSL writes nested OCTET STRING, but accept raw bytes + * too per RFC 5958. */ + if (copy[0] == ASN_OCTET_STRING) { + if (expectPrivKeySz < 0x80) { + ExpectIntEQ(copy[1], (byte)expectPrivKeySz); + } + else if (expectPrivKeySz < 0x100) { + ExpectIntEQ(copy[1], 0x81); + ExpectIntEQ(copy[2], (byte)expectPrivKeySz); + } + else { + ExpectIntEQ(copy[1], 0x82); + ExpectIntEQ(((word32)copy[2] << 8) | copy[3], + expectPrivKeySz); + } + } + else { + ExpectIntEQ(ret, (int)expectPrivKeySz); + } + } + } + XFREE(copy, NULL, DYNAMIC_TYPE_TMP_BUFFER); + + return EXPECT_RESULT(); +} +#endif + +/* Hand crafted PKCS#8 v0 and v1 Ed25519 buffers to test parser directly. */ +int test_ToTraditional_ex_handcrafted(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS8) && defined(HAVE_ED25519) && \ + (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \ + defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_PUBLIC_ASN)) + /* Ed25519 algorithm OID body (1.3.101.112). */ + static const byte algId[] = { 43, 101, 112 }; + const word32 privKeySz = ED25519_KEY_SIZE; + const word32 pubKeySz = ED25519_PUB_KEY_SIZE; + byte der[128]; + word32 sz; + word32 outerLenIdx; + /* Filler bytes for the dummy private/public key bodies */ + const byte keyPat = 0xCC; + const byte pubPat = 0xDD; + + /* v0: SEQ { INTEGER 0, SEQ { OID }, OCTET STRING { OCTET STRING priv } } */ + sz = 0; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + outerLenIdx = sz; + der[sz++] = 0; /* outer length, filled in below */ + der[sz++] = ASN_INTEGER; + der[sz++] = 1; + der[sz++] = 0x00; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + der[sz++] = (byte)(sizeof(algId) + 2); + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(algId); + XMEMCPY(der + sz, algId, sizeof(algId)); sz += sizeof(algId); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)(privKeySz + 2); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)privKeySz; + XMEMSET(der + sz, keyPat, privKeySz); sz += privKeySz; + der[outerLenIdx] = (byte)(sz - outerLenIdx - 1); + + EXPECT_TEST(test_ToTraditional_ex_once(der, sz, ED25519k, privKeySz)); + + /* v1: same plus [1] publicKey trailer. */ + sz = 0; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + outerLenIdx = sz; + der[sz++] = 0; + der[sz++] = ASN_INTEGER; + der[sz++] = 1; + der[sz++] = 0x01; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + der[sz++] = (byte)(sizeof(algId) + 2); + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(algId); + XMEMCPY(der + sz, algId, sizeof(algId)); sz += sizeof(algId); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)(privKeySz + 2); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)privKeySz; + XMEMSET(der + sz, keyPat, privKeySz); sz += privKeySz; + /* [1] publicKey trailer */ + der[sz++] = ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_PUBKEY; + der[sz++] = (byte)pubKeySz; + XMEMSET(der + sz, pubPat, pubKeySz); sz += pubKeySz; + der[outerLenIdx] = (byte)(sz - outerLenIdx - 1); + + EXPECT_TEST(test_ToTraditional_ex_once(der, sz, ED25519k, privKeySz)); + + /* v1 without publicKey: should still accept per RFC 5958. */ + sz = 0; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + outerLenIdx = sz; + der[sz++] = 0; + der[sz++] = ASN_INTEGER; + der[sz++] = 1; + der[sz++] = 0x01; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + der[sz++] = (byte)(sizeof(algId) + 2); + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(algId); + XMEMCPY(der + sz, algId, sizeof(algId)); sz += sizeof(algId); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)(privKeySz + 2); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)privKeySz; + XMEMSET(der + sz, keyPat, privKeySz); sz += privKeySz; + der[outerLenIdx] = (byte)(sz - outerLenIdx - 1); + + EXPECT_TEST(test_ToTraditional_ex_once(der, sz, ED25519k, privKeySz)); +#endif /* HAVE_PKCS8 && HAVE_ED25519 */ + return EXPECT_RESULT(); +} + +/* Encoder/parser round trip: ToTraditional_ex() must accept both forms created + * by SetAsymKeyDer() (v0 with PrivateKeyToDer, v1 with KeyToDer). */ +int test_ToTraditional_ex_roundtrip(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS8) && \ + (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \ + defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_PUBLIC_ASN)) + +#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \ + defined(WOLFSSL_KEY_GEN) + { + ed25519_key key; + WC_RNG rng; + byte der[256]; + int derSz = 0; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectIntEQ(wc_ed25519_init(&key), 0); + ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0); + + if (EXPECT_SUCCESS()) { + ExpectIntGT(derSz = wc_Ed25519KeyToDer(&key, der, sizeof(der)), 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, ED25519k, + ED25519_KEY_SIZE)); + + derSz = wc_Ed25519PrivateKeyToDer(&key, der, sizeof(der)); + ExpectIntGT(derSz, 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, ED25519k, + ED25519_KEY_SIZE)); + } + + wc_ed25519_free(&key); + wc_FreeRng(&rng); + } +#endif /* HAVE_ED25519 */ + +#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \ + defined(WOLFSSL_KEY_GEN) + { + ed448_key key; + WC_RNG rng; + byte der[256]; + int derSz = 0; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectIntEQ(wc_ed448_init(&key), 0); + ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0); + + if (EXPECT_SUCCESS()) { + ExpectIntGT(derSz = wc_Ed448KeyToDer(&key, der, sizeof(der)), 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, ED448k, + ED448_KEY_SIZE)); + + derSz = wc_Ed448PrivateKeyToDer(&key, der, sizeof(der)); + ExpectIntGT(derSz, 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, ED448k, + ED448_KEY_SIZE)); + } + + wc_ed448_free(&key); + wc_FreeRng(&rng); + } +#endif /* HAVE_ED448 */ + +#if defined(HAVE_DILITHIUM) && \ + !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \ + !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \ + (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_NO_ML_DSA_65) || \ + !defined(WOLFSSL_NO_ML_DSA_87)) + { + static const struct { + int wcLevel; + word32 oidSum; + word32 privKeySz; + } variants[] = { + #ifndef WOLFSSL_NO_ML_DSA_44 + { WC_ML_DSA_44, ML_DSA_LEVEL2k, ML_DSA_LEVEL2_KEY_SIZE }, + #endif + #ifndef WOLFSSL_NO_ML_DSA_65 + { WC_ML_DSA_65, ML_DSA_LEVEL3k, ML_DSA_LEVEL3_KEY_SIZE }, + #endif + #ifndef WOLFSSL_NO_ML_DSA_87 + { WC_ML_DSA_87, ML_DSA_LEVEL5k, ML_DSA_LEVEL5_KEY_SIZE }, + #endif + }; + + const word32 derMaxSz = DILITHIUM_MAX_BOTH_KEY_DER_SIZE; + byte* der = NULL; + WC_RNG rng; + size_t i; + int derSz; + + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectNotNull(der = (byte*)XMALLOC(derMaxSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER)); + + for (i = 0; i < sizeof(variants) / sizeof(variants[0]); i++) { + dilithium_key key; + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_dilithium_init(&key), 0); + ExpectIntEQ(wc_dilithium_set_level(&key, variants[i].wcLevel), 0); + ExpectIntEQ(wc_dilithium_make_key(&key, &rng), 0); + + if (EXPECT_SUCCESS()) { + ExpectIntGT(derSz = wc_Dilithium_KeyToDer(&key, der, derMaxSz), + 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, + variants[i].oidSum, variants[i].privKeySz)); + + derSz = wc_Dilithium_PrivateKeyToDer(&key, der, derMaxSz); + ExpectIntGT(derSz, 0); + EXPECT_TEST(test_ToTraditional_ex_once(der, (word32)derSz, + variants[i].oidSum, variants[i].privKeySz)); + } + + wc_dilithium_free(&key); + } + + XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER); + wc_FreeRng(&rng); + } +#endif /* HAVE_DILITHIUM */ + +#endif /* HAVE_PKCS8 */ + return EXPECT_RESULT(); +} + +/* Trailing garbage that is neither [0] attributes nor [1] publicKey must + * still be rejected. */ +int test_ToTraditional_ex_negative(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS8) && defined(HAVE_ED25519) && \ + defined(HAVE_ED25519_KEY_EXPORT) && defined(WOLFSSL_KEY_GEN) && \ + defined(WOLFSSL_ASN_TEMPLATE) && \ + (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \ + defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_PUBLIC_ASN)) + ed25519_key key; + WC_RNG rng; + byte der[256]; + byte copy[256]; + int derSz = 0; + word32 algId; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectIntEQ(wc_ed25519_init(&key), 0); + ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0); + ExpectIntGT(derSz = wc_Ed25519PrivateKeyToDer(&key, der, sizeof(der)), 0); + + if (EXPECT_SUCCESS() && (derSz > 0) && + ((size_t)derSz + 1 <= sizeof(copy))) { + /* Append one byte of trailing data, grow outer SEQ length to cover. + * Ed25519 PKCS#8 outer SEQ is under 128 bytes, expect DER short form + * so the negative path is always exercised. */ + XMEMCPY(copy, der, (size_t)derSz); + ExpectTrue(copy[1] < 0x80); + if (EXPECT_SUCCESS() && copy[1] < 0x80) { + copy[1] = (byte)(copy[1] + 1); + copy[derSz] = 0x05; + algId = 0; + ExpectIntLT(ToTraditional_ex(copy, (word32)(derSz + 1), &algId), 0); + } + } + + /* publicKey trailer is permitted only when version == v1 */ + if (EXPECT_SUCCESS() && (derSz > 0) && + ((size_t)derSz + 2 + ED25519_PUB_KEY_SIZE <= sizeof(copy))) { + word32 trailerSz = 2 + ED25519_PUB_KEY_SIZE; + XMEMCPY(copy, der, (size_t)derSz); + ExpectTrue(copy[1] < (byte)(0x80 - trailerSz)); + if (EXPECT_SUCCESS() && copy[1] < (byte)(0x80 - trailerSz)) { + copy[1] = (byte)(copy[1] + trailerSz); + copy[derSz] = ASN_CONTEXT_SPECIFIC | ASN_ASYMKEY_PUBKEY; + copy[derSz + 1] = ED25519_PUB_KEY_SIZE; + XMEMSET(copy + derSz + 2, 0xDD, ED25519_PUB_KEY_SIZE); + algId = 0; + ExpectIntLT(ToTraditional_ex(copy, + (word32)(derSz + (int)trailerSz), &algId), 0); + } + } + + /* v1 buffer (with publicKey) plus extra trailing garbage. */ + ExpectIntGT(derSz = wc_Ed25519KeyToDer(&key, der, sizeof(der)), 0); + if (EXPECT_SUCCESS() && (derSz > 0) && + ((size_t)derSz + 1 <= sizeof(copy))) { + XMEMCPY(copy, der, (size_t)derSz); + ExpectTrue(copy[1] < 0x80); + if (EXPECT_SUCCESS() && copy[1] < 0x80) { + copy[1] = (byte)(copy[1] + 1); + copy[derSz] = 0x05; + algId = 0; + ExpectIntLT(ToTraditional_ex(copy, (word32)(derSz + 1), &algId), 0); + } + } + + wc_ed25519_free(&key); + wc_FreeRng(&rng); +#endif + return EXPECT_RESULT(); +} + +/* ML-DSA AlgorithmIdentifier has no parameters per FIPS 204. Verify + * ToTraditional_ex() rejects a PKCS#8 whose algoSeq carries trailing NULL + * or OBJECT_ID parameters. Template parser only (legacy is lenient). */ +int test_ToTraditional_ex_mldsa_bad_params(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS8) && defined(HAVE_DILITHIUM) && \ + defined(WOLFSSL_ASN_TEMPLATE) && \ + (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \ + defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_PUBLIC_ASN)) + /* ML-DSA-65 OID body: 2.16.840.1.101.3.4.3.18 */ + static const byte mldsaOid[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, + 0x04, 0x03, 0x12 }; + /* Single-arc OID body, used only to occupy the OBJECT_ID slot. */ + static const byte extraOid[] = { 0x01 }; + byte der[64]; + byte copy[64]; + word32 sz; + word32 outerLenIdx; + word32 algId; + const word32 privKeySz = 4; + const byte privBody = 0xAA; + + /* Bad case, algoSeq = { OID, NULL } */ + sz = 0; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + outerLenIdx = sz; + der[sz++] = 0; /* outer length, filled in below */ + der[sz++] = ASN_INTEGER; + der[sz++] = 1; + der[sz++] = 0x00; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + der[sz++] = (byte)(sizeof(mldsaOid) + 2 + 2); + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(mldsaOid); + XMEMCPY(der + sz, mldsaOid, sizeof(mldsaOid)); sz += sizeof(mldsaOid); + /* Disallowed, NULL parameter after the ML-DSA OID. */ + der[sz++] = ASN_TAG_NULL; + der[sz++] = 0; + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)(privKeySz + 2); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)privKeySz; + XMEMSET(der + sz, privBody, privKeySz); sz += privKeySz; + der[outerLenIdx] = (byte)(sz - outerLenIdx - 1); + + XMEMCPY(copy, der, sz); + algId = 0; + ExpectIntLT(ToTraditional_ex(copy, sz, &algId), 0); + + /* Bad case, algoSeq = { OID, OBJECT_ID } */ + sz = 0; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + outerLenIdx = sz; + der[sz++] = 0; + der[sz++] = ASN_INTEGER; + der[sz++] = 1; + der[sz++] = 0x00; + der[sz++] = ASN_SEQUENCE | ASN_CONSTRUCTED; + der[sz++] = (byte)(sizeof(mldsaOid) + 2 + sizeof(extraOid) + 2); + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(mldsaOid); + XMEMCPY(der + sz, mldsaOid, sizeof(mldsaOid)); sz += sizeof(mldsaOid); + /* Disallowed, OBJECT_ID parameter after the ML-DSA OID. */ + der[sz++] = ASN_OBJECT_ID; + der[sz++] = (byte)sizeof(extraOid); + XMEMCPY(der + sz, extraOid, sizeof(extraOid)); sz += sizeof(extraOid); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)(privKeySz + 2); + der[sz++] = ASN_OCTET_STRING; + der[sz++] = (byte)privKeySz; + XMEMSET(der + sz, privBody, privKeySz); sz += privKeySz; + der[outerLenIdx] = (byte)(sz - outerLenIdx - 1); + + XMEMCPY(copy, der, sz); + algId = 0; + ExpectIntLT(ToTraditional_ex(copy, sz, &algId), 0); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_asn.h b/tests/api/test_asn.h index 598c255f6b..2654e3e858 100644 --- a/tests/api/test_asn.h +++ b/tests/api/test_asn.h @@ -30,10 +30,16 @@ int test_DecodeAsymKey_negative(void); int test_GetSetShortInt(void); int test_wc_IndexSequenceOf(void); int test_wolfssl_local_MatchBaseName(void); +int test_wolfssl_local_MatchDnsConstraintWildcard(void); +int test_wolfssl_local_MatchUriNameConstraint(void); int test_wc_DecodeRsaPssParams(void); int test_SerialNumber0_RootCA(void); int test_DecodeAltNames_length_underflow(void); int test_wc_DecodeObjectId(void); +int test_ToTraditional_ex_handcrafted(void); +int test_ToTraditional_ex_roundtrip(void); +int test_ToTraditional_ex_negative(void); +int test_ToTraditional_ex_mldsa_bad_params(void); #define TEST_ASN_DECLS \ TEST_DECL_GROUP("asn", test_SetAsymKeyDer), \ @@ -42,9 +48,15 @@ int test_wc_DecodeObjectId(void); TEST_DECL_GROUP("asn", test_GetSetShortInt), \ TEST_DECL_GROUP("asn", test_wc_IndexSequenceOf), \ TEST_DECL_GROUP("asn", test_wolfssl_local_MatchBaseName), \ + TEST_DECL_GROUP("asn", test_wolfssl_local_MatchDnsConstraintWildcard), \ + TEST_DECL_GROUP("asn", test_wolfssl_local_MatchUriNameConstraint), \ TEST_DECL_GROUP("asn", test_wc_DecodeRsaPssParams), \ TEST_DECL_GROUP("asn", test_SerialNumber0_RootCA), \ TEST_DECL_GROUP("asn", test_DecodeAltNames_length_underflow), \ - TEST_DECL_GROUP("asn", test_wc_DecodeObjectId) + TEST_DECL_GROUP("asn", test_wc_DecodeObjectId), \ + TEST_DECL_GROUP("asn", test_ToTraditional_ex_handcrafted), \ + TEST_DECL_GROUP("asn", test_ToTraditional_ex_roundtrip), \ + TEST_DECL_GROUP("asn", test_ToTraditional_ex_negative), \ + TEST_DECL_GROUP("asn", test_ToTraditional_ex_mldsa_bad_params) #endif /* WOLFCRYPT_TEST_ASN_H */ diff --git a/tests/api/test_certman.c b/tests/api/test_certman.c index f611010565..1c73e64a73 100644 --- a/tests/api/test_certman.c +++ b/tests/api/test_certman.c @@ -2109,6 +2109,70 @@ int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void) return EXPECT_RESULT(); } +int test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match(void) +{ + EXPECT_DECLS; +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \ + defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \ + defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \ + !defined(NO_SHA256) + /* RFC 6125 Sec. 6.4 / RFC 9525 Sec. 6.3: DNS-ID reference identifiers + * must be matched only against dNSName SANs, not uniformResourceIdentifier. + * wolfSSL_X509_add_altname() is used to attach a bare-hostname URI SAN + * (the misissue shape that can reach altNames when certificate parsing is + * built without strict URI checks). URI SAN presence still suppresses CN + * fallback per RFC 6125 Sec. 6.4.4. */ + WOLFSSL_EVP_PKEY *priv = NULL; + WOLFSSL_X509_NAME* name = NULL; + const char* server_cert = "./certs/test/server-goodcn.pem"; + const char hostName[] = "cnhost.local"; + const char uriSan[] = "http://cnhost.local"; + byte *pt; + WOLFSSL_X509 *leafUri = NULL; + WOLFSSL_X509 *leafUriDns = NULL; + + pt = (byte*)server_key_der_2048; + ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, + (const unsigned char**)&pt, sizeof_server_key_der_2048)); + + ExpectNotNull(leafUri = wolfSSL_X509_load_certificate_file(server_cert, + WOLFSSL_FILETYPE_PEM)); + ExpectNotNull(name = X509_NAME_new()); + ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUri, name), WOLFSSL_SUCCESS); + X509_NAME_free(name); + name = NULL; + ExpectIntEQ(wolfSSL_X509_add_altname(leafUri, uriSan, ASN_URI_TYPE), + WOLFSSL_SUCCESS); + ExpectIntGT(wolfSSL_X509_sign(leafUri, priv, EVP_sha256()), 0); + ExpectIntEQ(wolfSSL_X509_check_host(leafUri, hostName, XSTRLEN(hostName), + 0, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + + ExpectNotNull(leafUriDns = wolfSSL_X509_load_certificate_file(server_cert, + WOLFSSL_FILETYPE_PEM)); + ExpectNotNull(name = X509_NAME_new()); + ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8, + (byte*)hostName, (int)XSTRLEN(hostName), -1, 0), SSL_SUCCESS); + ExpectIntEQ(wolfSSL_X509_set_subject_name(leafUriDns, name), + WOLFSSL_SUCCESS); + X509_NAME_free(name); + name = NULL; + ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, uriSan, ASN_URI_TYPE), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_X509_add_altname(leafUriDns, hostName, ASN_DNS_TYPE), + WOLFSSL_SUCCESS); + ExpectIntGT(wolfSSL_X509_sign(leafUriDns, priv, EVP_sha256()), 0); + ExpectIntEQ(wolfSSL_X509_check_host(leafUriDns, hostName, + XSTRLEN(hostName), 0, NULL), WOLFSSL_SUCCESS); + + wolfSSL_X509_free(leafUri); + wolfSSL_X509_free(leafUriDns); + wolfSSL_EVP_PKEY_free(priv); +#endif + return EXPECT_RESULT(); +} + int test_wolfSSL_CertManagerCRL(void) { EXPECT_DECLS; diff --git a/tests/api/test_certman.h b/tests/api/test_certman.h index 52bef8e1aa..173c0f7e30 100644 --- a/tests/api/test_certman.h +++ b/tests/api/test_certman.h @@ -40,6 +40,7 @@ int test_wolfSSL_CertManagerNameConstraint_IP_SAN(void); int test_wolfSSL_CertManagerNameConstraint_RID_SAN(void); int test_wolfSSL_X509_get_ext_d2i_RID_SAN(void); int test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback(void); +int test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match(void); int test_wolfSSL_CertManagerCRL(void); int test_wolfSSL_CRL_reason_extensions_cleanup(void); int test_wolfSSL_CRL_static_revoked_list(void); @@ -70,6 +71,8 @@ int test_wolfSSL_X509_V_ERR_strings(void); TEST_DECL_GROUP("certman", test_wolfSSL_X509_get_ext_d2i_RID_SAN), \ TEST_DECL_GROUP("certman", \ test_wolfSSL_X509_check_host_IP_only_SAN_CN_fallback), \ + TEST_DECL_GROUP("certman", \ + test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match), \ TEST_DECL_GROUP("certman", test_wolfSSL_CertManagerCRL), \ TEST_DECL_GROUP("certman", test_wolfSSL_CRL_reason_extensions_cleanup), \ TEST_DECL_GROUP("certman", test_wolfSSL_CRL_static_revoked_list), \ diff --git a/tests/api/test_curve25519.c b/tests/api/test_curve25519.c index 4108ad0d34..33c51253f7 100644 --- a/tests/api/test_curve25519.c +++ b/tests/api/test_curve25519.c @@ -398,6 +398,99 @@ int test_wc_curve25519_shared_secret_zero_check(void) return EXPECT_RESULT(); } /* END test_wc_curve25519_shared_secret_zero_check */ +/* + * Known-answer tests for wc_curve25519_shared_secret_ex. + * + * Both vectors share one private scalar and produce a shared secret that is a + * small canonical value (9 and 16, little-endian). Because the result is close + * to a multiple of the field prime, these exercise the final modular reduction + * of the X25519 computation: a result that was only reduced mod 2^256 (or left + * in [p, 2^255)) instead of fully reduced mod 2^255-19 would not match. + * All values are 32-byte little-endian encodings per RFC 7748. + */ +int test_wc_curve25519_shared_secret_ex_kat(void) +{ + EXPECT_DECLS; +#if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_IMPORT) + /* Private scalar shared by both vectors. */ + static const byte kPriv[CURVE25519_KEYSIZE] = { + 0x60, 0xa3, 0xa4, 0xf1, 0x30, 0xb9, 0x8a, 0x5b, + 0xe4, 0xb1, 0xce, 0xdb, 0x7c, 0xb8, 0x55, 0x84, + 0xa3, 0x52, 0x0e, 0x14, 0x2d, 0x47, 0x4d, 0xc9, + 0xcc, 0xb9, 0x09, 0xa0, 0x73, 0xa9, 0x76, 0x7f + }; + /* Vector 1 public value, expected shared secret == 9. */ + static const byte kPub1[CURVE25519_KEYSIZE] = { + 0x3b, 0x18, 0xdf, 0x1e, 0x50, 0xb8, 0x99, 0xeb, + 0xd5, 0x88, 0xc3, 0x16, 0x1c, 0xbd, 0x3b, 0xf9, + 0x8e, 0xbc, 0xc2, 0xc1, 0xf7, 0xdf, 0x53, 0xb8, + 0x11, 0xbd, 0x0e, 0x91, 0xb4, 0xd5, 0x15, 0x3d + }; + static const byte kExpected1[CURVE25519_KEYSIZE] = { + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + /* Vector 2 public value, expected shared secret == 16. */ + static const byte kPub2[CURVE25519_KEYSIZE] = { + 0xca, 0xb6, 0xf9, 0xe7, 0xd8, 0xce, 0x00, 0xdf, + 0xce, 0xa9, 0xbb, 0xd8, 0xf0, 0x69, 0xef, 0x7f, + 0xb2, 0xac, 0x50, 0x4a, 0xbf, 0x83, 0xb8, 0x7d, + 0xb6, 0x01, 0xb5, 0xae, 0x0a, 0x7f, 0x76, 0x15 + }; + static const byte kExpected2[CURVE25519_KEYSIZE] = { + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + /* Table-driven so both vectors run through the identical code path. */ + struct { + const byte* pub; + const byte* expected; + } vec[2]; + curve25519_key private_key; + curve25519_key public_key; + WC_RNG rng; + byte out[CURVE25519_KEYSIZE]; + word32 outLen; + int i; + + vec[0].pub = kPub1; vec[0].expected = kExpected1; + vec[1].pub = kPub2; vec[1].expected = kExpected2; + + XMEMSET(&rng, 0, sizeof(WC_RNG)); + ExpectIntEQ(wc_InitRng(&rng), 0); + + for (i = 0; i < 2; i++) { + XMEMSET(&private_key, 0, sizeof(private_key)); + XMEMSET(&public_key, 0, sizeof(public_key)); + ExpectIntEQ(wc_curve25519_init(&private_key), 0); + ExpectIntEQ(wc_curve25519_init(&public_key), 0); + #ifdef WOLFSSL_CURVE25519_BLINDING + ExpectIntEQ(wc_curve25519_set_rng(&private_key, &rng), 0); + #endif + ExpectIntEQ(wc_curve25519_import_private_ex(kPriv, sizeof(kPriv), + &private_key, EC25519_LITTLE_ENDIAN), 0); + ExpectIntEQ(wc_curve25519_import_public_ex(vec[i].pub, + CURVE25519_KEYSIZE, &public_key, EC25519_LITTLE_ENDIAN), 0); + + outLen = sizeof(out); + ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, + out, &outLen, EC25519_LITTLE_ENDIAN), 0); + ExpectIntEQ(outLen, CURVE25519_KEYSIZE); + ExpectIntEQ(XMEMCMP(out, vec[i].expected, CURVE25519_KEYSIZE), 0); + + wc_curve25519_free(&private_key); + wc_curve25519_free(&public_key); + } + + DoExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + return EXPECT_RESULT(); +} /* END test_wc_curve25519_shared_secret_ex_kat */ + /* * Testing wc_curve25519_make_pub */ diff --git a/tests/api/test_curve25519.h b/tests/api/test_curve25519.h index c65ccb34f8..d6b749bed6 100644 --- a/tests/api/test_curve25519.h +++ b/tests/api/test_curve25519.h @@ -31,6 +31,7 @@ int test_wc_curve25519_export_key_raw_ex(void); int test_wc_curve25519_make_key(void); int test_wc_curve25519_shared_secret_ex(void); int test_wc_curve25519_shared_secret_zero_check(void); +int test_wc_curve25519_shared_secret_ex_kat(void); int test_wc_curve25519_make_pub(void); int test_wc_curve25519_export_public_ex(void); int test_wc_curve25519_export_private_raw_ex(void); @@ -47,6 +48,7 @@ int test_wc_Curve25519KeyToDer_oneasymkey_version(void); TEST_DECL_GROUP("curve25519", test_wc_curve25519_make_key), \ TEST_DECL_GROUP("curve25519", test_wc_curve25519_shared_secret_ex), \ TEST_DECL_GROUP("curve25519", test_wc_curve25519_shared_secret_zero_check),\ + TEST_DECL_GROUP("curve25519", test_wc_curve25519_shared_secret_ex_kat), \ TEST_DECL_GROUP("curve25519", test_wc_curve25519_make_pub), \ TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_public_ex), \ TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_private_raw_ex), \ diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index d72a9395c5..572dda6c94 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -32,8 +32,19 @@ #include #include +#include #include +/* Cast used to make send()/recv() buffer arguments portable between + * Windows (char*) and POSIX (void*). Mirrors the private macro in + * tests/api.c so the DTLS plaintext/fragments tests moved out of api.c + * still build here. */ +#ifdef USE_WINDOWS_API + #define MESSAGE_TYPE_CAST char* +#else + #define MESSAGE_TYPE_CAST void* +#endif + int test_dtls12_basic_connection_id(void) { EXPECT_DECLS; @@ -408,165 +419,6 @@ loop_exit: return EXPECT_RESULT(); } -int test_dtls13_basic_connection_id(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && defined(WOLFSSL_DTLS_CID) - unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - unsigned char readBuf[50]; - void * cid = NULL; - const char* params[] = { -#ifndef NO_SHA256 -#ifdef WOLFSSL_AES_128 -#ifdef HAVE_AESGCM - "TLS13-AES128-GCM-SHA256", -#endif -#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) - "TLS13-CHACHA20-POLY1305-SHA256", -#endif -#ifdef HAVE_AESCCM - "TLS13-AES128-CCM-8-SHA256", - "TLS13-AES128-CCM-SHA256", -#endif -#endif -#ifdef HAVE_NULL_CIPHER - "TLS13-SHA256-SHA256", -#endif -#endif - }; - size_t i; - - /* We check if the side included the CID in their output */ -#define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \ - client_cid, sizeof(client_cid)) -#define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \ - server_cid, sizeof(server_cid)) -#define RESET_CID(cid) if ((cid) != NULL) { \ - ((char*)(cid))[0] = -1; \ - } - - - printf("\n"); - for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) { - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - - printf("Testing %s ... ", params[i]); - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS); - - ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1); - ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)), - 1); - ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1); - ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)), - 1); - - /* CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectNull(CLIENT_CID()); - /* HRR */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectNull(SERVER_CID()); - /* CH2 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectNull(CLIENT_CID()); - /* Server first flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectNotNull(SERVER_CID()); - /* Client second flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectNotNull(CLIENT_CID()); - /* Server process flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); - /* Client process flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); - - /* Write some data */ - ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])), - XSTRLEN(params[i])); - ExpectNotNull(CLIENT_CID()); - ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])), - XSTRLEN(params[i])); - ExpectNotNull(SERVER_CID()); - /* Read the data */ - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), - XSTRLEN(params[i])); - ExpectStrEQ(readBuf, params[i]); - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), - XSTRLEN(params[i])); - ExpectStrEQ(readBuf, params[i]); - /* Write short data */ - ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1); - ExpectNotNull(CLIENT_CID()); - ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1); - ExpectNotNull(SERVER_CID()); - /* Read the short data */ - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1); - ExpectIntEQ(readBuf[0], params[i][0]); - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1); - ExpectIntEQ(readBuf[0], params[i][0]); - /* Write some data but with wrong CID */ - ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])), - XSTRLEN(params[i])); - /* Reset client cid. */ - ExpectNotNull(cid = CLIENT_CID()); - RESET_CID(cid); - ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])), - XSTRLEN(params[i])); - /* Reset server cid. */ - ExpectNotNull(cid = SERVER_CID()); - RESET_CID(cid); - /* Try to read the data but it shouldn't be there */ - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Close connection */ - ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE); - ExpectNotNull(CLIENT_CID()); - ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE); - ExpectNotNull(SERVER_CID()); - ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1); - ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1); - - if (EXPECT_SUCCESS()) - printf("ok\n"); - else - printf("failed\n"); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); - } - -#undef CLIENT_CID -#undef SERVER_CID -#undef RESET_CID - -#endif - return EXPECT_RESULT(); -} /** Test DTLS 1.3 behavior when server hits WANT_WRITE during HRR * The test sets up a DTLS 1.3 connection where the server is forced to @@ -574,74 +426,7 @@ int test_dtls13_basic_connection_id(void) * application data is exchanged in both directions to verify the connection * works as expected. */ -int test_dtls13_hrr_want_write(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - const char msg[] = "hello"; - const int msgLen = sizeof(msg); - struct test_memio_ctx test_ctx; - char readBuf[sizeof(msg)]; - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), - 0); - - /* Client sends first ClientHello */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* Force server to hit WANT_WRITE when producing the HRR */ - test_memio_simulate_want_write(&test_ctx, 0, 1); - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE); - - /* Allow the server to flush the HRR and proceed */ - test_memio_simulate_want_write(&test_ctx, 0, 0); - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Resume the DTLS 1.3 handshake */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - /* Verify post-handshake application data in both directions */ - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) -struct test_dtls13_wwrite_ctx { - int want_write; - struct test_memio_ctx *text_ctx; -}; -static int test_dtls13_want_write_send_cb(WOLFSSL *ssl, char *data, int sz, void *ctx) -{ - struct test_dtls13_wwrite_ctx *wwctx = (struct test_dtls13_wwrite_ctx *)ctx; - wwctx->want_write = !wwctx->want_write; - if (wwctx->want_write) { - return WOLFSSL_CBIO_ERR_WANT_WRITE; - } - return test_memio_write_cb(ssl, data, sz, wwctx->text_ctx); -} -#endif /** Test DTLS 1.3 behavior when every other write returns WANT_WRITE * The test sets up a DTLS 1.3 connection where both client and server * alternate between WANT_WRITE and successful writes. After the handshake, @@ -651,82 +436,6 @@ static int test_dtls13_want_write_send_cb(WOLFSSL *ssl, char *data, int sz, void * Data exchanged after the handshake is also tested with simulated WANT_WRITE * conditions to ensure the connection remains functional. */ -int test_dtls13_every_write_want_write(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char msg[] = "want-write"; - const int msgLen = sizeof(msg); - char readBuf[sizeof(msg)]; - struct test_dtls13_wwrite_ctx wwctx_c; - struct test_dtls13_wwrite_ctx wwctx_s; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), - 0); - - wwctx_c.want_write = 0; - wwctx_c.text_ctx = &test_ctx; - wolfSSL_SetIOWriteCtx(ssl_c, &wwctx_c); - wolfSSL_SSLSetIOSend(ssl_c, test_dtls13_want_write_send_cb); - wwctx_s.want_write = 0; - wwctx_s.text_ctx = &test_ctx; - wolfSSL_SetIOWriteCtx(ssl_s, &wwctx_s); - wolfSSL_SSLSetIOSend(ssl_s, test_dtls13_want_write_send_cb); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 20, NULL), 0); - - ExpectTrue(wolfSSL_is_init_finished(ssl_c)); - ExpectTrue(wolfSSL_is_init_finished(ssl_s)); - - test_memio_simulate_want_write(&test_ctx, 0, 0); - test_memio_simulate_want_write(&test_ctx, 1, 0); - - wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx); - wolfSSL_SSLSetIOSend(ssl_c, test_memio_write_cb); - wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx); - wolfSSL_SSLSetIOSend(ssl_s, test_memio_write_cb); - - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - test_memio_simulate_want_write(&test_ctx, 0, 1); - XMEMSET(readBuf, 0, sizeof(readBuf)); - ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE); - test_memio_simulate_want_write(&test_ctx, 0, 0); - ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - XMEMSET(readBuf, 0, sizeof(readBuf)); - test_memio_simulate_want_write(&test_ctx, 1, 1); - ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_WRITE); - test_memio_simulate_want_write(&test_ctx, 1, 0); - ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); - ExpectStrEQ(readBuf, msg); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} int test_wolfSSL_dtls_cid_parse(void) { @@ -809,253 +518,9 @@ int test_wolfSSL_dtls_set_pending_peer(void) return EXPECT_RESULT(); } -int test_dtls13_epochs(void) { - EXPECT_DECLS; -#if defined(WOLFSSL_DTLS13) && !defined(NO_WOLFSSL_CLIENT) - WOLFSSL_CTX* ctx = NULL; - WOLFSSL* ssl = NULL; - byte input[20]; - word32 inOutIdx = 0; - XMEMSET(input, 0, sizeof(input)); - ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_3_client_method())); - ExpectNotNull(ssl = wolfSSL_new(ctx)); - /* Some manual setup to enter the epoch check */ - ExpectTrue(ssl->options.tls1_3 = 1); - inOutIdx = 0; - if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x0); - ExpectIntEQ(DoApplicationData(ssl, input, &inOutIdx, 0), SANITY_MSG_E); - inOutIdx = 0; - if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x2); - ExpectIntEQ(DoApplicationData(ssl, input, &inOutIdx, 0), SANITY_MSG_E); - - if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x1); - ExpectIntEQ(Dtls13CheckEpoch(ssl, client_hello), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, server_hello), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_verify_request), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_retry_request), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_request), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, encrypted_extensions), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, server_key_exchange), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, server_hello_done), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, client_key_exchange), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_request), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_verify), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, finished), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_status), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, change_cipher_hs), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, key_update), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, session_ticket), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, end_of_early_data), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, message_hash), SANITY_MSG_E); - ExpectIntEQ(Dtls13CheckEpoch(ssl, no_shake), SANITY_MSG_E); - - wolfSSL_CTX_free(ctx); - wolfSSL_free(ssl); -#endif - return EXPECT_RESULT(); -} - -int test_dtls13_ack_order(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - unsigned char readBuf[50]; - word32 length = 0; - /* struct { - * uint64 epoch; - * uint64 sequence_number; - * } RecordNumber; - * Big endian */ - static const unsigned char expected_output[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, - }; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - /* Get a populated DTLS object */ - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - /* Clear the buffer of any extra messages */ - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_ctx.c_len, 0); - ExpectIntEQ(test_ctx.s_len, 0); - - /* Add seen records */ - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 2)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 0)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 1)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 4)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 0)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 6)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 6)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 1)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 2)), 0); - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 2)), 0); - ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, - ssl_c->dtls13Rtx.seenRecordsCount, &length), 0); - - /* must zero the span reserved for the header to avoid read of uninited - * data. - */ - XMEMSET(ssl_c->buffers.outputBuffer.buffer, 0, - 5 /* DTLS13_UNIFIED_HEADER_SIZE */); - /* N * RecordNumber + 2 extra bytes for length */ - ExpectIntEQ(length, sizeof(expected_output) + 2); - ExpectNotNull(mymemmem(ssl_c->buffers.outputBuffer.buffer, - ssl_c->buffers.outputBuffer.bufferSize, expected_output, - sizeof(expected_output))); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -int test_dtls13_ack_overflow(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - unsigned char readBuf[50]; - word32 length = 0; - int i; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Edge case 1: one below limit - all inserts must succeed */ - for (i = 0; i < DTLS13_ACK_MAX_RECORDS - 1; i++) { - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), - w64From32(0, (word32)i)), 0); - } - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS - 1); - - /* Edge case 2: insert the last allowed record - must succeed */ - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), - w64From32(0, (word32)(DTLS13_ACK_MAX_RECORDS - 1))), 0); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS); - - /* Writing a full-but-valid list must succeed */ - ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, - ssl_c->dtls13Rtx.seenRecordsCount, &length), 0); - - /* Edge case 3: one over limit - must be silently dropped */ - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), - w64From32(0, (word32)DTLS13_ACK_MAX_RECORDS)), 0); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS); - - /* Bypass the insert guard to force the list one element over the limit, - * then verify Dtls13WriteAckMessage errors out instead of overflowing */ - ssl_c->dtls13Rtx.seenRecordsCount = 0; - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 1), - w64From32(0, (word32)DTLS13_ACK_MAX_RECORDS)), 0); - ssl_c->dtls13Rtx.seenRecordsCount = (word16)(DTLS13_ACK_MAX_RECORDS + 1); - ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, - ssl_c->dtls13Rtx.seenRecordsCount, &length), BUFFER_E); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -int test_dtls13_ack_dup_write_counter(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ - && defined(HAVE_WRITE_DUP) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - WOLFSSL *ssl_c2 = NULL; - struct test_memio_ctx test_ctx; - unsigned char readBuf[50]; - int i; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - /* Drain any post-handshake messages */ - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Split ssl_c: ssl_c becomes READ_DUP_SIDE, ssl_c2 becomes WRITE_DUP_SIDE */ - ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c)); - - /* Cycle 1: add records, trigger handoff, verify counter is reset to 0 */ - for (i = 0; i < 5; i++) - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), - w64From32(0, (word32)i)), 0); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 5); - ssl_c->dtls13Rtx.sendAcks = 1; - ExpectIntEQ(Dtls13DoScheduledWork(ssl_c), 0); - /* seenRecords ownership was transferred to dupWrite->sendAckList; - * seenRecordsCount must be reset to 0, not left at 5. */ - ExpectNull(ssl_c->dtls13Rtx.seenRecords); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 0); - - /* Cycle 2 (different epoch to avoid the dup-filter): verify the counter - * did not accumulate across the previous transfer. Without the fix, - * seenRecordsCount would now be 10 after this second batch. */ - for (i = 0; i < 5; i++) - ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 4), - w64From32(0, (word32)i)), 0); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 5); - ssl_c->dtls13Rtx.sendAcks = 1; - ExpectIntEQ(Dtls13DoScheduledWork(ssl_c), 0); - ExpectNull(ssl_c->dtls13Rtx.seenRecords); - ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 0); - - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_c2); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} int test_dtls_version_checking(void) { @@ -1836,225 +1301,8 @@ int test_dtls_rtx_across_epoch_change(void) return EXPECT_RESULT(); } -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) -static int test_dtls13_get_message_seq(const char* msg, int msgSz, - word16* msgSeq) -{ - int hsOff = DTLS_RECORD_HEADER_SZ; - if (msg == NULL || msgSeq == NULL || - msgSz < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ) { - return BAD_FUNC_ARG; - } - *msgSeq = ((word16)(byte)msg[hsOff + 4] << 8) | - (word16)(byte)msg[hsOff + 5]; - - return WOLFSSL_SUCCESS; -} -#endif - -int test_dtls13_ch2_rtx_no_ch1(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - const char* msg = NULL; - int msgSz = 0; - word16 ch1Seq = 0; - int i; - int foundCh1Seq = 0; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), - 0); - - /* To force HRR */ - ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); - - /* CH1 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_memio_get_message(&test_ctx, 0, &msg, &msgSz, 0), 0); - ExpectIntGE(msgSz, DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ); - ExpectIntEQ(test_dtls13_get_message_seq(msg, msgSz, &ch1Seq), - WOLFSSL_SUCCESS); - - /* HRR */ - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntGT(test_ctx.c_msg_count, 0); - - /* CH2 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntGT(test_ctx.s_msg_count, 0); - - /* Drop CH2 and trigger the client retransmission timeout. */ - test_memio_clear_buffer(&test_ctx, 0); - if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - ExpectIntGT(test_ctx.s_msg_count, 0); - - for (i = 0; i < test_ctx.s_msg_count && EXPECT_SUCCESS(); i++) { - int hsOff = DTLS_RECORD_HEADER_SZ; - word16 msgSeq = 0; - - ExpectIntEQ(test_memio_get_message(&test_ctx, 0, &msg, &msgSz, i), 0); - /* memio stores one DTLS record per message in this handshake path. */ - if (msgSz >= DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ && - (byte)msg[0] == handshake && msg[hsOff] == client_hello) { - ExpectIntEQ(test_dtls13_get_message_seq(msg, msgSz, &msgSeq), - WOLFSSL_SUCCESS); - if (msgSeq == ch1Seq) - foundCh1Seq = 1; - } - } - - ExpectIntEQ(foundCh1Seq, 0); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} - -int test_dtls13_frag_ch2_with_ch1_rtx(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) && \ - defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ - (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - char hrr[TEST_MEMIO_BUF_SZ]; - int hrrSz = (int)sizeof(hrr); - char ch1Rtx[TEST_MEMIO_BUF_SZ]; - int ch1RtxSz = (int)sizeof(ch1Rtx); - char ch2[TEST_MEMIO_BUF_SZ]; - int ch2Sz = 0; - int ch2MsgCount = 0; - int ch2MsgSizes[TEST_MEMIO_MAX_MSGS] = {0}; - /* The DTLS record sequence number occupies the last 8 bytes of the - * record header. */ - int recordSeqOff = DTLS_RECORD_HEADER_SZ - 8; - int ch2Seq = 0; - int ch1RtxSeq = 0; - int off; - int i; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), - 0); - - /* To force HRR */ - ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); - - /* CH1 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* HRR */ - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrr, &hrrSz, 0), 0); - - /* Drop HRR, trigger CH1 retransmission, copy and drop it */ - test_memio_clear_buffer(&test_ctx, 1); - if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); - ExpectIntEQ(test_memio_copy_message(&test_ctx, 0, ch1Rtx, &ch1RtxSz, 0), 0); - test_memio_clear_buffer(&test_ctx, 0); - - /* Force CH2 fragmentation. MTU must be small enough to fragment but large - * enough that the cookie extension lands in the first fragment, otherwise - * the server can't validate it statelessly and the test scenario (server - * stateful after frag 1) does not hold. With --enable-all (PQ groups in - * supported_groups), the cookie extension can sit ~400 bytes into CH2; 600 - * gives margin while still producing multiple fragments (CH2 is ~2KB). */ - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, 600), WOLFSSL_SUCCESS); - - /* Forward HRR and let the client create fragmented CH2 */ - ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrr, hrrSz), 0); - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - ExpectIntGT(test_ctx.s_msg_count, 1); - ExpectIntLE(test_ctx.s_msg_count, TEST_MEMIO_MAX_MSGS); - ExpectIntLE(test_ctx.s_len, (int)sizeof(ch2)); - if (EXPECT_SUCCESS()) { - ch2Sz = test_ctx.s_len; - ch2MsgCount = test_ctx.s_msg_count; - XMEMCPY(ch2, test_ctx.s_buff, ch2Sz); - XMEMCPY(ch2MsgSizes, test_ctx.s_msg_sizes, - sizeof(ch2MsgSizes[0]) * (size_t)ch2MsgCount); - - ch2Seq = ((byte)ch2[recordSeqOff + 4] << 8) | - (byte)ch2[recordSeqOff + 5]; - ch1RtxSeq = ch2Seq + ch2MsgCount; - - /* Synthesize a CH1 retransmission that can pass the replay window after - * the first CH2 fragment makes the server stateful. The handshake - * message_seq remains the original CH1 value; only the DTLS record - * sequence is moved past the fragmented CH2 flight */ - ch1Rtx[recordSeqOff + 0] = 0; - ch1Rtx[recordSeqOff + 1] = 0; - ch1Rtx[recordSeqOff + 2] = 0; - ch1Rtx[recordSeqOff + 3] = 0; - ch1Rtx[recordSeqOff + 4] = (byte)(ch1RtxSeq >> 8); - ch1Rtx[recordSeqOff + 5] = (byte)ch1RtxSeq; - } - - test_memio_clear_buffer(&test_ctx, 0); - - /* Deliver CH2 first fragment only. Now server is stateful */ - ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch2, ch2MsgSizes[0]), 0); - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Deliver the retransmitted CH1 between CH2 fragments, it should be - * discarded as rtx */ - ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch1Rtx, ch1RtxSz), 0); - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - test_memio_clear_buffer(&test_ctx, 1); - - /* Deliver the rest of CH2 */ - off = ch2MsgSizes[0]; - for (i = 1; i < ch2MsgCount && EXPECT_SUCCESS(); i++) { - ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch2 + off, - ch2MsgSizes[i]), 0); - off += ch2MsgSizes[i]; - } - - /* Restore MTU so the client's input buffer can hold the full server - * flight (e.g. an SH carrying a hybrid PQC key share). */ - ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, 1500), WOLFSSL_SUCCESS); - - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} int test_dtls_drop_client_ack(void) { @@ -2262,43 +1510,6 @@ int test_dtls_replay(void) return EXPECT_RESULT(); } -#if defined(WOLFSSL_DTLS13) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(WOLFSSL_SRTP) -static int test_dtls_srtp_ctx_ready(WOLFSSL_CTX* ctx) -{ - EXPECT_DECLS; - ExpectIntEQ(wolfSSL_CTX_set_tlsext_use_srtp(ctx, "SRTP_AEAD_AES_256_GCM:" - "SRTP_AEAD_AES_128_GCM:SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32"), - 0); - return EXPECT_RESULT(); -} - -int test_dtls_srtp(void) -{ - EXPECT_DECLS; - test_ssl_cbf client_cbf; - test_ssl_cbf server_cbf; - - XMEMSET(&client_cbf, 0, sizeof(client_cbf)); - XMEMSET(&server_cbf, 0, sizeof(server_cbf)); - - client_cbf.method = wolfDTLSv1_3_client_method; - client_cbf.ctx_ready = test_dtls_srtp_ctx_ready; - server_cbf.method = wolfDTLSv1_3_server_method; - server_cbf.ctx_ready = test_dtls_srtp_ctx_ready; - - ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, - &server_cbf, NULL), TEST_SUCCESS); - - return EXPECT_RESULT(); -} -#else -int test_dtls_srtp(void) -{ - EXPECT_DECLS; - return EXPECT_RESULT(); -} -#endif int test_dtls_timeout(void) { @@ -2876,287 +2087,17 @@ int test_dtls_mtu_split_messages(void) * This tests relies on timing of the retransmission logic so it may be * flaky on very slow systems. */ -int test_dtls13_min_rtx_interval(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ - defined(WOLFSSL_DTLS13) && !defined(DTLS13_MIN_RTX_INTERVAL) && \ - !defined(NO_ASN_TIME) - /* We don't want to test when DTLS13_MIN_RTX_INTERVAL is defined because - * it may be too low to trigger reliably in a test. The default value is - * 1 second which is sufficient for testing here. */ - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - struct test_memio_ctx test_ctx; - int c_msg_count = 0; - - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - - /* Setup DTLS 1.3 contexts */ - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - - /* CH0 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), SSL_ERROR_WANT_READ); - - /* HRR */ - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), SSL_ERROR_WANT_READ); - - /* CH1 */ - ExpectIntEQ(wolfSSL_connect(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), SSL_ERROR_WANT_READ); - - /* SH ... FINISHED */ - ExpectIntEQ(wolfSSL_accept(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), SSL_ERROR_WANT_READ); - - /* We should have SH ... FINISHED messages in the buffer */ - ExpectIntGE(test_ctx.c_msg_count, 2); - - /* Drop everything */ - test_memio_clear_buffer(&test_ctx, 1); - - /* First timeout. This one should trigger a retransmission */ - if (wolfSSL_dtls13_use_quick_timeout(ssl_s)) - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); - /* Save the message count to make sure no new messages are sent */ - ExpectIntGE(test_ctx.c_msg_count, 2); - c_msg_count = test_ctx.c_msg_count; - - /* Second timeout. This one should not trigger a retransmission */ - if (wolfSSL_dtls13_use_quick_timeout(ssl_s)) - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); - /* This is the critical check. The message count should not increase - * after the second timeout. DTLS13_MIN_RTX_INTERVAL should have blocked - * retransmission here. */ - ExpectIntEQ(c_msg_count, test_ctx.c_msg_count); - - /* Now complete the handshake. We didn't clear the first retransmission - * so the handshake should proceed without issues. */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - /* Cleanup */ - wolfSSL_free(ssl_c); - wolfSSL_CTX_free(ctx_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} /* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty * legacy_session_id_echo, even if the ClientHello had a non-empty * legacy_session_id. */ -int test_dtls13_no_session_id_echo(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) && \ - defined(HAVE_SESSION_TICKET) && defined(HAVE_ECC) && \ - !defined(WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID) - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - WOLFSSL_SESSION *sess = NULL; - char readBuf[1]; - /* Pin to SECP256R1 to avoid a PQ-induced key-share HRR */ - int groups[] = { WOLFSSL_ECC_SECP256R1 }; - - /* First connection: complete a DTLS 1.3 handshake to get a session */ - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - /* Read to process any NewSessionTicket */ - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); - - /* Ensure the session has a non-empty session ID so the ClientHello - * will have a populated legacy_session_id field (which is legal per - * RFC 9147). */ - if (sess != NULL && sess->sessionIDSz == 0) { - sess->sessionIDSz = ID_LEN; - XMEMSET(sess->sessionID, 0x42, ID_LEN); - } - - wolfSSL_free(ssl_c); ssl_c = NULL; - wolfSSL_free(ssl_s); ssl_s = NULL; - wolfSSL_CTX_free(ctx_c); ctx_c = NULL; - wolfSSL_CTX_free(ctx_s); ctx_s = NULL; - - /* Second connection: set the session on the client so the ClientHello - * contains a non-empty legacy_session_id. Verify the server does NOT - * echo it in the ServerHello. */ - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); - /* Disable HRR cookie so the server directly sends a ServerHello */ - ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); - - /* Client sends ClientHello (with non-empty legacy_session_id) */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* Server processes ClientHello and sends ServerHello + flight */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Verify the ServerHello on the wire. - * Layout: DTLS Record Header (13) + DTLS Handshake Header (12) + - * ProtocolVersion (2) + Random (32) = offset 59 for - * legacy_session_id_echo length byte. */ - ExpectIntGE(test_ctx.c_len, 60); - ExpectIntEQ(test_ctx.c_buff[0], handshake); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + - DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], 0); - - /* Complete the handshake */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_SESSION_free(sess); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} /* Test that a server built with WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID echoes the * client's legacy_session_id in both the direct ServerHello path and the * stateless HRR path (which also exercises RestartHandshakeHashWithCookie). */ -int test_dtls13_5_9_0_compat(void) -{ - EXPECT_DECLS; -#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) && \ - defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID) && \ - defined(HAVE_ECC) - struct test_memio_ctx test_ctx; - WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; - WOLFSSL *ssl_c = NULL, *ssl_s = NULL; - WOLFSSL_SESSION *sess = NULL; - char readBuf[1]; - /* Pin to SECP256R1 to avoid a PQ-induced key-share HRR */ - int groups[] = { WOLFSSL_ECC_SECP256R1 }; - /* RFC 8446 Section 4.1.3: an HRR is a ServerHello carrying this magic - * random. Used to assert sub-test 1 is a real ServerHello, not an HRR. */ - static const byte hrrRandom[RAN_LEN] = { - 0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, - 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91, - 0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, - 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C - }; - /* --- initial connection: get a real session to carry the session ID --- */ - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - /* drain any NewSessionTicket before calling get1_session */ - ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); - - /* Force a non-zero session ID - simulates a wolfSSL <=v5.9.0 client that - * mistakenly sends 32 bytes as legacy_session_id in DTLS 1.3. */ - if (sess != NULL && sess->sessionIDSz == 0) { - sess->sessionIDSz = ID_LEN; - XMEMSET(sess->sessionID, 0x42, ID_LEN); - } - - wolfSSL_free(ssl_c); ssl_c = NULL; - wolfSSL_free(ssl_s); ssl_s = NULL; - wolfSSL_CTX_free(ctx_c); ctx_c = NULL; - wolfSSL_CTX_free(ctx_s); ctx_s = NULL; - - /* --- sub-test 1: direct ServerHello (HRR cookie disabled) --- - * Exercises DoTls13ClientHello (change 1) and - * SendTls13ServerHello (change 2). */ - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); - - /* Client sends CH1 with non-empty legacy_session_id */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* Server processes CH1 and sends ServerHello */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Verify that the ServerHello on the wire echoes the session ID. - * Layout: DTLS Record Header (13) + DTLS Handshake Header (12) + - * ProtocolVersion (2) + Random (32) = byte 59 for - * legacy_session_id_echo length. */ - ExpectIntGE(test_ctx.c_len, 60); - ExpectIntEQ(test_ctx.c_buff[0], handshake); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); - /* Confirm it is a real ServerHello, not an HRR (also encoded as a - * ServerHello but bearing the HelloRetryRequest magic random). */ - ExpectIntNE(XMEMCMP(&test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + - DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN], hrrRandom, RAN_LEN), 0); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + - DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], ID_LEN); - - /* Complete the handshake - Finished MAC validates the transcript */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_free(ssl_c); ssl_c = NULL; - wolfSSL_free(ssl_s); ssl_s = NULL; - wolfSSL_CTX_free(ctx_c); ctx_c = NULL; - wolfSSL_CTX_free(ctx_s); ctx_s = NULL; - - /* --- sub-test 2: stateless HRR (HRR cookie enabled by default) --- - * Exercises SendStatelessReplyDtls13 (change 4) and - * RestartHandshakeHashWithCookie (change 3). */ - XMEMSET(&test_ctx, 0, sizeof(test_ctx)); - ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, - wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); - ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); - - /* Client sends CH1 */ - ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); - - /* Server sends stateless HRR (SendStatelessReplyDtls13) */ - ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); - ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); - - /* Verify the HRR echoes the session ID at the same wire offset */ - ExpectIntGE(test_ctx.c_len, 60); - ExpectIntEQ(test_ctx.c_buff[0], handshake); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); - ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + - DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], ID_LEN); - - /* Complete the handshake - Finished MAC validates RestartHandshakeHashWithCookie */ - ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); - - wolfSSL_SESSION_free(sess); - wolfSSL_free(ssl_c); - wolfSSL_free(ssl_s); - wolfSSL_CTX_free(ctx_c); - wolfSSL_CTX_free(ctx_s); -#endif - return EXPECT_RESULT(); -} +/* Test that a DTLS 1.3 handshake with an oversized certificate chain does + * not crash or cause out-of-bounds access in SendTls13Certificate. */ /* DTLS counterpart to test_tls_set_session_min_downgrade. Exercises the * inverted DTLS minor-version comparison (DTLS 1.2 minor 0xFD is "below" @@ -3199,3 +2140,3301 @@ int test_dtls_set_session_min_downgrade(void) #endif return EXPECT_RESULT(); } + +/*----------------------------------------------------------------------------*/ +/* DTLS session export / import */ +/*----------------------------------------------------------------------------*/ + +#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) +/* canned export of a session using older version 3 */ +static unsigned char version_3[] = { + 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, + 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05, + 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05, + 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D, + 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B, + 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98, + 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0, + 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74, + 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26, + 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9, + 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04, + 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D, + 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01, + 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00, + 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, + 0x2E, 0x31, 0xED, 0x4F +}; +#endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */ + +int test_wolfSSL_dtls_export(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) + tcp_ready ready; + func_args client_args; + func_args server_args; + THREAD_TYPE serverThread; + callback_functions server_cbf; + callback_functions client_cbf; +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + + InitTcpReady(&ready); + + /* set using dtls */ + XMEMSET(&client_args, 0, sizeof(func_args)); + XMEMSET(&server_args, 0, sizeof(func_args)); + XMEMSET(&server_cbf, 0, sizeof(callback_functions)); + XMEMSET(&client_cbf, 0, sizeof(callback_functions)); + server_cbf.method = wolfDTLSv1_2_server_method; + client_cbf.method = wolfDTLSv1_2_client_method; + server_args.callbacks = &server_cbf; + client_args.callbacks = &client_cbf; + + server_args.signal = &ready; + client_args.signal = &ready; + + start_thread(run_wolfssl_server, &server_args, &serverThread); + wait_tcp_ready(&server_args); + run_wolfssl_client(&client_args); + join_thread(serverThread); + + ExpectTrue(client_args.return_code); + ExpectTrue(server_args.return_code); + + FreeTcpReady(&ready); + +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + + if (EXPECT_SUCCESS()) { + SOCKET_T sockfd = 0; + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + char msg[64] = "hello wolfssl!"; + char reply[1024]; + int msgSz = (int)XSTRLEN(msg); + byte *session, *window; + unsigned int sessionSz = 0; + unsigned int windowSz = 0; + +#ifndef TEST_IPV6 + struct sockaddr_in peerAddr; +#else + struct sockaddr_in6 peerAddr; +#endif /* TEST_IPV6 */ + + int i; + + + /* Set ctx to DTLS 1.2 */ + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* test importing version 3 */ + ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); + + /* test importing bad length and bad version */ + version_3[2]++; + ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); + version_3[2]--; version_3[1] = 0XA0; + ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0); + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + + + /* check storing client state after connection and storing window only */ +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + + InitTcpReady(&ready); + + /* set using dtls */ + XMEMSET(&server_args, 0, sizeof(func_args)); + XMEMSET(&server_cbf, 0, sizeof(callback_functions)); + server_cbf.method = wolfDTLSv1_2_server_method; + server_cbf.doUdp = 1; + server_args.callbacks = &server_cbf; + server_args.argc = 3; /* set loop_count to 3 */ + + + server_args.signal = &ready; + start_thread(test_server_nofail, &server_args, &serverThread); + wait_tcp_ready(&server_args); + + /* create and connect with client */ + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method())); + ExpectIntEQ(WOLFSSL_SUCCESS, + wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0)); + ExpectIntEQ(WOLFSSL_SUCCESS, + wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM)); + ExpectIntEQ(WOLFSSL_SUCCESS, + wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM)); + tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); + + /* store server information connected too */ + XMEMSET(&peerAddr, 0, sizeof(peerAddr)); +#ifndef TEST_IPV6 + peerAddr.sin_family = AF_INET; + ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1); + peerAddr.sin_port = XHTONS(server_args.signal->port); +#else + peerAddr.sin6_family = AF_INET6; + ExpectIntEQ( + XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1); + peerAddr.sin6_port = XHTONS(server_args.signal->port); +#endif + + ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)), + WOLFSSL_SUCCESS); + + ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0); + session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0); + ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz); + ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0); + ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0); + window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0); + wolfSSL_free(ssl); + + for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) { + /* restore state */ + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0); + ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0); + ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz); + ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0); + ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0); + wolfSSL_free(ssl); + } + XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wolfSSL_CTX_free(ctx); + + fprintf(stderr, "done and waiting for server\n"); + join_thread(serverThread); + ExpectIntEQ(server_args.return_code, TEST_SUCCESS); + + FreeTcpReady(&ready); + +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + } +#endif + + return EXPECT_RESULT(); +} + +#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \ + defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) +/* Dummy peer functions to satisfy the exporter/importer */ +static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip, + int* ipSz, unsigned short* port, int* fam) +{ + (void)ssl; + ip[0] = -1; + *ipSz = 1; + *port = 1; + *fam = 2; + return 1; +} + +static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip, + int ipSz, unsigned short port, int fam) +{ + (void)ssl; + if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2) + return 0; + return 1; +} + +static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx, + WOLFSSL **ssl) +{ + EXPECT_DECLS; + unsigned char* sessionBuf = NULL; + unsigned int sessionSz = 0; + void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl); + void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl); + + wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer); + wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer); + ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0); + ExpectNotNull(sessionBuf = + (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)); + ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0); + wolfSSL_free(*ssl); + *ssl = NULL; + ExpectNotNull(*ssl = wolfSSL_new(*ctx)); + ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0); + wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx); + wolfSSL_SetIOReadCtx(*ssl, ioReadCtx); + + XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + return EXPECT_RESULT(); +} +#endif + +int test_wolfSSL_dtls_export_peers(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \ + defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) + test_ssl_cbf client_cbf; + test_ssl_cbf server_cbf; + size_t i, j; + struct test_params { + method_provider client_meth; + method_provider server_meth; + const char* dtls_version; + } params[] = { +#ifndef NO_OLD_TLS + {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"}, +#endif + {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"}, + /* TODO DTLS 1.3 exporting not supported +#ifdef WOLFSSL_DTLS13 + {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"}, +#endif + */ + }; + + for (i = 0; i < sizeof(params)/sizeof(*params); i++) { + for (j = 0; j <= 3; j++) { + XMEMSET(&client_cbf, 0, sizeof(client_cbf)); + XMEMSET(&server_cbf, 0, sizeof(server_cbf)); + + printf("\n\tTesting DTLS %s connection;", params[i].dtls_version); + + client_cbf.method = params[i].client_meth; + server_cbf.method = params[i].server_meth; + + if (j & 0x1) { + client_cbf.on_handshake = + test_wolfSSL_dtls_export_peers_on_handshake; + printf(" With client export;"); + } + if (j & 0x2) { + server_cbf.on_handshake = + test_wolfSSL_dtls_export_peers_on_handshake; + printf(" With server export;"); + } + + printf("\n"); + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, + &server_cbf, NULL), TEST_SUCCESS); + if (!EXPECT_SUCCESS()) + break; + } + } +#endif + return EXPECT_RESULT(); +} + +/* Test that ImportKeyState correctly skips extra window words when importing + * state from a peer compiled with a larger WOLFSSL_DTLS_WINDOW_WORDS. */ +int test_wolfSSL_dtls_import_state_extra_window_words(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + unsigned int stateSz = 0; + byte* state = NULL; + byte* modified = NULL; + unsigned int modifiedSz; + word16 origKeyLen; + word16 origTotalLen; + /* Offset from start of key state data to the first wordCount field. + * Layout: 4 sequence numbers (16 bytes) + DTLS-specific fields (42 bytes) + + * encryptSz(4) + padSz(4) + encryptionOn(1) + decryptedCur(1) = 68 */ + const int keyStateWindowOffset = 68; + /* Buffer header: 2 proto + 2 total_len + 2 key_len = 6 */ + const int headerSz = 6; + int idx, modIdx; + int extraPerWindow = 2 * (int)sizeof(word32); /* 8 bytes extra per window */ + int totalExtra = extraPerWindow * 2; /* 16 bytes extra total */ + + /* Create DTLS context and SSL object */ + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + /* Get required buffer size and export state-only */ + ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &stateSz), 0); + ExpectIntGT((int)stateSz, 0); + state = (byte*)XMALLOC(stateSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(state); + ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, state, &stateSz), 0); + + /* Build a modified buffer that simulates a peer with + * WOLFSSL_DTLS_WINDOW_WORDS = WOLFSSL_DTLS_WINDOW_WORDS + 2. + * Each window section gets 2 extra word32 values (8 bytes). + * Two windows => 16 extra bytes total. */ + modifiedSz = stateSz + totalExtra; + modified = (byte*)XMALLOC(modifiedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + ExpectNotNull(modified); + + if (EXPECT_SUCCESS()) { + int windowWords = WOLFSSL_DTLS_WINDOW_WORDS; + int windowDataSz = windowWords * (int)sizeof(word32); + + XMEMSET(modified, 0, modifiedSz); + + /* Copy protocol/version bytes (first 2 bytes) */ + XMEMCPY(modified, state, 2); + + /* Read original total length and key state length */ + ato16(state + 2, &origTotalLen); + ato16(state + 4, &origKeyLen); + + /* Write updated total length and key state length */ + c16toa((word16)(origTotalLen + totalExtra), modified + 2); + c16toa((word16)(origKeyLen + totalExtra), modified + 4); + + /* Copy key state data up to first window section */ + idx = headerSz; + modIdx = headerSz; + XMEMCPY(modified + modIdx, state + idx, keyStateWindowOffset); + idx += keyStateWindowOffset; + modIdx += keyStateWindowOffset; + + /* First window: write increased wordCount */ + c16toa((word16)(windowWords + 2), modified + modIdx); + idx += OPAQUE16_LEN; + modIdx += OPAQUE16_LEN; + + /* Copy original window data */ + XMEMCPY(modified + modIdx, state + idx, windowDataSz); + idx += windowDataSz; + modIdx += windowDataSz; + + /* Insert 2 extra word32 padding values */ + XMEMSET(modified + modIdx, 0, extraPerWindow); + modIdx += extraPerWindow; + + /* Second window (prevWindow): same transformation */ + c16toa((word16)(windowWords + 2), modified + modIdx); + idx += OPAQUE16_LEN; + modIdx += OPAQUE16_LEN; + + XMEMCPY(modified + modIdx, state + idx, windowDataSz); + idx += windowDataSz; + modIdx += windowDataSz; + + XMEMSET(modified + modIdx, 0, extraPerWindow); + modIdx += extraPerWindow; + + /* Copy remainder of key state (after both windows) */ + XMEMCPY(modified + modIdx, state + idx, stateSz - idx); + } + + /* Import the modified state - should succeed with the fix */ + wolfSSL_free(ssl); + ssl = NULL; + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntGT(wolfSSL_dtls_import(ssl, modified, modifiedSz), 0); + + XFREE(state, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(modified, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} + +/*----------------------------------------------------------------------------*/ +/* DTLS either-side method and cookie generation */ +/*----------------------------------------------------------------------------*/ + +int test_wolfSSL_DTLS_either_side(void) +{ + EXPECT_DECLS; +#if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \ + defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) + test_ssl_cbf client_cb; + test_ssl_cbf server_cb; + + XMEMSET(&client_cb, 0, sizeof(client_cb)); + XMEMSET(&server_cb, 0, sizeof(server_cb)); + + /* Use different CTX for client and server */ + client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); + ExpectNotNull(client_cb.ctx); + server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); + ExpectNotNull(server_cb.ctx); + /* we are responsible for free'ing WOLFSSL_CTX */ + server_cb.isSharedCtx = client_cb.isSharedCtx = 1; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, + &server_cb, NULL), TEST_SUCCESS); + + wolfSSL_CTX_free(client_cb.ctx); + wolfSSL_CTX_free(server_cb.ctx); +#endif + return EXPECT_RESULT(); +} + +int test_generate_cookie(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO) + SSL_CTX* ctx = NULL; + SSL* ssl = NULL; + byte buf[FOURK_BUF] = {0}; + + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method())); + ExpectNotNull(ssl = SSL_new(ctx)); + + /* Test unconnected */ + ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E)); + + wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie); + + wolfSSL_SetCookieCtx(ssl, ctx); + + ExpectNotNull(wolfSSL_GetCookieCtx(ssl)); + + ExpectNull(wolfSSL_GetCookieCtx(NULL)); + + SSL_free(ssl); + SSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} + +/*----------------------------------------------------------------------------*/ +/* DTLS handshake: MTU, plaintext, fragments, bad records, AEAD, stateless */ +/*----------------------------------------------------------------------------*/ + +int test_wolfSSL_dtls_set_mtu(void) +{ + EXPECT_DECLS; +#if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \ + !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + const char* testCertFile; + const char* testKeyFile; + + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); +#ifndef NO_RSA + testCertFile = svrCertFile; + testKeyFile = svrKeyFile; +#elif defined(HAVE_ECC) + testCertFile = eccCertFile; + testKeyFile = eccKeyFile; +#endif + if (testCertFile != NULL && testKeyFile != NULL) { + ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile, + WOLFSSL_FILETYPE_PEM)); + ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile, + WOLFSSL_FILETYPE_PEM)); + } + ExpectNotNull(ssl = wolfSSL_new(ctx)); + + ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS); + +#ifdef OPENSSL_EXTRA + ExpectIntEQ(SSL_set_mtu(ssl, 1488), WOLFSSL_SUCCESS); +#endif + + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); +#endif + + return EXPECT_RESULT(); +} + +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ + defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) + +static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq, + enum HandShakeType hsType, word16 length) +{ + size_t idx = 0; + byte* l; + + /* record layer */ + /* handshake type */ + out[idx++] = handshake; + /* protocol version */ + out[idx++] = 0xfe; + out[idx++] = 0xfd; /* DTLS 1.2 */ + /* epoch 0 */ + XMEMSET(out + idx, 0, 2); + idx += 2; + /* sequence number */ + XMEMSET(out + idx, 0, 6); + c32toa(seq, out + idx + 2); + idx += 6; + /* length in BE */ + if (length) + c16toa(length, out + idx); + else + c16toa(outSz - idx - 2, out + idx); + idx += 2; + + /* handshake layer */ + /* handshake type */ + out[idx++] = (byte)hsType; + /* length */ + l = out + idx; + idx += 3; + /* message seq */ + c16toa(0, out + idx); + idx += 2; + /* frag offset */ + c32to24(0, out + idx); + idx += 3; + /* frag length */ + c32to24((word32)outSz - (word32)idx - 3, l); + c32to24((word32)outSz - (word32)idx - 3, out + idx); + idx += 3; + XMEMSET(out + idx, 0, outSz - idx); +} + +static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl) +{ + byte msg[] = "This is a msg for the client"; + byte reply[40]; + AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0); + reply[sizeof(reply) - 1] = '\0'; + fprintf(stderr, "Client message: %s\n", reply); + AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg)); +} + +static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl) +{ + byte ch[50]; + int fd = wolfSSL_get_wfd(ssl); + byte msg[] = "This is a msg for the server"; + byte reply[40]; + + AssertIntGE(fd, 0); + generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0); + /* Server should ignore this datagram */ + AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch)); + generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000); + /* Server should ignore this datagram */ + AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch)); + + AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg)); + AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0); + reply[sizeof(reply) - 1] = '\0'; + fprintf(stderr, "Server response: %s\n", reply); +} + +int test_wolfSSL_dtls_plaintext(void) +{ + callback_functions func_cb_client; + callback_functions func_cb_server; + size_t i; + struct test_params { + method_provider client_meth; + method_provider server_meth; + ssl_callback on_result_server; + ssl_callback on_result_client; + } params[] = { + {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, + test_wolfSSL_dtls_plaintext_server, + test_wolfSSL_dtls_plaintext_client}, + }; + + for (i = 0; i < sizeof(params)/sizeof(*params); i++) { + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_server.method = params[i].server_meth; + func_cb_client.method = params[i].client_meth; + func_cb_client.on_result = params[i].on_result_client; + func_cb_server.on_result = params[i].on_result_server; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + if (!func_cb_client.return_code) + return TEST_FAIL; + if (!func_cb_server.return_code) + return TEST_FAIL; + } + + return TEST_RES_CHECK(1); +} +#else +int test_wolfSSL_dtls_plaintext(void) +{ + return TEST_SKIPPED; +} +#endif + +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ + defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) + +static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl) +{ + byte b[1100]; /* buffer for the messages to send */ + size_t idx = 0; + size_t seq_offset = 0; + size_t msg_offset = 0; + int i; + int fd = wolfSSL_get_wfd(ssl); + int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */ + word32 seq_number = 100; /* start high so server definitely reads this */ + word16 msg_number = 50; /* start high so server has to buffer this */ + AssertIntEQ(ret, 1); + /* Now let's start spamming the peer with fragments it needs to store */ + XMEMSET(b, -1, sizeof(b)); + + /* record layer */ + /* handshake type */ + b[idx++] = 22; + /* protocol version */ + b[idx++] = 0xfe; + b[idx++] = 0xfd; /* DTLS 1.2 */ + /* epoch 0 */ + XMEMSET(b + idx, 0, 2); + idx += 2; + /* sequence number */ + XMEMSET(b + idx, 0, 6); + seq_offset = idx + 2; /* increment only the low 32 bits */ + idx += 6; + /* static length in BE */ + c16toa(42, b + idx); + idx += 2; + + /* handshake layer */ + /* cert type */ + b[idx++] = 11; + /* length */ + c32to24(1000, b + idx); + idx += 3; + /* message seq */ + c16toa(0, b + idx); + msg_offset = idx; + idx += 2; + /* frag offset */ + c32to24(500, b + idx); + idx += 3; + /* frag length */ + c32to24(30, b + idx); + idx += 3; + (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */ + + for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0; + seq_number++, msg_number++, i++) { + struct timespec delay; + XMEMSET(&delay, 0, sizeof(delay)); + delay.tv_nsec = 10000000; /* wait 0.01 seconds */ + c32toa(seq_number, b + seq_offset); + c16toa(msg_number, b + msg_offset); + ret = (int)send(fd, (MESSAGE_TYPE_CAST)b, 55, 0); + nanosleep(&delay, NULL); + } +} + +#ifdef WOLFSSL_DTLS13 +static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl) +{ + const word16 sendCountMax = 100; + byte b[150]; /* buffer for the messages to send */ + size_t idx = 0; + size_t msg_offset = 0; + int fd = wolfSSL_get_wfd(ssl); + word16 msg_number = 10; /* start high so server has to buffer this */ + int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */ + AssertIntEQ(ret, 1); + /* Now let's start spamming the peer with fragments it needs to store */ + XMEMSET(b, -1, sizeof(b)); + + /* handshake type */ + b[idx++] = 11; + /* length */ + c32to24(10000, b + idx); + idx += 3; + /* message_seq */ + msg_offset = idx; + idx += 2; + /* fragment_offset */ + c32to24(5000, b + idx); + idx += 3; + /* fragment_length */ + c32to24(100, b + idx); + idx += 3; + /* fragment contents */ + idx += 100; + + for (; ret > 0 && msg_number < sendCountMax; msg_number++) { + byte sendBuf[150]; + int sendSz = sizeof(sendBuf); + struct timespec delay; + XMEMSET(&delay, 0, sizeof(delay)); + delay.tv_nsec = 10000000; /* wait 0.01 seconds */ + c16toa(msg_number, b + msg_offset); + ret = sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b, + (int)idx, handshake, 0, 0, 0); + if (sendSz > 0) + ret = (int)send(fd, (MESSAGE_TYPE_CAST)sendBuf, (size_t)sendSz, 0); + nanosleep(&delay, NULL); + } +} +#endif + +int test_wolfSSL_dtls_fragments(void) +{ + EXPECT_DECLS; + callback_functions func_cb_client; + callback_functions func_cb_server; + size_t i; + struct test_params { + method_provider client_meth; + method_provider server_meth; + ssl_callback spammer; + } params[] = { +#if !defined(WOLFSSL_NO_TLS12) + {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, + test_wolfSSL_dtls12_fragments_spammer}, +#endif +#ifdef WOLFSSL_DTLS13 + {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, + test_wolfSSL_dtls13_fragments_spammer}, +#endif + }; + + for (i = 0; i < sizeof(params)/sizeof(*params); i++) { + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_server.method = params[i].server_meth; + func_cb_client.method = params[i].client_meth; + func_cb_client.ssl_ready = params[i].spammer; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + /* If the client failed, check that the error it encountered was from + * the server aborting, resulting in a socket error, fatal error or + * reading a close notify alert. + * + * Under slow execution (e.g. valgrind + noasm), the server may + * still be processing fragments when the client completes its + * handshake and write, so the client may succeed -- in that + * case return_code is TEST_SUCCESS and these checks don't apply. + */ + if (func_cb_client.return_code == TEST_FAIL) { + if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) && + func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN && + func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) { + ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); + } + } + /* Check the server returned an error indicating the msg buffer + * was full. + * + * Under slow execution (e.g. valgrind + noasm), the real handshake + * from wolfSSL_negotiate() may complete before enough spam fragments + * accumulate to trigger DTLS_TOO_MANY_FRAGMENTS_E. Accept both + * outcomes: server hit the fragment limit, or completed normally. + */ + if (func_cb_server.return_code == TEST_FAIL) { + ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E)); + } + + if (EXPECT_FAIL()) + break; + } + + return EXPECT_RESULT(); +} + +static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl) +{ + int fd, ret; + byte alert_msg[] = { + 0x15, /* alert type */ + 0xfe, 0xfd, /* version */ + 0x00, 0x00, /* epoch */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */ + 0x00, 0x02, /* length */ + 0x02, /* level: fatal */ + 0x46 /* protocol version */ + }; + + fd = wolfSSL_get_wfd(ssl); + AssertIntGE(fd, 0); + ret = (int)send(fd, (MESSAGE_TYPE_CAST)alert_msg, sizeof(alert_msg), 0); + AssertIntGT(ret, 0); +} + +static int _test_wolfSSL_ignore_alert_before_cookie(byte version12) +{ + callback_functions client_cbs, server_cbs; + + XMEMSET(&client_cbs, 0, sizeof(client_cbs)); + XMEMSET(&server_cbs, 0, sizeof(server_cbs)); + client_cbs.doUdp = server_cbs.doUdp = 1; + if (version12) { +#if !defined(WOLFSSL_NO_TLS12) + client_cbs.method = wolfDTLSv1_2_client_method; + server_cbs.method = wolfDTLSv1_2_server_method; +#else + return TEST_SKIPPED; +#endif + } + else + { +#ifdef WOLFSSL_DTLS13 + client_cbs.method = wolfDTLSv1_3_client_method; + server_cbs.method = wolfDTLSv1_3_server_method; +#else + return TEST_SKIPPED; +#endif /* WOLFSSL_DTLS13 */ + } + + client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert; + test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); + + if (!client_cbs.return_code) + return TEST_FAIL; + if (!server_cbs.return_code) + return TEST_FAIL; + + return TEST_SUCCESS; +} + +int test_wolfSSL_ignore_alert_before_cookie(void) +{ + int ret; + ret =_test_wolfSSL_ignore_alert_before_cookie(0); + if (ret != 0) + return ret; + ret =_test_wolfSSL_ignore_alert_before_cookie(1); + if (ret != 0) + return ret; + return 0; +} + +static void test_wolfSSL_send_bad_record(WOLFSSL* ssl) +{ + int ret; + int fd; + + byte bad_msg[] = { + 0x17, /* app data */ + 0xaa, 0xfd, /* bad version */ + 0x00, 0x01, /* epoch 1 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */ + 0x00, 0x26, /* length: 38 bytes */ + 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57, + 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1, + 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f, + 0x03, 0x18, 0x72 + }; + + fd = wolfSSL_get_wfd(ssl); + AssertIntGE(fd, 0); + ret = (int)send(fd, (MESSAGE_TYPE_CAST)bad_msg, sizeof(bad_msg), 0); + AssertIntEQ(ret, sizeof(bad_msg)); + ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest")); + AssertIntEQ(ret, sizeof("badrecordtest")); +} + +static void test_wolfSSL_read_string(WOLFSSL* ssl) +{ + byte buf[100]; + int ret; + + ret = wolfSSL_read(ssl, buf, sizeof(buf)); + AssertIntGT(ret, 0); + AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0); +} + +static int _test_wolfSSL_dtls_bad_record( + method_provider client_method, method_provider server_method) +{ + callback_functions client_cbs, server_cbs; + + XMEMSET(&client_cbs, 0, sizeof(client_cbs)); + XMEMSET(&server_cbs, 0, sizeof(server_cbs)); + client_cbs.doUdp = server_cbs.doUdp = 1; + client_cbs.method = client_method; + server_cbs.method = server_method; + + client_cbs.on_result = test_wolfSSL_send_bad_record; + server_cbs.on_result = test_wolfSSL_read_string; + + test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); + + if (!client_cbs.return_code) + return TEST_FAIL; + if (!server_cbs.return_code) + return TEST_FAIL; + + return TEST_SUCCESS; +} + +int test_wolfSSL_dtls_bad_record(void) +{ + int ret = TEST_SUCCESS; +#if !defined(WOLFSSL_NO_TLS12) + ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method, + wolfDTLSv1_2_server_method); +#endif +#ifdef WOLFSSL_DTLS13 + if (ret == TEST_SUCCESS) { + ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method, + wolfDTLSv1_3_server_method); + } +#endif /* WOLFSSL_DTLS13 */ + return ret; + +} + +#else +int test_wolfSSL_dtls_fragments(void) +{ + return TEST_SKIPPED; +} +int test_wolfSSL_ignore_alert_before_cookie(void) +{ + return TEST_SKIPPED; +} +int test_wolfSSL_dtls_bad_record(void) +{ + return TEST_SKIPPED; +} +#endif + +#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) +static volatile int test_AEAD_seq_num = 0; +#ifdef WOLFSSL_NO_ATOMICS +static volatile int test_AEAD_done = 0; +#else +wolfSSL_Atomic_Int test_AEAD_done = WOLFSSL_ATOMIC_INITIALIZER(0); +#endif +#ifdef WOLFSSL_MUTEX_INITIALIZER +static wolfSSL_Mutex test_AEAD_mutex = WOLFSSL_MUTEX_INITIALIZER(test_AEAD_mutex); +#endif + +static int test_AEAD_fail_decryption = 0; +static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx) +{ + int fd = wolfSSL_get_fd(ssl); + int ret = -1; + if (fd >= 0 && (ret = (int)recv(fd, buf, sz, 0)) > 0) { + if (test_AEAD_fail_decryption) { + /* Modify the packet to trigger a decryption failure */ + buf[ret/2] ^= 0xFF; + if (test_AEAD_fail_decryption == 1) + test_AEAD_fail_decryption = 0; + } + } + (void)ctx; + return ret; +} + +static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit, + w64wrapper* keyUpdateLimit, w64wrapper* sendLimit) +{ + if (sendLimit) + w64Zero(sendLimit); + switch (ssl->specs.bulk_cipher_algorithm) { + case wolfssl_aes_gcm: + if (sendLimit) + *sendLimit = AEAD_AES_LIMIT; + FALL_THROUGH; + case wolfssl_chacha: + if (hardLimit) + *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT; + if (keyUpdateLimit) + *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT; + break; + case wolfssl_aes_ccm: + if (sendLimit) + *sendLimit = DTLS_AEAD_AES_CCM_LIMIT; + if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) { + if (hardLimit) + *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT; + if (keyUpdateLimit) + *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT; + } + else { + if (hardLimit) + *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT; + if (keyUpdateLimit) + *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT; + } + break; + default: + fprintf(stderr, "Unrecognized bulk cipher"); + AssertFalse(1); + break; + } +} + +static void test_AEAD_limit_client(WOLFSSL* ssl) +{ + int ret; + int i; + int didReKey = 0; + char msgBuf[20]; + w64wrapper hardLimit; + w64wrapper keyUpdateLimit; + w64wrapper counter; + w64wrapper sendLimit; + + test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit); + + w64Zero(&counter); + AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)); + + wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv); + + for (i = 0; i < 10; i++) { + /* Test some failed decryptions */ + test_AEAD_fail_decryption = 1; + w64Increment(&counter); + ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); + /* Should succeed since decryption failures are dropped */ + AssertIntGT(ret, 0); + AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)); + } + + test_AEAD_fail_decryption = 1; + Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit; + w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount); + /* 100 read calls should be enough to complete the key update */ + w64Zero(&counter); + for (i = 0; i < 100; i++) { + /* Key update should be sent and negotiated */ + ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); + AssertIntGT(ret, 0); + /* Epoch after one key update is 4 */ + if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) && + w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) { + didReKey = 1; + break; + } + } + AssertTrue(didReKey); + + if (!w64IsZero(sendLimit)) { + /* Test the sending limit for AEAD ciphers */ +#ifdef WOLFSSL_MUTEX_INITIALIZER + (void)wc_LockMutex(&test_AEAD_mutex); +#endif + Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit; + test_AEAD_seq_num = 1; + XMEMSET(msgBuf, 0, sizeof(msgBuf)); + ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf)); + AssertIntGT(ret, 0); + didReKey = 0; + w64Zero(&counter); +#ifdef WOLFSSL_MUTEX_INITIALIZER + wc_UnLockMutex(&test_AEAD_mutex); +#endif + /* 100 read calls should be enough to complete the key update */ + for (i = 0; i < 100; i++) { + /* Key update should be sent and negotiated */ + ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); + AssertIntGT(ret, 0); + /* Epoch after another key update is 5 */ + if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) && + w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) { + didReKey = 1; + break; + } + } + AssertTrue(didReKey); + } + + test_AEAD_fail_decryption = 2; + Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit; + w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount); + /* Connection should fail with a DECRYPT_ERROR */ + ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); + AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR)); + +#ifdef WOLFSSL_ATOMIC_INITIALIZER + WOLFSSL_ATOMIC_STORE(test_AEAD_done, 1); +#else + test_AEAD_done = 1; +#endif +} + +int counter = 0; +static void test_AEAD_limit_server(WOLFSSL* ssl) +{ + char msgBuf[] = "Sending data"; + int ret = WOLFSSL_SUCCESS; + w64wrapper sendLimit; + SOCKET_T fd = wolfSSL_get_fd(ssl); + struct timespec delay; + XMEMSET(&delay, 0, sizeof(delay)); + delay.tv_nsec = 100000000; /* wait 0.1 seconds */ + tcp_set_nonblocking(&fd); /* So that read doesn't block */ + wolfSSL_dtls_set_using_nonblock(ssl, 1); + test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit); + while (! + #ifdef WOLFSSL_ATOMIC_INITIALIZER + WOLFSSL_ATOMIC_LOAD(test_AEAD_done) + #else + test_AEAD_done + #endif + && ret > 0) + { + counter++; +#ifdef WOLFSSL_MUTEX_INITIALIZER + (void)wc_LockMutex(&test_AEAD_mutex); +#endif + if (test_AEAD_seq_num) { + /* We need to update the seq number so that we can understand the + * peer. Otherwise we will incorrectly interpret the seq number. */ + Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch); + AssertNotNull(e); + e->nextPeerSeqNumber = sendLimit; + test_AEAD_seq_num = 0; + } +#ifdef WOLFSSL_MUTEX_INITIALIZER + wc_UnLockMutex(&test_AEAD_mutex); +#endif + (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)); + ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf)); + nanosleep(&delay, NULL); + } +} + +int test_wolfSSL_dtls_AEAD_limit(void) +{ + callback_functions func_cb_client; + callback_functions func_cb_server; + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_server.method = wolfDTLSv1_3_server_method; + func_cb_client.method = wolfDTLSv1_3_client_method; + func_cb_server.on_result = test_AEAD_limit_server; + func_cb_client.on_result = test_AEAD_limit_client; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + if (!func_cb_client.return_code) + return TEST_FAIL; + if (!func_cb_server.return_code) + return TEST_FAIL; + + return TEST_SUCCESS; +} +#else +int test_wolfSSL_dtls_AEAD_limit(void) +{ + return TEST_SKIPPED; +} +#endif + +#if defined(WOLFSSL_DTLS) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING) +static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl) +{ + int fd, ret; + byte ch_msg[] = { + 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a, + 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29, + 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00, + 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, + 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, + 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, + 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, + 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01, + 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, + 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, + 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, + 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c, + 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, + 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3, + 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6, + 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a, + 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43, + 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3, + 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d, + 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7, + 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e, + 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59, + 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0, + 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c, + 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6, + 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef, + 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45, + 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b, + 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83, + 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7, + 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2, + 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98, + 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a, + 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8, + 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d, + 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02, + 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33, + 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f, + 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3, + 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20, + 0x31, 0x68, 0x4c + }; + + fd = wolfSSL_get_wfd(ssl); + AssertIntGE(fd, 0); + ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0); + AssertIntGT(ret, 0); + /* consume the HRR otherwise handshake will fail */ + ret = (int)recv(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0); + AssertIntGT(ret, 0); +} + +#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) +static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl) +{ + int fd, ret; + byte ch_msh_invalid_cookie[] = { + 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, + 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60, + 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6, + 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00, + 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, + 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, + 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, + 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, + 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01, + 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, + 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, + 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, + 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45, + 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, + 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19, + 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00, + 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c, + 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02, + 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee, + 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f, + 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a, + 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27, + 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf, + 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1, + 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86, + 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d, + 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6, + 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7, + 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd, + 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4, + 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b, + 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0, + 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd, + 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51, + 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92, + 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e, + 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e, + 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc, + 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31, + 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d, + 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b, + 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad, + 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c, + 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00, + 0x23, 0x00, 0x00 + }; + byte alert_reply[50]; + byte expected_alert_reply[] = { + 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x02, 0x02, 0x2f + }; + + fd = wolfSSL_get_wfd(ssl); + if (fd >= 0) { + ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msh_invalid_cookie, + sizeof(ch_msh_invalid_cookie), 0); + AssertIntGT(ret, 0); + /* should reply with an illegal_parameter reply */ + ret = (int)recv(fd, (MESSAGE_TYPE_CAST)alert_reply, sizeof(alert_reply), 0); + AssertIntEQ(ret, sizeof(expected_alert_reply)); + AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, + sizeof(expected_alert_reply)), 0); + } +} +#endif + +static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl) +{ +#ifndef NO_MD5 + enum wc_HashType hashType = WC_HASH_TYPE_MD5; +#elif !defined(NO_SHA) + enum wc_HashType hashType = WC_HASH_TYPE_SHA; +#elif !defined(NO_SHA256) + enum wc_HashType hashType = WC_HASH_TYPE_SHA256; +#else + #error "We need a digest to hash the WOLFSSL object" +#endif + byte hashBuf[WC_MAX_DIGEST_SIZE]; + wc_HashAlg hash; + const TLSX* exts = ssl->extensions; + WOLFSSL sslCopy; /* Use a copy to omit certain fields */ +#ifndef WOLFSSL_SMALL_STACK_CACHE + HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in + * InitHandshakeHashes */ +#endif + + XMEMCPY(&sslCopy, ssl, sizeof(*ssl)); + XMEMSET(hashBuf, 0, sizeof(hashBuf)); + + /* Following fields are not important to compare */ + XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN); + sslCopy.buffers.inputBuffer.buffer = NULL; + sslCopy.buffers.inputBuffer.bufferSize = 0; + sslCopy.buffers.inputBuffer.dynamicFlag = 0; + sslCopy.buffers.inputBuffer.offset = 0; + XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN); + sslCopy.buffers.outputBuffer.buffer = NULL; + sslCopy.buffers.outputBuffer.bufferSize = 0; + sslCopy.buffers.outputBuffer.dynamicFlag = 0; + sslCopy.buffers.outputBuffer.offset = 0; + sslCopy.error = 0; + sslCopy.curSize = 0; + sslCopy.curStartIdx = 0; + sslCopy.keys.curSeq_lo = 0; + XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL)); +#ifdef WOLFSSL_DTLS13 + XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq)); + sslCopy.dtls13FastTimeout = 0; +#endif + sslCopy.keys.dtls_peer_handshake_number = 0; + XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history)); + sslCopy.hsHashes = NULL; +#if !defined(WOLFSSL_NO_CLIENT_AUTH) && \ + ((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \ + (defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \ + (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH))) + sslCopy.options.cacheMessages = 0; +#endif +#ifdef WOLFSSL_ASYNC_IO +#ifdef WOLFSSL_ASYNC_CRYPT + sslCopy.asyncDev = NULL; +#endif + sslCopy.async = NULL; +#endif + + AssertIntEQ(wc_HashInit(&hash, hashType), 0); + AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0); + /* hash extension list */ + while (exts != NULL) { + AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0); + exts = exts->next; + } + /* Hash suites */ + if (sslCopy.suites != NULL) { + AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites, + sizeof(struct Suites)), 0); + } + +#ifdef WOLFSSL_SMALL_STACK_CACHE + /* with WOLFSSL_SMALL_STACK_CACHE, the SHA-2 objects always differ after + * initialization because of cached W and (for SHA512) X buffers. + */ +#else + /* Hash hsHashes */ + AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes, + sizeof(*hsHashes)), 0); +#endif + + AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0); + AssertIntEQ(wc_HashFree(&hash, hashType), 0); + + return MakeWordFromHash(hashBuf); +} + +static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb; +static int test_wolfSSL_dtls_compare_stateless_cb_call_once; +static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl, + char *buf, int sz, void *ctx) +{ + if (test_wolfSSL_dtls_compare_stateless_cb_call_once) { + test_wolfSSL_dtls_compare_stateless_cb_call_once = 0; + return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx); + } + else { + return WOLFSSL_CBIO_ERR_WANT_READ; + } +} + +static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl) +{ + /* Compare the ssl object before and after one ClientHello msg */ + SOCKET_T fd = wolfSSL_get_fd(ssl); + int res; + int err; + word32 initHash; + + test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv; + test_wolfSSL_dtls_compare_stateless_cb_call_once = 1; + wolfSSL_dtls_set_using_nonblock(ssl, 1); + ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once; + + initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl); + (void)initHash; + + res = tcp_select(fd, 5); + /* We are expecting a msg. A timeout indicates failure. */ + AssertIntEQ(res, TEST_RECV_READY); + + res = wolfSSL_accept(ssl); + err = wolfSSL_get_error(ssl, res); + AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ); + + AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl)); + + wolfSSL_dtls_set_using_nonblock(ssl, 0); + ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb; + +} + +#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) +static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl) +{ + int ret; + ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0); + AssertIntEQ(ret, WOLFSSL_SUCCESS); + test_wolfSSL_dtls_compare_stateless(ssl); +} +#endif + +int test_wolfSSL_dtls_stateless(void) +{ + callback_functions client_cbs, server_cbs; + size_t i; + struct { + method_provider client_meth; + method_provider server_meth; + ssl_callback client_ssl_ready; + ssl_callback server_ssl_ready; + } test_params[] = { +#if !defined(WOLFSSL_NO_TLS12) + {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, + test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless}, +#endif +#if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE) + {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, + test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie}, + {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, + test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie}, +#endif + }; + + if (0 == sizeof(test_params)){ + return TEST_SKIPPED; + } + + for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) { + XMEMSET(&client_cbs, 0, sizeof(client_cbs)); + XMEMSET(&server_cbs, 0, sizeof(server_cbs)); + client_cbs.doUdp = server_cbs.doUdp = 1; + client_cbs.method = test_params[i].client_meth; + server_cbs.method = test_params[i].server_meth; + + client_cbs.ssl_ready = test_params[i].client_ssl_ready; + server_cbs.ssl_ready = test_params[i].server_ssl_ready; + test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs); + + if (!client_cbs.return_code) + return TEST_FAIL; + if (!server_cbs.return_code) + return TEST_FAIL; + } + + return TEST_SUCCESS; +} + +/* DTLS stateless API handling multiple CHs with different HRR groups */ +int test_wolfSSL_dtls_stateless_hrr_group(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_SEND_HRR_COOKIE) + size_t i; + word32 initHash; + struct { + method_provider client_meth; + method_provider server_meth; + } params[] = { +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method }, +#endif +#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS) + { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method }, +#endif + }; + for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) { + WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL; + WOLFSSL *ssl_s = NULL, *ssl_c = NULL, *ssl_c2 = NULL; + struct test_memio_ctx test_ctx; + int groups_1[] = { + WOLFSSL_ECC_SECP256R1, + WOLFSSL_ECC_SECP384R1, + WOLFSSL_ECC_SECP521R1 + }; + int groups_2[] = { + WOLFSSL_ECC_SECP384R1, + WOLFSSL_ECC_SECP521R1 + }; + char hrrBuf[1000]; + int hrrSz = sizeof(hrrBuf); + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + params[i].client_meth, params[i].server_meth), 0); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL, + params[i].client_meth, params[i].server_meth), 0); + + + wolfSSL_SetLoggingPrefix("server"); + wolfSSL_dtls_set_using_nonblock(ssl_s, 1); + + initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s); + + /* Set groups and disable key shares. This ensures that only the given + * groups are in the SupportedGroups extension and that an empty key + * share extension is sent in the initial ClientHello of each session. + * This triggers the server to send a HelloRetryRequest with the first + * group in the SupportedGroups extension selected. */ + wolfSSL_SetLoggingPrefix("client1"); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups_1, 3), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); + + wolfSSL_SetLoggingPrefix("client2"); + ExpectIntEQ(wolfSSL_set_groups(ssl_c2, groups_2, 2), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c2), WOLFSSL_SUCCESS); + + /* Start handshake, send first ClientHello */ + wolfSSL_SetLoggingPrefix("client1"); + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* Read first ClientHello, send HRR with WOLFSSL_ECC_SECP256R1 */ + wolfSSL_SetLoggingPrefix("server"); + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0); + ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrrBuf, &hrrSz, 0), 0); + ExpectIntGT(hrrSz, 0); + ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s)); + test_memio_clear_buffer(&test_ctx, 1); + + /* Send second ClientHello */ + wolfSSL_SetLoggingPrefix("client2"); + ExpectIntEQ(wolfSSL_connect(ssl_c2), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c2, -1), WOLFSSL_ERROR_WANT_READ); + + /* Read second ClientHello, send HRR now with WOLFSSL_ECC_SECP384R1 */ + wolfSSL_SetLoggingPrefix("server"); + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), 0); + ExpectIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl_s)); + test_memio_clear_buffer(&test_ctx, 1); + + /* Complete first handshake with WOLFSSL_ECC_SECP256R1 */ + wolfSSL_SetLoggingPrefix("client1"); + ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrrBuf, hrrSz), 0); + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + wolfSSL_SetLoggingPrefix("server"); + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_s); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_c2); + wolfSSL_CTX_free(ctx_s); + wolfSSL_CTX_free(ctx_c); + } +#endif /* WOLFSSL_SEND_HRR_COOKIE */ + return EXPECT_RESULT(); +} +#else +int test_wolfSSL_dtls_stateless(void) +{ + return TEST_SKIPPED; +} + +int test_wolfSSL_dtls_stateless_hrr_group(void) +{ + return TEST_SKIPPED; +} +#endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE && + * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */ + +/*----------------------------------------------------------------------------*/ +/* DTLS window updates, fragment buckets, stateless resume/downgrade, alerts */ +/*----------------------------------------------------------------------------*/ + +#ifdef WOLFSSL_DTLS + +/* Prints out the current window */ +static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) { +#ifdef WOLFSSL_DEBUG_DTLS_WINDOW + int i; + for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) { + word32 b = w[i]; + int j; + /* Prints out a 32 bit binary number in big endian order */ + for (j = 0; j < 32; j++, b <<= 1) { + if (b & (((word32)1) << 31)) + fprintf(stderr, "1"); + else + fprintf(stderr, "0"); + } + fprintf(stderr, " "); + } + fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l); +#else + (void)h; + (void)l; + (void)w; +#endif +} + +/* a - cur_hi + * b - cur_lo + * c - next_hi + * d - next_lo + * e - window + * f - expected next_hi + * g - expected next_lo + * h - expected window[1] + * i - expected window[0] + */ +#define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \ + ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \ + DUW_TEST_print_window_binary((a), (b), (e)); \ + ExpectIntEQ((c), (f)); \ + ExpectIntEQ((d), (g)); \ + ExpectIntEQ((e)[1], (h)); \ + ExpectIntEQ((e)[0], (i)); \ +} while (0) + +int test_wolfSSL_DtlsUpdateWindow(void) +{ + EXPECT_DECLS; + word32 window[WOLFSSL_DTLS_WINDOW_WORDS]; + word32 next_lo = 0; + word16 next_hi = 0; + +#ifdef WOLFSSL_DEBUG_DTLS_WINDOW + fprintf(stderr, "\n"); +#endif + + XMEMSET(window, 0, sizeof window); + DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01); + DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03); + DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31); + DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33); + DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01); + DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03); + DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01); + DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01); + DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01); + DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01); + DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05); + DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07); + DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71); + DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79); + DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01); + DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11); + DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19); + DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001); + DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005); + DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015); + DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151); + DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001); + DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001); + DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01); + DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11); + DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01); + DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01); + DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01); + DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01); + DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01); + DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01); + DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01); + + return EXPECT_RESULT(); +} +#else +int test_wolfSSL_DtlsUpdateWindow(void) +{ + return TEST_SKIPPED; +} +#endif /* WOLFSSL_DTLS */ + +#ifdef WOLFSSL_DTLS +static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset, + word32 f_len, word32 f_count, byte ready, word32 bytesReceived) +{ + EXPECT_DECLS; + DtlsMsg* cur = NULL; + static byte msg[100]; + static byte msgInit = 0; + + if (!msgInit) { + int i; + for (i = 0; i < 100; i++) + msg[i] = i + 1; + msgInit = 1; + } + + /* Sanitize test parameters */ + ExpectIntLE(len, sizeof(msg)); + ExpectIntLE(f_offset + f_len, sizeof(msg)); + + if (EXPECT_SUCCESS()) + DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL); + + ExpectNotNull(ssl->dtls_rx_msg_list); + + ExpectNotNull(cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)); + ExpectIntEQ(cur->fragBucketListCount, f_count); + ExpectIntEQ(cur->ready, ready); + ExpectIntEQ(cur->bytesReceived, bytesReceived); + if (ready) { + ExpectNull(cur->fragBucketList); + ExpectBufEQ(cur->fullMsg, msg, cur->sz); + } + else { + DtlsFragBucket* fb; + ExpectNotNull(cur->fragBucketList); + for (fb = cur != NULL ? cur->fragBucketList : NULL; + EXPECT_SUCCESS() && fb != NULL; fb = fb->m.m.next) + ExpectBufEQ(fb->buf, msg + fb->m.m.offset, fb->m.m.sz); + } + if (EXPECT_FAIL()) { + printf("Test parameters: seq %u len %u f_offset %u f_len %u f_count %u ready %u bytesReceived %u\n", + seq, len, f_offset, f_len, f_count, ready, bytesReceived); + } + return EXPECT_RESULT(); +} + +int test_wolfSSL_DTLS_fragment_buckets(void) +{ + EXPECT_DECLS; + WOLFSSL ssl[1]; + + XMEMSET(ssl, 0, sizeof(*ssl)); + + EXPECT_TEST(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100)); /* 0-100 */ + + EXPECT_TEST(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20)); /* 0-20 */ + EXPECT_TEST(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40)); /* 20-40 */ + EXPECT_TEST(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60)); /* 40-60 */ + EXPECT_TEST(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80)); /* 60-80 */ + EXPECT_TEST(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100)); /* 80-100 */ + + /* Test all permutations of 3 regions */ + /* 1 2 3 */ + EXPECT_TEST(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60)); /* 30-60 */ + EXPECT_TEST(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100)); /* 60-100 */ + /* 1 3 2 */ + EXPECT_TEST(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70)); /* 60-100 */ + EXPECT_TEST(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100)); /* 30-60 */ + /* 2 1 3 */ + EXPECT_TEST(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30)); /* 30-60 */ + EXPECT_TEST(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100)); /* 60-100 */ + /* 2 3 1 */ + EXPECT_TEST(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30)); /* 30-60 */ + EXPECT_TEST(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70)); /* 60-100 */ + EXPECT_TEST(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100)); /* 0-30 */ + /* 3 1 2 */ + EXPECT_TEST(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40)); /* 60-100 */ + EXPECT_TEST(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100)); /* 30-60 */ + /* 3 2 1 */ + EXPECT_TEST(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40)); /* 60-100 */ + EXPECT_TEST(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70)); /* 30-60 */ + EXPECT_TEST(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100)); /* 0-30 */ + + /* Test overlapping regions */ + EXPECT_TEST(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30)); /* 20-30 */ + EXPECT_TEST(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40)); /* 70-80 */ + EXPECT_TEST(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60)); /* 20-50 */ + EXPECT_TEST(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100)); /* 40-100 */ + + /* Test overlapping multiple regions */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20)); /* 0-20 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25)); /* 30-35 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30)); /* 40-45 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35)); /* 50-55 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40)); /* 60-65 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45)); /* 70-75 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55)); /* 30-55 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65)); /* 55-70 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90)); /* 75-100 */ + EXPECT_TEST(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100)); /* 10-35 */ + + EXPECT_TEST(DFB_TEST(ssl,10, 100, 0, 20, 1, 0, 20)); /* 0-20 */ + EXPECT_TEST(DFB_TEST(ssl,10, 100, 30, 20, 2, 0, 40)); /* 30-50 */ + EXPECT_TEST(DFB_TEST(ssl,10, 100, 0, 40, 1, 0, 50)); /* 0-40 */ + EXPECT_TEST(DFB_TEST(ssl,10, 100, 50, 50, 0, 1, 100)); /* 50-100 */ + + /* Test region between other regions */ + EXPECT_TEST(DFB_TEST(ssl,11, 100, 0, 20, 1, 0, 20)); /* 0-20 */ + EXPECT_TEST(DFB_TEST(ssl,11, 100, 80, 20, 2, 0, 40)); /* 80-100 */ + EXPECT_TEST(DFB_TEST(ssl,11, 100, 40, 20, 3, 0, 60)); /* 40-60 */ + EXPECT_TEST(DFB_TEST(ssl,11, 100, 20, 20, 2, 0, 80)); /* 20-40 */ + EXPECT_TEST(DFB_TEST(ssl,11, 100, 60, 20, 0, 1, 100)); /* 60-80 */ + + /* Test gap before first bucket (prev==NULL in gap-before branch) */ + EXPECT_TEST(DFB_TEST(ssl,12, 100, 50, 20, 1, 0, 20)); /* 50-70 */ + EXPECT_TEST(DFB_TEST(ssl,12, 100, 0, 20, 2, 0, 40)); /* 0-20 gap before first */ + EXPECT_TEST(DFB_TEST(ssl,12, 100, 20, 30, 1, 0, 70)); /* 20-50 bridges gap */ + EXPECT_TEST(DFB_TEST(ssl,12, 100, 70, 30, 0, 1, 100)); /* 70-100 */ + + /* Test fragment after message is already complete (ready early return) */ + EXPECT_TEST(DFB_TEST(ssl,13, 100, 0,100, 0, 1, 100)); /* 0-100 complete */ + EXPECT_TEST(DFB_TEST(ssl,13, 100, 0, 50, 0, 1, 100)); /* 0-50 dup on ready */ + + /* Test combine where next bucket is larger than cur (chosenBucket=&next) */ + EXPECT_TEST(DFB_TEST(ssl,14, 100, 0, 10, 1, 0, 10)); /* 0-10 */ + EXPECT_TEST(DFB_TEST(ssl,14, 100, 30, 50, 2, 0, 60)); /* 30-80 */ + EXPECT_TEST(DFB_TEST(ssl,14, 100, 5, 30, 1, 0, 80)); /* 5-35 next>cur */ + EXPECT_TEST(DFB_TEST(ssl,14, 100, 80, 20, 0, 1, 100)); /* 80-100 */ + + /* Test super fragment covering all existing buckets */ + EXPECT_TEST(DFB_TEST(ssl,15, 100, 10, 10, 1, 0, 10)); /* 10-20 */ + EXPECT_TEST(DFB_TEST(ssl,15, 100, 30, 10, 2, 0, 20)); /* 30-40 */ + EXPECT_TEST(DFB_TEST(ssl,15, 100, 60, 10, 3, 0, 30)); /* 60-70 */ + EXPECT_TEST(DFB_TEST(ssl,15, 100, 0,100, 0, 1, 100)); /* 0-100 super frag */ + + /* Test exact duplicate fragment */ + EXPECT_TEST(DFB_TEST(ssl,16, 100, 20, 40, 1, 0, 40)); /* 20-60 */ + EXPECT_TEST(DFB_TEST(ssl,16, 100, 20, 40, 1, 0, 40)); /* 20-60 exact dup */ + EXPECT_TEST(DFB_TEST(ssl,16, 100, 0, 20, 1, 0, 60)); /* 0-20 */ + EXPECT_TEST(DFB_TEST(ssl,16, 100, 60, 40, 0, 1, 100)); /* 60-100 */ + + /* Test combine bridging two buckets (combineNext, cur->data) */ + EXPECT_TEST(DFB_TEST(ssl,17, 100, 0, 30, 1, 0, 30)); /* 0-30 */ + EXPECT_TEST(DFB_TEST(ssl,17, 100, 60, 20, 2, 0, 50)); /* 60-80 */ + EXPECT_TEST(DFB_TEST(ssl,17, 100, 20, 45, 1, 0, 80)); /* 20-65 bridge */ + EXPECT_TEST(DFB_TEST(ssl,17, 100, 80, 20, 0, 1, 100)); /* 80-100 */ + + /* Test progressive left-extension with partial overlaps */ + EXPECT_TEST(DFB_TEST(ssl,18, 100, 70, 30, 1, 0, 30)); /* 70-100 */ + EXPECT_TEST(DFB_TEST(ssl,18, 100, 50, 30, 1, 0, 50)); /* 50-80 extend left */ + EXPECT_TEST(DFB_TEST(ssl,18, 100, 30, 30, 1, 0, 70)); /* 30-60 extend left */ + EXPECT_TEST(DFB_TEST(ssl,18, 100, 0, 40, 0, 1, 100)); /* 0-40 complete left */ + + DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap); + ssl->dtls_rx_msg_list = NULL; + ssl->dtls_rx_msg_list_sz = 0; + return EXPECT_RESULT(); +} + +#else +int test_wolfSSL_DTLS_fragment_buckets(void) +{ + return TEST_SKIPPED; +} +#endif + + +#if !defined(NO_FILESYSTEM) && \ + defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) + +int test_wolfSSL_dtls_stateless2(void) +{ + EXPECT_DECLS; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_c2 = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c2, NULL, + wolfDTLSv1_2_client_method, NULL), 0); + ExpectFalse(wolfSSL_is_stateful(ssl_s)); + /* send CH */ + ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_FAILURE); + ExpectFalse(wolfSSL_is_stateful(ssl_s)); + ExpectIntNE(test_ctx.c_len, 0); + /* consume HRR */ + test_memio_clear_buffer(&test_ctx, 1); + /* send CH1 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); + ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), + WOLFSSL_ERROR_WANT_READ); + /* send HRR */ + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_FAILURE); + /* send CH2 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR); + ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR), + WOLFSSL_ERROR_WANT_READ); + /* send HRR */ + ExpectIntEQ(wolfDTLS_accept_stateless(ssl_s), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + ExpectTrue(wolfSSL_is_stateful(ssl_s)); + + wolfSSL_free(ssl_c2); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + return EXPECT_RESULT(); +} + +int test_wolfSSL_dtls_stateless_maxfrag(void) +{ + EXPECT_DECLS; +#ifdef HAVE_MAX_FRAGMENT + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_c2 = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + word16 max_fragment = 0; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + ExpectNotNull(ssl_s); + ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c)); + ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8), + WOLFSSL_SUCCESS); + wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx); + wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx); + if (EXPECT_SUCCESS()) { + max_fragment = ssl_s->max_fragment; + } + /* send CH */ + ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); + /* CH without cookie shouldn't change state */ + ExpectIntEQ(ssl_s->max_fragment, max_fragment); + ExpectIntNE(test_ctx.c_len, 0); + + /* consume HRR from buffer */ + test_memio_clear_buffer(&test_ctx, 1); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c2); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif /* HAVE_MAX_FRAGMENT */ + return EXPECT_RESULT(); +} + +#if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME) +#define ROUNDS_WITH_HVR 4 +#define ROUNDS_WITHOUT_HVR 2 +#define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ +static int buf_is_hvr(const byte *data, int len) +{ + if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ) + return 0; + return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request; +} + +static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad) +{ + EXPECT_DECLS; + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + WOLFSSL_SESSION *sess = NULL; + int round_trips; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, + &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); +#ifdef HAVE_SESSION_TICKET + if (useticket) { + ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS); + } +#endif + round_trips = ROUNDS_WITH_HVR; + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips, + &round_trips), 0); + ExpectIntEQ(round_trips, ROUNDS_WITH_HVR); + ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); + wolfSSL_shutdown(ssl_c); + wolfSSL_shutdown(ssl_s); + wolfSSL_free(ssl_c); + ssl_c = NULL; + wolfSSL_free(ssl_s); + ssl_s = NULL; + + test_memio_clear_buffer(&test_ctx, 1); + test_memio_clear_buffer(&test_ctx, 0); + /* make resumption invalid */ + if (bad && (sess != NULL)) { + if (useticket) { +#ifdef HAVE_SESSION_TICKET + if (sess->ticket != NULL) { + sess->ticket[0] = !sess->ticket[0]; + } +#endif /* HAVE_SESSION_TICKET */ + } + else { + sess->sessionID[0] = !sess->sessionID[0]; + } + } + ExpectNotNull(ssl_c = wolfSSL_new(ctx_c)); + ExpectNotNull(ssl_s = wolfSSL_new(ctx_s)); + wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx); + wolfSSL_SetIOReadCtx(ssl_c, &test_ctx); + wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx); + wolfSSL_SetIOReadCtx(ssl_s, &test_ctx); + ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); + ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len)); + ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len)); + if (!useticket) { + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0); + ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1); + ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1); + } + wolfSSL_SESSION_free(sess); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + return EXPECT_RESULT(); +} + +int test_wolfSSL_dtls_stateless_resume(void) +{ + EXPECT_DECLS; +#ifdef HAVE_SESSION_TICKET + ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS); + ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS); +#endif /* HAVE_SESION_TICKET */ + ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS); + ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS); + return EXPECT_RESULT(); +} +#else +int test_wolfSSL_dtls_stateless_resume(void) +{ + return TEST_SKIPPED; +} +#endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */ + +int test_wolfSSL_dtls_stateless_downgrade(void) +{ + EXPECT_DECLS; +#if !defined(NO_OLD_TLS) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_c2 = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_c2 = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1), + WOLFSSL_SUCCESS); + ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method())); + wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb); + wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb); + ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2)); + wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx); + wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx); + /* send CH */ + ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); + ExpectIntNE(test_ctx.c_len, 0); + /* consume HRR */ + test_memio_clear_buffer(&test_ctx, 1); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c2); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_c2); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +#else /* outer wrap: WOLFSSL_DTLS && !WOLFSSL_NO_TLS12 && client/server && !NO_RSA */ +int test_wolfSSL_dtls_stateless2(void) +{ + return TEST_SKIPPED; +} +int test_wolfSSL_dtls_stateless_maxfrag(void) +{ + return TEST_SKIPPED; +} +int test_wolfSSL_dtls_stateless_resume(void) +{ + return TEST_SKIPPED; +} +int test_wolfSSL_dtls_stateless_downgrade(void) +{ + return TEST_SKIPPED; +} +#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/ + +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) +int test_WOLFSSL_dtls_version_alert(void) +{ + EXPECT_DECLS; + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0); + + /* client hello */ + ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); + /* hrr */ + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); + /* client hello 1 */ + ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ))); + /* server hello */ + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ))); + /* should fail */ + ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR))); + /* shuould fail */ + ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) && + (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR))); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + + return EXPECT_RESULT(); +} +#else +int test_WOLFSSL_dtls_version_alert(void) +{ + return TEST_SKIPPED; +} +#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && + * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && + * !defined(NO_OLD_TLS) && !defined(NO_RSA) + */ + +/*----------------------------------------------------------------------------*/ +/* Remaining DTLS tests moved out of api.c (msg, ipv6, downgrade, ccs, etc.) */ +/*----------------------------------------------------------------------------*/ + +/*-- msg_helpers_and_from_other_peer (api.c lines 30572,30671) ---*/ +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + !defined(SINGLE_THREADED) && !defined(NO_RSA) + +static int test_dtls_msg_get_connected_port(int fd, word16 *port) +{ + SOCKADDR_S peer; + XSOCKLENT len; + int ret; + + XMEMSET((byte*)&peer, 0, sizeof(peer)); + len = sizeof(peer); + ret = getpeername(fd, (SOCKADDR*)&peer, &len); + if (ret != 0 || len > (XSOCKLENT)sizeof(peer)) + return -1; + switch (peer.ss_family) { +#ifdef WOLFSSL_IPV6 + case WOLFSSL_IP6: { + *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port); + break; + } +#endif /* WOLFSSL_IPV6 */ + case WOLFSSL_IP4: + *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port); + break; + default: + return -1; + } + return 0; +} + +static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl) +{ + char buf[1] = {'t'}; + SOCKADDR_IN_T addr; + int sock_fd; + word16 port; + int err; + + (void)ssl; + (void)ctx; + + if (ssl == NULL) + return -1; + + err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port); + if (err != 0) + return -1; + + sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0); + if (sock_fd == -1) + return -1; + build_addr(&addr, wolfSSLIP, port, 1, 0); + + /* send a packet to the server. Being another socket, the kernel will ensure + * the source port will be different. */ + err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr, + sizeof(addr)); + + close(sock_fd); + if (err == -1) + return -1; + + return 0; +} + +/* setup a SSL session but just after the handshake send a packet to the server + * with a source address different than the one of the connected client. The I/O + * callback EmbedRecvFrom should just ignore the packet. Sending of the packet + * is done in test_dtls_msg_from_other_peer_cb */ +int test_dtls_msg_from_other_peer(void) +{ + EXPECT_DECLS; + callback_functions client_cbs; + callback_functions server_cbs; + + XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs)); + XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs)); + + client_cbs.method = wolfDTLSv1_2_client_method; + server_cbs.method = wolfDTLSv1_2_server_method; + client_cbs.doUdp = 1; + server_cbs.doUdp = 1; + + test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs, + test_dtls_msg_from_other_peer_cb); + + ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS); + ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS); + + return EXPECT_RESULT(); +} +#else +int test_dtls_msg_from_other_peer(void) +{ + return TEST_SKIPPED; +} +#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + * !defined(SINGLE_THREADED) && !defined(NO_RSA) */ + +/*-- ipv6_check (api.c lines 30672,30730) ---*/ +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) \ + && !defined(USE_WINDOWS_API) +int test_dtls_ipv6_check(void) +{ + EXPECT_DECLS; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + SOCKADDR_IN fake_addr6; + int sockfd = -1; + + ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method())); + ExpectNotNull(ssl_c = wolfSSL_new(ctx_c)); + ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method())); + ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile, + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile, + WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + ExpectNotNull(ssl_s = wolfSSL_new(ctx_s)); + XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6)); + /* mimic a sockaddr_in6 struct, this way we can't test without + * WOLFSSL_IPV6 */ + fake_addr6.sin_family = WOLFSSL_IP6; + ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1); + ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS); + /* can't return error here, as the peer is opaque for wolfssl library at + * this point */ + ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)), + WOLFSSL_SUCCESS); + ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1); + wolfSSL_dtls_set_using_nonblock(ssl_c, 1); + ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); + + ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)), + WOLFSSL_SUCCESS); + /* reuse the socket */ + ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS); + wolfSSL_dtls_set_using_nonblock(ssl_s, 1); + ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS); + ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E)); + if (sockfd != -1) + close(sockfd); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); + return EXPECT_RESULT(); +} +#else +int test_dtls_ipv6_check(void) +{ + return TEST_SKIPPED; +} +#endif + +/*-- no_extensions (api.c lines 30824,30913) ---*/ +int test_dtls_no_extensions(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL *ssl_s = NULL; + WOLFSSL_CTX *ctx_s = NULL; + struct test_memio_ctx test_ctx; + const byte chNoExtensions[] = { + /* Handshake type */ + 0x16, + /* Version */ + 0xfe, 0xff, + /* Epoch */ + 0x00, 0x00, + /* Seq number */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* Length */ + 0x00, 0x40, + /* CH type */ + 0x01, + /* Length */ + 0x00, 0x00, 0x34, + /* Msg Seq */ + 0x00, 0x00, + /* Frag offset */ + 0x00, 0x00, 0x00, + /* Frag length */ + 0x00, 0x00, 0x34, + /* Version */ + 0xfe, 0xff, + /* Random */ + 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37, + 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b, + 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d, + /* Session Length */ + 0x00, + /* Cookie Length */ + 0x00, + /* CS Length */ + 0x00, 0x0c, + /* CS */ + 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33, + /* Comp Meths Length */ + 0x01, + /* Comp Meths */ + 0x00 + /* And finally... no extensions */ + }; + int i; +#ifdef OPENSSL_EXTRA + int repeats = 2; +#else + int repeats = 1; +#endif + + for (i = 0; i < repeats; i++) { + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ssl_s = NULL; + ctx_s = NULL; + + ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s, + NULL, wolfDTLS_server_method), 0); + + test_memio_clear_buffer(&test_ctx, 0); + ExpectIntEQ( + test_memio_inject_message(&test_ctx, 1, + (const char *)chNoExtensions, sizeof(chNoExtensions)), 0); + + +#ifdef OPENSSL_EXTRA + if (i > 0) { + ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION), + WOLFSSL_SUCCESS); + } +#endif + + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Expecting a handshake msg. Either HVR or SH. */ + ExpectIntGT(test_ctx.c_len, 0); + ExpectIntEQ(test_ctx.c_buff[0], 0x16); + + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); + } +#endif + return EXPECT_RESULT(); +} + +/*-- dtls_1_0_hvr_downgrade (api.c lines 31038,31073) ---*/ +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) +static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx) +{ + AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), + WOLFSSL_SUCCESS); +} + +int test_dtls_1_0_hvr_downgrade(void) +{ + EXPECT_DECLS; + callback_functions func_cb_client; + callback_functions func_cb_server; + + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_client.method = wolfDTLS_client_method; + func_cb_server.method = wolfDTLSv1_2_server_method; + func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); + ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); + + return EXPECT_RESULT(); +} +#else +int test_dtls_1_0_hvr_downgrade(void) +{ + EXPECT_DECLS; + return EXPECT_RESULT(); +} +#endif + +/*-- downgrade_scr_server (api.c lines 31230,31293) ---*/ +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION) +static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx) +{ + AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), + WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); +} + +static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx) +{ + AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); +} + +static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl) +{ + char testMsg[] = "Message after SCR"; + char msgBuf[sizeof(testMsg)]; + if (wolfSSL_is_server(ssl)) { + AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY)); + AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); + AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), + sizeof(testMsg)); + } + else { + AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), + sizeof(testMsg)); + AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); + } +} + +int test_dtls_downgrade_scr_server(void) +{ + EXPECT_DECLS; + callback_functions func_cb_client; + callback_functions func_cb_server; + + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_client.method = wolfDTLSv1_2_client_method; + func_cb_server.method = wolfDTLS_server_method; + func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready; + func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server; + func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result; + func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); + ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); + + return EXPECT_RESULT(); +} +#else +int test_dtls_downgrade_scr_server(void) +{ + EXPECT_DECLS; + return EXPECT_RESULT(); +} +#endif + +/*-- downgrade_scr (api.c lines 31295,31352) ---*/ +#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION) +static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx) +{ + AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2), + WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS); +} + +static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl) +{ + char testMsg[] = "Message after SCR"; + char msgBuf[sizeof(testMsg)]; + if (wolfSSL_is_server(ssl)) { + AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)); + AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY)); + AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); + AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), + sizeof(testMsg)); + } + else { + AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)), + sizeof(testMsg)); + AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf)); + } +} + +int test_dtls_downgrade_scr(void) +{ + EXPECT_DECLS; + callback_functions func_cb_client; + callback_functions func_cb_server; + + XMEMSET(&func_cb_client, 0, sizeof(callback_functions)); + XMEMSET(&func_cb_server, 0, sizeof(callback_functions)); + + func_cb_client.doUdp = func_cb_server.doUdp = 1; + func_cb_client.method = wolfDTLS_client_method; + func_cb_server.method = wolfDTLSv1_2_server_method; + func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready; + func_cb_client.on_result = test_dtls_downgrade_scr_on_result; + func_cb_server.on_result = test_dtls_downgrade_scr_on_result; + + test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server); + + ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS); + ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS); + + return EXPECT_RESULT(); +} +#else +int test_dtls_downgrade_scr(void) +{ + EXPECT_DECLS; + return EXPECT_RESULT(); +} +#endif + +/*-- client_hello_timeout_downgrade_with_helper (api.c lines 31354,31490) ---*/ +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && !defined(WOLFSSL_NO_TLS12) + +static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl, + char *data, int sz, void *ctx) +{ + static int call_counter = 0; + call_counter++; + (void)ssl; + (void)data; + (void)sz; + (void)ctx; + switch (call_counter) { + case 1: + case 2: + return WOLFSSL_CBIO_ERR_TIMEOUT; + case 3: + return WOLFSSL_CBIO_ERR_WANT_READ; + default: + AssertIntLE(call_counter, 3); + return -1; + } +} +#endif + +/* Make sure we don't send acks before getting a server hello */ +int test_dtls_client_hello_timeout_downgrade(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && !defined(WOLFSSL_NO_TLS12) + + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + DtlsRecordLayerHeader* dtlsRH; + size_t len; + byte sequence_number[8]; + int i; + + for (i = 0; i < 2; i++) { + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0); + + if (i == 0) { + /* First time simulate timeout in IO layer */ + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* SH flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Drop the SH */ + if (EXPECT_SUCCESS()) { + ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); + } + /* Read the remainder of the flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + wolfSSL_SSLSetIORecv(ssl_c, + test_dtls_client_hello_timeout_downgrade_read_cb); + /* CH3 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb); + } + else { + /* Second time call wolfSSL_dtls_got_timeout */ + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* SH flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Drop the SH */ + if (EXPECT_SUCCESS()) { + ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); + } + /* Read the remainder of the flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Quick timeout should be set as we received at least one msg */ + ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + /* Quick timeout should be cleared after a quick timeout */ + /* CH3 */ + ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + } + + /* Parse out to make sure we got exactly one ClientHello message */ + XMEMSET(&sequence_number, 0, sizeof(sequence_number)); + /* Second ClientHello after HVR */ + sequence_number[7] = 2; + dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff; + ExpectIntEQ(dtlsRH->type, handshake); + ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); + ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); + ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, + sizeof(sequence_number)), 0); + len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); + ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); + + /* Connection should be able to continue */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + ssl_c = NULL; + ssl_s = NULL; + ctx_c = NULL; + ctx_s = NULL; + if (!EXPECT_SUCCESS()) + break; + } + +#endif + return EXPECT_RESULT(); +} + +/*-- client_hello_timeout_with_helper (api.c lines 31492,31581) ---*/ +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) +static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data, + int sz, void *ctx) +{ + static int call_counter = 0; + call_counter++; + (void)ssl; + (void)data; + (void)sz; + (void)ctx; + switch (call_counter) { + case 1: + return WOLFSSL_CBIO_ERR_TIMEOUT; + case 2: + return WOLFSSL_CBIO_ERR_WANT_READ; + default: + AssertIntLE(call_counter, 2); + return -1; + } +} +#endif + +/* Make sure we don't send acks before getting a server hello */ +int test_dtls_client_hello_timeout(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL *ssl_c = NULL; + WOLFSSL_CTX *ctx_c = NULL; + struct test_memio_ctx test_ctx; + DtlsRecordLayerHeader* dtlsRH; + size_t idx; + size_t len; + byte sequence_number[8]; + int i; + + for (i = 0; i < 2; i++) { + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL, + wolfDTLSv1_3_client_method, NULL), 0); + + if (i == 0) { + /* First time simulate timeout in IO layer */ + wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb); + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + } + else { + /* Second time call wolfSSL_dtls_got_timeout */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + } + + /* Parse out to make sure we got exactly two ClientHello messages */ + idx = 0; + XMEMSET(&sequence_number, 0, sizeof(sequence_number)); + /* First ClientHello */ + dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx); + ExpectIntEQ(dtlsRH->type, handshake); + ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); + ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); + ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, + sizeof(sequence_number)), 0); + len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); + ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); + idx += sizeof(DtlsRecordLayerHeader) + len; + /* Second ClientHello */ + sequence_number[7] = 1; + dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx); + ExpectIntEQ(dtlsRH->type, handshake); + ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); + ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); + ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, + sizeof(sequence_number)), 0); + len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); + ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + ssl_c = NULL; + ctx_c = NULL; + if (!EXPECT_SUCCESS()) + break; + } + +#endif + return EXPECT_RESULT(); +} + +/*-- dropped_ccs (api.c lines 31584,31648) ---*/ +int test_dtls_dropped_ccs(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ + && !defined(WOLFSSL_NO_TLS12) + + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + DtlsRecordLayerHeader* dtlsRH; + size_t len; + byte data[1]; + + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server ccs + finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); + + /* Drop the ccs */ + dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff; + len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]); + ExpectIntEQ(len, 1); + ExpectIntEQ(dtlsRH->type, change_cipher_spec); + if (EXPECT_SUCCESS()) { + ExpectIntEQ(test_memio_drop_message(&test_ctx, 1, 0), 0); + } + + /* Client rtx flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + /* Server ccs + finished rtx */ + ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client processes finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- seq_num_downgrade_with_helper (api.c lines 31650,31722) ---*/ +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ + && !defined(WOLFSSL_NO_TLS12) +static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen, + byte seq_num) +{ + EXPECT_DECLS; + DtlsRecordLayerHeader* dtlsRH; + byte sequence_number[8]; + + XMEMSET(&sequence_number, 0, sizeof(sequence_number)); + + ExpectIntGE(ioBufLen, sizeof(*dtlsRH)); + dtlsRH = (DtlsRecordLayerHeader*)ioBuf; + ExpectIntEQ(dtlsRH->type, handshake); + ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); + ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); + sequence_number[7] = seq_num; + ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, + sizeof(sequence_number)), 0); + + return EXPECT_RESULT(); +} +#endif + +/* + * Make sure that we send the correct sequence number after a HelloVerifyRequest + * and after a HelloRetryRequest. This is testing the server side as it is + * operating statelessly and should copy the sequence number of the ClientHello. + */ +int test_dtls_seq_num_downgrade(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ + && !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff, + test_ctx.s_len, 0), TEST_SUCCESS); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff, + test_ctx.c_len, 0), TEST_SUCCESS); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff, + test_ctx.s_len, 1), TEST_SUCCESS); + /* Server first flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff, + test_ctx.c_len, 1), TEST_SUCCESS); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- old_seq_number (api.c lines 31953,32005) ---*/ +int test_dtls_old_seq_number(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client second flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Modify the sequence number */ + { + DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff; + XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number)); + } + /* Server second flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Server should not do anything as a pkt was dropped */ + ExpectIntEQ(test_ctx.c_len, 0); + ExpectIntEQ(test_ctx.s_len, 0); + /* Trigger rtx */ + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + + /* Complete connection */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- dtls12_missing_finished (api.c lines 32007,32068) ---*/ +int test_dtls12_missing_finished(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ + !defined(WOLFSSL_NO_TLS12) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char test_str[] = "test string"; + char test_buf[sizeof(test_str)]; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HVR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); + /* Let's clear the output */ + test_memio_clear_buffer(&test_ctx, 1); + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), + sizeof(test_str)); + /* Client should not error out on a missing finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server rtx second flight with finished */ + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1); + /* Client process rest of handshake */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); + + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), + sizeof(test_str)); + ExpectIntEQ(wolfSSL_read(ssl_c, test_buf, sizeof(test_buf)), + sizeof(test_str)); + ExpectBufEQ(test_buf, test_str, sizeof(test_str)); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ + defined(WOLFSSL_SESSION_EXPORT) && defined(HAVE_ENCRYPT_THEN_MAC) && \ + !defined(WOLFSSL_AEAD_ONLY) && !defined(WOLFSSL_NO_TLS12) && \ + !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \ + !defined(NO_SHA256) && defined(HAVE_ECC) +/* Dummy peer callbacks so the DTLS exporter/importer has peer information to + * work with (the library requires these unless built with + * WOLFSSL_SESSION_EXPORT_NOPEER). */ +static int test_dtls_export_etm_get_peer(WOLFSSL* ssl, char* ip, int* ipSz, + unsigned short* port, int* fam) +{ + (void)ssl; + ip[0] = -1; + *ipSz = 1; + *port = 1; + *fam = 2; + return 1; +} + +static int test_dtls_export_etm_set_peer(WOLFSSL* ssl, char* ip, int ipSz, + unsigned short port, int fam) +{ + (void)ssl; + if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2) + return 0; + return 1; +} +#endif + +/* Regression test for DTLS session export/import dropping the Encrypt-Then-MAC + * options. Historically the ETM option fields were only serialized for TLS, so + * a re-imported DTLS session lost the negotiated ETM state and broke the record + * layer. Establish a DTLS 1.2 connection with a CBC cipher suite (where ETM + * applies), export the session, re-import it into a fresh WOLFSSL, and confirm + * the ETM option fields survive the round trip. */ +int test_dtls12_export_import_etm(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) && \ + defined(WOLFSSL_SESSION_EXPORT) && defined(HAVE_ENCRYPT_THEN_MAC) && \ + !defined(WOLFSSL_AEAD_ONLY) && !defined(WOLFSSL_NO_TLS12) && \ + !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \ + !defined(NO_SHA256) && defined(HAVE_ECC) + /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - a CBC suite, where ETM applies. */ + const char* cbcSuite = "ECDHE-RSA-AES128-SHA256"; + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + WOLFSSL *ssl_imp = NULL; + struct test_memio_ctx test_ctx; + unsigned char* session = NULL; + unsigned int sessionSz = 0; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0); + ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, cbcSuite), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, cbcSuite), WOLFSSL_SUCCESS); + + /* The exporter/importer needs peer info callbacks. */ + wolfSSL_CTX_SetIOGetPeer(ctx_s, test_dtls_export_etm_get_peer); + wolfSSL_CTX_SetIOSetPeer(ctx_s, test_dtls_export_etm_set_peer); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + /* Sanity: the handshake itself negotiated ETM on both sides. */ + if (ssl_c != NULL) + ExpectIntEQ(ssl_c->options.encThenMac, 1); + if (ssl_s != NULL) + ExpectIntEQ(ssl_s->options.encThenMac, 1); + + /* Export the server's DTLS session. */ + ExpectIntGE(wolfSSL_dtls_export(ssl_s, NULL, &sessionSz), 0); + ExpectIntGT(sessionSz, 0); + ExpectNotNull(session = (unsigned char*)XMALLOC(sessionSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER)); + ExpectIntGE(wolfSSL_dtls_export(ssl_s, session, &sessionSz), 0); + + /* Import into a fresh WOLFSSL and confirm the ETM state survived. */ + ExpectNotNull(ssl_imp = wolfSSL_new(ctx_s)); + ExpectIntGE(wolfSSL_dtls_import(ssl_imp, session, sessionSz), 0); + if (ssl_imp != NULL) { + /* Regression check: pre-fix these were all reset to 0 for DTLS. */ + ExpectIntEQ(ssl_imp->options.encThenMac, 1); + ExpectIntEQ(ssl_imp->options.startedETMRead, 1); + ExpectIntEQ(ssl_imp->options.startedETMWrite, 1); + ExpectIntEQ(ssl_imp->options.disallowEncThenMac, 0); + } + + XFREE(session, NULL, DYNAMIC_TYPE_TMP_BUFFER); + wolfSSL_free(ssl_imp); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_dtls.h b/tests/api/test_dtls.h index 823b9b9f45..fd22d125bf 100644 --- a/tests/api/test_dtls.h +++ b/tests/api/test_dtls.h @@ -23,15 +23,8 @@ #define TESTS_API_DTLS_H int test_dtls12_basic_connection_id(void); -int test_dtls13_basic_connection_id(void); -int test_dtls13_hrr_want_write(void); -int test_dtls13_every_write_want_write(void); int test_wolfSSL_dtls_cid_parse(void); int test_wolfSSL_dtls_set_pending_peer(void); -int test_dtls13_epochs(void); -int test_dtls13_ack_order(void); -int test_dtls13_ack_overflow(void); -int test_dtls13_ack_dup_write_counter(void); int test_dtls_version_checking(void); int test_dtls_short_ciphertext(void); int test_dtls12_record_length_mismatch(void); @@ -41,34 +34,56 @@ int test_dtls13_short_read(void); int test_records_span_network_boundaries(void); int test_dtls_record_cross_boundaries(void); int test_dtls_rtx_across_epoch_change(void); -int test_dtls13_ch2_rtx_no_ch1(void); -int test_dtls13_frag_ch2_with_ch1_rtx(void); int test_dtls_drop_client_ack(void); int test_dtls_bogus_finished_epoch_zero(void); int test_dtls_replay(void); -int test_dtls_srtp(void); int test_dtls_timeout(void); int test_dtls_certreq_order(void); int test_dtls_memio_wolfio(void); int test_dtls_memio_wolfio_stateless(void); int test_dtls_mtu_fragment_headroom(void); int test_dtls_mtu_split_messages(void); -int test_dtls13_min_rtx_interval(void); -int test_dtls13_no_session_id_echo(void); -int test_dtls13_5_9_0_compat(void); int test_dtls_set_session_min_downgrade(void); +int test_dtls12_export_import_etm(void); + +/* DTLS tests moved out of tests/api.c. */ +int test_dtls_msg_from_other_peer(void); +int test_dtls_ipv6_check(void); +int test_dtls_no_extensions(void); +int test_dtls_1_0_hvr_downgrade(void); +int test_dtls_downgrade_scr_server(void); +int test_dtls_downgrade_scr(void); +int test_dtls_client_hello_timeout_downgrade(void); +int test_dtls_client_hello_timeout(void); +int test_dtls_dropped_ccs(void); +int test_dtls_seq_num_downgrade(void); +int test_dtls_old_seq_number(void); +int test_dtls12_missing_finished(void); +int test_wolfSSL_dtls_export(void); +int test_wolfSSL_dtls_export_peers(void); +int test_wolfSSL_dtls_import_state_extra_window_words(void); +int test_wolfSSL_DTLS_either_side(void); +int test_generate_cookie(void); +int test_wolfSSL_dtls_set_mtu(void); +int test_wolfSSL_dtls_plaintext(void); +int test_wolfSSL_dtls_fragments(void); +int test_wolfSSL_ignore_alert_before_cookie(void); +int test_wolfSSL_dtls_bad_record(void); +int test_wolfSSL_dtls_AEAD_limit(void); +int test_wolfSSL_dtls_stateless(void); +int test_wolfSSL_dtls_stateless_hrr_group(void); +int test_wolfSSL_DtlsUpdateWindow(void); +int test_wolfSSL_DTLS_fragment_buckets(void); +int test_wolfSSL_dtls_stateless2(void); +int test_wolfSSL_dtls_stateless_maxfrag(void); +int test_wolfSSL_dtls_stateless_resume(void); +int test_wolfSSL_dtls_stateless_downgrade(void); +int test_WOLFSSL_dtls_version_alert(void); #define TEST_DTLS_DECLS \ TEST_DECL_GROUP("dtls", test_dtls12_basic_connection_id), \ - TEST_DECL_GROUP("dtls", test_dtls13_basic_connection_id), \ - TEST_DECL_GROUP("dtls", test_dtls13_hrr_want_write), \ - TEST_DECL_GROUP("dtls", test_dtls13_every_write_want_write), \ TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_cid_parse), \ TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_set_pending_peer), \ - TEST_DECL_GROUP("dtls", test_dtls13_epochs), \ - TEST_DECL_GROUP("dtls", test_dtls13_ack_order), \ - TEST_DECL_GROUP("dtls", test_dtls13_ack_overflow), \ - TEST_DECL_GROUP("dtls", test_dtls13_ack_dup_write_counter), \ TEST_DECL_GROUP("dtls", test_dtls_version_checking), \ TEST_DECL_GROUP("dtls", test_dtls_short_ciphertext), \ TEST_DECL_GROUP("dtls", test_dtls12_record_length_mismatch), \ @@ -78,20 +93,47 @@ int test_dtls_set_session_min_downgrade(void); TEST_DECL_GROUP("dtls", test_records_span_network_boundaries), \ TEST_DECL_GROUP("dtls", test_dtls_record_cross_boundaries), \ TEST_DECL_GROUP("dtls", test_dtls_rtx_across_epoch_change), \ - TEST_DECL_GROUP("dtls", test_dtls13_ch2_rtx_no_ch1), \ - TEST_DECL_GROUP("dtls", test_dtls13_frag_ch2_with_ch1_rtx), \ TEST_DECL_GROUP("dtls", test_dtls_drop_client_ack), \ TEST_DECL_GROUP("dtls", test_dtls_bogus_finished_epoch_zero), \ TEST_DECL_GROUP("dtls", test_dtls_replay), \ - TEST_DECL_GROUP("dtls", test_dtls_srtp), \ TEST_DECL_GROUP("dtls", test_dtls_certreq_order), \ TEST_DECL_GROUP("dtls", test_dtls_timeout), \ TEST_DECL_GROUP("dtls", test_dtls_memio_wolfio), \ TEST_DECL_GROUP("dtls", test_dtls_mtu_fragment_headroom), \ TEST_DECL_GROUP("dtls", test_dtls_mtu_split_messages), \ TEST_DECL_GROUP("dtls", test_dtls_memio_wolfio_stateless), \ - TEST_DECL_GROUP("dtls", test_dtls13_min_rtx_interval), \ - TEST_DECL_GROUP("dtls", test_dtls13_no_session_id_echo), \ TEST_DECL_GROUP("dtls", test_dtls_set_session_min_downgrade), \ - TEST_DECL_GROUP("dtls", test_dtls13_5_9_0_compat) + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_export), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_export_peers), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_import_state_extra_window_words), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_DTLS_either_side), \ + TEST_DECL_GROUP("dtls", test_generate_cookie), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_set_mtu), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_plaintext), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_fragments), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_ignore_alert_before_cookie), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_bad_record), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_AEAD_limit), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless_hrr_group), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_DtlsUpdateWindow), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_DTLS_fragment_buckets), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless2), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless_maxfrag), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless_resume), \ + TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_stateless_downgrade), \ + TEST_DECL_GROUP("dtls", test_WOLFSSL_dtls_version_alert), \ + TEST_DECL_GROUP("dtls", test_dtls_msg_from_other_peer), \ + TEST_DECL_GROUP("dtls", test_dtls_ipv6_check), \ + TEST_DECL_GROUP("dtls", test_dtls_no_extensions), \ + TEST_DECL_GROUP("dtls", test_dtls_1_0_hvr_downgrade), \ + TEST_DECL_GROUP("dtls", test_dtls_downgrade_scr_server), \ + TEST_DECL_GROUP("dtls", test_dtls_downgrade_scr), \ + TEST_DECL_GROUP("dtls", test_dtls_client_hello_timeout_downgrade), \ + TEST_DECL_GROUP("dtls", test_dtls_client_hello_timeout), \ + TEST_DECL_GROUP("dtls", test_dtls_dropped_ccs), \ + TEST_DECL_GROUP("dtls", test_dtls_seq_num_downgrade), \ + TEST_DECL_GROUP("dtls", test_dtls_old_seq_number), \ + TEST_DECL_GROUP("dtls", test_dtls12_missing_finished), \ + TEST_DECL_GROUP("dtls", test_dtls12_export_import_etm) #endif /* TESTS_API_DTLS_H */ diff --git a/tests/api/test_dtls13.c b/tests/api/test_dtls13.c new file mode 100644 index 0000000000..1716fd439d --- /dev/null +++ b/tests/api/test_dtls13.c @@ -0,0 +1,1781 @@ +/* test_dtls13.c + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include + +#ifdef NO_INLINE + #include +#else + #define WOLFSSL_MISC_INCLUDED + #include +#endif + +#include +#include +#include +#include +#include + +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + + +int test_dtls13_bad_epoch_ch(void) +{ + EXPECT_DECLS; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const int EPOCH_OFF = 3; + int groups[] = { + WOLFSSL_ECC_SECP256R1, + WOLFSSL_ECC_SECP384R1, + }; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* disable hrr cookie so we can later check msgsReceived.got_client_hello + * with just one message */ + ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); + + /* Set client groups to traditional only to avoid CH fragmentation */ + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 2), WOLFSSL_SUCCESS); + + ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WOLFSSL_ERROR_WANT_READ); + + ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2); + + /* first CH should use epoch 0x0 */ + ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) && + (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0)); + + /* change epoch to 2 */ + test_ctx.s_buff[EPOCH_OFF + 1] = 0x2; + + ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)), + WOLFSSL_ERROR_WANT_READ); + + ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1); + + /* resend the CH */ + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); + + return EXPECT_RESULT(); +} +#else +int test_dtls13_bad_epoch_ch(void) +{ + return TEST_SKIPPED; +} +#endif + +#if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \ + && defined(WOLFSSL_DTLS13) +static byte* test_find_string(const char *string, + byte *buf, int buf_size) +{ + int string_size, i; + + string_size = (int)XSTRLEN(string); + for (i = 0; i < buf_size - string_size - 1; i++) { + if (XSTRCMP((char*)&buf[i], string) == 0) + return &buf[i]; + } + return NULL; +} + +int test_wolfSSL_dtls13_null_cipher(void) +{ + EXPECT_DECLS; + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char *test_str = "test"; + int test_str_size; + byte buf[255], *ptr = NULL; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256"; + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + test_str_size = XSTRLEN("test") + 1; + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); + ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size); + ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0); + + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); + + /* check that the packet was sent cleartext */ + ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff, + test_ctx.s_len)); + if (ptr != NULL) { + /* modify the message */ + *ptr = 'H'; + /* bad messages should be ignored in DTLS */ + ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1); + ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ)); + } + + ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE); + ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE); + ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1); + ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + return TEST_SUCCESS; +} +#else +int test_wolfSSL_dtls13_null_cipher(void) +{ + return TEST_SKIPPED; +} +#endif + +int test_dtls13_frag_ch_pq(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && defined(WOLFSSL_DTLS_CH_FRAG) && defined(WOLFSSL_HAVE_MLKEM) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char *test_str = "test"; + int test_str_size; + byte buf[255]; +#if defined(WOLFSSL_MLKEM_KYBER) + #if !defined(WOLFSSL_NO_KYBER1024) + int group = WOLFSSL_KYBER_LEVEL5; + const char *group_name = "KYBER_LEVEL5"; + #elif !defined(WOLFSSL_NO_KYBER768) + int group = WOLFSSL_KYBER_LEVEL3; + const char *group_name = "KYBER_LEVEL3"; + #else + int group = WOLFSSL_KYBER_LEVEL1; + const char *group_name = "KYBER_LEVEL1"; + #endif +#elif !defined(WOLFSSL_NO_ML_KEM) && !defined(WOLFSSL_TLS_NO_MLKEM_STANDALONE) + #if !defined(WOLFSSL_NO_ML_KEM_1024) + int group = WOLFSSL_ML_KEM_1024; + const char *group_name = "ML_KEM_1024"; + #elif !defined(WOLFSSL_NO_ML_KEM_768) + int group = WOLFSSL_ML_KEM_768; + const char *group_name = "ML_KEM_768"; + #else + int group = WOLFSSL_ML_KEM_512; + const char *group_name = "ML_KEM_512"; + #endif +#elif defined(WOLFSSL_PQC_HYBRIDS) + #if defined(HAVE_CURVE25519) && !defined(WOLFSSL_NO_ML_KEM_768) + int group = WOLFSSL_X25519MLKEM768; + const char *group_name = "X25519MLKEM768"; + #elif !defined(WOLFSSL_NO_ML_KEM_768) + int group = WOLFSSL_SECP256R1MLKEM768; + const char *group_name = "SecP256r1MLKEM768"; + #else + int group = WOLFSSL_SECP384R1MLKEM1024; + const char *group_name = "SecP384r1MLKEM1024"; + #endif +#endif + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + /* Add in a large post-quantum key share to make the CH long. */ + ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), group_name); + ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), group_name); + test_str_size = XSTRLEN("test") + 1; + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); + ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size); + ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0); + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \ + && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ + defined(WOLFSSL_AES_256) +static int test_dtls_frag_ch_count_records(byte* b, int len) +{ + DtlsRecordLayerHeader* dtlsRH; + int records = 0; + size_t recordLen; + while (len > 0) { + records++; + dtlsRH = (DtlsRecordLayerHeader*)b; + recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1]; + if (recordLen > (size_t)len) + break; + b += sizeof(DtlsRecordLayerHeader) + recordLen; + len -= sizeof(DtlsRecordLayerHeader) + recordLen; + } + return records; +} +#endif + +int test_dtls_frag_ch(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ + defined(WOLFSSL_AES_256) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + static unsigned int DUMMY_MTU = 256; + unsigned int len; + unsigned char four_frag_CH[] = { + 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1, + 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85, + 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00, + 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, + 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, + 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, + 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, + 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02, + 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20, + 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, + 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01, + 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c, + 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17, + 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1, + 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19, + 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9, + 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, + 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f, + 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e, + 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61, + 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6, + 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b, + 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2, + 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b, + 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28, + 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86, + 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf, + 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c, + 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f, + 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06, + 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78, + 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8, + 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b, + 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6, + 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, + 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46, + 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96, + 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50, + 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80, + 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7, + 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5, + 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4, + 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d, + 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3, + 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e, + 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc, + 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72, + 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4, + 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4, + 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb, + 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17, + 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b, + 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00, + 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66, + 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c, + 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50, + 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4, + 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99, + 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3, + 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43, + 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13, + 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb, + 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87, + 0xa5, 0xcb, 0x68, 0xf3 + }; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* Fragment msgs */ + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS); + + /* Add in some key shares to make the CH long */ + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1), + WOLFSSL_SUCCESS); +#ifdef HAVE_FFDHE_2048 + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048), + WOLFSSL_SUCCESS); +#endif +#ifdef HAVE_FFDHE_3072 + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_3072), + WOLFSSL_SUCCESS); +#endif +#ifdef HAVE_FFDHE_4096 + ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_4096), + WOLFSSL_SUCCESS); +#endif + + ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); + + /* Reject fragmented first CH */ + ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH, + sizeof(four_frag_CH)), 4); + len = sizeof(four_frag_CH); + test_memio_clear_buffer(&test_ctx, 0); + while (len > 0 && EXPECT_SUCCESS()) { + unsigned int inj_len = len > DUMMY_MTU ? DUMMY_MTU : len; + unsigned char *idx = four_frag_CH + sizeof(four_frag_CH) - len; + ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, (const char *)idx, + inj_len), 0); + len -= inj_len; + } + ExpectIntEQ(test_ctx.s_len, sizeof(four_frag_CH)); + while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) { + int s_len = test_ctx.s_len; + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Fail if we didn't advance the buffer to avoid infinite loops */ + ExpectIntLT(test_ctx.s_len, s_len); + } + /* Expect all fragments read */ + ExpectIntEQ(test_ctx.s_len, 0); + /* Expect quietly dropping fragmented first CH */ + ExpectIntEQ(test_ctx.c_len, 0); + +#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) + /* Disable ECH as it pushes it over our MTU */ + wolfSSL_SetEchEnable(ssl_c, 0); +#endif + + /* Limit options to make the CH a fixed length */ + /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2 + * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */ +#ifdef OPENSSL_EXTRA + ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384" + ":DHE-RSA-AES256-GCM-SHA384")); +#else + ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384")); +#endif + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Count records. Expect 1 unfragmented CH */ + ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff, + test_ctx.s_len), 1); + /* HRR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Count records. Expect fragmented CH */ + ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff, + test_ctx.s_len), 1); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + ssl_c = ssl_s = NULL; + ctx_c = ctx_s = NULL; +#endif + return EXPECT_RESULT(); +} + +int test_dtls_empty_keyshare_with_cookie(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + unsigned char ch_empty_keyshare_with_cookie[] = { + 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, + 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3, + 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9, + 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00, + 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, + 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc, + 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0, + 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00, + 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00, + 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47, + 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf, + 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f, + 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13, + 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d, + 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5, + 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00, + 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, + 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08, + 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, + 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, + 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, + 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f, + 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00 + }; + DtlsRecordLayerHeader* dtlsRH; + byte sequence_number[8]; + + XMEMSET(&sequence_number, 0, sizeof(sequence_number)); + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s, + NULL, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, + (const char *)ch_empty_keyshare_with_cookie, + sizeof(ch_empty_keyshare_with_cookie)), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Expect an alert. A plaintext alert should be exactly 15 bytes. */ + ExpectIntEQ(test_ctx.c_len, 15); + dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff; + ExpectIntEQ(dtlsRH->type, alert); + ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR); + ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR); + sequence_number[7] = 1; + ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number, + sizeof(sequence_number)), 0); + ExpectIntEQ(dtlsRH->length[0], 0); + ExpectIntEQ(dtlsRH->length[1], 2); + ExpectIntEQ(test_ctx.c_buff[13], alert_fatal); + ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter); + + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +int test_dtls13_missing_finished_client(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char test_str[] = "test string"; + char test_buf[sizeof(test_str)]; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HRR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Let's clear the output */ + test_memio_clear_buffer(&test_ctx, 1); + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), + sizeof(test_str)); + /* Client second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server should not error out on a missing finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client rtx second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); + /* Client */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_s, test_str, sizeof(test_str)), + sizeof(test_str)); + ExpectIntEQ(wolfSSL_read(ssl_c, test_buf, sizeof(test_buf)), + sizeof(test_str)); + ExpectBufEQ(test_buf, test_str, sizeof(test_str)); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +int test_dtls13_missing_finished_server(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char test_str[] = "test string"; + char test_buf[sizeof(test_str)]; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HRR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Let's clear the output */ + test_memio_clear_buffer(&test_ctx, 0); + ExpectFalse(wolfSSL_is_init_finished(ssl_c)); + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, sizeof(test_str)), + sizeof(test_str)); + /* Server should not error out on a missing finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client rtx second flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); + /* Let's send some app data */ + ExpectIntEQ(wolfSSL_write(ssl_c, test_str, sizeof(test_str)), + sizeof(test_str)); + ExpectIntEQ(wolfSSL_read(ssl_s, test_buf, sizeof(test_buf)), + sizeof(test_str)); + ExpectBufEQ(test_buf, test_str, sizeof(test_str)); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +int test_dtls13_finished_send_error_propagation(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL; + WOLFSSL_CTX *ctx_s = NULL; + WOLFSSL *ssl_c = NULL; + WOLFSSL *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* HRR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + /* Server first flight with finished */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + /* Client second flight with finished - block sends to force error */ + test_ctx.s_len = TEST_MEMIO_BUF_SZ; + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + /* Verify the error is propagated, not silently swallowed as success */ + ExpectIntNE(wolfSSL_get_error(ssl_c, -1), 0); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + + +/*----------------------------------------------------------------------------*/ +/* DTLSv1.3-only tests moved from test_dtls.c (isolated from DTLS<=1.2 code) */ +/*----------------------------------------------------------------------------*/ + +/*-- basic_connection_id (test_dtls.c lines 422,580) ---*/ +int test_dtls13_basic_connection_id(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && defined(WOLFSSL_DTLS_CID) + unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + unsigned char readBuf[50]; + void * cid = NULL; + const char* params[] = { +#ifndef NO_SHA256 +#ifdef WOLFSSL_AES_128 +#ifdef HAVE_AESGCM + "TLS13-AES128-GCM-SHA256", +#endif +#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) + "TLS13-CHACHA20-POLY1305-SHA256", +#endif +#ifdef HAVE_AESCCM + "TLS13-AES128-CCM-8-SHA256", + "TLS13-AES128-CCM-SHA256", +#endif +#endif +#ifdef HAVE_NULL_CIPHER + "TLS13-SHA256-SHA256", +#endif +#endif + }; + size_t i; + + /* We check if the side included the CID in their output */ +#define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \ + client_cid, sizeof(client_cid)) +#define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \ + server_cid, sizeof(server_cid)) +#define RESET_CID(cid) if ((cid) != NULL) { \ + ((char*)(cid))[0] = -1; \ + } + + + printf("\n"); + for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) { + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + printf("Testing %s ... ", params[i]); + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS); + + ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1); + ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)), + 1); + ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1); + ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)), + 1); + + /* CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectNull(CLIENT_CID()); + /* HRR */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectNull(SERVER_CID()); + /* CH2 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectNull(CLIENT_CID()); + /* Server first flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectNotNull(SERVER_CID()); + /* Client second flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectNotNull(CLIENT_CID()); + /* Server process flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1); + /* Client process flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1); + + /* Write some data */ + ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])), + XSTRLEN(params[i])); + ExpectNotNull(CLIENT_CID()); + ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])), + XSTRLEN(params[i])); + ExpectNotNull(SERVER_CID()); + /* Read the data */ + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), + XSTRLEN(params[i])); + ExpectStrEQ(readBuf, params[i]); + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), + XSTRLEN(params[i])); + ExpectStrEQ(readBuf, params[i]); + /* Write short data */ + ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1); + ExpectNotNull(CLIENT_CID()); + ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1); + ExpectNotNull(SERVER_CID()); + /* Read the short data */ + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1); + ExpectIntEQ(readBuf[0], params[i][0]); + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1); + ExpectIntEQ(readBuf[0], params[i][0]); + /* Write some data but with wrong CID */ + ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])), + XSTRLEN(params[i])); + /* Reset client cid. */ + ExpectNotNull(cid = CLIENT_CID()); + RESET_CID(cid); + ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])), + XSTRLEN(params[i])); + /* Reset server cid. */ + ExpectNotNull(cid = SERVER_CID()); + RESET_CID(cid); + /* Try to read the data but it shouldn't be there */ + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Close connection */ + ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE); + ExpectNotNull(CLIENT_CID()); + ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE); + ExpectNotNull(SERVER_CID()); + ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1); + ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1); + + if (EXPECT_SUCCESS()) + printf("ok\n"); + else + printf("failed\n"); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); + } + +#undef CLIENT_CID +#undef SERVER_CID +#undef RESET_CID + +#endif + return EXPECT_RESULT(); +} + +/*-- hrr_want_write (test_dtls.c lines 588,639) ---*/ +int test_dtls13_hrr_want_write(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + const char msg[] = "hello"; + const int msgLen = sizeof(msg); + struct test_memio_ctx test_ctx; + char readBuf[sizeof(msg)]; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), + 0); + + /* Client sends first ClientHello */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* Force server to hit WANT_WRITE when producing the HRR */ + test_memio_simulate_want_write(&test_ctx, 0, 1); + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE); + + /* Allow the server to flush the HRR and proceed */ + test_memio_simulate_want_write(&test_ctx, 0, 0); + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Resume the DTLS 1.3 handshake */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + /* Verify post-handshake application data in both directions */ + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- want_write_send_cb_helper (test_dtls.c lines 641,655) ---*/ +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) +struct test_dtls13_wwrite_ctx { + int want_write; + struct test_memio_ctx *text_ctx; +}; +static int test_dtls13_want_write_send_cb(WOLFSSL *ssl, char *data, int sz, void *ctx) +{ + struct test_dtls13_wwrite_ctx *wwctx = (struct test_dtls13_wwrite_ctx *)ctx; + wwctx->want_write = !wwctx->want_write; + if (wwctx->want_write) { + return WOLFSSL_CBIO_ERR_WANT_WRITE; + } + return test_memio_write_cb(ssl, data, sz, wwctx->text_ctx); +} +#endif + +/*-- every_write_want_write (test_dtls.c lines 665,740) ---*/ +int test_dtls13_every_write_want_write(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char msg[] = "want-write"; + const int msgLen = sizeof(msg); + char readBuf[sizeof(msg)]; + struct test_dtls13_wwrite_ctx wwctx_c; + struct test_dtls13_wwrite_ctx wwctx_s; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), + 0); + + wwctx_c.want_write = 0; + wwctx_c.text_ctx = &test_ctx; + wolfSSL_SetIOWriteCtx(ssl_c, &wwctx_c); + wolfSSL_SSLSetIOSend(ssl_c, test_dtls13_want_write_send_cb); + wwctx_s.want_write = 0; + wwctx_s.text_ctx = &test_ctx; + wolfSSL_SetIOWriteCtx(ssl_s, &wwctx_s); + wolfSSL_SSLSetIOSend(ssl_s, test_dtls13_want_write_send_cb); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 20, NULL), 0); + + ExpectTrue(wolfSSL_is_init_finished(ssl_c)); + ExpectTrue(wolfSSL_is_init_finished(ssl_s)); + + test_memio_simulate_want_write(&test_ctx, 0, 0); + test_memio_simulate_want_write(&test_ctx, 1, 0); + + wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx); + wolfSSL_SSLSetIOSend(ssl_c, test_memio_write_cb); + wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx); + wolfSSL_SSLSetIOSend(ssl_s, test_memio_write_cb); + + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + test_memio_simulate_want_write(&test_ctx, 0, 1); + XMEMSET(readBuf, 0, sizeof(readBuf)); + ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE); + test_memio_simulate_want_write(&test_ctx, 0, 0); + ExpectIntEQ(wolfSSL_write(ssl_s, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + XMEMSET(readBuf, 0, sizeof(readBuf)); + test_memio_simulate_want_write(&test_ctx, 1, 1); + ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_WRITE); + test_memio_simulate_want_write(&test_ctx, 1, 0); + ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen); + ExpectStrEQ(readBuf, msg); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- epochs (test_dtls.c lines 823,871) ---*/ +int test_dtls13_epochs(void) { + EXPECT_DECLS; +#if defined(WOLFSSL_DTLS13) && !defined(NO_WOLFSSL_CLIENT) + WOLFSSL_CTX* ctx = NULL; + WOLFSSL* ssl = NULL; + byte input[20]; + word32 inOutIdx = 0; + + XMEMSET(input, 0, sizeof(input)); + + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_3_client_method())); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + /* Some manual setup to enter the epoch check */ + ExpectTrue(ssl->options.tls1_3 = 1); + + inOutIdx = 0; + if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x0); + ExpectIntEQ(DoApplicationData(ssl, input, &inOutIdx, 0), SANITY_MSG_E); + inOutIdx = 0; + if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x2); + ExpectIntEQ(DoApplicationData(ssl, input, &inOutIdx, 0), SANITY_MSG_E); + + if (ssl != NULL) ssl->keys.curEpoch64 = w64From32(0x0, 0x1); + ExpectIntEQ(Dtls13CheckEpoch(ssl, client_hello), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, server_hello), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_verify_request), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_retry_request), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, hello_request), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, encrypted_extensions), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, server_key_exchange), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, server_hello_done), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, client_key_exchange), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_request), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_verify), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, finished), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, certificate_status), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, change_cipher_hs), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, key_update), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, session_ticket), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, end_of_early_data), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, message_hash), SANITY_MSG_E); + ExpectIntEQ(Dtls13CheckEpoch(ssl, no_shake), SANITY_MSG_E); + + wolfSSL_CTX_free(ctx); + wolfSSL_free(ssl); +#endif + return EXPECT_RESULT(); +} + +/*-- ack_order (test_dtls.c lines 873,951) ---*/ +int test_dtls13_ack_order(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + unsigned char readBuf[50]; + word32 length = 0; + /* struct { + * uint64 epoch; + * uint64 sequence_number; + * } RecordNumber; + * Big endian */ + static const unsigned char expected_output[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + }; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + /* Get a populated DTLS object */ + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + /* Clear the buffer of any extra messages */ + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_ctx.c_len, 0); + ExpectIntEQ(test_ctx.s_len, 0); + + /* Add seen records */ + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 2)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 0)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 1)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 4)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 0)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 6)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), w64From32(0, 6)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 1)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 2)), 0); + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 2), w64From32(0, 2)), 0); + ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, + ssl_c->dtls13Rtx.seenRecordsCount, &length), 0); + + /* must zero the span reserved for the header to avoid read of uninited + * data. + */ + XMEMSET(ssl_c->buffers.outputBuffer.buffer, 0, + 5 /* DTLS13_UNIFIED_HEADER_SIZE */); + /* N * RecordNumber + 2 extra bytes for length */ + ExpectIntEQ(length, sizeof(expected_output) + 2); + ExpectNotNull(mymemmem(ssl_c->buffers.outputBuffer.buffer, + ssl_c->buffers.outputBuffer.bufferSize, expected_output, + sizeof(expected_output))); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- ack_overflow (test_dtls.c lines 953,1010) ---*/ +int test_dtls13_ack_overflow(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + unsigned char readBuf[50]; + word32 length = 0; + int i; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Edge case 1: one below limit - all inserts must succeed */ + for (i = 0; i < DTLS13_ACK_MAX_RECORDS - 1; i++) { + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), + w64From32(0, (word32)i)), 0); + } + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS - 1); + + /* Edge case 2: insert the last allowed record - must succeed */ + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), + w64From32(0, (word32)(DTLS13_ACK_MAX_RECORDS - 1))), 0); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS); + + /* Writing a full-but-valid list must succeed */ + ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, + ssl_c->dtls13Rtx.seenRecordsCount, &length), 0); + + /* Edge case 3: one over limit - must be silently dropped */ + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 0), + w64From32(0, (word32)DTLS13_ACK_MAX_RECORDS)), 0); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, DTLS13_ACK_MAX_RECORDS); + + /* Bypass the insert guard to force the list one element over the limit, + * then verify Dtls13WriteAckMessage errors out instead of overflowing */ + ssl_c->dtls13Rtx.seenRecordsCount = 0; + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 1), + w64From32(0, (word32)DTLS13_ACK_MAX_RECORDS)), 0); + ssl_c->dtls13Rtx.seenRecordsCount = (word16)(DTLS13_ACK_MAX_RECORDS + 1); + ExpectIntEQ(Dtls13WriteAckMessage(ssl_c, ssl_c->dtls13Rtx.seenRecords, + ssl_c->dtls13Rtx.seenRecordsCount, &length), BUFFER_E); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- ack_dup_write_counter (test_dtls.c lines 1012,1069) ---*/ +int test_dtls13_ack_dup_write_counter(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \ + && defined(HAVE_WRITE_DUP) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + WOLFSSL *ssl_c2 = NULL; + struct test_memio_ctx test_ctx; + unsigned char readBuf[50]; + int i; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + /* Drain any post-handshake messages */ + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Split ssl_c: ssl_c becomes READ_DUP_SIDE, ssl_c2 becomes WRITE_DUP_SIDE */ + ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c)); + + /* Cycle 1: add records, trigger handoff, verify counter is reset to 0 */ + for (i = 0; i < 5; i++) + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 3), + w64From32(0, (word32)i)), 0); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 5); + ssl_c->dtls13Rtx.sendAcks = 1; + ExpectIntEQ(Dtls13DoScheduledWork(ssl_c), 0); + /* seenRecords ownership was transferred to dupWrite->sendAckList; + * seenRecordsCount must be reset to 0, not left at 5. */ + ExpectNull(ssl_c->dtls13Rtx.seenRecords); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 0); + + /* Cycle 2 (different epoch to avoid the dup-filter): verify the counter + * did not accumulate across the previous transfer. Without the fix, + * seenRecordsCount would now be 10 after this second batch. */ + for (i = 0; i < 5; i++) + ExpectIntEQ(Dtls13RtxAddAck(ssl_c, w64From32(0, 4), + w64From32(0, (word32)i)), 0); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 5); + ssl_c->dtls13Rtx.sendAcks = 1; + ExpectIntEQ(Dtls13DoScheduledWork(ssl_c), 0); + ExpectNull(ssl_c->dtls13Rtx.seenRecords); + ExpectIntEQ(ssl_c->dtls13Rtx.seenRecordsCount, 0); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_c2); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- get_message_seq_helper (test_dtls.c lines 1850,1867) ---*/ +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) +static int test_dtls13_get_message_seq(const char* msg, int msgSz, + word16* msgSeq) +{ + int hsOff = DTLS_RECORD_HEADER_SZ; + + if (msg == NULL || msgSeq == NULL || + msgSz < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ) { + return BAD_FUNC_ARG; + } + + *msgSeq = ((word16)(byte)msg[hsOff + 4] << 8) | + (word16)(byte)msg[hsOff + 5]; + + return WOLFSSL_SUCCESS; +} +#endif + +/*-- ch2_rtx_no_ch1 (test_dtls.c lines 1869,1940) ---*/ +int test_dtls13_ch2_rtx_no_ch1(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + const char* msg = NULL; + int msgSz = 0; + word16 ch1Seq = 0; + int i; + int foundCh1Seq = 0; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), + 0); + + /* To force HRR */ + ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); + + /* CH1 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_memio_get_message(&test_ctx, 0, &msg, &msgSz, 0), 0); + ExpectIntGE(msgSz, DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ); + ExpectIntEQ(test_dtls13_get_message_seq(msg, msgSz, &ch1Seq), + WOLFSSL_SUCCESS); + + /* HRR */ + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntGT(test_ctx.c_msg_count, 0); + + /* CH2 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntGT(test_ctx.s_msg_count, 0); + + /* Drop CH2 and trigger the client retransmission timeout. */ + test_memio_clear_buffer(&test_ctx, 0); + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntGT(test_ctx.s_msg_count, 0); + + for (i = 0; i < test_ctx.s_msg_count && EXPECT_SUCCESS(); i++) { + int hsOff = DTLS_RECORD_HEADER_SZ; + word16 msgSeq = 0; + + ExpectIntEQ(test_memio_get_message(&test_ctx, 0, &msg, &msgSz, i), 0); + /* memio stores one DTLS record per message in this handshake path. */ + if (msgSz >= DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ && + (byte)msg[0] == handshake && msg[hsOff] == client_hello) { + ExpectIntEQ(test_dtls13_get_message_seq(msg, msgSz, &msgSeq), + WOLFSSL_SUCCESS); + if (msgSeq == ch1Seq) + foundCh1Seq = 1; + } + } + + ExpectIntEQ(foundCh1Seq, 0); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- frag_ch2_with_ch1_rtx (test_dtls.c lines 1942,2068) ---*/ +int test_dtls13_frag_ch2_with_ch1_rtx(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS) && \ + defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + char hrr[TEST_MEMIO_BUF_SZ]; + int hrrSz = (int)sizeof(hrr); + char ch1Rtx[TEST_MEMIO_BUF_SZ]; + int ch1RtxSz = (int)sizeof(ch1Rtx); + char ch2[TEST_MEMIO_BUF_SZ]; + int ch2Sz = 0; + int ch2MsgCount = 0; + int ch2MsgSizes[TEST_MEMIO_MAX_MSGS] = {0}; + /* The DTLS record sequence number occupies the last 8 bytes of the + * record header. */ + int recordSeqOff = DTLS_RECORD_HEADER_SZ - 8; + int ch2Seq = 0; + int ch1RtxSeq = 0; + int off; + int i; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), + 0); + + /* To force HRR */ + ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS); + + /* CH1 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* HRR */ + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(test_memio_copy_message(&test_ctx, 1, hrr, &hrrSz, 0), 0); + + /* Drop HRR, trigger CH1 retransmission, copy and drop it */ + test_memio_clear_buffer(&test_ctx, 1); + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_copy_message(&test_ctx, 0, ch1Rtx, &ch1RtxSz, 0), 0); + test_memio_clear_buffer(&test_ctx, 0); + + /* Force CH2 fragmentation. MTU must be small enough to fragment but large + * enough that the cookie extension lands in the first fragment, otherwise + * the server can't validate it statelessly and the test scenario (server + * stateful after frag 1) does not hold. With --enable-all (PQ groups in + * supported_groups), the cookie extension can sit ~400 bytes into CH2; 600 + * gives margin while still producing multiple fragments (CH2 is ~2KB). */ + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, 600), WOLFSSL_SUCCESS); + + /* Forward HRR and let the client create fragmented CH2 */ + ExpectIntEQ(test_memio_inject_message(&test_ctx, 1, hrr, hrrSz), 0); + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + ExpectIntGT(test_ctx.s_msg_count, 1); + ExpectIntLE(test_ctx.s_msg_count, TEST_MEMIO_MAX_MSGS); + ExpectIntLE(test_ctx.s_len, (int)sizeof(ch2)); + if (EXPECT_SUCCESS()) { + ch2Sz = test_ctx.s_len; + ch2MsgCount = test_ctx.s_msg_count; + XMEMCPY(ch2, test_ctx.s_buff, ch2Sz); + XMEMCPY(ch2MsgSizes, test_ctx.s_msg_sizes, + sizeof(ch2MsgSizes[0]) * (size_t)ch2MsgCount); + + ch2Seq = ((byte)ch2[recordSeqOff + 4] << 8) | + (byte)ch2[recordSeqOff + 5]; + ch1RtxSeq = ch2Seq + ch2MsgCount; + + /* Synthesize a CH1 retransmission that can pass the replay window after + * the first CH2 fragment makes the server stateful. The handshake + * message_seq remains the original CH1 value; only the DTLS record + * sequence is moved past the fragmented CH2 flight */ + ch1Rtx[recordSeqOff + 0] = 0; + ch1Rtx[recordSeqOff + 1] = 0; + ch1Rtx[recordSeqOff + 2] = 0; + ch1Rtx[recordSeqOff + 3] = 0; + ch1Rtx[recordSeqOff + 4] = (byte)(ch1RtxSeq >> 8); + ch1Rtx[recordSeqOff + 5] = (byte)ch1RtxSeq; + } + + test_memio_clear_buffer(&test_ctx, 0); + + /* Deliver CH2 first fragment only. Now server is stateful */ + ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch2, ch2MsgSizes[0]), 0); + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Deliver the retransmitted CH1 between CH2 fragments, it should be + * discarded as rtx */ + ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch1Rtx, ch1RtxSz), 0); + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + test_memio_clear_buffer(&test_ctx, 1); + + /* Deliver the rest of CH2 */ + off = ch2MsgSizes[0]; + for (i = 1; i < ch2MsgCount && EXPECT_SUCCESS(); i++) { + ExpectIntEQ(test_memio_inject_message(&test_ctx, 0, ch2 + off, + ch2MsgSizes[i]), 0); + off += ch2MsgSizes[i]; + } + + /* Restore MTU so the client's input buffer can hold the full server + * flight (e.g. an SH carrying a hybrid PQC key share). */ + ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, 1500), WOLFSSL_SUCCESS); + + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- srtp_with_helper_and_stub (test_dtls.c lines 2276,2312) ---*/ +#if defined(WOLFSSL_DTLS13) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_SRTP) +static int test_dtls_srtp_ctx_ready(WOLFSSL_CTX* ctx) +{ + EXPECT_DECLS; + ExpectIntEQ(wolfSSL_CTX_set_tlsext_use_srtp(ctx, "SRTP_AEAD_AES_256_GCM:" + "SRTP_AEAD_AES_128_GCM:SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32"), + 0); + return EXPECT_RESULT(); +} + +int test_dtls_srtp(void) +{ + EXPECT_DECLS; + test_ssl_cbf client_cbf; + test_ssl_cbf server_cbf; + + XMEMSET(&client_cbf, 0, sizeof(client_cbf)); + XMEMSET(&server_cbf, 0, sizeof(server_cbf)); + + client_cbf.method = wolfDTLSv1_3_client_method; + client_cbf.ctx_ready = test_dtls_srtp_ctx_ready; + server_cbf.method = wolfDTLSv1_3_server_method; + server_cbf.ctx_ready = test_dtls_srtp_ctx_ready; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf, + &server_cbf, NULL), TEST_SUCCESS); + + return EXPECT_RESULT(); +} +#else +int test_dtls_srtp(void) +{ + EXPECT_DECLS; + return EXPECT_RESULT(); +} +#endif + +/*-- min_rtx_interval (test_dtls.c lines 2890,2960) ---*/ +int test_dtls13_min_rtx_interval(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(WOLFSSL_DTLS13) && !defined(DTLS13_MIN_RTX_INTERVAL) && \ + !defined(NO_ASN_TIME) + /* We don't want to test when DTLS13_MIN_RTX_INTERVAL is defined because + * it may be too low to trigger reliably in a test. The default value is + * 1 second which is sufficient for testing here. */ + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + int c_msg_count = 0; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + /* Setup DTLS 1.3 contexts */ + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + + /* CH0 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), SSL_ERROR_WANT_READ); + + /* HRR */ + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), SSL_ERROR_WANT_READ); + + /* CH1 */ + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), SSL_ERROR_WANT_READ); + + /* SH ... FINISHED */ + ExpectIntEQ(wolfSSL_accept(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), SSL_ERROR_WANT_READ); + + /* We should have SH ... FINISHED messages in the buffer */ + ExpectIntGE(test_ctx.c_msg_count, 2); + + /* Drop everything */ + test_memio_clear_buffer(&test_ctx, 1); + + /* First timeout. This one should trigger a retransmission */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_s)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); + /* Save the message count to make sure no new messages are sent */ + ExpectIntGE(test_ctx.c_msg_count, 2); + c_msg_count = test_ctx.c_msg_count; + + /* Second timeout. This one should not trigger a retransmission */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_s)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS); + /* This is the critical check. The message count should not increase + * after the second timeout. DTLS13_MIN_RTX_INTERVAL should have blocked + * retransmission here. */ + ExpectIntEQ(c_msg_count, test_ctx.c_msg_count); + + /* Now complete the handshake. We didn't clear the first retransmission + * so the handshake should proceed without issues. */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + /* Cleanup */ + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- no_session_id_echo (test_dtls.c lines 2965,3044) ---*/ +int test_dtls13_no_session_id_echo(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) && \ + defined(HAVE_SESSION_TICKET) && defined(HAVE_ECC) && \ + !defined(WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID) + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + WOLFSSL_SESSION *sess = NULL; + char readBuf[1]; + /* Pin to SECP256R1 to avoid a PQ-induced key-share HRR */ + int groups[] = { WOLFSSL_ECC_SECP256R1 }; + + /* First connection: complete a DTLS 1.3 handshake to get a session */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + /* Read to process any NewSessionTicket */ + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); + + /* Ensure the session has a non-empty session ID so the ClientHello + * will have a populated legacy_session_id field (which is legal per + * RFC 9147). */ + if (sess != NULL && sess->sessionIDSz == 0) { + sess->sessionIDSz = ID_LEN; + XMEMSET(sess->sessionID, 0x42, ID_LEN); + } + + wolfSSL_free(ssl_c); ssl_c = NULL; + wolfSSL_free(ssl_s); ssl_s = NULL; + wolfSSL_CTX_free(ctx_c); ctx_c = NULL; + wolfSSL_CTX_free(ctx_s); ctx_s = NULL; + + /* Second connection: set the session on the client so the ClientHello + * contains a non-empty legacy_session_id. Verify the server does NOT + * echo it in the ServerHello. */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); + /* Disable HRR cookie so the server directly sends a ServerHello */ + ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); + + /* Client sends ClientHello (with non-empty legacy_session_id) */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* Server processes ClientHello and sends ServerHello + flight */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Verify the ServerHello on the wire. + * Layout: DTLS Record Header (13) + DTLS Handshake Header (12) + + * ProtocolVersion (2) + Random (32) = offset 59 for + * legacy_session_id_echo length byte. */ + ExpectIntGE(test_ctx.c_len, 60); + ExpectIntEQ(test_ctx.c_buff[0], handshake); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + + DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], 0); + + /* Complete the handshake */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_SESSION_free(sess); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} + +/*-- 5_9_0_compat (test_dtls.c lines 3049,3170) ---*/ +int test_dtls13_5_9_0_compat(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) && \ + defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_DTLS13_ECHO_LEGACY_SESSION_ID) && \ + defined(HAVE_ECC) + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + WOLFSSL_SESSION *sess = NULL; + char readBuf[1]; + /* Pin to SECP256R1 to avoid a PQ-induced key-share HRR */ + int groups[] = { WOLFSSL_ECC_SECP256R1 }; + /* RFC 8446 Section 4.1.3: an HRR is a ServerHello carrying this magic + * random. Used to assert sub-test 1 is a real ServerHello, not an HRR. */ + static const byte hrrRandom[RAN_LEN] = { + 0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, + 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91, + 0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, + 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C + }; + + /* --- initial connection: get a real session to carry the session ID --- */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + /* drain any NewSessionTicket before calling get1_session */ + ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + ExpectNotNull(sess = wolfSSL_get1_session(ssl_c)); + + /* Force a non-zero session ID - simulates a wolfSSL <=v5.9.0 client that + * mistakenly sends 32 bytes as legacy_session_id in DTLS 1.3. */ + if (sess != NULL && sess->sessionIDSz == 0) { + sess->sessionIDSz = ID_LEN; + XMEMSET(sess->sessionID, 0x42, ID_LEN); + } + + wolfSSL_free(ssl_c); ssl_c = NULL; + wolfSSL_free(ssl_s); ssl_s = NULL; + wolfSSL_CTX_free(ctx_c); ctx_c = NULL; + wolfSSL_CTX_free(ctx_s); ctx_s = NULL; + + /* --- sub-test 1: direct ServerHello (HRR cookie disabled) --- + * Exercises DoTls13ClientHello (change 1) and + * SendTls13ServerHello (change 2). */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS); + + /* Client sends CH1 with non-empty legacy_session_id */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* Server processes CH1 and sends ServerHello */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Verify that the ServerHello on the wire echoes the session ID. + * Layout: DTLS Record Header (13) + DTLS Handshake Header (12) + + * ProtocolVersion (2) + Random (32) = byte 59 for + * legacy_session_id_echo length. */ + ExpectIntGE(test_ctx.c_len, 60); + ExpectIntEQ(test_ctx.c_buff[0], handshake); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); + /* Confirm it is a real ServerHello, not an HRR (also encoded as a + * ServerHello but bearing the HelloRetryRequest magic random). */ + ExpectIntNE(XMEMCMP(&test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + + DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN], hrrRandom, RAN_LEN), 0); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + + DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], ID_LEN); + + /* Complete the handshake - Finished MAC validates the transcript */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_c); ssl_c = NULL; + wolfSSL_free(ssl_s); ssl_s = NULL; + wolfSSL_CTX_free(ctx_c); ctx_c = NULL; + wolfSSL_CTX_free(ctx_s); ctx_s = NULL; + + /* --- sub-test 2: stateless HRR (HRR cookie enabled by default) --- + * Exercises SendStatelessReplyDtls13 (change 4) and + * RestartHandshakeHashWithCookie (change 3). */ + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0); + ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS); + + /* Client sends CH1 */ + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); + + /* Server sends stateless HRR (SendStatelessReplyDtls13) */ + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + + /* Verify the HRR echoes the session ID at the same wire offset */ + ExpectIntGE(test_ctx.c_len, 60); + ExpectIntEQ(test_ctx.c_buff[0], handshake); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ], server_hello); + ExpectIntEQ(test_ctx.c_buff[DTLS_RECORD_HEADER_SZ + + DTLS_HANDSHAKE_HEADER_SZ + OPAQUE16_LEN + RAN_LEN], ID_LEN); + + /* Complete the handshake - Finished MAC validates RestartHandshakeHashWithCookie */ + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_SESSION_free(sess); + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_dtls13.h b/tests/api/test_dtls13.h new file mode 100644 index 0000000000..6b82a50483 --- /dev/null +++ b/tests/api/test_dtls13.h @@ -0,0 +1,79 @@ +/* test_dtls13.h + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#ifndef TESTS_API_DTLS13_H +#define TESTS_API_DTLS13_H + +#include + +/* DTLSv1.3-only tests. None share helpers with DTLS<=1.2 tests, so they + * live in their own translation unit and register under the "dtls13" + * group. Each function is defined unconditionally with the body (or the + * whole function via #else stub) guarded by WOLFSSL_DTLS13. */ +int test_dtls13_bad_epoch_ch(void); +int test_wolfSSL_dtls13_null_cipher(void); +int test_dtls13_frag_ch_pq(void); +int test_dtls_frag_ch(void); +int test_dtls_empty_keyshare_with_cookie(void); +int test_dtls13_missing_finished_client(void); +int test_dtls13_missing_finished_server(void); +int test_dtls13_finished_send_error_propagation(void); + +/* DTLSv1.3-only tests moved from test_dtls.c (isolated from DTLS<=1.2 code, + * none share helpers with non-DTLS13 tests). */ +int test_dtls13_basic_connection_id(void); +int test_dtls13_hrr_want_write(void); +int test_dtls13_every_write_want_write(void); +int test_dtls13_epochs(void); +int test_dtls13_ack_order(void); +int test_dtls13_ack_overflow(void); +int test_dtls13_ack_dup_write_counter(void); +int test_dtls13_ch2_rtx_no_ch1(void); +int test_dtls13_frag_ch2_with_ch1_rtx(void); +int test_dtls_srtp(void); +int test_dtls13_min_rtx_interval(void); +int test_dtls13_no_session_id_echo(void); +int test_dtls13_5_9_0_compat(void); + +#define TEST_DTLS13_DECLS \ + TEST_DECL_GROUP("dtls13", test_dtls13_bad_epoch_ch), \ + TEST_DECL_GROUP("dtls13", test_wolfSSL_dtls13_null_cipher), \ + TEST_DECL_GROUP("dtls13", test_dtls13_frag_ch_pq), \ + TEST_DECL_GROUP("dtls13", test_dtls_frag_ch), \ + TEST_DECL_GROUP("dtls13", test_dtls_empty_keyshare_with_cookie), \ + TEST_DECL_GROUP("dtls13", test_dtls13_missing_finished_client), \ + TEST_DECL_GROUP("dtls13", test_dtls13_missing_finished_server), \ + TEST_DECL_GROUP("dtls13", test_dtls13_finished_send_error_propagation), \ + TEST_DECL_GROUP("dtls13", test_dtls13_basic_connection_id), \ + TEST_DECL_GROUP("dtls13", test_dtls13_hrr_want_write), \ + TEST_DECL_GROUP("dtls13", test_dtls13_every_write_want_write), \ + TEST_DECL_GROUP("dtls13", test_dtls13_epochs), \ + TEST_DECL_GROUP("dtls13", test_dtls13_ack_order), \ + TEST_DECL_GROUP("dtls13", test_dtls13_ack_overflow), \ + TEST_DECL_GROUP("dtls13", test_dtls13_ack_dup_write_counter), \ + TEST_DECL_GROUP("dtls13", test_dtls13_ch2_rtx_no_ch1), \ + TEST_DECL_GROUP("dtls13", test_dtls13_frag_ch2_with_ch1_rtx), \ + TEST_DECL_GROUP("dtls13", test_dtls_srtp), \ + TEST_DECL_GROUP("dtls13", test_dtls13_min_rtx_interval), \ + TEST_DECL_GROUP("dtls13", test_dtls13_no_session_id_echo), \ + TEST_DECL_GROUP("dtls13", test_dtls13_5_9_0_compat) + +#endif /* TESTS_API_DTLS13_H */ diff --git a/tests/api/test_ed25519.c b/tests/api/test_ed25519.c index 2df8d41270..e68505b862 100644 --- a/tests/api/test_ed25519.c +++ b/tests/api/test_ed25519.c @@ -725,3 +725,184 @@ int test_wc_Ed25519KeyToDer_oneasymkey_version(void) return EXPECT_RESULT(); } +/* Ed25519 identity and small-order public keys must be rejected. When + * the public key is the identity point (or any small-order point), any + * signature of the form (R = [S]B, S) verifies for arbitrary messages + * because h*A is the neutral element. Gated on FIPS_VERSION3_GE(7,0,0) + * because older FIPS-certified modules do not have this check in their + * frozen copy of ed25519.c and would fail this test. */ +int test_wc_ed25519_reject_small_order_keys(void) +{ + EXPECT_DECLS; +#if (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) && \ + defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT) + /* Each entry holds an encoded small-order Ed25519 public key. The + * sign-bit variants of each y-coordinate are listed explicitly so + * the test catches both possible encodings of each y. */ + static const byte small_order_keys[][ED25519_PUB_KEY_SIZE] = { + /* identity (y = 1) */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + /* identity with x-sign bit set */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80}, + /* order 2: y = p - 1 */ + {0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + /* order 2: y = p - 1 with x-sign bit set */ + {0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, + /* non-canonical y = p (decodes to y = 0) */ + {0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + /* non-canonical y = p with x-sign bit set */ + {0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, + /* non-canonical y = p + 1 (decodes to y = 1) */ + {0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + /* non-canonical y = p + 1 with x-sign bit set */ + {0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}, + /* order 4: y = 0 */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + /* order 4 with x-sign bit set */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80}, + /* order 8 */ + {0x26,0xe8,0x95,0x8f,0xc2,0xb2,0x27,0xb0, + 0x45,0xc3,0xf4,0x89,0xf2,0xef,0x98,0xf0, + 0xd5,0xdf,0xac,0x05,0xd3,0xc6,0x33,0x39, + 0xb1,0x38,0x02,0x88,0x6d,0x53,0xfc,0x05}, + /* order 8 with x-sign bit set */ + {0x26,0xe8,0x95,0x8f,0xc2,0xb2,0x27,0xb0, + 0x45,0xc3,0xf4,0x89,0xf2,0xef,0x98,0xf0, + 0xd5,0xdf,0xac,0x05,0xd3,0xc6,0x33,0x39, + 0xb1,0x38,0x02,0x88,0x6d,0x53,0xfc,0x85}, + /* order 8 (other y) */ + {0xc7,0x17,0x6a,0x70,0x3d,0x4d,0xd8,0x4f, + 0xba,0x3c,0x0b,0x76,0x0d,0x10,0x67,0x0f, + 0x2a,0x20,0x53,0xfa,0x2c,0x39,0xcc,0xc6, + 0x4e,0xc7,0xfd,0x77,0x92,0xac,0x03,0x7a}, + /* order 8 (other y) with x-sign bit set */ + {0xc7,0x17,0x6a,0x70,0x3d,0x4d,0xd8,0x4f, + 0xba,0x3c,0x0b,0x76,0x0d,0x10,0x67,0x0f, + 0x2a,0x20,0x53,0xfa,0x2c,0x39,0xcc,0xc6, + 0x4e,0xc7,0xfd,0x77,0x92,0xac,0x03,0xfa}, + }; + /* Forged signature: R = B (base point), S = 1. + * With public key A = identity, S*B - h*A = B = R for any message. */ + static const byte forged_sig[ED25519_SIG_SIZE] = { + 0x58,0x66,0x66,0x66,0x66,0x66,0x66,0x66, + 0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66, + 0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66, + 0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66, + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + ed25519_key key; + word32 i; + word32 num_keys = (word32)(sizeof(small_order_keys) / ED25519_PUB_KEY_SIZE); + + /* (1) Untrusted wc_ed25519_import_public must reject every small-order + * encoding (it runs wc_ed25519_check_key as part of the import). */ + for (i = 0; i < num_keys; i++) { + int rc; + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed25519_init(&key), 0); + rc = wc_ed25519_import_public(small_order_keys[i], + ED25519_PUB_KEY_SIZE, &key); + if (rc != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + fprintf(stderr, "small_order_keys[%u]: import_public returned %d, " + "expected PUBLIC_KEY_E\n", (unsigned)i, rc); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(PUBLIC_KEY_E)); + wc_ed25519_free(&key); + } + + /* (2) wc_ed25519_check_key called directly must also reject. Guards + * against a refactor that moves the small-order check out of + * check_key and into the import path: (1) would still pass, but the + * documented check_key contract would silently regress. */ + for (i = 0; i < num_keys; i++) { + int rc; + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed25519_init(&key), 0); + /* trusted = 1 bypasses the import-time check_key call so the + * direct check_key below is what's under test. */ + ExpectIntEQ(wc_ed25519_import_public_ex(small_order_keys[i], + ED25519_PUB_KEY_SIZE, &key, 1), 0); + rc = wc_ed25519_check_key(&key); + if (rc != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + fprintf(stderr, "small_order_keys[%u]: check_key returned %d, " + "expected PUBLIC_KEY_E\n", (unsigned)i, rc); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(PUBLIC_KEY_E)); + wc_ed25519_free(&key); + } + + /* (3) Even a "trusted" import (which bypasses wc_ed25519_check_key) + * must not let wc_ed25519_verify_msg accept a forged signature against + * an identity public key. Test both the canonical encoding (y = 1, + * small_order_keys[0]) and the non-canonical encoding (y = p + 1, + * small_order_keys[6]) so the verify-side check is exercised against + * the canonical-form bypass route, not just the byte-for-byte + * identity. The forged sig (R = B, S = 1) verifies for an identity + * public key only - other small-order points would reject it on the + * math alone, so they aren't useful here. */ + { + static const word32 identity_indices[] = { 0, 6 }; + const char* msg = "forged message"; + word32 j; + + for (j = 0; + j < sizeof(identity_indices)/sizeof(identity_indices[0]); + j++) { + word32 idx = identity_indices[j]; + int verify_result = 1; + int rc; + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed25519_init(&key), 0); + ExpectIntEQ(wc_ed25519_import_public_ex(small_order_keys[idx], + ED25519_PUB_KEY_SIZE, &key, 1), 0); + rc = wc_ed25519_verify_msg(forged_sig, sizeof(forged_sig), + (const byte*)msg, (word32)XSTRLEN(msg), &verify_result, &key); + if (rc != WC_NO_ERR_TRACE(BAD_FUNC_ARG) || verify_result != 0) { + fprintf(stderr, "verify_msg with identity-equiv " + "small_order_keys[%u]: rc=%d verify_result=%d " + "(expected BAD_FUNC_ARG and 0)\n", + (unsigned)idx, rc, verify_result); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(verify_result, 0); + wc_ed25519_free(&key); + } + } +#endif + return EXPECT_RESULT(); +} + diff --git a/tests/api/test_ed25519.h b/tests/api/test_ed25519.h index 4ac3693f66..a14b2a4496 100644 --- a/tests/api/test_ed25519.h +++ b/tests/api/test_ed25519.h @@ -37,6 +37,7 @@ int test_wc_Ed25519PublicKeyToDer(void); int test_wc_Ed25519KeyToDer(void); int test_wc_Ed25519PrivateKeyToDer(void); int test_wc_Ed25519KeyToDer_oneasymkey_version(void); +int test_wc_ed25519_reject_small_order_keys(void); #define TEST_ED25519_DECLS \ TEST_DECL_GROUP("ed25519", test_wc_ed25519_make_key), \ @@ -51,6 +52,7 @@ int test_wc_Ed25519KeyToDer_oneasymkey_version(void); TEST_DECL_GROUP("ed25519", test_wc_Ed25519PublicKeyToDer), \ TEST_DECL_GROUP("ed25519", test_wc_Ed25519KeyToDer), \ TEST_DECL_GROUP("ed25519", test_wc_Ed25519PrivateKeyToDer), \ - TEST_DECL_GROUP("ed25519", test_wc_Ed25519KeyToDer_oneasymkey_version) + TEST_DECL_GROUP("ed25519", test_wc_Ed25519KeyToDer_oneasymkey_version), \ + TEST_DECL_GROUP("ed25519", test_wc_ed25519_reject_small_order_keys) #endif /* WOLFCRYPT_TEST_ED25519_H */ diff --git a/tests/api/test_ed448.c b/tests/api/test_ed448.c index f6b7552302..6bb7934615 100644 --- a/tests/api/test_ed448.c +++ b/tests/api/test_ed448.c @@ -649,3 +649,224 @@ int test_wc_Ed448KeyToDer_oneasymkey_version(void) return EXPECT_RESULT(); } +/* Ed448 identity and small-order public keys must be rejected. + * Edwards448 has cofactor 4, so the small-order subgroup contains the + * identity, an order-2 point, and two order-4 points. With any of these + * as the public key, h*A is the neutral element and forged signatures + * verify for arbitrary messages. Gated on FIPS_VERSION3_GE(7,0,0) + * because older FIPS-certified modules do not have this check in their + * frozen copy of ed448.c. */ +int test_wc_ed448_reject_small_order_keys(void) +{ + EXPECT_DECLS; +#if (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) && \ + defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT) + /* Two regressions are guarded here. Both sign-bit variants of each + * y are listed so weakening the "clear all of byte 56" mask in + * ed448_is_small_order() would be caught. The non-canonical rows + * (y = p, y = p + 1) guard against dropping the canonical-form + * coverage: fe448_from_bytes reads bytes 0-55 modulo p with no + * canonical-form check, so y = p decodes to 0 and y = p + 1 + * decodes to 1, both of which are small order. */ + static const byte small_order_keys[][ED448_PUB_KEY_SIZE] = { + /* identity (y = 1), sign 0 */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00}, + /* identity (y = 1), sign bit set */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x80}, + /* order 4: y = 0, x-sign 0 */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00}, + /* order 4: y = 0, x-sign 1 */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x80}, + /* order 2: y = p - 1, x = 0, sign 0 */ + {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + /* order 2: y = p - 1, sign bit set */ + {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x80}, + /* non-canonical y = p (decodes to y = 0), sign 0 */ + {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + /* non-canonical y = p, sign bit set */ + {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x80}, + /* non-canonical y = p + 1 (decodes to y = 1), sign 0 */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + /* non-canonical y = p + 1, sign bit set */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x80}, + }; + /* Arbitrary signature bytes: S = 1 (must be below the Ed448 group + * order or wc_ed448_verify_msg() returns BAD_FUNC_ARG before the + * small-order check has a chance to fire). The R bytes do not need + * to encode a valid curve point for this test - the small-order + * defence in ed448_verify_msg_final_with_sha() rejects the public + * key before the R/S verification math runs. */ + static const byte forged_sig[ED448_SIG_SIZE] = { + /* R: 57 bytes of arbitrary data (last byte 0 to satisfy the + * spec-mandated zero of byte 56 bits 0-6; sign bit doesn't + * matter here). */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00, + /* S = 1 */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00 + }; + ed448_key key; + word32 i; + word32 num_keys = (word32)(sizeof(small_order_keys) / ED448_PUB_KEY_SIZE); + + /* (1) Untrusted wc_ed448_import_public must reject every small-order + * encoding (it runs wc_ed448_check_key as part of the import). */ + for (i = 0; i < num_keys; i++) { + int rc; + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed448_init(&key), 0); + rc = wc_ed448_import_public(small_order_keys[i], + ED448_PUB_KEY_SIZE, &key); + if (rc != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + fprintf(stderr, "small_order_keys[%u]: import_public returned %d, " + "expected PUBLIC_KEY_E\n", (unsigned)i, rc); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(PUBLIC_KEY_E)); + wc_ed448_free(&key); + } + + /* (2) wc_ed448_check_key called directly must also reject. Guards + * against a refactor that moves the small-order check out of + * check_key and into the import path: (1) would still pass, but the + * documented check_key contract would silently regress. */ + for (i = 0; i < num_keys; i++) { + int rc; + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed448_init(&key), 0); + /* trusted = 1 bypasses the import-time check_key call so the + * direct check_key below is what's under test. */ + ExpectIntEQ(wc_ed448_import_public_ex(small_order_keys[i], + ED448_PUB_KEY_SIZE, &key, 1), 0); + rc = wc_ed448_check_key(&key); + if (rc != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + fprintf(stderr, "small_order_keys[%u]: check_key returned %d, " + "expected PUBLIC_KEY_E\n", (unsigned)i, rc); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(PUBLIC_KEY_E)); + wc_ed448_free(&key); + } + + /* (3) Even a "trusted" import (which bypasses wc_ed448_check_key) + * must not let wc_ed448_verify_msg accept a forged signature against + * an identity public key. Test both the canonical encoding (y = 1, + * small_order_keys[0]) and the non-canonical encoding (y = p + 1, + * small_order_keys[8]) so the verify-side check is exercised against + * the canonical-form bypass route, not just the byte-for-byte + * identity. */ + { + static const word32 identity_indices[] = { 0, 8 }; + const char* msg = "forged message"; + word32 j; + + for (j = 0; + j < sizeof(identity_indices)/sizeof(identity_indices[0]); + j++) { + word32 idx = identity_indices[j]; + int verify_result = 1; + int rc; + + XMEMSET(&key, 0, sizeof(key)); + ExpectIntEQ(wc_ed448_init(&key), 0); + ExpectIntEQ(wc_ed448_import_public_ex(small_order_keys[idx], + ED448_PUB_KEY_SIZE, &key, 1), 0); + rc = wc_ed448_verify_msg(forged_sig, sizeof(forged_sig), + (const byte*)msg, (word32)XSTRLEN(msg), &verify_result, + &key, NULL, 0); + if (rc != WC_NO_ERR_TRACE(BAD_FUNC_ARG) || verify_result != 0) { + fprintf(stderr, "verify_msg with identity-equiv " + "small_order_keys[%u]: rc=%d verify_result=%d " + "(expected BAD_FUNC_ARG and 0)\n", + (unsigned)idx, rc, verify_result); + } + ExpectIntEQ(rc, WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(verify_result, 0); + wc_ed448_free(&key); + } + } +#endif + return EXPECT_RESULT(); +} + diff --git a/tests/api/test_ed448.h b/tests/api/test_ed448.h index 68d85a6338..a40edd17bb 100644 --- a/tests/api/test_ed448.h +++ b/tests/api/test_ed448.h @@ -37,6 +37,7 @@ int test_wc_Ed448PublicKeyToDer(void); int test_wc_Ed448KeyToDer(void); int test_wc_Ed448PrivateKeyToDer(void); int test_wc_Ed448KeyToDer_oneasymkey_version(void); +int test_wc_ed448_reject_small_order_keys(void); #define TEST_ED448_DECLS \ TEST_DECL_GROUP("ed448", test_wc_ed448_make_key), \ @@ -51,6 +52,7 @@ int test_wc_Ed448KeyToDer_oneasymkey_version(void); TEST_DECL_GROUP("ed448", test_wc_Ed448PublicKeyToDer), \ TEST_DECL_GROUP("ed448", test_wc_Ed448KeyToDer), \ TEST_DECL_GROUP("ed448", test_wc_Ed448PrivateKeyToDer), \ - TEST_DECL_GROUP("ed448", test_wc_Ed448KeyToDer_oneasymkey_version) + TEST_DECL_GROUP("ed448", test_wc_Ed448KeyToDer_oneasymkey_version), \ + TEST_DECL_GROUP("ed448", test_wc_ed448_reject_small_order_keys) #endif /* WOLFCRYPT_TEST_ED448_H */ diff --git a/tests/api/test_evp_pkey.c b/tests/api/test_evp_pkey.c index 13de8ebe25..6b15f38d96 100644 --- a/tests/api/test_evp_pkey.c +++ b/tests/api/test_evp_pkey.c @@ -2702,3 +2702,162 @@ int test_wolfSSL_EVP_PKEY_ed448(void) return EXPECT_RESULT(); } +int test_wolfSSL_EVP_PKEY_x25519(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && defined(HAVE_CURVE25519) + EVP_PKEY* pkey = NULL; + EVP_PKEY* peer = NULL; + EVP_PKEY_CTX* genCtx = NULL; + EVP_PKEY_CTX* ctx = NULL; + unsigned char rawPriv[32]; + unsigned char rawPub[32]; + unsigned char secretA[32]; + unsigned char secretB[32]; + size_t secretLen; + int i; + + for (i = 0; i < 32; i++) { + rawPriv[i] = (unsigned char)i; + rawPub[i] = (unsigned char)(0x40 + i); + } + + /* Raw import with the correct length reports the X25519 type. */ + ExpectNotNull(pkey = EVP_PKEY_new_raw_public_key( + EVP_PKEY_X25519, NULL, rawPub, sizeof(rawPub))); + ExpectIntEQ(EVP_PKEY_id(pkey), EVP_PKEY_X25519); + EVP_PKEY_free(pkey); + pkey = NULL; + + ExpectNotNull(pkey = EVP_PKEY_new_raw_private_key( + EVP_PKEY_X25519, NULL, rawPriv, sizeof(rawPriv))); + ExpectIntEQ(EVP_PKEY_id(pkey), EVP_PKEY_X25519); + + /* X25519 is key-agreement only: signing must be rejected. */ + ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + ExpectIntNE(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + EVP_PKEY_free(pkey); + pkey = NULL; + + /* Wrong raw lengths are rejected. */ + ExpectNull(EVP_PKEY_new_raw_public_key( + EVP_PKEY_X25519, NULL, rawPub, 16)); + ExpectNull(EVP_PKEY_new_raw_private_key( + EVP_PKEY_X25519, NULL, rawPriv, 16)); + + /* Generate two key pairs and confirm ECDH agreement is symmetric. This + * also exercises the little-endian convention used on import/derive. */ + ExpectNotNull(genCtx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL)); + ExpectIntEQ(EVP_PKEY_keygen_init(genCtx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_keygen(genCtx, &pkey), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_keygen(genCtx, &peer), WOLFSSL_SUCCESS); + EVP_PKEY_CTX_free(genCtx); + genCtx = NULL; + + ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peer), WOLFSSL_SUCCESS); + secretLen = sizeof(secretA); + ExpectIntEQ(EVP_PKEY_derive(ctx, secretA, &secretLen), WOLFSSL_SUCCESS); + ExpectIntEQ((int)secretLen, 32); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + + ExpectNotNull(ctx = EVP_PKEY_CTX_new(peer, NULL)); + ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, pkey), WOLFSSL_SUCCESS); + secretLen = sizeof(secretB); + ExpectIntEQ(EVP_PKEY_derive(ctx, secretB, &secretLen), WOLFSSL_SUCCESS); + ExpectIntEQ((int)secretLen, 32); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + + ExpectIntEQ(XMEMCMP(secretA, secretB, 32), 0); + + EVP_PKEY_free(peer); + EVP_PKEY_free(pkey); +#endif + return EXPECT_RESULT(); +} + +int test_wolfSSL_EVP_PKEY_x448(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && defined(HAVE_CURVE448) + EVP_PKEY* pkey = NULL; + EVP_PKEY* peer = NULL; + EVP_PKEY_CTX* genCtx = NULL; + EVP_PKEY_CTX* ctx = NULL; + unsigned char rawPriv[56]; + unsigned char rawPub[56]; + unsigned char secretA[56]; + unsigned char secretB[56]; + size_t secretLen; + int i; + + for (i = 0; i < 56; i++) { + rawPriv[i] = (unsigned char)i; + rawPub[i] = (unsigned char)(0x40 + i); + } + + /* Raw import with the correct length reports the X448 type. */ + ExpectNotNull(pkey = EVP_PKEY_new_raw_public_key( + EVP_PKEY_X448, NULL, rawPub, sizeof(rawPub))); + ExpectIntEQ(EVP_PKEY_id(pkey), EVP_PKEY_X448); + EVP_PKEY_free(pkey); + pkey = NULL; + + ExpectNotNull(pkey = EVP_PKEY_new_raw_private_key( + EVP_PKEY_X448, NULL, rawPriv, sizeof(rawPriv))); + ExpectIntEQ(EVP_PKEY_id(pkey), EVP_PKEY_X448); + + /* X448 is key-agreement only: signing must be rejected. */ + ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + ExpectIntNE(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + EVP_PKEY_free(pkey); + pkey = NULL; + + /* Wrong raw lengths are rejected. */ + ExpectNull(EVP_PKEY_new_raw_public_key( + EVP_PKEY_X448, NULL, rawPub, 16)); + ExpectNull(EVP_PKEY_new_raw_private_key( + EVP_PKEY_X448, NULL, rawPriv, 16)); + + /* Generate two key pairs and confirm ECDH agreement is symmetric. */ + ExpectNotNull(genCtx = EVP_PKEY_CTX_new_id(EVP_PKEY_X448, NULL)); + ExpectIntEQ(EVP_PKEY_keygen_init(genCtx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_keygen(genCtx, &pkey), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_keygen(genCtx, &peer), WOLFSSL_SUCCESS); + EVP_PKEY_CTX_free(genCtx); + genCtx = NULL; + + ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peer), WOLFSSL_SUCCESS); + secretLen = sizeof(secretA); + ExpectIntEQ(EVP_PKEY_derive(ctx, secretA, &secretLen), WOLFSSL_SUCCESS); + ExpectIntEQ((int)secretLen, 56); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + + ExpectNotNull(ctx = EVP_PKEY_CTX_new(peer, NULL)); + ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS); + ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, pkey), WOLFSSL_SUCCESS); + secretLen = sizeof(secretB); + ExpectIntEQ(EVP_PKEY_derive(ctx, secretB, &secretLen), WOLFSSL_SUCCESS); + ExpectIntEQ((int)secretLen, 56); + EVP_PKEY_CTX_free(ctx); + ctx = NULL; + + ExpectIntEQ(XMEMCMP(secretA, secretB, 56), 0); + + EVP_PKEY_free(peer); + EVP_PKEY_free(pkey); +#endif + return EXPECT_RESULT(); +} + diff --git a/tests/api/test_evp_pkey.h b/tests/api/test_evp_pkey.h index 2b77782a59..97388dfd7a 100644 --- a/tests/api/test_evp_pkey.h +++ b/tests/api/test_evp_pkey.h @@ -66,6 +66,8 @@ int test_wolfSSL_EVP_PKEY_print_public(void); int test_wolfSSL_EVP_PKEY_ed25519(void); int test_wolfSSL_CTX_use_PrivateKey_ed25519(void); int test_wolfSSL_EVP_PKEY_ed448(void); +int test_wolfSSL_EVP_PKEY_x25519(void); +int test_wolfSSL_EVP_PKEY_x448(void); #define TEST_EVP_PKEY_DECLS \ TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_CTX_new_id), \ @@ -110,6 +112,8 @@ int test_wolfSSL_EVP_PKEY_ed448(void); TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_print_public), \ TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_ed25519), \ TEST_DECL_GROUP("evp_pkey", test_wolfSSL_CTX_use_PrivateKey_ed25519), \ - TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_ed448) + TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_ed448), \ + TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_x25519), \ + TEST_DECL_GROUP("evp_pkey", test_wolfSSL_EVP_PKEY_x448) #endif /* WOLFCRYPT_TEST_EVP_PKEY_H */ diff --git a/tests/api/test_lms_xmss.c b/tests/api/test_lms_xmss.c new file mode 100644 index 0000000000..2dc3ff2158 --- /dev/null +++ b/tests/api/test_lms_xmss.c @@ -0,0 +1,934 @@ +/* test_lms_xmss.c + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include + +#ifdef NO_INLINE + #include +#else + #define WOLFSSL_MISC_INCLUDED + #include +#endif + +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/* LMS tests */ +/*----------------------------------------------------------------------------*/ + +#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) + +#include + +#define LMS_TEST_PRIV_KEY_FILE "/tmp/wolfssl_test_lms.key" + +static int test_lms_write_key(const byte* priv, word32 privSz, void* context) +{ + FILE* f = fopen((const char*)context, "wb"); + int ret = WC_LMS_RC_SAVED_TO_NV_MEMORY; + if (f == NULL) + return -1; + if (fwrite(priv, 1, privSz, f) != privSz) + ret = -1; + fclose(f); + return ret; +} + +static int test_lms_read_key(byte* priv, word32 privSz, void* context) +{ + FILE* f = fopen((const char*)context, "rb"); + if (f == NULL) + return -1; + if (fread(priv, 1, privSz, f) == 0) { + fclose(f); + return -1; + } + fclose(f); + return WC_LMS_RC_READ_TO_MEMORY; +} + +/* Helper: init an LMS key with callbacks and L1-H10-W8 params */ +static int test_lms_init_key(LmsKey* key, WC_RNG* rng) +{ + int ret; + + ret = wc_LmsKey_Init(key, NULL, INVALID_DEVID); + if (ret != 0) return ret; + +#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) + ret = wc_LmsKey_SetParameters(key, 1, 10, 8); +#else + ret = wc_LmsKey_SetParameters(key, 1, 5, 8); +#endif + if (ret != 0) return ret; + + ret = wc_LmsKey_SetWriteCb(key, test_lms_write_key); + if (ret != 0) return ret; + + ret = wc_LmsKey_SetReadCb(key, test_lms_read_key); + if (ret != 0) return ret; + + ret = wc_LmsKey_SetContext(key, (void*)LMS_TEST_PRIV_KEY_FILE); + if (ret != 0) return ret; + + (void)rng; + return 0; +} + +#endif /* WOLFSSL_HAVE_LMS && !WOLFSSL_LMS_VERIFY_ONLY */ + +/* + * Test basic LMS sign/verify with multiple signings. + * Uses L1-H10-W8 (1024 total signatures, 32-entry leaf cache). + */ +int test_wc_LmsKey_sign_verify(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) + LmsKey key; + WC_RNG rng; + byte msg[] = "test message for LMS signing"; + byte sig[2048]; + word32 sigSz; + int i; + int numSigs = 5; + + ExpectIntEQ(wc_InitRng(&rng), 0); + + remove(LMS_TEST_PRIV_KEY_FILE); + ExpectIntEQ(test_lms_init_key(&key, &rng), 0); + ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), 0); + + for (i = 0; i < numSigs; i++) { + sigSz = sizeof(sig); + ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); + ExpectIntEQ(wc_LmsKey_Verify(&key, sig, sigSz, msg, sizeof(msg)), 0); + } + + wc_LmsKey_Free(&key); + wc_FreeRng(&rng); + remove(LMS_TEST_PRIV_KEY_FILE); +#endif + return EXPECT_RESULT(); +} + +/* + * Test LMS key reload after advancing past the leaf cache window. + * + * Reproduces a heap-buffer-overflow bug in wc_lms_treehash_init() where the + * leaf cache write uses (i * hash_len) instead of ((i - leaf->idx) * hash_len). + * When q > max_cb (default 32), wc_LmsKey_Reload calls wc_hss_init_auth_path + * which calls wc_lms_treehash_init with q > 0, causing writes past the end of + * the leaf cache buffer. + * + * Reproduction steps: + * 1. Generate L1-H10-W8 key (cacheBits=5, max_cb=32) + * 2. Sign 33 times to advance q past the cache window + * 3. Free the key and reload from persisted state + * 4. Sign and verify after reload + * + * Without the fix: heap-buffer-overflow at wc_lms_impl.c:1965 + * With the fix: all operations succeed, signatures verify + */ +int test_wc_LmsKey_reload_cache(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) && \ + (!defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10)) + LmsKey key; + LmsKey vkey; + WC_RNG rng; + byte msg[] = "test message for LMS signing"; + byte sig[2048]; + word32 sigSz; + byte pub[64]; + word32 pubSz = sizeof(pub); + int i; + /* Sign 33 times to advance q past the 32-entry cache window. */ + int preSigs = 33; + + ExpectIntEQ(wc_InitRng(&rng), 0); + + /* Phase 1: Generate key and sign past cache window */ + remove(LMS_TEST_PRIV_KEY_FILE); + ExpectIntEQ(test_lms_init_key(&key, &rng), 0); + ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), 0); + + for (i = 0; i < preSigs; i++) { + sigSz = sizeof(sig); + ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); + } + + /* Save public key for verification after reload */ + ExpectIntEQ(wc_LmsKey_ExportPubRaw(&key, pub, &pubSz), 0); + + wc_LmsKey_Free(&key); + + /* Phase 2: Reload key. Triggers wc_lms_treehash_init with q=33 */ + ExpectIntEQ(test_lms_init_key(&key, &rng), 0); + ExpectIntEQ(wc_LmsKey_Reload(&key), 0); + + /* Phase 3: Sign after reload and verify with separate verify-only key */ + sigSz = sizeof(sig); + ExpectIntEQ(wc_LmsKey_Sign(&key, sig, &sigSz, msg, sizeof(msg)), 0); + + ExpectIntEQ(wc_LmsKey_Init(&vkey, NULL, INVALID_DEVID), 0); +#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) + ExpectIntEQ(wc_LmsKey_SetParameters(&vkey, 1, 10, 8), 0); +#else + ExpectIntEQ(wc_LmsKey_SetParameters(&vkey, 1, 5, 8), 0); +#endif + ExpectIntEQ(wc_LmsKey_ImportPubRaw(&vkey, pub, pubSz), 0); + ExpectIntEQ(wc_LmsKey_Verify(&vkey, sig, sigSz, msg, sizeof(msg)), 0); + + wc_LmsKey_Free(&vkey); + wc_LmsKey_Free(&key); + wc_FreeRng(&rng); + remove(LMS_TEST_PRIV_KEY_FILE); +#endif + return EXPECT_RESULT(); +} + +/*----------------------------------------------------------------------------*/ +/* RFC 9802 (HSS/LMS and XMSS/XMSS^MT in X.509) tests */ +/*----------------------------------------------------------------------------*/ + +/* For every committed self-signed test certificate confirm: + * - wc_ParseCert succeeds on the RFC 9802 AlgorithmIdentifier encoding + * (OID-only SEQUENCE, no NULL parameters) + * - keyOID and signatureOID are set to the expected values + * - loading as a trust anchor and verifying the same bytes through + * wolfSSL_CertManagerVerifyBuffer exercises the ConfirmSignature + * path and succeeds on a valid cert + * - flipping a byte in the signature AND flipping a byte in the + * TBSCertificate both cause verification to fail. + * + * Test vectors are in certs/lms/ and certs/xmss/, generated with Bouncy + * Castle 1.81. BC's default XMSS / XMSS^MT X.509 encoding uses pre- + * standard ISARA OIDs and wraps the raw RFC 8391 pub key in an OCTET + * STRING, so the fixtures were produced with a small generator that + * overrides the AlgorithmIdentifier and SPKI to match RFC 9802. */ +#if (defined(WOLFSSL_HAVE_LMS) || defined(WOLFSSL_HAVE_XMSS)) && \ + !defined(NO_FILESYSTEM) && !defined(NO_CERTS) +/* Sanity bound on a test fixture cert. The largest BC-generated + * fixture we ship (XMSS^MT 40/8) is ~19 KiB; 1 MiB is well above + * any realistic RFC 9802 cert and catches a wild XFTELL. Typed as + * long to match XFTELL's return so the size comparison below isn't + * a mixed long-vs-int compare. */ +#define RFC9802_TEST_MAX_CERT_SIZE ((long)(1L << 20)) + +/* Load a whole file into a freshly-allocated buffer. Caller frees. */ +static int rfc9802_load_file(const char* path, byte** out, int* outLen) +{ + EXPECT_DECLS; + XFILE f = XBADFILE; + long sz = 0; + size_t got = 0; + byte* buf = NULL; + + *out = NULL; + *outLen = 0; + ExpectTrue((f = XFOPEN(path, "rb")) != XBADFILE); + if (f == XBADFILE) + return TEST_FAIL; + if (XFSEEK(f, 0, XSEEK_END) == 0) + sz = XFTELL(f); + (void)XFSEEK(f, 0, XSEEK_SET); + ExpectIntGT(sz, 0); + ExpectIntLT(sz, RFC9802_TEST_MAX_CERT_SIZE); + /* Hard-fail before XMALLOC if XFSEEK / XFTELL produced an unusable + * size: ExpectInt* records the failure but doesn't short-circuit, + * so without this guard a -1 from XFTELL would cast to a multi-GiB + * (size_t) allocation, and a 0 would request a zero-byte malloc. */ + if (sz <= 0 || sz >= RFC9802_TEST_MAX_CERT_SIZE) { + XFCLOSE(f); + return TEST_FAIL; + } + ExpectNotNull(buf = (byte*)XMALLOC((size_t)sz, NULL, + DYNAMIC_TYPE_TMP_BUFFER)); + if (buf != NULL) { + got = XFREAD(buf, 1, (size_t)sz, f); + ExpectIntEQ(got, (size_t)sz); + /* On a short read the caller would otherwise proceed with a + * partially-initialized buffer and produce cascading parse + * failures driven by the uninitialized tail. Free here so the + * caller's `if (buf == NULL) return TEST_FAIL;` short-circuits + * cleanly with a single recorded failure. */ + if (got != (size_t)sz) { + XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + buf = NULL; + sz = 0; + } + } + XFCLOSE(f); + *out = buf; + *outLen = (int)sz; + return EXPECT_RESULT(); +} + +static int rfc9802_verify_one_cert(const char* path, word32 expectedKeyOID, + word32 expectedSigOID) +{ + EXPECT_DECLS; + byte* buf = NULL; + byte* tampered = NULL; + int bytes = 0; + DecodedCert cert; + WOLFSSL_CERT_MANAGER* cm = NULL; + word32 certBegin = 0; + word32 sigIndex = 0; + + ExpectIntEQ(rfc9802_load_file(path, &buf, &bytes), TEST_SUCCESS); + if (buf == NULL) + return TEST_FAIL; + + /* Parse + check OIDs, capture certBegin and sigIndex for later tamper. */ + wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); + ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); + ExpectIntEQ((int)cert.keyOID, (int)expectedKeyOID); + ExpectIntEQ((int)cert.signatureOID, (int)expectedSigOID); + certBegin = cert.certBegin; + sigIndex = cert.sigIndex; + wc_FreeDecodedCert(&cert); + + /* Full verify against a self-installed trust anchor. */ + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, buf, (long)bytes, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + + ExpectNotNull(tampered = (byte*)XMALLOC((size_t)bytes, NULL, + DYNAMIC_TYPE_TMP_BUFFER)); + + /* Negative 1: flip a byte inside the signatureValue BIT STRING. + * Everything after sigIndex is the signatureAlgorithm + the BIT + * STRING payload, so flipping the last byte is always inside the + * signature content. */ + if (tampered != NULL) { + XMEMCPY(tampered, buf, (size_t)bytes); + tampered[bytes - 1] ^= 0x01; + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, tampered, + (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + } + + /* Negative 2: flip a byte at the midpoint of the TBSCertificate. The + * TBS is the first element of the outer Certificate SEQUENCE and + * its bytes lie between (certBegin + outerSeqHeader) and sigIndex. + * Picking the midpoint ensures we're inside TBS regardless of the + * fixture's DN / extensions layout. */ + if (tampered != NULL && sigIndex > certBegin + 8U) { + word32 midTbs = certBegin + 8 + ((sigIndex - (certBegin + 8)) / 2); + XMEMCPY(tampered, buf, (size_t)bytes); + tampered[midTbs] ^= 0x01; + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, tampered, + (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + } + + /* The fixtures MUST carry a KeyUsage extension with at least one of + * digitalSignature / nonRepudiation / keyCertSign / cRLSign set per + * RFC 9802 sec 3. Re-parse and assert that wolfSSL recorded a non- + * empty set of KeyUsage bits from one of those values. */ + wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); + ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); + ExpectIntEQ(cert.extKeyUsageSet, 1); + ExpectIntNE(cert.extKeyUsage & (KEYUSE_DIGITAL_SIG | KEYUSE_CONTENT_COMMIT | + KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN), 0); + wc_FreeDecodedCert(&cert); + + XFREE(tampered, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + return EXPECT_RESULT(); +} +#endif + +/* Direct wolfCrypt-level negative tests for the parameter-derivation + * helpers used by the RFC 9802 parse path. These exercise failure modes + * (unknown algorithm bytes, truncated inputs, mismatches) that a real + * cert body wouldn't easily reach. */ +#if defined(WOLFSSL_HAVE_LMS) +static int rfc9802_lms_import_negative(void) +{ + EXPECT_DECLS; + LmsKey key; + /* 60-byte buffer matches HSS_PUBLIC_KEY_LEN(32), just like a valid + * SHA-256/M32/H5 key; the algorithm-type bytes are junk so param + * derivation must fail cleanly. */ + byte junk[60]; + + XMEMSET(junk, 0, sizeof(junk)); + /* levels=1, lmsType=0xFFFFFFFF, lmOtsType=0xFFFFFFFF. */ + junk[3] = 1; + XMEMSET(junk + 4, 0xFF, 4); + XMEMSET(junk + 8, 0xFF, 4); + + /* Unknown algorithm types must be rejected. */ + ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, sizeof(junk)), + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + wc_LmsKey_Free(&key); + + /* Too-short buffer: only L + lmsType, no lmOtsType. */ + ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, 8), + WC_NO_ERR_TRACE(BUFFER_E)); + wc_LmsKey_Free(&key); + +#if !defined(WOLFSSL_NO_LMS_SHA256_256) + /* The two cases below pin specific SHA-256/M32 parameter codes + * (L1_H5_W8, L1_H5_W4, L1_H10_W2). Skip them in builds where the + * SHA-256/M32 family is disabled -- the family-agnostic checks + * above (junk algorithm types, too-short buffer, GetSigLen on + * unconfigured key) still cover the universal invariants. */ + + /* Pre-set params that disagree with the raw key's algorithm bytes: + * configure H=5/W=8 but feed buffer that claims H=10 / W=2. */ + XMEMSET(junk, 0, sizeof(junk)); + junk[3] = 1; /* levels=1 */ + junk[7] = 6; /* lmsType = LMS_SHA256_M32_H10 = 6 */ + junk[11] = 2; /* lmOtsType = LMOTS_SHA256_N32_W2 = 2 */ + ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_LmsKey_SetParameters(&key, 1, 5, 8), 0); + ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, junk, sizeof(junk)), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_LmsKey_Free(&key); +#endif /* !WOLFSSL_NO_LMS_SHA256_256 */ + + /* GetSigLen on a key with no params set must not NULL-deref the + * params pointer; it must return BAD_FUNC_ARG instead. */ + { + word32 sigLen = 0; + ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_LmsKey_GetSigLen(&key, &sigLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_LmsKey_Free(&key); + } + +#if !defined(WOLFSSL_NO_LMS_SHA256_256) + /* Partial-write invariant: a length mismatch after a successful + * auto-derive must leave key->params NULL. Build a buffer whose + * leading u32str(L) || lmsType || lmOtsType identifies a known + * parameter set, but truncate to one byte less than the real pub + * key length so the post-derive length check fails. */ + { + byte truncated[59]; /* HSS_PUBLIC_KEY_LEN(32) is 60 */ + XMEMSET(truncated, 0, sizeof(truncated)); + truncated[3] = 1; /* L = 1 */ + truncated[7] = 5; /* lmsType = LMS_SHA256_M32_H5 */ + truncated[11] = 4; /* lmOtsType = LMOTS_SHA256_N32_W4 */ + ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectNull(key.params); + ExpectIntEQ(wc_LmsKey_ImportPubRaw(&key, truncated, + sizeof(truncated)), WC_NO_ERR_TRACE(BUFFER_E)); + ExpectNull(key.params); + wc_LmsKey_Free(&key); + } +#endif /* !WOLFSSL_NO_LMS_SHA256_256 */ + + return EXPECT_RESULT(); +} +#endif + +#if defined(WOLFSSL_HAVE_XMSS) +static int rfc9802_xmss_import_negative(void) +{ + EXPECT_DECLS; + XmssKey key; + byte junk[8]; + + XMEMSET(junk, 0, sizeof(junk)); + + /* Too-short buffer. */ + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, 2, 0), + WC_NO_ERR_TRACE(BUFFER_E)); + wc_XmssKey_Free(&key); + + /* Unknown OID (all-zero) for both XMSS and XMSS^MT. */ + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, sizeof(junk), 0), + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + wc_XmssKey_Free(&key); + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, junk, sizeof(junk), 1), + WC_NO_ERR_TRACE(NOT_COMPILED_IN)); + wc_XmssKey_Free(&key); + + /* NULL key / input. */ + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(NULL, junk, sizeof(junk), 0), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, NULL, 8, 0), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_XmssKey_Free(&key); + + /* GetSigLen on a key with no params set must not NULL-deref the + * params pointer; it must return BAD_FUNC_ARG instead. */ + { + word32 sigLen = 0; + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_GetSigLen(&key, &sigLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_XmssKey_Free(&key); + } + + /* Once params have been configured (state != INITED), the OID + * prefix in the raw key MUST match key->oid and is_xmssmt MUST + * match key->is_xmssmt. Set XMSS-SHA2_10_256 and feed a valid- + * sized buffer whose 4-byte OID prefix is bogus -> BAD_FUNC_ARG. */ + { + byte mismatch[XMSS_SHA256_PUBLEN]; + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0); + XMEMSET(mismatch, 0, sizeof(mismatch)); + mismatch[3] = 0x77; /* nonsense OID */ + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, mismatch, + sizeof(mismatch), 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* Same buffer with the correct OID, but is_xmssmt hint + * contradicts the configured family -> BAD_FUNC_ARG. */ + mismatch[3] = 0x01; /* WC_XMSS_OID_SHA2_10_256 */ + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, mismatch, + sizeof(mismatch), 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_XmssKey_Free(&key); + } + + /* Partial-write invariant: a length mismatch after a successful + * auto-derive must leave the key in its INITED state, with + * key->params NULL. */ + { + byte truncated[XMSS_SHA256_PUBLEN - 1]; + XMEMSET(truncated, 0, sizeof(truncated)); + truncated[3] = 0x01; + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectNull(key.params); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, truncated, + sizeof(truncated), 0), WC_NO_ERR_TRACE(BUFFER_E)); + ExpectNull(key.params); + wc_XmssKey_Free(&key); + } + + /* is_xmssmt disambiguation: XMSS oid=1 and XMSS^MT oid=1 share + * the wire-numeric value but resolve to different parameter sets. + * Importing the same 68-byte buffer with hint=0 vs hint=1 must + * land in different tables and produce distinct is_xmssmt. */ + { + byte buf[XMSS_SHA256_PUBLEN]; + XMEMSET(buf, 0, sizeof(buf)); + buf[3] = 0x01; + + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); + ExpectIntEQ((int)key.is_xmssmt, 0); + wc_XmssKey_Free(&key); + + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 1), 0); + ExpectIntEQ((int)key.is_xmssmt, 1); + wc_XmssKey_Free(&key); + } + + /* Lenient state: re-importing the same pub key into a VERIFYONLY + * key (params set, no private material) succeeds. The second + * call exercises the lenient-state branch. */ + { + byte buf[XMSS_SHA256_PUBLEN]; + XMEMSET(buf, 0, sizeof(buf)); + buf[3] = 0x01; + + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); + ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, buf, sizeof(buf), 0), 0); + ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); + wc_XmssKey_Free(&key); + } + + /* Strict signature-length check: wc_XmssKey_Verify rejects any + * sigLen != key->params->sig_len. This guards every consumer + * (RFC 9802 X.509, PKCS#7, CMS, ...) against a longer wrapper that + * happens to start with a valid signature. Construct a key in + * VERIFYONLY state, then verify with sig_len + 1 and sig_len - 1 + * byte buffers; both must fail with BUFFER_E before any crypto + * runs. The buffer contents are irrelevant since the length check + * fires first. */ + { + byte pub[XMSS_SHA256_PUBLEN]; + byte* sigBuf = NULL; + word32 sigLen = 0; + const byte msg[1] = { 0 }; + + XMEMSET(pub, 0, sizeof(pub)); + pub[3] = 0x01; + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, pub, sizeof(pub), 0), 0); + ExpectIntEQ((int)key.state, (int)WC_XMSS_STATE_VERIFYONLY); + ExpectIntEQ(wc_XmssKey_GetSigLen(&key, &sigLen), 0); + ExpectIntGT(sigLen, 0); + ExpectNotNull(sigBuf = (byte*)XMALLOC((size_t)sigLen + 1, NULL, + DYNAMIC_TYPE_TMP_BUFFER)); + if (sigBuf != NULL) { + XMEMSET(sigBuf, 0, (size_t)sigLen + 1); + ExpectIntEQ(wc_XmssKey_Verify(&key, sigBuf, sigLen + 1, + msg, (int)sizeof(msg)), WC_NO_ERR_TRACE(BUFFER_E)); + ExpectIntEQ(wc_XmssKey_Verify(&key, sigBuf, sigLen - 1, + msg, (int)sizeof(msg)), WC_NO_ERR_TRACE(BUFFER_E)); + XFREE(sigBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + } + wc_XmssKey_Free(&key); + } + + /* BAD_STATE_E branch: WC_XMSS_STATE_OK must be rejected. Reaching + * OK normally requires a successful private-key Reload / sign, + * which is unavailable in WOLFSSL_XMSS_VERIFY_ONLY builds. Force + * the state directly to exercise the rejection without coupling + * this helper to the signing test fixture; sk stays NULL so Free + * is still safe. */ + { + byte pub[XMSS_SHA256_PUBLEN]; + + XMEMSET(pub, 0, sizeof(pub)); + pub[3] = 0x01; + ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0); + ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0); + key.state = WC_XMSS_STATE_OK; + ExpectIntEQ(wc_XmssKey_ImportPubRaw_ex(&key, pub, sizeof(pub), 0), + WC_NO_ERR_TRACE(BAD_STATE_E)); + wc_XmssKey_Free(&key); + } + + return EXPECT_RESULT(); +} +#endif + +/* Walk the AlgorithmIdentifier SEQUENCE that begins at sigIndex and + * locate the byte offset of the last byte of its OID content. Handles + * both short-form (length < 128) and long-form DER length encodings, + * so a future fixture-regenerator that emits longer OIDs / SEQUENCEs + * still drives this test rather than tripping the loud-fail branch. + * + * Returns 0 on success with *oidLastByte set; returns -1 on any DER + * shape mismatch. */ +#if defined(WOLFSSL_HAVE_XMSS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) +static int rfc9802_find_sig_alg_oid_last_byte(const byte* buf, word32 bufLen, + word32 sigIndex, word32* oidLastByte) +{ + word32 idx = sigIndex; + word32 oidContentLen = 0; + + /* AlgorithmIdentifier ::= SEQUENCE { algorithm OID, ... } */ + if (idx >= bufLen || buf[idx] != 0x30) + return -1; + idx++; + /* Skip SEQUENCE length (short or long form). */ + if (idx >= bufLen) + return -1; + if (buf[idx] < 0x80) { + idx++; + } + else { + word32 nbytes = (word32)(buf[idx] & 0x7F); + if (nbytes == 0 || nbytes > 4 || idx + 1 + nbytes > bufLen) + return -1; + idx += 1 + nbytes; + } + /* algorithm OID tag. */ + if (idx >= bufLen || buf[idx] != 0x06) + return -1; + idx++; + /* OID length (short or long form). */ + if (idx >= bufLen) + return -1; + if (buf[idx] < 0x80) { + oidContentLen = buf[idx]; + idx++; + } + else { + word32 nbytes = (word32)(buf[idx] & 0x7F); + word32 i; + if (nbytes == 0 || nbytes > 4 || idx + 1 + nbytes > bufLen) + return -1; + for (i = 0; i < nbytes; i++) + oidContentLen = (oidContentLen << 8) | buf[idx + 1 + i]; + idx += 1 + nbytes; + } + if (oidContentLen == 0 || idx + oidContentLen > bufLen) + return -1; + *oidLastByte = idx + oidContentLen - 1; + return 0; +} + +/* Helper: load fixture, locate last byte of outer signatureAlgorithm + * OID, patch it from `expected` to `swap`, and assert that verifying + * the patched cert against itself as a trust anchor fails. */ +static int rfc9802_assert_oid_patch_breaks_verify(const char* path, + byte expectedLastByte, byte patchedLastByte) +{ + EXPECT_DECLS; + byte* buf = NULL; + int bytes = 0; + DecodedCert cert; + WOLFSSL_CERT_MANAGER* cm = NULL; + word32 sigIndex = 0; + word32 lastOidByte = 0; + + ExpectIntEQ(rfc9802_load_file(path, &buf, &bytes), TEST_SUCCESS); + if (buf == NULL) + return TEST_FAIL; + + wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL); + ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0); + sigIndex = cert.sigIndex; + wc_FreeDecodedCert(&cert); + + ExpectIntEQ(rfc9802_find_sig_alg_oid_last_byte(buf, (word32)bytes, + sigIndex, &lastOidByte), 0); + /* Sanity-check the fixture matches the family the caller asserted, + * so a future regenerator swapping fixtures fails loudly here + * rather than silently testing the wrong direction. */ + ExpectIntEQ((int)buf[lastOidByte], (int)expectedLastByte); + + if (lastOidByte < (word32)bytes && + buf[lastOidByte] == expectedLastByte) { + buf[lastOidByte] = patchedLastByte; + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + /* After the patch the cert's outer signatureAlgorithm and SPKI + * disagree. Verification must fail somewhere (at parse, at + * load, or at ConfirmSignature). The load is best-effort - + * some shape changes get caught there, others only at verify. */ + (void)wolfSSL_CertManagerLoadCABuffer(cm, buf, (long)bytes, + WOLFSSL_FILETYPE_ASN1); + ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, buf, + (long)bytes, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + } + + XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + return EXPECT_RESULT(); +} + +/* X.509-level negative: swap the outer signatureAlgorithm OID byte so + * the cert declares XMSS where the SPKI is XMSS^MT, and vice versa. + * SigOidMatchesKeyOid must reject both directions before any crypto. */ +static int rfc9802_xmss_sig_oid_mismatch(void) +{ + EXPECT_DECLS; + /* XMSS sigOID ends 0x22; XMSS^MT sigOID ends 0x23. Patch each + * direction so the asymmetric-key path is exercised both ways - + * a regression that only stripped the check from one branch of + * SigOidMatchesKeyOid would otherwise be missed. */ + ExpectIntEQ(rfc9802_assert_oid_patch_breaks_verify( + "./certs/xmss/bc_xmss_sha2_10_256_root.der", + /* expected XMSS */ 0x22, /* patched to XMSS^MT */ 0x23), + TEST_SUCCESS); + ExpectIntEQ(rfc9802_assert_oid_patch_breaks_verify( + "./certs/xmss/bc_xmssmt_sha2_20_2_256_root.der", + /* expected XMSS^MT */ 0x23, /* patched to XMSS */ 0x22), + TEST_SUCCESS); + return EXPECT_RESULT(); +} +#endif + +/* Exercise a real CA -> leaf certificate chain, not just self-signed. + * Loads the CA as a trust anchor and verifies the leaf against it. */ +#if defined(WOLFSSL_HAVE_LMS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) +static int rfc9802_lms_chain_verify(void) +{ + EXPECT_DECLS; + byte* caBuf = NULL; + byte* leafBuf = NULL; + int caLen = 0; + int leafLen = 0; + WOLFSSL_CERT_MANAGER* cm = NULL; + + ExpectIntEQ(rfc9802_load_file("./certs/lms/bc_lms_chain_ca.der", + &caBuf, &caLen), TEST_SUCCESS); + ExpectIntEQ(rfc9802_load_file("./certs/lms/bc_lms_chain_leaf.der", + &leafBuf, &leafLen), TEST_SUCCESS); + + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + /* Only the CA is a trust anchor; the leaf is verified against it. */ + ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, caBuf, (long)caLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + + /* Without loading the CA the leaf must NOT verify. */ + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + + XFREE(leafBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(caBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + return EXPECT_RESULT(); +} +#endif + +/* Mirror of rfc9802_lms_chain_verify but for an XMSS CA -> leaf pair. */ +#if defined(WOLFSSL_HAVE_XMSS) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) +static int rfc9802_xmss_chain_verify(void) +{ + EXPECT_DECLS; + byte* caBuf = NULL; + byte* leafBuf = NULL; + int caLen = 0; + int leafLen = 0; + WOLFSSL_CERT_MANAGER* cm = NULL; + + ExpectIntEQ(rfc9802_load_file("./certs/xmss/bc_xmss_chain_ca.der", + &caBuf, &caLen), TEST_SUCCESS); + ExpectIntEQ(rfc9802_load_file("./certs/xmss/bc_xmss_chain_leaf.der", + &leafBuf, &leafLen), TEST_SUCCESS); + + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, caBuf, (long)caLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + ExpectNotNull(cm = wolfSSL_CertManagerNew()); + ExpectIntNE(wolfSSL_CertManagerVerifyBuffer(cm, leafBuf, (long)leafLen, + WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); + if (cm != NULL) { + wolfSSL_CertManagerFree(cm); + cm = NULL; + } + + XFREE(leafBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(caBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + return EXPECT_RESULT(); +} +#endif + +int test_rfc9802_lms_x509_verify(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_LMS) +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ + !defined(WOLFSSL_NO_LMS_SHA256_256) + /* Mixed single-level LMS and multi-level HSS fixtures. The HSS + * public key carries only the top-level LMS/LM-OTS types, so + * wc_LmsKey_ImportPubRaw's auto-derive path searches the map + * by (levels, lmsType, lmOtsType). The bc_lms_native_bc_root + * fixture is generated through Bouncy Castle's stock + * JcaContentSignerBuilder("LMS") + JcaX509v3CertificateBuilder + * with no overrides; including it here is the cross-impl interop + * gate (BC's native LMS X.509 path is RFC 9802-compliant for HSS/ + * LMS, so wolfSSL must accept it end-to-end). + * + * All fixtures use the SHA-256/M32 family, so the whole block + * is gated on that family being compiled in. Truncated SHA-256/192 + * or SHAKE-only builds skip this block. */ + static const char* const lmsFiles[] = { + "./certs/lms/bc_lms_sha256_h5_w4_root.der", +#if !defined(WOLFSSL_LMS_MAX_HEIGHT) || (WOLFSSL_LMS_MAX_HEIGHT >= 10) + "./certs/lms/bc_lms_sha256_h10_w8_root.der", +#endif +#if !defined(WOLFSSL_LMS_MAX_LEVELS) || (WOLFSSL_LMS_MAX_LEVELS >= 2) + "./certs/lms/bc_hss_L2_H5_W8_root.der", +#endif +#if !defined(WOLFSSL_LMS_MAX_LEVELS) || (WOLFSSL_LMS_MAX_LEVELS >= 3) + "./certs/lms/bc_hss_L3_H5_W4_root.der", +#endif + "./certs/lms/bc_lms_native_bc_root.der", + }; + size_t i; + for (i = 0; i < sizeof(lmsFiles) / sizeof(lmsFiles[0]); i++) { + ExpectIntEQ(rfc9802_verify_one_cert(lmsFiles[i], + HSS_LMSk, CTC_HSS_LMS), TEST_SUCCESS); + } + ExpectIntEQ(rfc9802_lms_chain_verify(), TEST_SUCCESS); +#endif /* !NO_FILESYSTEM && !NO_CERTS && !WOLFSSL_NO_LMS_SHA256_256 */ + /* Pure wolfCrypt-level negative tests don't need filesystem or cert + * support, so they run for any LMS-enabled build. */ + ExpectIntEQ(rfc9802_lms_import_negative(), TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + +int test_rfc9802_xmss_x509_verify(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_XMSS) +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) + static const char* const xmssFiles[] = { + "./certs/xmss/bc_xmss_sha2_10_256_root.der", + "./certs/xmss/bc_xmss_sha2_16_256_root.der", + }; + static const char* const xmssmtFiles[] = { + "./certs/xmss/bc_xmssmt_sha2_20_2_256_root.der", + "./certs/xmss/bc_xmssmt_sha2_20_4_256_root.der", + "./certs/xmss/bc_xmssmt_sha2_40_8_256_root.der", + }; + size_t i; + for (i = 0; i < sizeof(xmssFiles) / sizeof(xmssFiles[0]); i++) { + ExpectIntEQ(rfc9802_verify_one_cert(xmssFiles[i], + XMSSk, CTC_XMSS), TEST_SUCCESS); + } + for (i = 0; i < sizeof(xmssmtFiles) / sizeof(xmssmtFiles[0]); i++) { + ExpectIntEQ(rfc9802_verify_one_cert(xmssmtFiles[i], + XMSSMTk, CTC_XMSSMT), TEST_SUCCESS); + } + ExpectIntEQ(rfc9802_xmss_sig_oid_mismatch(), TEST_SUCCESS); + ExpectIntEQ(rfc9802_xmss_chain_verify(), TEST_SUCCESS); +#endif /* !NO_FILESYSTEM && !NO_CERTS */ + /* Pure wolfCrypt-level negative tests don't need filesystem or cert + * support, so they run for any XMSS-enabled build. */ + ExpectIntEQ(rfc9802_xmss_import_negative(), TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_lms_xmss.h b/tests/api/test_lms_xmss.h new file mode 100644 index 0000000000..b2ff579987 --- /dev/null +++ b/tests/api/test_lms_xmss.h @@ -0,0 +1,39 @@ +/* test_lms_xmss.h + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#ifndef WOLFCRYPT_TEST_LMS_XMSS_H +#define WOLFCRYPT_TEST_LMS_XMSS_H + +#include + +int test_wc_LmsKey_sign_verify(void); +int test_wc_LmsKey_reload_cache(void); +int test_rfc9802_lms_x509_verify(void); +int test_rfc9802_xmss_x509_verify(void); + +/* LMS, and RFC 9802 (HSS/LMS and XMSS/XMSS^MT in X.509). */ +#define TEST_LMS_XMSS_DECLS \ + TEST_DECL_GROUP("lms", test_wc_LmsKey_sign_verify), \ + TEST_DECL_GROUP("lms", test_wc_LmsKey_reload_cache), \ + TEST_DECL_GROUP("lms", test_rfc9802_lms_x509_verify), \ + TEST_DECL_GROUP("xmss", test_rfc9802_xmss_x509_verify) + +#endif /* WOLFCRYPT_TEST_LMS_XMSS_H */ diff --git a/tests/api/test_mldsa.c b/tests/api/test_mldsa.c index dc52a54453..5a91f220c3 100644 --- a/tests/api/test_mldsa.c +++ b/tests/api/test_mldsa.c @@ -30508,3 +30508,85 @@ WOLFSSL_MLDSA_API_CHECK_INLINE void wc_mldsa_canonical_api_check(void) PRAGMA_CLANG_DIAG_POP #endif /* WOLFSSL_HAVE_MLDSA */ + +/*----------------------------------------------------------------------------*/ +/* ML-DSA / Dilithium negative length-validation tests */ +/*----------------------------------------------------------------------------*/ + +/* ML-DSA HashML-DSA verify must reject hashLen > WC_MAX_DIGEST_SIZE */ +int test_mldsa_verify_hash(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_MLDSA) && \ + !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ + !defined(WOLFSSL_MLDSA_NO_VERIFY) + wc_MlDsaKey key; + WC_RNG rng; + int res = 0; + byte sig[4000]; + byte hash[4096]; /* larger than WC_MAX_DIGEST_SIZE */ + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(sig, 0x41, sizeof(sig)); + XMEMSET(hash, 'A', sizeof(hash)); + + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); +#ifndef WOLFSSL_NO_ML_DSA_65 + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_65), 0); +#elif !defined(WOLFSSL_NO_ML_DSA_44) + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); +#else + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_87), 0); +#endif + ExpectIntEQ(wc_MlDsaKey_MakeKey(&key, &rng), 0); + + /* hashLen=4096 must be rejected, not overflow the stack */ + ExpectIntEQ(wc_MlDsaKey_VerifyCtxHash(&key, sig, sizeof(sig), NULL, 0, + hash, sizeof(hash), WC_HASH_TYPE_SHA256, &res), + WC_NO_ERR_TRACE(BAD_LENGTH_E)); + + wc_MlDsaKey_Free(&key); + DoExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + return EXPECT_RESULT(); +} + +/* Dilithium verify_ctx_msg must reject absurdly large msgLen */ +int test_dilithium_hash(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_HAVE_MLDSA) && \ + !defined(WOLFSSL_MLDSA_NO_MAKE_KEY) && \ + !defined(WOLFSSL_MLDSA_NO_VERIFY) + wc_MlDsaKey key; + WC_RNG rng; + int res = 0; + byte sig[4000]; + byte msg[64]; + + XMEMSET(&key, 0, sizeof(key)); + XMEMSET(&rng, 0, sizeof(rng)); + XMEMSET(sig, 0, sizeof(sig)); + XMEMSET(msg, 'A', sizeof(msg)); + + ExpectIntEQ(wc_InitRng(&rng), 0); + ExpectIntEQ(wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID), 0); +#ifndef WOLFSSL_NO_ML_DSA_65 + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_65), 0); +#elif !defined(WOLFSSL_NO_ML_DSA_44) + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44), 0); +#else + ExpectIntEQ(wc_MlDsaKey_SetParams(&key, WC_ML_DSA_87), 0); +#endif + ExpectIntEQ(wc_MlDsaKey_MakeKey(&key, &rng), 0); + + ExpectIntEQ(wc_MlDsaKey_VerifyCtx(&key, sig, sizeof(sig), NULL, 0, + msg, 0xFFFFFFC0, &res), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + + wc_MlDsaKey_Free(&key); + DoExpectIntEQ(wc_FreeRng(&rng), 0); +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_mldsa.h b/tests/api/test_mldsa.h index 82c844b54e..631ebabdc1 100644 --- a/tests/api/test_mldsa.h +++ b/tests/api/test_mldsa.h @@ -51,6 +51,11 @@ int test_mldsa_encode_w1_large_values(void); int test_mldsa_pkcs12(void); int test_mldsa_x509_pubkey_sigtype(void); +/* Negative length-validation regression tests, also defined in + * tests/api/test_mldsa.c. */ +int test_mldsa_verify_hash(void); +int test_dilithium_hash(void); + /* Legacy-name shim coverage defined in tests/api/test_mldsa_legacy.c. * Single function -- compile-time wc_static_assert checks for every alias * + one runtime smoke test that drives each arg-reordering macro family. @@ -82,6 +87,8 @@ int test_mldsa_legacy_shim(void); TEST_DECL_GROUP("mldsa", test_mldsa_encode_w1_large_values), \ TEST_DECL_GROUP("mldsa", test_mldsa_pkcs12), \ TEST_DECL_GROUP("mldsa", test_mldsa_x509_pubkey_sigtype), \ + TEST_DECL_GROUP("mldsa", test_mldsa_verify_hash), \ + TEST_DECL_GROUP("mldsa", test_dilithium_hash), \ TEST_DECL_GROUP("mldsa", test_mldsa_legacy_shim) #endif /* WOLFCRYPT_TEST_MLDSA_H */ diff --git a/tests/api/test_ocsp.c b/tests/api/test_ocsp.c index bd4a0633bb..e9df5a6068 100644 --- a/tests/api/test_ocsp.c +++ b/tests/api/test_ocsp.c @@ -247,6 +247,15 @@ int test_ocsp_basic_verify(void) ExpectNull( response = wolfSSL_d2i_OCSP_RESPONSE(NULL, &ptr, sizeof(resp_bad))); + /* reuse failure must clear caller pointer */ + ptr = (const unsigned char*)resp; + ExpectNotNull( + response = wolfSSL_d2i_OCSP_RESPONSE(&response, &ptr, sizeof(resp))); + ptr = (const unsigned char*)resp_bad; + ExpectNull( + wolfSSL_d2i_OCSP_RESPONSE(&response, &ptr, sizeof(resp_bad))); + ExpectNull(response); + ptr = (const unsigned char*)resp; ExpectNotNull( response = wolfSSL_d2i_OCSP_RESPONSE(NULL, &ptr, sizeof(resp))); @@ -765,6 +774,63 @@ int test_ocsp_certid_dup(void) } #endif +int test_ocsp_resp_find_status_serial_prefix(void) +{ + EXPECT_DECLS; +#if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && !defined(NO_SHA) + OcspResponse response; + OcspEntry single; + CertStatus responseStatus; + OcspEntry requestedId; + CertStatus requestedStatus; + int status; + + XMEMSET(&response, 0, sizeof(response)); + XMEMSET(&single, 0, sizeof(single)); + XMEMSET(&responseStatus, 0, sizeof(responseStatus)); + XMEMSET(&requestedId, 0, sizeof(requestedId)); + XMEMSET(&requestedStatus, 0, sizeof(requestedStatus)); + + single.status = &responseStatus; + requestedId.status = &requestedStatus; + response.single = &single; + + /* Matching issuer name and key hashes on both sides. */ + XMEMSET(single.issuerHash, 0x41, OCSP_DIGEST_SIZE); + XMEMSET(single.issuerKeyHash, 0x42, OCSP_DIGEST_SIZE); + XMEMCPY(requestedId.issuerHash, single.issuerHash, OCSP_DIGEST_SIZE); + XMEMCPY(requestedId.issuerKeyHash, single.issuerKeyHash, OCSP_DIGEST_SIZE); + + /* Response carries a CERT_GOOD status for serial 01:02 (2 bytes). */ + responseStatus.serial[0] = 0x01; + responseStatus.serial[1] = 0x02; + responseStatus.serialSz = 2; + responseStatus.status = CERT_GOOD; + + /* Sanity check: an exact serial match must be found and report CERT_GOOD. */ + requestedStatus.serial[0] = 0x01; + requestedStatus.serial[1] = 0x02; + requestedStatus.serialSz = 2; + status = -1; + ExpectIntEQ(wolfSSL_OCSP_resp_find_status(&response, &requestedId, &status, + NULL, NULL, NULL, NULL), WOLFSSL_SUCCESS); + ExpectIntEQ(status, CERT_GOOD); + + /* Request serial 01:02:03 (3 bytes) shares the 01:02 prefix of the + * response serial. + * The lookup must not bind the good response to this longer and + * differing serial. */ + requestedStatus.serial[0] = 0x01; + requestedStatus.serial[1] = 0x02; + requestedStatus.serial[2] = 0x03; + requestedStatus.serialSz = 3; + status = -1; + ExpectIntEQ(wolfSSL_OCSP_resp_find_status(&response, &requestedId, &status, + NULL, NULL, NULL, NULL), WOLFSSL_FAILURE); +#endif + return EXPECT_RESULT(); +} + #if defined(HAVE_OCSP) && defined(WOLFSSL_CERT_SETUP_CB) && \ defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) && \ (defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \ diff --git a/tests/api/test_ocsp.h b/tests/api/test_ocsp.h index a139f56824..41dd21329d 100644 --- a/tests/api/test_ocsp.h +++ b/tests/api/test_ocsp.h @@ -24,6 +24,7 @@ int test_ocsp_certid_enc_dec(void); int test_ocsp_certid_dup(void); +int test_ocsp_resp_find_status_serial_prefix(void); int test_ocsp_status_callback(void); int test_ocsp_basic_verify(void); int test_ocsp_responder_keyhash_binding(void); diff --git a/tests/api/test_ossl_pem.c b/tests/api/test_ossl_pem.c index 547768854e..9715319ae6 100644 --- a/tests/api/test_ossl_pem.c +++ b/tests/api/test_ossl_pem.c @@ -755,6 +755,126 @@ int test_wolfSSL_PEM_PrivateKey(void) return EXPECT_RESULT(); } +int test_wolfSSL_PEM_write_PrivateKey(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \ + !defined(NO_FILESYSTEM) && defined(USE_CERT_BUFFERS_2048) && \ + !defined(NO_ASN) && !defined(NO_PWDBASED) + const char* privFile = "./test-pem-write-private-key.pem"; + const unsigned char* serverKey = + (const unsigned char*)server_key_der_2048; + EVP_PKEY* pkey = NULL; + EVP_PKEY* readPriv = NULL; + XFILE fp = XBADFILE; + + remove(privFile); + + ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &serverKey, + (long)sizeof_server_key_der_2048)); + + /* Bad-argument checks. */ + ExpectIntEQ(PEM_write_PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL, + NULL), 0); + ExpectIntEQ(PEM_write_PrivateKey(stderr, NULL, NULL, NULL, 0, NULL, + NULL), 0); + + /* Write private key to file. */ + ExpectTrue((fp = XFOPEN(privFile, "wb")) != XBADFILE); + if (fp != XBADFILE) { + ExpectIntEQ(PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL), + 1); + XFCLOSE(fp); + fp = XBADFILE; + } + + /* Read it back and verify the DER content matches. */ + ExpectTrue((fp = XFOPEN(privFile, "rb")) != XBADFILE); + if (fp != XBADFILE) { + ExpectNotNull(readPriv = PEM_read_PrivateKey(fp, NULL, NULL, NULL)); + XFCLOSE(fp); + fp = XBADFILE; + } + if ((pkey != NULL) && (readPriv != NULL) && (pkey->pkey.ptr != NULL) && + (readPriv->pkey.ptr != NULL)) { + ExpectIntEQ(pkey->pkey_sz, readPriv->pkey_sz); + ExpectIntEQ(XMEMCMP(pkey->pkey.ptr, readPriv->pkey.ptr, + pkey->pkey_sz), 0); + } + + EVP_PKEY_free(readPriv); + EVP_PKEY_free(pkey); + if (fp != XBADFILE) { + XFCLOSE(fp); + } + remove(privFile); +#endif + return EXPECT_RESULT(); +} + +int test_wolfSSL_PEM_write_PUBKEY(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \ + !defined(NO_FILESYSTEM) && defined(USE_CERT_BUFFERS_2048) && \ + !defined(NO_ASN) && !defined(NO_PWDBASED) + const char* pubFile = "./test-pem-write-pubkey.pem"; + const unsigned char* serverKey = + (const unsigned char*)server_key_der_2048; + EVP_PKEY* pkey = NULL; + EVP_PKEY* readPub = NULL; + unsigned char* pubDer = NULL; + unsigned char* readPubDer = NULL; + XFILE fp = XBADFILE; + int pubDerSz = 0; + int readPubDerSz = 0; + + remove(pubFile); + + ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &serverKey, + (long)sizeof_server_key_der_2048)); + + /* Bad-argument checks. */ + ExpectIntEQ(PEM_write_PUBKEY(XBADFILE, pkey), 0); + ExpectIntEQ(PEM_write_PUBKEY(stderr, NULL), 0); + + /* Capture the expected public-key DER for later comparison. */ + ExpectIntGT(pubDerSz = wolfSSL_i2d_PUBKEY(pkey, &pubDer), 0); + + /* Write public key to file. */ + ExpectTrue((fp = XFOPEN(pubFile, "wb")) != XBADFILE); + if (fp != XBADFILE) { + ExpectIntEQ(PEM_write_PUBKEY(fp, pkey), 1); + XFCLOSE(fp); + fp = XBADFILE; + } + + /* Read it back and verify the DER content matches. */ + ExpectTrue((fp = XFOPEN(pubFile, "rb")) != XBADFILE); + if (fp != XBADFILE) { + ExpectNotNull(readPub = PEM_read_PUBKEY(fp, NULL, NULL, NULL)); + XFCLOSE(fp); + fp = XBADFILE; + } + ExpectIntGT(readPubDerSz = wolfSSL_i2d_PUBKEY(readPub, &readPubDer), 0); + ExpectIntEQ(pubDerSz, readPubDerSz); + if ((pubDer != NULL) && (readPubDer != NULL) && (pubDerSz > 0) && + (pubDerSz == readPubDerSz)) { + ExpectIntEQ(XMEMCMP(pubDer, readPubDer, pubDerSz), 0); + } + + XFREE(readPubDer, NULL, DYNAMIC_TYPE_PUBLIC_KEY); + XFREE(pubDer, NULL, DYNAMIC_TYPE_PUBLIC_KEY); + EVP_PKEY_free(readPub); + EVP_PKEY_free(pkey); + if (fp != XBADFILE) { + XFCLOSE(fp); + } + remove(pubFile); +#endif + return EXPECT_RESULT(); +} + int test_wolfSSL_PEM_file_RSAKey(void) { EXPECT_DECLS; diff --git a/tests/api/test_ossl_pem.h b/tests/api/test_ossl_pem.h index 55480d218e..3de900a6fa 100644 --- a/tests/api/test_ossl_pem.h +++ b/tests/api/test_ossl_pem.h @@ -32,6 +32,8 @@ int test_wolfSSL_PEM_PrivateKey_ecc(void); int test_wolfSSL_PEM_PrivateKey_dsa(void); int test_wolfSSL_PEM_PrivateKey_dh(void); int test_wolfSSL_PEM_PrivateKey(void); +int test_wolfSSL_PEM_write_PrivateKey(void); +int test_wolfSSL_PEM_write_PUBKEY(void); int test_wolfSSL_PEM_file_RSAKey(void); int test_wolfSSL_PEM_file_RSAPrivateKey(void); int test_wolfSSL_PEM_read_RSA_PUBKEY(void); @@ -52,6 +54,8 @@ int test_wolfSSL_PEM_PUBKEY(void); TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_PrivateKey_dsa), \ TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_PrivateKey_dh), \ TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_PrivateKey), \ + TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_write_PrivateKey), \ + TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_write_PUBKEY), \ TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_file_RSAKey), \ TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_file_RSAPrivateKey), \ TEST_DECL_GROUP("ossl_pem", test_wolfSSL_PEM_read_RSA_PUBKEY), \ diff --git a/tests/api/test_ossl_x509_crypto.c b/tests/api/test_ossl_x509_crypto.c index 01f5735480..4c84d40617 100644 --- a/tests/api/test_ossl_x509_crypto.c +++ b/tests/api/test_ossl_x509_crypto.c @@ -71,6 +71,114 @@ int test_wolfSSL_X509_check_private_key(void) return EXPECT_RESULT(); } +/* EVP_PKCS82PKEY() must populate pkey.ptr/pkey_sz for ML-DSA so + * X509_check_private_key() (wc_CheckPrivateKey) can redecode the DER, and + * d2i_PKCS8_PKEY() must keep the full PKCS#8 wrapper for ML-DSA level recovery + * from the AlgorithmIdentifier. */ +int test_wolfSSL_X509_check_private_key_mldsa(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \ + !defined(NO_BIO) && !defined(NO_CHECK_PRIVATE_KEY) && \ + defined(HAVE_DILITHIUM) && !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \ + !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \ + (defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)) && \ + (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_NO_ML_DSA_65) || \ + !defined(WOLFSSL_NO_ML_DSA_87)) + static const struct { + const char* keyPath; + const char* certPath; + const char* mismatchCertPath; /* NULL if no other level available */ + } cases[] = { + #if !defined(WOLFSSL_NO_ML_DSA_44) + { "./certs/mldsa/mldsa44-key.pem", + "./certs/mldsa/mldsa44-cert.der", + #if !defined(WOLFSSL_NO_ML_DSA_65) + "./certs/mldsa/mldsa65-cert.der" + #elif !defined(WOLFSSL_NO_ML_DSA_87) + "./certs/mldsa/mldsa87-cert.der" + #else + NULL + #endif + }, + #endif + #if !defined(WOLFSSL_NO_ML_DSA_65) + { "./certs/mldsa/mldsa65-key.pem", + "./certs/mldsa/mldsa65-cert.der", + #if !defined(WOLFSSL_NO_ML_DSA_87) + "./certs/mldsa/mldsa87-cert.der" + #elif !defined(WOLFSSL_NO_ML_DSA_44) + "./certs/mldsa/mldsa44-cert.der" + #else + NULL + #endif + }, + #endif + #if !defined(WOLFSSL_NO_ML_DSA_87) + { "./certs/mldsa/mldsa87-key.pem", + "./certs/mldsa/mldsa87-cert.der", + #if !defined(WOLFSSL_NO_ML_DSA_44) + "./certs/mldsa/mldsa44-cert.der" + #elif !defined(WOLFSSL_NO_ML_DSA_65) + "./certs/mldsa/mldsa65-cert.der" + #else + NULL + #endif + }, + #endif + }; + size_t i; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + PKCS8_PRIV_KEY_INFO* pt = NULL; + EVP_PKEY* pkey = NULL; + X509* x509 = NULL; + X509* mismatchX509 = NULL; + BIO* bio = NULL; + byte* buf = NULL; + size_t sz = 0; + + ExpectIntEQ(load_file(cases[i].keyPath, &buf, &sz), 0); + + ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, (int)sz)); + ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL)); + + ExpectNotNull(pkey = EVP_PKCS82PKEY(pt)); + if (pkey != NULL) { + ExpectIntEQ(EVP_PKEY_id(pkey), EVP_PKEY_DILITHIUM); + /* pkey.ptr must hold the DER so that X509_check_private_key() to + * wc_CheckPrivateKey() can re-decode it. */ + ExpectNotNull(pkey->pkey.ptr); + ExpectIntGT(pkey->pkey_sz, 0); + } + + ExpectNotNull(x509 = X509_load_certificate_file( + cases[i].certPath, SSL_FILETYPE_ASN1)); + ExpectIntEQ(X509_check_private_key(x509, pkey), 1); + + if (cases[i].mismatchCertPath != NULL) { + ExpectNotNull(mismatchX509 = X509_load_certificate_file( + cases[i].mismatchCertPath, SSL_FILETYPE_ASN1)); + ExpectIntEQ(X509_check_private_key(mismatchX509, pkey), 0); + } + + /* Negative check, corrupt the outer SEQ tag so the key DER fails */ + if (EXPECT_SUCCESS() && (pkey != NULL) && (pkey->pkey.ptr != NULL)) { + pkey->pkey.ptr[0] ^= 0xFF; + ExpectIntEQ(X509_check_private_key(x509, pkey), 0); + } + + X509_free(mismatchX509); + X509_free(x509); + EVP_PKEY_free(pkey); + PKCS8_PRIV_KEY_INFO_free(pt); + BIO_free(bio); + XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + } +#endif + return EXPECT_RESULT(); +} + int test_wolfSSL_X509_verify(void) { EXPECT_DECLS; diff --git a/tests/api/test_ossl_x509_crypto.h b/tests/api/test_ossl_x509_crypto.h index fe09acf6d1..cf40bca9a3 100644 --- a/tests/api/test_ossl_x509_crypto.h +++ b/tests/api/test_ossl_x509_crypto.h @@ -25,6 +25,7 @@ #include int test_wolfSSL_X509_check_private_key(void); +int test_wolfSSL_X509_check_private_key_mldsa(void); int test_wolfSSL_X509_verify(void); int test_wolfSSL_X509_sign(void); int test_wolfSSL_X509_sign2(void); @@ -32,6 +33,8 @@ int test_wolfSSL_make_cert(void); #define TEST_OSSL_X509_CRYPTO_DECLS \ TEST_DECL_GROUP("ossl_x509_crypto", test_wolfSSL_X509_check_private_key), \ + TEST_DECL_GROUP("ossl_x509_crypto", \ + test_wolfSSL_X509_check_private_key_mldsa), \ TEST_DECL_GROUP("ossl_x509_crypto", test_wolfSSL_X509_verify), \ TEST_DECL_GROUP("ossl_x509_crypto", test_wolfSSL_X509_sign), \ TEST_DECL_GROUP("ossl_x509_crypto", test_wolfSSL_X509_sign2), \ diff --git a/tests/api/test_ossl_x509_ext.c b/tests/api/test_ossl_x509_ext.c index dfc2451529..fb0967be5e 100644 --- a/tests/api/test_ossl_x509_ext.c +++ b/tests/api/test_ossl_x509_ext.c @@ -593,6 +593,70 @@ int test_wolfSSL_X509_add_ext(void) return EXPECT_RESULT(); } +int test_wolfSSL_X509_add_ext_dirname_san_rejected(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_ALL) && !defined(NO_RSA) + WOLFSSL_X509* x509 = NULL; + WOLFSSL_X509_EXTENSION* ext = NULL; + WOLFSSL_ASN1_OBJECT* obj = NULL; + WOLFSSL_GENERAL_NAME* gn = NULL; + WOLFSSL_X509_NAME* dirName = NULL; + WOLFSSL_STACK* sk = NULL; + + ExpectNotNull(x509 = wolfSSL_X509_new()); + ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new()); + + /* Build a GEN_DIRNAME GENERAL_NAME with a real directoryName so that + * gn->d.directoryName aliases an X509_NAME object via the union. */ + ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new()); + ExpectNotNull(dirName = wolfSSL_X509_NAME_new()); + ExpectIntEQ(wolfSSL_X509_NAME_add_entry_by_NID(dirName, NID_commonName, + MBSTRING_UTF8, (unsigned char*)"dirname-san-test", -1, -1, 0), 1); + if (gn != NULL) { + /* Drop the default IA5 string and install the X509_NAME. */ + wolfSSL_ASN1_STRING_free(gn->d.ia5); + gn->type = GEN_DIRNAME; + gn->d.directoryName = dirName; + dirName = NULL; /* gn owns the X509_NAME now */ + } + + /* Build the ext: SAN OID + ext_sk containing the DirName GENERAL_NAME. */ + ExpectNotNull(sk = wolfSSL_sk_new_null()); + if (sk != NULL) { + sk->type = STACK_TYPE_GEN_NAME; + } + ExpectIntGT(wolfSSL_sk_GENERAL_NAME_push(sk, gn), 0); + gn = NULL; /* sk owns gn now */ + + ExpectNotNull(obj = wolfSSL_OBJ_nid2obj(NID_subject_alt_name)); + if (obj != NULL) { + obj->type = NID_subject_alt_name; + obj->nid = NID_subject_alt_name; + } + if ((ext != NULL) && (obj != NULL) && (sk != NULL)) { + ext->obj = obj; + obj = NULL; /* ext owns obj now */ + ext->ext_sk = sk; + sk = NULL; /* ext owns sk now */ + } + + /* The unsupported GeneralName type must be rejected safely, NOT crash + * or read OOB via a type-confused d.ia5 dereference. */ + ExpectIntEQ(wolfSSL_X509_add_ext(x509, ext, -1), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + + /* Cleanup. The success-path owners (set to NULL above) are no-ops. */ + wolfSSL_ASN1_OBJECT_free(obj); + wolfSSL_sk_GENERAL_NAME_pop_free(sk, wolfSSL_GENERAL_NAME_free); + wolfSSL_GENERAL_NAME_free(gn); + wolfSSL_X509_NAME_free(dirName); + wolfSSL_X509_EXTENSION_free(ext); + wolfSSL_X509_free(x509); +#endif + return EXPECT_RESULT(); +} + int test_wolfSSL_X509_get_ext_count(void) { EXPECT_DECLS; @@ -1098,10 +1162,6 @@ int test_wolfSSL_X509V3_EXT_bc(void) ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new()); ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new()); - ExpectNotNull(pathLen = wolfSSL_ASN1_INTEGER_new()); - if (pathLen != NULL) { - pathLen->length = 2; - } if (obj != NULL) { obj->type = NID_basic_constraints; @@ -1109,17 +1169,47 @@ int test_wolfSSL_X509V3_EXT_bc(void) } ExpectIntEQ(wolfSSL_X509_EXTENSION_set_object(ext, obj), WOLFSSL_SUCCESS); ExpectNotNull(wolfSSL_X509V3_EXT_get(ext)); - /* No pathlen set. */ + + /* No pathLenConstraint present. Per RFC 5280 4.2.1.9 no limit is imposed, + * so pathlen must be NULL (and distinguishable from a value of 0). */ ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext)); + ExpectNull(bc->pathlen); wolfSSL_BASIC_CONSTRAINTS_free(bc); bc = NULL; + /* pathLenConstraint of 0 is valid and meaningful (the CA may only issue + * end-entity certificates). It must be preserved, not conflated with an + * absent constraint. */ + ExpectNotNull(pathLen = wolfSSL_ASN1_INTEGER_new()); + if (pathLen != NULL) { + pathLen->length = 0; + } if ((ext != NULL) && (ext->obj != NULL)) { ext->obj->pathlen = pathLen; pathLen = NULL; } - /* pathlen set. */ ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext)); + ExpectNotNull(bc->pathlen); + ExpectIntEQ(bc->pathlen->length, 0); + wolfSSL_BASIC_CONSTRAINTS_free(bc); + bc = NULL; + + /* A non-zero pathLenConstraint is preserved as-is. */ + if ((ext != NULL) && (ext->obj != NULL)) { + wolfSSL_ASN1_INTEGER_free(ext->obj->pathlen); + ext->obj->pathlen = NULL; + } + ExpectNotNull(pathLen = wolfSSL_ASN1_INTEGER_new()); + if (pathLen != NULL) { + pathLen->length = 2; + } + if ((ext != NULL) && (ext->obj != NULL)) { + ext->obj->pathlen = pathLen; + pathLen = NULL; + } + ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext)); + ExpectNotNull(bc->pathlen); + ExpectIntEQ(bc->pathlen->length, 2); wolfSSL_ASN1_INTEGER_free(pathLen); wolfSSL_BASIC_CONSTRAINTS_free(bc); @@ -1129,6 +1219,72 @@ int test_wolfSSL_X509V3_EXT_bc(void) return EXPECT_RESULT(); } +int test_wolfSSL_X509_get_ext_d2i_basic_constraints(void) +{ + EXPECT_DECLS; +#if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA) + XFILE f = XBADFILE; + WOLFSSL_X509* x509 = NULL; + WOLFSSL_BASIC_CONSTRAINTS* bc = NULL; + int crit = 0; + + /* CA certificate with basicConstraints CA:TRUE and *no* pathLenConstraint. + * Per RFC 5280 4.2.1.9 no path length limit is imposed, so the returned + * pathlen must be NULL - it must not be reported as a value of 0. */ + ExpectTrue((f = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE); + ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL)); + if (f != XBADFILE) { + XFCLOSE(f); + f = XBADFILE; + } + ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509_get_ext_d2i( + x509, NID_basic_constraints, &crit, NULL)); + ExpectNull(bc->pathlen); + wolfSSL_BASIC_CONSTRAINTS_free(bc); + bc = NULL; + wolfSSL_X509_free(x509); + x509 = NULL; + + /* Intermediate CA with basicConstraints CA:TRUE, pathlen:1. */ + ExpectTrue((f = XFOPEN("./certs/intermediate/ca-int-cert.pem", "rb")) != + XBADFILE); + ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL)); + if (f != XBADFILE) { + XFCLOSE(f); + f = XBADFILE; + } + ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509_get_ext_d2i( + x509, NID_basic_constraints, &crit, NULL)); + ExpectNotNull(bc->pathlen); + ExpectIntEQ(bc->pathlen->length, 1); + wolfSSL_BASIC_CONSTRAINTS_free(bc); + bc = NULL; + wolfSSL_X509_free(x509); + x509 = NULL; + + /* CA with basicConstraints CA:TRUE, pathlen:0. A pathLenConstraint of 0 is + * valid and meaningful (the CA may only issue end-entity certificates) and + * must be reported (non-NULL pathlen, value 0) - it must not be conflated + * with an absent constraint. */ + ExpectTrue((f = XFOPEN("./certs/test-pathlen/chainG-ICA1-pathlen0.pem", + "rb")) != XBADFILE); + ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL)); + if (f != XBADFILE) { + XFCLOSE(f); + f = XBADFILE; + } + ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509_get_ext_d2i( + x509, NID_basic_constraints, &crit, NULL)); + ExpectNotNull(bc->pathlen); + ExpectIntEQ(bc->pathlen->length, 0); + wolfSSL_BASIC_CONSTRAINTS_free(bc); + bc = NULL; + wolfSSL_X509_free(x509); + x509 = NULL; +#endif + return EXPECT_RESULT(); +} + int test_wolfSSL_X509V3_EXT_san(void) { EXPECT_DECLS; diff --git a/tests/api/test_ossl_x509_ext.h b/tests/api/test_ossl_x509_ext.h index ee749facd9..68be4ebf5e 100644 --- a/tests/api/test_ossl_x509_ext.h +++ b/tests/api/test_ossl_x509_ext.h @@ -30,6 +30,7 @@ int test_wolfSSL_X509_get_ext_by_NID(void); int test_wolfSSL_X509_get_ext_subj_alt_name(void); int test_wolfSSL_X509_set_ext(void); int test_wolfSSL_X509_add_ext(void); +int test_wolfSSL_X509_add_ext_dirname_san_rejected(void); int test_wolfSSL_X509_get_ext_count(void); int test_wolfSSL_X509_stack_extensions(void); int test_wolfSSL_X509_EXTENSION_new(void); @@ -42,6 +43,7 @@ int test_wolfSSL_X509V3_set_ctx(void); int test_wolfSSL_X509V3_EXT_get(void); int test_wolfSSL_X509V3_EXT_nconf(void); int test_wolfSSL_X509V3_EXT_bc(void); +int test_wolfSSL_X509_get_ext_d2i_basic_constraints(void); int test_wolfSSL_X509V3_EXT_san(void); int test_wolfSSL_X509V3_EXT_aia(void); int test_wolfSSL_X509V3_EXT(void); @@ -62,6 +64,8 @@ int test_wolfSSL_NAME_CONSTRAINTS_excluded(void); TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_get_ext_subj_alt_name), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_set_ext), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_add_ext), \ + TEST_DECL_GROUP("ossl_x509_ext", \ + test_wolfSSL_X509_add_ext_dirname_san_rejected), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_get_ext_count), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_stack_extensions), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509_EXTENSION_new), \ @@ -76,6 +80,8 @@ int test_wolfSSL_NAME_CONSTRAINTS_excluded(void); TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT_get), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT_nconf), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT_bc), \ + TEST_DECL_GROUP("ossl_x509_ext", \ + test_wolfSSL_X509_get_ext_d2i_basic_constraints), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT_san), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT_aia), \ TEST_DECL_GROUP("ossl_x509_ext", test_wolfSSL_X509V3_EXT), \ diff --git a/tests/api/test_pkcs12.c b/tests/api/test_pkcs12.c index 8b9e4863e1..cbe2186e8e 100644 --- a/tests/api/test_pkcs12.c +++ b/tests/api/test_pkcs12.c @@ -648,10 +648,12 @@ int test_wc_PKCS12_PBKDF(void) ExpectIntEQ(XMEMCMP(derived, verify2, 24), 0); /* iterations <= 0 must be rejected */ + #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0) ExpectIntEQ(wc_PKCS12_PBKDF(derived, passwd, (int)sizeof(passwd), salt, (int)sizeof(salt), 0, 24, WC_SHA256, 1), BAD_FUNC_ARG); ExpectIntEQ(wc_PKCS12_PBKDF(derived, passwd, (int)sizeof(passwd), salt, (int)sizeof(salt), -1, 24, WC_SHA256, 1), BAD_FUNC_ARG); + #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(7,0,0) */ #endif return EXPECT_RESULT(); } @@ -717,12 +719,14 @@ int test_wc_PKCS12_PBKDF_ex(void) salt, (int)sizeof(salt), 1, 24, WC_SHA256, 3, NULL), 0); /* iterations <= 0 must be rejected */ + #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0) ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd), salt, (int)sizeof(salt), 0, 24, WC_SHA256, 1, NULL), BAD_FUNC_ARG); ExpectIntEQ(wc_PKCS12_PBKDF_ex(derived, passwd, (int)sizeof(passwd), salt, (int)sizeof(salt), -1, 24, WC_SHA256, 1, NULL), BAD_FUNC_ARG); + #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(7,0,0) */ #endif return EXPECT_RESULT(); } diff --git a/tests/api/test_pwdbased.c b/tests/api/test_pwdbased.c index 7facfd2005..92a144c42c 100644 --- a/tests/api/test_pwdbased.c +++ b/tests/api/test_pwdbased.c @@ -29,7 +29,8 @@ int test_wc_PBKDF1_ex_iterations(void) { EXPECT_DECLS; #if defined(HAVE_PBKDF1) && !defined(NO_PWDBASED) && !defined(NO_SHA) && \ - !defined(HAVE_SELFTEST) + !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) + static const byte passwd[] = { 'p', 'a', 's', 's' }; static const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 }; diff --git a/tests/api/test_session.c b/tests/api/test_session.c new file mode 100644 index 0000000000..e7557ff007 --- /dev/null +++ b/tests/api/test_session.c @@ -0,0 +1,1616 @@ +/* test_session.c + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include + +#ifdef NO_INLINE + #include +#else + #define WOLFSSL_MISC_INCLUDED + #include +#endif + +#include +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/* WOLFSSL_CTX_add_session / session resumption */ +/*----------------------------------------------------------------------------*/ + +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \ + !defined(NO_SESSION_CACHE) + +/* Sessions to restore/store */ +static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess; +static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess; +static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx; + +static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx) +{ + /* Don't store sessions. Lookup is still enabled. */ + AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); +#ifdef OPENSSL_EXTRA + AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); +#endif + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); +} + +static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl) +{ + WOLFSSL_SESSION** sess; +#ifdef WOLFSSL_MUTEX_INITIALIZER + static wolfSSL_Mutex m = WOLFSSL_MUTEX_INITIALIZER(m); + + (void)wc_LockMutex(&m); +#endif + if (wolfSSL_is_server(ssl)) + sess = &test_wolfSSL_CTX_add_session_server_sess; + else + sess = &test_wolfSSL_CTX_add_session_client_sess; + if (*sess == NULL) { +#ifdef NO_SESSION_CACHE_REF + *sess = wolfSSL_get1_session(ssl); + AssertNotNull(*sess); +#else + /* Test for backwards compatibility */ + if (wolfSSL_is_server(ssl)) { + *sess = wolfSSL_get1_session(ssl); + AssertNotNull(*sess); + } + else { + *sess = wolfSSL_get_session(ssl); + AssertNotNull(*sess); + } +#endif + /* Now save the session in the internal store to make it available + * for lookup. For TLS 1.3, we can't save the session without + * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the + * session from cache. */ + if (wolfSSL_is_server(ssl) +#ifndef WOLFSSL_TICKET_HAVE_ID + && wolfSSL_version(ssl) != TLS1_3_VERSION +#endif + ) + AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl), + *sess), WOLFSSL_SUCCESS); + } + else { + /* If we have a session retrieved then remaining connections should be + * resuming on that session */ + AssertIntEQ(wolfSSL_session_reused(ssl), 1); + } +#ifdef WOLFSSL_MUTEX_INITIALIZER + wc_UnLockMutex(&m); +#endif + + /* Save CTX to be able to decrypt tickets */ + if (wolfSSL_is_server(ssl) && + test_wolfSSL_CTX_add_session_server_ctx == NULL) { + test_wolfSSL_CTX_add_session_server_ctx = wolfSSL_get_SSL_CTX(ssl); + AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx); + AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)), + WOLFSSL_SUCCESS); + } +#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) +#ifndef WOLFSSL_TICKET_HAVE_ID + if (wolfSSL_version(ssl) != TLS1_3_VERSION && + wolfSSL_session_reused(ssl)) +#endif + { + /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available + * for all connections. TLS 1.3 only has tickets so if we don't + * include the session id in the ticket then the certificates + * will not be available on resumption. */ + #ifdef KEEP_PEER_CERT + WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl); + AssertNotNull(peer); + wolfSSL_X509_free(peer); + #endif + AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); + #ifdef OPENSSL_EXTRA + AssertNotNull(SSL_SESSION_get0_peer(*sess)); + #endif + } +#endif /* SESSION_CERTS && !WOLFSSL_NO_CLIENT_AUTH */ +} + +static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl) +{ + /* Set the session to reuse for the client */ + AssertIntEQ(wolfSSL_set_session(ssl, + test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS); +} +#endif + +int test_wolfSSL_CTX_add_session(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \ + !defined(NO_SESSION_CACHE) + tcp_ready ready; + func_args client_args; + func_args server_args; + THREAD_TYPE serverThread; + callback_functions client_cb; + callback_functions server_cb; + method_provider methods[][2] = { +#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ + !defined(NO_DES3)) + /* Without AES there are almost no ciphersuites available. This leads + * to no ciphersuites being available and an error. */ + { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method }, +#endif +#ifndef WOLFSSL_NO_TLS12 + { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method }, +#endif + /* Needs the default ticket callback since it is tied to the + * connection context and this makes it easy to carry over the ticket + * crypto context between connections */ +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ + defined(HAVE_SESSION_TICKET) + { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method }, +#endif + }; + const size_t methodsLen = sizeof(methods)/sizeof(*methods); + size_t i, j; + + for (i = 0; i < methodsLen; i++) { + /* First run creates a connection while the second+ run will attempt + * to resume the connection. The trick is that the internal cache + * is turned off. wolfSSL_CTX_add_session should put the session in + * the cache anyway. */ + test_wolfSSL_CTX_add_session_client_sess = NULL; + test_wolfSSL_CTX_add_session_server_sess = NULL; + test_wolfSSL_CTX_add_session_server_ctx = NULL; + +#ifdef NO_SESSION_CACHE_REF + for (j = 0; j < 4; j++) { +#else + /* The session may be overwritten in this case. Do only one resumption + * to stop this test from failing intermittently. */ + for (j = 0; j < 2; j++) { +#endif +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + + StartTCP(); + InitTcpReady(&ready); + + XMEMSET(&client_args, 0, sizeof(func_args)); + XMEMSET(&server_args, 0, sizeof(func_args)); + + XMEMSET(&client_cb, 0, sizeof(callback_functions)); + XMEMSET(&server_cb, 0, sizeof(callback_functions)); + client_cb.method = methods[i][0]; + server_cb.method = methods[i][1]; + + server_args.signal = &ready; + server_args.callbacks = &server_cb; + client_args.signal = &ready; + client_args.callbacks = &client_cb; + + if (test_wolfSSL_CTX_add_session_server_ctx != NULL) { + server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx; + server_cb.isSharedCtx = 1; + } + server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready; + client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready; + if (j != 0) + client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready; + server_cb.on_result = test_wolfSSL_CTX_add_session_on_result; + client_cb.on_result = test_wolfSSL_CTX_add_session_on_result; + server_cb.ticNoInit = 1; /* Use default builtin */ + + start_thread(test_server_nofail, &server_args, &serverThread); + wait_tcp_ready(&server_args); + test_client_nofail(&client_args, NULL); + join_thread(serverThread); + + ExpectTrue(client_args.return_code); + ExpectTrue(server_args.return_code); + + FreeTcpReady(&ready); + + if (EXPECT_FAIL()) + break; + } + wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess); + wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess); + wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx); + + if (EXPECT_FAIL()) + break; + } +#endif + + return EXPECT_RESULT(); +} +#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) + +/* twcase - prefix for test_wolfSSL_CTX_add_session_ext */ +/* Sessions to restore/store */ +static WOLFSSL_SESSION* twcase_server_first_session_ptr; +static WOLFSSL_SESSION* twcase_client_first_session_ptr; +static WOLFSSL_CTX* twcase_server_current_ctx_ptr; +static int twcase_new_session_called = 0; +static int twcase_remove_session_called = 0; +static int twcase_get_session_called = 0; + +/* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */ +#define SESSION_CACHE_SIZE 33 + +typedef struct { + const byte* key; /* key, altSessionID, session ID, NULL if empty */ + WOLFSSL_SESSION* value; +} hashTable_entry; + +typedef struct { + hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */ + size_t capacity; /* size of entries */ + size_t length; /* number of items in the hash table */ + wolfSSL_Mutex htLock; /* lock */ +}hashTable; + +static hashTable server_sessionCache; + +static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess) +{ + int i; + unsigned int len; + (void)ssl; + + /* + * This example uses a hash table. + * Steps you should take for a non-demo code: + * - acquire a lock for the file named according to the session id + * - open the file + * - encrypt and write the SSL_SESSION object to the file + * - release the lock + * + * Return: + * 0: The callback does not wish to hold a reference of the sess + * 1: The callback wants to hold a reference of the sess. The callback is + * now also responsible for calling wolfSSL_SESSION_free() on sess. + */ + if (sess == NULL) + return 0; + + if (wc_LockMutex(&server_sessionCache.htLock) != 0) { + return 0; + } + for (i = 0; i < SESSION_CACHE_SIZE; i++) { + if (server_sessionCache.entries[i].value == NULL) { + server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len); + server_sessionCache.entries[i].value = sess; + server_sessionCache.length++; + break; + } + } + ++twcase_new_session_called; + wc_UnLockMutex(&server_sessionCache.htLock); + fprintf(stderr, "\t\ttwcase_new_session_called %d\n", + twcase_new_session_called); + return 1; +} + +static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess) +{ + int i; + (void)ctx; + (void)sess; + + if (sess == NULL) + return; + /* + * This example uses a hash table. + * Steps you should take for a non-demo code: + * - acquire a lock for the file named according to the session id + * - remove the file + * - release the lock + */ + if (wc_LockMutex(&server_sessionCache.htLock) != 0) { + return; + } + for (i = 0; i < SESSION_CACHE_SIZE; i++) { + if (server_sessionCache.entries[i].key != NULL && + XMEMCMP(server_sessionCache.entries[i].key, + sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { + wolfSSL_SESSION_free(server_sessionCache.entries[i].value); + server_sessionCache.entries[i].value = NULL; + server_sessionCache.entries[i].key = NULL; + server_sessionCache.length--; + break; + } + } + ++twcase_remove_session_called; + wc_UnLockMutex(&server_sessionCache.htLock); + fprintf(stderr, "\t\ttwcase_remove_session_called %d\n", + twcase_remove_session_called); +} + +static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl, + const unsigned char *id, int len, int *ref) +{ + int i; + (void)ssl; + (void)id; + (void)len; + + /* + * This example uses a hash table. + * Steps you should take for a non-demo code: + * - acquire a lock for the file named according to the session id in the + * 2nd arg + * - read and decrypt contents of file and create a new SSL_SESSION + * - object release the lock + * - return the new session object + */ + fprintf(stderr, "\t\ttwcase_get_session_called %d\n", + ++twcase_get_session_called); + /* This callback want to retain a copy of the object. If we want wolfSSL to + * be responsible for the pointer then set to 0. */ + *ref = 1; + + for (i = 0; i < SESSION_CACHE_SIZE; i++) { + if (server_sessionCache.entries[i].key != NULL && + XMEMCMP(server_sessionCache.entries[i].key, id, + SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) { + return server_sessionCache.entries[i].value; + } + } + return NULL; +} +static int twcase_get_sessionCb_cleanup(void) +{ + int i; + int cnt = 0; + + /* If twcase_get_sessionCb sets *ref = 1, the application is responsible + * for freeing sessions */ + + for (i = 0; i < SESSION_CACHE_SIZE; i++) { + if (server_sessionCache.entries[i].value != NULL) { + wolfSSL_SESSION_free(server_sessionCache.entries[i].value); + cnt++; + } + } + + fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n", + cnt); + + return TEST_SUCCESS; +} + +static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx) +{ + EXPECT_DECLS; + /* off - Disable internal cache */ + ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); +#ifdef OPENSSL_EXTRA + ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); +#endif + /* off - Do not setup external cache */ + + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); + return EXPECT_RESULT(); +} + +static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx) +{ + /* on - internal cache is on by default */ + /* off - Do not setup external cache */ + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); + return TEST_SUCCESS; +} + +static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx) +{ + EXPECT_DECLS; + /* off - Disable internal cache */ + ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS); +#ifdef OPENSSL_EXTRA + ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) & + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE, + WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE); +#endif + /* on - Enable external cache */ + wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); + wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); + wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); + + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); + return EXPECT_RESULT(); +} + +static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx) +{ + /* on - internal cache is on by default */ + /* on - Enable external cache */ + wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); + wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); + wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); + + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); + return TEST_SUCCESS; +} +static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx) +{ + /* on - internal cache is on by default */ + /* on - Enable external cache */ + wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb); + wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb); + wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb); + + wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET); + /* Require both peers to provide certs */ + wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL); + return TEST_SUCCESS; +} +static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl) +{ + EXPECT_DECLS; + WOLFSSL_SESSION** sess; + if (wolfSSL_is_server(ssl)) + sess = &twcase_server_first_session_ptr; + else + return TEST_SUCCESS; + + if (*sess == NULL) { + ExpectNotNull(*sess = wolfSSL_get1_session(ssl)); + /* Now save the session in the internal store to make it available + * for lookup. For TLS 1.3, we can't save the session without + * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the + * session from cache. */ + if (wolfSSL_is_server(ssl) +#ifndef WOLFSSL_TICKET_HAVE_ID + && wolfSSL_version(ssl) != TLS1_3_VERSION + && wolfSSL_version(ssl) != DTLS1_3_VERSION +#endif + ) { + ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl), + *sess), WOLFSSL_SUCCESS); + } + } + /* Save CTX to be able to decrypt tickets */ + if (twcase_server_current_ctx_ptr == NULL) { + ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl)); + ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)), + WOLFSSL_SUCCESS); + } +#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) +#ifndef WOLFSSL_TICKET_HAVE_ID + if (wolfSSL_version(ssl) != TLS1_3_VERSION && + wolfSSL_session_reused(ssl)) +#endif + { + /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available + * for all connections. TLS 1.3 only has tickets so if we don't + * include the session id in the ticket then the certificates + * will not be available on resumption. */ + #ifdef KEEP_PEER_CERT + WOLFSSL_X509* peer = NULL; + ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl)); + wolfSSL_X509_free(peer); + #endif + ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); + } +#endif + return EXPECT_RESULT(); +} + +static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl) +{ + EXPECT_DECLS; + WOLFSSL_SESSION** sess; + sess = &twcase_client_first_session_ptr; + if (*sess == NULL) { + ExpectNotNull(*sess = wolfSSL_get1_session(ssl)); + } + else { + /* If we have a session retrieved then remaining connections should be + * resuming on that session */ + ExpectIntEQ(wolfSSL_session_reused(ssl), 1); + } + +#if defined(SESSION_CERTS) && !defined(WOLFSSL_NO_CLIENT_AUTH) +#ifndef WOLFSSL_TICKET_HAVE_ID + if (wolfSSL_version(ssl) != TLS1_3_VERSION && + wolfSSL_session_reused(ssl)) +#endif + { + #ifdef KEEP_PEER_CERT + WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl); + ExpectNotNull(peer); + wolfSSL_X509_free(peer); + #endif + ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess)); +#ifdef OPENSSL_EXTRA + ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess)); +#endif + } +#endif + return EXPECT_RESULT(); +} +static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl) +{ + EXPECT_DECLS; + /* Set the session to reuse for the client */ + ExpectNotNull(ssl); + ExpectNotNull(twcase_client_first_session_ptr); + ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr), + WOLFSSL_SUCCESS); + return EXPECT_RESULT(); +} + +struct test_add_session_ext_params { + method_provider client_meth; + method_provider server_meth; + const char* tls_version; +}; + +/* Marked WC_MAYBE_UNUSED: each registered test_wolfSSL_CTX_add_session_ext_* + * variant below calls this helper, but each variant is gated on a specific + * TLS/DTLS version combination. In builds where no version combination is + * enabled, the helper is defined but unused. */ +static WC_MAYBE_UNUSED int test_wolfSSL_CTX_add_session_ext( + struct test_add_session_ext_params* param) +{ + EXPECT_DECLS; + /* Test the default 33 sessions */ + int j; + + /* Clear cache before starting */ + wolfSSL_CTX_flush_sessions(NULL, -1); + + XMEMSET(&server_sessionCache, 0, sizeof(hashTable)); + if (wc_InitMutex(&server_sessionCache.htLock) != 0) + return BAD_MUTEX_E; + server_sessionCache.capacity = SESSION_CACHE_SIZE; + + fprintf(stderr, "\tBegin %s\n", param->tls_version); + for (j = 0; j < 5; j++) { + int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL; + int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL; + test_ssl_cbf client_cb; + test_ssl_cbf server_cb; + + (void)dtls; + + /* Test five cache configurations */ + twcase_client_first_session_ptr = NULL; + twcase_server_first_session_ptr = NULL; + twcase_server_current_ctx_ptr = NULL; + twcase_new_session_called = 0; + twcase_remove_session_called = 0; + twcase_get_session_called = 0; + + /* connection 1 - first connection */ + fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j); + + XMEMSET(&client_cb, 0, sizeof(client_cb)); + XMEMSET(&server_cb, 0, sizeof(server_cb)); + client_cb.method = param->client_meth; + server_cb.method = param->server_meth; + + if (dtls) + client_cb.doUdp = server_cb.doUdp = 1; + + /* Setup internal and external cache */ + switch (j) { + case 0: + /* SSL_OP_NO_TICKET stateful ticket case */ + server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket; + break; + case 1: + server_cb.ctx_ready = twcase_cache_intOn_extOn; + break; + case 2: + server_cb.ctx_ready = twcase_cache_intOff_extOn; + break; + case 3: + server_cb.ctx_ready = twcase_cache_intOn_extOff; + break; + case 4: + server_cb.ctx_ready = twcase_cache_intOff_extOff; + break; + } + client_cb.ctx_ready = twcase_cache_intOff_extOff; + + /* Add session to internal cache and save SSL session for testing */ + server_cb.on_result = twcase_server_sess_ctx_pre_shutdown; + /* Save client SSL session for testing */ + client_cb.on_result = twcase_client_sess_ctx_pre_shutdown; + server_cb.ticNoInit = 1; /* Use default builtin */ + /* Don't free/release ctx */ + server_cb.ctx = twcase_server_current_ctx_ptr; + server_cb.isSharedCtx = 1; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, + &server_cb, NULL), TEST_SUCCESS); + + ExpectIntEQ(twcase_get_session_called, 0); + if (EXPECT_FAIL()) { + wolfSSL_SESSION_free(twcase_client_first_session_ptr); + wolfSSL_SESSION_free(twcase_server_first_session_ptr); + wolfSSL_CTX_free(twcase_server_current_ctx_ptr); + break; + } + + switch (j) { + case 0: + case 1: + case 2: + /* cache cannot be searched with out a connection */ + /* Add a new session */ + ExpectIntEQ(twcase_new_session_called, 1); + /* In twcase_server_sess_ctx_pre_shutdown + * wolfSSL_CTX_add_session which evicts the existing session + * in cache and adds it back in */ + ExpectIntLE(twcase_remove_session_called, 1); + break; + case 3: + case 4: + /* no external cache */ + ExpectIntEQ(twcase_new_session_called, 0); + ExpectIntEQ(twcase_remove_session_called, 0); + break; + } + + /* connection 2 - session resume */ + fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j); + twcase_new_session_called = 0; + twcase_remove_session_called = 0; + twcase_get_session_called = 0; + server_cb.on_result = 0; + client_cb.on_result = 0; + server_cb.ticNoInit = 1; /* Use default builtin */ + + server_cb.ctx = twcase_server_current_ctx_ptr; + + /* try session resumption */ + client_cb.ssl_ready = twcase_client_set_sess_ssl_ready; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb, + &server_cb, NULL), TEST_SUCCESS); + + /* Clear cache before checking */ + wolfSSL_CTX_flush_sessions(NULL, -1); + + switch (j) { + case 0: + if (tls13) { + /* (D)TLSv1.3 stateful case */ + /* cache hit */ + /* DTLS accesses cache once for stateless parsing and + * once for stateful parsing */ + ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); + + /* (D)TLSv1.3 creates a new ticket, + * updates both internal and external cache */ + ExpectIntEQ(twcase_new_session_called, 1); + /* A new session ID is created for a new ticket */ + ExpectIntEQ(twcase_remove_session_called, 2); + + } + else { + /* non (D)TLSv1.3 case, no update */ + /* DTLS accesses cache once for stateless parsing and + * once for stateful parsing */ +#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME + ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); +#else + ExpectIntEQ(twcase_get_session_called, 1); +#endif + ExpectIntEQ(twcase_new_session_called, 0); + /* Called on session added in + * twcase_server_sess_ctx_pre_shutdown */ + ExpectIntEQ(twcase_remove_session_called, 1); + } + break; + case 1: + if (tls13) { + /* (D)TLSv1.3 case */ + /* cache hit */ + ExpectIntEQ(twcase_get_session_called, 1); + /* (D)TLSv1.3 creates a new ticket, + * updates both internal and external cache */ + ExpectIntEQ(twcase_new_session_called, 1); + /* Called on session added in + * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */ + ExpectIntEQ(twcase_remove_session_called, 1); + } + else { + /* non (D)TLSv1.3 case */ + /* cache hit */ + /* DTLS accesses cache once for stateless parsing and + * once for stateful parsing */ +#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME + ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); +#else + ExpectIntEQ(twcase_get_session_called, 1); +#endif + ExpectIntEQ(twcase_new_session_called, 0); + /* Called on session added in + * twcase_server_sess_ctx_pre_shutdown */ + ExpectIntEQ(twcase_remove_session_called, 1); + } + break; + case 2: + if (tls13) { + /* (D)TLSv1.3 case */ + /* cache hit */ + ExpectIntEQ(twcase_get_session_called, 1); + /* (D)TLSv1.3 creates a new ticket, + * updates both internal and external cache */ + ExpectIntEQ(twcase_new_session_called, 1); + /* Called on session added in + * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */ + ExpectIntEQ(twcase_remove_session_called, 1); + } + else { + /* non (D)TLSv1.3 case */ + /* cache hit */ + /* DTLS accesses cache once for stateless parsing and + * once for stateful parsing */ +#ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME + ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2); +#else + ExpectIntEQ(twcase_get_session_called, 1); +#endif + ExpectIntEQ(twcase_new_session_called, 0); + /* Called on session added in + * twcase_server_sess_ctx_pre_shutdown */ + ExpectIntEQ(twcase_remove_session_called, 1); + } + break; + case 3: + case 4: + /* no external cache */ + ExpectIntEQ(twcase_get_session_called, 0); + ExpectIntEQ(twcase_new_session_called, 0); + ExpectIntEQ(twcase_remove_session_called, 0); + break; + } + wolfSSL_SESSION_free(twcase_client_first_session_ptr); + wolfSSL_SESSION_free(twcase_server_first_session_ptr); + wolfSSL_CTX_free(twcase_server_current_ctx_ptr); + + if (EXPECT_FAIL()) + break; + } + twcase_get_sessionCb_cleanup(); + XMEMSET(&server_sessionCache.entries, 0, + sizeof(server_sessionCache.entries)); + fprintf(stderr, "\tEnd %s\n", param->tls_version); + + wc_FreeMutex(&server_sessionCache.htLock); + + return EXPECT_RESULT(); +} +#endif + +int test_wolfSSL_CTX_add_session_ext_tls13(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ + defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) + struct test_add_session_ext_params param[1] = { + { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif + return EXPECT_RESULT(); +} +int test_wolfSSL_CTX_add_session_ext_dtls13(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ + defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) +#ifdef WOLFSSL_DTLS13 + struct test_add_session_ext_params param[1] = { + { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif +#endif + return EXPECT_RESULT(); +} +int test_wolfSSL_CTX_add_session_ext_tls12(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#ifndef WOLFSSL_NO_TLS12 + struct test_add_session_ext_params param[1] = { + { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif + return EXPECT_RESULT(); +} +int test_wolfSSL_CTX_add_session_ext_dtls12(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#ifndef WOLFSSL_NO_TLS12 +#ifdef WOLFSSL_DTLS + struct test_add_session_ext_params param[1] = { + { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif +#endif + return EXPECT_RESULT(); +} +int test_wolfSSL_CTX_add_session_ext_tls11(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ + !defined(NO_DES3)) + struct test_add_session_ext_params param[1] = { + { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif + return EXPECT_RESULT(); +} +int test_wolfSSL_CTX_add_session_ext_dtls1(void) +{ + EXPECT_DECLS; +#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \ + defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \ + defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \ + defined(HAVE_SESSION_TICKET) && \ + !defined(TITAN_SESSION_CACHE) && \ + !defined(HUGE_SESSION_CACHE) && \ + !defined(BIG_SESSION_CACHE) && \ + !defined(MEDIUM_SESSION_CACHE) +#if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \ + !defined(NO_DES3)) +#ifdef WOLFSSL_DTLS + struct test_add_session_ext_params param[1] = { + { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" } + }; + ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS); +#endif +#endif +#endif + return EXPECT_RESULT(); +} + +/*----------------------------------------------------------------------------*/ +/* WOLFSSL_SESSION, ticket keys and session removal callbacks */ +/*----------------------------------------------------------------------------*/ + +int test_wolfSSL_SESSION(void) +{ + EXPECT_DECLS; +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ + !defined(NO_RSA) && !defined(NO_SHA256) && \ + defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE) + WOLFSSL* ssl = NULL; + WOLFSSL_CTX* ctx = NULL; + WOLFSSL_SESSION* sess = NULL; + WOLFSSL_SESSION* sess_copy = NULL; +#ifdef OPENSSL_EXTRA +#ifdef HAVE_EXT_CACHE + unsigned char* sessDer = NULL; + unsigned char* ptr = NULL; + int sz = 0; +#endif + const unsigned char context[] = "user app context"; + unsigned int contextSz = (unsigned int)sizeof(context); +#endif + int ret = 0, err = 0; + SOCKET_T sockfd; + tcp_ready ready; + func_args server_args; + THREAD_TYPE serverThread; + char msg[80]; + const char* sendGET = "GET"; + + /* TLS v1.3 requires session tickets */ + /* CHACHA and POLY1305 required for myTicketEncCb */ +#if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \ + !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \ + defined(HAVE_POLY1305)) || defined(HAVE_AESGCM)))) + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())); +#else + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); +#endif + + ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, + CERT_FILETYPE)); + ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, + CERT_FILETYPE)); + ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), + WOLFSSL_SUCCESS); +#ifdef WOLFSSL_ENCRYPTED_KEYS + wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack); +#endif +#ifdef HAVE_SESSION_TICKET + /* Use session tickets, for ticket tests below */ + ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS); +#endif + + XMEMSET(&server_args, 0, sizeof(func_args)); +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + + StartTCP(); + InitTcpReady(&ready); + + server_args.signal = &ready; + start_thread(test_server_nofail, &server_args, &serverThread); + wait_tcp_ready(&server_args); + + /* client connection */ + ExpectNotNull(ssl = wolfSSL_new(ctx)); + tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl); + ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS); + + WOLFSSL_ASYNC_WHILE_PENDING(ret = wolfSSL_connect(ssl), + ret != WOLFSSL_SUCCESS); + ExpectIntEQ(ret, WOLFSSL_SUCCESS); + + WOLFSSL_ASYNC_WHILE_PENDING( + ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET)), + ret <= 0); + ExpectIntEQ(ret, (int)XSTRLEN(sendGET)); + + WOLFSSL_ASYNC_WHILE_PENDING(ret = wolfSSL_read(ssl, msg, sizeof(msg)), + ret != 23); + ExpectIntEQ(ret, 23); + + ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */ + ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */ + ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1); +#ifdef HAVE_EXT_CACHE + ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without + * HAVE_EXT_CACHE we get new objects each time */ +#endif + wolfSSL_SESSION_free(sess_copy); sess_copy = NULL; + wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */ + + sess = wolfSSL_get_session(ssl); + +#ifdef OPENSSL_EXTRA + ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0); + ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1); + + ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0); + ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0); + #ifdef HAVE_SESSION_TICKET + ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1); + ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess), + SESSION_TICKET_HINT_DEFAULT); + #else + ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0); + #endif +#else + (void)sess; +#endif /* OPENSSL_EXTRA */ + + /* Retain copy of the session for later testing */ + ExpectNotNull(sess = wolfSSL_get1_session(ssl)); + + wolfSSL_shutdown(ssl); + wolfSSL_free(ssl); ssl = NULL; + + CloseSocket(sockfd); + + join_thread(serverThread); + + FreeTcpReady(&ready); + +#ifdef WOLFSSL_TIRTOS + fdOpenSession(Task_self()); +#endif + +#if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA) + { + X509 *x509 = NULL; + char buf[30]; + int bufSz = 0; + + ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess)); + ExpectIntGT((bufSz = X509_NAME_get_text_by_NID( + X509_get_subject_name(x509), NID_organizationalUnitName, buf, + sizeof(buf))), 0); + ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/ + if (bufSz == 7) { + ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0); + } + if (bufSz == 16) { + ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0); + } + } +#endif + +#ifdef HAVE_EXT_CACHE + ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess)); + wolfSSL_SESSION_free(sess_copy); sess_copy = NULL; + sess_copy = NULL; +#endif + +#if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE) + /* get session from DER and update the timeout */ + ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0); + wolfSSL_SESSION_free(sess); sess = NULL; + sess = NULL; + ptr = sessDer; + ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz)); + ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, + (const unsigned char**)&ptr, sz)); + XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL); + sessDer = NULL; + + ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0); + ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS); +#endif + + /* successful set session test */ + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS); + +#ifdef HAVE_SESSION_TICKET + /* Test set/get session ticket */ + { + const char* ticket = "This is a session ticket"; + char buf[64] = {0}; + word32 bufSz = (word32)sizeof(buf); + word32 retSz = 0; + + ExpectIntEQ(WOLFSSL_SUCCESS, + wolfSSL_set_SessionTicket(ssl, (byte *)ticket, + (word32)XSTRLEN(ticket))); + ExpectIntEQ(WOLFSSL_SUCCESS, + wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz)); + ExpectStrEQ(ticket, buf); + + /* return ticket length if buffer parameter is null */ + wolfSSL_get_SessionTicket(ssl, NULL, &retSz); + ExpectIntEQ(bufSz, retSz); + } +#endif + +#ifdef OPENSSL_EXTRA + /* session timeout case */ + /* make the session to be expired */ + ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS); + XSLEEP_MS(1200); + + /* SSL_set_session should reject specified session but return success + * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility. + */ +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS); +#else + ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); +#endif + ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS); + +#ifdef WOLFSSL_SESSION_ID_CTX + /* fail case with miss match session context IDs (use compatibility API) */ + ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz), + SSL_SUCCESS); + ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + wolfSSL_free(ssl); ssl = NULL; + + ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz), + SSL_SUCCESS); + ExpectNotNull(ssl = wolfSSL_new(ctx)); + ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); +#endif +#endif /* OPENSSL_EXTRA */ + + wolfSSL_free(ssl); + wolfSSL_SESSION_free(sess); + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} + +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ + !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \ + !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \ + !defined(WOLFSSL_NO_TLS12) +static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL; + +static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx) +{ + #ifdef WOLFSSL_ERROR_CODE_OPENSSL + /* returns previous timeout value */ + AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500); + #else + AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS); + #endif +} + + +/* set the session to timeout in a second */ +static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl) +{ + AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1); +} + + +/* store the client side session from the first successful connection */ +static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl) +{ + AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)), + NULL); /* ref count 1 */ +} + + +/* wait till session is expired then set it in the WOLFSSL struct for use */ +static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl) +{ + AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1); + AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), + WOLFSSL_SUCCESS); + XSLEEP_MS(2000); /* wait 2 seconds for session to expire */ +} + + +/* set expired session in the WOLFSSL struct for use */ +static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl) +{ + XSLEEP_MS(1200); /* wait a second for session to expire */ + + /* set the expired session, call to set session fails but continuing on + after failure should be handled here */ +#if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) + AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), + WOLFSSL_SUCCESS); +#else + AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess), + WOLFSSL_SUCCESS); +#endif +} + + +/* check that the expired session was not reused */ +static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl) +{ + /* since the session has expired it should not have been reused */ + AssertIntEQ(wolfSSL_session_reused(ssl), 0); +} +#endif + +int test_wolfSSL_SESSION_expire_downgrade(void) +{ + EXPECT_DECLS; +#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ + !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \ + !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \ + !defined(WOLFSSL_NO_TLS12) + callback_functions server_cbf, client_cbf; + + XMEMSET(&server_cbf, 0, sizeof(callback_functions)); + XMEMSET(&client_cbf, 0, sizeof(callback_functions)); + + /* force server side to use TLS 1.2 */ + server_cbf.method = wolfTLSv1_2_server_method; + + client_cbf.method = wolfSSLv23_client_method; + server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; + client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready; + client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result; + + test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); + ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); + ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); + + client_cbf.method = wolfSSLv23_client_method; + server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; + client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait; + client_cbf.on_result = + test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse; + + test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); + ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); + ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); + + client_cbf.method = wolfSSLv23_client_method; + server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready; + client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set; + client_cbf.on_result = + test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse; + + test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf); + ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS); + ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS); + + wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess); +#endif + return EXPECT_RESULT(); +} + +#if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE) +#ifdef WOLFSSL_ATOMIC_OPS + typedef wolfSSL_Atomic_Int SessRemCounter_t; +#else + typedef int SessRemCounter_t; +#endif +static SessRemCounter_t clientSessRemCountMalloc; +static SessRemCounter_t serverSessRemCountMalloc; +static SessRemCounter_t clientSessRemCountFree; +static SessRemCounter_t serverSessRemCountFree; + +static WOLFSSL_CTX* serverSessCtx = NULL; +static WOLFSSL_SESSION* serverSess = NULL; +#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ + !defined(NO_SESSION_CACHE_REF) +static WOLFSSL_CTX* clientSessCtx = NULL; +static WOLFSSL_SESSION* clientSess = NULL; +#endif +static int serverSessRemIdx = 3; +static int sessRemCtx_Server = WOLFSSL_SERVER_END; +static int sessRemCtx_Client = WOLFSSL_CLIENT_END; + +static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess) +{ + int* side; + + (void)ctx; + + side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx); + if (side != NULL) { + if (*side == WOLFSSL_CLIENT_END) + (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1); + else + (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1); + + SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL); + } +} + +static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx) +{ + SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb); +#if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \ + !defined(NO_SESSION_CACHE_REF) + { + EXPECT_DECLS; + /* Allow downgrade, set min version, and disable TLS 1.3. + * Do this because without NO_SESSION_CACHE_REF we will want to return a + * reference to the session cache. But with WOLFSSL_TLS13 and without + * HAVE_SESSION_TICKET we won't have a session ID to be able to place + * the session in the cache. In this case we need to downgrade to + * previous versions to just use the legacy session ID field. */ + ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION), + SSL_SUCCESS); + ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION), + SSL_SUCCESS); + return EXPECT_RESULT(); + } +#else + return TEST_SUCCESS; +#endif +} + +static int SessRemSslSetupCb(WOLFSSL* ssl) +{ + EXPECT_DECLS; + int* side; + + if (SSL_is_server(ssl)) { + side = &sessRemCtx_Server; + (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1); + ExpectNotNull(serverSess = SSL_get1_session(ssl)); + ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)), + SSL_SUCCESS); + } + else { + side = &sessRemCtx_Client; + (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1); +#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ + !defined(NO_SESSION_CACHE_REF) + ExpectNotNull(clientSess = SSL_get1_session(ssl)); + ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)), + SSL_SUCCESS); +#endif + } + ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl), + serverSessRemIdx, side), SSL_SUCCESS); + + return EXPECT_RESULT(); +} +#endif + +int test_wolfSSL_CTX_sess_set_remove_cb(void) +{ + EXPECT_DECLS; +#if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE) + /* Check that the remove callback gets called for external data in a + * session object */ + test_ssl_cbf func_cb; + + wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0); + wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0); + wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0); + wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0); + + XMEMSET(&func_cb, 0, sizeof(func_cb)); + func_cb.ctx_ready = SessRemCtxSetupCb; + func_cb.on_result = SessRemSslSetupCb; + + ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb, + NULL), TEST_SUCCESS); + + /* Both should have been allocated */ + ExpectIntEQ(clientSessRemCountMalloc, 1); + ExpectIntEQ(serverSessRemCountMalloc, 1); + + /* This should not be called yet. Session wasn't evicted from cache yet. */ + ExpectIntEQ(clientSessRemCountFree, 0); +#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ + !defined(NO_SESSION_CACHE_REF) + /* Force a cache lookup */ + ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx)); + /* Force a cache update */ + ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0)); + /* This should set the timeout to 0 and call the remove callback from within + * the session cache. Returns 1 per OpenSSL semantics (session was + * present in the cache and removed). */ + ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 1); + ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx)); + ExpectIntEQ(clientSessRemCountFree, 1); +#endif + /* Server session is in the cache so ex_data isn't free'd with the SSL + * object */ + ExpectIntEQ(serverSessRemCountFree, 0); + /* Force a cache lookup */ + ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx)); + /* Force a cache update */ + ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0)); + /* This should set the timeout to 0 and call the remove callback from within + * the session cache. Returns 1 per OpenSSL semantics (session was + * present in the cache and removed). */ + ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 1); + ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx)); + ExpectIntEQ(serverSessRemCountFree, 1); + /* Need to free the references that we kept */ + SSL_CTX_free(serverSessCtx); + SSL_SESSION_free(serverSess); +#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \ + !defined(NO_SESSION_CACHE_REF) + SSL_CTX_free(clientSessCtx); + SSL_SESSION_free(clientSess); +#endif +#endif + return EXPECT_RESULT(); +} + +int test_wolfSSL_ticket_keys(void) +{ + EXPECT_DECLS; +#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \ + !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) + WOLFSSL_CTX* ctx = NULL; + byte keys[WOLFSSL_TICKET_KEYS_SZ]; + + ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); + + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)), + WC_NO_ERR_TRACE(WOLFSSL_FAILURE)); + + ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)), + WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)), + WOLFSSL_SUCCESS); + + wolfSSL_CTX_free(ctx); +#endif + return EXPECT_RESULT(); +} + +/*----------------------------------------------------------------------------*/ +/* SESSION ex_data new index */ +/*----------------------------------------------------------------------------*/ + +#if defined(HAVE_EX_DATA_CRYPTO) && defined(OPENSSL_EXTRA) + +#define SESSION_NEW_IDX_LONG 0xDEADBEEF +#define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD) +#define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE) +#define SESSION_NEW_IDX_PTR "Testing" + +static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr, + CRYPTO_EX_DATA* a, int idx, long argValue, void* arg) +{ + AssertNotNull(p); + AssertNull(ptr); + AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS); + AssertIntEQ(argValue, SESSION_NEW_IDX_LONG); + AssertStrEQ(arg, SESSION_NEW_IDX_PTR); +} + +static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out, + const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV, + void* arg) +{ + EXPECT_DECLS; + + ExpectNotNull(out); + ExpectNotNull(in); + ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL); + ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL); + ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL); + ExpectIntEQ(argV, SESSION_NEW_IDX_LONG); + ExpectStrEQ(arg, SESSION_NEW_IDX_PTR); + *(void**)inPtr = SESSION_DUP_IDX_VAL; + if (EXPECT_SUCCESS()) { + return SSL_SUCCESS; + } + else { + return SSL_FAILURE; + } +} + +static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0; +static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr, + CRYPTO_EX_DATA* a, int idx, long argValue, void* arg) +{ + EXPECT_DECLS; + + ExpectNotNull(p); + ExpectNull(ptr); + ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0); + ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG); + ExpectStrEQ(arg, SESSION_NEW_IDX_PTR); + if (EXPECT_SUCCESS()) { + test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++; + } +} + +int test_wolfSSL_SESSION_get_ex_new_index(void) +{ + EXPECT_DECLS; + int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG, + (void*)SESSION_NEW_IDX_PTR, + test_wolfSSL_SESSION_get_ex_new_index_new_cb, + test_wolfSSL_SESSION_get_ex_new_index_dup_cb, + test_wolfSSL_SESSION_get_ex_new_index_free_cb); + SSL_SESSION* s = SSL_SESSION_new(); + SSL_SESSION* d = NULL; + + ExpectNotNull(s); + ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL); + ExpectNotNull(d = SSL_SESSION_dup(s)); + ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL); + SSL_SESSION_free(s); + ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1); + SSL_SESSION_free(d); + ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2); + + crypto_ex_cb_free(crypto_ex_cb_ctx_session); + crypto_ex_cb_ctx_session = NULL; + return EXPECT_RESULT(); +} +#else +int test_wolfSSL_SESSION_get_ex_new_index(void) +{ + return TEST_SKIPPED; +} +#endif diff --git a/tests/api/test_session.h b/tests/api/test_session.h new file mode 100644 index 0000000000..9dc2e258f1 --- /dev/null +++ b/tests/api/test_session.h @@ -0,0 +1,54 @@ +/* test_session.h + * + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#ifndef WOLFCRYPT_TEST_SESSION_H +#define WOLFCRYPT_TEST_SESSION_H + +#include + +int test_wolfSSL_CTX_add_session(void); +int test_wolfSSL_CTX_add_session_ext_tls13(void); +int test_wolfSSL_CTX_add_session_ext_dtls13(void); +int test_wolfSSL_CTX_add_session_ext_tls12(void); +int test_wolfSSL_CTX_add_session_ext_dtls12(void); +int test_wolfSSL_CTX_add_session_ext_tls11(void); +int test_wolfSSL_CTX_add_session_ext_dtls1(void); +int test_wolfSSL_SESSION(void); +int test_wolfSSL_SESSION_expire_downgrade(void); +int test_wolfSSL_CTX_sess_set_remove_cb(void); +int test_wolfSSL_ticket_keys(void); +int test_wolfSSL_SESSION_get_ex_new_index(void); + +#define TEST_SESSION_DECLS \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls13), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls13), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls12), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls12), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls11), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls1), \ + TEST_DECL_GROUP("session", test_wolfSSL_SESSION), \ + TEST_DECL_GROUP("session", test_wolfSSL_SESSION_expire_downgrade), \ + TEST_DECL_GROUP("session", test_wolfSSL_CTX_sess_set_remove_cb), \ + TEST_DECL_GROUP("session", test_wolfSSL_ticket_keys), \ + TEST_DECL_GROUP("session", test_wolfSSL_SESSION_get_ex_new_index) + +#endif /* WOLFCRYPT_TEST_SESSION_H */ diff --git a/tests/api/test_tls13.c b/tests/api/test_tls13.c index 8684d1bd96..ca37fb48cc 100644 --- a/tests/api/test_tls13.c +++ b/tests/api/test_tls13.c @@ -6310,3 +6310,216 @@ int test_tls13_cipher_fuzz_aes128_ccm_8_sha256(void) #endif return EXPECT_RESULT(); } + +/* Regression test for the AEAD record-protection limit constants in + * internal.h. The macros expand to w64From32(hi, lo). A prior version split + * the intended 32-bit constants into 16-bit halves and passed each half as + * a separate 32-bit argument, producing a 64-bit value many orders of + * magnitude larger than RFC 8446 / RFC 9147 require. That made + * CheckTLS13AEADSendLimit's key-update trigger effectively unreachable. + * Compare against the hard-coded spec values so a recurrence is caught even + * if the macro is reused on both sides of the comparison. */ +int test_tls13_AEAD_limit_macros(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) + w64wrapper limit; + + /* RFC 8446 5.5: 2^24.5 ~= 23726566 (0x016A09E6). */ + limit = AEAD_AES_LIMIT; + ExpectIntEQ(w64GetHigh32(limit), 0); + ExpectIntEQ(w64GetLow32(limit), 0x016A09E6); + +#ifdef WOLFSSL_DTLS13 + /* RFC 9147 (AES-CCM integrity): 2^23.5 ~= 11863283 (0x00B504F3). */ + limit = DTLS_AEAD_AES_CCM_FAIL_LIMIT; + ExpectIntEQ(w64GetHigh32(limit), 0); + ExpectIntEQ(w64GetLow32(limit), 0x00B504F3); + + /* Key-update threshold is half the fail limit: 5931641 (0x005A8279). */ + limit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT; + ExpectIntEQ(w64GetHigh32(limit), 0); + ExpectIntEQ(w64GetLow32(limit), 0x005A8279); +#endif +#endif + return EXPECT_RESULT(); +} + +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + (defined(BUILD_TLS_AES_128_GCM_SHA256) || \ + defined(BUILD_TLS_AES_256_GCM_SHA384) || \ + defined(BUILD_TLS_AES_128_CCM_SHA256) || \ + defined(BUILD_TLS_AES_128_CCM_8_SHA256)) +/* Drive the client's encrypt sequence number towards the spec limit for + * `suite` and verify CheckTLS13AEADSendLimit's KeyUpdate trigger fires at + * exactly the right boundary. + * + * Two writes are exercised: + * 1. Counter set to limit - 2. After the write the counter must read + * limit - 1 (record incremented it by 1) and no KeyUpdate must have + * been emitted. CheckTLS13AEADSendLimit uses `seq >= limit`, so neither + * the pre-send check nor the trailing loop check (which runs once more + * after the last record before wolfSSL_write exits) is allowed to fire. + * 2. A second write follows with the counter already sitting at limit - 1 + * from the previous record. The user record goes out at seq = limit-1, + * which bumps the counter to limit; the trailing limit check then + * fires SendTls13KeyUpdate. SetKeysSide zeroes the encrypt counter, so + * the post-write counter is 0. + * + * With the previous broken AEAD-limit macros the limit was unreachable, no + * KeyUpdate would ever fire, and the counter would simply advance to + * limit_lo + 1 in the second case instead of being reset. + * + * The AEAD nonce mixes in the record sequence number on both sides, so the + * server's decrypt counter has to be advanced in lockstep with the client's + * encrypt counter or the record fails the integrity check. */ +static int test_tls13_AEAD_limit_triggers_KeyUpdate_cs(const char* suite, + word32 limit_hi, word32 limit_lo, int expected_bulk_cipher) +{ + EXPECT_DECLS; + struct test_memio_ctx test_ctx; + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + const char msg[] = "post-limit-record"; + char buf[sizeof(msg)]; + int written; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + test_ctx.c_ciphers = suite; + test_ctx.s_ciphers = suite; + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + if (EXPECT_SUCCESS() && ssl_c != NULL && ssl_s != NULL) { + /* Sanity check: the negotiated bulk cipher matches what the caller + * intends to exercise. If a build flag combination falls through to + * a different suite, the limit constant would be wrong. */ + ExpectIntEQ(ssl_c->specs.bulk_cipher_algorithm, expected_bulk_cipher); + + /* Stage the counters two below the limit so the first write stays + * comfortably below the trigger threshold. */ + ssl_c->keys.sequence_number_hi = limit_hi; + ssl_c->keys.sequence_number_lo = limit_lo - 2; + ssl_s->keys.peer_sequence_number_hi = limit_hi; + ssl_s->keys.peer_sequence_number_lo = limit_lo - 2; + } + + /* First write: below the limit, no KeyUpdate expected. */ + written = wolfSSL_write(ssl_c, msg, (int)sizeof(msg)); + ExpectIntEQ(written, (int)sizeof(msg)); + + if (EXPECT_SUCCESS() && ssl_c != NULL) { + /* The record bumped the counter from limit-2 to limit-1. A + * KeyUpdate would have zeroed it via SetKeysSide and bumped to 1. */ + ExpectIntEQ((int)ssl_c->keys.sequence_number_hi, (int)limit_hi); + ExpectIntEQ(ssl_c->keys.sequence_number_lo, limit_lo - 1); + } + + /* Server consumes the below-limit record with its existing keys. */ + XMEMSET(buf, 0, sizeof(buf)); + ExpectIntEQ(wolfSSL_read(ssl_s, buf, (int)sizeof(buf)), (int)sizeof(msg)); + ExpectIntEQ(XMEMCMP(buf, msg, sizeof(msg)), 0); + + /* Second write: the client's counter is now at limit-1. Sending this + * record will push it to limit, at which point the trailing check + * inside SendData's loop fires SendTls13KeyUpdate. No manual counter + * adjustment is needed -- the counter is allowed to "naturally" reach + * the limit through the previous send. */ + written = wolfSSL_write(ssl_c, msg, (int)sizeof(msg)); + ExpectIntEQ(written, (int)sizeof(msg)); + + if (EXPECT_SUCCESS() && ssl_c != NULL) { + /* SendTls13KeyUpdate -> DeriveTls13Keys -> SetKeysSide zeroes the + * encrypt sequence number. The user record went out before the + * trigger fired, so no record was sent on the new keys. */ + ExpectIntEQ((int)ssl_c->keys.sequence_number_hi, 0); + ExpectIntEQ((int)ssl_c->keys.sequence_number_lo, 0); + } + + /* The server reads the user record (sent under the pre-update keys at + * seq = limit - 1) before it sees the KeyUpdate record. The KeyUpdate + * is consumed transparently on a subsequent read; for the test we just + * need to confirm the user data round-trips. */ + XMEMSET(buf, 0, sizeof(buf)); + { + int r = -1, attempts; + for (attempts = 0; attempts < 5; attempts++) { + r = wolfSSL_read(ssl_s, buf, (int)sizeof(buf)); + if (r > 0) + break; + if (wolfSSL_get_error(ssl_s, r) != WOLFSSL_ERROR_WANT_READ) + break; + } + ExpectIntEQ(r, (int)sizeof(msg)); + } + ExpectIntEQ(XMEMCMP(buf, msg, sizeof(msg)), 0); + + wolfSSL_free(ssl_c); + wolfSSL_free(ssl_s); + wolfSSL_CTX_free(ctx_c); + wolfSSL_CTX_free(ctx_s); + + return EXPECT_RESULT(); +} +#endif + +int test_tls13_AEAD_limit_KU_aes128_gcm_sha256(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(BUILD_TLS_AES_128_GCM_SHA256) + ExpectIntEQ(test_tls13_AEAD_limit_triggers_KeyUpdate_cs( + "TLS13-AES128-GCM-SHA256", 0, 0x016A09E6, wolfssl_aes_gcm), + TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + +int test_tls13_AEAD_limit_KU_aes256_gcm_sha384(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(BUILD_TLS_AES_256_GCM_SHA384) + ExpectIntEQ(test_tls13_AEAD_limit_triggers_KeyUpdate_cs( + "TLS13-AES256-GCM-SHA384", 0, 0x016A09E6, wolfssl_aes_gcm), + TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + +int test_tls13_AEAD_limit_KU_aes128_ccm_sha256(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(BUILD_TLS_AES_128_CCM_SHA256) + ExpectIntEQ(test_tls13_AEAD_limit_triggers_KeyUpdate_cs( + "TLS13-AES128-CCM-SHA256", 0, 0x016A09E6, wolfssl_aes_ccm), + TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + +int test_tls13_AEAD_limit_KU_aes128_ccm_8_sha256(void) +{ + EXPECT_DECLS; +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \ + !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \ + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ + defined(BUILD_TLS_AES_128_CCM_8_SHA256) + ExpectIntEQ(test_tls13_AEAD_limit_triggers_KeyUpdate_cs( + "TLS13-AES128-CCM-8-SHA256", 0, 0x016A09E6, wolfssl_aes_ccm), + TEST_SUCCESS); +#endif + return EXPECT_RESULT(); +} + diff --git a/tests/api/test_tls13.h b/tests/api/test_tls13.h index 2a04b9069a..e01527f0e0 100644 --- a/tests/api/test_tls13.h +++ b/tests/api/test_tls13.h @@ -76,6 +76,11 @@ int test_tls13_cipher_fuzz_aes256_gcm_sha384(void); int test_tls13_cipher_fuzz_chacha20_poly1305_sha256(void); int test_tls13_cipher_fuzz_aes128_ccm_sha256(void); int test_tls13_cipher_fuzz_aes128_ccm_8_sha256(void); +int test_tls13_AEAD_limit_macros(void); +int test_tls13_AEAD_limit_KU_aes128_gcm_sha256(void); +int test_tls13_AEAD_limit_KU_aes256_gcm_sha384(void); +int test_tls13_AEAD_limit_KU_aes128_ccm_sha256(void); +int test_tls13_AEAD_limit_KU_aes128_ccm_8_sha256(void); #define TEST_TLS13_DECLS \ TEST_DECL_GROUP("tls13", test_tls13_apis), \ @@ -129,6 +134,11 @@ int test_tls13_cipher_fuzz_aes128_ccm_8_sha256(void); TEST_DECL_GROUP("tls13", test_tls13_cipher_fuzz_aes256_gcm_sha384), \ TEST_DECL_GROUP("tls13", test_tls13_cipher_fuzz_chacha20_poly1305_sha256), \ TEST_DECL_GROUP("tls13", test_tls13_cipher_fuzz_aes128_ccm_sha256), \ - TEST_DECL_GROUP("tls13", test_tls13_cipher_fuzz_aes128_ccm_8_sha256) + TEST_DECL_GROUP("tls13", test_tls13_cipher_fuzz_aes128_ccm_8_sha256), \ + TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_macros), \ + TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_KU_aes128_gcm_sha256), \ + TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_KU_aes256_gcm_sha384), \ + TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_KU_aes128_ccm_sha256), \ + TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_KU_aes128_ccm_8_sha256) #endif /* WOLFCRYPT_TEST_TLS13_H */ diff --git a/tests/utils.h b/tests/utils.h index 8a7942086d..bd9a150e01 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -87,6 +87,15 @@ int test_memio_modify_message_len(struct test_memio_ctx *ctx, int client, int ms int test_memio_remove_from_buffer(struct test_memio_ctx *ctx, int client, int off, int sz); #endif +/* Shared TLS server/client thread bodies, defined in tests/api.c. The + * definitions are gated on ENABLE_TLS_CALLBACK_TEST (a composite condition + * locally #defined inside api.c) or (WOLFSSL_DTLS && WOLFSSL_SESSION_EXPORT). + * Declared unconditionally here so api.c itself sees the prototype regardless + * of which side of the local #define triggers; absent the definition the + * prototypes are harmless and any caller would get a link error. */ +THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args); +void run_wolfssl_client(void* args); + #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \ defined(DEBUG_UNIT_TEST_CERTS) void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName); diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index c99fc71822..1f05e157de 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1298,9 +1298,6 @@ static const bench_alg bench_other_opt[] = { #endif { NULL, 0} }; -#endif /* MAIN_NO_ARGS */ - -#endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */ #if defined(BENCH_PQ_STATEFUL_HBS) typedef struct bench_pq_hash_sig_alg { @@ -1353,6 +1350,10 @@ static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = { }; #endif /* BENCH_PQ_STATEFUL_HBS */ +#endif /* MAIN_NO_ARGS */ + +#endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */ + #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(MAIN_NO_ARGS) #if defined(WOLFSSL_HAVE_MLKEM) || defined(HAVE_FALCON) || \ defined(WOLFSSL_HAVE_MLDSA) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index b9ef36f472..dccab8ff78 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -977,6 +977,30 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock, } #endif /* HAVE_AES_DECRYPT && WOLFSSL_AES_DIRECT */ +#elif defined(WOLFSSL_PPC64_ASM) + +#if defined(WOLFSSL_AES_DIRECT) || defined(HAVE_AESCCM) || \ + defined(WOLFSSL_AESGCM_STREAM) || defined(HAVE_AESGCM) +static WARN_UNUSED_RESULT int wc_AesEncrypt(Aes* aes, const byte* inBlock, + byte* outBlock) +{ + AES_ECB_encrypt(inBlock, outBlock, WC_AES_BLOCK_SIZE, (byte*)aes->key, + (int)aes->rounds); + + return 0; +} +#endif + +#if defined(HAVE_AES_DECRYPT) && defined(WOLFSSL_AES_DIRECT) +static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock, + byte* outBlock) +{ + AES_ECB_decrypt(inBlock, outBlock, WC_AES_BLOCK_SIZE, (byte*)aes->key, + (int)aes->rounds); + return 0; +} +#endif /* HAVE_AES_DECRYPT && WOLFSSL_AES_DIRECT */ + #elif defined(FREESCALE_MMCAU) /* Freescale mmCAU hardware AES support for Direct, CBC, CCM, GCM modes * through the CAU/mmCAU library. Documentation located in @@ -1285,12 +1309,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock, #if !defined(WOLFSSL_ESP32_CRYPT) || \ (defined(NO_ESP32_CRYPT) || defined(NO_WOLFSSL_ESP32_CRYPT_AES) || \ defined(NEED_AES_HW_FALLBACK)) +#ifndef WOLFSSL_PPC64_ASM static const FLASH_QUALIFIER word32 rcon[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; +#endif #endif /* ESP32 */ #endif /* __aarch64__ || !WOLFSSL_ARMASM */ @@ -4637,6 +4663,102 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock, return AesSetKey(aes, userKey, keylen, iv, dir); } + #if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) + /* AES-CTR and AES-DIRECT need to use this for key setup */ + /* This function allows key sizes that are not 128/192/256 bits */ + int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen, + const byte* iv, int dir) + { + if (aes == NULL) { + return BAD_FUNC_ARG; + } + if (keylen > sizeof(aes->key)) { + return BAD_FUNC_ARG; + } + + return AesSetKey(aes, userKey, keylen, iv, dir); + } + #endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER */ +#elif defined(WOLFSSL_PPC64_ASM) + static int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, + const byte* iv, int dir) + { + #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ + defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS) || \ + defined(WOLFSSL_AES_CTS) + aes->left = 0; + #endif + + aes->keylen = (int)keylen; + aes->rounds = (keylen/4) + 6; + + AES_set_encrypt_key(userKey, keylen * 8, (byte*)aes->key); + + #ifdef HAVE_AES_DECRYPT + if (dir == AES_DECRYPTION) { + AES_invert_key((byte*)aes->key, aes->rounds); + } + #else + (void)dir; + #endif + return wc_AesSetIV(aes, iv); + } + + int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, + const byte* iv, int dir) + { + if ((aes == NULL) || (userKey == NULL)) { + return BAD_FUNC_ARG; + } + + switch (keylen) { + #if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE >= 128 && \ + defined(WOLFSSL_AES_128) + case 16: + #endif + #if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE >= 192 && \ + defined(WOLFSSL_AES_192) + case 24: + #endif + #if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE >= 256 && \ + defined(WOLFSSL_AES_256) + case 32: + #endif + break; + default: + return BAD_FUNC_ARG; + } + + #ifdef WOLF_CRYPTO_CB + if (aes->devId != INVALID_DEVID) { + #ifdef WOLF_CRYPTO_CB_AES_SETKEY + int ret = wc_CryptoCb_AesSetKey(aes, userKey, keylen); + if (ret == 0) { + /* Callback succeeded - SE owns the key */ + aes->keylen = (int)keylen; + if (iv != NULL) + XMEMCPY(aes->reg, iv, WC_AES_BLOCK_SIZE); + else + XMEMSET(aes->reg, 0, WC_AES_BLOCK_SIZE); + return 0; + } + else if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) { + aes->devCtx = NULL; + return ret; + } + /* CRYPTOCB_UNAVAILABLE: continue to software setup */ + #endif + /* Standard CryptoCB path - copy key to devKey for encrypt/decrypt offload */ + if (keylen > sizeof(aes->devKey)) { + return BAD_FUNC_ARG; + } + XMEMCPY(aes->devKey, userKey, keylen); + } + #endif + + return AesSetKey(aes, userKey, keylen, iv, dir); + } + #if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) /* AES-CTR and AES-DIRECT need to use this for key setup */ /* This function allows key sizes that are not 128/192/256 bits */ @@ -6598,7 +6720,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) word32 blocks; int ret; #endif @@ -6611,7 +6733,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) return 0; } -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) blocks = sz / WC_AES_BLOCK_SIZE; #endif #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS @@ -6687,6 +6809,10 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) } #endif return 0; +#elif defined(WOLFSSL_PPC64_ASM) + AES_CBC_encrypt(in, out, sz, (const unsigned char*)aes->key, + aes->rounds, (unsigned char*)aes->reg); + return 0; #else #if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) /* Implemented in wolfcrypt/src/port/nxp/se050_port.c */ @@ -6788,7 +6914,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) /* Software AES - CBC Decrypt */ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) { -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) word32 blocks; int ret; #endif @@ -6816,7 +6942,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) } #endif -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) blocks = sz / WC_AES_BLOCK_SIZE; #endif if (sz % WC_AES_BLOCK_SIZE) { @@ -6909,6 +7035,10 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) #endif #endif /* __aarch64__ || WOLFSSL_ARMASM_NO_HW_CRYPTO */ return 0; +#elif defined(WOLFSSL_PPC64_ASM) + AES_CBC_decrypt(in, out, sz, (const unsigned char*)aes->key, + aes->rounds, (unsigned char*)aes->reg); + return 0; #else VECTOR_REGISTERS_PUSH; @@ -7266,7 +7396,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) !defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) byte scratch[WC_AES_BLOCK_SIZE]; #endif - #if !defined(WOLFSSL_ARMASM) + #if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) int ret = 0; #endif word32 processed; @@ -7389,6 +7519,47 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) } #endif /* __aarch64__ || WOLFSSL_ARMASM_NO_HW_CRYPTO */ return 0; + #elif defined(WOLFSSL_PPC64_ASM) + { + word32 numBlocks; + byte* tmp = (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left; + /* consume any unused bytes left in aes->tmp */ + while ((aes->left != 0) && (sz != 0)) { + *(out++) = *(in++) ^ *(tmp++); + aes->left--; + sz--; + } + + /* do as many block size ops as possible */ + numBlocks = sz / WC_AES_BLOCK_SIZE; + if (numBlocks > 0) { + AES_CTR_encrypt(in, out, numBlocks * WC_AES_BLOCK_SIZE, + (byte*)aes->key, aes->rounds, (byte*)aes->reg); + + sz -= numBlocks * WC_AES_BLOCK_SIZE; + out += numBlocks * WC_AES_BLOCK_SIZE; + in += numBlocks * WC_AES_BLOCK_SIZE; + } + + /* handle non block size remaining */ + if (sz) { + byte zeros[WC_AES_BLOCK_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + AES_CTR_encrypt(zeros, (byte*)aes->tmp, + WC_AES_BLOCK_SIZE, (byte*)aes->key, aes->rounds, + (byte*)aes->reg); + + aes->left = WC_AES_BLOCK_SIZE; + tmp = (byte*)aes->tmp; + + while (sz--) { + *(out++) = *(in++) ^ *(tmp++); + aes->left--; + } + } + } + return 0; #else VECTOR_REGISTERS_PUSH; @@ -7640,6 +7811,13 @@ void GenerateM0(Gcm* gcm) } } +#if defined(WOLFSSL_PPC64_ASM) + for (i = 1; i < 256; i++) { + word64* m64 = (word64*)gcm->M0[i]; + m64[0] = ByteReverseWord64(m64[0]); + m64[1] = ByteReverseWord64(m64[1]); + } +#endif XMEMSET(m[0], 0, WC_AES_BLOCK_SIZE); } @@ -7725,7 +7903,6 @@ void GenerateM0(Gcm* gcm) #endif } #endif - } #endif /* GCM_TABLE */ @@ -8125,6 +8302,37 @@ static void GCM_gmult_len_armasm_C( #elif defined(WOLFSSL_ARMASM) #define GCM_GMULT_LEN(gcm, x, a, len) \ GCM_gmult_len_NEON(x, (const byte*)((gcm)->H), a, len) +#elif defined(WOLFSSL_PPC64_ASM) +static void GCM_gmult_len_armasm_C( + byte* x, const byte* h, const unsigned char* a, unsigned long len) +{ + byte Z[AES_BLOCK_SIZE]; + byte V[AES_BLOCK_SIZE]; + int i; + int j; + + while (len >= AES_BLOCK_SIZE) { + xorbuf(x, a, AES_BLOCK_SIZE); + XMEMSET(Z, 0, AES_BLOCK_SIZE); + XMEMCPY(V, x, AES_BLOCK_SIZE); + for (i = 0; i < AES_BLOCK_SIZE; i++) { + byte y = h[i]; + for (j = 0; j < 8; j++) { + if (y & 0x80) { + xorbuf(Z, V, AES_BLOCK_SIZE); + } + RIGHTSHIFTX(V); + y = y << 1; + } + } + XMEMCPY(x, Z, AES_BLOCK_SIZE); + len -= AES_BLOCK_SIZE; + a += AES_BLOCK_SIZE; + } +} + +#define GCM_GMULT_LEN(gcm, x, a, len) \ + GCM_gmult_len_armasm_C(x, (gcm)->H, a, len) #endif #elif defined(GCM_TABLE) @@ -8138,6 +8346,9 @@ static void GCM_gmult_len_armasm_C( #define GCM_GMULT_LEN(gcm, x, a, len) \ GCM_gmult_len(x, (const byte**)((gcm)->M0), a, len) #endif +#elif defined(WOLFSSL_PPC64_ASM) +#define GCM_GMULT_LEN(gcm, x, a, len) \ + GCM_gmult_len(x, (const byte**)((gcm)->M0), a, len) #else ALIGN16 static const byte R[256][2] = { {0x00, 0x00}, {0x01, 0xc2}, {0x03, 0x84}, {0x02, 0x46}, @@ -8400,7 +8611,7 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, #endif /* WOLFSSL_AESGCM_STREAM */ /* end GCM_TABLE */ #elif defined(GCM_TABLE_4BIT) - +/* ARM assembly */ #if defined(WOLFSSL_ARMASM) && (defined(__aarch64__) || \ defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) #if !defined(WOLFSSL_ARMASM_NO_NEON) && defined(__aarch64__) @@ -8414,6 +8625,14 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, #define GMULT(x, m) \ GCM_gmult(x, (const byte**)m) #endif + +/* PPC64 assembly */ +#elif defined(WOLFSSL_PPC64_ASM) +#define GCM_GMULT_LEN(gcm, x, a, len) \ + GCM_gmult_len(x, (const byte**)((gcm)->M0), a, len) +#define GMULT(x, m) \ + GCM_gmult(x, (const byte**)m) + #else /* remainder = x^7 + x^2 + x^1 + 1 => 0xe1 * R shifts right a reverse bit pair of bytes such that: @@ -9928,7 +10147,7 @@ static WARN_UNUSED_RESULT int wc_AesGcmEncrypt_STM32( #endif /* STM32_CRYPTO_AES_GCM */ -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) #ifdef WOLFSSL_AESNI /* For performance reasons, this code needs to be not inlined. */ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( @@ -10048,8 +10267,9 @@ WARN_UNUSED_RESULT int AES_GCM_encrypt_C( return ret; } -#elif defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO) -static int AES_GCM_encrypt_ARM(Aes* aes, byte* out, const byte* in, +#elif (defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) || \ + defined(WOLFSSL_PPC64_ASM) +static int AES_GCM_encrypt_ASM(Aes* aes, byte* out, const byte* in, word32 sz, const byte* iv, word32 ivSz, byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz) { @@ -10305,10 +10525,13 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, #endif /* !WOLFSSL_ARMASM_NO_HW_CRYPTO */ #if defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO) { - ret = AES_GCM_encrypt_ARM(aes, out, in, sz, iv, ivSz, authTag, + ret = AES_GCM_encrypt_ASM(aes, out, in, sz, iv, ivSz, authTag, authTagSz, authIn, authInSz); } #endif /* __aarch64__ || WOLFSSL_ARMASM_NO_HW_CRYPTO */ +#elif defined(WOLFSSL_PPC64_ASM) + ret = AES_GCM_encrypt_ASM(aes, out, in, sz, iv, ivSz, authTag, authTagSz, + authIn, authInSz); #else #ifdef WOLFSSL_AESNI if (aes->use_aesni) { @@ -10653,7 +10876,7 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32( #endif /* STM32_CRYPTO_AES_GCM */ -#if !defined(WOLFSSL_ARMASM) +#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PPC64_ASM) #ifdef WOLFSSL_AESNI /* For performance reasons, this code needs to be not inlined. */ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( @@ -10802,8 +11025,9 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C( #endif return ret; } -#elif defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO) -static int AES_GCM_decrypt_ARM(Aes* aes, byte* out, const byte* in, +#elif (defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) || \ + defined(WOLFSSL_PPC64_ASM) +static int AES_GCM_decrypt_ASM(Aes* aes, byte* out, const byte* in, word32 sz, const byte* iv, word32 ivSz, const byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz) { @@ -11057,10 +11281,15 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, #endif /* !WOLFSSL_ARMASM_NO_HW_CRYPTO */ #if defined(__aarch64__) || defined(WOLFSSL_ARMASM_NO_HW_CRYPTO) { - ret = AES_GCM_decrypt_ARM(aes, out, in, sz, iv, ivSz, authTag, + ret = AES_GCM_decrypt_ASM(aes, out, in, sz, iv, ivSz, authTag, authTagSz, authIn, authInSz); } #endif /* __aarch64__ || WOLFSSL_ARMASM_NO_HW_CRYPTO */ +#elif defined(WOLFSSL_PPC64_ASM) + { + ret = AES_GCM_decrypt_ASM(aes, out, in, sz, iv, ivSz, authTag, + authTagSz, authIn, authInSz); + } #else #ifdef WOLFSSL_AESNI if (aes->use_aesni) { @@ -14233,6 +14462,9 @@ static WARN_UNUSED_RESULT int _AesEcbEncrypt( aes->rounds); } #endif +#elif defined(WOLFSSL_PPC64_ASM) + AES_ECB_encrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds); + ret = 0; #else #ifdef WOLFSSL_AESNI if (aes->use_aesni) { @@ -14325,6 +14557,9 @@ static WARN_UNUSED_RESULT int _AesEcbDecrypt( aes->rounds); } #endif +#elif defined(WOLFSSL_PPC64_ASM) + AES_ECB_decrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds); + ret = 0; #else #ifdef WOLFSSL_AESNI if (aes->use_aesni) { @@ -15584,8 +15819,8 @@ static WARN_UNUSED_RESULT int _AesXtsHelper( */ /* Software AES - XTS Encrypt */ -#if !defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \ - defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) +#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \ + defined(WOLFSSL_ARMASM_NO_HW_CRYPTO))) && !defined(WOLFSSL_PPC64_ASM) static int AesXtsEncryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz, byte *i); @@ -15825,6 +16060,10 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, ret = 0; } #endif +#elif defined(WOLFSSL_PPC64_ASM) + AES_XTS_encrypt(in, out, sz, i, (byte*)xaes->aes.key, + (byte*)xaes->tweak.key, (byte*)xaes->aes.tmp, xaes->aes.rounds); + ret = 0; #else ret = AesXtsEncrypt_sw(xaes, out, in, sz, i); #endif @@ -16043,8 +16282,8 @@ int wc_AesXtsEncryptFinal(XtsAes* xaes, byte* out, const byte* in, word32 sz, */ /* Software AES - XTS Decrypt */ -#if !defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \ - defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) +#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \ + defined(WOLFSSL_ARMASM_NO_HW_CRYPTO))) && !defined(WOLFSSL_PPC64_ASM) static int AesXtsDecryptUpdate_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz, byte *i); @@ -16302,6 +16541,10 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz, ret = 0; } #endif +#elif defined(WOLFSSL_PPC64_ASM) + AES_XTS_decrypt(in, out, sz, i, (byte*)xaes->aes.key, + (byte*)xaes->tweak.key, (byte*)xaes->aes.tmp, xaes->aes.rounds); + ret = 0; #else ret = AesXtsDecrypt_sw(xaes, out, in, sz, i); #endif diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index a4bd0d7ae2..9c76e4d5ee 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -8743,9 +8743,8 @@ int wc_RsaPrivateKeyValidate(const byte* input, word32* inOutIdx, int* keySz, #endif /* NO_RSA */ #ifdef WOLFSSL_ASN_TEMPLATE -/* ASN.1 template for a PKCS #8 key. - * Ignoring optional attributes and public key. - * PKCS #8: RFC 5958, 2 - PrivateKeyInfo +/* ASN.1 template for a PKCS #8 PrivateKeyInfo / RFC 5958 OneAsymmetricKey. + * Includes the optional [0] attributes and [1] publicKey trailing fields. */ static const ASNItem pkcs8KeyASN[] = { /* SEQ */ { 0, ASN_SEQUENCE, 1, 1, 0 }, @@ -8758,9 +8757,10 @@ static const ASNItem pkcs8KeyASN[] = { /* PKEY_ALGO_PARAM_SEQ */ { 2, ASN_SEQUENCE, 1, 0, 1 }, #endif /* PKEY_DATA */ { 1, ASN_OCTET_STRING, 0, 0, 0 }, -/* OPTIONAL Attributes IMPLICIT [0] */ +/* Attributes [0] OPTIONAL */ { 1, ASN_CONTEXT_SPECIFIC | 0, 1, 0, 1 }, -/* [[2: publicKey [1] PublicKey OPTIONAL ]] */ +/* publicKey [1] OPTIONAL */ + { 1, ASN_CONTEXT_SPECIFIC | 1, 0, 0, 1 }, }; enum { PKCS8KEYASN_IDX_SEQ = 0, @@ -8774,6 +8774,7 @@ enum { #endif PKCS8KEYASN_IDX_PKEY_DATA, PKCS8KEYASN_IDX_PKEY_ATTRIBUTES, + PKCS8KEYASN_IDX_PKEY_PUBKEY, WOLF_ENUM_DUMMY_LAST_ELEMENT(PKCS8KEYASN_IDX) }; @@ -8833,13 +8834,15 @@ int ToTraditionalInline_ex2(const byte* input, word32* inOutIdx, word32 sz, /* Key type OID. */ oid = dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_KEY].data.oid.sum; - /* Version 1 includes an optional public key. - * If public key is included then the parsing will fail as it did not - * use all the data. - */ + /* Only v1(0) and v2(1) are supported (RFC 5958). The [1] publicKey + * trailer is permitted only when version == v1. */ if (version > PKCS8v1) { ret = ASN_PARSE_E; } + else if ((version < PKCS8v1) && + (dataASN[PKCS8KEYASN_IDX_PKEY_PUBKEY].tag != 0)) { + ret = ASN_PARSE_E; + } } if (ret == 0) { switch (oid) { @@ -8935,9 +8938,71 @@ int ToTraditionalInline_ex2(const byte* input, word32* inOutIdx, word32 sz, } break; #endif - /* DSAk not supported. */ - /* Falcon, Dilithium and SLH-DSA not supported. */ - /* Ignore OID lookup failures. */ + #ifdef HAVE_FALCON + case FALCON_LEVEL1k: + case FALCON_LEVEL5k: + /* Neither NULL item nor OBJECT_ID item allowed. */ + if ((dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_NULL].tag != 0) || + (dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_CURVE].tag != 0)) { + ret = ASN_PARSE_E; + } + break; + #endif + #ifdef HAVE_DILITHIUM + #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT + case DILITHIUM_LEVEL2k: + case DILITHIUM_LEVEL3k: + case DILITHIUM_LEVEL5k: + #endif + case ML_DSA_LEVEL2k: + case ML_DSA_LEVEL3k: + case ML_DSA_LEVEL5k: + /* Neither NULL item nor OBJECT_ID item allowed. */ + if ((dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_NULL].tag != 0) || + (dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_CURVE].tag != 0)) { + ret = ASN_PARSE_E; + } + break; + #endif + #ifdef WOLFSSL_HAVE_SLHDSA + case SLH_DSA_SHA2_128Sk: + case SLH_DSA_SHA2_128Fk: + case SLH_DSA_SHA2_192Sk: + case SLH_DSA_SHA2_192Fk: + case SLH_DSA_SHA2_256Sk: + case SLH_DSA_SHA2_256Fk: + case SLH_DSA_SHAKE_128Sk: + case SLH_DSA_SHAKE_128Fk: + case SLH_DSA_SHAKE_192Sk: + case SLH_DSA_SHAKE_192Fk: + case SLH_DSA_SHAKE_256Sk: + case SLH_DSA_SHAKE_256Fk: + /* Neither NULL item nor OBJECT_ID item allowed. */ + if ((dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_NULL].tag != 0) || + (dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_CURVE].tag != 0)) { + ret = ASN_PARSE_E; + } + break; + #endif + #ifdef WOLFSSL_HAVE_LMS + case HSS_LMSk: + /* Neither NULL item nor OBJECT_ID item allowed. */ + if ((dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_NULL].tag != 0) || + (dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_CURVE].tag != 0)) { + ret = ASN_PARSE_E; + } + break; + #endif + #ifdef WOLFSSL_HAVE_XMSS + case XMSSk: + /* Neither NULL item nor OBJECT_ID item allowed. */ + if ((dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_NULL].tag != 0) || + (dataASN[PKCS8KEYASN_IDX_PKEY_ALGO_OID_CURVE].tag != 0)) { + ret = ASN_PARSE_E; + } + break; + #endif + /* Other OIDs (DSAk), no parameter validation. */ default: break; } @@ -9037,9 +9102,9 @@ int wc_GetPkcs8TraditionalOffset(byte* input, word32* inOutIdx, word32 sz) int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz, int algoID, const byte* curveOID, word32 oidSz) { - /* pkcs8KeyASN_Length-1, the -1 is because we are not adding the optional - * set of attributes */ - DECL_ASNSETDATA(dataASN, pkcs8KeyASN_Length-1); + /* pkcs8KeyASN_Length-2, the -2 is because we are not adding the optional + * set of attributes or publicKey */ + DECL_ASNSETDATA(dataASN, pkcs8KeyASN_Length-2); word32 sz = 0; int ret = 0; word32 keyIdx = 0; @@ -9066,7 +9131,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz, #endif if (ret == 0) - CALLOC_ASNSETDATA(dataASN, pkcs8KeyASN_Length-1, ret, NULL); + CALLOC_ASNSETDATA(dataASN, pkcs8KeyASN_Length-2, ret, NULL); if (ret == 0) { /* Only support default PKCS #8 format - v0. */ @@ -9092,7 +9157,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz, SetASN_Buffer(&dataASN[PKCS8KEYASN_IDX_PKEY_DATA], key, keySz); /* Get the size of the DER encoding. */ - ret = SizeASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-1, &sz); + ret = SizeASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-2, &sz); } if ((ret == 0) || (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E))) { /* Always return the calculated size. */ @@ -9105,7 +9170,7 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz, } if (ret == 0) { /* Encode PKCS #8 key into buffer. */ - SetASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-1, out); + SetASN_Items(pkcs8KeyASN, dataASN, pkcs8KeyASN_Length-2, out); ret = (int)sz; } @@ -17833,12 +17898,31 @@ int wolfssl_local_MatchBaseName(int type, const char* name, int nameSz, const char* base, int baseSz) { if (base == NULL || baseSz <= 0 || name == NULL || nameSz <= 0 || - name[0] == '.' || nameSz < baseSz || + name[0] == '.' || (type != ASN_RFC822_TYPE && type != ASN_DNS_TYPE && type != ASN_DIR_TYPE)) { return 0; } + if (type == ASN_DNS_TYPE) { + /* MatchDomainName treats one trailing dot as the absolute-FQDN marker. + * Apply the same normalization before enforcing DNS name constraints. + */ + if (name[nameSz - 1] == '.') { + nameSz--; + } + if (base[baseSz - 1] == '.') { + baseSz--; + } + if (nameSz <= 0 || baseSz <= 0) { + return 0; + } + } + + if (nameSz < baseSz) { + return 0; + } + if (type == ASN_DIR_TYPE) return XMEMCMP(name, base, (size_t)baseSz) == 0; @@ -17927,8 +18011,8 @@ int wolfssl_local_MatchBaseName(int type, const char* name, int nameSz, return 1; } -static int MatchUriNameConstraint(const char* uri, int uriSz, const char* base, - int baseSz) +int wolfssl_local_MatchUriNameConstraint(const char* uri, int uriSz, + const char* base, int baseSz) { const char* hostStart; const char* hostEnd; @@ -17936,7 +18020,10 @@ static int MatchUriNameConstraint(const char* uri, int uriSz, const char* base, const char* uriEnd; int hostSz; - if (uri == NULL || uriSz <= 0 || base == NULL || baseSz <= 0) { + /* Need at least 3 bytes for the "://" scheme separator; rejecting short + * inputs early also keeps the loop bound (uriEnd - 2) from forming a + * pointer before `uri`. */ + if (uri == NULL || uriSz < 3 || base == NULL || baseSz <= 0) { return 0; } @@ -17992,8 +18079,168 @@ static int MatchUriNameConstraint(const char* uri, int uriSz, const char* base, return 0; } - return wolfssl_local_MatchBaseName(ASN_DNS_TYPE, hostStart, hostSz, base, - baseSz); + /* RFC 5280 4.2.1.10: for URIs the constraint applies to the host part. + * A constraint that begins with a '.' matches any host with one or more + * additional leading labels (the bare host is excluded) - this is the + * DNS subtree behaviour. A constraint without a leading '.' specifies a + * single host and must match it exactly. */ + if (base[0] == '.') { + return wolfssl_local_MatchBaseName(ASN_DNS_TYPE, hostStart, hostSz, + base, baseSz); + } + else { + int i; + if (hostSz != baseSz) { + return 0; + } + for (i = 0; i < baseSz; i++) { + if (XTOLOWER((unsigned char)hostStart[i]) != + XTOLOWER((unsigned char)base[i])) { + return 0; + } + } + return 1; + } +} + +/* Locate the right-most label of `s` that ends (exclusive) at index `end`. + * Sets *outStart to its starting index (the index of its first byte). If + * outHasWild is non-NULL, sets *outHasWild to 1 iff the label contains '*'. + * The '.' immediately before *outStart (if any) is the label separator and is + * not part of either the current or the preceding label. */ +static void PrevDnsLabel(const char* s, int end, int* outStart, + int* outHasWild) +{ + int start = end; + int hasWild = 0; + while (start > 0 && s[start - 1] != '.') { + if (s[start - 1] == '*') { + hasWild = 1; + } + start--; + } + *outStart = start; + if (outHasWild != NULL) { + *outHasWild = hasWild; + } +} + +/* Match a wildcard DNS SAN against a DNS name-constraint subtree. + * + * A wildcard SAN denotes the set of names its '*'(s) can expand to. Because a + * '*' never crosses a label boundary (see MatchDomainName), every expansion + * has the same number of labels and only the content of '*'-bearing labels + * varies. Matching is therefore done label-by-label from the right against the + * constraint base. + * + * permitted != 0: containment. Accept only if EVERY expansion stays inside the + * subtree, i.e. each of the right-most base-length labels of the name is + * wildcard-free and equal to the corresponding base label. Extra labels to + * the left may be anything (adding labels on the left stays in-subtree). + * + * permitted == 0: intersection (for excluded subtrees). Reject if SOME + * expansion falls inside the subtree. A label containing a '*' is + * conservatively treated as able to match any single base label; a literal + * label must equal the base label. + * + * A leading '.' on the base denotes a proper subtree (the apex is excluded), + * which requires at least one extra label on the left of the name. + * + * Returns 1 on match (contained / intersecting), 0 otherwise. + */ +int wolfssl_local_MatchDnsConstraintWildcard(const char* name, int nameSz, + const char* base, int baseSz, int permitted) +{ + int baseLead; + int ni, bi; + + if (name == NULL || base == NULL || nameSz <= 0 || baseSz <= 0) { + return 0; + } + + /* MatchDomainName treats one trailing dot as the absolute-FQDN marker. + * Apply the same normalization before label-wise constraint matching. + */ + if (name[nameSz - 1] == '.') { + nameSz--; + } + if (base[baseSz - 1] == '.') { + baseSz--; + } + if (nameSz <= 0 || baseSz <= 0 || name[0] == '.') { + return 0; + } + + baseLead = (base[0] == '.'); + if (baseLead) { + base++; + baseSz--; + } + /* A base of only dots (".", "..") has no labels to match. */ + if (baseSz <= 0 || base[0] == '.') { + return 0; + } + + ni = nameSz; /* exclusive end of the unconsumed name */ + bi = baseSz; /* exclusive end of the unconsumed base */ + + /* Compare each base label (right to left) with the aligned name label. */ + while (bi > 0) { + int nStart, bStart, nLen, bLen, k; + int hasWild = 0; + + /* Base labels remain but the name has none left -> name is shorter in + * labels and cannot contain the base. */ + if (ni <= 0) { + return 0; + } + + PrevDnsLabel(name, ni, &nStart, &hasWild); + PrevDnsLabel(base, bi, &bStart, NULL); + nLen = ni - nStart; + bLen = bi - bStart; + + /* Empty label (e.g. "a..b" or an extra trailing dot) is invalid. */ + if (nLen == 0 || bLen == 0) { + return 0; + } + + if (hasWild) { + /* permitted: a wildcard label cannot prove containment. + * excluded: a wildcard label is conservatively treated as + * compatible, so nothing more to check. */ + if (permitted) { + return 0; + } + } + else { + /* Literal label: both modes require exact case-insensitive + * equality with the base label. */ + if (nLen != bLen) { + return 0; + } + for (k = 0; k < bLen; k++) { + if (XTOLOWER((unsigned char)name[nStart + k]) != + XTOLOWER((unsigned char)base[bStart + k])) { + return 0; + } + } + } + + /* Consume both labels and the '.' that precedes them (if any). */ + ni = nStart - 1; + bi = bStart - 1; + } + + /* All base labels matched. ni >= 0 means name[ni] == '.' and at least one + * extra label remains on the left; ni < 0 means the name had exactly the + * base's label count (an apex match). A leading-dot base is a proper + * subtree and requires at least one extra left label. */ + if (baseLead && ni < 0) { + return 0; + } + + return 1; } /* Check if IP address matches a name constraint. @@ -18046,6 +18293,18 @@ static int MatchOtherNameConstraint(DNS_entry* name, Base_entry* current) return XMEMCMP(name->name, current->name, (size_t)current->nameSz) == 0; } +/* Return 1 if the name contains a wildcard '*' character. */ +static int DnsNameHasWildcard(const char* name, int nameSz) +{ + int i; + for (i = 0; i < nameSz; i++) { + if (name[i] == '*') { + return 1; + } + } + return 0; +} + /* Search through the list to find if the name is permitted. * name The DNS name to search for * dnsList The list to search through @@ -18073,7 +18332,7 @@ static int PermittedListOk(DNS_entry* name, Base_entry* dnsList, byte nameType) } } else if (nameType == ASN_URI_TYPE) { - if (MatchUriNameConstraint(name->name, name->len, + if (wolfssl_local_MatchUriNameConstraint(name->name, name->len, current->name, current->nameSz)) { match = 1; break; @@ -18096,6 +18355,17 @@ static int PermittedListOk(DNS_entry* name, Base_entry* dnsList, byte nameType) break; } } + else if (nameType == ASN_DNS_TYPE && + DnsNameHasWildcard(name->name, name->len)) { + /* Wildcard DNS SAN: a '*' can expand to a longer label, so the + * byte-length guard used for literal names below is invalid. + * Permit only if every expansion stays inside the subtree. */ + if (wolfssl_local_MatchDnsConstraintWildcard(name->name, + name->len, current->name, current->nameSz, 1)) { + match = 1; + break; + } + } else if (name->len >= current->nameSz && wolfssl_local_MatchBaseName(nameType, name->name, name->len, current->name, current->nameSz)) { @@ -18137,7 +18407,7 @@ static int IsInExcludedList(DNS_entry* name, Base_entry* dnsList, byte nameType) } } else if (nameType == ASN_URI_TYPE) { - if (MatchUriNameConstraint(name->name, name->len, + if (wolfssl_local_MatchUriNameConstraint(name->name, name->len, current->name, current->nameSz)) { ret = 1; break; @@ -18159,6 +18429,17 @@ static int IsInExcludedList(DNS_entry* name, Base_entry* dnsList, byte nameType) break; } } + else if (nameType == ASN_DNS_TYPE && + DnsNameHasWildcard(name->name, name->len)) { + /* Wildcard DNS SAN: a '*' can expand to a longer label, so the + * byte-length guard used for literal names below is invalid. + * Exclude if any expansion can fall inside the subtree. */ + if (wolfssl_local_MatchDnsConstraintWildcard(name->name, + name->len, current->name, current->nameSz, 0)) { + ret = 1; + break; + } + } else if (name->len >= current->nameSz && wolfssl_local_MatchBaseName(nameType, name->name, name->len, current->name, current->nameSz)) { @@ -18579,7 +18860,7 @@ static int DecodeGeneralName(const byte* input, word32* inOutIdx, byte tag, } WOLFSSL_MSG("\tPutting URI into list but not using"); - #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_FPKI) + #ifndef WOLFSSL_NO_ASN_STRICT /* Verify RFC 5280 Sec 4.2.1.6 rule: "The name MUST NOT be a relative URI" As per RFC 3986 Sec 4.3, an absolute URI is only required to contain @@ -18595,9 +18876,8 @@ static int DecodeGeneralName(const byte* input, word32* inOutIdx, byte tag, break; } if (input[idx + (word32)i] == '/') { - i = len; /* error, found relative path since '/' was - * encountered before ':'. Returning error - * value in next if statement. */ + /* path is relative since '/' was encountered before ':'. */ + return ASN_ALT_NAME_E; } } @@ -18669,6 +18949,10 @@ static int DecodeGeneralName(const byte* input, word32* inOutIdx, byte tag, * - CheckForAltNames (TLS hostname matching): skips ASN_RID_TYPE * unconditionally and excludes them from *checkCN, so a cert * with only registeredID SANs still falls back to CN. + * - CheckForAltNames (TLS hostname matching): skips ASN_URI_TYPE + * for DNS hostname checks (RFC 9525 Sec. 6.3) but URI SAN presence + * still suppresses CN fallback because URI-ID is a distinct presented + * identifier. * - DNS_to_GENERAL_NAME (used by wolfSSL_X509_get_ext) and the * ALT_NAMES_OID arm of wolfSSL_X509_get_ext_d2i: build a proper * ASN1_OBJECT in d.registeredID from raw OID bytes regardless @@ -37657,7 +37941,7 @@ static int DecodeAcertGeneralName(const byte* input, word32* inOutIdx, else if (tag == (ASN_CONTEXT_SPECIFIC | ASN_URI_TYPE)) { WOLFSSL_MSG("\tPutting URI into list but not using"); - #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_FPKI) + #ifndef WOLFSSL_NO_ASN_STRICT /* Verify RFC 5280 Sec 4.2.1.6 rule: "The name MUST NOT be a relative URI" As per RFC 3986 Sec 4.3, an absolute URI is only required to contain @@ -37673,9 +37957,8 @@ static int DecodeAcertGeneralName(const byte* input, word32* inOutIdx, break; } if (input[idx + (word32)i] == '/') { - i = len; /* error, found relative path since '/' was - * encountered before ':'. Returning error - * value in next if statement. */ + /* path is relative since '/' was encountered before ':'. */ + return ASN_ALT_NAME_E; } } diff --git a/wolfcrypt/src/asn_orig.c b/wolfcrypt/src/asn_orig.c index 7db2a4eed1..f1e67ff4f5 100644 --- a/wolfcrypt/src/asn_orig.c +++ b/wolfcrypt/src/asn_orig.c @@ -750,81 +750,6 @@ int EncryptContent(byte* input, word32 inputSz, byte* out, word32* outSz, #endif #endif #ifndef NO_RSA -#if defined(WOLFSSL_RENESAS_TSIP_TLS) || defined(WOLFSSL_RENESAS_FSPSM_TLS) -static int RsaPublicKeyDecodeRawIndex(const byte* input, word32* inOutIdx, - word32 inSz, word32* key_n, - word32* key_n_len, word32* key_e, - word32* key_e_len) -{ - int ret = 0; - int length = 0; - -#if defined(OPENSSL_EXTRA) || defined(RSA_DECODE_EXTRA) - byte b; -#endif - - if (input == NULL || inOutIdx == NULL) - return BAD_FUNC_ARG; - - if (GetSequence(input, inOutIdx, &length, inSz) < 0) - return ASN_PARSE_E; - -#if defined(OPENSSL_EXTRA) || defined(RSA_DECODE_EXTRA) - if ((*inOutIdx + 1) > inSz) - return BUFFER_E; - - b = input[*inOutIdx]; - if (b != ASN_INTEGER) { - /* not from decoded cert, will have algo id, skip past */ - if (GetSequence(input, inOutIdx, &length, inSz) < 0) - return ASN_PARSE_E; - - if (SkipObjectId(input, inOutIdx, inSz) < 0) - return ASN_PARSE_E; - - /* Option NULL ASN.1 tag */ - if (*inOutIdx >= inSz) { - return BUFFER_E; - } - if (input[*inOutIdx] == ASN_TAG_NULL) { - ret = GetASNNull(input, inOutIdx, inSz); - if (ret != 0) - return ret; - } - /* TODO: support RSA PSS */ - - /* should have bit tag length and seq next */ - ret = CheckBitString(input, inOutIdx, NULL, inSz, 1, NULL); - if (ret != 0) - return ret; - - if (GetSequence(input, inOutIdx, &length, inSz) < 0) - return ASN_PARSE_E; - } -#endif /* OPENSSL_EXTRA */ - - /* Get modulus */ - ret = GetASNInt(input, inOutIdx, &length, inSz); - *key_n += *inOutIdx; - if (ret < 0) { - return ASN_RSA_KEY_E; - } - if (key_n_len) - *key_n_len = length; - *inOutIdx += length; - - /* Get exponent */ - ret = GetASNInt(input, inOutIdx, &length, inSz); - *key_e += *inOutIdx; - if (ret < 0) { - return ASN_RSA_KEY_E; - } - if (key_e_len) - *key_e_len = length; - return ret; -} - -#endif int wc_RsaPublicKeyDecode_ex(const byte* input, word32* inOutIdx, word32 inSz, const byte** n, word32* nSz, const byte** e, word32* eSz) { @@ -3420,7 +3345,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert) return ASN_PARSE_E; } - #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_FPKI) + #ifndef WOLFSSL_NO_ASN_STRICT /* Verify RFC 5280 Sec 4.2.1.6 rule: "The name MUST NOT be a relative URI" As per RFC 3986 Sec 4.3, an absolute URI is only required to contain diff --git a/wolfcrypt/src/cryptocb.c b/wolfcrypt/src/cryptocb.c index d647fda7bf..c3af7ed608 100644 --- a/wolfcrypt/src/cryptocb.c +++ b/wolfcrypt/src/cryptocb.c @@ -2033,10 +2033,20 @@ int wc_CryptoCb_Sha384Hash(wc_Sha384* sha384, const byte* in, #ifdef WOLFSSL_SHA512 int wc_CryptoCb_Sha512Hash(wc_Sha512* sha512, const byte* in, - word32 inSz, byte* digest, size_t digestSz) + word32 inSz, byte* digest +#if !(defined(HAVE_FIPS) && FIPS_VERSION_LT(7,0)) + , size_t digestSz +#endif + ) { int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); CryptoCb* dev; +#if defined(HAVE_FIPS) && FIPS_VERSION_LT(7,0) + /* Older FIPS sha512.c snapshots call the 4-arg API (no digestSz). Treat as + * full-size SHA-512 with no variant dispatch, matching pre-digestSz + * behavior. */ + size_t digestSz = WC_SHA512_DIGEST_SIZE; +#endif /* locate registered callback */ #ifndef NO_SHA2_CRYPTO_CB diff --git a/wolfcrypt/src/dh.c b/wolfcrypt/src/dh.c index 26166c7310..c7560d185c 100644 --- a/wolfcrypt/src/dh.c +++ b/wolfcrypt/src/dh.c @@ -57,14 +57,6 @@ } #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - /* Possible DH enable options: * NO_RSA: Overall control of DH default: on (not defined) @@ -1425,8 +1417,6 @@ int wc_DhGeneratePublic(DhKey* key, byte* priv, word32 privSz, return BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - ret = GeneratePublicDh(key, priv, privSz, pub, pubSz); #if FIPS_VERSION_GE(5,0) || defined(WOLFSSL_VALIDATE_DH_KEYGEN) @@ -1436,8 +1426,6 @@ int wc_DhGeneratePublic(DhKey* key, byte* priv, word32 privSz, ret = _ffc_pairwise_consistency_test(key, pub, *pubSz, priv, privSz); #endif /* FIPS V5 or later || WOLFSSL_VALIDATE_DH_KEYGEN */ - RESTORE_VECTOR_REGISTERS(); - return ret; } @@ -1451,8 +1439,6 @@ static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng, return BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - ret = GeneratePrivateDh(key, rng, priv, privSz); if (ret == 0) @@ -1464,9 +1450,6 @@ static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng, ret = _ffc_pairwise_consistency_test(key, pub, *pubSz, priv, *privSz); #endif /* FIPS V5 or later || WOLFSSL_VALIDATE_DH_KEYGEN */ - - RESTORE_VECTOR_REGISTERS(); - return ret; } #endif /* !WOLFSSL_KCAPI_DH */ @@ -1589,8 +1572,6 @@ static int _ffc_validate_public_key(DhKey* key, const byte* pub, word32 pubSz, return MP_INIT_E; } - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (mp_read_unsigned_bin(y, pub, pubSz) != MP_OKAY) { ret = MP_READ_E; } @@ -1679,8 +1660,6 @@ static int _ffc_validate_public_key(DhKey* key, const byte* pub, word32 pubSz, mp_clear(p); mp_clear(q); - RESTORE_VECTOR_REGISTERS(); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(q, key->heap, DYNAMIC_TYPE_DH); XFREE(p, key->heap, DYNAMIC_TYPE_DH); @@ -1919,8 +1898,6 @@ static int _ffc_pairwise_consistency_test(DhKey* key, return MP_INIT_E; } - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - /* Load the private and public keys into big integers. */ if (mp_read_unsigned_bin(publicKey, pub, pubSz) != MP_OKAY || mp_read_unsigned_bin(privateKey, priv, privSz) != MP_OKAY) { @@ -1979,8 +1956,6 @@ static int _ffc_pairwise_consistency_test(DhKey* key, mp_clear(publicKey); mp_clear(checkKey); - RESTORE_VECTOR_REGISTERS(); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(checkKey, key->heap, DYNAMIC_TYPE_DH); XFREE(privateKey, key->heap, DYNAMIC_TYPE_DH); @@ -2174,8 +2149,6 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz, ret = MP_INIT_E; if (ret == 0) { - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (ret == 0 && mp_read_unsigned_bin(y, otherPub, pubSz) != MP_OKAY) ret = MP_READ_E; @@ -2201,8 +2174,6 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz, } mp_clear(y); - - RESTORE_VECTOR_REGISTERS(); } /* make sure agree is > 1 (SP800-56A, 5.7.1.1) */ @@ -2253,8 +2224,6 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz, } #endif - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (mp_read_unsigned_bin(x, priv, privSz) != MP_OKAY) ret = MP_READ_E; #ifdef WOLFSSL_CHECK_MEM_ZERO @@ -2313,8 +2282,6 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz, mp_clear(y); mp_forcezero(x); - RESTORE_VECTOR_REGISTERS(); - #else (void)ct; ret = WC_KEY_SIZE_E; @@ -2601,8 +2568,6 @@ static int _DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, ret = BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - if (ret == 0) { /* may have leading 0 */ if (p[0] == 0) { @@ -2714,8 +2679,6 @@ static int _DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, mp_clear(keyP); } - RESTORE_VECTOR_REGISTERS(); - return ret; } @@ -3204,8 +3167,6 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh) } #endif - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (ret == 0) { /* force magnitude */ buf[0] |= 0xC0; @@ -3264,9 +3225,10 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh) if (ret != 0 || primeCheck == MP_YES) break; - /* linuxkm: release the kernel for a moment before iterating. */ - RESTORE_VECTOR_REGISTERS(); - SAVE_VECTOR_REGISTERS(ret = _svr_ret; break;); + ret = WC_CHECK_FOR_INTR_SIGNALS(); + if (ret != 0) + break; + WC_RELAX_LONG_LOOP(); }; } @@ -3308,8 +3270,6 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh) mp_clear(&dh->g); } - RESTORE_VECTOR_REGISTERS(); - #ifndef WOLFSSL_NO_MALLOC if (buf != NULL) #endif diff --git a/wolfcrypt/src/dsa.c b/wolfcrypt/src/dsa.c index 0e849c2349..5df809c2da 100644 --- a/wolfcrypt/src/dsa.c +++ b/wolfcrypt/src/dsa.c @@ -36,14 +36,6 @@ #include #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - #ifdef _MSC_VER /* disable for while(0) cases (MSVC bug) */ #pragma warning(disable:4127) @@ -269,8 +261,6 @@ int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa) } #endif - SAVE_VECTOR_REGISTERS(;); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((tmpQ = (mp_int *)XMALLOC(sizeof(*tmpQ), dsa->heap, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) @@ -338,8 +328,6 @@ int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa) mp_clear(tmpQ); #endif - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -454,6 +442,11 @@ int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa) break; loop_check_prime++; } + + err = WC_CHECK_FOR_INTR_SIGNALS(); + if (err != 0) + break; + WC_RELAX_LONG_LOOP(); } } @@ -794,8 +787,6 @@ int wc_DsaSign_ex(const byte* digest, word32 digestSz, byte* out, DsaKey* key, return BAD_LENGTH_E; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - do { #ifdef WOLFSSL_SMALL_STACK k = (mp_int *)XMALLOC(sizeof *k, key->heap, DYNAMIC_TYPE_TMP_BUFFER); @@ -1040,8 +1031,6 @@ int wc_DsaSign_ex(const byte* digest, word32 digestSz, byte* out, DsaKey* key, } } while (0); - RESTORE_VECTOR_REGISTERS(); - #ifdef WOLFSSL_SMALL_STACK if (k) { if ((ret != WC_NO_ERR_TRACE(MP_INIT_E)) && diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 57b29197d6..11276ce6e9 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -275,14 +275,6 @@ ECC Curve Sizes: #include #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ !defined(WOLFSSL_MICROCHIP_TA100) && \ !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \ @@ -5150,8 +5142,6 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point, return ECC_BAD_ARG_E; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - switch (private_key->state) { case ECC_STATE_NONE: case ECC_STATE_SHARED_SEC_GEN: @@ -5194,8 +5184,6 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point, err = BAD_STATE_E; } /* switch */ - RESTORE_VECTOR_REGISTERS(); - /* if async pending then return and skip done cleanup below */ if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) { return err; @@ -5280,8 +5268,6 @@ int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx) return ECC_BAD_ARG_E; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - ALLOC_CURVE_SPECS(3, err); if (err == MP_OKAY) { err = wc_ecc_curve_load(wc_ecc_get_curve_params(curve_idx), &curve, @@ -5296,8 +5282,6 @@ int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx) wc_ecc_curve_free(curve); FREE_CURVE_SPECS(); - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -5456,8 +5440,6 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curve, return BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - #ifdef HAVE_ECC_MAKE_PUB /* if ecc_point passed in then use it as output for public key point */ if (pubOut != NULL) { @@ -5603,8 +5585,6 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curve, key->type = ECC_PRIVATEKEY; } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -6107,8 +6087,6 @@ int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id, { int err; - SAVE_VECTOR_REGISTERS(return _svr_ret;); - err = _ecc_make_key_ex(rng, keysize, key, curve_id, flags); #if (FIPS_VERSION_GE(5,0) || defined(WOLFSSL_VALIDATE_ECC_KEYGEN)) && \ @@ -6132,8 +6110,6 @@ int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id, } #endif - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -7195,6 +7171,11 @@ static int ecc_sign_hash_sw(ecc_key* key, ecc_key* pubkey, WC_RNG* rng, mp_clear(pubkey->pubkey.z); #endif mp_forcezero(pubkey->k); + + err = WC_CHECK_FOR_INTR_SIGNALS(); + if (err != 0) + break; + WC_RELAX_LONG_LOOP(); } mp_forcezero(b); FREE_MP_INT_SIZE(b, key->heap, DYNAMIC_TYPE_ECC); @@ -7244,10 +7225,8 @@ static int ecc_sign_hash_sp(const byte* in, word32 inlen, WC_RNG* rng, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_sign_256(in, inlen, rng, ecc_get_k(key), r, s, sign_k, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -7256,10 +7235,8 @@ static int ecc_sign_hash_sp(const byte* in, word32 inlen, WC_RNG* rng, #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SP_SM2) if (ecc_sets[key->idx].id == ECC_SM2P256V1) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_sign_sm2_256(in, inlen, rng, ecc_get_k(key), r, s, sign_k, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -7284,10 +7261,8 @@ static int ecc_sign_hash_sp(const byte* in, word32 inlen, WC_RNG* rng, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_sign_384(in, inlen, rng, ecc_get_k(key), r, s, sign_k, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -7314,10 +7289,8 @@ static int ecc_sign_hash_sp(const byte* in, word32 inlen, WC_RNG* rng, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_sign_521(in, inlen, rng, ecc_get_k(key), r, s, sign_k, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -8938,10 +8911,8 @@ static int ecc_verify_hash_sp(mp_int *r, mp_int *s, const byte* hash, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_verify_256(hash, hashlen, key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -8982,10 +8953,8 @@ static int ecc_verify_hash_sp(mp_int *r, mp_int *s, const byte* hash, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_verify_384(hash, hashlen, key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -9011,10 +8980,8 @@ static int ecc_verify_hash_sp(mp_int *r, mp_int *s, const byte* hash, #if !defined(WC_ECC_NONBLOCK) || (defined(WC_ECC_NONBLOCK) && !defined(WC_ECC_NONBLOCK_ONLY)) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_verify_521(hash, hashlen, key->pubkey.x, key->pubkey.y, key->pubkey.z, r, s, res, key->heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -9652,8 +9619,6 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen, if (err != MP_OKAY) return MEMORY_E; - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* check for point type (4, 2, or 3) */ pointType = in[0]; if (pointType != ECC_POINT_UNCOMP && pointType != ECC_POINT_COMP_EVEN && @@ -9845,8 +9810,6 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen, mp_clear(point->z); } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -10197,8 +10160,6 @@ static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime) return err; } - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - /* compute y^2 */ if (err == MP_OKAY) err = mp_sqr(ecp->y, t1); @@ -10267,8 +10228,6 @@ static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime) mp_clear(t1); mp_clear(t2); - RESTORE_VECTOR_REGISTERS(); - WC_FREE_VAR_EX(t2, NULL, DYNAMIC_TYPE_ECC); WC_FREE_VAR_EX(t1, NULL, DYNAMIC_TYPE_ECC); @@ -10718,8 +10677,6 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv) DECLARE_CURVE_SPECS(4); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (key == NULL) return BAD_FUNC_ARG; @@ -10871,9 +10828,7 @@ WOLFSSL_ABI int wc_ecc_check_key(ecc_key* key) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = _ecc_validate_public_key(key, 0, 1); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -10938,8 +10893,6 @@ static int _ecc_import_x963_ex2(const byte* in, word32 inLen, ecc_key* key, mp_forcezero(key->kb); #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* check for point type (4, 2, or 3) */ pointType = in[0]; if (pointType != ECC_POINT_UNCOMP && pointType != ECC_POINT_COMP_EVEN && @@ -11271,8 +11224,6 @@ static int _ecc_import_x963_ex2(const byte* in, word32 inLen, ecc_key* key, mp_forcezero(key->k); } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -11691,10 +11642,6 @@ static int _ecc_import_private_key_ex(const byte* priv, word32 privSz, } #else -#ifdef WOLFSSL_VALIDATE_ECC_IMPORT - SAVE_VECTOR_REGISTERS(return _svr_ret;); -#endif - ret = mp_read_unsigned_bin(key->k, priv, privSz); #ifdef HAVE_WOLF_BIGINT if (ret == 0 && wc_bigint_from_unsigned_bin(&key->k->raw, priv, @@ -11745,10 +11692,6 @@ static int _ecc_import_private_key_ex(const byte* priv, word32 privSz, #endif -#ifdef WOLFSSL_VALIDATE_ECC_IMPORT - RESTORE_VECTOR_REGISTERS(); -#endif - #ifdef WOLFSSL_MAXQ10XX_CRYPTO if ((ret == 0) && (key->devId != INVALID_DEVID)) { ret = wc_MAXQ10XX_EccSetKey(key, key->dp->size); @@ -12137,10 +12080,6 @@ static int _ecc_import_raw_private(ecc_key* key, const char* qx, } #endif -#ifdef WOLFSSL_VALIDATE_ECC_IMPORT - SAVE_VECTOR_REGISTERS(return _svr_ret;); -#endif - /* import private key */ if (err == MP_OKAY) { if (d != NULL) { @@ -12234,10 +12173,6 @@ static int _ecc_import_raw_private(ecc_key* key, const char* qx, } #endif -#ifdef WOLFSSL_VALIDATE_ECC_IMPORT - RESTORE_VECTOR_REGISTERS(); -#endif - #ifdef WOLFSSL_MAXQ10XX_CRYPTO if (err == MP_OKAY) { err = wc_MAXQ10XX_EccSetKey(key, key->dp->size); @@ -13858,8 +13793,6 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, } #endif /* HAVE_THREAD_LS */ - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - /* find point */ idx1 = find_base(A); @@ -13942,8 +13875,6 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, } } - RESTORE_VECTOR_REGISTERS(); - #ifndef HAVE_THREAD_LS wc_UnLockMutex(&ecc_fp_lock); #endif /* HAVE_THREAD_LS */ @@ -14011,8 +13942,6 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, got_ecc_fp_lock = 1; #endif /* HAVE_THREAD_LS */ - SAVE_VECTOR_REGISTERS(err = _svr_ret; goto out;); - /* find point */ idx = find_base(G); @@ -14061,8 +13990,6 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, } } - RESTORE_VECTOR_REGISTERS(); - out: #ifndef HAVE_THREAD_LS @@ -14088,36 +14015,28 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SP_SM2) if ((mp_count_bits(modulus) == 256) && (!mp_is_bit_set(modulus, 224))) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret); ret = sp_ecc_mulmod_sm2_256(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifndef WOLFSSL_SP_NO_256 if (mp_count_bits(modulus) == 256) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_256(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifdef WOLFSSL_SP_384 if (mp_count_bits(modulus) == 384) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_384(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifdef WOLFSSL_SP_521 if (mp_count_bits(modulus) == 521) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_521(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -14182,8 +14101,6 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, got_ecc_fp_lock = 1; #endif /* HAVE_THREAD_LS */ - SAVE_VECTOR_REGISTERS(err = _svr_ret; goto out;); - /* find point */ idx = find_base(G); @@ -14232,8 +14149,6 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, } } - RESTORE_VECTOR_REGISTERS(); - out: #ifndef HAVE_THREAD_LS @@ -14262,36 +14177,28 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SP_SM2) if ((mp_count_bits(modulus) == 256) && (!mp_is_bit_set(modulus, 224))) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_sm2_256(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifndef WOLFSSL_SP_NO_256 if (mp_count_bits(modulus) == 256) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_256(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifdef WOLFSSL_SP_384 if (mp_count_bits(modulus) == 384) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_384(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif #ifdef WOLFSSL_SP_521 if (mp_count_bits(modulus) == 521) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = sp_ecc_mulmod_521(k, G, R, map, heap); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -14887,8 +14794,6 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg, } #endif - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - #ifdef WOLFSSL_ECIES_ISO18033 XMEMCPY(sharedSecret, out - pubKeySz, pubKeySz); sharedSz -= pubKeySz; @@ -15105,8 +15010,6 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg, #endif } - RESTORE_VECTOR_REGISTERS(); - ForceZero(sharedSecret, sharedSz); ForceZero(keys, (word32)keysLen); WC_FREE_VAR_EX(sharedSecret, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER); @@ -15266,8 +15169,6 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, } #endif - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - #ifndef WOLFSSL_ECIES_OLD if (pubKey == NULL) { WC_ALLOC_VAR_EX(peerKey, ecc_key, 1, ctx->heap, @@ -15501,8 +15402,6 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, if (ret == 0) *outSz = msgSz - digestSz; - RESTORE_VECTOR_REGISTERS(); - #ifndef WOLFSSL_ECIES_OLD if (pubKey == peerKey) wc_ecc_free(peerKey); @@ -15576,8 +15475,6 @@ static int mp_jacobi(mp_int* a, mp_int* n, int* c) return res; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - if ((res = mp_mod(a, n, a1)) != MP_OKAY) { goto done; } @@ -15635,8 +15532,6 @@ static int mp_jacobi(mp_int* a, mp_int* n, int* c) done: - RESTORE_VECTOR_REGISTERS(); - /* cleanup */ mp_clear(n1); mp_clear(a1); @@ -15674,8 +15569,6 @@ static int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret) return MP_VAL; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - res = mp_init(&e); if (res == MP_OKAY) res = mp_mod_d(prime, 8, &i); @@ -15699,8 +15592,6 @@ static int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret) mp_clear(&e); - RESTORE_VECTOR_REGISTERS(); - return res; #else int res, legendre, done = 0; @@ -15720,8 +15611,6 @@ static int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret) mp_int t1[1], C[1], Q[1], S[1], Z[1], M[1], T[1], R[1], N[1], two[1]; #endif - SAVE_VECTOR_REGISTERS(res = _svr_ret; goto out;); - if ((mp_init_multi(t1, C, Q, S, Z, M) != MP_OKAY) || (mp_init_multi(T, R, N, two, NULL, NULL) != MP_OKAY)) { res = MP_INIT_E; @@ -15933,8 +15822,6 @@ static int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret) out: - RESTORE_VECTOR_REGISTERS(); - #ifdef WOLFSSL_SMALL_STACK if (t1) { if (res != WC_NO_ERR_TRACE(MP_INIT_E)) diff --git a/wolfcrypt/src/eccsi.c b/wolfcrypt/src/eccsi.c index d919dd8a34..d0417ec879 100644 --- a/wolfcrypt/src/eccsi.c +++ b/wolfcrypt/src/eccsi.c @@ -36,14 +36,6 @@ #include #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV /* FIPS build has replaced ecc.h. */ #define wc_ecc_key_get_priv(key) (&((key)->k)) @@ -1507,8 +1499,6 @@ int wc_ValidateEccsiPair(EccsiKey* key, enum wc_HashType hashType, if (err != 0) return err; - SAVE_VECTOR_REGISTERS(return _svr_ret;); - params = &key->params; hs = &key->tmp; res = &key->pubkey.pubkey; @@ -1563,8 +1553,6 @@ int wc_ValidateEccsiPair(EccsiKey* key, enum wc_HashType hashType, } } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -2231,8 +2219,6 @@ int wc_VerifyEccsiHash(EccsiKey* key, enum wc_HashType hashType, if (err != 0) return err; - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* Decode the signature into components. */ r = wc_ecc_key_get_priv(&key->pubkey); pvt = &key->pubkey.pubkey; @@ -2318,8 +2304,6 @@ int wc_VerifyEccsiHash(EccsiKey* key, enum wc_HashType hashType, *verified = ((err == 0) && (mp_cmp(jx, r) == MP_EQ)); } - RESTORE_VECTOR_REGISTERS(); - return err; } #endif /* WOLFCRYPT_ECCSI_CLIENT */ diff --git a/wolfcrypt/src/ed25519.c b/wolfcrypt/src/ed25519.c index de12e87b83..b84d7e9b15 100644 --- a/wolfcrypt/src/ed25519.c +++ b/wolfcrypt/src/ed25519.c @@ -205,6 +205,64 @@ static int ed25519_hash(ed25519_key* key, const byte* in, word32 inLen, return ret; } +/* Reject small-order Ed25519 public keys: h*A vanishes during verification + * so any (R = [S]B, S) verifies for an arbitrary message. */ +static int ed25519_is_small_order(const byte p[ED25519_PUB_KEY_SIZE]) +{ + /* y-coordinates of every order-1/2/4/8 point plus the two non-canonical + * encodings y = p / y = p+1. Sign bit masked before compare. Only + * {y, y + p} fits in 32 bytes (2p overflows the 255-bit y field), so + * listing y and y + p exhausts the reachable encodings for each + * small-order y. */ + static const byte small_order_y[][ED25519_PUB_KEY_SIZE] = { + /* order 4: y = 0 */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + /* order 1: y = 1 (identity) */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + /* order 8 */ + {0x26,0xe8,0x95,0x8f,0xc2,0xb2,0x27,0xb0, + 0x45,0xc3,0xf4,0x89,0xf2,0xef,0x98,0xf0, + 0xd5,0xdf,0xac,0x05,0xd3,0xc6,0x33,0x39, + 0xb1,0x38,0x02,0x88,0x6d,0x53,0xfc,0x05}, + /* order 8 */ + {0xc7,0x17,0x6a,0x70,0x3d,0x4d,0xd8,0x4f, + 0xba,0x3c,0x0b,0x76,0x0d,0x10,0x67,0x0f, + 0x2a,0x20,0x53,0xfa,0x2c,0x39,0xcc,0xc6, + 0x4e,0xc7,0xfd,0x77,0x92,0xac,0x03,0x7a}, + /* order 2: y = p - 1 */ + {0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + /* non-canonical y = p (decodes to y = 0) */ + {0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + /* non-canonical y = p + 1 (decodes to y = 1) */ + {0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f}, + }; + byte y[ED25519_PUB_KEY_SIZE]; + word32 i; + + XMEMCPY(y, p, ED25519_PUB_KEY_SIZE); + y[ED25519_PUB_KEY_SIZE - 1] &= 0x7f; + for (i = 0; i < sizeof(small_order_y) / ED25519_PUB_KEY_SIZE; i++) { + if (XMEMCMP(y, small_order_y[i], ED25519_PUB_KEY_SIZE) == 0) + return 1; + } + return 0; +} + #ifdef HAVE_ED25519_MAKE_KEY #if FIPS_VERSION3_GE(6,0,0) /* Performs a Pairwise Consistency Test on an Ed25519 key pair. @@ -808,6 +866,13 @@ static int ed25519_verify_msg_final_with_sha(const byte* sig, word32 sigLen, if (i == -1) return BAD_FUNC_ARG; + /* Defence in depth: also catch small-order keys imported with trusted=1. */ + if (ed25519_is_small_order(key->p)) { + WOLFSSL_MSG("Ed25519 small-order public key rejected during " + "signature verification"); + return BAD_FUNC_ARG; + } + /* uncompress A (public key), test if valid, and negate it */ #ifndef FREESCALE_LTC_ECC if (ge_frombytes_negate_vartime(&A, key->p) != 0) @@ -1502,6 +1567,13 @@ int wc_ed25519_check_key(ed25519_key* key) ret = PUBLIC_KEY_E; } + /* Reject small-order pub key before the priv-vs-pub compare so the + * diagnostic isn't masked by a "mismatch" error. */ + if ((ret == 0) && ed25519_is_small_order(key->p)) { + WOLFSSL_MSG("Ed25519 small-order public key rejected during key check"); + ret = PUBLIC_KEY_E; + } + #ifdef HAVE_ED25519_MAKE_KEY /* If we have a private key just make the public key and compare. */ if ((ret == 0) && (key->privKeySet)) { @@ -1521,9 +1593,6 @@ int wc_ed25519_check_key(ed25519_key* key) && (!key->privKeySet) #endif ) { - /* Verify that Q is not identity element 0. - * 0 has no representation for Ed25519. */ - /* Verify that xQ and yQ are integers in the interval [0, p - 1]. * Only have yQ so check that ordinate. p = 2^255 - 19 */ if ((key->p[ED25519_PUB_KEY_SIZE - 1] & 0x7f) == 0x7f) { diff --git a/wolfcrypt/src/ed448.c b/wolfcrypt/src/ed448.c index 72f1724856..d6c35c6245 100644 --- a/wolfcrypt/src/ed448.c +++ b/wolfcrypt/src/ed448.c @@ -238,6 +238,77 @@ static int ed448_pairwise_consistency_test(ed448_key* key, WC_RNG* rng) } #endif +/* Reject small-order Ed448 public keys: h*A vanishes during verification + * so any (R = [S]B, S) verifies for an arbitrary message. Cofactor is 4. */ +static int ed448_is_small_order(const byte p[ED448_PUB_KEY_SIZE]) +{ + /* y-coordinates of every order-1/2/4 point plus the non-canonical + * encodings y = p / y = p+1. Byte 56 is cleared in both table and + * input before compare, masking the x-sign bit and the + * spec-mandated-zero (but decoder-ignored) bits 0-6. The decoder + * (fe448_from_bytes) reads bytes 0-55 modulo p with no canonical-form + * check, so y = p decodes to 0 and y = p+1 decodes to 1; both must + * be rejected here. Only {y, y + p} fits in 56 bytes (2p overflows), + * so listing y and y + p exhausts the reachable encodings. */ + static const byte small_order_y[][ED448_PUB_KEY_SIZE] = { + /* order 1: identity y = 1, x = 0 */ + {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00}, + /* order 4: y = 0 (x = +/-1; sign bit covered by mask) */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00}, + /* order 2: y = p - 1, x = 0; p = 2^448 - 2^224 - 1 */ + {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + /* non-canonical y = p (decodes to y = 0) */ + {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + /* non-canonical y = p + 1 (decodes to y = 1) */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00}, + }; + byte y[ED448_PUB_KEY_SIZE]; + word32 i; + + XMEMCPY(y, p, ED448_PUB_KEY_SIZE); + y[ED448_PUB_KEY_SIZE - 1] = 0; + for (i = 0; i < sizeof(small_order_y) / ED448_PUB_KEY_SIZE; i++) { + if (XMEMCMP(y, small_order_y[i], ED448_PUB_KEY_SIZE) == 0) + return 1; + } + return 0; +} + /* Derive the public key for the private key. * * key [in] Ed448 key object. @@ -731,16 +802,11 @@ static int ed448_verify_msg_final_with_sha(const byte* sig, word32 sigLen, if (i == -1) return BAD_FUNC_ARG; - /* Reject identity public key (0,1): 0x01 followed by 56 zero bytes. */ - { - int isIdentity = (key->p[0] == 0x01); - int j; - for (j = 1; j < ED448_PUB_KEY_SIZE && isIdentity; j++) { - if (key->p[j] != 0x00) - isIdentity = 0; - } - if (isIdentity) - return BAD_FUNC_ARG; + /* Defence in depth: also catch small-order keys imported with trusted=1. */ + if (ed448_is_small_order(key->p)) { + WOLFSSL_MSG("Ed448 small-order public key rejected during " + "signature verification"); + return BAD_FUNC_ARG; } /* uncompress A (public key), test if valid, and negate it */ @@ -1412,6 +1478,13 @@ int wc_ed448_check_key(ed448_key* key) ret = PUBLIC_KEY_E; } + /* Reject small-order pub key before the priv-vs-pub compare so the + * diagnostic isn't masked by a "mismatch" error. */ + if ((ret == 0) && ed448_is_small_order(key->p)) { + WOLFSSL_MSG("Ed448 small-order public key rejected during key check"); + ret = PUBLIC_KEY_E; + } + /* If we have a private key just make the public key and compare. */ if ((ret == 0) && key->privKeySet) { ret = wc_ed448_make_public(key, pubKey, sizeof(pubKey)); @@ -1421,23 +1494,6 @@ int wc_ed448_check_key(ed448_key* key) } /* No private key, check Y is valid. */ else if ((ret == 0) && (!key->privKeySet)) { - /* Reject the identity element (0, 1). - * Encoding: 0x01 followed by 56 zero bytes. */ - { - int isIdentity = 1; - int i; - if (key->p[0] != 0x01) - isIdentity = 0; - for (i = 1; i < ED448_PUB_KEY_SIZE && isIdentity; i++) { - if (key->p[i] != 0x00) - isIdentity = 0; - } - if (isIdentity) { - WOLFSSL_MSG("Ed448 public key is the identity element"); - ret = PUBLIC_KEY_E; - } - } - /* Verify that xQ and yQ are integers in the interval [0, p - 1]. * Only have yQ so check that ordinate. * p = 2^448-2^224-1 = 0xff..fe..ff diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 20f921ba37..c7e1e4c885 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -47,6 +47,12 @@ #ifdef HAVE_ED448 #include #endif +#ifdef HAVE_CURVE25519 +#include +#endif +#ifdef HAVE_CURVE448 +#include +#endif static const struct s_ent { const enum wc_HashType macType; @@ -2767,7 +2773,7 @@ int wolfSSL_EVP_PKEY_CTX_ctrl_str(WOLFSSL_EVP_PKEY_CTX *ctx, #endif /* NO_WOLFSSL_STUB */ #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC) || \ - defined(HAVE_HKDF) + defined(HAVE_HKDF) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448) int wolfSSL_EVP_PKEY_derive(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen) { int len; @@ -2884,6 +2890,54 @@ int wolfSSL_EVP_PKEY_derive(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *key, size_ *keylen = (size_t)len; break; #endif +#ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: + if (!ctx->pkey->curve25519 || !ctx->peerKey->curve25519) { + return WOLFSSL_FAILURE; + } + len = CURVE25519_KEYSIZE; + if (key) { + word32 len32 = (word32)*keylen; + if (*keylen < (size_t)len) { + WOLFSSL_MSG("buffer too short"); + return WOLFSSL_FAILURE; + } + /* X25519 shared secret is little-endian (RFC 7748). */ + if (wc_curve25519_shared_secret_ex(ctx->pkey->curve25519, + ctx->peerKey->curve25519, key, &len32, + EC25519_LITTLE_ENDIAN) != 0) { + WOLFSSL_MSG("wc_curve25519_shared_secret_ex failed"); + return WOLFSSL_FAILURE; + } + len = (int)len32; + } + *keylen = (size_t)len; + break; +#endif +#ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: + if (!ctx->pkey->curve448 || !ctx->peerKey->curve448) { + return WOLFSSL_FAILURE; + } + len = CURVE448_KEY_SIZE; + if (key) { + word32 len32 = (word32)*keylen; + if (*keylen < (size_t)len) { + WOLFSSL_MSG("buffer too short"); + return WOLFSSL_FAILURE; + } + /* X448 shared secret is little-endian (RFC 7748). */ + if (wc_curve448_shared_secret_ex(ctx->pkey->curve448, + ctx->peerKey->curve448, key, &len32, + EC448_LITTLE_ENDIAN) != 0) { + WOLFSSL_MSG("wc_curve448_shared_secret_ex failed"); + return WOLFSSL_FAILURE; + } + len = (int)len32; + } + *keylen = (size_t)len; + break; +#endif #ifdef HAVE_HKDF case WC_EVP_PKEY_HKDF: (void)len; @@ -3761,6 +3815,12 @@ int wolfSSL_EVP_PKEY_keygen(WOLFSSL_EVP_PKEY_CTX *ctx, if (ctx->pkey == NULL || (ctx->pkey->type != WC_EVP_PKEY_EC && ctx->pkey->type != WC_EVP_PKEY_RSA && + #ifdef HAVE_CURVE25519 + ctx->pkey->type != WC_EVP_PKEY_X25519 && + #endif + #ifdef HAVE_CURVE448 + ctx->pkey->type != WC_EVP_PKEY_X448 && + #endif ctx->pkey->type != WC_EVP_PKEY_DH)) { WOLFSSL_MSG("Key not set or key type not supported"); return WOLFSSL_FAILURE; @@ -3821,6 +3881,57 @@ int wolfSSL_EVP_PKEY_keygen(WOLFSSL_EVP_PKEY_CTX *ctx, } } break; +#endif +#ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: + if (pkey->curve25519 == NULL) { + pkey->curve25519 = (curve25519_key*)XMALLOC( + sizeof(curve25519_key), pkey->heap, DYNAMIC_TYPE_CURVE25519); + if (pkey->curve25519 == NULL) { + ret = MEMORY_E; + break; + } + if (wc_curve25519_init_ex(pkey->curve25519, pkey->heap, + INVALID_DEVID) != 0) { + XFREE(pkey->curve25519, pkey->heap, DYNAMIC_TYPE_CURVE25519); + pkey->curve25519 = NULL; + break; + } + #ifdef WOLFSSL_CURVE25519_BLINDING + /* Use the EVP_PKEY's RNG for scalar blinding on derive. */ + (void)wc_curve25519_set_rng(pkey->curve25519, &pkey->rng); + #endif + pkey->ownCurve25519 = 1; + } + /* Reuse the RNG already initialized on the EVP_PKEY. */ + if (wc_curve25519_make_key(&pkey->rng, CURVE25519_KEYSIZE, + pkey->curve25519) == 0) { + ret = WOLFSSL_SUCCESS; + } + break; +#endif +#ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: + if (pkey->curve448 == NULL) { + pkey->curve448 = (curve448_key*)XMALLOC(sizeof(curve448_key), + pkey->heap, DYNAMIC_TYPE_CURVE448); + if (pkey->curve448 == NULL) { + ret = MEMORY_E; + break; + } + if (wc_curve448_init(pkey->curve448) != 0) { + XFREE(pkey->curve448, pkey->heap, DYNAMIC_TYPE_CURVE448); + pkey->curve448 = NULL; + break; + } + pkey->ownCurve448 = 1; + } + /* Reuse the RNG already initialized on the EVP_PKEY. */ + if (wc_curve448_make_key(&pkey->rng, CURVE448_KEY_SIZE, + pkey->curve448) == 0) { + ret = WOLFSSL_SUCCESS; + } + break; #endif default: break; @@ -3871,6 +3982,16 @@ int wolfSSL_EVP_PKEY_size(WOLFSSL_EVP_PKEY *pkey) return wc_ecc_sig_size((ecc_key*)(pkey->ecc->internal)); #endif /* HAVE_ECC */ +#ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: + return CURVE25519_KEYSIZE; +#endif + +#ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: + return CURVE448_KEY_SIZE; +#endif + default: break; } @@ -11822,6 +11943,27 @@ void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key) break; #endif /* HAVE_ED448 */ + #ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: + if (key->curve25519 != NULL && key->ownCurve25519 == 1) { + wc_curve25519_free(key->curve25519); + XFREE(key->curve25519, key->heap, + DYNAMIC_TYPE_CURVE25519); + key->curve25519 = NULL; + } + break; + #endif /* HAVE_CURVE25519 */ + + #ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: + if (key->curve448 != NULL && key->ownCurve448 == 1) { + wc_curve448_free(key->curve448); + XFREE(key->curve448, key->heap, DYNAMIC_TYPE_CURVE448); + key->curve448 = NULL; + } + break; + #endif /* HAVE_CURVE448 */ + #ifdef HAVE_HKDF case WC_EVP_PKEY_HKDF: XFREE(key->hkdfSalt, NULL, DYNAMIC_TYPE_SALT); diff --git a/wolfcrypt/src/evp_pk.c b/wolfcrypt/src/evp_pk.c index 03eb059b8c..9ef4d459bd 100644 --- a/wolfcrypt/src/evp_pk.c +++ b/wolfcrypt/src/evp_pk.c @@ -439,6 +439,64 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_raw_public_key(int type, ok = 1; break; } + #endif + #ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: { + curve25519_key* cKey; + if (len != CURVE25519_PUB_KEY_SIZE) { + break; + } + cKey = (curve25519_key*)XMALLOC(sizeof(curve25519_key), pkey->heap, + DYNAMIC_TYPE_CURVE25519); + if (cKey == NULL) { + break; + } + if (wc_curve25519_init_ex(cKey, pkey->heap, INVALID_DEVID) != 0) { + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE25519); + break; + } + /* Raw X25519 keys are little-endian (RFC 7748). */ + if (wc_curve25519_import_public_ex(pub, (word32)len, cKey, + EC25519_LITTLE_ENDIAN) != 0) { + wc_curve25519_free(cKey); + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE25519); + break; + } + pkey->type = WC_EVP_PKEY_X25519; + pkey->curve25519 = cKey; + pkey->ownCurve25519 = 1; + ok = 1; + break; + } + #endif + #ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: { + curve448_key* cKey; + if (len != CURVE448_PUB_KEY_SIZE) { + break; + } + cKey = (curve448_key*)XMALLOC(sizeof(curve448_key), pkey->heap, + DYNAMIC_TYPE_CURVE448); + if (cKey == NULL) { + break; + } + if (wc_curve448_init(cKey) != 0) { + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE448); + break; + } + /* Raw X448 keys are little-endian (RFC 7748). */ + if (wc_curve448_import_public_ex(pub, (word32)len, cKey, + EC448_LITTLE_ENDIAN) != 0) { + wc_curve448_free(cKey); + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE448); + break; + } + pkey->type = WC_EVP_PKEY_X448; + pkey->curve448 = cKey; + pkey->ownCurve448 = 1; + ok = 1; + break; + } #endif default: break; @@ -526,6 +584,68 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_raw_private_key(int type, ok = 1; break; } + #endif + #ifdef HAVE_CURVE25519 + case WC_EVP_PKEY_X25519: { + curve25519_key* cKey; + if (len != CURVE25519_KEYSIZE) { + break; + } + cKey = (curve25519_key*)XMALLOC(sizeof(curve25519_key), pkey->heap, + DYNAMIC_TYPE_CURVE25519); + if (cKey == NULL) { + break; + } + if (wc_curve25519_init_ex(cKey, pkey->heap, INVALID_DEVID) != 0) { + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE25519); + break; + } + #ifdef WOLFSSL_CURVE25519_BLINDING + /* Use the EVP_PKEY's RNG for scalar blinding on shared-secret. */ + (void)wc_curve25519_set_rng(cKey, &pkey->rng); + #endif + /* Raw X25519 keys are little-endian (RFC 7748). */ + if (wc_curve25519_import_private_ex(priv, (word32)len, cKey, + EC25519_LITTLE_ENDIAN) != 0) { + wc_curve25519_free(cKey); + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE25519); + break; + } + pkey->type = WC_EVP_PKEY_X25519; + pkey->curve25519 = cKey; + pkey->ownCurve25519 = 1; + ok = 1; + break; + } + #endif + #ifdef HAVE_CURVE448 + case WC_EVP_PKEY_X448: { + curve448_key* cKey; + if (len != CURVE448_KEY_SIZE) { + break; + } + cKey = (curve448_key*)XMALLOC(sizeof(curve448_key), pkey->heap, + DYNAMIC_TYPE_CURVE448); + if (cKey == NULL) { + break; + } + if (wc_curve448_init(cKey) != 0) { + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE448); + break; + } + /* Raw X448 keys are little-endian (RFC 7748). */ + if (wc_curve448_import_private_ex(priv, (word32)len, cKey, + EC448_LITTLE_ENDIAN) != 0) { + wc_curve448_free(cKey); + XFREE(cKey, pkey->heap, DYNAMIC_TYPE_CURVE448); + break; + } + pkey->type = WC_EVP_PKEY_X448; + pkey->curve448 = cKey; + pkey->ownCurve448 = 1; + ok = 1; + break; + } #endif default: break; @@ -942,7 +1062,8 @@ static int d2iTryMlDsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem, return WOLFSSL_FATAL_ERROR; } - return d2i_make_pkey(out, NULL, 0, priv, WC_EVP_PKEY_DILITHIUM); + /* Copy the consumed DER into pkey->pkey.ptr when the input was DER */ + return d2i_make_pkey(out, mem, keyIdx, priv, WC_EVP_PKEY_DILITHIUM); } #endif /* WOLFSSL_HAVE_MLDSA */ @@ -1696,6 +1817,10 @@ WOLFSSL_PKCS8_PRIV_KEY_INFO* wolfSSL_d2i_PKCS8_PKEY( DerBuffer rawDer; EncryptedInfo info; int advanceLen = 0; +#ifdef HAVE_DILITHIUM + word32 outerIdx = 0; + int outerLen = 0; +#endif /* Clear the encryption information and DER buffer. */ XMEMSET(&info, 0, sizeof(info)); @@ -1737,15 +1862,40 @@ WOLFSSL_PKCS8_PRIV_KEY_INFO* wolfSSL_d2i_PKCS8_PKEY( } if (algId == DHk) { /* Special case for DH as we expect the DER buffer to be always - * be in PKCS8 format */ + * in PKCS8 format */ rawDer.buffer = pkcs8Der->buffer; rawDer.length = inOutIdx + (word32)ret; } + #ifdef HAVE_DILITHIUM + else if ( + #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT + (algId == DILITHIUM_LEVEL2k) || + (algId == DILITHIUM_LEVEL3k) || + (algId == DILITHIUM_LEVEL5k) || + #endif + (algId == ML_DSA_LEVEL2k) || + (algId == ML_DSA_LEVEL3k) || + (algId == ML_DSA_LEVEL5k)) { + + /* Keep full PKCS#8 wrapper for level recovery from + * AlgorithmIdentifier parameters */ + rawDer.buffer = pkcs8Der->buffer; + if (GetSequence(pkcs8Der->buffer, &outerIdx, &outerLen, + pkcs8Der->length) < 0) { + ret = ASN_PARSE_E; + } + else { + rawDer.length = outerIdx + (word32)outerLen; + } + } + #endif else { rawDer.buffer = pkcs8Der->buffer + inOutIdx; rawDer.length = (word32)ret; } - ret = 0; /* good DER */ + if (ret > 0) { + ret = 0; /* good DER */ + } } } diff --git a/wolfcrypt/src/fe_x25519_asm.S b/wolfcrypt/src/fe_x25519_asm.S index ed53856bca..3f0e0dd6a8 100644 --- a/wolfcrypt/src/fe_x25519_asm.S +++ b/wolfcrypt/src/fe_x25519_asm.S @@ -4639,6 +4639,7 @@ L_curve25519_base_x64_3: adcq $0x00, %r8 adcq $0x00, %r9 adcq $0x00, %r10 + andq %rax, %r10 # Store movq %rcx, (%rdi) movq %r8, 8(%rdi) @@ -7054,6 +7055,7 @@ L_curve25519_x64_3: adcq $0x00, %r9 adcq $0x00, %r10 adcq $0x00, %r11 + andq %rax, %r11 # Store movq %rcx, (%rdi) movq %r9, 8(%rdi) @@ -15107,6 +15109,7 @@ L_curve25519_base_avx2_last_3: adcq $0x00, %r9 adcq $0x00, %r10 adcq $0x00, %r11 + andq %rcx, %r11 # Store movq %r8, (%rdi) movq %r9, 8(%rdi) @@ -17116,6 +17119,7 @@ L_curve25519_avx2_last_3: adcq $0x00, %r10 adcq $0x00, %r11 adcq $0x00, %r12 + andq %rcx, %r12 # Store movq %r9, (%rdi) movq %r10, 8(%rdi) diff --git a/wolfcrypt/src/port/pic32/pic32mz-crypt.c b/wolfcrypt/src/port/pic32/pic32mz-crypt.c index 75be92b306..2a86445957 100644 --- a/wolfcrypt/src/port/pic32/pic32mz-crypt.c +++ b/wolfcrypt/src/port/pic32/pic32mz-crypt.c @@ -657,9 +657,9 @@ static int wc_Pic32HashFinal(hashUpdCache* cache, byte* stdBuf, return ret; } -static void wc_Pic32HashFree(hashUpdCache* cache, void* heap) +static void wc_Pic32HashFree(hashUpdCache* cache, void* stdBuf, void* heap) { - if (cache && cache->buf && !cache->isCopy) { + if (cache && cache->buf && cache->buf != stdBuf && !cache->isCopy) { XFREE(cache->buf, heap, DYNAMIC_TYPE_HASH_TMP); cache->buf = NULL; } @@ -713,7 +713,7 @@ static void wc_Pic32HashFree(hashUpdCache* cache, void* heap) void wc_Md5Pic32Free(wc_Md5* md5) { if (md5) { - wc_Pic32HashFree(&md5->cache, md5->heap); + wc_Pic32HashFree(&md5->cache, (byte*)md5->buffer, md5->heap); } } #endif /* !NO_MD5 */ @@ -764,7 +764,7 @@ static void wc_Pic32HashFree(hashUpdCache* cache, void* heap) void wc_ShaPic32Free(wc_Sha* sha) { if (sha) { - wc_Pic32HashFree(&sha->cache, sha->heap); + wc_Pic32HashFree(&sha->cache, (byte*)sha->buffer, sha->heap); } } #endif /* !NO_SHA */ @@ -815,7 +815,7 @@ static void wc_Pic32HashFree(hashUpdCache* cache, void* heap) void wc_Sha256Pic32Free(wc_Sha256* sha256) { if (sha256) { - wc_Pic32HashFree(&sha256->cache, sha256->heap); + wc_Pic32HashFree(&sha256->cache, (byte*)sha256->buffer, sha256->heap); } } #endif /* !NO_SHA256 */ diff --git a/wolfcrypt/src/port/ppc64/ppc64-aes-asm.S b/wolfcrypt/src/port/ppc64/ppc64-aes-asm.S new file mode 100644 index 0000000000..4e3c681efc --- /dev/null +++ b/wolfcrypt/src/port/ppc64/ppc64-aes-asm.S @@ -0,0 +1,8627 @@ +/* ppc64-aes-asm + * + * Copyright (C) 2006-2025 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include + +/* Generated using (from wolfssl): + * cd ../scripts + * ruby ./aes/aes.rb ppc64 \ + * ../wolfssl/wolfcrypt/src/port/ppc64/ppc64-aes-asm.S + */ +#ifdef WOLFSSL_PPC64_ASM +#ifndef WOLFSSL_PPC64_ASM_INLINE +#if !defined(NO_AES) && defined(WOLFSSL_PPC64_ASM) +#ifdef HAVE_AES_DECRYPT +#ifndef __APPLE__ + .text + .section .rodata + .type L_AES_PPC64_td, @object + .size L_AES_PPC64_td, 1024 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_AES_PPC64_td: + .long 0x5051f4a7 + .long 0x537e4165 + .long 0xc31a17a4 + .long 0x963a275e + .long 0xcb3bab6b + .long 0xf11f9d45 + .long 0xabacfa58 + .long 0x934be303 + .long 0x552030fa + .long 0xf6ad766d + .long 0x9188cc76 + .long 0x25f5024c + .long 0xfc4fe5d7 + .long 0xd7c52acb + .long 0x80263544 + .long 0x8fb562a3 + .long 0x49deb15a + .long 0x6725ba1b + .long 0x9845ea0e + .long 0xe15dfec0 + .long 0x2c32f75 + .long 0x12814cf0 + .long 0xa38d4697 + .long 0xc66bd3f9 + .long 0xe7038f5f + .long 0x9515929c + .long 0xebbf6d7a + .long 0xda955259 + .long 0x2dd4be83 + .long 0xd3587421 + .long 0x2949e069 + .long 0x448ec9c8 + .long 0x6a75c289 + .long 0x78f48e79 + .long 0x6b99583e + .long 0xdd27b971 + .long 0xb6bee14f + .long 0x17f088ad + .long 0x66c920ac + .long 0xb47dce3a + .long 0x1863df4a + .long 0x82e51a31 + .long 0x60975133 + .long 0x4562537f + .long 0xe0b16477 + .long 0x84bb6bae + .long 0x1cfe81a0 + .long 0x94f9082b + .long 0x58704868 + .long 0x198f45fd + .long 0x8794de6c + .long 0xb7527bf8 + .long 0x23ab73d3 + .long 0xe2724b02 + .long 0x57e31f8f + .long 0x2a6655ab + .long 0x7b2eb28 + .long 0x32fb5c2 + .long 0x9a86c57b + .long 0xa5d33708 + .long 0xf2302887 + .long 0xb223bfa5 + .long 0xba02036a + .long 0x5ced1682 + .long 0x2b8acf1c + .long 0x92a779b4 + .long 0xf0f307f2 + .long 0xa14e69e2 + .long 0xcd65daf4 + .long 0xd50605be + .long 0x1fd13462 + .long 0x8ac4a6fe + .long 0x9d342e53 + .long 0xa0a2f355 + .long 0x32058ae1 + .long 0x75a4f6eb + .long 0x390b83ec + .long 0xaa4060ef + .long 0x65e719f + .long 0x51bd6e10 + .long 0xf93e218a + .long 0x3d96dd06 + .long 0xaedd3e05 + .long 0x464de6bd + .long 0xb591548d + .long 0x571c45d + .long 0x6f0406d4 + .long 0xff605015 + .long 0x241998fb + .long 0x97d6bde9 + .long 0xcc894043 + .long 0x7767d99e + .long 0xbdb0e842 + .long 0x8807898b + .long 0x38e7195b + .long 0xdb79c8ee + .long 0x47a17c0a + .long 0xe97c420f + .long 0xc9f8841e + .long 0x0 + .long 0x83098086 + .long 0x48322bed + .long 0xac1e1170 + .long 0x4e6c5a72 + .long 0xfbfd0eff + .long 0x560f8538 + .long 0x1e3daed5 + .long 0x27362d39 + .long 0x640a0fd9 + .long 0x21685ca6 + .long 0xd19b5b54 + .long 0x3a24362e + .long 0xb10c0a67 + .long 0xf9357e7 + .long 0xd2b4ee96 + .long 0x9e1b9b91 + .long 0x4f80c0c5 + .long 0xa261dc20 + .long 0x695a774b + .long 0x161c121a + .long 0xae293ba + .long 0xe5c0a02a + .long 0x433c22e0 + .long 0x1d121b17 + .long 0xb0e090d + .long 0xadf28bc7 + .long 0xb92db6a8 + .long 0xc8141ea9 + .long 0x8557f119 + .long 0x4caf7507 + .long 0xbbee99dd + .long 0xfda37f60 + .long 0x9ff70126 + .long 0xbc5c72f5 + .long 0xc544663b + .long 0x345bfb7e + .long 0x768b4329 + .long 0xdccb23c6 + .long 0x68b6edfc + .long 0x63b8e4f1 + .long 0xcad731dc + .long 0x10426385 + .long 0x40139722 + .long 0x2084c611 + .long 0x7d854a24 + .long 0xf8d2bb3d + .long 0x11aef932 + .long 0x6dc729a1 + .long 0x4b1d9e2f + .long 0xf3dcb230 + .long 0xec0d8652 + .long 0xd077c1e3 + .long 0x6c2bb316 + .long 0x99a970b9 + .long 0xfa119448 + .long 0x2247e964 + .long 0xc4a8fc8c + .long 0x1aa0f03f + .long 0xd8567d2c + .long 0xef223390 + .long 0xc787494e + .long 0xc1d938d1 + .long 0xfe8ccaa2 + .long 0x3698d40b + .long 0xcfa6f581 + .long 0x28a57ade + .long 0x26dab78e + .long 0xa43fadbf + .long 0xe42c3a9d + .long 0xd507892 + .long 0x9b6a5fcc + .long 0x62547e46 + .long 0xc2f68d13 + .long 0xe890d8b8 + .long 0x5e2e39f7 + .long 0xf582c3af + .long 0xbe9f5d80 + .long 0x7c69d093 + .long 0xa96fd52d + .long 0xb3cf2512 + .long 0x3bc8ac99 + .long 0xa710187d + .long 0x6ee89c63 + .long 0x7bdb3bbb + .long 0x9cd2678 + .long 0xf46e5918 + .long 0x1ec9ab7 + .long 0xa8834f9a + .long 0x65e6956e + .long 0x7eaaffe6 + .long 0x821bccf + .long 0xe6ef15e8 + .long 0xd9bae79b + .long 0xce4a6f36 + .long 0xd4ea9f09 + .long 0xd629b07c + .long 0xaf31a4b2 + .long 0x312a3f23 + .long 0x30c6a594 + .long 0xc035a266 + .long 0x37744ebc + .long 0xa6fc82ca + .long 0xb0e090d0 + .long 0x1533a7d8 + .long 0x4af10498 + .long 0xf741ecda + .long 0xe7fcd50 + .long 0x2f1791f6 + .long 0x8d764dd6 + .long 0x4d43efb0 + .long 0x54ccaa4d + .long 0xdfe49604 + .long 0xe39ed1b5 + .long 0x1b4c6a88 + .long 0xb8c12c1f + .long 0x7f466551 + .long 0x49d5eea + .long 0x5d018c35 + .long 0x73fa8774 + .long 0x2efb0b41 + .long 0x5ab3671d + .long 0x5292dbd2 + .long 0x33e91056 + .long 0x136dd647 + .long 0x8c9ad761 + .long 0x7a37a10c + .long 0x8e59f814 + .long 0x89eb133c + .long 0xeecea927 + .long 0x35b761c9 + .long 0xede11ce5 + .long 0x3c7a47b1 + .long 0x599cd2df + .long 0x3f55f273 + .long 0x791814ce + .long 0xbf73c737 + .long 0xea53f7cd + .long 0x5b5ffdaa + .long 0x14df3d6f + .long 0x867844db + .long 0x81caaff3 + .long 0x3eb968c4 + .long 0x2c382434 + .long 0x5fc2a340 + .long 0x72161dc3 + .long 0xcbce225 + .long 0x8b283c49 + .long 0x41ff0d95 + .long 0x7139a801 + .long 0xde080cb3 + .long 0x9cd8b4e4 + .long 0x906456c1 + .long 0x617bcb84 + .long 0x70d532b6 + .long 0x74486c5c + .long 0x42d0b857 +#endif /* HAVE_AES_DECRYPT */ +#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AES_CBC) || \ + defined(HAVE_AESCCM) || defined(HAVE_AESGCM) || \ + defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) +#ifndef __APPLE__ + .text + .section .rodata + .type L_AES_PPC64_te, @object + .size L_AES_PPC64_te, 1024 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_AES_PPC64_te: + .long 0xa5c66363 + .long 0x84f87c7c + .long 0x99ee7777 + .long 0x8df67b7b + .long 0xdfff2f2 + .long 0xbdd66b6b + .long 0xb1de6f6f + .long 0x5491c5c5 + .long 0x50603030 + .long 0x3020101 + .long 0xa9ce6767 + .long 0x7d562b2b + .long 0x19e7fefe + .long 0x62b5d7d7 + .long 0xe64dabab + .long 0x9aec7676 + .long 0x458fcaca + .long 0x9d1f8282 + .long 0x4089c9c9 + .long 0x87fa7d7d + .long 0x15effafa + .long 0xebb25959 + .long 0xc98e4747 + .long 0xbfbf0f0 + .long 0xec41adad + .long 0x67b3d4d4 + .long 0xfd5fa2a2 + .long 0xea45afaf + .long 0xbf239c9c + .long 0xf753a4a4 + .long 0x96e47272 + .long 0x5b9bc0c0 + .long 0xc275b7b7 + .long 0x1ce1fdfd + .long 0xae3d9393 + .long 0x6a4c2626 + .long 0x5a6c3636 + .long 0x417e3f3f + .long 0x2f5f7f7 + .long 0x4f83cccc + .long 0x5c683434 + .long 0xf451a5a5 + .long 0x34d1e5e5 + .long 0x8f9f1f1 + .long 0x93e27171 + .long 0x73abd8d8 + .long 0x53623131 + .long 0x3f2a1515 + .long 0xc080404 + .long 0x5295c7c7 + .long 0x65462323 + .long 0x5e9dc3c3 + .long 0x28301818 + .long 0xa1379696 + .long 0xf0a0505 + .long 0xb52f9a9a + .long 0x90e0707 + .long 0x36241212 + .long 0x9b1b8080 + .long 0x3ddfe2e2 + .long 0x26cdebeb + .long 0x694e2727 + .long 0xcd7fb2b2 + .long 0x9fea7575 + .long 0x1b120909 + .long 0x9e1d8383 + .long 0x74582c2c + .long 0x2e341a1a + .long 0x2d361b1b + .long 0xb2dc6e6e + .long 0xeeb45a5a + .long 0xfb5ba0a0 + .long 0xf6a45252 + .long 0x4d763b3b + .long 0x61b7d6d6 + .long 0xce7db3b3 + .long 0x7b522929 + .long 0x3edde3e3 + .long 0x715e2f2f + .long 0x97138484 + .long 0xf5a65353 + .long 0x68b9d1d1 + .long 0x0 + .long 0x2cc1eded + .long 0x60402020 + .long 0x1fe3fcfc + .long 0xc879b1b1 + .long 0xedb65b5b + .long 0xbed46a6a + .long 0x468dcbcb + .long 0xd967bebe + .long 0x4b723939 + .long 0xde944a4a + .long 0xd4984c4c + .long 0xe8b05858 + .long 0x4a85cfcf + .long 0x6bbbd0d0 + .long 0x2ac5efef + .long 0xe54faaaa + .long 0x16edfbfb + .long 0xc5864343 + .long 0xd79a4d4d + .long 0x55663333 + .long 0x94118585 + .long 0xcf8a4545 + .long 0x10e9f9f9 + .long 0x6040202 + .long 0x81fe7f7f + .long 0xf0a05050 + .long 0x44783c3c + .long 0xba259f9f + .long 0xe34ba8a8 + .long 0xf3a25151 + .long 0xfe5da3a3 + .long 0xc0804040 + .long 0x8a058f8f + .long 0xad3f9292 + .long 0xbc219d9d + .long 0x48703838 + .long 0x4f1f5f5 + .long 0xdf63bcbc + .long 0xc177b6b6 + .long 0x75afdada + .long 0x63422121 + .long 0x30201010 + .long 0x1ae5ffff + .long 0xefdf3f3 + .long 0x6dbfd2d2 + .long 0x4c81cdcd + .long 0x14180c0c + .long 0x35261313 + .long 0x2fc3ecec + .long 0xe1be5f5f + .long 0xa2359797 + .long 0xcc884444 + .long 0x392e1717 + .long 0x5793c4c4 + .long 0xf255a7a7 + .long 0x82fc7e7e + .long 0x477a3d3d + .long 0xacc86464 + .long 0xe7ba5d5d + .long 0x2b321919 + .long 0x95e67373 + .long 0xa0c06060 + .long 0x98198181 + .long 0xd19e4f4f + .long 0x7fa3dcdc + .long 0x66442222 + .long 0x7e542a2a + .long 0xab3b9090 + .long 0x830b8888 + .long 0xca8c4646 + .long 0x29c7eeee + .long 0xd36bb8b8 + .long 0x3c281414 + .long 0x79a7dede + .long 0xe2bc5e5e + .long 0x1d160b0b + .long 0x76addbdb + .long 0x3bdbe0e0 + .long 0x56643232 + .long 0x4e743a3a + .long 0x1e140a0a + .long 0xdb924949 + .long 0xa0c0606 + .long 0x6c482424 + .long 0xe4b85c5c + .long 0x5d9fc2c2 + .long 0x6ebdd3d3 + .long 0xef43acac + .long 0xa6c46262 + .long 0xa8399191 + .long 0xa4319595 + .long 0x37d3e4e4 + .long 0x8bf27979 + .long 0x32d5e7e7 + .long 0x438bc8c8 + .long 0x596e3737 + .long 0xb7da6d6d + .long 0x8c018d8d + .long 0x64b1d5d5 + .long 0xd29c4e4e + .long 0xe049a9a9 + .long 0xb4d86c6c + .long 0xfaac5656 + .long 0x7f3f4f4 + .long 0x25cfeaea + .long 0xafca6565 + .long 0x8ef47a7a + .long 0xe947aeae + .long 0x18100808 + .long 0xd56fbaba + .long 0x88f07878 + .long 0x6f4a2525 + .long 0x725c2e2e + .long 0x24381c1c + .long 0xf157a6a6 + .long 0xc773b4b4 + .long 0x5197c6c6 + .long 0x23cbe8e8 + .long 0x7ca1dddd + .long 0x9ce87474 + .long 0x213e1f1f + .long 0xdd964b4b + .long 0xdc61bdbd + .long 0x860d8b8b + .long 0x850f8a8a + .long 0x90e07070 + .long 0x427c3e3e + .long 0xc471b5b5 + .long 0xaacc6666 + .long 0xd8904848 + .long 0x5060303 + .long 0x1f7f6f6 + .long 0x121c0e0e + .long 0xa3c26161 + .long 0x5f6a3535 + .long 0xf9ae5757 + .long 0xd069b9b9 + .long 0x91178686 + .long 0x5899c1c1 + .long 0x273a1d1d + .long 0xb9279e9e + .long 0x38d9e1e1 + .long 0x13ebf8f8 + .long 0xb32b9898 + .long 0x33221111 + .long 0xbbd26969 + .long 0x70a9d9d9 + .long 0x89078e8e + .long 0xa7339494 + .long 0xb62d9b9b + .long 0x223c1e1e + .long 0x92158787 + .long 0x20c9e9e9 + .long 0x4987cece + .long 0xffaa5555 + .long 0x78502828 + .long 0x7aa5dfdf + .long 0x8f038c8c + .long 0xf859a1a1 + .long 0x80098989 + .long 0x171a0d0d + .long 0xda65bfbf + .long 0x31d7e6e6 + .long 0xc6844242 + .long 0xb8d06868 + .long 0xc3824141 + .long 0xb0299999 + .long 0x775a2d2d + .long 0x111e0f0f + .long 0xcb7bb0b0 + .long 0xfca85454 + .long 0xd66dbbbb + .long 0x3a2c1616 +#endif /* HAVE_AES_DECRYPT || HAVE_AES_CBC || HAVE_AESCCM || HAVE_AESGCM || + * WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER */ +#ifdef HAVE_AES_DECRYPT +#ifndef __APPLE__ +.text +.globl AES_invert_key +.type AES_invert_key,@function +.align 16 +AES_invert_key: +#else +.section __TEXT,__text +.globl _AES_invert_key +.p2align 4 +_AES_invert_key: +#endif /* __APPLE__ */ + stdu 1, -32(1) + mflr 0 + std 0, 24(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 5, 2, L_AES_PPC64_te@toc@ha + addi 5, 5, L_AES_PPC64_te@toc@l +#else + lis 5, L_AES_PPC64_te@ha + la 5, L_AES_PPC64_te@l(5) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 6, 2, L_AES_PPC64_td@toc@ha + addi 6, 6, L_AES_PPC64_td@toc@l +#else + lis 6, L_AES_PPC64_td@ha + la 6, L_AES_PPC64_td@l(6) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 5, 5, 3 + sldi 16, 4, 4 + add 16, 16, 3 + ld 7, 0(3) + ld 8, 8(3) + ld 11, 0(16) + ld 12, 8(16) + rldicr 7, 7, 32, 63 + rldicr 8, 8, 32, 63 + rldicr 11, 11, 32, 63 + rldicr 12, 12, 32, 63 + std 7, 0(16) + std 8, 8(16) + std 11, 0(3) + std 12, 8(3) + addi 3, 3, 16 + addi 16, 16, -16 + addi 0, 4, -2 + srdi 0, 0, 1 + mtctr 0 +L_AES_invert_key_loop: + ld 7, 0(3) + ld 8, 8(3) + ld 11, 0(16) + ld 12, 8(16) + std 7, 0(16) + std 8, 8(16) + std 11, 0(3) + std 12, 8(3) + addi 3, 3, 16 + addi 16, 16, -16 + bdnz L_AES_invert_key_loop + sldi 16, 4, 3 + subf 3, 16, 3 + addi 3, 3, 16 + addi 0, 4, -1 + mtctr 0 +L_AES_invert_key_mix_loop: + lwz 8, 0(3) + lwz 7, 4(3) + lwz 10, 8(3) + lwz 9, 12(3) + rlwinm 11, 7, 2, 22, 29 + rlwinm 12, 7, 26, 22, 29 + rlwinm 14, 7, 18, 22, 29 + rlwinm 15, 7, 10, 22, 29 + lbzx 11, 5, 11 + lbzx 12, 5, 12 + lbzx 14, 5, 14 + lbzx 15, 5, 15 + slwi 11, 11, 2 + slwi 12, 12, 2 + slwi 14, 14, 2 + slwi 15, 15, 2 + lwzx 11, 6, 11 + lwzx 12, 6, 12 + lwzx 14, 6, 14 + lwzx 15, 6, 15 + rlwimi 11, 11, 16, 0, 31 + rlwimi 12, 12, 24, 0, 31 + rlwimi 15, 15, 8, 0, 31 + xor 14, 14, 11 + xor 14, 14, 12 + xor 14, 14, 15 + stw 14, 4(3) + rlwinm 11, 8, 2, 22, 29 + rlwinm 12, 8, 26, 22, 29 + rlwinm 14, 8, 18, 22, 29 + rlwinm 15, 8, 10, 22, 29 + lbzx 11, 5, 11 + lbzx 12, 5, 12 + lbzx 14, 5, 14 + lbzx 15, 5, 15 + slwi 11, 11, 2 + slwi 12, 12, 2 + slwi 14, 14, 2 + slwi 15, 15, 2 + lwzx 11, 6, 11 + lwzx 12, 6, 12 + lwzx 14, 6, 14 + lwzx 15, 6, 15 + rlwimi 11, 11, 16, 0, 31 + rlwimi 12, 12, 24, 0, 31 + rlwimi 15, 15, 8, 0, 31 + xor 14, 14, 11 + xor 14, 14, 12 + xor 14, 14, 15 + stw 14, 0(3) + addi 3, 3, 8 + rlwinm 11, 9, 2, 22, 29 + rlwinm 12, 9, 26, 22, 29 + rlwinm 14, 9, 18, 22, 29 + rlwinm 15, 9, 10, 22, 29 + lbzx 11, 5, 11 + lbzx 12, 5, 12 + lbzx 14, 5, 14 + lbzx 15, 5, 15 + slwi 11, 11, 2 + slwi 12, 12, 2 + slwi 14, 14, 2 + slwi 15, 15, 2 + lwzx 11, 6, 11 + lwzx 12, 6, 12 + lwzx 14, 6, 14 + lwzx 15, 6, 15 + rlwimi 11, 11, 16, 0, 31 + rlwimi 12, 12, 24, 0, 31 + rlwimi 15, 15, 8, 0, 31 + xor 14, 14, 11 + xor 14, 14, 12 + xor 14, 14, 15 + stw 14, 4(3) + rlwinm 11, 10, 2, 22, 29 + rlwinm 12, 10, 26, 22, 29 + rlwinm 14, 10, 18, 22, 29 + rlwinm 15, 10, 10, 22, 29 + lbzx 11, 5, 11 + lbzx 12, 5, 12 + lbzx 14, 5, 14 + lbzx 15, 5, 15 + slwi 11, 11, 2 + slwi 12, 12, 2 + slwi 14, 14, 2 + slwi 15, 15, 2 + lwzx 11, 6, 11 + lwzx 12, 6, 12 + lwzx 14, 6, 14 + lwzx 15, 6, 15 + rlwimi 11, 11, 16, 0, 31 + rlwimi 12, 12, 24, 0, 31 + rlwimi 15, 15, 8, 0, 31 + xor 14, 14, 11 + xor 14, 14, 12 + xor 14, 14, 15 + stw 14, 0(3) + addi 3, 3, 8 + bdnz L_AES_invert_key_mix_loop + ld 0, 24(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + addi 1, 1, 32 + blr +#ifndef __APPLE__ + .size AES_invert_key,.-AES_invert_key +#endif /* __APPLE__ */ +#endif /* HAVE_AES_DECRYPT */ +#ifndef __APPLE__ + .text + .section .rodata + .type L_AES_PPC64_rcon, @object + .size L_AES_PPC64_rcon, 40 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_AES_PPC64_rcon: + .long 0x1000000 + .long 0x2000000 + .long 0x4000000 + .long 0x8000000 + .long 0x10000000 + .long 0x20000000 + .long 0x40000000 + .long 0x80000000 + .long 0x1b000000 + .long 0x36000000 +#ifndef __APPLE__ +.text +.globl AES_set_encrypt_key +.type AES_set_encrypt_key,@function +.align 16 +AES_set_encrypt_key: +#else +.section __TEXT,__text +.globl _AES_set_encrypt_key +.p2align 4 +_AES_set_encrypt_key: +#endif /* __APPLE__ */ + stdu 1, -24(1) + mflr 0 + std 0, 16(1) + std 14, 0(1) + std 15, 8(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 6, 2, L_AES_PPC64_te@toc@ha + addi 6, 6, L_AES_PPC64_te@toc@l +#else + lis 6, L_AES_PPC64_te@ha + la 6, L_AES_PPC64_te@l(6) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 7, 2, L_AES_PPC64_rcon@toc@ha + addi 7, 7, L_AES_PPC64_rcon@toc@l +#else + lis 7, L_AES_PPC64_rcon@ha + la 7, L_AES_PPC64_rcon@l(7) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 6, 6, 3 + cmplwi 4, 0x80 + beq L_AES_set_encrypt_key_start_128 + cmplwi 4, 0xc0 + beq L_AES_set_encrypt_key_start_192 + ld 9, 0(3) + ld 10, 8(3) + ld 11, 16(3) + ld 12, 24(3) + rldicr 9, 9, 32, 63 + rldicr 10, 10, 32, 63 + rldicr 11, 11, 32, 63 + rldicr 12, 12, 32, 63 + std 9, 0(5) + std 10, 8(5) + std 11, 16(5) + std 12, 24(5) + rldicr 12, 12, 32, 63 + li 8, 6 + mtctr 8 +L_AES_set_encrypt_key_loop_256: + rlwinm 9, 12, 2, 22, 29 + rlwinm 10, 12, 26, 22, 29 + rlwinm 11, 12, 18, 22, 29 + rlwinm 12, 12, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 12 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + addi 5, 5, 16 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 10, 16(5) + stw 9, 20(5) + stw 12, 24(5) + stw 11, 28(5) + rlwinm 9, 12, 26, 22, 29 + rlwinm 10, 12, 18, 22, 29 + rlwinm 11, 12, 10, 22, 29 + rlwinm 12, 12, 2, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 12 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + addi 5, 5, 16 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 10, 16(5) + stw 9, 20(5) + stw 12, 24(5) + stw 11, 28(5) + bdnz L_AES_set_encrypt_key_loop_256 + rlwinm 9, 12, 2, 22, 29 + rlwinm 10, 12, 26, 22, 29 + rlwinm 11, 12, 18, 22, 29 + rlwinm 12, 12, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 12 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + addi 5, 5, 16 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 9, 16(5) + stw 10, 20(5) + stw 11, 24(5) + stw 12, 28(5) + b L_AES_set_encrypt_key_end +L_AES_set_encrypt_key_start_192: + ld 12, 0(3) + ld 14, 8(3) + ld 15, 16(3) + rldicr 12, 12, 32, 63 + rldicr 14, 14, 32, 63 + rldicr 15, 15, 32, 63 + std 12, 0(5) + std 14, 8(5) + std 15, 16(5) + rldicr 15, 15, 32, 63 + li 8, 7 + mtctr 8 +L_AES_set_encrypt_key_loop_192: + rlwinm 9, 15, 2, 22, 29 + rlwinm 10, 15, 26, 22, 29 + rlwinm 11, 15, 18, 22, 29 + rlwinm 15, 15, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 15 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + lwz 15, 16(5) + lwz 14, 20(5) + addi 5, 5, 24 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + xor 14, 14, 12 + xor 15, 15, 14 + stw 10, 0(5) + stw 9, 4(5) + stw 12, 8(5) + stw 11, 12(5) + stw 15, 16(5) + stw 14, 20(5) + bdnz L_AES_set_encrypt_key_loop_192 + rlwinm 9, 15, 2, 22, 29 + rlwinm 10, 15, 26, 22, 29 + rlwinm 11, 15, 18, 22, 29 + rlwinm 15, 15, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 15 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + lwz 15, 16(5) + lwz 14, 20(5) + addi 5, 5, 24 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 9, 0(5) + stw 10, 4(5) + stw 11, 8(5) + stw 12, 12(5) + b L_AES_set_encrypt_key_end +L_AES_set_encrypt_key_start_128: + li 8, 0 + ld 11, 0(3) + ld 12, 8(3) + rldicr 11, 11, 32, 63 + rldicr 12, 12, 32, 63 + std 11, 0(5) + std 12, 8(5) + rldicr 12, 12, 32, 63 + li 8, 9 + mtctr 8 +L_AES_set_encrypt_key_loop_128: + rlwinm 9, 12, 2, 22, 29 + rlwinm 10, 12, 26, 22, 29 + rlwinm 11, 12, 18, 22, 29 + rlwinm 12, 12, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 12 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + addi 5, 5, 16 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 10, 0(5) + stw 9, 4(5) + stw 12, 8(5) + stw 11, 12(5) + bdnz L_AES_set_encrypt_key_loop_128 + rlwinm 9, 12, 2, 22, 29 + rlwinm 10, 12, 26, 22, 29 + rlwinm 11, 12, 18, 22, 29 + rlwinm 12, 12, 10, 22, 29 + lbzx 9, 6, 9 + lbzx 10, 6, 10 + lbzx 11, 6, 11 + lbzx 0, 6, 12 + rlwimi 0, 9, 8, 16, 23 + rlwimi 0, 10, 16, 8, 15 + rlwimi 0, 11, 24, 0, 7 + lwz 10, 0(5) + lwz 9, 4(5) + lwz 12, 8(5) + lwz 11, 12(5) + addi 5, 5, 16 + xor 9, 9, 0 + lwz 0, 0(7) + addi 7, 7, 4 + xor 9, 9, 0 + xor 10, 10, 9 + xor 11, 11, 10 + xor 12, 12, 11 + stw 9, 0(5) + stw 10, 4(5) + stw 11, 8(5) + stw 12, 12(5) +L_AES_set_encrypt_key_end: + ld 0, 16(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + addi 1, 1, 24 + blr +#ifndef __APPLE__ + .size AES_set_encrypt_key,.-AES_set_encrypt_key +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .text + .section .rodata + .type L_AES_PPC64_te4_0, @object + .size L_AES_PPC64_te4_0, 4096 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_AES_PPC64_te4_0: + .long 0xc66363a5 + .long 0xf87c7c84 + .long 0xee777799 + .long 0xf67b7b8d + .long 0xfff2f20d + .long 0xd66b6bbd + .long 0xde6f6fb1 + .long 0x91c5c554 + .long 0x60303050 + .long 0x2010103 + .long 0xce6767a9 + .long 0x562b2b7d + .long 0xe7fefe19 + .long 0xb5d7d762 + .long 0x4dababe6 + .long 0xec76769a + .long 0x8fcaca45 + .long 0x1f82829d + .long 0x89c9c940 + .long 0xfa7d7d87 + .long 0xeffafa15 + .long 0xb25959eb + .long 0x8e4747c9 + .long 0xfbf0f00b + .long 0x41adadec + .long 0xb3d4d467 + .long 0x5fa2a2fd + .long 0x45afafea + .long 0x239c9cbf + .long 0x53a4a4f7 + .long 0xe4727296 + .long 0x9bc0c05b + .long 0x75b7b7c2 + .long 0xe1fdfd1c + .long 0x3d9393ae + .long 0x4c26266a + .long 0x6c36365a + .long 0x7e3f3f41 + .long 0xf5f7f702 + .long 0x83cccc4f + .long 0x6834345c + .long 0x51a5a5f4 + .long 0xd1e5e534 + .long 0xf9f1f108 + .long 0xe2717193 + .long 0xabd8d873 + .long 0x62313153 + .long 0x2a15153f + .long 0x804040c + .long 0x95c7c752 + .long 0x46232365 + .long 0x9dc3c35e + .long 0x30181828 + .long 0x379696a1 + .long 0xa05050f + .long 0x2f9a9ab5 + .long 0xe070709 + .long 0x24121236 + .long 0x1b80809b + .long 0xdfe2e23d + .long 0xcdebeb26 + .long 0x4e272769 + .long 0x7fb2b2cd + .long 0xea75759f + .long 0x1209091b + .long 0x1d83839e + .long 0x582c2c74 + .long 0x341a1a2e + .long 0x361b1b2d + .long 0xdc6e6eb2 + .long 0xb45a5aee + .long 0x5ba0a0fb + .long 0xa45252f6 + .long 0x763b3b4d + .long 0xb7d6d661 + .long 0x7db3b3ce + .long 0x5229297b + .long 0xdde3e33e + .long 0x5e2f2f71 + .long 0x13848497 + .long 0xa65353f5 + .long 0xb9d1d168 + .long 0x0 + .long 0xc1eded2c + .long 0x40202060 + .long 0xe3fcfc1f + .long 0x79b1b1c8 + .long 0xb65b5bed + .long 0xd46a6abe + .long 0x8dcbcb46 + .long 0x67bebed9 + .long 0x7239394b + .long 0x944a4ade + .long 0x984c4cd4 + .long 0xb05858e8 + .long 0x85cfcf4a + .long 0xbbd0d06b + .long 0xc5efef2a + .long 0x4faaaae5 + .long 0xedfbfb16 + .long 0x864343c5 + .long 0x9a4d4dd7 + .long 0x66333355 + .long 0x11858594 + .long 0x8a4545cf + .long 0xe9f9f910 + .long 0x4020206 + .long 0xfe7f7f81 + .long 0xa05050f0 + .long 0x783c3c44 + .long 0x259f9fba + .long 0x4ba8a8e3 + .long 0xa25151f3 + .long 0x5da3a3fe + .long 0x804040c0 + .long 0x58f8f8a + .long 0x3f9292ad + .long 0x219d9dbc + .long 0x70383848 + .long 0xf1f5f504 + .long 0x63bcbcdf + .long 0x77b6b6c1 + .long 0xafdada75 + .long 0x42212163 + .long 0x20101030 + .long 0xe5ffff1a + .long 0xfdf3f30e + .long 0xbfd2d26d + .long 0x81cdcd4c + .long 0x180c0c14 + .long 0x26131335 + .long 0xc3ecec2f + .long 0xbe5f5fe1 + .long 0x359797a2 + .long 0x884444cc + .long 0x2e171739 + .long 0x93c4c457 + .long 0x55a7a7f2 + .long 0xfc7e7e82 + .long 0x7a3d3d47 + .long 0xc86464ac + .long 0xba5d5de7 + .long 0x3219192b + .long 0xe6737395 + .long 0xc06060a0 + .long 0x19818198 + .long 0x9e4f4fd1 + .long 0xa3dcdc7f + .long 0x44222266 + .long 0x542a2a7e + .long 0x3b9090ab + .long 0xb888883 + .long 0x8c4646ca + .long 0xc7eeee29 + .long 0x6bb8b8d3 + .long 0x2814143c + .long 0xa7dede79 + .long 0xbc5e5ee2 + .long 0x160b0b1d + .long 0xaddbdb76 + .long 0xdbe0e03b + .long 0x64323256 + .long 0x743a3a4e + .long 0x140a0a1e + .long 0x924949db + .long 0xc06060a + .long 0x4824246c + .long 0xb85c5ce4 + .long 0x9fc2c25d + .long 0xbdd3d36e + .long 0x43acacef + .long 0xc46262a6 + .long 0x399191a8 + .long 0x319595a4 + .long 0xd3e4e437 + .long 0xf279798b + .long 0xd5e7e732 + .long 0x8bc8c843 + .long 0x6e373759 + .long 0xda6d6db7 + .long 0x18d8d8c + .long 0xb1d5d564 + .long 0x9c4e4ed2 + .long 0x49a9a9e0 + .long 0xd86c6cb4 + .long 0xac5656fa + .long 0xf3f4f407 + .long 0xcfeaea25 + .long 0xca6565af + .long 0xf47a7a8e + .long 0x47aeaee9 + .long 0x10080818 + .long 0x6fbabad5 + .long 0xf0787888 + .long 0x4a25256f + .long 0x5c2e2e72 + .long 0x381c1c24 + .long 0x57a6a6f1 + .long 0x73b4b4c7 + .long 0x97c6c651 + .long 0xcbe8e823 + .long 0xa1dddd7c + .long 0xe874749c + .long 0x3e1f1f21 + .long 0x964b4bdd + .long 0x61bdbddc + .long 0xd8b8b86 + .long 0xf8a8a85 + .long 0xe0707090 + .long 0x7c3e3e42 + .long 0x71b5b5c4 + .long 0xcc6666aa + .long 0x904848d8 + .long 0x6030305 + .long 0xf7f6f601 + .long 0x1c0e0e12 + .long 0xc26161a3 + .long 0x6a35355f + .long 0xae5757f9 + .long 0x69b9b9d0 + .long 0x17868691 + .long 0x99c1c158 + .long 0x3a1d1d27 + .long 0x279e9eb9 + .long 0xd9e1e138 + .long 0xebf8f813 + .long 0x2b9898b3 + .long 0x22111133 + .long 0xd26969bb + .long 0xa9d9d970 + .long 0x78e8e89 + .long 0x339494a7 + .long 0x2d9b9bb6 + .long 0x3c1e1e22 + .long 0x15878792 + .long 0xc9e9e920 + .long 0x87cece49 + .long 0xaa5555ff + .long 0x50282878 + .long 0xa5dfdf7a + .long 0x38c8c8f + .long 0x59a1a1f8 + .long 0x9898980 + .long 0x1a0d0d17 + .long 0x65bfbfda + .long 0xd7e6e631 + .long 0x844242c6 + .long 0xd06868b8 + .long 0x824141c3 + .long 0x299999b0 + .long 0x5a2d2d77 + .long 0x1e0f0f11 + .long 0x7bb0b0cb + .long 0xa85454fc + .long 0x6dbbbbd6 + .long 0x2c16163a + .long 0xa5c66363 + .long 0x84f87c7c + .long 0x99ee7777 + .long 0x8df67b7b + .long 0xdfff2f2 + .long 0xbdd66b6b + .long 0xb1de6f6f + .long 0x5491c5c5 + .long 0x50603030 + .long 0x3020101 + .long 0xa9ce6767 + .long 0x7d562b2b + .long 0x19e7fefe + .long 0x62b5d7d7 + .long 0xe64dabab + .long 0x9aec7676 + .long 0x458fcaca + .long 0x9d1f8282 + .long 0x4089c9c9 + .long 0x87fa7d7d + .long 0x15effafa + .long 0xebb25959 + .long 0xc98e4747 + .long 0xbfbf0f0 + .long 0xec41adad + .long 0x67b3d4d4 + .long 0xfd5fa2a2 + .long 0xea45afaf + .long 0xbf239c9c + .long 0xf753a4a4 + .long 0x96e47272 + .long 0x5b9bc0c0 + .long 0xc275b7b7 + .long 0x1ce1fdfd + .long 0xae3d9393 + .long 0x6a4c2626 + .long 0x5a6c3636 + .long 0x417e3f3f + .long 0x2f5f7f7 + .long 0x4f83cccc + .long 0x5c683434 + .long 0xf451a5a5 + .long 0x34d1e5e5 + .long 0x8f9f1f1 + .long 0x93e27171 + .long 0x73abd8d8 + .long 0x53623131 + .long 0x3f2a1515 + .long 0xc080404 + .long 0x5295c7c7 + .long 0x65462323 + .long 0x5e9dc3c3 + .long 0x28301818 + .long 0xa1379696 + .long 0xf0a0505 + .long 0xb52f9a9a + .long 0x90e0707 + .long 0x36241212 + .long 0x9b1b8080 + .long 0x3ddfe2e2 + .long 0x26cdebeb + .long 0x694e2727 + .long 0xcd7fb2b2 + .long 0x9fea7575 + .long 0x1b120909 + .long 0x9e1d8383 + .long 0x74582c2c + .long 0x2e341a1a + .long 0x2d361b1b + .long 0xb2dc6e6e + .long 0xeeb45a5a + .long 0xfb5ba0a0 + .long 0xf6a45252 + .long 0x4d763b3b + .long 0x61b7d6d6 + .long 0xce7db3b3 + .long 0x7b522929 + .long 0x3edde3e3 + .long 0x715e2f2f + .long 0x97138484 + .long 0xf5a65353 + .long 0x68b9d1d1 + .long 0x0 + .long 0x2cc1eded + .long 0x60402020 + .long 0x1fe3fcfc + .long 0xc879b1b1 + .long 0xedb65b5b + .long 0xbed46a6a + .long 0x468dcbcb + .long 0xd967bebe + .long 0x4b723939 + .long 0xde944a4a + .long 0xd4984c4c + .long 0xe8b05858 + .long 0x4a85cfcf + .long 0x6bbbd0d0 + .long 0x2ac5efef + .long 0xe54faaaa + .long 0x16edfbfb + .long 0xc5864343 + .long 0xd79a4d4d + .long 0x55663333 + .long 0x94118585 + .long 0xcf8a4545 + .long 0x10e9f9f9 + .long 0x6040202 + .long 0x81fe7f7f + .long 0xf0a05050 + .long 0x44783c3c + .long 0xba259f9f + .long 0xe34ba8a8 + .long 0xf3a25151 + .long 0xfe5da3a3 + .long 0xc0804040 + .long 0x8a058f8f + .long 0xad3f9292 + .long 0xbc219d9d + .long 0x48703838 + .long 0x4f1f5f5 + .long 0xdf63bcbc + .long 0xc177b6b6 + .long 0x75afdada + .long 0x63422121 + .long 0x30201010 + .long 0x1ae5ffff + .long 0xefdf3f3 + .long 0x6dbfd2d2 + .long 0x4c81cdcd + .long 0x14180c0c + .long 0x35261313 + .long 0x2fc3ecec + .long 0xe1be5f5f + .long 0xa2359797 + .long 0xcc884444 + .long 0x392e1717 + .long 0x5793c4c4 + .long 0xf255a7a7 + .long 0x82fc7e7e + .long 0x477a3d3d + .long 0xacc86464 + .long 0xe7ba5d5d + .long 0x2b321919 + .long 0x95e67373 + .long 0xa0c06060 + .long 0x98198181 + .long 0xd19e4f4f + .long 0x7fa3dcdc + .long 0x66442222 + .long 0x7e542a2a + .long 0xab3b9090 + .long 0x830b8888 + .long 0xca8c4646 + .long 0x29c7eeee + .long 0xd36bb8b8 + .long 0x3c281414 + .long 0x79a7dede + .long 0xe2bc5e5e + .long 0x1d160b0b + .long 0x76addbdb + .long 0x3bdbe0e0 + .long 0x56643232 + .long 0x4e743a3a + .long 0x1e140a0a + .long 0xdb924949 + .long 0xa0c0606 + .long 0x6c482424 + .long 0xe4b85c5c + .long 0x5d9fc2c2 + .long 0x6ebdd3d3 + .long 0xef43acac + .long 0xa6c46262 + .long 0xa8399191 + .long 0xa4319595 + .long 0x37d3e4e4 + .long 0x8bf27979 + .long 0x32d5e7e7 + .long 0x438bc8c8 + .long 0x596e3737 + .long 0xb7da6d6d + .long 0x8c018d8d + .long 0x64b1d5d5 + .long 0xd29c4e4e + .long 0xe049a9a9 + .long 0xb4d86c6c + .long 0xfaac5656 + .long 0x7f3f4f4 + .long 0x25cfeaea + .long 0xafca6565 + .long 0x8ef47a7a + .long 0xe947aeae + .long 0x18100808 + .long 0xd56fbaba + .long 0x88f07878 + .long 0x6f4a2525 + .long 0x725c2e2e + .long 0x24381c1c + .long 0xf157a6a6 + .long 0xc773b4b4 + .long 0x5197c6c6 + .long 0x23cbe8e8 + .long 0x7ca1dddd + .long 0x9ce87474 + .long 0x213e1f1f + .long 0xdd964b4b + .long 0xdc61bdbd + .long 0x860d8b8b + .long 0x850f8a8a + .long 0x90e07070 + .long 0x427c3e3e + .long 0xc471b5b5 + .long 0xaacc6666 + .long 0xd8904848 + .long 0x5060303 + .long 0x1f7f6f6 + .long 0x121c0e0e + .long 0xa3c26161 + .long 0x5f6a3535 + .long 0xf9ae5757 + .long 0xd069b9b9 + .long 0x91178686 + .long 0x5899c1c1 + .long 0x273a1d1d + .long 0xb9279e9e + .long 0x38d9e1e1 + .long 0x13ebf8f8 + .long 0xb32b9898 + .long 0x33221111 + .long 0xbbd26969 + .long 0x70a9d9d9 + .long 0x89078e8e + .long 0xa7339494 + .long 0xb62d9b9b + .long 0x223c1e1e + .long 0x92158787 + .long 0x20c9e9e9 + .long 0x4987cece + .long 0xffaa5555 + .long 0x78502828 + .long 0x7aa5dfdf + .long 0x8f038c8c + .long 0xf859a1a1 + .long 0x80098989 + .long 0x171a0d0d + .long 0xda65bfbf + .long 0x31d7e6e6 + .long 0xc6844242 + .long 0xb8d06868 + .long 0xc3824141 + .long 0xb0299999 + .long 0x775a2d2d + .long 0x111e0f0f + .long 0xcb7bb0b0 + .long 0xfca85454 + .long 0xd66dbbbb + .long 0x3a2c1616 + .long 0x63a5c663 + .long 0x7c84f87c + .long 0x7799ee77 + .long 0x7b8df67b + .long 0xf20dfff2 + .long 0x6bbdd66b + .long 0x6fb1de6f + .long 0xc55491c5 + .long 0x30506030 + .long 0x1030201 + .long 0x67a9ce67 + .long 0x2b7d562b + .long 0xfe19e7fe + .long 0xd762b5d7 + .long 0xabe64dab + .long 0x769aec76 + .long 0xca458fca + .long 0x829d1f82 + .long 0xc94089c9 + .long 0x7d87fa7d + .long 0xfa15effa + .long 0x59ebb259 + .long 0x47c98e47 + .long 0xf00bfbf0 + .long 0xadec41ad + .long 0xd467b3d4 + .long 0xa2fd5fa2 + .long 0xafea45af + .long 0x9cbf239c + .long 0xa4f753a4 + .long 0x7296e472 + .long 0xc05b9bc0 + .long 0xb7c275b7 + .long 0xfd1ce1fd + .long 0x93ae3d93 + .long 0x266a4c26 + .long 0x365a6c36 + .long 0x3f417e3f + .long 0xf702f5f7 + .long 0xcc4f83cc + .long 0x345c6834 + .long 0xa5f451a5 + .long 0xe534d1e5 + .long 0xf108f9f1 + .long 0x7193e271 + .long 0xd873abd8 + .long 0x31536231 + .long 0x153f2a15 + .long 0x40c0804 + .long 0xc75295c7 + .long 0x23654623 + .long 0xc35e9dc3 + .long 0x18283018 + .long 0x96a13796 + .long 0x50f0a05 + .long 0x9ab52f9a + .long 0x7090e07 + .long 0x12362412 + .long 0x809b1b80 + .long 0xe23ddfe2 + .long 0xeb26cdeb + .long 0x27694e27 + .long 0xb2cd7fb2 + .long 0x759fea75 + .long 0x91b1209 + .long 0x839e1d83 + .long 0x2c74582c + .long 0x1a2e341a + .long 0x1b2d361b + .long 0x6eb2dc6e + .long 0x5aeeb45a + .long 0xa0fb5ba0 + .long 0x52f6a452 + .long 0x3b4d763b + .long 0xd661b7d6 + .long 0xb3ce7db3 + .long 0x297b5229 + .long 0xe33edde3 + .long 0x2f715e2f + .long 0x84971384 + .long 0x53f5a653 + .long 0xd168b9d1 + .long 0x0 + .long 0xed2cc1ed + .long 0x20604020 + .long 0xfc1fe3fc + .long 0xb1c879b1 + .long 0x5bedb65b + .long 0x6abed46a + .long 0xcb468dcb + .long 0xbed967be + .long 0x394b7239 + .long 0x4ade944a + .long 0x4cd4984c + .long 0x58e8b058 + .long 0xcf4a85cf + .long 0xd06bbbd0 + .long 0xef2ac5ef + .long 0xaae54faa + .long 0xfb16edfb + .long 0x43c58643 + .long 0x4dd79a4d + .long 0x33556633 + .long 0x85941185 + .long 0x45cf8a45 + .long 0xf910e9f9 + .long 0x2060402 + .long 0x7f81fe7f + .long 0x50f0a050 + .long 0x3c44783c + .long 0x9fba259f + .long 0xa8e34ba8 + .long 0x51f3a251 + .long 0xa3fe5da3 + .long 0x40c08040 + .long 0x8f8a058f + .long 0x92ad3f92 + .long 0x9dbc219d + .long 0x38487038 + .long 0xf504f1f5 + .long 0xbcdf63bc + .long 0xb6c177b6 + .long 0xda75afda + .long 0x21634221 + .long 0x10302010 + .long 0xff1ae5ff + .long 0xf30efdf3 + .long 0xd26dbfd2 + .long 0xcd4c81cd + .long 0xc14180c + .long 0x13352613 + .long 0xec2fc3ec + .long 0x5fe1be5f + .long 0x97a23597 + .long 0x44cc8844 + .long 0x17392e17 + .long 0xc45793c4 + .long 0xa7f255a7 + .long 0x7e82fc7e + .long 0x3d477a3d + .long 0x64acc864 + .long 0x5de7ba5d + .long 0x192b3219 + .long 0x7395e673 + .long 0x60a0c060 + .long 0x81981981 + .long 0x4fd19e4f + .long 0xdc7fa3dc + .long 0x22664422 + .long 0x2a7e542a + .long 0x90ab3b90 + .long 0x88830b88 + .long 0x46ca8c46 + .long 0xee29c7ee + .long 0xb8d36bb8 + .long 0x143c2814 + .long 0xde79a7de + .long 0x5ee2bc5e + .long 0xb1d160b + .long 0xdb76addb + .long 0xe03bdbe0 + .long 0x32566432 + .long 0x3a4e743a + .long 0xa1e140a + .long 0x49db9249 + .long 0x60a0c06 + .long 0x246c4824 + .long 0x5ce4b85c + .long 0xc25d9fc2 + .long 0xd36ebdd3 + .long 0xacef43ac + .long 0x62a6c462 + .long 0x91a83991 + .long 0x95a43195 + .long 0xe437d3e4 + .long 0x798bf279 + .long 0xe732d5e7 + .long 0xc8438bc8 + .long 0x37596e37 + .long 0x6db7da6d + .long 0x8d8c018d + .long 0xd564b1d5 + .long 0x4ed29c4e + .long 0xa9e049a9 + .long 0x6cb4d86c + .long 0x56faac56 + .long 0xf407f3f4 + .long 0xea25cfea + .long 0x65afca65 + .long 0x7a8ef47a + .long 0xaee947ae + .long 0x8181008 + .long 0xbad56fba + .long 0x7888f078 + .long 0x256f4a25 + .long 0x2e725c2e + .long 0x1c24381c + .long 0xa6f157a6 + .long 0xb4c773b4 + .long 0xc65197c6 + .long 0xe823cbe8 + .long 0xdd7ca1dd + .long 0x749ce874 + .long 0x1f213e1f + .long 0x4bdd964b + .long 0xbddc61bd + .long 0x8b860d8b + .long 0x8a850f8a + .long 0x7090e070 + .long 0x3e427c3e + .long 0xb5c471b5 + .long 0x66aacc66 + .long 0x48d89048 + .long 0x3050603 + .long 0xf601f7f6 + .long 0xe121c0e + .long 0x61a3c261 + .long 0x355f6a35 + .long 0x57f9ae57 + .long 0xb9d069b9 + .long 0x86911786 + .long 0xc15899c1 + .long 0x1d273a1d + .long 0x9eb9279e + .long 0xe138d9e1 + .long 0xf813ebf8 + .long 0x98b32b98 + .long 0x11332211 + .long 0x69bbd269 + .long 0xd970a9d9 + .long 0x8e89078e + .long 0x94a73394 + .long 0x9bb62d9b + .long 0x1e223c1e + .long 0x87921587 + .long 0xe920c9e9 + .long 0xce4987ce + .long 0x55ffaa55 + .long 0x28785028 + .long 0xdf7aa5df + .long 0x8c8f038c + .long 0xa1f859a1 + .long 0x89800989 + .long 0xd171a0d + .long 0xbfda65bf + .long 0xe631d7e6 + .long 0x42c68442 + .long 0x68b8d068 + .long 0x41c38241 + .long 0x99b02999 + .long 0x2d775a2d + .long 0xf111e0f + .long 0xb0cb7bb0 + .long 0x54fca854 + .long 0xbbd66dbb + .long 0x163a2c16 + .long 0x6363a5c6 + .long 0x7c7c84f8 + .long 0x777799ee + .long 0x7b7b8df6 + .long 0xf2f20dff + .long 0x6b6bbdd6 + .long 0x6f6fb1de + .long 0xc5c55491 + .long 0x30305060 + .long 0x1010302 + .long 0x6767a9ce + .long 0x2b2b7d56 + .long 0xfefe19e7 + .long 0xd7d762b5 + .long 0xababe64d + .long 0x76769aec + .long 0xcaca458f + .long 0x82829d1f + .long 0xc9c94089 + .long 0x7d7d87fa + .long 0xfafa15ef + .long 0x5959ebb2 + .long 0x4747c98e + .long 0xf0f00bfb + .long 0xadadec41 + .long 0xd4d467b3 + .long 0xa2a2fd5f + .long 0xafafea45 + .long 0x9c9cbf23 + .long 0xa4a4f753 + .long 0x727296e4 + .long 0xc0c05b9b + .long 0xb7b7c275 + .long 0xfdfd1ce1 + .long 0x9393ae3d + .long 0x26266a4c + .long 0x36365a6c + .long 0x3f3f417e + .long 0xf7f702f5 + .long 0xcccc4f83 + .long 0x34345c68 + .long 0xa5a5f451 + .long 0xe5e534d1 + .long 0xf1f108f9 + .long 0x717193e2 + .long 0xd8d873ab + .long 0x31315362 + .long 0x15153f2a + .long 0x4040c08 + .long 0xc7c75295 + .long 0x23236546 + .long 0xc3c35e9d + .long 0x18182830 + .long 0x9696a137 + .long 0x5050f0a + .long 0x9a9ab52f + .long 0x707090e + .long 0x12123624 + .long 0x80809b1b + .long 0xe2e23ddf + .long 0xebeb26cd + .long 0x2727694e + .long 0xb2b2cd7f + .long 0x75759fea + .long 0x9091b12 + .long 0x83839e1d + .long 0x2c2c7458 + .long 0x1a1a2e34 + .long 0x1b1b2d36 + .long 0x6e6eb2dc + .long 0x5a5aeeb4 + .long 0xa0a0fb5b + .long 0x5252f6a4 + .long 0x3b3b4d76 + .long 0xd6d661b7 + .long 0xb3b3ce7d + .long 0x29297b52 + .long 0xe3e33edd + .long 0x2f2f715e + .long 0x84849713 + .long 0x5353f5a6 + .long 0xd1d168b9 + .long 0x0 + .long 0xeded2cc1 + .long 0x20206040 + .long 0xfcfc1fe3 + .long 0xb1b1c879 + .long 0x5b5bedb6 + .long 0x6a6abed4 + .long 0xcbcb468d + .long 0xbebed967 + .long 0x39394b72 + .long 0x4a4ade94 + .long 0x4c4cd498 + .long 0x5858e8b0 + .long 0xcfcf4a85 + .long 0xd0d06bbb + .long 0xefef2ac5 + .long 0xaaaae54f + .long 0xfbfb16ed + .long 0x4343c586 + .long 0x4d4dd79a + .long 0x33335566 + .long 0x85859411 + .long 0x4545cf8a + .long 0xf9f910e9 + .long 0x2020604 + .long 0x7f7f81fe + .long 0x5050f0a0 + .long 0x3c3c4478 + .long 0x9f9fba25 + .long 0xa8a8e34b + .long 0x5151f3a2 + .long 0xa3a3fe5d + .long 0x4040c080 + .long 0x8f8f8a05 + .long 0x9292ad3f + .long 0x9d9dbc21 + .long 0x38384870 + .long 0xf5f504f1 + .long 0xbcbcdf63 + .long 0xb6b6c177 + .long 0xdada75af + .long 0x21216342 + .long 0x10103020 + .long 0xffff1ae5 + .long 0xf3f30efd + .long 0xd2d26dbf + .long 0xcdcd4c81 + .long 0xc0c1418 + .long 0x13133526 + .long 0xecec2fc3 + .long 0x5f5fe1be + .long 0x9797a235 + .long 0x4444cc88 + .long 0x1717392e + .long 0xc4c45793 + .long 0xa7a7f255 + .long 0x7e7e82fc + .long 0x3d3d477a + .long 0x6464acc8 + .long 0x5d5de7ba + .long 0x19192b32 + .long 0x737395e6 + .long 0x6060a0c0 + .long 0x81819819 + .long 0x4f4fd19e + .long 0xdcdc7fa3 + .long 0x22226644 + .long 0x2a2a7e54 + .long 0x9090ab3b + .long 0x8888830b + .long 0x4646ca8c + .long 0xeeee29c7 + .long 0xb8b8d36b + .long 0x14143c28 + .long 0xdede79a7 + .long 0x5e5ee2bc + .long 0xb0b1d16 + .long 0xdbdb76ad + .long 0xe0e03bdb + .long 0x32325664 + .long 0x3a3a4e74 + .long 0xa0a1e14 + .long 0x4949db92 + .long 0x6060a0c + .long 0x24246c48 + .long 0x5c5ce4b8 + .long 0xc2c25d9f + .long 0xd3d36ebd + .long 0xacacef43 + .long 0x6262a6c4 + .long 0x9191a839 + .long 0x9595a431 + .long 0xe4e437d3 + .long 0x79798bf2 + .long 0xe7e732d5 + .long 0xc8c8438b + .long 0x3737596e + .long 0x6d6db7da + .long 0x8d8d8c01 + .long 0xd5d564b1 + .long 0x4e4ed29c + .long 0xa9a9e049 + .long 0x6c6cb4d8 + .long 0x5656faac + .long 0xf4f407f3 + .long 0xeaea25cf + .long 0x6565afca + .long 0x7a7a8ef4 + .long 0xaeaee947 + .long 0x8081810 + .long 0xbabad56f + .long 0x787888f0 + .long 0x25256f4a + .long 0x2e2e725c + .long 0x1c1c2438 + .long 0xa6a6f157 + .long 0xb4b4c773 + .long 0xc6c65197 + .long 0xe8e823cb + .long 0xdddd7ca1 + .long 0x74749ce8 + .long 0x1f1f213e + .long 0x4b4bdd96 + .long 0xbdbddc61 + .long 0x8b8b860d + .long 0x8a8a850f + .long 0x707090e0 + .long 0x3e3e427c + .long 0xb5b5c471 + .long 0x6666aacc + .long 0x4848d890 + .long 0x3030506 + .long 0xf6f601f7 + .long 0xe0e121c + .long 0x6161a3c2 + .long 0x35355f6a + .long 0x5757f9ae + .long 0xb9b9d069 + .long 0x86869117 + .long 0xc1c15899 + .long 0x1d1d273a + .long 0x9e9eb927 + .long 0xe1e138d9 + .long 0xf8f813eb + .long 0x9898b32b + .long 0x11113322 + .long 0x6969bbd2 + .long 0xd9d970a9 + .long 0x8e8e8907 + .long 0x9494a733 + .long 0x9b9bb62d + .long 0x1e1e223c + .long 0x87879215 + .long 0xe9e920c9 + .long 0xcece4987 + .long 0x5555ffaa + .long 0x28287850 + .long 0xdfdf7aa5 + .long 0x8c8c8f03 + .long 0xa1a1f859 + .long 0x89898009 + .long 0xd0d171a + .long 0xbfbfda65 + .long 0xe6e631d7 + .long 0x4242c684 + .long 0x6868b8d0 + .long 0x4141c382 + .long 0x9999b029 + .long 0x2d2d775a + .long 0xf0f111e + .long 0xb0b0cb7b + .long 0x5454fca8 + .long 0xbbbbd66d + .long 0x16163a2c +#if defined(HAVE_AESCCM) || defined(HAVE_AESGCM) || \ + defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || \ + defined(HAVE_AES_ECB) +#ifndef __APPLE__ +.text +.globl AES_ECB_encrypt +.type AES_ECB_encrypt,@function +.align 16 +AES_ECB_encrypt: +#else +.section __TEXT,__text +.globl _AES_ECB_encrypt +.p2align 4 +_AES_ECB_encrypt: +#endif /* __APPLE__ */ + stdu 1, -104(1) + mflr 0 + std 0, 96(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 8, 2, L_AES_PPC64_te4_0@toc@ha + addi 8, 8, L_AES_PPC64_te4_0@toc@l +#else + lis 8, L_AES_PPC64_te4_0@ha + la 8, L_AES_PPC64_te4_0@l(8) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 9, 8, 0x400 + addi 10, 8, 0x800 + addi 11, 8, 0xc00 +L_AES_ECB_encrypt_loop_block_128: + addi 25, 6, 0 + ld 12, 0(3) + ld 14, 8(3) + ld 17, 0(25) + ld 18, 8(25) + addi 25, 25, 16 + rldicr 12, 12, 32, 63 + rldicr 14, 14, 32, 63 + # Round: 0 - XOR in key schedule + xor 12, 12, 17 + xor 14, 14, 18 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 20, 0(8) + ld 20, 64(8) + ld 20, 128(8) + ld 20, 192(8) + ld 20, 256(8) + ld 20, 320(8) + ld 20, 384(8) + ld 20, 448(8) + ld 20, 512(8) + ld 20, 576(8) + ld 20, 640(8) + ld 20, 704(8) + ld 20, 768(8) + ld 20, 832(8) + ld 20, 896(8) + ld 20, 960(8) + ld 20, 1024(8) + ld 20, 1088(8) + ld 20, 1152(8) + ld 20, 1216(8) + ld 20, 1280(8) + ld 20, 1344(8) + ld 20, 1408(8) + ld 20, 1472(8) + ld 20, 1536(8) + ld 20, 1600(8) + ld 20, 1664(8) + ld 20, 1728(8) + ld 20, 1792(8) + ld 20, 1856(8) + ld 20, 1920(8) + ld 20, 1984(8) + ld 20, 2048(8) + ld 20, 2112(8) + ld 20, 2176(8) + ld 20, 2240(8) + ld 20, 2304(8) + ld 20, 2368(8) + ld 20, 2432(8) + ld 20, 2496(8) + ld 20, 2560(8) + ld 20, 2624(8) + ld 20, 2688(8) + ld 20, 2752(8) + ld 20, 2816(8) + ld 20, 2880(8) + ld 20, 2944(8) + ld 20, 3008(8) + ld 20, 3072(8) + ld 20, 3136(8) + ld 20, 3200(8) + ld 20, 3264(8) + ld 20, 3328(8) + ld 20, 3392(8) + ld 20, 3456(8) + ld 20, 3520(8) + ld 20, 3584(8) + ld 20, 3648(8) + ld 20, 3712(8) + ld 20, 3776(8) + ld 20, 3840(8) + ld 20, 3904(8) + ld 20, 3968(8) + ld 20, 4032(8) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_ECB_encrypt_loop_nr: + srdi 15, 12, 32 + srdi 16, 14, 32 + rlwinm 17, 12, 10, 22, 29 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + lwzx 17, 8, 17 + lwzx 18, 8, 18 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + rlwinm 21, 15, 18, 22, 29 + rlwinm 22, 14, 18, 22, 29 + rlwinm 23, 16, 18, 22, 29 + rlwinm 24, 12, 18, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + rlwinm 21, 14, 26, 22, 29 + rlwinm 22, 16, 26, 22, 29 + rlwinm 23, 12, 26, 22, 29 + rlwinm 24, 15, 26, 22, 29 + lwzx 21, 10, 21 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + rlwinm 21, 16, 2, 22, 29 + rlwinm 22, 12, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 14, 2, 22, 29 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + ld 12, 0(25) + ld 14, 8(25) + rldimi 17, 19, 32, 0 + rldimi 18, 20, 32, 0 + addi 25, 25, 16 + # XOR in Key Schedule + xor 17, 17, 12 + xor 18, 18, 14 + srdi 19, 17, 32 + srdi 20, 18, 32 + rlwinm 12, 17, 10, 22, 29 + rlwinm 14, 18, 10, 22, 29 + rlwinm 15, 19, 10, 22, 29 + rlwinm 16, 20, 10, 22, 29 + lwzx 12, 8, 12 + lwzx 14, 8, 14 + lwzx 15, 8, 15 + lwzx 16, 8, 16 + rlwinm 21, 19, 18, 22, 29 + rlwinm 22, 18, 18, 22, 29 + rlwinm 23, 20, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + xor 12, 12, 21 + xor 15, 15, 22 + xor 14, 14, 23 + xor 16, 16, 24 + rlwinm 21, 18, 26, 22, 29 + rlwinm 22, 20, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 19, 26, 22, 29 + lwzx 21, 10, 21 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + xor 12, 12, 21 + xor 15, 15, 22 + xor 14, 14, 23 + xor 16, 16, 24 + rlwinm 21, 20, 2, 22, 29 + rlwinm 22, 17, 2, 22, 29 + rlwinm 23, 19, 2, 22, 29 + rlwinm 24, 18, 2, 22, 29 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + xor 12, 12, 21 + xor 15, 15, 22 + xor 14, 14, 23 + xor 16, 16, 24 + ld 17, 0(25) + ld 18, 8(25) + rldimi 12, 15, 32, 0 + rldimi 14, 16, 32, 0 + addi 25, 25, 16 + # XOR in Key Schedule + xor 12, 12, 17 + xor 14, 14, 18 + bdnz L_AES_ECB_encrypt_loop_nr + srdi 15, 12, 32 + srdi 16, 14, 32 + rlwinm 17, 12, 10, 22, 29 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + lwzx 17, 8, 17 + lwzx 18, 8, 18 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + rlwinm 21, 15, 18, 22, 29 + rlwinm 22, 14, 18, 22, 29 + rlwinm 23, 16, 18, 22, 29 + rlwinm 24, 12, 18, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + rlwinm 21, 14, 26, 22, 29 + rlwinm 22, 16, 26, 22, 29 + rlwinm 23, 12, 26, 22, 29 + rlwinm 24, 15, 26, 22, 29 + lwzx 21, 10, 21 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + rlwinm 21, 16, 2, 22, 29 + rlwinm 22, 12, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 14, 2, 22, 29 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + xor 17, 17, 21 + xor 19, 19, 22 + xor 18, 18, 23 + xor 20, 20, 24 + ld 12, 0(25) + ld 14, 8(25) + rldimi 17, 19, 32, 0 + rldimi 18, 20, 32, 0 + addi 25, 25, 16 + # XOR in Key Schedule + xor 17, 17, 12 + xor 18, 18, 14 + srdi 19, 17, 32 + srdi 20, 18, 32 + rlwinm 12, 17, 2, 22, 29 + rlwinm 14, 18, 2, 22, 29 + rlwinm 16, 19, 2, 22, 29 + rlwinm 15, 20, 2, 22, 29 + lwzx 12, 9, 12 + lwzx 14, 9, 14 + lwzx 16, 9, 16 + lwzx 15, 9, 15 + rlwinm 21, 18, 26, 22, 29 + rlwinm 22, 20, 26, 22, 29 + rldimi 14, 16, 32, 24 + rldimi 12, 15, 32, 24 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 19, 26, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + rldimi 12, 21, 40, 16 + rlwimi 12, 22, 8, 16, 23 + rldimi 14, 23, 40, 16 + rlwimi 14, 24, 8, 16, 23 + rlwinm 21, 19, 18, 22, 29 + rlwinm 22, 18, 18, 22, 29 + rlwinm 23, 20, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + rldimi 12, 21, 48, 8 + rlwimi 12, 22, 16, 8, 15 + rldimi 14, 23, 48, 8 + rlwimi 14, 24, 16, 8, 15 + rlwinm 21, 17, 10, 22, 29 + rlwinm 22, 19, 10, 22, 29 + rlwinm 23, 18, 10, 22, 29 + rlwinm 24, 20, 10, 22, 29 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + lwzx 24, 9, 24 + ld 17, 0(25) + ld 18, 8(25) + rldimi 12, 21, 56, 0 + rlwimi 12, 22, 24, 0, 7 + rldimi 14, 23, 56, 0 + rlwimi 14, 24, 24, 0, 7 + addi 25, 25, 16 + # XOR in Key Schedule + xor 12, 12, 17 + xor 14, 14, 18 + std 12, 0(4) + std 14, 8(4) + addi 3, 3, 16 + addi 4, 4, 16 + addic. 5, 5, -16 + bne L_AES_ECB_encrypt_loop_block_128 + ld 0, 96(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + addi 1, 1, 0x68 + blr +#ifndef __APPLE__ + .size AES_ECB_encrypt,.-AES_ECB_encrypt +#endif /* __APPLE__ */ +#endif /* HAVE_AESCCM || HAVE_AESGCM || WOLFSSL_AES_DIRECT || + * WOLFSSL_AES_COUNTER || HAVE_AES_ECB */ +#ifdef HAVE_AES_CBC +#ifndef __APPLE__ +.text +.globl AES_CBC_encrypt +.type AES_CBC_encrypt,@function +.align 16 +AES_CBC_encrypt: +#else +.section __TEXT,__text +.globl _AES_CBC_encrypt +.p2align 4 +_AES_CBC_encrypt: +#endif /* __APPLE__ */ + stdu 1, -112(1) + mflr 0 + std 0, 104(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 9, 2, L_AES_PPC64_te4_0@toc@ha + addi 9, 9, L_AES_PPC64_te4_0@toc@l +#else + lis 9, L_AES_PPC64_te4_0@ha + la 9, L_AES_PPC64_te4_0@l(9) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + ld 14, 0(8) + ld 15, 8(8) + addi 10, 9, 0x400 + addi 11, 9, 0x800 + addi 12, 9, 0xc00 +L_AES_CBC_encrypt_loop_block: + addi 26, 6, 0 + ld 18, 0(3) + ld 19, 8(3) + xor 14, 14, 18 + xor 15, 15, 19 + ld 18, 0(26) + ld 19, 8(26) + addi 26, 26, 16 + rldicr 14, 14, 32, 63 + rldicr 15, 15, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(9) + ld 21, 64(9) + ld 21, 128(9) + ld 21, 192(9) + ld 21, 256(9) + ld 21, 320(9) + ld 21, 384(9) + ld 21, 448(9) + ld 21, 512(9) + ld 21, 576(9) + ld 21, 640(9) + ld 21, 704(9) + ld 21, 768(9) + ld 21, 832(9) + ld 21, 896(9) + ld 21, 960(9) + ld 21, 1024(9) + ld 21, 1088(9) + ld 21, 1152(9) + ld 21, 1216(9) + ld 21, 1280(9) + ld 21, 1344(9) + ld 21, 1408(9) + ld 21, 1472(9) + ld 21, 1536(9) + ld 21, 1600(9) + ld 21, 1664(9) + ld 21, 1728(9) + ld 21, 1792(9) + ld 21, 1856(9) + ld 21, 1920(9) + ld 21, 1984(9) + ld 21, 2048(9) + ld 21, 2112(9) + ld 21, 2176(9) + ld 21, 2240(9) + ld 21, 2304(9) + ld 21, 2368(9) + ld 21, 2432(9) + ld 21, 2496(9) + ld 21, 2560(9) + ld 21, 2624(9) + ld 21, 2688(9) + ld 21, 2752(9) + ld 21, 2816(9) + ld 21, 2880(9) + ld 21, 2944(9) + ld 21, 3008(9) + ld 21, 3072(9) + ld 21, 3136(9) + ld 21, 3200(9) + ld 21, 3264(9) + ld 21, 3328(9) + ld 21, 3392(9) + ld 21, 3456(9) + ld 21, 3520(9) + ld 21, 3584(9) + ld 21, 3648(9) + ld 21, 3712(9) + ld 21, 3776(9) + ld 21, 3840(9) + ld 21, 3904(9) + ld 21, 3968(9) + ld 21, 4032(9) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_CBC_encrypt_loop_nr: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 22, 16, 18, 22, 29 + rlwinm 23, 15, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + rlwinm 25, 14, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 17, 2, 22, 29 + rlwinm 23, 14, 2, 22, 29 + rlwinm 24, 16, 2, 22, 29 + rlwinm 25, 15, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 14, 0(26) + ld 15, 8(26) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 26, 26, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 10, 22, 29 + rlwinm 15, 19, 10, 22, 29 + rlwinm 16, 20, 10, 22, 29 + rlwinm 17, 21, 10, 22, 29 + lwzx 14, 9, 14 + lwzx 15, 9, 15 + lwzx 16, 9, 16 + lwzx 17, 9, 17 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 21, 2, 22, 29 + rlwinm 23, 18, 2, 22, 29 + rlwinm 24, 20, 2, 22, 29 + rlwinm 25, 19, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + ld 18, 0(26) + ld 19, 8(26) + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + addi 26, 26, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_CBC_encrypt_loop_nr + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 22, 16, 18, 22, 29 + rlwinm 23, 15, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + rlwinm 25, 14, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 17, 2, 22, 29 + rlwinm 23, 14, 2, 22, 29 + rlwinm 24, 16, 2, 22, 29 + rlwinm 25, 15, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 14, 0(26) + ld 15, 8(26) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 26, 26, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 2, 22, 29 + rlwinm 15, 19, 2, 22, 29 + rlwinm 17, 20, 2, 22, 29 + rlwinm 16, 21, 2, 22, 29 + lwzx 14, 10, 14 + lwzx 15, 10, 15 + lwzx 17, 10, 17 + lwzx 16, 10, 16 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rldimi 15, 17, 32, 24 + rldimi 14, 16, 32, 24 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + rldimi 14, 22, 40, 16 + rlwimi 14, 23, 8, 16, 23 + rldimi 15, 24, 40, 16 + rlwimi 15, 25, 8, 16, 23 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + rldimi 14, 22, 48, 8 + rlwimi 14, 23, 16, 8, 15 + rldimi 15, 24, 48, 8 + rlwimi 15, 25, 16, 8, 15 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + ld 18, 0(26) + ld 19, 8(26) + rldimi 14, 22, 56, 0 + rlwimi 14, 23, 24, 0, 7 + rldimi 15, 24, 56, 0 + rlwimi 15, 25, 24, 0, 7 + addi 26, 26, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + std 14, 0(4) + std 15, 8(4) + addi 3, 3, 16 + addi 4, 4, 16 + addic. 5, 5, -16 + bne L_AES_CBC_encrypt_loop_block + std 14, 0(8) + std 15, 8(8) + ld 0, 104(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + addi 1, 1, 0x70 + blr +#ifndef __APPLE__ + .size AES_CBC_encrypt,.-AES_CBC_encrypt +#endif /* __APPLE__ */ +#endif /* HAVE_AES_CBC */ +#ifdef WOLFSSL_AES_COUNTER +#ifndef __APPLE__ +.text +.globl AES_CTR_encrypt +.type AES_CTR_encrypt,@function +.align 16 +AES_CTR_encrypt: +#else +.section __TEXT,__text +.globl _AES_CTR_encrypt +.p2align 4 +_AES_CTR_encrypt: +#endif /* __APPLE__ */ + stdu 1, -128(1) + mflr 0 + std 0, 120(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) + std 27, 104(1) + std 28, 112(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 9, 2, L_AES_PPC64_te4_0@toc@ha + addi 9, 9, L_AES_PPC64_te4_0@toc@l +#else + lis 9, L_AES_PPC64_te4_0@ha + la 9, L_AES_PPC64_te4_0@l(9) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + ld 22, 0(8) + ld 23, 8(8) + addi 10, 9, 0x400 + addi 11, 9, 0x800 + addi 12, 9, 0xc00 +L_AES_CTR_encrypt_loop_block_128: + addi 28, 6, 0 + ld 18, 0(28) + ld 19, 8(28) + addi 28, 28, 16 + rldicr 14, 22, 32, 63 + rldicr 15, 23, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(9) + ld 21, 64(9) + ld 21, 128(9) + ld 21, 192(9) + ld 21, 256(9) + ld 21, 320(9) + ld 21, 384(9) + ld 21, 448(9) + ld 21, 512(9) + ld 21, 576(9) + ld 21, 640(9) + ld 21, 704(9) + ld 21, 768(9) + ld 21, 832(9) + ld 21, 896(9) + ld 21, 960(9) + ld 21, 1024(9) + ld 21, 1088(9) + ld 21, 1152(9) + ld 21, 1216(9) + ld 21, 1280(9) + ld 21, 1344(9) + ld 21, 1408(9) + ld 21, 1472(9) + ld 21, 1536(9) + ld 21, 1600(9) + ld 21, 1664(9) + ld 21, 1728(9) + ld 21, 1792(9) + ld 21, 1856(9) + ld 21, 1920(9) + ld 21, 1984(9) + ld 21, 2048(9) + ld 21, 2112(9) + ld 21, 2176(9) + ld 21, 2240(9) + ld 21, 2304(9) + ld 21, 2368(9) + ld 21, 2432(9) + ld 21, 2496(9) + ld 21, 2560(9) + ld 21, 2624(9) + ld 21, 2688(9) + ld 21, 2752(9) + ld 21, 2816(9) + ld 21, 2880(9) + ld 21, 2944(9) + ld 21, 3008(9) + ld 21, 3072(9) + ld 21, 3136(9) + ld 21, 3200(9) + ld 21, 3264(9) + ld 21, 3328(9) + ld 21, 3392(9) + ld 21, 3456(9) + ld 21, 3520(9) + ld 21, 3584(9) + ld 21, 3648(9) + ld 21, 3712(9) + ld 21, 3776(9) + ld 21, 3840(9) + ld 21, 3904(9) + ld 21, 3968(9) + ld 21, 4032(9) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_CTR_encrypt_loop_nr: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 24, 16, 18, 22, 29 + rlwinm 25, 15, 18, 22, 29 + rlwinm 26, 17, 18, 22, 29 + rlwinm 27, 14, 18, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + rlwinm 24, 15, 26, 22, 29 + rlwinm 25, 17, 26, 22, 29 + rlwinm 26, 14, 26, 22, 29 + rlwinm 27, 16, 26, 22, 29 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + lwzx 26, 11, 26 + lwzx 27, 11, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + rlwinm 26, 16, 2, 22, 29 + rlwinm 27, 15, 2, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + ld 14, 0(28) + ld 15, 8(28) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 10, 22, 29 + rlwinm 15, 19, 10, 22, 29 + rlwinm 16, 20, 10, 22, 29 + rlwinm 17, 21, 10, 22, 29 + lwzx 14, 9, 14 + lwzx 15, 9, 15 + lwzx 16, 9, 16 + lwzx 17, 9, 17 + rlwinm 24, 20, 18, 22, 29 + rlwinm 25, 19, 18, 22, 29 + rlwinm 26, 21, 18, 22, 29 + rlwinm 27, 18, 18, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + xor 14, 14, 24 + xor 16, 16, 25 + xor 15, 15, 26 + xor 17, 17, 27 + rlwinm 24, 19, 26, 22, 29 + rlwinm 25, 21, 26, 22, 29 + rlwinm 26, 18, 26, 22, 29 + rlwinm 27, 20, 26, 22, 29 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + lwzx 26, 11, 26 + lwzx 27, 11, 27 + xor 14, 14, 24 + xor 16, 16, 25 + xor 15, 15, 26 + xor 17, 17, 27 + rlwinm 24, 21, 2, 22, 29 + rlwinm 25, 18, 2, 22, 29 + rlwinm 26, 20, 2, 22, 29 + rlwinm 27, 19, 2, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 14, 14, 24 + xor 16, 16, 25 + xor 15, 15, 26 + xor 17, 17, 27 + ld 18, 0(28) + ld 19, 8(28) + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_CTR_encrypt_loop_nr + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 24, 16, 18, 22, 29 + rlwinm 25, 15, 18, 22, 29 + rlwinm 26, 17, 18, 22, 29 + rlwinm 27, 14, 18, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + rlwinm 24, 15, 26, 22, 29 + rlwinm 25, 17, 26, 22, 29 + rlwinm 26, 14, 26, 22, 29 + rlwinm 27, 16, 26, 22, 29 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + lwzx 26, 11, 26 + lwzx 27, 11, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + rlwinm 26, 16, 2, 22, 29 + rlwinm 27, 15, 2, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 18, 18, 24 + xor 20, 20, 25 + xor 19, 19, 26 + xor 21, 21, 27 + ld 14, 0(28) + ld 15, 8(28) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 2, 22, 29 + rlwinm 15, 19, 2, 22, 29 + rlwinm 17, 20, 2, 22, 29 + rlwinm 16, 21, 2, 22, 29 + lwzx 14, 10, 14 + lwzx 15, 10, 15 + lwzx 17, 10, 17 + lwzx 16, 10, 16 + rlwinm 24, 19, 26, 22, 29 + rlwinm 25, 21, 26, 22, 29 + rldimi 15, 17, 32, 24 + rldimi 14, 16, 32, 24 + rlwinm 26, 18, 26, 22, 29 + rlwinm 27, 20, 26, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + rldimi 14, 24, 40, 16 + rlwimi 14, 25, 8, 16, 23 + rldimi 15, 26, 40, 16 + rlwimi 15, 27, 8, 16, 23 + rlwinm 24, 20, 18, 22, 29 + rlwinm 25, 19, 18, 22, 29 + rlwinm 26, 21, 18, 22, 29 + rlwinm 27, 18, 18, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + rldimi 14, 24, 48, 8 + rlwimi 14, 25, 16, 8, 15 + rldimi 15, 26, 48, 8 + rlwimi 15, 27, 16, 8, 15 + rlwinm 24, 18, 10, 22, 29 + rlwinm 25, 20, 10, 22, 29 + rlwinm 26, 19, 10, 22, 29 + rlwinm 27, 21, 10, 22, 29 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + lwzx 26, 10, 26 + lwzx 27, 10, 27 + ld 18, 0(28) + ld 19, 8(28) + rldimi 14, 24, 56, 0 + rlwimi 14, 25, 24, 0, 7 + rldimi 15, 26, 56, 0 + rlwimi 15, 27, 24, 0, 7 + addi 28, 28, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + ld 18, 0(3) + ld 19, 8(3) + xor 14, 14, 18 + xor 15, 15, 19 + std 14, 0(4) + std 15, 8(4) + addic 23, 23, 1 + addze 22, 22 + addi 3, 3, 16 + addi 4, 4, 16 + addic. 5, 5, -16 + bne L_AES_CTR_encrypt_loop_block_128 + std 22, 0(8) + std 23, 8(8) + ld 0, 120(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + ld 27, 104(1) + ld 28, 112(1) + addi 1, 1, 0x80 + blr +#ifndef __APPLE__ + .size AES_CTR_encrypt,.-AES_CTR_encrypt +#endif /* __APPLE__ */ +#endif /* WOLFSSL_AES_COUNTER */ +#ifdef HAVE_AESGCM +#ifndef __APPLE__ +.text +.globl AES_GCM_encrypt +.type AES_GCM_encrypt,@function +.align 16 +AES_GCM_encrypt: +#else +.section __TEXT,__text +.globl _AES_GCM_encrypt +.p2align 4 +_AES_GCM_encrypt: +#endif /* __APPLE__ */ + stdu 1, -128(1) + mflr 0 + std 0, 120(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) + std 27, 104(1) + std 28, 112(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 9, 2, L_AES_PPC64_te4_0@toc@ha + addi 9, 9, L_AES_PPC64_te4_0@toc@l +#else + lis 9, L_AES_PPC64_te4_0@ha + la 9, L_AES_PPC64_te4_0@l(9) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + ld 26, 0(8) + ld 27, 8(8) + addi 10, 9, 0x400 + addi 11, 9, 0x800 + addi 12, 9, 0xc00 +L_AES_GCM_encrypt_loop_block: + addi 28, 6, 0 + addi 17, 27, 1 + ld 18, 0(28) + ld 19, 8(28) + addi 28, 28, 16 + rldimi 27, 17, 0, 32 + rldicr 14, 26, 32, 63 + rldicr 15, 27, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(9) + ld 21, 64(9) + ld 21, 128(9) + ld 21, 192(9) + ld 21, 256(9) + ld 21, 320(9) + ld 21, 384(9) + ld 21, 448(9) + ld 21, 512(9) + ld 21, 576(9) + ld 21, 640(9) + ld 21, 704(9) + ld 21, 768(9) + ld 21, 832(9) + ld 21, 896(9) + ld 21, 960(9) + ld 21, 1024(9) + ld 21, 1088(9) + ld 21, 1152(9) + ld 21, 1216(9) + ld 21, 1280(9) + ld 21, 1344(9) + ld 21, 1408(9) + ld 21, 1472(9) + ld 21, 1536(9) + ld 21, 1600(9) + ld 21, 1664(9) + ld 21, 1728(9) + ld 21, 1792(9) + ld 21, 1856(9) + ld 21, 1920(9) + ld 21, 1984(9) + ld 21, 2048(9) + ld 21, 2112(9) + ld 21, 2176(9) + ld 21, 2240(9) + ld 21, 2304(9) + ld 21, 2368(9) + ld 21, 2432(9) + ld 21, 2496(9) + ld 21, 2560(9) + ld 21, 2624(9) + ld 21, 2688(9) + ld 21, 2752(9) + ld 21, 2816(9) + ld 21, 2880(9) + ld 21, 2944(9) + ld 21, 3008(9) + ld 21, 3072(9) + ld 21, 3136(9) + ld 21, 3200(9) + ld 21, 3264(9) + ld 21, 3328(9) + ld 21, 3392(9) + ld 21, 3456(9) + ld 21, 3520(9) + ld 21, 3584(9) + ld 21, 3648(9) + ld 21, 3712(9) + ld 21, 3776(9) + ld 21, 3840(9) + ld 21, 3904(9) + ld 21, 3968(9) + ld 21, 4032(9) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_GCM_encrypt_loop_nr: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 22, 16, 18, 22, 29 + rlwinm 23, 15, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + rlwinm 25, 14, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 17, 2, 22, 29 + rlwinm 23, 14, 2, 22, 29 + rlwinm 24, 16, 2, 22, 29 + rlwinm 25, 15, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 14, 0(28) + ld 15, 8(28) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 10, 22, 29 + rlwinm 15, 19, 10, 22, 29 + rlwinm 16, 20, 10, 22, 29 + rlwinm 17, 21, 10, 22, 29 + lwzx 14, 9, 14 + lwzx 15, 9, 15 + lwzx 16, 9, 16 + lwzx 17, 9, 17 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 21, 2, 22, 29 + rlwinm 23, 18, 2, 22, 29 + rlwinm 24, 20, 2, 22, 29 + rlwinm 25, 19, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + ld 18, 0(28) + ld 19, 8(28) + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_GCM_encrypt_loop_nr + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 14, 10, 22, 29 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + lwzx 18, 9, 18 + lwzx 19, 9, 19 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + rlwinm 22, 16, 18, 22, 29 + rlwinm 23, 15, 18, 22, 29 + rlwinm 24, 17, 18, 22, 29 + rlwinm 25, 14, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 17, 2, 22, 29 + rlwinm 23, 14, 2, 22, 29 + rlwinm 24, 16, 2, 22, 29 + rlwinm 25, 15, 2, 22, 29 + lwzx 22, 12, 22 + lwzx 23, 12, 23 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 14, 0(28) + ld 15, 8(28) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 28, 28, 16 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 18, 2, 22, 29 + rlwinm 15, 19, 2, 22, 29 + rlwinm 17, 20, 2, 22, 29 + rlwinm 16, 21, 2, 22, 29 + lwzx 14, 10, 14 + lwzx 15, 10, 15 + lwzx 17, 10, 17 + lwzx 16, 10, 16 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rldimi 15, 17, 32, 24 + rldimi 14, 16, 32, 24 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + rldimi 14, 22, 40, 16 + rlwimi 14, 23, 8, 16, 23 + rldimi 15, 24, 40, 16 + rlwimi 15, 25, 8, 16, 23 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + rldimi 14, 22, 48, 8 + rlwimi 14, 23, 16, 8, 15 + rldimi 15, 24, 48, 8 + rlwimi 15, 25, 16, 8, 15 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 10, 22 + lwzx 23, 10, 23 + lwzx 24, 10, 24 + lwzx 25, 10, 25 + ld 18, 0(28) + ld 19, 8(28) + rldimi 14, 22, 56, 0 + rlwimi 14, 23, 24, 0, 7 + rldimi 15, 24, 56, 0 + rlwimi 15, 25, 24, 0, 7 + addi 28, 28, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + ld 18, 0(3) + ld 19, 8(3) + addi 3, 3, 16 + addic. 5, 5, -16 + xor 14, 14, 18 + xor 15, 15, 19 + std 14, 0(4) + std 15, 8(4) + addi 4, 4, 16 + bne L_AES_GCM_encrypt_loop_block + std 26, 0(8) + std 27, 8(8) + ld 0, 120(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + ld 27, 104(1) + ld 28, 112(1) + addi 1, 1, 0x80 + blr +#ifndef __APPLE__ + .size AES_GCM_encrypt,.-AES_GCM_encrypt +#endif /* __APPLE__ */ +#endif /* HAVE_AESGCM */ +#ifdef WOLFSSL_AES_XTS +#ifndef __APPLE__ +.text +.globl AES_XTS_encrypt +.type AES_XTS_encrypt,@function +.align 16 +AES_XTS_encrypt: +#else +.section __TEXT,__text +.globl _AES_XTS_encrypt +.p2align 4 +_AES_XTS_encrypt: +#endif /* __APPLE__ */ + stdu 1, -136(1) + mflr 0 + std 0, 128(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) + std 27, 104(1) + std 28, 112(1) + std 29, 120(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 11, 2, L_AES_PPC64_te4_0@toc@ha + addi 11, 11, L_AES_PPC64_te4_0@toc@l +#else + lis 11, L_AES_PPC64_te4_0@ha + la 11, L_AES_PPC64_te4_0@l(11) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 12, 11, 0x400 + addi 14, 11, 0x800 + addi 15, 11, 0xc00 + ld 28, 0(6) + ld 29, 8(6) + ld 20, 0(8) + ld 21, 8(8) + addi 8, 8, 16 + rldicr 28, 28, 32, 63 + rldicr 29, 29, 32, 63 + # Round: 0 - XOR in key schedule + xor 28, 28, 20 + xor 29, 29, 21 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 23, 0(11) + ld 23, 64(11) + ld 23, 128(11) + ld 23, 192(11) + ld 23, 256(11) + ld 23, 320(11) + ld 23, 384(11) + ld 23, 448(11) + ld 23, 512(11) + ld 23, 576(11) + ld 23, 640(11) + ld 23, 704(11) + ld 23, 768(11) + ld 23, 832(11) + ld 23, 896(11) + ld 23, 960(11) + ld 23, 1024(11) + ld 23, 1088(11) + ld 23, 1152(11) + ld 23, 1216(11) + ld 23, 1280(11) + ld 23, 1344(11) + ld 23, 1408(11) + ld 23, 1472(11) + ld 23, 1536(11) + ld 23, 1600(11) + ld 23, 1664(11) + ld 23, 1728(11) + ld 23, 1792(11) + ld 23, 1856(11) + ld 23, 1920(11) + ld 23, 1984(11) + ld 23, 2048(11) + ld 23, 2112(11) + ld 23, 2176(11) + ld 23, 2240(11) + ld 23, 2304(11) + ld 23, 2368(11) + ld 23, 2432(11) + ld 23, 2496(11) + ld 23, 2560(11) + ld 23, 2624(11) + ld 23, 2688(11) + ld 23, 2752(11) + ld 23, 2816(11) + ld 23, 2880(11) + ld 23, 2944(11) + ld 23, 3008(11) + ld 23, 3072(11) + ld 23, 3136(11) + ld 23, 3200(11) + ld 23, 3264(11) + ld 23, 3328(11) + ld 23, 3392(11) + ld 23, 3456(11) + ld 23, 3520(11) + ld 23, 3584(11) + ld 23, 3648(11) + ld 23, 3712(11) + ld 23, 3776(11) + ld 23, 3840(11) + ld 23, 3904(11) + ld 23, 3968(11) + ld 23, 4032(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_encrypt_loop_nr_tweak: + srdi 18, 28, 32 + srdi 19, 29, 32 + rlwinm 20, 28, 10, 22, 29 + rlwinm 21, 29, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 29, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 28, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 29, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 28, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 28, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 29, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 28, 0(8) + ld 29, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 28 + xor 21, 21, 29 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 28, 20, 10, 22, 29 + rlwinm 29, 21, 10, 22, 29 + rlwinm 18, 22, 10, 22, 29 + rlwinm 19, 23, 10, 22, 29 + lwzx 28, 11, 28 + lwzx 29, 11, 29 + lwzx 18, 11, 18 + lwzx 19, 11, 19 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 28, 28, 24 + xor 18, 18, 25 + xor 29, 29, 26 + xor 19, 19, 27 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 28, 28, 24 + xor 18, 18, 25 + xor 29, 29, 26 + xor 19, 19, 27 + rlwinm 24, 23, 2, 22, 29 + rlwinm 25, 20, 2, 22, 29 + rlwinm 26, 22, 2, 22, 29 + rlwinm 27, 21, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 28, 28, 24 + xor 18, 18, 25 + xor 29, 29, 26 + xor 19, 19, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 28, 18, 32, 0 + rldimi 29, 19, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 28, 28, 20 + xor 29, 29, 21 + bdnz L_AES_XTS_encrypt_loop_nr_tweak + srdi 18, 28, 32 + srdi 19, 29, 32 + rlwinm 20, 28, 10, 22, 29 + rlwinm 21, 29, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 29, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 28, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 29, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 28, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 28, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 29, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 28, 0(8) + ld 29, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 28 + xor 21, 21, 29 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 28, 20, 2, 22, 29 + rlwinm 29, 21, 2, 22, 29 + rlwinm 19, 22, 2, 22, 29 + rlwinm 18, 23, 2, 22, 29 + lwzx 28, 12, 28 + lwzx 29, 12, 29 + lwzx 19, 12, 19 + lwzx 18, 12, 18 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rldimi 29, 19, 32, 24 + rldimi 28, 18, 32, 24 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 28, 24, 40, 16 + rlwimi 28, 25, 8, 16, 23 + rldimi 29, 26, 40, 16 + rlwimi 29, 27, 8, 16, 23 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 28, 24, 48, 8 + rlwimi 28, 25, 16, 8, 15 + rldimi 29, 26, 48, 8 + rlwimi 29, 27, 16, 8, 15 + rlwinm 24, 20, 10, 22, 29 + rlwinm 25, 22, 10, 22, 29 + rlwinm 26, 21, 10, 22, 29 + rlwinm 27, 23, 10, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 28, 24, 56, 0 + rlwimi 28, 25, 24, 0, 7 + rldimi 29, 26, 56, 0 + rlwimi 29, 27, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 28, 28, 20 + xor 29, 29, 21 + std 28, 0(9) + std 29, 8(9) +L_AES_XTS_encrypt_loop_block: + addi 8, 7, 0 + ld 16, 0(3) + ld 17, 8(3) + ld 20, 0(8) + ld 21, 8(8) + addi 8, 8, 16 + xor 16, 16, 28 + xor 17, 17, 29 + rldicr 16, 16, 32, 63 + rldicr 17, 17, 32, 63 + # Round: 0 - XOR in key schedule + xor 16, 16, 20 + xor 17, 17, 21 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 23, 0(11) + ld 23, 64(11) + ld 23, 128(11) + ld 23, 192(11) + ld 23, 256(11) + ld 23, 320(11) + ld 23, 384(11) + ld 23, 448(11) + ld 23, 512(11) + ld 23, 576(11) + ld 23, 640(11) + ld 23, 704(11) + ld 23, 768(11) + ld 23, 832(11) + ld 23, 896(11) + ld 23, 960(11) + ld 23, 1024(11) + ld 23, 1088(11) + ld 23, 1152(11) + ld 23, 1216(11) + ld 23, 1280(11) + ld 23, 1344(11) + ld 23, 1408(11) + ld 23, 1472(11) + ld 23, 1536(11) + ld 23, 1600(11) + ld 23, 1664(11) + ld 23, 1728(11) + ld 23, 1792(11) + ld 23, 1856(11) + ld 23, 1920(11) + ld 23, 1984(11) + ld 23, 2048(11) + ld 23, 2112(11) + ld 23, 2176(11) + ld 23, 2240(11) + ld 23, 2304(11) + ld 23, 2368(11) + ld 23, 2432(11) + ld 23, 2496(11) + ld 23, 2560(11) + ld 23, 2624(11) + ld 23, 2688(11) + ld 23, 2752(11) + ld 23, 2816(11) + ld 23, 2880(11) + ld 23, 2944(11) + ld 23, 3008(11) + ld 23, 3072(11) + ld 23, 3136(11) + ld 23, 3200(11) + ld 23, 3264(11) + ld 23, 3328(11) + ld 23, 3392(11) + ld 23, 3456(11) + ld 23, 3520(11) + ld 23, 3584(11) + ld 23, 3648(11) + ld 23, 3712(11) + ld 23, 3776(11) + ld 23, 3840(11) + ld 23, 3904(11) + ld 23, 3968(11) + ld 23, 4032(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_encrypt_loop_nr: + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 17, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 16, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 17, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 16, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 16, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 17, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 16, 0(8) + ld 17, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 16 + xor 21, 21, 17 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 16, 20, 10, 22, 29 + rlwinm 17, 21, 10, 22, 29 + rlwinm 18, 22, 10, 22, 29 + rlwinm 19, 23, 10, 22, 29 + lwzx 16, 11, 16 + lwzx 17, 11, 17 + lwzx 18, 11, 18 + lwzx 19, 11, 19 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + rlwinm 24, 23, 2, 22, 29 + rlwinm 25, 20, 2, 22, 29 + rlwinm 26, 22, 2, 22, 29 + rlwinm 27, 21, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 16, 16, 20 + xor 17, 17, 21 + bdnz L_AES_XTS_encrypt_loop_nr + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 17, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 16, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 17, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 16, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 16, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 17, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 16, 0(8) + ld 17, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 16 + xor 21, 21, 17 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 16, 20, 2, 22, 29 + rlwinm 17, 21, 2, 22, 29 + rlwinm 19, 22, 2, 22, 29 + rlwinm 18, 23, 2, 22, 29 + lwzx 16, 12, 16 + lwzx 17, 12, 17 + lwzx 19, 12, 19 + lwzx 18, 12, 18 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rldimi 17, 19, 32, 24 + rldimi 16, 18, 32, 24 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 16, 24, 40, 16 + rlwimi 16, 25, 8, 16, 23 + rldimi 17, 26, 40, 16 + rlwimi 17, 27, 8, 16, 23 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 16, 24, 48, 8 + rlwimi 16, 25, 16, 8, 15 + rldimi 17, 26, 48, 8 + rlwimi 17, 27, 16, 8, 15 + rlwinm 24, 20, 10, 22, 29 + rlwinm 25, 22, 10, 22, 29 + rlwinm 26, 21, 10, 22, 29 + rlwinm 27, 23, 10, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 16, 24, 56, 0 + rlwimi 16, 25, 24, 0, 7 + rldimi 17, 26, 56, 0 + rlwimi 17, 27, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 16, 16, 20 + xor 17, 17, 21 + xor 16, 16, 28 + xor 17, 17, 29 + li 19, 8 + ldbrx 28, 0, 9 + ldbrx 29, 9, 19 + std 16, 0(4) + std 17, 8(4) + sradi 24, 29, 63 + srdi 25, 28, 63 + sldi 29, 29, 1 + andi. 24, 24, 0x87 + sldi 28, 28, 1 + xor 29, 29, 25 + xor 28, 28, 24 + stdbrx 28, 0, 9 + stdbrx 29, 9, 19 + ld 28, 0(9) + ld 29, 8(9) + addi 5, 5, -16 + addi 3, 3, 16 + addi 4, 4, 16 + cmpdi 5, 16 + bge L_AES_XTS_encrypt_loop_block + cmpdi 5, 0 + beq L_AES_XTS_encrypt_done_data + addi 8, 7, 0 + addi 4, 4, -16 + ld 16, 0(4) + ld 17, 8(4) + addi 4, 4, 16 + std 16, 0(9) + std 17, 8(9) + addi 20, 5, 0 +L_AES_XTS_encrypt_start_byte: + lbz 24, 0(9) + lbz 25, 0(3) + addi 3, 3, 1 + stb 24, 0(4) + addi 4, 4, 1 + stb 25, 0(9) + addi 9, 9, 1 + addic. 20, 20, -1 + bne L_AES_XTS_encrypt_start_byte + subf 4, 5, 4 + subf 9, 5, 9 + addi 4, 4, -16 + ld 16, 0(9) + ld 17, 8(9) + ld 20, 0(8) + ld 21, 8(8) + addi 8, 8, 16 + xor 16, 16, 28 + xor 17, 17, 29 + rldicr 16, 16, 32, 63 + rldicr 17, 17, 32, 63 + # Round: 0 - XOR in key schedule + xor 16, 16, 20 + xor 17, 17, 21 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 23, 0(11) + ld 23, 64(11) + ld 23, 128(11) + ld 23, 192(11) + ld 23, 256(11) + ld 23, 320(11) + ld 23, 384(11) + ld 23, 448(11) + ld 23, 512(11) + ld 23, 576(11) + ld 23, 640(11) + ld 23, 704(11) + ld 23, 768(11) + ld 23, 832(11) + ld 23, 896(11) + ld 23, 960(11) + ld 23, 1024(11) + ld 23, 1088(11) + ld 23, 1152(11) + ld 23, 1216(11) + ld 23, 1280(11) + ld 23, 1344(11) + ld 23, 1408(11) + ld 23, 1472(11) + ld 23, 1536(11) + ld 23, 1600(11) + ld 23, 1664(11) + ld 23, 1728(11) + ld 23, 1792(11) + ld 23, 1856(11) + ld 23, 1920(11) + ld 23, 1984(11) + ld 23, 2048(11) + ld 23, 2112(11) + ld 23, 2176(11) + ld 23, 2240(11) + ld 23, 2304(11) + ld 23, 2368(11) + ld 23, 2432(11) + ld 23, 2496(11) + ld 23, 2560(11) + ld 23, 2624(11) + ld 23, 2688(11) + ld 23, 2752(11) + ld 23, 2816(11) + ld 23, 2880(11) + ld 23, 2944(11) + ld 23, 3008(11) + ld 23, 3072(11) + ld 23, 3136(11) + ld 23, 3200(11) + ld 23, 3264(11) + ld 23, 3328(11) + ld 23, 3392(11) + ld 23, 3456(11) + ld 23, 3520(11) + ld 23, 3584(11) + ld 23, 3648(11) + ld 23, 3712(11) + ld 23, 3776(11) + ld 23, 3840(11) + ld 23, 3904(11) + ld 23, 3968(11) + ld 23, 4032(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_encrypt_loop_nr_partial: + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 17, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 16, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 17, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 16, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 16, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 17, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 16, 0(8) + ld 17, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 16 + xor 21, 21, 17 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 16, 20, 10, 22, 29 + rlwinm 17, 21, 10, 22, 29 + rlwinm 18, 22, 10, 22, 29 + rlwinm 19, 23, 10, 22, 29 + lwzx 16, 11, 16 + lwzx 17, 11, 17 + lwzx 18, 11, 18 + lwzx 19, 11, 19 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + rlwinm 24, 23, 2, 22, 29 + rlwinm 25, 20, 2, 22, 29 + rlwinm 26, 22, 2, 22, 29 + rlwinm 27, 21, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 16, 16, 24 + xor 18, 18, 25 + xor 17, 17, 26 + xor 19, 19, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 16, 16, 20 + xor 17, 17, 21 + bdnz L_AES_XTS_encrypt_loop_nr_partial + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 17, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 11, 20 + lwzx 21, 11, 21 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + rlwinm 24, 18, 18, 22, 29 + rlwinm 25, 17, 18, 22, 29 + rlwinm 26, 19, 18, 22, 29 + rlwinm 27, 16, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 17, 26, 22, 29 + rlwinm 25, 19, 26, 22, 29 + rlwinm 26, 16, 26, 22, 29 + rlwinm 27, 18, 26, 22, 29 + lwzx 24, 14, 24 + lwzx 25, 14, 25 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + rlwinm 24, 19, 2, 22, 29 + rlwinm 25, 16, 2, 22, 29 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 17, 2, 22, 29 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + xor 20, 20, 24 + xor 22, 22, 25 + xor 21, 21, 26 + xor 23, 23, 27 + ld 16, 0(8) + ld 17, 8(8) + rldimi 20, 22, 32, 0 + rldimi 21, 23, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 20, 20, 16 + xor 21, 21, 17 + srdi 22, 20, 32 + srdi 23, 21, 32 + rlwinm 16, 20, 2, 22, 29 + rlwinm 17, 21, 2, 22, 29 + rlwinm 19, 22, 2, 22, 29 + rlwinm 18, 23, 2, 22, 29 + lwzx 16, 12, 16 + lwzx 17, 12, 17 + lwzx 19, 12, 19 + lwzx 18, 12, 18 + rlwinm 24, 21, 26, 22, 29 + rlwinm 25, 23, 26, 22, 29 + rldimi 17, 19, 32, 24 + rldimi 16, 18, 32, 24 + rlwinm 26, 20, 26, 22, 29 + rlwinm 27, 22, 26, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 16, 24, 40, 16 + rlwimi 16, 25, 8, 16, 23 + rldimi 17, 26, 40, 16 + rlwimi 17, 27, 8, 16, 23 + rlwinm 24, 22, 18, 22, 29 + rlwinm 25, 21, 18, 22, 29 + rlwinm 26, 23, 18, 22, 29 + rlwinm 27, 20, 18, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + rldimi 16, 24, 48, 8 + rlwimi 16, 25, 16, 8, 15 + rldimi 17, 26, 48, 8 + rlwimi 17, 27, 16, 8, 15 + rlwinm 24, 20, 10, 22, 29 + rlwinm 25, 22, 10, 22, 29 + rlwinm 26, 21, 10, 22, 29 + rlwinm 27, 23, 10, 22, 29 + lwzx 24, 12, 24 + lwzx 25, 12, 25 + lwzx 26, 12, 26 + lwzx 27, 12, 27 + ld 20, 0(8) + ld 21, 8(8) + rldimi 16, 24, 56, 0 + rlwimi 16, 25, 24, 0, 7 + rldimi 17, 26, 56, 0 + rlwimi 17, 27, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 16, 16, 20 + xor 17, 17, 21 + xor 16, 16, 28 + xor 17, 17, 29 + std 16, 0(4) + std 17, 8(4) +L_AES_XTS_encrypt_done_data: + ld 0, 128(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + ld 27, 104(1) + ld 28, 112(1) + ld 29, 120(1) + addi 1, 1, 0x88 + blr +#ifndef __APPLE__ + .size AES_XTS_encrypt,.-AES_XTS_encrypt +#endif /* __APPLE__ */ +#endif /* WOLFSSL_AES_XTS */ +#ifdef HAVE_AES_DECRYPT +#if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || \ + defined(HAVE_AES_CBC) || defined(HAVE_AES_ECB) +#ifndef __APPLE__ + .text + .section .rodata + .type L_AES_PPC64_td4, @object + .size L_AES_PPC64_td4, 256 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_AES_PPC64_td4: + .byte 0x52 + .byte 0x9 + .byte 0x6a + .byte 0xd5 + .byte 0x30 + .byte 0x36 + .byte 0xa5 + .byte 0x38 + .byte 0xbf + .byte 0x40 + .byte 0xa3 + .byte 0x9e + .byte 0x81 + .byte 0xf3 + .byte 0xd7 + .byte 0xfb + .byte 0x7c + .byte 0xe3 + .byte 0x39 + .byte 0x82 + .byte 0x9b + .byte 0x2f + .byte 0xff + .byte 0x87 + .byte 0x34 + .byte 0x8e + .byte 0x43 + .byte 0x44 + .byte 0xc4 + .byte 0xde + .byte 0xe9 + .byte 0xcb + .byte 0x54 + .byte 0x7b + .byte 0x94 + .byte 0x32 + .byte 0xa6 + .byte 0xc2 + .byte 0x23 + .byte 0x3d + .byte 0xee + .byte 0x4c + .byte 0x95 + .byte 0xb + .byte 0x42 + .byte 0xfa + .byte 0xc3 + .byte 0x4e + .byte 0x8 + .byte 0x2e + .byte 0xa1 + .byte 0x66 + .byte 0x28 + .byte 0xd9 + .byte 0x24 + .byte 0xb2 + .byte 0x76 + .byte 0x5b + .byte 0xa2 + .byte 0x49 + .byte 0x6d + .byte 0x8b + .byte 0xd1 + .byte 0x25 + .byte 0x72 + .byte 0xf8 + .byte 0xf6 + .byte 0x64 + .byte 0x86 + .byte 0x68 + .byte 0x98 + .byte 0x16 + .byte 0xd4 + .byte 0xa4 + .byte 0x5c + .byte 0xcc + .byte 0x5d + .byte 0x65 + .byte 0xb6 + .byte 0x92 + .byte 0x6c + .byte 0x70 + .byte 0x48 + .byte 0x50 + .byte 0xfd + .byte 0xed + .byte 0xb9 + .byte 0xda + .byte 0x5e + .byte 0x15 + .byte 0x46 + .byte 0x57 + .byte 0xa7 + .byte 0x8d + .byte 0x9d + .byte 0x84 + .byte 0x90 + .byte 0xd8 + .byte 0xab + .byte 0x0 + .byte 0x8c + .byte 0xbc + .byte 0xd3 + .byte 0xa + .byte 0xf7 + .byte 0xe4 + .byte 0x58 + .byte 0x5 + .byte 0xb8 + .byte 0xb3 + .byte 0x45 + .byte 0x6 + .byte 0xd0 + .byte 0x2c + .byte 0x1e + .byte 0x8f + .byte 0xca + .byte 0x3f + .byte 0xf + .byte 0x2 + .byte 0xc1 + .byte 0xaf + .byte 0xbd + .byte 0x3 + .byte 0x1 + .byte 0x13 + .byte 0x8a + .byte 0x6b + .byte 0x3a + .byte 0x91 + .byte 0x11 + .byte 0x41 + .byte 0x4f + .byte 0x67 + .byte 0xdc + .byte 0xea + .byte 0x97 + .byte 0xf2 + .byte 0xcf + .byte 0xce + .byte 0xf0 + .byte 0xb4 + .byte 0xe6 + .byte 0x73 + .byte 0x96 + .byte 0xac + .byte 0x74 + .byte 0x22 + .byte 0xe7 + .byte 0xad + .byte 0x35 + .byte 0x85 + .byte 0xe2 + .byte 0xf9 + .byte 0x37 + .byte 0xe8 + .byte 0x1c + .byte 0x75 + .byte 0xdf + .byte 0x6e + .byte 0x47 + .byte 0xf1 + .byte 0x1a + .byte 0x71 + .byte 0x1d + .byte 0x29 + .byte 0xc5 + .byte 0x89 + .byte 0x6f + .byte 0xb7 + .byte 0x62 + .byte 0xe + .byte 0xaa + .byte 0x18 + .byte 0xbe + .byte 0x1b + .byte 0xfc + .byte 0x56 + .byte 0x3e + .byte 0x4b + .byte 0xc6 + .byte 0xd2 + .byte 0x79 + .byte 0x20 + .byte 0x9a + .byte 0xdb + .byte 0xc0 + .byte 0xfe + .byte 0x78 + .byte 0xcd + .byte 0x5a + .byte 0xf4 + .byte 0x1f + .byte 0xdd + .byte 0xa8 + .byte 0x33 + .byte 0x88 + .byte 0x7 + .byte 0xc7 + .byte 0x31 + .byte 0xb1 + .byte 0x12 + .byte 0x10 + .byte 0x59 + .byte 0x27 + .byte 0x80 + .byte 0xec + .byte 0x5f + .byte 0x60 + .byte 0x51 + .byte 0x7f + .byte 0xa9 + .byte 0x19 + .byte 0xb5 + .byte 0x4a + .byte 0xd + .byte 0x2d + .byte 0xe5 + .byte 0x7a + .byte 0x9f + .byte 0x93 + .byte 0xc9 + .byte 0x9c + .byte 0xef + .byte 0xa0 + .byte 0xe0 + .byte 0x3b + .byte 0x4d + .byte 0xae + .byte 0x2a + .byte 0xf5 + .byte 0xb0 + .byte 0xc8 + .byte 0xeb + .byte 0xbb + .byte 0x3c + .byte 0x83 + .byte 0x53 + .byte 0x99 + .byte 0x61 + .byte 0x17 + .byte 0x2b + .byte 0x4 + .byte 0x7e + .byte 0xba + .byte 0x77 + .byte 0xd6 + .byte 0x26 + .byte 0xe1 + .byte 0x69 + .byte 0x14 + .byte 0x63 + .byte 0x55 + .byte 0x21 + .byte 0xc + .byte 0x7d +#if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) +#ifndef __APPLE__ +.text +.globl AES_ECB_decrypt +.type AES_ECB_decrypt,@function +.align 16 +AES_ECB_decrypt: +#else +.section __TEXT,__text +.globl _AES_ECB_decrypt +.p2align 4 +_AES_ECB_decrypt: +#endif /* __APPLE__ */ + stdu 1, -88(1) + mflr 0 + std 0, 80(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 8, 2, L_AES_PPC64_td@toc@ha + addi 8, 8, L_AES_PPC64_td@toc@l +#else + lis 8, L_AES_PPC64_td@ha + la 8, L_AES_PPC64_td@l(8) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 9, 2, L_AES_PPC64_td4@toc@ha + addi 9, 9, L_AES_PPC64_td4@toc@l +#else + lis 9, L_AES_PPC64_td4@ha + la 9, L_AES_PPC64_td4@l(9) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +L_AES_ECB_decrypt_loop_block: + addi 23, 6, 0 + ld 10, 0(3) + ld 11, 8(3) + ld 15, 0(23) + ld 16, 8(23) + addi 23, 23, 16 + rldicr 10, 10, 32, 63 + rldicr 11, 11, 32, 63 + # Round: 0 - XOR in key schedule + xor 10, 10, 15 + xor 11, 11, 16 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 18, 0(8) + ld 18, 64(8) + ld 18, 128(8) + ld 18, 192(8) + ld 18, 256(8) + ld 18, 320(8) + ld 18, 384(8) + ld 18, 448(8) + ld 18, 512(8) + ld 18, 576(8) + ld 18, 640(8) + ld 18, 704(8) + ld 18, 768(8) + ld 18, 832(8) + ld 18, 896(8) + ld 18, 960(8) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_ECB_decrypt_loop_nr: + srdi 12, 10, 32 + srdi 14, 11, 32 + rlwinm 15, 14, 18, 22, 29 + rlwinm 17, 10, 18, 22, 29 + rlwinm 16, 12, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + lwzx 15, 8, 15 + lwzx 17, 8, 17 + lwzx 16, 8, 16 + lwzx 18, 8, 18 + rlwinm 19, 10, 10, 22, 29 + rlwinm 20, 12, 10, 22, 29 + rlwinm 21, 11, 10, 22, 29 + rlwinm 22, 14, 10, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 8, 0, 31 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + rlwinm 19, 11, 26, 22, 29 + rlwinm 20, 14, 26, 22, 29 + rlwinm 21, 10, 26, 22, 29 + rlwinm 22, 12, 26, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 24, 0, 31 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + rlwinm 19, 12, 2, 22, 29 + rlwinm 20, 11, 2, 22, 29 + rlwinm 21, 14, 2, 22, 29 + rlwinm 22, 10, 2, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 16, 0, 31 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + ld 10, 0(23) + ld 11, 8(23) + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + addi 23, 23, 16 + rldimi 15, 17, 32, 0 + rldimi 16, 18, 32, 0 + # XOR in Key Schedule + xor 15, 15, 10 + xor 16, 16, 11 + srdi 17, 15, 32 + srdi 18, 16, 32 + rlwinm 10, 18, 18, 22, 29 + rlwinm 12, 15, 18, 22, 29 + rlwinm 11, 17, 18, 22, 29 + rlwinm 14, 16, 18, 22, 29 + lwzx 10, 8, 10 + lwzx 12, 8, 12 + lwzx 11, 8, 11 + lwzx 14, 8, 14 + rlwinm 19, 15, 10, 22, 29 + rlwinm 20, 17, 10, 22, 29 + rlwinm 21, 16, 10, 22, 29 + rlwinm 22, 18, 10, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 8, 0, 31 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + xor 10, 10, 19 + xor 12, 12, 20 + xor 11, 11, 21 + xor 14, 14, 22 + rlwinm 19, 16, 26, 22, 29 + rlwinm 20, 18, 26, 22, 29 + rlwinm 21, 15, 26, 22, 29 + rlwinm 22, 17, 26, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 24, 0, 31 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + xor 10, 10, 19 + xor 12, 12, 20 + xor 11, 11, 21 + xor 14, 14, 22 + rlwinm 19, 17, 2, 22, 29 + rlwinm 20, 16, 2, 22, 29 + rlwinm 21, 18, 2, 22, 29 + rlwinm 22, 15, 2, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 16, 0, 31 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + ld 15, 0(23) + ld 16, 8(23) + xor 10, 10, 19 + xor 12, 12, 20 + xor 11, 11, 21 + xor 14, 14, 22 + addi 23, 23, 16 + rldimi 10, 12, 32, 0 + rldimi 11, 14, 32, 0 + # XOR in Key Schedule + xor 10, 10, 15 + xor 11, 11, 16 + bdnz L_AES_ECB_decrypt_loop_nr + srdi 12, 10, 32 + srdi 14, 11, 32 + rlwinm 15, 14, 18, 22, 29 + rlwinm 17, 10, 18, 22, 29 + rlwinm 16, 12, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + lwzx 15, 8, 15 + lwzx 17, 8, 17 + lwzx 16, 8, 16 + lwzx 18, 8, 18 + rlwinm 19, 10, 10, 22, 29 + rlwinm 20, 12, 10, 22, 29 + rlwinm 21, 11, 10, 22, 29 + rlwinm 22, 14, 10, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 8, 0, 31 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + rlwinm 19, 11, 26, 22, 29 + rlwinm 20, 14, 26, 22, 29 + rlwinm 21, 10, 26, 22, 29 + rlwinm 22, 12, 26, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 24, 0, 31 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + rlwinm 19, 12, 2, 22, 29 + rlwinm 20, 11, 2, 22, 29 + rlwinm 21, 14, 2, 22, 29 + rlwinm 22, 10, 2, 22, 29 + lwzx 19, 8, 19 + lwzx 20, 8, 20 + lwzx 21, 8, 21 + lwzx 22, 8, 22 + rlwimi 19, 19, 16, 0, 31 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + ld 10, 0(23) + ld 11, 8(23) + xor 15, 15, 19 + xor 17, 17, 20 + xor 16, 16, 21 + xor 18, 18, 22 + addi 23, 23, 16 + rldimi 15, 17, 32, 0 + rldimi 16, 18, 32, 0 + # XOR in Key Schedule + xor 15, 15, 10 + xor 16, 16, 11 + ld 18, 0(9) + ld 18, 64(9) + ld 18, 128(9) + ld 18, 192(9) + ld 18, 256(9) + ld 18, 320(9) + ld 18, 384(9) + ld 18, 448(9) + ld 18, 512(9) + ld 18, 576(9) + ld 18, 640(9) + ld 18, 704(9) + ld 18, 768(9) + ld 18, 832(9) + ld 18, 896(9) + ld 18, 960(9) + rldicl 12, 15, 32, 56 + andi. 10, 16, 255 + rldicl 14, 16, 32, 56 + andi. 11, 15, 255 + lbzx 12, 9, 12 + lbzx 10, 9, 10 + lbzx 14, 9, 14 + lbzx 11, 9, 11 + rldimi 10, 12, 32, 24 + rldimi 11, 14, 32, 24 + rldicl 19, 16, 56, 56 + rldicl 20, 16, 24, 56 + rldicl 21, 15, 56, 56 + rldicl 22, 15, 24, 56 + lbzx 19, 9, 19 + lbzx 20, 9, 20 + lbzx 21, 9, 21 + lbzx 22, 9, 22 + rldimi 10, 19, 40, 16 + rlwimi 10, 20, 8, 16, 23 + rldimi 11, 21, 40, 16 + rlwimi 11, 22, 8, 16, 23 + rldicl 19, 16, 16, 56 + rldicl 20, 15, 48, 56 + rldicl 21, 15, 16, 56 + rldicl 22, 16, 48, 56 + lbzx 19, 9, 19 + lbzx 20, 9, 20 + lbzx 21, 9, 21 + lbzx 22, 9, 22 + rldimi 10, 19, 48, 8 + rlwimi 10, 20, 16, 8, 15 + rldimi 11, 21, 48, 8 + rlwimi 11, 22, 16, 8, 15 + rldicl 19, 15, 40, 56 + rldicl 20, 15, 8, 56 + rldicl 21, 16, 40, 56 + rldicl 22, 16, 8, 56 + lbzx 19, 9, 19 + lbzx 20, 9, 20 + lbzx 21, 9, 21 + lbzx 22, 9, 22 + ld 15, 0(23) + ld 16, 8(23) + rldimi 10, 19, 56, 0 + rlwimi 10, 20, 24, 0, 7 + rldimi 11, 21, 56, 0 + rlwimi 11, 22, 24, 0, 7 + addi 23, 23, 16 + # XOR in Key Schedule + xor 10, 10, 15 + xor 11, 11, 16 + std 10, 0(4) + std 11, 8(4) + addic. 5, 5, -16 + addi 3, 3, 16 + addi 4, 4, 16 + bne L_AES_ECB_decrypt_loop_block + ld 0, 80(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + addi 1, 1, 0x58 + blr +#ifndef __APPLE__ + .size AES_ECB_decrypt,.-AES_ECB_decrypt +#endif /* __APPLE__ */ +#endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER || defined(HAVE_AES_ECB) */ +#ifdef HAVE_AES_CBC +#ifndef __APPLE__ +.text +.globl AES_CBC_decrypt +.type AES_CBC_decrypt,@function +.align 16 +AES_CBC_decrypt: +#else +.section __TEXT,__text +.globl _AES_CBC_decrypt +.p2align 4 +_AES_CBC_decrypt: +#endif /* __APPLE__ */ + stdu 1, -128(1) + mflr 0 + std 0, 120(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) + std 27, 104(1) + std 28, 112(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 10, 2, L_AES_PPC64_td4@toc@ha + addi 10, 10, L_AES_PPC64_td4@toc@l +#else + lis 10, L_AES_PPC64_td4@ha + la 10, L_AES_PPC64_td4@l(10) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 9, 2, L_AES_PPC64_td@toc@ha + addi 9, 9, L_AES_PPC64_td@toc@l +#else + lis 9, L_AES_PPC64_td@ha + la 9, L_AES_PPC64_td@l(9) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + ld 24, 0(8) + ld 25, 8(8) +L_AES_CBC_decrypt_loop_block: + addi 28, 6, 0 + ld 26, 0(3) + ld 27, 8(3) + ld 16, 0(28) + ld 17, 8(28) + addi 28, 28, 16 + rldicr 11, 26, 32, 63 + rldicr 12, 27, 32, 63 + # Round: 0 - XOR in key schedule + xor 11, 11, 16 + xor 12, 12, 17 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 19, 0(9) + ld 19, 64(9) + ld 19, 128(9) + ld 19, 192(9) + ld 19, 256(9) + ld 19, 320(9) + ld 19, 384(9) + ld 19, 448(9) + ld 19, 512(9) + ld 19, 576(9) + ld 19, 640(9) + ld 19, 704(9) + ld 19, 768(9) + ld 19, 832(9) + ld 19, 896(9) + ld 19, 960(9) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_CBC_decrypt_loop_nr_even: + srdi 14, 11, 32 + srdi 15, 12, 32 + rlwinm 16, 15, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + rlwinm 17, 14, 18, 22, 29 + rlwinm 19, 12, 18, 22, 29 + lwzx 16, 9, 16 + lwzx 18, 9, 18 + lwzx 17, 9, 17 + lwzx 19, 9, 19 + rlwinm 20, 11, 10, 22, 29 + rlwinm 21, 14, 10, 22, 29 + rlwinm 22, 12, 10, 22, 29 + rlwinm 23, 15, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 12, 26, 22, 29 + rlwinm 21, 15, 26, 22, 29 + rlwinm 22, 11, 26, 22, 29 + rlwinm 23, 14, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 14, 2, 22, 29 + rlwinm 21, 12, 2, 22, 29 + rlwinm 22, 15, 2, 22, 29 + rlwinm 23, 11, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 11, 0(28) + ld 12, 8(28) + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + addi 28, 28, 16 + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + # XOR in Key Schedule + xor 16, 16, 11 + xor 17, 17, 12 + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 11, 19, 18, 22, 29 + rlwinm 14, 16, 18, 22, 29 + rlwinm 12, 18, 18, 22, 29 + rlwinm 15, 17, 18, 22, 29 + lwzx 11, 9, 11 + lwzx 14, 9, 14 + lwzx 12, 9, 12 + lwzx 15, 9, 15 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 18, 10, 22, 29 + rlwinm 22, 17, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + rlwinm 20, 17, 26, 22, 29 + rlwinm 21, 19, 26, 22, 29 + rlwinm 22, 16, 26, 22, 29 + rlwinm 23, 18, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + rlwinm 20, 18, 2, 22, 29 + rlwinm 21, 17, 2, 22, 29 + rlwinm 22, 19, 2, 22, 29 + rlwinm 23, 16, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 16, 0(28) + ld 17, 8(28) + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + addi 28, 28, 16 + rldimi 11, 14, 32, 0 + rldimi 12, 15, 32, 0 + # XOR in Key Schedule + xor 11, 11, 16 + xor 12, 12, 17 + bdnz L_AES_CBC_decrypt_loop_nr_even + srdi 14, 11, 32 + srdi 15, 12, 32 + rlwinm 16, 15, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + rlwinm 17, 14, 18, 22, 29 + rlwinm 19, 12, 18, 22, 29 + lwzx 16, 9, 16 + lwzx 18, 9, 18 + lwzx 17, 9, 17 + lwzx 19, 9, 19 + rlwinm 20, 11, 10, 22, 29 + rlwinm 21, 14, 10, 22, 29 + rlwinm 22, 12, 10, 22, 29 + rlwinm 23, 15, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 12, 26, 22, 29 + rlwinm 21, 15, 26, 22, 29 + rlwinm 22, 11, 26, 22, 29 + rlwinm 23, 14, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 14, 2, 22, 29 + rlwinm 21, 12, 2, 22, 29 + rlwinm 22, 15, 2, 22, 29 + rlwinm 23, 11, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 11, 0(28) + ld 12, 8(28) + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + addi 28, 28, 16 + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + # XOR in Key Schedule + xor 16, 16, 11 + xor 17, 17, 12 + ld 19, 0(10) + ld 19, 64(10) + ld 19, 128(10) + ld 19, 192(10) + ld 19, 256(10) + ld 19, 320(10) + ld 19, 384(10) + ld 19, 448(10) + ld 19, 512(10) + ld 19, 576(10) + ld 19, 640(10) + ld 19, 704(10) + ld 19, 768(10) + ld 19, 832(10) + ld 19, 896(10) + ld 19, 960(10) + rldicl 14, 16, 32, 56 + andi. 11, 17, 255 + rldicl 15, 17, 32, 56 + andi. 12, 16, 255 + lbzx 14, 10, 14 + lbzx 11, 10, 11 + lbzx 15, 10, 15 + lbzx 12, 10, 12 + rldimi 11, 14, 32, 24 + rldimi 12, 15, 32, 24 + rldicl 20, 17, 56, 56 + rldicl 21, 17, 24, 56 + rldicl 22, 16, 56, 56 + rldicl 23, 16, 24, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + rldimi 11, 20, 40, 16 + rlwimi 11, 21, 8, 16, 23 + rldimi 12, 22, 40, 16 + rlwimi 12, 23, 8, 16, 23 + rldicl 20, 17, 16, 56 + rldicl 21, 16, 48, 56 + rldicl 22, 16, 16, 56 + rldicl 23, 17, 48, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + rldimi 11, 20, 48, 8 + rlwimi 11, 21, 16, 8, 15 + rldimi 12, 22, 48, 8 + rlwimi 12, 23, 16, 8, 15 + rldicl 20, 16, 40, 56 + rldicl 21, 16, 8, 56 + rldicl 22, 17, 40, 56 + rldicl 23, 17, 8, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + ld 16, 0(28) + ld 17, 8(28) + rldimi 11, 20, 56, 0 + rlwimi 11, 21, 24, 0, 7 + rldimi 12, 22, 56, 0 + rlwimi 12, 23, 24, 0, 7 + addi 28, 28, 16 + # XOR in Key Schedule + xor 11, 11, 16 + xor 12, 12, 17 + xor 11, 11, 24 + xor 12, 12, 25 + std 11, 0(4) + std 12, 8(4) + addic. 5, 5, -16 + addi 3, 3, 16 + addi 4, 4, 16 + beq L_AES_CBC_decrypt_end_dec_odd + addi 28, 6, 0 + ld 24, 0(3) + ld 25, 8(3) + ld 16, 0(28) + ld 17, 8(28) + addi 28, 28, 16 + rldicr 11, 24, 32, 63 + rldicr 12, 25, 32, 63 + # Round: 0 - XOR in key schedule + xor 11, 11, 16 + xor 12, 12, 17 + addi 0, 7, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 19, 0(9) + ld 19, 64(9) + ld 19, 128(9) + ld 19, 192(9) + ld 19, 256(9) + ld 19, 320(9) + ld 19, 384(9) + ld 19, 448(9) + ld 19, 512(9) + ld 19, 576(9) + ld 19, 640(9) + ld 19, 704(9) + ld 19, 768(9) + ld 19, 832(9) + ld 19, 896(9) + ld 19, 960(9) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_CBC_decrypt_loop_nr_odd: + srdi 14, 11, 32 + srdi 15, 12, 32 + rlwinm 16, 15, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + rlwinm 17, 14, 18, 22, 29 + rlwinm 19, 12, 18, 22, 29 + lwzx 16, 9, 16 + lwzx 18, 9, 18 + lwzx 17, 9, 17 + lwzx 19, 9, 19 + rlwinm 20, 11, 10, 22, 29 + rlwinm 21, 14, 10, 22, 29 + rlwinm 22, 12, 10, 22, 29 + rlwinm 23, 15, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 12, 26, 22, 29 + rlwinm 21, 15, 26, 22, 29 + rlwinm 22, 11, 26, 22, 29 + rlwinm 23, 14, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 14, 2, 22, 29 + rlwinm 21, 12, 2, 22, 29 + rlwinm 22, 15, 2, 22, 29 + rlwinm 23, 11, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 11, 0(28) + ld 12, 8(28) + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + addi 28, 28, 16 + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + # XOR in Key Schedule + xor 16, 16, 11 + xor 17, 17, 12 + srdi 18, 16, 32 + srdi 19, 17, 32 + rlwinm 11, 19, 18, 22, 29 + rlwinm 14, 16, 18, 22, 29 + rlwinm 12, 18, 18, 22, 29 + rlwinm 15, 17, 18, 22, 29 + lwzx 11, 9, 11 + lwzx 14, 9, 14 + lwzx 12, 9, 12 + lwzx 15, 9, 15 + rlwinm 20, 16, 10, 22, 29 + rlwinm 21, 18, 10, 22, 29 + rlwinm 22, 17, 10, 22, 29 + rlwinm 23, 19, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + rlwinm 20, 17, 26, 22, 29 + rlwinm 21, 19, 26, 22, 29 + rlwinm 22, 16, 26, 22, 29 + rlwinm 23, 18, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + rlwinm 20, 18, 2, 22, 29 + rlwinm 21, 17, 2, 22, 29 + rlwinm 22, 19, 2, 22, 29 + rlwinm 23, 16, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 16, 0(28) + ld 17, 8(28) + xor 11, 11, 20 + xor 14, 14, 21 + xor 12, 12, 22 + xor 15, 15, 23 + addi 28, 28, 16 + rldimi 11, 14, 32, 0 + rldimi 12, 15, 32, 0 + # XOR in Key Schedule + xor 11, 11, 16 + xor 12, 12, 17 + bdnz L_AES_CBC_decrypt_loop_nr_odd + srdi 14, 11, 32 + srdi 15, 12, 32 + rlwinm 16, 15, 18, 22, 29 + rlwinm 18, 11, 18, 22, 29 + rlwinm 17, 14, 18, 22, 29 + rlwinm 19, 12, 18, 22, 29 + lwzx 16, 9, 16 + lwzx 18, 9, 18 + lwzx 17, 9, 17 + lwzx 19, 9, 19 + rlwinm 20, 11, 10, 22, 29 + rlwinm 21, 14, 10, 22, 29 + rlwinm 22, 12, 10, 22, 29 + rlwinm 23, 15, 10, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 8, 0, 31 + rlwimi 21, 21, 8, 0, 31 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 12, 26, 22, 29 + rlwinm 21, 15, 26, 22, 29 + rlwinm 22, 11, 26, 22, 29 + rlwinm 23, 14, 26, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 24, 0, 31 + rlwimi 21, 21, 24, 0, 31 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + rlwinm 20, 14, 2, 22, 29 + rlwinm 21, 12, 2, 22, 29 + rlwinm 22, 15, 2, 22, 29 + rlwinm 23, 11, 2, 22, 29 + lwzx 20, 9, 20 + lwzx 21, 9, 21 + lwzx 22, 9, 22 + lwzx 23, 9, 23 + rlwimi 20, 20, 16, 0, 31 + rlwimi 21, 21, 16, 0, 31 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + ld 11, 0(28) + ld 12, 8(28) + xor 16, 16, 20 + xor 18, 18, 21 + xor 17, 17, 22 + xor 19, 19, 23 + addi 28, 28, 16 + rldimi 16, 18, 32, 0 + rldimi 17, 19, 32, 0 + # XOR in Key Schedule + xor 16, 16, 11 + xor 17, 17, 12 + ld 19, 0(10) + ld 19, 64(10) + ld 19, 128(10) + ld 19, 192(10) + ld 19, 256(10) + ld 19, 320(10) + ld 19, 384(10) + ld 19, 448(10) + ld 19, 512(10) + ld 19, 576(10) + ld 19, 640(10) + ld 19, 704(10) + ld 19, 768(10) + ld 19, 832(10) + ld 19, 896(10) + ld 19, 960(10) + rldicl 14, 16, 32, 56 + andi. 11, 17, 255 + rldicl 15, 17, 32, 56 + andi. 12, 16, 255 + lbzx 14, 10, 14 + lbzx 11, 10, 11 + lbzx 15, 10, 15 + lbzx 12, 10, 12 + rldimi 11, 14, 32, 24 + rldimi 12, 15, 32, 24 + rldicl 20, 17, 56, 56 + rldicl 21, 17, 24, 56 + rldicl 22, 16, 56, 56 + rldicl 23, 16, 24, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + rldimi 11, 20, 40, 16 + rlwimi 11, 21, 8, 16, 23 + rldimi 12, 22, 40, 16 + rlwimi 12, 23, 8, 16, 23 + rldicl 20, 17, 16, 56 + rldicl 21, 16, 48, 56 + rldicl 22, 16, 16, 56 + rldicl 23, 17, 48, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + rldimi 11, 20, 48, 8 + rlwimi 11, 21, 16, 8, 15 + rldimi 12, 22, 48, 8 + rlwimi 12, 23, 16, 8, 15 + rldicl 20, 16, 40, 56 + rldicl 21, 16, 8, 56 + rldicl 22, 17, 40, 56 + rldicl 23, 17, 8, 56 + lbzx 20, 10, 20 + lbzx 21, 10, 21 + lbzx 22, 10, 22 + lbzx 23, 10, 23 + ld 16, 0(28) + ld 17, 8(28) + rldimi 11, 20, 56, 0 + rlwimi 11, 21, 24, 0, 7 + rldimi 12, 22, 56, 0 + rlwimi 12, 23, 24, 0, 7 + addi 28, 28, 16 + # XOR in Key Schedule + xor 11, 11, 16 + xor 12, 12, 17 + xor 11, 11, 26 + xor 12, 12, 27 + std 11, 0(4) + std 12, 8(4) + addic. 5, 5, -16 + addi 3, 3, 16 + addi 4, 4, 16 + bne L_AES_CBC_decrypt_loop_block + std 24, 0(8) + std 25, 8(8) + b L_AES_CBC_decrypt_end_dec +L_AES_CBC_decrypt_end_dec_odd: + std 26, 0(8) + std 27, 8(8) +L_AES_CBC_decrypt_end_dec: + ld 0, 120(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + ld 27, 104(1) + ld 28, 112(1) + addi 1, 1, 0x80 + blr +#ifndef __APPLE__ + .size AES_CBC_decrypt,.-AES_CBC_decrypt +#endif /* __APPLE__ */ +#endif /* HAVE_AES_CBC */ +#endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER || HAVE_AES_CBC + * HAVE_AES_ECB */ +#ifdef WOLFSSL_AES_XTS +#ifndef __APPLE__ +.text +.globl AES_XTS_decrypt +.type AES_XTS_decrypt,@function +.align 16 +AES_XTS_decrypt: +#else +.section __TEXT,__text +.globl _AES_XTS_decrypt +.p2align 4 +_AES_XTS_decrypt: +#endif /* __APPLE__ */ + stdu 1, -136(1) + mflr 0 + std 0, 128(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + std 26, 96(1) + std 27, 104(1) + std 28, 112(1) + std 29, 120(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 14, 2, L_AES_PPC64_te4_0@toc@ha + addi 14, 14, L_AES_PPC64_te4_0@toc@l +#else + lis 14, L_AES_PPC64_te4_0@ha + la 14, L_AES_PPC64_te4_0@l(14) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 15, 14, 0x400 + addi 16, 14, 0x800 + addi 17, 14, 0xc00 + andi. 18, 5, 15 + addi 18, 18, 15 + andi. 18, 18, 16 + subf 5, 18, 5 + ld 26, 0(6) + ld 27, 8(6) + ld 18, 0(8) + ld 19, 8(8) + addi 8, 8, 16 + rldicr 26, 26, 32, 63 + rldicr 27, 27, 32, 63 + # Round: 0 - XOR in key schedule + xor 26, 26, 18 + xor 27, 27, 19 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(14) + ld 21, 32(14) + ld 21, 64(14) + ld 21, 96(14) + ld 21, 128(14) + ld 21, 160(14) + ld 21, 192(14) + ld 21, 224(14) + ld 21, 256(14) + ld 21, 288(14) + ld 21, 320(14) + ld 21, 352(14) + ld 21, 384(14) + ld 21, 416(14) + ld 21, 448(14) + ld 21, 480(14) + ld 21, 512(14) + ld 21, 544(14) + ld 21, 576(14) + ld 21, 608(14) + ld 21, 640(14) + ld 21, 672(14) + ld 21, 704(14) + ld 21, 736(14) + ld 21, 768(14) + ld 21, 800(14) + ld 21, 832(14) + ld 21, 864(14) + ld 21, 896(14) + ld 21, 928(14) + ld 21, 960(14) + ld 21, 992(14) + ld 21, 1024(14) + ld 21, 1056(14) + ld 21, 1088(14) + ld 21, 1120(14) + ld 21, 1152(14) + ld 21, 1184(14) + ld 21, 1216(14) + ld 21, 1248(14) + ld 21, 1280(14) + ld 21, 1312(14) + ld 21, 1344(14) + ld 21, 1376(14) + ld 21, 1408(14) + ld 21, 1440(14) + ld 21, 1472(14) + ld 21, 1504(14) + ld 21, 1536(14) + ld 21, 1568(14) + ld 21, 1600(14) + ld 21, 1632(14) + ld 21, 1664(14) + ld 21, 1696(14) + ld 21, 1728(14) + ld 21, 1760(14) + ld 21, 1792(14) + ld 21, 1824(14) + ld 21, 1856(14) + ld 21, 1888(14) + ld 21, 1920(14) + ld 21, 1952(14) + ld 21, 1984(14) + ld 21, 2016(14) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_decrypt_loop_nr_tweak: + srdi 28, 26, 32 + srdi 29, 27, 32 + rlwinm 18, 26, 10, 22, 29 + rlwinm 19, 27, 10, 22, 29 + rlwinm 20, 28, 10, 22, 29 + rlwinm 21, 29, 10, 22, 29 + lwzx 18, 14, 18 + lwzx 19, 14, 19 + lwzx 20, 14, 20 + lwzx 21, 14, 21 + rlwinm 22, 28, 18, 22, 29 + rlwinm 23, 27, 18, 22, 29 + rlwinm 24, 29, 18, 22, 29 + rlwinm 25, 26, 18, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 27, 26, 22, 29 + rlwinm 23, 29, 26, 22, 29 + rlwinm 24, 26, 26, 22, 29 + rlwinm 25, 28, 26, 22, 29 + lwzx 22, 16, 22 + lwzx 23, 16, 23 + lwzx 24, 16, 24 + lwzx 25, 16, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 29, 2, 22, 29 + rlwinm 23, 26, 2, 22, 29 + rlwinm 24, 28, 2, 22, 29 + rlwinm 25, 27, 2, 22, 29 + lwzx 22, 17, 22 + lwzx 23, 17, 23 + lwzx 24, 17, 24 + lwzx 25, 17, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 26, 0(8) + ld 27, 8(8) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 18, 18, 26 + xor 19, 19, 27 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 26, 18, 10, 22, 29 + rlwinm 27, 19, 10, 22, 29 + rlwinm 28, 20, 10, 22, 29 + rlwinm 29, 21, 10, 22, 29 + lwzx 26, 14, 26 + lwzx 27, 14, 27 + lwzx 28, 14, 28 + lwzx 29, 14, 29 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + xor 26, 26, 22 + xor 28, 28, 23 + xor 27, 27, 24 + xor 29, 29, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 16, 22 + lwzx 23, 16, 23 + lwzx 24, 16, 24 + lwzx 25, 16, 25 + xor 26, 26, 22 + xor 28, 28, 23 + xor 27, 27, 24 + xor 29, 29, 25 + rlwinm 22, 21, 2, 22, 29 + rlwinm 23, 18, 2, 22, 29 + rlwinm 24, 20, 2, 22, 29 + rlwinm 25, 19, 2, 22, 29 + lwzx 22, 17, 22 + lwzx 23, 17, 23 + lwzx 24, 17, 24 + lwzx 25, 17, 25 + xor 26, 26, 22 + xor 28, 28, 23 + xor 27, 27, 24 + xor 29, 29, 25 + ld 18, 0(8) + ld 19, 8(8) + rldimi 26, 28, 32, 0 + rldimi 27, 29, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 26, 26, 18 + xor 27, 27, 19 + bdnz L_AES_XTS_decrypt_loop_nr_tweak + srdi 28, 26, 32 + srdi 29, 27, 32 + rlwinm 18, 26, 10, 22, 29 + rlwinm 19, 27, 10, 22, 29 + rlwinm 20, 28, 10, 22, 29 + rlwinm 21, 29, 10, 22, 29 + lwzx 18, 14, 18 + lwzx 19, 14, 19 + lwzx 20, 14, 20 + lwzx 21, 14, 21 + rlwinm 22, 28, 18, 22, 29 + rlwinm 23, 27, 18, 22, 29 + rlwinm 24, 29, 18, 22, 29 + rlwinm 25, 26, 18, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 27, 26, 22, 29 + rlwinm 23, 29, 26, 22, 29 + rlwinm 24, 26, 26, 22, 29 + rlwinm 25, 28, 26, 22, 29 + lwzx 22, 16, 22 + lwzx 23, 16, 23 + lwzx 24, 16, 24 + lwzx 25, 16, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 29, 2, 22, 29 + rlwinm 23, 26, 2, 22, 29 + rlwinm 24, 28, 2, 22, 29 + rlwinm 25, 27, 2, 22, 29 + lwzx 22, 17, 22 + lwzx 23, 17, 23 + lwzx 24, 17, 24 + lwzx 25, 17, 25 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + ld 26, 0(8) + ld 27, 8(8) + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + addi 8, 8, 16 + # XOR in Key Schedule + xor 18, 18, 26 + xor 19, 19, 27 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 26, 18, 2, 22, 29 + rlwinm 27, 19, 2, 22, 29 + rlwinm 29, 20, 2, 22, 29 + rlwinm 28, 21, 2, 22, 29 + lwzx 26, 15, 26 + lwzx 27, 15, 27 + lwzx 29, 15, 29 + lwzx 28, 15, 28 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rldimi 27, 29, 32, 24 + rldimi 26, 28, 32, 24 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + rldimi 26, 22, 40, 16 + rlwimi 26, 23, 8, 16, 23 + rldimi 27, 24, 40, 16 + rlwimi 27, 25, 8, 16, 23 + rlwinm 22, 20, 18, 22, 29 + rlwinm 23, 19, 18, 22, 29 + rlwinm 24, 21, 18, 22, 29 + rlwinm 25, 18, 18, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + rldimi 26, 22, 48, 8 + rlwimi 26, 23, 16, 8, 15 + rldimi 27, 24, 48, 8 + rlwimi 27, 25, 16, 8, 15 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 15, 22 + lwzx 23, 15, 23 + lwzx 24, 15, 24 + lwzx 25, 15, 25 + ld 18, 0(8) + ld 19, 8(8) + rldimi 26, 22, 56, 0 + rlwimi 26, 23, 24, 0, 7 + rldimi 27, 24, 56, 0 + rlwimi 27, 25, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 26, 26, 18 + xor 27, 27, 19 + std 26, 0(9) + std 27, 8(9) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 11, 2, L_AES_PPC64_td@toc@ha + addi 11, 11, L_AES_PPC64_td@toc@l +#else + lis 11, L_AES_PPC64_td@ha + la 11, L_AES_PPC64_td@l(11) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 12, 2, L_AES_PPC64_td4@toc@ha + addi 12, 12, L_AES_PPC64_td4@toc@l +#else + lis 12, L_AES_PPC64_td4@ha + la 12, L_AES_PPC64_td4@l(12) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + cmpdi 5, 16 + blt L_AES_XTS_decrypt_start_partail +L_AES_XTS_decrypt_loop_block: + addi 8, 7, 0 + ld 14, 0(3) + ld 15, 8(3) + ld 18, 0(8) + ld 19, 8(8) + addi 8, 8, 16 + xor 14, 14, 26 + xor 15, 15, 27 + rldicr 14, 14, 32, 63 + rldicr 15, 15, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(11) + ld 21, 64(11) + ld 21, 128(11) + ld 21, 192(11) + ld 21, 256(11) + ld 21, 320(11) + ld 21, 384(11) + ld 21, 448(11) + ld 21, 512(11) + ld 21, 576(11) + ld 21, 640(11) + ld 21, 704(11) + ld 21, 768(11) + ld 21, 832(11) + ld 21, 896(11) + ld 21, 960(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_decrypt_loop_nr: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 21, 18, 22, 29 + rlwinm 16, 18, 18, 22, 29 + rlwinm 15, 20, 18, 22, 29 + rlwinm 17, 19, 18, 22, 29 + lwzx 14, 11, 14 + lwzx 16, 11, 16 + lwzx 15, 11, 15 + lwzx 17, 11, 17 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 20, 2, 22, 29 + rlwinm 23, 19, 2, 22, 29 + rlwinm 24, 21, 2, 22, 29 + rlwinm 25, 18, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 18, 0(8) + ld 19, 8(8) + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + addi 8, 8, 16 + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_XTS_decrypt_loop_nr + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + ld 21, 0(12) + ld 21, 64(12) + ld 21, 128(12) + ld 21, 192(12) + ld 21, 256(12) + ld 21, 320(12) + ld 21, 384(12) + ld 21, 448(12) + ld 21, 512(12) + ld 21, 576(12) + ld 21, 640(12) + ld 21, 704(12) + ld 21, 768(12) + ld 21, 832(12) + ld 21, 896(12) + ld 21, 960(12) + rldicl 16, 18, 32, 56 + andi. 14, 19, 255 + rldicl 17, 19, 32, 56 + andi. 15, 18, 255 + lbzx 16, 12, 16 + lbzx 14, 12, 14 + lbzx 17, 12, 17 + lbzx 15, 12, 15 + rldimi 14, 16, 32, 24 + rldimi 15, 17, 32, 24 + rldicl 22, 19, 56, 56 + rldicl 23, 19, 24, 56 + rldicl 24, 18, 56, 56 + rldicl 25, 18, 24, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 40, 16 + rlwimi 14, 23, 8, 16, 23 + rldimi 15, 24, 40, 16 + rlwimi 15, 25, 8, 16, 23 + rldicl 22, 19, 16, 56 + rldicl 23, 18, 48, 56 + rldicl 24, 18, 16, 56 + rldicl 25, 19, 48, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 48, 8 + rlwimi 14, 23, 16, 8, 15 + rldimi 15, 24, 48, 8 + rlwimi 15, 25, 16, 8, 15 + rldicl 22, 18, 40, 56 + rldicl 23, 18, 8, 56 + rldicl 24, 19, 40, 56 + rldicl 25, 19, 8, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + ld 18, 0(8) + ld 19, 8(8) + rldimi 14, 22, 56, 0 + rlwimi 14, 23, 24, 0, 7 + rldimi 15, 24, 56, 0 + rlwimi 15, 25, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + xor 14, 14, 26 + xor 15, 15, 27 + li 17, 8 + ldbrx 26, 0, 9 + ldbrx 27, 9, 17 + std 14, 0(4) + std 15, 8(4) + sradi 22, 27, 63 + srdi 23, 26, 63 + sldi 27, 27, 1 + andi. 22, 22, 0x87 + sldi 26, 26, 1 + xor 27, 27, 23 + xor 26, 26, 22 + stdbrx 26, 0, 9 + stdbrx 27, 9, 17 + ld 26, 0(9) + ld 27, 8(9) + addi 5, 5, -16 + addi 3, 3, 16 + addi 4, 4, 16 + cmpdi 5, 16 + bge L_AES_XTS_decrypt_loop_block + cmpdi 5, 0 + beq L_AES_XTS_decrypt_done_data +L_AES_XTS_decrypt_start_partail: + li 17, 8 + ldbrx 28, 0, 9 + ldbrx 29, 9, 17 + sradi 22, 29, 63 + srdi 23, 28, 63 + sldi 29, 29, 1 + andi. 22, 22, 0x87 + sldi 28, 28, 1 + xor 29, 29, 23 + xor 28, 28, 22 + stdbrx 28, 0, 9 + stdbrx 29, 9, 17 + ld 28, 0(9) + ld 29, 8(9) + addi 8, 7, 0 + ld 14, 0(3) + ld 15, 8(3) + addi 3, 3, 16 + ld 18, 0(8) + ld 19, 8(8) + addi 8, 8, 16 + xor 14, 14, 28 + xor 15, 15, 29 + rldicr 14, 14, 32, 63 + rldicr 15, 15, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(11) + ld 21, 64(11) + ld 21, 128(11) + ld 21, 192(11) + ld 21, 256(11) + ld 21, 320(11) + ld 21, 384(11) + ld 21, 448(11) + ld 21, 512(11) + ld 21, 576(11) + ld 21, 640(11) + ld 21, 704(11) + ld 21, 768(11) + ld 21, 832(11) + ld 21, 896(11) + ld 21, 960(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_decrypt_loop_nr_partial_1: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 21, 18, 22, 29 + rlwinm 16, 18, 18, 22, 29 + rlwinm 15, 20, 18, 22, 29 + rlwinm 17, 19, 18, 22, 29 + lwzx 14, 11, 14 + lwzx 16, 11, 16 + lwzx 15, 11, 15 + lwzx 17, 11, 17 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 20, 2, 22, 29 + rlwinm 23, 19, 2, 22, 29 + rlwinm 24, 21, 2, 22, 29 + rlwinm 25, 18, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 18, 0(8) + ld 19, 8(8) + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + addi 8, 8, 16 + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_XTS_decrypt_loop_nr_partial_1 + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + ld 21, 0(12) + ld 21, 64(12) + ld 21, 128(12) + ld 21, 192(12) + ld 21, 256(12) + ld 21, 320(12) + ld 21, 384(12) + ld 21, 448(12) + ld 21, 512(12) + ld 21, 576(12) + ld 21, 640(12) + ld 21, 704(12) + ld 21, 768(12) + ld 21, 832(12) + ld 21, 896(12) + ld 21, 960(12) + rldicl 16, 18, 32, 56 + andi. 14, 19, 255 + rldicl 17, 19, 32, 56 + andi. 15, 18, 255 + lbzx 16, 12, 16 + lbzx 14, 12, 14 + lbzx 17, 12, 17 + lbzx 15, 12, 15 + rldimi 14, 16, 32, 24 + rldimi 15, 17, 32, 24 + rldicl 22, 19, 56, 56 + rldicl 23, 19, 24, 56 + rldicl 24, 18, 56, 56 + rldicl 25, 18, 24, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 40, 16 + rlwimi 14, 23, 8, 16, 23 + rldimi 15, 24, 40, 16 + rlwimi 15, 25, 8, 16, 23 + rldicl 22, 19, 16, 56 + rldicl 23, 18, 48, 56 + rldicl 24, 18, 16, 56 + rldicl 25, 19, 48, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 48, 8 + rlwimi 14, 23, 16, 8, 15 + rldimi 15, 24, 48, 8 + rlwimi 15, 25, 16, 8, 15 + rldicl 22, 18, 40, 56 + rldicl 23, 18, 8, 56 + rldicl 24, 19, 40, 56 + rldicl 25, 19, 8, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + ld 18, 0(8) + ld 19, 8(8) + rldimi 14, 22, 56, 0 + rlwimi 14, 23, 24, 0, 7 + rldimi 15, 24, 56, 0 + rlwimi 15, 25, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + xor 14, 14, 28 + xor 15, 15, 29 + std 14, 0(9) + std 15, 8(9) + addi 4, 4, 16 + addi 18, 5, 0 +L_AES_XTS_decrypt_start_byte: + lbz 22, 0(9) + lbz 23, 0(3) + addi 3, 3, 1 + stb 22, 0(4) + addi 4, 4, 1 + stb 23, 0(9) + addi 9, 9, 1 + addic. 18, 18, -1 + bne L_AES_XTS_decrypt_start_byte + subf 4, 5, 4 + subf 9, 5, 9 + addi 4, 4, -16 + addi 8, 7, 0 + ld 14, 0(9) + ld 15, 8(9) + ld 18, 0(8) + ld 19, 8(8) + addi 8, 8, 16 + xor 14, 14, 26 + xor 15, 15, 27 + rldicr 14, 14, 32, 63 + rldicr 15, 15, 32, 63 + # Round: 0 - XOR in key schedule + xor 14, 14, 18 + xor 15, 15, 19 + addi 0, 10, -2 +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + ld 21, 0(11) + ld 21, 64(11) + ld 21, 128(11) + ld 21, 192(11) + ld 21, 256(11) + ld 21, 320(11) + ld 21, 384(11) + ld 21, 448(11) + ld 21, 512(11) + ld 21, 576(11) + ld 21, 640(11) + ld 21, 704(11) + ld 21, 768(11) + ld 21, 832(11) + ld 21, 896(11) + ld 21, 960(11) +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + srwi 0, 0, 1 + mtctr 0 +L_AES_XTS_decrypt_loop_nr_partial_2: + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + srdi 20, 18, 32 + srdi 21, 19, 32 + rlwinm 14, 21, 18, 22, 29 + rlwinm 16, 18, 18, 22, 29 + rlwinm 15, 20, 18, 22, 29 + rlwinm 17, 19, 18, 22, 29 + lwzx 14, 11, 14 + lwzx 16, 11, 16 + lwzx 15, 11, 15 + lwzx 17, 11, 17 + rlwinm 22, 18, 10, 22, 29 + rlwinm 23, 20, 10, 22, 29 + rlwinm 24, 19, 10, 22, 29 + rlwinm 25, 21, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 19, 26, 22, 29 + rlwinm 23, 21, 26, 22, 29 + rlwinm 24, 18, 26, 22, 29 + rlwinm 25, 20, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + rlwinm 22, 20, 2, 22, 29 + rlwinm 23, 19, 2, 22, 29 + rlwinm 24, 21, 2, 22, 29 + rlwinm 25, 18, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 18, 0(8) + ld 19, 8(8) + xor 14, 14, 22 + xor 16, 16, 23 + xor 15, 15, 24 + xor 17, 17, 25 + addi 8, 8, 16 + rldimi 14, 16, 32, 0 + rldimi 15, 17, 32, 0 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + bdnz L_AES_XTS_decrypt_loop_nr_partial_2 + srdi 16, 14, 32 + srdi 17, 15, 32 + rlwinm 18, 17, 18, 22, 29 + rlwinm 20, 14, 18, 22, 29 + rlwinm 19, 16, 18, 22, 29 + rlwinm 21, 15, 18, 22, 29 + lwzx 18, 11, 18 + lwzx 20, 11, 20 + lwzx 19, 11, 19 + lwzx 21, 11, 21 + rlwinm 22, 14, 10, 22, 29 + rlwinm 23, 16, 10, 22, 29 + rlwinm 24, 15, 10, 22, 29 + rlwinm 25, 17, 10, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 8, 0, 31 + rlwimi 23, 23, 8, 0, 31 + rlwimi 24, 24, 8, 0, 31 + rlwimi 25, 25, 8, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 15, 26, 22, 29 + rlwinm 23, 17, 26, 22, 29 + rlwinm 24, 14, 26, 22, 29 + rlwinm 25, 16, 26, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 24, 0, 31 + rlwimi 23, 23, 24, 0, 31 + rlwimi 24, 24, 24, 0, 31 + rlwimi 25, 25, 24, 0, 31 + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + rlwinm 22, 16, 2, 22, 29 + rlwinm 23, 15, 2, 22, 29 + rlwinm 24, 17, 2, 22, 29 + rlwinm 25, 14, 2, 22, 29 + lwzx 22, 11, 22 + lwzx 23, 11, 23 + lwzx 24, 11, 24 + lwzx 25, 11, 25 + rlwimi 22, 22, 16, 0, 31 + rlwimi 23, 23, 16, 0, 31 + rlwimi 24, 24, 16, 0, 31 + rlwimi 25, 25, 16, 0, 31 + ld 14, 0(8) + ld 15, 8(8) + xor 18, 18, 22 + xor 20, 20, 23 + xor 19, 19, 24 + xor 21, 21, 25 + addi 8, 8, 16 + rldimi 18, 20, 32, 0 + rldimi 19, 21, 32, 0 + # XOR in Key Schedule + xor 18, 18, 14 + xor 19, 19, 15 + ld 21, 0(12) + ld 21, 64(12) + ld 21, 128(12) + ld 21, 192(12) + ld 21, 256(12) + ld 21, 320(12) + ld 21, 384(12) + ld 21, 448(12) + ld 21, 512(12) + ld 21, 576(12) + ld 21, 640(12) + ld 21, 704(12) + ld 21, 768(12) + ld 21, 832(12) + ld 21, 896(12) + ld 21, 960(12) + rldicl 16, 18, 32, 56 + andi. 14, 19, 255 + rldicl 17, 19, 32, 56 + andi. 15, 18, 255 + lbzx 16, 12, 16 + lbzx 14, 12, 14 + lbzx 17, 12, 17 + lbzx 15, 12, 15 + rldimi 14, 16, 32, 24 + rldimi 15, 17, 32, 24 + rldicl 22, 19, 56, 56 + rldicl 23, 19, 24, 56 + rldicl 24, 18, 56, 56 + rldicl 25, 18, 24, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 40, 16 + rlwimi 14, 23, 8, 16, 23 + rldimi 15, 24, 40, 16 + rlwimi 15, 25, 8, 16, 23 + rldicl 22, 19, 16, 56 + rldicl 23, 18, 48, 56 + rldicl 24, 18, 16, 56 + rldicl 25, 19, 48, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + rldimi 14, 22, 48, 8 + rlwimi 14, 23, 16, 8, 15 + rldimi 15, 24, 48, 8 + rlwimi 15, 25, 16, 8, 15 + rldicl 22, 18, 40, 56 + rldicl 23, 18, 8, 56 + rldicl 24, 19, 40, 56 + rldicl 25, 19, 8, 56 + lbzx 22, 12, 22 + lbzx 23, 12, 23 + lbzx 24, 12, 24 + lbzx 25, 12, 25 + ld 18, 0(8) + ld 19, 8(8) + rldimi 14, 22, 56, 0 + rlwimi 14, 23, 24, 0, 7 + rldimi 15, 24, 56, 0 + rlwimi 15, 25, 24, 0, 7 + addi 8, 8, 16 + # XOR in Key Schedule + xor 14, 14, 18 + xor 15, 15, 19 + xor 14, 14, 26 + xor 15, 15, 27 + std 14, 0(4) + std 15, 8(4) +L_AES_XTS_decrypt_done_data: + ld 0, 128(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + ld 26, 96(1) + ld 27, 104(1) + ld 28, 112(1) + ld 29, 120(1) + addi 1, 1, 0x88 + blr +#ifndef __APPLE__ + .size AES_XTS_decrypt,.-AES_XTS_decrypt +#endif /* __APPLE__ */ +#endif /* WOLFSSL_AES_XTS */ +#endif /* HAVE_AES_DECRYPT */ +#ifdef HAVE_AESGCM +#ifdef GCM_TABLE_4BIT +#ifndef __APPLE__ + .text + .section .rodata + .type L_GCM_gmult_len_r, @object + .size L_GCM_gmult_len_r, 128 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_GCM_gmult_len_r: + .long 0x0 + .long 0x1c200000 + .long 0x38400000 + .long 0x24600000 + .long 0x70800000 + .long 0x6ca00000 + .long 0x48c00000 + .long 0x54e00000 + .long 0xe1000000 + .long 0xfd200000 + .long 0xd9400000 + .long 0xc5600000 + .long 0x91800000 + .long 0x8da00000 + .long 0xa9c00000 + .long 0xb5e00000 + .long 0x0 + .long 0x1c20000 + .long 0x3840000 + .long 0x2460000 + .long 0x7080000 + .long 0x6ca0000 + .long 0x48c0000 + .long 0x54e0000 + .long 0xe100000 + .long 0xfd20000 + .long 0xd940000 + .long 0xc560000 + .long 0x9180000 + .long 0x8da0000 + .long 0xa9c0000 + .long 0xb5e0000 +#ifndef __APPLE__ +.text +.globl GCM_gmult_len +.type GCM_gmult_len,@function +.align 16 +GCM_gmult_len: +#else +.section __TEXT,__text +.globl _GCM_gmult_len +.p2align 4 +_GCM_gmult_len: +#endif /* __APPLE__ */ + stdu 1, -104(1) + mflr 0 + std 0, 96(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) + std 20, 48(1) + std 21, 56(1) + std 22, 64(1) + std 23, 72(1) + std 24, 80(1) + std 25, 88(1) + li 21, 0x100 + li 25, 8 +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 7, 2, L_GCM_gmult_len_r@toc@ha + addi 7, 7, L_GCM_gmult_len_r@toc@l +#else + lis 7, L_GCM_gmult_len_r@ha + la 7, L_GCM_gmult_len_r@l(7) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + add 21, 21, 4 + addi 20, 4, 8 + addi 22, 21, 8 + addi 8, 7, 0x40 +L_GCM_gmult_len_start_block: + ldbrx 18, 0, 3 + ldbrx 19, 25, 3 + ldbrx 9, 0, 5 + ldbrx 10, 25, 5 + xor 18, 18, 9 + xor 19, 19, 10 + rldicr 0, 19, 32, 63 + # Byte 15 + rlwinm 23, 0, 12, 24, 27 + rlwinm 24, 0, 8, 24, 27 + ldx 14, 23, 4 + ldx 15, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 14 + rlwinm 23, 0, 20, 24, 27 + rlwinm 24, 0, 16, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 13 + rlwinm 23, 0, 28, 24, 27 + rlwinm 24, 0, 24, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 12 + rlwinm 23, 0, 4, 24, 27 + rlwinm 24, 0, 0, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 11 + rlwinm 23, 19, 12, 24, 27 + rlwinm 24, 19, 8, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 10 + rlwinm 23, 19, 20, 24, 27 + rlwinm 24, 19, 16, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 9 + rlwinm 23, 19, 28, 24, 27 + rlwinm 24, 19, 24, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 8 + rlwinm 23, 19, 4, 24, 27 + rlwinm 24, 19, 0, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + rldicr 0, 18, 32, 63 + # Byte 7 + rlwinm 23, 0, 12, 24, 27 + rlwinm 24, 0, 8, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 6 + rlwinm 23, 0, 20, 24, 27 + rlwinm 24, 0, 16, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 5 + rlwinm 23, 0, 28, 24, 27 + rlwinm 24, 0, 24, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 4 + rlwinm 23, 0, 4, 24, 27 + rlwinm 24, 0, 0, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 3 + rlwinm 23, 18, 12, 24, 27 + rlwinm 24, 18, 8, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 2 + rlwinm 23, 18, 20, 24, 27 + rlwinm 24, 18, 16, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 1 + rlwinm 23, 18, 28, 24, 27 + rlwinm 24, 18, 24, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 21 + ldx 12, 24, 22 + xor 14, 14, 9 + xor 15, 15, 10 + ldx 10, 24, 20 + rldicl 16, 15, 60, 60 + rldic 17, 15, 2, 58 + srdi 15, 15, 8 + rldimi 15, 14, 56, 0 + srdi 14, 14, 8 + lwzx 9, 17, 8 + xor 16, 16, 10 + xor 14, 14, 11 + rlwinm 16, 16, 2, 26, 29 + lwzx 10, 16, 7 + xor 15, 15, 12 + sldi 9, 9, 32 + xor 14, 14, 9 + sldi 10, 10, 32 + xor 14, 14, 10 + # Byte 0 + rlwinm 23, 18, 4, 24, 27 + rlwinm 24, 18, 0, 24, 27 + ldx 9, 23, 4 + ldx 10, 23, 20 + ldx 11, 24, 4 + ldx 12, 24, 20 + xor 14, 14, 9 + xor 15, 15, 10 + rldic 16, 15, 2, 58 + srdi 15, 15, 4 + lwzx 9, 16, 7 + rldimi 15, 14, 60, 0 + srdi 14, 14, 4 + xor 19, 15, 12 + xor 14, 14, 11 + sldi 9, 9, 32 + xor 18, 14, 9 + addi 5, 5, 16 + addic. 6, 6, -16 + std 18, 0(3) + std 19, 8(3) + bne L_GCM_gmult_len_start_block + ld 0, 96(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + ld 20, 48(1) + ld 21, 56(1) + ld 22, 64(1) + ld 23, 72(1) + ld 24, 80(1) + ld 25, 88(1) + addi 1, 1, 0x68 + blr +#ifndef __APPLE__ + .size GCM_gmult_len,.-GCM_gmult_len +#endif /* __APPLE__ */ +#endif /* GCM_TABLE_4BIT */ +#ifdef GCM_TABLE +#ifndef __APPLE__ + .text + .section .rodata + .type L_GCM_gmult_len_r, @object + .size L_GCM_gmult_len_r, 512 +#else + .section __DATA,__data +#endif /* __APPLE__ */ +#ifndef __APPLE__ + .align 4 +#else + .p2align 4 +#endif /* __APPLE__ */ +L_GCM_gmult_len_r: + .byte 0x0 + .byte 0x0 + .byte 0xc2 + .byte 0x1 + .byte 0x84 + .byte 0x3 + .byte 0x46 + .byte 0x2 + .byte 0x8 + .byte 0x7 + .byte 0xca + .byte 0x6 + .byte 0x8c + .byte 0x4 + .byte 0x4e + .byte 0x5 + .byte 0x10 + .byte 0xe + .byte 0xd2 + .byte 0xf + .byte 0x94 + .byte 0xd + .byte 0x56 + .byte 0xc + .byte 0x18 + .byte 0x9 + .byte 0xda + .byte 0x8 + .byte 0x9c + .byte 0xa + .byte 0x5e + .byte 0xb + .byte 0x20 + .byte 0x1c + .byte 0xe2 + .byte 0x1d + .byte 0xa4 + .byte 0x1f + .byte 0x66 + .byte 0x1e + .byte 0x28 + .byte 0x1b + .byte 0xea + .byte 0x1a + .byte 0xac + .byte 0x18 + .byte 0x6e + .byte 0x19 + .byte 0x30 + .byte 0x12 + .byte 0xf2 + .byte 0x13 + .byte 0xb4 + .byte 0x11 + .byte 0x76 + .byte 0x10 + .byte 0x38 + .byte 0x15 + .byte 0xfa + .byte 0x14 + .byte 0xbc + .byte 0x16 + .byte 0x7e + .byte 0x17 + .byte 0x40 + .byte 0x38 + .byte 0x82 + .byte 0x39 + .byte 0xc4 + .byte 0x3b + .byte 0x6 + .byte 0x3a + .byte 0x48 + .byte 0x3f + .byte 0x8a + .byte 0x3e + .byte 0xcc + .byte 0x3c + .byte 0xe + .byte 0x3d + .byte 0x50 + .byte 0x36 + .byte 0x92 + .byte 0x37 + .byte 0xd4 + .byte 0x35 + .byte 0x16 + .byte 0x34 + .byte 0x58 + .byte 0x31 + .byte 0x9a + .byte 0x30 + .byte 0xdc + .byte 0x32 + .byte 0x1e + .byte 0x33 + .byte 0x60 + .byte 0x24 + .byte 0xa2 + .byte 0x25 + .byte 0xe4 + .byte 0x27 + .byte 0x26 + .byte 0x26 + .byte 0x68 + .byte 0x23 + .byte 0xaa + .byte 0x22 + .byte 0xec + .byte 0x20 + .byte 0x2e + .byte 0x21 + .byte 0x70 + .byte 0x2a + .byte 0xb2 + .byte 0x2b + .byte 0xf4 + .byte 0x29 + .byte 0x36 + .byte 0x28 + .byte 0x78 + .byte 0x2d + .byte 0xba + .byte 0x2c + .byte 0xfc + .byte 0x2e + .byte 0x3e + .byte 0x2f + .byte 0x80 + .byte 0x70 + .byte 0x42 + .byte 0x71 + .byte 0x4 + .byte 0x73 + .byte 0xc6 + .byte 0x72 + .byte 0x88 + .byte 0x77 + .byte 0x4a + .byte 0x76 + .byte 0xc + .byte 0x74 + .byte 0xce + .byte 0x75 + .byte 0x90 + .byte 0x7e + .byte 0x52 + .byte 0x7f + .byte 0x14 + .byte 0x7d + .byte 0xd6 + .byte 0x7c + .byte 0x98 + .byte 0x79 + .byte 0x5a + .byte 0x78 + .byte 0x1c + .byte 0x7a + .byte 0xde + .byte 0x7b + .byte 0xa0 + .byte 0x6c + .byte 0x62 + .byte 0x6d + .byte 0x24 + .byte 0x6f + .byte 0xe6 + .byte 0x6e + .byte 0xa8 + .byte 0x6b + .byte 0x6a + .byte 0x6a + .byte 0x2c + .byte 0x68 + .byte 0xee + .byte 0x69 + .byte 0xb0 + .byte 0x62 + .byte 0x72 + .byte 0x63 + .byte 0x34 + .byte 0x61 + .byte 0xf6 + .byte 0x60 + .byte 0xb8 + .byte 0x65 + .byte 0x7a + .byte 0x64 + .byte 0x3c + .byte 0x66 + .byte 0xfe + .byte 0x67 + .byte 0xc0 + .byte 0x48 + .byte 0x2 + .byte 0x49 + .byte 0x44 + .byte 0x4b + .byte 0x86 + .byte 0x4a + .byte 0xc8 + .byte 0x4f + .byte 0xa + .byte 0x4e + .byte 0x4c + .byte 0x4c + .byte 0x8e + .byte 0x4d + .byte 0xd0 + .byte 0x46 + .byte 0x12 + .byte 0x47 + .byte 0x54 + .byte 0x45 + .byte 0x96 + .byte 0x44 + .byte 0xd8 + .byte 0x41 + .byte 0x1a + .byte 0x40 + .byte 0x5c + .byte 0x42 + .byte 0x9e + .byte 0x43 + .byte 0xe0 + .byte 0x54 + .byte 0x22 + .byte 0x55 + .byte 0x64 + .byte 0x57 + .byte 0xa6 + .byte 0x56 + .byte 0xe8 + .byte 0x53 + .byte 0x2a + .byte 0x52 + .byte 0x6c + .byte 0x50 + .byte 0xae + .byte 0x51 + .byte 0xf0 + .byte 0x5a + .byte 0x32 + .byte 0x5b + .byte 0x74 + .byte 0x59 + .byte 0xb6 + .byte 0x58 + .byte 0xf8 + .byte 0x5d + .byte 0x3a + .byte 0x5c + .byte 0x7c + .byte 0x5e + .byte 0xbe + .byte 0x5f + .byte 0x0 + .byte 0xe1 + .byte 0xc2 + .byte 0xe0 + .byte 0x84 + .byte 0xe2 + .byte 0x46 + .byte 0xe3 + .byte 0x8 + .byte 0xe6 + .byte 0xca + .byte 0xe7 + .byte 0x8c + .byte 0xe5 + .byte 0x4e + .byte 0xe4 + .byte 0x10 + .byte 0xef + .byte 0xd2 + .byte 0xee + .byte 0x94 + .byte 0xec + .byte 0x56 + .byte 0xed + .byte 0x18 + .byte 0xe8 + .byte 0xda + .byte 0xe9 + .byte 0x9c + .byte 0xeb + .byte 0x5e + .byte 0xea + .byte 0x20 + .byte 0xfd + .byte 0xe2 + .byte 0xfc + .byte 0xa4 + .byte 0xfe + .byte 0x66 + .byte 0xff + .byte 0x28 + .byte 0xfa + .byte 0xea + .byte 0xfb + .byte 0xac + .byte 0xf9 + .byte 0x6e + .byte 0xf8 + .byte 0x30 + .byte 0xf3 + .byte 0xf2 + .byte 0xf2 + .byte 0xb4 + .byte 0xf0 + .byte 0x76 + .byte 0xf1 + .byte 0x38 + .byte 0xf4 + .byte 0xfa + .byte 0xf5 + .byte 0xbc + .byte 0xf7 + .byte 0x7e + .byte 0xf6 + .byte 0x40 + .byte 0xd9 + .byte 0x82 + .byte 0xd8 + .byte 0xc4 + .byte 0xda + .byte 0x6 + .byte 0xdb + .byte 0x48 + .byte 0xde + .byte 0x8a + .byte 0xdf + .byte 0xcc + .byte 0xdd + .byte 0xe + .byte 0xdc + .byte 0x50 + .byte 0xd7 + .byte 0x92 + .byte 0xd6 + .byte 0xd4 + .byte 0xd4 + .byte 0x16 + .byte 0xd5 + .byte 0x58 + .byte 0xd0 + .byte 0x9a + .byte 0xd1 + .byte 0xdc + .byte 0xd3 + .byte 0x1e + .byte 0xd2 + .byte 0x60 + .byte 0xc5 + .byte 0xa2 + .byte 0xc4 + .byte 0xe4 + .byte 0xc6 + .byte 0x26 + .byte 0xc7 + .byte 0x68 + .byte 0xc2 + .byte 0xaa + .byte 0xc3 + .byte 0xec + .byte 0xc1 + .byte 0x2e + .byte 0xc0 + .byte 0x70 + .byte 0xcb + .byte 0xb2 + .byte 0xca + .byte 0xf4 + .byte 0xc8 + .byte 0x36 + .byte 0xc9 + .byte 0x78 + .byte 0xcc + .byte 0xba + .byte 0xcd + .byte 0xfc + .byte 0xcf + .byte 0x3e + .byte 0xce + .byte 0x80 + .byte 0x91 + .byte 0x42 + .byte 0x90 + .byte 0x4 + .byte 0x92 + .byte 0xc6 + .byte 0x93 + .byte 0x88 + .byte 0x96 + .byte 0x4a + .byte 0x97 + .byte 0xc + .byte 0x95 + .byte 0xce + .byte 0x94 + .byte 0x90 + .byte 0x9f + .byte 0x52 + .byte 0x9e + .byte 0x14 + .byte 0x9c + .byte 0xd6 + .byte 0x9d + .byte 0x98 + .byte 0x98 + .byte 0x5a + .byte 0x99 + .byte 0x1c + .byte 0x9b + .byte 0xde + .byte 0x9a + .byte 0xa0 + .byte 0x8d + .byte 0x62 + .byte 0x8c + .byte 0x24 + .byte 0x8e + .byte 0xe6 + .byte 0x8f + .byte 0xa8 + .byte 0x8a + .byte 0x6a + .byte 0x8b + .byte 0x2c + .byte 0x89 + .byte 0xee + .byte 0x88 + .byte 0xb0 + .byte 0x83 + .byte 0x72 + .byte 0x82 + .byte 0x34 + .byte 0x80 + .byte 0xf6 + .byte 0x81 + .byte 0xb8 + .byte 0x84 + .byte 0x7a + .byte 0x85 + .byte 0x3c + .byte 0x87 + .byte 0xfe + .byte 0x86 + .byte 0xc0 + .byte 0xa9 + .byte 0x2 + .byte 0xa8 + .byte 0x44 + .byte 0xaa + .byte 0x86 + .byte 0xab + .byte 0xc8 + .byte 0xae + .byte 0xa + .byte 0xaf + .byte 0x4c + .byte 0xad + .byte 0x8e + .byte 0xac + .byte 0xd0 + .byte 0xa7 + .byte 0x12 + .byte 0xa6 + .byte 0x54 + .byte 0xa4 + .byte 0x96 + .byte 0xa5 + .byte 0xd8 + .byte 0xa0 + .byte 0x1a + .byte 0xa1 + .byte 0x5c + .byte 0xa3 + .byte 0x9e + .byte 0xa2 + .byte 0xe0 + .byte 0xb5 + .byte 0x22 + .byte 0xb4 + .byte 0x64 + .byte 0xb6 + .byte 0xa6 + .byte 0xb7 + .byte 0xe8 + .byte 0xb2 + .byte 0x2a + .byte 0xb3 + .byte 0x6c + .byte 0xb1 + .byte 0xae + .byte 0xb0 + .byte 0xf0 + .byte 0xbb + .byte 0x32 + .byte 0xba + .byte 0x74 + .byte 0xb8 + .byte 0xb6 + .byte 0xb9 + .byte 0xf8 + .byte 0xbc + .byte 0x3a + .byte 0xbd + .byte 0x7c + .byte 0xbf + .byte 0xbe + .byte 0xbe +#ifndef __APPLE__ +.text +.globl GCM_gmult_len +.type GCM_gmult_len,@function +.align 16 +GCM_gmult_len: +#else +.section __TEXT,__text +.globl _GCM_gmult_len +.p2align 4 +_GCM_gmult_len: +#endif /* __APPLE__ */ + stdu 1, -56(1) + mflr 0 + std 0, 48(1) + std 14, 0(1) + std 15, 8(1) + std 16, 16(1) + std 17, 24(1) + std 18, 32(1) + std 19, 40(1) +#if defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) + addis 7, 2, L_GCM_gmult_len_r@toc@ha + addi 7, 7, L_GCM_gmult_len_r@toc@l +#else + lis 7, L_GCM_gmult_len_r@ha + la 7, L_GCM_gmult_len_r@l(7) +#endif /* defined(__ARCH_PWR8) || (defined(_ARCH_PWR8)) */ + addi 0, 4, 8 + li 17, 8 +L_GCM_gmult_len_start_block: + ldbrx 8, 0, 3 + ldbrx 9, 17, 3 + ldbrx 10, 0, 5 + ldbrx 11, 17, 5 + xor 8, 8, 10 + xor 9, 9, 11 + rldicr 19, 9, 32, 63 + rldicr 18, 8, 32, 63 + rlwinm 16, 19, 12, 20, 27 + # Byte 15 + ldx 12, 16, 4 + ldx 14, 16, 0 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 19, 20, 20, 27 + xor 12, 12, 10 + # Byte 14 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 19, 28, 20, 27 + xor 12, 12, 10 + # Byte 13 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 19, 4, 20, 27 + xor 12, 12, 10 + # Byte 12 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 9, 12, 20, 27 + xor 12, 12, 10 + # Byte 11 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 9, 20, 20, 27 + xor 12, 12, 10 + # Byte 10 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 9, 28, 20, 27 + xor 12, 12, 10 + # Byte 9 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 9, 4, 20, 27 + xor 12, 12, 10 + # Byte 8 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 18, 12, 20, 27 + xor 12, 12, 10 + # Byte 7 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 18, 20, 20, 27 + xor 12, 12, 10 + # Byte 6 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 18, 28, 20, 27 + xor 12, 12, 10 + # Byte 5 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 18, 4, 20, 27 + xor 12, 12, 10 + # Byte 4 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 8, 12, 20, 27 + xor 12, 12, 10 + # Byte 3 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 8, 20, 20, 27 + xor 12, 12, 10 + # Byte 2 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 8, 28, 20, 27 + xor 12, 12, 10 + # Byte 1 + ldx 10, 16, 4 + ldx 11, 16, 0 + xor 12, 12, 10 + xor 14, 14, 11 + rldicl 11, 12, 8, 56 + rldicl 15, 14, 9, 55 + sldi 14, 14, 8 + andi. 15, 15, 510 + sldi 12, 12, 8 + lhzx 10, 15, 7 + xor 14, 14, 11 + rlwinm 16, 8, 4, 20, 27 + xor 12, 12, 10 + # Byte 0 + ldx 10, 16, 4 + ldx 11, 16, 0 + addi 5, 5, 16 + addic. 6, 6, -16 + xor 8, 12, 10 + xor 9, 14, 11 + stdbrx 8, 0, 3 + stdbrx 9, 17, 3 + bne L_GCM_gmult_len_start_block + ld 0, 48(1) + mtlr 0 + ld 14, 0(1) + ld 15, 8(1) + ld 16, 16(1) + ld 17, 24(1) + ld 18, 32(1) + ld 19, 40(1) + addi 1, 1, 56 + blr +#ifndef __APPLE__ + .size GCM_gmult_len,.-GCM_gmult_len +#endif /* __APPLE__ */ +#endif /* GCM_TABLE */ +#endif /* HAVE_AESGCM */ +#endif /* !defined(NO_AES) && defined(WOLFSSL_PPC64_ASM) */ +#endif /* WOLFSSL_PPC64_ASM */ + +#if defined(__linux__) && defined(__ELF__) +.section .note.GNU-stack,"",%progbits +#endif +#endif /* !WOLFSSL_PPC64_ASM_INLINE */ diff --git a/wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c b/wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c new file mode 100644 index 0000000000..d0c25755aa --- /dev/null +++ b/wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.c @@ -0,0 +1,6648 @@ +/* ppc64-aes-asm + * + * Copyright (C) 2006-2025 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include +#include + +/* Generated using (from wolfssl): + * cd ../scripts + * ruby ./aes/aes.rb ppc64 \ + * ../wolfssl/wolfcrypt/src/port/ppc64/ppc64-aes-asm.c + */ +#ifdef WOLFSSL_PPC64_ASM +#include +#include +#ifdef WOLFSSL_PPC64_ASM_INLINE + +#ifdef __IAR_SYSTEMS_ICC__ +#define __asm__ asm +#define __volatile__ volatile +#define WOLFSSL_NO_VAR_ASSIGN_REG +#endif /* __IAR_SYSTEMS_ICC__ */ +#ifdef __KEIL__ +#define __asm__ __asm +#define __volatile__ volatile +#endif /* __KEIL__ */ +#ifdef __ghs__ +#define __asm__ __asm +#define __volatile__ +#define WOLFSSL_NO_VAR_ASSIGN_REG +#endif /* __ghs__ */ +#include + +#if !defined(NO_AES) && defined(WOLFSSL_PPC64_ASM) +#ifdef HAVE_AES_DECRYPT +static const word32 L_AES_PPC64_td[] = { + 0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, + 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, + 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, + 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, + 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, + 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, + 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, + 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, + 0x6a75c289, 0x78f48e79, 0x6b99583e, 0xdd27b971, + 0xb6bee14f, 0x17f088ad, 0x66c920ac, 0xb47dce3a, + 0x1863df4a, 0x82e51a31, 0x60975133, 0x4562537f, + 0xe0b16477, 0x84bb6bae, 0x1cfe81a0, 0x94f9082b, + 0x58704868, 0x198f45fd, 0x8794de6c, 0xb7527bf8, + 0x23ab73d3, 0xe2724b02, 0x57e31f8f, 0x2a6655ab, + 0x07b2eb28, 0x032fb5c2, 0x9a86c57b, 0xa5d33708, + 0xf2302887, 0xb223bfa5, 0xba02036a, 0x5ced1682, + 0x2b8acf1c, 0x92a779b4, 0xf0f307f2, 0xa14e69e2, + 0xcd65daf4, 0xd50605be, 0x1fd13462, 0x8ac4a6fe, + 0x9d342e53, 0xa0a2f355, 0x32058ae1, 0x75a4f6eb, + 0x390b83ec, 0xaa4060ef, 0x065e719f, 0x51bd6e10, + 0xf93e218a, 0x3d96dd06, 0xaedd3e05, 0x464de6bd, + 0xb591548d, 0x0571c45d, 0x6f0406d4, 0xff605015, + 0x241998fb, 0x97d6bde9, 0xcc894043, 0x7767d99e, + 0xbdb0e842, 0x8807898b, 0x38e7195b, 0xdb79c8ee, + 0x47a17c0a, 0xe97c420f, 0xc9f8841e, 0x00000000, + 0x83098086, 0x48322bed, 0xac1e1170, 0x4e6c5a72, + 0xfbfd0eff, 0x560f8538, 0x1e3daed5, 0x27362d39, + 0x640a0fd9, 0x21685ca6, 0xd19b5b54, 0x3a24362e, + 0xb10c0a67, 0x0f9357e7, 0xd2b4ee96, 0x9e1b9b91, + 0x4f80c0c5, 0xa261dc20, 0x695a774b, 0x161c121a, + 0x0ae293ba, 0xe5c0a02a, 0x433c22e0, 0x1d121b17, + 0x0b0e090d, 0xadf28bc7, 0xb92db6a8, 0xc8141ea9, + 0x8557f119, 0x4caf7507, 0xbbee99dd, 0xfda37f60, + 0x9ff70126, 0xbc5c72f5, 0xc544663b, 0x345bfb7e, + 0x768b4329, 0xdccb23c6, 0x68b6edfc, 0x63b8e4f1, + 0xcad731dc, 0x10426385, 0x40139722, 0x2084c611, + 0x7d854a24, 0xf8d2bb3d, 0x11aef932, 0x6dc729a1, + 0x4b1d9e2f, 0xf3dcb230, 0xec0d8652, 0xd077c1e3, + 0x6c2bb316, 0x99a970b9, 0xfa119448, 0x2247e964, + 0xc4a8fc8c, 0x1aa0f03f, 0xd8567d2c, 0xef223390, + 0xc787494e, 0xc1d938d1, 0xfe8ccaa2, 0x3698d40b, + 0xcfa6f581, 0x28a57ade, 0x26dab78e, 0xa43fadbf, + 0xe42c3a9d, 0x0d507892, 0x9b6a5fcc, 0x62547e46, + 0xc2f68d13, 0xe890d8b8, 0x5e2e39f7, 0xf582c3af, + 0xbe9f5d80, 0x7c69d093, 0xa96fd52d, 0xb3cf2512, + 0x3bc8ac99, 0xa710187d, 0x6ee89c63, 0x7bdb3bbb, + 0x09cd2678, 0xf46e5918, 0x01ec9ab7, 0xa8834f9a, + 0x65e6956e, 0x7eaaffe6, 0x0821bccf, 0xe6ef15e8, + 0xd9bae79b, 0xce4a6f36, 0xd4ea9f09, 0xd629b07c, + 0xaf31a4b2, 0x312a3f23, 0x30c6a594, 0xc035a266, + 0x37744ebc, 0xa6fc82ca, 0xb0e090d0, 0x1533a7d8, + 0x4af10498, 0xf741ecda, 0x0e7fcd50, 0x2f1791f6, + 0x8d764dd6, 0x4d43efb0, 0x54ccaa4d, 0xdfe49604, + 0xe39ed1b5, 0x1b4c6a88, 0xb8c12c1f, 0x7f466551, + 0x049d5eea, 0x5d018c35, 0x73fa8774, 0x2efb0b41, + 0x5ab3671d, 0x5292dbd2, 0x33e91056, 0x136dd647, + 0x8c9ad761, 0x7a37a10c, 0x8e59f814, 0x89eb133c, + 0xeecea927, 0x35b761c9, 0xede11ce5, 0x3c7a47b1, + 0x599cd2df, 0x3f55f273, 0x791814ce, 0xbf73c737, + 0xea53f7cd, 0x5b5ffdaa, 0x14df3d6f, 0x867844db, + 0x81caaff3, 0x3eb968c4, 0x2c382434, 0x5fc2a340, + 0x72161dc3, 0x0cbce225, 0x8b283c49, 0x41ff0d95, + 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, + 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857, +}; + +#endif /* HAVE_AES_DECRYPT */ +#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AES_CBC) || \ + defined(HAVE_AESCCM) || defined(HAVE_AESGCM) || \ + defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) +static const word32 L_AES_PPC64_te[] = { + 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, + 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, + 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, + 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, + 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, + 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, + 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, + 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, + 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, + 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, + 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, + 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, + 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, + 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, + 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, + 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, + 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, + 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, + 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, + 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, + 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, + 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, + 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, + 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, + 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, + 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, + 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, + 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, + 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, + 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, + 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, + 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, + 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, + 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, + 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, + 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, + 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, + 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, + 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, + 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, + 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, + 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, + 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, + 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, + 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, + 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, + 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, + 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, + 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, + 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, + 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, + 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, + 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, + 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, + 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, + 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, + 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, + 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, + 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, + 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, + 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, + 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, + 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, + 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616, +}; + +#endif /* HAVE_AES_DECRYPT || HAVE_AES_CBC || HAVE_AESCCM || HAVE_AESGCM || + * WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER */ +#ifdef HAVE_AES_DECRYPT +void AES_invert_key(unsigned char* ks, word32 rounds); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_invert_key(unsigned char* ks_p, word32 rounds_p) +#else +void AES_invert_key(unsigned char* ks, word32 rounds) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register unsigned char* ks asm ("3") = (unsigned char*)ks_p; + register word32 rounds asm ("4") = (word32)rounds_p; + register word32* L_AES_PPC64_te_c asm ("5") = (word32*)&L_AES_PPC64_te; + register word32* L_AES_PPC64_td_c asm ("6") = (word32*)&L_AES_PPC64_td; +#else + register word32* L_AES_PPC64_te_c = (word32*)&L_AES_PPC64_te; + register word32* L_AES_PPC64_td_c = (word32*)&L_AES_PPC64_td; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 5, %[L_AES_PPC64_te]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 6, %[L_AES_PPC64_td]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 5, 5, 3\n\t" + "sldi 16, %[rounds], 4\n\t" + "add 16, 16, %[ks]\n\t" + "ld 7, 0(%[ks])\n\t" + "ld 8, 8(%[ks])\n\t" + "ld 11, 0(16)\n\t" + "ld 12, 8(16)\n\t" + "rldicr 7, 7, 32, 63\n\t" + "rldicr 8, 8, 32, 63\n\t" + "rldicr 11, 11, 32, 63\n\t" + "rldicr 12, 12, 32, 63\n\t" + "std 7, 0(16)\n\t" + "std 8, 8(16)\n\t" + "std 11, 0(%[ks])\n\t" + "std 12, 8(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "addi 16, 16, -16\n\t" + "addi 0, %[rounds], -2\n\t" + "srdi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_invert_key_loop_%=: \n\t" + "ld 7, 0(%[ks])\n\t" + "ld 8, 8(%[ks])\n\t" + "ld 11, 0(16)\n\t" + "ld 12, 8(16)\n\t" + "std 7, 0(16)\n\t" + "std 8, 8(16)\n\t" + "std 11, 0(%[ks])\n\t" + "std 12, 8(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "addi 16, 16, -16\n\t" + "bdnz L_AES_invert_key_loop_%=\n\t" + "sldi 16, %[rounds], 3\n\t" + "subf %[ks], 16, %[ks]\n\t" + "addi %[ks], %[ks], 16\n\t" + "addi 0, %[rounds], -1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_invert_key_mix_loop_%=: \n\t" + "lwz 8, 0(%[ks])\n\t" + "lwz 7, 4(%[ks])\n\t" + "lwz 10, 8(%[ks])\n\t" + "lwz 9, 12(%[ks])\n\t" + "rlwinm 11, 7, 2, 22, 29\n\t" + "rlwinm 12, 7, 26, 22, 29\n\t" + "rlwinm 14, 7, 18, 22, 29\n\t" + "rlwinm 15, 7, 10, 22, 29\n\t" + "lbzx 11, 5, 11\n\t" + "lbzx 12, 5, 12\n\t" + "lbzx 14, 5, 14\n\t" + "lbzx 15, 5, 15\n\t" + "slwi 11, 11, 2\n\t" + "slwi 12, 12, 2\n\t" + "slwi 14, 14, 2\n\t" + "slwi 15, 15, 2\n\t" + "lwzx 11, 6, 11\n\t" + "lwzx 12, 6, 12\n\t" + "lwzx 14, 6, 14\n\t" + "lwzx 15, 6, 15\n\t" + "rlwimi 11, 11, 16, 0, 31\n\t" + "rlwimi 12, 12, 24, 0, 31\n\t" + "rlwimi 15, 15, 8, 0, 31\n\t" + "xor 14, 14, 11\n\t" + "xor 14, 14, 12\n\t" + "xor 14, 14, 15\n\t" + "stw 14, 4(%[ks])\n\t" + "rlwinm 11, 8, 2, 22, 29\n\t" + "rlwinm 12, 8, 26, 22, 29\n\t" + "rlwinm 14, 8, 18, 22, 29\n\t" + "rlwinm 15, 8, 10, 22, 29\n\t" + "lbzx 11, 5, 11\n\t" + "lbzx 12, 5, 12\n\t" + "lbzx 14, 5, 14\n\t" + "lbzx 15, 5, 15\n\t" + "slwi 11, 11, 2\n\t" + "slwi 12, 12, 2\n\t" + "slwi 14, 14, 2\n\t" + "slwi 15, 15, 2\n\t" + "lwzx 11, 6, 11\n\t" + "lwzx 12, 6, 12\n\t" + "lwzx 14, 6, 14\n\t" + "lwzx 15, 6, 15\n\t" + "rlwimi 11, 11, 16, 0, 31\n\t" + "rlwimi 12, 12, 24, 0, 31\n\t" + "rlwimi 15, 15, 8, 0, 31\n\t" + "xor 14, 14, 11\n\t" + "xor 14, 14, 12\n\t" + "xor 14, 14, 15\n\t" + "stw 14, 0(%[ks])\n\t" + "addi %[ks], %[ks], 8\n\t" + "rlwinm 11, 9, 2, 22, 29\n\t" + "rlwinm 12, 9, 26, 22, 29\n\t" + "rlwinm 14, 9, 18, 22, 29\n\t" + "rlwinm 15, 9, 10, 22, 29\n\t" + "lbzx 11, 5, 11\n\t" + "lbzx 12, 5, 12\n\t" + "lbzx 14, 5, 14\n\t" + "lbzx 15, 5, 15\n\t" + "slwi 11, 11, 2\n\t" + "slwi 12, 12, 2\n\t" + "slwi 14, 14, 2\n\t" + "slwi 15, 15, 2\n\t" + "lwzx 11, 6, 11\n\t" + "lwzx 12, 6, 12\n\t" + "lwzx 14, 6, 14\n\t" + "lwzx 15, 6, 15\n\t" + "rlwimi 11, 11, 16, 0, 31\n\t" + "rlwimi 12, 12, 24, 0, 31\n\t" + "rlwimi 15, 15, 8, 0, 31\n\t" + "xor 14, 14, 11\n\t" + "xor 14, 14, 12\n\t" + "xor 14, 14, 15\n\t" + "stw 14, 4(%[ks])\n\t" + "rlwinm 11, 10, 2, 22, 29\n\t" + "rlwinm 12, 10, 26, 22, 29\n\t" + "rlwinm 14, 10, 18, 22, 29\n\t" + "rlwinm 15, 10, 10, 22, 29\n\t" + "lbzx 11, 5, 11\n\t" + "lbzx 12, 5, 12\n\t" + "lbzx 14, 5, 14\n\t" + "lbzx 15, 5, 15\n\t" + "slwi 11, 11, 2\n\t" + "slwi 12, 12, 2\n\t" + "slwi 14, 14, 2\n\t" + "slwi 15, 15, 2\n\t" + "lwzx 11, 6, 11\n\t" + "lwzx 12, 6, 12\n\t" + "lwzx 14, 6, 14\n\t" + "lwzx 15, 6, 15\n\t" + "rlwimi 11, 11, 16, 0, 31\n\t" + "rlwimi 12, 12, 24, 0, 31\n\t" + "rlwimi 15, 15, 8, 0, 31\n\t" + "xor 14, 14, 11\n\t" + "xor 14, 14, 12\n\t" + "xor 14, 14, 15\n\t" + "stw 14, 0(%[ks])\n\t" + "addi %[ks], %[ks], 8\n\t" + "bdnz L_AES_invert_key_mix_loop_%=\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [ks] "+r" (ks), [rounds] "+r" (rounds), + [L_AES_PPC64_te] "+r" (L_AES_PPC64_te_c), + [L_AES_PPC64_td] "+r" (L_AES_PPC64_td_c) + : + : "memory", "cc", "0", "7", "8", "9", "10", "11", "12", "14", "15", + "16" +#else + : + : [ks] "r" (ks), [rounds] "r" (rounds), + [L_AES_PPC64_te] "r" (L_AES_PPC64_te_c), + [L_AES_PPC64_td] "r" (L_AES_PPC64_td_c) + : "memory", "cc", "0", "5", "6", "7", "8", "9", "10", "11", "12", "14", + "15", "16" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* HAVE_AES_DECRYPT */ +static const word32 L_AES_PPC64_rcon[] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1b000000, 0x36000000 +}; + +void AES_set_encrypt_key(const unsigned char* key, word32 len, + unsigned char* ks); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_set_encrypt_key(const unsigned char* key_p, word32 len_p, + unsigned char* ks_p) +#else +void AES_set_encrypt_key(const unsigned char* key, word32 len, + unsigned char* ks) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* key asm ("3") = (const unsigned char*)key_p; + register word32 len asm ("4") = (word32)len_p; + register unsigned char* ks asm ("5") = (unsigned char*)ks_p; + register word32* L_AES_PPC64_te_c asm ("6") = (word32*)&L_AES_PPC64_te; + register word32* L_AES_PPC64_rcon_c asm ("7") = (word32*)&L_AES_PPC64_rcon; +#else + register word32* L_AES_PPC64_te_c = (word32*)&L_AES_PPC64_te; + register word32* L_AES_PPC64_rcon_c = (word32*)&L_AES_PPC64_rcon; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 6, %[L_AES_PPC64_te]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 7, %[L_AES_PPC64_rcon]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 6, 6, 3\n\t" + "cmplwi %[len], 0x80\n\t" + "beq L_AES_set_encrypt_key_start_128_%=\n\t" + "cmplwi %[len], 0xc0\n\t" + "beq L_AES_set_encrypt_key_start_192_%=\n\t" + "ld 9, 0(%[key])\n\t" + "ld 10, 8(%[key])\n\t" + "ld 11, 16(%[key])\n\t" + "ld 12, 24(%[key])\n\t" + "rldicr 9, 9, 32, 63\n\t" + "rldicr 10, 10, 32, 63\n\t" + "rldicr 11, 11, 32, 63\n\t" + "rldicr 12, 12, 32, 63\n\t" + "std 9, 0(%[ks])\n\t" + "std 10, 8(%[ks])\n\t" + "std 11, 16(%[ks])\n\t" + "std 12, 24(%[ks])\n\t" + "rldicr 12, 12, 32, 63\n\t" + "li 8, 6\n\t" + "mtctr 8\n\t" + "\n" + "L_AES_set_encrypt_key_loop_256_%=: \n\t" + "rlwinm 9, 12, 2, 22, 29\n\t" + "rlwinm 10, 12, 26, 22, 29\n\t" + "rlwinm 11, 12, 18, 22, 29\n\t" + "rlwinm 12, 12, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 12\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 10, 16(%[ks])\n\t" + "stw 9, 20(%[ks])\n\t" + "stw 12, 24(%[ks])\n\t" + "stw 11, 28(%[ks])\n\t" + "rlwinm 9, 12, 26, 22, 29\n\t" + "rlwinm 10, 12, 18, 22, 29\n\t" + "rlwinm 11, 12, 10, 22, 29\n\t" + "rlwinm 12, 12, 2, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 12\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 10, 16(%[ks])\n\t" + "stw 9, 20(%[ks])\n\t" + "stw 12, 24(%[ks])\n\t" + "stw 11, 28(%[ks])\n\t" + "bdnz L_AES_set_encrypt_key_loop_256_%=\n\t" + "rlwinm 9, 12, 2, 22, 29\n\t" + "rlwinm 10, 12, 26, 22, 29\n\t" + "rlwinm 11, 12, 18, 22, 29\n\t" + "rlwinm 12, 12, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 12\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 9, 16(%[ks])\n\t" + "stw 10, 20(%[ks])\n\t" + "stw 11, 24(%[ks])\n\t" + "stw 12, 28(%[ks])\n\t" + "b L_AES_set_encrypt_key_end_%=\n\t" + "\n" + "L_AES_set_encrypt_key_start_192_%=: \n\t" + "ld 12, 0(%[key])\n\t" + "ld 14, 8(%[key])\n\t" + "ld 15, 16(%[key])\n\t" + "rldicr 12, 12, 32, 63\n\t" + "rldicr 14, 14, 32, 63\n\t" + "rldicr 15, 15, 32, 63\n\t" + "std 12, 0(%[ks])\n\t" + "std 14, 8(%[ks])\n\t" + "std 15, 16(%[ks])\n\t" + "rldicr 15, 15, 32, 63\n\t" + "li 8, 7\n\t" + "mtctr 8\n\t" + "\n" + "L_AES_set_encrypt_key_loop_192_%=: \n\t" + "rlwinm 9, 15, 2, 22, 29\n\t" + "rlwinm 10, 15, 26, 22, 29\n\t" + "rlwinm 11, 15, 18, 22, 29\n\t" + "rlwinm 15, 15, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 15\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "lwz 15, 16(%[ks])\n\t" + "lwz 14, 20(%[ks])\n\t" + "addi %[ks], %[ks], 24\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "xor 14, 14, 12\n\t" + "xor 15, 15, 14\n\t" + "stw 10, 0(%[ks])\n\t" + "stw 9, 4(%[ks])\n\t" + "stw 12, 8(%[ks])\n\t" + "stw 11, 12(%[ks])\n\t" + "stw 15, 16(%[ks])\n\t" + "stw 14, 20(%[ks])\n\t" + "bdnz L_AES_set_encrypt_key_loop_192_%=\n\t" + "rlwinm 9, 15, 2, 22, 29\n\t" + "rlwinm 10, 15, 26, 22, 29\n\t" + "rlwinm 11, 15, 18, 22, 29\n\t" + "rlwinm 15, 15, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 15\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "lwz 15, 16(%[ks])\n\t" + "lwz 14, 20(%[ks])\n\t" + "addi %[ks], %[ks], 24\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 9, 0(%[ks])\n\t" + "stw 10, 4(%[ks])\n\t" + "stw 11, 8(%[ks])\n\t" + "stw 12, 12(%[ks])\n\t" + "b L_AES_set_encrypt_key_end_%=\n\t" + "\n" + "L_AES_set_encrypt_key_start_128_%=: \n\t" + "li 8, 0\n\t" + "ld 11, 0(%[key])\n\t" + "ld 12, 8(%[key])\n\t" + "rldicr 11, 11, 32, 63\n\t" + "rldicr 12, 12, 32, 63\n\t" + "std 11, 0(%[ks])\n\t" + "std 12, 8(%[ks])\n\t" + "rldicr 12, 12, 32, 63\n\t" + "li 8, 9\n\t" + "mtctr 8\n\t" + "\n" + "L_AES_set_encrypt_key_loop_128_%=: \n\t" + "rlwinm 9, 12, 2, 22, 29\n\t" + "rlwinm 10, 12, 26, 22, 29\n\t" + "rlwinm 11, 12, 18, 22, 29\n\t" + "rlwinm 12, 12, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 12\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 10, 0(%[ks])\n\t" + "stw 9, 4(%[ks])\n\t" + "stw 12, 8(%[ks])\n\t" + "stw 11, 12(%[ks])\n\t" + "bdnz L_AES_set_encrypt_key_loop_128_%=\n\t" + "rlwinm 9, 12, 2, 22, 29\n\t" + "rlwinm 10, 12, 26, 22, 29\n\t" + "rlwinm 11, 12, 18, 22, 29\n\t" + "rlwinm 12, 12, 10, 22, 29\n\t" + "lbzx 9, 6, 9\n\t" + "lbzx 10, 6, 10\n\t" + "lbzx 11, 6, 11\n\t" + "lbzx 0, 6, 12\n\t" + "rlwimi 0, 9, 8, 16, 23\n\t" + "rlwimi 0, 10, 16, 8, 15\n\t" + "rlwimi 0, 11, 24, 0, 7\n\t" + "lwz 10, 0(%[ks])\n\t" + "lwz 9, 4(%[ks])\n\t" + "lwz 12, 8(%[ks])\n\t" + "lwz 11, 12(%[ks])\n\t" + "addi %[ks], %[ks], 16\n\t" + "xor 9, 9, 0\n\t" + "lwz 0, 0(7)\n\t" + "addi 7, 7, 4\n\t" + "xor 9, 9, 0\n\t" + "xor 10, 10, 9\n\t" + "xor 11, 11, 10\n\t" + "xor 12, 12, 11\n\t" + "stw 9, 0(%[ks])\n\t" + "stw 10, 4(%[ks])\n\t" + "stw 11, 8(%[ks])\n\t" + "stw 12, 12(%[ks])\n\t" + "\n" + "L_AES_set_encrypt_key_end_%=: \n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [key] "+r" (key), [len] "+r" (len), [ks] "+r" (ks), + [L_AES_PPC64_te] "+r" (L_AES_PPC64_te_c), + [L_AES_PPC64_rcon] "+r" (L_AES_PPC64_rcon_c) + : + : "memory", "cc", "0", "8", "9", "10", "11", "12", "14", "15" +#else + : + : [key] "r" (key), [len] "r" (len), [ks] "r" (ks), + [L_AES_PPC64_te] "r" (L_AES_PPC64_te_c), + [L_AES_PPC64_rcon] "r" (L_AES_PPC64_rcon_c) + : "memory", "cc", "0", "6", "7", "8", "9", "10", "11", "12", "14", "15" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +static const word32 L_AES_PPC64_te4_0[] = { + 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, + 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, + 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, + 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, + 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, + 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, + 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, + 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, + 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, + 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, + 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, + 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, + 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, + 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, + 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, + 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, + 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, + 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, + 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, + 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, + 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, + 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, + 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, + 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, + 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, + 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, + 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, + 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, + 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, + 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, + 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, + 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, + 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, + 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, + 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, + 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, + 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, + 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, + 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, + 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, + 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, + 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, + 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, + 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, + 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, + 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, + 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, + 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, + 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, + 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, + 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, + 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, + 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, + 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, + 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, + 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, + 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, + 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, + 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, + 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, + 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, + 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, + 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, + 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a, + 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, + 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, + 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, + 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, + 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, + 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, + 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, + 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, + 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, + 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, + 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, + 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, + 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, + 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, + 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, + 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, + 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, + 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, + 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, + 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, + 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, + 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, + 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, + 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, + 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, + 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, + 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, + 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, + 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, + 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, + 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, + 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, + 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, + 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, + 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, + 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, + 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, + 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, + 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, + 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, + 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, + 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, + 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, + 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, + 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, + 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, + 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, + 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, + 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, + 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, + 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, + 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, + 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, + 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, + 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, + 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, + 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, + 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, + 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, + 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, + 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, + 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, + 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, + 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616, + 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, + 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, + 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, + 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, + 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, + 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, + 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, + 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, + 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, + 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, + 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, + 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, + 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, + 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, + 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, + 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, + 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, + 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, + 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, + 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, + 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, + 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, + 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, + 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, + 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, + 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, + 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, + 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, + 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, + 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, + 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, + 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, + 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, + 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, + 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, + 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, + 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, + 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, + 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, + 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, + 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, + 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, + 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, + 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, + 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, + 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, + 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, + 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, + 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, + 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, + 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, + 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, + 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, + 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, + 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, + 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, + 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, + 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, + 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, + 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, + 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, + 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, + 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, + 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16, + 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, + 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, + 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, + 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, + 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, + 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, + 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, + 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, + 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, + 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, + 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, + 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, + 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, + 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, + 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, + 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, + 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, + 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, + 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, + 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, + 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, + 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, + 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, + 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, + 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, + 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, + 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, + 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, + 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, + 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, + 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, + 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, + 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, + 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, + 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, + 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, + 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, + 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, + 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, + 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, + 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, + 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, + 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, + 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, + 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, + 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, + 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, + 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, + 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, + 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, + 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, + 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, + 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, + 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, + 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, + 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, + 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, + 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, + 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, + 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, + 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, + 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, + 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, + 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c, +}; + +#if defined(HAVE_AESCCM) || defined(HAVE_AESGCM) || \ + defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || \ + defined(HAVE_AES_ECB) +void AES_ECB_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_ECB_encrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p) +#else +void AES_ECB_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register word32* L_AES_PPC64_te4_0_c asm ("8") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 8, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 9, 8, 0x400\n\t" + "addi 10, 8, 0x800\n\t" + "addi 11, 8, 0xc00\n\t" + "\n" + "L_AES_ECB_encrypt_loop_block_128_%=: \n\t" + "addi 25, %[ks], 0\n\t" + "ld 12, 0(%[in])\n\t" + "ld 14, 8(%[in])\n\t" + "ld 17, 0(25)\n\t" + "ld 18, 8(25)\n\t" + "addi 25, 25, 16\n\t" + "rldicr 12, 12, 32, 63\n\t" + "rldicr 14, 14, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 12, 12, 17\n\t" + "xor 14, 14, 18\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 20, 0(8)\n\t" + "ld 20, 64(8)\n\t" + "ld 20, 128(8)\n\t" + "ld 20, 192(8)\n\t" + "ld 20, 256(8)\n\t" + "ld 20, 320(8)\n\t" + "ld 20, 384(8)\n\t" + "ld 20, 448(8)\n\t" + "ld 20, 512(8)\n\t" + "ld 20, 576(8)\n\t" + "ld 20, 640(8)\n\t" + "ld 20, 704(8)\n\t" + "ld 20, 768(8)\n\t" + "ld 20, 832(8)\n\t" + "ld 20, 896(8)\n\t" + "ld 20, 960(8)\n\t" + "ld 20, 1024(8)\n\t" + "ld 20, 1088(8)\n\t" + "ld 20, 1152(8)\n\t" + "ld 20, 1216(8)\n\t" + "ld 20, 1280(8)\n\t" + "ld 20, 1344(8)\n\t" + "ld 20, 1408(8)\n\t" + "ld 20, 1472(8)\n\t" + "ld 20, 1536(8)\n\t" + "ld 20, 1600(8)\n\t" + "ld 20, 1664(8)\n\t" + "ld 20, 1728(8)\n\t" + "ld 20, 1792(8)\n\t" + "ld 20, 1856(8)\n\t" + "ld 20, 1920(8)\n\t" + "ld 20, 1984(8)\n\t" + "ld 20, 2048(8)\n\t" + "ld 20, 2112(8)\n\t" + "ld 20, 2176(8)\n\t" + "ld 20, 2240(8)\n\t" + "ld 20, 2304(8)\n\t" + "ld 20, 2368(8)\n\t" + "ld 20, 2432(8)\n\t" + "ld 20, 2496(8)\n\t" + "ld 20, 2560(8)\n\t" + "ld 20, 2624(8)\n\t" + "ld 20, 2688(8)\n\t" + "ld 20, 2752(8)\n\t" + "ld 20, 2816(8)\n\t" + "ld 20, 2880(8)\n\t" + "ld 20, 2944(8)\n\t" + "ld 20, 3008(8)\n\t" + "ld 20, 3072(8)\n\t" + "ld 20, 3136(8)\n\t" + "ld 20, 3200(8)\n\t" + "ld 20, 3264(8)\n\t" + "ld 20, 3328(8)\n\t" + "ld 20, 3392(8)\n\t" + "ld 20, 3456(8)\n\t" + "ld 20, 3520(8)\n\t" + "ld 20, 3584(8)\n\t" + "ld 20, 3648(8)\n\t" + "ld 20, 3712(8)\n\t" + "ld 20, 3776(8)\n\t" + "ld 20, 3840(8)\n\t" + "ld 20, 3904(8)\n\t" + "ld 20, 3968(8)\n\t" + "ld 20, 4032(8)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_ECB_encrypt_loop_nr_%=: \n\t" + "srdi 15, 12, 32\n\t" + "srdi 16, 14, 32\n\t" + "rlwinm 17, 12, 10, 22, 29\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "lwzx 17, 8, 17\n\t" + "lwzx 18, 8, 18\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "rlwinm 22, 14, 18, 22, 29\n\t" + "rlwinm 23, 16, 18, 22, 29\n\t" + "rlwinm 24, 12, 18, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "rlwinm 21, 14, 26, 22, 29\n\t" + "rlwinm 22, 16, 26, 22, 29\n\t" + "rlwinm 23, 12, 26, 22, 29\n\t" + "rlwinm 24, 15, 26, 22, 29\n\t" + "lwzx 21, 10, 21\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "rlwinm 21, 16, 2, 22, 29\n\t" + "rlwinm 22, 12, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 14, 2, 22, 29\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "ld 12, 0(25)\n\t" + "ld 14, 8(25)\n\t" + "rldimi 17, 19, 32, 0\n\t" + "rldimi 18, 20, 32, 0\n\t" + "addi 25, 25, 16\n\t" + /* XOR in Key Schedule */ + "xor 17, 17, 12\n\t" + "xor 18, 18, 14\n\t" + "srdi 19, 17, 32\n\t" + "srdi 20, 18, 32\n\t" + "rlwinm 12, 17, 10, 22, 29\n\t" + "rlwinm 14, 18, 10, 22, 29\n\t" + "rlwinm 15, 19, 10, 22, 29\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "lwzx 12, 8, 12\n\t" + "lwzx 14, 8, 14\n\t" + "lwzx 15, 8, 15\n\t" + "lwzx 16, 8, 16\n\t" + "rlwinm 21, 19, 18, 22, 29\n\t" + "rlwinm 22, 18, 18, 22, 29\n\t" + "rlwinm 23, 20, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "xor 12, 12, 21\n\t" + "xor 15, 15, 22\n\t" + "xor 14, 14, 23\n\t" + "xor 16, 16, 24\n\t" + "rlwinm 21, 18, 26, 22, 29\n\t" + "rlwinm 22, 20, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 19, 26, 22, 29\n\t" + "lwzx 21, 10, 21\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "xor 12, 12, 21\n\t" + "xor 15, 15, 22\n\t" + "xor 14, 14, 23\n\t" + "xor 16, 16, 24\n\t" + "rlwinm 21, 20, 2, 22, 29\n\t" + "rlwinm 22, 17, 2, 22, 29\n\t" + "rlwinm 23, 19, 2, 22, 29\n\t" + "rlwinm 24, 18, 2, 22, 29\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "xor 12, 12, 21\n\t" + "xor 15, 15, 22\n\t" + "xor 14, 14, 23\n\t" + "xor 16, 16, 24\n\t" + "ld 17, 0(25)\n\t" + "ld 18, 8(25)\n\t" + "rldimi 12, 15, 32, 0\n\t" + "rldimi 14, 16, 32, 0\n\t" + "addi 25, 25, 16\n\t" + /* XOR in Key Schedule */ + "xor 12, 12, 17\n\t" + "xor 14, 14, 18\n\t" + "bdnz L_AES_ECB_encrypt_loop_nr_%=\n\t" + "srdi 15, 12, 32\n\t" + "srdi 16, 14, 32\n\t" + "rlwinm 17, 12, 10, 22, 29\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "lwzx 17, 8, 17\n\t" + "lwzx 18, 8, 18\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "rlwinm 22, 14, 18, 22, 29\n\t" + "rlwinm 23, 16, 18, 22, 29\n\t" + "rlwinm 24, 12, 18, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "rlwinm 21, 14, 26, 22, 29\n\t" + "rlwinm 22, 16, 26, 22, 29\n\t" + "rlwinm 23, 12, 26, 22, 29\n\t" + "rlwinm 24, 15, 26, 22, 29\n\t" + "lwzx 21, 10, 21\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "rlwinm 21, 16, 2, 22, 29\n\t" + "rlwinm 22, 12, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 14, 2, 22, 29\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "xor 17, 17, 21\n\t" + "xor 19, 19, 22\n\t" + "xor 18, 18, 23\n\t" + "xor 20, 20, 24\n\t" + "ld 12, 0(25)\n\t" + "ld 14, 8(25)\n\t" + "rldimi 17, 19, 32, 0\n\t" + "rldimi 18, 20, 32, 0\n\t" + "addi 25, 25, 16\n\t" + /* XOR in Key Schedule */ + "xor 17, 17, 12\n\t" + "xor 18, 18, 14\n\t" + "srdi 19, 17, 32\n\t" + "srdi 20, 18, 32\n\t" + "rlwinm 12, 17, 2, 22, 29\n\t" + "rlwinm 14, 18, 2, 22, 29\n\t" + "rlwinm 16, 19, 2, 22, 29\n\t" + "rlwinm 15, 20, 2, 22, 29\n\t" + "lwzx 12, 9, 12\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 15, 9, 15\n\t" + "rlwinm 21, 18, 26, 22, 29\n\t" + "rlwinm 22, 20, 26, 22, 29\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rldimi 12, 15, 32, 24\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 19, 26, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "rldimi 12, 21, 40, 16\n\t" + "rlwimi 12, 22, 8, 16, 23\n\t" + "rldimi 14, 23, 40, 16\n\t" + "rlwimi 14, 24, 8, 16, 23\n\t" + "rlwinm 21, 19, 18, 22, 29\n\t" + "rlwinm 22, 18, 18, 22, 29\n\t" + "rlwinm 23, 20, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "rldimi 12, 21, 48, 8\n\t" + "rlwimi 12, 22, 16, 8, 15\n\t" + "rldimi 14, 23, 48, 8\n\t" + "rlwimi 14, 24, 16, 8, 15\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "rlwinm 22, 19, 10, 22, 29\n\t" + "rlwinm 23, 18, 10, 22, 29\n\t" + "rlwinm 24, 20, 10, 22, 29\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "lwzx 24, 9, 24\n\t" + "ld 17, 0(25)\n\t" + "ld 18, 8(25)\n\t" + "rldimi 12, 21, 56, 0\n\t" + "rlwimi 12, 22, 24, 0, 7\n\t" + "rldimi 14, 23, 56, 0\n\t" + "rlwimi 14, 24, 24, 0, 7\n\t" + "addi 25, 25, 16\n\t" + /* XOR in Key Schedule */ + "xor 12, 12, 17\n\t" + "xor 14, 14, 18\n\t" + "std 12, 0(%[out])\n\t" + "std 14, 8(%[out])\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "bne L_AES_ECB_encrypt_loop_block_128_%=\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "9", "10", "11", "12", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24", "25" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "8", "9", "10", "11", "12", "14", "15", "16", + "17", "18", "19", "20", "21", "22", "23", "24", "25" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* HAVE_AESCCM || HAVE_AESGCM || WOLFSSL_AES_DIRECT || + * WOLFSSL_AES_COUNTER || HAVE_AES_ECB */ +#ifdef HAVE_AES_CBC +void AES_CBC_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_CBC_encrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p, + unsigned char* iv_p) +#else +void AES_CBC_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register unsigned char* iv asm ("8") = (unsigned char*)iv_p; + register word32* L_AES_PPC64_te4_0_c asm ("9") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 9, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "ld 14, 0(%[iv])\n\t" + "ld 15, 8(%[iv])\n\t" + "addi 10, 9, 0x400\n\t" + "addi 11, 9, 0x800\n\t" + "addi 12, 9, 0xc00\n\t" + "\n" + "L_AES_CBC_encrypt_loop_block_%=: \n\t" + "addi 26, %[ks], 0\n\t" + "ld 18, 0(%[in])\n\t" + "ld 19, 8(%[in])\n\t" + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "ld 18, 0(26)\n\t" + "ld 19, 8(26)\n\t" + "addi 26, 26, 16\n\t" + "rldicr 14, 14, 32, 63\n\t" + "rldicr 15, 15, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(9)\n\t" + "ld 21, 64(9)\n\t" + "ld 21, 128(9)\n\t" + "ld 21, 192(9)\n\t" + "ld 21, 256(9)\n\t" + "ld 21, 320(9)\n\t" + "ld 21, 384(9)\n\t" + "ld 21, 448(9)\n\t" + "ld 21, 512(9)\n\t" + "ld 21, 576(9)\n\t" + "ld 21, 640(9)\n\t" + "ld 21, 704(9)\n\t" + "ld 21, 768(9)\n\t" + "ld 21, 832(9)\n\t" + "ld 21, 896(9)\n\t" + "ld 21, 960(9)\n\t" + "ld 21, 1024(9)\n\t" + "ld 21, 1088(9)\n\t" + "ld 21, 1152(9)\n\t" + "ld 21, 1216(9)\n\t" + "ld 21, 1280(9)\n\t" + "ld 21, 1344(9)\n\t" + "ld 21, 1408(9)\n\t" + "ld 21, 1472(9)\n\t" + "ld 21, 1536(9)\n\t" + "ld 21, 1600(9)\n\t" + "ld 21, 1664(9)\n\t" + "ld 21, 1728(9)\n\t" + "ld 21, 1792(9)\n\t" + "ld 21, 1856(9)\n\t" + "ld 21, 1920(9)\n\t" + "ld 21, 1984(9)\n\t" + "ld 21, 2048(9)\n\t" + "ld 21, 2112(9)\n\t" + "ld 21, 2176(9)\n\t" + "ld 21, 2240(9)\n\t" + "ld 21, 2304(9)\n\t" + "ld 21, 2368(9)\n\t" + "ld 21, 2432(9)\n\t" + "ld 21, 2496(9)\n\t" + "ld 21, 2560(9)\n\t" + "ld 21, 2624(9)\n\t" + "ld 21, 2688(9)\n\t" + "ld 21, 2752(9)\n\t" + "ld 21, 2816(9)\n\t" + "ld 21, 2880(9)\n\t" + "ld 21, 2944(9)\n\t" + "ld 21, 3008(9)\n\t" + "ld 21, 3072(9)\n\t" + "ld 21, 3136(9)\n\t" + "ld 21, 3200(9)\n\t" + "ld 21, 3264(9)\n\t" + "ld 21, 3328(9)\n\t" + "ld 21, 3392(9)\n\t" + "ld 21, 3456(9)\n\t" + "ld 21, 3520(9)\n\t" + "ld 21, 3584(9)\n\t" + "ld 21, 3648(9)\n\t" + "ld 21, 3712(9)\n\t" + "ld 21, 3776(9)\n\t" + "ld 21, 3840(9)\n\t" + "ld 21, 3904(9)\n\t" + "ld 21, 3968(9)\n\t" + "ld 21, 4032(9)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_CBC_encrypt_loop_nr_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 22, 16, 18, 22, 29\n\t" + "rlwinm 23, 15, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "rlwinm 25, 14, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 17, 2, 22, 29\n\t" + "rlwinm 23, 14, 2, 22, 29\n\t" + "rlwinm 24, 16, 2, 22, 29\n\t" + "rlwinm 25, 15, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 14, 0(26)\n\t" + "ld 15, 8(26)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 26, 26, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 10, 22, 29\n\t" + "rlwinm 15, 19, 10, 22, 29\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "rlwinm 17, 21, 10, 22, 29\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 15, 9, 15\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 17, 9, 17\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 21, 2, 22, 29\n\t" + "rlwinm 23, 18, 2, 22, 29\n\t" + "rlwinm 24, 20, 2, 22, 29\n\t" + "rlwinm 25, 19, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "ld 18, 0(26)\n\t" + "ld 19, 8(26)\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + "addi 26, 26, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_CBC_encrypt_loop_nr_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 22, 16, 18, 22, 29\n\t" + "rlwinm 23, 15, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "rlwinm 25, 14, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 17, 2, 22, 29\n\t" + "rlwinm 23, 14, 2, 22, 29\n\t" + "rlwinm 24, 16, 2, 22, 29\n\t" + "rlwinm 25, 15, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 14, 0(26)\n\t" + "ld 15, 8(26)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 26, 26, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 2, 22, 29\n\t" + "rlwinm 15, 19, 2, 22, 29\n\t" + "rlwinm 17, 20, 2, 22, 29\n\t" + "rlwinm 16, 21, 2, 22, 29\n\t" + "lwzx 14, 10, 14\n\t" + "lwzx 15, 10, 15\n\t" + "lwzx 17, 10, 17\n\t" + "lwzx 16, 10, 16\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "rldimi 14, 22, 40, 16\n\t" + "rlwimi 14, 23, 8, 16, 23\n\t" + "rldimi 15, 24, 40, 16\n\t" + "rlwimi 15, 25, 8, 16, 23\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "rldimi 14, 22, 48, 8\n\t" + "rlwimi 14, 23, 16, 8, 15\n\t" + "rldimi 15, 24, 48, 8\n\t" + "rlwimi 15, 25, 16, 8, 15\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "ld 18, 0(26)\n\t" + "ld 19, 8(26)\n\t" + "rldimi 14, 22, 56, 0\n\t" + "rlwimi 14, 23, 24, 0, 7\n\t" + "rldimi 15, 24, 56, 0\n\t" + "rlwimi 15, 25, 24, 0, 7\n\t" + "addi 26, 26, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "std 14, 0(%[out])\n\t" + "std 15, 8(%[out])\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "bne L_AES_CBC_encrypt_loop_block_%=\n\t" + "std 14, 0(%[iv])\n\t" + "std 15, 8(%[iv])\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [iv] "+r" (iv), + [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "10", "11", "12", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", "25", "26" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [iv] "r" (iv), + [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "9", "10", "11", "12", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24", "25", "26" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* HAVE_AES_CBC */ +#ifdef WOLFSSL_AES_COUNTER +void AES_CTR_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_CTR_encrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p, + unsigned char* ctr_p) +#else +void AES_CTR_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register unsigned char* ctr asm ("8") = (unsigned char*)ctr_p; + register word32* L_AES_PPC64_te4_0_c asm ("9") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 9, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "ld 22, 0(%[ctr])\n\t" + "ld 23, 8(%[ctr])\n\t" + "addi 10, 9, 0x400\n\t" + "addi 11, 9, 0x800\n\t" + "addi 12, 9, 0xc00\n\t" + "\n" + "L_AES_CTR_encrypt_loop_block_128_%=: \n\t" + "addi 28, %[ks], 0\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "addi 28, 28, 16\n\t" + "rldicr 14, 22, 32, 63\n\t" + "rldicr 15, 23, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(9)\n\t" + "ld 21, 64(9)\n\t" + "ld 21, 128(9)\n\t" + "ld 21, 192(9)\n\t" + "ld 21, 256(9)\n\t" + "ld 21, 320(9)\n\t" + "ld 21, 384(9)\n\t" + "ld 21, 448(9)\n\t" + "ld 21, 512(9)\n\t" + "ld 21, 576(9)\n\t" + "ld 21, 640(9)\n\t" + "ld 21, 704(9)\n\t" + "ld 21, 768(9)\n\t" + "ld 21, 832(9)\n\t" + "ld 21, 896(9)\n\t" + "ld 21, 960(9)\n\t" + "ld 21, 1024(9)\n\t" + "ld 21, 1088(9)\n\t" + "ld 21, 1152(9)\n\t" + "ld 21, 1216(9)\n\t" + "ld 21, 1280(9)\n\t" + "ld 21, 1344(9)\n\t" + "ld 21, 1408(9)\n\t" + "ld 21, 1472(9)\n\t" + "ld 21, 1536(9)\n\t" + "ld 21, 1600(9)\n\t" + "ld 21, 1664(9)\n\t" + "ld 21, 1728(9)\n\t" + "ld 21, 1792(9)\n\t" + "ld 21, 1856(9)\n\t" + "ld 21, 1920(9)\n\t" + "ld 21, 1984(9)\n\t" + "ld 21, 2048(9)\n\t" + "ld 21, 2112(9)\n\t" + "ld 21, 2176(9)\n\t" + "ld 21, 2240(9)\n\t" + "ld 21, 2304(9)\n\t" + "ld 21, 2368(9)\n\t" + "ld 21, 2432(9)\n\t" + "ld 21, 2496(9)\n\t" + "ld 21, 2560(9)\n\t" + "ld 21, 2624(9)\n\t" + "ld 21, 2688(9)\n\t" + "ld 21, 2752(9)\n\t" + "ld 21, 2816(9)\n\t" + "ld 21, 2880(9)\n\t" + "ld 21, 2944(9)\n\t" + "ld 21, 3008(9)\n\t" + "ld 21, 3072(9)\n\t" + "ld 21, 3136(9)\n\t" + "ld 21, 3200(9)\n\t" + "ld 21, 3264(9)\n\t" + "ld 21, 3328(9)\n\t" + "ld 21, 3392(9)\n\t" + "ld 21, 3456(9)\n\t" + "ld 21, 3520(9)\n\t" + "ld 21, 3584(9)\n\t" + "ld 21, 3648(9)\n\t" + "ld 21, 3712(9)\n\t" + "ld 21, 3776(9)\n\t" + "ld 21, 3840(9)\n\t" + "ld 21, 3904(9)\n\t" + "ld 21, 3968(9)\n\t" + "ld 21, 4032(9)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_CTR_encrypt_loop_nr_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 24, 16, 18, 22, 29\n\t" + "rlwinm 25, 15, 18, 22, 29\n\t" + "rlwinm 26, 17, 18, 22, 29\n\t" + "rlwinm 27, 14, 18, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "rlwinm 24, 15, 26, 22, 29\n\t" + "rlwinm 25, 17, 26, 22, 29\n\t" + "rlwinm 26, 14, 26, 22, 29\n\t" + "rlwinm 27, 16, 26, 22, 29\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "lwzx 26, 11, 26\n\t" + "lwzx 27, 11, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "rlwinm 26, 16, 2, 22, 29\n\t" + "rlwinm 27, 15, 2, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "ld 14, 0(28)\n\t" + "ld 15, 8(28)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 10, 22, 29\n\t" + "rlwinm 15, 19, 10, 22, 29\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "rlwinm 17, 21, 10, 22, 29\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 15, 9, 15\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 17, 9, 17\n\t" + "rlwinm 24, 20, 18, 22, 29\n\t" + "rlwinm 25, 19, 18, 22, 29\n\t" + "rlwinm 26, 21, 18, 22, 29\n\t" + "rlwinm 27, 18, 18, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "xor 14, 14, 24\n\t" + "xor 16, 16, 25\n\t" + "xor 15, 15, 26\n\t" + "xor 17, 17, 27\n\t" + "rlwinm 24, 19, 26, 22, 29\n\t" + "rlwinm 25, 21, 26, 22, 29\n\t" + "rlwinm 26, 18, 26, 22, 29\n\t" + "rlwinm 27, 20, 26, 22, 29\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "lwzx 26, 11, 26\n\t" + "lwzx 27, 11, 27\n\t" + "xor 14, 14, 24\n\t" + "xor 16, 16, 25\n\t" + "xor 15, 15, 26\n\t" + "xor 17, 17, 27\n\t" + "rlwinm 24, 21, 2, 22, 29\n\t" + "rlwinm 25, 18, 2, 22, 29\n\t" + "rlwinm 26, 20, 2, 22, 29\n\t" + "rlwinm 27, 19, 2, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 14, 14, 24\n\t" + "xor 16, 16, 25\n\t" + "xor 15, 15, 26\n\t" + "xor 17, 17, 27\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_CTR_encrypt_loop_nr_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 24, 16, 18, 22, 29\n\t" + "rlwinm 25, 15, 18, 22, 29\n\t" + "rlwinm 26, 17, 18, 22, 29\n\t" + "rlwinm 27, 14, 18, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "rlwinm 24, 15, 26, 22, 29\n\t" + "rlwinm 25, 17, 26, 22, 29\n\t" + "rlwinm 26, 14, 26, 22, 29\n\t" + "rlwinm 27, 16, 26, 22, 29\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "lwzx 26, 11, 26\n\t" + "lwzx 27, 11, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "rlwinm 26, 16, 2, 22, 29\n\t" + "rlwinm 27, 15, 2, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 18, 18, 24\n\t" + "xor 20, 20, 25\n\t" + "xor 19, 19, 26\n\t" + "xor 21, 21, 27\n\t" + "ld 14, 0(28)\n\t" + "ld 15, 8(28)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 2, 22, 29\n\t" + "rlwinm 15, 19, 2, 22, 29\n\t" + "rlwinm 17, 20, 2, 22, 29\n\t" + "rlwinm 16, 21, 2, 22, 29\n\t" + "lwzx 14, 10, 14\n\t" + "lwzx 15, 10, 15\n\t" + "lwzx 17, 10, 17\n\t" + "lwzx 16, 10, 16\n\t" + "rlwinm 24, 19, 26, 22, 29\n\t" + "rlwinm 25, 21, 26, 22, 29\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rlwinm 26, 18, 26, 22, 29\n\t" + "rlwinm 27, 20, 26, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "rldimi 14, 24, 40, 16\n\t" + "rlwimi 14, 25, 8, 16, 23\n\t" + "rldimi 15, 26, 40, 16\n\t" + "rlwimi 15, 27, 8, 16, 23\n\t" + "rlwinm 24, 20, 18, 22, 29\n\t" + "rlwinm 25, 19, 18, 22, 29\n\t" + "rlwinm 26, 21, 18, 22, 29\n\t" + "rlwinm 27, 18, 18, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "rldimi 14, 24, 48, 8\n\t" + "rlwimi 14, 25, 16, 8, 15\n\t" + "rldimi 15, 26, 48, 8\n\t" + "rlwimi 15, 27, 16, 8, 15\n\t" + "rlwinm 24, 18, 10, 22, 29\n\t" + "rlwinm 25, 20, 10, 22, 29\n\t" + "rlwinm 26, 19, 10, 22, 29\n\t" + "rlwinm 27, 21, 10, 22, 29\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "lwzx 26, 10, 26\n\t" + "lwzx 27, 10, 27\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "rldimi 14, 24, 56, 0\n\t" + "rlwimi 14, 25, 24, 0, 7\n\t" + "rldimi 15, 26, 56, 0\n\t" + "rlwimi 15, 27, 24, 0, 7\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "ld 18, 0(%[in])\n\t" + "ld 19, 8(%[in])\n\t" + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "std 14, 0(%[out])\n\t" + "std 15, 8(%[out])\n\t" + "addic 23, 23, 1\n\t" + "addze 22, 22\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "bne L_AES_CTR_encrypt_loop_block_128_%=\n\t" + "std 22, 0(%[ctr])\n\t" + "std 23, 8(%[ctr])\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [ctr] "+r" (ctr), + [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "10", "11", "12", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [ctr] "r" (ctr), + [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "9", "10", "11", "12", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* WOLFSSL_AES_COUNTER */ +#ifdef HAVE_AESGCM +void AES_GCM_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_GCM_encrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p, + unsigned char* ctr_p) +#else +void AES_GCM_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register unsigned char* ctr asm ("8") = (unsigned char*)ctr_p; + register word32* L_AES_PPC64_te4_0_c asm ("9") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 9, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "ld 26, 0(%[ctr])\n\t" + "ld 27, 8(%[ctr])\n\t" + "addi 10, 9, 0x400\n\t" + "addi 11, 9, 0x800\n\t" + "addi 12, 9, 0xc00\n\t" + "\n" + "L_AES_GCM_encrypt_loop_block_%=: \n\t" + "addi 28, %[ks], 0\n\t" + "addi 17, 27, 1\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "addi 28, 28, 16\n\t" + "rldimi 27, 17, 0, 32\n\t" + "rldicr 14, 26, 32, 63\n\t" + "rldicr 15, 27, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(9)\n\t" + "ld 21, 64(9)\n\t" + "ld 21, 128(9)\n\t" + "ld 21, 192(9)\n\t" + "ld 21, 256(9)\n\t" + "ld 21, 320(9)\n\t" + "ld 21, 384(9)\n\t" + "ld 21, 448(9)\n\t" + "ld 21, 512(9)\n\t" + "ld 21, 576(9)\n\t" + "ld 21, 640(9)\n\t" + "ld 21, 704(9)\n\t" + "ld 21, 768(9)\n\t" + "ld 21, 832(9)\n\t" + "ld 21, 896(9)\n\t" + "ld 21, 960(9)\n\t" + "ld 21, 1024(9)\n\t" + "ld 21, 1088(9)\n\t" + "ld 21, 1152(9)\n\t" + "ld 21, 1216(9)\n\t" + "ld 21, 1280(9)\n\t" + "ld 21, 1344(9)\n\t" + "ld 21, 1408(9)\n\t" + "ld 21, 1472(9)\n\t" + "ld 21, 1536(9)\n\t" + "ld 21, 1600(9)\n\t" + "ld 21, 1664(9)\n\t" + "ld 21, 1728(9)\n\t" + "ld 21, 1792(9)\n\t" + "ld 21, 1856(9)\n\t" + "ld 21, 1920(9)\n\t" + "ld 21, 1984(9)\n\t" + "ld 21, 2048(9)\n\t" + "ld 21, 2112(9)\n\t" + "ld 21, 2176(9)\n\t" + "ld 21, 2240(9)\n\t" + "ld 21, 2304(9)\n\t" + "ld 21, 2368(9)\n\t" + "ld 21, 2432(9)\n\t" + "ld 21, 2496(9)\n\t" + "ld 21, 2560(9)\n\t" + "ld 21, 2624(9)\n\t" + "ld 21, 2688(9)\n\t" + "ld 21, 2752(9)\n\t" + "ld 21, 2816(9)\n\t" + "ld 21, 2880(9)\n\t" + "ld 21, 2944(9)\n\t" + "ld 21, 3008(9)\n\t" + "ld 21, 3072(9)\n\t" + "ld 21, 3136(9)\n\t" + "ld 21, 3200(9)\n\t" + "ld 21, 3264(9)\n\t" + "ld 21, 3328(9)\n\t" + "ld 21, 3392(9)\n\t" + "ld 21, 3456(9)\n\t" + "ld 21, 3520(9)\n\t" + "ld 21, 3584(9)\n\t" + "ld 21, 3648(9)\n\t" + "ld 21, 3712(9)\n\t" + "ld 21, 3776(9)\n\t" + "ld 21, 3840(9)\n\t" + "ld 21, 3904(9)\n\t" + "ld 21, 3968(9)\n\t" + "ld 21, 4032(9)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_GCM_encrypt_loop_nr_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 22, 16, 18, 22, 29\n\t" + "rlwinm 23, 15, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "rlwinm 25, 14, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 17, 2, 22, 29\n\t" + "rlwinm 23, 14, 2, 22, 29\n\t" + "rlwinm 24, 16, 2, 22, 29\n\t" + "rlwinm 25, 15, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 14, 0(28)\n\t" + "ld 15, 8(28)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 10, 22, 29\n\t" + "rlwinm 15, 19, 10, 22, 29\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "rlwinm 17, 21, 10, 22, 29\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 15, 9, 15\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 17, 9, 17\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 21, 2, 22, 29\n\t" + "rlwinm 23, 18, 2, 22, 29\n\t" + "rlwinm 24, 20, 2, 22, 29\n\t" + "rlwinm 25, 19, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_GCM_encrypt_loop_nr_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 14, 10, 22, 29\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 19, 9, 19\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "rlwinm 22, 16, 18, 22, 29\n\t" + "rlwinm 23, 15, 18, 22, 29\n\t" + "rlwinm 24, 17, 18, 22, 29\n\t" + "rlwinm 25, 14, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 17, 2, 22, 29\n\t" + "rlwinm 23, 14, 2, 22, 29\n\t" + "rlwinm 24, 16, 2, 22, 29\n\t" + "rlwinm 25, 15, 2, 22, 29\n\t" + "lwzx 22, 12, 22\n\t" + "lwzx 23, 12, 23\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 14, 0(28)\n\t" + "ld 15, 8(28)\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 18, 2, 22, 29\n\t" + "rlwinm 15, 19, 2, 22, 29\n\t" + "rlwinm 17, 20, 2, 22, 29\n\t" + "rlwinm 16, 21, 2, 22, 29\n\t" + "lwzx 14, 10, 14\n\t" + "lwzx 15, 10, 15\n\t" + "lwzx 17, 10, 17\n\t" + "lwzx 16, 10, 16\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "rldimi 14, 22, 40, 16\n\t" + "rlwimi 14, 23, 8, 16, 23\n\t" + "rldimi 15, 24, 40, 16\n\t" + "rlwimi 15, 25, 8, 16, 23\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "rldimi 14, 22, 48, 8\n\t" + "rlwimi 14, 23, 16, 8, 15\n\t" + "rldimi 15, 24, 48, 8\n\t" + "rlwimi 15, 25, 16, 8, 15\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 10, 22\n\t" + "lwzx 23, 10, 23\n\t" + "lwzx 24, 10, 24\n\t" + "lwzx 25, 10, 25\n\t" + "ld 18, 0(28)\n\t" + "ld 19, 8(28)\n\t" + "rldimi 14, 22, 56, 0\n\t" + "rlwimi 14, 23, 24, 0, 7\n\t" + "rldimi 15, 24, 56, 0\n\t" + "rlwimi 15, 25, 24, 0, 7\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "ld 18, 0(%[in])\n\t" + "ld 19, 8(%[in])\n\t" + "addi %[in], %[in], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "std 14, 0(%[out])\n\t" + "std 15, 8(%[out])\n\t" + "addi %[out], %[out], 16\n\t" + "bne L_AES_GCM_encrypt_loop_block_%=\n\t" + "std 26, 0(%[ctr])\n\t" + "std 27, 8(%[ctr])\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [ctr] "+r" (ctr), + [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "10", "11", "12", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [ctr] "r" (ctr), + [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "9", "10", "11", "12", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* HAVE_AESGCM */ +#ifdef WOLFSSL_AES_XTS +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_XTS_encrypt(const byte* in_p, byte* out_p, word32 sz_p, + const byte* i_p, byte* key_p, byte* key2_p, byte* tmp_p, int nr_p) +#else +void AES_XTS_encrypt(const byte* in, byte* out, word32 sz, const byte* i, + byte* key, byte* key2, byte* tmp, int nr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const byte* in asm ("3") = (const byte*)in_p; + register byte* out asm ("4") = (byte*)out_p; + register word32 sz asm ("5") = (word32)sz_p; + register const byte* i asm ("6") = (const byte*)i_p; + register byte* key asm ("7") = (byte*)key_p; + register byte* key2 asm ("8") = (byte*)key2_p; + register byte* tmp asm ("9") = (byte*)tmp_p; + register int nr asm ("10") = (int)nr_p; + register word32* L_AES_PPC64_te4_0_c asm ("11") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( + "subi 1, 1, 8\n\t" +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 11, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 12, 11, 0x400\n\t" + "addi 14, 11, 0x800\n\t" + "addi 15, 11, 0xc00\n\t" + "ld 28, 0(%[i])\n\t" + "ld 29, 8(%[i])\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldicr 28, 28, 32, 63\n\t" + "rldicr 29, 29, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 28, 28, 20\n\t" + "xor 29, 29, 21\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 23, 0(11)\n\t" + "ld 23, 64(11)\n\t" + "ld 23, 128(11)\n\t" + "ld 23, 192(11)\n\t" + "ld 23, 256(11)\n\t" + "ld 23, 320(11)\n\t" + "ld 23, 384(11)\n\t" + "ld 23, 448(11)\n\t" + "ld 23, 512(11)\n\t" + "ld 23, 576(11)\n\t" + "ld 23, 640(11)\n\t" + "ld 23, 704(11)\n\t" + "ld 23, 768(11)\n\t" + "ld 23, 832(11)\n\t" + "ld 23, 896(11)\n\t" + "ld 23, 960(11)\n\t" + "ld 23, 1024(11)\n\t" + "ld 23, 1088(11)\n\t" + "ld 23, 1152(11)\n\t" + "ld 23, 1216(11)\n\t" + "ld 23, 1280(11)\n\t" + "ld 23, 1344(11)\n\t" + "ld 23, 1408(11)\n\t" + "ld 23, 1472(11)\n\t" + "ld 23, 1536(11)\n\t" + "ld 23, 1600(11)\n\t" + "ld 23, 1664(11)\n\t" + "ld 23, 1728(11)\n\t" + "ld 23, 1792(11)\n\t" + "ld 23, 1856(11)\n\t" + "ld 23, 1920(11)\n\t" + "ld 23, 1984(11)\n\t" + "ld 23, 2048(11)\n\t" + "ld 23, 2112(11)\n\t" + "ld 23, 2176(11)\n\t" + "ld 23, 2240(11)\n\t" + "ld 23, 2304(11)\n\t" + "ld 23, 2368(11)\n\t" + "ld 23, 2432(11)\n\t" + "ld 23, 2496(11)\n\t" + "ld 23, 2560(11)\n\t" + "ld 23, 2624(11)\n\t" + "ld 23, 2688(11)\n\t" + "ld 23, 2752(11)\n\t" + "ld 23, 2816(11)\n\t" + "ld 23, 2880(11)\n\t" + "ld 23, 2944(11)\n\t" + "ld 23, 3008(11)\n\t" + "ld 23, 3072(11)\n\t" + "ld 23, 3136(11)\n\t" + "ld 23, 3200(11)\n\t" + "ld 23, 3264(11)\n\t" + "ld 23, 3328(11)\n\t" + "ld 23, 3392(11)\n\t" + "ld 23, 3456(11)\n\t" + "ld 23, 3520(11)\n\t" + "ld 23, 3584(11)\n\t" + "ld 23, 3648(11)\n\t" + "ld 23, 3712(11)\n\t" + "ld 23, 3776(11)\n\t" + "ld 23, 3840(11)\n\t" + "ld 23, 3904(11)\n\t" + "ld 23, 3968(11)\n\t" + "ld 23, 4032(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_encrypt_loop_nr_tweak_%=: \n\t" + "srdi 18, 28, 32\n\t" + "srdi 19, 29, 32\n\t" + "rlwinm 20, 28, 10, 22, 29\n\t" + "rlwinm 21, 29, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 29, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 28, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 29, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 28, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 28, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 29, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 28, 0(%[key2])\n\t" + "ld 29, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 28\n\t" + "xor 21, 21, 29\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 28, 20, 10, 22, 29\n\t" + "rlwinm 29, 21, 10, 22, 29\n\t" + "rlwinm 18, 22, 10, 22, 29\n\t" + "rlwinm 19, 23, 10, 22, 29\n\t" + "lwzx 28, 11, 28\n\t" + "lwzx 29, 11, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 19, 11, 19\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 28, 28, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 29, 29, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 28, 28, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 29, 29, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 23, 2, 22, 29\n\t" + "rlwinm 25, 20, 2, 22, 29\n\t" + "rlwinm 26, 22, 2, 22, 29\n\t" + "rlwinm 27, 21, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 28, 28, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 29, 29, 26\n\t" + "xor 19, 19, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 28, 18, 32, 0\n\t" + "rldimi 29, 19, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 28, 28, 20\n\t" + "xor 29, 29, 21\n\t" + "bdnz L_AES_XTS_encrypt_loop_nr_tweak_%=\n\t" + "srdi 18, 28, 32\n\t" + "srdi 19, 29, 32\n\t" + "rlwinm 20, 28, 10, 22, 29\n\t" + "rlwinm 21, 29, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 29, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 28, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 29, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 28, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 28, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 29, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 28, 0(%[key2])\n\t" + "ld 29, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 28\n\t" + "xor 21, 21, 29\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 28, 20, 2, 22, 29\n\t" + "rlwinm 29, 21, 2, 22, 29\n\t" + "rlwinm 19, 22, 2, 22, 29\n\t" + "rlwinm 18, 23, 2, 22, 29\n\t" + "lwzx 28, 12, 28\n\t" + "lwzx 29, 12, 29\n\t" + "lwzx 19, 12, 19\n\t" + "lwzx 18, 12, 18\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rldimi 29, 19, 32, 24\n\t" + "rldimi 28, 18, 32, 24\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 28, 24, 40, 16\n\t" + "rlwimi 28, 25, 8, 16, 23\n\t" + "rldimi 29, 26, 40, 16\n\t" + "rlwimi 29, 27, 8, 16, 23\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 28, 24, 48, 8\n\t" + "rlwimi 28, 25, 16, 8, 15\n\t" + "rldimi 29, 26, 48, 8\n\t" + "rlwimi 29, 27, 16, 8, 15\n\t" + "rlwinm 24, 20, 10, 22, 29\n\t" + "rlwinm 25, 22, 10, 22, 29\n\t" + "rlwinm 26, 21, 10, 22, 29\n\t" + "rlwinm 27, 23, 10, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 28, 24, 56, 0\n\t" + "rlwimi 28, 25, 24, 0, 7\n\t" + "rldimi 29, 26, 56, 0\n\t" + "rlwimi 29, 27, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 28, 28, 20\n\t" + "xor 29, 29, 21\n\t" + "std 28, 0(%[tmp])\n\t" + "std 29, 8(%[tmp])\n\t" + "\n" + "L_AES_XTS_encrypt_loop_block_%=: \n\t" + "addi %[key2], %[key], 0\n\t" + "ld 16, 0(%[in])\n\t" + "ld 17, 8(%[in])\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "xor 16, 16, 28\n\t" + "xor 17, 17, 29\n\t" + "rldicr 16, 16, 32, 63\n\t" + "rldicr 17, 17, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 23, 0(11)\n\t" + "ld 23, 64(11)\n\t" + "ld 23, 128(11)\n\t" + "ld 23, 192(11)\n\t" + "ld 23, 256(11)\n\t" + "ld 23, 320(11)\n\t" + "ld 23, 384(11)\n\t" + "ld 23, 448(11)\n\t" + "ld 23, 512(11)\n\t" + "ld 23, 576(11)\n\t" + "ld 23, 640(11)\n\t" + "ld 23, 704(11)\n\t" + "ld 23, 768(11)\n\t" + "ld 23, 832(11)\n\t" + "ld 23, 896(11)\n\t" + "ld 23, 960(11)\n\t" + "ld 23, 1024(11)\n\t" + "ld 23, 1088(11)\n\t" + "ld 23, 1152(11)\n\t" + "ld 23, 1216(11)\n\t" + "ld 23, 1280(11)\n\t" + "ld 23, 1344(11)\n\t" + "ld 23, 1408(11)\n\t" + "ld 23, 1472(11)\n\t" + "ld 23, 1536(11)\n\t" + "ld 23, 1600(11)\n\t" + "ld 23, 1664(11)\n\t" + "ld 23, 1728(11)\n\t" + "ld 23, 1792(11)\n\t" + "ld 23, 1856(11)\n\t" + "ld 23, 1920(11)\n\t" + "ld 23, 1984(11)\n\t" + "ld 23, 2048(11)\n\t" + "ld 23, 2112(11)\n\t" + "ld 23, 2176(11)\n\t" + "ld 23, 2240(11)\n\t" + "ld 23, 2304(11)\n\t" + "ld 23, 2368(11)\n\t" + "ld 23, 2432(11)\n\t" + "ld 23, 2496(11)\n\t" + "ld 23, 2560(11)\n\t" + "ld 23, 2624(11)\n\t" + "ld 23, 2688(11)\n\t" + "ld 23, 2752(11)\n\t" + "ld 23, 2816(11)\n\t" + "ld 23, 2880(11)\n\t" + "ld 23, 2944(11)\n\t" + "ld 23, 3008(11)\n\t" + "ld 23, 3072(11)\n\t" + "ld 23, 3136(11)\n\t" + "ld 23, 3200(11)\n\t" + "ld 23, 3264(11)\n\t" + "ld 23, 3328(11)\n\t" + "ld 23, 3392(11)\n\t" + "ld 23, 3456(11)\n\t" + "ld 23, 3520(11)\n\t" + "ld 23, 3584(11)\n\t" + "ld 23, 3648(11)\n\t" + "ld 23, 3712(11)\n\t" + "ld 23, 3776(11)\n\t" + "ld 23, 3840(11)\n\t" + "ld 23, 3904(11)\n\t" + "ld 23, 3968(11)\n\t" + "ld 23, 4032(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_encrypt_loop_nr_%=: \n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 17, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 16, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 17, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 16, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 16, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 17, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 16, 0(%[key2])\n\t" + "ld 17, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 16\n\t" + "xor 21, 21, 17\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "rlwinm 17, 21, 10, 22, 29\n\t" + "rlwinm 18, 22, 10, 22, 29\n\t" + "rlwinm 19, 23, 10, 22, 29\n\t" + "lwzx 16, 11, 16\n\t" + "lwzx 17, 11, 17\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 19, 11, 19\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 23, 2, 22, 29\n\t" + "rlwinm 25, 20, 2, 22, 29\n\t" + "rlwinm 26, 22, 2, 22, 29\n\t" + "rlwinm 27, 21, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "bdnz L_AES_XTS_encrypt_loop_nr_%=\n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 17, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 16, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 17, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 16, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 16, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 17, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 16, 0(%[key2])\n\t" + "ld 17, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 16\n\t" + "xor 21, 21, 17\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 16, 20, 2, 22, 29\n\t" + "rlwinm 17, 21, 2, 22, 29\n\t" + "rlwinm 19, 22, 2, 22, 29\n\t" + "rlwinm 18, 23, 2, 22, 29\n\t" + "lwzx 16, 12, 16\n\t" + "lwzx 17, 12, 17\n\t" + "lwzx 19, 12, 19\n\t" + "lwzx 18, 12, 18\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rldimi 17, 19, 32, 24\n\t" + "rldimi 16, 18, 32, 24\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 16, 24, 40, 16\n\t" + "rlwimi 16, 25, 8, 16, 23\n\t" + "rldimi 17, 26, 40, 16\n\t" + "rlwimi 17, 27, 8, 16, 23\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 16, 24, 48, 8\n\t" + "rlwimi 16, 25, 16, 8, 15\n\t" + "rldimi 17, 26, 48, 8\n\t" + "rlwimi 17, 27, 16, 8, 15\n\t" + "rlwinm 24, 20, 10, 22, 29\n\t" + "rlwinm 25, 22, 10, 22, 29\n\t" + "rlwinm 26, 21, 10, 22, 29\n\t" + "rlwinm 27, 23, 10, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 16, 24, 56, 0\n\t" + "rlwimi 16, 25, 24, 0, 7\n\t" + "rldimi 17, 26, 56, 0\n\t" + "rlwimi 17, 27, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "xor 16, 16, 28\n\t" + "xor 17, 17, 29\n\t" + "li 19, 8\n\t" + "ldbrx 28, 0, %[tmp]\n\t" + "ldbrx 29, %[tmp], 19\n\t" + "std 16, 0(%[out])\n\t" + "std 17, 8(%[out])\n\t" + "sradi 24, 29, 63\n\t" + "srdi 25, 28, 63\n\t" + "sldi 29, 29, 1\n\t" + "andi. 24, 24, 0x87\n\t" + "sldi 28, 28, 1\n\t" + "xor 29, 29, 25\n\t" + "xor 28, 28, 24\n\t" + "stdbrx 28, 0, %[tmp]\n\t" + "stdbrx 29, %[tmp], 19\n\t" + "ld 28, 0(%[tmp])\n\t" + "ld 29, 8(%[tmp])\n\t" + "addi %[sz], %[sz], -16\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "cmpdi %[sz], 16\n\t" + "bge L_AES_XTS_encrypt_loop_block_%=\n\t" + "cmpdi %[sz], 0\n\t" + "beq L_AES_XTS_encrypt_done_data_%=\n\t" + "addi %[key2], %[key], 0\n\t" + "addi %[out], %[out], -16\n\t" + "ld 16, 0(%[out])\n\t" + "ld 17, 8(%[out])\n\t" + "addi %[out], %[out], 16\n\t" + "std 16, 0(%[tmp])\n\t" + "std 17, 8(%[tmp])\n\t" + "addi 20, %[sz], 0\n\t" + "\n" + "L_AES_XTS_encrypt_start_byte_%=: \n\t" + "lbz 24, 0(%[tmp])\n\t" + "lbz 25, 0(%[in])\n\t" + "addi %[in], %[in], 1\n\t" + "stb 24, 0(%[out])\n\t" + "addi %[out], %[out], 1\n\t" + "stb 25, 0(%[tmp])\n\t" + "addi %[tmp], %[tmp], 1\n\t" + "addic. 20, 20, -1\n\t" + "bne L_AES_XTS_encrypt_start_byte_%=\n\t" + "subf %[out], %[sz], %[out]\n\t" + "subf %[tmp], %[sz], %[tmp]\n\t" + "addi %[out], %[out], -16\n\t" + "ld 16, 0(%[tmp])\n\t" + "ld 17, 8(%[tmp])\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "xor 16, 16, 28\n\t" + "xor 17, 17, 29\n\t" + "rldicr 16, 16, 32, 63\n\t" + "rldicr 17, 17, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 23, 0(11)\n\t" + "ld 23, 64(11)\n\t" + "ld 23, 128(11)\n\t" + "ld 23, 192(11)\n\t" + "ld 23, 256(11)\n\t" + "ld 23, 320(11)\n\t" + "ld 23, 384(11)\n\t" + "ld 23, 448(11)\n\t" + "ld 23, 512(11)\n\t" + "ld 23, 576(11)\n\t" + "ld 23, 640(11)\n\t" + "ld 23, 704(11)\n\t" + "ld 23, 768(11)\n\t" + "ld 23, 832(11)\n\t" + "ld 23, 896(11)\n\t" + "ld 23, 960(11)\n\t" + "ld 23, 1024(11)\n\t" + "ld 23, 1088(11)\n\t" + "ld 23, 1152(11)\n\t" + "ld 23, 1216(11)\n\t" + "ld 23, 1280(11)\n\t" + "ld 23, 1344(11)\n\t" + "ld 23, 1408(11)\n\t" + "ld 23, 1472(11)\n\t" + "ld 23, 1536(11)\n\t" + "ld 23, 1600(11)\n\t" + "ld 23, 1664(11)\n\t" + "ld 23, 1728(11)\n\t" + "ld 23, 1792(11)\n\t" + "ld 23, 1856(11)\n\t" + "ld 23, 1920(11)\n\t" + "ld 23, 1984(11)\n\t" + "ld 23, 2048(11)\n\t" + "ld 23, 2112(11)\n\t" + "ld 23, 2176(11)\n\t" + "ld 23, 2240(11)\n\t" + "ld 23, 2304(11)\n\t" + "ld 23, 2368(11)\n\t" + "ld 23, 2432(11)\n\t" + "ld 23, 2496(11)\n\t" + "ld 23, 2560(11)\n\t" + "ld 23, 2624(11)\n\t" + "ld 23, 2688(11)\n\t" + "ld 23, 2752(11)\n\t" + "ld 23, 2816(11)\n\t" + "ld 23, 2880(11)\n\t" + "ld 23, 2944(11)\n\t" + "ld 23, 3008(11)\n\t" + "ld 23, 3072(11)\n\t" + "ld 23, 3136(11)\n\t" + "ld 23, 3200(11)\n\t" + "ld 23, 3264(11)\n\t" + "ld 23, 3328(11)\n\t" + "ld 23, 3392(11)\n\t" + "ld 23, 3456(11)\n\t" + "ld 23, 3520(11)\n\t" + "ld 23, 3584(11)\n\t" + "ld 23, 3648(11)\n\t" + "ld 23, 3712(11)\n\t" + "ld 23, 3776(11)\n\t" + "ld 23, 3840(11)\n\t" + "ld 23, 3904(11)\n\t" + "ld 23, 3968(11)\n\t" + "ld 23, 4032(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_encrypt_loop_nr_partial_%=: \n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 17, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 16, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 17, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 16, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 16, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 17, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 16, 0(%[key2])\n\t" + "ld 17, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 16\n\t" + "xor 21, 21, 17\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 16, 20, 10, 22, 29\n\t" + "rlwinm 17, 21, 10, 22, 29\n\t" + "rlwinm 18, 22, 10, 22, 29\n\t" + "rlwinm 19, 23, 10, 22, 29\n\t" + "lwzx 16, 11, 16\n\t" + "lwzx 17, 11, 17\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 19, 11, 19\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "rlwinm 24, 23, 2, 22, 29\n\t" + "rlwinm 25, 20, 2, 22, 29\n\t" + "rlwinm 26, 22, 2, 22, 29\n\t" + "rlwinm 27, 21, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 16, 16, 24\n\t" + "xor 18, 18, 25\n\t" + "xor 17, 17, 26\n\t" + "xor 19, 19, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "bdnz L_AES_XTS_encrypt_loop_nr_partial_%=\n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 17, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 21, 11, 21\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "rlwinm 24, 18, 18, 22, 29\n\t" + "rlwinm 25, 17, 18, 22, 29\n\t" + "rlwinm 26, 19, 18, 22, 29\n\t" + "rlwinm 27, 16, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 17, 26, 22, 29\n\t" + "rlwinm 25, 19, 26, 22, 29\n\t" + "rlwinm 26, 16, 26, 22, 29\n\t" + "rlwinm 27, 18, 26, 22, 29\n\t" + "lwzx 24, 14, 24\n\t" + "lwzx 25, 14, 25\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "rlwinm 24, 19, 2, 22, 29\n\t" + "rlwinm 25, 16, 2, 22, 29\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 17, 2, 22, 29\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "xor 20, 20, 24\n\t" + "xor 22, 22, 25\n\t" + "xor 21, 21, 26\n\t" + "xor 23, 23, 27\n\t" + "ld 16, 0(%[key2])\n\t" + "ld 17, 8(%[key2])\n\t" + "rldimi 20, 22, 32, 0\n\t" + "rldimi 21, 23, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 20, 20, 16\n\t" + "xor 21, 21, 17\n\t" + "srdi 22, 20, 32\n\t" + "srdi 23, 21, 32\n\t" + "rlwinm 16, 20, 2, 22, 29\n\t" + "rlwinm 17, 21, 2, 22, 29\n\t" + "rlwinm 19, 22, 2, 22, 29\n\t" + "rlwinm 18, 23, 2, 22, 29\n\t" + "lwzx 16, 12, 16\n\t" + "lwzx 17, 12, 17\n\t" + "lwzx 19, 12, 19\n\t" + "lwzx 18, 12, 18\n\t" + "rlwinm 24, 21, 26, 22, 29\n\t" + "rlwinm 25, 23, 26, 22, 29\n\t" + "rldimi 17, 19, 32, 24\n\t" + "rldimi 16, 18, 32, 24\n\t" + "rlwinm 26, 20, 26, 22, 29\n\t" + "rlwinm 27, 22, 26, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 16, 24, 40, 16\n\t" + "rlwimi 16, 25, 8, 16, 23\n\t" + "rldimi 17, 26, 40, 16\n\t" + "rlwimi 17, 27, 8, 16, 23\n\t" + "rlwinm 24, 22, 18, 22, 29\n\t" + "rlwinm 25, 21, 18, 22, 29\n\t" + "rlwinm 26, 23, 18, 22, 29\n\t" + "rlwinm 27, 20, 18, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "rldimi 16, 24, 48, 8\n\t" + "rlwimi 16, 25, 16, 8, 15\n\t" + "rldimi 17, 26, 48, 8\n\t" + "rlwimi 17, 27, 16, 8, 15\n\t" + "rlwinm 24, 20, 10, 22, 29\n\t" + "rlwinm 25, 22, 10, 22, 29\n\t" + "rlwinm 26, 21, 10, 22, 29\n\t" + "rlwinm 27, 23, 10, 22, 29\n\t" + "lwzx 24, 12, 24\n\t" + "lwzx 25, 12, 25\n\t" + "lwzx 26, 12, 26\n\t" + "lwzx 27, 12, 27\n\t" + "ld 20, 0(%[key2])\n\t" + "ld 21, 8(%[key2])\n\t" + "rldimi 16, 24, 56, 0\n\t" + "rlwimi 16, 25, 24, 0, 7\n\t" + "rldimi 17, 26, 56, 0\n\t" + "rlwimi 17, 27, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 20\n\t" + "xor 17, 17, 21\n\t" + "xor 16, 16, 28\n\t" + "xor 17, 17, 29\n\t" + "std 16, 0(%[out])\n\t" + "std 17, 8(%[out])\n\t" + "\n" + "L_AES_XTS_encrypt_done_data_%=: \n\t" + "addi 1, 1, 8\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [sz] "+r" (sz), [i] "+r" (i), + [key] "+r" (key), [key2] "+r" (key2), [tmp] "+r" (tmp), + [nr] "+r" (nr), [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "12", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29" +#else + : + : [in] "r" (in), [out] "r" (out), [sz] "r" (sz), [i] "r" (i), + [key] "r" (key), [key2] "r" (key2), [tmp] "r" (tmp), [nr] "r" (nr), + [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "11", "12", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28", "29" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* WOLFSSL_AES_XTS */ +#ifdef HAVE_AES_DECRYPT +#if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || \ + defined(HAVE_AES_CBC) || defined(HAVE_AES_ECB) +static const byte L_AES_PPC64_td4[] = { + 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, + 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, + 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, + 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, + 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, + 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, + 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, + 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, + 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, + 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, + 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, + 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, + 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, + 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, + 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, + 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, + 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, + 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, + 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, + 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, + 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, + 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, + 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, + 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, + 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, + 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, + 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, + 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, + 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d, +}; + +#if defined(WOLFSSL_AES_DIRECT) || defined(WOLFSSL_AES_COUNTER) || \ + defined(HAVE_AES_ECB) +void AES_ECB_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_ECB_decrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p) +#else +void AES_ECB_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register word32* L_AES_PPC64_td_c asm ("8") = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c asm ("9") = (byte*)&L_AES_PPC64_td4; +#else + register word32* L_AES_PPC64_td_c = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c = (byte*)&L_AES_PPC64_td4; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 8, %[L_AES_PPC64_td]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 9, %[L_AES_PPC64_td4]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "\n" + "L_AES_ECB_decrypt_loop_block_%=: \n\t" + "addi 23, %[ks], 0\n\t" + "ld 10, 0(%[in])\n\t" + "ld 11, 8(%[in])\n\t" + "ld 15, 0(23)\n\t" + "ld 16, 8(23)\n\t" + "addi 23, 23, 16\n\t" + "rldicr 10, 10, 32, 63\n\t" + "rldicr 11, 11, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 10, 10, 15\n\t" + "xor 11, 11, 16\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 18, 0(8)\n\t" + "ld 18, 64(8)\n\t" + "ld 18, 128(8)\n\t" + "ld 18, 192(8)\n\t" + "ld 18, 256(8)\n\t" + "ld 18, 320(8)\n\t" + "ld 18, 384(8)\n\t" + "ld 18, 448(8)\n\t" + "ld 18, 512(8)\n\t" + "ld 18, 576(8)\n\t" + "ld 18, 640(8)\n\t" + "ld 18, 704(8)\n\t" + "ld 18, 768(8)\n\t" + "ld 18, 832(8)\n\t" + "ld 18, 896(8)\n\t" + "ld 18, 960(8)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_ECB_decrypt_loop_nr_%=: \n\t" + "srdi 12, 10, 32\n\t" + "srdi 14, 11, 32\n\t" + "rlwinm 15, 14, 18, 22, 29\n\t" + "rlwinm 17, 10, 18, 22, 29\n\t" + "rlwinm 16, 12, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "lwzx 15, 8, 15\n\t" + "lwzx 17, 8, 17\n\t" + "lwzx 16, 8, 16\n\t" + "lwzx 18, 8, 18\n\t" + "rlwinm 19, 10, 10, 22, 29\n\t" + "rlwinm 20, 12, 10, 22, 29\n\t" + "rlwinm 21, 11, 10, 22, 29\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 8, 0, 31\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "rlwinm 19, 11, 26, 22, 29\n\t" + "rlwinm 20, 14, 26, 22, 29\n\t" + "rlwinm 21, 10, 26, 22, 29\n\t" + "rlwinm 22, 12, 26, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 24, 0, 31\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "rlwinm 19, 12, 2, 22, 29\n\t" + "rlwinm 20, 11, 2, 22, 29\n\t" + "rlwinm 21, 14, 2, 22, 29\n\t" + "rlwinm 22, 10, 2, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 16, 0, 31\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "ld 10, 0(23)\n\t" + "ld 11, 8(23)\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "addi 23, 23, 16\n\t" + "rldimi 15, 17, 32, 0\n\t" + "rldimi 16, 18, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 15, 15, 10\n\t" + "xor 16, 16, 11\n\t" + "srdi 17, 15, 32\n\t" + "srdi 18, 16, 32\n\t" + "rlwinm 10, 18, 18, 22, 29\n\t" + "rlwinm 12, 15, 18, 22, 29\n\t" + "rlwinm 11, 17, 18, 22, 29\n\t" + "rlwinm 14, 16, 18, 22, 29\n\t" + "lwzx 10, 8, 10\n\t" + "lwzx 12, 8, 12\n\t" + "lwzx 11, 8, 11\n\t" + "lwzx 14, 8, 14\n\t" + "rlwinm 19, 15, 10, 22, 29\n\t" + "rlwinm 20, 17, 10, 22, 29\n\t" + "rlwinm 21, 16, 10, 22, 29\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 8, 0, 31\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "xor 10, 10, 19\n\t" + "xor 12, 12, 20\n\t" + "xor 11, 11, 21\n\t" + "xor 14, 14, 22\n\t" + "rlwinm 19, 16, 26, 22, 29\n\t" + "rlwinm 20, 18, 26, 22, 29\n\t" + "rlwinm 21, 15, 26, 22, 29\n\t" + "rlwinm 22, 17, 26, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 24, 0, 31\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "xor 10, 10, 19\n\t" + "xor 12, 12, 20\n\t" + "xor 11, 11, 21\n\t" + "xor 14, 14, 22\n\t" + "rlwinm 19, 17, 2, 22, 29\n\t" + "rlwinm 20, 16, 2, 22, 29\n\t" + "rlwinm 21, 18, 2, 22, 29\n\t" + "rlwinm 22, 15, 2, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 16, 0, 31\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "ld 15, 0(23)\n\t" + "ld 16, 8(23)\n\t" + "xor 10, 10, 19\n\t" + "xor 12, 12, 20\n\t" + "xor 11, 11, 21\n\t" + "xor 14, 14, 22\n\t" + "addi 23, 23, 16\n\t" + "rldimi 10, 12, 32, 0\n\t" + "rldimi 11, 14, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 10, 10, 15\n\t" + "xor 11, 11, 16\n\t" + "bdnz L_AES_ECB_decrypt_loop_nr_%=\n\t" + "srdi 12, 10, 32\n\t" + "srdi 14, 11, 32\n\t" + "rlwinm 15, 14, 18, 22, 29\n\t" + "rlwinm 17, 10, 18, 22, 29\n\t" + "rlwinm 16, 12, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "lwzx 15, 8, 15\n\t" + "lwzx 17, 8, 17\n\t" + "lwzx 16, 8, 16\n\t" + "lwzx 18, 8, 18\n\t" + "rlwinm 19, 10, 10, 22, 29\n\t" + "rlwinm 20, 12, 10, 22, 29\n\t" + "rlwinm 21, 11, 10, 22, 29\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 8, 0, 31\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "rlwinm 19, 11, 26, 22, 29\n\t" + "rlwinm 20, 14, 26, 22, 29\n\t" + "rlwinm 21, 10, 26, 22, 29\n\t" + "rlwinm 22, 12, 26, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 24, 0, 31\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "rlwinm 19, 12, 2, 22, 29\n\t" + "rlwinm 20, 11, 2, 22, 29\n\t" + "rlwinm 21, 14, 2, 22, 29\n\t" + "rlwinm 22, 10, 2, 22, 29\n\t" + "lwzx 19, 8, 19\n\t" + "lwzx 20, 8, 20\n\t" + "lwzx 21, 8, 21\n\t" + "lwzx 22, 8, 22\n\t" + "rlwimi 19, 19, 16, 0, 31\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "ld 10, 0(23)\n\t" + "ld 11, 8(23)\n\t" + "xor 15, 15, 19\n\t" + "xor 17, 17, 20\n\t" + "xor 16, 16, 21\n\t" + "xor 18, 18, 22\n\t" + "addi 23, 23, 16\n\t" + "rldimi 15, 17, 32, 0\n\t" + "rldimi 16, 18, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 15, 15, 10\n\t" + "xor 16, 16, 11\n\t" + "ld 18, 0(9)\n\t" + "ld 18, 64(9)\n\t" + "ld 18, 128(9)\n\t" + "ld 18, 192(9)\n\t" + "ld 18, 256(9)\n\t" + "ld 18, 320(9)\n\t" + "ld 18, 384(9)\n\t" + "ld 18, 448(9)\n\t" + "ld 18, 512(9)\n\t" + "ld 18, 576(9)\n\t" + "ld 18, 640(9)\n\t" + "ld 18, 704(9)\n\t" + "ld 18, 768(9)\n\t" + "ld 18, 832(9)\n\t" + "ld 18, 896(9)\n\t" + "ld 18, 960(9)\n\t" + "rldicl 12, 15, 32, 56\n\t" + "andi. 10, 16, 255\n\t" + "rldicl 14, 16, 32, 56\n\t" + "andi. 11, 15, 255\n\t" + "lbzx 12, 9, 12\n\t" + "lbzx 10, 9, 10\n\t" + "lbzx 14, 9, 14\n\t" + "lbzx 11, 9, 11\n\t" + "rldimi 10, 12, 32, 24\n\t" + "rldimi 11, 14, 32, 24\n\t" + "rldicl 19, 16, 56, 56\n\t" + "rldicl 20, 16, 24, 56\n\t" + "rldicl 21, 15, 56, 56\n\t" + "rldicl 22, 15, 24, 56\n\t" + "lbzx 19, 9, 19\n\t" + "lbzx 20, 9, 20\n\t" + "lbzx 21, 9, 21\n\t" + "lbzx 22, 9, 22\n\t" + "rldimi 10, 19, 40, 16\n\t" + "rlwimi 10, 20, 8, 16, 23\n\t" + "rldimi 11, 21, 40, 16\n\t" + "rlwimi 11, 22, 8, 16, 23\n\t" + "rldicl 19, 16, 16, 56\n\t" + "rldicl 20, 15, 48, 56\n\t" + "rldicl 21, 15, 16, 56\n\t" + "rldicl 22, 16, 48, 56\n\t" + "lbzx 19, 9, 19\n\t" + "lbzx 20, 9, 20\n\t" + "lbzx 21, 9, 21\n\t" + "lbzx 22, 9, 22\n\t" + "rldimi 10, 19, 48, 8\n\t" + "rlwimi 10, 20, 16, 8, 15\n\t" + "rldimi 11, 21, 48, 8\n\t" + "rlwimi 11, 22, 16, 8, 15\n\t" + "rldicl 19, 15, 40, 56\n\t" + "rldicl 20, 15, 8, 56\n\t" + "rldicl 21, 16, 40, 56\n\t" + "rldicl 22, 16, 8, 56\n\t" + "lbzx 19, 9, 19\n\t" + "lbzx 20, 9, 20\n\t" + "lbzx 21, 9, 21\n\t" + "lbzx 22, 9, 22\n\t" + "ld 15, 0(23)\n\t" + "ld 16, 8(23)\n\t" + "rldimi 10, 19, 56, 0\n\t" + "rlwimi 10, 20, 24, 0, 7\n\t" + "rldimi 11, 21, 56, 0\n\t" + "rlwimi 11, 22, 24, 0, 7\n\t" + "addi 23, 23, 16\n\t" + /* XOR in Key Schedule */ + "xor 10, 10, 15\n\t" + "xor 11, 11, 16\n\t" + "std 10, 0(%[out])\n\t" + "std 11, 8(%[out])\n\t" + "addic. %[len], %[len], -16\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "bne L_AES_ECB_decrypt_loop_block_%=\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [L_AES_PPC64_td] "+r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "+r" (L_AES_PPC64_td4_c) + : + : "memory", "cc", "0", "10", "11", "12", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [L_AES_PPC64_td] "r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "r" (L_AES_PPC64_td4_c) + : "memory", "cc", "0", "8", "9", "10", "11", "12", "14", "15", "16", + "17", "18", "19", "20", "21", "22", "23" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER || defined(HAVE_AES_ECB) */ +#ifdef HAVE_AES_CBC +void AES_CBC_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_CBC_decrypt(const unsigned char* in_p, unsigned char* out_p, + unsigned long len_p, const unsigned char* ks_p, int nr_p, + unsigned char* iv_p) +#else +void AES_CBC_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const unsigned char* in asm ("3") = (const unsigned char*)in_p; + register unsigned char* out asm ("4") = (unsigned char*)out_p; + register unsigned long len asm ("5") = (unsigned long)len_p; + register const unsigned char* ks asm ("6") = (const unsigned char*)ks_p; + register int nr asm ("7") = (int)nr_p; + register unsigned char* iv asm ("8") = (unsigned char*)iv_p; + register word32* L_AES_PPC64_td_c asm ("9") = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c asm ("10") = (byte*)&L_AES_PPC64_td4; +#else + register word32* L_AES_PPC64_td_c = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c = (byte*)&L_AES_PPC64_td4; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 10, %[L_AES_PPC64_td4]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 9, %[L_AES_PPC64_td]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "ld 24, 0(%[iv])\n\t" + "ld 25, 8(%[iv])\n\t" + "\n" + "L_AES_CBC_decrypt_loop_block_%=: \n\t" + "addi 28, %[ks], 0\n\t" + "ld 26, 0(%[in])\n\t" + "ld 27, 8(%[in])\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "addi 28, 28, 16\n\t" + "rldicr 11, 26, 32, 63\n\t" + "rldicr 12, 27, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 19, 0(9)\n\t" + "ld 19, 64(9)\n\t" + "ld 19, 128(9)\n\t" + "ld 19, 192(9)\n\t" + "ld 19, 256(9)\n\t" + "ld 19, 320(9)\n\t" + "ld 19, 384(9)\n\t" + "ld 19, 448(9)\n\t" + "ld 19, 512(9)\n\t" + "ld 19, 576(9)\n\t" + "ld 19, 640(9)\n\t" + "ld 19, 704(9)\n\t" + "ld 19, 768(9)\n\t" + "ld 19, 832(9)\n\t" + "ld 19, 896(9)\n\t" + "ld 19, 960(9)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_CBC_decrypt_loop_nr_even_%=: \n\t" + "srdi 14, 11, 32\n\t" + "srdi 15, 12, 32\n\t" + "rlwinm 16, 15, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "rlwinm 17, 14, 18, 22, 29\n\t" + "rlwinm 19, 12, 18, 22, 29\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 17, 9, 17\n\t" + "lwzx 19, 9, 19\n\t" + "rlwinm 20, 11, 10, 22, 29\n\t" + "rlwinm 21, 14, 10, 22, 29\n\t" + "rlwinm 22, 12, 10, 22, 29\n\t" + "rlwinm 23, 15, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 12, 26, 22, 29\n\t" + "rlwinm 21, 15, 26, 22, 29\n\t" + "rlwinm 22, 11, 26, 22, 29\n\t" + "rlwinm 23, 14, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 14, 2, 22, 29\n\t" + "rlwinm 21, 12, 2, 22, 29\n\t" + "rlwinm 22, 15, 2, 22, 29\n\t" + "rlwinm 23, 11, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 11, 0(28)\n\t" + "ld 12, 8(28)\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 11\n\t" + "xor 17, 17, 12\n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 11, 19, 18, 22, 29\n\t" + "rlwinm 14, 16, 18, 22, 29\n\t" + "rlwinm 12, 18, 18, 22, 29\n\t" + "rlwinm 15, 17, 18, 22, 29\n\t" + "lwzx 11, 9, 11\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 12, 9, 12\n\t" + "lwzx 15, 9, 15\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 18, 10, 22, 29\n\t" + "rlwinm 22, 17, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "rlwinm 20, 17, 26, 22, 29\n\t" + "rlwinm 21, 19, 26, 22, 29\n\t" + "rlwinm 22, 16, 26, 22, 29\n\t" + "rlwinm 23, 18, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "rlwinm 20, 18, 2, 22, 29\n\t" + "rlwinm 21, 17, 2, 22, 29\n\t" + "rlwinm 22, 19, 2, 22, 29\n\t" + "rlwinm 23, 16, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 11, 14, 32, 0\n\t" + "rldimi 12, 15, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "bdnz L_AES_CBC_decrypt_loop_nr_even_%=\n\t" + "srdi 14, 11, 32\n\t" + "srdi 15, 12, 32\n\t" + "rlwinm 16, 15, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "rlwinm 17, 14, 18, 22, 29\n\t" + "rlwinm 19, 12, 18, 22, 29\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 17, 9, 17\n\t" + "lwzx 19, 9, 19\n\t" + "rlwinm 20, 11, 10, 22, 29\n\t" + "rlwinm 21, 14, 10, 22, 29\n\t" + "rlwinm 22, 12, 10, 22, 29\n\t" + "rlwinm 23, 15, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 12, 26, 22, 29\n\t" + "rlwinm 21, 15, 26, 22, 29\n\t" + "rlwinm 22, 11, 26, 22, 29\n\t" + "rlwinm 23, 14, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 14, 2, 22, 29\n\t" + "rlwinm 21, 12, 2, 22, 29\n\t" + "rlwinm 22, 15, 2, 22, 29\n\t" + "rlwinm 23, 11, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 11, 0(28)\n\t" + "ld 12, 8(28)\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 11\n\t" + "xor 17, 17, 12\n\t" + "ld 19, 0(10)\n\t" + "ld 19, 64(10)\n\t" + "ld 19, 128(10)\n\t" + "ld 19, 192(10)\n\t" + "ld 19, 256(10)\n\t" + "ld 19, 320(10)\n\t" + "ld 19, 384(10)\n\t" + "ld 19, 448(10)\n\t" + "ld 19, 512(10)\n\t" + "ld 19, 576(10)\n\t" + "ld 19, 640(10)\n\t" + "ld 19, 704(10)\n\t" + "ld 19, 768(10)\n\t" + "ld 19, 832(10)\n\t" + "ld 19, 896(10)\n\t" + "ld 19, 960(10)\n\t" + "rldicl 14, 16, 32, 56\n\t" + "andi. 11, 17, 255\n\t" + "rldicl 15, 17, 32, 56\n\t" + "andi. 12, 16, 255\n\t" + "lbzx 14, 10, 14\n\t" + "lbzx 11, 10, 11\n\t" + "lbzx 15, 10, 15\n\t" + "lbzx 12, 10, 12\n\t" + "rldimi 11, 14, 32, 24\n\t" + "rldimi 12, 15, 32, 24\n\t" + "rldicl 20, 17, 56, 56\n\t" + "rldicl 21, 17, 24, 56\n\t" + "rldicl 22, 16, 56, 56\n\t" + "rldicl 23, 16, 24, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "rldimi 11, 20, 40, 16\n\t" + "rlwimi 11, 21, 8, 16, 23\n\t" + "rldimi 12, 22, 40, 16\n\t" + "rlwimi 12, 23, 8, 16, 23\n\t" + "rldicl 20, 17, 16, 56\n\t" + "rldicl 21, 16, 48, 56\n\t" + "rldicl 22, 16, 16, 56\n\t" + "rldicl 23, 17, 48, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "rldimi 11, 20, 48, 8\n\t" + "rlwimi 11, 21, 16, 8, 15\n\t" + "rldimi 12, 22, 48, 8\n\t" + "rlwimi 12, 23, 16, 8, 15\n\t" + "rldicl 20, 16, 40, 56\n\t" + "rldicl 21, 16, 8, 56\n\t" + "rldicl 22, 17, 40, 56\n\t" + "rldicl 23, 17, 8, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "rldimi 11, 20, 56, 0\n\t" + "rlwimi 11, 21, 24, 0, 7\n\t" + "rldimi 12, 22, 56, 0\n\t" + "rlwimi 12, 23, 24, 0, 7\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "xor 11, 11, 24\n\t" + "xor 12, 12, 25\n\t" + "std 11, 0(%[out])\n\t" + "std 12, 8(%[out])\n\t" + "addic. %[len], %[len], -16\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "beq L_AES_CBC_decrypt_end_dec_odd_%=\n\t" + "addi 28, %[ks], 0\n\t" + "ld 24, 0(%[in])\n\t" + "ld 25, 8(%[in])\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "addi 28, 28, 16\n\t" + "rldicr 11, 24, 32, 63\n\t" + "rldicr 12, 25, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 19, 0(9)\n\t" + "ld 19, 64(9)\n\t" + "ld 19, 128(9)\n\t" + "ld 19, 192(9)\n\t" + "ld 19, 256(9)\n\t" + "ld 19, 320(9)\n\t" + "ld 19, 384(9)\n\t" + "ld 19, 448(9)\n\t" + "ld 19, 512(9)\n\t" + "ld 19, 576(9)\n\t" + "ld 19, 640(9)\n\t" + "ld 19, 704(9)\n\t" + "ld 19, 768(9)\n\t" + "ld 19, 832(9)\n\t" + "ld 19, 896(9)\n\t" + "ld 19, 960(9)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_CBC_decrypt_loop_nr_odd_%=: \n\t" + "srdi 14, 11, 32\n\t" + "srdi 15, 12, 32\n\t" + "rlwinm 16, 15, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "rlwinm 17, 14, 18, 22, 29\n\t" + "rlwinm 19, 12, 18, 22, 29\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 17, 9, 17\n\t" + "lwzx 19, 9, 19\n\t" + "rlwinm 20, 11, 10, 22, 29\n\t" + "rlwinm 21, 14, 10, 22, 29\n\t" + "rlwinm 22, 12, 10, 22, 29\n\t" + "rlwinm 23, 15, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 12, 26, 22, 29\n\t" + "rlwinm 21, 15, 26, 22, 29\n\t" + "rlwinm 22, 11, 26, 22, 29\n\t" + "rlwinm 23, 14, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 14, 2, 22, 29\n\t" + "rlwinm 21, 12, 2, 22, 29\n\t" + "rlwinm 22, 15, 2, 22, 29\n\t" + "rlwinm 23, 11, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 11, 0(28)\n\t" + "ld 12, 8(28)\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 11\n\t" + "xor 17, 17, 12\n\t" + "srdi 18, 16, 32\n\t" + "srdi 19, 17, 32\n\t" + "rlwinm 11, 19, 18, 22, 29\n\t" + "rlwinm 14, 16, 18, 22, 29\n\t" + "rlwinm 12, 18, 18, 22, 29\n\t" + "rlwinm 15, 17, 18, 22, 29\n\t" + "lwzx 11, 9, 11\n\t" + "lwzx 14, 9, 14\n\t" + "lwzx 12, 9, 12\n\t" + "lwzx 15, 9, 15\n\t" + "rlwinm 20, 16, 10, 22, 29\n\t" + "rlwinm 21, 18, 10, 22, 29\n\t" + "rlwinm 22, 17, 10, 22, 29\n\t" + "rlwinm 23, 19, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "rlwinm 20, 17, 26, 22, 29\n\t" + "rlwinm 21, 19, 26, 22, 29\n\t" + "rlwinm 22, 16, 26, 22, 29\n\t" + "rlwinm 23, 18, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "rlwinm 20, 18, 2, 22, 29\n\t" + "rlwinm 21, 17, 2, 22, 29\n\t" + "rlwinm 22, 19, 2, 22, 29\n\t" + "rlwinm 23, 16, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "xor 11, 11, 20\n\t" + "xor 14, 14, 21\n\t" + "xor 12, 12, 22\n\t" + "xor 15, 15, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 11, 14, 32, 0\n\t" + "rldimi 12, 15, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "bdnz L_AES_CBC_decrypt_loop_nr_odd_%=\n\t" + "srdi 14, 11, 32\n\t" + "srdi 15, 12, 32\n\t" + "rlwinm 16, 15, 18, 22, 29\n\t" + "rlwinm 18, 11, 18, 22, 29\n\t" + "rlwinm 17, 14, 18, 22, 29\n\t" + "rlwinm 19, 12, 18, 22, 29\n\t" + "lwzx 16, 9, 16\n\t" + "lwzx 18, 9, 18\n\t" + "lwzx 17, 9, 17\n\t" + "lwzx 19, 9, 19\n\t" + "rlwinm 20, 11, 10, 22, 29\n\t" + "rlwinm 21, 14, 10, 22, 29\n\t" + "rlwinm 22, 12, 10, 22, 29\n\t" + "rlwinm 23, 15, 10, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 8, 0, 31\n\t" + "rlwimi 21, 21, 8, 0, 31\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 12, 26, 22, 29\n\t" + "rlwinm 21, 15, 26, 22, 29\n\t" + "rlwinm 22, 11, 26, 22, 29\n\t" + "rlwinm 23, 14, 26, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 24, 0, 31\n\t" + "rlwimi 21, 21, 24, 0, 31\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "rlwinm 20, 14, 2, 22, 29\n\t" + "rlwinm 21, 12, 2, 22, 29\n\t" + "rlwinm 22, 15, 2, 22, 29\n\t" + "rlwinm 23, 11, 2, 22, 29\n\t" + "lwzx 20, 9, 20\n\t" + "lwzx 21, 9, 21\n\t" + "lwzx 22, 9, 22\n\t" + "lwzx 23, 9, 23\n\t" + "rlwimi 20, 20, 16, 0, 31\n\t" + "rlwimi 21, 21, 16, 0, 31\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "ld 11, 0(28)\n\t" + "ld 12, 8(28)\n\t" + "xor 16, 16, 20\n\t" + "xor 18, 18, 21\n\t" + "xor 17, 17, 22\n\t" + "xor 19, 19, 23\n\t" + "addi 28, 28, 16\n\t" + "rldimi 16, 18, 32, 0\n\t" + "rldimi 17, 19, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 16, 16, 11\n\t" + "xor 17, 17, 12\n\t" + "ld 19, 0(10)\n\t" + "ld 19, 64(10)\n\t" + "ld 19, 128(10)\n\t" + "ld 19, 192(10)\n\t" + "ld 19, 256(10)\n\t" + "ld 19, 320(10)\n\t" + "ld 19, 384(10)\n\t" + "ld 19, 448(10)\n\t" + "ld 19, 512(10)\n\t" + "ld 19, 576(10)\n\t" + "ld 19, 640(10)\n\t" + "ld 19, 704(10)\n\t" + "ld 19, 768(10)\n\t" + "ld 19, 832(10)\n\t" + "ld 19, 896(10)\n\t" + "ld 19, 960(10)\n\t" + "rldicl 14, 16, 32, 56\n\t" + "andi. 11, 17, 255\n\t" + "rldicl 15, 17, 32, 56\n\t" + "andi. 12, 16, 255\n\t" + "lbzx 14, 10, 14\n\t" + "lbzx 11, 10, 11\n\t" + "lbzx 15, 10, 15\n\t" + "lbzx 12, 10, 12\n\t" + "rldimi 11, 14, 32, 24\n\t" + "rldimi 12, 15, 32, 24\n\t" + "rldicl 20, 17, 56, 56\n\t" + "rldicl 21, 17, 24, 56\n\t" + "rldicl 22, 16, 56, 56\n\t" + "rldicl 23, 16, 24, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "rldimi 11, 20, 40, 16\n\t" + "rlwimi 11, 21, 8, 16, 23\n\t" + "rldimi 12, 22, 40, 16\n\t" + "rlwimi 12, 23, 8, 16, 23\n\t" + "rldicl 20, 17, 16, 56\n\t" + "rldicl 21, 16, 48, 56\n\t" + "rldicl 22, 16, 16, 56\n\t" + "rldicl 23, 17, 48, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "rldimi 11, 20, 48, 8\n\t" + "rlwimi 11, 21, 16, 8, 15\n\t" + "rldimi 12, 22, 48, 8\n\t" + "rlwimi 12, 23, 16, 8, 15\n\t" + "rldicl 20, 16, 40, 56\n\t" + "rldicl 21, 16, 8, 56\n\t" + "rldicl 22, 17, 40, 56\n\t" + "rldicl 23, 17, 8, 56\n\t" + "lbzx 20, 10, 20\n\t" + "lbzx 21, 10, 21\n\t" + "lbzx 22, 10, 22\n\t" + "lbzx 23, 10, 23\n\t" + "ld 16, 0(28)\n\t" + "ld 17, 8(28)\n\t" + "rldimi 11, 20, 56, 0\n\t" + "rlwimi 11, 21, 24, 0, 7\n\t" + "rldimi 12, 22, 56, 0\n\t" + "rlwimi 12, 23, 24, 0, 7\n\t" + "addi 28, 28, 16\n\t" + /* XOR in Key Schedule */ + "xor 11, 11, 16\n\t" + "xor 12, 12, 17\n\t" + "xor 11, 11, 26\n\t" + "xor 12, 12, 27\n\t" + "std 11, 0(%[out])\n\t" + "std 12, 8(%[out])\n\t" + "addic. %[len], %[len], -16\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "bne L_AES_CBC_decrypt_loop_block_%=\n\t" + "std 24, 0(%[iv])\n\t" + "std 25, 8(%[iv])\n\t" + "b L_AES_CBC_decrypt_end_dec_%=\n\t" + "\n" + "L_AES_CBC_decrypt_end_dec_odd_%=: \n\t" + "std 26, 0(%[iv])\n\t" + "std 27, 8(%[iv])\n\t" + "\n" + "L_AES_CBC_decrypt_end_dec_%=: \n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [len] "+r" (len), [ks] "+r" (ks), + [nr] "+r" (nr), [iv] "+r" (iv), + [L_AES_PPC64_td] "+r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "+r" (L_AES_PPC64_td4_c) + : + : "memory", "cc", "0", "11", "12", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28" +#else + : + : [in] "r" (in), [out] "r" (out), [len] "r" (len), [ks] "r" (ks), + [nr] "r" (nr), [iv] "r" (iv), [L_AES_PPC64_td] "r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "r" (L_AES_PPC64_td4_c) + : "memory", "cc", "0", "9", "10", "11", "12", "14", "15", "16", "17", + "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* HAVE_AES_CBC */ +#endif /* WOLFSSL_AES_DIRECT || WOLFSSL_AES_COUNTER || HAVE_AES_CBC + * HAVE_AES_ECB */ +#ifdef WOLFSSL_AES_XTS +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void AES_XTS_decrypt(const byte* in_p, byte* out_p, word32 sz_p, + const byte* i_p, byte* key_p, byte* key2_p, byte* tmp_p, int nr_p) +#else +void AES_XTS_decrypt(const byte* in, byte* out, word32 sz, const byte* i, + byte* key, byte* key2, byte* tmp, int nr) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register const byte* in asm ("3") = (const byte*)in_p; + register byte* out asm ("4") = (byte*)out_p; + register word32 sz asm ("5") = (word32)sz_p; + register const byte* i asm ("6") = (const byte*)i_p; + register byte* key asm ("7") = (byte*)key_p; + register byte* key2 asm ("8") = (byte*)key2_p; + register byte* tmp asm ("9") = (byte*)tmp_p; + register int nr asm ("10") = (int)nr_p; + register word32* L_AES_PPC64_td_c asm ("11") = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c asm ("12") = (byte*)&L_AES_PPC64_td4; + register word32* L_AES_PPC64_te4_0_c asm ("14") = + (word32*)&L_AES_PPC64_te4_0; +#else + register word32* L_AES_PPC64_td_c = (word32*)&L_AES_PPC64_td; + register byte* L_AES_PPC64_td4_c = (byte*)&L_AES_PPC64_td4; + register word32* L_AES_PPC64_te4_0_c = (word32*)&L_AES_PPC64_te4_0; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( + "subi 1, 1, 8\n\t" +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 14, %[L_AES_PPC64_te4_0]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 15, 14, 0x400\n\t" + "addi 16, 14, 0x800\n\t" + "addi 17, 14, 0xc00\n\t" + "andi. 18, %[sz], 15\n\t" + "addi 18, 18, 15\n\t" + "andi. 18, 18, 16\n\t" + "subf %[sz], 18, %[sz]\n\t" + "ld 26, 0(%[i])\n\t" + "ld 27, 8(%[i])\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldicr 26, 26, 32, 63\n\t" + "rldicr 27, 27, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 26, 26, 18\n\t" + "xor 27, 27, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(14)\n\t" + "ld 21, 32(14)\n\t" + "ld 21, 64(14)\n\t" + "ld 21, 96(14)\n\t" + "ld 21, 128(14)\n\t" + "ld 21, 160(14)\n\t" + "ld 21, 192(14)\n\t" + "ld 21, 224(14)\n\t" + "ld 21, 256(14)\n\t" + "ld 21, 288(14)\n\t" + "ld 21, 320(14)\n\t" + "ld 21, 352(14)\n\t" + "ld 21, 384(14)\n\t" + "ld 21, 416(14)\n\t" + "ld 21, 448(14)\n\t" + "ld 21, 480(14)\n\t" + "ld 21, 512(14)\n\t" + "ld 21, 544(14)\n\t" + "ld 21, 576(14)\n\t" + "ld 21, 608(14)\n\t" + "ld 21, 640(14)\n\t" + "ld 21, 672(14)\n\t" + "ld 21, 704(14)\n\t" + "ld 21, 736(14)\n\t" + "ld 21, 768(14)\n\t" + "ld 21, 800(14)\n\t" + "ld 21, 832(14)\n\t" + "ld 21, 864(14)\n\t" + "ld 21, 896(14)\n\t" + "ld 21, 928(14)\n\t" + "ld 21, 960(14)\n\t" + "ld 21, 992(14)\n\t" + "ld 21, 1024(14)\n\t" + "ld 21, 1056(14)\n\t" + "ld 21, 1088(14)\n\t" + "ld 21, 1120(14)\n\t" + "ld 21, 1152(14)\n\t" + "ld 21, 1184(14)\n\t" + "ld 21, 1216(14)\n\t" + "ld 21, 1248(14)\n\t" + "ld 21, 1280(14)\n\t" + "ld 21, 1312(14)\n\t" + "ld 21, 1344(14)\n\t" + "ld 21, 1376(14)\n\t" + "ld 21, 1408(14)\n\t" + "ld 21, 1440(14)\n\t" + "ld 21, 1472(14)\n\t" + "ld 21, 1504(14)\n\t" + "ld 21, 1536(14)\n\t" + "ld 21, 1568(14)\n\t" + "ld 21, 1600(14)\n\t" + "ld 21, 1632(14)\n\t" + "ld 21, 1664(14)\n\t" + "ld 21, 1696(14)\n\t" + "ld 21, 1728(14)\n\t" + "ld 21, 1760(14)\n\t" + "ld 21, 1792(14)\n\t" + "ld 21, 1824(14)\n\t" + "ld 21, 1856(14)\n\t" + "ld 21, 1888(14)\n\t" + "ld 21, 1920(14)\n\t" + "ld 21, 1952(14)\n\t" + "ld 21, 1984(14)\n\t" + "ld 21, 2016(14)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_decrypt_loop_nr_tweak_%=: \n\t" + "srdi 28, 26, 32\n\t" + "srdi 29, 27, 32\n\t" + "rlwinm 18, 26, 10, 22, 29\n\t" + "rlwinm 19, 27, 10, 22, 29\n\t" + "rlwinm 20, 28, 10, 22, 29\n\t" + "rlwinm 21, 29, 10, 22, 29\n\t" + "lwzx 18, 14, 18\n\t" + "lwzx 19, 14, 19\n\t" + "lwzx 20, 14, 20\n\t" + "lwzx 21, 14, 21\n\t" + "rlwinm 22, 28, 18, 22, 29\n\t" + "rlwinm 23, 27, 18, 22, 29\n\t" + "rlwinm 24, 29, 18, 22, 29\n\t" + "rlwinm 25, 26, 18, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 27, 26, 22, 29\n\t" + "rlwinm 23, 29, 26, 22, 29\n\t" + "rlwinm 24, 26, 26, 22, 29\n\t" + "rlwinm 25, 28, 26, 22, 29\n\t" + "lwzx 22, 16, 22\n\t" + "lwzx 23, 16, 23\n\t" + "lwzx 24, 16, 24\n\t" + "lwzx 25, 16, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 29, 2, 22, 29\n\t" + "rlwinm 23, 26, 2, 22, 29\n\t" + "rlwinm 24, 28, 2, 22, 29\n\t" + "rlwinm 25, 27, 2, 22, 29\n\t" + "lwzx 22, 17, 22\n\t" + "lwzx 23, 17, 23\n\t" + "lwzx 24, 17, 24\n\t" + "lwzx 25, 17, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 26, 0(%[key2])\n\t" + "ld 27, 8(%[key2])\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 26\n\t" + "xor 19, 19, 27\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 26, 18, 10, 22, 29\n\t" + "rlwinm 27, 19, 10, 22, 29\n\t" + "rlwinm 28, 20, 10, 22, 29\n\t" + "rlwinm 29, 21, 10, 22, 29\n\t" + "lwzx 26, 14, 26\n\t" + "lwzx 27, 14, 27\n\t" + "lwzx 28, 14, 28\n\t" + "lwzx 29, 14, 29\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "xor 26, 26, 22\n\t" + "xor 28, 28, 23\n\t" + "xor 27, 27, 24\n\t" + "xor 29, 29, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 16, 22\n\t" + "lwzx 23, 16, 23\n\t" + "lwzx 24, 16, 24\n\t" + "lwzx 25, 16, 25\n\t" + "xor 26, 26, 22\n\t" + "xor 28, 28, 23\n\t" + "xor 27, 27, 24\n\t" + "xor 29, 29, 25\n\t" + "rlwinm 22, 21, 2, 22, 29\n\t" + "rlwinm 23, 18, 2, 22, 29\n\t" + "rlwinm 24, 20, 2, 22, 29\n\t" + "rlwinm 25, 19, 2, 22, 29\n\t" + "lwzx 22, 17, 22\n\t" + "lwzx 23, 17, 23\n\t" + "lwzx 24, 17, 24\n\t" + "lwzx 25, 17, 25\n\t" + "xor 26, 26, 22\n\t" + "xor 28, 28, 23\n\t" + "xor 27, 27, 24\n\t" + "xor 29, 29, 25\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "rldimi 26, 28, 32, 0\n\t" + "rldimi 27, 29, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 26, 26, 18\n\t" + "xor 27, 27, 19\n\t" + "bdnz L_AES_XTS_decrypt_loop_nr_tweak_%=\n\t" + "srdi 28, 26, 32\n\t" + "srdi 29, 27, 32\n\t" + "rlwinm 18, 26, 10, 22, 29\n\t" + "rlwinm 19, 27, 10, 22, 29\n\t" + "rlwinm 20, 28, 10, 22, 29\n\t" + "rlwinm 21, 29, 10, 22, 29\n\t" + "lwzx 18, 14, 18\n\t" + "lwzx 19, 14, 19\n\t" + "lwzx 20, 14, 20\n\t" + "lwzx 21, 14, 21\n\t" + "rlwinm 22, 28, 18, 22, 29\n\t" + "rlwinm 23, 27, 18, 22, 29\n\t" + "rlwinm 24, 29, 18, 22, 29\n\t" + "rlwinm 25, 26, 18, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 27, 26, 22, 29\n\t" + "rlwinm 23, 29, 26, 22, 29\n\t" + "rlwinm 24, 26, 26, 22, 29\n\t" + "rlwinm 25, 28, 26, 22, 29\n\t" + "lwzx 22, 16, 22\n\t" + "lwzx 23, 16, 23\n\t" + "lwzx 24, 16, 24\n\t" + "lwzx 25, 16, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 29, 2, 22, 29\n\t" + "rlwinm 23, 26, 2, 22, 29\n\t" + "rlwinm 24, 28, 2, 22, 29\n\t" + "rlwinm 25, 27, 2, 22, 29\n\t" + "lwzx 22, 17, 22\n\t" + "lwzx 23, 17, 23\n\t" + "lwzx 24, 17, 24\n\t" + "lwzx 25, 17, 25\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "ld 26, 0(%[key2])\n\t" + "ld 27, 8(%[key2])\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 26\n\t" + "xor 19, 19, 27\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 26, 18, 2, 22, 29\n\t" + "rlwinm 27, 19, 2, 22, 29\n\t" + "rlwinm 29, 20, 2, 22, 29\n\t" + "rlwinm 28, 21, 2, 22, 29\n\t" + "lwzx 26, 15, 26\n\t" + "lwzx 27, 15, 27\n\t" + "lwzx 29, 15, 29\n\t" + "lwzx 28, 15, 28\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rldimi 27, 29, 32, 24\n\t" + "rldimi 26, 28, 32, 24\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "rldimi 26, 22, 40, 16\n\t" + "rlwimi 26, 23, 8, 16, 23\n\t" + "rldimi 27, 24, 40, 16\n\t" + "rlwimi 27, 25, 8, 16, 23\n\t" + "rlwinm 22, 20, 18, 22, 29\n\t" + "rlwinm 23, 19, 18, 22, 29\n\t" + "rlwinm 24, 21, 18, 22, 29\n\t" + "rlwinm 25, 18, 18, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "rldimi 26, 22, 48, 8\n\t" + "rlwimi 26, 23, 16, 8, 15\n\t" + "rldimi 27, 24, 48, 8\n\t" + "rlwimi 27, 25, 16, 8, 15\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 15, 22\n\t" + "lwzx 23, 15, 23\n\t" + "lwzx 24, 15, 24\n\t" + "lwzx 25, 15, 25\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "rldimi 26, 22, 56, 0\n\t" + "rlwimi 26, 23, 24, 0, 7\n\t" + "rldimi 27, 24, 56, 0\n\t" + "rlwimi 27, 25, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 26, 26, 18\n\t" + "xor 27, 27, 19\n\t" + "std 26, 0(%[tmp])\n\t" + "std 27, 8(%[tmp])\n\t" +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 11, %[L_AES_PPC64_td]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 12, %[L_AES_PPC64_td4]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "cmpdi %[sz], 16\n\t" + "blt L_AES_XTS_decrypt_start_partail_%=\n\t" + "\n" + "L_AES_XTS_decrypt_loop_block_%=: \n\t" + "addi %[key2], %[key], 0\n\t" + "ld 14, 0(%[in])\n\t" + "ld 15, 8(%[in])\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "xor 14, 14, 26\n\t" + "xor 15, 15, 27\n\t" + "rldicr 14, 14, 32, 63\n\t" + "rldicr 15, 15, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(11)\n\t" + "ld 21, 64(11)\n\t" + "ld 21, 128(11)\n\t" + "ld 21, 192(11)\n\t" + "ld 21, 256(11)\n\t" + "ld 21, 320(11)\n\t" + "ld 21, 384(11)\n\t" + "ld 21, 448(11)\n\t" + "ld 21, 512(11)\n\t" + "ld 21, 576(11)\n\t" + "ld 21, 640(11)\n\t" + "ld 21, 704(11)\n\t" + "ld 21, 768(11)\n\t" + "ld 21, 832(11)\n\t" + "ld 21, 896(11)\n\t" + "ld 21, 960(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_decrypt_loop_nr_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 21, 18, 22, 29\n\t" + "rlwinm 16, 18, 18, 22, 29\n\t" + "rlwinm 15, 20, 18, 22, 29\n\t" + "rlwinm 17, 19, 18, 22, 29\n\t" + "lwzx 14, 11, 14\n\t" + "lwzx 16, 11, 16\n\t" + "lwzx 15, 11, 15\n\t" + "lwzx 17, 11, 17\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 20, 2, 22, 29\n\t" + "rlwinm 23, 19, 2, 22, 29\n\t" + "rlwinm 24, 21, 2, 22, 29\n\t" + "rlwinm 25, 18, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_XTS_decrypt_loop_nr_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "ld 21, 0(12)\n\t" + "ld 21, 64(12)\n\t" + "ld 21, 128(12)\n\t" + "ld 21, 192(12)\n\t" + "ld 21, 256(12)\n\t" + "ld 21, 320(12)\n\t" + "ld 21, 384(12)\n\t" + "ld 21, 448(12)\n\t" + "ld 21, 512(12)\n\t" + "ld 21, 576(12)\n\t" + "ld 21, 640(12)\n\t" + "ld 21, 704(12)\n\t" + "ld 21, 768(12)\n\t" + "ld 21, 832(12)\n\t" + "ld 21, 896(12)\n\t" + "ld 21, 960(12)\n\t" + "rldicl 16, 18, 32, 56\n\t" + "andi. 14, 19, 255\n\t" + "rldicl 17, 19, 32, 56\n\t" + "andi. 15, 18, 255\n\t" + "lbzx 16, 12, 16\n\t" + "lbzx 14, 12, 14\n\t" + "lbzx 17, 12, 17\n\t" + "lbzx 15, 12, 15\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldicl 22, 19, 56, 56\n\t" + "rldicl 23, 19, 24, 56\n\t" + "rldicl 24, 18, 56, 56\n\t" + "rldicl 25, 18, 24, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 40, 16\n\t" + "rlwimi 14, 23, 8, 16, 23\n\t" + "rldimi 15, 24, 40, 16\n\t" + "rlwimi 15, 25, 8, 16, 23\n\t" + "rldicl 22, 19, 16, 56\n\t" + "rldicl 23, 18, 48, 56\n\t" + "rldicl 24, 18, 16, 56\n\t" + "rldicl 25, 19, 48, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 48, 8\n\t" + "rlwimi 14, 23, 16, 8, 15\n\t" + "rldimi 15, 24, 48, 8\n\t" + "rlwimi 15, 25, 16, 8, 15\n\t" + "rldicl 22, 18, 40, 56\n\t" + "rldicl 23, 18, 8, 56\n\t" + "rldicl 24, 19, 40, 56\n\t" + "rldicl 25, 19, 8, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "rldimi 14, 22, 56, 0\n\t" + "rlwimi 14, 23, 24, 0, 7\n\t" + "rldimi 15, 24, 56, 0\n\t" + "rlwimi 15, 25, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "xor 14, 14, 26\n\t" + "xor 15, 15, 27\n\t" + "li 17, 8\n\t" + "ldbrx 26, 0, %[tmp]\n\t" + "ldbrx 27, %[tmp], 17\n\t" + "std 14, 0(%[out])\n\t" + "std 15, 8(%[out])\n\t" + "sradi 22, 27, 63\n\t" + "srdi 23, 26, 63\n\t" + "sldi 27, 27, 1\n\t" + "andi. 22, 22, 0x87\n\t" + "sldi 26, 26, 1\n\t" + "xor 27, 27, 23\n\t" + "xor 26, 26, 22\n\t" + "stdbrx 26, 0, %[tmp]\n\t" + "stdbrx 27, %[tmp], 17\n\t" + "ld 26, 0(%[tmp])\n\t" + "ld 27, 8(%[tmp])\n\t" + "addi %[sz], %[sz], -16\n\t" + "addi %[in], %[in], 16\n\t" + "addi %[out], %[out], 16\n\t" + "cmpdi %[sz], 16\n\t" + "bge L_AES_XTS_decrypt_loop_block_%=\n\t" + "cmpdi %[sz], 0\n\t" + "beq L_AES_XTS_decrypt_done_data_%=\n\t" + "\n" + "L_AES_XTS_decrypt_start_partail_%=: \n\t" + "li 17, 8\n\t" + "ldbrx 28, 0, %[tmp]\n\t" + "ldbrx 29, %[tmp], 17\n\t" + "sradi 22, 29, 63\n\t" + "srdi 23, 28, 63\n\t" + "sldi 29, 29, 1\n\t" + "andi. 22, 22, 0x87\n\t" + "sldi 28, 28, 1\n\t" + "xor 29, 29, 23\n\t" + "xor 28, 28, 22\n\t" + "stdbrx 28, 0, %[tmp]\n\t" + "stdbrx 29, %[tmp], 17\n\t" + "ld 28, 0(%[tmp])\n\t" + "ld 29, 8(%[tmp])\n\t" + "addi %[key2], %[key], 0\n\t" + "ld 14, 0(%[in])\n\t" + "ld 15, 8(%[in])\n\t" + "addi %[in], %[in], 16\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "xor 14, 14, 28\n\t" + "xor 15, 15, 29\n\t" + "rldicr 14, 14, 32, 63\n\t" + "rldicr 15, 15, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(11)\n\t" + "ld 21, 64(11)\n\t" + "ld 21, 128(11)\n\t" + "ld 21, 192(11)\n\t" + "ld 21, 256(11)\n\t" + "ld 21, 320(11)\n\t" + "ld 21, 384(11)\n\t" + "ld 21, 448(11)\n\t" + "ld 21, 512(11)\n\t" + "ld 21, 576(11)\n\t" + "ld 21, 640(11)\n\t" + "ld 21, 704(11)\n\t" + "ld 21, 768(11)\n\t" + "ld 21, 832(11)\n\t" + "ld 21, 896(11)\n\t" + "ld 21, 960(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_decrypt_loop_nr_partial_1_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 21, 18, 22, 29\n\t" + "rlwinm 16, 18, 18, 22, 29\n\t" + "rlwinm 15, 20, 18, 22, 29\n\t" + "rlwinm 17, 19, 18, 22, 29\n\t" + "lwzx 14, 11, 14\n\t" + "lwzx 16, 11, 16\n\t" + "lwzx 15, 11, 15\n\t" + "lwzx 17, 11, 17\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 20, 2, 22, 29\n\t" + "rlwinm 23, 19, 2, 22, 29\n\t" + "rlwinm 24, 21, 2, 22, 29\n\t" + "rlwinm 25, 18, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_XTS_decrypt_loop_nr_partial_1_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "ld 21, 0(12)\n\t" + "ld 21, 64(12)\n\t" + "ld 21, 128(12)\n\t" + "ld 21, 192(12)\n\t" + "ld 21, 256(12)\n\t" + "ld 21, 320(12)\n\t" + "ld 21, 384(12)\n\t" + "ld 21, 448(12)\n\t" + "ld 21, 512(12)\n\t" + "ld 21, 576(12)\n\t" + "ld 21, 640(12)\n\t" + "ld 21, 704(12)\n\t" + "ld 21, 768(12)\n\t" + "ld 21, 832(12)\n\t" + "ld 21, 896(12)\n\t" + "ld 21, 960(12)\n\t" + "rldicl 16, 18, 32, 56\n\t" + "andi. 14, 19, 255\n\t" + "rldicl 17, 19, 32, 56\n\t" + "andi. 15, 18, 255\n\t" + "lbzx 16, 12, 16\n\t" + "lbzx 14, 12, 14\n\t" + "lbzx 17, 12, 17\n\t" + "lbzx 15, 12, 15\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldicl 22, 19, 56, 56\n\t" + "rldicl 23, 19, 24, 56\n\t" + "rldicl 24, 18, 56, 56\n\t" + "rldicl 25, 18, 24, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 40, 16\n\t" + "rlwimi 14, 23, 8, 16, 23\n\t" + "rldimi 15, 24, 40, 16\n\t" + "rlwimi 15, 25, 8, 16, 23\n\t" + "rldicl 22, 19, 16, 56\n\t" + "rldicl 23, 18, 48, 56\n\t" + "rldicl 24, 18, 16, 56\n\t" + "rldicl 25, 19, 48, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 48, 8\n\t" + "rlwimi 14, 23, 16, 8, 15\n\t" + "rldimi 15, 24, 48, 8\n\t" + "rlwimi 15, 25, 16, 8, 15\n\t" + "rldicl 22, 18, 40, 56\n\t" + "rldicl 23, 18, 8, 56\n\t" + "rldicl 24, 19, 40, 56\n\t" + "rldicl 25, 19, 8, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "rldimi 14, 22, 56, 0\n\t" + "rlwimi 14, 23, 24, 0, 7\n\t" + "rldimi 15, 24, 56, 0\n\t" + "rlwimi 15, 25, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "xor 14, 14, 28\n\t" + "xor 15, 15, 29\n\t" + "std 14, 0(%[tmp])\n\t" + "std 15, 8(%[tmp])\n\t" + "addi %[out], %[out], 16\n\t" + "addi 18, %[sz], 0\n\t" + "\n" + "L_AES_XTS_decrypt_start_byte_%=: \n\t" + "lbz 22, 0(%[tmp])\n\t" + "lbz 23, 0(%[in])\n\t" + "addi %[in], %[in], 1\n\t" + "stb 22, 0(%[out])\n\t" + "addi %[out], %[out], 1\n\t" + "stb 23, 0(%[tmp])\n\t" + "addi %[tmp], %[tmp], 1\n\t" + "addic. 18, 18, -1\n\t" + "bne L_AES_XTS_decrypt_start_byte_%=\n\t" + "subf %[out], %[sz], %[out]\n\t" + "subf %[tmp], %[sz], %[tmp]\n\t" + "addi %[out], %[out], -16\n\t" + "addi %[key2], %[key], 0\n\t" + "ld 14, 0(%[tmp])\n\t" + "ld 15, 8(%[tmp])\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "addi %[key2], %[key2], 16\n\t" + "xor 14, 14, 26\n\t" + "xor 15, 15, 27\n\t" + "rldicr 14, 14, 32, 63\n\t" + "rldicr 15, 15, 32, 63\n\t" + /* Round: 0 - XOR in key schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "addi 0, %[nr], -2\n\t" +#ifndef WOLFSSL_PPC64_ASM_AES_NO_HARDEN + "ld 21, 0(11)\n\t" + "ld 21, 64(11)\n\t" + "ld 21, 128(11)\n\t" + "ld 21, 192(11)\n\t" + "ld 21, 256(11)\n\t" + "ld 21, 320(11)\n\t" + "ld 21, 384(11)\n\t" + "ld 21, 448(11)\n\t" + "ld 21, 512(11)\n\t" + "ld 21, 576(11)\n\t" + "ld 21, 640(11)\n\t" + "ld 21, 704(11)\n\t" + "ld 21, 768(11)\n\t" + "ld 21, 832(11)\n\t" + "ld 21, 896(11)\n\t" + "ld 21, 960(11)\n\t" +#endif /* !WOLFSSL_PPC64_ASM_AES_NO_HARDEN */ + "srwi 0, 0, 1\n\t" + "mtctr 0\n\t" + "\n" + "L_AES_XTS_decrypt_loop_nr_partial_2_%=: \n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "srdi 20, 18, 32\n\t" + "srdi 21, 19, 32\n\t" + "rlwinm 14, 21, 18, 22, 29\n\t" + "rlwinm 16, 18, 18, 22, 29\n\t" + "rlwinm 15, 20, 18, 22, 29\n\t" + "rlwinm 17, 19, 18, 22, 29\n\t" + "lwzx 14, 11, 14\n\t" + "lwzx 16, 11, 16\n\t" + "lwzx 15, 11, 15\n\t" + "lwzx 17, 11, 17\n\t" + "rlwinm 22, 18, 10, 22, 29\n\t" + "rlwinm 23, 20, 10, 22, 29\n\t" + "rlwinm 24, 19, 10, 22, 29\n\t" + "rlwinm 25, 21, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 19, 26, 22, 29\n\t" + "rlwinm 23, 21, 26, 22, 29\n\t" + "rlwinm 24, 18, 26, 22, 29\n\t" + "rlwinm 25, 20, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "rlwinm 22, 20, 2, 22, 29\n\t" + "rlwinm 23, 19, 2, 22, 29\n\t" + "rlwinm 24, 21, 2, 22, 29\n\t" + "rlwinm 25, 18, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "xor 14, 14, 22\n\t" + "xor 16, 16, 23\n\t" + "xor 15, 15, 24\n\t" + "xor 17, 17, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 14, 16, 32, 0\n\t" + "rldimi 15, 17, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "bdnz L_AES_XTS_decrypt_loop_nr_partial_2_%=\n\t" + "srdi 16, 14, 32\n\t" + "srdi 17, 15, 32\n\t" + "rlwinm 18, 17, 18, 22, 29\n\t" + "rlwinm 20, 14, 18, 22, 29\n\t" + "rlwinm 19, 16, 18, 22, 29\n\t" + "rlwinm 21, 15, 18, 22, 29\n\t" + "lwzx 18, 11, 18\n\t" + "lwzx 20, 11, 20\n\t" + "lwzx 19, 11, 19\n\t" + "lwzx 21, 11, 21\n\t" + "rlwinm 22, 14, 10, 22, 29\n\t" + "rlwinm 23, 16, 10, 22, 29\n\t" + "rlwinm 24, 15, 10, 22, 29\n\t" + "rlwinm 25, 17, 10, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 8, 0, 31\n\t" + "rlwimi 23, 23, 8, 0, 31\n\t" + "rlwimi 24, 24, 8, 0, 31\n\t" + "rlwimi 25, 25, 8, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 15, 26, 22, 29\n\t" + "rlwinm 23, 17, 26, 22, 29\n\t" + "rlwinm 24, 14, 26, 22, 29\n\t" + "rlwinm 25, 16, 26, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 24, 0, 31\n\t" + "rlwimi 23, 23, 24, 0, 31\n\t" + "rlwimi 24, 24, 24, 0, 31\n\t" + "rlwimi 25, 25, 24, 0, 31\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "rlwinm 22, 16, 2, 22, 29\n\t" + "rlwinm 23, 15, 2, 22, 29\n\t" + "rlwinm 24, 17, 2, 22, 29\n\t" + "rlwinm 25, 14, 2, 22, 29\n\t" + "lwzx 22, 11, 22\n\t" + "lwzx 23, 11, 23\n\t" + "lwzx 24, 11, 24\n\t" + "lwzx 25, 11, 25\n\t" + "rlwimi 22, 22, 16, 0, 31\n\t" + "rlwimi 23, 23, 16, 0, 31\n\t" + "rlwimi 24, 24, 16, 0, 31\n\t" + "rlwimi 25, 25, 16, 0, 31\n\t" + "ld 14, 0(%[key2])\n\t" + "ld 15, 8(%[key2])\n\t" + "xor 18, 18, 22\n\t" + "xor 20, 20, 23\n\t" + "xor 19, 19, 24\n\t" + "xor 21, 21, 25\n\t" + "addi %[key2], %[key2], 16\n\t" + "rldimi 18, 20, 32, 0\n\t" + "rldimi 19, 21, 32, 0\n\t" + /* XOR in Key Schedule */ + "xor 18, 18, 14\n\t" + "xor 19, 19, 15\n\t" + "ld 21, 0(12)\n\t" + "ld 21, 64(12)\n\t" + "ld 21, 128(12)\n\t" + "ld 21, 192(12)\n\t" + "ld 21, 256(12)\n\t" + "ld 21, 320(12)\n\t" + "ld 21, 384(12)\n\t" + "ld 21, 448(12)\n\t" + "ld 21, 512(12)\n\t" + "ld 21, 576(12)\n\t" + "ld 21, 640(12)\n\t" + "ld 21, 704(12)\n\t" + "ld 21, 768(12)\n\t" + "ld 21, 832(12)\n\t" + "ld 21, 896(12)\n\t" + "ld 21, 960(12)\n\t" + "rldicl 16, 18, 32, 56\n\t" + "andi. 14, 19, 255\n\t" + "rldicl 17, 19, 32, 56\n\t" + "andi. 15, 18, 255\n\t" + "lbzx 16, 12, 16\n\t" + "lbzx 14, 12, 14\n\t" + "lbzx 17, 12, 17\n\t" + "lbzx 15, 12, 15\n\t" + "rldimi 14, 16, 32, 24\n\t" + "rldimi 15, 17, 32, 24\n\t" + "rldicl 22, 19, 56, 56\n\t" + "rldicl 23, 19, 24, 56\n\t" + "rldicl 24, 18, 56, 56\n\t" + "rldicl 25, 18, 24, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 40, 16\n\t" + "rlwimi 14, 23, 8, 16, 23\n\t" + "rldimi 15, 24, 40, 16\n\t" + "rlwimi 15, 25, 8, 16, 23\n\t" + "rldicl 22, 19, 16, 56\n\t" + "rldicl 23, 18, 48, 56\n\t" + "rldicl 24, 18, 16, 56\n\t" + "rldicl 25, 19, 48, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "rldimi 14, 22, 48, 8\n\t" + "rlwimi 14, 23, 16, 8, 15\n\t" + "rldimi 15, 24, 48, 8\n\t" + "rlwimi 15, 25, 16, 8, 15\n\t" + "rldicl 22, 18, 40, 56\n\t" + "rldicl 23, 18, 8, 56\n\t" + "rldicl 24, 19, 40, 56\n\t" + "rldicl 25, 19, 8, 56\n\t" + "lbzx 22, 12, 22\n\t" + "lbzx 23, 12, 23\n\t" + "lbzx 24, 12, 24\n\t" + "lbzx 25, 12, 25\n\t" + "ld 18, 0(%[key2])\n\t" + "ld 19, 8(%[key2])\n\t" + "rldimi 14, 22, 56, 0\n\t" + "rlwimi 14, 23, 24, 0, 7\n\t" + "rldimi 15, 24, 56, 0\n\t" + "rlwimi 15, 25, 24, 0, 7\n\t" + "addi %[key2], %[key2], 16\n\t" + /* XOR in Key Schedule */ + "xor 14, 14, 18\n\t" + "xor 15, 15, 19\n\t" + "xor 14, 14, 26\n\t" + "xor 15, 15, 27\n\t" + "std 14, 0(%[out])\n\t" + "std 15, 8(%[out])\n\t" + "\n" + "L_AES_XTS_decrypt_done_data_%=: \n\t" + "addi 1, 1, 8\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [in] "+r" (in), [out] "+r" (out), [sz] "+r" (sz), [i] "+r" (i), + [key] "+r" (key), [key2] "+r" (key2), [tmp] "+r" (tmp), + [nr] "+r" (nr), [L_AES_PPC64_td] "+r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "+r" (L_AES_PPC64_td4_c), + [L_AES_PPC64_te4_0] "+r" (L_AES_PPC64_te4_0_c) + : + : "memory", "cc", "0", "15", "16", "17", "18", "19", "20", "21", "22", + "23", "24", "25", "26", "27", "28", "29" +#else + : + : [in] "r" (in), [out] "r" (out), [sz] "r" (sz), [i] "r" (i), + [key] "r" (key), [key2] "r" (key2), [tmp] "r" (tmp), [nr] "r" (nr), + [L_AES_PPC64_td] "r" (L_AES_PPC64_td_c), + [L_AES_PPC64_td4] "r" (L_AES_PPC64_td4_c), + [L_AES_PPC64_te4_0] "r" (L_AES_PPC64_te4_0_c) + : "memory", "cc", "0", "11", "12", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28", "29" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* WOLFSSL_AES_XTS */ +#endif /* HAVE_AES_DECRYPT */ +#ifdef HAVE_AESGCM +#ifdef GCM_TABLE_4BIT +static const word32 L_GCM_gmult_len_r[] = { + 0x00000000, 0x1c200000, 0x38400000, 0x24600000, + 0x70800000, 0x6ca00000, 0x48c00000, 0x54e00000, + 0xe1000000, 0xfd200000, 0xd9400000, 0xc5600000, + 0x91800000, 0x8da00000, 0xa9c00000, 0xb5e00000, + 0x00000000, 0x01c20000, 0x03840000, 0x02460000, + 0x07080000, 0x06ca0000, 0x048c0000, 0x054e0000, + 0x0e100000, 0x0fd20000, 0x0d940000, 0x0c560000, + 0x09180000, 0x08da0000, 0x0a9c0000, 0x0b5e0000, +}; + +void GCM_gmult_len(unsigned char* x, const unsigned char** m, + const unsigned char* data, unsigned long len); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void GCM_gmult_len(unsigned char* x_p, const unsigned char** m_p, + const unsigned char* data_p, unsigned long len_p) +#else +void GCM_gmult_len(unsigned char* x, const unsigned char** m, + const unsigned char* data, unsigned long len) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register unsigned char* x asm ("3") = (unsigned char*)x_p; + register const unsigned char** m asm ("4") = (const unsigned char**)m_p; + register const unsigned char* data asm ("5") = + (const unsigned char*)data_p; + register unsigned long len asm ("6") = (unsigned long)len_p; + register word32* L_GCM_gmult_len_r_c asm ("7") = + (word32*)&L_GCM_gmult_len_r; +#else + register word32* L_GCM_gmult_len_r_c = (word32*)&L_GCM_gmult_len_r; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( + "li 21, 0x100\n\t" + "li 25, 8\n\t" +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 7, %[L_GCM_gmult_len_r]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "add 21, 21, %[m]\n\t" + "addi 20, %[m], 8\n\t" + "addi 22, 21, 8\n\t" + "addi 8, 7, 0x40\n\t" + "\n" + "L_GCM_gmult_len_start_block_%=: \n\t" + "ldbrx 18, 0, %[x]\n\t" + "ldbrx 19, 25, %[x]\n\t" + "ldbrx 9, 0, %[data]\n\t" + "ldbrx 10, 25, %[data]\n\t" + "xor 18, 18, 9\n\t" + "xor 19, 19, 10\n\t" + "rldicr 0, 19, 32, 63\n\t" + /* Byte 15 */ + "rlwinm 23, 0, 12, 24, 27\n\t" + "rlwinm 24, 0, 8, 24, 27\n\t" + "ldx 14, 23, %[m]\n\t" + "ldx 15, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 14 */ + "rlwinm 23, 0, 20, 24, 27\n\t" + "rlwinm 24, 0, 16, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 13 */ + "rlwinm 23, 0, 28, 24, 27\n\t" + "rlwinm 24, 0, 24, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 12 */ + "rlwinm 23, 0, 4, 24, 27\n\t" + "rlwinm 24, 0, 0, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 11 */ + "rlwinm 23, 19, 12, 24, 27\n\t" + "rlwinm 24, 19, 8, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 10 */ + "rlwinm 23, 19, 20, 24, 27\n\t" + "rlwinm 24, 19, 16, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 9 */ + "rlwinm 23, 19, 28, 24, 27\n\t" + "rlwinm 24, 19, 24, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 8 */ + "rlwinm 23, 19, 4, 24, 27\n\t" + "rlwinm 24, 19, 0, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + "rldicr 0, 18, 32, 63\n\t" + /* Byte 7 */ + "rlwinm 23, 0, 12, 24, 27\n\t" + "rlwinm 24, 0, 8, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 6 */ + "rlwinm 23, 0, 20, 24, 27\n\t" + "rlwinm 24, 0, 16, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 5 */ + "rlwinm 23, 0, 28, 24, 27\n\t" + "rlwinm 24, 0, 24, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 4 */ + "rlwinm 23, 0, 4, 24, 27\n\t" + "rlwinm 24, 0, 0, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 3 */ + "rlwinm 23, 18, 12, 24, 27\n\t" + "rlwinm 24, 18, 8, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 2 */ + "rlwinm 23, 18, 20, 24, 27\n\t" + "rlwinm 24, 18, 16, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 1 */ + "rlwinm 23, 18, 28, 24, 27\n\t" + "rlwinm 24, 18, 24, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, 21\n\t" + "ldx 12, 24, 22\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "ldx 10, 24, 20\n\t" + "rldicl 16, 15, 60, 60\n\t" + "rldic 17, 15, 2, 58\n\t" + "srdi 15, 15, 8\n\t" + "rldimi 15, 14, 56, 0\n\t" + "srdi 14, 14, 8\n\t" + "lwzx 9, 17, 8\n\t" + "xor 16, 16, 10\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 16, 2, 26, 29\n\t" + "lwzx 10, 16, 7\n\t" + "xor 15, 15, 12\n\t" + "sldi 9, 9, 32\n\t" + "xor 14, 14, 9\n\t" + "sldi 10, 10, 32\n\t" + "xor 14, 14, 10\n\t" + /* Byte 0 */ + "rlwinm 23, 18, 4, 24, 27\n\t" + "rlwinm 24, 18, 0, 24, 27\n\t" + "ldx 9, 23, %[m]\n\t" + "ldx 10, 23, 20\n\t" + "ldx 11, 24, %[m]\n\t" + "ldx 12, 24, 20\n\t" + "xor 14, 14, 9\n\t" + "xor 15, 15, 10\n\t" + "rldic 16, 15, 2, 58\n\t" + "srdi 15, 15, 4\n\t" + "lwzx 9, 16, 7\n\t" + "rldimi 15, 14, 60, 0\n\t" + "srdi 14, 14, 4\n\t" + "xor 19, 15, 12\n\t" + "xor 14, 14, 11\n\t" + "sldi 9, 9, 32\n\t" + "xor 18, 14, 9\n\t" + "addi %[data], %[data], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "std 18, 0(%[x])\n\t" + "std 19, 8(%[x])\n\t" + "bne L_GCM_gmult_len_start_block_%=\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [x] "+r" (x), [m] "+r" (m), [data] "+r" (data), [len] "+r" (len), + [L_GCM_gmult_len_r] "+r" (L_GCM_gmult_len_r_c) + : + : "memory", "cc", "0", "8", "9", "10", "11", "12", "14", "15", "16", + "17", "18", "19", "20", "21", "22", "23", "24", "25" +#else + : + : [x] "r" (x), [m] "r" (m), [data] "r" (data), [len] "r" (len), + [L_GCM_gmult_len_r] "r" (L_GCM_gmult_len_r_c) + : "memory", "cc", "0", "7", "8", "9", "10", "11", "12", "14", "15", + "16", "17", "18", "19", "20", "21", "22", "23", "24", "25" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* GCM_TABLE_4BIT */ +#ifdef GCM_TABLE +static const byte L_GCM_gmult_len_r[] = { + 0x00, 0x00, 0xc2, 0x01, 0x84, 0x03, 0x46, 0x02, + 0x08, 0x07, 0xca, 0x06, 0x8c, 0x04, 0x4e, 0x05, + 0x10, 0x0e, 0xd2, 0x0f, 0x94, 0x0d, 0x56, 0x0c, + 0x18, 0x09, 0xda, 0x08, 0x9c, 0x0a, 0x5e, 0x0b, + 0x20, 0x1c, 0xe2, 0x1d, 0xa4, 0x1f, 0x66, 0x1e, + 0x28, 0x1b, 0xea, 0x1a, 0xac, 0x18, 0x6e, 0x19, + 0x30, 0x12, 0xf2, 0x13, 0xb4, 0x11, 0x76, 0x10, + 0x38, 0x15, 0xfa, 0x14, 0xbc, 0x16, 0x7e, 0x17, + 0x40, 0x38, 0x82, 0x39, 0xc4, 0x3b, 0x06, 0x3a, + 0x48, 0x3f, 0x8a, 0x3e, 0xcc, 0x3c, 0x0e, 0x3d, + 0x50, 0x36, 0x92, 0x37, 0xd4, 0x35, 0x16, 0x34, + 0x58, 0x31, 0x9a, 0x30, 0xdc, 0x32, 0x1e, 0x33, + 0x60, 0x24, 0xa2, 0x25, 0xe4, 0x27, 0x26, 0x26, + 0x68, 0x23, 0xaa, 0x22, 0xec, 0x20, 0x2e, 0x21, + 0x70, 0x2a, 0xb2, 0x2b, 0xf4, 0x29, 0x36, 0x28, + 0x78, 0x2d, 0xba, 0x2c, 0xfc, 0x2e, 0x3e, 0x2f, + 0x80, 0x70, 0x42, 0x71, 0x04, 0x73, 0xc6, 0x72, + 0x88, 0x77, 0x4a, 0x76, 0x0c, 0x74, 0xce, 0x75, + 0x90, 0x7e, 0x52, 0x7f, 0x14, 0x7d, 0xd6, 0x7c, + 0x98, 0x79, 0x5a, 0x78, 0x1c, 0x7a, 0xde, 0x7b, + 0xa0, 0x6c, 0x62, 0x6d, 0x24, 0x6f, 0xe6, 0x6e, + 0xa8, 0x6b, 0x6a, 0x6a, 0x2c, 0x68, 0xee, 0x69, + 0xb0, 0x62, 0x72, 0x63, 0x34, 0x61, 0xf6, 0x60, + 0xb8, 0x65, 0x7a, 0x64, 0x3c, 0x66, 0xfe, 0x67, + 0xc0, 0x48, 0x02, 0x49, 0x44, 0x4b, 0x86, 0x4a, + 0xc8, 0x4f, 0x0a, 0x4e, 0x4c, 0x4c, 0x8e, 0x4d, + 0xd0, 0x46, 0x12, 0x47, 0x54, 0x45, 0x96, 0x44, + 0xd8, 0x41, 0x1a, 0x40, 0x5c, 0x42, 0x9e, 0x43, + 0xe0, 0x54, 0x22, 0x55, 0x64, 0x57, 0xa6, 0x56, + 0xe8, 0x53, 0x2a, 0x52, 0x6c, 0x50, 0xae, 0x51, + 0xf0, 0x5a, 0x32, 0x5b, 0x74, 0x59, 0xb6, 0x58, + 0xf8, 0x5d, 0x3a, 0x5c, 0x7c, 0x5e, 0xbe, 0x5f, + 0x00, 0xe1, 0xc2, 0xe0, 0x84, 0xe2, 0x46, 0xe3, + 0x08, 0xe6, 0xca, 0xe7, 0x8c, 0xe5, 0x4e, 0xe4, + 0x10, 0xef, 0xd2, 0xee, 0x94, 0xec, 0x56, 0xed, + 0x18, 0xe8, 0xda, 0xe9, 0x9c, 0xeb, 0x5e, 0xea, + 0x20, 0xfd, 0xe2, 0xfc, 0xa4, 0xfe, 0x66, 0xff, + 0x28, 0xfa, 0xea, 0xfb, 0xac, 0xf9, 0x6e, 0xf8, + 0x30, 0xf3, 0xf2, 0xf2, 0xb4, 0xf0, 0x76, 0xf1, + 0x38, 0xf4, 0xfa, 0xf5, 0xbc, 0xf7, 0x7e, 0xf6, + 0x40, 0xd9, 0x82, 0xd8, 0xc4, 0xda, 0x06, 0xdb, + 0x48, 0xde, 0x8a, 0xdf, 0xcc, 0xdd, 0x0e, 0xdc, + 0x50, 0xd7, 0x92, 0xd6, 0xd4, 0xd4, 0x16, 0xd5, + 0x58, 0xd0, 0x9a, 0xd1, 0xdc, 0xd3, 0x1e, 0xd2, + 0x60, 0xc5, 0xa2, 0xc4, 0xe4, 0xc6, 0x26, 0xc7, + 0x68, 0xc2, 0xaa, 0xc3, 0xec, 0xc1, 0x2e, 0xc0, + 0x70, 0xcb, 0xb2, 0xca, 0xf4, 0xc8, 0x36, 0xc9, + 0x78, 0xcc, 0xba, 0xcd, 0xfc, 0xcf, 0x3e, 0xce, + 0x80, 0x91, 0x42, 0x90, 0x04, 0x92, 0xc6, 0x93, + 0x88, 0x96, 0x4a, 0x97, 0x0c, 0x95, 0xce, 0x94, + 0x90, 0x9f, 0x52, 0x9e, 0x14, 0x9c, 0xd6, 0x9d, + 0x98, 0x98, 0x5a, 0x99, 0x1c, 0x9b, 0xde, 0x9a, + 0xa0, 0x8d, 0x62, 0x8c, 0x24, 0x8e, 0xe6, 0x8f, + 0xa8, 0x8a, 0x6a, 0x8b, 0x2c, 0x89, 0xee, 0x88, + 0xb0, 0x83, 0x72, 0x82, 0x34, 0x80, 0xf6, 0x81, + 0xb8, 0x84, 0x7a, 0x85, 0x3c, 0x87, 0xfe, 0x86, + 0xc0, 0xa9, 0x02, 0xa8, 0x44, 0xaa, 0x86, 0xab, + 0xc8, 0xae, 0x0a, 0xaf, 0x4c, 0xad, 0x8e, 0xac, + 0xd0, 0xa7, 0x12, 0xa6, 0x54, 0xa4, 0x96, 0xa5, + 0xd8, 0xa0, 0x1a, 0xa1, 0x5c, 0xa3, 0x9e, 0xa2, + 0xe0, 0xb5, 0x22, 0xb4, 0x64, 0xb6, 0xa6, 0xb7, + 0xe8, 0xb2, 0x2a, 0xb3, 0x6c, 0xb1, 0xae, 0xb0, + 0xf0, 0xbb, 0x32, 0xba, 0x74, 0xb8, 0xb6, 0xb9, + 0xf8, 0xbc, 0x3a, 0xbd, 0x7c, 0xbf, 0xbe, 0xbe, +}; + +void GCM_gmult_len(unsigned char* x, const unsigned char** m, + const unsigned char* data, unsigned long len); +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG +void GCM_gmult_len(unsigned char* x_p, const unsigned char** m_p, + const unsigned char* data_p, unsigned long len_p) +#else +void GCM_gmult_len(unsigned char* x, const unsigned char** m, + const unsigned char* data, unsigned long len) +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ +{ +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + register unsigned char* x asm ("3") = (unsigned char*)x_p; + register const unsigned char** m asm ("4") = (const unsigned char**)m_p; + register const unsigned char* data asm ("5") = + (const unsigned char*)data_p; + register unsigned long len asm ("6") = (unsigned long)len_p; + register byte* L_GCM_gmult_len_r_c asm ("7") = (byte*)&L_GCM_gmult_len_r; +#else + register byte* L_GCM_gmult_len_r_c = (byte*)&L_GCM_gmult_len_r; +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + + __asm__ __volatile__ ( +#ifdef WOLFSSL_NO_VAR_ASSIGN_REG + "mr 7, %[L_GCM_gmult_len_r]\n\t" +#endif /* WOLFSSL_NO_VAR_ASSIGN_REG */ + "addi 0, %[m], 8\n\t" + "li 17, 8\n\t" + "\n" + "L_GCM_gmult_len_start_block_%=: \n\t" + "ldbrx 8, 0, %[x]\n\t" + "ldbrx 9, 17, %[x]\n\t" + "ldbrx 10, 0, %[data]\n\t" + "ldbrx 11, 17, %[data]\n\t" + "xor 8, 8, 10\n\t" + "xor 9, 9, 11\n\t" + "rldicr 19, 9, 32, 63\n\t" + "rldicr 18, 8, 32, 63\n\t" + "rlwinm 16, 19, 12, 20, 27\n\t" + /* Byte 15 */ + "ldx 12, 16, %[m]\n\t" + "ldx 14, 16, 0\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 19, 20, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 14 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 19, 28, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 13 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 19, 4, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 12 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 9, 12, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 11 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 9, 20, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 10 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 9, 28, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 9 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 9, 4, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 8 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 18, 12, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 7 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 18, 20, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 6 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 18, 28, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 5 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 18, 4, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 4 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 8, 12, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 3 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 8, 20, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 2 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 8, 28, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 1 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "xor 12, 12, 10\n\t" + "xor 14, 14, 11\n\t" + "rldicl 11, 12, 8, 56\n\t" + "rldicl 15, 14, 9, 55\n\t" + "sldi 14, 14, 8\n\t" + "andi. 15, 15, 510\n\t" + "sldi 12, 12, 8\n\t" + "lhzx 10, 15, 7\n\t" + "xor 14, 14, 11\n\t" + "rlwinm 16, 8, 4, 20, 27\n\t" + "xor 12, 12, 10\n\t" + /* Byte 0 */ + "ldx 10, 16, %[m]\n\t" + "ldx 11, 16, 0\n\t" + "addi %[data], %[data], 16\n\t" + "addic. %[len], %[len], -16\n\t" + "xor 8, 12, 10\n\t" + "xor 9, 14, 11\n\t" + "stdbrx 8, 0, %[x]\n\t" + "stdbrx 9, 17, %[x]\n\t" + "bne L_GCM_gmult_len_start_block_%=\n\t" +#ifndef WOLFSSL_NO_VAR_ASSIGN_REG + : [x] "+r" (x), [m] "+r" (m), [data] "+r" (data), [len] "+r" (len), + [L_GCM_gmult_len_r] "+r" (L_GCM_gmult_len_r_c) + : + : "memory", "cc", "0", "8", "9", "10", "11", "12", "14", "15", "16", + "17", "18", "19" +#else + : + : [x] "r" (x), [m] "r" (m), [data] "r" (data), [len] "r" (len), + [L_GCM_gmult_len_r] "r" (L_GCM_gmult_len_r_c) + : "memory", "cc", "0", "7", "8", "9", "10", "11", "12", "14", "15", + "16", "17", "18", "19" +#endif /* !WOLFSSL_NO_VAR_ASSIGN_REG */ + ); +} + +#endif /* GCM_TABLE */ +#endif /* HAVE_AESGCM */ +#endif /* !defined(NO_AES) && defined(WOLFSSL_PPC64_ASM) */ +#endif /* WOLFSSL_PPC64_ASM */ + +#endif /* WOLFSSL_PPC64_ASM_INLINE */ diff --git a/wolfcrypt/src/port/riscv/riscv-64-aes.c b/wolfcrypt/src/port/riscv/riscv-64-aes.c index 37918217e9..64d77a3630 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-aes.c +++ b/wolfcrypt/src/port/riscv/riscv-64-aes.c @@ -1871,8 +1871,7 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 keyLen, const byte* iv, static void wc_AesEncrypt(Aes* aes, const byte* in, byte* out) { __asm__ __volatile__ ( - "ld t2, 0(%[in])\n\t" - "ld t3, 8(%[in])\n\t" + UNALIGNED_LD2(t2, t3, 0, %[in], t0) "ld a3, 0(%[key])\n\t" "ld a4, 8(%[key])\n\t" "ld a5, 16(%[key])\n\t" @@ -1897,8 +1896,7 @@ static void wc_AesEncrypt(Aes* aes, const byte* in, byte* out) AESENC_2_ROUNDS(208, 216, 224, 232) "L_aes_encrypt_done:\n\t" AESENC_LAST_ROUND() - "sd t2, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t2, t3, 0, %[out], t0) : : [in] "r" (in), [out] "r" (out), [key] "r" (aes->key), [rounds] "r" (aes->rounds) @@ -1918,8 +1916,7 @@ static void wc_AesEncrypt(Aes* aes, const byte* in, byte* out) static void wc_AesDecrypt(Aes* aes, const byte* in, byte* out) { __asm__ __volatile__ ( - "ld t2, 0(%[in])\n\t" - "ld t3, 8(%[in])\n\t" + UNALIGNED_LD2(t2, t3, 0, %[in], t0) "ld a3, 0(%[key])\n\t" "ld a4, 8(%[key])\n\t" "ld a5, 16(%[key])\n\t" @@ -1944,8 +1941,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* in, byte* out) AESDEC_2_ROUNDS(208, 216, 224, 232) "L_aes_decrypt_done:\n\t" AESDEC_LAST_ROUND() - "sd t2, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t2, t3, 0, %[out], t0) : : [in] "r" (in), [out] "r" (out), [key] "r" (aes->key), [rounds] "r" (aes->rounds) @@ -3209,8 +3205,7 @@ static void wc_AesEncrypt(Aes* aes, const byte* in, byte* out) LOAD_WORD_REV(t2, 8, %[in]) LOAD_WORD_REV(t3, 12, %[in]) #else - "ld t1, 0(%[in])\n\t" - "ld t3, 8(%[in])\n\t" + UNALIGNED_LD2(t1, t3, 0, %[in], t0) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) "srli t0, t1, 32\n\t" @@ -3376,16 +3371,14 @@ static void wc_AesEncrypt(Aes* aes, const byte* in, byte* out) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) /* Write encrypted block to output. */ - "sd t1, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t1, t3, 0, %[out], t0) #else PACK(REG_T1, REG_A5, REG_A4) PACK(REG_T3, REG_A7, REG_A6) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) /* Write encrypted block to output. */ - "sd t1, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t1, t3, 0, %[out], t0) #endif : @@ -3641,8 +3634,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* in, byte* out) LOAD_WORD_REV(t2, 8, %[in]) LOAD_WORD_REV(t3, 12, %[in]) #else - "ld t1, 0(%[in])\n\t" - "ld t3, 8(%[in])\n\t" + UNALIGNED_LD2(t1, t3, 0, %[in], t0) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) "srli t0, t1, 32\n\t" @@ -3793,16 +3785,14 @@ static void wc_AesDecrypt(Aes* aes, const byte* in, byte* out) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) /* Write encrypted block to output. */ - "sd t1, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t1, t3, 0, %[out], t0) #else PACK(REG_T1, REG_A5, REG_A4) PACK(REG_T3, REG_A7, REG_A6) REV8(REG_T1, REG_T1) REV8(REG_T3, REG_T3) /* Write encrypted block to output. */ - "sd t1, 0(%[out])\n\t" - "sd t3, 8(%[out])\n\t" + UNALIGNED_SD2(t1, t3, 0, %[out], t0) #endif : @@ -4113,7 +4103,7 @@ static WC_INLINE void IncrementAesCounter(byte* inOutCtr) */ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; word32 processed; int ret = 0; @@ -4563,8 +4553,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { if (gcm != NULL) { - byte x[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte x[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; byte* h = gcm->H; __asm__ __volatile__ ( @@ -4896,8 +4886,8 @@ static void GMULT(byte* x, byte* y) void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { - byte x[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte x[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; byte* h; @@ -5163,8 +5153,7 @@ static void ghash_blocks(byte* x, byte* y, const byte* in, word32 blocks) "L_ghash_loop:\n\t" /* Load input block. */ - "ld t5, 0(%[in])\n\t" - "ld a5, 8(%[in])\n\t" + UNALIGNED_LD2(t5, a5, 0, %[in], t4) /* Reverse bits to match x. */ #ifdef WOLFSSL_RISCV_BIT_MANIPULATION BREV8(REG_T5, REG_T5) @@ -5307,8 +5296,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { if (gcm != NULL) { - byte x[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte x[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; byte* h = gcm->H; @@ -5388,8 +5377,8 @@ static void Aes128GcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* nonce, word32 nonceSz, byte* tag, word32 tagSz, const byte* aad, word32 aadSz) { - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -5886,8 +5875,8 @@ static void Aes192GcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* nonce, word32 nonceSz, byte* tag, word32 tagSz, const byte* aad, word32 aadSz) { - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -6398,8 +6387,8 @@ static void Aes256GcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* nonce, word32 nonceSz, byte* tag, word32 tagSz, const byte* aad, word32 aadSz) { - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -7003,8 +6992,8 @@ static int Aes128GcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* aad, word32 aadSz) { int ret = 0; - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -7512,8 +7501,8 @@ static int Aes192GcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* aad, word32 aadSz) { int ret = 0; - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -8035,8 +8024,8 @@ static int Aes256GcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* aad, word32 aadSz) { int ret = 0; - byte counter[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Noticed different optimization levels treated head of array different. * Some cases was stack pointer plus offset others was a register containing * address. To make uniform for passing in to inline assembly code am using @@ -8733,8 +8722,8 @@ void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c, word32 cSz, byte* s, word32 sSz) { if (gcm != NULL) { - byte x[WC_AES_BLOCK_SIZE]; - byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte x[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; word32 blocks, partial; XMEMSET(x, 0, WC_AES_BLOCK_SIZE); @@ -8834,9 +8823,9 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, word32 partial = sz % WC_AES_BLOCK_SIZE; const byte* p = in; byte* c = out; - ALIGN16 byte counter[WC_AES_BLOCK_SIZE]; - ALIGN16 byte initialCounter[WC_AES_BLOCK_SIZE]; - ALIGN16 byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte initialCounter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; /* Validate parameters. */ if ((aes == NULL) || (nonce == NULL) || (nonceSz == 0) || (tag == NULL) || @@ -8934,10 +8923,10 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, word32 partial = sz % WC_AES_BLOCK_SIZE; const byte* c = in; byte* p = out; - ALIGN16 byte counter[WC_AES_BLOCK_SIZE]; - ALIGN16 byte scratch[WC_AES_BLOCK_SIZE]; - ALIGN16 byte Tprime[WC_AES_BLOCK_SIZE]; - ALIGN16 byte EKY0[WC_AES_BLOCK_SIZE]; + ALIGN8 byte counter[WC_AES_BLOCK_SIZE]; + ALIGN8 byte scratch[WC_AES_BLOCK_SIZE]; + ALIGN8 byte Tprime[WC_AES_BLOCK_SIZE]; + ALIGN8 byte EKY0[WC_AES_BLOCK_SIZE]; sword32 res; /* Validate parameters. */ diff --git a/wolfcrypt/src/port/riscv/riscv-64-chacha.c b/wolfcrypt/src/port/riscv/riscv-64-chacha.c index c150e4bb7f..ba0a8b21d3 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-chacha.c +++ b/wolfcrypt/src/port/riscv/riscv-64-chacha.c @@ -1825,9 +1825,9 @@ static WC_INLINE void wc_chacha_encrypt_64(const word32* input, const byte* m, VSETIVLI(REG_X0, 2, 1, 1, 0b011, 0b000) VMV_X_S(REG_T0, REG_V0) VSETIVLI(REG_X0, 4, 1, 1, 0b010, 0b000) - "ld t1, (%[m])\n\t" + UNALIGNED_LD(t1, 0, %[m], t2) "xor t1, t1, t0\n\t" - "sd t1, (%[c])\n\t" + UNALIGNED_SD(t1, 0, %[c], t2) "addi %[bytes], %[bytes], -8\n\t" "addi %[c], %[c], 8\n\t" "addi %[m], %[m], 8\n\t" @@ -2155,10 +2155,7 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "bltz %[bytes], L_chacha20_riscv_over\n\t" #if !defined(WOLFSSL_RISCV_BIT_MANIPULATION) - "ld t0, 0(%[m])\n\t" - "ld t1, 8(%[m])\n\t" - "ld t2, 16(%[m])\n\t" - "ld s1, 24(%[m])\n\t" + UNALIGNED_LD4(t0, t1, t2, s1, 0, %[m], a3) "xor a4, a4, t0\n\t" "xor a6, a6, t1\n\t" "xor t3, t3, t2\n\t" @@ -2171,10 +2168,7 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "xor a7, a7, t1\n\t" "xor t4, t4, t2\n\t" "xor t6, t6, s1\n\t" - "ld t0, 32(%[m])\n\t" - "ld t1, 40(%[m])\n\t" - "ld t2, 48(%[m])\n\t" - "ld s1, 56(%[m])\n\t" + UNALIGNED_LD4(t0, t1, t2, s1, 32, %[m], a3) "xor s2, s2, t0\n\t" "xor s4, s4, t1\n\t" "xor s6, s6, t2\n\t" @@ -2187,22 +2181,8 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "xor s5, s5, t1\n\t" "xor s7, s7, t2\n\t" "xor s9, s9, s1\n\t" - "sw a4, 0(%[c])\n\t" - "sw a5, 4(%[c])\n\t" - "sw a6, 8(%[c])\n\t" - "sw a7, 12(%[c])\n\t" - "sw t3, 16(%[c])\n\t" - "sw t4, 20(%[c])\n\t" - "sw t5, 24(%[c])\n\t" - "sw t6, 28(%[c])\n\t" - "sw s2, 32(%[c])\n\t" - "sw s3, 36(%[c])\n\t" - "sw s4, 40(%[c])\n\t" - "sw s5, 44(%[c])\n\t" - "sw s6, 48(%[c])\n\t" - "sw s7, 52(%[c])\n\t" - "sw s8, 56(%[c])\n\t" - "sw s9, 60(%[c])\n\t" + UNALIGNED_SW8(a4, a5, a6, a7, t3, t4, t5, t6, 0, %[c], t0) + UNALIGNED_SW8(s2, s3, s4, s5, s6, s7, s8, s9, 32, %[c], t0) #else PACK(REG_A4, REG_A4, REG_A5) PACK(REG_A6, REG_A6, REG_A7) @@ -2212,14 +2192,7 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, PACK(REG_S4, REG_S4, REG_S5) PACK(REG_S6, REG_S6, REG_S7) PACK(REG_S8, REG_S8, REG_S9) - "ld a5, 0(%[m])\n\t" - "ld a7, 8(%[m])\n\t" - "ld t4, 16(%[m])\n\t" - "ld t6, 24(%[m])\n\t" - "ld s3, 32(%[m])\n\t" - "ld s5, 40(%[m])\n\t" - "ld s7, 48(%[m])\n\t" - "ld s9, 56(%[m])\n\t" + UNALIGNED_LD8(a5, a7, t4, t6, s3, s5, s7, s9, 0, %[m], t0) "xor a4, a4, a5\n\t" "xor a6, a6, a7\n\t" "xor t3, t3, t4\n\t" @@ -2228,14 +2201,7 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "xor s4, s4, s5\n\t" "xor s6, s6, s7\n\t" "xor s8, s8, s9\n\t" - "sd a4, 0(%[c])\n\t" - "sd a6, 8(%[c])\n\t" - "sd t3, 16(%[c])\n\t" - "sd t5, 24(%[c])\n\t" - "sd s2, 32(%[c])\n\t" - "sd s4, 40(%[c])\n\t" - "sd s6, 48(%[c])\n\t" - "sd s8, 56(%[c])\n\t" + UNALIGNED_SD8(a4, a6, t3, t5, s2, s4, s6, s8, 0, %[c], t0) #endif "addi %[m], %[m], 64\n\t" @@ -2268,10 +2234,10 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "bltz t0, L_chacha20_riscv_32bit\n\t" "addi a3, a3, -1\n\t" "L_chacha20_riscv_64bit_loop:\n\t" - "ld t0, (%[m])\n\t" + UNALIGNED_LD(t0, 0, %[m], t2) "ld t1, (%[over])\n\t" "xor t0, t0, t1\n\t" - "sd t0, (%[c])\n\t" + UNALIGNED_SD(t0, 0, %[c], t2) "addi %[m], %[m], 8\n\t" "addi %[c], %[c], 8\n\t" "addi %[over], %[over], 8\n\t" @@ -2282,10 +2248,10 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "L_chacha20_riscv_32bit:\n\t" "addi t0, a3, -4\n\t" "bltz t0, L_chacha20_riscv_16bit\n\t" - "lw t0, (%[m])\n\t" + UNALIGNED_LW(t0, 0, %[m], t2) "lw t1, (%[over])\n\t" "xor t0, t0, t1\n\t" - "sw t0, (%[c])\n\t" + UNALIGNED_SW(t0, 0, %[c], t2) "addi %[m], %[m], 4\n\t" "addi %[c], %[c], 4\n\t" "addi %[over], %[over], 4\n\t" @@ -2293,10 +2259,10 @@ static WC_INLINE void wc_chacha_encrypt(const word32* input, const byte* m, "L_chacha20_riscv_16bit:\n\t" "addi t0, a3, -2\n\t" "bltz t0, L_chacha20_riscv_8bit\n\t" - "lh t0, (%[m])\n\t" + UNALIGNED_LH(t0, 0, %[m], t2) "lh t1, (%[over])\n\t" "xor t0, t0, t1\n\t" - "sh t0, (%[c])\n\t" + UNALIGNED_SH(t0, 0, %[c], t2) "addi %[m], %[m], 2\n\t" "addi %[c], %[c], 2\n\t" "addi %[over], %[over], 2\n\t" diff --git a/wolfcrypt/src/port/riscv/riscv-64-poly1305.c b/wolfcrypt/src/port/riscv/riscv-64-poly1305.c index de846ffde8..5733b75bc7 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-poly1305.c +++ b/wolfcrypt/src/port/riscv/riscv-64-poly1305.c @@ -145,8 +145,7 @@ static WC_INLINE void poly1305_blocks_riscv64_16(Poly1305* ctx, "L_poly1305_riscv64_16_64_loop_%=:\n\t" /* Load m */ - "ld t0, (%[m])\n\t" - "ld t1, 8(%[m])\n\t" + UNALIGNED_LD2(t0, t1, 0, %[m], t5) /* Split m into 26, 52, 52 */ SPLIT_130(t2, t3, t4, t0, t1, %[notLast], t5) @@ -285,8 +284,7 @@ void poly1305_blocks_riscv64(Poly1305* ctx, const unsigned char *m, "L_poly1305_riscv64_vec_loop_%=:\n\t" /* m0 + nfin */ - "ld t0, 0(%[m])\n\t" - "ld t1, 8(%[m])\n\t" + UNALIGNED_LD2(t0, t1, 0, %[m], t5) "li t6, 1\n\t" /* Split m into 24, 52, 52 */ SPLIT_130(t2, t3, t4, t0, t1, t6, t5) @@ -294,8 +292,7 @@ void poly1305_blocks_riscv64(Poly1305* ctx, const unsigned char *m, VMV_S_X(REG_V12, REG_T3) VMV_S_X(REG_V13, REG_T4) /* m1+ nfin */ - "ld t0, 16(%[m])\n\t" - "ld t1, 24(%[m])\n\t" + UNALIGNED_LD2(t0, t1, 16, %[m], t5) /* Split m into 24, 52, 52 */ SPLIT_130(t2, t3, t4, t0, t1, t6, t5) VMV_S_X(REG_V14, REG_T2) @@ -464,10 +461,7 @@ int wc_Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) __asm__ __volatile__ ( /* Load key material */ - "ld t0, 0(%[key])\n\t" - "ld t1, 8(%[key])\n\t" - "ld t2, 16(%[key])\n\t" - "ld t3, 24(%[key])\n\t" + UNALIGNED_LD4(t0, t1, t2, t3, 0, %[key], t4) /* Load clamp */ "ld t4, 0(%[clamp])\n\t" "ld t5, 8(%[clamp])\n\t" @@ -636,8 +630,7 @@ int wc_Poly1305Final(Poly1305* ctx, byte* mac) "sltu t3, t1, t3\n\t" "add t2, t2, t3\n\t" "andi t2, t2, 3\n\t" - "sd t0, 0(%[mac])\n\t" - "sd t1, 8(%[mac])\n\t" + UNALIGNED_SD2(t0, t1, 0, %[mac], t2) /* Zero out h. */ "sd x0, %[ctx_h_0]\n\t" "sd x0, %[ctx_h_1]\n\t" diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha256.c b/wolfcrypt/src/port/riscv/riscv-64-sha256.c index 44af0b80c3..f672db2739 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha256.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha256.c @@ -484,14 +484,7 @@ static WC_OMIT_FRAME_POINTER WC_INLINE void Sha256Transform(wc_Sha256* sha256, LOAD_DWORD_REV(s6, 48, %[data], a4, a5, a6, a7) LOAD_DWORD_REV(s7, 56, %[data], a4, a5, a6, a7) #else - "lwu a4, 0(%[data])\n\t" - "lwu s0, 4(%[data])\n\t" - "lwu a5, 8(%[data])\n\t" - "lwu s1, 12(%[data])\n\t" - "lwu a6, 16(%[data])\n\t" - "lwu s2, 20(%[data])\n\t" - "lwu a7, 24(%[data])\n\t" - "lwu s3, 28(%[data])\n\t" + UNALIGNED_LWU8(a4, s0, a5, s1, a6, s2, a7, s3, 0, %[data], t4) PACK_BB(s0, s0, a4, REG_S0, REG_S0, REG_A4) PACK_BB(s1, s1, a5, REG_S1, REG_S1, REG_A5) PACK_BB(s2, s2, a6, REG_S2, REG_S2, REG_A6) @@ -500,14 +493,7 @@ static WC_OMIT_FRAME_POINTER WC_INLINE void Sha256Transform(wc_Sha256* sha256, REV8(REG_S1, REG_S1) REV8(REG_S2, REG_S2) REV8(REG_S3, REG_S3) - "lwu a4, 32(%[data])\n\t" - "lwu s4, 36(%[data])\n\t" - "lwu a5, 40(%[data])\n\t" - "lwu s5, 44(%[data])\n\t" - "lwu a6, 48(%[data])\n\t" - "lwu s6, 52(%[data])\n\t" - "lwu a7, 56(%[data])\n\t" - "lwu s7, 60(%[data])\n\t" + UNALIGNED_LWU8(a4, s4, a5, s5, a6, s6, a7, s7, 32, %[data], t4) PACK_BB(s4, s4, a4, REG_S4, REG_S4, REG_A4) PACK_BB(s5, s5, a5, REG_S5, REG_S5, REG_A5) PACK_BB(s6, s6, a6, REG_S6, REG_S6, REG_A6) @@ -840,31 +826,18 @@ static WC_INLINE void Sha256Final(wc_Sha256* sha256, byte* hash) "srli t2, t3, 32\n\t" "srli a4, a5, 32\n\t" "srli a6, a7, 32\n\t" - "sw t0, 0(%[hash])\n\t" - "sw t1, 4(%[hash])\n\t" - "sw t2, 8(%[hash])\n\t" - "sw t3, 12(%[hash])\n\t" - "sw a4, 16(%[hash])\n\t" - "sw a5, 20(%[hash])\n\t" - "sw a6, 24(%[hash])\n\t" - "sw a7, 28(%[hash])\n\t" + UNALIGNED_SW8(t0, t1, t2, t3, a4, a5, a6, a7, 0, %[hash], t4) #else LOAD_WORD_REV(t0, 0, %[digest], t2, t3, t4) LOAD_WORD_REV(t1, 4, %[digest], t2, t3, t4) LOAD_WORD_REV(a4, 8, %[digest], t2, t3, t4) LOAD_WORD_REV(a5, 12, %[digest], t2, t3, t4) - "sw t0, 0(%[hash])\n\t" - "sw t1, 4(%[hash])\n\t" - "sw a4, 8(%[hash])\n\t" - "sw a5, 12(%[hash])\n\t" + UNALIGNED_SW4(t0, t1, a4, a5, 0, %[hash], t2) LOAD_WORD_REV(t0, 16, %[digest], t2, t3, t4) LOAD_WORD_REV(t1, 20, %[digest], t2, t3, t4) LOAD_WORD_REV(a4, 24, %[digest], t2, t3, t4) LOAD_WORD_REV(a5, 28, %[digest], t2, t3, t4) - "sw t0, 16(%[hash])\n\t" - "sw t1, 20(%[hash])\n\t" - "sw a4, 24(%[hash])\n\t" - "sw a5, 28(%[hash])\n\t" + UNALIGNED_SW4(t0, t1, a4, a5, 16, %[hash], t2) #endif : : [digest] "r" (sha256->digest), [hash] "r" (hash) diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha3.c b/wolfcrypt/src/port/riscv/riscv-64-sha3.c index 9d2a959afe..3ecb68d065 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha3.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha3.c @@ -139,7 +139,7 @@ static const word64 hash_keccak_r[24] = #endif -void BlockSha3(word64* s) +WC_OMIT_FRAME_POINTER void BlockSha3(word64* s) { const word64* r = hash_keccak_r; diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha512.c b/wolfcrypt/src/port/riscv/riscv-64-sha512.c index 473b115dc0..8a2fd23e26 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha512.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha512.c @@ -554,14 +554,7 @@ static WC_INLINE void Sha512Transform(wc_Sha512* sha512, const byte* data, LOAD_DWORD_REV(s6, 48, %[data], a4, a5, a6, a7) LOAD_DWORD_REV(s7, 56, %[data], a4, a5, a6, a7) #else - "ld t4, 0(%[data])\n\t" - "ld s1, 8(%[data])\n\t" - "ld s2, 16(%[data])\n\t" - "ld s3, 24(%[data])\n\t" - "ld s4, 32(%[data])\n\t" - "ld s5, 40(%[data])\n\t" - "ld s6, 48(%[data])\n\t" - "ld s7, 56(%[data])\n\t" + UNALIGNED_LD8(t4, s1, s2, s3, s4, s5, s6, s7, 0, %[data], t5) REV8(REG_T4, REG_T4) REV8(REG_S1, REG_S1) REV8(REG_S2, REG_S2) @@ -946,14 +939,7 @@ static WC_INLINE void Sha512Final(wc_Sha512* sha512, byte* hash, int hashLen) REV8(REG_S9, REG_S9) REV8(REG_S10, REG_S10) REV8(REG_S11, REG_S11) - "sd t0, 0(%[hash])\n\t" - "sd t1, 8(%[hash])\n\t" - "sd t2, 16(%[hash])\n\t" - "sd t3, 24(%[hash])\n\t" - "sd s8, 32(%[hash])\n\t" - "sd s9, 40(%[hash])\n\t" - "sd s10, 48(%[hash])\n\t" - "sd s11, 56(%[hash])\n\t" + UNALIGNED_SD8(t0, t1, t2, t3, s8, s9, s10, s11, 0, %[hash], t4) #else LOAD_DWORD_REV(t0, 0, %[digest], a4, a5, a6, a7) LOAD_DWORD_REV(t1, 8, %[digest], a4, a5, a6, a7) @@ -963,14 +949,7 @@ static WC_INLINE void Sha512Final(wc_Sha512* sha512, byte* hash, int hashLen) LOAD_DWORD_REV(s9, 40, %[digest], a4, a5, a6, a7) LOAD_DWORD_REV(s10, 48, %[digest], a4, a5, a6, a7) LOAD_DWORD_REV(s11, 56, %[digest], a4, a5, a6, a7) - "sd t0, 0(%[hash])\n\t" - "sd t1, 8(%[hash])\n\t" - "sd t2, 16(%[hash])\n\t" - "sd t3, 24(%[hash])\n\t" - "sd s8, 32(%[hash])\n\t" - "sd s9, 40(%[hash])\n\t" - "sd s10, 48(%[hash])\n\t" - "sd s11, 56(%[hash])\n\t" + UNALIGNED_SD8(t0, t1, t2, t3, s8, s9, s10, s11, 0, %[hash], t4) #endif : : [digest] "r" (sha512->digest), [hash] "r" (hashRes) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 4631734d7c..7b85d481d7 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1720,11 +1720,11 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz, word32 seedSz = SEED_SZ; #else word32 seedSz = SEED_SZ + SEED_BLOCK_SZ; +#endif WC_DECLARE_VAR(seed, byte, MAX_SEED_SZ, rng->heap); #ifdef WOLFSSL_SMALL_STACK_CACHE int drbg_scratch_instantiated = 0; #endif -#endif #endif (void)nonce; diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 5fbbd6bdf8..e265d69cf4 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -60,14 +60,6 @@ RSA keys can be used to encrypt, decrypt, sign and verify data. #include #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - /* * RSA Build Options: * @@ -868,8 +860,6 @@ int wc_CheckRsaKey(RsaKey* key) } } - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (ret == 0) { if (INIT_MP_INT_SIZE(tmp, mp_bitsused(&key->n)) != MP_OKAY) ret = MP_INIT_E; @@ -982,8 +972,6 @@ int wc_CheckRsaKey(RsaKey* key) mp_forcezero(tmp); - RESTORE_VECTOR_REGISTERS(); - if ((rng != NULL) && (rng != key->rng)) { wc_FreeRng(rng); #ifdef WOLFSSL_SMALL_STACK @@ -3571,7 +3559,6 @@ static int wc_RsaFunction_ex(const byte* in, word32 inLen, byte* out, #ifdef WOLF_CRYPTO_CB_ONLY_RSA return NO_VALID_DEVID; #else /* !WOLF_CRYPTO_CB_ONLY_RSA */ - SAVE_VECTOR_REGISTERS(return _svr_ret;); #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(TEST_UNPAD_CONSTANT_TIME) && \ !defined(NO_RSA_BOUNDS_CHECK) @@ -3580,7 +3567,6 @@ static int wc_RsaFunction_ex(const byte* in, word32 inLen, byte* out, ret = RsaFunctionCheckIn(in, inLen, key, checkSmallCt); if (ret != 0) { - RESTORE_VECTOR_REGISTERS(); return ret; } } @@ -3592,7 +3578,6 @@ static int wc_RsaFunction_ex(const byte* in, word32 inLen, byte* out, ret = RsaFunctionCheckIn(in, inLen, key, checkSmallCt); if (ret != 0) { - RESTORE_VECTOR_REGISTERS(); return ret; } } @@ -3623,8 +3608,6 @@ static int wc_RsaFunction_ex(const byte* in, word32 inLen, byte* out, ret = wc_RsaFunctionSync(in, inLen, out, outLen, type, key, rng); } - RESTORE_VECTOR_REGISTERS(); - /* handle error */ if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PENDING_E) #ifdef WC_RSA_NONBLOCK @@ -4172,11 +4155,9 @@ int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, word32 outLen, RsaKey* key, WC_RNG* rng) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PUBLIC_ENCRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4188,10 +4169,8 @@ int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out, word32 labelSz) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PUBLIC_ENCRYPT, RSA_BLOCK_TYPE_2, type, hash, mgf, label, labelSz, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif /* WC_NO_RSA_OAEP */ @@ -4211,11 +4190,9 @@ int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key) #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key, RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4235,11 +4212,9 @@ int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen, byte** out, #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key, RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, type, hash, mgf, label, labelSz, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif /* WC_NO_RSA_OAEP */ @@ -4258,11 +4233,9 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key, RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4282,11 +4255,9 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, byte* out, #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key, RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, type, hash, mgf, label, labelSz, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif /* WC_NO_RSA_OAEP || WC_RSA_NO_PADDING */ @@ -4305,11 +4276,9 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key) #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key, RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -4325,10 +4294,8 @@ int wc_RsaSSL_Verify_ex(const byte* in, word32 inLen, byte* out, word32 outLen, RsaKey* key, int pad_type) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = wc_RsaSSL_Verify_ex2(in, inLen, out, outLen, key, pad_type, WC_HASH_TYPE_NONE); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4348,7 +4315,6 @@ int wc_RsaSSL_Verify_ex2(const byte* in, word32 inLen, byte* out, word32 outLen rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key, RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, pad_type, @@ -4358,7 +4324,6 @@ int wc_RsaSSL_Verify_ex2(const byte* in, word32 inLen, byte* out, word32 outLen RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, pad_type, hash, wc_hash2mgf(hash), NULL, 0, RSA_PSS_SALT_LEN_DISCOVER, rng); #endif - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -4416,11 +4381,9 @@ int wc_RsaPSS_VerifyInline_ex(byte* in, word32 inLen, byte** out, #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key, RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD, hash, mgf, NULL, 0, saltLen, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4474,11 +4437,9 @@ int wc_RsaPSS_Verify_ex(const byte* in, word32 inLen, byte* out, word32 outLen, #else rng = NULL; #endif - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key, RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD, hash, mgf, NULL, 0, saltLen, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4754,11 +4715,9 @@ int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out, word32 outLen, RsaKey* key, WC_RNG* rng) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PRIVATE_ENCRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } @@ -4805,11 +4764,9 @@ int wc_RsaPSS_Sign_ex(const byte* in, word32 inLen, byte* out, word32 outLen, WC_RNG* rng) { int ret; - SAVE_VECTOR_REGISTERS(return _svr_ret;); ret = RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PRIVATE_ENCRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD, hash, mgf, NULL, 0, saltLen, rng); - RESTORE_VECTOR_REGISTERS(); return ret; } #endif @@ -5350,12 +5307,8 @@ int wc_CheckProbablePrime_ex(const byte* pRaw, word32 pRawSz, if (ret == MP_OKAY) ret = mp_read_unsigned_bin(e, eRaw, eRawSz); - if (ret == MP_OKAY) - SAVE_VECTOR_REGISTERS(ret = _svr_ret;); - if (ret == 0) { ret = _CheckProbablePrime(p, Q, e, nlen, isPrime, rng); - RESTORE_VECTOR_REGISTERS(); } ret = (ret == MP_OKAY) ? 0 : PRIME_GEN_E; @@ -5549,8 +5502,6 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) } #endif - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - /* make p */ if (err == MP_OKAY) { #ifdef WOLFSSL_CHECK_MEM_ZERO @@ -5591,9 +5542,10 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) if (err != MP_OKAY || isPrime || i >= failCount) break; - /* linuxkm: release the kernel for a moment before iterating. */ - RESTORE_VECTOR_REGISTERS(); - SAVE_VECTOR_REGISTERS(err = _svr_ret; break;); + err = WC_CHECK_FOR_INTR_SIGNALS(); + if (err != 0) + break; + WC_RELAX_LONG_LOOP(); }; } @@ -5644,6 +5596,12 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) /* Keep the old retry behavior in non-FIPS build. */ (void)i; #endif + + err = WC_CHECK_FOR_INTR_SIGNALS(); + if (err != 0) + break; + WC_RELAX_LONG_LOOP(); + } while (err == MP_OKAY && !isPrime && i < failCount); } @@ -5769,9 +5727,6 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) } #endif - if (err != WC_NO_ERR_TRACE(WC_ACCEL_INHIBIT_E)) - RESTORE_VECTOR_REGISTERS(); - /* Last value p - 1. */ mp_forcezero(tmp1); /* Last value q - 1. */ diff --git a/wolfcrypt/src/sakke.c b/wolfcrypt/src/sakke.c index 4fc1a85b48..a7b64e32a7 100644 --- a/wolfcrypt/src/sakke.c +++ b/wolfcrypt/src/sakke.c @@ -37,14 +37,6 @@ #include #include -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV /* FIPS build has replaced ecc.h. */ #define wc_ecc_key_get_priv(key) (&((key)->k)) @@ -1328,13 +1320,11 @@ int wc_GenerateSakkeRskTable(const SakkeKey* key, const ecc_point* rsk, err = BAD_FUNC_ARG; } if (err == 0) { - SAVE_VECTOR_REGISTERS(return _svr_ret;); #ifdef WOLFSSL_SP_1024 err = sp_Pairing_gen_precomp_1024(rsk, table, len); #else err = NOT_COMPILED_IN; #endif - RESTORE_VECTOR_REGISTERS(); } return err; @@ -2441,8 +2431,6 @@ int wc_ValidateSakkeRsk(SakkeKey* key, const byte* id, word16 idSz, err = BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* Load elliptic curve parameters */ if (err == 0) { err = sakke_load_params(key); @@ -2478,8 +2466,6 @@ int wc_ValidateSakkeRsk(SakkeKey* key, const byte* id, word16 idSz, *valid = ((err == 0) && (mp_cmp(a, &key->params.g) == MP_EQ)); } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -2622,6 +2608,22 @@ static int sakke_modexp_loop(SakkeKey* key, mp_int* b, mp_int* e, mp_proj* r, mp_int* by = key->tmp.p1->z; mp_int* prime = &key->params.prime; int i; +#ifdef WC_NO_GLOBAL_OBJECT_POINTERS + static const wc_ptr_t wc_off_on_addr[2] = + { + #if defined(WC_64BIT_CPU) + W64LIT(0x0000000000000000), + W64LIT(0xffffffffffffffff) + #elif defined(WC_16BIT_CPU) + 0x0000U, + 0xffffU + #else + /* 32 bit */ + 0x00000000U, + 0xffffffffU + #endif + }; +#endif #ifdef WC_NO_CACHE_RESISTANT c[0] = r; @@ -6387,8 +6389,6 @@ int wc_MakeSakkePointI(SakkeKey* key, const byte* id, word16 idSz) err = BAD_FUNC_ARG; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - if (err == 0) { err = sakke_load_params(key); } @@ -6401,8 +6401,6 @@ int wc_MakeSakkePointI(SakkeKey* key, const byte* id, word16 idSz) key->i.idSz = idSz; } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -6532,9 +6530,7 @@ int wc_GenerateSakkePointITable(SakkeKey* key, byte* table, word32* len) #ifdef WOLFSSL_HAVE_SP_ECC if (err == 0) { - SAVE_VECTOR_REGISTERS(return _svr_ret;); err = sp_ecc_gen_table_1024(key->i.i, table, len, key->heap); - RESTORE_VECTOR_REGISTERS(); } if (err == 0) { key->i.table = table; @@ -6722,8 +6718,6 @@ int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key, enum wc_HashType hashType, err = BAD_STATE_E; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* Load parameters */ if (err == 0) { err = sakke_load_params(key); @@ -6799,8 +6793,6 @@ int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key, enum wc_HashType hashType, /* Step 6: Output SSV - already encoded in buffer */ - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -6898,7 +6890,9 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv, mp_int* ri = NULL; byte* wb = NULL; byte* test = NULL; - byte a[WC_MAX_DIGEST_SIZE] = {0}; + byte a[WC_MAX_DIGEST_SIZE]; + + XMEMSET(a, 0, sizeof(a)); if ((key == NULL) || (ssv == NULL) || (auth == NULL) || (ssvSz == 0)) { err = BAD_FUNC_ARG; @@ -6907,8 +6901,6 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv, err = BAD_STATE_E; } - SAVE_VECTOR_REGISTERS(return _svr_ret;); - /* Load parameters */ if (err == 0) { err = sakke_load_params(key); @@ -6979,8 +6971,6 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv, err = SAKKE_VERIFY_FAIL_E; } - RESTORE_VECTOR_REGISTERS(); - return err; } #endif /* WOLFCRYPT_SAKKE_CLIENT */ diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 41c7d9ce1e..dd10cc64ad 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -47,6 +47,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -141,10 +152,10 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -199,7 +210,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -234,7 +245,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -6583,17 +6594,17 @@ WC_OMIT_FRAME_POINTER static void sp_2048_sqr_32(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -12498,10 +12509,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -12510,14 +12521,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -12525,12 +12536,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -12651,10 +12662,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -12663,14 +12674,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -12678,12 +12689,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -17364,10 +17375,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -17376,14 +17387,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -17391,12 +17402,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -17500,10 +17511,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -17512,14 +17523,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -17527,12 +17538,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -17605,7 +17616,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -18087,7 +18098,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -18112,7 +18123,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -18646,10 +18657,10 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -18658,14 +18669,14 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_2048_lshift_64(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -18673,12 +18684,12 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -18846,10 +18857,10 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -18904,7 +18915,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -18939,7 +18950,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -29998,17 +30009,17 @@ WC_OMIT_FRAME_POINTER static void sp_3072_sqr_48(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -38353,10 +38364,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -38365,14 +38376,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -38380,12 +38391,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -38506,10 +38517,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -38518,14 +38529,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -38533,12 +38544,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -45088,10 +45099,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -45100,14 +45111,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -45115,12 +45126,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -45224,10 +45235,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -45236,14 +45247,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -45251,12 +45262,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -45329,7 +45340,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -45867,7 +45878,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -45892,7 +45903,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -46618,10 +46629,10 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -46630,14 +46641,14 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_3072_lshift_96(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -46645,12 +46656,12 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -46818,10 +46829,10 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -46876,7 +46887,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -46911,7 +46922,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -48059,17 +48070,17 @@ WC_OMIT_FRAME_POINTER static void sp_4096_sqr_128(sp_digit* r, */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -60696,10 +60707,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -60708,14 +60719,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -60723,12 +60734,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -60832,10 +60843,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -60844,14 +60855,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -60859,12 +60870,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -60937,7 +60948,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -61531,7 +61542,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -61556,7 +61567,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -62474,10 +62485,10 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -62486,14 +62497,14 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_4096_lshift_128(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -62501,12 +62512,12 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -67597,7 +67608,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -67632,7 +67643,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -67698,7 +67709,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -67723,7 +67734,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -72601,7 +72612,7 @@ static void sp_256_mont_inv_8(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 8); for (i=254; i>=0; i--) { sp_256_mont_sqr_8(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p256_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_256_mont_mul_8(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 8); @@ -75246,7 +75257,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons t[15].infinity = 0; i = 6; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -75259,14 +75270,14 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons { XMEMCPY(rt, &t[y], sizeof(sp_point_256)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_256_proj_point_dbl_8(rt, rt, tmp); @@ -77932,10 +77943,10 @@ static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -90478,7 +90489,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -90513,7 +90524,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -90579,7 +90590,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -90604,7 +90615,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -91540,7 +91551,7 @@ static void sp_384_mont_inv_12(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 12); for (i=382; i>=0; i--) { sp_384_mont_sqr_12(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p384_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_384_mont_mul_12(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 12); @@ -93263,7 +93274,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con t[15].infinity = 0; i = 10; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -93276,14 +93287,14 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_384)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_384_proj_point_dbl_12(rt, rt, tmp); @@ -95987,10 +95998,10 @@ static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -117084,7 +117095,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -117119,7 +117130,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -117185,7 +117196,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -117210,7 +117221,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -118769,7 +118780,7 @@ static void sp_521_mont_inv_17(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 17); for (i=519; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 17); @@ -119658,7 +119669,7 @@ static void sp_521_mont_div2_17(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; - sp_521_rshift1_17(r, r); + sp_521_rshift1_17(r, a); r[16] |= o << 8; } @@ -120388,7 +120399,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con t[15].infinity = 0; i = 15; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 5; y = (int)(n >> 5); #ifndef WC_NO_CACHE_RESISTANT @@ -120401,15 +120412,15 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_521)); } - n <<= 27; + n = (sp_uint32)n << (27); for (; i>=0 || c>=4; ) { if (c < 4) { - n = (k[i+1] << 31) | (k[i] >> 1); + n = ((sp_uint32)k[i+1] << 31) | (k[i] >> 1); i--; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_521_proj_point_dbl_17(rt, rt, tmp); @@ -123719,10 +123730,10 @@ static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -125606,8 +125617,6 @@ static WC_INLINE int sp_521_div_17(const sp_digit* a, const sp_digit* d, sp_digit r1; int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = (d[16] << 23) | (d[15] >> 9); XMEMCPY(t1, a, sizeof(*t1) * 2 * 17); @@ -128335,7 +128344,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 17); for (i=518; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_sqrt_power[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 17); @@ -146613,7 +146622,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -146648,7 +146657,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -146714,7 +146723,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -146739,7 +146748,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -150295,18 +150304,18 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, t[15].infinity = 0; i = 30; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); XMEMCPY(rt, &t[y], sizeof(sp_point_1024)); - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_1024_proj_point_dbl_32(rt, rt, tmp); @@ -158411,10 +158420,10 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index 402e75a6db..59751ebe0c 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -47,6 +47,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -265,7 +276,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -300,7 +311,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -2911,10 +2922,10 @@ static void sp_2048_sqr_16(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -2922,7 +2933,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } /* Mul a by digit b into r. (r = a * b) @@ -4151,10 +4162,10 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -4163,14 +4174,14 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 16); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 60); - n <<= 4; + n = (sp_uint64)n << 4; c = 60; } else if (c < 4) { @@ -4178,12 +4189,12 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } @@ -4304,10 +4315,10 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -4316,14 +4327,14 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 16); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 59); - n <<= 5; + n = (sp_uint64)n << 5; c = 59; } else if (c < 5) { @@ -4331,12 +4342,12 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } @@ -5746,10 +5757,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -5758,14 +5769,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 59); - n <<= 5; + n = (sp_uint64)n << 5; c = 59; } else if (c < 5) { @@ -5773,12 +5784,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } @@ -5932,10 +5943,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -5944,14 +5955,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=6; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 58); - n <<= 6; + n = (sp_uint64)n << 6; c = 58; } else if (c < 6) { @@ -5959,12 +5970,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 6 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 58) & 0x3f); - n <<= 6; + n = (sp_uint64)n << 6; c -= 6; } @@ -6039,7 +6050,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -6352,7 +6363,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -6377,7 +6388,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -6703,10 +6714,10 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -6715,14 +6726,14 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } sp_2048_lshift_32(r, norm, y); for (; i>=0 || c>=6; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 58); - n <<= 6; + n = (sp_uint64)n << 6; c = 58; } else if (c < 6) { @@ -6730,12 +6741,12 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 6 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 58) & 0x3f); - n <<= 6; + n = (sp_uint64)n << 6; c -= 6; } @@ -7028,7 +7039,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -7063,7 +7074,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -11584,10 +11595,10 @@ static void sp_3072_sqr_24(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -11595,7 +11606,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } /* Mul a by digit b into r. (r = a * b) @@ -13212,10 +13223,10 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -13224,14 +13235,14 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 24); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 60); - n <<= 4; + n = (sp_uint64)n << 4; c = 60; } else if (c < 4) { @@ -13239,12 +13250,12 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } @@ -13365,10 +13376,10 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -13377,14 +13388,14 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 24); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 59); - n <<= 5; + n = (sp_uint64)n << 5; c = 59; } else if (c < 5) { @@ -13392,12 +13403,12 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } @@ -15175,10 +15186,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -15187,14 +15198,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 61); - n <<= 3; + n = (sp_uint64)n << 3; c = 61; } else if (c < 3) { @@ -15202,12 +15213,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 61) & 0x7); - n <<= 3; + n = (sp_uint64)n << 3; c -= 3; } @@ -15311,10 +15322,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -15323,14 +15334,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 60); - n <<= 4; + n = (sp_uint64)n << 4; c = 60; } else if (c < 4) { @@ -15338,12 +15349,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } @@ -15416,7 +15427,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -15729,7 +15740,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 48; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -15754,7 +15765,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 48; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -16176,10 +16187,10 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -16188,14 +16199,14 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } sp_3072_lshift_48(r, norm, y); for (; i>=0 || c>=6; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 58); - n <<= 6; + n = (sp_uint64)n << 6; c = 58; } else if (c < 6) { @@ -16203,12 +16214,12 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 6 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 58) & 0x3f); - n <<= 6; + n = (sp_uint64)n << 6; c -= 6; } @@ -16501,7 +16512,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -16536,7 +16547,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -17444,10 +17455,10 @@ static void sp_4096_sqr_64(sp_digit* r, const sp_digit* a) */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -17455,7 +17466,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } /* Mul a by digit b into r. (r = a * b) @@ -20186,10 +20197,10 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -20198,14 +20209,14 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 61); - n <<= 3; + n = (sp_uint64)n << 3; c = 61; } else if (c < 3) { @@ -20213,12 +20224,12 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 61) & 0x7); - n <<= 3; + n = (sp_uint64)n << 3; c -= 3; } @@ -20322,10 +20333,10 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -20334,14 +20345,14 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 60); - n <<= 4; + n = (sp_uint64)n << 4; c = 60; } else if (c < 4) { @@ -20349,12 +20360,12 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } @@ -20427,7 +20438,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -20740,7 +20751,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -20765,7 +20776,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -21283,10 +21294,10 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint64)n << c); n = e[i--]; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else if (c == 0) { @@ -21295,14 +21306,14 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 64 - c; + n = (sp_uint64)n << (64 - c); } sp_4096_lshift_64(r, norm, y); for (; i>=0 || c>=6; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 58); - n <<= 6; + n = (sp_uint64)n << 6; c = 58; } else if (c < 6) { @@ -21310,12 +21321,12 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 6 - c; y |= (byte)(n >> (64 - c)); - n <<= c; + n = (sp_uint64)n << c; c = 64 - c; } else { y = (byte)((n >> 58) & 0x3f); - n <<= 6; + n = (sp_uint64)n << 6; c -= 6; } @@ -21865,10 +21876,10 @@ static int sp_256_mod_mul_norm_4(sp_digit* r, const sp_digit* a, const sp_digit* t[5] += t[4] >> 32; t[4] &= 0xffffffff; t[6] += t[5] >> 32; t[5] &= 0xffffffff; t[7] += t[6] >> 32; t[6] &= 0xffffffff; - r[0] = (sp_digit)((t[1] << 32) | t[0]); - r[1] = (sp_digit)((t[3] << 32) | t[2]); - r[2] = (sp_digit)((t[5] << 32) | t[4]); - r[3] = (sp_digit)((t[7] << 32) | t[6]); + r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]); + r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]); + r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]); + r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]); return MP_OKAY; } @@ -21899,7 +21910,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -21934,7 +21945,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -22000,7 +22011,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 4; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -22025,7 +22036,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 4; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -22465,7 +22476,7 @@ static void sp_256_mont_inv_4(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 4); for (i=254; i>=0; i--) { sp_256_mont_sqr_4(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_256_mont_mul_4(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 4); @@ -23959,7 +23970,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v) } else if (++j < 4) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -26903,7 +26914,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v) } else if (++j < 4) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -42693,12 +42704,12 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* t[10] += t[9] >> 32; t[9] &= 0xffffffff; t[11] += t[10] >> 32; t[10] &= 0xffffffff; - r[0] = (sp_digit)((t[1] << 32) | t[0]); - r[1] = (sp_digit)((t[3] << 32) | t[2]); - r[2] = (sp_digit)((t[5] << 32) | t[4]); - r[3] = (sp_digit)((t[7] << 32) | t[6]); - r[4] = (sp_digit)((t[9] << 32) | t[8]); - r[5] = (sp_digit)((t[11] << 32) | t[10]); + r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]); + r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]); + r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]); + r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]); + r[4] = (sp_digit)(((sp_uint64)t[9] << 32) | (sp_uint64)t[8]); + r[5] = (sp_digit)(((sp_uint64)t[11] << 32) | (sp_uint64)t[10]); } SP_FREE_VAR(t, NULL, DYNAMIC_TYPE_ECC); @@ -42732,7 +42743,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -42767,7 +42778,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -42833,7 +42844,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 6; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -42858,7 +42869,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 6; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -43247,7 +43258,7 @@ static void sp_384_mont_inv_6(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 6); for (i=382; i>=0; i--) { sp_384_mont_sqr_6(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_384_mont_mul_6(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 6); @@ -44497,7 +44508,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v) } else if (++j < 6) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -47405,7 +47416,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v) } else if (++j < 6) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -69631,8 +69642,6 @@ static WC_INLINE int sp_521_div_9(const sp_digit* a, const sp_digit* d, sp_digit r1; int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = (d[8] << 55) | (d[7] >> 9); XMEMCPY(t1, a, sizeof(*t1) * 2 * 9); @@ -69713,7 +69722,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -69748,7 +69757,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -69814,7 +69823,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -69839,7 +69848,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -71004,7 +71013,7 @@ static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 9); for (i=519; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 9); @@ -72442,7 +72451,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -76049,7 +76058,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -111994,7 +112003,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 9); for (i=518; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 9); @@ -114032,7 +114041,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -114067,7 +114076,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -114133,7 +114142,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 16; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -114158,7 +114167,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 16; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -116114,7 +116123,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) } else if (++j < 16) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index b479c93b9b..f56e1d9091 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -47,6 +47,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -141,10 +152,10 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -199,7 +210,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -234,7 +245,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -21740,17 +21751,17 @@ WC_OMIT_FRAME_POINTER static SP_NOINLINE void sp_2048_sqr_32(sp_digit* r, */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } /* Mul a by digit b into r. (r = a * b) @@ -24177,10 +24188,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -24189,14 +24200,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -24204,12 +24215,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -24330,10 +24341,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -24342,14 +24353,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -24357,12 +24368,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -27737,10 +27748,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -27749,14 +27760,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -27764,12 +27775,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -27873,10 +27884,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -27885,14 +27896,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -27900,12 +27911,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -27978,7 +27989,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -28325,7 +28336,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -28350,7 +28361,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -30066,10 +30077,10 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -30078,14 +30089,14 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_2048_lshift_64(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -30093,12 +30104,12 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -30266,10 +30277,10 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -30324,7 +30335,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -30359,7 +30370,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -72867,17 +72878,17 @@ WC_OMIT_FRAME_POINTER static SP_NOINLINE void sp_3072_sqr_48(sp_digit* r, */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } /* Mul a by digit b into r. (r = a * b) @@ -75576,10 +75587,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -75588,14 +75599,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -75603,12 +75614,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -75729,10 +75740,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -75741,14 +75752,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -75756,12 +75767,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -79967,10 +79978,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -79979,14 +79990,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -79994,12 +80005,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -80103,10 +80114,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -80115,14 +80126,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -80130,12 +80141,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -80208,7 +80219,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -80555,7 +80566,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -80580,7 +80591,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -83094,10 +83105,10 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -83106,14 +83117,14 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_3072_lshift_96(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -83121,12 +83132,12 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -83294,10 +83305,10 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -83352,7 +83363,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -83387,7 +83398,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -87248,17 +87259,17 @@ WC_OMIT_FRAME_POINTER static SP_NOINLINE void sp_4096_sqr_128(sp_digit* r, */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } /* Mul a by digit b into r. (r = a * b) @@ -92447,10 +92458,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -92459,14 +92470,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -92474,12 +92485,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -92583,10 +92594,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -92595,14 +92606,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -92610,12 +92621,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -92688,7 +92699,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -93040,7 +93051,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -93065,7 +93076,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -96367,10 +96378,10 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -96379,14 +96390,14 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_4096_lshift_128(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -96394,12 +96405,12 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -97538,7 +97549,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -97573,7 +97584,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -97639,7 +97650,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -97664,7 +97675,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -98763,7 +98774,7 @@ static void sp_256_mont_inv_8(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 8); for (i=254; i>=0; i--) { sp_256_mont_sqr_8(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p256_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_256_mont_mul_8(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 8); @@ -100866,7 +100877,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons t[15].infinity = 0; i = 6; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -100879,14 +100890,14 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons { XMEMCPY(rt, &t[y], sizeof(sp_point_256)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_256_proj_point_dbl_8(rt, rt, tmp); @@ -103600,10 +103611,10 @@ static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -108780,7 +108791,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -108815,7 +108826,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -108881,7 +108892,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -108906,7 +108917,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -109816,7 +109827,7 @@ static void sp_384_mont_inv_12(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 12); for (i=382; i>=0; i--) { sp_384_mont_sqr_12(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p384_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_384_mont_mul_12(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 12); @@ -111318,7 +111329,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con t[15].infinity = 0; i = 10; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -111331,14 +111342,14 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_384)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_384_proj_point_dbl_12(rt, rt, tmp); @@ -114120,10 +114131,10 @@ static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -119587,7 +119598,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -119622,7 +119633,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -119688,7 +119699,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -119713,7 +119724,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -121713,7 +121724,7 @@ static void sp_521_mont_inv_17(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 17); for (i=519; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 17); @@ -124547,7 +124558,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con t[15].infinity = 0; i = 15; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 5; y = (int)(n >> 5); #ifndef WC_NO_CACHE_RESISTANT @@ -124560,15 +124571,15 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_521)); } - n <<= 27; + n = (sp_uint32)n << (27); for (; i>=0 || c>=4; ) { if (c < 4) { - n = (k[i+1] << 31) | (k[i] >> 1); + n = ((sp_uint32)k[i+1] << 31) | (k[i] >> 1); i--; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_521_proj_point_dbl_17(rt, rt, tmp); @@ -127992,10 +128003,10 @@ static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -131069,8 +131080,6 @@ static WC_INLINE int sp_521_div_17(const sp_digit* a, const sp_digit* d, sp_digit r1; int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = (d[16] << 23) | (d[15] >> 9); XMEMCPY(t1, a, sizeof(*t1) * 2 * 17); @@ -134979,7 +134988,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 17); for (i=518; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_sqrt_power[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 17); @@ -201254,7 +201263,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -201289,7 +201298,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -201355,7 +201364,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -201380,7 +201389,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -208949,18 +208958,18 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, t[15].infinity = 0; i = 30; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); XMEMCPY(rt, &t[y], sizeof(sp_point_1024)); - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_1024_proj_point_dbl_32(rt, rt, tmp); @@ -217065,10 +217074,10 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index 907c04c61a..8262fb2f73 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -51,6 +51,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -239,7 +250,7 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 21U) { r[j] &= 0x1fffffff; s = 29U - s; @@ -285,7 +296,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1fffffff; s = 29U - s; if (j + 1 >= size) { @@ -320,7 +331,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 29) { r[j] &= 0x1fffffff; if (j + 1 >= size) { @@ -369,7 +380,7 @@ static void sp_2048_to_bin_72(sp_digit* r, byte* a) for (i=0; i<71 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -1526,10 +1537,10 @@ SP_NOINLINE static void sp_2048_sqr_36(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -1537,7 +1548,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffff; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 29) - x; + *rho = (sp_digit)(((sp_uint32)1 << 29) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -2030,22 +2041,22 @@ SP_NOINLINE static void sp_2048_rshift_36(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<35; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } #else for (i=0; i<32; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (29 - n)) & 0x1fffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (29 - n)) & 0x1fffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (29 - n)) & 0x1fffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (29 - n)) & 0x1fffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (29 - n)) & 0x1fffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (29 - n)) & 0x1fffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (29 - n)) & 0x1fffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (29 - n)) & 0x1fffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (29 - n)) & 0x1fffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (29 - n)) & 0x1fffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (29 - n)) & 0x1fffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (29 - n)) & 0x1fffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (29 - n)) & 0x1fffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (29 - n)) & 0x1fffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (29 - n)) & 0x1fffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (29 - n)) & 0x1fffffff); } - r[32] = (a[32] >> n) | (sp_digit)((a[33] << (29 - n)) & 0x1fffffff); - r[33] = (a[33] >> n) | (sp_digit)((a[34] << (29 - n)) & 0x1fffffff); - r[34] = (a[34] >> n) | (sp_digit)((a[35] << (29 - n)) & 0x1fffffff); + r[32] = (a[32] >> n) | (sp_digit)(((sp_uint32)a[33] << (29 - n)) & 0x1fffffff); + r[33] = (a[33] >> n) | (sp_digit)(((sp_uint32)a[34] << (29 - n)) & 0x1fffffff); + r[34] = (a[34] >> n) | (sp_digit)(((sp_uint32)a[35] << (29 - n)) & 0x1fffffff); #endif /* WOLFSSL_SP_SMALL */ r[35] = a[35] >> n; } @@ -2085,7 +2096,7 @@ static WC_INLINE sp_digit sp_2048_div_word_36(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -2277,9 +2288,9 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -2291,7 +2302,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp); @@ -2353,9 +2364,9 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -2367,7 +2378,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp); @@ -2468,38 +2479,38 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 29; } if (i < 36) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 72); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c = 24; } else { y = (byte)((n >> 27) & 0x1f); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 5 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -3027,26 +3038,26 @@ SP_NOINLINE static void sp_2048_rshift_72(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<71; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } #else for (i=0; i<64; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (29 - n)) & 0x1fffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (29 - n)) & 0x1fffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (29 - n)) & 0x1fffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (29 - n)) & 0x1fffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (29 - n)) & 0x1fffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (29 - n)) & 0x1fffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (29 - n)) & 0x1fffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (29 - n)) & 0x1fffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (29 - n)) & 0x1fffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (29 - n)) & 0x1fffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (29 - n)) & 0x1fffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (29 - n)) & 0x1fffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (29 - n)) & 0x1fffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (29 - n)) & 0x1fffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (29 - n)) & 0x1fffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (29 - n)) & 0x1fffffff); } - r[64] = (a[64] >> n) | (sp_digit)((a[65] << (29 - n)) & 0x1fffffff); - r[65] = (a[65] >> n) | (sp_digit)((a[66] << (29 - n)) & 0x1fffffff); - r[66] = (a[66] >> n) | (sp_digit)((a[67] << (29 - n)) & 0x1fffffff); - r[67] = (a[67] >> n) | (sp_digit)((a[68] << (29 - n)) & 0x1fffffff); - r[68] = (a[68] >> n) | (sp_digit)((a[69] << (29 - n)) & 0x1fffffff); - r[69] = (a[69] >> n) | (sp_digit)((a[70] << (29 - n)) & 0x1fffffff); - r[70] = (a[70] >> n) | (sp_digit)((a[71] << (29 - n)) & 0x1fffffff); + r[64] = (a[64] >> n) | (sp_digit)(((sp_uint32)a[65] << (29 - n)) & 0x1fffffff); + r[65] = (a[65] >> n) | (sp_digit)(((sp_uint32)a[66] << (29 - n)) & 0x1fffffff); + r[66] = (a[66] >> n) | (sp_digit)(((sp_uint32)a[67] << (29 - n)) & 0x1fffffff); + r[67] = (a[67] >> n) | (sp_digit)(((sp_uint32)a[68] << (29 - n)) & 0x1fffffff); + r[68] = (a[68] >> n) | (sp_digit)(((sp_uint32)a[69] << (29 - n)) & 0x1fffffff); + r[69] = (a[69] >> n) | (sp_digit)(((sp_uint32)a[70] << (29 - n)) & 0x1fffffff); + r[70] = (a[70] >> n) | (sp_digit)(((sp_uint32)a[71] << (29 - n)) & 0x1fffffff); #endif /* WOLFSSL_SP_SMALL */ r[71] = a[71] >> n; } @@ -3086,7 +3097,7 @@ static WC_INLINE sp_digit sp_2048_div_word_72(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -3281,9 +3292,9 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -3295,7 +3306,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_2048_mont_mul_72(t[y^1], t[0], t[1], m, mp); @@ -3357,9 +3368,9 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -3371,7 +3382,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_2048_mont_mul_72(t[y^1], t[0], t[1], m, mp); @@ -3456,38 +3467,38 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 29; } if (i < 72) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 144); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -3583,10 +3594,10 @@ static int sp_2048_mod_exp_72_nb(sp_2048_mod_exp_72_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 29 + 1 keeps the shift in [1, 29]. */ ctx->i = (ctx->bits - 1) / 29; ctx->c = ((ctx->bits - 1) % 29) + 1; - ctx->n = e[ctx->i--] << (29 - ctx->c); + ctx->n = (sp_uint32)e[ctx->i--] << (29 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -3599,7 +3610,7 @@ static int sp_2048_mod_exp_72_nb(sp_2048_mod_exp_72_ctx* ctx, ctx->c = 29; } ctx->y = (byte)((ctx->n >> 28) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -4372,7 +4383,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 71; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -4397,7 +4408,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 71; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 29 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -4614,7 +4625,7 @@ SP_NOINLINE static void sp_2048_lshift_72(sp_digit* r, const sp_digit* a, r[72] = a[71] >> (29 - n); for (i=71; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); } #else sp_int_digit s; @@ -4765,7 +4776,7 @@ SP_NOINLINE static void sp_2048_lshift_72(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (29U - n))) & 0x1fffffff); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x1fffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x1fffffff); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -4811,38 +4822,38 @@ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const c = 29; } if (i < 72) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_2048_lshift_72(r, norm, (byte)y); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -5172,7 +5183,7 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 21U) { r[j] &= 0x1fffffff; s = 29U - s; @@ -5218,7 +5229,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1fffffff; s = 29U - s; if (j + 1 >= size) { @@ -5253,7 +5264,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 29) { r[j] &= 0x1fffffff; if (j + 1 >= size) { @@ -5302,7 +5313,7 @@ static void sp_3072_to_bin_106(sp_digit* r, byte* a) for (i=0; i<106 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -5478,10 +5489,10 @@ SP_NOINLINE static void sp_3072_sqr_106(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -5489,7 +5500,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffff; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 29) - x; + *rho = (sp_digit)(((sp_uint32)1 << 29) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -5902,7 +5913,7 @@ SP_NOINLINE static void sp_3072_rshift_53(sp_digit* r, const sp_digit* a, int i; for (i=0; i<52; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } r[52] = a[52] >> n; } @@ -5942,7 +5953,7 @@ static WC_INLINE sp_digit sp_3072_div_word_53(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -6134,9 +6145,9 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -6148,7 +6159,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_53(t[y^1], t[0], t[1], m, mp); @@ -6210,9 +6221,9 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -6224,7 +6235,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_53(t[y^1], t[0], t[1], m, mp); @@ -6325,38 +6336,38 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 29; } if (i < 53) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 106); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c = 24; } else { y = (byte)((n >> 27) & 0x1f); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 5 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -6680,7 +6691,7 @@ SP_NOINLINE static void sp_3072_rshift_106(sp_digit* r, const sp_digit* a, int i; for (i=0; i<105; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } r[105] = a[105] >> n; } @@ -6720,7 +6731,7 @@ static WC_INLINE sp_digit sp_3072_div_word_106(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -6913,9 +6924,9 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -6927,7 +6938,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_106(t[y^1], t[0], t[1], m, mp); @@ -6989,9 +7000,9 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -7003,7 +7014,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_106(t[y^1], t[0], t[1], m, mp); @@ -7088,38 +7099,38 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e c = 29; } if (i < 106) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 212); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -7215,10 +7226,10 @@ static int sp_3072_mod_exp_106_nb(sp_3072_mod_exp_106_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 29 + 1 keeps the shift in [1, 29]. */ ctx->i = (ctx->bits - 1) / 29; ctx->c = ((ctx->bits - 1) % 29) + 1; - ctx->n = e[ctx->i--] << (29 - ctx->c); + ctx->n = (sp_uint32)e[ctx->i--] << (29 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -7231,7 +7242,7 @@ static int sp_3072_mod_exp_106_nb(sp_3072_mod_exp_106_ctx* ctx, ctx->c = 29; } ctx->y = (byte)((ctx->n >> 28) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -8002,7 +8013,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 106; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -8027,7 +8038,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 106; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 29 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -8243,9 +8254,9 @@ SP_NOINLINE static void sp_3072_lshift_106(sp_digit* r, const sp_digit* a, r[106] = a[105] >> (29 - n); for (i=105; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); } - r[0] = (sp_digit)((a[0] << n) & 0x1fffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x1fffffff); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -8291,38 +8302,38 @@ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const c = 29; } if (i < 106) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_3072_lshift_106(r, norm, (byte)y); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -8649,7 +8660,7 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 20U) { r[j] &= 0xfffffff; s = 28U - s; @@ -8695,7 +8706,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xfffffff; s = 28U - s; if (j + 1 >= size) { @@ -8730,7 +8741,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 28) { r[j] &= 0xfffffff; if (j + 1 >= size) { @@ -8779,7 +8790,7 @@ static void sp_3072_to_bin_112(sp_digit* r, byte* a) for (i=0; i<110 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -9701,10 +9712,10 @@ SP_NOINLINE static void sp_3072_sqr_112(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -9712,7 +9723,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0xfffffff; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 28) - x; + *rho = (sp_digit)(((sp_uint32)1 << 28) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -10094,22 +10105,22 @@ SP_NOINLINE static void sp_3072_rshift_56(sp_digit* r, const sp_digit* a, int i; for (i=0; i<48; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (28 - n)) & 0xfffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (28 - n)) & 0xfffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (28 - n)) & 0xfffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (28 - n)) & 0xfffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (28 - n)) & 0xfffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (28 - n)) & 0xfffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (28 - n)) & 0xfffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (28 - n)) & 0xfffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (28 - n)) & 0xfffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (28 - n)) & 0xfffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (28 - n)) & 0xfffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (28 - n)) & 0xfffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (28 - n)) & 0xfffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (28 - n)) & 0xfffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (28 - n)) & 0xfffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (28 - n)) & 0xfffffff); } - r[48] = (a[48] >> n) | (sp_digit)((a[49] << (28 - n)) & 0xfffffff); - r[49] = (a[49] >> n) | (sp_digit)((a[50] << (28 - n)) & 0xfffffff); - r[50] = (a[50] >> n) | (sp_digit)((a[51] << (28 - n)) & 0xfffffff); - r[51] = (a[51] >> n) | (sp_digit)((a[52] << (28 - n)) & 0xfffffff); - r[52] = (a[52] >> n) | (sp_digit)((a[53] << (28 - n)) & 0xfffffff); - r[53] = (a[53] >> n) | (sp_digit)((a[54] << (28 - n)) & 0xfffffff); - r[54] = (a[54] >> n) | (sp_digit)((a[55] << (28 - n)) & 0xfffffff); + r[48] = (a[48] >> n) | (sp_digit)(((sp_uint32)a[49] << (28 - n)) & 0xfffffff); + r[49] = (a[49] >> n) | (sp_digit)(((sp_uint32)a[50] << (28 - n)) & 0xfffffff); + r[50] = (a[50] >> n) | (sp_digit)(((sp_uint32)a[51] << (28 - n)) & 0xfffffff); + r[51] = (a[51] >> n) | (sp_digit)(((sp_uint32)a[52] << (28 - n)) & 0xfffffff); + r[52] = (a[52] >> n) | (sp_digit)(((sp_uint32)a[53] << (28 - n)) & 0xfffffff); + r[53] = (a[53] >> n) | (sp_digit)(((sp_uint32)a[54] << (28 - n)) & 0xfffffff); + r[54] = (a[54] >> n) | (sp_digit)(((sp_uint32)a[55] << (28 - n)) & 0xfffffff); r[55] = a[55] >> n; } @@ -10148,7 +10159,7 @@ static WC_INLINE sp_digit sp_3072_div_word_56(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 26; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 27) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -10340,9 +10351,9 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 28; - c = bits % 28; - n = e[i--] << (28 - c); + i = (bits - 1) / 28; + c = ((bits - 1) % 28) + 1; + n = (sp_uint32)e[i--] << (28 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -10354,7 +10365,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 27) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_56(t[y^1], t[0], t[1], m, mp); @@ -10416,9 +10427,9 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 28; - c = bits % 28; - n = e[i--] << (28 - c); + i = (bits - 1) / 28; + c = ((bits - 1) % 28) + 1; + n = (sp_uint32)e[i--] << (28 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -10430,7 +10441,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 27) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_56(t[y^1], t[0], t[1], m, mp); @@ -10531,38 +10542,38 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 28; } if (i < 56) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (4 - c); + n |= (sp_uint32)e[i--] << (4 - c); c += 28; } y = (int)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 112); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c = 23; } else { y = (byte)((n >> 27) & 0x1f); - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; c = 5 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 28 - c; } @@ -10951,22 +10962,22 @@ SP_NOINLINE static void sp_3072_rshift_112(sp_digit* r, const sp_digit* a, int i; for (i=0; i<104; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (28 - n)) & 0xfffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (28 - n)) & 0xfffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (28 - n)) & 0xfffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (28 - n)) & 0xfffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (28 - n)) & 0xfffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (28 - n)) & 0xfffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (28 - n)) & 0xfffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (28 - n)) & 0xfffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (28 - n)) & 0xfffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (28 - n)) & 0xfffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (28 - n)) & 0xfffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (28 - n)) & 0xfffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (28 - n)) & 0xfffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (28 - n)) & 0xfffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (28 - n)) & 0xfffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (28 - n)) & 0xfffffff); } - r[104] = (a[104] >> n) | (sp_digit)((a[105] << (28 - n)) & 0xfffffff); - r[105] = (a[105] >> n) | (sp_digit)((a[106] << (28 - n)) & 0xfffffff); - r[106] = (a[106] >> n) | (sp_digit)((a[107] << (28 - n)) & 0xfffffff); - r[107] = (a[107] >> n) | (sp_digit)((a[108] << (28 - n)) & 0xfffffff); - r[108] = (a[108] >> n) | (sp_digit)((a[109] << (28 - n)) & 0xfffffff); - r[109] = (a[109] >> n) | (sp_digit)((a[110] << (28 - n)) & 0xfffffff); - r[110] = (a[110] >> n) | (sp_digit)((a[111] << (28 - n)) & 0xfffffff); + r[104] = (a[104] >> n) | (sp_digit)(((sp_uint32)a[105] << (28 - n)) & 0xfffffff); + r[105] = (a[105] >> n) | (sp_digit)(((sp_uint32)a[106] << (28 - n)) & 0xfffffff); + r[106] = (a[106] >> n) | (sp_digit)(((sp_uint32)a[107] << (28 - n)) & 0xfffffff); + r[107] = (a[107] >> n) | (sp_digit)(((sp_uint32)a[108] << (28 - n)) & 0xfffffff); + r[108] = (a[108] >> n) | (sp_digit)(((sp_uint32)a[109] << (28 - n)) & 0xfffffff); + r[109] = (a[109] >> n) | (sp_digit)(((sp_uint32)a[110] << (28 - n)) & 0xfffffff); + r[110] = (a[110] >> n) | (sp_digit)(((sp_uint32)a[111] << (28 - n)) & 0xfffffff); r[111] = a[111] >> n; } @@ -11005,7 +11016,7 @@ static WC_INLINE sp_digit sp_3072_div_word_112(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 26; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 27) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -11201,9 +11212,9 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 28; - c = bits % 28; - n = e[i--] << (28 - c); + i = (bits - 1) / 28; + c = ((bits - 1) % 28) + 1; + n = (sp_uint32)e[i--] << (28 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -11215,7 +11226,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 27) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_112(t[y^1], t[0], t[1], m, mp); @@ -11277,9 +11288,9 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 28; - c = bits % 28; - n = e[i--] << (28 - c); + i = (bits - 1) / 28; + c = ((bits - 1) % 28) + 1; + n = (sp_uint32)e[i--] << (28 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -11291,7 +11302,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 27) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_3072_mont_mul_112(t[y^1], t[0], t[1], m, mp); @@ -11376,38 +11387,38 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e c = 28; } if (i < 112) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (4 - c); + n |= (sp_uint32)e[i--] << (4 - c); c += 28; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 224); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 24; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 28 - c; } @@ -11503,10 +11514,10 @@ static int sp_3072_mod_exp_112_nb(sp_3072_mod_exp_112_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 28 + 1 keeps the shift in [1, 28]. */ ctx->i = (ctx->bits - 1) / 28; ctx->c = ((ctx->bits - 1) % 28) + 1; - ctx->n = e[ctx->i--] << (28 - ctx->c); + ctx->n = (sp_uint32)e[ctx->i--] << (28 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -11519,7 +11530,7 @@ static int sp_3072_mod_exp_112_nb(sp_3072_mod_exp_112_ctx* ctx, ctx->c = 28; } ctx->y = (byte)((ctx->n >> 27) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -12090,7 +12101,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 110; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -12115,7 +12126,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 110; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 28 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -12468,7 +12479,7 @@ SP_NOINLINE static void sp_3072_lshift_112(sp_digit* r, const sp_digit* a, r[2] = (sp_digit)(((s << n) | (t >> (28U - n))) & 0xfffffff); s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (28U - n))) & 0xfffffff); - r[0] = (sp_digit)((a[0] << n) & 0xfffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0xfffffff); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -12514,38 +12525,38 @@ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const c = 28; } if (i < 112) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (4 - c); + n |= (sp_uint32)e[i--] << (4 - c); c += 28; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_3072_lshift_112(r, norm, (byte)y); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 24; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 4; + n = (sp_uint32)e[i--] << 4; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 28 - c; } @@ -12774,7 +12785,7 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 21U) { r[j] &= 0x1fffffff; s = 29U - s; @@ -12820,7 +12831,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1fffffff; s = 29U - s; if (j + 1 >= size) { @@ -12855,7 +12866,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 29) { r[j] &= 0x1fffffff; if (j + 1 >= size) { @@ -12904,7 +12915,7 @@ static void sp_4096_to_bin_142(sp_digit* r, byte* a) for (i=0; i<142 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -13082,10 +13093,10 @@ SP_NOINLINE static void sp_4096_sqr_142(sp_digit* r, const sp_digit* a) */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -13093,7 +13104,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffff; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 29) - x; + *rho = (sp_digit)(((sp_uint32)1 << 29) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -13513,7 +13524,7 @@ SP_NOINLINE static void sp_4096_rshift_71(sp_digit* r, const sp_digit* a, int i; for (i=0; i<70; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } r[70] = a[70] >> n; } @@ -13553,7 +13564,7 @@ static WC_INLINE sp_digit sp_4096_div_word_71(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -13745,9 +13756,9 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -13759,7 +13770,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_71(t[y^1], t[0], t[1], m, mp); @@ -13821,9 +13832,9 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -13835,7 +13846,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_71(t[y^1], t[0], t[1], m, mp); @@ -13936,38 +13947,38 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 29; } if (i < 71) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 142); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c = 24; } else { y = (byte)((n >> 27) & 0x1f); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 5 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -14292,7 +14303,7 @@ SP_NOINLINE static void sp_4096_rshift_142(sp_digit* r, const sp_digit* a, int i; for (i=0; i<141; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } r[141] = a[141] >> n; } @@ -14332,7 +14343,7 @@ static WC_INLINE sp_digit sp_4096_div_word_142(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 27; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 28) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -14525,9 +14536,9 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -14539,7 +14550,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_142(t[y^1], t[0], t[1], m, mp); @@ -14601,9 +14612,9 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 29; - c = bits % 29; - n = e[i--] << (29 - c); + i = (bits - 1) / 29; + c = ((bits - 1) % 29) + 1; + n = (sp_uint32)e[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -14615,7 +14626,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 28) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_142(t[y^1], t[0], t[1], m, mp); @@ -14700,38 +14711,38 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e c = 29; } if (i < 142) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 284); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -14827,10 +14838,10 @@ static int sp_4096_mod_exp_142_nb(sp_4096_mod_exp_142_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 29 + 1 keeps the shift in [1, 29]. */ ctx->i = (ctx->bits - 1) / 29; ctx->c = ((ctx->bits - 1) % 29) + 1; - ctx->n = e[ctx->i--] << (29 - ctx->c); + ctx->n = (sp_uint32)e[ctx->i--] << (29 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -14843,7 +14854,7 @@ static int sp_4096_mod_exp_142_nb(sp_4096_mod_exp_142_ctx* ctx, ctx->c = 29; } ctx->y = (byte)((ctx->n >> 28) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -15614,7 +15625,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 142; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -15639,7 +15650,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 142; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 29 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -15855,9 +15866,9 @@ SP_NOINLINE static void sp_4096_lshift_142(sp_digit* r, const sp_digit* a, r[142] = a[141] >> (29 - n); for (i=141; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); } - r[0] = (sp_digit)((a[0] << n) & 0x1fffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x1fffffff); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -15903,38 +15914,38 @@ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const c = 29; } if (i < 142) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint32)e[i--] << (3 - c); c += 29; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_4096_lshift_142(r, norm, (byte)y); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 25; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 3; + n = (sp_uint32)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 29 - c; } @@ -16160,7 +16171,7 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 18U) { r[j] &= 0x3ffffff; s = 26U - s; @@ -16206,7 +16217,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x3ffffff; s = 26U - s; if (j + 1 >= size) { @@ -16241,7 +16252,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 26) { r[j] &= 0x3ffffff; if (j + 1 >= size) { @@ -16290,7 +16301,7 @@ static void sp_4096_to_bin_162(sp_digit* r, byte* a) for (i=0; i<158 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -17221,10 +17232,10 @@ SP_NOINLINE static void sp_4096_sqr_162(sp_digit* r, const sp_digit* a) */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -17232,7 +17243,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x3ffffff; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 26) - x; + *rho = (sp_digit)(((sp_uint32)1 << 26) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -17633,14 +17644,14 @@ SP_NOINLINE static void sp_4096_rshift_81(sp_digit* r, const sp_digit* a, int i; for (i=0; i<80; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (26 - n)) & 0x3ffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (26 - n)) & 0x3ffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (26 - n)) & 0x3ffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (26 - n)) & 0x3ffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (26 - n)) & 0x3ffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (26 - n)) & 0x3ffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (26 - n)) & 0x3ffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (26 - n)) & 0x3ffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (26 - n)) & 0x3ffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (26 - n)) & 0x3ffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (26 - n)) & 0x3ffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (26 - n)) & 0x3ffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (26 - n)) & 0x3ffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (26 - n)) & 0x3ffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (26 - n)) & 0x3ffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (26 - n)) & 0x3ffffff); } r[80] = a[80] >> n; } @@ -17680,7 +17691,7 @@ static WC_INLINE sp_digit sp_4096_div_word_81(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 24; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 25) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -17873,9 +17884,9 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 26; - c = bits % 26; - n = e[i--] << (26 - c); + i = (bits - 1) / 26; + c = ((bits - 1) % 26) + 1; + n = (sp_uint32)e[i--] << (26 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -17887,7 +17898,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 25) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_81(t[y^1], t[0], t[1], m, mp); @@ -17949,9 +17960,9 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 26; - c = bits % 26; - n = e[i--] << (26 - c); + i = (bits - 1) / 26; + c = ((bits - 1) % 26) + 1; + n = (sp_uint32)e[i--] << (26 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -17963,7 +17974,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 25) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_81(t[y^1], t[0], t[1], m, mp); @@ -18064,38 +18075,38 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 26; } if (i < 81) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (6 - c); + n |= (sp_uint32)e[i--] << (6 - c); c += 26; } y = (int)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 162); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c = 21; } else { y = (byte)((n >> 27) & 0x1f); - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; c = 5 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 26 - c; } @@ -18475,16 +18486,16 @@ SP_NOINLINE static void sp_4096_rshift_162(sp_digit* r, const sp_digit* a, int i; for (i=0; i<160; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (26 - n)) & 0x3ffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (26 - n)) & 0x3ffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (26 - n)) & 0x3ffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (26 - n)) & 0x3ffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (26 - n)) & 0x3ffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (26 - n)) & 0x3ffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (26 - n)) & 0x3ffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (26 - n)) & 0x3ffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (26 - n)) & 0x3ffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (26 - n)) & 0x3ffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (26 - n)) & 0x3ffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (26 - n)) & 0x3ffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (26 - n)) & 0x3ffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (26 - n)) & 0x3ffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (26 - n)) & 0x3ffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (26 - n)) & 0x3ffffff); } - r[160] = (a[160] >> n) | (sp_digit)((a[161] << (26 - n)) & 0x3ffffff); + r[160] = (a[160] >> n) | (sp_digit)(((sp_uint32)a[161] << (26 - n)) & 0x3ffffff); r[161] = a[161] >> n; } @@ -18523,7 +18534,7 @@ static WC_INLINE sp_digit sp_4096_div_word_162(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 24; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 25) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -18721,9 +18732,9 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 26; - c = bits % 26; - n = e[i--] << (26 - c); + i = (bits - 1) / 26; + c = ((bits - 1) % 26) + 1; + n = (sp_uint32)e[i--] << (26 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -18735,7 +18746,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 25) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_162(t[y^1], t[0], t[1], m, mp); @@ -18797,9 +18808,9 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e } if (err == MP_OKAY) { - i = bits / 26; - c = bits % 26; - n = e[i--] << (26 - c); + i = (bits - 1) / 26; + c = ((bits - 1) % 26) + 1; + n = (sp_uint32)e[i--] << (26 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -18811,7 +18822,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e } y = (int)((n >> 25) & 1); - n <<= 1; + n = (sp_uint32)n << 1; sp_4096_mont_mul_162(t[y^1], t[0], t[1], m, mp); @@ -18896,38 +18907,38 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e c = 26; } if (i < 162) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (6 - c); + n |= (sp_uint32)e[i--] << (6 - c); c += 26; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 324); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 22; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 26 - c; } @@ -19023,10 +19034,10 @@ static int sp_4096_mod_exp_162_nb(sp_4096_mod_exp_162_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 26 + 1 keeps the shift in [1, 26]. */ ctx->i = (ctx->bits - 1) / 26; ctx->c = ((ctx->bits - 1) % 26) + 1; - ctx->n = e[ctx->i--] << (26 - ctx->c); + ctx->n = (sp_uint32)e[ctx->i--] << (26 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -19039,7 +19050,7 @@ static int sp_4096_mod_exp_162_nb(sp_4096_mod_exp_162_ctx* ctx, ctx->c = 26; } ctx->y = (byte)((ctx->n >> 25) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -19610,7 +19621,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 158; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -19635,7 +19646,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 158; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 26 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -20088,7 +20099,7 @@ SP_NOINLINE static void sp_4096_lshift_162(sp_digit* r, const sp_digit* a, r[2] = (sp_digit)(((s << n) | (t >> (26U - n))) & 0x3ffffff); s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (26U - n))) & 0x3ffffff); - r[0] = (sp_digit)((a[0] << n) & 0x3ffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x3ffffff); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -20134,38 +20145,38 @@ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const c = 26; } if (i < 162) { - n = e[i--] << (32 - c); + n = (sp_uint32)e[i--] << (32 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (6 - c); + n |= (sp_uint32)e[i--] << (6 - c); c += 26; } y = (int)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_4096_lshift_162(r, norm, (byte)y); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c = 22; } else { y = (byte)((n >> 28) & 0xf); - n = e[i--] << 6; + n = (sp_uint32)e[i--] << 6; c = 4 - c; y |= (byte)((n >> (32 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint32)n << c; c = 26 - c; } @@ -20753,7 +20764,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1fffffff; s = 29U - s; if (j + 1 >= size) { @@ -20788,7 +20799,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 29) { r[j] &= 0x1fffffff; if (j + 1 >= size) { @@ -20854,7 +20865,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -20879,7 +20890,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 29 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -21170,32 +21181,32 @@ static void sp_256_mont_reduce_9(sp_digit* a, const sp_digit* m, sp_digit mp) for (i = 0; i < 8; i++) { am = (sp_digit)(a[i] & 0x1fffffff); - a[i + 3] += (sp_digit)((am << 9) & 0x1fffffff); + a[i + 3] += (sp_digit)(((sp_uint32)am << 9) & 0x1fffffff); a[i + 4] += am >> 20; - a[i + 6] += (sp_digit)((am << 18) & 0x1fffffff); - a[i + 7] += (am >> 11) - (sp_digit)((am << 21) & 0x1fffffff); - a[i + 8] += -(am >> 8) + (sp_digit)((am << 24) & 0x1fffffff); + a[i + 6] += (sp_digit)(((sp_uint32)am << 18) & 0x1fffffff); + a[i + 7] += (am >> 11) - (sp_digit)(((sp_uint32)am << 21) & 0x1fffffff); + a[i + 8] += -(am >> 8) + (sp_digit)(((sp_uint32)am << 24) & 0x1fffffff); a[i + 9] += am >> 5; a[i + 1] += a[i] >> 29; } am = (sp_digit)(a[8] & 0xffffff); - a[8 + 3] += (sp_digit)((am << 9) & 0x1fffffff); + a[8 + 3] += (sp_digit)(((sp_uint32)am << 9) & 0x1fffffff); a[8 + 4] += am >> 20; - a[8 + 6] += (sp_digit)((am << 18) & 0x1fffffff); - a[8 + 7] += (am >> 11) - (sp_digit)((am << 21) & 0x1fffffff); - a[8 + 8] += -(am >> 8) + (sp_digit)((am << 24) & 0x1fffffff); + a[8 + 6] += (sp_digit)(((sp_uint32)am << 18) & 0x1fffffff); + a[8 + 7] += (am >> 11) - (sp_digit)(((sp_uint32)am << 21) & 0x1fffffff); + a[8 + 8] += -(am >> 8) + (sp_digit)(((sp_uint32)am << 24) & 0x1fffffff); a[8 + 9] += am >> 5; - a[0] = (a[ 8] >> 24) + (sp_digit)((a[ 9] << 5) & 0x1fffffff); - a[1] = (a[ 9] >> 24) + (sp_digit)((a[10] << 5) & 0x1fffffff); - a[2] = (a[10] >> 24) + (sp_digit)((a[11] << 5) & 0x1fffffff); - a[3] = (a[11] >> 24) + (sp_digit)((a[12] << 5) & 0x1fffffff); - a[4] = (a[12] >> 24) + (sp_digit)((a[13] << 5) & 0x1fffffff); - a[5] = (a[13] >> 24) + (sp_digit)((a[14] << 5) & 0x1fffffff); - a[6] = (a[14] >> 24) + (sp_digit)((a[15] << 5) & 0x1fffffff); - a[7] = (a[15] >> 24) + (sp_digit)((a[16] << 5) & 0x1fffffff); - a[8] = (a[16] >> 24) + (a[17] << 5); + a[0] = (a[ 8] >> 24) + (sp_digit)(((sp_uint32)a[ 9] << 5) & 0x1fffffff); + a[1] = (a[ 9] >> 24) + (sp_digit)(((sp_uint32)a[10] << 5) & 0x1fffffff); + a[2] = (a[10] >> 24) + (sp_digit)(((sp_uint32)a[11] << 5) & 0x1fffffff); + a[3] = (a[11] >> 24) + (sp_digit)(((sp_uint32)a[12] << 5) & 0x1fffffff); + a[4] = (a[12] >> 24) + (sp_digit)(((sp_uint32)a[13] << 5) & 0x1fffffff); + a[5] = (a[13] >> 24) + (sp_digit)(((sp_uint32)a[14] << 5) & 0x1fffffff); + a[6] = (a[14] >> 24) + (sp_digit)(((sp_uint32)a[15] << 5) & 0x1fffffff); + a[7] = (a[15] >> 24) + (sp_digit)(((sp_uint32)a[16] << 5) & 0x1fffffff); + a[8] = (a[16] >> 24) + (sp_digit)((sp_uint32)a[17] << 5); a[1] += a[0] >> 29; a[0] &= 0x1fffffff; a[2] += a[1] >> 29; a[1] &= 0x1fffffff; @@ -21304,7 +21315,7 @@ static void sp_256_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 9); for (i=254; i>=0; i--) { sp_256_mont_sqr_9(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p256_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_256_mont_mul_9(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 9); @@ -21524,17 +21535,17 @@ SP_NOINLINE static void sp_256_rshift1_9(sp_digit* r, const sp_digit* a) int i; for (i=0; i<8; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 28) & 0x1fffffff); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint32)a[i + 1] << 28) & 0x1fffffff); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 28) & 0x1fffffff); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 28) & 0x1fffffff); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 28) & 0x1fffffff); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 28) & 0x1fffffff); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 28) & 0x1fffffff); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 28) & 0x1fffffff); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 28) & 0x1fffffff); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 28) & 0x1fffffff); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint32)a[1] << 28) & 0x1fffffff); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint32)a[2] << 28) & 0x1fffffff); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint32)a[3] << 28) & 0x1fffffff); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint32)a[4] << 28) & 0x1fffffff); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint32)a[5] << 28) & 0x1fffffff); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint32)a[6] << 28) & 0x1fffffff); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint32)a[7] << 28) & 0x1fffffff); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint32)a[8] << 28) & 0x1fffffff); #endif r[8] = a[8] >> 1; } @@ -22156,25 +22167,25 @@ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* r[0] = (sp_digit)(t[0]) & 0x1fffffffL; r[1] = (sp_digit)(t[0] >> 29U); - r[1] |= (sp_digit)(t[1] << 3U); + r[1] |= (sp_digit)((sp_uint32)t[1] << 3U); r[1] &= 0x1fffffffL; r[2] = (sp_digit)(t[1] >> 26U); - r[2] |= (sp_digit)(t[2] << 6U); + r[2] |= (sp_digit)((sp_uint32)t[2] << 6U); r[2] &= 0x1fffffffL; r[3] = (sp_digit)(t[2] >> 23U); - r[3] |= (sp_digit)(t[3] << 9U); + r[3] |= (sp_digit)((sp_uint32)t[3] << 9U); r[3] &= 0x1fffffffL; r[4] = (sp_digit)(t[3] >> 20U); - r[4] |= (sp_digit)(t[4] << 12U); + r[4] |= (sp_digit)((sp_uint32)t[4] << 12U); r[4] &= 0x1fffffffL; r[5] = (sp_digit)(t[4] >> 17U); - r[5] |= (sp_digit)(t[5] << 15U); + r[5] |= (sp_digit)((sp_uint32)t[5] << 15U); r[5] &= 0x1fffffffL; r[6] = (sp_digit)(t[5] >> 14U); - r[6] |= (sp_digit)(t[6] << 18U); + r[6] |= (sp_digit)((sp_uint32)t[6] << 18U); r[6] &= 0x1fffffffL; r[7] = (sp_digit)(t[6] >> 11U); - r[7] |= (sp_digit)(t[7] << 21U); + r[7] |= (sp_digit)((sp_uint32)t[7] << 21U); r[7] &= 0x1fffffffL; r[8] = (sp_digit)(t[7] >> 8U); } @@ -22234,7 +22245,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, if (err == MP_OKAY) { i = 8; c = 24; - n = k[i--] << (29 - c); + n = (sp_uint32)k[i--] << (29 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -22245,7 +22256,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, } y = (n >> 28) & 1; - n <<= 1; + n = (sp_uint32)n << 1; sp_256_proj_point_add_9(&t[y^1], &t[0], &t[1], tmp); @@ -22304,7 +22315,7 @@ static int sp_256_ecc_mulmod_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, XMEMSET(ctx->t, 0, sizeof(sp_point_256) * 3); ctx->i = 8; ctx->c = 24; - ctx->n = k[ctx->i--] << (29 - ctx->c); + ctx->n = (sp_uint32)k[ctx->i--] << (29 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -22334,7 +22345,7 @@ static int sp_256_ecc_mulmod_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, ctx->c = 29; } ctx->y = (ctx->n >> 28) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -22737,7 +22748,7 @@ static void sp_256_ecc_recode_6_9(const sp_digit* k, ecc_recode_256* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (29 - o)) & 0x3f); + y |= (word8)(((sp_uint32)n << (29 - o)) & 0x3f); o -= 23; n >>= o; } @@ -24987,7 +24998,7 @@ static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 21U) { r[j] &= 0x1fffffff; s = 29U - s; @@ -25208,7 +25219,7 @@ static void sp_256_to_bin_9(sp_digit* r, byte* a) for (i=0; i<9 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -25332,18 +25343,18 @@ SP_NOINLINE static void sp_256_rshift_9(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<8; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (29 - n))) & 0x1fffffff); } #else for (i=0; i<8; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (29 - n)) & 0x1fffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (29 - n)) & 0x1fffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (29 - n)) & 0x1fffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (29 - n)) & 0x1fffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (29 - n)) & 0x1fffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (29 - n)) & 0x1fffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (29 - n)) & 0x1fffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (29 - n)) & 0x1fffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (29 - n)) & 0x1fffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (29 - n)) & 0x1fffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (29 - n)) & 0x1fffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (29 - n)) & 0x1fffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (29 - n)) & 0x1fffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (29 - n)) & 0x1fffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (29 - n)) & 0x1fffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (29 - n)) & 0x1fffffff); } #endif /* WOLFSSL_SP_SMALL */ r[8] = a[8] >> n; @@ -25403,7 +25414,7 @@ SP_NOINLINE static void sp_256_lshift_18(sp_digit* r, const sp_digit* a, r[18] = a[17] >> (29 - n); for (i=17; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (29 - n))) & 0x1fffffff); } #else sp_int_digit s; @@ -25446,7 +25457,7 @@ SP_NOINLINE static void sp_256_lshift_18(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (29U - n))) & 0x1fffffff); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x1fffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x1fffffff); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -27681,7 +27692,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x3ffffff; s = 26U - s; if (j + 1 >= size) { @@ -27716,7 +27727,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 26) { r[j] &= 0x3ffffff; if (j + 1 >= size) { @@ -27782,7 +27793,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 15; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -27807,7 +27818,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 15; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 26 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -28113,43 +28124,43 @@ static void sp_384_mont_reduce_15(sp_digit* a, const sp_digit* m, sp_digit mp) (void)mp; for (i = 0; i < 14; i++) { - am = (sp_digit)((a[i] * 0x1) & 0x3ffffff); - a[i + 1] += (sp_digit)((am << 6) & 0x3ffffff); + am = (sp_digit)((((sp_uint32)a[i]) * 0x1) & 0x3ffffff); + a[i + 1] += (sp_digit)(((sp_uint32)am << 6) & 0x3ffffff); a[i + 2] += am >> 20; - a[i + 3] -= (sp_digit)((am << 18) & 0x3ffffff); + a[i + 3] -= (sp_digit)(((sp_uint32)am << 18) & 0x3ffffff); a[i + 4] -= am >> 8; - a[i + 4] -= (sp_digit)((am << 24) & 0x3ffffff); + a[i + 4] -= (sp_digit)(((sp_uint32)am << 24) & 0x3ffffff); a[i + 5] -= am >> 2; - a[i + 14] += (sp_digit)((am << 20) & 0x3ffffff); + a[i + 14] += (sp_digit)(((sp_uint32)am << 20) & 0x3ffffff); a[i + 15] += am >> 6; a[i + 1] += a[i] >> 26; } - am = (sp_digit)((a[14] * 0x1) & 0xfffff); - a[14 + 1] += (sp_digit)((am << 6) & 0x3ffffff); + am = (sp_digit)((((sp_uint32)a[14]) * 0x1) & 0xfffff); + a[14 + 1] += (sp_digit)(((sp_uint32)am << 6) & 0x3ffffff); a[14 + 2] += am >> 20; - a[14 + 3] -= (sp_digit)((am << 18) & 0x3ffffff); + a[14 + 3] -= (sp_digit)(((sp_uint32)am << 18) & 0x3ffffff); a[14 + 4] -= am >> 8; - a[14 + 4] -= (sp_digit)((am << 24) & 0x3ffffff); + a[14 + 4] -= (sp_digit)(((sp_uint32)am << 24) & 0x3ffffff); a[14 + 5] -= am >> 2; - a[14 + 14] += (sp_digit)((am << 20) & 0x3ffffff); + a[14 + 14] += (sp_digit)(((sp_uint32)am << 20) & 0x3ffffff); a[14 + 15] += am >> 6; - a[0] = (a[14] >> 20) + (sp_digit)((a[15] << 6) & 0x3ffffff); - a[1] = (a[15] >> 20) + (sp_digit)((a[16] << 6) & 0x3ffffff); - a[2] = (a[16] >> 20) + (sp_digit)((a[17] << 6) & 0x3ffffff); - a[3] = (a[17] >> 20) + (sp_digit)((a[18] << 6) & 0x3ffffff); - a[4] = (a[18] >> 20) + (sp_digit)((a[19] << 6) & 0x3ffffff); - a[5] = (a[19] >> 20) + (sp_digit)((a[20] << 6) & 0x3ffffff); - a[6] = (a[20] >> 20) + (sp_digit)((a[21] << 6) & 0x3ffffff); - a[7] = (a[21] >> 20) + (sp_digit)((a[22] << 6) & 0x3ffffff); - a[8] = (a[22] >> 20) + (sp_digit)((a[23] << 6) & 0x3ffffff); - a[9] = (a[23] >> 20) + (sp_digit)((a[24] << 6) & 0x3ffffff); - a[10] = (a[24] >> 20) + (sp_digit)((a[25] << 6) & 0x3ffffff); - a[11] = (a[25] >> 20) + (sp_digit)((a[26] << 6) & 0x3ffffff); - a[12] = (a[26] >> 20) + (sp_digit)((a[27] << 6) & 0x3ffffff); - a[13] = (a[27] >> 20) + (sp_digit)((a[28] << 6) & 0x3ffffff); - a[14] = (a[14 + 14] >> 20) + (a[29] << 6); + a[0] = (a[14] >> 20) + (sp_digit)(((sp_uint32)a[15] << 6) & 0x3ffffff); + a[1] = (a[15] >> 20) + (sp_digit)(((sp_uint32)a[16] << 6) & 0x3ffffff); + a[2] = (a[16] >> 20) + (sp_digit)(((sp_uint32)a[17] << 6) & 0x3ffffff); + a[3] = (a[17] >> 20) + (sp_digit)(((sp_uint32)a[18] << 6) & 0x3ffffff); + a[4] = (a[18] >> 20) + (sp_digit)(((sp_uint32)a[19] << 6) & 0x3ffffff); + a[5] = (a[19] >> 20) + (sp_digit)(((sp_uint32)a[20] << 6) & 0x3ffffff); + a[6] = (a[20] >> 20) + (sp_digit)(((sp_uint32)a[21] << 6) & 0x3ffffff); + a[7] = (a[21] >> 20) + (sp_digit)(((sp_uint32)a[22] << 6) & 0x3ffffff); + a[8] = (a[22] >> 20) + (sp_digit)(((sp_uint32)a[23] << 6) & 0x3ffffff); + a[9] = (a[23] >> 20) + (sp_digit)(((sp_uint32)a[24] << 6) & 0x3ffffff); + a[10] = (a[24] >> 20) + (sp_digit)(((sp_uint32)a[25] << 6) & 0x3ffffff); + a[11] = (a[25] >> 20) + (sp_digit)(((sp_uint32)a[26] << 6) & 0x3ffffff); + a[12] = (a[26] >> 20) + (sp_digit)(((sp_uint32)a[27] << 6) & 0x3ffffff); + a[13] = (a[27] >> 20) + (sp_digit)(((sp_uint32)a[28] << 6) & 0x3ffffff); + a[14] = (a[14 + 14] >> 20) + (sp_digit)((sp_uint32)a[29] << 6); a[1] += a[0] >> 26; a[0] &= 0x3ffffff; a[2] += a[1] >> 26; a[1] &= 0x3ffffff; @@ -28276,7 +28287,7 @@ static void sp_384_mont_inv_15(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 15); for (i=382; i>=0; i--) { sp_384_mont_sqr_15(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p384_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_384_mont_mul_15(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 15); @@ -28518,23 +28529,23 @@ SP_NOINLINE static void sp_384_rshift1_15(sp_digit* r, const sp_digit* a) int i; for (i=0; i<14; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 25) & 0x3ffffff); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint32)a[i + 1] << 25) & 0x3ffffff); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 25) & 0x3ffffff); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 25) & 0x3ffffff); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 25) & 0x3ffffff); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 25) & 0x3ffffff); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 25) & 0x3ffffff); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 25) & 0x3ffffff); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 25) & 0x3ffffff); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 25) & 0x3ffffff); - r[8] = (a[8] >> 1) + (sp_digit)((a[9] << 25) & 0x3ffffff); - r[9] = (a[9] >> 1) + (sp_digit)((a[10] << 25) & 0x3ffffff); - r[10] = (a[10] >> 1) + (sp_digit)((a[11] << 25) & 0x3ffffff); - r[11] = (a[11] >> 1) + (sp_digit)((a[12] << 25) & 0x3ffffff); - r[12] = (a[12] >> 1) + (sp_digit)((a[13] << 25) & 0x3ffffff); - r[13] = (a[13] >> 1) + (sp_digit)((a[14] << 25) & 0x3ffffff); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint32)a[1] << 25) & 0x3ffffff); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint32)a[2] << 25) & 0x3ffffff); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint32)a[3] << 25) & 0x3ffffff); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint32)a[4] << 25) & 0x3ffffff); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint32)a[5] << 25) & 0x3ffffff); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint32)a[6] << 25) & 0x3ffffff); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint32)a[7] << 25) & 0x3ffffff); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint32)a[8] << 25) & 0x3ffffff); + r[8] = (a[8] >> 1) + (sp_digit)(((sp_uint32)a[9] << 25) & 0x3ffffff); + r[9] = (a[9] >> 1) + (sp_digit)(((sp_uint32)a[10] << 25) & 0x3ffffff); + r[10] = (a[10] >> 1) + (sp_digit)(((sp_uint32)a[11] << 25) & 0x3ffffff); + r[11] = (a[11] >> 1) + (sp_digit)(((sp_uint32)a[12] << 25) & 0x3ffffff); + r[12] = (a[12] >> 1) + (sp_digit)(((sp_uint32)a[13] << 25) & 0x3ffffff); + r[13] = (a[13] >> 1) + (sp_digit)(((sp_uint32)a[14] << 25) & 0x3ffffff); #endif r[14] = a[14] >> 1; } @@ -29188,39 +29199,39 @@ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit r[0] = (sp_digit)(t[0]) & 0x3ffffffL; r[1] = (sp_digit)(t[0] >> 26U); - r[1] |= (sp_digit)(t[1] << 6U); + r[1] |= (sp_digit)((sp_uint32)t[1] << 6U); r[1] &= 0x3ffffffL; r[2] = (sp_digit)(t[1] >> 20U); - r[2] |= (sp_digit)(t[2] << 12U); + r[2] |= (sp_digit)((sp_uint32)t[2] << 12U); r[2] &= 0x3ffffffL; r[3] = (sp_digit)(t[2] >> 14U); - r[3] |= (sp_digit)(t[3] << 18U); + r[3] |= (sp_digit)((sp_uint32)t[3] << 18U); r[3] &= 0x3ffffffL; r[4] = (sp_digit)(t[3] >> 8U); - r[4] |= (sp_digit)(t[4] << 24U); + r[4] |= (sp_digit)((sp_uint32)t[4] << 24U); r[4] &= 0x3ffffffL; r[5] = (sp_digit)(t[4] >> 2U) & 0x3ffffffL; r[6] = (sp_digit)(t[4] >> 28U); - r[6] |= (sp_digit)(t[5] << 4U); + r[6] |= (sp_digit)((sp_uint32)t[5] << 4U); r[6] &= 0x3ffffffL; r[7] = (sp_digit)(t[5] >> 22U); - r[7] |= (sp_digit)(t[6] << 10U); + r[7] |= (sp_digit)((sp_uint32)t[6] << 10U); r[7] &= 0x3ffffffL; r[8] = (sp_digit)(t[6] >> 16U); - r[8] |= (sp_digit)(t[7] << 16U); + r[8] |= (sp_digit)((sp_uint32)t[7] << 16U); r[8] &= 0x3ffffffL; r[9] = (sp_digit)(t[7] >> 10U); - r[9] |= (sp_digit)(t[8] << 22U); + r[9] |= (sp_digit)((sp_uint32)t[8] << 22U); r[9] &= 0x3ffffffL; r[10] = (sp_digit)(t[8] >> 4U) & 0x3ffffffL; r[11] = (sp_digit)(t[8] >> 30U); - r[11] |= (sp_digit)(t[9] << 2U); + r[11] |= (sp_digit)((sp_uint32)t[9] << 2U); r[11] &= 0x3ffffffL; r[12] = (sp_digit)(t[9] >> 24U); - r[12] |= (sp_digit)(t[10] << 8U); + r[12] |= (sp_digit)((sp_uint32)t[10] << 8U); r[12] &= 0x3ffffffL; r[13] = (sp_digit)(t[10] >> 18U); - r[13] |= (sp_digit)(t[11] << 14U); + r[13] |= (sp_digit)((sp_uint32)t[11] << 14U); r[13] &= 0x3ffffffL; r[14] = (sp_digit)(t[11] >> 12U); } @@ -29280,7 +29291,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, if (err == MP_OKAY) { i = 14; c = 20; - n = k[i--] << (26 - c); + n = (sp_uint32)k[i--] << (26 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -29291,7 +29302,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, } y = (n >> 25) & 1; - n <<= 1; + n = (sp_uint32)n << 1; sp_384_proj_point_add_15(&t[y^1], &t[0], &t[1], tmp); @@ -29350,7 +29361,7 @@ static int sp_384_ecc_mulmod_15_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, XMEMSET(ctx->t, 0, sizeof(sp_point_384) * 3); ctx->i = 14; ctx->c = 20; - ctx->n = k[ctx->i--] << (26 - ctx->c); + ctx->n = (sp_uint32)k[ctx->i--] << (26 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -29380,7 +29391,7 @@ static int sp_384_ecc_mulmod_15_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, ctx->c = 26; } ctx->y = (ctx->n >> 25) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -29795,7 +29806,7 @@ static void sp_384_ecc_recode_6_15(const sp_digit* k, ecc_recode_384* v) } else if (++j < 15) { n = k[j]; - y |= (word8)((n << (26 - o)) & 0x3f); + y |= (word8)(((sp_uint32)n << (26 - o)) & 0x3f); o -= 20; n >>= o; } @@ -32617,7 +32628,7 @@ static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 18U) { r[j] &= 0x3ffffff; s = 26U - s; @@ -32838,7 +32849,7 @@ static void sp_384_to_bin_15(sp_digit* r, byte* a) for (i=0; i<15 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -32962,25 +32973,25 @@ SP_NOINLINE static void sp_384_rshift_15(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<14; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (26 - n))) & 0x3ffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (26 - n))) & 0x3ffffff); } #else for (i=0; i<8; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (26 - n)) & 0x3ffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (26 - n)) & 0x3ffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (26 - n)) & 0x3ffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (26 - n)) & 0x3ffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (26 - n)) & 0x3ffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (26 - n)) & 0x3ffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (26 - n)) & 0x3ffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (26 - n)) & 0x3ffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (26 - n)) & 0x3ffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (26 - n)) & 0x3ffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (26 - n)) & 0x3ffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (26 - n)) & 0x3ffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (26 - n)) & 0x3ffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (26 - n)) & 0x3ffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (26 - n)) & 0x3ffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (26 - n)) & 0x3ffffff); } - r[8] = (a[8] >> n) | (sp_digit)((a[9] << (26 - n)) & 0x3ffffff); - r[9] = (a[9] >> n) | (sp_digit)((a[10] << (26 - n)) & 0x3ffffff); - r[10] = (a[10] >> n) | (sp_digit)((a[11] << (26 - n)) & 0x3ffffff); - r[11] = (a[11] >> n) | (sp_digit)((a[12] << (26 - n)) & 0x3ffffff); - r[12] = (a[12] >> n) | (sp_digit)((a[13] << (26 - n)) & 0x3ffffff); - r[13] = (a[13] >> n) | (sp_digit)((a[14] << (26 - n)) & 0x3ffffff); + r[8] = (a[8] >> n) | (sp_digit)(((sp_uint32)a[9] << (26 - n)) & 0x3ffffff); + r[9] = (a[9] >> n) | (sp_digit)(((sp_uint32)a[10] << (26 - n)) & 0x3ffffff); + r[10] = (a[10] >> n) | (sp_digit)(((sp_uint32)a[11] << (26 - n)) & 0x3ffffff); + r[11] = (a[11] >> n) | (sp_digit)(((sp_uint32)a[12] << (26 - n)) & 0x3ffffff); + r[12] = (a[12] >> n) | (sp_digit)(((sp_uint32)a[13] << (26 - n)) & 0x3ffffff); + r[13] = (a[13] >> n) | (sp_digit)(((sp_uint32)a[14] << (26 - n)) & 0x3ffffff); #endif /* WOLFSSL_SP_SMALL */ r[14] = a[14] >> n; } @@ -33051,7 +33062,7 @@ SP_NOINLINE static void sp_384_lshift_30(sp_digit* r, const sp_digit* a, r[30] = a[29] >> (26 - n); for (i=29; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (26 - n))) & 0x3ffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (26 - n))) & 0x3ffffff); } #else sp_int_digit s; @@ -33118,7 +33129,7 @@ SP_NOINLINE static void sp_384_lshift_30(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (26U - n))) & 0x3ffffff); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x3ffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x3ffffff); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -34983,7 +34994,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1ffffff; s = 25U - s; if (j + 1 >= size) { @@ -35018,7 +35029,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 25) { r[j] &= 0x1ffffff; if (j + 1 >= size) { @@ -35084,7 +35095,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 21; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -35109,7 +35120,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 21; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 25 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -35197,10 +35208,10 @@ static void sp_521_mont_reduce_21(sp_digit* a, const sp_digit* m, sp_digit mp) (void)mp; for (i = 0; i < 20; i++) { - a[i] += (sp_digit)(((a[20 + i] >> 21) + (a[20 + i + 1] << 4)) & 0x1ffffff); + a[i] += (sp_digit)(((a[20 + i] >> 21) + ((sp_uint32)a[20 + i + 1] << 4)) & 0x1ffffff); } a[20] &= 0x1fffff; - a[20] += (sp_digit)(((a[40] >> 21) + (a[41] << 4)) & 0x1ffffff); + a[20] += (sp_digit)(((a[40] >> 21) + ((sp_uint32)a[41] << 4)) & 0x1ffffff); sp_521_norm_21(a); @@ -35368,12 +35379,12 @@ static void sp_521_mont_shift_21(sp_digit* r, const sp_digit* a) s = a[21]; n = a[20] >> 21; for (i = 0; i < 20; i++) { - n += (sp_digit)((s & 0x1ffffff) << 4); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[22 + i] + (s >> 25); } - n += s << 4; + n += (sp_uint32)s << 4; r[20] = n; #else sp_digit n; @@ -35382,32 +35393,32 @@ static void sp_521_mont_shift_21(sp_digit* r, const sp_digit* a) s = a[21]; n = a[20] >> 21; for (i = 0; i < 16; i += 8) { - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+0] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+0] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+22] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+1] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+1] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+23] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+2] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+2] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+24] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+3] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+3] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+25] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+4] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+4] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+26] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+5] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+5] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+27] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+6] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+6] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+28] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[i+7] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[i+7] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[i+29] + (s >> 25); } - n += (sp_digit)((s & 0x1ffffff) << 4); r[16] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[16] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[38] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[17] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[17] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[39] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[18] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[18] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[40] + (s >> 25); - n += (sp_digit)((s & 0x1ffffff) << 4); r[19] = (sp_digit)(n & 0x1ffffff); + n += (sp_digit)((sp_uint32)(s & 0x1ffffff) << 4); r[19] = (sp_digit)(n & 0x1ffffff); n >>= 25; s = a[41] + (s >> 25); - n += s << 4; r[20] = n; + n += (sp_uint32)s << 4; r[20] = n; #endif /* WOLFSSL_SP_SMALL */ XMEMSET(&r[21], 0, sizeof(*r) * 21U); } @@ -35515,7 +35526,7 @@ static void sp_521_mont_inv_21(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 21); for (i=519; i>=0; i--) { sp_521_mont_sqr_21(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_21(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 21); @@ -35755,29 +35766,29 @@ SP_NOINLINE static void sp_521_rshift1_21(sp_digit* r, const sp_digit* a) int i; for (i=0; i<20; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 24) & 0x1ffffff); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint32)a[i + 1] << 24) & 0x1ffffff); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 24) & 0x1ffffff); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 24) & 0x1ffffff); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 24) & 0x1ffffff); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 24) & 0x1ffffff); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 24) & 0x1ffffff); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 24) & 0x1ffffff); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 24) & 0x1ffffff); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 24) & 0x1ffffff); - r[8] = (a[8] >> 1) + (sp_digit)((a[9] << 24) & 0x1ffffff); - r[9] = (a[9] >> 1) + (sp_digit)((a[10] << 24) & 0x1ffffff); - r[10] = (a[10] >> 1) + (sp_digit)((a[11] << 24) & 0x1ffffff); - r[11] = (a[11] >> 1) + (sp_digit)((a[12] << 24) & 0x1ffffff); - r[12] = (a[12] >> 1) + (sp_digit)((a[13] << 24) & 0x1ffffff); - r[13] = (a[13] >> 1) + (sp_digit)((a[14] << 24) & 0x1ffffff); - r[14] = (a[14] >> 1) + (sp_digit)((a[15] << 24) & 0x1ffffff); - r[15] = (a[15] >> 1) + (sp_digit)((a[16] << 24) & 0x1ffffff); - r[16] = (a[16] >> 1) + (sp_digit)((a[17] << 24) & 0x1ffffff); - r[17] = (a[17] >> 1) + (sp_digit)((a[18] << 24) & 0x1ffffff); - r[18] = (a[18] >> 1) + (sp_digit)((a[19] << 24) & 0x1ffffff); - r[19] = (a[19] >> 1) + (sp_digit)((a[20] << 24) & 0x1ffffff); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint32)a[1] << 24) & 0x1ffffff); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint32)a[2] << 24) & 0x1ffffff); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint32)a[3] << 24) & 0x1ffffff); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint32)a[4] << 24) & 0x1ffffff); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint32)a[5] << 24) & 0x1ffffff); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint32)a[6] << 24) & 0x1ffffff); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint32)a[7] << 24) & 0x1ffffff); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint32)a[8] << 24) & 0x1ffffff); + r[8] = (a[8] >> 1) + (sp_digit)(((sp_uint32)a[9] << 24) & 0x1ffffff); + r[9] = (a[9] >> 1) + (sp_digit)(((sp_uint32)a[10] << 24) & 0x1ffffff); + r[10] = (a[10] >> 1) + (sp_digit)(((sp_uint32)a[11] << 24) & 0x1ffffff); + r[11] = (a[11] >> 1) + (sp_digit)(((sp_uint32)a[12] << 24) & 0x1ffffff); + r[12] = (a[12] >> 1) + (sp_digit)(((sp_uint32)a[13] << 24) & 0x1ffffff); + r[13] = (a[13] >> 1) + (sp_digit)(((sp_uint32)a[14] << 24) & 0x1ffffff); + r[14] = (a[14] >> 1) + (sp_digit)(((sp_uint32)a[15] << 24) & 0x1ffffff); + r[15] = (a[15] >> 1) + (sp_digit)(((sp_uint32)a[16] << 24) & 0x1ffffff); + r[16] = (a[16] >> 1) + (sp_digit)(((sp_uint32)a[17] << 24) & 0x1ffffff); + r[17] = (a[17] >> 1) + (sp_digit)(((sp_uint32)a[18] << 24) & 0x1ffffff); + r[18] = (a[18] >> 1) + (sp_digit)(((sp_uint32)a[19] << 24) & 0x1ffffff); + r[19] = (a[19] >> 1) + (sp_digit)(((sp_uint32)a[20] << 24) & 0x1ffffff); #endif r[20] = a[20] >> 1; } @@ -36388,7 +36399,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, if (err == MP_OKAY) { i = 20; c = 21; - n = k[i--] << (25 - c); + n = (sp_uint32)k[i--] << (25 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -36399,7 +36410,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, } y = (n >> 24) & 1; - n <<= 1; + n = (sp_uint32)n << 1; sp_521_proj_point_add_21(&t[y^1], &t[0], &t[1], tmp); @@ -36458,7 +36469,7 @@ static int sp_521_ecc_mulmod_21_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r, XMEMSET(ctx->t, 0, sizeof(sp_point_521) * 3); ctx->i = 20; ctx->c = 21; - ctx->n = k[ctx->i--] << (25 - ctx->c); + ctx->n = (sp_uint32)k[ctx->i--] << (25 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -36488,7 +36499,7 @@ static int sp_521_ecc_mulmod_21_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r, ctx->c = 25; } ctx->y = (ctx->n >> 24) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -36915,7 +36926,7 @@ static void sp_521_ecc_recode_6_21(const sp_digit* k, ecc_recode_521* v) } else if (++j < 21) { n = k[j]; - y |= (word8)((n << (25 - o)) & 0x3f); + y |= (word8)(((sp_uint32)n << (25 - o)) & 0x3f); o -= 19; n >>= o; } @@ -40307,7 +40318,7 @@ static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 17U) { r[j] &= 0x1ffffff; s = 25U - s; @@ -40529,7 +40540,7 @@ static void sp_521_to_bin_21(sp_digit* r, byte* a) for (i=0; i<21 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint32)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -40651,23 +40662,23 @@ SP_NOINLINE static void sp_521_rshift_21(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<20; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (25 - n))) & 0x1ffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (25 - n))) & 0x1ffffff); } #else for (i=0; i<16; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (25 - n)) & 0x1ffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (25 - n)) & 0x1ffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (25 - n)) & 0x1ffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (25 - n)) & 0x1ffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (25 - n)) & 0x1ffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (25 - n)) & 0x1ffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (25 - n)) & 0x1ffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (25 - n)) & 0x1ffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (25 - n)) & 0x1ffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (25 - n)) & 0x1ffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (25 - n)) & 0x1ffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (25 - n)) & 0x1ffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (25 - n)) & 0x1ffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (25 - n)) & 0x1ffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (25 - n)) & 0x1ffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (25 - n)) & 0x1ffffff); } - r[16] = (a[16] >> n) | (sp_digit)((a[17] << (25 - n)) & 0x1ffffff); - r[17] = (a[17] >> n) | (sp_digit)((a[18] << (25 - n)) & 0x1ffffff); - r[18] = (a[18] >> n) | (sp_digit)((a[19] << (25 - n)) & 0x1ffffff); - r[19] = (a[19] >> n) | (sp_digit)((a[20] << (25 - n)) & 0x1ffffff); + r[16] = (a[16] >> n) | (sp_digit)(((sp_uint32)a[17] << (25 - n)) & 0x1ffffff); + r[17] = (a[17] >> n) | (sp_digit)(((sp_uint32)a[18] << (25 - n)) & 0x1ffffff); + r[18] = (a[18] >> n) | (sp_digit)(((sp_uint32)a[19] << (25 - n)) & 0x1ffffff); + r[19] = (a[19] >> n) | (sp_digit)(((sp_uint32)a[20] << (25 - n)) & 0x1ffffff); #endif /* WOLFSSL_SP_SMALL */ r[20] = a[20] >> n; } @@ -40738,7 +40749,7 @@ SP_NOINLINE static void sp_521_lshift_42(sp_digit* r, const sp_digit* a, r[42] = a[41] >> (25 - n); for (i=41; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (25 - n))) & 0x1ffffff); + r[i] = (sp_digit)((((sp_uint32)a[i] << n) | (a[i-1] >> (25 - n))) & 0x1ffffff); } #else sp_int_digit s; @@ -40829,7 +40840,7 @@ SP_NOINLINE static void sp_521_lshift_42(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (25U - n))) & 0x1ffffff); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x1ffffff); + r[0] = (sp_digit)(((sp_uint32)a[0] << n) & 0x1ffffff); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -42253,7 +42264,7 @@ static int sp_521_mont_sqrt_21(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 21); for (i=518; i>=0; i--) { sp_521_mont_sqr_21(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_sqrt_power[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_21(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 21); @@ -43165,20 +43176,20 @@ SP_NOINLINE static void sp_1024_rshift_42(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<41; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (25 - n))) & 0x1ffffff); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint32)a[i + 1] << (25 - n))) & 0x1ffffff); } #else for (i=0; i<40; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (25 - n)) & 0x1ffffff); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (25 - n)) & 0x1ffffff); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (25 - n)) & 0x1ffffff); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (25 - n)) & 0x1ffffff); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (25 - n)) & 0x1ffffff); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (25 - n)) & 0x1ffffff); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (25 - n)) & 0x1ffffff); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (25 - n)) & 0x1ffffff); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint32)a[i+1] << (25 - n)) & 0x1ffffff); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint32)a[i+2] << (25 - n)) & 0x1ffffff); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint32)a[i+3] << (25 - n)) & 0x1ffffff); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint32)a[i+4] << (25 - n)) & 0x1ffffff); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint32)a[i+5] << (25 - n)) & 0x1ffffff); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint32)a[i+6] << (25 - n)) & 0x1ffffff); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint32)a[i+7] << (25 - n)) & 0x1ffffff); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint32)a[i+8] << (25 - n)) & 0x1ffffff); } - r[40] = (a[40] >> n) | (sp_digit)((a[41] << (25 - n)) & 0x1ffffff); + r[40] = (a[40] >> n) | (sp_digit)(((sp_uint32)a[41] << (25 - n)) & 0x1ffffff); #endif /* WOLFSSL_SP_SMALL */ r[41] = a[41] >> n; } @@ -43218,7 +43229,7 @@ static WC_INLINE sp_digit sp_1024_div_word_42(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 23; i >= 1; i--) { t1 += t1 + (((sp_uint32)t0 >> 24) & 1); - t0 <<= 1; + t0 = (sp_uint32)t0 << 1; t2 = (sp_digit)(((sp_uint32)(dv - t1)) >> 31); r += r + t2; t1 -= dv & (0 - t2); @@ -43461,7 +43472,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0x1ffffff; s = 25U - s; if (j + 1 >= size) { @@ -43496,7 +43507,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 25) { r[j] &= 0x1ffffff; if (j + 1 >= size) { @@ -43562,7 +43573,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 41; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -43587,7 +43598,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 41; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 25 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -43850,11 +43861,11 @@ static void sp_1024_mont_reduce_42(sp_digit* a, const sp_digit* m, sp_digit mp) if (mp != 1) { for (i=0; i<40; i++) { - mu = (sp_digit)((a[i] * mp) & 0x1ffffff); + mu = (sp_digit)(((sp_uint32)a[i] * (sp_uint32)mp) & 0x1ffffff); sp_1024_mul_add_42(a+i, m, mu); a[i+1] += a[i] >> 25; } - mu = (sp_digit)((a[i] * mp) & 0xffffffL); + mu = (sp_digit)(((sp_uint32)a[i] * (sp_uint32)mp) & 0xffffffL); sp_1024_mul_add_42(a+i, m, mu); a[i+1] += a[i] >> 25; a[i] &= 0x1ffffff; @@ -44091,50 +44102,50 @@ SP_NOINLINE static void sp_1024_rshift1_42(sp_digit* r, const sp_digit* a) int i; for (i=0; i<41; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 24) & 0x1ffffff); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint32)a[i + 1] << 24) & 0x1ffffff); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 24) & 0x1ffffff); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 24) & 0x1ffffff); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 24) & 0x1ffffff); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 24) & 0x1ffffff); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 24) & 0x1ffffff); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 24) & 0x1ffffff); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 24) & 0x1ffffff); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 24) & 0x1ffffff); - r[8] = (a[8] >> 1) + (sp_digit)((a[9] << 24) & 0x1ffffff); - r[9] = (a[9] >> 1) + (sp_digit)((a[10] << 24) & 0x1ffffff); - r[10] = (a[10] >> 1) + (sp_digit)((a[11] << 24) & 0x1ffffff); - r[11] = (a[11] >> 1) + (sp_digit)((a[12] << 24) & 0x1ffffff); - r[12] = (a[12] >> 1) + (sp_digit)((a[13] << 24) & 0x1ffffff); - r[13] = (a[13] >> 1) + (sp_digit)((a[14] << 24) & 0x1ffffff); - r[14] = (a[14] >> 1) + (sp_digit)((a[15] << 24) & 0x1ffffff); - r[15] = (a[15] >> 1) + (sp_digit)((a[16] << 24) & 0x1ffffff); - r[16] = (a[16] >> 1) + (sp_digit)((a[17] << 24) & 0x1ffffff); - r[17] = (a[17] >> 1) + (sp_digit)((a[18] << 24) & 0x1ffffff); - r[18] = (a[18] >> 1) + (sp_digit)((a[19] << 24) & 0x1ffffff); - r[19] = (a[19] >> 1) + (sp_digit)((a[20] << 24) & 0x1ffffff); - r[20] = (a[20] >> 1) + (sp_digit)((a[21] << 24) & 0x1ffffff); - r[21] = (a[21] >> 1) + (sp_digit)((a[22] << 24) & 0x1ffffff); - r[22] = (a[22] >> 1) + (sp_digit)((a[23] << 24) & 0x1ffffff); - r[23] = (a[23] >> 1) + (sp_digit)((a[24] << 24) & 0x1ffffff); - r[24] = (a[24] >> 1) + (sp_digit)((a[25] << 24) & 0x1ffffff); - r[25] = (a[25] >> 1) + (sp_digit)((a[26] << 24) & 0x1ffffff); - r[26] = (a[26] >> 1) + (sp_digit)((a[27] << 24) & 0x1ffffff); - r[27] = (a[27] >> 1) + (sp_digit)((a[28] << 24) & 0x1ffffff); - r[28] = (a[28] >> 1) + (sp_digit)((a[29] << 24) & 0x1ffffff); - r[29] = (a[29] >> 1) + (sp_digit)((a[30] << 24) & 0x1ffffff); - r[30] = (a[30] >> 1) + (sp_digit)((a[31] << 24) & 0x1ffffff); - r[31] = (a[31] >> 1) + (sp_digit)((a[32] << 24) & 0x1ffffff); - r[32] = (a[32] >> 1) + (sp_digit)((a[33] << 24) & 0x1ffffff); - r[33] = (a[33] >> 1) + (sp_digit)((a[34] << 24) & 0x1ffffff); - r[34] = (a[34] >> 1) + (sp_digit)((a[35] << 24) & 0x1ffffff); - r[35] = (a[35] >> 1) + (sp_digit)((a[36] << 24) & 0x1ffffff); - r[36] = (a[36] >> 1) + (sp_digit)((a[37] << 24) & 0x1ffffff); - r[37] = (a[37] >> 1) + (sp_digit)((a[38] << 24) & 0x1ffffff); - r[38] = (a[38] >> 1) + (sp_digit)((a[39] << 24) & 0x1ffffff); - r[39] = (a[39] >> 1) + (sp_digit)((a[40] << 24) & 0x1ffffff); - r[40] = (a[40] >> 1) + (sp_digit)((a[41] << 24) & 0x1ffffff); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint32)a[1] << 24) & 0x1ffffff); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint32)a[2] << 24) & 0x1ffffff); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint32)a[3] << 24) & 0x1ffffff); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint32)a[4] << 24) & 0x1ffffff); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint32)a[5] << 24) & 0x1ffffff); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint32)a[6] << 24) & 0x1ffffff); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint32)a[7] << 24) & 0x1ffffff); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint32)a[8] << 24) & 0x1ffffff); + r[8] = (a[8] >> 1) + (sp_digit)(((sp_uint32)a[9] << 24) & 0x1ffffff); + r[9] = (a[9] >> 1) + (sp_digit)(((sp_uint32)a[10] << 24) & 0x1ffffff); + r[10] = (a[10] >> 1) + (sp_digit)(((sp_uint32)a[11] << 24) & 0x1ffffff); + r[11] = (a[11] >> 1) + (sp_digit)(((sp_uint32)a[12] << 24) & 0x1ffffff); + r[12] = (a[12] >> 1) + (sp_digit)(((sp_uint32)a[13] << 24) & 0x1ffffff); + r[13] = (a[13] >> 1) + (sp_digit)(((sp_uint32)a[14] << 24) & 0x1ffffff); + r[14] = (a[14] >> 1) + (sp_digit)(((sp_uint32)a[15] << 24) & 0x1ffffff); + r[15] = (a[15] >> 1) + (sp_digit)(((sp_uint32)a[16] << 24) & 0x1ffffff); + r[16] = (a[16] >> 1) + (sp_digit)(((sp_uint32)a[17] << 24) & 0x1ffffff); + r[17] = (a[17] >> 1) + (sp_digit)(((sp_uint32)a[18] << 24) & 0x1ffffff); + r[18] = (a[18] >> 1) + (sp_digit)(((sp_uint32)a[19] << 24) & 0x1ffffff); + r[19] = (a[19] >> 1) + (sp_digit)(((sp_uint32)a[20] << 24) & 0x1ffffff); + r[20] = (a[20] >> 1) + (sp_digit)(((sp_uint32)a[21] << 24) & 0x1ffffff); + r[21] = (a[21] >> 1) + (sp_digit)(((sp_uint32)a[22] << 24) & 0x1ffffff); + r[22] = (a[22] >> 1) + (sp_digit)(((sp_uint32)a[23] << 24) & 0x1ffffff); + r[23] = (a[23] >> 1) + (sp_digit)(((sp_uint32)a[24] << 24) & 0x1ffffff); + r[24] = (a[24] >> 1) + (sp_digit)(((sp_uint32)a[25] << 24) & 0x1ffffff); + r[25] = (a[25] >> 1) + (sp_digit)(((sp_uint32)a[26] << 24) & 0x1ffffff); + r[26] = (a[26] >> 1) + (sp_digit)(((sp_uint32)a[27] << 24) & 0x1ffffff); + r[27] = (a[27] >> 1) + (sp_digit)(((sp_uint32)a[28] << 24) & 0x1ffffff); + r[28] = (a[28] >> 1) + (sp_digit)(((sp_uint32)a[29] << 24) & 0x1ffffff); + r[29] = (a[29] >> 1) + (sp_digit)(((sp_uint32)a[30] << 24) & 0x1ffffff); + r[30] = (a[30] >> 1) + (sp_digit)(((sp_uint32)a[31] << 24) & 0x1ffffff); + r[31] = (a[31] >> 1) + (sp_digit)(((sp_uint32)a[32] << 24) & 0x1ffffff); + r[32] = (a[32] >> 1) + (sp_digit)(((sp_uint32)a[33] << 24) & 0x1ffffff); + r[33] = (a[33] >> 1) + (sp_digit)(((sp_uint32)a[34] << 24) & 0x1ffffff); + r[34] = (a[34] >> 1) + (sp_digit)(((sp_uint32)a[35] << 24) & 0x1ffffff); + r[35] = (a[35] >> 1) + (sp_digit)(((sp_uint32)a[36] << 24) & 0x1ffffff); + r[36] = (a[36] >> 1) + (sp_digit)(((sp_uint32)a[37] << 24) & 0x1ffffff); + r[37] = (a[37] >> 1) + (sp_digit)(((sp_uint32)a[38] << 24) & 0x1ffffff); + r[38] = (a[38] >> 1) + (sp_digit)(((sp_uint32)a[39] << 24) & 0x1ffffff); + r[39] = (a[39] >> 1) + (sp_digit)(((sp_uint32)a[40] << 24) & 0x1ffffff); + r[40] = (a[40] >> 1) + (sp_digit)(((sp_uint32)a[41] << 24) & 0x1ffffff); #endif r[41] = a[41] >> 1; } @@ -44737,7 +44748,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, if (err == MP_OKAY) { i = 40; c = 24; - n = k[i--] << (25 - c); + n = (sp_uint32)k[i--] << (25 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -44748,7 +44759,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, } y = (n >> 24) & 1; - n <<= 1; + n = (sp_uint32)n << 1; sp_1024_proj_point_add_42(&t[y^1], &t[0], &t[1], tmp); @@ -44807,7 +44818,7 @@ static int sp_1024_ecc_mulmod_42_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, XMEMSET(ctx->t, 0, sizeof(sp_point_1024) * 3); ctx->i = 40; ctx->c = 24; - ctx->n = k[ctx->i--] << (25 - ctx->c); + ctx->n = (sp_uint32)k[ctx->i--] << (25 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -44837,7 +44848,7 @@ static int sp_1024_ecc_mulmod_42_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, ctx->c = 25; } ctx->y = (ctx->n >> 24) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint32)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -45314,7 +45325,7 @@ static void sp_1024_ecc_recode_7_42(const sp_digit* k, ecc_recode_1024* v) } else if (++j < 42) { n = k[j]; - y |= (word8)((n << (25 - o)) & 0x7f); + y |= (word8)(((sp_uint32)n << (25 - o)) & 0x7f); o -= 18; n >>= o; } @@ -53427,7 +53438,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint32)a[i]) << s); if (s >= 17U) { r[j] &= 0x1ffffff; s = 25U - s; diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index ae32ae2ce7..b0dd93cbd9 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -51,6 +51,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -175,7 +186,7 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 53U) { r[j] &= 0x1fffffffffffffffL; s = 61U - s; @@ -221,7 +232,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x1fffffffffffffffL; s = 61U - s; if (j + 1 >= size) { @@ -256,7 +267,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 61) { r[j] &= 0x1fffffffffffffffL; if (j + 1 >= size) { @@ -305,7 +316,7 @@ static void sp_2048_to_bin_34(sp_digit* r, byte* a) for (i=0; i<34 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -481,10 +492,10 @@ SP_NOINLINE static void sp_2048_sqr_34(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -493,7 +504,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 61) - x; + *rho = (sp_digit)(((sp_uint64)1 << 61) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -892,7 +903,7 @@ SP_NOINLINE static void sp_2048_rshift_17(sp_digit* r, const sp_digit* a, int i; for (i=0; i<16; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (61 - n))) & 0x1fffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (61 - n))) & 0x1fffffffffffffffL); } r[16] = a[16] >> n; } @@ -932,7 +943,7 @@ static WC_INLINE sp_digit sp_2048_div_word_17(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 59; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 60) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -1124,9 +1135,9 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 61; - c = bits % 61; - n = e[i--] << (61 - c); + i = (bits - 1) / 61; + c = ((bits - 1) % 61) + 1; + n = (sp_uint64)e[i--] << (61 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -1138,7 +1149,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 60) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_17(t[y^1], t[0], t[1], m, mp); @@ -1200,9 +1211,9 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 61; - c = bits % 61; - n = e[i--] << (61 - c); + i = (bits - 1) / 61; + c = ((bits - 1) % 61) + 1; + n = (sp_uint64)e[i--] << (61 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -1214,7 +1225,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 60) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_17(t[y^1], t[0], t[1], m, mp); @@ -1315,38 +1326,38 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 61; } if (i < 17) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (3 - c); + n |= (sp_uint64)e[i--] << (3 - c); c += 61; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 34); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 56; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 61 - c; } @@ -1656,7 +1667,7 @@ SP_NOINLINE static void sp_2048_rshift_34(sp_digit* r, const sp_digit* a, int i; for (i=0; i<33; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (61 - n))) & 0x1fffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (61 - n))) & 0x1fffffffffffffffL); } r[33] = a[33] >> n; } @@ -1696,7 +1707,7 @@ static WC_INLINE sp_digit sp_2048_div_word_34(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 59; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 60) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -1889,9 +1900,9 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 61; - c = bits % 61; - n = e[i--] << (61 - c); + i = (bits - 1) / 61; + c = ((bits - 1) % 61) + 1; + n = (sp_uint64)e[i--] << (61 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -1903,7 +1914,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 60) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_34(t[y^1], t[0], t[1], m, mp); @@ -1965,9 +1976,9 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 61; - c = bits % 61; - n = e[i--] << (61 - c); + i = (bits - 1) / 61; + c = ((bits - 1) % 61) + 1; + n = (sp_uint64)e[i--] << (61 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -1979,7 +1990,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 60) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_34(t[y^1], t[0], t[1], m, mp); @@ -2064,38 +2075,38 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 61; } if (i < 34) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (3 - c); + n |= (sp_uint64)e[i--] << (3 - c); c += 61; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 68); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 57; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 61 - c; } @@ -2191,10 +2202,10 @@ static int sp_2048_mod_exp_34_nb(sp_2048_mod_exp_34_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 61 + 1 keeps the shift in [1, 61]. */ ctx->i = (ctx->bits - 1) / 61; ctx->c = ((ctx->bits - 1) % 61) + 1; - ctx->n = e[ctx->i--] << (61 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (61 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -2207,7 +2218,7 @@ static int sp_2048_mod_exp_34_nb(sp_2048_mod_exp_34_ctx* ctx, ctx->c = 61; } ctx->y = (byte)((ctx->n >> 60) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -2978,7 +2989,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 34; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -3003,7 +3014,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 34; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 61 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -3219,9 +3230,9 @@ SP_NOINLINE static void sp_2048_lshift_34(sp_digit* r, const sp_digit* a, r[34] = a[33] >> (61 - n); for (i=33; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (61 - n))) & 0x1fffffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (61 - n))) & 0x1fffffffffffffffL); } - r[0] = (sp_digit)((a[0] << n) & 0x1fffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x1fffffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -3267,38 +3278,38 @@ static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const c = 61; } if (i < 34) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (3 - c); + n |= (sp_uint64)e[i--] << (3 - c); c += 61; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_2048_lshift_34(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 56; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 3; + n = (sp_uint64)e[i--] << 3; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 61 - c; } @@ -3626,7 +3637,7 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 49U) { r[j] &= 0x1ffffffffffffffL; s = 57U - s; @@ -3672,7 +3683,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x1ffffffffffffffL; s = 57U - s; if (j + 1 >= size) { @@ -3707,7 +3718,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 57) { r[j] &= 0x1ffffffffffffffL; if (j + 1 >= size) { @@ -3756,7 +3767,7 @@ static void sp_2048_to_bin_36(sp_digit* r, byte* a) for (i=0; i<36 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -4245,10 +4256,10 @@ SP_NOINLINE static void sp_2048_sqr_36(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -4257,7 +4268,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1ffffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 57) - x; + *rho = (sp_digit)(((sp_uint64)1 << 57) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -4591,16 +4602,16 @@ SP_NOINLINE static void sp_2048_rshift_18(sp_digit* r, const sp_digit* a, int i; for (i=0; i<16; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (57 - n)) & 0x1ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (57 - n)) & 0x1ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (57 - n)) & 0x1ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (57 - n)) & 0x1ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (57 - n)) & 0x1ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (57 - n)) & 0x1ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (57 - n)) & 0x1ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (57 - n)) & 0x1ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (57 - n)) & 0x1ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (57 - n)) & 0x1ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (57 - n)) & 0x1ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (57 - n)) & 0x1ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (57 - n)) & 0x1ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (57 - n)) & 0x1ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (57 - n)) & 0x1ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (57 - n)) & 0x1ffffffffffffffL); } - r[16] = (a[16] >> n) | (sp_digit)((a[17] << (57 - n)) & 0x1ffffffffffffffL); + r[16] = (a[16] >> n) | (sp_digit)(((sp_uint64)a[17] << (57 - n)) & 0x1ffffffffffffffL); r[17] = a[17] >> n; } @@ -4639,7 +4650,7 @@ static WC_INLINE sp_digit sp_2048_div_word_18(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 55; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 56) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -4831,9 +4842,9 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -4845,7 +4856,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_18(t[y^1], t[0], t[1], m, mp); @@ -4907,9 +4918,9 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -4921,7 +4932,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_18(t[y^1], t[0], t[1], m, mp); @@ -5022,38 +5033,38 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 57; } if (i < 18) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 36); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 52; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -5226,30 +5237,30 @@ static void sp_2048_mont_shift_36(sp_digit* r, const sp_digit* a) s = a[36]; n = a[35] >> 53; for (i = 0; i < 32; i += 8) { - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+0] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+0] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+37] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+1] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+1] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+38] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+2] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+2] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+39] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+3] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+3] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+40] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+4] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+4] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+41] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+5] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+5] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+42] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+6] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+6] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+43] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[i+7] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[i+7] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+44] + (s >> 57); } - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[32] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[32] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[69] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[33] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[33] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[70] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 4); r[34] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 4); r[34] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[71] + (s >> 57); - n += s << 4; r[35] = n; + n += (sp_uint64)s << 4; r[35] = n; XMEMSET(&r[36], 0, sizeof(*r) * 36U); } @@ -5414,18 +5425,18 @@ SP_NOINLINE static void sp_2048_rshift_36(sp_digit* r, const sp_digit* a, int i; for (i=0; i<32; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (57 - n)) & 0x1ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (57 - n)) & 0x1ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (57 - n)) & 0x1ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (57 - n)) & 0x1ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (57 - n)) & 0x1ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (57 - n)) & 0x1ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (57 - n)) & 0x1ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (57 - n)) & 0x1ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (57 - n)) & 0x1ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (57 - n)) & 0x1ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (57 - n)) & 0x1ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (57 - n)) & 0x1ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (57 - n)) & 0x1ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (57 - n)) & 0x1ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (57 - n)) & 0x1ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (57 - n)) & 0x1ffffffffffffffL); } - r[32] = (a[32] >> n) | (sp_digit)((a[33] << (57 - n)) & 0x1ffffffffffffffL); - r[33] = (a[33] >> n) | (sp_digit)((a[34] << (57 - n)) & 0x1ffffffffffffffL); - r[34] = (a[34] >> n) | (sp_digit)((a[35] << (57 - n)) & 0x1ffffffffffffffL); + r[32] = (a[32] >> n) | (sp_digit)(((sp_uint64)a[33] << (57 - n)) & 0x1ffffffffffffffL); + r[33] = (a[33] >> n) | (sp_digit)(((sp_uint64)a[34] << (57 - n)) & 0x1ffffffffffffffL); + r[34] = (a[34] >> n) | (sp_digit)(((sp_uint64)a[35] << (57 - n)) & 0x1ffffffffffffffL); r[35] = a[35] >> n; } @@ -5464,7 +5475,7 @@ static WC_INLINE sp_digit sp_2048_div_word_36(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 55; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 56) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -5659,9 +5670,9 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -5673,7 +5684,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp); @@ -5735,9 +5746,9 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -5749,7 +5760,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp); @@ -5834,38 +5845,38 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 57; } if (i < 36) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 72); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 53; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -5961,10 +5972,10 @@ static int sp_2048_mod_exp_36_nb(sp_2048_mod_exp_36_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 57 + 1 keeps the shift in [1, 57]. */ ctx->i = (ctx->bits - 1) / 57; ctx->c = ((ctx->bits - 1) % 57) + 1; - ctx->n = e[ctx->i--] << (57 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (57 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -5977,7 +5988,7 @@ static int sp_2048_mod_exp_36_nb(sp_2048_mod_exp_36_ctx* ctx, ctx->c = 57; } ctx->y = (byte)((ctx->n >> 56) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -6548,7 +6559,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 36; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -6573,7 +6584,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 36; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 57 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -6774,7 +6785,7 @@ SP_NOINLINE static void sp_2048_lshift_36(sp_digit* r, const sp_digit* a, r[2] = (sp_digit)(((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL); s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL); - r[0] = (sp_digit)((a[0] << n) & 0x1ffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x1ffffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -6820,38 +6831,38 @@ static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const c = 57; } if (i < 36) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_2048_lshift_36(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 52; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -7081,7 +7092,7 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 52U) { r[j] &= 0xfffffffffffffffL; s = 60U - s; @@ -7127,7 +7138,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xfffffffffffffffL; s = 60U - s; if (j + 1 >= size) { @@ -7162,7 +7173,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 60) { r[j] &= 0xfffffffffffffffL; if (j + 1 >= size) { @@ -7211,7 +7222,7 @@ static void sp_3072_to_bin_52(sp_digit* r, byte* a) for (i=0; i<52 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -7348,10 +7359,10 @@ SP_NOINLINE static void sp_3072_sqr_52(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -7360,7 +7371,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0xfffffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 60) - x; + *rho = (sp_digit)(((sp_uint64)1 << 60) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -7723,7 +7734,7 @@ SP_NOINLINE static void sp_3072_rshift_26(sp_digit* r, const sp_digit* a, int i; for (i=0; i<25; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (60 - n))) & 0xfffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (60 - n))) & 0xfffffffffffffffL); } r[25] = a[25] >> n; } @@ -7763,7 +7774,7 @@ static WC_INLINE sp_digit sp_3072_div_word_26(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 58; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 59) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -7955,9 +7966,9 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 60; - c = bits % 60; - n = e[i--] << (60 - c); + i = (bits - 1) / 60; + c = ((bits - 1) % 60) + 1; + n = (sp_uint64)e[i--] << (60 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -7969,7 +7980,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 59) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_26(t[y^1], t[0], t[1], m, mp); @@ -8031,9 +8042,9 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 60; - c = bits % 60; - n = e[i--] << (60 - c); + i = (bits - 1) / 60; + c = ((bits - 1) % 60) + 1; + n = (sp_uint64)e[i--] << (60 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -8045,7 +8056,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 59) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_26(t[y^1], t[0], t[1], m, mp); @@ -8146,38 +8157,38 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 60; } if (i < 26) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (4 - c); + n |= (sp_uint64)e[i--] << (4 - c); c += 60; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 52); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 55; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 60 - c; } @@ -8493,7 +8504,7 @@ SP_NOINLINE static void sp_3072_rshift_52(sp_digit* r, const sp_digit* a, int i; for (i=0; i<51; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (60 - n))) & 0xfffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (60 - n))) & 0xfffffffffffffffL); } r[51] = a[51] >> n; } @@ -8533,7 +8544,7 @@ static WC_INLINE sp_digit sp_3072_div_word_52(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 58; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 59) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -8726,9 +8737,9 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 60; - c = bits % 60; - n = e[i--] << (60 - c); + i = (bits - 1) / 60; + c = ((bits - 1) % 60) + 1; + n = (sp_uint64)e[i--] << (60 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -8740,7 +8751,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 59) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_52(t[y^1], t[0], t[1], m, mp); @@ -8802,9 +8813,9 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 60; - c = bits % 60; - n = e[i--] << (60 - c); + i = (bits - 1) / 60; + c = ((bits - 1) % 60) + 1; + n = (sp_uint64)e[i--] << (60 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -8816,7 +8827,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 59) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_52(t[y^1], t[0], t[1], m, mp); @@ -8901,38 +8912,38 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 60; } if (i < 52) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (4 - c); + n |= (sp_uint64)e[i--] << (4 - c); c += 60; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 104); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 56; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 60 - c; } @@ -9028,10 +9039,10 @@ static int sp_3072_mod_exp_52_nb(sp_3072_mod_exp_52_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 60 + 1 keeps the shift in [1, 60]. */ ctx->i = (ctx->bits - 1) / 60; ctx->c = ((ctx->bits - 1) % 60) + 1; - ctx->n = e[ctx->i--] << (60 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (60 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -9044,7 +9055,7 @@ static int sp_3072_mod_exp_52_nb(sp_3072_mod_exp_52_ctx* ctx, ctx->c = 60; } ctx->y = (byte)((ctx->n >> 59) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -9815,7 +9826,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 52; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -9840,7 +9851,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 52; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 60 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -10056,9 +10067,9 @@ SP_NOINLINE static void sp_3072_lshift_52(sp_digit* r, const sp_digit* a, r[52] = a[51] >> (60 - n); for (i=51; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (60 - n))) & 0xfffffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (60 - n))) & 0xfffffffffffffffL); } - r[0] = (sp_digit)((a[0] << n) & 0xfffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0xfffffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -10104,38 +10115,38 @@ static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const c = 60; } if (i < 52) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (4 - c); + n |= (sp_uint64)e[i--] << (4 - c); c += 60; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_3072_lshift_52(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 55; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 4; + n = (sp_uint64)e[i--] << 4; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 60 - c; } @@ -10463,7 +10474,7 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 49U) { r[j] &= 0x1ffffffffffffffL; s = 57U - s; @@ -10509,7 +10520,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x1ffffffffffffffL; s = 57U - s; if (j + 1 >= size) { @@ -10544,7 +10555,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 57) { r[j] &= 0x1ffffffffffffffL; if (j + 1 >= size) { @@ -10593,7 +10604,7 @@ static void sp_3072_to_bin_54(sp_digit* r, byte* a) for (i=0; i<54 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -11165,10 +11176,10 @@ SP_NOINLINE static void sp_3072_sqr_54(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -11177,7 +11188,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1ffffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 57) - x; + *rho = (sp_digit)(((sp_uint64)1 << 57) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -11396,28 +11407,28 @@ static void sp_3072_mont_shift_27(sp_digit* r, const sp_digit* a) s = a[27]; n = a[26] >> 54; for (i = 0; i < 24; i += 8) { - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+0] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+0] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+28] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+1] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+1] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+29] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+2] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+2] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+30] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+3] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+3] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+31] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+4] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+4] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+32] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+5] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+5] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+33] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+6] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+6] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+34] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[i+7] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[i+7] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[i+35] + (s >> 57); } - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[24] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[24] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[52] + (s >> 57); - n += (sp_digit)((s & 0x1ffffffffffffffL) << 3); r[25] = (sp_digit)(n & 0x1ffffffffffffffL); + n += (sp_digit)((sp_uint64)(s & 0x1ffffffffffffffL) << 3); r[25] = (sp_digit)(n & 0x1ffffffffffffffL); n >>= 57; s = a[53] + (s >> 57); - n += s << 3; r[26] = n; + n += (sp_uint64)s << 3; r[26] = n; XMEMSET(&r[27], 0, sizeof(*r) * 27U); } @@ -11565,17 +11576,17 @@ SP_NOINLINE static void sp_3072_rshift_27(sp_digit* r, const sp_digit* a, int i; for (i=0; i<24; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (57 - n)) & 0x1ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (57 - n)) & 0x1ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (57 - n)) & 0x1ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (57 - n)) & 0x1ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (57 - n)) & 0x1ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (57 - n)) & 0x1ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (57 - n)) & 0x1ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (57 - n)) & 0x1ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (57 - n)) & 0x1ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (57 - n)) & 0x1ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (57 - n)) & 0x1ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (57 - n)) & 0x1ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (57 - n)) & 0x1ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (57 - n)) & 0x1ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (57 - n)) & 0x1ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (57 - n)) & 0x1ffffffffffffffL); } - r[24] = (a[24] >> n) | (sp_digit)((a[25] << (57 - n)) & 0x1ffffffffffffffL); - r[25] = (a[25] >> n) | (sp_digit)((a[26] << (57 - n)) & 0x1ffffffffffffffL); + r[24] = (a[24] >> n) | (sp_digit)(((sp_uint64)a[25] << (57 - n)) & 0x1ffffffffffffffL); + r[25] = (a[25] >> n) | (sp_digit)(((sp_uint64)a[26] << (57 - n)) & 0x1ffffffffffffffL); r[26] = a[26] >> n; } @@ -11614,7 +11625,7 @@ static WC_INLINE sp_digit sp_3072_div_word_27(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 55; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 56) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -11806,9 +11817,9 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -11820,7 +11831,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_27(t[y^1], t[0], t[1], m, mp); @@ -11882,9 +11893,9 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -11896,7 +11907,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_27(t[y^1], t[0], t[1], m, mp); @@ -11997,38 +12008,38 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 57; } if (i < 27) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 54); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 52; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -12398,20 +12409,20 @@ SP_NOINLINE static void sp_3072_rshift_54(sp_digit* r, const sp_digit* a, int i; for (i=0; i<48; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (57 - n)) & 0x1ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (57 - n)) & 0x1ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (57 - n)) & 0x1ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (57 - n)) & 0x1ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (57 - n)) & 0x1ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (57 - n)) & 0x1ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (57 - n)) & 0x1ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (57 - n)) & 0x1ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (57 - n)) & 0x1ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (57 - n)) & 0x1ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (57 - n)) & 0x1ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (57 - n)) & 0x1ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (57 - n)) & 0x1ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (57 - n)) & 0x1ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (57 - n)) & 0x1ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (57 - n)) & 0x1ffffffffffffffL); } - r[48] = (a[48] >> n) | (sp_digit)((a[49] << (57 - n)) & 0x1ffffffffffffffL); - r[49] = (a[49] >> n) | (sp_digit)((a[50] << (57 - n)) & 0x1ffffffffffffffL); - r[50] = (a[50] >> n) | (sp_digit)((a[51] << (57 - n)) & 0x1ffffffffffffffL); - r[51] = (a[51] >> n) | (sp_digit)((a[52] << (57 - n)) & 0x1ffffffffffffffL); - r[52] = (a[52] >> n) | (sp_digit)((a[53] << (57 - n)) & 0x1ffffffffffffffL); + r[48] = (a[48] >> n) | (sp_digit)(((sp_uint64)a[49] << (57 - n)) & 0x1ffffffffffffffL); + r[49] = (a[49] >> n) | (sp_digit)(((sp_uint64)a[50] << (57 - n)) & 0x1ffffffffffffffL); + r[50] = (a[50] >> n) | (sp_digit)(((sp_uint64)a[51] << (57 - n)) & 0x1ffffffffffffffL); + r[51] = (a[51] >> n) | (sp_digit)(((sp_uint64)a[52] << (57 - n)) & 0x1ffffffffffffffL); + r[52] = (a[52] >> n) | (sp_digit)(((sp_uint64)a[53] << (57 - n)) & 0x1ffffffffffffffL); r[53] = a[53] >> n; } @@ -12450,7 +12461,7 @@ static WC_INLINE sp_digit sp_3072_div_word_54(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 55; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 56) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -12645,9 +12656,9 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -12659,7 +12670,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_54(t[y^1], t[0], t[1], m, mp); @@ -12721,9 +12732,9 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 57; - c = bits % 57; - n = e[i--] << (57 - c); + i = (bits - 1) / 57; + c = ((bits - 1) % 57) + 1; + n = (sp_uint64)e[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -12735,7 +12746,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 56) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_3072_mont_mul_54(t[y^1], t[0], t[1], m, mp); @@ -12820,38 +12831,38 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 57; } if (i < 54) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 108); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 53; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -12947,10 +12958,10 @@ static int sp_3072_mod_exp_54_nb(sp_3072_mod_exp_54_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 57 + 1 keeps the shift in [1, 57]. */ ctx->i = (ctx->bits - 1) / 57; ctx->c = ((ctx->bits - 1) % 57) + 1; - ctx->n = e[ctx->i--] << (57 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (57 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -12963,7 +12974,7 @@ static int sp_3072_mod_exp_54_nb(sp_3072_mod_exp_54_ctx* ctx, ctx->c = 57; } ctx->y = (byte)((ctx->n >> 56) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -13534,7 +13545,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 54; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -13559,7 +13570,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 54; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 57 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -13796,7 +13807,7 @@ SP_NOINLINE static void sp_3072_lshift_54(sp_digit* r, const sp_digit* a, r[2] = (sp_digit)(((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL); s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL); - r[0] = (sp_digit)((a[0] << n) & 0x1ffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x1ffffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -13842,38 +13853,38 @@ static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const c = 57; } if (i < 54) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (7 - c); + n |= (sp_uint64)e[i--] << (7 - c); c += 57; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_3072_lshift_54(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 52; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 7; + n = (sp_uint64)e[i--] << 7; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 57 - c; } @@ -14103,7 +14114,7 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 51U) { r[j] &= 0x7ffffffffffffffL; s = 59U - s; @@ -14149,7 +14160,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x7ffffffffffffffL; s = 59U - s; if (j + 1 >= size) { @@ -14184,7 +14195,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 59) { r[j] &= 0x7ffffffffffffffL; if (j + 1 >= size) { @@ -14233,7 +14244,7 @@ static void sp_4096_to_bin_70(sp_digit* r, byte* a) for (i=0; i<70 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -14372,10 +14383,10 @@ SP_NOINLINE static void sp_4096_sqr_70(sp_digit* r, const sp_digit* a) */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -14384,7 +14395,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x7ffffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 59) - x; + *rho = (sp_digit)(((sp_uint64)1 << 59) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -14751,7 +14762,7 @@ SP_NOINLINE static void sp_4096_rshift_35(sp_digit* r, const sp_digit* a, int i; for (i=0; i<34; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (59 - n))) & 0x7ffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (59 - n))) & 0x7ffffffffffffffL); } r[34] = a[34] >> n; } @@ -14791,7 +14802,7 @@ static WC_INLINE sp_digit sp_4096_div_word_35(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 57; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 58) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -14983,9 +14994,9 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 59; - c = bits % 59; - n = e[i--] << (59 - c); + i = (bits - 1) / 59; + c = ((bits - 1) % 59) + 1; + n = (sp_uint64)e[i--] << (59 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -14997,7 +15008,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 58) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_35(t[y^1], t[0], t[1], m, mp); @@ -15059,9 +15070,9 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 59; - c = bits % 59; - n = e[i--] << (59 - c); + i = (bits - 1) / 59; + c = ((bits - 1) % 59) + 1; + n = (sp_uint64)e[i--] << (59 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -15073,7 +15084,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 58) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_35(t[y^1], t[0], t[1], m, mp); @@ -15174,38 +15185,38 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 59; } if (i < 35) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (5 - c); + n |= (sp_uint64)e[i--] << (5 - c); c += 59; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 70); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 54; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 59 - c; } @@ -15516,7 +15527,7 @@ SP_NOINLINE static void sp_4096_rshift_70(sp_digit* r, const sp_digit* a, int i; for (i=0; i<69; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (59 - n))) & 0x7ffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (59 - n))) & 0x7ffffffffffffffL); } r[69] = a[69] >> n; } @@ -15556,7 +15567,7 @@ static WC_INLINE sp_digit sp_4096_div_word_70(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 57; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 58) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -15749,9 +15760,9 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 59; - c = bits % 59; - n = e[i--] << (59 - c); + i = (bits - 1) / 59; + c = ((bits - 1) % 59) + 1; + n = (sp_uint64)e[i--] << (59 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -15763,7 +15774,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 58) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_70(t[y^1], t[0], t[1], m, mp); @@ -15825,9 +15836,9 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 59; - c = bits % 59; - n = e[i--] << (59 - c); + i = (bits - 1) / 59; + c = ((bits - 1) % 59) + 1; + n = (sp_uint64)e[i--] << (59 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -15839,7 +15850,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 58) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_70(t[y^1], t[0], t[1], m, mp); @@ -15924,38 +15935,38 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 59; } if (i < 70) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (5 - c); + n |= (sp_uint64)e[i--] << (5 - c); c += 59; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 140); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 55; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 59 - c; } @@ -16051,10 +16062,10 @@ static int sp_4096_mod_exp_70_nb(sp_4096_mod_exp_70_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 59 + 1 keeps the shift in [1, 59]. */ ctx->i = (ctx->bits - 1) / 59; ctx->c = ((ctx->bits - 1) % 59) + 1; - ctx->n = e[ctx->i--] << (59 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (59 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -16067,7 +16078,7 @@ static int sp_4096_mod_exp_70_nb(sp_4096_mod_exp_70_ctx* ctx, ctx->c = 59; } ctx->y = (byte)((ctx->n >> 58) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -16838,7 +16849,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 70; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -16863,7 +16874,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 70; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 59 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -17079,9 +17090,9 @@ SP_NOINLINE static void sp_4096_lshift_70(sp_digit* r, const sp_digit* a, r[70] = a[69] >> (59 - n); for (i=69; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (59 - n))) & 0x7ffffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (59 - n))) & 0x7ffffffffffffffL); } - r[0] = (sp_digit)((a[0] << n) & 0x7ffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x7ffffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -17127,38 +17138,38 @@ static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const c = 59; } if (i < 70) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (5 - c); + n |= (sp_uint64)e[i--] << (5 - c); c += 59; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_4096_lshift_70(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 54; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 5; + n = (sp_uint64)e[i--] << 5; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 59 - c; } @@ -17385,7 +17396,7 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 45U) { r[j] &= 0x1fffffffffffffL; s = 53U - s; @@ -17431,7 +17442,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x1fffffffffffffL; s = 53U - s; if (j + 1 >= size) { @@ -17466,7 +17477,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 53) { r[j] &= 0x1fffffffffffffL; if (j + 1 >= size) { @@ -17515,7 +17526,7 @@ static void sp_4096_to_bin_78(sp_digit* r, byte* a) for (i=0; i<78 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -18255,10 +18266,10 @@ SP_NOINLINE static void sp_4096_sqr_78(sp_digit* r, const sp_digit* a) */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -18267,7 +18278,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffffffffffL; /* rho = -1/m mod b */ - *rho = ((sp_digit)1 << 53) - x; + *rho = (sp_digit)(((sp_uint64)1 << 53) - (sp_digit)x); } /* Multiply a by scalar b into r. (r = a * b) @@ -18684,21 +18695,21 @@ SP_NOINLINE static void sp_4096_rshift_39(sp_digit* r, const sp_digit* a, int i; for (i=0; i<32; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (53 - n)) & 0x1fffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (53 - n)) & 0x1fffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (53 - n)) & 0x1fffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (53 - n)) & 0x1fffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (53 - n)) & 0x1fffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (53 - n)) & 0x1fffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (53 - n)) & 0x1fffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (53 - n)) & 0x1fffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (53 - n)) & 0x1fffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (53 - n)) & 0x1fffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (53 - n)) & 0x1fffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (53 - n)) & 0x1fffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (53 - n)) & 0x1fffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (53 - n)) & 0x1fffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (53 - n)) & 0x1fffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (53 - n)) & 0x1fffffffffffffL); } - r[32] = (a[32] >> n) | (sp_digit)((a[33] << (53 - n)) & 0x1fffffffffffffL); - r[33] = (a[33] >> n) | (sp_digit)((a[34] << (53 - n)) & 0x1fffffffffffffL); - r[34] = (a[34] >> n) | (sp_digit)((a[35] << (53 - n)) & 0x1fffffffffffffL); - r[35] = (a[35] >> n) | (sp_digit)((a[36] << (53 - n)) & 0x1fffffffffffffL); - r[36] = (a[36] >> n) | (sp_digit)((a[37] << (53 - n)) & 0x1fffffffffffffL); - r[37] = (a[37] >> n) | (sp_digit)((a[38] << (53 - n)) & 0x1fffffffffffffL); + r[32] = (a[32] >> n) | (sp_digit)(((sp_uint64)a[33] << (53 - n)) & 0x1fffffffffffffL); + r[33] = (a[33] >> n) | (sp_digit)(((sp_uint64)a[34] << (53 - n)) & 0x1fffffffffffffL); + r[34] = (a[34] >> n) | (sp_digit)(((sp_uint64)a[35] << (53 - n)) & 0x1fffffffffffffL); + r[35] = (a[35] >> n) | (sp_digit)(((sp_uint64)a[36] << (53 - n)) & 0x1fffffffffffffL); + r[36] = (a[36] >> n) | (sp_digit)(((sp_uint64)a[37] << (53 - n)) & 0x1fffffffffffffL); + r[37] = (a[37] >> n) | (sp_digit)(((sp_uint64)a[38] << (53 - n)) & 0x1fffffffffffffL); r[38] = a[38] >> n; } @@ -18737,7 +18748,7 @@ static WC_INLINE sp_digit sp_4096_div_word_39(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 51; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 52) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -18929,9 +18940,9 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 53; - c = bits % 53; - n = e[i--] << (53 - c); + i = (bits - 1) / 53; + c = ((bits - 1) % 53) + 1; + n = (sp_uint64)e[i--] << (53 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -18943,7 +18954,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 52) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_39(t[y^1], t[0], t[1], m, mp); @@ -19005,9 +19016,9 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 53; - c = bits % 53; - n = e[i--] << (53 - c); + i = (bits - 1) / 53; + c = ((bits - 1) % 53) + 1; + n = (sp_uint64)e[i--] << (53 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -19019,7 +19030,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 52) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_39(t[y^1], t[0], t[1], m, mp); @@ -19120,38 +19131,38 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 53; } if (i < 39) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (11 - c); + n |= (sp_uint64)e[i--] << (11 - c); c += 53; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; XMEMCPY(rt, t[y], sizeof(sp_digit) * 78); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 48; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 53 - c; } @@ -19522,20 +19533,20 @@ SP_NOINLINE static void sp_4096_rshift_78(sp_digit* r, const sp_digit* a, int i; for (i=0; i<72; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (53 - n)) & 0x1fffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (53 - n)) & 0x1fffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (53 - n)) & 0x1fffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (53 - n)) & 0x1fffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (53 - n)) & 0x1fffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (53 - n)) & 0x1fffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (53 - n)) & 0x1fffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (53 - n)) & 0x1fffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (53 - n)) & 0x1fffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (53 - n)) & 0x1fffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (53 - n)) & 0x1fffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (53 - n)) & 0x1fffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (53 - n)) & 0x1fffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (53 - n)) & 0x1fffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (53 - n)) & 0x1fffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (53 - n)) & 0x1fffffffffffffL); } - r[72] = (a[72] >> n) | (sp_digit)((a[73] << (53 - n)) & 0x1fffffffffffffL); - r[73] = (a[73] >> n) | (sp_digit)((a[74] << (53 - n)) & 0x1fffffffffffffL); - r[74] = (a[74] >> n) | (sp_digit)((a[75] << (53 - n)) & 0x1fffffffffffffL); - r[75] = (a[75] >> n) | (sp_digit)((a[76] << (53 - n)) & 0x1fffffffffffffL); - r[76] = (a[76] >> n) | (sp_digit)((a[77] << (53 - n)) & 0x1fffffffffffffL); + r[72] = (a[72] >> n) | (sp_digit)(((sp_uint64)a[73] << (53 - n)) & 0x1fffffffffffffL); + r[73] = (a[73] >> n) | (sp_digit)(((sp_uint64)a[74] << (53 - n)) & 0x1fffffffffffffL); + r[74] = (a[74] >> n) | (sp_digit)(((sp_uint64)a[75] << (53 - n)) & 0x1fffffffffffffL); + r[75] = (a[75] >> n) | (sp_digit)(((sp_uint64)a[76] << (53 - n)) & 0x1fffffffffffffL); + r[76] = (a[76] >> n) | (sp_digit)(((sp_uint64)a[77] << (53 - n)) & 0x1fffffffffffffL); r[77] = a[77] >> n; } @@ -19574,7 +19585,7 @@ static WC_INLINE sp_digit sp_4096_div_word_78(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 51; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 52) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -19769,9 +19780,9 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 53; - c = bits % 53; - n = e[i--] << (53 - c); + i = (bits - 1) / 53; + c = ((bits - 1) % 53) + 1; + n = (sp_uint64)e[i--] << (53 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -19783,7 +19794,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 52) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_78(t[y^1], t[0], t[1], m, mp); @@ -19845,9 +19856,9 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, } if (err == MP_OKAY) { - i = bits / 53; - c = bits % 53; - n = e[i--] << (53 - c); + i = (bits - 1) / 53; + c = ((bits - 1) % 53) + 1; + n = (sp_uint64)e[i--] << (53 - c); for (; ; c--) { if (c == 0) { if (i == -1) { @@ -19859,7 +19870,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, } y = (int)((n >> 52) & 1); - n <<= 1; + n = (sp_uint64)n << 1; sp_4096_mont_mul_78(t[y^1], t[0], t[1], m, mp); @@ -19944,38 +19955,38 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, c = 53; } if (i < 78) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 4) { - n |= e[i--] << (11 - c); + n |= (sp_uint64)e[i--] << (11 - c); c += 53; } y = (int)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; XMEMCPY(rt, t[y], sizeof(sp_digit) * 156); while ((i >= 0) || (c >= 4)) { if (c >= 4) { y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c -= 4; } else if (c == 0) { - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; y = (byte)((n >> 60) & 0xf); - n <<= 4; + n = (sp_uint64)n << 4; c = 49; } else { y = (byte)((n >> 60) & 0xf); - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; c = 4 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 53 - c; } @@ -20071,10 +20082,10 @@ static int sp_4096_mod_exp_78_nb(sp_4096_mod_exp_78_ctx* ctx, case 4: /* BIT_INIT: index the most-significant exponent limb without reading off the end when bits is an exact multiple of the limb width. (bits-1) keeps i within the populated range and - c = (bits-1) % @bits + 1 keeps the shift in [1, @bits]. */ + c = (bits-1) % 53 + 1 keeps the shift in [1, 53]. */ ctx->i = (ctx->bits - 1) / 53; ctx->c = ((ctx->bits - 1) % 53) + 1; - ctx->n = e[ctx->i--] << (53 - ctx->c); + ctx->n = (sp_uint64)e[ctx->i--] << (53 - ctx->c); ctx->state = 5; break; case 5: /* BIT_NEXT: refill on word boundary, peel one exponent bit */ @@ -20087,7 +20098,7 @@ static int sp_4096_mod_exp_78_nb(sp_4096_mod_exp_78_ctx* ctx, ctx->c = 53; } ctx->y = (byte)((ctx->n >> 52) & 1); - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; ctx->state = 6; break; case 6: /* MUL: t[y^1] = t[0] * t[1] in Montgomery form */ @@ -20658,7 +20669,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 78; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -20683,7 +20694,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 78; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 53 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -20968,7 +20979,7 @@ SP_NOINLINE static void sp_4096_lshift_78(sp_digit* r, const sp_digit* a, r[2] = (sp_digit)(((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL); s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL); - r[0] = (sp_digit)((a[0] << n) & 0x1fffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x1fffffffffffffL); } /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m) @@ -21014,38 +21025,38 @@ static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const c = 53; } if (i < 78) { - n = e[i--] << (64 - c); + n = (sp_uint64)e[i--] << (64 - c); } else { n = 0; i--; } if (c < 5) { - n |= e[i--] << (11 - c); + n |= (sp_uint64)e[i--] << (11 - c); c += 53; } y = (int)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; sp_4096_lshift_78(r, norm, (byte)y); while ((i >= 0) || (c >= 5)) { if (c >= 5) { y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c -= 5; } else if (c == 0) { - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; y = (byte)((n >> 59) & 0x1f); - n <<= 5; + n = (sp_uint64)n << 5; c = 48; } else { y = (byte)((n >> 59) & 0x1f); - n = e[i--] << 11; + n = (sp_uint64)e[i--] << 11; c = 5 - c; y |= (byte)((n >> (64 - c)) & ((1 << c) - 1)); - n <<= c; + n = (sp_uint64)n << c; c = 53 - c; } @@ -21513,7 +21524,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xfffffffffffffL; s = 52U - s; if (j + 1 >= size) { @@ -21548,7 +21559,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 52) { r[j] &= 0xfffffffffffffL; if (j + 1 >= size) { @@ -21614,7 +21625,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 5; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -21639,7 +21650,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 5; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 52 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -21886,9 +21897,9 @@ static void sp_256_mont_reduce_5(sp_digit* a, const sp_digit* m, sp_digit mp) /* Fifth word of modulus word */ t = am; t *= 0x0ffffffff0000L; - a[i + 1] += (sp_digit)((am << 44) & 0xfffffffffffffL); + a[i + 1] += (sp_digit)(((sp_uint64)am << 44) & 0xfffffffffffffL); a[i + 2] += am >> 8; - a[i + 3] += (sp_digit)((am << 36) & 0xfffffffffffffL); + a[i + 3] += (sp_digit)(((sp_uint64)am << 36) & 0xfffffffffffffL); a[i + 4] += (am >> 16) + (sp_digit)(t & 0xfffffffffffffL); a[i + 5] += t >> 52; @@ -21898,17 +21909,17 @@ static void sp_256_mont_reduce_5(sp_digit* a, const sp_digit* m, sp_digit mp) /* Fifth word of modulus word */ t = am; t *= 0x0ffffffff0000L; - a[4 + 1] += (sp_digit)((am << 44) & 0xfffffffffffffL); + a[4 + 1] += (sp_digit)(((sp_uint64)am << 44) & 0xfffffffffffffL); a[4 + 2] += am >> 8; - a[4 + 3] += (sp_digit)((am << 36) & 0xfffffffffffffL); + a[4 + 3] += (sp_digit)(((sp_uint64)am << 36) & 0xfffffffffffffL); a[4 + 4] += (am >> 16) + (sp_digit)(t & 0xfffffffffffffL); a[4 + 5] += t >> 52; - a[0] = (a[4] >> 48) + (sp_digit)((a[5] << 4) & 0xfffffffffffffL); - a[1] = (a[5] >> 48) + (sp_digit)((a[6] << 4) & 0xfffffffffffffL); - a[2] = (a[6] >> 48) + (sp_digit)((a[7] << 4) & 0xfffffffffffffL); - a[3] = (a[7] >> 48) + (sp_digit)((a[8] << 4) & 0xfffffffffffffL); - a[4] = (a[8] >> 48) + (a[9] << 4); + a[0] = (a[4] >> 48) + (sp_digit)(((sp_uint64)a[5] << 4) & 0xfffffffffffffL); + a[1] = (a[5] >> 48) + (sp_digit)(((sp_uint64)a[6] << 4) & 0xfffffffffffffL); + a[2] = (a[6] >> 48) + (sp_digit)(((sp_uint64)a[7] << 4) & 0xfffffffffffffL); + a[3] = (a[7] >> 48) + (sp_digit)(((sp_uint64)a[8] << 4) & 0xfffffffffffffL); + a[4] = (a[8] >> 48) + (sp_digit)((sp_uint64)a[9] << 4); a[1] += a[0] >> 52; a[0] &= 0xfffffffffffffL; a[2] += a[1] >> 52; a[1] &= 0xfffffffffffffL; @@ -22005,7 +22016,7 @@ static void sp_256_mont_inv_5(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 5); for (i=254; i>=0; i--) { sp_256_mont_sqr_5(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_256_mont_mul_5(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 5); @@ -22221,13 +22232,13 @@ SP_NOINLINE static void sp_256_rshift1_5(sp_digit* r, const sp_digit* a) int i; for (i=0; i<4; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 51) & 0xfffffffffffffL); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint64)a[i + 1] << 51) & 0xfffffffffffffL); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 51) & 0xfffffffffffffL); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 51) & 0xfffffffffffffL); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 51) & 0xfffffffffffffL); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 51) & 0xfffffffffffffL); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint64)a[1] << 51) & 0xfffffffffffffL); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint64)a[2] << 51) & 0xfffffffffffffL); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint64)a[3] << 51) & 0xfffffffffffffL); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint64)a[4] << 51) & 0xfffffffffffffL); #endif r[4] = a[4] >> 1; } @@ -22785,18 +22796,18 @@ static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* a32[0] = (sp_digit)(a[0]) & 0xffffffffL; a32[1] = (sp_digit)(a[0] >> 32U); - a32[1] |= (sp_digit)(a[1] << 20U); + a32[1] |= (sp_digit)((sp_uint64)a[1] << 20U); a32[1] &= 0xffffffffL; a32[2] = (sp_digit)(a[1] >> 12U) & 0xffffffffL; a32[3] = (sp_digit)(a[1] >> 44U); - a32[3] |= (sp_digit)(a[2] << 8U); + a32[3] |= (sp_digit)((sp_uint64)a[2] << 8U); a32[3] &= 0xffffffffL; a32[4] = (sp_digit)(a[2] >> 24U); - a32[4] |= (sp_digit)(a[3] << 28U); + a32[4] |= (sp_digit)((sp_uint64)a[3] << 28U); a32[4] &= 0xffffffffL; a32[5] = (sp_digit)(a[3] >> 4U) & 0xffffffffL; a32[6] = (sp_digit)(a[3] >> 36U); - a32[6] |= (sp_digit)(a[4] << 16U); + a32[6] |= (sp_digit)((sp_uint64)a[4] << 16U); a32[6] &= 0xffffffffL; a32[7] = (sp_digit)(a[4] >> 16U) & 0xffffffffL; @@ -22910,7 +22921,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, if (err == MP_OKAY) { i = 4; c = 48; - n = k[i--] << (52 - c); + n = (sp_uint64)k[i--] << (52 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -22921,7 +22932,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, } y = (n >> 51) & 1; - n <<= 1; + n = (sp_uint64)n << 1; sp_256_proj_point_add_5(&t[y^1], &t[0], &t[1], tmp); @@ -22980,7 +22991,7 @@ static int sp_256_ecc_mulmod_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, XMEMSET(ctx->t, 0, sizeof(sp_point_256) * 3); ctx->i = 4; ctx->c = 48; - ctx->n = k[ctx->i--] << (52 - ctx->c); + ctx->n = (sp_uint64)k[ctx->i--] << (52 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -23010,7 +23021,7 @@ static int sp_256_ecc_mulmod_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, ctx->c = 52; } ctx->y = (ctx->n >> 51) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -23405,7 +23416,7 @@ static void sp_256_ecc_recode_6_5(const sp_digit* k, ecc_recode_256* v) } else if (++j < 5) { n = k[j]; - y |= (word8)((n << (52 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (52 - o)) & 0x3f); o -= 46; n >>= o; } @@ -25615,7 +25626,7 @@ static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 44U) { r[j] &= 0xfffffffffffffL; s = 52U - s; @@ -25836,7 +25847,7 @@ static void sp_256_to_bin_5(sp_digit* r, byte* a) for (i=0; i<5 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -25960,23 +25971,23 @@ SP_NOINLINE static void sp_256_rshift_5(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<4; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (52 - n))) & 0xfffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (52 - n))) & 0xfffffffffffffL); } #else for (i=0; i<0; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (52 - n)) & 0xfffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (52 - n)) & 0xfffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (52 - n)) & 0xfffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (52 - n)) & 0xfffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (52 - n)) & 0xfffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (52 - n)) & 0xfffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (52 - n)) & 0xfffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (52 - n)) & 0xfffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (52 - n)) & 0xfffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (52 - n)) & 0xfffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (52 - n)) & 0xfffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (52 - n)) & 0xfffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (52 - n)) & 0xfffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (52 - n)) & 0xfffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (52 - n)) & 0xfffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (52 - n)) & 0xfffffffffffffL); } - r[0] = (a[0] >> n) | (sp_digit)((a[1] << (52 - n)) & 0xfffffffffffffL); - r[1] = (a[1] >> n) | (sp_digit)((a[2] << (52 - n)) & 0xfffffffffffffL); - r[2] = (a[2] >> n) | (sp_digit)((a[3] << (52 - n)) & 0xfffffffffffffL); - r[3] = (a[3] >> n) | (sp_digit)((a[4] << (52 - n)) & 0xfffffffffffffL); + r[0] = (a[0] >> n) | (sp_digit)(((sp_uint64)a[1] << (52 - n)) & 0xfffffffffffffL); + r[1] = (a[1] >> n) | (sp_digit)(((sp_uint64)a[2] << (52 - n)) & 0xfffffffffffffL); + r[2] = (a[2] >> n) | (sp_digit)(((sp_uint64)a[3] << (52 - n)) & 0xfffffffffffffL); + r[3] = (a[3] >> n) | (sp_digit)(((sp_uint64)a[4] << (52 - n)) & 0xfffffffffffffL); #endif /* WOLFSSL_SP_SMALL */ r[4] = a[4] >> n; } @@ -26027,7 +26038,7 @@ SP_NOINLINE static void sp_256_lshift_10(sp_digit* r, const sp_digit* a, r[10] = a[9] >> (52 - n); for (i=9; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (52 - n))) & 0xfffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (52 - n))) & 0xfffffffffffffL); } #else sp_int_digit s; @@ -26054,7 +26065,7 @@ SP_NOINLINE static void sp_256_lshift_10(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0xfffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0xfffffffffffffL); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -27960,7 +27971,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x7fffffffffffffL; s = 55U - s; if (j + 1 >= size) { @@ -27995,7 +28006,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 55) { r[j] &= 0x7fffffffffffffL; if (j + 1 >= size) { @@ -28061,7 +28072,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 7; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -28086,7 +28097,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 7; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 55 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -28346,31 +28357,31 @@ static void sp_384_mont_reduce_7(sp_digit* a, const sp_digit* m, sp_digit mp) (void)mp; for (i = 0; i < 6; i++) { - am = (sp_digit)((a[i] * 0x100000001) & 0x7fffffffffffffL); - a[i + 0] += (sp_digit)((am << 32) & 0x7fffffffffffffL); - a[i + 1] += (am >> 23) - (sp_digit)((am << 41) & 0x7fffffffffffffL); - a[i + 2] += -(am >> 14) - ((sp_digit)(am << 18) & 0x7fffffffffffffL); + am = (sp_digit)((((sp_uint64)a[i]) * 0x100000001) & 0x7fffffffffffffL); + a[i + 0] += (sp_digit)(((sp_uint64)am << 32) & 0x7fffffffffffffL); + a[i + 1] += (am >> 23) - (sp_digit)(((sp_uint64)am << 41) & 0x7fffffffffffffL); + a[i + 2] += -(am >> 14) - (sp_digit)(((sp_uint64)am << 18) & 0x7fffffffffffffL); a[i + 3] += -(am >> 37); - a[i + 6] += ((sp_digit)(am << 54) & 0x7fffffffffffffL); + a[i + 6] += (sp_digit)(((sp_uint64)am << 54) & 0x7fffffffffffffL); a[i + 7] += am >> 1; a[i + 1] += a[i] >> 55; } - am = (sp_digit)((a[6] * 0x100000001) & 0x3fffffffffffff); - a[6 + 0] += (sp_digit)((am << 32) & 0x7fffffffffffffL); - a[6 + 1] += (am >> 23) - (sp_digit)((am << 41) & 0x7fffffffffffffL); - a[6 + 2] += -(am >> 14) - (sp_digit)((am << 18) & 0x7fffffffffffffL); + am = (sp_digit)((((sp_uint64)a[6]) * 0x100000001) & 0x3fffffffffffff); + a[6 + 0] += (sp_digit)(((sp_uint64)am << 32) & 0x7fffffffffffffL); + a[6 + 1] += (am >> 23) - (sp_digit)(((sp_uint64)am << 41) & 0x7fffffffffffffL); + a[6 + 2] += -(am >> 14) - (sp_digit)(((sp_uint64)am << 18) & 0x7fffffffffffffL); a[6 + 3] += -(am >> 37); - a[6 + 6] += (sp_digit)((am << 54) & 0x7fffffffffffffL); + a[6 + 6] += (sp_digit)(((sp_uint64)am << 54) & 0x7fffffffffffffL); a[6 + 7] += am >> 1; - a[0] = (a[6] >> 54) + (sp_digit)((a[7] << 1) & 0x7fffffffffffffL); - a[1] = (a[7] >> 54) + (sp_digit)((a[8] << 1) & 0x7fffffffffffffL); - a[2] = (a[8] >> 54) + (sp_digit)((a[9] << 1) & 0x7fffffffffffffL); - a[3] = (a[9] >> 54) + (sp_digit)((a[10] << 1) & 0x7fffffffffffffL); - a[4] = (a[10] >> 54) + (sp_digit)((a[11] << 1) & 0x7fffffffffffffL); - a[5] = (a[11] >> 54) + (sp_digit)((a[12] << 1) & 0x7fffffffffffffL); - a[6] = (a[12] >> 54) + (a[13] << 1); + a[0] = (a[6] >> 54) + (sp_digit)(((sp_uint64)a[7] << 1) & 0x7fffffffffffffL); + a[1] = (a[7] >> 54) + (sp_digit)(((sp_uint64)a[8] << 1) & 0x7fffffffffffffL); + a[2] = (a[8] >> 54) + (sp_digit)(((sp_uint64)a[9] << 1) & 0x7fffffffffffffL); + a[3] = (a[9] >> 54) + (sp_digit)(((sp_uint64)a[10] << 1) & 0x7fffffffffffffL); + a[4] = (a[10] >> 54) + (sp_digit)(((sp_uint64)a[11] << 1) & 0x7fffffffffffffL); + a[5] = (a[11] >> 54) + (sp_digit)(((sp_uint64)a[12] << 1) & 0x7fffffffffffffL); + a[6] = (a[12] >> 54) + (sp_digit)((sp_uint64)a[13] << 1); a[1] += a[0] >> 55; a[0] &= 0x7fffffffffffffL; a[2] += a[1] >> 55; a[1] &= 0x7fffffffffffffL; @@ -28473,7 +28484,7 @@ static void sp_384_mont_inv_7(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 7); for (i=382; i>=0; i--) { sp_384_mont_sqr_7(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_384_mont_mul_7(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 7); @@ -28707,15 +28718,15 @@ SP_NOINLINE static void sp_384_rshift1_7(sp_digit* r, const sp_digit* a) int i; for (i=0; i<6; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 54) & 0x7fffffffffffffL); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint64)a[i + 1] << 54) & 0x7fffffffffffffL); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 54) & 0x7fffffffffffffL); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 54) & 0x7fffffffffffffL); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 54) & 0x7fffffffffffffL); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 54) & 0x7fffffffffffffL); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 54) & 0x7fffffffffffffL); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 54) & 0x7fffffffffffffL); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint64)a[1] << 54) & 0x7fffffffffffffL); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint64)a[2] << 54) & 0x7fffffffffffffL); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint64)a[3] << 54) & 0x7fffffffffffffL); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint64)a[4] << 54) & 0x7fffffffffffffL); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint64)a[5] << 54) & 0x7fffffffffffffL); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint64)a[6] << 54) & 0x7fffffffffffffL); #endif r[6] = a[6] >> 1; } @@ -29274,26 +29285,26 @@ static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* a32[0] = (sp_digit)(a[0]) & 0xffffffffL; a32[1] = (sp_digit)(a[0] >> 32U); - a32[1] |= (sp_digit)(a[1] << 23U); + a32[1] |= (sp_digit)((sp_uint64)a[1] << 23U); a32[1] &= 0xffffffffL; a32[2] = (sp_digit)(a[1] >> 9U) & 0xffffffffL; a32[3] = (sp_digit)(a[1] >> 41U); - a32[3] |= (sp_digit)(a[2] << 14U); + a32[3] |= (sp_digit)((sp_uint64)a[2] << 14U); a32[3] &= 0xffffffffL; a32[4] = (sp_digit)(a[2] >> 18U) & 0xffffffffL; a32[5] = (sp_digit)(a[2] >> 50U); - a32[5] |= (sp_digit)(a[3] << 5U); + a32[5] |= (sp_digit)((sp_uint64)a[3] << 5U); a32[5] &= 0xffffffffL; a32[6] = (sp_digit)(a[3] >> 27U); - a32[6] |= (sp_digit)(a[4] << 28U); + a32[6] |= (sp_digit)((sp_uint64)a[4] << 28U); a32[6] &= 0xffffffffL; a32[7] = (sp_digit)(a[4] >> 4U) & 0xffffffffL; a32[8] = (sp_digit)(a[4] >> 36U); - a32[8] |= (sp_digit)(a[5] << 19U); + a32[8] |= (sp_digit)((sp_uint64)a[5] << 19U); a32[8] &= 0xffffffffL; a32[9] = (sp_digit)(a[5] >> 13U) & 0xffffffffL; a32[10] = (sp_digit)(a[5] >> 45U); - a32[10] |= (sp_digit)(a[6] << 10U); + a32[10] |= (sp_digit)((sp_uint64)a[6] << 10U); a32[10] &= 0xffffffffL; a32[11] = (sp_digit)(a[6] >> 22U) & 0xffffffffL; @@ -29431,7 +29442,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, if (err == MP_OKAY) { i = 6; c = 54; - n = k[i--] << (55 - c); + n = (sp_uint64)k[i--] << (55 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -29442,7 +29453,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, } y = (n >> 54) & 1; - n <<= 1; + n = (sp_uint64)n << 1; sp_384_proj_point_add_7(&t[y^1], &t[0], &t[1], tmp); @@ -29501,7 +29512,7 @@ static int sp_384_ecc_mulmod_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, XMEMSET(ctx->t, 0, sizeof(sp_point_384) * 3); ctx->i = 6; ctx->c = 54; - ctx->n = k[ctx->i--] << (55 - ctx->c); + ctx->n = (sp_uint64)k[ctx->i--] << (55 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -29531,7 +29542,7 @@ static int sp_384_ecc_mulmod_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, ctx->c = 55; } ctx->y = (ctx->n >> 54) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -29930,7 +29941,7 @@ static void sp_384_ecc_recode_6_7(const sp_digit* k, ecc_recode_384* v) } else if (++j < 7) { n = k[j]; - y |= (word8)((n << (55 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (55 - o)) & 0x3f); o -= 49; n >>= o; } @@ -32670,7 +32681,7 @@ static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 47U) { r[j] &= 0x7fffffffffffffL; s = 55U - s; @@ -32891,7 +32902,7 @@ static void sp_384_to_bin_7(sp_digit* r, byte* a) for (i=0; i<7 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -33015,25 +33026,25 @@ SP_NOINLINE static void sp_384_rshift_7(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<6; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (55 - n))) & 0x7fffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (55 - n))) & 0x7fffffffffffffL); } #else for (i=0; i<0; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (55 - n)) & 0x7fffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (55 - n)) & 0x7fffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (55 - n)) & 0x7fffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (55 - n)) & 0x7fffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (55 - n)) & 0x7fffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (55 - n)) & 0x7fffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (55 - n)) & 0x7fffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (55 - n)) & 0x7fffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (55 - n)) & 0x7fffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (55 - n)) & 0x7fffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (55 - n)) & 0x7fffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (55 - n)) & 0x7fffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (55 - n)) & 0x7fffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (55 - n)) & 0x7fffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (55 - n)) & 0x7fffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (55 - n)) & 0x7fffffffffffffL); } - r[0] = (a[0] >> n) | (sp_digit)((a[1] << (55 - n)) & 0x7fffffffffffffL); - r[1] = (a[1] >> n) | (sp_digit)((a[2] << (55 - n)) & 0x7fffffffffffffL); - r[2] = (a[2] >> n) | (sp_digit)((a[3] << (55 - n)) & 0x7fffffffffffffL); - r[3] = (a[3] >> n) | (sp_digit)((a[4] << (55 - n)) & 0x7fffffffffffffL); - r[4] = (a[4] >> n) | (sp_digit)((a[5] << (55 - n)) & 0x7fffffffffffffL); - r[5] = (a[5] >> n) | (sp_digit)((a[6] << (55 - n)) & 0x7fffffffffffffL); + r[0] = (a[0] >> n) | (sp_digit)(((sp_uint64)a[1] << (55 - n)) & 0x7fffffffffffffL); + r[1] = (a[1] >> n) | (sp_digit)(((sp_uint64)a[2] << (55 - n)) & 0x7fffffffffffffL); + r[2] = (a[2] >> n) | (sp_digit)(((sp_uint64)a[3] << (55 - n)) & 0x7fffffffffffffL); + r[3] = (a[3] >> n) | (sp_digit)(((sp_uint64)a[4] << (55 - n)) & 0x7fffffffffffffL); + r[4] = (a[4] >> n) | (sp_digit)(((sp_uint64)a[5] << (55 - n)) & 0x7fffffffffffffL); + r[5] = (a[5] >> n) | (sp_digit)(((sp_uint64)a[6] << (55 - n)) & 0x7fffffffffffffL); #endif /* WOLFSSL_SP_SMALL */ r[6] = a[6] >> n; } @@ -33088,7 +33099,7 @@ SP_NOINLINE static void sp_384_lshift_14(sp_digit* r, const sp_digit* a, r[14] = a[13] >> (55 - n); for (i=13; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (55 - n))) & 0x7fffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (55 - n))) & 0x7fffffffffffffL); } #else sp_int_digit s; @@ -33123,7 +33134,7 @@ SP_NOINLINE static void sp_384_lshift_14(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x7fffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x7fffffffffffffL); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -35101,7 +35112,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x3ffffffffffffffL; s = 58U - s; if (j + 1 >= size) { @@ -35136,7 +35147,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 58) { r[j] &= 0x3ffffffffffffffL; if (j + 1 >= size) { @@ -35202,7 +35213,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -35227,7 +35238,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 58 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -35308,10 +35319,10 @@ static void sp_521_mont_reduce_9(sp_digit* a, const sp_digit* m, sp_digit mp) (void)mp; for (i = 0; i < 8; i++) { - a[i] += (sp_digit)(((a[8 + i] >> 57) + (a[8 + i + 1] << 1)) & 0x3ffffffffffffffL); + a[i] += (sp_digit)(((a[8 + i] >> 57) + ((sp_uint64)a[8 + i + 1] << 1)) & 0x3ffffffffffffffL); } a[8] &= 0x1ffffffffffffff; - a[8] += (sp_digit)(((a[16] >> 57) + (a[17] << 1)) & 0x3ffffffffffffffL); + a[8] += (sp_digit)(((a[16] >> 57) + ((sp_uint64)a[17] << 1)) & 0x3ffffffffffffffL); sp_521_norm_9(a); @@ -35577,7 +35588,7 @@ static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 9); for (i=519; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 9); @@ -35809,17 +35820,17 @@ SP_NOINLINE static void sp_521_rshift1_9(sp_digit* r, const sp_digit* a) int i; for (i=0; i<8; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 57) & 0x3ffffffffffffffL); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint64)a[i + 1] << 57) & 0x3ffffffffffffffL); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 57) & 0x3ffffffffffffffL); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 57) & 0x3ffffffffffffffL); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 57) & 0x3ffffffffffffffL); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 57) & 0x3ffffffffffffffL); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 57) & 0x3ffffffffffffffL); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 57) & 0x3ffffffffffffffL); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 57) & 0x3ffffffffffffffL); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 57) & 0x3ffffffffffffffL); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint64)a[1] << 57) & 0x3ffffffffffffffL); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint64)a[2] << 57) & 0x3ffffffffffffffL); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint64)a[3] << 57) & 0x3ffffffffffffffL); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint64)a[4] << 57) & 0x3ffffffffffffffL); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint64)a[5] << 57) & 0x3ffffffffffffffL); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint64)a[6] << 57) & 0x3ffffffffffffffL); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint64)a[7] << 57) & 0x3ffffffffffffffL); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint64)a[8] << 57) & 0x3ffffffffffffffL); #endif r[8] = a[8] >> 1; } @@ -36425,7 +36436,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, if (err == MP_OKAY) { i = 8; c = 57; - n = k[i--] << (58 - c); + n = (sp_uint64)k[i--] << (58 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -36436,7 +36447,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, } y = (n >> 57) & 1; - n <<= 1; + n = (sp_uint64)n << 1; sp_521_proj_point_add_9(&t[y^1], &t[0], &t[1], tmp); @@ -36495,7 +36506,7 @@ static int sp_521_ecc_mulmod_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r, XMEMSET(ctx->t, 0, sizeof(sp_point_521) * 3); ctx->i = 8; ctx->c = 57; - ctx->n = k[ctx->i--] << (58 - ctx->c); + ctx->n = (sp_uint64)k[ctx->i--] << (58 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -36525,7 +36536,7 @@ static int sp_521_ecc_mulmod_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r, ctx->c = 58; } ctx->y = (ctx->n >> 57) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -36928,7 +36939,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (58 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (58 - o)) & 0x3f); o -= 52; n >>= o; } @@ -39688,7 +39699,7 @@ static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 50U) { r[j] &= 0x3ffffffffffffffL; s = 58U - s; @@ -39910,7 +39921,7 @@ static void sp_521_to_bin_9(sp_digit* r, byte* a) for (i=0; i<9 && j>=0; i++) { b = 0; /* lint allow cast of mismatch sp_digit and int */ - a[j--] |= (byte)(r[i] << s); /*lint !e9033*/ + a[j--] |= (byte)((sp_uint64)r[i] << s); /*lint !e9033*/ b += 8 - s; if (j < 0) { break; @@ -40032,18 +40043,18 @@ SP_NOINLINE static void sp_521_rshift_9(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<8; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (58 - n))) & 0x3ffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (58 - n))) & 0x3ffffffffffffffL); } #else for (i=0; i<8; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (58 - n)) & 0x3ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (58 - n)) & 0x3ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (58 - n)) & 0x3ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (58 - n)) & 0x3ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (58 - n)) & 0x3ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (58 - n)) & 0x3ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (58 - n)) & 0x3ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (58 - n)) & 0x3ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (58 - n)) & 0x3ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (58 - n)) & 0x3ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (58 - n)) & 0x3ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (58 - n)) & 0x3ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (58 - n)) & 0x3ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (58 - n)) & 0x3ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (58 - n)) & 0x3ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (58 - n)) & 0x3ffffffffffffffL); } #endif /* WOLFSSL_SP_SMALL */ r[8] = a[8] >> n; @@ -40105,7 +40116,7 @@ SP_NOINLINE static void sp_521_lshift_18(sp_digit* r, const sp_digit* a, r[18] = a[17] >> (58 - n); for (i=17; i>0; i--) { - r[i] = (sp_digit)(((a[i] << n) | (a[i-1] >> (58 - n))) & 0x3ffffffffffffffL); + r[i] = (sp_digit)((((sp_uint64)a[i] << n) | (a[i-1] >> (58 - n))) & 0x3ffffffffffffffL); } #else sp_int_digit s; @@ -40148,7 +40159,7 @@ SP_NOINLINE static void sp_521_lshift_18(sp_digit* r, const sp_digit* a, s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]); r[1] = (sp_digit)(((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL); #endif /* WOLFSSL_SP_SMALL */ - r[0] = (sp_digit)((a[0] << n) & 0x3ffffffffffffffL); + r[0] = (sp_digit)(((sp_uint64)a[0] << n) & 0x3ffffffffffffffL); } /* Divide d in a and put remainder into r (m*d + r = a) @@ -41565,7 +41576,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 9); for (i=518; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 9); @@ -42351,20 +42362,20 @@ SP_NOINLINE static void sp_1024_rshift_18(sp_digit* r, const sp_digit* a, #ifdef WOLFSSL_SP_SMALL for (i=0; i<17; i++) { - r[i] = (sp_digit)(((a[i] >> n) | (a[i + 1] << (57 - n))) & 0x1ffffffffffffffL); + r[i] = (sp_digit)(((a[i] >> n) | ((sp_uint64)a[i + 1] << (57 - n))) & 0x1ffffffffffffffL); } #else for (i=0; i<16; i += 8) { - r[i+0] = (a[i+0] >> n) | (sp_digit)((a[i+1] << (57 - n)) & 0x1ffffffffffffffL); - r[i+1] = (a[i+1] >> n) | (sp_digit)((a[i+2] << (57 - n)) & 0x1ffffffffffffffL); - r[i+2] = (a[i+2] >> n) | (sp_digit)((a[i+3] << (57 - n)) & 0x1ffffffffffffffL); - r[i+3] = (a[i+3] >> n) | (sp_digit)((a[i+4] << (57 - n)) & 0x1ffffffffffffffL); - r[i+4] = (a[i+4] >> n) | (sp_digit)((a[i+5] << (57 - n)) & 0x1ffffffffffffffL); - r[i+5] = (a[i+5] >> n) | (sp_digit)((a[i+6] << (57 - n)) & 0x1ffffffffffffffL); - r[i+6] = (a[i+6] >> n) | (sp_digit)((a[i+7] << (57 - n)) & 0x1ffffffffffffffL); - r[i+7] = (a[i+7] >> n) | (sp_digit)((a[i+8] << (57 - n)) & 0x1ffffffffffffffL); + r[i+0] = (a[i+0] >> n) | (sp_digit)(((sp_uint64)a[i+1] << (57 - n)) & 0x1ffffffffffffffL); + r[i+1] = (a[i+1] >> n) | (sp_digit)(((sp_uint64)a[i+2] << (57 - n)) & 0x1ffffffffffffffL); + r[i+2] = (a[i+2] >> n) | (sp_digit)(((sp_uint64)a[i+3] << (57 - n)) & 0x1ffffffffffffffL); + r[i+3] = (a[i+3] >> n) | (sp_digit)(((sp_uint64)a[i+4] << (57 - n)) & 0x1ffffffffffffffL); + r[i+4] = (a[i+4] >> n) | (sp_digit)(((sp_uint64)a[i+5] << (57 - n)) & 0x1ffffffffffffffL); + r[i+5] = (a[i+5] >> n) | (sp_digit)(((sp_uint64)a[i+6] << (57 - n)) & 0x1ffffffffffffffL); + r[i+6] = (a[i+6] >> n) | (sp_digit)(((sp_uint64)a[i+7] << (57 - n)) & 0x1ffffffffffffffL); + r[i+7] = (a[i+7] >> n) | (sp_digit)(((sp_uint64)a[i+8] << (57 - n)) & 0x1ffffffffffffffL); } - r[16] = (a[16] >> n) | (sp_digit)((a[17] << (57 - n)) & 0x1ffffffffffffffL); + r[16] = (a[16] >> n) | (sp_digit)(((sp_uint64)a[17] << (57 - n)) & 0x1ffffffffffffffL); #endif /* WOLFSSL_SP_SMALL */ r[17] = a[17] >> n; } @@ -42404,7 +42415,7 @@ static WC_INLINE sp_digit sp_1024_div_word_18(sp_digit d1, sp_digit d0, t1 -= dv & (0 - r); for (i = 55; i >= 1; i--) { t1 += t1 + (((sp_uint64)t0 >> 56) & 1); - t0 <<= 1; + t0 = (sp_uint64)t0 << 1; t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63); r += r + t2; t1 -= dv & (0 - t2); @@ -42647,7 +42658,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0x1ffffffffffffffL; s = 57U - s; if (j + 1 >= size) { @@ -42682,7 +42693,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 57) { r[j] &= 0x1ffffffffffffffL; if (j + 1 >= size) { @@ -42748,7 +42759,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 18; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -42773,7 +42784,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 18; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 57 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -43009,11 +43020,11 @@ static void sp_1024_mont_reduce_18(sp_digit* a, const sp_digit* m, sp_digit mp) if (mp != 1) { for (i=0; i<17; i++) { - mu = (sp_digit)((a[i] * mp) & 0x1ffffffffffffffL); + mu = (sp_digit)(((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL); sp_1024_mul_add_18(a+i, m, mu); a[i+1] += a[i] >> 57; } - mu = (sp_digit)((a[i] * mp) & 0x7fffffffffffffL); + mu = (sp_digit)(((sp_uint64)a[i] * (sp_uint64)mp) & 0x7fffffffffffffL); sp_1024_mul_add_18(a+i, m, mu); a[i+1] += a[i] >> 57; a[i] &= 0x1ffffffffffffffL; @@ -43249,26 +43260,26 @@ SP_NOINLINE static void sp_1024_rshift1_18(sp_digit* r, const sp_digit* a) int i; for (i=0; i<17; i++) { - r[i] = (a[i] >> 1) + (sp_digit)((a[i + 1] << 56) & 0x1ffffffffffffffL); + r[i] = (a[i] >> 1) + (sp_digit)(((sp_uint64)a[i + 1] << 56) & 0x1ffffffffffffffL); } #else - r[0] = (a[0] >> 1) + (sp_digit)((a[1] << 56) & 0x1ffffffffffffffL); - r[1] = (a[1] >> 1) + (sp_digit)((a[2] << 56) & 0x1ffffffffffffffL); - r[2] = (a[2] >> 1) + (sp_digit)((a[3] << 56) & 0x1ffffffffffffffL); - r[3] = (a[3] >> 1) + (sp_digit)((a[4] << 56) & 0x1ffffffffffffffL); - r[4] = (a[4] >> 1) + (sp_digit)((a[5] << 56) & 0x1ffffffffffffffL); - r[5] = (a[5] >> 1) + (sp_digit)((a[6] << 56) & 0x1ffffffffffffffL); - r[6] = (a[6] >> 1) + (sp_digit)((a[7] << 56) & 0x1ffffffffffffffL); - r[7] = (a[7] >> 1) + (sp_digit)((a[8] << 56) & 0x1ffffffffffffffL); - r[8] = (a[8] >> 1) + (sp_digit)((a[9] << 56) & 0x1ffffffffffffffL); - r[9] = (a[9] >> 1) + (sp_digit)((a[10] << 56) & 0x1ffffffffffffffL); - r[10] = (a[10] >> 1) + (sp_digit)((a[11] << 56) & 0x1ffffffffffffffL); - r[11] = (a[11] >> 1) + (sp_digit)((a[12] << 56) & 0x1ffffffffffffffL); - r[12] = (a[12] >> 1) + (sp_digit)((a[13] << 56) & 0x1ffffffffffffffL); - r[13] = (a[13] >> 1) + (sp_digit)((a[14] << 56) & 0x1ffffffffffffffL); - r[14] = (a[14] >> 1) + (sp_digit)((a[15] << 56) & 0x1ffffffffffffffL); - r[15] = (a[15] >> 1) + (sp_digit)((a[16] << 56) & 0x1ffffffffffffffL); - r[16] = (a[16] >> 1) + (sp_digit)((a[17] << 56) & 0x1ffffffffffffffL); + r[0] = (a[0] >> 1) + (sp_digit)(((sp_uint64)a[1] << 56) & 0x1ffffffffffffffL); + r[1] = (a[1] >> 1) + (sp_digit)(((sp_uint64)a[2] << 56) & 0x1ffffffffffffffL); + r[2] = (a[2] >> 1) + (sp_digit)(((sp_uint64)a[3] << 56) & 0x1ffffffffffffffL); + r[3] = (a[3] >> 1) + (sp_digit)(((sp_uint64)a[4] << 56) & 0x1ffffffffffffffL); + r[4] = (a[4] >> 1) + (sp_digit)(((sp_uint64)a[5] << 56) & 0x1ffffffffffffffL); + r[5] = (a[5] >> 1) + (sp_digit)(((sp_uint64)a[6] << 56) & 0x1ffffffffffffffL); + r[6] = (a[6] >> 1) + (sp_digit)(((sp_uint64)a[7] << 56) & 0x1ffffffffffffffL); + r[7] = (a[7] >> 1) + (sp_digit)(((sp_uint64)a[8] << 56) & 0x1ffffffffffffffL); + r[8] = (a[8] >> 1) + (sp_digit)(((sp_uint64)a[9] << 56) & 0x1ffffffffffffffL); + r[9] = (a[9] >> 1) + (sp_digit)(((sp_uint64)a[10] << 56) & 0x1ffffffffffffffL); + r[10] = (a[10] >> 1) + (sp_digit)(((sp_uint64)a[11] << 56) & 0x1ffffffffffffffL); + r[11] = (a[11] >> 1) + (sp_digit)(((sp_uint64)a[12] << 56) & 0x1ffffffffffffffL); + r[12] = (a[12] >> 1) + (sp_digit)(((sp_uint64)a[13] << 56) & 0x1ffffffffffffffL); + r[13] = (a[13] >> 1) + (sp_digit)(((sp_uint64)a[14] << 56) & 0x1ffffffffffffffL); + r[14] = (a[14] >> 1) + (sp_digit)(((sp_uint64)a[15] << 56) & 0x1ffffffffffffffL); + r[15] = (a[15] >> 1) + (sp_digit)(((sp_uint64)a[16] << 56) & 0x1ffffffffffffffL); + r[16] = (a[16] >> 1) + (sp_digit)(((sp_uint64)a[17] << 56) & 0x1ffffffffffffffL); #endif r[17] = a[17] >> 1; } @@ -43860,7 +43871,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, if (err == MP_OKAY) { i = 17; c = 55; - n = k[i--] << (57 - c); + n = (sp_uint64)k[i--] << (57 - c); for (; ; c--) { if (c == 0) { if (i == -1) @@ -43871,7 +43882,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, } y = (n >> 56) & 1; - n <<= 1; + n = (sp_uint64)n << 1; sp_1024_proj_point_add_18(&t[y^1], &t[0], &t[1], tmp); @@ -43930,7 +43941,7 @@ static int sp_1024_ecc_mulmod_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, XMEMSET(ctx->t, 0, sizeof(sp_point_1024) * 3); ctx->i = 17; ctx->c = 55; - ctx->n = k[ctx->i--] << (57 - ctx->c); + ctx->n = (sp_uint64)k[ctx->i--] << (57 - ctx->c); /* t[0] = {0, 0, 1} * norm */ ctx->t[0].infinity = 1; @@ -43960,7 +43971,7 @@ static int sp_1024_ecc_mulmod_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, ctx->c = 57; } ctx->y = (ctx->n >> 56) & 1; - ctx->n <<= 1; + ctx->n = (sp_uint64)ctx->n << 1; XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx)); ctx->state = 5; break; @@ -44389,7 +44400,7 @@ static void sp_1024_ecc_recode_7_18(const sp_digit* k, ecc_recode_1024* v) } else if (++j < 18) { n = k[j]; - y |= (word8)((n << (57 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (57 - o)) & 0x7f); o -= 50; n >>= o; } @@ -51732,7 +51743,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) r[0] = 0; for (i = n-1; i >= 0; i--) { - r[j] |= (((sp_digit)a[i]) << s); + r[j] |= (((sp_uint64)a[i]) << s); if (s >= 49U) { r[j] &= 0x1ffffffffffffffL; s = 57U - s; diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 9a334f4d4a..f9d22092d9 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -47,6 +47,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -141,10 +152,10 @@ static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -199,7 +210,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -234,7 +245,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -3136,17 +3147,17 @@ WC_OMIT_FRAME_POINTER static void sp_2048_sqr_32(sp_digit* r, const sp_digit* a) */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -5600,10 +5611,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -5612,14 +5623,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -5627,12 +5638,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -5753,10 +5764,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -5765,14 +5776,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 32); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -5780,12 +5791,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -8772,10 +8783,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -8784,14 +8795,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -8799,12 +8810,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -8908,10 +8919,10 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -8920,14 +8931,14 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 64); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -8935,12 +8946,12 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -9013,7 +9024,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -9505,7 +9516,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -9530,7 +9541,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -10064,10 +10075,10 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -10076,14 +10087,14 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_2048_lshift_64(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -10091,12 +10102,12 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -10264,10 +10275,10 @@ static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -10322,7 +10333,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -10357,7 +10368,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -14361,17 +14372,17 @@ WC_OMIT_FRAME_POINTER static void sp_3072_sqr_48(sp_digit* r, const sp_digit* a) */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -17505,10 +17516,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -17517,14 +17528,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -17532,12 +17543,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -17658,10 +17669,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -17670,14 +17681,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 48); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -17685,12 +17696,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -21613,10 +21624,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -21625,14 +21636,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -21640,12 +21651,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -21749,10 +21760,10 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -21761,14 +21772,14 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 96); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -21776,12 +21787,12 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -21854,7 +21865,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -22402,7 +22413,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -22427,7 +22438,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 96; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -23153,10 +23164,10 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -23165,14 +23176,14 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_3072_lshift_96(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -23180,12 +23191,12 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -23353,10 +23364,10 @@ static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -23411,7 +23422,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -23446,7 +23457,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -24488,17 +24499,17 @@ WC_OMIT_FRAME_POINTER static void sp_4096_sqr_128(sp_digit* r, */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint32 x; + sp_uint32 b; - b = a[0]; + b = (sp_uint32)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ x *= 2 - b * x; /* here x*a==1 mod 2**32 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int32)0 - (sp_int32)x); } #ifdef WOLFSSL_SP_SMALL @@ -30072,10 +30083,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -30084,14 +30095,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=3; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 29); - n <<= 3; + n = (sp_uint32)n << 3; c = 29; } else if (c < 3) { @@ -30099,12 +30110,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 3 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 29) & 0x7); - n <<= 3; + n = (sp_uint32)n << 3; c -= 3; } @@ -30208,10 +30219,10 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -30220,14 +30231,14 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } XMEMCPY(r, t[y], sizeof(sp_digit) * 128); for (; i>=0 || c>=4; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 28); - n <<= 4; + n = (sp_uint32)n << 4; c = 28; } else if (c < 4) { @@ -30235,12 +30246,12 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e n = e[i--]; c = 4 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 28) & 0xf); - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; } @@ -30313,7 +30324,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, #else e[0] = em->dp[0]; if (em->used > 1) { - e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT; + e[0] |= ((sp_uint32)em->dp[1]) << DIGIT_BIT; } #endif if (e[0] == 0) { @@ -30917,7 +30928,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -30942,7 +30953,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 128; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -31860,10 +31871,10 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, if (c < 0) { /* Number of bits in top word is less than number needed. */ c = -c; - y = (byte)(n << c); + y = (byte)((sp_uint32)n << c); n = e[i--]; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else if (c == 0) { @@ -31872,14 +31883,14 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, } else { y = (byte)(n >> c); - n <<= 32 - c; + n = (sp_uint32)n << (32 - c); } sp_4096_lshift_128(r, norm, y); for (; i>=0 || c>=5; ) { if (c == 0) { n = e[i--]; y = (byte)(n >> 27); - n <<= 5; + n = (sp_uint32)n << 5; c = 27; } else if (c < 5) { @@ -31887,12 +31898,12 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, n = e[i--]; c = 5 - c; y |= (byte)(n >> (32 - c)); - n <<= c; + n = (sp_uint32)n << c; c = 32 - c; } else { y = (byte)((n >> 27) & 0x1f); - n <<= 5; + n = (sp_uint32)n << 5; c -= 5; } @@ -33632,7 +33643,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -33667,7 +33678,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -33733,7 +33744,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -33758,7 +33769,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 8; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -35269,7 +35280,7 @@ static void sp_256_mont_inv_8(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 8); for (i=254; i>=0; i--) { sp_256_mont_sqr_8(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p256_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_256_mont_mul_8(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 8); @@ -37352,7 +37363,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons t[15].infinity = 0; i = 6; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -37365,14 +37376,14 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons { XMEMCPY(rt, &t[y], sizeof(sp_point_256)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_256_proj_point_dbl_8(rt, rt, tmp); @@ -40038,10 +40049,10 @@ static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -45025,7 +45036,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -45060,7 +45071,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -45126,7 +45137,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -45151,7 +45162,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 12; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -45703,7 +45714,7 @@ static void sp_384_mont_inv_12(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 12); for (i=382; i>=0; i--) { sp_384_mont_sqr_12(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p384_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_384_mont_mul_12(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 12); @@ -47444,7 +47455,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con t[15].infinity = 0; i = 10; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); #ifndef WC_NO_CACHE_RESISTANT @@ -47457,14 +47468,14 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_384)); } - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_384_proj_point_dbl_12(rt, rt, tmp); @@ -50168,10 +50179,10 @@ static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -56725,7 +56736,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -56760,7 +56771,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -56826,7 +56837,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -56851,7 +56862,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 17; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -57804,7 +57815,7 @@ static void sp_521_mont_inv_17(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 17); for (i=519; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_mod_minus_2[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 17); @@ -58677,7 +58688,7 @@ static void sp_521_mont_div2_17(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; - sp_521_rshift1_17(r, r); + sp_521_rshift1_17(r, a); r[16] |= o << 8; } @@ -59407,7 +59418,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con t[15].infinity = 0; i = 15; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 5; y = (int)(n >> 5); #ifndef WC_NO_CACHE_RESISTANT @@ -59420,15 +59431,15 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con { XMEMCPY(rt, &t[y], sizeof(sp_point_521)); } - n <<= 27; + n = (sp_uint32)n << (27); for (; i>=0 || c>=4; ) { if (c < 4) { - n = (k[i+1] << 31) | (k[i] >> 1); + n = ((sp_uint32)k[i+1] << 31) | (k[i] >> 1); i--; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_521_proj_point_dbl_17(rt, rt, tmp); @@ -62738,10 +62749,10 @@ static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } @@ -64063,8 +64074,6 @@ static WC_INLINE int sp_521_div_17(const sp_digit* a, const sp_digit* d, sp_digit r1; int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = (d[16] << 23) | (d[15] >> 9); XMEMCPY(t1, a, sizeof(*t1) * 2 * 17); @@ -66139,7 +66148,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 17); for (i=518; i>=0; i--) { sp_521_mont_sqr_17(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 32] & ((sp_digit)1 << (i % 32))) + if (p521_sqrt_power[i / 32] & ((sp_uint32)1 << (i % 32))) sp_521_mont_mul_17(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 17); @@ -71319,7 +71328,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint32)a->dp[i] << s); r[j] &= 0xffffffff; s = 32U - s; if (j + 1 >= size) { @@ -71354,7 +71363,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint32)a->dp[i]) << s; if (s + DIGIT_BIT >= 32) { r[j] &= 0xffffffff; if (j + 1 >= size) { @@ -71420,7 +71429,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint32)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -71445,7 +71454,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint32)a[i]) << s; if (s + 32 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -74032,18 +74041,18 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, t[15].infinity = 0; i = 30; - n = k[i+1] << 0; + n = (sp_uint32)k[i+1] << 0; c = 28; y = (int)(n >> 28); XMEMCPY(rt, &t[y], sizeof(sp_point_1024)); - n <<= 4; + n = (sp_uint32)n << (4); for (; i>=0 || c>=4; ) { if (c < 4) { n |= k[i--]; c += 32; } y = (n >> 28) & 0xf; - n <<= 4; + n = (sp_uint32)n << 4; c -= 4; sp_1024_proj_point_dbl_32(rt, rt, tmp); @@ -82148,10 +82157,10 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) j = 0; for (i = n - 1; i >= 3; i -= 4) { - r[j] = ((sp_digit)a[i - 0] << 0) | - ((sp_digit)a[i - 1] << 8) | - ((sp_digit)a[i - 2] << 16) | - ((sp_digit)a[i - 3] << 24); + r[j] = ((sp_uint32)a[i - 0] << 0) | + ((sp_uint32)a[i - 1] << 8) | + ((sp_uint32)a[i - 2] << 16) | + ((sp_uint32)a[i - 3] << 24); j++; } diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 71ad6c25be..ff5a33e2e6 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -125,8 +125,6 @@ This library provides single precision (SP) integer math functions. * WOLFSSL_NO_ASM: Disable all assembly implementations * WOLFSSL_KEIL: Keil compiler in use, affects inline assembly * syntax - * WOLFSSL_USE_SAVE_VECTOR_REGISTERS: Save/restore vector registers around - * SP ASM calls * WOLFSSL_SP_INT_LARGE_COMBA: Enable large Comba multiplication and * squaring * WOLFSSL_SP_INT_SQR_VOLATILE: Declare squaring intermediate variables as @@ -198,15 +196,6 @@ This library provides single precision (SP) integer math functions. PRAGMA_GCC("GCC diagnostic ignored \"-Warray-bounds\"") #endif -#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) - /* force off unneeded vector register save/restore. */ - #undef SAVE_VECTOR_REGISTERS - #define SAVE_VECTOR_REGISTERS(fail_clause) \ - SAVE_NO_VECTOR_REGISTERS(fail_clause) - #undef RESTORE_VECTOR_REGISTERS - #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() -#endif - /* DECL_SP_INT: Declare one variable of type 'sp_int'. */ #if (defined(WOLFSSL_SMALL_STACK) || defined(SP_ALLOC)) && \ !defined(WOLFSSL_SP_NO_MALLOC) @@ -5487,6 +5476,22 @@ static void _sp_copy_2_ct(const sp_int* a1, const sp_int* a2, sp_int* r1, sp_int* r2, int y, unsigned int used) { unsigned int i; +#ifdef WC_NO_GLOBAL_OBJECT_POINTERS + static const wc_ptr_t wc_off_on_addr[2] = + { + #if defined(WC_64BIT_CPU) + W64LIT(0x0000000000000000), + W64LIT(0xffffffffffffffff) + #elif defined(WC_16BIT_CPU) + 0x0000U, + 0xffffU + #else + /* 32 bit */ + 0x00000000U, + 0xffffffffU + #endif + }; +#endif /* Copy data - constant time. */ for (i = 0; i < used; i++) { @@ -14329,11 +14334,9 @@ int sp_exptmod(const sp_int* b, const sp_int* e, const sp_int* m, sp_int* r) if ((b == NULL) || (e == NULL) || (m == NULL) || (r == NULL)) { err = MP_VAL; } - SAVE_VECTOR_REGISTERS(err = _svr_ret;); if (err == MP_OKAY) { err = sp_exptmod_ex(b, e, (int)e->used, m, r); } - RESTORE_VECTOR_REGISTERS(); return err; } #endif @@ -19554,8 +19557,6 @@ int sp_prime_is_prime(const sp_int* a, int trials, int* result) haveRes = 1; } - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - /* Check against known small primes when a has 1 digit. */ if ((err == MP_OKAY) && (!haveRes) && (a->used == 1) && (a->dp[0] <= sp_primes[SP_PRIME_SIZE - 1])) { @@ -19572,8 +19573,6 @@ int sp_prime_is_prime(const sp_int* a, int trials, int* result) err = _sp_prime_trials(a, trials, result); } - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -19714,8 +19713,6 @@ int sp_prime_is_prime_ex(const sp_int* a, int trials, int* result, WC_RNG* rng) haveRes = 1; } - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - /* Check against known small primes when a has 1 digit. */ if ((err == MP_OKAY) && (!haveRes) && (a->used == 1) && (a->dp[0] <= (sp_int_digit)sp_primes[SP_PRIME_SIZE - 1])) { @@ -19740,8 +19737,6 @@ int sp_prime_is_prime_ex(const sp_int* a, int trials, int* result, WC_RNG* rng) *result = ret; } - RESTORE_VECTOR_REGISTERS(); - return err; } #endif /* WOLFSSL_SP_PRIME_GEN */ @@ -19783,8 +19778,6 @@ static WC_INLINE int _sp_gcd(const sp_int* a, const sp_int* b, sp_int* r) unsigned int used = (a->used >= b->used) ? a->used + 1U : b->used + 1U; DECL_SP_INT_ARRAY(d, used, 3); - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - ALLOC_SP_INT_ARRAY(d, used, 3, err, NULL); if (err == MP_OKAY) { u = d[0]; @@ -19849,8 +19842,6 @@ static WC_INLINE int _sp_gcd(const sp_int* a, const sp_int* b, sp_int* r) FREE_SP_INT_ARRAY(d, NULL); - RESTORE_VECTOR_REGISTERS(); - return err; } @@ -19955,8 +19946,6 @@ static int _sp_lcm(const sp_int* a, const sp_int* b, sp_int* r) _sp_init_size(t[0], used); _sp_init_size(t[1], used); - SAVE_VECTOR_REGISTERS(err = _svr_ret;); - if (err == MP_OKAY) { /* 1. t0 = gcd(a, b) */ err = sp_gcd(a, b, t[0]); @@ -19985,8 +19974,6 @@ static int _sp_lcm(const sp_int* a, const sp_int* b, sp_int* r) } } } - - RESTORE_VECTOR_REGISTERS(); } FREE_SP_INT_ARRAY(t, NULL); diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index 1f7cd9e396..7ce9b9ab6a 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -47,6 +47,17 @@ #include +#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WOLFSSL_SP_ASM) && \ + !defined(DEBUG_VECTOR_REGISTER_ACCESS) + /* force off unneeded vector register save/restore. */ + #undef SAVE_VECTOR_REGISTERS + #define SAVE_VECTOR_REGISTERS(fail_clause) SAVE_NO_VECTOR_REGISTERS(fail_clause) + #undef SAVE_VECTOR_REGISTERS2 + #define SAVE_VECTOR_REGISTERS2() SAVE_NO_VECTOR_REGISTERS2() + #undef RESTORE_VECTOR_REGISTERS + #define RESTORE_VECTOR_REGISTERS() RESTORE_NO_VECTOR_REGISTERS() +#endif + #ifdef __IAR_SYSTEMS_ICC__ #define __asm__ asm #define __volatile__ volatile @@ -188,7 +199,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -223,7 +234,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -397,10 +408,10 @@ extern sp_digit sp_2048_sub_in_place_16(sp_digit* a, const sp_digit* b); */ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -408,7 +419,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } #ifdef __cplusplus @@ -429,8 +440,6 @@ static void sp_2048_mont_norm_16(sp_digit* r, const sp_digit* m) { XMEMSET(r, 0, sizeof(sp_digit) * 16); - ASSERT_SAVED_VECTOR_REGISTERS(); - /* r = 2^n mod m */ sp_2048_sub_in_place_16(r, m); } @@ -520,7 +529,6 @@ extern sp_digit div_2048_word_asm_16(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_2048_word_16(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -539,7 +547,6 @@ static WC_INLINE sp_digit div_2048_word_16(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -607,8 +614,6 @@ static WC_INLINE int sp_2048_div_16(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[15]; @@ -661,18 +666,38 @@ static WC_INLINE int sp_2048_div_16(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_2048_mod_16(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_2048_div_16(a, m, NULL, r); } -#ifdef __cplusplus -extern "C" { -#endif -extern void sp_2048_get_from_table_16(sp_digit* r, sp_digit** table, int idx); -#ifdef __cplusplus -} -#endif +#ifndef WC_NO_CACHE_RESISTANT +static void sp_2048_get_from_table_16(sp_digit* r, + sp_digit** table, int idx) +{ + int e, j; + sp_digit mask; + sp_digit diff; + for (j = 0; j < 16; j++) { + r[j] = 0; + } + + for (e = 0; e < 32; e++) { + /* Constant-time: mask = (e == idx) ? ~0 : 0 + * diff = e ^ idx is 0 iff equal. + * (diff | -diff) has its sign bit set iff diff != 0. + * Shift to get 1/0, subtract from 1 to invert, negate to mask. + */ + diff = (sp_digit)(e ^ idx); + diff = (diff | ((sp_digit)0 - diff)) + >> (sizeof(sp_digit) * 8 - 1); /* 1 if !=, 0 if == */ + mask = (sp_digit)0 - ((sp_digit)1 - diff); /* all-1 if ==, else 0 */ + + for (j = 0; j < 16; j++) { + r[j] |= table[e][j] & mask; + } + } +} +#endif /* !WC_NO_CACHE_RESISTANT */ /* Modular exponentiate a to the e mod m. (r = a^e mod m) * * r A single precision number that is the result of the operation. @@ -699,8 +724,6 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -869,6 +892,7 @@ extern void sp_2048_mont_reduce_avx2_16(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_2048_mont_mul_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_2048_mul_avx2_16(r, a, b); sp_2048_mont_reduce_avx2_16(r, m, mp); } @@ -885,6 +909,7 @@ SP_NOINLINE static void sp_2048_mont_mul_avx2_16(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_2048_mont_sqr_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_2048_sqr_avx2_16(r, a); sp_2048_mont_reduce_avx2_16(r, m, mp); } @@ -926,7 +951,6 @@ static int sp_2048_mod_exp_avx2_16(sp_digit* r, const sp_digit* a, const sp_digi int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -1089,8 +1113,6 @@ static void sp_2048_mont_norm_32(sp_digit* r, const sp_digit* m) { XMEMSET(r, 0, sizeof(sp_digit) * 32); - ASSERT_SAVED_VECTOR_REGISTERS(); - /* r = 2^n mod m */ sp_2048_sub_in_place_32(r, m); } @@ -1174,7 +1196,6 @@ extern sp_digit div_2048_word_asm_32(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_2048_word_32(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -1193,7 +1214,6 @@ static WC_INLINE sp_digit div_2048_word_32(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -1224,8 +1244,6 @@ static WC_INLINE int sp_2048_div_32_cond(const sp_digit* a, const sp_digit* d, s word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[31]; @@ -1284,7 +1302,6 @@ static WC_INLINE int sp_2048_div_32_cond(const sp_digit* a, const sp_digit* d, s static WC_INLINE int sp_2048_mod_32_cond(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_2048_div_32_cond(a, m, NULL, r); } @@ -1354,8 +1371,6 @@ static WC_INLINE int sp_2048_div_32(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[31]; @@ -1409,19 +1424,39 @@ static WC_INLINE int sp_2048_div_32(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_2048_div_32(a, m, NULL, r); } #endif /* WOLFSSL_HAVE_SP_DH || !WOLFSSL_RSA_PUBLIC_ONLY */ -#ifdef __cplusplus -extern "C" { -#endif -extern void sp_2048_get_from_table_32(sp_digit* r, sp_digit** table, int idx); -#ifdef __cplusplus -} -#endif +#ifndef WC_NO_CACHE_RESISTANT +static void sp_2048_get_from_table_32(sp_digit* r, + sp_digit** table, int idx) +{ + int e, j; + sp_digit mask; + sp_digit diff; + for (j = 0; j < 32; j++) { + r[j] = 0; + } + + for (e = 0; e < 64; e++) { + /* Constant-time: mask = (e == idx) ? ~0 : 0 + * diff = e ^ idx is 0 iff equal. + * (diff | -diff) has its sign bit set iff diff != 0. + * Shift to get 1/0, subtract from 1 to invert, negate to mask. + */ + diff = (sp_digit)(e ^ idx); + diff = (diff | ((sp_digit)0 - diff)) + >> (sizeof(sp_digit) * 8 - 1); /* 1 if !=, 0 if == */ + mask = (sp_digit)0 - ((sp_digit)1 - diff); /* all-1 if ==, else 0 */ + + for (j = 0; j < 32; j++) { + r[j] |= table[e][j] & mask; + } + } +} +#endif /* !WC_NO_CACHE_RESISTANT */ /* Modular exponentiate a to the e mod m. (r = a^e mod m) * * r A single precision number that is the result of the operation. @@ -1448,8 +1483,6 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -1652,6 +1685,7 @@ extern void sp_2048_mont_reduce_avx2_32(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_2048_mont_mul_avx2_32(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_2048_mul_avx2_32(r, a, b); sp_2048_mont_reduce_avx2_32(r, m, mp); } @@ -1668,6 +1702,7 @@ SP_NOINLINE static void sp_2048_mont_mul_avx2_32(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_2048_mont_sqr_avx2_32(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_2048_sqr_avx2_32(r, a); sp_2048_mont_reduce_avx2_32(r, m, mp); } @@ -1710,7 +1745,6 @@ static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digi int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -1918,10 +1952,9 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (*outLen < 256) { err = MP_TO_E; } @@ -1953,6 +1986,13 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { sp_2048_from_mp(m, 32, mm); +#ifdef HAVE_INTEL_AVX2 + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; +#endif + if (e == 0x10001) { int i; sp_digit mp; @@ -1967,8 +2007,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { /* r = a ^ 0x10000 => r = a squared 16 times */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i = 15; i >= 0; i--) { sp_2048_mont_sqr_avx2_32(r, r, m, mp); } @@ -1999,8 +2038,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } else if (e == 0x3) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { if (err == MP_OKAY) { sp_2048_sqr_avx2_32(r, ah); err = sp_2048_mod_32_cond(r, r, m); @@ -2042,8 +2080,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, XMEMCPY(r, a, sizeof(sp_digit) * 32); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i--; i>=0; i--) { sp_2048_mont_sqr_avx2_32(r, r, m, mp); if (((e >> i) & 1) == 1) { @@ -2081,6 +2118,11 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(a, NULL, DYNAMIC_TYPE_RSA); return err; @@ -2115,8 +2157,6 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, sp_digit* r = NULL; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)pm; (void)qm; (void)dpm; @@ -2214,10 +2254,9 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)dm; (void)mm; @@ -2238,6 +2277,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } SP_ALLOC_VAR(sp_digit, a, 16 * 11, NULL, DYNAMIC_TYPE_RSA); + if (err == MP_OKAY) { p = a + 32 * 2; q = p + 16; @@ -2253,9 +2293,11 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_2048_mod_exp_avx2_16(tmpa, a, dp, 1024, p, 1); - } else #endif err = sp_2048_mod_exp_16(tmpa, a, dp, 1024, p, 1); @@ -2263,10 +2305,8 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { sp_2048_from_mp(dq, 16, dqm); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) err = sp_2048_mod_exp_avx2_16(tmpb, a, dq, 1024, q, 1); - } else #endif err = sp_2048_mod_exp_16(tmpb, a, dq, 1024, q, 1); @@ -2275,8 +2315,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { c = sp_2048_sub_in_place_16(tmpa, tmpb); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { c += sp_2048_cond_add_avx2_16(tmpa, tmpa, p, c); sp_2048_cond_add_avx2_16(tmpa, tmpa, p, c); } @@ -2289,29 +2328,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, sp_2048_from_mp(qi, 16, qim); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_2048_mul_avx2_16(tmpa, tmpa, qi); - } else #endif - { sp_2048_mul_16(tmpa, tmpa, qi); - } err = sp_2048_mod_16(tmpa, tmpa, p); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_2048_mul_avx2_16(tmpa, q, tmpa); - } else #endif - { sp_2048_mul_16(tmpa, q, tmpa); - } XMEMSET(&tmpb[16], 0, sizeof(sp_digit) * 16); sp_2048_add_32(r, tmpb, tmpa); @@ -2319,6 +2350,11 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_ZEROFREE_VAR(sp_digit, a, 16 * 11, NULL, DYNAMIC_TYPE_RSA); return err; @@ -2350,7 +2386,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -2375,7 +2411,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 32; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -2418,8 +2454,6 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, #endif int expBits = mp_count_bits(exp); - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 2048) { err = MP_READ_E; } @@ -2445,8 +2479,9 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_2048_mod_exp_avx2_32(r, b, e, expBits, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -2500,7 +2535,6 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -2618,8 +2652,6 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -2738,8 +2770,6 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 2048) { err = MP_READ_E; } @@ -2767,8 +2797,10 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, if (base->used == 1 && base->dp[0] == 2 && m[31] == (sp_digit)-1) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_2048_mod_exp_2_avx2_32(r, e, (int)expLen * 8, m); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -2779,8 +2811,10 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_2048_mod_exp_avx2_32(r, b, e, (int)expLen * 8, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -2827,8 +2861,6 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, #endif int expBits = mp_count_bits(exp); - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 1024) { err = MP_READ_E; } @@ -2854,8 +2886,9 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_2048_mod_exp_avx2_16(r, b, e, expBits, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -2941,7 +2974,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -2976,7 +3009,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -3189,10 +3222,10 @@ extern void sp_3072_sqr_avx2_48(sp_digit* r, const sp_digit* a); */ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -3200,7 +3233,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } #ifdef __cplusplus @@ -3221,8 +3254,6 @@ static void sp_3072_mont_norm_24(sp_digit* r, const sp_digit* m) { XMEMSET(r, 0, sizeof(sp_digit) * 24); - ASSERT_SAVED_VECTOR_REGISTERS(); - /* r = 2^n mod m */ sp_3072_sub_in_place_24(r, m); } @@ -3312,7 +3343,6 @@ extern sp_digit div_3072_word_asm_24(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_3072_word_24(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -3331,7 +3361,6 @@ static WC_INLINE sp_digit div_3072_word_24(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -3399,8 +3428,6 @@ static WC_INLINE int sp_3072_div_24(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[23]; @@ -3453,18 +3480,38 @@ static WC_INLINE int sp_3072_div_24(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_3072_mod_24(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_3072_div_24(a, m, NULL, r); } -#ifdef __cplusplus -extern "C" { -#endif -extern void sp_3072_get_from_table_24(sp_digit* r, sp_digit** table, int idx); -#ifdef __cplusplus -} -#endif +#ifndef WC_NO_CACHE_RESISTANT +static void sp_3072_get_from_table_24(sp_digit* r, + sp_digit** table, int idx) +{ + int e, j; + sp_digit mask; + sp_digit diff; + for (j = 0; j < 24; j++) { + r[j] = 0; + } + + for (e = 0; e < 32; e++) { + /* Constant-time: mask = (e == idx) ? ~0 : 0 + * diff = e ^ idx is 0 iff equal. + * (diff | -diff) has its sign bit set iff diff != 0. + * Shift to get 1/0, subtract from 1 to invert, negate to mask. + */ + diff = (sp_digit)(e ^ idx); + diff = (diff | ((sp_digit)0 - diff)) + >> (sizeof(sp_digit) * 8 - 1); /* 1 if !=, 0 if == */ + mask = (sp_digit)0 - ((sp_digit)1 - diff); /* all-1 if ==, else 0 */ + + for (j = 0; j < 24; j++) { + r[j] |= table[e][j] & mask; + } + } +} +#endif /* !WC_NO_CACHE_RESISTANT */ /* Modular exponentiate a to the e mod m. (r = a^e mod m) * * r A single precision number that is the result of the operation. @@ -3491,8 +3538,6 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -3661,6 +3706,7 @@ extern void sp_3072_mont_reduce_avx2_24(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_3072_mont_mul_avx2_24(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_3072_mul_avx2_24(r, a, b); sp_3072_mont_reduce_avx2_24(r, m, mp); } @@ -3677,6 +3723,7 @@ SP_NOINLINE static void sp_3072_mont_mul_avx2_24(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_3072_mont_sqr_avx2_24(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_3072_sqr_avx2_24(r, a); sp_3072_mont_reduce_avx2_24(r, m, mp); } @@ -3718,7 +3765,6 @@ static int sp_3072_mod_exp_avx2_24(sp_digit* r, const sp_digit* a, const sp_digi int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -3881,8 +3927,6 @@ static void sp_3072_mont_norm_48(sp_digit* r, const sp_digit* m) { XMEMSET(r, 0, sizeof(sp_digit) * 48); - ASSERT_SAVED_VECTOR_REGISTERS(); - /* r = 2^n mod m */ sp_3072_sub_in_place_48(r, m); } @@ -3966,7 +4010,6 @@ extern sp_digit div_3072_word_asm_48(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_3072_word_48(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -3985,7 +4028,6 @@ static WC_INLINE sp_digit div_3072_word_48(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -4016,8 +4058,6 @@ static WC_INLINE int sp_3072_div_48_cond(const sp_digit* a, const sp_digit* d, s word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[47]; @@ -4076,7 +4116,6 @@ static WC_INLINE int sp_3072_div_48_cond(const sp_digit* a, const sp_digit* d, s static WC_INLINE int sp_3072_mod_48_cond(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_3072_div_48_cond(a, m, NULL, r); } @@ -4146,8 +4185,6 @@ static WC_INLINE int sp_3072_div_48(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[47]; @@ -4201,19 +4238,39 @@ static WC_INLINE int sp_3072_div_48(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_3072_div_48(a, m, NULL, r); } #endif /* WOLFSSL_HAVE_SP_DH || !WOLFSSL_RSA_PUBLIC_ONLY */ -#ifdef __cplusplus -extern "C" { -#endif -extern void sp_3072_get_from_table_48(sp_digit* r, sp_digit** table, int idx); -#ifdef __cplusplus -} -#endif +#ifndef WC_NO_CACHE_RESISTANT +static void sp_3072_get_from_table_48(sp_digit* r, + sp_digit** table, int idx) +{ + int e, j; + sp_digit mask; + sp_digit diff; + for (j = 0; j < 48; j++) { + r[j] = 0; + } + + for (e = 0; e < 16; e++) { + /* Constant-time: mask = (e == idx) ? ~0 : 0 + * diff = e ^ idx is 0 iff equal. + * (diff | -diff) has its sign bit set iff diff != 0. + * Shift to get 1/0, subtract from 1 to invert, negate to mask. + */ + diff = (sp_digit)(e ^ idx); + diff = (diff | ((sp_digit)0 - diff)) + >> (sizeof(sp_digit) * 8 - 1); /* 1 if !=, 0 if == */ + mask = (sp_digit)0 - ((sp_digit)1 - diff); /* all-1 if ==, else 0 */ + + for (j = 0; j < 48; j++) { + r[j] |= table[e][j] & mask; + } + } +} +#endif /* !WC_NO_CACHE_RESISTANT */ /* Modular exponentiate a to the e mod m. (r = a^e mod m) * * r A single precision number that is the result of the operation. @@ -4240,8 +4297,6 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -4392,6 +4447,7 @@ extern void sp_3072_mont_reduce_avx2_48(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_3072_mont_mul_avx2_48(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_3072_mul_avx2_48(r, a, b); sp_3072_mont_reduce_avx2_48(r, m, mp); } @@ -4408,6 +4464,7 @@ SP_NOINLINE static void sp_3072_mont_mul_avx2_48(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_3072_mont_sqr_avx2_48(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_3072_sqr_avx2_48(r, a); sp_3072_mont_reduce_avx2_48(r, m, mp); } @@ -4450,7 +4507,6 @@ static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digi int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -4606,10 +4662,9 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (*outLen < 384) { err = MP_TO_E; } @@ -4641,6 +4696,13 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { sp_3072_from_mp(m, 48, mm); +#ifdef HAVE_INTEL_AVX2 + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; +#endif + if (e == 0x10001) { int i; sp_digit mp; @@ -4655,8 +4717,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { /* r = a ^ 0x10000 => r = a squared 16 times */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i = 15; i >= 0; i--) { sp_3072_mont_sqr_avx2_48(r, r, m, mp); } @@ -4687,8 +4748,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } else if (e == 0x3) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { if (err == MP_OKAY) { sp_3072_sqr_avx2_48(r, ah); err = sp_3072_mod_48_cond(r, r, m); @@ -4730,8 +4790,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, XMEMCPY(r, a, sizeof(sp_digit) * 48); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i--; i>=0; i--) { sp_3072_mont_sqr_avx2_48(r, r, m, mp); if (((e >> i) & 1) == 1) { @@ -4769,6 +4828,11 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(a, NULL, DYNAMIC_TYPE_RSA); return err; @@ -4803,8 +4867,6 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, sp_digit* r = NULL; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)pm; (void)qm; (void)dpm; @@ -4902,10 +4964,9 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)dm; (void)mm; @@ -4926,6 +4987,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } SP_ALLOC_VAR(sp_digit, a, 24 * 11, NULL, DYNAMIC_TYPE_RSA); + if (err == MP_OKAY) { p = a + 48 * 2; q = p + 24; @@ -4941,9 +5003,11 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_3072_mod_exp_avx2_24(tmpa, a, dp, 1536, p, 1); - } else #endif err = sp_3072_mod_exp_24(tmpa, a, dp, 1536, p, 1); @@ -4951,10 +5015,8 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { sp_3072_from_mp(dq, 24, dqm); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) err = sp_3072_mod_exp_avx2_24(tmpb, a, dq, 1536, q, 1); - } else #endif err = sp_3072_mod_exp_24(tmpb, a, dq, 1536, q, 1); @@ -4963,8 +5025,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { c = sp_3072_sub_in_place_24(tmpa, tmpb); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { c += sp_3072_cond_add_avx2_24(tmpa, tmpa, p, c); sp_3072_cond_add_avx2_24(tmpa, tmpa, p, c); } @@ -4977,29 +5038,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, sp_3072_from_mp(qi, 24, qim); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_3072_mul_avx2_24(tmpa, tmpa, qi); - } else #endif - { sp_3072_mul_24(tmpa, tmpa, qi); - } err = sp_3072_mod_24(tmpa, tmpa, p); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_3072_mul_avx2_24(tmpa, q, tmpa); - } else #endif - { sp_3072_mul_24(tmpa, q, tmpa); - } XMEMSET(&tmpb[24], 0, sizeof(sp_digit) * 24); sp_3072_add_48(r, tmpb, tmpa); @@ -5007,6 +5060,11 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_ZEROFREE_VAR(sp_digit, a, 24 * 11, NULL, DYNAMIC_TYPE_RSA); return err; @@ -5038,7 +5096,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 48; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -5063,7 +5121,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 48; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -5106,8 +5164,6 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, #endif int expBits = mp_count_bits(exp); - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 3072) { err = MP_READ_E; } @@ -5133,8 +5189,9 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_3072_mod_exp_avx2_48(r, b, e, expBits, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -5188,7 +5245,6 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -5306,8 +5362,6 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -5426,8 +5480,6 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 3072) { err = MP_READ_E; } @@ -5455,8 +5507,10 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, if (base->used == 1 && base->dp[0] == 2 && m[47] == (sp_digit)-1) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_3072_mod_exp_2_avx2_48(r, e, (int)expLen * 8, m); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -5467,8 +5521,10 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_3072_mod_exp_avx2_48(r, b, e, (int)expLen * 8, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -5515,8 +5571,6 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, #endif int expBits = mp_count_bits(exp); - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 1536) { err = MP_READ_E; } @@ -5542,8 +5596,9 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_3072_mod_exp_avx2_24(r, b, e, expBits, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -5629,7 +5684,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -5664,7 +5719,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -5793,10 +5848,10 @@ extern void sp_4096_sqr_avx2_64(sp_digit* r, const sp_digit* a); */ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) { - sp_digit x; - sp_digit b; + sp_uint64 x; + sp_uint64 b; - b = a[0]; + b = (sp_uint64)a[0]; x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ x *= 2 - b * x; /* here x*a==1 mod 2**8 */ x *= 2 - b * x; /* here x*a==1 mod 2**16 */ @@ -5804,7 +5859,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x *= 2 - b * x; /* here x*a==1 mod 2**64 */ /* rho = -1/m mod b */ - *rho = (sp_digit)0 - x; + *rho = (sp_digit)((sp_int64)0 - (sp_int64)x); } #ifdef __cplusplus @@ -5825,8 +5880,6 @@ static void sp_4096_mont_norm_64(sp_digit* r, const sp_digit* m) { XMEMSET(r, 0, sizeof(sp_digit) * 64); - ASSERT_SAVED_VECTOR_REGISTERS(); - /* r = 2^n mod m */ sp_4096_sub_in_place_64(r, m); } @@ -5910,7 +5963,6 @@ extern sp_digit div_4096_word_asm_64(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_4096_word_64(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -5929,7 +5981,6 @@ static WC_INLINE sp_digit div_4096_word_64(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -5960,8 +6011,6 @@ static WC_INLINE int sp_4096_div_64_cond(const sp_digit* a, const sp_digit* d, s word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[63]; @@ -6020,7 +6069,6 @@ static WC_INLINE int sp_4096_div_64_cond(const sp_digit* a, const sp_digit* d, s static WC_INLINE int sp_4096_mod_64_cond(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_4096_div_64_cond(a, m, NULL, r); } @@ -6090,8 +6138,6 @@ static WC_INLINE int sp_4096_div_64(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[63]; @@ -6145,19 +6191,39 @@ static WC_INLINE int sp_4096_div_64(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_4096_mod_64(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_4096_div_64(a, m, NULL, r); } #endif /* WOLFSSL_HAVE_SP_DH || !WOLFSSL_RSA_PUBLIC_ONLY */ -#ifdef __cplusplus -extern "C" { -#endif -extern void sp_4096_get_from_table_64(sp_digit* r, sp_digit** table, int idx); -#ifdef __cplusplus -} -#endif +#ifndef WC_NO_CACHE_RESISTANT +static void sp_4096_get_from_table_64(sp_digit* r, + sp_digit** table, int idx) +{ + int e, j; + sp_digit mask; + sp_digit diff; + for (j = 0; j < 64; j++) { + r[j] = 0; + } + + for (e = 0; e < 16; e++) { + /* Constant-time: mask = (e == idx) ? ~0 : 0 + * diff = e ^ idx is 0 iff equal. + * (diff | -diff) has its sign bit set iff diff != 0. + * Shift to get 1/0, subtract from 1 to invert, negate to mask. + */ + diff = (sp_digit)(e ^ idx); + diff = (diff | ((sp_digit)0 - diff)) + >> (sizeof(sp_digit) * 8 - 1); /* 1 if !=, 0 if == */ + mask = (sp_digit)0 - ((sp_digit)1 - diff); /* all-1 if ==, else 0 */ + + for (j = 0; j < 64; j++) { + r[j] |= table[e][j] & mask; + } + } +} +#endif /* !WC_NO_CACHE_RESISTANT */ /* Modular exponentiate a to the e mod m. (r = a^e mod m) * * r A single precision number that is the result of the operation. @@ -6184,8 +6250,6 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -6336,6 +6400,7 @@ extern void sp_4096_mont_reduce_avx2_64(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_4096_mont_mul_avx2_64(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_4096_mul_avx2_64(r, a, b); sp_4096_mont_reduce_avx2_64(r, m, mp); } @@ -6352,6 +6417,7 @@ SP_NOINLINE static void sp_4096_mont_mul_avx2_64(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_4096_mont_sqr_avx2_64(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_4096_sqr_avx2_64(r, a); sp_4096_mont_reduce_avx2_64(r, m, mp); } @@ -6394,7 +6460,6 @@ static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digi int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -6550,10 +6615,9 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (*outLen < 512) { err = MP_TO_E; } @@ -6585,6 +6649,13 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { sp_4096_from_mp(m, 64, mm); +#ifdef HAVE_INTEL_AVX2 + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; +#endif + if (e == 0x10001) { int i; sp_digit mp; @@ -6599,8 +6670,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, if (err == MP_OKAY) { /* r = a ^ 0x10000 => r = a squared 16 times */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i = 15; i >= 0; i--) { sp_4096_mont_sqr_avx2_64(r, r, m, mp); } @@ -6631,8 +6701,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } else if (e == 0x3) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { if (err == MP_OKAY) { sp_4096_sqr_avx2_64(r, ah); err = sp_4096_mod_64_cond(r, r, m); @@ -6674,8 +6743,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, XMEMCPY(r, a, sizeof(sp_digit) * 64); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { for (i--; i>=0; i--) { sp_4096_mont_sqr_avx2_64(r, r, m, mp); if (((e >> i) & 1) == 1) { @@ -6713,6 +6781,11 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(a, NULL, DYNAMIC_TYPE_RSA); return err; @@ -6747,8 +6820,6 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, sp_digit* r = NULL; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)pm; (void)qm; (void)dpm; @@ -6846,10 +6917,9 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)dm; (void)mm; @@ -6870,6 +6940,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } SP_ALLOC_VAR(sp_digit, a, 32 * 11, NULL, DYNAMIC_TYPE_RSA); + if (err == MP_OKAY) { p = a + 64 * 2; q = p + 32; @@ -6885,9 +6956,11 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_2048_mod_exp_avx2_32(tmpa, a, dp, 2048, p, 1); - } else #endif err = sp_2048_mod_exp_32(tmpa, a, dp, 2048, p, 1); @@ -6895,10 +6968,8 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { sp_4096_from_mp(dq, 32, dqm); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) err = sp_2048_mod_exp_avx2_32(tmpb, a, dq, 2048, q, 1); - } else #endif err = sp_2048_mod_exp_32(tmpb, a, dq, 2048, q, 1); @@ -6907,8 +6978,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, if (err == MP_OKAY) { c = sp_2048_sub_in_place_32(tmpa, tmpb); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { c += sp_4096_cond_add_avx2_32(tmpa, tmpa, p, c); sp_4096_cond_add_avx2_32(tmpa, tmpa, p, c); } @@ -6921,29 +6991,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, sp_2048_from_mp(qi, 32, qim); #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_2048_mul_avx2_32(tmpa, tmpa, qi); - } else #endif - { sp_2048_mul_32(tmpa, tmpa, qi); - } err = sp_2048_mod_32(tmpa, tmpa, p); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_2048_mul_avx2_32(tmpa, q, tmpa); - } else #endif - { sp_2048_mul_32(tmpa, q, tmpa); - } XMEMSET(&tmpb[32], 0, sizeof(sp_digit) * 32); sp_4096_add_64(r, tmpb, tmpa); @@ -6951,6 +7013,11 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_ZEROFREE_VAR(sp_digit, a, 32 * 11, NULL, DYNAMIC_TYPE_RSA); return err; @@ -6982,7 +7049,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -7007,7 +7074,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 64; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -7050,8 +7117,6 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, #endif int expBits = mp_count_bits(exp); - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 4096) { err = MP_READ_E; } @@ -7077,8 +7142,9 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_4096_mod_exp_avx2_64(r, b, e, expBits, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -7132,7 +7198,6 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, int err = MP_OKAY; ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -7250,8 +7315,6 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, byte y; int err = MP_OKAY; - ASSERT_SAVED_VECTOR_REGISTERS(); - if (bits == 0) { err = MP_VAL; } @@ -7370,8 +7433,6 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - if (mp_count_bits(base) > 4096) { err = MP_READ_E; } @@ -7399,8 +7460,10 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, if (base->used == 1 && base->dp[0] == 2 && m[63] == (sp_digit)-1) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_4096_mod_exp_2_avx2_64(r, e, (int)expLen * 8, m); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -7411,8 +7474,10 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_4096_mod_exp_avx2_64(r, b, e, (int)expLen * 8, m, 0); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -7586,8 +7651,6 @@ static int sp_256_mod_mul_norm_4(sp_digit* r, const sp_digit* a, const sp_digit* int64_t a32[8]; int64_t o; - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; a32[0] = (int64_t)(a[0] & 0xffffffff); @@ -7647,10 +7710,10 @@ static int sp_256_mod_mul_norm_4(sp_digit* r, const sp_digit* a, const sp_digit* t[5] += t[4] >> 32; t[4] &= 0xffffffff; t[6] += t[5] >> 32; t[5] &= 0xffffffff; t[7] += t[6] >> 32; t[6] &= 0xffffffff; - r[0] = (sp_digit)((t[1] << 32) | t[0]); - r[1] = (sp_digit)((t[3] << 32) | t[2]); - r[2] = (sp_digit)((t[5] << 32) | t[4]); - r[3] = (sp_digit)((t[7] << 32) | t[6]); + r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]); + r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]); + r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]); + r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]); return MP_OKAY; } @@ -7681,7 +7744,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -7716,7 +7779,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -7782,7 +7845,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 4; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -7807,7 +7870,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 4; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -7914,7 +7977,7 @@ static void sp_256_mont_inv_4(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 4); for (i=254; i>=0; i--) { sp_256_mont_sqr_4(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_256_mont_mul_4(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 4); @@ -8885,7 +8948,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v) } else if (++j < 4) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -9088,7 +9151,7 @@ static void sp_256_mont_inv_avx2_4(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 4); for (i=254; i>=0; i--) { sp_256_mont_sqr_avx2_4(t, t, p256_mod, p256_mp_mod); - if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_256_mont_mul_avx2_4(t, t, a, p256_mod, p256_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 4); @@ -10872,8 +10935,9 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_avx2_4(point, point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -10911,6 +10975,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_256, point, 2, heap, DYNAMIC_TYPE_ECC); @@ -10935,29 +11000,26 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_256_ecc_mulmod_avx2_4(point, point, k, 0, 0, heap); - } else #endif err = sp_256_ecc_mulmod_4(point, point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_proj_point_add_avx2_4(point, point, addP, tmp); - } else #endif sp_256_proj_point_add_4(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_map_avx2_4(point, point, tmp); - } else #endif sp_256_map_4(point, point, tmp); @@ -10966,6 +11028,11 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_4(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, heap, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, heap, DYNAMIC_TYPE_ECC); @@ -11404,7 +11471,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v) } else if (++j < 4) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -23624,8 +23691,9 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_base_avx2_4(point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -23662,6 +23730,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_256, point, 2, NULL, DYNAMIC_TYPE_ECC); @@ -23685,29 +23754,26 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_256_ecc_mulmod_base_avx2_4(point, k, 0, 0, heap); - } else #endif err = sp_256_ecc_mulmod_base_4(point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_proj_point_add_avx2_4(point, point, addP, tmp); - } else #endif sp_256_proj_point_add_4(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_map_avx2_4(point, point, tmp); - } else #endif sp_256_map_4(point, point, tmp); @@ -23716,6 +23782,11 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_4(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, NULL, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, NULL, DYNAMIC_TYPE_ECC); @@ -23827,6 +23898,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif (void)heap; @@ -23847,9 +23919,11 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_256_ecc_mulmod_base_avx2_4(point, k, 1, 1, NULL); - } else #endif err = sp_256_ecc_mulmod_base_4(point, k, 1, 1, NULL); @@ -23858,8 +23932,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { err = sp_256_ecc_mulmod_avx2_4(infinity, point, p256_order, 1, 1, NULL); } @@ -23874,6 +23947,11 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) } #endif +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + if (err == MP_OKAY) { err = sp_256_to_mp(k, priv); } @@ -24035,8 +24113,9 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, sp_256_point_from_ecc_point_4(point, pub); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_avx2_4(point, point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -24148,7 +24227,6 @@ extern sp_digit div_256_word_asm_4(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_256_word_4(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -24167,7 +24245,6 @@ static WC_INLINE sp_digit div_256_word_4(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -24220,8 +24297,6 @@ static WC_INLINE int sp_256_div_4(const sp_digit* a, const sp_digit* d, sp_digit word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[3]; @@ -24274,7 +24349,6 @@ static WC_INLINE int sp_256_div_4(const sp_digit* a, const sp_digit* d, sp_digit static WC_INLINE int sp_256_mod_4(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_256_div_4(a, m, NULL, r); } @@ -24288,7 +24362,6 @@ static WC_INLINE int sp_256_mod_4(sp_digit* r, const sp_digit* a, */ static void sp_256_mont_mul_order_4(sp_digit* r, const sp_digit* a, const sp_digit* b) { - ASSERT_SAVED_VECTOR_REGISTERS(); sp_256_mul_4(r, a, b); sp_256_mont_reduce_order_4(r, p256_order, p256_mp_order); } @@ -24314,7 +24387,6 @@ static const word64 p256_order_low[2] = { */ static void sp_256_mont_sqr_order_4(sp_digit* r, const sp_digit* a) { - ASSERT_SAVED_VECTOR_REGISTERS(); sp_256_sqr_4(r, a); sp_256_mont_reduce_order_4(r, p256_order, p256_mp_order); } @@ -24330,8 +24402,6 @@ static void sp_256_mont_sqr_n_order_4(sp_digit* r, const sp_digit* a, int n) { int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - sp_256_mont_sqr_order_4(r, a); for (i=1; i= sizeof(*sp_ctx) ? -1 : 1]; @@ -24420,8 +24488,6 @@ static void sp_256_mont_inv_order_4(sp_digit* r, const sp_digit* a, sp_digit* t4 = td + 6 * 4; int i; - ASSERT_SAVED_VECTOR_REGISTERS(); - /* t = a^2 */ sp_256_mont_sqr_order_4(t, a); /* t = a^3 = t * a */ @@ -24554,7 +24620,6 @@ static void sp_256_mont_sqr_n_order_avx2_4(sp_digit* r, const sp_digit* a, int n int i; ASSERT_SAVED_VECTOR_REGISTERS(); - sp_256_mont_sqr_order_avx2_4(r, a); for (i=1; i= sizeof(*sp_ctx) ? -1 : 1]; @@ -24644,7 +24708,6 @@ static void sp_256_mont_inv_order_avx2_4(sp_digit* r, const sp_digit* a, int i; ASSERT_SAVED_VECTOR_REGISTERS(); - /* t = a^2 */ sp_256_mont_sqr_order_avx2_4(t, a); /* t = a^3 = t * a */ @@ -24776,14 +24839,16 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, sp_digit* kInv = k; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif /* Conv k to Montgomery form (mod order) */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) sp_256_mul_avx2_4(k, k, p256_norm_order); - } else #endif sp_256_mul_4(k, k, p256_norm_order); @@ -24793,10 +24858,8 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, /* kInv = 1/k mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_mont_inv_order_avx2_4(kInv, k, tmp); - } else #endif sp_256_mont_inv_order_4(kInv, k, tmp); @@ -24804,10 +24867,8 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = r * x + e */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_mul_avx2_4(x, x, r); - } else #endif sp_256_mul_4(x, x, r); @@ -24825,16 +24886,19 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = s * k^-1 mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_256_mont_mul_order_avx2_4(s, s, kInv); - } else #endif sp_256_mont_mul_order_4(s, s, kInv); sp_256_norm_4(s); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + return err; } @@ -24899,8 +24963,10 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_base_avx2_4(point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25148,8 +25214,9 @@ static void sp_256_add_points_4(sp_point_256* p1, const sp_point_256* p2, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_proj_point_add_avx2_4(p1, p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25158,8 +25225,10 @@ static void sp_256_add_points_4(sp_point_256* p1, const sp_point_256* p2, if (sp_256_iszero_4(p1->x) && sp_256_iszero_4(p1->y)) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_proj_point_dbl_avx2_4(p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25197,8 +25266,9 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, #ifndef WOLFSSL_SP_SMALL #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mod_inv_avx2_4(s, s, p256_order); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25209,8 +25279,9 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mul_avx2_4(s, s, p256_norm_order); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25224,10 +25295,11 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, #ifdef WOLFSSL_SP_SMALL #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_inv_order_avx2_4(s, s, tmp); sp_256_mont_mul_order_avx2_4(u1, u1, s); sp_256_mont_mul_order_avx2_4(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25239,9 +25311,10 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, #else #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_mul_order_avx2_4(u1, u1, s); sp_256_mont_mul_order_avx2_4(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25252,8 +25325,9 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, #endif /* WOLFSSL_SP_SMALL */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_base_avx2_4(p1, u1, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25267,8 +25341,9 @@ static int sp_256_calc_vfy_point_4(sp_point_256* p1, sp_point_256* p2, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_avx2_4(p2, p2, u2, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25354,16 +25429,18 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = r.z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_sqr_avx2_4(p1->z, p1->z, p256_mod, p256_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif sp_256_mont_sqr_4(p1->z, p1->z, p256_mod, p256_mp_mod); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_mul_avx2_4(u1, u2, p1->z, p256_mod, p256_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25388,9 +25465,11 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = (r + 1*order).z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_mul_avx2_4(u1, u2, p1->z, p256_mod, p256_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25698,8 +25777,9 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, /* Point * order = infinity */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_avx2_4(p, pub, p256_order, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25716,8 +25796,10 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, /* Base * private = point */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_256_ecc_mulmod_base_avx2_4(p, priv, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25782,8 +25864,9 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_proj_point_add_avx2_4(p, p, q, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25838,8 +25921,9 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_proj_point_dbl_avx2_4(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25891,8 +25975,9 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_map_avx2_4(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -25936,7 +26021,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { /* t2 = y ^ 0x2 */ sp_256_mont_sqr_avx2_4(t2, y, p256_mod, p256_mp_mod); /* t1 = y ^ 0x3 */ @@ -25966,6 +26051,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) /* t1 = y ^ 0xffffffff00000001000000000000000000000001 */ sp_256_mont_mul_avx2_4(t1, t1, y, p256_mod, p256_mp_mod); sp_256_mont_sqr_n_avx2_4(y, t1, 94, p256_mod, p256_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -26035,9 +26121,10 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) /* y = x^3 */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_256_mont_sqr_avx2_4(y, x, p256_mod, p256_mp_mod); sp_256_mont_mul_avx2_4(y, y, x, p256_mod, p256_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -26293,12 +26380,12 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* t[10] += t[9] >> 32; t[9] &= 0xffffffff; t[11] += t[10] >> 32; t[10] &= 0xffffffff; - r[0] = (sp_digit)((t[1] << 32) | t[0]); - r[1] = (sp_digit)((t[3] << 32) | t[2]); - r[2] = (sp_digit)((t[5] << 32) | t[4]); - r[3] = (sp_digit)((t[7] << 32) | t[6]); - r[4] = (sp_digit)((t[9] << 32) | t[8]); - r[5] = (sp_digit)((t[11] << 32) | t[10]); + r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]); + r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]); + r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]); + r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]); + r[4] = (sp_digit)(((sp_uint64)t[9] << 32) | (sp_uint64)t[8]); + r[5] = (sp_digit)(((sp_uint64)t[11] << 32) | (sp_uint64)t[10]); } SP_FREE_VAR(t, NULL, DYNAMIC_TYPE_ECC); @@ -26332,7 +26419,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -26367,7 +26454,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -26433,7 +26520,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 6; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -26458,7 +26545,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 6; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -26602,7 +26689,7 @@ static void sp_384_mont_inv_6(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 6); for (i=382; i>=0; i--) { sp_384_mont_sqr_6(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_384_mont_mul_6(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 6); @@ -27579,7 +27666,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v) } else if (++j < 6) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -27753,6 +27840,7 @@ extern void sp_384_mont_reduce_order_avx2_6(sp_digit* a, const sp_digit* m, sp_d SP_NOINLINE static void sp_384_mont_mul_avx2_6(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_384_mul_avx2_6(r, a, b); sp_384_mont_reduce_avx2_6(r, m, mp); } @@ -27769,6 +27857,7 @@ SP_NOINLINE static void sp_384_mont_mul_avx2_6(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_384_mont_sqr_avx2_6(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_384_sqr_avx2_6(r, a); sp_384_mont_reduce_avx2_6(r, m, mp); } @@ -27810,7 +27899,7 @@ static void sp_384_mont_inv_avx2_6(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 6); for (i=382; i>=0; i--) { sp_384_mont_sqr_avx2_6(t, t, p384_mod, p384_mp_mod); - if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_384_mont_mul_avx2_6(t, t, a, p384_mod, p384_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 6); @@ -29625,8 +29714,9 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_avx2_6(point, point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -29664,6 +29754,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_384, point, 2, heap, DYNAMIC_TYPE_ECC); @@ -29688,29 +29779,26 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_384_ecc_mulmod_avx2_6(point, point, k, 0, 0, heap); - } else #endif err = sp_384_ecc_mulmod_6(point, point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_proj_point_add_avx2_6(point, point, addP, tmp); - } else #endif sp_384_proj_point_add_6(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_map_avx2_6(point, point, tmp); - } else #endif sp_384_map_6(point, point, tmp); @@ -29719,6 +29807,11 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_6(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, heap, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, heap, DYNAMIC_TYPE_ECC); @@ -30157,7 +30250,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v) } else if (++j < 6) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -48191,8 +48284,9 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_base_avx2_6(point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -48229,6 +48323,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_384, point, 2, NULL, DYNAMIC_TYPE_ECC); @@ -48252,29 +48347,26 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_384_ecc_mulmod_base_avx2_6(point, k, 0, 0, heap); - } else #endif err = sp_384_ecc_mulmod_base_6(point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_proj_point_add_avx2_6(point, point, addP, tmp); - } else #endif sp_384_proj_point_add_6(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_map_avx2_6(point, point, tmp); - } else #endif sp_384_map_6(point, point, tmp); @@ -48283,6 +48375,11 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_6(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, NULL, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, NULL, DYNAMIC_TYPE_ECC); @@ -48394,6 +48491,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif (void)heap; @@ -48414,9 +48512,11 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_384_ecc_mulmod_base_avx2_6(point, k, 1, 1, NULL); - } else #endif err = sp_384_ecc_mulmod_base_6(point, k, 1, 1, NULL); @@ -48425,8 +48525,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { err = sp_384_ecc_mulmod_avx2_6(infinity, point, p384_order, 1, 1, NULL); } @@ -48441,6 +48540,11 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) } #endif +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + if (err == MP_OKAY) { err = sp_384_to_mp(k, priv); } @@ -48602,8 +48706,9 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, sp_384_point_from_ecc_point_6(point, pub); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_avx2_6(point, point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -48715,7 +48820,6 @@ extern sp_digit div_384_word_asm_6(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_384_word_6(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -48734,7 +48838,6 @@ static WC_INLINE sp_digit div_384_word_6(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -48789,8 +48892,6 @@ static WC_INLINE int sp_384_div_6(const sp_digit* a, const sp_digit* d, sp_digit word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[5]; @@ -48843,7 +48944,6 @@ static WC_INLINE int sp_384_div_6(const sp_digit* a, const sp_digit* d, sp_digit static WC_INLINE int sp_384_mod_6(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_384_div_6(a, m, NULL, r); } @@ -49201,14 +49301,16 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, sp_digit* kInv = k; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif /* Conv k to Montgomery form (mod order) */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) sp_384_mul_avx2_6(k, k, p384_norm_order); - } else #endif sp_384_mul_6(k, k, p384_norm_order); @@ -49218,10 +49320,8 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, /* kInv = 1/k mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_mont_inv_order_avx2_6(kInv, k, tmp); - } else #endif sp_384_mont_inv_order_6(kInv, k, tmp); @@ -49229,10 +49329,8 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = r * x + e */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_mul_avx2_6(x, x, r); - } else #endif sp_384_mul_6(x, x, r); @@ -49250,16 +49348,19 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = s * k^-1 mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_384_mont_mul_order_avx2_6(s, s, kInv); - } else #endif sp_384_mont_mul_order_6(s, s, kInv); sp_384_norm_6(s); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + return err; } @@ -49324,8 +49425,10 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_base_avx2_6(point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49662,8 +49765,9 @@ static void sp_384_add_points_6(sp_point_384* p1, const sp_point_384* p2, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_proj_point_add_avx2_6(p1, p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49672,8 +49776,10 @@ static void sp_384_add_points_6(sp_point_384* p1, const sp_point_384* p2, if (sp_384_iszero_6(p1->x) && sp_384_iszero_6(p1->y)) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_proj_point_dbl_avx2_6(p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49717,8 +49823,9 @@ static int sp_384_calc_vfy_point_6(sp_point_384* p1, sp_point_384* p2, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mul_avx2_6(s, s, p384_norm_order); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49732,10 +49839,11 @@ static int sp_384_calc_vfy_point_6(sp_point_384* p1, sp_point_384* p2, #ifdef WOLFSSL_SP_SMALL #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_inv_order_avx2_6(s, s, tmp); sp_384_mont_mul_order_avx2_6(u1, u1, s); sp_384_mont_mul_order_avx2_6(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49747,9 +49855,10 @@ static int sp_384_calc_vfy_point_6(sp_point_384* p1, sp_point_384* p2, #else #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_mul_order_avx2_6(u1, u1, s); sp_384_mont_mul_order_avx2_6(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49760,8 +49869,9 @@ static int sp_384_calc_vfy_point_6(sp_point_384* p1, sp_point_384* p2, #endif /* WOLFSSL_SP_SMALL */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_base_avx2_6(p1, u1, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49775,8 +49885,9 @@ static int sp_384_calc_vfy_point_6(sp_point_384* p1, sp_point_384* p2, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_avx2_6(p2, p2, u2, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49862,16 +49973,18 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = r.z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_sqr_avx2_6(p1->z, p1->z, p384_mod, p384_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif sp_384_mont_sqr_6(p1->z, p1->z, p384_mod, p384_mp_mod); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_mul_avx2_6(u1, u2, p1->z, p384_mod, p384_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -49896,9 +50009,11 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = (r + 1*order).z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_mul_avx2_6(u1, u2, p1->z, p384_mod, p384_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50206,8 +50321,9 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, /* Point * order = infinity */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_avx2_6(p, pub, p384_order, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50224,8 +50340,10 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, /* Base * private = point */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_384_ecc_mulmod_base_avx2_6(p, priv, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50290,8 +50408,9 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_proj_point_add_avx2_6(p, p, q, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50346,8 +50465,9 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_proj_point_dbl_avx2_6(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50399,8 +50519,9 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_map_avx2_6(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50450,7 +50571,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { /* t2 = y ^ 0x2 */ sp_384_mont_sqr_avx2_6(t2, y, p384_mod, p384_mp_mod); /* t1 = y ^ 0x3 */ @@ -50505,6 +50626,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) sp_384_mont_mul_avx2_6(t1, y, t2, p384_mod, p384_mp_mod); /* t2 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffc00000000000000040000000 */ sp_384_mont_sqr_n_avx2_6(y, t1, 30, p384_mod, p384_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50599,9 +50721,10 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) /* y = x^3 */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_384_mont_sqr_avx2_6(y, x, p384_mod, p384_mp_mod); sp_384_mont_mul_avx2_6(y, y, x, p384_mod, p384_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -50824,7 +50947,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -50859,7 +50982,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -50925,7 +51048,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -50950,7 +51073,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 9; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -51058,7 +51181,7 @@ static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 9); for (i=519; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 9); @@ -52054,7 +52177,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x3f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f); o -= 58; n >>= o; } @@ -52257,7 +52380,7 @@ static void sp_521_mont_inv_avx2_9(sp_digit* r, const sp_digit* a, sp_digit* td) XMEMCPY(t, a, sizeof(sp_digit) * 9); for (i=519; i>=0; i--) { sp_521_mont_sqr_avx2_9(t, t, p521_mod, p521_mp_mod); - if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_avx2_9(t, t, a, p521_mod, p521_mp_mod); } XMEMCPY(r, t, sizeof(sp_digit) * 9); @@ -54077,8 +54200,9 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_avx2_9(point, point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -54116,6 +54240,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_521, point, 2, heap, DYNAMIC_TYPE_ECC); @@ -54140,29 +54265,26 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_521_ecc_mulmod_avx2_9(point, point, k, 0, 0, heap); - } else #endif err = sp_521_ecc_mulmod_9(point, point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_proj_point_add_avx2_9(point, point, addP, tmp); - } else #endif sp_521_proj_point_add_9(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_map_avx2_9(point, point, tmp); - } else #endif sp_521_map_9(point, point, tmp); @@ -54171,6 +54293,11 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_9(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, heap, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, heap, DYNAMIC_TYPE_ECC); @@ -54735,7 +54862,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v) } else if (++j < 9) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -88829,8 +88956,9 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_base_avx2_9(point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -88867,6 +88995,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_521, point, 2, NULL, DYNAMIC_TYPE_ECC); @@ -88890,29 +89019,26 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_521_ecc_mulmod_base_avx2_9(point, k, 0, 0, heap); - } else #endif err = sp_521_ecc_mulmod_base_9(point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_proj_point_add_avx2_9(point, point, addP, tmp); - } else #endif sp_521_proj_point_add_9(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_map_avx2_9(point, point, tmp); - } else #endif sp_521_map_9(point, point, tmp); @@ -88921,6 +89047,11 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_9(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, NULL, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, NULL, DYNAMIC_TYPE_ECC); @@ -89033,6 +89164,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif (void)heap; @@ -89053,9 +89185,11 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + + if (saved_vector_registers) err = sp_521_ecc_mulmod_base_avx2_9(point, k, 1, 1, NULL); - } else #endif err = sp_521_ecc_mulmod_base_9(point, k, 1, 1, NULL); @@ -89064,8 +89198,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) { err = sp_521_ecc_mulmod_avx2_9(infinity, point, p521_order, 1, 1, NULL); } @@ -89080,6 +89213,11 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) } #endif +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + if (err == MP_OKAY) { err = sp_521_to_mp(k, priv); } @@ -89241,8 +89379,9 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, sp_521_point_from_ecc_point_9(point, pub); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_avx2_9(point, point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -89375,7 +89514,6 @@ extern sp_digit div_521_word_asm_9(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_521_word_9(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -89394,7 +89532,6 @@ static WC_INLINE sp_digit div_521_word_9(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -89453,8 +89590,6 @@ static WC_INLINE int sp_521_div_9(const sp_digit* a, const sp_digit* d, sp_digit word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = (d[8] << 55) | (d[7] >> 9); @@ -89509,7 +89644,6 @@ static WC_INLINE int sp_521_div_9(const sp_digit* a, const sp_digit* d, sp_digit static WC_INLINE int sp_521_mod_9(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_521_div_9(a, m, NULL, r); } @@ -89895,14 +90029,16 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, sp_digit* kInv = k; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif /* Conv k to Montgomery form (mod order) */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) sp_521_mul_avx2_9(k, k, p521_norm_order); - } else #endif sp_521_mul_9(k, k, p521_norm_order); @@ -89912,10 +90048,8 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, /* kInv = 1/k mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_mont_inv_order_avx2_9(kInv, k, tmp); - } else #endif sp_521_mont_inv_order_9(kInv, k, tmp); @@ -89923,10 +90057,8 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = r * x + e */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_mul_avx2_9(x, x, r); - } else #endif sp_521_mul_9(x, x, r); @@ -89944,16 +90076,19 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, /* s = s * k^-1 mod order */ #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_521_mont_mul_order_avx2_9(s, s, kInv); - } else #endif sp_521_mont_mul_order_9(s, s, kInv); sp_521_norm_9(s); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + return err; } @@ -90018,8 +90153,10 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_base_avx2_9(point, k, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90364,8 +90501,9 @@ static void sp_521_add_points_9(sp_point_521* p1, const sp_point_521* p2, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_proj_point_add_avx2_9(p1, p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90374,8 +90512,10 @@ static void sp_521_add_points_9(sp_point_521* p1, const sp_point_521* p2, if (sp_521_iszero_9(p1->x) && sp_521_iszero_9(p1->y)) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_proj_point_dbl_avx2_9(p1, p2, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90422,8 +90562,9 @@ static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2, { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mul_avx2_9(s, s, p521_norm_order); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90437,10 +90578,11 @@ static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2, #ifdef WOLFSSL_SP_SMALL #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_inv_order_avx2_9(s, s, tmp); sp_521_mont_mul_order_avx2_9(u1, u1, s); sp_521_mont_mul_order_avx2_9(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90452,9 +90594,10 @@ static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2, #else #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_mul_order_avx2_9(u1, u1, s); sp_521_mont_mul_order_avx2_9(u2, u2, s); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90465,8 +90608,9 @@ static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2, #endif /* WOLFSSL_SP_SMALL */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_base_avx2_9(p1, u1, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90480,8 +90624,9 @@ static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_avx2_9(p2, p2, u2, 0, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90571,16 +90716,18 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = r.z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_sqr_avx2_9(p1->z, p1->z, p521_mod, p521_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif sp_521_mont_sqr_9(p1->z, p1->z, p521_mod, p521_mp_mod); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_mul_avx2_9(u1, u2, p1->z, p521_mod, p521_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90605,9 +90752,11 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, /* u1 = (r + 1*order).z'.z' mod prime */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_mul_avx2_9(u1, u2, p1->z, p521_mod, p521_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90918,8 +91067,9 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, /* Point * order = infinity */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_avx2_9(p, pub, p521_order, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -90936,8 +91086,10 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, /* Base * private = point */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_521_ecc_mulmod_base_avx2_9(p, priv, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91002,8 +91154,9 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_proj_point_add_avx2_9(p, p, q, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91058,8 +91211,9 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_proj_point_dbl_avx2_9(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91111,8 +91265,9 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_map_avx2_9(p, p, tmp); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91161,16 +91316,17 @@ static int sp_521_mont_sqrt_9(sp_digit* y) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { int i; XMEMCPY(t, y, sizeof(sp_digit) * 9); for (i=518; i>=0; i--) { sp_521_mont_sqr_avx2_9(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_avx2_9(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 9); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91180,7 +91336,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) XMEMCPY(t, y, sizeof(sp_digit) * 9); for (i=518; i>=0; i--) { sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod); - if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64))) + if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64))) sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod); } XMEMCPY(y, t, sizeof(sp_digit) * 9); @@ -91220,9 +91376,10 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) /* y = x^3 */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { sp_521_mont_sqr_avx2_9(y, x, p521_mod, p521_mp_mod); sp_521_mont_mul_avx2_9(y, y, x, p521_mod, p521_mp_mod); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -91439,7 +91596,6 @@ extern sp_digit div_1024_word_asm_16(sp_digit d1, sp_digit d0, sp_digit div); static WC_INLINE sp_digit div_1024_word_16(sp_digit d1, sp_digit d0, sp_digit div) { - ASSERT_SAVED_VECTOR_REGISTERS(); #if _MSC_VER >= 1920 return _udiv128(d1, d0, div, NULL); #else @@ -91458,7 +91614,6 @@ static WC_INLINE sp_digit div_1024_word_16(sp_digit d1, sp_digit d0, sp_digit div) { register sp_digit r asm("rax"); - ASSERT_SAVED_VECTOR_REGISTERS(); __asm__ __volatile__ ( "divq %3" : "=a" (r) @@ -91526,8 +91681,6 @@ static WC_INLINE int sp_1024_div_16(const sp_digit* a, const sp_digit* d, sp_dig word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - (void)m; div = d[15]; @@ -91580,7 +91733,6 @@ static WC_INLINE int sp_1024_div_16(const sp_digit* a, const sp_digit* d, sp_dig static WC_INLINE int sp_1024_mod_16(sp_digit* r, const sp_digit* a, const sp_digit* m) { - ASSERT_SAVED_VECTOR_REGISTERS(); return sp_1024_div_16(a, m, NULL, r); } @@ -91702,7 +91854,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i] << s); + r[j] |= ((sp_uint64)a->dp[i] << s); r[j] &= 0xffffffffffffffffl; s = 64U - s; if (j + 1 >= size) { @@ -91737,7 +91889,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[0] = 0; for (i = 0; i < (unsigned int)a->used && j < size; i++) { - r[j] |= ((sp_digit)a->dp[i]) << s; + r[j] |= ((sp_uint64)a->dp[i]) << s; if (s + DIGIT_BIT >= 64) { r[j] &= 0xffffffffffffffffl; if (j + 1 >= size) { @@ -91803,7 +91955,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 16; i++) { - r->dp[j] |= (mp_digit)(a[i] << s); + r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s); r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; s = DIGIT_BIT - s; r->dp[++j] = (mp_digit)(a[i] >> s); @@ -91828,7 +91980,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r) r->dp[0] = 0; for (i = 0; i < 16; i++) { - r->dp[j] |= ((mp_digit)a[i]) << s; + r->dp[j] |= ((sp_uint64)a[i]) << s; if (s + 64 >= DIGIT_BIT) { #if DIGIT_BIT != 32 && DIGIT_BIT != 64 r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1; @@ -92890,7 +93042,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) } else if (++j < 16) { n = k[j]; - y |= (word8)((n << (64 - o)) & 0x7f); + y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f); o -= 57; n >>= o; } @@ -93052,6 +93204,7 @@ extern void sp_1024_mont_reduce_avx2_16(sp_digit* a, const sp_digit* m, sp_digit SP_NOINLINE static void sp_1024_mont_mul_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_1024_mul_avx2_16(r, a, b); sp_1024_mont_reduce_avx2_16(r, m, mp); } @@ -93068,6 +93221,7 @@ SP_NOINLINE static void sp_1024_mont_mul_avx2_16(sp_digit* r, const sp_digit* a, SP_NOINLINE static void sp_1024_mont_sqr_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* m, sp_digit mp) { + ASSERT_SAVED_VECTOR_REGISTERS(); sp_1024_sqr_avx2_16(r, a); sp_1024_mont_reduce_avx2_16(r, m, mp); } @@ -94831,8 +94985,9 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_ecc_mulmod_avx2_16(point, point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -98246,8 +98401,9 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_ecc_mulmod_base_avx2_16(point, k, map, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -98284,6 +98440,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int err = MP_OKAY; #ifdef HAVE_INTEL_AVX2 word32 cpuid_flags = cpuid_get_flags(); + int saved_vector_registers = 0; #endif SP_ALLOC_VAR(sp_point_1024, point, 2, NULL, DYNAMIC_TYPE_ECC); @@ -98307,29 +98464,26 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) + saved_vector_registers = 1; + if (saved_vector_registers) err = sp_1024_ecc_mulmod_base_avx2_16(point, k, 0, 0, heap); - } else #endif err = sp_1024_ecc_mulmod_base_16(point, k, 0, 0, heap); } if (err == MP_OKAY) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_1024_proj_point_add_avx2_16(point, point, addP, tmp); - } else #endif sp_1024_proj_point_add_16(point, point, addP, tmp); if (map) { #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + if (saved_vector_registers) sp_1024_map_avx2_16(point, point, tmp); - } else #endif sp_1024_map_16(point, point, tmp); @@ -98338,6 +98492,11 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_16(point, r); } +#ifdef HAVE_INTEL_AVX2 + if (saved_vector_registers) + RESTORE_VECTOR_REGISTERS(); +#endif + SP_FREE_VAR(k, NULL, DYNAMIC_TYPE_ECC); SP_FREE_VAR(point, NULL, DYNAMIC_TYPE_ECC); @@ -98382,9 +98541,10 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, sp_1024_point_from_ecc_point_16(point, gm); #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_gen_stripe_table_avx2_16(point, (sp_table_entry_1024*)table, t, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -98465,9 +98625,10 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #ifndef WOLFSSL_SP_SMALL #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_ecc_mulmod_stripe_avx2_16(point, point, (const sp_table_entry_1024*)table, k, map, 0, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -100536,11 +100697,11 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) { + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_ModExp_Fp_star_avx2_1024(base, exp, res); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -102138,11 +102299,11 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) { + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_Pairing_avx2_1024(pm, qm, res); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -103263,11 +103424,11 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) { + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_Pairing_gen_precomp_avx2_1024(pm, table, len); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -103299,11 +103460,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* re word32 cpuid_flags = cpuid_get_flags(); #endif - ASSERT_SAVED_VECTOR_REGISTERS(); - #ifdef HAVE_INTEL_AVX2 - if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) { + if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_Pairing_precomp_avx2_1024(pm, qm, res, table, len); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -103494,8 +103655,9 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, /* Point * order = infinity */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_ecc_mulmod_avx2_16(p, pub, p1024_order, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif @@ -103512,8 +103674,10 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, /* Base * private = point */ #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags) && - IS_INTEL_AVX2(cpuid_flags)) { + IS_INTEL_AVX2(cpuid_flags) && + (SAVE_VECTOR_REGISTERS2() == 0)) { err = sp_1024_ecc_mulmod_base_avx2_16(p, priv, 1, 1, heap); + RESTORE_VECTOR_REGISTERS(); } else #endif diff --git a/wolfcrypt/src/sp_x86_64_asm.S b/wolfcrypt/src/sp_x86_64_asm.S index 7aaae4bb60..fbd2de64a8 100644 --- a/wolfcrypt/src/sp_x86_64_asm.S +++ b/wolfcrypt/src/sp_x86_64_asm.S @@ -9983,1173 +9983,6 @@ _sp_2048_cmp_16: #ifndef __APPLE__ .size sp_2048_cmp_16,.-sp_2048_cmp_16 #endif /* __APPLE__ */ -#ifndef WC_NO_CACHE_RESISTANT -#ifndef __APPLE__ -.text -.globl sp_2048_get_from_table_16 -.type sp_2048_get_from_table_16,@function -.align 16 -sp_2048_get_from_table_16: -#else -.section __TEXT,__text -.globl _sp_2048_get_from_table_16 -.p2align 4 -_sp_2048_get_from_table_16: -#endif /* __APPLE__ */ - movq $0x01, %rax - movd %rdx, %xmm10 - movd %rax, %xmm11 - pxor %xmm13, %xmm13 - pshufd $0x00, %xmm11, %xmm11 - pshufd $0x00, %xmm10, %xmm10 - # START: 0-7 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 0-7 - # START: 8-15 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - # END: 8-15 - repz retq -#ifndef __APPLE__ -.size sp_2048_get_from_table_16,.-sp_2048_get_from_table_16 -#endif /* __APPLE__ */ -#endif /* !WC_NO_CACHE_RESISTANT */ #ifdef HAVE_INTEL_AVX2 /* Reduce the number back to 2048 bits using Montgomery reduction. * @@ -13501,4621 +12334,6 @@ _sp_2048_cmp_32: #ifndef __APPLE__ .size sp_2048_cmp_32,.-sp_2048_cmp_32 #endif /* __APPLE__ */ -#ifndef WC_NO_CACHE_RESISTANT -#ifndef __APPLE__ -.text -.globl sp_2048_get_from_table_32 -.type sp_2048_get_from_table_32,@function -.align 16 -sp_2048_get_from_table_32: -#else -.section __TEXT,__text -.globl _sp_2048_get_from_table_32 -.p2align 4 -_sp_2048_get_from_table_32: -#endif /* __APPLE__ */ - movq $0x01, %rax - movd %rdx, %xmm10 - movd %rax, %xmm11 - pxor %xmm13, %xmm13 - pshufd $0x00, %xmm11, %xmm11 - pshufd $0x00, %xmm10, %xmm10 - # START: 0-7 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 32 - movq 256(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 33 - movq 264(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 34 - movq 272(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 35 - movq 280(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 36 - movq 288(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 37 - movq 296(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 38 - movq 304(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 39 - movq 312(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 40 - movq 320(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 41 - movq 328(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 42 - movq 336(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 43 - movq 344(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 44 - movq 352(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 45 - movq 360(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 46 - movq 368(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 47 - movq 376(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 48 - movq 384(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 49 - movq 392(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 50 - movq 400(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 51 - movq 408(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 52 - movq 416(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 53 - movq 424(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 54 - movq 432(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 55 - movq 440(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 56 - movq 448(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 57 - movq 456(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 58 - movq 464(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 59 - movq 472(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 60 - movq 480(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 61 - movq 488(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 62 - movq 496(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 63 - movq 504(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 0-7 - # START: 8-15 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 32 - movq 256(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 33 - movq 264(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 34 - movq 272(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 35 - movq 280(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 36 - movq 288(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 37 - movq 296(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 38 - movq 304(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 39 - movq 312(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 40 - movq 320(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 41 - movq 328(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 42 - movq 336(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 43 - movq 344(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 44 - movq 352(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 45 - movq 360(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 46 - movq 368(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 47 - movq 376(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 48 - movq 384(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 49 - movq 392(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 50 - movq 400(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 51 - movq 408(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 52 - movq 416(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 53 - movq 424(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 54 - movq 432(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 55 - movq 440(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 56 - movq 448(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 57 - movq 456(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 58 - movq 464(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 59 - movq 472(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 60 - movq 480(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 61 - movq 488(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 62 - movq 496(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 63 - movq 504(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 8-15 - # START: 16-23 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 32 - movq 256(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 33 - movq 264(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 34 - movq 272(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 35 - movq 280(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 36 - movq 288(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 37 - movq 296(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 38 - movq 304(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 39 - movq 312(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 40 - movq 320(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 41 - movq 328(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 42 - movq 336(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 43 - movq 344(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 44 - movq 352(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 45 - movq 360(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 46 - movq 368(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 47 - movq 376(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 48 - movq 384(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 49 - movq 392(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 50 - movq 400(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 51 - movq 408(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 52 - movq 416(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 53 - movq 424(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 54 - movq 432(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 55 - movq 440(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 56 - movq 448(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 57 - movq 456(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 58 - movq 464(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 59 - movq 472(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 60 - movq 480(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 61 - movq 488(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 62 - movq 496(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 63 - movq 504(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 16-23 - # START: 24-31 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 32 - movq 256(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 33 - movq 264(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 34 - movq 272(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 35 - movq 280(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 36 - movq 288(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 37 - movq 296(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 38 - movq 304(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 39 - movq 312(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 40 - movq 320(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 41 - movq 328(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 42 - movq 336(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 43 - movq 344(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 44 - movq 352(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 45 - movq 360(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 46 - movq 368(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 47 - movq 376(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 48 - movq 384(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 49 - movq 392(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 50 - movq 400(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 51 - movq 408(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 52 - movq 416(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 53 - movq 424(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 54 - movq 432(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 55 - movq 440(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 56 - movq 448(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 57 - movq 456(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 58 - movq 464(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 59 - movq 472(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 60 - movq 480(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 61 - movq 488(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 62 - movq 496(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 63 - movq 504(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - # END: 24-31 - repz retq -#ifndef __APPLE__ -.size sp_2048_get_from_table_32,.-sp_2048_get_from_table_32 -#endif /* __APPLE__ */ -#endif /* !WC_NO_CACHE_RESISTANT */ #ifdef HAVE_INTEL_AVX2 /* Reduce the number back to 2048 bits using Montgomery reduction. * @@ -32549,1761 +26767,6 @@ _sp_3072_cmp_24: #ifndef __APPLE__ .size sp_3072_cmp_24,.-sp_3072_cmp_24 #endif /* __APPLE__ */ -#ifndef WC_NO_CACHE_RESISTANT -#ifndef __APPLE__ -.text -.globl sp_3072_get_from_table_24 -.type sp_3072_get_from_table_24,@function -.align 16 -sp_3072_get_from_table_24: -#else -.section __TEXT,__text -.globl _sp_3072_get_from_table_24 -.p2align 4 -_sp_3072_get_from_table_24: -#endif /* __APPLE__ */ - movq $0x01, %rax - movd %rdx, %xmm10 - movd %rax, %xmm11 - pxor %xmm13, %xmm13 - pshufd $0x00, %xmm11, %xmm11 - pshufd $0x00, %xmm10, %xmm10 - # START: 0-7 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 0-7 - # START: 8-15 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 8-15 - # START: 16-23 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 16 - movq 128(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 17 - movq 136(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 18 - movq 144(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 19 - movq 152(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 20 - movq 160(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 21 - movq 168(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 22 - movq 176(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 23 - movq 184(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 24 - movq 192(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 25 - movq 200(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 26 - movq 208(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 27 - movq 216(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 28 - movq 224(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 29 - movq 232(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 30 - movq 240(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 31 - movq 248(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - # END: 16-23 - repz retq -#ifndef __APPLE__ -.size sp_3072_get_from_table_24,.-sp_3072_get_from_table_24 -#endif /* __APPLE__ */ -#endif /* !WC_NO_CACHE_RESISTANT */ #ifdef HAVE_INTEL_AVX2 /* Reduce the number back to 3072 bits using Montgomery reduction. * @@ -37626,1813 +30089,6 @@ _sp_3072_cmp_48: #ifndef __APPLE__ .size sp_3072_cmp_48,.-sp_3072_cmp_48 #endif /* __APPLE__ */ -#ifndef WC_NO_CACHE_RESISTANT -#ifndef __APPLE__ -.text -.globl sp_3072_get_from_table_48 -.type sp_3072_get_from_table_48,@function -.align 16 -sp_3072_get_from_table_48: -#else -.section __TEXT,__text -.globl _sp_3072_get_from_table_48 -.p2align 4 -_sp_3072_get_from_table_48: -#endif /* __APPLE__ */ - movq $0x01, %rax - movd %rdx, %xmm10 - movd %rax, %xmm11 - pxor %xmm13, %xmm13 - pshufd $0x00, %xmm11, %xmm11 - pshufd $0x00, %xmm10, %xmm10 - # START: 0-7 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 0-7 - # START: 8-15 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 8-15 - # START: 16-23 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 16-23 - # START: 24-31 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 24-31 - # START: 32-39 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 32-39 - # START: 40-47 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - # END: 40-47 - repz retq -#ifndef __APPLE__ -.size sp_3072_get_from_table_48,.-sp_3072_get_from_table_48 -#endif /* __APPLE__ */ -#endif /* !WC_NO_CACHE_RESISTANT */ #ifdef HAVE_INTEL_AVX2 /* Reduce the number back to 3072 bits using Montgomery reduction. * @@ -50237,2413 +40893,6 @@ _sp_4096_cmp_64: #ifndef __APPLE__ .size sp_4096_cmp_64,.-sp_4096_cmp_64 #endif /* __APPLE__ */ -#ifndef WC_NO_CACHE_RESISTANT -#ifndef __APPLE__ -.text -.globl sp_4096_get_from_table_64 -.type sp_4096_get_from_table_64,@function -.align 16 -sp_4096_get_from_table_64: -#else -.section __TEXT,__text -.globl _sp_4096_get_from_table_64 -.p2align 4 -_sp_4096_get_from_table_64: -#endif /* __APPLE__ */ - movq $0x01, %rax - movd %rdx, %xmm10 - movd %rax, %xmm11 - pxor %xmm13, %xmm13 - pshufd $0x00, %xmm11, %xmm11 - pshufd $0x00, %xmm10, %xmm10 - # START: 0-7 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 0-7 - # START: 8-15 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x40, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 8-15 - # START: 16-23 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x80, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 16-23 - # START: 24-31 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0xc0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 24-31 - # START: 32-39 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x100, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 32-39 - # START: 40-47 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x140, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 40-47 - # START: 48-55 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x180, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - addq $0x40, %rdi - # END: 48-55 - # START: 56-63 - pxor %xmm13, %xmm13 - pxor %xmm4, %xmm4 - pxor %xmm5, %xmm5 - pxor %xmm6, %xmm6 - pxor %xmm7, %xmm7 - # ENTRY: 0 - movq (%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 1 - movq 8(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 2 - movq 16(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 3 - movq 24(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 4 - movq 32(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 5 - movq 40(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 6 - movq 48(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 7 - movq 56(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 8 - movq 64(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 9 - movq 72(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 10 - movq 80(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 11 - movq 88(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 12 - movq 96(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 13 - movq 104(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 14 - movq 112(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - # ENTRY: 15 - movq 120(%rsi), %rcx - addq $0x1c0, %rcx - movdqu %xmm13, %xmm12 - pcmpeqd %xmm10, %xmm12 - movdqu (%rcx), %xmm0 - movdqu 16(%rcx), %xmm1 - movdqu 32(%rcx), %xmm2 - movdqu 48(%rcx), %xmm3 - pand %xmm12, %xmm0 - pand %xmm12, %xmm1 - pand %xmm12, %xmm2 - pand %xmm12, %xmm3 - por %xmm0, %xmm4 - por %xmm1, %xmm5 - por %xmm2, %xmm6 - por %xmm3, %xmm7 - paddd %xmm11, %xmm13 - movdqu %xmm4, (%rdi) - movdqu %xmm5, 16(%rdi) - movdqu %xmm6, 32(%rdi) - movdqu %xmm7, 48(%rdi) - # END: 56-63 - repz retq -#ifndef __APPLE__ -.size sp_4096_get_from_table_64,.-sp_4096_get_from_table_64 -#endif /* __APPLE__ */ -#endif /* !WC_NO_CACHE_RESISTANT */ #ifdef HAVE_INTEL_AVX2 /* Reduce the number back to 4096 bits using Montgomery reduction. * diff --git a/wolfcrypt/src/sp_x86_64_asm.asm b/wolfcrypt/src/sp_x86_64_asm.asm index cdf5789407..2ad38bb43b 100644 --- a/wolfcrypt/src/sp_x86_64_asm.asm +++ b/wolfcrypt/src/sp_x86_64_asm.asm @@ -9709,1180 +9709,6 @@ sp_2048_cmp_16 PROC ret sp_2048_cmp_16 ENDP _TEXT ENDS -IFNDEF WC_NO_CACHE_RESISTANT -_TEXT SEGMENT READONLY PARA -sp_2048_get_from_table_16 PROC - sub rsp, 128 - movdqu OWORD PTR [rsp], xmm6 - movdqu OWORD PTR [rsp+16], xmm7 - movdqu OWORD PTR [rsp+32], xmm8 - movdqu OWORD PTR [rsp+48], xmm9 - movdqu OWORD PTR [rsp+64], xmm10 - movdqu OWORD PTR [rsp+80], xmm11 - movdqu OWORD PTR [rsp+96], xmm12 - movdqu OWORD PTR [rsp+112], xmm13 - mov rax, 1 - movd xmm10, r8 - movd xmm11, rax - pxor xmm13, xmm13 - pshufd xmm11, xmm11, 0 - pshufd xmm10, xmm10, 0 - ; START: 0-7 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 0-7 - ; START: 8-15 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - ; END: 8-15 - movdqu xmm6, OWORD PTR [rsp] - movdqu xmm7, OWORD PTR [rsp+16] - movdqu xmm8, OWORD PTR [rsp+32] - movdqu xmm9, OWORD PTR [rsp+48] - movdqu xmm10, OWORD PTR [rsp+64] - movdqu xmm11, OWORD PTR [rsp+80] - movdqu xmm12, OWORD PTR [rsp+96] - movdqu xmm13, OWORD PTR [rsp+112] - add rsp, 128 - ret -sp_2048_get_from_table_16 ENDP -_TEXT ENDS -ENDIF IFDEF HAVE_INTEL_AVX2 ; /* Reduce the number back to 2048 bits using Montgomery reduction. ; * @@ -13166,4628 +11992,6 @@ sp_2048_cmp_32 PROC ret sp_2048_cmp_32 ENDP _TEXT ENDS -IFNDEF WC_NO_CACHE_RESISTANT -_TEXT SEGMENT READONLY PARA -sp_2048_get_from_table_32 PROC - sub rsp, 128 - movdqu OWORD PTR [rsp], xmm6 - movdqu OWORD PTR [rsp+16], xmm7 - movdqu OWORD PTR [rsp+32], xmm8 - movdqu OWORD PTR [rsp+48], xmm9 - movdqu OWORD PTR [rsp+64], xmm10 - movdqu OWORD PTR [rsp+80], xmm11 - movdqu OWORD PTR [rsp+96], xmm12 - movdqu OWORD PTR [rsp+112], xmm13 - mov rax, 1 - movd xmm10, r8 - movd xmm11, rax - pxor xmm13, xmm13 - pshufd xmm11, xmm11, 0 - pshufd xmm10, xmm10, 0 - ; START: 0-7 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 32 - mov r9, QWORD PTR [rdx+256] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 33 - mov r9, QWORD PTR [rdx+264] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 34 - mov r9, QWORD PTR [rdx+272] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 35 - mov r9, QWORD PTR [rdx+280] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 36 - mov r9, QWORD PTR [rdx+288] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 37 - mov r9, QWORD PTR [rdx+296] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 38 - mov r9, QWORD PTR [rdx+304] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 39 - mov r9, QWORD PTR [rdx+312] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 40 - mov r9, QWORD PTR [rdx+320] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 41 - mov r9, QWORD PTR [rdx+328] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 42 - mov r9, QWORD PTR [rdx+336] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 43 - mov r9, QWORD PTR [rdx+344] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 44 - mov r9, QWORD PTR [rdx+352] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 45 - mov r9, QWORD PTR [rdx+360] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 46 - mov r9, QWORD PTR [rdx+368] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 47 - mov r9, QWORD PTR [rdx+376] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 48 - mov r9, QWORD PTR [rdx+384] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 49 - mov r9, QWORD PTR [rdx+392] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 50 - mov r9, QWORD PTR [rdx+400] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 51 - mov r9, QWORD PTR [rdx+408] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 52 - mov r9, QWORD PTR [rdx+416] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 53 - mov r9, QWORD PTR [rdx+424] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 54 - mov r9, QWORD PTR [rdx+432] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 55 - mov r9, QWORD PTR [rdx+440] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 56 - mov r9, QWORD PTR [rdx+448] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 57 - mov r9, QWORD PTR [rdx+456] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 58 - mov r9, QWORD PTR [rdx+464] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 59 - mov r9, QWORD PTR [rdx+472] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 60 - mov r9, QWORD PTR [rdx+480] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 61 - mov r9, QWORD PTR [rdx+488] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 62 - mov r9, QWORD PTR [rdx+496] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 63 - mov r9, QWORD PTR [rdx+504] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 0-7 - ; START: 8-15 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 32 - mov r9, QWORD PTR [rdx+256] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 33 - mov r9, QWORD PTR [rdx+264] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 34 - mov r9, QWORD PTR [rdx+272] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 35 - mov r9, QWORD PTR [rdx+280] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 36 - mov r9, QWORD PTR [rdx+288] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 37 - mov r9, QWORD PTR [rdx+296] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 38 - mov r9, QWORD PTR [rdx+304] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 39 - mov r9, QWORD PTR [rdx+312] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 40 - mov r9, QWORD PTR [rdx+320] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 41 - mov r9, QWORD PTR [rdx+328] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 42 - mov r9, QWORD PTR [rdx+336] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 43 - mov r9, QWORD PTR [rdx+344] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 44 - mov r9, QWORD PTR [rdx+352] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 45 - mov r9, QWORD PTR [rdx+360] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 46 - mov r9, QWORD PTR [rdx+368] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 47 - mov r9, QWORD PTR [rdx+376] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 48 - mov r9, QWORD PTR [rdx+384] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 49 - mov r9, QWORD PTR [rdx+392] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 50 - mov r9, QWORD PTR [rdx+400] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 51 - mov r9, QWORD PTR [rdx+408] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 52 - mov r9, QWORD PTR [rdx+416] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 53 - mov r9, QWORD PTR [rdx+424] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 54 - mov r9, QWORD PTR [rdx+432] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 55 - mov r9, QWORD PTR [rdx+440] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 56 - mov r9, QWORD PTR [rdx+448] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 57 - mov r9, QWORD PTR [rdx+456] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 58 - mov r9, QWORD PTR [rdx+464] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 59 - mov r9, QWORD PTR [rdx+472] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 60 - mov r9, QWORD PTR [rdx+480] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 61 - mov r9, QWORD PTR [rdx+488] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 62 - mov r9, QWORD PTR [rdx+496] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 63 - mov r9, QWORD PTR [rdx+504] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 8-15 - ; START: 16-23 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 32 - mov r9, QWORD PTR [rdx+256] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 33 - mov r9, QWORD PTR [rdx+264] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 34 - mov r9, QWORD PTR [rdx+272] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 35 - mov r9, QWORD PTR [rdx+280] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 36 - mov r9, QWORD PTR [rdx+288] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 37 - mov r9, QWORD PTR [rdx+296] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 38 - mov r9, QWORD PTR [rdx+304] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 39 - mov r9, QWORD PTR [rdx+312] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 40 - mov r9, QWORD PTR [rdx+320] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 41 - mov r9, QWORD PTR [rdx+328] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 42 - mov r9, QWORD PTR [rdx+336] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 43 - mov r9, QWORD PTR [rdx+344] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 44 - mov r9, QWORD PTR [rdx+352] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 45 - mov r9, QWORD PTR [rdx+360] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 46 - mov r9, QWORD PTR [rdx+368] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 47 - mov r9, QWORD PTR [rdx+376] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 48 - mov r9, QWORD PTR [rdx+384] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 49 - mov r9, QWORD PTR [rdx+392] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 50 - mov r9, QWORD PTR [rdx+400] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 51 - mov r9, QWORD PTR [rdx+408] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 52 - mov r9, QWORD PTR [rdx+416] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 53 - mov r9, QWORD PTR [rdx+424] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 54 - mov r9, QWORD PTR [rdx+432] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 55 - mov r9, QWORD PTR [rdx+440] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 56 - mov r9, QWORD PTR [rdx+448] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 57 - mov r9, QWORD PTR [rdx+456] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 58 - mov r9, QWORD PTR [rdx+464] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 59 - mov r9, QWORD PTR [rdx+472] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 60 - mov r9, QWORD PTR [rdx+480] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 61 - mov r9, QWORD PTR [rdx+488] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 62 - mov r9, QWORD PTR [rdx+496] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 63 - mov r9, QWORD PTR [rdx+504] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 16-23 - ; START: 24-31 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 32 - mov r9, QWORD PTR [rdx+256] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 33 - mov r9, QWORD PTR [rdx+264] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 34 - mov r9, QWORD PTR [rdx+272] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 35 - mov r9, QWORD PTR [rdx+280] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 36 - mov r9, QWORD PTR [rdx+288] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 37 - mov r9, QWORD PTR [rdx+296] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 38 - mov r9, QWORD PTR [rdx+304] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 39 - mov r9, QWORD PTR [rdx+312] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 40 - mov r9, QWORD PTR [rdx+320] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 41 - mov r9, QWORD PTR [rdx+328] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 42 - mov r9, QWORD PTR [rdx+336] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 43 - mov r9, QWORD PTR [rdx+344] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 44 - mov r9, QWORD PTR [rdx+352] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 45 - mov r9, QWORD PTR [rdx+360] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 46 - mov r9, QWORD PTR [rdx+368] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 47 - mov r9, QWORD PTR [rdx+376] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 48 - mov r9, QWORD PTR [rdx+384] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 49 - mov r9, QWORD PTR [rdx+392] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 50 - mov r9, QWORD PTR [rdx+400] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 51 - mov r9, QWORD PTR [rdx+408] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 52 - mov r9, QWORD PTR [rdx+416] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 53 - mov r9, QWORD PTR [rdx+424] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 54 - mov r9, QWORD PTR [rdx+432] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 55 - mov r9, QWORD PTR [rdx+440] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 56 - mov r9, QWORD PTR [rdx+448] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 57 - mov r9, QWORD PTR [rdx+456] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 58 - mov r9, QWORD PTR [rdx+464] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 59 - mov r9, QWORD PTR [rdx+472] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 60 - mov r9, QWORD PTR [rdx+480] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 61 - mov r9, QWORD PTR [rdx+488] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 62 - mov r9, QWORD PTR [rdx+496] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 63 - mov r9, QWORD PTR [rdx+504] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - ; END: 24-31 - movdqu xmm6, OWORD PTR [rsp] - movdqu xmm7, OWORD PTR [rsp+16] - movdqu xmm8, OWORD PTR [rsp+32] - movdqu xmm9, OWORD PTR [rsp+48] - movdqu xmm10, OWORD PTR [rsp+64] - movdqu xmm11, OWORD PTR [rsp+80] - movdqu xmm12, OWORD PTR [rsp+96] - movdqu xmm13, OWORD PTR [rsp+112] - add rsp, 128 - ret -sp_2048_get_from_table_32 ENDP -_TEXT ENDS -ENDIF IFDEF HAVE_INTEL_AVX2 ; /* Reduce the number back to 2048 bits using Montgomery reduction. ; * @@ -31834,1768 +26038,6 @@ sp_3072_cmp_24 PROC ret sp_3072_cmp_24 ENDP _TEXT ENDS -IFNDEF WC_NO_CACHE_RESISTANT -_TEXT SEGMENT READONLY PARA -sp_3072_get_from_table_24 PROC - sub rsp, 128 - movdqu OWORD PTR [rsp], xmm6 - movdqu OWORD PTR [rsp+16], xmm7 - movdqu OWORD PTR [rsp+32], xmm8 - movdqu OWORD PTR [rsp+48], xmm9 - movdqu OWORD PTR [rsp+64], xmm10 - movdqu OWORD PTR [rsp+80], xmm11 - movdqu OWORD PTR [rsp+96], xmm12 - movdqu OWORD PTR [rsp+112], xmm13 - mov rax, 1 - movd xmm10, r8 - movd xmm11, rax - pxor xmm13, xmm13 - pshufd xmm11, xmm11, 0 - pshufd xmm10, xmm10, 0 - ; START: 0-7 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 0-7 - ; START: 8-15 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 8-15 - ; START: 16-23 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 16 - mov r9, QWORD PTR [rdx+128] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 17 - mov r9, QWORD PTR [rdx+136] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 18 - mov r9, QWORD PTR [rdx+144] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 19 - mov r9, QWORD PTR [rdx+152] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 20 - mov r9, QWORD PTR [rdx+160] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 21 - mov r9, QWORD PTR [rdx+168] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 22 - mov r9, QWORD PTR [rdx+176] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 23 - mov r9, QWORD PTR [rdx+184] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 24 - mov r9, QWORD PTR [rdx+192] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 25 - mov r9, QWORD PTR [rdx+200] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 26 - mov r9, QWORD PTR [rdx+208] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 27 - mov r9, QWORD PTR [rdx+216] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 28 - mov r9, QWORD PTR [rdx+224] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 29 - mov r9, QWORD PTR [rdx+232] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 30 - mov r9, QWORD PTR [rdx+240] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 31 - mov r9, QWORD PTR [rdx+248] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - ; END: 16-23 - movdqu xmm6, OWORD PTR [rsp] - movdqu xmm7, OWORD PTR [rsp+16] - movdqu xmm8, OWORD PTR [rsp+32] - movdqu xmm9, OWORD PTR [rsp+48] - movdqu xmm10, OWORD PTR [rsp+64] - movdqu xmm11, OWORD PTR [rsp+80] - movdqu xmm12, OWORD PTR [rsp+96] - movdqu xmm13, OWORD PTR [rsp+112] - add rsp, 128 - ret -sp_3072_get_from_table_24 ENDP -_TEXT ENDS -ENDIF IFDEF HAVE_INTEL_AVX2 ; /* Reduce the number back to 3072 bits using Montgomery reduction. ; * @@ -36850,1820 +29292,6 @@ sp_3072_cmp_48 PROC ret sp_3072_cmp_48 ENDP _TEXT ENDS -IFNDEF WC_NO_CACHE_RESISTANT -_TEXT SEGMENT READONLY PARA -sp_3072_get_from_table_48 PROC - sub rsp, 128 - movdqu OWORD PTR [rsp], xmm6 - movdqu OWORD PTR [rsp+16], xmm7 - movdqu OWORD PTR [rsp+32], xmm8 - movdqu OWORD PTR [rsp+48], xmm9 - movdqu OWORD PTR [rsp+64], xmm10 - movdqu OWORD PTR [rsp+80], xmm11 - movdqu OWORD PTR [rsp+96], xmm12 - movdqu OWORD PTR [rsp+112], xmm13 - mov rax, 1 - movd xmm10, r8 - movd xmm11, rax - pxor xmm13, xmm13 - pshufd xmm11, xmm11, 0 - pshufd xmm10, xmm10, 0 - ; START: 0-7 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 0-7 - ; START: 8-15 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 8-15 - ; START: 16-23 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 16-23 - ; START: 24-31 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 24-31 - ; START: 32-39 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 32-39 - ; START: 40-47 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - ; END: 40-47 - movdqu xmm6, OWORD PTR [rsp] - movdqu xmm7, OWORD PTR [rsp+16] - movdqu xmm8, OWORD PTR [rsp+32] - movdqu xmm9, OWORD PTR [rsp+48] - movdqu xmm10, OWORD PTR [rsp+64] - movdqu xmm11, OWORD PTR [rsp+80] - movdqu xmm12, OWORD PTR [rsp+96] - movdqu xmm13, OWORD PTR [rsp+112] - add rsp, 128 - ret -sp_3072_get_from_table_48 ENDP -_TEXT ENDS -ENDIF IFDEF HAVE_INTEL_AVX2 ; /* Reduce the number back to 3072 bits using Montgomery reduction. ; * @@ -49221,2420 +39849,6 @@ sp_4096_cmp_64 PROC ret sp_4096_cmp_64 ENDP _TEXT ENDS -IFNDEF WC_NO_CACHE_RESISTANT -_TEXT SEGMENT READONLY PARA -sp_4096_get_from_table_64 PROC - sub rsp, 128 - movdqu OWORD PTR [rsp], xmm6 - movdqu OWORD PTR [rsp+16], xmm7 - movdqu OWORD PTR [rsp+32], xmm8 - movdqu OWORD PTR [rsp+48], xmm9 - movdqu OWORD PTR [rsp+64], xmm10 - movdqu OWORD PTR [rsp+80], xmm11 - movdqu OWORD PTR [rsp+96], xmm12 - movdqu OWORD PTR [rsp+112], xmm13 - mov rax, 1 - movd xmm10, r8 - movd xmm11, rax - pxor xmm13, xmm13 - pshufd xmm11, xmm11, 0 - pshufd xmm10, xmm10, 0 - ; START: 0-7 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 0-7 - ; START: 8-15 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 64 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 8-15 - ; START: 16-23 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 128 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 16-23 - ; START: 24-31 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 192 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 24-31 - ; START: 32-39 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 256 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 32-39 - ; START: 40-47 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 320 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 40-47 - ; START: 48-55 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 384 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - add rcx, 64 - ; END: 48-55 - ; START: 56-63 - pxor xmm13, xmm13 - pxor xmm4, xmm4 - pxor xmm5, xmm5 - pxor xmm6, xmm6 - pxor xmm7, xmm7 - ; ENTRY: 0 - mov r9, QWORD PTR [rdx] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 1 - mov r9, QWORD PTR [rdx+8] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 2 - mov r9, QWORD PTR [rdx+16] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 3 - mov r9, QWORD PTR [rdx+24] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 4 - mov r9, QWORD PTR [rdx+32] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 5 - mov r9, QWORD PTR [rdx+40] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 6 - mov r9, QWORD PTR [rdx+48] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 7 - mov r9, QWORD PTR [rdx+56] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 8 - mov r9, QWORD PTR [rdx+64] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 9 - mov r9, QWORD PTR [rdx+72] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 10 - mov r9, QWORD PTR [rdx+80] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 11 - mov r9, QWORD PTR [rdx+88] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 12 - mov r9, QWORD PTR [rdx+96] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 13 - mov r9, QWORD PTR [rdx+104] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 14 - mov r9, QWORD PTR [rdx+112] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - ; ENTRY: 15 - mov r9, QWORD PTR [rdx+120] - add r9, 448 - movdqu xmm12, xmm13 - pcmpeqd xmm12, xmm10 - movdqu xmm0, OWORD PTR [r9] - movdqu xmm1, OWORD PTR [r9+16] - movdqu xmm2, OWORD PTR [r9+32] - movdqu xmm3, OWORD PTR [r9+48] - pand xmm0, xmm12 - pand xmm1, xmm12 - pand xmm2, xmm12 - pand xmm3, xmm12 - por xmm4, xmm0 - por xmm5, xmm1 - por xmm6, xmm2 - por xmm7, xmm3 - paddd xmm13, xmm11 - movdqu OWORD PTR [rcx], xmm4 - movdqu OWORD PTR [rcx+16], xmm5 - movdqu OWORD PTR [rcx+32], xmm6 - movdqu OWORD PTR [rcx+48], xmm7 - ; END: 56-63 - movdqu xmm6, OWORD PTR [rsp] - movdqu xmm7, OWORD PTR [rsp+16] - movdqu xmm8, OWORD PTR [rsp+32] - movdqu xmm9, OWORD PTR [rsp+48] - movdqu xmm10, OWORD PTR [rsp+64] - movdqu xmm11, OWORD PTR [rsp+80] - movdqu xmm12, OWORD PTR [rsp+96] - movdqu xmm13, OWORD PTR [rsp+112] - add rsp, 128 - ret -sp_4096_get_from_table_64 ENDP -_TEXT ENDS -ENDIF IFDEF HAVE_INTEL_AVX2 ; /* Reduce the number back to 4096 bits using Montgomery reduction. ; * diff --git a/wolfcrypt/src/wolfmath.c b/wolfcrypt/src/wolfmath.c index 06fb8ed017..f073be133e 100644 --- a/wolfcrypt/src/wolfmath.c +++ b/wolfcrypt/src/wolfmath.c @@ -43,12 +43,13 @@ #if !defined(NO_BIG_INT) || defined(WOLFSSL_SP_MATH) -#if (!defined(WC_NO_CACHE_RESISTANT) && \ - ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ - (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))) || \ - ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \ - !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \ - defined(OPENSSL_ALL) && defined(WC_PROTECT_ENCRYPTED_MEM)) +#if !defined(WC_NO_GLOBAL_OBJECT_POINTERS) && \ + ((!defined(WC_NO_CACHE_RESISTANT) && \ + ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ + (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))) || \ + ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \ + !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \ + defined(OPENSSL_ALL) && defined(WC_PROTECT_ENCRYPTED_MEM))) /* all off / all on pointer addresses for constant calculations */ /* ecc.c uses same table */ diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 329c88cffd..cd3275650b 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -44767,7 +44767,9 @@ static wc_test_ret_t ed25519_test_check_key(void) 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, }; - /* Y-ordinate value equal to prime - 1. */ + /* Y-ordinate value equal to prime - 1. Older FIPS modules accept + * this as a valid key; the current source rejects it as an order-2 + * point. */ WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = { 0x40, 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff, @@ -44775,6 +44777,15 @@ static wc_test_ret_t ed25519_test_check_key(void) 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, }; + /* RFC 8032 section 7.1 test-vector public key: a genuinely valid + * Ed25519 point used as a positive control. */ + WOLFSSL_SMALL_STACK_STATIC const byte key_good[] = { + 0x40, + 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7, + 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a, + 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25, + 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a, + }; ed25519_key key; int ret; int res = 0; @@ -44807,9 +44818,26 @@ static wc_test_ret_t ed25519_test_check_key(void) } } if (res == 0) { - /* Load good public key only and perform checks. */ ret = wc_ed25519_import_public(key_y_is_p_minus_1, ED25519_PUB_KEY_SIZE + 1, &key); +#if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0) + /* y = p - 1 is an order-2 point; check_key rejects it because + * h*A is the neutral element for small-order public keys and + * forged signatures would otherwise verify. */ + if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + res = WC_TEST_RET_ENC_NC; + } +#else + /* Older FIPS modules accept this order-2 point. */ + if (ret != 0) { + res = WC_TEST_RET_ENC_NC; + } +#endif + } + if (res == 0) { + /* Positive control: a real Ed25519 public key must be accepted. */ + ret = wc_ed25519_import_public(key_good, ED25519_PUB_KEY_SIZE + 1, + &key); if (ret != 0) { res = WC_TEST_RET_ENC_NC; } @@ -46484,7 +46512,9 @@ static wc_test_ret_t ed448_test_check_key(void) 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff }; - /* Y-ordinate value equal to prime - 1. */ + /* Y-ordinate value equal to prime - 1. Older FIPS modules accept + * this as a valid key; the current source rejects it as an order-2 + * point. */ WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = { 0x40, 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff, @@ -46496,6 +46526,19 @@ static wc_test_ret_t ed448_test_check_key(void) 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff }; + /* RFC 8032 section 7.4 test-vector public key: a genuinely valid + * Ed448 point used as a positive control. */ + WOLFSSL_SMALL_STACK_STATIC const byte key_good[] = { + 0x40, + 0x5f,0xd7,0x44,0x9b,0x59,0xb4,0x61,0xfd, + 0x2c,0xe7,0x87,0xec,0x61,0x6a,0xd4,0x6a, + 0x1d,0xa1,0x34,0x24,0x85,0xa7,0x0e,0x1f, + 0x8a,0x0e,0xa7,0x5d,0x80,0xe9,0x67,0x78, + 0xed,0xf1,0x24,0x76,0x9b,0x46,0xc7,0x06, + 0x1b,0xd6,0x78,0x3d,0xf1,0xe5,0x0f,0x6c, + 0xd1,0xfa,0x1a,0xbe,0xaf,0xe8,0x25,0x61, + 0x80 + }; ed448_key key; int ret; int res = 0; @@ -46528,9 +46571,25 @@ static wc_test_ret_t ed448_test_check_key(void) } } if (res == 0) { - /* Load good public key only and perform checks. */ ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1, &key); +#if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0) + /* y = p - 1 is an order-2 point; check_key rejects it because + * h*A is the neutral element for small-order public keys and + * forged signatures would otherwise verify. */ + if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) { + res = WC_TEST_RET_ENC_NC; + } +#else + /* Older FIPS modules accept this order-2 point. */ + if (ret != 0) { + res = WC_TEST_RET_ENC_NC; + } +#endif + } + if (res == 0) { + /* Positive control: a real Ed448 public key must be accepted. */ + ret = wc_ed448_import_public(key_good, ED448_PUB_KEY_SIZE + 1, &key); if (ret != 0) { res = WC_TEST_RET_ENC_NC; } @@ -60460,38 +60519,25 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void) wc_test_ret_t ret = 0; WC_RNG rng; int rng_inited = 0; - EccsiKey* priv = NULL; - EccsiKey* pub = NULL; - mp_int* ssk = NULL; + WC_DECLARE_VAR(priv, EccsiKey, 1, HEAP_HINT); + WC_DECLARE_VAR(pub, EccsiKey, 1, HEAP_HINT); + WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT); ecc_point* pvt = NULL; WOLFSSL_ENTER("eccsi_test"); - priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (priv == NULL) - ret = WC_TEST_RET_ENC_NC; - else + WC_ALLOC_VAR_EX(priv, EccsiKey, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); + if (ret == 0) { XMEMSET(priv, 0, sizeof(*priv)); - + WC_ALLOC_VAR_EX(pub, EccsiKey, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); + } if (ret == 0) { - pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (pub == NULL) - ret = WC_TEST_RET_ENC_NC; - else - XMEMSET(pub, 0, sizeof(*pub)); + XMEMSET(pub, 0, sizeof(*pub)); + WC_ALLOC_VAR_EX(ssk, mp_int, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); } if (ret == 0) { - ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (ssk == NULL) - ret = WC_TEST_RET_ENC_NC; - else - XMEMSET(ssk, 0, sizeof(*ssk)); - } + XMEMSET(ssk, 0, sizeof(*ssk)); - if (ret == 0) { #ifndef HAVE_FIPS ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); #else @@ -60547,18 +60593,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void) wc_ecc_del_point(pvt); if (rng_inited) wc_FreeRng(&rng); - if (ssk != NULL) { - mp_free(ssk); - XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - } - if (pub != NULL) { - wc_FreeEccsiKey(pub); - XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - } - if (priv != NULL) { - wc_FreeEccsiKey(priv); - XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - } + mp_free(ssk); + WC_FREE_VAR_EX(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wc_FreeEccsiKey(pub); + WC_FREE_VAR_EX(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wc_FreeEccsiKey(priv); + WC_FREE_VAR_EX(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -61704,38 +61744,25 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void) wc_test_ret_t ret = 0; WC_RNG rng; int rng_inited = 0; - SakkeKey* priv = NULL; - SakkeKey* pub = NULL; - SakkeKey* key = NULL; + WC_DECLARE_VAR(priv, SakkeKey, 1, HEAP_HINT); + WC_DECLARE_VAR(pub, SakkeKey, 1, HEAP_HINT); + WC_DECLARE_VAR(key, SakkeKey, 1, HEAP_HINT); ecc_point* rsk = NULL; WOLFSSL_ENTER("sakke_test"); - priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (priv == NULL) - ret = WC_TEST_RET_ENC_NC; - else + WC_ALLOC_VAR_EX(priv, SakkeKey, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); + if (ret == 0) { XMEMSET(priv, 0, sizeof(*priv)); - + WC_ALLOC_VAR_EX(pub, SakkeKey, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); + } if (ret == 0) { - pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (pub == NULL) - ret = WC_TEST_RET_ENC_NC; - else - XMEMSET(pub, 0, sizeof(*pub)); + XMEMSET(pub, 0, sizeof(*pub)); + WC_ALLOC_VAR_EX(key, SakkeKey, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER, ret = WC_TEST_RET_ENC_EC(MEMORY_E)); } if (ret == 0) { - key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (key == NULL) - ret = WC_TEST_RET_ENC_NC; - else - XMEMSET(key, 0, sizeof(*key)); - } + XMEMSET(key, 0, sizeof(*key)); - if (ret == 0) { #ifndef HAVE_FIPS ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); #else @@ -61791,15 +61818,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void) } if (rng_inited) wc_FreeRng(&rng); - XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (pub != NULL) { - wc_FreeSakkeKey(pub); - XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - } - if (priv != NULL) { - wc_FreeSakkeKey(priv); - XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - } + + WC_FREE_VAR_EX(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wc_FreeSakkeKey(pub); + WC_FREE_VAR_EX(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + wc_FreeSakkeKey(priv); + WC_FREE_VAR_EX(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return ret; } diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 025878a8d3..794808f38b 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -1419,7 +1419,7 @@ enum { /* Limit is 2^24.5 * https://www.rfc-editor.org/rfc/rfc8446#section-5.5 * Without the fraction is 23726566 (0x016A09E6) */ -#define AEAD_AES_LIMIT w64From32(0x016A, 0x09E6) +#define AEAD_AES_LIMIT w64From32(0, 0x016A09E6) /* Limit is 2^23 * https://www.rfc-editor.org/rfc/rfc9147.html#name-integrity-limits */ #define DTLS_AEAD_AES_CCM_LIMIT w64From32(0, 1 << 22) @@ -1436,8 +1436,8 @@ enum { * https://www.rfc-editor.org/rfc/rfc9147.html#name-integrity-limits * Without the fraction is 11863283 (0x00B504F3) * Half of this value is 5931641 (0x005A8279) */ -#define DTLS_AEAD_AES_CCM_FAIL_LIMIT w64From32(0x00B5, 0x04F3) -#define DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT w64From32(0x005A, 0x8279) +#define DTLS_AEAD_AES_CCM_FAIL_LIMIT w64From32(0, 0x00B504F3) +#define DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT w64From32(0, 0x005A8279) /* Limit is (2^22 - 1) full messages [2^36 - 31 octets] * https://www.rfc-editor.org/rfc/rfc8998.html#name-aead_sm4_gcm @@ -1632,25 +1632,28 @@ enum Misc { DTLS_EXPORT_PRO = 165,/* wolfSSL protocol for serialized session */ DTLS_EXPORT_STATE_PRO = 166,/* wolfSSL protocol for serialized state */ TLS_EXPORT_PRO = 167,/* wolfSSL protocol for serialized TLS */ - DTLS_EXPORT_OPT_SZ = 62, /* amount of bytes used from Options */ - DTLS_EXPORT_OPT_SZ_4 = 61, /* amount of bytes used from Options */ - TLS_EXPORT_OPT_SZ = 66, /* amount of bytes used from Options */ - TLS_EXPORT_OPT_SZ_4 = 65, /* amount of bytes used from Options */ - DTLS_EXPORT_OPT_SZ_3 = 60, /* amount of bytes used from Options */ + DTLS_EXPORT_OPT_SZ = 66, /* number of bytes used from Options */ + DTLS_EXPORT_OPT_SZ_5 = 62, /* number of bytes used from Options */ + DTLS_EXPORT_OPT_SZ_4 = 61, /* number of bytes used from Options */ + TLS_EXPORT_OPT_SZ = 66, /* number of bytes used from Options */ + TLS_EXPORT_OPT_SZ_5 = 66, /* number of bytes used from Options */ + TLS_EXPORT_OPT_SZ_4 = 65, /* number of bytes used from Options */ + DTLS_EXPORT_OPT_SZ_3 = 60, /* number of bytes used from Options */ DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2), - /* max amount of bytes used from Keys */ + /* max number of bytes used from Keys */ DTLS_EXPORT_MIN_KEY_SZ = 85 + (DTLS_SEQ_SZ * 2), - /* min amount of bytes used from Keys */ + /* min number of bytes used from Keys */ WOLFSSL_EXPORT_TLS = 1, WOLFSSL_EXPORT_DTLS = 0, #ifndef WOLFSSL_EXPORT_SPC_SZ - WOLFSSL_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */ + WOLFSSL_EXPORT_SPC_SZ = 16, /* number of bytes used from CipherSpecs */ #endif WOLFSSL_EXPORT_LEN = 2, /* 2 bytes for length and protocol */ - WOLFSSL_EXPORT_VERSION = 5, /* wolfSSL version for serialized session */ + WOLFSSL_EXPORT_VERSION = 6, /* wolfSSL version for serialized session */ - WOLFSSL_EXPORT_VERSION_4 = 4, /* 5.6.4 release and before */ /* older export versions supported */ + WOLFSSL_EXPORT_VERSION_5 = 5, /* version before DTLS Encrypt-Then-MAC */ + WOLFSSL_EXPORT_VERSION_4 = 4, /* 5.6.4 release and before */ WOLFSSL_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */ MAX_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */ diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index 9b90563cf8..bc873695bf 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -455,6 +455,12 @@ enum { #endif #ifdef HAVE_ED448 WC_EVP_PKEY_ED448 = WC_NID_ED448, +#endif +#ifdef HAVE_CURVE25519 + WC_EVP_PKEY_X25519 = WC_NID_X25519, +#endif +#ifdef HAVE_CURVE448 + WC_EVP_PKEY_X448 = WC_NID_X448, #endif WC_AES_128_CFB1_TYPE = 24, WC_AES_192_CFB1_TYPE = 25, @@ -529,6 +535,12 @@ enum { #ifdef HAVE_ED448 #define EVP_PKEY_ED448 WC_EVP_PKEY_ED448 #endif +#ifdef HAVE_CURVE25519 +#define EVP_PKEY_X25519 WC_EVP_PKEY_X25519 +#endif +#ifdef HAVE_CURVE448 +#define EVP_PKEY_X448 WC_EVP_PKEY_X448 +#endif #define AES_128_CFB1_TYPE WC_AES_128_CFB1_TYPE #define AES_192_CFB1_TYPE WC_AES_192_CFB1_TYPE #define AES_256_CFB1_TYPE WC_AES_256_CFB1_TYPE diff --git a/wolfssl/openssl/pem.h b/wolfssl/openssl/pem.h index 9ccc4731de..6ad42052b2 100644 --- a/wolfssl/openssl/pem.h +++ b/wolfssl/openssl/pem.h @@ -231,6 +231,13 @@ WOLFSSL_API int wolfSSL_PEM_write_X509(XFILE fp, WOLFSSL_X509 *x); WOLFSSL_API int wolfSSL_PEM_write_DHparams(XFILE fp, WOLFSSL_DH* dh); +WOLFSSL_API +int wolfSSL_PEM_write_PrivateKey(XFILE fp, WOLFSSL_EVP_PKEY* key, + const WOLFSSL_EVP_CIPHER* cipher, + unsigned char* passwd, int len, + wc_pem_password_cb* cb, void* arg); +WOLFSSL_API +int wolfSSL_PEM_write_PUBKEY(XFILE fp, WOLFSSL_EVP_PKEY* key); #endif /* NO_FILESYSTEM */ #ifndef OPENSSL_COEXIST @@ -244,6 +251,7 @@ int wolfSSL_PEM_write_DHparams(XFILE fp, WOLFSSL_DH* dh); #define PEM_read_X509 wolfSSL_PEM_read_X509 #define PEM_read_PrivateKey wolfSSL_PEM_read_PrivateKey +#define PEM_write_PrivateKey wolfSSL_PEM_write_PrivateKey #define PEM_write_X509 wolfSSL_PEM_write_X509 #define PEM_write_bio_PrivateKey wolfSSL_PEM_write_bio_PrivateKey #define PEM_write_bio_PKCS8PrivateKey wolfSSL_PEM_write_bio_PKCS8PrivateKey @@ -287,6 +295,7 @@ int wolfSSL_PEM_write_DHparams(XFILE fp, WOLFSSL_DH* dh); #define PEM_read_PUBKEY wolfSSL_PEM_read_PUBKEY #define PEM_read_bio_PUBKEY wolfSSL_PEM_read_bio_PUBKEY #define PEM_write_bio_PUBKEY wolfSSL_PEM_write_bio_PUBKEY +#define PEM_write_PUBKEY wolfSSL_PEM_write_PUBKEY #define PEM_write_bio_PKCS8_PRIV_KEY_INFO wolfSSL_PEM_write_bio_PKCS8_PRIV_KEY_INFO #define PEM_read_bio_PKCS8_PRIV_KEY_INFO wolfSSL_PEM_read_bio_PKCS8_PRIV_KEY_INFO diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 0081cfc494..2281bb2f26 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -609,6 +609,12 @@ struct WOLFSSL_EVP_PKEY { #ifdef HAVE_ED448 struct ed448_key* ed448; #endif + #ifdef HAVE_CURVE25519 + struct curve25519_key* curve25519; + #endif + #ifdef HAVE_CURVE448 + struct curve448_key* curve448; + #endif WC_RNG rng; #ifdef HAVE_HKDF const WOLFSSL_EVP_MD* hkdfMd; @@ -640,6 +646,12 @@ struct WOLFSSL_EVP_PKEY { #ifdef HAVE_ED448 WC_BITFIELD ownEd448:1; /* if struct owns Ed448 and should free it */ #endif +#ifdef HAVE_CURVE25519 + WC_BITFIELD ownCurve25519:1; /* if struct owns X25519 and should free it */ +#endif +#ifdef HAVE_CURVE448 + WC_BITFIELD ownCurve448:1; /* if struct owns X448 and should free it */ +#endif }; diff --git a/wolfssl/wolfcrypt/aes.h b/wolfssl/wolfcrypt/aes.h index 0afc129009..e3d7637470 100644 --- a/wolfssl/wolfcrypt/aes.h +++ b/wolfssl/wolfcrypt/aes.h @@ -1112,6 +1112,53 @@ WOLFSSL_LOCAL void AES_XTS_decrypt_AARCH32(const byte* in, byte* out, #endif /* !__aarch64__ && !WOLFSSL_ARMASM_NO_HW_CRYPTO */ #endif /* WOLFSSL_ARMASM */ +#if defined(WOLFSSL_PPC64_ASM) +WOLFSSL_LOCAL void AES_set_encrypt_key(const unsigned char* key, word32 len, + unsigned char* ks); +WOLFSSL_LOCAL void AES_invert_key(unsigned char* ks, word32 rounds); +WOLFSSL_LOCAL void AES_ECB_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr); +WOLFSSL_LOCAL void AES_ECB_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr); +WOLFSSL_LOCAL void AES_CBC_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv); +WOLFSSL_LOCAL void AES_CBC_decrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* iv); +WOLFSSL_LOCAL void AES_CTR_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr); +#if defined(GCM_TABLE) || defined(GCM_TABLE_4BIT) +/* in pre-C2x C, constness conflicts for dimensioned arrays can't be resolved. + */ +WOLFSSL_LOCAL void GCM_gmult_len(byte* x, const byte** m, + const unsigned char* data, unsigned long len); +#endif +WOLFSSL_LOCAL void AES_GCM_encrypt(const unsigned char* in, unsigned char* out, + unsigned long len, const unsigned char* ks, int nr, unsigned char* ctr); + +#if defined(BUILDING_WOLFSSL) + WOLFSSL_API WARN_UNUSED_RESULT int wc_AesEncryptDirect(Aes* aes, byte* out, + const byte* in); + WOLFSSL_API WARN_UNUSED_RESULT int wc_AesDecryptDirect(Aes* aes, byte* out, + const byte* in); + WOLFSSL_API WARN_UNUSED_RESULT int wc_AesSetKeyDirect(Aes* aes, + const byte* key, + word32 len, + const byte* iv, int dir); +#else + WOLFSSL_API int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in); + WOLFSSL_API int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in); + WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len, + const byte* iv, int dir); +#endif + +#if defined(WOLFSSL_AES_XTS) +WOLFSSL_LOCAL void AES_XTS_encrypt(const byte* in, byte* out, word32 sz, + const byte* i, byte* key, byte* key2, byte* tmp, int nr); +WOLFSSL_LOCAL void AES_XTS_decrypt(const byte* in, byte* out, word32 sz, + const byte* i, byte* key, byte* key2, byte* tmp, int nr); +#endif +#endif /* WOLFSSL_PPC64_ASM */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 5db17afab1..70f823fc80 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -3213,6 +3213,13 @@ WOLFSSL_TEST_VIS int wolfssl_local_MatchBaseName(int type, const char* name, WOLFSSL_TEST_VIS int wolfssl_local_MatchIpSubnet(const byte* ip, int ipSz, const byte* constraint, int constraintSz); +WOLFSSL_TEST_VIS int wolfssl_local_MatchUriNameConstraint(const char* uri, + int uriSz, const char* base, + int baseSz); +WOLFSSL_TEST_VIS int wolfssl_local_MatchDnsConstraintWildcard( + const char* name, int nameSz, + const char* base, int baseSz, + int permitted); #endif #if ((defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)) \ diff --git a/wolfssl/wolfcrypt/chacha.h b/wolfssl/wolfcrypt/chacha.h index 5ae021fa43..a2467ba1f9 100644 --- a/wolfssl/wolfcrypt/chacha.h +++ b/wolfssl/wolfcrypt/chacha.h @@ -86,9 +86,10 @@ typedef struct ChaCha { byte extra[12]; #endif word32 left; /* number of bytes leftover */ -#if defined(USE_INTEL_CHACHA_SPEEDUP) || defined(USE_ARM_CHACHA_SPEEDUP) || \ - defined(WOLFSSL_RISCV_ASM) +#if defined(USE_INTEL_CHACHA_SPEEDUP) || defined(USE_ARM_CHACHA_SPEEDUP) word32 over[CHACHA_CHUNK_WORDS]; +#elif defined(WOLFSSL_RISCV_ASM) + ALIGN8 word32 over[CHACHA_CHUNK_WORDS]; #endif } ChaCha; diff --git a/wolfssl/wolfcrypt/cryptocb.h b/wolfssl/wolfcrypt/cryptocb.h index 1d86bf1169..b0aaad2f37 100644 --- a/wolfssl/wolfcrypt/cryptocb.h +++ b/wolfssl/wolfcrypt/cryptocb.h @@ -871,7 +871,11 @@ WOLFSSL_LOCAL int wc_CryptoCb_Sha384Hash(wc_Sha384* sha384, const byte* in, #endif #ifdef WOLFSSL_SHA512 WOLFSSL_LOCAL int wc_CryptoCb_Sha512Hash(wc_Sha512* sha512, const byte* in, - word32 inSz, byte* digest, size_t digestSz); + word32 inSz, byte* digest +#if !(defined(HAVE_FIPS) && FIPS_VERSION_LT(7,0)) + , size_t digestSz +#endif + ); #endif #ifdef WOLFSSL_SHA3 diff --git a/wolfssl/wolfcrypt/error-crypt.h b/wolfssl/wolfcrypt/error-crypt.h index 8d49ffc18e..736954a0a7 100644 --- a/wolfssl/wolfcrypt/error-crypt.h +++ b/wolfssl/wolfcrypt/error-crypt.h @@ -356,10 +356,13 @@ WOLFSSL_API void wc_ErrorString(int err, char* buff); WOLFSSL_ABI WOLFSSL_API const char* wc_GetErrorString(int error); #endif +#ifdef WOLFSSL_DEBUG_BACKTRACE_ERROR_CODES + WOLFSSL_API extern int wc_backtrace_render(void); +#endif + #if defined(WOLFSSL_DEBUG_TRACE_ERROR_CODES) && \ (defined(BUILDING_WOLFSSL) || \ defined(WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS)) - WOLFSSL_API extern int wc_backtrace_render(void); #define WC_NO_ERR_TRACE(label) (CONST_NUM_ERR_ ## label) #ifndef WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE #ifdef WOLFSSL_DEBUG_BACKTRACE_ERROR_CODES diff --git a/wolfssl/wolfcrypt/logging.h b/wolfssl/wolfcrypt/logging.h index 414b41c233..efed186fdb 100644 --- a/wolfssl/wolfcrypt/logging.h +++ b/wolfssl/wolfcrypt/logging.h @@ -579,12 +579,13 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix); #error "Failed: Cannot WOLFSSL_DEBUG_CERTS with WOLFSSL_DEBUG_ERRORS_ONLY" #endif +#if defined(WOLFSSL_DEBUG_BACKTRACE_ERROR_CODES) && defined(XFILE) + WOLFSSL_API XFILE wc_backtrace_set_fp(XFILE new_fp); +#endif + #ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES WOLFSSL_API int wc_debug_trace_error_codes_enabled(void); WOLFSSL_API int wc_debug_trace_error_codes_set(int state); - #ifdef XFILE - WOLFSSL_API XFILE wc_backtrace_set_fp(XFILE new_fp); - #endif #endif #ifdef __cplusplus diff --git a/wolfssl/wolfcrypt/memory.h b/wolfssl/wolfcrypt/memory.h index 0651869060..cdc6a04045 100644 --- a/wolfssl/wolfcrypt/memory.h +++ b/wolfssl/wolfcrypt/memory.h @@ -370,6 +370,8 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, #define DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE abort(); #elif defined(DEBUG_VECTOR_REGISTERS_EXIT_ON_FAIL) #define DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE exit(1); + #elif defined(DEBUG_VECTOR_REGISTERS_BACKTRACE_ON_FAIL) + #define DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE wc_backtrace_render(); #elif !defined(DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE) #define DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE #endif @@ -381,8 +383,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, ++wc_svr_count; \ if (wc_svr_count > 5) { \ fprintf(stderr, \ - ("%s @ L%d : incr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : incr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -403,8 +406,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, #define WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(x) do { \ if (((x) != 0) && (wc_svr_count > 0)) { \ fprintf(stderr, \ - ("%s @ L%d : incr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : incr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -422,8 +426,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, ++wc_svr_count; \ if (wc_svr_count > 5) { \ fprintf(stderr, \ - ("%s @ L%d : incr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : incr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -445,8 +450,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, if (wc_debug_vector_registers_retval != 0) { \ if (wc_svr_count > 0) { \ fprintf(stderr, \ - ("%s @ L%d : incr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : incr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -459,8 +465,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, ++wc_svr_count; \ if (wc_svr_count > 5) { \ fprintf(stderr, \ - ("%s @ L%d : incr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : incr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -480,8 +487,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, #define ASSERT_SAVED_VECTOR_REGISTERS() do { \ if (wc_svr_count <= 0) { \ fprintf(stderr, \ - ("ASSERT_SAVED_VECTOR_REGISTERS : %s @ L%d : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("ASSERT_SAVED_VECTOR_REGISTERS : %s() %s @ L %d : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -493,8 +501,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, #define ASSERT_RESTORED_VECTOR_REGISTERS(fail_clause) do { \ if (wc_svr_count != 0) { \ fprintf(stderr, \ - ("ASSERT_RESTORED_VECTOR_REGISTERS : %s @ L%d" \ - " : wc_svr_count %d (last op %s L%d)\n"), \ + ("ASSERT_RESTORED_VECTOR_REGISTERS : %s() %s @ L %d" \ + " : wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ @@ -508,8 +517,9 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag, --wc_svr_count; \ if ((wc_svr_count > 4) || (wc_svr_count < 0)) { \ fprintf(stderr, \ - ("%s @ L%d : decr : " \ - "wc_svr_count %d (last op %s L%d)\n"), \ + ("%s() %s @ L %d : decr : " \ + "wc_svr_count %d (last op %s L %d)\n"), \ + __FUNCTION__, \ __FILE__, \ __LINE__, \ wc_svr_count, \ diff --git a/wolfssl/wolfcrypt/port/riscv/riscv-64-asm.h b/wolfssl/wolfcrypt/port/riscv/riscv-64-asm.h index 70cabff507..11090c65e5 100644 --- a/wolfssl/wolfcrypt/port/riscv/riscv-64-asm.h +++ b/wolfssl/wolfcrypt/port/riscv/riscv-64-asm.h @@ -181,6 +181,633 @@ /* 32-bit width when loading. */ #define WIDTH_32 0b110 +/* + * Scalar load/store helpers. + * + * Each macro performs the same operation as the ld/lwu/lw/lh/sd/sw/sh + * instruction it is named after. By default it expands to that native + * instruction. When built with WOLFSSL_RISCV_ASM_NO_UNALIGNED - for cores that + * don't support misaligned access - it checks the effective address alignment + * at run time and dispatches to the widest supported sequence: word-wise + * (lwu/sw) when 4-byte aligned, half-wise (lhu/sh) when 2-byte aligned, + * otherwise byte-wise (lbu/sb). The narrower _BY_BYTE / _BY_HALF / _BY_WORD + * forms are also exposed for sites that already know the alignment. Values + * are little-endian, matching the native instructions either way. + * + * Bulk variants UNALIGNED_ (N = 2, 4, 8) issue N + * consecutive accesses starting at o(p) - stride 8 bytes for LD/SD, 4 bytes + * for LWU/LW/SW. Under WOLFSSL_RISCV_ASM_NO_UNALIGNED they share a single + * alignment check across all N elements; otherwise they are just N native + * instructions back-to-back. + * + * r = data register: destination (loads) or source (stores) + * o = constant byte offset + * p = base address register + * t = scratch register - must differ from r and p; clobbered. For stores the + * data register r is preserved. Only used when + * WOLFSSL_RISCV_ASM_NO_UNALIGNED is defined; ignored otherwise. + */ + +/* Apply X to N doublewords at 8-byte stride starting at o(p). */ +#define UNALIGNED_DW_REP2(X, r0, r1, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+8, p, t) +#define UNALIGNED_DW_REP4(X, r0, r1, r2, r3, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+8, p, t) \ + X(r2, o+16, p, t) \ + X(r3, o+24, p, t) +#define UNALIGNED_DW_REP8(X, r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+8, p, t) \ + X(r2, o+16, p, t) \ + X(r3, o+24, p, t) \ + X(r4, o+32, p, t) \ + X(r5, o+40, p, t) \ + X(r6, o+48, p, t) \ + X(r7, o+56, p, t) + +/* Apply X to N words at 4-byte stride starting at o(p). */ +#define UNALIGNED_W_REP2(X, r0, r1, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+4, p, t) +#define UNALIGNED_W_REP4(X, r0, r1, r2, r3, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+4, p, t) \ + X(r2, o+8, p, t) \ + X(r3, o+12, p, t) +#define UNALIGNED_W_REP8(X, r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + X(r0, o, p, t) \ + X(r1, o+4, p, t) \ + X(r2, o+8, p, t) \ + X(r3, o+12, p, t) \ + X(r4, o+16, p, t) \ + X(r5, o+20, p, t) \ + X(r6, o+24, p, t) \ + X(r7, o+28, p, t) + +#ifndef WOLFSSL_RISCV_ASM_NO_UNALIGNED + +/* Load 64-bits. */ +#define UNALIGNED_LD(r, o, p, t) \ + "ld " #r ", " #o "(" #p ")\n\t" + +/* Load 32-bits, zero extended. */ +#define UNALIGNED_LWU(r, o, p, t) \ + "lwu " #r ", " #o "(" #p ")\n\t" + +/* Load 32-bits, sign extended. */ +#define UNALIGNED_LW(r, o, p, t) \ + "lw " #r ", " #o "(" #p ")\n\t" + +/* Load 16-bits, sign extended. */ +#define UNALIGNED_LH(r, o, p, t) \ + "lh " #r ", " #o "(" #p ")\n\t" + +/* Store 64-bits. */ +#define UNALIGNED_SD(r, o, p, t) \ + "sd " #r ", " #o "(" #p ")\n\t" + +/* Store 32-bits. */ +#define UNALIGNED_SW(r, o, p, t) \ + "sw " #r ", " #o "(" #p ")\n\t" + +/* Store 16-bits. */ +#define UNALIGNED_SH(r, o, p, t) \ + "sh " #r ", " #o "(" #p ")\n\t" + +/* Bulk variants - hardware handles unaligned access, so just emit N native + * instructions. */ +#define UNALIGNED_LD2(r0, r1, o, p, t) \ + UNALIGNED_DW_REP2(UNALIGNED_LD, r0, r1, o, p, t) +#define UNALIGNED_LD4(r0, r1, r2, r3, o, p, t) \ + UNALIGNED_DW_REP4(UNALIGNED_LD, r0, r1, r2, r3, o, p, t) +#define UNALIGNED_LD8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + UNALIGNED_DW_REP8(UNALIGNED_LD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) +#define UNALIGNED_SD2(r0, r1, o, p, t) \ + UNALIGNED_DW_REP2(UNALIGNED_SD, r0, r1, o, p, t) +#define UNALIGNED_SD4(r0, r1, r2, r3, o, p, t) \ + UNALIGNED_DW_REP4(UNALIGNED_SD, r0, r1, r2, r3, o, p, t) +#define UNALIGNED_SD8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + UNALIGNED_DW_REP8(UNALIGNED_SD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) +#define UNALIGNED_LWU2(r0, r1, o, p, t) \ + UNALIGNED_W_REP2(UNALIGNED_LWU, r0, r1, o, p, t) +#define UNALIGNED_LWU4(r0, r1, r2, r3, o, p, t) \ + UNALIGNED_W_REP4(UNALIGNED_LWU, r0, r1, r2, r3, o, p, t) +#define UNALIGNED_LWU8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + UNALIGNED_W_REP8(UNALIGNED_LWU, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) +#define UNALIGNED_LW2(r0, r1, o, p, t) \ + UNALIGNED_W_REP2(UNALIGNED_LW, r0, r1, o, p, t) +#define UNALIGNED_LW4(r0, r1, r2, r3, o, p, t) \ + UNALIGNED_W_REP4(UNALIGNED_LW, r0, r1, r2, r3, o, p, t) +#define UNALIGNED_LW8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + UNALIGNED_W_REP8(UNALIGNED_LW, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) +#define UNALIGNED_SW2(r0, r1, o, p, t) \ + UNALIGNED_W_REP2(UNALIGNED_SW, r0, r1, o, p, t) +#define UNALIGNED_SW4(r0, r1, r2, r3, o, p, t) \ + UNALIGNED_W_REP4(UNALIGNED_SW, r0, r1, r2, r3, o, p, t) +#define UNALIGNED_SW8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + UNALIGNED_W_REP8(UNALIGNED_SW, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) + +#else + +/* Load 64-bits. */ +#define UNALIGNED_LD_BY_BYTE(r, o, p, t) \ + "lbu " #r ", " #o "+0(" #p ")\n\t" \ + "lbu " #t ", " #o "+1(" #p ")\n\t" \ + "slli " #t ", " #t ", 8\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+2(" #p ")\n\t" \ + "slli " #t ", " #t ", 16\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+3(" #p ")\n\t" \ + "slli " #t ", " #t ", 24\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+4(" #p ")\n\t" \ + "slli " #t ", " #t ", 32\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+5(" #p ")\n\t" \ + "slli " #t ", " #t ", 40\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+6(" #p ")\n\t" \ + "slli " #t ", " #t ", 48\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+7(" #p ")\n\t" \ + "slli " #t ", " #t ", 56\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LD_BY_HALF(r, o, p, t) \ + "lhu " #r ", " #o "+0(" #p ")\n\t" \ + "lhu " #t ", " #o "+2(" #p ")\n\t" \ + "slli " #t ", " #t ", 16\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lhu " #t ", " #o "+4(" #p ")\n\t" \ + "slli " #t ", " #t ", 32\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lhu " #t ", " #o "+6(" #p ")\n\t" \ + "slli " #t ", " #t ", 48\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LD_BY_WORD(r, o, p, t) \ + "lwu " #r ", " #o "+0(" #p ")\n\t" \ + "lwu " #t ", " #o "+4(" #p ")\n\t" \ + "slli " #t ", " #t ", 32\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LD_BY_DWORD(r, o, p, t) \ + "ld " #r ", " #o "(" #p ")\n\t" +/* Assumes o is a multiple of 8. */ +#define UNALIGNED_LD(r, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_LD_BY_DWORD(r, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_LD_BY_WORD(r, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_LD_BY_HALF(r, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_LD_BY_BYTE(r, o, p, t) \ + "4:\n\t" + +/* Load 32-bits, zero extended. */ +#define UNALIGNED_LWU_BY_BYTE(r, o, p, t) \ + "lbu " #r ", " #o "+0(" #p ")\n\t" \ + "lbu " #t ", " #o "+1(" #p ")\n\t" \ + "slli " #t ", " #t ", 8\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+2(" #p ")\n\t" \ + "slli " #t ", " #t ", 16\n\t" \ + "or " #r ", " #r ", " #t "\n\t" \ + "lbu " #t ", " #o "+3(" #p ")\n\t" \ + "slli " #t ", " #t ", 24\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LWU_BY_HALF(r, o, p, t) \ + "lhu " #r ", " #o "+0(" #p ")\n\t" \ + "lhu " #t ", " #o "+2(" #p ")\n\t" \ + "slli " #t ", " #t ", 16\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LWU_BY_WORD(r, o, p, t) \ + "lwu " #r ", " #o "(" #p ")\n\t" +/* Assumes o is a multiple of 4. */ +#define UNALIGNED_LWU(r, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_LWU_BY_WORD(r, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_LWU_BY_HALF(r, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_LWU_BY_BYTE(r, o, p, t) \ + "3:\n\t" + +/* Load 32-bits, sign extended. */ +#define UNALIGNED_LW_BY_BYTE(r, o, p, t) \ + UNALIGNED_LWU_BY_BYTE(r, o, p, t) \ + "sext.w " #r ", " #r "\n\t" +#define UNALIGNED_LW_BY_HALF(r, o, p, t) \ + UNALIGNED_LWU_BY_HALF(r, o, p, t) \ + "sext.w " #r ", " #r "\n\t" +#define UNALIGNED_LW_BY_WORD(r, o, p, t) \ + "lw " #r ", " #o "(" #p ")\n\t" +/* Assumes o is a multiple of 4. */ +#define UNALIGNED_LW(r, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_LW_BY_WORD(r, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_LW_BY_HALF(r, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_LW_BY_BYTE(r, o, p, t) \ + "3:\n\t" + +/* Load 16-bits, sign extended. */ +#define UNALIGNED_LH_BY_BYTE(r, o, p, t) \ + "lbu " #r ", " #o "+0(" #p ")\n\t" \ + "lb " #t ", " #o "+1(" #p ")\n\t" \ + "slli " #t ", " #t ", 8\n\t" \ + "or " #r ", " #r ", " #t "\n\t" +#define UNALIGNED_LH(r, o, p, t) \ + UNALIGNED_LH_BY_BYTE(r, o, p, t) + +/* Store 64-bits. */ +#define UNALIGNED_SD_BY_BYTE(r, o, p, t) \ + "sb " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 8\n\t" \ + "sb " #t ", " #o "+1(" #p ")\n\t" \ + "srli " #t ", " #r ", 16\n\t" \ + "sb " #t ", " #o "+2(" #p ")\n\t" \ + "srli " #t ", " #r ", 24\n\t" \ + "sb " #t ", " #o "+3(" #p ")\n\t" \ + "srli " #t ", " #r ", 32\n\t" \ + "sb " #t ", " #o "+4(" #p ")\n\t" \ + "srli " #t ", " #r ", 40\n\t" \ + "sb " #t ", " #o "+5(" #p ")\n\t" \ + "srli " #t ", " #r ", 48\n\t" \ + "sb " #t ", " #o "+6(" #p ")\n\t" \ + "srli " #t ", " #r ", 56\n\t" \ + "sb " #t ", " #o "+7(" #p ")\n\t" +#define UNALIGNED_SD_BY_HALF(r, o, p, t) \ + "sh " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 16\n\t" \ + "sh " #t ", " #o "+2(" #p ")\n\t" \ + "srli " #t ", " #r ", 32\n\t" \ + "sh " #t ", " #o "+4(" #p ")\n\t" \ + "srli " #t ", " #r ", 48\n\t" \ + "sh " #t ", " #o "+6(" #p ")\n\t" +#define UNALIGNED_SD_BY_WORD(r, o, p, t) \ + "sw " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 32\n\t" \ + "sw " #t ", " #o "+4(" #p ")\n\t" +#define UNALIGNED_SD_BY_DWORD(r, o, p, t) \ + "sd " #r ", " #o "(" #p ")\n\t" +/* Assumes o is a multiple of 8. */ +#define UNALIGNED_SD(r, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_SD_BY_DWORD(r, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_SD_BY_WORD(r, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_SD_BY_HALF(r, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_SD_BY_BYTE(r, o, p, t) \ + "4:\n\t" + +/* Store 32-bits. */ +#define UNALIGNED_SW_BY_BYTE(r, o, p, t) \ + "sb " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 8\n\t" \ + "sb " #t ", " #o "+1(" #p ")\n\t" \ + "srli " #t ", " #r ", 16\n\t" \ + "sb " #t ", " #o "+2(" #p ")\n\t" \ + "srli " #t ", " #r ", 24\n\t" \ + "sb " #t ", " #o "+3(" #p ")\n\t" +#define UNALIGNED_SW_BY_HALF(r, o, p, t) \ + "sh " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 16\n\t" \ + "sh " #t ", " #o "+2(" #p ")\n\t" +#define UNALIGNED_SW_BY_WORD(r, o, p, t) \ + "sw " #r ", " #o "(" #p ")\n\t" +/* Assumes o is a multiple of 4. */ +#define UNALIGNED_SW(r, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_SW_BY_WORD(r, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_SW_BY_HALF(r, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_SW_BY_BYTE(r, o, p, t) \ + "3:\n\t" + +/* Store 16-bits. */ +#define UNALIGNED_SH_BY_BYTE(r, o, p, t) \ + "sb " #r ", " #o "+0(" #p ")\n\t" \ + "srli " #t ", " #r ", 8\n\t" \ + "sb " #t ", " #o "+1(" #p ")\n\t" +#define UNALIGNED_SH(r, o, p, t) \ + UNALIGNED_SH_BY_BYTE(r, o, p, t) + +/* Load 2 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_LD2(r0, r1, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_LD_BY_DWORD, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_LD_BY_WORD, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_LD_BY_HALF, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_LD_BY_BYTE, r0, r1, o, p, t) \ + "4:\n\t" + +/* Load 4 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_LD4(r0, r1, r2, r3, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_LD_BY_DWORD, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_LD_BY_WORD, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_LD_BY_HALF, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_LD_BY_BYTE, r0, r1, r2, r3, o, p, t) \ + "4:\n\t" + +/* Load 8 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_LD8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_LD_BY_DWORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_LD_BY_WORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_LD_BY_HALF, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_LD_BY_BYTE, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "4:\n\t" + +/* Store 2 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_SD2(r0, r1, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_SD_BY_DWORD, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_SD_BY_WORD, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_SD_BY_HALF, r0, r1, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP2(UNALIGNED_SD_BY_BYTE, r0, r1, o, p, t) \ + "4:\n\t" + +/* Store 4 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_SD4(r0, r1, r2, r3, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_SD_BY_DWORD, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_SD_BY_WORD, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_SD_BY_HALF, r0, r1, r2, r3, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP4(UNALIGNED_SD_BY_BYTE, r0, r1, r2, r3, o, p, t) \ + "4:\n\t" + +/* Store 8 64-bits. Assumes o is a multiple of 8. */ +#define UNALIGNED_SD8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "andi " #t ", " #p ", 7\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_SD_BY_DWORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 3\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_SD_BY_WORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "2:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 3f\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_SD_BY_HALF, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 4f\n\t" \ + "3:\n\t" \ + UNALIGNED_DW_REP8(UNALIGNED_SD_BY_BYTE, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "4:\n\t" + +/* Load 2 32-bits, zero extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LWU2(r0, r1, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LWU_BY_WORD, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LWU_BY_HALF, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LWU_BY_BYTE, r0, r1, o, p, t) \ + "3:\n\t" + +/* Load 4 32-bits, zero extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LWU4(r0, r1, r2, r3, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LWU_BY_WORD, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LWU_BY_HALF, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LWU_BY_BYTE, r0, r1, r2, r3, o, p, t) \ + "3:\n\t" + +/* Load 8 32-bits, zero extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LWU8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LWU_BY_WORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LWU_BY_HALF, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LWU_BY_BYTE, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "3:\n\t" + +/* Load 2 32-bits, sign extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LW2(r0, r1, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LW_BY_WORD, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LW_BY_HALF, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_LW_BY_BYTE, r0, r1, o, p, t) \ + "3:\n\t" + +/* Load 4 32-bits, sign extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LW4(r0, r1, r2, r3, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LW_BY_WORD, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LW_BY_HALF, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_LW_BY_BYTE, r0, r1, r2, r3, o, p, t) \ + "3:\n\t" + +/* Load 8 32-bits, sign extended. Assumes o is a multiple of 4. */ +#define UNALIGNED_LW8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LW_BY_WORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LW_BY_HALF, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_LW_BY_BYTE, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "3:\n\t" + +/* Store 2 32-bits. Assumes o is a multiple of 4. */ +#define UNALIGNED_SW2(r0, r1, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_SW_BY_WORD, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_SW_BY_HALF, r0, r1, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP2(UNALIGNED_SW_BY_BYTE, r0, r1, o, p, t) \ + "3:\n\t" + +/* Store 4 32-bits. Assumes o is a multiple of 4. */ +#define UNALIGNED_SW4(r0, r1, r2, r3, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_SW_BY_WORD, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_SW_BY_HALF, r0, r1, r2, r3, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP4(UNALIGNED_SW_BY_BYTE, r0, r1, r2, r3, o, p, t) \ + "3:\n\t" + +/* Store 8 32-bits. Assumes o is a multiple of 4. */ +#define UNALIGNED_SW8(r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "andi " #t ", " #p ", 3\n\t" \ + "bnez " #t ", 1f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_SW_BY_WORD, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "1:\n\t" \ + "andi " #t ", " #t ", 1\n\t" \ + "bnez " #t ", 2f\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_SW_BY_HALF, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "j 3f\n\t" \ + "2:\n\t" \ + UNALIGNED_W_REP8(UNALIGNED_SW_BY_BYTE, \ + r0, r1, r2, r3, r4, r5, r6, r7, o, p, t) \ + "3:\n\t" + +#endif /* !WOLFSSL_RISCV_ASM_NO_UNALIGNED */ + #define VLSEG_V(vd, rs1, cnt, width) \ ASM_WORD(0b0000111 | (width << 12) | (0b10101000 << 20) | \ diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index c3ced88da7..e7d9b568f6 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -327,7 +327,7 @@ #define WC_16BIT_CPU #define WOLFSSL_OLD_OID_SUM #elif defined(__SAM3X8E__) - #define WOLFSSL_NO_ATOMIC + #define WOLFSSL_NO_STDATOMIC_FENCE #define WOLFSSL_NO_SOCK #define WOLFSSL_USER_IO #define NO_WRITEV @@ -3963,6 +3963,9 @@ extern void uITRON4_free(void *p) ; #ifndef WC_NO_INTERNAL_FUNCTION_POINTERS #define WC_NO_INTERNAL_FUNCTION_POINTERS #endif + #ifndef WC_NO_GLOBAL_OBJECT_POINTERS + #define WC_NO_GLOBAL_OBJECT_POINTERS + #endif #ifndef WOLFSSL_ECC_CURVE_STATIC #define WOLFSSL_ECC_CURVE_STATIC #endif diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 042551bfc0..775794ae1f 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -1786,7 +1786,7 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); /* use user-supplied XFENCE definition. */ #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ !defined(__STDC_NO_ATOMICS__) && !defined(NO_STDATOMIC_H) - #ifdef WOLFSSL_NO_ATOMIC + #ifdef WOLFSSL_NO_STDATOMIC_FENCE #define XFENCE() WC_DO_NOTHING #else #include diff --git a/wolfssl/wolfcrypt/wolfmath.h b/wolfssl/wolfcrypt/wolfmath.h index f656329979..1353f40d17 100644 --- a/wolfssl/wolfcrypt/wolfmath.h +++ b/wolfssl/wolfcrypt/wolfmath.h @@ -74,12 +74,13 @@ This library provides big integer math functions. #endif /* timing resistance array */ -#if (!defined(WC_NO_CACHE_RESISTANT) && \ - ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ - (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))) || \ - ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \ - !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \ - defined(OPENSSL_ALL) && defined(WC_PROTECT_ENCRYPTED_MEM)) +#if !defined(WC_NO_GLOBAL_OBJECT_POINTERS) && \ + ((!defined(WC_NO_CACHE_RESISTANT) && \ + ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ + (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))) || \ + ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \ + !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \ + defined(OPENSSL_ALL) && defined(WC_PROTECT_ENCRYPTED_MEM))) extern const wc_ptr_t wc_off_on_addr[2]; #endif diff --git a/wrapper/rust/wolfssl-wolfcrypt/Cargo.toml b/wrapper/rust/wolfssl-wolfcrypt/Cargo.toml index 0e3ceed443..6a38933619 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/Cargo.toml +++ b/wrapper/rust/wolfssl-wolfcrypt/Cargo.toml @@ -11,7 +11,7 @@ categories = ["cryptography", "security", "api-bindings"] readme = "README.md" [features] -std = [] +alloc = [] rand_core = ["dep:rand_core"] aead = ["dep:aead"] cipher = ["dep:cipher"] diff --git a/wrapper/rust/wolfssl-wolfcrypt/Makefile b/wrapper/rust/wolfssl-wolfcrypt/Makefile index f705c4f8c0..0b7eac1d47 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/Makefile +++ b/wrapper/rust/wolfssl-wolfcrypt/Makefile @@ -1,4 +1,4 @@ -FEATURES := rand_core,aead,cipher,digest,mac,signature,password-hash,kem +FEATURES := alloc,rand_core,aead,cipher,digest,mac,signature,password-hash,kem CARGO_FEATURE_FLAGS := --features $(FEATURES) .PHONY: all diff --git a/wrapper/rust/wolfssl-wolfcrypt/README.md b/wrapper/rust/wolfssl-wolfcrypt/README.md index d2509b508e..ec4fea9221 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/README.md +++ b/wrapper/rust/wolfssl-wolfcrypt/README.md @@ -3,6 +3,8 @@ The `wolfssl-wolfcrypt` crate is a Rust wrapper for the wolfCrypt cryptographic algorithms portion of the wolfSSL C library. +This crate requires wolfSSL version 5.9.0 or newer. + ## Installation The `wolfssl` C library must be installed to be used by the Rust crate. diff --git a/wrapper/rust/wolfssl-wolfcrypt/build.rs b/wrapper/rust/wolfssl-wolfcrypt/build.rs index 6495d6bdb8..3d0c7ea6b1 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/build.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/build.rs @@ -371,6 +371,9 @@ fn scan_cfg() -> Result<()> { check_cfg(&binding, "wc_Dh_ffdhe6144_Get", "dh_ffdhe_6144"); check_cfg(&binding, "wc_Dh_ffdhe8192_Get", "dh_ffdhe_8192"); + /* crypto callback */ + check_cfg(&binding, "wc_CryptoCb_RegisterDevice", "wolf_crypto_cb"); + /* ecc */ check_cfg(&binding, "wc_ecc_init", "ecc"); check_cfg(&binding, "wc_ecc_export_point_der_compressed", "ecc_comp_key"); diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/aes.rs b/wrapper/rust/wolfssl-wolfcrypt/src/aes.rs index 9aede17418..7d954d2164 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/aes.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/aes.rs @@ -33,13 +33,10 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; use aead::{AeadCore, AeadInPlace, KeyInit, KeySizeUser}; #[cfg(feature = "aead")] -use aead::generic_array::typenum::{U0, U12, U16, U32}; +use aead::generic_array::typenum::{U0, U12, U16, U24, U32}; #[cfg(all(feature = "cipher", not(feature = "aead")))] -use cipher::typenum::consts::{U16, U32}; - -#[cfg(feature = "cipher")] -use cipher::typenum::consts::U24; +use cipher::typenum::consts::{U16, U24, U32}; #[cfg(feature = "cipher")] use cipher::{ @@ -557,6 +554,58 @@ impl AeadInPlace for Aes128Ccm { } } +/// AES-192-CCM authenticated encryption (12-byte nonce, 16-byte tag). +#[cfg(all(aes_ccm, feature = "aead"))] +#[derive(Zeroize, ZeroizeOnDrop)] +pub struct Aes192Ccm { + key: [u8; 24], +} + +#[cfg(all(aes_ccm, feature = "aead"))] +impl KeySizeUser for Aes192Ccm { + type KeySize = U24; +} + +#[cfg(all(aes_ccm, feature = "aead"))] +impl AeadCore for Aes192Ccm { + type NonceSize = U12; + type TagSize = U16; + type CiphertextOverhead = U0; +} + +#[cfg(all(aes_ccm, feature = "aead"))] +impl KeyInit for Aes192Ccm { + fn new(key: &aead::Key) -> Self { + let mut k = [0u8; 24]; + k.copy_from_slice(key.as_ref()); + Aes192Ccm { key: k } + } +} + +#[cfg(all(aes_ccm, feature = "aead"))] +impl AeadInPlace for Aes192Ccm { + fn encrypt_in_place_detached( + &self, + nonce: &aead::Nonce, + associated_data: &[u8], + buffer: &mut [u8], + ) -> Result, aead::Error> { + let mut tag = aead::Tag::::default(); + ccm_encrypt_in_place(&self.key, nonce.as_ref(), associated_data, buffer, tag.as_mut())?; + Ok(tag) + } + + fn decrypt_in_place_detached( + &self, + nonce: &aead::Nonce, + associated_data: &[u8], + buffer: &mut [u8], + tag: &aead::Tag, + ) -> Result<(), aead::Error> { + ccm_decrypt_in_place(&self.key, nonce.as_ref(), associated_data, buffer, tag.as_ref()) + } +} + /// AES-256-CCM authenticated encryption (12-byte nonce, 16-byte tag). #[cfg(all(aes_ccm, feature = "aead"))] #[derive(Zeroize, ZeroizeOnDrop)] @@ -1713,6 +1762,58 @@ impl AeadInPlace for Aes128Gcm { } } +/// AES-192-GCM authenticated encryption (12-byte nonce, 16-byte tag). +#[cfg(all(aes_gcm, feature = "aead"))] +#[derive(Zeroize, ZeroizeOnDrop)] +pub struct Aes192Gcm { + key: [u8; 24], +} + +#[cfg(all(aes_gcm, feature = "aead"))] +impl KeySizeUser for Aes192Gcm { + type KeySize = U24; +} + +#[cfg(all(aes_gcm, feature = "aead"))] +impl AeadCore for Aes192Gcm { + type NonceSize = U12; + type TagSize = U16; + type CiphertextOverhead = U0; +} + +#[cfg(all(aes_gcm, feature = "aead"))] +impl KeyInit for Aes192Gcm { + fn new(key: &aead::Key) -> Self { + let mut k = [0u8; 24]; + k.copy_from_slice(key.as_ref()); + Aes192Gcm { key: k } + } +} + +#[cfg(all(aes_gcm, feature = "aead"))] +impl AeadInPlace for Aes192Gcm { + fn encrypt_in_place_detached( + &self, + nonce: &aead::Nonce, + associated_data: &[u8], + buffer: &mut [u8], + ) -> Result, aead::Error> { + let mut tag = aead::Tag::::default(); + gcm_encrypt_in_place(&self.key, nonce.as_ref(), associated_data, buffer, tag.as_mut())?; + Ok(tag) + } + + fn decrypt_in_place_detached( + &self, + nonce: &aead::Nonce, + associated_data: &[u8], + buffer: &mut [u8], + tag: &aead::Tag, + ) -> Result<(), aead::Error> { + gcm_decrypt_in_place(&self.key, nonce.as_ref(), associated_data, buffer, tag.as_ref()) + } +} + /// AES-256-GCM authenticated encryption (12-byte nonce, 16-byte tag). #[cfg(all(aes_gcm, feature = "aead"))] #[derive(Zeroize, ZeroizeOnDrop)] diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/blake2_digest.rs b/wrapper/rust/wolfssl-wolfcrypt/src/blake2_digest.rs new file mode 100644 index 0000000000..133b66d97f --- /dev/null +++ b/wrapper/rust/wolfssl-wolfcrypt/src/blake2_digest.rs @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/*! +RustCrypto `digest` trait implementations for the wolfCrypt BLAKE2 hash +types. + +Because BLAKE2b and BLAKE2s have variable digest sizes, this module exposes +typed wrappers that pin the digest size of an underlying [`crate::blake2`] +instance to a specific value, matching the typed aliases provided by the +RustCrypto `blake2` crate (`Blake2b512`, `Blake2b256`, `Blake2s256`, etc.). + +Each typed wrapper implements the traits from the `digest` crate +(`HashMarker`, `OutputSizeUser`, `BlockSizeUser`, `Update`, `Reset`, +`FixedOutput`, and `FixedOutputReset`). With these implementations the +`digest::Digest` trait becomes available via its blanket implementation, +allowing these hashers to be used anywhere a RustCrypto `Digest` is +accepted. + +Any failure returned by the underlying wolfCrypt call in a trait method +will result in a panic, matching the infallible signatures required by the +RustCrypto traits. +*/ + +use digest::consts::{U16, U24, U32, U48, U64, U128}; + +macro_rules! impl_blake2_digest { + ( + $(#[$attr:meta])* + $name:ident, + wc_ty = $wc_ty:path, + digest_size = $digest_size:literal, + out = $out_size:ty, + block = $block_size:ty + ) => { + $(#[$attr])* + pub struct $name { + blake2: $wc_ty, + } + + $(#[$attr])* + impl Default for $name { + fn default() -> Self { + Self { + blake2: <$wc_ty>::new($digest_size) + .expect("wolfCrypt BLAKE2 init failed"), + } + } + } + + $(#[$attr])* + impl digest::HashMarker for $name {} + + $(#[$attr])* + impl digest::OutputSizeUser for $name { + type OutputSize = $out_size; + } + + $(#[$attr])* + impl digest::block_api::BlockSizeUser for $name { + type BlockSize = $block_size; + } + + $(#[$attr])* + impl digest::Update for $name { + fn update(&mut self, data: &[u8]) { + <$wc_ty>::update(&mut self.blake2, data) + .expect("wolfCrypt BLAKE2 update failed"); + } + } + + $(#[$attr])* + impl digest::Reset for $name { + fn reset(&mut self) { + self.blake2 = <$wc_ty>::new($digest_size) + .expect("wolfCrypt BLAKE2 init failed"); + } + } + + $(#[$attr])* + impl digest::FixedOutput for $name { + fn finalize_into(mut self, out: &mut digest::Output) { + <$wc_ty>::finalize(&mut self.blake2, out.as_mut_slice()) + .expect("wolfCrypt BLAKE2 finalize failed"); + } + } + + $(#[$attr])* + impl digest::FixedOutputReset for $name { + fn finalize_into_reset(&mut self, out: &mut digest::Output) { + <$wc_ty>::finalize(&mut self.blake2, out.as_mut_slice()) + .expect("wolfCrypt BLAKE2 finalize failed"); + self.blake2 = <$wc_ty>::new($digest_size) + .expect("wolfCrypt BLAKE2 init failed"); + } + } + }; +} + +impl_blake2_digest! { + #[cfg(blake2b)] + Blake2b256, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 32, + out = U32, + block = U128 +} + +impl_blake2_digest! { + #[cfg(blake2b)] + Blake2b384, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 48, + out = U48, + block = U128 +} + +impl_blake2_digest! { + #[cfg(blake2b)] + Blake2b512, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 64, + out = U64, + block = U128 +} + +impl_blake2_digest! { + #[cfg(blake2s)] + Blake2s128, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 16, + out = U16, + block = U64 +} + +impl_blake2_digest! { + #[cfg(blake2s)] + Blake2s192, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 24, + out = U24, + block = U64 +} + +impl_blake2_digest! { + #[cfg(blake2s)] + Blake2s256, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 32, + out = U32, + block = U64 +} diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/blake2_mac.rs b/wrapper/rust/wolfssl-wolfcrypt/src/blake2_mac.rs new file mode 100644 index 0000000000..561cba9498 --- /dev/null +++ b/wrapper/rust/wolfssl-wolfcrypt/src/blake2_mac.rs @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2006-2026 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/*! +RustCrypto `digest::Mac` trait implementations for the wolfCrypt keyed +BLAKE2 types. + +These wrappers cover keyed BLAKE2 (the construction exposed by RustCrypto's +`blake2` crate as `Blake2bMac` / `Blake2sMac`), not the wolfCrypt-specific +HMAC-BLAKE2 construction. With these implementations the `digest::Mac` +trait becomes available via its blanket implementation, allowing these +types to be used anywhere a RustCrypto `Mac` is accepted. + +Each typed wrapper pins the digest size and the maximum key size to a +specific algorithm parameterization. The `Blake2sMac128`, `Blake2sMac192`, +and `Blake2sMac256` wrappers all accept keys of any length up to 32 bytes +(the BLAKE2s maximum), and the `Blake2bMac512` wrapper accepts keys of any +length up to 64 bytes (the BLAKE2b maximum), matching the variable-length +key behavior of the RustCrypto `blake2` crate's `Blake2sMac` / `Blake2bMac` +types. + +Any failure returned by the underlying wolfCrypt call in a trait method +will result in a panic, matching the infallible signatures required by the +RustCrypto traits. +*/ + +use digest::consts::{U16, U24, U32, U48, U64}; + +macro_rules! impl_blake2_mac { + ( + $(#[$attr:meta])* + $name:ident, + wc_ty = $wc_ty:path, + digest_size = $digest_size:literal, + out = $out_size:ty, + key = $key_size:ty + ) => { + $(#[$attr])* + pub struct $name { + blake2: $wc_ty, + } + + $(#[$attr])* + impl digest::MacMarker for $name {} + + $(#[$attr])* + impl digest::OutputSizeUser for $name { + type OutputSize = $out_size; + } + + $(#[$attr])* + impl digest::common::KeySizeUser for $name { + type KeySize = $key_size; + } + + $(#[$attr])* + impl digest::KeyInit for $name { + fn new(key: &digest::Key) -> Self { + Self { + blake2: <$wc_ty>::new_with_key($digest_size, key.as_slice()) + .expect("wolfCrypt BLAKE2 init failed"), + } + } + + fn new_from_slice(key: &[u8]) -> Result { + if key.len() > ::key_size() { + return Err(digest::InvalidLength); + } + Ok(Self { + blake2: <$wc_ty>::new_with_key($digest_size, key) + .map_err(|_| digest::InvalidLength)?, + }) + } + } + + $(#[$attr])* + impl digest::Update for $name { + fn update(&mut self, data: &[u8]) { + <$wc_ty>::update(&mut self.blake2, data) + .expect("wolfCrypt BLAKE2 update failed"); + } + } + + $(#[$attr])* + impl digest::FixedOutput for $name { + fn finalize_into(mut self, out: &mut digest::Output) { + <$wc_ty>::finalize(&mut self.blake2, out.as_mut_slice()) + .expect("wolfCrypt BLAKE2 finalize failed"); + } + } + }; +} + +impl_blake2_mac! { + #[cfg(blake2b)] + Blake2bMac256, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 32, + out = U32, + key = U64 +} + +impl_blake2_mac! { + #[cfg(blake2b)] + Blake2bMac384, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 48, + out = U48, + key = U64 +} + +impl_blake2_mac! { + #[cfg(blake2b)] + Blake2bMac512, + wc_ty = crate::blake2::BLAKE2b, + digest_size = 64, + out = U64, + key = U64 +} + +impl_blake2_mac! { + #[cfg(blake2s)] + Blake2sMac128, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 16, + out = U16, + key = U32 +} + +impl_blake2_mac! { + #[cfg(blake2s)] + Blake2sMac192, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 24, + out = U24, + key = U32 +} + +impl_blake2_mac! { + #[cfg(blake2s)] + Blake2sMac256, + wc_ty = crate::blake2::BLAKE2s, + digest_size = 32, + out = U32, + key = U32 +} diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs b/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs index ef3c3ca8bd..7be171ff2d 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs @@ -26,12 +26,15 @@ functionality. #![cfg(curve25519)] #[cfg(random)] -use crate::random::RNG; +use crate::random::{RNG, RngHandle}; use crate::sys; use core::mem::MaybeUninit; pub struct Curve25519Key { wc_key: sys::curve25519_key, + /// RNG bound via `set_rng`, kept alive while the C struct holds its pointer. + #[cfg(random)] + rng: Option, } impl Curve25519Key { @@ -73,7 +76,7 @@ impl Curve25519Key { /// Returns either Ok(curve25519key) on success or Err(e) containing the /// wolfSSL library error code value. #[cfg(random)] - pub fn generate(rng: &mut RNG) -> Result { + pub fn generate(rng: &RNG) -> Result { let mut wc_key: MaybeUninit = MaybeUninit::uninit(); let rc = unsafe { sys::wc_curve25519_init(wc_key.as_mut_ptr()) @@ -82,9 +85,13 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let rc = unsafe { - sys::wc_curve25519_make_key(&mut rng.wc_rng, Self::KEYSIZE as i32, + sys::wc_curve25519_make_key(rng.wc_rng, Self::KEYSIZE as i32, &mut curve25519key.wc_key) }; if rc != 0 { @@ -104,12 +111,12 @@ impl Curve25519Key { /// Returns either Ok(()) on success or Err(e) containing the wolfSSL /// library error code value. #[cfg(random)] - pub fn generate_priv(rng: &mut RNG, out: &mut [u8]) -> Result<(), i32> { + pub fn generate_priv(rng: &RNG, out: &mut [u8]) -> Result<(), i32> { if out.len() != Self::KEYSIZE { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } let rc = unsafe { - sys::wc_curve25519_make_priv(&mut rng.wc_rng, Self::KEYSIZE as i32, out.as_mut_ptr()) + sys::wc_curve25519_make_priv(rng.wc_rng, Self::KEYSIZE as i32, out.as_mut_ptr()) }; if rc != 0 { return Err(rc); @@ -137,7 +144,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let rc = unsafe { sys::wc_curve25519_import_private(private.as_ptr(), private_size, &mut curve25519key.wc_key) @@ -169,7 +180,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let endian = if big_endian {sys::EC25519_BIG_ENDIAN} else {sys::EC25519_LITTLE_ENDIAN}; let rc = unsafe { sys::wc_curve25519_import_private_ex(private.as_ptr(), @@ -203,7 +218,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let rc = unsafe { sys::wc_curve25519_import_private_raw(private.as_ptr(), private_size, public.as_ptr(), public_size, @@ -238,7 +257,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let endian = if big_endian {sys::EC25519_BIG_ENDIAN} else {sys::EC25519_LITTLE_ENDIAN}; let rc = unsafe { sys::wc_curve25519_import_private_raw_ex(private.as_ptr(), @@ -271,7 +294,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let rc = unsafe { sys::wc_curve25519_import_public(public.as_ptr(), public_size, &mut curve25519key.wc_key) @@ -303,7 +330,11 @@ impl Curve25519Key { return Err(rc); } let wc_key = unsafe { wc_key.assume_init() }; - let mut curve25519key = Curve25519Key { wc_key }; + let mut curve25519key = Curve25519Key { + wc_key, + #[cfg(random)] + rng: None, + }; let endian = if big_endian {sys::EC25519_BIG_ENDIAN} else {sys::EC25519_LITTLE_ENDIAN}; let rc = unsafe { sys::wc_curve25519_import_public_ex(public.as_ptr(), public_size, @@ -353,12 +384,12 @@ impl Curve25519Key { /// Returns either Ok(()) on success or Err(e) containing the wolfSSL /// library error code value. #[cfg(all(curve25519_blinding, random))] - pub fn make_pub_blind(private: &[u8], public: &mut [u8], rng: &mut RNG) -> Result<(), i32> { + pub fn make_pub_blind(private: &[u8], public: &mut [u8], rng: &RNG) -> Result<(), i32> { let private_size = crate::buffer_len_to_i32(private.len())?; let public_size = crate::buffer_len_to_i32(public.len())?; let rc = unsafe { sys::wc_curve25519_make_pub_blind(public_size, public.as_mut_ptr(), - private_size, private.as_ptr(), &mut rng.wc_rng) + private_size, private.as_ptr(), rng.wc_rng) }; if rc != 0 { return Err(rc); @@ -408,14 +439,14 @@ impl Curve25519Key { /// Returns either Ok(()) on success or Err(e) containing the wolfSSL /// library error code value. #[cfg(all(curve25519_blinding, random))] - pub fn make_pub_generic_blind(private: &[u8], public: &mut [u8], basepoint: &[u8], rng: &mut RNG) -> Result<(), i32> { + pub fn make_pub_generic_blind(private: &[u8], public: &mut [u8], basepoint: &[u8], rng: &RNG) -> Result<(), i32> { let private_size = crate::buffer_len_to_i32(private.len())?; let public_size = crate::buffer_len_to_i32(public.len())?; let basepoint_size = crate::buffer_len_to_i32(basepoint.len())?; let rc = unsafe { sys::wc_curve25519_generic_blind(public_size, public.as_mut_ptr(), private_size, private.as_ptr(), basepoint_size, basepoint.as_ptr(), - &mut rng.wc_rng) + rng.wc_rng) }; if rc != 0 { return Err(rc); @@ -454,27 +485,57 @@ impl Curve25519Key { /// This is necessary when generating a shared secret if wolfSSL is built /// with the `WOLFSSL_CURVE25519_BLINDING` build option enabled. /// + /// The key takes ownership of the RNG, so the underlying `WC_RNG` is + /// guaranteed to outlive this key. + /// /// # Parameters /// /// * `rng`: The `RNG` struct instance to associate with this - /// `Curve25519Key` instance. The `RNG` struct should not be moved in - /// memory after calling this method. + /// `Curve25519Key` instance. /// /// # Returns /// /// Returns Ok(()) on success or Err(e) containing the wolfSSL library /// error code value. #[cfg(all(curve25519_blinding, random))] - pub fn set_rng(&mut self, rng: &mut RNG) -> Result<(), i32> { + pub fn set_rng(&mut self, rng: RNG) -> Result<(), i32> { + let wc_rng = rng.wc_rng; let rc = unsafe { - sys::wc_curve25519_set_rng(&mut self.wc_key, &mut rng.wc_rng) + sys::wc_curve25519_set_rng(&mut self.wc_key, wc_rng) }; if rc != 0 { return Err(rc); } + self.rng = Some(RngHandle::Owned(rng)); Ok(()) } + /// Bind a shared `RNG` to this key. Available when the `alloc` feature + /// is enabled. + #[cfg(all(curve25519_blinding, random, feature = "alloc"))] + pub fn set_shared_rng(&mut self, rng: alloc::rc::Rc) -> Result<(), i32> { + let wc_rng = rng.wc_rng; + let rc = unsafe { + sys::wc_curve25519_set_rng(&mut self.wc_key, wc_rng) + }; + if rc != 0 { + return Err(rc); + } + self.rng = Some(RngHandle::Shared(rng)); + Ok(()) + } + + /// Borrow the RNG previously bound via `set_rng` or `set_shared_rng`. + #[cfg(random)] + pub fn rng(&self) -> Option<&RNG> { + match &self.rng { + Some(RngHandle::Owned(rng)) => Some(rng), + #[cfg(feature = "alloc")] + Some(RngHandle::Shared(rng)) => Some(rng), + None => None, + } + } + /// Compute a shared secret key given a secret private key and a received /// public key. It stores the generated secret key in the buffer out and /// returns the generated key size. Supports big or little endian. diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/dh.rs b/wrapper/rust/wolfssl-wolfcrypt/src/dh.rs index 36c4fca3fa..c6f2140f37 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/dh.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/dh.rs @@ -194,7 +194,7 @@ impl DH { /// } /// ``` #[cfg(all(dh_keygen, random))] - pub fn generate(rng: &mut RNG, modulus_size: i32) -> Result { + pub fn generate(rng: &RNG, modulus_size: i32) -> Result { Self::generate_ex(rng, modulus_size, None, None) } @@ -225,7 +225,7 @@ impl DH { /// } /// ``` #[cfg(all(dh_keygen, random))] - pub fn generate_ex(rng: &mut RNG, modulus_size: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + pub fn generate_ex(rng: &RNG, modulus_size: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let mut wc_dhkey: MaybeUninit = MaybeUninit::uninit(); let heap = match heap { Some(heap) => heap, @@ -242,7 +242,7 @@ impl DH { let wc_dhkey = unsafe { wc_dhkey.assume_init() }; let mut dh = DH { wc_dhkey }; let rc = unsafe { - sys::wc_DhGenerateParams(&mut rng.wc_rng, modulus_size, &mut dh.wc_dhkey) + sys::wc_DhGenerateParams(rng.wc_rng, modulus_size, &mut dh.wc_dhkey) }; if rc != 0 { return Err(rc); @@ -921,7 +921,7 @@ impl DH { /// } /// ``` #[cfg(random)] - pub fn new_from_pgq_with_check(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &mut RNG) -> Result { + pub fn new_from_pgq_with_check(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &RNG) -> Result { Self::new_from_pgq_with_check_ex(p, g, q, trusted, rng, None, None) } @@ -1030,7 +1030,7 @@ impl DH { /// } /// ``` #[cfg(random)] - pub fn new_from_pgq_with_check_ex(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + pub fn new_from_pgq_with_check_ex(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let p_size = crate::buffer_len_to_u32(p.len())?; let g_size = crate::buffer_len_to_u32(g.len())?; let q_size = crate::buffer_len_to_u32(q.len())?; @@ -1050,7 +1050,7 @@ impl DH { let wc_dhkey = unsafe { wc_dhkey.assume_init() }; let mut dh = DH { wc_dhkey }; let rc = unsafe { - sys::wc_DhSetCheckKey(&mut dh.wc_dhkey, p.as_ptr(), p_size, g.as_ptr(), g_size, q.as_ptr(), q_size, trusted, &mut rng.wc_rng) + sys::wc_DhSetCheckKey(&mut dh.wc_dhkey, p.as_ptr(), p_size, g.as_ptr(), g_size, q.as_ptr(), q_size, trusted, rng.wc_rng) }; if rc != 0 { return Err(rc); @@ -1509,13 +1509,13 @@ impl DH { /// } /// ``` #[cfg(random)] - pub fn generate_key_pair(&mut self, rng: &mut RNG, + pub fn generate_key_pair(&mut self, rng: &RNG, private: &mut [u8], private_size: &mut u32, public: &mut [u8], public_size: &mut u32) -> Result<(), i32> { *private_size = crate::buffer_len_to_u32(private.len())?; *public_size = crate::buffer_len_to_u32(public.len())?; let rc = unsafe { - sys::wc_DhGenerateKeyPair(&mut self.wc_dhkey, &mut rng.wc_rng, + sys::wc_DhGenerateKeyPair(&mut self.wc_dhkey, rng.wc_rng, private.as_mut_ptr(), private_size, public.as_mut_ptr(), public_size) }; diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs b/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs index 0005147859..6e1ac0564c 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs @@ -159,7 +159,7 @@ impl Dilithium { /// } /// ``` #[cfg(all(dilithium_make_key, random))] - pub fn generate(level: u8, rng: &mut RNG) -> Result { + pub fn generate(level: u8, rng: &RNG) -> Result { Self::generate_ex(level, rng, None, None) } @@ -193,7 +193,7 @@ impl Dilithium { #[cfg(all(dilithium_make_key, random))] pub fn generate_ex( level: u8, - rng: &mut RNG, + rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option, ) -> Result { @@ -202,7 +202,7 @@ impl Dilithium { if rc != 0 { return Err(rc); } - let rc = unsafe { sys::wc_dilithium_make_key(&mut key.ws_key, &mut rng.wc_rng) }; + let rc = unsafe { sys::wc_dilithium_make_key(&mut key.ws_key, rng.wc_rng) }; if rc != 0 { return Err(rc); } @@ -859,7 +859,7 @@ impl Dilithium { &mut self, msg: &[u8], sig: &mut [u8], - rng: &mut RNG, + rng: &RNG, ) -> Result { let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; @@ -869,7 +869,7 @@ impl Dilithium { msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, &mut self.ws_key, - &mut rng.wc_rng, + rng.wc_rng, ) }; if rc != 0 { @@ -917,7 +917,7 @@ impl Dilithium { ctx: &[u8], msg: &[u8], sig: &mut [u8], - rng: &mut RNG, + rng: &RNG, ) -> Result { if ctx.len() > 255 { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); @@ -931,7 +931,7 @@ impl Dilithium { msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, &mut self.ws_key, - &mut rng.wc_rng, + rng.wc_rng, ) }; if rc != 0 { @@ -966,7 +966,7 @@ impl Dilithium { hash_alg: i32, hash: &[u8], sig: &mut [u8], - rng: &mut RNG, + rng: &RNG, ) -> Result { if ctx.len() > 255 { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); @@ -981,7 +981,7 @@ impl Dilithium { hash.as_ptr(), hash_len, sig.as_mut_ptr(), &mut sig_len, &mut self.ws_key, - &mut rng.wc_rng, + rng.wc_rng, ) }; if rc != 0 { diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs b/wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs index d154654a96..d0e3fefc79 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs @@ -30,8 +30,7 @@ wolfSSL `ecc_key` object. It ensures proper initialization and deallocation. use crate::sys; #[cfg(random)] -use crate::random::RNG; -use core::mem::{MaybeUninit}; +use crate::random::{RNG, RngHandle}; /// Rust wrapper for wolfSSL `ecc_point` object. pub struct ECCPoint { @@ -60,11 +59,11 @@ impl ECCPoint { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::{ECC,ECCPoint}; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); - /// let ecc_point = ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); + /// let ecc_point = ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// let mut der = [0u8; 128]; /// let size = ecc_point.export_der(&mut der, curve_id).expect("Error with export_der()"); /// ECCPoint::import_der(&der[0..size], curve_id, None).expect("Error with import_der()"); @@ -118,11 +117,11 @@ impl ECCPoint { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::{ECC,ECCPoint}; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); - /// let ecc_point = ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); + /// let ecc_point = ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// let mut der = [0u8; 128]; /// let size = ecc_point.export_der(&mut der, curve_id).expect("Error with export_der()"); /// ECCPoint::import_der_ex(&der[0..size], curve_id, 0, None).expect("Error with import_der_ex()"); @@ -173,11 +172,11 @@ impl ECCPoint { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::{ECC,ECCPoint}; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); - /// let ecc_point = ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); + /// let ecc_point = ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// let mut der = [0u8; 128]; /// let size = ecc_point.export_der(&mut der, curve_id).expect("Error with export_der()"); /// assert!(size > 0 && size <= der.len()); @@ -220,11 +219,11 @@ impl ECCPoint { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::{ECC,ECCPoint}; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); - /// let ecc_point = ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); + /// let ecc_point = ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// let mut der = [0u8; 128]; /// let size = ecc_point.export_der_compressed(&mut der, curve_id).expect("Error with export_der_compressed()"); /// } @@ -256,9 +255,9 @@ impl ECCPoint { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); - /// let mut ecc_point = ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); + /// let mut ecc_point = ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// ecc_point.forcezero(); /// } /// ``` @@ -290,13 +289,18 @@ impl Drop for ECCPoint { /// The `ECC` struct manages the lifecycle of a wolfSSL `ecc_key` object. /// -/// It ensures proper initialization and deallocation. +/// It ensures proper initialization and deallocation. The struct holds a +/// pointer to a `sys::ecc_key` allocated on the C heap. /// /// An instance can be created with `generate()`, `import_x963()`, /// `import_x963_ex()`, `import_private_key()`, `import_private_key_ex()`, /// `import_raw()`, or `import_raw_ex()`. pub struct ECC { - pub(crate) wc_ecc_key: sys::ecc_key, + pub(crate) wc_ecc_key: *mut sys::ecc_key, + /// RNG bound to this key via `set_rng`, kept alive for as long as the C + /// struct holds its pointer. + #[cfg(random)] + rng: Option, } #[cfg(ecc_curve_ids)] @@ -392,6 +396,25 @@ impl ECC { pub const FLAG_COFACTOR: i32 = sys::WC_ECC_FLAG_COFACTOR as i32; pub const FLAG_DEC_SIGN: i32 = sys::WC_ECC_FLAG_DEC_SIGN as i32; + /// Allocate and initialize a new `sys::ecc_key` on the C heap. + fn new_ecc_key(heap: *mut core::ffi::c_void, dev_id: i32) -> Result<*mut sys::ecc_key, i32> { + let key = unsafe { sys::wc_ecc_key_new(heap) }; + if key.is_null() { + return Err(sys::wolfCrypt_ErrorCodes_MEMORY_E); + } + // wc_ecc_key_new() always initializes the key with INVALID_DEVID. + // Calling wc_ecc_init_ex() a second time to install the user's dev_id + // would re-run every initialization step (including allocations under + // some build configurations such as async crypto without WOLF_CRYPTO_CB) + // and orphan resources from the first init. Instead, just patch devId + // in place for WOLF_CRYPTO_CB builds. + #[cfg(wolf_crypto_cb)] + unsafe { (*key).devId = dev_id; } + #[cfg(not(wolf_crypto_cb))] + let _ = dev_id; + Ok(key) + } + /// Generate a new ECC key with the given size. /// /// # Parameters @@ -415,30 +438,23 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// ecc.check().expect("Error with check()"); /// } /// ``` #[cfg(random)] - pub fn generate(size: i32, rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + pub fn generate(size: i32, rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let rc = unsafe { - sys::wc_ecc_make_key(&mut rng.wc_rng, size, &mut ecc.wc_ecc_key) + sys::wc_ecc_make_key(rng.wc_rng, size, ecc.wc_ecc_key) }; if rc != 0 { return Err(rc); @@ -470,32 +486,25 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate_ex()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate_ex()"); /// ecc.check().expect("Error with check()"); /// } /// ``` #[cfg(random)] - pub fn generate_ex(size: i32, rng: &mut RNG, curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + pub fn generate_ex(size: i32, rng: &RNG, curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let rc = unsafe { - sys::wc_ecc_make_key_ex(&mut rng.wc_rng, size, &mut ecc.wc_ecc_key, curve_id) + sys::wc_ecc_make_key_ex(rng.wc_rng, size, ecc.wc_ecc_key, curve_id) }; if rc != 0 { return Err(rc); @@ -528,32 +537,25 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex2(curve_size, &mut rng, curve_id, ECC::FLAG_COFACTOR, None, None).expect("Error with generate_ex2()"); + /// let mut ecc = ECC::generate_ex2(curve_size, &rng, curve_id, ECC::FLAG_COFACTOR, None, None).expect("Error with generate_ex2()"); /// ecc.check().expect("Error with check()"); /// } /// ``` #[cfg(random)] - pub fn generate_ex2(size: i32, rng: &mut RNG, curve_id: i32, flags: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + pub fn generate_ex2(size: i32, rng: &RNG, curve_id: i32, flags: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let rc = unsafe { - sys::wc_ecc_make_key_ex2(&mut rng.wc_rng, size, &mut ecc.wc_ecc_key, curve_id, flags) + sys::wc_ecc_make_key_ex2(rng.wc_rng, size, ecc.wc_ecc_key, curve_id, flags) }; if rc != 0 { return Err(rc); @@ -580,10 +582,10 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); /// ecc.check().expect("Error with check()"); /// } /// ``` @@ -617,32 +619,25 @@ impl ECC { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; /// use std::fs; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); /// } /// ``` pub fn import_der(der: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let mut idx = 0u32; let der_size = crate::buffer_len_to_u32(der.len())?; let rc = unsafe { - sys::wc_EccPrivateKeyDecode(der.as_ptr(), &mut idx, &mut ecc.wc_ecc_key, der_size) + sys::wc_EccPrivateKeyDecode(der.as_ptr(), &mut idx, ecc.wc_ecc_key, der_size) }; if rc != 0 { return Err(rc); @@ -672,13 +667,13 @@ impl ECC { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; /// use std::fs; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// assert!(signature_length > 0 && signature_length <= signature.len()); /// let signature = &mut signature[0..signature_length]; /// let key_path = "../../../certs/ecc-client-keyPub.der"; @@ -687,25 +682,18 @@ impl ECC { /// } /// ``` pub fn import_public_der(der: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let mut idx = 0u32; let der_size = crate::buffer_len_to_u32(der.len())?; let rc = unsafe { - sys::wc_EccPublicKeyDecode(der.as_ptr(), &mut idx, &mut ecc.wc_ecc_key, der_size) + sys::wc_EccPublicKeyDecode(der.as_ptr(), &mut idx, ecc.wc_ecc_key, der_size) }; if rc != 0 { return Err(rc); @@ -738,11 +726,11 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &signature[0..signature_length]; /// let mut d = [0u8; 32]; /// let d_size = ecc.export_private(&mut d).expect("Error with export_private()"); @@ -756,27 +744,20 @@ impl ECC { /// ``` #[cfg(ecc_import)] pub fn import_private_key(priv_buf: &[u8], pub_buf: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let priv_size = crate::buffer_len_to_u32(priv_buf.len())?; let pub_ptr = if pub_buf.is_empty() {core::ptr::null()} else {pub_buf.as_ptr()}; let pub_size = crate::buffer_len_to_u32(pub_buf.len())?; let rc = unsafe { sys::wc_ecc_import_private_key(priv_buf.as_ptr(), priv_size, - pub_ptr, pub_size, &mut ecc.wc_ecc_key) + pub_ptr, pub_size, ecc.wc_ecc_key) }; if rc != 0 { return Err(rc); @@ -810,13 +791,13 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate_ex()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate_ex()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &signature[0..signature_length]; /// let mut d = [0u8; 32]; /// let d_size = ecc.export_private(&mut d).expect("Error with export_private()"); @@ -830,27 +811,20 @@ impl ECC { /// ``` #[cfg(ecc_import)] pub fn import_private_key_ex(priv_buf: &[u8], pub_buf: &[u8], curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let priv_size = crate::buffer_len_to_u32(priv_buf.len())?; let pub_ptr = if pub_buf.is_empty() {core::ptr::null()} else {pub_buf.as_ptr()}; let pub_size = crate::buffer_len_to_u32(pub_buf.len())?; let rc = unsafe { sys::wc_ecc_import_private_key_ex(priv_buf.as_ptr(), priv_size, - pub_ptr, pub_size, &mut ecc.wc_ecc_key, curve_id) + pub_ptr, pub_size, ecc.wc_ecc_key, curve_id) }; if rc != 0 { return Err(rc); @@ -889,27 +863,24 @@ impl ECC { /// ``` #[cfg(ecc_import)] pub fn import_raw(qx: &[u8], qy: &[u8], d: &[u8], curve_name: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), - }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); + if qx.is_empty() || qy.is_empty() || d.is_empty() || curve_name.is_empty() || + qx[qx.len() - 1] != 0 || qy[qy.len() - 1] != 0 || d[d.len() - 1] != 0 || curve_name[curve_name.len() - 1] != 0 { + return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG); } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, + }; let qx_ptr = qx.as_ptr() as *const core::ffi::c_char; let qy_ptr = qy.as_ptr() as *const core::ffi::c_char; let d_ptr = d.as_ptr() as *const core::ffi::c_char; let curve_name_ptr = curve_name.as_ptr() as *const core::ffi::c_char; let rc = unsafe { - sys::wc_ecc_import_raw(&mut ecc.wc_ecc_key, qx_ptr, qy_ptr, d_ptr, + sys::wc_ecc_import_raw(ecc.wc_ecc_key, qx_ptr, qy_ptr, d_ptr, curve_name_ptr) }; if rc != 0 { @@ -949,26 +920,23 @@ impl ECC { /// ``` #[cfg(ecc_import)] pub fn import_raw_ex(qx: &[u8], qy: &[u8], d: &[u8], curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), - }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); + if qx.is_empty() || qy.is_empty() || d.is_empty() || + qx[qx.len() - 1] != 0 || qy[qy.len() - 1] != 0 || d[d.len() - 1] != 0 { + return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG); } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, + }; let qx_ptr = qx.as_ptr() as *const core::ffi::c_char; let qy_ptr = qy.as_ptr() as *const core::ffi::c_char; let d_ptr = d.as_ptr() as *const core::ffi::c_char; let rc = unsafe { - sys::wc_ecc_import_raw_ex(&mut ecc.wc_ecc_key, qx_ptr, qy_ptr, + sys::wc_ecc_import_raw_ex(ecc.wc_ecc_key, qx_ptr, qy_ptr, d_ptr, curve_id) }; if rc != 0 { @@ -1001,10 +969,10 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate()"); /// let mut qx = [0u8; 32]; /// let mut qx_len = 0u32; /// let mut qy = [0u8; 32]; @@ -1017,23 +985,20 @@ impl ECC { /// ``` #[cfg(ecc_import)] pub fn import_unsigned(qx: &[u8], qy: &[u8], d: &[u8], curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), - }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); + let curve_size = Self::get_curve_size_from_id(curve_id)? as usize; + if qx.len() < curve_size || qy.len() < curve_size || d.len() < curve_size { + return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG); } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, + }; let rc = unsafe { - sys::wc_ecc_import_unsigned(&mut ecc.wc_ecc_key, qx.as_ptr(), + sys::wc_ecc_import_unsigned(ecc.wc_ecc_key, qx.as_ptr(), qy.as_ptr(), d.as_ptr(), curve_id) }; if rc != 0 { @@ -1065,8 +1030,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut x963 = [0u8; 128]; /// let x963_size = ecc.export_x963(&mut x963).expect("Error with export_x963()"); /// let x963 = &x963[0..x963_size]; @@ -1076,23 +1041,16 @@ impl ECC { #[cfg(ecc_import)] pub fn import_x963(din: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let rc = unsafe { - sys::wc_ecc_import_x963(din.as_ptr(), din_size, &mut ecc.wc_ecc_key) + sys::wc_ecc_import_x963(din.as_ptr(), din_size, ecc.wc_ecc_key) }; if rc != 0 { return Err(rc); @@ -1126,10 +1084,10 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let curve_id = ECC::SECP256R1; /// let curve_size = ECC::get_curve_size_from_id(curve_id).expect("Error with get_curve_size_from_id()"); - /// let mut ecc = ECC::generate_ex(curve_size, &mut rng, curve_id, None, None).expect("Error with generate_ex()"); + /// let mut ecc = ECC::generate_ex(curve_size, &rng, curve_id, None, None).expect("Error with generate_ex()"); /// let mut x963 = [0u8; 128]; /// let x963_size = ecc.export_x963(&mut x963).expect("Error with export_x963()"); /// let x963 = &x963[0..x963_size]; @@ -1139,23 +1097,16 @@ impl ECC { #[cfg(ecc_import)] pub fn import_x963_ex(din: &[u8], curve_id: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; - let mut wc_ecc_key: MaybeUninit = MaybeUninit::uninit(); - let heap = match heap { - Some(heap) => heap, - None => core::ptr::null_mut(), + let heap = heap.unwrap_or(core::ptr::null_mut()); + let dev_id = dev_id.unwrap_or(sys::INVALID_DEVID); + let wc_ecc_key = Self::new_ecc_key(heap, dev_id)?; + let ecc = ECC { + wc_ecc_key, + #[cfg(random)] + rng: None, }; - let dev_id = match dev_id { - Some(dev_id) => dev_id, - None => sys::INVALID_DEVID, - }; - let rc = unsafe { sys::wc_ecc_init_ex(wc_ecc_key.as_mut_ptr(), heap, dev_id) }; - if rc != 0 { - return Err(rc); - } - let wc_ecc_key = unsafe { wc_ecc_key.assume_init() }; - let mut ecc = ECC { wc_ecc_key }; let rc = unsafe { - sys::wc_ecc_import_x963_ex(din.as_ptr(), din_size, &mut ecc.wc_ecc_key, curve_id) + sys::wc_ecc_import_x963_ex(din.as_ptr(), din_size, ecc.wc_ecc_key, curve_id) }; if rc != 0 { return Err(rc); @@ -1196,13 +1147,13 @@ impl ECC { /// hex_string.push('\0'); /// hex_string /// } - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &mut signature[0..signature_length]; /// let mut r = [0u8; 32]; /// let mut r_size = 0u32; @@ -1258,13 +1209,13 @@ impl ECC { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &mut signature[0..signature_length]; /// let mut r = [0u8; 32]; /// let mut r_size = 0u32; @@ -1311,13 +1262,13 @@ impl ECC { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &mut signature[0..signature_length]; /// let mut r = [0u8; 32]; /// let mut r_size = 0u32; @@ -1360,13 +1311,13 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// ecc.check().expect("Error with check()"); /// } /// ``` pub fn check(&mut self) -> Result<(), i32> { - let rc = unsafe { sys::wc_ecc_check_key(&mut self.wc_ecc_key) }; + let rc = unsafe { sys::wc_ecc_check_key(self.wc_ecc_key) }; if rc != 0 { return Err(rc); } @@ -1396,8 +1347,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut qx = [0u8; 32]; /// let mut qx_len = 0u32; /// let mut qy = [0u8; 32]; @@ -1414,7 +1365,7 @@ impl ECC { *qy_len = crate::buffer_len_to_u32(qy.len())?; *d_len = crate::buffer_len_to_u32(d.len())?; let rc = unsafe { - sys::wc_ecc_export_private_raw(&mut self.wc_ecc_key, + sys::wc_ecc_export_private_raw(self.wc_ecc_key, qx.as_mut_ptr(), qx_len, qy.as_mut_ptr(), qy_len, d.as_mut_ptr(), d_len) @@ -1451,8 +1402,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut qx = [0u8; 32]; /// let mut qx_len = 0u32; /// let mut qy = [0u8; 32]; @@ -1477,7 +1428,7 @@ impl ECC { sys::WC_TYPE_UNSIGNED_BIN as i32 }; let rc = unsafe { - sys::wc_ecc_export_ex(&mut self.wc_ecc_key, + sys::wc_ecc_export_ex(self.wc_ecc_key, qx.as_mut_ptr(), qx_len, qy.as_mut_ptr(), qy_len, d.as_mut_ptr(), d_len, @@ -1507,8 +1458,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut d = [0u8; 32]; /// let d_size = ecc.export_private(&mut d).expect("Error with export_private()"); /// assert_eq!(d_size, 32); @@ -1518,7 +1469,7 @@ impl ECC { pub fn export_private(&mut self, d: &mut [u8]) -> Result { let mut d_size = crate::buffer_len_to_u32(d.len())?; let rc = unsafe { - sys::wc_ecc_export_private_only(&mut self.wc_ecc_key, + sys::wc_ecc_export_private_only(self.wc_ecc_key, d.as_mut_ptr(), &mut d_size) }; if rc != 0 { @@ -1548,8 +1499,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut qx = [0u8; 32]; /// let mut qx_len = 0u32; /// let mut qy = [0u8; 32]; @@ -1563,7 +1514,7 @@ impl ECC { *qx_len = crate::buffer_len_to_u32(qx.len())?; *qy_len = crate::buffer_len_to_u32(qy.len())?; let rc = unsafe { - sys::wc_ecc_export_public_raw(&mut self.wc_ecc_key, + sys::wc_ecc_export_public_raw(self.wc_ecc_key, qx.as_mut_ptr(), qx_len, qy.as_mut_ptr(), qy_len) }; @@ -1591,8 +1542,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut x963 = [0u8; 128]; /// let _x963_size = ecc.export_x963(&mut x963).expect("Error with export_x963()"); /// } @@ -1601,7 +1552,7 @@ impl ECC { pub fn export_x963(&mut self, dout: &mut [u8]) -> Result { let mut out_len = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { - sys::wc_ecc_export_x963(&mut self.wc_ecc_key, dout.as_mut_ptr(), &mut out_len) + sys::wc_ecc_export_x963(self.wc_ecc_key, dout.as_mut_ptr(), &mut out_len) }; if rc != 0 { return Err(rc); @@ -1627,8 +1578,8 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut x963 = [0u8; 128]; /// let _x963_size = ecc.export_x963_compressed(&mut x963).expect("Error with export_x963_compressed()"); /// } @@ -1637,7 +1588,7 @@ impl ECC { pub fn export_x963_compressed(&mut self, dout: &mut [u8]) -> Result { let mut out_len = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { - sys::wc_ecc_export_x963_ex(&mut self.wc_ecc_key, dout.as_mut_ptr(), &mut out_len, 1) + sys::wc_ecc_export_x963_ex(self.wc_ecc_key, dout.as_mut_ptr(), &mut out_len, 1) }; if rc != 0 { return Err(rc); @@ -1666,21 +1617,21 @@ impl ECC { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); - /// ecc.make_pub(Some(&mut rng)).expect("Error with make_pub()"); + /// ecc.make_pub(Some(&rng)).expect("Error with make_pub()"); /// } /// ``` #[cfg(random)] - pub fn make_pub(&mut self, rng: Option<&mut RNG>) -> Result<(), i32> { + pub fn make_pub(&mut self, rng: Option<&RNG>) -> Result<(), i32> { let rng_ptr = match rng { - Some(rng) => &mut rng.wc_rng, + Some(rng) => rng.wc_rng, None => core::ptr::null_mut(), }; let rc = unsafe { - sys::wc_ecc_make_pub_ex(&mut self.wc_ecc_key, core::ptr::null_mut(), rng_ptr) + sys::wc_ecc_make_pub_ex(self.wc_ecc_key, core::ptr::null_mut(), rng_ptr) }; if rc != 0 { return Err(rc); @@ -1710,17 +1661,17 @@ impl ECC { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); + /// let rng = RNG::new().expect("Failed to create RNG"); /// let key_path = "../../../certs/ecc-client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut ecc = ECC::import_der(&der, None, None).expect("Error with import_der()"); - /// ecc.make_pub_to_point(Some(&mut rng), None).expect("Error with make_pub_to_point()"); + /// ecc.make_pub_to_point(Some(&rng), None).expect("Error with make_pub_to_point()"); /// } /// ``` #[cfg(random)] - pub fn make_pub_to_point(&mut self, rng: Option<&mut RNG>, heap: Option<*mut core::ffi::c_void>) -> Result { + pub fn make_pub_to_point(&mut self, rng: Option<&RNG>, heap: Option<*mut core::ffi::c_void>) -> Result { let rng_ptr = match rng { - Some(rng) => &mut rng.wc_rng, + Some(rng) => rng.wc_rng, None => core::ptr::null_mut(), }; let heap = match heap { @@ -1733,7 +1684,7 @@ impl ECC { } let ecc_point = ECCPoint { wc_ecc_point, heap }; let rc = unsafe { - sys::wc_ecc_make_pub_ex(&mut self.wc_ecc_key, wc_ecc_point, rng_ptr) + sys::wc_ecc_make_pub_ex(self.wc_ecc_key, wc_ecc_point, rng_ptr) }; if rc != 0 { return Err(rc); @@ -1749,8 +1700,7 @@ impl ECC { /// # Parameters /// /// * `rng`: The `RNG` struct instance to associate with this `ECC` - /// instance. The `RNG` struct should not be moved in memory after - /// calling this method. + /// instance. /// /// # Returns /// @@ -1765,22 +1715,51 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); - /// ecc.set_rng(&mut rng).expect("Error with set_rng()"); + /// let blinding_rng = RNG::new().expect("Failed to create RNG"); + /// let key_gen_rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &key_gen_rng, None, None).expect("Error with generate()"); + /// ecc.set_rng(blinding_rng).expect("Error with set_rng()"); /// } /// ``` #[cfg(random)] - pub fn set_rng(&mut self, rng: &mut RNG) -> Result<(), i32> { + pub fn set_rng(&mut self, rng: RNG) -> Result<(), i32> { + let wc_rng = rng.wc_rng; let rc = unsafe { - sys::wc_ecc_set_rng(&mut self.wc_ecc_key, &mut rng.wc_rng) + sys::wc_ecc_set_rng(self.wc_ecc_key, wc_rng) }; if rc != 0 { return Err(rc); } + self.rng = Some(RngHandle::Owned(rng)); Ok(()) } + /// Bind a shared `RNG` to this key. Available when the `alloc` feature + /// is enabled. + #[cfg(all(random, feature = "alloc"))] + pub fn set_shared_rng(&mut self, rng: alloc::rc::Rc) -> Result<(), i32> { + let wc_rng = rng.wc_rng; + let rc = unsafe { + sys::wc_ecc_set_rng(self.wc_ecc_key, wc_rng) + }; + if rc != 0 { + return Err(rc); + } + self.rng = Some(RngHandle::Shared(rng)); + Ok(()) + } + + /// Borrow the RNG previously bound via `set_rng` or `set_shared_rng`. + #[cfg(random)] + pub fn rng(&self) -> Option<&RNG> { + match &self.rng { + Some(RngHandle::Owned(rng)) => Some(rng), + #[cfg(feature = "alloc")] + Some(RngHandle::Shared(rng)) => Some(rng), + None => None, + } + } + /// Compute the ECDH shared secret using this key's private component /// and the peer public key. /// @@ -1797,17 +1776,18 @@ impl ECC { /// # Example /// /// ```rust - /// #[cfg(all(ecc_dh, random))] + /// #[cfg(all(ecc_dh, random, feature = "alloc"))] /// { + /// use std::rc::Rc; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc0 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); - /// let mut ecc1 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = Rc::new(RNG::new().expect("Failed to create RNG")); + /// let mut ecc0 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); + /// let mut ecc1 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let mut ss0 = [0u8; 128]; /// let mut ss1 = [0u8; 128]; - /// ecc0.set_rng(&mut rng).expect("Error with set_rng()"); - /// ecc1.set_rng(&mut rng).expect("Error with set_rng()"); + /// ecc0.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); + /// ecc1.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let ss0_size = ecc0.shared_secret(&mut ecc1, &mut ss0).expect("Error with shared_secret()"); /// let ss1_size = ecc1.shared_secret(&mut ecc0, &mut ss1).expect("Error with shared_secret()"); /// assert_eq!(ss0_size, ss1_size); @@ -1820,8 +1800,8 @@ impl ECC { pub fn shared_secret(&mut self, peer_key: &mut ECC, dout: &mut [u8]) -> Result { let mut out_len = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { - sys::wc_ecc_shared_secret(&mut self.wc_ecc_key, - &mut peer_key.wc_ecc_key, dout.as_mut_ptr(), &mut out_len) + sys::wc_ecc_shared_secret(self.wc_ecc_key, + peer_key.wc_ecc_key, dout.as_mut_ptr(), &mut out_len) }; if rc != 0 { return Err(rc); @@ -1846,18 +1826,19 @@ impl ECC { /// # Example /// /// ```rust - /// #[cfg(all(ecc_dh, random))] + /// #[cfg(all(ecc_dh, random, feature = "alloc"))] /// { + /// use std::rc::Rc; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc0 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); - /// let mut ecc1 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = Rc::new(RNG::new().expect("Failed to create RNG")); + /// let mut ecc0 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); + /// let mut ecc1 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let ecc1_point = ecc1.make_pub_to_point(None, None).expect("Error with make_pub_to_point()"); /// let mut ss0 = [0u8; 128]; /// let mut ss1 = [0u8; 128]; - /// ecc0.set_rng(&mut rng).expect("Error with set_rng()"); - /// ecc1.set_rng(&mut rng).expect("Error with set_rng()"); + /// ecc0.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); + /// ecc1.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let ss0_size = ecc0.shared_secret_ex(&ecc1_point, &mut ss0).expect("Error with shared_secret_ex()"); /// let ss1_size = ecc1.shared_secret(&mut ecc0, &mut ss1).expect("Error with shared_secret()"); /// assert_eq!(ss0_size, ss1_size); @@ -1870,7 +1851,7 @@ impl ECC { pub fn shared_secret_ex(&mut self, peer: &ECCPoint, dout: &mut [u8]) -> Result { let mut out_len = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { - sys::wc_ecc_shared_secret_ex(&mut self.wc_ecc_key, + sys::wc_ecc_shared_secret_ex(self.wc_ecc_key, peer.wc_ecc_point, dout.as_mut_ptr(), &mut out_len) }; if rc != 0 { @@ -1899,23 +1880,23 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &mut signature[0..signature_length]; /// let valid = ecc.verify_hash(&signature, &hash).expect("Error with verify_hash()"); /// assert_eq!(valid, true); /// } /// ``` #[cfg(all(ecc_sign, random))] - pub fn sign_hash(&mut self, din: &[u8], dout: &mut [u8], rng: &mut RNG) -> Result { + pub fn sign_hash(&mut self, din: &[u8], dout: &mut [u8], rng: &RNG) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; let mut dout_size = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { sys::wc_ecc_sign_hash(din.as_ptr(), din_size, dout.as_mut_ptr(), - &mut dout_size, &mut rng.wc_rng, &mut self.wc_ecc_key) + &mut dout_size, rng.wc_rng, self.wc_ecc_key) }; if rc != 0 { return Err(rc); @@ -1942,11 +1923,11 @@ impl ECC { /// { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::ecc::ECC; - /// let mut rng = RNG::new().expect("Failed to create RNG"); - /// let mut ecc = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + /// let rng = RNG::new().expect("Failed to create RNG"); + /// let mut ecc = ECC::generate(32, &rng, None, None).expect("Error with generate()"); /// let hash = [0x42u8; 32]; /// let mut signature = [0u8; 128]; - /// let signature_length = ecc.sign_hash(&hash, &mut signature, &mut rng).expect("Error with sign_hash()"); + /// let signature_length = ecc.sign_hash(&hash, &mut signature, &rng).expect("Error with sign_hash()"); /// let signature = &mut signature[0..signature_length]; /// let valid = ecc.verify_hash(&signature, &hash).expect("Error with verify_hash()"); /// assert_eq!(valid, true); @@ -1959,7 +1940,7 @@ impl ECC { let hash_len = crate::buffer_len_to_u32(hash.len())?; let rc = unsafe { sys::wc_ecc_verify_hash(sig.as_ptr(), sig_len, - hash.as_ptr(), hash_len, &mut res, &mut self.wc_ecc_key) + hash.as_ptr(), hash_len, &mut res, self.wc_ecc_key) }; if rc != 0 { return Err(rc); @@ -1968,22 +1949,16 @@ impl ECC { } } -impl ECC { - fn zeroize(&mut self) { - unsafe { crate::zeroize_raw(&mut self.wc_ecc_key); } - } -} - impl Drop for ECC { /// Safely free the underlying wolfSSL ECC context. /// - /// This calls the `wc_ecc_key_free()` wolfssl library function. + /// This calls the `wc_ecc_key_free()` wolfssl library function, which + /// frees the C-heap-allocated `ecc_key` object. /// /// The Rust Drop trait guarantees that this method is called when the ECC /// struct goes out of scope, automatically cleaning up resources and /// preventing memory leaks. fn drop(&mut self) { - unsafe { sys::wc_ecc_free(&mut self.wc_ecc_key); } - self.zeroize(); + unsafe { sys::wc_ecc_key_free(self.wc_ecc_key); } } } diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs b/wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs index b771694b05..f3c06d451f 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs @@ -252,9 +252,9 @@ macro_rules! define_ecdsa_curve { sys::wc_SignatureType_WC_SIGNATURE_TYPE_ECC, msg.as_ptr(), msg_len, der.as_mut_ptr(), &mut der_len, - &mut self.inner.wc_ecc_key as *mut _ as *mut c_void, + self.inner.wc_ecc_key as *mut c_void, size_of::() as u32, - &mut self.rng.wc_rng, + self.rng.wc_rng, ) }; if rc != 0 { @@ -313,7 +313,7 @@ macro_rules! define_ecdsa_curve { fn verify(&self, msg: &[u8], sig: &$signature) -> Result<(), Error> { let mut der = [0u8; $der_max]; let der_len = rs_to_der::<$field_size>(&sig.0, &mut der)?; - let mut key = ECC::import_x963_ex(&self.pub_bytes, $curve_id, None, None) + let key = ECC::import_x963_ex(&self.pub_bytes, $curve_id, None, None) .map_err(|_| Error::new())?; let msg_len: u32 = msg.len().try_into().map_err(|_| Error::new())?; let rc = unsafe { @@ -322,7 +322,7 @@ macro_rules! define_ecdsa_curve { sys::wc_SignatureType_WC_SIGNATURE_TYPE_ECC, msg.as_ptr(), msg_len, der.as_ptr(), der_len as u32, - &mut key.wc_ecc_key as *mut _ as *mut c_void, + key.wc_ecc_key as *mut c_void, size_of::() as u32, ) }; diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs b/wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs index a0b91f1e27..5a950e729c 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs @@ -72,7 +72,7 @@ impl Ed25519 { /// let mut rng = RNG::new().expect("Error creating RNG"); /// let ed = Ed25519::generate(&mut rng).expect("Error with generate()"); /// ``` - pub fn generate(rng: &mut RNG) -> Result { + pub fn generate(rng: &RNG) -> Result { Self::generate_ex(rng, None, None) } @@ -97,7 +97,7 @@ impl Ed25519 { /// let mut rng = RNG::new().expect("Error creating RNG"); /// let ed = Ed25519::generate_ex(&mut rng, None, None).expect("Error with generate_ex()"); /// ``` - pub fn generate_ex(rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + pub fn generate_ex(rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let mut ws_key: MaybeUninit = MaybeUninit::uninit(); let heap = match heap { Some(heap) => heap, @@ -114,7 +114,7 @@ impl Ed25519 { let ws_key = unsafe { ws_key.assume_init() }; let mut ed25519 = Ed25519 { ws_key }; let rc = unsafe { - sys::wc_ed25519_make_key(&mut rng.wc_rng, + sys::wc_ed25519_make_key(rng.wc_rng, sys::ED25519_KEY_SIZE as i32, &mut ed25519.ws_key) }; if rc != 0 { diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs b/wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs index 0a77aa071e..bb134ce796 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs @@ -71,7 +71,7 @@ impl Ed448 { /// let mut rng = RNG::new().expect("Error creating RNG"); /// let ed = Ed448::generate(&mut rng).expect("Error with generate()"); /// ``` - pub fn generate(rng: &mut RNG) -> Result { + pub fn generate(rng: &RNG) -> Result { Self::generate_ex(rng, None, None) } @@ -96,7 +96,7 @@ impl Ed448 { /// let mut rng = RNG::new().expect("Error creating RNG"); /// let ed = Ed448::generate_ex(&mut rng, None, None).expect("Error with generate_ex()"); /// ``` - pub fn generate_ex(rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + pub fn generate_ex(rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let mut ws_key: MaybeUninit = MaybeUninit::uninit(); let heap = match heap { Some(heap) => heap, @@ -113,7 +113,7 @@ impl Ed448 { let ws_key = unsafe { ws_key.assume_init() }; let mut ed448 = Ed448 { ws_key }; let rc = unsafe { - sys::wc_ed448_make_key(&mut rng.wc_rng, + sys::wc_ed448_make_key(rng.wc_rng, sys::ED448_KEY_SIZE as i32, &mut ed448.ws_key) }; if rc != 0 { diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/hmac.rs b/wrapper/rust/wolfssl-wolfcrypt/src/hmac.rs index b1d004006c..11a05adbbd 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/hmac.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/hmac.rs @@ -330,6 +330,24 @@ impl HMAC { } } +impl Clone for HMAC { + /// Deep-copy the HMAC state via `wc_HmacCopy()`. + /// + /// Panics if the underlying wolfSSL copy fails. + fn clone(&self) -> Self { + let mut wc_hmac: MaybeUninit = MaybeUninit::uninit(); + let rc = unsafe { + sys::wc_HmacCopy(&self.wc_hmac as *const _ as *mut _, + wc_hmac.as_mut_ptr()) + }; + if rc != 0 { + panic!("wc_HmacCopy() failed: {}", rc); + } + let wc_hmac = unsafe { wc_hmac.assume_init() }; + HMAC { wc_hmac } + } +} + impl Drop for HMAC { /// Safely free the underlying wolfSSL Hmac context. /// diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs b/wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs index 452debaa22..e5060d6f8d 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs @@ -42,6 +42,7 @@ macro_rules! impl_hmac_mac { $name:ident, hmac_type = $hmac_type:expr, key = $key_size:ty, out = $out_size:ty ) => { $(#[$attr])* + #[derive(Clone)] pub struct $name { hmac: crate::hmac::HMAC, } diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs b/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs index 1c6a23dcdd..36dc42bd94 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs @@ -20,6 +20,9 @@ #![no_std] +#[cfg(feature = "alloc")] +extern crate alloc; + /* bindgen-generated bindings to the C library */ pub mod sys; @@ -42,6 +45,10 @@ pub(crate) unsafe fn zeroize_raw(val: &mut T) { pub mod aes; pub mod blake2; +#[cfg(all(any(blake2b, blake2s), feature = "digest"))] +pub mod blake2_digest; +#[cfg(all(any(blake2b, blake2s), feature = "mac"))] +pub mod blake2_mac; pub mod chacha20_poly1305; pub mod cmac; #[cfg(all(cmac, feature = "mac"))] diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/lms.rs b/wrapper/rust/wolfssl-wolfcrypt/src/lms.rs index 90d4f1127f..4eca40433c 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/lms.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/lms.rs @@ -442,8 +442,8 @@ impl Lms { /// } /// ``` #[cfg(all(lms_make_key, random))] - pub fn make_key(&mut self, rng: &mut RNG) -> Result<(), i32> { - let rc = unsafe { sys::wc_LmsKey_MakeKey(&mut self.ws_key, &mut rng.wc_rng) }; + pub fn make_key(&mut self, rng: &RNG) -> Result<(), i32> { + let rc = unsafe { sys::wc_LmsKey_MakeKey(&mut self.ws_key, rng.wc_rng) }; if rc != 0 { return Err(rc); } diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs b/wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs index e63709dea5..b2711fc996 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs @@ -123,7 +123,7 @@ impl MlKem { /// } /// ``` #[cfg(random)] - pub fn generate(key_type: i32, rng: &mut RNG) -> Result { + pub fn generate(key_type: i32, rng: &RNG) -> Result { Self::generate_ex(key_type, rng, None, None) } @@ -157,12 +157,12 @@ impl MlKem { #[cfg(random)] pub fn generate_ex( key_type: i32, - rng: &mut RNG, + rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option, ) -> Result { let key = Self::new_ex(key_type, heap, dev_id)?; - let rc = unsafe { sys::wc_MlKemKey_MakeKey(key.ws_key, &mut rng.wc_rng) }; + let rc = unsafe { sys::wc_MlKemKey_MakeKey(key.ws_key, rng.wc_rng) }; if rc != 0 { return Err(rc); } @@ -472,7 +472,7 @@ impl MlKem { &mut self, ct: &mut [u8], ss: &mut [u8], - rng: &mut RNG, + rng: &RNG, ) -> Result<(), i32> { // Verify the cipher text length is as expected based on the parameter // set (key type) in use. @@ -489,7 +489,7 @@ impl MlKem { self.ws_key, ct.as_mut_ptr(), ss.as_mut_ptr(), - &mut rng.wc_rng, + rng.wc_rng, ) }; if rc != 0 { diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/random.rs b/wrapper/rust/wolfssl-wolfcrypt/src/random.rs index a5904daa40..5e3a1833ac 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/random.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/random.rs @@ -31,7 +31,7 @@ wolfSSL `WC_RNG` object. It ensures proper initialization and deallocation. use wolfssl_wolfcrypt::random::RNG; // Create a RNG instance. -let mut rng = RNG::new().expect("Failed to create RNG"); +let rng = RNG::new().expect("Failed to create RNG"); // Generate a single random byte value. let byte = rng.generate_byte().expect("Failed to generate a single byte"); @@ -45,18 +45,42 @@ rng.generate_block(&mut buffer).expect("Failed to generate a block"); #![cfg(random)] use crate::sys; -use core::mem::{size_of_val, MaybeUninit}; +use core::mem::size_of_val; use num_traits::PrimInt; /// A cryptographically secure random number generator based on the wolfSSL /// library. /// -/// This struct wraps the wolfssl `WC_RNG` type, providing a high-level API -/// for generating random bytes and blocks of data. The `Drop` implementation -/// ensures that the underlying wolfSSL RNG context is correctly freed when the -/// `RNG` struct goes out of scope, preventing memory leaks. +/// This struct wraps a pointer to a wolfssl `WC_RNG` allocated on the C heap, +/// providing a high-level API for generating random bytes and blocks of data. +/// The `Drop` implementation ensures that the underlying wolfSSL RNG context is +/// correctly freed when the `RNG` struct goes out of scope, preventing memory +/// leaks. +/// +/// All generation methods take `&self`. The actual mutation of the DRBG state +/// happens through the raw pointer in the C library; the `RNG` struct itself +/// is logically immutable after construction. pub struct RNG { - pub(crate) wc_rng: sys::WC_RNG, + pub(crate) wc_rng: *mut sys::WC_RNG, +} + +// Safety: the only field of `RNG` is a non-null pointer to a `WC_RNG` that +// lives on the C heap and is never reassigned after construction. Moving the +// struct between threads is sound. +unsafe impl Send for RNG {} + +// Note: `RNG` is intentionally not `Sync`. The underlying C `WC_RNG` state is +// mutated by every call to a generation routine, with no internal locking. +// Callers that need cross-thread sharing of a single RNG struct must implement +// their own locking. + +/// Storage for an RNG that a consumer (e.g. `RSA`, `ECC`) has been bound to +/// via `set_rng`. The consumer keeps the `RngHandle` alive for as long as the +/// C struct holds its pointer, ensuring the `WC_RNG` outlives the consumer. +pub(crate) enum RngHandle { + Owned(RNG), + #[cfg(feature = "alloc")] + Shared(alloc::rc::Rc), } impl RNG { @@ -97,7 +121,7 @@ impl RNG { return Err(rc); } } - let mut wc_rng: MaybeUninit = MaybeUninit::uninit(); + let mut wc_rng: *mut sys::WC_RNG = core::ptr::null_mut(); let heap = match heap { Some(heap) => heap, None => core::ptr::null_mut(), @@ -107,12 +131,10 @@ impl RNG { None => sys::INVALID_DEVID, }; let rc = unsafe { - sys::wc_InitRng_ex(wc_rng.as_mut_ptr(), heap, dev_id) + sys::wc_rng_new_ex(&mut wc_rng, core::ptr::null_mut(), 0, heap, dev_id) }; if rc == 0 { - let wc_rng = unsafe { wc_rng.assume_init() }; - let rng = RNG {wc_rng}; - Ok(rng) + Ok(RNG {wc_rng}) } else { Err(rc) } @@ -159,7 +181,7 @@ impl RNG { } let ptr = nonce.as_mut_ptr() as *mut u8; let size = crate::buffer_len_to_u32(size_of_val(nonce))?; - let mut wc_rng: MaybeUninit = MaybeUninit::uninit(); + let mut wc_rng: *mut sys::WC_RNG = core::ptr::null_mut(); let heap = match heap { Some(heap) => heap, None => core::ptr::null_mut(), @@ -169,12 +191,10 @@ impl RNG { None => sys::INVALID_DEVID, }; let rc = unsafe { - sys::wc_InitRngNonce_ex(wc_rng.as_mut_ptr(), ptr, size, heap, dev_id) + sys::wc_rng_new_ex(&mut wc_rng, ptr, size, heap, dev_id) }; if rc == 0 { - let wc_rng = unsafe { wc_rng.assume_init() }; - let rng = RNG {wc_rng}; - Ok(rng) + Ok(RNG {wc_rng}) } else { Err(rc) } @@ -315,9 +335,9 @@ impl RNG { /// /// A `Result` which is `Ok(u8)` containing the random byte on success or /// an `Err` with the wolfssl library return code on failure. - pub fn generate_byte(&mut self) -> Result { + pub fn generate_byte(&self) -> Result { let mut b: u8 = 0; - let rc = unsafe { sys::wc_RNG_GenerateByte(&mut self.wc_rng, &mut b) }; + let rc = unsafe { sys::wc_RNG_GenerateByte(self.wc_rng, &mut b) }; if rc == 0 { Ok(b) } else { @@ -339,10 +359,10 @@ impl RNG { /// /// A `Result` which is `Ok(())` on success or an `Err` with the wolfssl /// library return code on failure. - pub fn generate_block(&mut self, buf: &mut [T]) -> Result<(), i32> { + pub fn generate_block(&self, buf: &mut [T]) -> Result<(), i32> { let ptr = buf.as_mut_ptr() as *mut u8; let size = crate::buffer_len_to_u32(size_of_val(buf))?; - let rc = unsafe { sys::wc_RNG_GenerateBlock(&mut self.wc_rng, ptr, size) }; + let rc = unsafe { sys::wc_RNG_GenerateBlock(self.wc_rng, ptr, size) }; if rc == 0 { Ok(()) } else { @@ -371,10 +391,10 @@ impl RNG { /// rng.reseed(&seed).expect("Error with reseed()"); /// ``` #[cfg(random_hashdrbg)] - pub fn reseed(&mut self, seed: &[u8]) -> Result<(), i32> { + pub fn reseed(&self, seed: &[u8]) -> Result<(), i32> { let seed_size = crate::buffer_len_to_u32(seed.len())?; let rc = unsafe { - sys::wc_RNG_DRBG_Reseed(&mut self.wc_rng, seed.as_ptr(), seed_size) + sys::wc_RNG_DRBG_Reseed(self.wc_rng, seed.as_ptr(), seed_size) }; if rc != 0 { return Err(rc); @@ -411,22 +431,16 @@ impl rand_core::TryRng for RNG { #[cfg(feature = "rand_core")] impl rand_core::TryCryptoRng for RNG {} -impl RNG { - fn zeroize(&mut self) { - unsafe { crate::zeroize_raw(&mut self.wc_rng); } - } -} - impl Drop for RNG { /// Safely free the underlying wolfSSL RNG context. /// - /// This calls the `wc_FreeRng` wolfssl library function. + /// This calls the `wc_rng_free` wolfssl library function, which frees the + /// C-heap-allocated `WC_RNG` object. /// /// The Rust Drop trait guarantees that this method is called when the RNG /// struct goes out of scope, automatically cleaning up resources and /// preventing memory leaks. fn drop(&mut self) { - unsafe { sys::wc_FreeRng(&mut self.wc_rng); } - self.zeroize(); + unsafe { sys::wc_rng_free(self.wc_rng); } } } diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/rsa.rs b/wrapper/rust/wolfssl-wolfcrypt/src/rsa.rs index 3e89b79142..da9dc765d1 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/rsa.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/rsa.rs @@ -29,26 +29,26 @@ wolfSSL `RsaKey` object. It ensures proper initialization and deallocation. ```rust # extern crate std; -#[cfg(random)] +#[cfg(all(random, feature = "alloc"))] { use std::fs; use wolfssl_wolfcrypt::random::RNG; use wolfssl_wolfcrypt::rsa::RSA; -let mut rng = RNG::new().expect("Error creating RNG"); +let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); let key_path = "../../../certs/client-keyPub.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); -rsa.set_rng(&mut rng).expect("Error with set_rng()"); +rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); let plain: &[u8] = b"Test message"; let mut enc: [u8; 512] = [0; 512]; -let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); +let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); assert!(enc_len > 0 && enc_len <= 512); let key_path = "../../../certs/client-key.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); -rsa.set_rng(&mut rng).expect("Error with set_rng()"); +rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); let mut plain_out: [u8; 512] = [0; 512]; let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); assert!(dec_len as usize == plain.len()); @@ -61,7 +61,7 @@ assert_eq!(plain_out[0..dec_len], *plain); use crate::sys; #[cfg(random)] -use crate::random::RNG; +use crate::random::{RNG, RngHandle}; use core::mem::{MaybeUninit}; /// The `RSA` struct manages the lifecycle of a wolfSSL `RsaKey` object. @@ -72,6 +72,10 @@ use core::mem::{MaybeUninit}; /// or `generate()`. pub struct RSA { pub(crate) wc_rsakey: sys::RsaKey, + /// RNG bound to this key via `set_rng`. Kept alive here so the C struct's + /// internal `WC_RNG` pointer remains valid for as long as the key exists. + #[cfg(random)] + rng: Option, } impl RSA { @@ -143,26 +147,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -191,26 +195,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der_ex(&der, None, None).expect("Error with new_from_der_ex()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -241,7 +245,11 @@ impl RSA { unsafe { sys::wc_FreeRsaKey(&mut wc_rsakey); } return Err(rc); } - let rsa = RSA { wc_rsakey }; + let rsa = RSA { + wc_rsakey, + #[cfg(random)] + rng: None, + }; Ok(rsa) } @@ -260,26 +268,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -308,26 +316,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der_ex(&der, None, None).expect("Error with new_public_from_der_ex()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -358,7 +366,11 @@ impl RSA { unsafe { sys::wc_FreeRsaKey(&mut wc_rsakey); } return Err(rc); } - let rsa = RSA { wc_rsakey }; + let rsa = RSA { + wc_rsakey, + #[cfg(random)] + rng: None, + }; Ok(rsa) } @@ -411,7 +423,11 @@ impl RSA { unsafe { sys::wc_FreeRsaKey(&mut wc_rsakey); } return Err(rc); } - Ok(RSA { wc_rsakey }) + Ok(RSA { + wc_rsakey, + #[cfg(random)] + rng: None, + }) } /// Generate a new RSA key using the given size and exponent. @@ -446,15 +462,15 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); /// rsa.check().expect("Error with check()"); /// let encrypt_size = rsa.get_encrypt_size().expect("Error with get_encrypt_size()"); /// assert_eq!(encrypt_size, 256); /// } /// ``` #[cfg(all(random, rsa_keygen))] - pub fn generate(size: i32, e: i32, rng: &mut RNG) -> Result { + pub fn generate(size: i32, e: i32, rng: &RNG) -> Result { Self::generate_ex(size, e, rng, None, None) } @@ -493,15 +509,15 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate_ex(2048, 65537, &mut rng, None, None).expect("Error with generate_ex()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate_ex(2048, 65537, &rng, None, None).expect("Error with generate_ex()"); /// rsa.check().expect("Error with check()"); /// let encrypt_size = rsa.get_encrypt_size().expect("Error with get_encrypt_size()"); /// assert_eq!(encrypt_size, 256); /// } /// ``` #[cfg(all(random, rsa_keygen))] - pub fn generate_ex(size: i32, e: i32, rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { + pub fn generate_ex(size: i32, e: i32, rng: &RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option) -> Result { let mut wc_rsakey: MaybeUninit = MaybeUninit::uninit(); let heap = match heap { Some(heap) => heap, @@ -518,13 +534,17 @@ impl RSA { let mut wc_rsakey = unsafe { wc_rsakey.assume_init() }; let e = e as core::ffi::c_long; let rc = unsafe { - sys::wc_MakeRsaKey(&mut wc_rsakey, size, e, &mut rng.wc_rng) + sys::wc_MakeRsaKey(&mut wc_rsakey, size, e, rng.wc_rng) }; if rc != 0 { unsafe { sys::wc_FreeRsaKey(&mut wc_rsakey); } return Err(rc); } - let rsa = RSA { wc_rsakey }; + let rsa = RSA { + wc_rsakey, + #[cfg(random)] + rng: None, + }; Ok(rsa) } @@ -556,8 +576,8 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); /// let mut e: [u8; 256] = [0; 256]; /// let mut e_size: u32 = 0; /// let mut n: [u8; 256] = [0; 256]; @@ -624,8 +644,8 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); /// let mut e: [u8; 256] = [0; 256]; /// let mut e_size: u32 = 0; /// let mut n: [u8; 256] = [0; 256]; @@ -667,8 +687,8 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); /// let encrypt_size = rsa.get_encrypt_size().expect("Error with get_encrypt_size()"); /// assert_eq!(encrypt_size, 256); /// } @@ -696,8 +716,8 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + /// let rng = RNG::new().expect("Error creating RNG"); + /// let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); /// rsa.check().expect("Error with check()"); /// } /// ``` @@ -729,26 +749,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -756,13 +776,13 @@ impl RSA { /// } /// ``` #[cfg(random)] - pub fn public_encrypt(&mut self, din: &[u8], dout: &mut [u8], rng: &mut RNG) -> Result { + pub fn public_encrypt(&mut self, din: &[u8], dout: &mut [u8], rng: &RNG) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; let dout_size = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { sys::wc_RsaPublicEncrypt(din.as_ptr(), din_size, dout.as_mut_ptr(), dout_size, &mut self.wc_rsakey, - &mut rng.wc_rng) + rng.wc_rng) }; if rc < 0 { return Err(rc); @@ -788,26 +808,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -849,26 +869,26 @@ impl RSA { /// # Example /// /// ```rust - /// #[cfg(all(random, rsa_pss))] + /// #[cfg(all(random, rsa_pss, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &mut rng).expect("Error with pss_sign()"); + /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &rng).expect("Error with pss_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.pss_verify(signature, &mut verify_out, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256).expect("Error with pss_verify()"); @@ -880,12 +900,12 @@ impl RSA { /// } /// ``` #[cfg(all(random, rsa_pss))] - pub fn pss_sign(&mut self, din: &[u8], dout: &mut [u8], hash_algo: u32, mgf: i32, rng: &mut RNG) -> Result { + pub fn pss_sign(&mut self, din: &[u8], dout: &mut [u8], hash_algo: u32, mgf: i32, rng: &RNG) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; let dout_size = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { sys::wc_RsaPSS_Sign(din.as_ptr(), din_size, dout.as_mut_ptr(), dout_size, - hash_algo, mgf, &mut self.wc_rsakey, &mut rng.wc_rng) + hash_algo, mgf, &mut self.wc_rsakey, rng.wc_rng) }; if rc < 0 { return Err(rc); @@ -912,26 +932,26 @@ impl RSA { /// # Example /// /// ```rust - /// #[cfg(all(random, rsa_pss, rsa_const_api))] + /// #[cfg(all(random, rsa_pss, rsa_const_api, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &mut rng).expect("Error with pss_sign()"); + /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &rng).expect("Error with pss_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.pss_verify(signature, &mut verify_out, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256).expect("Error with pss_verify()"); @@ -978,26 +998,26 @@ impl RSA { /// # Example /// /// ```rust - /// #[cfg(all(random, rsa_pss, rsa_const_api))] + /// #[cfg(all(random, rsa_pss, rsa_const_api, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &mut rng).expect("Error with pss_sign()"); + /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &rng).expect("Error with pss_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.pss_verify(signature, &mut verify_out, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256).expect("Error with pss_verify()"); @@ -1049,26 +1069,26 @@ impl RSA { /// # Example /// /// ```rust - /// #[cfg(all(random, rsa_pss, rsa_const_api))] + /// #[cfg(all(random, rsa_pss, rsa_const_api, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &mut rng).expect("Error with pss_sign()"); + /// let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &rng).expect("Error with pss_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.pss_verify(signature, &mut verify_out, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256).expect("Error with pss_verify()"); @@ -1125,7 +1145,7 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = RNG::new().expect("Error creating RNG"); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); @@ -1134,22 +1154,22 @@ impl RSA { /// let mut plain = [0u8; 256]; /// plain[..msg.len()].copy_from_slice(msg); /// let mut enc = [0u8; 256]; - /// let enc_len = rsa.rsa_direct(&plain, &mut enc, RSA::PRIVATE_ENCRYPT, &mut rng).expect("Error with rsa_direct()"); + /// let enc_len = rsa.rsa_direct(&plain, &mut enc, RSA::PRIVATE_ENCRYPT, &rng).expect("Error with rsa_direct()"); /// assert_eq!(enc_len, 256); /// let mut plain_out = [0u8; 256]; - /// let dec_len = rsa.rsa_direct(&enc, &mut plain_out, RSA::PUBLIC_DECRYPT, &mut rng).expect("Error with rsa_direct()"); + /// let dec_len = rsa.rsa_direct(&enc, &mut plain_out, RSA::PUBLIC_DECRYPT, &rng).expect("Error with rsa_direct()"); /// assert_eq!(dec_len, 256); /// assert_eq!(plain_out, plain); /// } /// ``` #[cfg(all(rsa_direct, rsa_const_api))] - pub fn rsa_direct(&mut self, din: &[u8], dout: &mut [u8], typ: i32, rng: &mut RNG) -> Result { + pub fn rsa_direct(&mut self, din: &[u8], dout: &mut [u8], typ: i32, rng: &RNG) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; let mut dout_size = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { sys::wc_RsaDirect(din.as_ptr(), din_size, dout.as_mut_ptr(), &mut dout_size, - &mut self.wc_rsakey, typ, &mut rng.wc_rng) + &mut self.wc_rsakey, typ, rng.wc_rng) }; if rc < 0 { return Err(rc); @@ -1165,8 +1185,7 @@ impl RSA { /// # Parameters /// /// * `rng`: The `RNG` struct instance to associate with this `RSA` - /// instance. The `RNG` struct should not be moved in memory after - /// calling this method. + /// instance. /// /// # Returns /// @@ -1183,19 +1202,19 @@ impl RSA { /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_rng(RNG::new().expect("Error creating RNG")).expect("Error with set_rng()"); /// let plain: &[u8] = b"Test message"; /// let mut enc: [u8; 512] = [0; 512]; - /// let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + /// let enc_rng = RNG::new().expect("Error creating RNG"); + /// let enc_len = rsa.public_encrypt(plain, &mut enc, &enc_rng).expect("Error with public_encrypt()"); /// assert!(enc_len > 0 && enc_len <= 512); /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_rng(RNG::new().expect("Error creating RNG")).expect("Error with set_rng()"); /// let mut plain_out: [u8; 512] = [0; 512]; /// let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); /// assert!(dec_len as usize == plain.len()); @@ -1203,16 +1222,47 @@ impl RSA { /// } /// ``` #[cfg(random)] - pub fn set_rng(&mut self, rng: &mut RNG) -> Result<(), i32> { + pub fn set_rng(&mut self, rng: RNG) -> Result<(), i32> { + let wc_rng = rng.wc_rng; let rc = unsafe { - sys::wc_RsaSetRNG(&mut self.wc_rsakey, &mut rng.wc_rng) + sys::wc_RsaSetRNG(&mut self.wc_rsakey, wc_rng) }; if rc != 0 { return Err(rc); } + self.rng = Some(RngHandle::Owned(rng)); Ok(()) } + /// Bind a shared `RNG` to this key for blinding during private operations. + /// + /// Like `set_rng`, but takes an `Rc` so the same RNG can be shared + /// among multiple consumers and used directly by the caller. Available + /// when the `alloc` feature is enabled. + #[cfg(all(random, feature = "alloc"))] + pub fn set_shared_rng(&mut self, rng: alloc::rc::Rc) -> Result<(), i32> { + let wc_rng = rng.wc_rng; + let rc = unsafe { + sys::wc_RsaSetRNG(&mut self.wc_rsakey, wc_rng) + }; + if rc != 0 { + return Err(rc); + } + self.rng = Some(RngHandle::Shared(rng)); + Ok(()) + } + + /// Borrow the RNG previously bound via `set_rng` or `set_shared_rng`. + #[cfg(random)] + pub fn rng(&self) -> Option<&RNG> { + match &self.rng { + Some(RngHandle::Owned(rng)) => Some(rng), + #[cfg(feature = "alloc")] + Some(RngHandle::Shared(rng)) => Some(rng), + None => None, + } + } + /// Sign the provided data with the private key. /// /// # Parameters @@ -1233,26 +1283,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.ssl_sign(msg, &mut signature, &mut rng).expect("Error with ssl_sign()"); + /// let sig_len = rsa.ssl_sign(msg, &mut signature, &rng).expect("Error with ssl_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.ssl_verify(signature, &mut verify_out).expect("Error with ssl_verify()"); @@ -1260,13 +1310,13 @@ impl RSA { /// } /// ``` #[cfg(random)] - pub fn ssl_sign(&mut self, din: &[u8], dout: &mut [u8], rng: &mut RNG) -> Result { + pub fn ssl_sign(&mut self, din: &[u8], dout: &mut [u8], rng: &RNG) -> Result { let din_size = crate::buffer_len_to_u32(din.len())?; let dout_size = crate::buffer_len_to_u32(dout.len())?; let rc = unsafe { sys::wc_RsaSSL_Sign(din.as_ptr(), din_size, dout.as_mut_ptr(), dout_size, - &mut self.wc_rsakey, &mut rng.wc_rng) + &mut self.wc_rsakey, rng.wc_rng) }; if rc < 0 { return Err(rc); @@ -1295,26 +1345,26 @@ impl RSA { /// /// ```rust /// # extern crate std; - /// #[cfg(random)] + /// #[cfg(all(random, feature = "alloc"))] /// { /// use std::fs; /// use wolfssl_wolfcrypt::random::RNG; /// use wolfssl_wolfcrypt::rsa::RSA; /// - /// let mut rng = RNG::new().expect("Error creating RNG"); + /// let rng = std::rc::Rc::new(RNG::new().expect("Error creating RNG")); /// /// let key_path = "../../../certs/client-key.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); /// let msg: &[u8] = b"This is the string to be signed!"; /// let mut signature: [u8; 512] = [0; 512]; - /// let sig_len = rsa.ssl_sign(msg, &mut signature, &mut rng).expect("Error with ssl_sign()"); + /// let sig_len = rsa.ssl_sign(msg, &mut signature, &rng).expect("Error with ssl_sign()"); /// assert!(sig_len > 0 && sig_len <= 512); /// /// let key_path = "../../../certs/client-keyPub.der"; /// let der: Vec = fs::read(key_path).expect("Error reading key file"); /// let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - /// rsa.set_rng(&mut rng).expect("Error with set_rng()"); + /// rsa.set_shared_rng(std::rc::Rc::clone(&rng)).expect("Error with set_shared_rng()"); /// let signature = &signature[0..sig_len]; /// let mut verify_out: [u8; 512] = [0; 512]; /// let verify_out_size = rsa.ssl_verify(signature, &mut verify_out).expect("Error with ssl_verify()"); diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs b/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs index 40314f9548..576f63e222 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs @@ -149,9 +149,9 @@ pub struct SigningKey { impl SigningKey { /// Generate a fresh `N * 8`-bit RSA key with public exponent 65537. #[cfg(rsa_keygen)] - pub fn generate(mut rng: RNG) -> Result { + pub fn generate(rng: RNG) -> Result { let bits: i32 = (N * 8).try_into().map_err(|_| sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG)?; - let rsa = RSA::generate(bits, 65537, &mut rng)?; + let rsa = RSA::generate(bits, 65537, &rng)?; Ok(Self { inner: rsa, rng, _hash: PhantomData }) } @@ -186,7 +186,7 @@ impl SignerMut> for SigningKey { sig.as_mut_ptr(), &mut sig_len, &mut self.inner.wc_rsakey as *mut _ as *mut c_void, size_of::() as u32, - &mut self.rng.wc_rng, + self.rng.wc_rng, ) }; if rc != 0 || sig_len as usize != N { diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs index e215891691..d5a171fd9e 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs @@ -1030,6 +1030,29 @@ fn test_aes256gcm_nist_tc14_encrypt() { assert_eq!(&tag[..], &expected_tag); } +/// Roundtrip test for AES-192-GCM using `aead::Aead`. +#[test] +#[cfg(all(feature = "aead", aes_gcm))] +fn test_aes192gcm_aead_roundtrip() { + let key = [0x77u8; 24]; + let nonce_bytes = [0x88u8; 12]; + let aad = b"aes-192-gcm test"; + let plaintext = b"AES-192-GCM roundtrip test"; + + let cipher = Aes192Gcm::new_from_slice(&key).unwrap(); + let nonce: aead::Nonce = nonce_bytes.into(); + + let ciphertext = cipher + .encrypt(&nonce, Payload { msg: plaintext, aad }) + .expect("AES-192-GCM encrypt failed"); + + let recovered = cipher + .decrypt(&nonce, Payload { msg: &ciphertext, aad }) + .expect("AES-192-GCM decrypt failed"); + + assert_eq!(recovered, plaintext); +} + /// Roundtrip test for AES-256-GCM using `aead::Aead`. #[test] #[cfg(all(feature = "aead", aes_gcm))] @@ -1092,6 +1115,29 @@ fn test_aes128ccm_reject_tampered() { assert!(cipher.decrypt(&nonce, ct.as_slice()).is_err()); } +/// Roundtrip test for AES-192-CCM using `aead::Aead`. +#[test] +#[cfg(all(feature = "aead", aes_ccm))] +fn test_aes192ccm_aead_roundtrip() { + let key = [0x33u8; 24]; + let nonce_bytes = [0x44u8; 12]; + let aad = b"aes-192-ccm test"; + let plaintext = b"AES-192-CCM plaintext data"; + + let cipher = Aes192Ccm::new_from_slice(&key).unwrap(); + let nonce: aead::Nonce = nonce_bytes.into(); + + let ciphertext = cipher + .encrypt(&nonce, Payload { msg: plaintext, aad }) + .expect("AES-192-CCM encrypt failed"); + + let recovered = cipher + .decrypt(&nonce, Payload { msg: &ciphertext, aad }) + .expect("AES-192-CCM decrypt failed"); + + assert_eq!(recovered, plaintext); +} + /// Roundtrip test for AES-256-CCM using `aead::Aead`. #[test] #[cfg(all(feature = "aead", aes_ccm))] diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_digest.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_digest.rs new file mode 100644 index 0000000000..49d28c6fac --- /dev/null +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_digest.rs @@ -0,0 +1,126 @@ +#![cfg(all(any(blake2b, blake2s), feature = "digest"))] + +use digest::{Digest, FixedOutputReset}; +use digest::block_api::BlockSizeUser; + +mod common; + +fn check_digest( + input: &[u8], + expected: &[u8], + expected_block_size: usize, +) { + assert_eq!(::output_size(), expected.len()); + assert_eq!(::block_size(), expected_block_size); + + /* One-shot digest via associated function. */ + let out = D::digest(input); + assert_eq!(out.as_slice(), expected); + + /* Streaming via Digest::update and finalize. */ + let mut hasher = D::new(); + Digest::update(&mut hasher, input); + let out = hasher.finalize(); + assert_eq!(out.as_slice(), expected); + + /* Split update via Default + Update + FixedOutputReset::finalize_reset. */ + let mut hasher = D::default(); + if input.len() >= 2 { + let mid = input.len() / 2; + Digest::update(&mut hasher, &input[..mid]); + Digest::update(&mut hasher, &input[mid..]); + } else { + Digest::update(&mut hasher, input); + } + let out = hasher.finalize_reset(); + assert_eq!(out.as_slice(), expected); + + /* After reset, the same hasher should produce the same result. */ + Digest::update(&mut hasher, input); + let out = hasher.finalize(); + assert_eq!(out.as_slice(), expected); +} + +#[test] +#[cfg(blake2b)] +fn test_digest_blake2b_512() { + use wolfssl_wolfcrypt::blake2_digest::Blake2b512; + common::setup(); + check_digest::( + b"abc", + b"\xBA\x80\xA5\x3F\x98\x1C\x4D\x0D\x6A\x27\x97\xB6\x9F\x12\xF6\xE9\x4C\x21\x2F\x14\x68\x5A\xC4\xB7\x4B\x12\xBB\x6F\xDB\xFF\xA2\xD1\x7D\x87\xC5\x39\x2A\xAB\x79\x2D\xC2\x52\xD5\xDE\x45\x33\xCC\x95\x18\xD3\x8A\xA8\xDB\xF1\x92\x5A\xB9\x23\x86\xED\xD4\x00\x99\x23", + 128, + ); +} + +#[test] +#[cfg(blake2b)] +fn test_digest_blake2b_384() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_digest::Blake2b384; + common::setup(); + + let mut reference = BLAKE2b::new(48).expect("Error with new()"); + reference.update(b"abc").expect("Error with update()"); + let mut expected = [0u8; 48]; + reference.finalize(&mut expected).expect("Error with finalize()"); + + check_digest::(b"abc", &expected, 128); +} + +#[test] +#[cfg(blake2b)] +fn test_digest_blake2b_256() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_digest::Blake2b256; + common::setup(); + + let mut reference = BLAKE2b::new(32).expect("Error with new()"); + reference.update(b"abc").expect("Error with update()"); + let mut expected = [0u8; 32]; + reference.finalize(&mut expected).expect("Error with finalize()"); + + check_digest::(b"abc", &expected, 128); +} + +#[test] +#[cfg(blake2s)] +fn test_digest_blake2s_256() { + use wolfssl_wolfcrypt::blake2_digest::Blake2s256; + common::setup(); + check_digest::( + b"abc", + b"\x50\x8C\x5E\x8C\x32\x7C\x14\xE2\xE1\xA7\x2B\xA3\x4E\xEB\x45\x2F\x37\x45\x8B\x20\x9E\xD6\x3A\x29\x4D\x99\x9B\x4C\x86\x67\x59\x82", + 64, + ); +} + +#[test] +#[cfg(blake2s)] +fn test_digest_blake2s_192() { + use wolfssl_wolfcrypt::blake2::BLAKE2s; + use wolfssl_wolfcrypt::blake2_digest::Blake2s192; + common::setup(); + + let mut reference = BLAKE2s::new(24).expect("Error with new()"); + reference.update(b"abc").expect("Error with update()"); + let mut expected = [0u8; 24]; + reference.finalize(&mut expected).expect("Error with finalize()"); + + check_digest::(b"abc", &expected, 64); +} + +#[test] +#[cfg(blake2s)] +fn test_digest_blake2s_128() { + use wolfssl_wolfcrypt::blake2::BLAKE2s; + use wolfssl_wolfcrypt::blake2_digest::Blake2s128; + common::setup(); + + let mut reference = BLAKE2s::new(16).expect("Error with new()"); + reference.update(b"abc").expect("Error with update()"); + let mut expected = [0u8; 16]; + reference.finalize(&mut expected).expect("Error with finalize()"); + + check_digest::(b"abc", &expected, 64); +} diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_mac.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_mac.rs new file mode 100644 index 0000000000..a25761a2bd --- /dev/null +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_mac.rs @@ -0,0 +1,181 @@ +#![cfg(all(any(blake2b, blake2s), feature = "mac"))] + +use digest::{KeyInit, Mac}; + +#[test] +#[cfg(blake2b)] +fn test_blake2b_mac_512() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_mac::Blake2bMac512; + + let key = [0x42u8; 64]; + let input = b"The quick brown fox jumps over the lazy dog"; + + let mut reference = BLAKE2b::new_with_key(64, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 64]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2bMac512::new_from_slice(&key) + .expect("Blake2bMac512 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2b)] +fn test_blake2b_mac_256() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_mac::Blake2bMac256; + + let key = [0x33u8; 64]; + let input = b"libsodium crypto_generichash analog"; + + let mut reference = BLAKE2b::new_with_key(32, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 32]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2bMac256::new_from_slice(&key) + .expect("Blake2bMac256 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2b)] +fn test_blake2b_mac_384() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_mac::Blake2bMac384; + + let key = [0x77u8; 64]; + let input = b"sha-384 sized blake2b mac"; + + let mut reference = BLAKE2b::new_with_key(48, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 48]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2bMac384::new_from_slice(&key) + .expect("Blake2bMac384 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2b)] +fn test_blake2b_mac_512_chunked() { + use wolfssl_wolfcrypt::blake2::BLAKE2b; + use wolfssl_wolfcrypt::blake2_mac::Blake2bMac512; + + let key = [0xA5u8; 64]; + let input: Vec = (0u8..200).collect(); + + let mut reference = BLAKE2b::new_with_key(64, &key) + .expect("Error with new_with_key()"); + reference.update(&input).expect("Error with update()"); + let mut expected = [0u8; 64]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2bMac512::new_from_slice(&key) + .expect("Blake2bMac512 init failed"); + for chunk in input.chunks(17) { + mac.update(chunk); + } + mac.verify_slice(&expected) + .expect("Blake2bMac512 verify failed"); +} + +#[test] +#[cfg(blake2s)] +fn test_blake2s_mac_128() { + use wolfssl_wolfcrypt::blake2::BLAKE2s; + use wolfssl_wolfcrypt::blake2_mac::Blake2sMac128; + + let key = [0x55u8; 32]; + let input = b"short blake2s mac"; + + let mut reference = BLAKE2s::new_with_key(16, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 16]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2sMac128::new_from_slice(&key) + .expect("Blake2sMac128 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2s)] +fn test_blake2s_mac_192() { + use wolfssl_wolfcrypt::blake2::BLAKE2s; + use wolfssl_wolfcrypt::blake2_mac::Blake2sMac192; + + let key = [0x99u8; 32]; + let input = b"medium blake2s mac"; + + let mut reference = BLAKE2s::new_with_key(24, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 24]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2sMac192::new_from_slice(&key) + .expect("Blake2sMac192 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2s)] +fn test_blake2s_mac_256() { + use wolfssl_wolfcrypt::blake2::BLAKE2s; + use wolfssl_wolfcrypt::blake2_mac::Blake2sMac256; + + let key = [0x42u8; 32]; + let input = b"The quick brown fox jumps over the lazy dog"; + + let mut reference = BLAKE2s::new_with_key(32, &key) + .expect("Error with new_with_key()"); + reference.update(input).expect("Error with update()"); + let mut expected = [0u8; 32]; + reference.finalize(&mut expected) + .expect("Error with finalize()"); + + let mut mac = Blake2sMac256::new_from_slice(&key) + .expect("Blake2sMac256 init failed"); + mac.update(input); + let tag = mac.finalize(); + assert_eq!(tag.into_bytes().as_slice(), &expected); +} + +#[test] +#[cfg(blake2s)] +fn test_blake2s_mac_256_verify_fail() { + use wolfssl_wolfcrypt::blake2_mac::Blake2sMac256; + + let key = [0x0Bu8; 32]; + let input = b"hello"; + let wrong_tag = [0u8; 32]; + + let mut mac = Blake2sMac256::new_from_slice(&key) + .expect("Blake2sMac256 init failed"); + mac.update(input); + assert!(mac.verify_slice(&wrong_tag).is_err()); +} diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs index ce1e3cc39d..ae4881dd1a 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs @@ -1,5 +1,7 @@ #![cfg(all(curve25519, random))] +#[cfg(curve25519_blinding)] +use std::rc::Rc; use wolfssl_wolfcrypt::curve25519::*; use wolfssl_wolfcrypt::random::RNG; @@ -97,14 +99,17 @@ fn test_make_pub_blind() { #[test] fn test_shared_secret() { - let mut rng = RNG::new().expect("Error with new()"); - let mut key1 = Curve25519Key::generate(&mut rng).expect("Error with generate()"); - let mut key2 = Curve25519Key::generate(&mut rng).expect("Error with generate()"); + #[cfg(curve25519_blinding)] + let rng = Rc::new(RNG::new().expect("Error with new()")); + #[cfg(not(curve25519_blinding))] + let rng = RNG::new().expect("Error with new()"); + let mut key1 = Curve25519Key::generate(&rng).expect("Error with generate()"); + let mut key2 = Curve25519Key::generate(&rng).expect("Error with generate()"); #[cfg(curve25519_blinding)] - key1.set_rng(&mut rng).expect("Error with set_rng()"); + key1.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); #[cfg(curve25519_blinding)] - key2.set_rng(&mut rng).expect("Error with set_rng()"); + key2.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let mut public_buffer = [0u8; Curve25519Key::KEYSIZE]; key1.export_public(&mut public_buffer).expect("Error with export_public()"); @@ -122,14 +127,17 @@ fn test_shared_secret() { #[test] fn test_shared_secret_ex() { - let mut rng = RNG::new().expect("Error with new()"); - let mut key1 = Curve25519Key::generate(&mut rng).expect("Error with generate()"); - let mut key2 = Curve25519Key::generate(&mut rng).expect("Error with generate()"); + #[cfg(curve25519_blinding)] + let rng = Rc::new(RNG::new().expect("Error with new()")); + #[cfg(not(curve25519_blinding))] + let rng = RNG::new().expect("Error with new()"); + let mut key1 = Curve25519Key::generate(&rng).expect("Error with generate()"); + let mut key2 = Curve25519Key::generate(&rng).expect("Error with generate()"); #[cfg(curve25519_blinding)] - key1.set_rng(&mut rng).expect("Error with set_rng()"); + key1.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); #[cfg(curve25519_blinding)] - key2.set_rng(&mut rng).expect("Error with set_rng()"); + key2.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let mut public_buffer = [0u8; Curve25519Key::KEYSIZE]; key1.export_public(&mut public_buffer).expect("Error with export_public()"); diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs index 30d2d5b3fc..8bc3d369c1 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs @@ -4,9 +4,13 @@ mod common; #[cfg(any(all(ecc_import, ecc_export, ecc_sign, ecc_verify, random), random))] use std::fs; +#[cfg(all(ecc_dh, random))] +use std::rc::Rc; use wolfssl_wolfcrypt::ecc::*; #[cfg(random)] use wolfssl_wolfcrypt::random::RNG; +#[cfg(ecc_import)] +use wolfssl_wolfcrypt::sys; #[test] #[cfg(random)] @@ -134,7 +138,7 @@ fn test_ecc_import_export_sign_verify() { let valid = ecc.verify_hash(&signature, &hash).expect("Error with verify_hash()"); assert_eq!(valid, false); - ecc.set_rng(&mut rng).expect("Error with set_rng()"); + ecc.set_rng(rng).expect("Error with set_rng()"); } #[test] @@ -142,13 +146,13 @@ fn test_ecc_import_export_sign_verify() { fn test_ecc_shared_secret() { common::setup(); - let mut rng = RNG::new().expect("Failed to create RNG"); - let mut ecc0 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); - let mut ecc1 = ECC::generate(32, &mut rng, None, None).expect("Error with generate()"); + let rng = Rc::new(RNG::new().expect("Failed to create RNG")); + let mut ecc0 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); + let mut ecc1 = ECC::generate(32, &rng, None, None).expect("Error with generate()"); let mut ss0 = [0u8; 128]; let mut ss1 = [0u8; 128]; - ecc0.set_rng(&mut rng).expect("Error with set_rng()"); - ecc1.set_rng(&mut rng).expect("Error with set_rng()"); + ecc0.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); + ecc1.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let ss0_size = ecc0.shared_secret(&mut ecc1, &mut ss0).expect("Error with shared_secret()"); let ss1_size = ecc1.shared_secret(&mut ecc0, &mut ss1).expect("Error with shared_secret()"); assert_eq!(ss0_size, ss1_size); @@ -290,6 +294,33 @@ fn test_ecc_import_unsigned() { assert_eq!(valid, true); } +#[test] +#[cfg(ecc_import)] +fn test_ecc_import_unsigned_short_slices() { + common::setup(); + + let curve_id = ECC::SECP256R1; + let qx = [0u8; 32]; + let qy = [0u8; 32]; + let d = [0u8; 32]; + let empty: [u8; 0] = []; + + let cases: [(&[u8], &[u8], &[u8]); 6] = [ + (&qx[..31], &qy, &d ), + (&qx, &qy[..31], &d ), + (&qx, &qy, &d[..31] ), + (&empty, &qy, &d ), + (&qx, &empty, &d ), + (&qx, &qy, &empty ), + ]; + for (qx, qy, d) in cases { + match ECC::import_unsigned(qx, qy, d, curve_id, None, None) { + Ok(_) => panic!("import_unsigned() should fail with short slice"), + Err(rc) => assert_eq!(rc, sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG), + } + } +} + #[test] #[cfg(random)] fn test_ecc_make_pub() { @@ -365,6 +396,38 @@ fn test_ecc_import() { ECC::import_raw_ex(qx, qy, d, ECC::SECP256R1, None, None).expect("Error with import_raw_ex()"); } +#[test] +#[cfg(ecc_import)] +fn test_ecc_import_raw_not_null_terminated() { + common::setup(); + + let qx = b"7a4e287890a1a47ad3457e52f2f76a83ce46cbc947616d0cbaa82323818a793d\0"; + let qy = b"eec4084f5b29ebf29c44cce3b3059610922f8b30ea6e8811742ac7238fe87308\0"; + let d = b"8c14b793cb19137e323a6d2e2a870bca2e7a493ec1153b3a95feb8a4873f8d08\0"; + let qx_no_nul: &[u8] = &qx[..qx.len() - 1]; + let qy_no_nul: &[u8] = &qy[..qy.len() - 1]; + let d_no_nul: &[u8] = &d[..d.len() - 1]; + let curve_name = b"SECP256R1\0"; + let curve_name_no_nul: &[u8] = b"SECP256R1"; + let empty: &[u8] = b""; + + assert!(ECC::import_raw(qx_no_nul, qy, d, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, qy_no_nul, d, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, qy, d_no_nul, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, qy, d, curve_name_no_nul, None, None).is_err()); + assert!(ECC::import_raw(empty, qy, d, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, empty, d, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, qy, empty, curve_name, None, None).is_err()); + assert!(ECC::import_raw(qx, qy, d, empty, None, None).is_err()); + + assert!(ECC::import_raw_ex(qx_no_nul, qy, d, ECC::SECP256R1, None, None).is_err()); + assert!(ECC::import_raw_ex(qx, qy_no_nul, d, ECC::SECP256R1, None, None).is_err()); + assert!(ECC::import_raw_ex(qx, qy, d_no_nul, ECC::SECP256R1, None, None).is_err()); + assert!(ECC::import_raw_ex(empty, qy, d, ECC::SECP256R1, None, None).is_err()); + assert!(ECC::import_raw_ex(qx, empty, d, ECC::SECP256R1, None, None).is_err()); + assert!(ECC::import_raw_ex(qx, qy, empty, ECC::SECP256R1, None, None).is_err()); +} + #[test] fn test_ecc_rs_hex_to_sig_not_null_terminated() { common::setup(); diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs index 6a7067b0ee..fab799bae6 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs @@ -40,6 +40,27 @@ fn test_hmac_sha256_mac_finalize() { assert_eq!(result.as_bytes().as_slice(), expected); } +#[test] +fn test_hmac_sha256_mac_clone() { + let key = b"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; + let prefix = b"Hi "; + let suffix = b"There"; + let expected = b"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7"; + + let mut mac = HmacSha256::new_from_slice(key) + .expect("HMAC init failed"); + mac.update(prefix); + + let mut forked = mac.clone(); + forked.update(suffix); + let forked_tag = forked.finalize(); + assert_eq!(forked_tag.as_bytes().as_slice(), expected); + + mac.update(suffix); + let original_tag = mac.finalize(); + assert_eq!(original_tag.as_bytes().as_slice(), expected); +} + #[test] fn test_hmac_sha256_mac_verify_fail() { let key = b"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_random.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_random.rs index bf7f1536a7..45977123ad 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_random.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_random.rs @@ -52,7 +52,7 @@ fn test_test_seed() { fn test_rng_generate_byte() { // Since a single 0x00 or 0xFF could occur occasionally, we'll combine four // bytes into a u32 and make sure they aren't all 0x00 or all 0xFF. - let mut rng = RNG::new().expect("Failed to create RNG"); + let rng = RNG::new().expect("Failed to create RNG"); let mut v: u32 = 0; for _i in 0..4 { let byte = rng.generate_byte().expect("Failed to generate a single byte"); @@ -65,7 +65,7 @@ fn test_rng_generate_byte() { // Test that generate_block works for a slice of u8. #[test] fn test_rng_generate_block_u8() { - let mut rng = RNG::new().expect("Failed to create RNG"); + let rng = RNG::new().expect("Failed to create RNG"); let mut buffer = [0u8; 32]; rng.generate_block(&mut buffer).expect("Failed to generate a block of bytes"); @@ -77,7 +77,7 @@ fn test_rng_generate_block_u8() { // Test that generate_block works for a slice of u32. #[test] fn test_rng_generate_block_u32() { - let mut rng = RNG::new().expect("Failed to create RNG"); + let rng = RNG::new().expect("Failed to create RNG"); let mut buffer = [0u32; 8]; rng.generate_block(&mut buffer).expect("Failed to generate a block of u32"); @@ -93,7 +93,7 @@ fn test_rng_generate_block_u32() { #[test] #[cfg(random_hashdrbg)] fn test_rng_reseed() { - let mut rng = RNG::new().expect("Failed to create RNG"); + let rng = RNG::new().expect("Failed to create RNG"); let seed = [1u8, 2, 3, 4]; rng.reseed(&seed).expect("Error with reseed()"); } diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_rsa.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_rsa.rs index b8d19cfaec..c935113433 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_rsa.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_rsa.rs @@ -5,6 +5,8 @@ mod common; #[cfg(any(all(sha256, random, rsa_pss), random, rsa_direct))] use std::fs; #[cfg(random)] +use std::rc::Rc; +#[cfg(random)] use wolfssl_wolfcrypt::random::RNG; #[cfg(any(random, rsa_direct, rsa_keygen))] use wolfssl_wolfcrypt::rsa::*; @@ -14,8 +16,8 @@ use wolfssl_wolfcrypt::rsa::*; fn test_rsa_generate() { common::setup(); - let mut rng = RNG::new().expect("Error creating RNG"); - let mut rsa = RSA::generate(2048, 65537, &mut rng).expect("Error with generate()"); + let rng = RNG::new().expect("Error creating RNG"); + let mut rsa = RSA::generate(2048, 65537, &rng).expect("Error with generate()"); rsa.check().expect("Error with check()"); let encrypt_size = rsa.get_encrypt_size().expect("Error with get_encrypt_size()"); @@ -58,20 +60,20 @@ fn test_rsa_generate() { #[test] #[cfg(random)] fn test_rsa_encrypt_decrypt() { - let mut rng = RNG::new().expect("Error creating RNG"); + let rng = Rc::new(RNG::new().expect("Error creating RNG")); let key_path = "../../../certs/client-keyPub.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - rsa.set_rng(&mut rng).expect("Error with set_rng()"); + rsa.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let plain: &[u8] = b"Test message"; let mut enc: [u8; 512] = [0; 512]; - let enc_len = rsa.public_encrypt(plain, &mut enc, &mut rng).expect("Error with public_encrypt()"); + let enc_len = rsa.public_encrypt(plain, &mut enc, &rng).expect("Error with public_encrypt()"); assert!(enc_len > 0 && enc_len <= 512); let key_path = "../../../certs/client-key.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); - rsa.set_rng(&mut rng).expect("Error with set_rng()"); + rsa.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let mut plain_out: [u8; 512] = [0; 512]; let dec_len = rsa.private_decrypt(&enc[0..enc_len], &mut plain_out).expect("Error with private_decrypt()"); assert!(dec_len as usize == plain.len()); @@ -81,20 +83,20 @@ fn test_rsa_encrypt_decrypt() { #[test] #[cfg(all(sha256, random, rsa_pss))] fn test_rsa_pss() { - let mut rng = RNG::new().expect("Error creating RNG"); + let rng = Rc::new(RNG::new().expect("Error creating RNG")); let key_path = "../../../certs/client-key.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); let msg: &[u8] = b"This is the string to be signed!"; let mut signature: [u8; 512] = [0; 512]; - let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &mut rng).expect("Error with pss_sign()"); + let sig_len = rsa.pss_sign(msg, &mut signature, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256, &rng).expect("Error with pss_sign()"); assert!(sig_len > 0 && sig_len <= 512); let key_path = "../../../certs/client-keyPub.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - rsa.set_rng(&mut rng).expect("Error with set_rng()"); + rsa.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let signature = &signature[0..sig_len]; let mut verify_out: [u8; 512] = [0; 512]; let verify_out_size = rsa.pss_verify(signature, &mut verify_out, RSA::HASH_TYPE_SHA256, RSA::MGF1SHA256).expect("Error with pss_verify()"); @@ -108,7 +110,7 @@ fn test_rsa_pss() { #[test] #[cfg(rsa_direct)] fn test_rsa_direct() { - let mut rng = RNG::new().expect("Error creating RNG"); + let rng = RNG::new().expect("Error creating RNG"); let key_path = "../../../certs/client-key.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); @@ -117,10 +119,10 @@ fn test_rsa_direct() { let mut plain = [0u8; 256]; plain[..msg.len()].copy_from_slice(msg); let mut enc = [0u8; 256]; - let enc_len = rsa.rsa_direct(&plain, &mut enc, RSA::PRIVATE_ENCRYPT, &mut rng).expect("Error with rsa_direct()"); + let enc_len = rsa.rsa_direct(&plain, &mut enc, RSA::PRIVATE_ENCRYPT, &rng).expect("Error with rsa_direct()"); assert_eq!(enc_len, 256); let mut plain_out = [0u8; 256]; - let dec_len = rsa.rsa_direct(&enc, &mut plain_out, RSA::PUBLIC_DECRYPT, &mut rng).expect("Error with rsa_direct()"); + let dec_len = rsa.rsa_direct(&enc, &mut plain_out, RSA::PUBLIC_DECRYPT, &rng).expect("Error with rsa_direct()"); assert_eq!(dec_len, 256); assert_eq!(plain_out, plain); } @@ -128,20 +130,20 @@ fn test_rsa_direct() { #[test] #[cfg(random)] fn test_rsa_ssl() { - let mut rng = RNG::new().expect("Error creating RNG"); + let rng = Rc::new(RNG::new().expect("Error creating RNG")); let key_path = "../../../certs/client-key.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_from_der(&der).expect("Error with new_from_der()"); let msg: &[u8] = b"This is the string to be signed!"; let mut signature: [u8; 512] = [0; 512]; - let sig_len = rsa.ssl_sign(msg, &mut signature, &mut rng).expect("Error with ssl_sign()"); + let sig_len = rsa.ssl_sign(msg, &mut signature, &rng).expect("Error with ssl_sign()"); assert!(sig_len > 0 && sig_len <= 512); let key_path = "../../../certs/client-keyPub.der"; let der: Vec = fs::read(key_path).expect("Error reading key file"); let mut rsa = RSA::new_public_from_der(&der).expect("Error with new_public_from_der()"); - rsa.set_rng(&mut rng).expect("Error with set_rng()"); + rsa.set_shared_rng(Rc::clone(&rng)).expect("Error with set_shared_rng()"); let signature = &signature[0..sig_len]; let mut verify_out: [u8; 512] = [0; 512]; let verify_out_size = rsa.ssl_verify(signature, &mut verify_out).expect("Error with ssl_verify()");