From 99b9bad178362bd5dd9113613d31b1af41c2aad5 Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 19 Nov 2024 00:47:27 +0100 Subject: [PATCH] Replace our AES code with the one from MbedTLS 3.6.2 This one supports AES-NI (Intel) and AES-CE (ARM, including Apple Silicon) and does not depend on yasm as it's primarily written in C with intrinsics. Unlike the old code that was only used for o5logon, this code kicks in for any format using AES. Great boosts seen with AES-heavy formats. The AES-CBC function was modifed so it accepts sizes not a multiple of block size, and does what OpenSSL and others do: Treat the last block as a full one, possibly writing past end of output buffer. Closes #4314 --- .gitignore | 2 +- doc/NEWS | 6 + src/Makefile.in | 41 +- src/Makefile.legacy | 85 +- src/aes.h | 80 +- src/aes/Makefile.in | 54 - src/aes/Makefile.legacy | 38 - src/aes/aes.c | 43 - src/aes/aes_func.h | 26 - src/aes/aesni/LICENSE | 34 - src/aes/aesni/Makefile.in | 24 - src/aes/aesni/Makefile.legacy | 16 - src/aes/aesni/asm/x64/do_rdtsc.s | 44 - src/aes/aesni/asm/x64/iaesx64.s | 2090 -------------------------- src/aes/aesni/asm/x86/do_rdtsc.s | 42 - src/aes/aesni/asm/x86/iaesx86.s | 2206 ---------------------------- src/aes/aesni/iaes_asm_interface.h | 125 -- src/aes/aesni/iaesni.h | 145 -- src/aes/aesni/intel_aes.c | 310 ---- src/aes/openssl/Makefile.in | 20 - src/aes/openssl/Makefile.legacy | 5 - src/aes/openssl/ossl_aes.c | 87 -- src/aes/openssl/ossl_aes.h | 12 - src/aes/openssl/ossl_aes_crypto.c | 1283 ---------------- src/aes_ige.h | 2 +- src/aes_ige_plug.c | 2 +- src/configure | 104 +- src/configure.ac | 62 +- src/ed25519-donna/Makefile.in | 1 - src/ed25519-donna/Makefile.legacy | 1 - src/enpass_fmt_plug.c | 2 +- src/gpg_common_plug.c | 13 +- src/krb5_common.h | 2 +- src/krb5_common_plug.c | 2 +- src/listconf.c | 23 +- src/mbedtls/Makefile.in | 32 + src/mbedtls/Makefile.legacy | 25 + src/mbedtls/aes.c | 22 +- src/mbedtls/aes.h | 6 +- src/mbedtls/aesce.h | 4 +- src/mbedtls/aesni.h | 4 +- src/mbedtls/build_info.h | 12 +- src/mbedtls/common.h | 2 +- src/mbedtls/error.h | 2 +- src/mbedtls/mbedtls_config.h | 258 ++-- src/mbedtls/platform.h | 6 +- src/mbedtls/platform_util.h | 9 +- src/o5logon_fmt_plug.c | 26 +- src/poly1305-donna/Makefile.legacy | 1 - src/secp256k1/Makefile.in | 1 - src/secp256k1/Makefile.legacy | 1 - src/strip_fmt_plug.c | 2 +- 52 files changed, 331 insertions(+), 7114 deletions(-) delete mode 100644 src/aes/Makefile.in delete mode 100644 src/aes/Makefile.legacy delete mode 100644 src/aes/aes.c delete mode 100644 src/aes/aes_func.h delete mode 100644 src/aes/aesni/LICENSE delete mode 100644 src/aes/aesni/Makefile.in delete mode 100644 src/aes/aesni/Makefile.legacy delete mode 100644 src/aes/aesni/asm/x64/do_rdtsc.s delete mode 100644 src/aes/aesni/asm/x64/iaesx64.s delete mode 100644 src/aes/aesni/asm/x86/do_rdtsc.s delete mode 100644 src/aes/aesni/asm/x86/iaesx86.s delete mode 100644 src/aes/aesni/iaes_asm_interface.h delete mode 100644 src/aes/aesni/iaesni.h delete mode 100644 src/aes/aesni/intel_aes.c delete mode 100644 src/aes/openssl/Makefile.in delete mode 100644 src/aes/openssl/Makefile.legacy delete mode 100644 src/aes/openssl/ossl_aes.c delete mode 100644 src/aes/openssl/ossl_aes.h delete mode 100644 src/aes/openssl/ossl_aes_crypto.c create mode 100644 src/mbedtls/Makefile.in create mode 100644 src/mbedtls/Makefile.legacy diff --git a/.gitignore b/.gitignore index f8c881dbaf1..40a3b9fe7bc 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ run/wpapcap2john run/zip2john src/.gdbinit -src/aes/aes.a +src/mbedtls/aes.a src/arch.h src/all_tests.lst src/autoconfig-stamp-h diff --git a/doc/NEWS b/doc/NEWS index 4511a6246dc..6a0d3637eda 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -354,6 +354,12 @@ Major changes from 1.9.0-jumbo-1 (May 2019) in this bleeding-edge version: character classes got (very minor) changes - this can affect resuming old jobs [magnum; 2024] +- Dropped our old AES-NI code in favor of the AES code from mbedTLS, which + supports AES-NI (Intel) as well as AES-CE (Arm). The new code kicks in for + any format using AES. Boosts of up to 13x seen on Intel and 7x on MacBook + M1 (those are for the KeePass format with AES-KDF, which is extreme because + all the heavy lifting is AES). [magnum; 2024] + Major changes from 1.8.0-jumbo-1 (December 2014) to 1.9.0-jumbo-1 (May 2019): diff --git a/src/Makefile.in b/src/Makefile.in index f10524b9ad1..7225b052f81 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -39,7 +39,7 @@ PEFLAGS = peflags --dynamicbase=true --nxcompat=true SHELL = /bin/sh VPATH = @srcdir@ -subdirs = aes secp256k1 ed25519-donna poly1305-donna @ZTEX_SUBDIRS@ +subdirs = mbedtls secp256k1 ed25519-donna poly1305-donna @ZTEX_SUBDIRS@ top_srcdir = @top_srcdir@ srcdir = @srcdir@ prefix = @prefix@ @@ -71,20 +71,6 @@ LDFLAGS = -g @LDFLAGS@ $(LIBS) @HAVE_MPI@ OPT_NORMAL = @OPT_NORMAL_FLAGS@ OPT_INLINE = @OPT_INLINE_FLAGS@ # -AES_OK := $(shell expr `$(CC) -dumpversion | cut -d '.' -f 1` \>= 4) -YASM = @YASM@ -USE_AESNI = @AESNI_OS@ -AESNI_ARCH=@AESNI_ARCH@ - -ifeq "$(AES_OK)" "1" - ifneq "$(YASM)" "" - ifdef USE_AESNI - ifdef AESNI_ARCH - AESNI_DEC = -DAESNI_IN_USE - endif - endif - endif -endif PLUGFORMATS_OBJS = @PLUGFORMATS_OBJS@ @@ -206,8 +192,7 @@ endif default: $(MAKE) find_version @$(MAKE) $(PROJ) \ - JOHN_OBJS="$(JOHN_OBJS) @CC_ASM_OBJS@" \ - AESNI_ARCH=@AESNI_ARCH@ + JOHN_OBJS="$(JOHN_OBJS) @CC_ASM_OBJS@" @if [ "$(OS)" = "Windows_NT" ]; then \ $(MAKE) peflags; \ @@ -525,15 +510,15 @@ unicode.o: unicode.c common.h arch.h memory.h byteorder.h unicode.h options.h au unique.o: unique.c autoconfig.h arch.h misc.h jumbo.h params.h memory.h os.h os-autoconf.h -unrar.o: unrar.c arch.h unrar.h aes.h autoconfig.h aes/aes_func.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h +unrar.o: unrar.c arch.h unrar.h aes.h autoconfig.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h -unrarcmd.o: unrarcmd.c aes.h autoconfig.h aes/aes_func.h unrar.h arch.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h +unrarcmd.o: unrarcmd.c aes.h autoconfig.h unrar.h arch.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h -unrarfilter.o: unrarfilter.c arch.h aes.h autoconfig.h aes/aes_func.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h +unrarfilter.o: unrarfilter.c arch.h aes.h autoconfig.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h os.h os-autoconf.h unrarhlp.o: unrarhlp.c jumbo.h arch.h unrarhlp.h memory.h os.h os-autoconf.h autoconfig.h -unrarvm.o: unrarvm.c arch.h aes.h autoconfig.h aes/aes_func.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h common.h os.h os-autoconf.h +unrarvm.o: unrarvm.c arch.h aes.h autoconfig.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h common.h os.h os-autoconf.h unshadow.o: unshadow.c misc.h jumbo.h arch.h autoconfig.h params.h memory.h os.h os-autoconf.h @@ -574,7 +559,7 @@ find_version: echo "#define JTR_GIT_VERSION $(JTR_GIT_VERSION)" > version.h.new diff >/dev/null 2>/dev/null version.h.new version.h && $(RM) version.h.new || $(MV) version.h.new version.h -SUBDIRS = aes secp256k1 ed25519-donna poly1305-donna @ZTEX_SUBDIRS@ +SUBDIRS = mbedtls secp256k1 ed25519-donna poly1305-donna @ZTEX_SUBDIRS@ .PHONY: subdirs $(SUBDIRS) find_version @@ -590,8 +575,8 @@ DES_bs_b.o: DES_bs_b.c arch.h common.h memory.h DES_bs.h loader.h params.h list. miscnl.o: misc.c $(CC) $(CFLAGS) $(OPT_NORMAL) -D_JOHN_MISC_NO_LOG misc.c -o miscnl.o -aes/aes.a: - $(MAKE) -C aes all +mbedtls/aes.a: + $(MAKE) -C mbedtls all secp256k1/secp256k1.a: $(MAKE) -C secp256k1 all @@ -614,8 +599,8 @@ poly1305-donna/poly1305-donna.a: # PTHREAD_CFLAGS and OPENMP_CFLAGS may actually contain linker options, # like -fopenmp -../run/john@EXE_EXT@: $(JOHN_OBJS) aes/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a @ZTEX_SUBDIRS@ - $(LD) $(JOHN_OBJS) $(LDFLAGS) @OPENSSL_LIBS@ @OPENMP_CFLAGS@ @GMP_LIBS@ @SKEY_LIBS@ @REXGEN_LIBS@ @CL_LIBS@ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ @M_LIBS@ @RT_LIBS@ @Z_LIBS@ @DL_LIBS@ @CRYPT_LIBS@ @BZ2_LIBS@ @ZTEX_LIBS@ aes/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -o $@ +../run/john@EXE_EXT@: $(JOHN_OBJS) mbedtls/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a @ZTEX_SUBDIRS@ + $(LD) $(JOHN_OBJS) $(LDFLAGS) @OPENSSL_LIBS@ @OPENMP_CFLAGS@ @GMP_LIBS@ @SKEY_LIBS@ @REXGEN_LIBS@ @CL_LIBS@ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ @M_LIBS@ @RT_LIBS@ @Z_LIBS@ @DL_LIBS@ @CRYPT_LIBS@ @BZ2_LIBS@ @ZTEX_LIBS@ mbedtls/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -o $@ ../run/unshadow: ../run/john $(RM) ../run/unshadow @@ -756,11 +741,11 @@ path.o: path.c path.h autoconfig.h arch.h params.h misc.h memory.h $(CC) $(CFLAGS_MAIN) $(OPT_NORMAL) -O1 $*.c # Workaround for gcc 3.4.6 (seen on Sparc32) (do not use -funroll-loops) -unrarppm.o: unrarppm.c arch.h aes.h autoconfig.h aes/aes_func.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h common.h os.h os-autoconf.h +unrarppm.o: unrarppm.c arch.h aes.h autoconfig.h unrar.h unrarhlp.h memory.h jumbo.h unrarppm.h unrarvm.h unrarcmd.h unrarfilter.h common.h os.h os-autoconf.h $(CC) -DAC_BUILT $(CFLAGS) $< -o $@ .c.o: - $(CC) $(CFLAGS) $(OPT_NORMAL) $(AESNI_DEC) $< -o $@ + $(CC) $(CFLAGS) $(OPT_NORMAL) $< -o $@ .S.o: $(AS) $(ASFLAGS) $*.S diff --git a/src/Makefile.legacy b/src/Makefile.legacy index 9eddff33495..b60574e212a 100644 --- a/src/Makefile.legacy +++ b/src/Makefile.legacy @@ -369,8 +369,7 @@ linux-x86-64-xop: CFLAGS_MAIN="$(CFLAGS) -DJOHN_XOP -DHAVE_CRYPT -DHAVE_LIBDL" \ CFLAGS="$(CFLAGS) -mxop -DHAVE_CRYPT -DHAVE_LIBDL" \ ASFLAGS="$(ASFLAGS) -mxop" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -383,8 +382,7 @@ linux-x86-64-avx: CFLAGS_MAIN="$(CFLAGS) -DJOHN_AVX -DHAVE_CRYPT -DHAVE_LIBDL" \ CFLAGS="$(CFLAGS) -mavx -DHAVE_CRYPT -DHAVE_LIBDL" \ ASFLAGS="$(ASFLAGS) -mavx" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -396,8 +394,7 @@ linux-x86-64-opencl: JOHN_OBJS="$(JOHN_OBJS) $(OCL_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -I$(OCLROOT)/include -DHAVE_CRYPT -DHAVE_OPENCL -DHAVE_LIBDL -march=native" \ ASFLAGS="$(ASFLAGS) -march=native" \ - LDFLAGS="$(LDFLAGS) -L$(OCLROOT)/lib/x86_64 -L$(OCLROOT)/lib64 -lcrypt -lOpenCL -ldl -march=native" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="$(LDFLAGS) -L$(OCLROOT)/lib/x86_64 -L$(OCLROOT)/lib64 -lcrypt -lOpenCL -ldl -march=native" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -409,8 +406,7 @@ linux-x86-64-native: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -march=native" \ ASFLAGS="$(ASFLAGS) -march=native" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -422,8 +418,7 @@ linux-X32-native: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -march=native -mx32" \ ASFLAGS="$(ASFLAGS) -march=native -mx32" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native -mx32" \ - AESNI_ARCH=64 YASM_FORMAT="elfx32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native -mx32" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -435,8 +430,7 @@ linux-X32: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -mx32" \ ASFLAGS="$(ASFLAGS) -mx32" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl -mx32" \ - AESNI_ARCH=64 YASM_FORMAT="elfx32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl -mx32" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -447,8 +441,7 @@ linux-x86-64: $(MAKE_ORIG) $(PROJ) \ JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -461,8 +454,7 @@ linux-x86-64-clang: CFLAGS="-Wall -c -O2 -I/usr/include -msse2 -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" \ - OPT_INLINE="$(OPT_NORMAL)" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + OPT_INLINE="$(OPT_NORMAL)" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CC="clang" @echo "All done" @@ -474,8 +466,7 @@ linux-x86-64-clang-debug: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="-Wall -c -g -O1 -faddress-sanitizer -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ LDFLAGS="-L/usr/local/lib $(LDFLAGS_OPENSSL) -lm -lz -lcrypt -ldl -faddress-sanitizer $(GMP_LDFLAGS) $(JOHN_LDFLAGS)" \ - CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) \ CFLAGS="-Wall -c -g -O1 -faddress-sanitizer -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ @@ -489,8 +480,7 @@ linux-x86-64-newgcc-debug: $(MAKE_ORIG) $(PROJ) \ JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86-64.o simd-intrinsics.o" \ CFLAGS="-Wall -c -g -O1 -fsanitize=address -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ - LDFLAGS="-L/usr/local/lib $(LDFLAGS_OPENSSL) -lm -lz -lcrypt -ldl -fsanitize=address $(GMP_LDFLAGS) $(JOHN_LDFLAGS)" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + LDFLAGS="-L/usr/local/lib $(LDFLAGS_OPENSSL) -lm -lz -lcrypt -ldl -fsanitize=address $(GMP_LDFLAGS) $(JOHN_LDFLAGS)" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) \ CFLAGS="-Wall -c -g -O1 -fsanitize=address -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ @@ -505,8 +495,7 @@ linux-x86-64-icc: CFLAGS="-c -fast -O2 -I/usr/include -static-intel -DHAVE_CRYPT -DHAVE_LIBDL $(ICCOMPFLAGS) $(HAVE_LIBGMP) $(JOHN_CFLAGS)" \ ASFLAGS="-c -xHost $(JOHN_ASFLAGS)" \ LDFLAGS="-lm $(LDFLAGS_OPENSSL) -ipo -static-intel -lcrypt -ldl -lz $(ICCOMPFLAGS) -s $(GMP_LDFLAGS) $(JOHN_LDFLAGS)" \ - CPP="icc" CC="icc" AS="icc" LD="icc" \ - AESNI_ARCH=64 YASM_FORMAT="elf64" + CPP="icc" CC="icc" AS="icc" LD="icc" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CPP="icc" CC="icc" AS="icc" LD="icc" @echo "All done" @@ -518,8 +507,7 @@ linux-x86-64-32-native: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -m32 -msse2 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE -march=native" \ ASFLAGS="$(ASFLAGS) -m32 -msse2 -march=native" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl -march=native" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl -march=native" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" @echo "All done" @@ -531,8 +519,7 @@ linux-x86-64-32-sse2: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -m32 -msse2 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -m32 -msse2" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" @echo "All done" @@ -544,8 +531,7 @@ linux-x86-64-32-sse2asm: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o" \ CFLAGS="$(CFLAGS) -m32 -msse2 -DHAVE_CRYPT -DHAVE_LIBDL -DJOHN_DISABLE_INTRINSICS -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -m32 -msse2" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" @echo "All done" @@ -557,8 +543,7 @@ linux-x86-64-32-mmx: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-mmx.o" \ CFLAGS="$(CFLAGS) -m32 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -m32" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" @echo "All done" @@ -570,8 +555,7 @@ linux-x86-64-32-any: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o" \ CFLAGS="$(CFLAGS) -m32 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -m32" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" @echo "All done" @@ -604,8 +588,7 @@ linux-x86-xop: CFLAGS_MAIN="$(CFLAGS) -m32 -DJOHN_XOP -DHAVE_CRYPT" \ CFLAGS="$(CFLAGS) -m32 -mxop -DHAVE_CRYPT -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -m32 -mxop" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" @echo "All done" @@ -618,8 +601,7 @@ linux-x86-avx: CFLAGS_MAIN="$(CFLAGS) -m32 -DJOHN_AVX -DHAVE_CRYPT -D_LARGEFILE64_SOURCE" \ CFLAGS="$(CFLAGS) -m32 -mavx -DHAVE_CRYPT" \ ASFLAGS="$(ASFLAGS) -m32 -mavx" \ - LDFLAGS="$(LDFLAGS) -m32 -lcrypt" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -m32 -lcrypt" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CFLAGS="$(CFLAGS) -m32" @echo "All done" @@ -631,8 +613,7 @@ linux-x86-opencl: JOHN_OBJS="$(JOHN_OBJS) $(OCL_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -I$(OCLROOT)/include -DHAVE_CRYPT -DHAVE_OPENCL -DHAVE_LIBDL -D_LARGEFILE64_SOURCE -march=native" \ ASFLAGS="$(ASFLAGS) -march=native" \ - LDFLAGS="$(LDFLAGS) -L$(OCLROOT)/lib/x86 -L$(OCLROOT)/lib -lcrypt -lOpenCL -ldl -march=native" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -L$(OCLROOT)/lib/x86 -L$(OCLROOT)/lib -lcrypt -lOpenCL -ldl -march=native" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -644,8 +625,7 @@ linux-x86-native: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE -march=native" \ ASFLAGS="$(ASFLAGS) -march=native" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl -march=native" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -657,8 +637,7 @@ linux-x86-sse2: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="$(CFLAGS) -msse2 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ ASFLAGS="$(ASFLAGS) -msse2" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -669,8 +648,7 @@ linux-x86-mmx: $(MAKE_ORIG) $(PROJ) \ JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-mmx.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -681,8 +659,7 @@ linux-x86-any: $(MAKE_ORIG) $(PROJ) \ JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o" \ CFLAGS="$(CFLAGS) -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE" \ - LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + LDFLAGS="$(LDFLAGS) -lcrypt -ldl" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) @echo "All done" @@ -695,8 +672,7 @@ linux-x86-clang: CFLAGS="-Wall -c -O2 -I/usr/include -msse2 -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE $(HAVE_LIBGMP) $(OMPFLAGS) $(JOHN_CFLAGS)" \ LDFLAGS="$(LDFLAGS) -lcrypt -ldl" \ CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" \ - OPT_INLINE="$(OPT_NORMAL)" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + OPT_INLINE="$(OPT_NORMAL)" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) CC="clang" @echo "All done" @@ -708,8 +684,7 @@ linux-x86-clang-debug: JOHN_OBJS="$(JOHN_OBJS) c3_fmt.o x86.o x86-sse.o simd-intrinsics.o" \ CFLAGS="-Wall -c -g -O1 -faddress-sanitizer -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL -D_LARGEFILE64_SOURCE $(HAVE_LIBGMP) $(OMPFLAGS) $(JOHN_CFLAGS)" \ LDFLAGS="-L/usr/local/lib $(LDFLAGS_OPENSSL) -lm -lz -lcrypt -ldl -faddress-sanitizer $(GMP_LDFLAGS) $(JOHN_LDFLAGS)" \ - CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" \ - AESNI_ARCH=86 YASM_FORMAT="elf32" + CPP="clang" CC="clang" AS="clang" LD="clang" CXX="clang++" @echo "Failing after this point just means some helper tools did not build:" $(MAKE_ORIG) $(PROJ_PCAP) \ CFLAGS="-Wall -c -g -O1 -faddress-sanitizer -I/usr/include -msse2 -DDEBUG -DHAVE_CRYPT -DHAVE_LIBDL $(HAVE_LIBGMP) $(OMPFLAGS) $(JOHN_CFLAGS)" \ @@ -1745,7 +1720,7 @@ find_version: echo "#define JTR_GIT_VERSION $(JTR_GIT_VERSION)" > version.h.new diff >/dev/null 2>/dev/null version.h.new version.h && $(RM) version.h.new || $(MV) version.h.new version.h -SUBDIRS = aes secp256k1 ed25519-donna poly1305-donna +SUBDIRS = mbedtls secp256k1 ed25519-donna poly1305-donna .PHONY: subdirs $(SUBDIRS) find_version @@ -1755,7 +1730,7 @@ $(SUBDIRS): $(MAKE_ORIG) -C $@ all CC=$(CC) ../run/john: $(JOHN_OBJS) $(SUBDIRS) - $(LD) $(JOHN_OBJS) $(LDFLAGS) aes/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.o poly1305-donna/poly1305-donna.o -o ../run/john + $(LD) $(JOHN_OBJS) $(LDFLAGS) mbedtls/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.o poly1305-donna/poly1305-donna.o -o ../run/john ../run/unshadow: ../run/john $(RM) ../run/unshadow @@ -1831,7 +1806,7 @@ john.com: john.asm # $(LD) $(JOHN_OBJS) -lkernel32 -lcrypto -o ../run/john.exe ../run/john.exe: $(JOHN_OBJS) $(SUBDIRS) - $(LD) $(JOHN_OBJS) $(LDFLAGS) aes/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -lkernel32 -o ../run/john.exe + $(LD) $(JOHN_OBJS) $(LDFLAGS) mbedtls/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -lkernel32 -o ../run/john.exe $(STRIP) ../run/john.exe # this LD line removed from the ../run/john-mingw.exe rule (MinGW32 builds) @@ -1840,7 +1815,7 @@ john.com: john.asm # $(LD) $(JOHN_OBJS) $(LDFLAGS) -lkernel32 -o ../run/john-mingw.exe ../run/john-mingw.exe: $(JOHN_OBJS) - $(LD) $(JOHN_OBJS) $(LDFLAGS) aes/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -lkernel32 -o ../run/john-mingw.exe + $(LD) $(JOHN_OBJS) $(LDFLAGS) mbedtls/aes.a secp256k1/secp256k1.a ed25519-donna/ed25519-donna.a poly1305-donna/poly1305-donna.a -lkernel32 -o ../run/john-mingw.exe $(STRIP) ../run/john-mingw.exe cp ../run/john-mingw.exe ../run/john.exe @@ -2058,7 +2033,7 @@ clean: $(RM) *~ $(RM) dynamic_big_crypt.c fmt_registers.h fmt_externs.h john_build_rule.h version.h version.h.new $(CP) $(NULL) Makefile.dep - +$(MAKE_ORIG) -C aes clean + +$(MAKE_ORIG) -C mbedtls clean +$(MAKE_ORIG) -C secp256k1 clean +$(MAKE_ORIG) -C ed25519-donna clean +$(MAKE_ORIG) -C poly1305-donna clean diff --git a/src/aes.h b/src/aes.h index db1276ec7e3..a2c555da618 100644 --- a/src/aes.h +++ b/src/aes.h @@ -1,77 +1,29 @@ /* - * (c) 2014 Harrison Neal. Licensed under GPLv2. - * A set of convenience functions that return a function pointer to an - * appropriate AES implementation depending on your platform. - * - * NOTE: These functions are intended to be used by algorithms that - * continuously switch out AES keys - with each computation, state is - * built, used and torn down. - * Consider using straight OpenSSL EVP methods if your algorithm would - * do a lot of work with any single key. + * This software is Copyright (c) 2024 magnum, and it is hereby released to + * the general public under the following terms: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. */ #ifndef JTR_AES_H #define JTR_AES_H -#include -#include -#ifdef AC_BUILT -#include "autoconfig.h" -#endif +#include "mbedtls/aes.h" -// Input, output, key, number of blocks -typedef void (*aes_fptr_vanilla)(unsigned char *, unsigned char *, unsigned char *, size_t); -// Input, output, key, number of blocks, iv -typedef void (*aes_fptr_cbc)(unsigned char *, unsigned char *, unsigned char *, size_t, unsigned char *); -// Input, output, key, number of blocks, iv -typedef void (*aes_fptr_ctr)(unsigned char *, unsigned char *, unsigned char *, size_t, unsigned char *); +typedef mbedtls_aes_context AES_KEY; -#define FUNC(r,p) aes_fptr_##r get_##p(); +#define AES_ENCRYPT MBEDTLS_AES_ENCRYPT +#define AES_DECRYPT MBEDTLS_AES_DECRYPT +#define AES_BLOCK_SIZE 16 -#include "aes/aes_func.h" +#define AES_set_encrypt_key(key, size, ctx) mbedtls_aes_setkey_enc(ctx, key, size) +#define AES_encrypt(in, out, ctx) mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, in, out) -#undef FUNC +#define AES_set_decrypt_key(key, size, ctx) mbedtls_aes_setkey_dec(ctx, key, size) +#define AES_decrypt(in, out, ctx) mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_DECRYPT, in, out) -extern int using_aes_asm(); -extern const char *get_AES_type_string(); - -#if HAVE_AES_ENCRYPT - -#include - -#else -/* - * this code copied from oSSL newer version. This is ALL we do, so it - * has been pared down here. - */ -#define AES_ENCRYPT 1 -#define AES_DECRYPT 0 -#define AES_MAXNR 14 -#define AES_BLOCK_SIZE 16 -typedef struct aes_key_st { - unsigned int rd_key[4 *(AES_MAXNR + 1)]; - int rounds; -} AES_KEY; - -extern void JTR_AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); -#define AES_encrypt(a,b,c) JTR_AES_encrypt(a,b,c) - -#define AES_ecb_encrypt(a,b,c,d) (d == AES_ENCRYPT) ? JTR_AES_encrypt(a,b,c) : JTR_AES_decrypt(a,b,c) - -extern void JTR_AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); -#define AES_decrypt(a,b,c) JTR_AES_decrypt(a,b,c) - -extern int JTR_AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); -#define AES_set_encrypt_key(a,b,c) JTR_AES_set_encrypt_key(a,b,c) - -extern int JTR_AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); -#define AES_set_decrypt_key(a,b,c) JTR_AES_set_decrypt_key(a,b,c) - -extern void JTR_AES_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, const AES_KEY *key, unsigned char *ivec, const int enc); -#define AES_cbc_encrypt(a,b,c,d,e,f) JTR_AES_cbc_encrypt(a,b,c,d,e,f) - -// probably need to also do AES_cbc_decrypt, but will wait until someone 'needs' it. - -#endif +#define AES_ecb_encrypt(in, out, ctx, mode) mbedtls_aes_crypt_ecb(ctx, mode, in, out) +#define AES_cbc_encrypt(in, out, len, ctx, iv, mode) mbedtls_aes_crypt_cbc(ctx, mode, len, iv, in, out) +#define AES_cfb128_encrypt(in, out, len, ctx, iv, iv_off, mode) mbedtls_aes_crypt_cfb128(ctx, mode, len, iv_off, iv, in, out) #endif /* JTR_AES_H */ diff --git a/src/aes/Makefile.in b/src/aes/Makefile.in deleted file mode 100644 index 8942ed8681d..00000000000 --- a/src/aes/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -@SET_MAKE@ -CC = @CC@ -CXX = @CXX@ -AS = @CC@ -LD = @CC@ -CPP = @CC@ -CFLAGS = @CFLAGS@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ -ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@ -LDFLAGS = @LDFLAGS@ @OPENSSL_LIBS@ -YASM = @YASM@ -AR = @AR@ -FIND = @FIND@ -RM = /bin/rm -f -GCCV44 := $(shell expr `$(CC) -dumpversion | cut -d '.' -f 1` \>= 4) -USE_AESNI = @AESNI_OS@ - -AESIN = aes.o openssl/ossl_aes.o -SUBDIRS = openssl -ifeq "$(GCCV44)" "1" - ifneq "$(YASM)" "" - ifdef USE_AESNI - ifdef AESNI_ARCH - AESIN += aesni/*.o - SUBDIRS += aesni - AESNI_DEC = -DAESNI_IN_USE - endif - endif - endif -endif - -aes.o: aes.c ../aes.h aes_func.h - $(CC) $(CFLAGS) $(AESNI_DEC) -c aes.c -o aes.o - -.PHONY: subdirs $(SUBDIRS) - -subdirs: $(SUBDIRS) - -$(SUBDIRS): - $(MAKE) -C $@ all - -aes.a: $(SUBDIRS) aes.o - $(AR) -rs $@ $(AESIN) - -default: aes.a -all: aes.a - -clean: - $(FIND) . -name \*.a -exec $(RM) {} \; - $(FIND) . -name \*.o -exec $(RM) {} \; - -distclean: clean - $(RM) Makefile - $(RM) aesni/Makefile - $(RM) openssl/Makefile diff --git a/src/aes/Makefile.legacy b/src/aes/Makefile.legacy deleted file mode 100644 index 611a9e34b54..00000000000 --- a/src/aes/Makefile.legacy +++ /dev/null @@ -1,38 +0,0 @@ -RM = rm -f -GCCV44 := $(shell expr `$(CC) -dumpversion 2>/dev/null | cut -d '.' -f 1` \>= 4) -YASM := $(shell yasm -f $(YASM_FORMAT) 2>&1 | grep "No input files") -UNAME := $(shell $(CC) -dumpmachine 2>/dev/null) - -AESIN = aes.o openssl/ossl_aes.o -SUBDIRS = openssl -ifeq "$(GCCV44)" "1" - ifneq "$(YASM)" "" - ifneq (, $(findstring linux, $(UNAME))) - ifdef AESNI_ARCH - AESIN += aesni/*.o - SUBDIRS += aesni - AESNI_DEC = -DAESNI_IN_USE - endif - endif - endif -endif - -aes.o: aes.c ../aes.h aes_func.h - $(CC) $(CFLAGS) $(AESNI_DEC) -c aes.c -o aes.o - -.PHONY: subdirs $(SUBDIRS) - -subdirs: $(SUBDIRS) - -$(SUBDIRS): - $(MAKE) -f Makefile.legacy -C $@ all - -aes.a: $(SUBDIRS) aes.o - ar -r $@ $(AESIN) - -default: aes.a -all: aes.a - -clean: - find . -iname \*.a -exec $(RM) {} \; - find . -iname \*.o -exec $(RM) {} \; diff --git a/src/aes/aes.c b/src/aes/aes.c deleted file mode 100644 index eaef87a31aa..00000000000 --- a/src/aes/aes.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (c) 2014 Harrison Neal. Licensed under GPLv2. - * A set of convenience functions that return a function pointer to an - * appropriate AES implementation depending on your platform. - * - * NOTE: These functions are intended to be used by algorithms that - * continuously switch out AES keys - with each computation, state is - * built, used and torn down. - * Consider using straight OpenSSL EVP methods if your algorithm would - * do a lot of work with any single key. - */ - -#include -#include - -#include "../aes.h" - -#if HAVE_AES_ENCRYPT || !defined(AC_BUILT) -#include "openssl/ossl_aes.h" -const char *get_AES_type_string() { if (using_aes_asm()) return "AES-NI"; return "AES-oSSL"; } -#else -const char *get_AES_type_string() { if (using_aes_asm()) return "AES-NI"; return "AES-JtR"; } -#endif - - -#ifdef AESNI_IN_USE - #include "aesni/iaesni.h" - #define FUNC(r,p) aes_fptr_##r get_##p() { return check_for_aes_instructions() ? intel_##p : openssl_##p; } - int using_aes_asm() { - if (check_for_aes_instructions()) - return 1; - return 0; - } -#else - #define FUNC(r,p) aes_fptr_##r get_##p() { return openssl_##p; } - int using_aes_asm() { - return 0; - } -#endif - -#include "aes_func.h" - -#undef FUNC diff --git a/src/aes/aes_func.h b/src/aes/aes_func.h deleted file mode 100644 index 75c242c4623..00000000000 --- a/src/aes/aes_func.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * (c) 2014 Harrison Neal. Licensed under GPLv2. - * A set of convenience functions that return a function pointer to an - * appropriate AES implementation depending on your platform. - * - * NOTE: These functions are intended to be used by algorithms that - * continuously switch out AES keys - with each computation, state is - * built, used and torn down. - * Consider using straight OpenSSL EVP methods if your algorithm would - * do a lot of work with any single key. - */ - -// For the moment, only CBC stuff is implemented in both sources, so we won't expose more than that. - -#define FUNC_BITS(n) \ - /*FUNC(vanilla, AES_enc##n)*/ \ - FUNC(cbc, AES_enc##n##_CBC) \ - /*FUNC(vanilla, AES_dec##n)*/ \ - FUNC(cbc, AES_dec##n##_CBC) \ - /*FUNC(ctr, AES_encdec##n##_CTR)*/ - -FUNC_BITS(128) -FUNC_BITS(192) -FUNC_BITS(256) - -#undef FUNC_BITS diff --git a/src/aes/aesni/LICENSE b/src/aes/aesni/LICENSE deleted file mode 100644 index b67e7129892..00000000000 --- a/src/aes/aesni/LICENSE +++ /dev/null @@ -1,34 +0,0 @@ -Many files in this directory are largely based on the Intel AES-NI Sample Library v1.2. - -The license originally included with these files is as follows: - -/* - * Copyright (c) 2010, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ - -Modifications (c) 2014 Harrison Neal, under the same license terms. diff --git a/src/aes/aesni/Makefile.in b/src/aes/aesni/Makefile.in deleted file mode 100644 index 633183f4895..00000000000 --- a/src/aes/aesni/Makefile.in +++ /dev/null @@ -1,24 +0,0 @@ -@SET_MAKE@ -CC = @CC@ -ASM_DIR = asm/x$(AESNI_ARCH) -IAES = $(ASM_DIR)/iaesx$(AESNI_ARCH).s -RDTSC = $(ASM_DIR)/do_rdtsc.s -YASM = @YASM@ - -iaesx.o: $(IAES) - $(YASM) -D__@AESNI_OS@__ @YASM_OPTIONS@ $(IAES) -o $@ - -rdtsc.o: $(RDTSC) - $(YASM) -D__@AESNI_OS@__ @YASM_OPTIONS@ $(RDTSC) -o $@ - -aesni.o: iaes_asm_interface.h iaesni.h intel_aes.c - $(CC) $(CFLAGS) @CFLAGS_EXTRA@ -m@CPU_BIT_STR@ -c intel_aes.c -o $@ - -all: iaesx.o rdtsc.o aesni.o - -default: all - -clean: - -distclean: clean - $(RM) Makefile diff --git a/src/aes/aesni/Makefile.legacy b/src/aes/aesni/Makefile.legacy deleted file mode 100644 index b7158681f0a..00000000000 --- a/src/aes/aesni/Makefile.legacy +++ /dev/null @@ -1,16 +0,0 @@ -ASM_DIR = asm/x$(AESNI_ARCH) -IAES = $(ASM_DIR)/iaesx$(AESNI_ARCH).s -RDTSC = $(ASM_DIR)/do_rdtsc.s - -iaesx.o: $(IAES) - yasm -D__linux__ -g dwarf2 -f $(YASM_FORMAT) $(IAES) -o $@ - -rdtsc.o: $(RDTSC) - yasm -D__linux__ -g dwarf2 -f $(YASM_FORMAT) $(RDTSC) -o $@ - -aesni.o: iaes_asm_interface.h iaesni.h intel_aes.c - $(CC) $(CFLAGS) -c intel_aes.c -o $@ - -all: iaesx.o rdtsc.o aesni.o - -default: all diff --git a/src/aes/aesni/asm/x64/do_rdtsc.s b/src/aes/aesni/asm/x64/do_rdtsc.s deleted file mode 100644 index 0a84ccf2469..00000000000 --- a/src/aes/aesni/asm/x64/do_rdtsc.s +++ /dev/null @@ -1,44 +0,0 @@ -[bits 64] -[CPU intelnop] - -%ifidn __OUTPUT_FORMAT__,elf -section .note.GNU-stack noalloc noexec nowrite progbits -%endif -%ifidn __OUTPUT_FORMAT__,elf64 -section .note.GNU-stack noalloc noexec nowrite progbits -%endif - -; Copyright (c) 2010, Intel Corporation -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions are met: -; -; * Redistributions of source code must retain the above copyright notice, -; this list of conditions and the following disclaimer. -; * Redistributions in binary form must reproduce the above copyright notice, -; this list of conditions and the following disclaimer in the documentation -; and/or other materials provided with the distribution. -; * Neither the name of Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -align 16 -global do_rdtsc -do_rdtsc: - - rdtsc - shl rdx, 32 - or rax, rdx - ret 0 diff --git a/src/aes/aesni/asm/x64/iaesx64.s b/src/aes/aesni/asm/x64/iaesx64.s deleted file mode 100644 index 83df57f54ff..00000000000 --- a/src/aes/aesni/asm/x64/iaesx64.s +++ /dev/null @@ -1,2090 +0,0 @@ -[bits 64] -[CPU intelnop] - -%ifidn __OUTPUT_FORMAT__,elf -section .note.GNU-stack noalloc noexec nowrite progbits -%endif -%ifidn __OUTPUT_FORMAT__,elf64 -section .note.GNU-stack noalloc noexec nowrite progbits -%endif - -; Copyright (c) 2010, Intel Corporation -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions are met: -; -; * Redistributions of source code must retain the above copyright notice, -; this list of conditions and the following disclaimer. -; * Redistributions in binary form must reproduce the above copyright notice, -; this list of conditions and the following disclaimer in the documentation -; and/or other materials provided with the distribution. -; * Neither the name of Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -%macro linux_setup 0 -;; Needed for OSX too. Who does not need this? -;; %ifdef __linux__ -%ifndef __cygwin__ - mov rcx, rdi - mov rdx, rsi -%endif -%endmacro - -%macro inversekey 1 - movdqu xmm1,%1 - aesimc xmm0,xmm1 - movdqu %1,xmm0 -%endmacro - -%macro aesdeclast1 1 - aesdeclast xmm0,%1 -%endmacro - -%macro aesenclast1 1 - aesenclast xmm0,%1 -%endmacro - -%macro aesdec1 1 - aesdec xmm0,%1 -%endmacro - -%macro aesenc1 1 - aesenc xmm0,%1 -%endmacro - - -%macro aesdeclast1_u 1 - movdqu xmm4,%1 - aesdeclast xmm0,xmm4 -%endmacro - -%macro aesenclast1_u 1 - movdqu xmm4,%1 - aesenclast xmm0,xmm4 -%endmacro - -%macro aesdec1_u 1 - movdqu xmm4,%1 - aesdec xmm0,xmm4 -%endmacro - -%macro aesenc1_u 1 - movdqu xmm4,%1 - aesenc xmm0,xmm4 -%endmacro - -%macro aesdec4 1 - movdqa xmm4,%1 - - aesdec xmm0,xmm4 - aesdec xmm1,xmm4 - aesdec xmm2,xmm4 - aesdec xmm3,xmm4 - -%endmacro - -%macro aesdeclast4 1 - movdqa xmm4,%1 - - aesdeclast xmm0,xmm4 - aesdeclast xmm1,xmm4 - aesdeclast xmm2,xmm4 - aesdeclast xmm3,xmm4 - -%endmacro - - -%macro aesenc4 1 - movdqa xmm4,%1 - - aesenc xmm0,xmm4 - aesenc xmm1,xmm4 - aesenc xmm2,xmm4 - aesenc xmm3,xmm4 - -%endmacro - -%macro aesenclast4 1 - movdqa xmm4,%1 - - aesenclast xmm0,xmm4 - aesenclast xmm1,xmm4 - aesenclast xmm2,xmm4 - aesenclast xmm3,xmm4 - -%endmacro - - -%macro load_and_inc4 1 - movdqa xmm4,%1 - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - movdqa xmm1,xmm5 - paddd xmm1,[counter_add_one wrt rip] - pshufb xmm1, xmm6 ; byte swap counter back - movdqa xmm2,xmm5 - paddd xmm2,[counter_add_two wrt rip] - pshufb xmm2, xmm6 ; byte swap counter back - movdqa xmm3,xmm5 - paddd xmm3,[counter_add_three wrt rip] - pshufb xmm3, xmm6 ; byte swap counter back - pxor xmm0,xmm4 - paddd xmm5,[counter_add_four wrt rip] - pxor xmm1,xmm4 - pxor xmm2,xmm4 - pxor xmm3,xmm4 -%endmacro - -%macro xor_with_input4 1 - movdqu xmm4,[%1] - pxor xmm0,xmm4 - movdqu xmm4,[%1+16] - pxor xmm1,xmm4 - movdqu xmm4,[%1+32] - pxor xmm2,xmm4 - movdqu xmm4,[%1+48] - pxor xmm3,xmm4 -%endmacro - - - -%macro load_and_xor4 2 - movdqa xmm4,%2 - movdqu xmm0,[%1 + 0*16] - pxor xmm0,xmm4 - movdqu xmm1,[%1 + 1*16] - pxor xmm1,xmm4 - movdqu xmm2,[%1 + 2*16] - pxor xmm2,xmm4 - movdqu xmm3,[%1 + 3*16] - pxor xmm3,xmm4 -%endmacro - -%macro store4 1 - movdqu [%1 + 0*16],xmm0 - movdqu [%1 + 1*16],xmm1 - movdqu [%1 + 2*16],xmm2 - movdqu [%1 + 3*16],xmm3 -%endmacro - -%macro copy_round_keys 3 - movdqu xmm4,[%2 + ((%3)*16)] - movdqa [%1 + ((%3)*16)],xmm4 -%endmacro - - -%macro key_expansion_1_192 1 - ;; Assumes the xmm3 includes all zeros at this point. - pshufd xmm2, xmm2, 11111111b - shufps xmm3, xmm1, 00010000b - pxor xmm1, xmm3 - shufps xmm3, xmm1, 10001100b - pxor xmm1, xmm3 - pxor xmm1, xmm2 - movdqu [rdx+%1], xmm1 -%endmacro - -; Calculate w10 and w11 using calculated w9 and known w4-w5 -%macro key_expansion_2_192 1 - movdqa xmm5, xmm4 - pslldq xmm5, 4 - shufps xmm6, xmm1, 11110000b - pxor xmm6, xmm5 - pxor xmm4, xmm6 - pshufd xmm7, xmm4, 00001110b - movdqu [rdx+%1], xmm7 -%endmacro - - -section .data -align 16 -shuffle_mask: -DD 0FFFFFFFFh -DD 03020100h -DD 07060504h -DD 0B0A0908h - -byte_swap_16: -DDQ 0x000102030405060708090A0B0C0D0E0F - -align 16 -counter_add_one: -DD 1 -DD 0 -DD 0 -DD 0 - -counter_add_two: -DD 2 -DD 0 -DD 0 -DD 0 - -counter_add_three: -DD 3 -DD 0 -DD 0 -DD 0 - -counter_add_four: -DD 4 -DD 0 -DD 0 -DD 0 - - - -section .text - -align 16 -key_expansion256: - - pshufd xmm2, xmm2, 011111111b - - movdqa xmm4, xmm1 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pxor xmm1, xmm2 - - movdqu [rdx], xmm1 - add rdx, 0x10 - - aeskeygenassist xmm4, xmm1, 0 - pshufd xmm2, xmm4, 010101010b - - movdqa xmm4, xmm3 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pxor xmm3, xmm2 - - movdqu [rdx], xmm3 - add rdx, 0x10 - - ret - - - -align 16 -key_expansion128: - pshufd xmm2, xmm2, 0xFF; - movdqa xmm3, xmm1 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pxor xmm1, xmm2 - - ; storing the result in the key schedule array - movdqu [rdx], xmm1 - add rdx, 0x10 - ret - - - - - - -align 16 -global iEncExpandKey128 -iEncExpandKey128: - - linux_setup - - movdqu xmm1, [rcx] ; loading the key - - movdqu [rdx], xmm1 - - movdqa xmm5, [shuffle_mask wrt rip] - - add rdx,16 - - aeskeygenassist xmm2, xmm1, 0x1 ; Generating round key 1 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x2 ; Generating round key 2 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x4 ; Generating round key 3 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x8 ; Generating round key 4 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x10 ; Generating round key 5 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x20 ; Generating round key 6 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x40 ; Generating round key 7 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x80 ; Generating round key 8 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x1b ; Generating round key 9 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x36 ; Generating round key 10 - call key_expansion128 - - ret - - - -align 16 -global iEncExpandKey192 -iEncExpandKey192: - - linux_setup - sub rsp,64+8 - movdqa [rsp],xmm6 - movdqa [rsp+16],xmm7 - - - movq xmm7, [rcx+16] ; loading the AES key - movq [rdx+16], xmm7 ; Storing key in memory where all key expansion - pshufd xmm4, xmm7, 01001111b - movdqu xmm1, [rcx] ; loading the AES key - movdqu [rdx], xmm1 ; Storing key in memory where all key expansion - - pxor xmm3, xmm3 ; Set xmm3 to be all zeros. Required for the key_expansion. - pxor xmm6, xmm6 ; Set xmm3 to be all zeros. Required for the key_expansion. - - aeskeygenassist xmm2, xmm4, 0x1 ; Complete round key 1 and generate round key 2 - key_expansion_1_192 24 - key_expansion_2_192 40 - - aeskeygenassist xmm2, xmm4, 0x2 ; Generate round key 3 and part of round key 4 - key_expansion_1_192 48 - key_expansion_2_192 64 - - aeskeygenassist xmm2, xmm4, 0x4 ; Complete round key 4 and generate round key 5 - key_expansion_1_192 72 - key_expansion_2_192 88 - - aeskeygenassist xmm2, xmm4, 0x8 ; Generate round key 6 and part of round key 7 - key_expansion_1_192 96 - key_expansion_2_192 112 - - aeskeygenassist xmm2, xmm4, 0x10 ; Complete round key 7 and generate round key 8 - key_expansion_1_192 120 - key_expansion_2_192 136 - - aeskeygenassist xmm2, xmm4, 0x20 ; Generate round key 9 and part of round key 10 - key_expansion_1_192 144 - key_expansion_2_192 160 - - aeskeygenassist xmm2, xmm4, 0x40 ; Complete round key 10 and generate round key 11 - key_expansion_1_192 168 - key_expansion_2_192 184 - - aeskeygenassist xmm2, xmm4, 0x80 ; Generate round key 12 - key_expansion_1_192 192 - - - movdqa xmm6,[rsp] - movdqa xmm7,[rsp+16] - add rsp,64+8 - - ret - - - - -align 16 -global iDecExpandKey128 -iDecExpandKey128: - - linux_setup - push rcx - push rdx - sub rsp,16+8 - - call iEncExpandKey128 - - add rsp,16+8 - pop rdx - pop rcx - - inversekey [rdx + 1*16] - inversekey [rdx + 2*16] - inversekey [rdx + 3*16] - inversekey [rdx + 4*16] - inversekey [rdx + 5*16] - inversekey [rdx + 6*16] - inversekey [rdx + 7*16] - inversekey [rdx + 8*16] - inversekey [rdx + 9*16] - - ret - - -align 16 -global iDecExpandKey192 -iDecExpandKey192: - - linux_setup - push rcx - push rdx - sub rsp,16+8 - - call iEncExpandKey192 - - add rsp,16+8 - pop rdx - pop rcx - - - inversekey [rdx + 1*16] - inversekey [rdx + 2*16] - inversekey [rdx + 3*16] - inversekey [rdx + 4*16] - inversekey [rdx + 5*16] - inversekey [rdx + 6*16] - inversekey [rdx + 7*16] - inversekey [rdx + 8*16] - inversekey [rdx + 9*16] - inversekey [rdx + 10*16] - inversekey [rdx + 11*16] - - ret - - - -align 16 -global iDecExpandKey256 -iDecExpandKey256: - - linux_setup - push rcx - push rdx - sub rsp,16+8 - - call iEncExpandKey256 - - add rsp,16+8 - pop rdx - pop rcx - - inversekey [rdx + 1*16] - inversekey [rdx + 2*16] - inversekey [rdx + 3*16] - inversekey [rdx + 4*16] - inversekey [rdx + 5*16] - inversekey [rdx + 6*16] - inversekey [rdx + 7*16] - inversekey [rdx + 8*16] - inversekey [rdx + 9*16] - inversekey [rdx + 10*16] - inversekey [rdx + 11*16] - inversekey [rdx + 12*16] - inversekey [rdx + 13*16] - - ret - - - - -align 16 -global iEncExpandKey256 -iEncExpandKey256: - - linux_setup - - movdqu xmm1, [rcx] ; loading the key - movdqu xmm3, [rcx+16] - movdqu [rdx], xmm1 ; Storing key in memory where all key schedule will be stored - movdqu [rdx+16], xmm3 - - add rdx,32 - - movdqa xmm5, [shuffle_mask wrt rip] ; this mask is used by key_expansion - - aeskeygenassist xmm2, xmm3, 0x1 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x2 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x4 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x8 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x10 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x20 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x40 ; -; call key_expansion256 - - pshufd xmm2, xmm2, 011111111b - - movdqa xmm4, xmm1 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pxor xmm1, xmm2 - - movdqu [rdx], xmm1 - - - ret - - - - - - -align 16 -global iDec128 -iDec128: - - linux_setup - sub rsp,16*16+8 - - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test eax,eax - jz end_dec128 - - cmp eax,4 - jl lp128decsingle - - test rcx,0xf - jz lp128decfour - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - mov rcx,rsp - - - -align 16 -lp128decfour: - - test eax,eax - jz end_dec128 - - cmp eax,4 - jl lp128decsingle - - load_and_xor4 rdx, [rcx+10*16] - add rdx,16*4 - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - sub eax,4 - store4 r8+rdx-(16*4) - jmp lp128decfour - - - align 16 -lp128decsingle: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+10*16] - pxor xmm0, xmm4 - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - add rdx, 16 - movdqu [r8 + rdx - 16], xmm0 - dec eax - jnz lp128decsingle - -end_dec128: - - add rsp,16*16+8 - ret - - -align 16 -global iDec128_CBC -iDec128_CBC: - - linux_setup - sub rsp,16*16+8 - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - - sub r8,rdx - - - test eax,eax - jz end_dec128_CBC - - cmp eax,4 - jl lp128decsingle_CBC - - test rcx,0xf - jz lp128decfour_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - mov rcx,rsp - - -align 16 -lp128decfour_CBC: - - test eax,eax - jz end_dec128_CBC - - cmp eax,4 - jl lp128decsingle_CBC - - load_and_xor4 rdx, [rcx+10*16] - add rdx,16*4 - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[rdx - 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[rdx - 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[rdx - 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[rdx - 16*4 + 3*16] - - sub eax,4 - store4 r8+rdx-(16*4) - jmp lp128decfour_CBC - - - align 16 -lp128decsingle_CBC: - - movdqu xmm0, [rdx] - movdqa xmm1,xmm0 - movdqu xmm4,[rcx+10*16] - pxor xmm0, xmm4 - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - add rdx, 16 - movdqu [r8 + rdx - 16], xmm0 - dec eax - jnz lp128decsingle_CBC - -end_dec128_CBC: - - mov r9,[r9+24] - movdqu [r9],xmm5 - add rsp,16*16+8 - ret - - -align 16 -global iDec192_CBC -iDec192_CBC: - - linux_setup - sub rsp,16*16+8 - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - - sub r8,rdx - - test eax,eax - jz end_dec192_CBC - - cmp eax,4 - jl lp192decsingle_CBC - - test rcx,0xf - jz lp192decfour_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - mov rcx,rsp - - -align 16 -lp192decfour_CBC: - - test eax,eax - jz end_dec192_CBC - - cmp eax,4 - jl lp192decsingle_CBC - - load_and_xor4 rdx, [rcx+12*16] - add rdx,16*4 - aesdec4 [rcx+11*16] - aesdec4 [rcx+10*16] - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[rdx - 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[rdx - 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[rdx - 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[rdx - 16*4 + 3*16] - - sub eax,4 - store4 r8+rdx-(16*4) - jmp lp192decfour_CBC - - - align 16 -lp192decsingle_CBC: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+12*16] - movdqa xmm1,xmm0 - pxor xmm0, xmm4 - aesdec1_u [rcx+11*16] - aesdec1_u [rcx+10*16] - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - add rdx, 16 - movdqu [r8 + rdx - 16], xmm0 - dec eax - jnz lp192decsingle_CBC - -end_dec192_CBC: - - mov r9,[r9+24] - movdqu [r9],xmm5 - add rsp,16*16+8 - ret - - - - -align 16 -global iDec256_CBC -iDec256_CBC: - - linux_setup - sub rsp,16*16+8 - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - - sub r8,rdx - - test eax,eax - jz end_dec256_CBC - - cmp eax,4 - jl lp256decsingle_CBC - - test rcx,0xf - jz lp256decfour_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - copy_round_keys rsp,rcx,13 - copy_round_keys rsp,rcx,14 - mov rcx,rsp - -align 16 -lp256decfour_CBC: - - test eax,eax - jz end_dec256_CBC - - cmp eax,4 - jl lp256decsingle_CBC - - load_and_xor4 rdx, [rcx+14*16] - add rdx,16*4 - aesdec4 [rcx+13*16] - aesdec4 [rcx+12*16] - aesdec4 [rcx+11*16] - aesdec4 [rcx+10*16] - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[rdx - 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[rdx - 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[rdx - 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[rdx - 16*4 + 3*16] - - sub eax,4 - store4 r8+rdx-(16*4) - jmp lp256decfour_CBC - - - align 16 -lp256decsingle_CBC: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+14*16] - movdqa xmm1,xmm0 - pxor xmm0, xmm4 - aesdec1_u [rcx+13*16] - aesdec1_u [rcx+12*16] - aesdec1_u [rcx+11*16] - aesdec1_u [rcx+10*16] - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - add rdx, 16 - movdqu [r8 + rdx - 16], xmm0 - dec eax - jnz lp256decsingle_CBC - -end_dec256_CBC: - - mov r9,[r9+24] - movdqu [r9],xmm5 - add rsp,16*16+8 - ret - - - - - -align 16 -global iDec192 -iDec192: - - linux_setup - sub rsp,16*16+8 - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test eax,eax - jz end_dec192 - - cmp eax,4 - jl lp192decsingle - - test rcx,0xf - jz lp192decfour - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - mov rcx,rsp - -align 16 -lp192decfour: - - test eax,eax - jz end_dec192 - - cmp eax,4 - jl lp192decsingle - - load_and_xor4 rdx, [rcx+12*16] - add rdx,16*4 - aesdec4 [rcx+11*16] - aesdec4 [rcx+10*16] - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - sub eax,4 - store4 r8+rdx-(16*4) - jmp lp192decfour - - - align 16 -lp192decsingle: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+12*16] - pxor xmm0, xmm4 - aesdec1_u [rcx+11*16] - aesdec1_u [rcx+10*16] - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - add rdx, 16 - movdqu [r8 + rdx - 16], xmm0 - dec eax - jnz lp192decsingle - -end_dec192: - - add rsp,16*16+8 - ret - - - - -align 16 -global iDec256 -iDec256: - - linux_setup - sub rsp,16*16+8 - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test eax,eax - jz end_dec256 - - cmp eax,4 - jl lp256dec - - test rcx,0xf - jz lp256dec4 - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - copy_round_keys rsp,rcx,13 - copy_round_keys rsp,rcx,14 - mov rcx,rsp - - - align 16 -lp256dec4: - test eax,eax - jz end_dec256 - - cmp eax,4 - jl lp256dec - - load_and_xor4 rdx,[rcx+14*16] - add rdx, 4*16 - aesdec4 [rcx+13*16] - aesdec4 [rcx+12*16] - aesdec4 [rcx+11*16] - aesdec4 [rcx+10*16] - aesdec4 [rcx+9*16] - aesdec4 [rcx+8*16] - aesdec4 [rcx+7*16] - aesdec4 [rcx+6*16] - aesdec4 [rcx+5*16] - aesdec4 [rcx+4*16] - aesdec4 [rcx+3*16] - aesdec4 [rcx+2*16] - aesdec4 [rcx+1*16] - aesdeclast4 [rcx+0*16] - - store4 r8+rdx-16*4 - sub eax,4 - jmp lp256dec4 - - align 16 -lp256dec: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+14*16] - add rdx, 16 - pxor xmm0, xmm4 ; Round 0 (only xor) - aesdec1_u [rcx+13*16] - aesdec1_u [rcx+12*16] - aesdec1_u [rcx+11*16] - aesdec1_u [rcx+10*16] - aesdec1_u [rcx+9*16] - aesdec1_u [rcx+8*16] - aesdec1_u [rcx+7*16] - aesdec1_u [rcx+6*16] - aesdec1_u [rcx+5*16] - aesdec1_u [rcx+4*16] - aesdec1_u [rcx+3*16] - aesdec1_u [rcx+2*16] - aesdec1_u [rcx+1*16] - aesdeclast1_u [rcx+0*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp256dec - -end_dec256: - - add rsp,16*16+8 - ret - - - - - - -align 16 -global iEnc128 -iEnc128: - - linux_setup - sub rsp,16*16+8 - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test eax,eax - jz end_enc128 - - cmp eax,4 - jl lp128encsingle - - test rcx,0xf - jz lpenc128four - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - mov rcx,rsp - - - align 16 - -lpenc128four: - - test eax,eax - jz end_enc128 - - cmp eax,4 - jl lp128encsingle - - load_and_xor4 rdx,[rcx+0*16] - add rdx,4*16 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenclast4 [rcx+10*16] - - store4 r8+rdx-16*4 - sub eax,4 - jmp lpenc128four - - align 16 -lp128encsingle: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+0*16] - add rdx, 16 - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenclast1_u [rcx+10*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp128encsingle - -end_enc128: - - add rsp,16*16+8 - ret - - -align 16 -global iEnc128_CTR -iEnc128_CTR: - - linux_setup - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - - sub rsp,16*16+8+16 - - movdqa [rsp+16*16], xmm6 - movdqa xmm6, [byte_swap_16 wrt rip] - pshufb xmm5, xmm6 ; byte swap counter - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test eax,eax - jz end_encctr128 - - cmp eax,4 - jl lp128encctrsingle - - test rcx,0xf - jz lpencctr128four - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - mov rcx,rsp - - - align 16 - -lpencctr128four: - - test eax,eax - jz end_encctr128 - - cmp eax,4 - jl lp128encctrsingle - - load_and_inc4 [rcx+0*16] - add rdx,4*16 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenclast4 [rcx+10*16] - xor_with_input4 rdx-(4*16) - - store4 r8+rdx-16*4 - sub eax,4 - jmp lpencctr128four - - align 16 -lp128encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - paddd xmm5,[counter_add_one wrt rip] - add rdx, 16 - movdqu xmm4,[rcx+0*16] - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenclast1_u [rcx+10*16] - movdqu xmm4, [rdx-16] - pxor xmm0,xmm4 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp128encctrsingle - -end_encctr128: - - mov r9,[r9+24] - - pshufb xmm5, xmm6 ; byte swap counter - movdqu [r9],xmm5 - movdqa xmm6, [rsp+16*16] - add rsp,16*16+8+16 - ret - - - -align 16 -global iEnc192_CTR -iEnc192_CTR: - - linux_setup - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - - sub rsp,16*16+8+16 - - movdqa [rsp+16*16], xmm6 - movdqa xmm6, [byte_swap_16 wrt rip] - pshufb xmm5, xmm6 ; byte swap counter - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test eax,eax - jz end_encctr192 - - cmp eax,4 - jl lp192encctrsingle - - test rcx,0xf - jz lpencctr192four - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - mov rcx,rsp - - - align 16 - -lpencctr192four: - - test eax,eax - jz end_encctr192 - - cmp eax,4 - jl lp192encctrsingle - - load_and_inc4 [rcx+0*16] - add rdx,4*16 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenc4 [rcx+10*16] - aesenc4 [rcx+11*16] - aesenclast4 [rcx+12*16] - xor_with_input4 rdx-(4*16) - - store4 r8+rdx-16*4 - sub eax,4 - jmp lpencctr192four - - align 16 -lp192encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - movdqu xmm4,[rcx+0*16] - paddd xmm5,[counter_add_one wrt rip] - add rdx, 16 - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenc1_u [rcx+10*16] - aesenc1_u [rcx+11*16] - aesenclast1_u [rcx+12*16] - movdqu xmm4, [rdx-16] - pxor xmm0,xmm4 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp192encctrsingle - -end_encctr192: - - mov r9,[r9+24] - pshufb xmm5, xmm6 ; byte swap counter - movdqu [r9],xmm5 - movdqa xmm6, [rsp+16*16] - add rsp,16*16+8+16 - ret - - -align 16 -global iEnc256_CTR -iEnc256_CTR: - - linux_setup - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm5,[rax] - - - sub rsp,16*16+8+16 - - movdqa [rsp+16*16], xmm6 - movdqa xmm6, [byte_swap_16 wrt rip] - pshufb xmm5, xmm6 ; byte swap counter - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test eax,eax - jz end_encctr256 - - cmp eax,4 - jl lp256encctrsingle - - test rcx,0xf - jz lpencctr256four - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - copy_round_keys rsp,rcx,13 - copy_round_keys rsp,rcx,14 - mov rcx,rsp - - - align 16 - -lpencctr256four: - - test eax,eax - jz end_encctr256 - - cmp eax,4 - jl lp256encctrsingle - - load_and_inc4 [rcx+0*16] - add rdx,4*16 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenc4 [rcx+10*16] - aesenc4 [rcx+11*16] - aesenc4 [rcx+12*16] - aesenc4 [rcx+13*16] - aesenclast4 [rcx+14*16] - xor_with_input4 rdx-(4*16) - - store4 r8+rdx-16*4 - sub eax,4 - jmp lpencctr256four - - align 16 -lp256encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - movdqu xmm4,[rcx+0*16] - paddd xmm5,[counter_add_one wrt rip] - add rdx, 16 - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenc1_u [rcx+10*16] - aesenc1_u [rcx+11*16] - aesenc1_u [rcx+12*16] - aesenc1_u [rcx+13*16] - aesenclast1_u [rcx+14*16] - movdqu xmm4, [rdx-16] - pxor xmm0,xmm4 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp256encctrsingle - -end_encctr256: - - mov r9,[r9+24] - pshufb xmm5, xmm6 ; byte swap counter - movdqu [r9],xmm5 - movdqa xmm6, [rsp+16*16] - add rsp,16*16+8+16 - ret - - - - - - - -align 16 -global iEnc128_CBC -iEnc128_CBC: - - linux_setup - sub rsp,16*16+8 - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm1,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test rcx,0xf - jz lp128encsingle_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - mov rcx,rsp - - - align 16 - -lp128encsingle_CBC: - - movdqu xmm0, [rdx] - movdqu xmm4,[rcx+0*16] - add rdx, 16 - pxor xmm0, xmm1 - pxor xmm0, xmm4 - aesenc1 [rcx+1*16] - aesenc1 [rcx+2*16] - aesenc1 [rcx+3*16] - aesenc1 [rcx+4*16] - aesenc1 [rcx+5*16] - aesenc1 [rcx+6*16] - aesenc1 [rcx+7*16] - aesenc1 [rcx+8*16] - aesenc1 [rcx+9*16] - aesenclast1 [rcx+10*16] - movdqa xmm1,xmm0 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp128encsingle_CBC - - mov r9,[r9+24] - movdqu [r9],xmm1 - add rsp,16*16+8 - ret - - -align 16 -global iEnc192_CBC -iEnc192_CBC: - - linux_setup - sub rsp,16*16+8 - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm1,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test rcx,0xf - jz lp192encsingle_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - mov rcx,rsp - - - - align 16 - -lp192encsingle_CBC: - - movdqu xmm0, [rdx] - movdqu xmm4, [rcx+0*16] - add rdx, 16 - pxor xmm0, xmm1 - pxor xmm0, xmm4 - aesenc1 [rcx+1*16] - aesenc1 [rcx+2*16] - aesenc1 [rcx+3*16] - aesenc1 [rcx+4*16] - aesenc1 [rcx+5*16] - aesenc1 [rcx+6*16] - aesenc1 [rcx+7*16] - aesenc1 [rcx+8*16] - aesenc1 [rcx+9*16] - aesenc1 [rcx+10*16] - aesenc1 [rcx+11*16] - aesenclast1 [rcx+12*16] - movdqa xmm1,xmm0 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp192encsingle_CBC - - mov r9,[r9+24] - movdqu [r9],xmm1 - - add rsp,16*16+8 - ret - - -align 16 -global iEnc256_CBC -iEnc256_CBC: - - linux_setup - sub rsp,16*16+8 - - mov r9,rcx - mov rax,[rcx+24] - movdqu xmm1,[rax] - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test rcx,0xf - jz lp256encsingle_CBC - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - copy_round_keys rsp,rcx,13 - copy_round_keys rsp,rcx,14 - mov rcx,rsp - - align 16 - -lp256encsingle_CBC: - - movdqu xmm0, [rdx] - movdqu xmm4, [rcx+0*16] - add rdx, 16 - pxor xmm0, xmm1 - pxor xmm0, xmm4 - aesenc1 [rcx+1*16] - aesenc1 [rcx+2*16] - aesenc1 [rcx+3*16] - aesenc1 [rcx+4*16] - aesenc1 [rcx+5*16] - aesenc1 [rcx+6*16] - aesenc1 [rcx+7*16] - aesenc1 [rcx+8*16] - aesenc1 [rcx+9*16] - aesenc1 [rcx+10*16] - aesenc1 [rcx+11*16] - aesenc1 [rcx+12*16] - aesenc1 [rcx+13*16] - aesenclast1 [rcx+14*16] - movdqa xmm1,xmm0 - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp256encsingle_CBC - - mov r9,[r9+24] - movdqu [r9],xmm1 - add rsp,16*16+8 - ret - - - - -align 16 -global iEnc192 -iEnc192: - - linux_setup - sub rsp,16*16+8 - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - test eax,eax - jz end_enc192 - - cmp eax,4 - jl lp192encsingle - - test rcx,0xf - jz lpenc192four - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - mov rcx,rsp - - - align 16 - -lpenc192four: - - test eax,eax - jz end_enc192 - - cmp eax,4 - jl lp192encsingle - - load_and_xor4 rdx,[rcx+0*16] - add rdx,4*16 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenc4 [rcx+10*16] - aesenc4 [rcx+11*16] - aesenclast4 [rcx+12*16] - - store4 r8+rdx-16*4 - sub eax,4 - jmp lpenc192four - - align 16 -lp192encsingle: - - movdqu xmm0, [rdx] - movdqu xmm4, [rcx+0*16] - add rdx, 16 - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenc1_u [rcx+10*16] - aesenc1_u [rcx+11*16] - aesenclast1_u [rcx+12*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp192encsingle - -end_enc192: - - add rsp,16*16+8 - ret - - - - - - -align 16 -global iEnc256 -iEnc256: - - linux_setup - sub rsp,16*16+8 - - mov eax,[rcx+32] ; numblocks - mov rdx,[rcx] - mov r8,[rcx+8] - mov rcx,[rcx+16] - - sub r8,rdx - - - test eax,eax - jz end_enc256 - - cmp eax,4 - jl lp256enc - - test rcx,0xf - jz lp256enc4 - - copy_round_keys rsp,rcx,0 - copy_round_keys rsp,rcx,1 - copy_round_keys rsp,rcx,2 - copy_round_keys rsp,rcx,3 - copy_round_keys rsp,rcx,4 - copy_round_keys rsp,rcx,5 - copy_round_keys rsp,rcx,6 - copy_round_keys rsp,rcx,7 - copy_round_keys rsp,rcx,8 - copy_round_keys rsp,rcx,9 - copy_round_keys rsp,rcx,10 - copy_round_keys rsp,rcx,11 - copy_round_keys rsp,rcx,12 - copy_round_keys rsp,rcx,13 - copy_round_keys rsp,rcx,14 - mov rcx,rsp - - - align 16 - -lp256enc4: - test eax,eax - jz end_enc256 - - cmp eax,4 - jl lp256enc - - - load_and_xor4 rdx,[rcx+0*16] - add rdx, 16*4 - aesenc4 [rcx+1*16] - aesenc4 [rcx+2*16] - aesenc4 [rcx+3*16] - aesenc4 [rcx+4*16] - aesenc4 [rcx+5*16] - aesenc4 [rcx+6*16] - aesenc4 [rcx+7*16] - aesenc4 [rcx+8*16] - aesenc4 [rcx+9*16] - aesenc4 [rcx+10*16] - aesenc4 [rcx+11*16] - aesenc4 [rcx+12*16] - aesenc4 [rcx+13*16] - aesenclast4 [rcx+14*16] - - store4 r8+rdx-16*4 - sub eax,4 - jmp lp256enc4 - - align 16 -lp256enc: - - movdqu xmm0, [rdx] - movdqu xmm4, [rcx+0*16] - add rdx, 16 - pxor xmm0, xmm4 - aesenc1_u [rcx+1*16] - aesenc1_u [rcx+2*16] - aesenc1_u [rcx+3*16] - aesenc1_u [rcx+4*16] - aesenc1_u [rcx+5*16] - aesenc1_u [rcx+6*16] - aesenc1_u [rcx+7*16] - aesenc1_u [rcx+8*16] - aesenc1_u [rcx+9*16] - aesenc1_u [rcx+10*16] - aesenc1_u [rcx+11*16] - aesenc1_u [rcx+12*16] - aesenc1_u [rcx+13*16] - aesenclast1_u [rcx+14*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [r8+rdx-16], xmm0 - dec eax - jnz lp256enc - -end_enc256: - - add rsp,16*16+8 - ret diff --git a/src/aes/aesni/asm/x86/do_rdtsc.s b/src/aes/aesni/asm/x86/do_rdtsc.s deleted file mode 100644 index 9d6652f7af5..00000000000 --- a/src/aes/aesni/asm/x86/do_rdtsc.s +++ /dev/null @@ -1,42 +0,0 @@ -[bits 32] -[CPU intelnop] - -%ifidn __OUTPUT_FORMAT__,elf -section .note.GNU-stack noalloc noexec nowrite progbits -%endif -%ifidn __OUTPUT_FORMAT__,elf32 -section .note.GNU-stack noalloc noexec nowrite progbits -%endif - -; Copyright (c) 2010, Intel Corporation -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions are met: -; -; * Redistributions of source code must retain the above copyright notice, -; this list of conditions and the following disclaimer. -; * Redistributions in binary form must reproduce the above copyright notice, -; this list of conditions and the following disclaimer in the documentation -; and/or other materials provided with the distribution. -; * Neither the name of Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -align 16 -global _do_rdtsc -_do_rdtsc: - - rdtsc - ret diff --git a/src/aes/aesni/asm/x86/iaesx86.s b/src/aes/aesni/asm/x86/iaesx86.s deleted file mode 100644 index 2255ab56f08..00000000000 --- a/src/aes/aesni/asm/x86/iaesx86.s +++ /dev/null @@ -1,2206 +0,0 @@ -[bits 32] -[CPU intelnop] - -%ifidn __OUTPUT_FORMAT__,elf -section .note.GNU-stack noalloc noexec nowrite progbits -%endif -%ifidn __OUTPUT_FORMAT__,elf32 -section .note.GNU-stack noalloc noexec nowrite progbits -%endif - -; Copyright (c) 2010, Intel Corporation -; All rights reserved. -; -; Redistribution and use in source and binary forms, with or without -; modification, are permitted provided that the following conditions are met: -; -; * Redistributions of source code must retain the above copyright notice, -; this list of conditions and the following disclaimer. -; * Redistributions in binary form must reproduce the above copyright notice, -; this list of conditions and the following disclaimer in the documentation -; and/or other materials provided with the distribution. -; * Neither the name of Intel Corporation nor the names of its contributors -; may be used to endorse or promote products derived from this software -; without specific prior written permission. -; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -; IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -%macro inversekey 1 - movdqu xmm1,%1 - aesimc xmm0,xmm1 - movdqu %1,xmm0 -%endmacro - - -%macro aesdec4 1 - movdqa xmm4,%1 - - aesdec xmm0,xmm4 - aesdec xmm1,xmm4 - aesdec xmm2,xmm4 - aesdec xmm3,xmm4 - -%endmacro - - -%macro aesdeclast4 1 - movdqa xmm4,%1 - - aesdeclast xmm0,xmm4 - aesdeclast xmm1,xmm4 - aesdeclast xmm2,xmm4 - aesdeclast xmm3,xmm4 - -%endmacro - - -%macro aesenc4 1 - movdqa xmm4,%1 - - aesenc xmm0,xmm4 - aesenc xmm1,xmm4 - aesenc xmm2,xmm4 - aesenc xmm3,xmm4 - -%endmacro - -%macro aesenclast4 1 - movdqa xmm4,%1 - - aesenclast xmm0,xmm4 - aesenclast xmm1,xmm4 - aesenclast xmm2,xmm4 - aesenclast xmm3,xmm4 - -%endmacro - - -%macro aesdeclast1 1 - aesdeclast xmm0,%1 -%endmacro - -%macro aesenclast1 1 - aesenclast xmm0,%1 -%endmacro - -%macro aesdec1 1 - aesdec xmm0,%1 -%endmacro - -;abab -%macro aesenc1 1 - aesenc xmm0,%1 -%endmacro - - -%macro aesdeclast1_u 1 - movdqu xmm4,%1 - aesdeclast xmm0,xmm4 -%endmacro - -%macro aesenclast1_u 1 - movdqu xmm4,%1 - aesenclast xmm0,xmm4 -%endmacro - -%macro aesdec1_u 1 - movdqu xmm4,%1 - aesdec xmm0,xmm4 -%endmacro - -%macro aesenc1_u 1 - movdqu xmm4,%1 - aesenc xmm0,xmm4 -%endmacro - - -%macro load_and_xor4 2 - movdqa xmm4,%2 - movdqu xmm0,[%1 + 0*16] - pxor xmm0,xmm4 - movdqu xmm1,[%1 + 1*16] - pxor xmm1,xmm4 - movdqu xmm2,[%1 + 2*16] - pxor xmm2,xmm4 - movdqu xmm3,[%1 + 3*16] - pxor xmm3,xmm4 -%endmacro - - -%macro load_and_inc4 1 - movdqa xmm4,%1 - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - movdqa xmm1,xmm5 - paddd xmm1,[counter_add_one] - pshufb xmm1, xmm6 ; byte swap counter back - movdqa xmm2,xmm5 - paddd xmm2,[counter_add_two] - pshufb xmm2, xmm6 ; byte swap counter back - movdqa xmm3,xmm5 - paddd xmm3,[counter_add_three] - pshufb xmm3, xmm6 ; byte swap counter back - pxor xmm0,xmm4 - paddd xmm5,[counter_add_four] - pxor xmm1,xmm4 - pxor xmm2,xmm4 - pxor xmm3,xmm4 -%endmacro - -%macro xor_with_input4 1 - movdqu xmm4,[%1] - pxor xmm0,xmm4 - movdqu xmm4,[%1+16] - pxor xmm1,xmm4 - movdqu xmm4,[%1+32] - pxor xmm2,xmm4 - movdqu xmm4,[%1+48] - pxor xmm3,xmm4 -%endmacro - -%macro store4 1 - movdqu [%1 + 0*16],xmm0 - movdqu [%1 + 1*16],xmm1 - movdqu [%1 + 2*16],xmm2 - movdqu [%1 + 3*16],xmm3 -%endmacro - - -%macro copy_round_keys 3 - movdqu xmm4,[%2 + ((%3)*16)] - movdqa [%1 + ((%3)*16)],xmm4 -%endmacro - -;abab -%macro copy_round_keyx 3 - movdqu xmm4,[%2 + ((%3)*16)] - movdqa %1,xmm4 -%endmacro - - - -%macro key_expansion_1_192 1 - ;; Assumes the xmm3 includes all zeros at this point. - pshufd xmm2, xmm2, 11111111b - shufps xmm3, xmm1, 00010000b - pxor xmm1, xmm3 - shufps xmm3, xmm1, 10001100b - pxor xmm1, xmm3 - pxor xmm1, xmm2 - movdqu [edx+%1], xmm1 -%endmacro - -; Calculate w10 and w11 using calculated w9 and known w4-w5 -%macro key_expansion_2_192 1 - movdqa xmm5, xmm4 - pslldq xmm5, 4 - shufps xmm6, xmm1, 11110000b - pxor xmm6, xmm5 - pxor xmm4, xmm6 - pshufd xmm7, xmm4, 00001110b - movdqu [edx+%1], xmm7 -%endmacro - - - - - -section .data -align 16 -shuffle_mask: -DD 0FFFFFFFFh -DD 03020100h -DD 07060504h -DD 0B0A0908h - -byte_swap_16: -DDQ 0x000102030405060708090A0B0C0D0E0F - -align 16 -counter_add_one: -DD 1 -DD 0 -DD 0 -DD 0 - -counter_add_two: -DD 2 -DD 0 -DD 0 -DD 0 - -counter_add_three: -DD 3 -DD 0 -DD 0 -DD 0 - -counter_add_four: -DD 4 -DD 0 -DD 0 -DD 0 - - -section .text - - - -align 16 -key_expansion256: - - pshufd xmm2, xmm2, 011111111b - - movdqu xmm4, xmm1 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pxor xmm1, xmm2 - - movdqu [edx], xmm1 - add edx, 0x10 - - aeskeygenassist xmm4, xmm1, 0 - pshufd xmm2, xmm4, 010101010b - - movdqu xmm4, xmm3 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pshufb xmm4, xmm5 - pxor xmm3, xmm4 - pxor xmm3, xmm2 - - movdqu [edx], xmm3 - add edx, 0x10 - - ret - - - -align 16 -key_expansion128: - pshufd xmm2, xmm2, 0xFF; - movdqu xmm3, xmm1 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pshufb xmm3, xmm5 - pxor xmm1, xmm3 - pxor xmm1, xmm2 - - ; storing the result in the key schedule array - movdqu [edx], xmm1 - add edx, 0x10 - ret - - - -align 16 -global _iEncExpandKey128 -_iEncExpandKey128: - - mov ecx,[esp-4+8] ;input - mov edx,[esp-4+12] ;ctx - - movdqu xmm1, [ecx] ; loading the key - - movdqu [edx], xmm1 - - movdqa xmm5, [shuffle_mask] - - add edx,16 - - aeskeygenassist xmm2, xmm1, 0x1 ; Generating round key 1 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x2 ; Generating round key 2 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x4 ; Generating round key 3 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x8 ; Generating round key 4 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x10 ; Generating round key 5 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x20 ; Generating round key 6 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x40 ; Generating round key 7 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x80 ; Generating round key 8 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x1b ; Generating round key 9 - call key_expansion128 - aeskeygenassist xmm2, xmm1, 0x36 ; Generating round key 10 - call key_expansion128 - - ret - - -align 16 -global _iEncExpandKey192 -_iEncExpandKey192: - - mov ecx,[esp-4+8] ;input - mov edx,[esp-4+12] ;ctx - - movq xmm7, [ecx+16] ; loading the AES key - movq [edx+16], xmm7 ; Storing key in memory where all key expansion - pshufd xmm4, xmm7, 01001111b - movdqu xmm1, [ecx] ; loading the AES key - movdqu [edx], xmm1 ; Storing key in memory where all key expansion - - pxor xmm3, xmm3 ; Set xmm3 to be all zeros. Required for the key_expansion. - pxor xmm6, xmm6 ; Set xmm3 to be all zeros. Required for the key_expansion. - - aeskeygenassist xmm2, xmm4, 0x1 ; Complete round key 1 and generate round key 2 - key_expansion_1_192 24 - key_expansion_2_192 40 - - aeskeygenassist xmm2, xmm4, 0x2 ; Generate round key 3 and part of round key 4 - key_expansion_1_192 48 - key_expansion_2_192 64 - - aeskeygenassist xmm2, xmm4, 0x4 ; Complete round key 4 and generate round key 5 - key_expansion_1_192 72 - key_expansion_2_192 88 - - aeskeygenassist xmm2, xmm4, 0x8 ; Generate round key 6 and part of round key 7 - key_expansion_1_192 96 - key_expansion_2_192 112 - - aeskeygenassist xmm2, xmm4, 0x10 ; Complete round key 7 and generate round key 8 - key_expansion_1_192 120 - key_expansion_2_192 136 - - aeskeygenassist xmm2, xmm4, 0x20 ; Generate round key 9 and part of round key 10 - key_expansion_1_192 144 - key_expansion_2_192 160 - - aeskeygenassist xmm2, xmm4, 0x40 ; Complete round key 10 and generate round key 11 - key_expansion_1_192 168 - key_expansion_2_192 184 - - aeskeygenassist xmm2, xmm4, 0x80 ; Generate round key 12 - key_expansion_1_192 192 - - ret - - - - - - -align 16 -global _iDecExpandKey128 -_iDecExpandKey128: - push DWORD [esp+8] - push DWORD [esp+8] - - call _iEncExpandKey128 - add esp,8 - - mov edx,[esp-4+12] ;ctx - - inversekey [edx + 1*16] - inversekey [edx + 2*16] - inversekey [edx + 3*16] - inversekey [edx + 4*16] - inversekey [edx + 5*16] - inversekey [edx + 6*16] - inversekey [edx + 7*16] - inversekey [edx + 8*16] - inversekey [edx + 9*16] - - ret - - - - -align 16 -global _iDecExpandKey192 -_iDecExpandKey192: - push DWORD [esp+8] - push DWORD [esp+8] - - call _iEncExpandKey192 - add esp,8 - - mov edx,[esp-4+12] ;ctx - - inversekey [edx + 1*16] - inversekey [edx + 2*16] - inversekey [edx + 3*16] - inversekey [edx + 4*16] - inversekey [edx + 5*16] - inversekey [edx + 6*16] - inversekey [edx + 7*16] - inversekey [edx + 8*16] - inversekey [edx + 9*16] - inversekey [edx + 10*16] - inversekey [edx + 11*16] - - ret - - - - -align 16 -global _iDecExpandKey256 -_iDecExpandKey256: - push DWORD [esp+8] - push DWORD [esp+8] - - call _iEncExpandKey256 - add esp, 8 - - mov edx, [esp-4+12] ;expanded key - - inversekey [edx + 1*16] - inversekey [edx + 2*16] - inversekey [edx + 3*16] - inversekey [edx + 4*16] - inversekey [edx + 5*16] - inversekey [edx + 6*16] - inversekey [edx + 7*16] - inversekey [edx + 8*16] - inversekey [edx + 9*16] - inversekey [edx + 10*16] - inversekey [edx + 11*16] - inversekey [edx + 12*16] - inversekey [edx + 13*16] - - ret - - - - -align 16 -global _iEncExpandKey256 -_iEncExpandKey256: - mov ecx, [esp-4+8] ;input - mov edx, [esp-4+12] ;expanded key - - - movdqu xmm1, [ecx] ; loading the key - movdqu xmm3, [ecx+16] - movdqu [edx], xmm1 ; Storing key in memory where all key schedule will be stored - movdqu [edx+16], xmm3 - - add edx,32 - - movdqa xmm5, [shuffle_mask] ; this mask is used by key_expansion - - aeskeygenassist xmm2, xmm3, 0x1 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x2 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x4 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x8 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x10 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x20 ; - call key_expansion256 - aeskeygenassist xmm2, xmm3, 0x40 ; -; call key_expansion256 - - pshufd xmm2, xmm2, 011111111b - - movdqu xmm4, xmm1 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pshufb xmm4, xmm5 - pxor xmm1, xmm4 - pxor xmm1, xmm2 - - movdqu [edx], xmm1 - - - ret - - - - - - -align 16 -global _iDec128 -_iDec128: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_dec128 - - cmp eax,4 - jl lp128decsingle - - test ecx,0xf - jz lp128decfour - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - mov ecx,esp - - -align 16 -lp128decfour: - - test eax,eax - jz end_dec128 - - cmp eax,4 - jl lp128decsingle - - load_and_xor4 esi, [ecx+10*16] - add esi,16*4 - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - sub eax,4 - store4 esi+edi-(16*4) - jmp lp128decfour - - - align 16 -lp128decsingle: - - movdqu xmm0, [esi] - movdqu xmm4,[ecx+10*16] - pxor xmm0, xmm4 - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - add esi, 16 - movdqu [edi+esi - 16], xmm0 - dec eax - jnz lp128decsingle - -end_dec128: - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret - - - -align 16 -global _iDec128_CBC -_iDec128_CBC: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_dec128_CBC - - cmp eax,4 - jl lp128decsingle_CBC - - test ecx,0xf - jz lp128decfour_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - mov ecx,esp - - -align 16 -lp128decfour_CBC: - - test eax,eax - jz end_dec128_CBC - - cmp eax,4 - jl lp128decsingle_CBC - - load_and_xor4 esi, [ecx+10*16] - add esi,16*4 - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[esi- 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[esi- 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[esi- 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[esi- 16*4 + 3*16] - - sub eax,4 - store4 esi+edi-(16*4) - jmp lp128decfour_CBC - - - align 16 -lp128decsingle_CBC: - - movdqu xmm0, [esi] - movdqa xmm1,xmm0 - movdqu xmm4,[ecx+10*16] - pxor xmm0, xmm4 - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - - add esi, 16 - movdqu [edi+esi - 16], xmm0 - dec eax - jnz lp128decsingle_CBC - -end_dec128_CBC: - - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last iv for chaining - - ret - - - - - - -align 16 -global _iDec192 -_iDec192: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_dec192 - - cmp eax,4 - jl lp192decsingle - - test ecx,0xf - jz lp192decfour - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - mov ecx,esp - - -align 16 -lp192decfour: - - test eax,eax - jz end_dec192 - - cmp eax,4 - jl lp192decsingle - - load_and_xor4 esi, [ecx+12*16] - add esi,16*4 - aesdec4 [ecx+11*16] - aesdec4 [ecx+10*16] - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - sub eax,4 - store4 esi+edi-(16*4) - jmp lp192decfour - - - align 16 -lp192decsingle: - - movdqu xmm0, [esi] - movdqu xmm4,[ecx+12*16] - pxor xmm0, xmm4 - aesdec1_u [ecx+11*16] - aesdec1_u [ecx+10*16] - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - add esi, 16 - movdqu [edi+esi - 16], xmm0 - dec eax - jnz lp192decsingle - -end_dec192: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret - - -align 16 -global _iDec192_CBC -_iDec192_CBC: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_dec192_CBC - - cmp eax,4 - jl lp192decsingle_CBC - - test ecx,0xf - jz lp192decfour_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - mov ecx,esp - -align 16 -lp192decfour_CBC: - - test eax,eax - jz end_dec192_CBC - - cmp eax,4 - jl lp192decsingle_CBC - - load_and_xor4 esi, [ecx+12*16] - add esi,16*4 - aesdec4 [ecx+11*16] - aesdec4 [ecx+10*16] - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[esi- 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[esi- 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[esi- 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[esi- 16*4 + 3*16] - - sub eax,4 - store4 esi+edi-(16*4) - jmp lp192decfour_CBC - - - align 16 -lp192decsingle_CBC: - - movdqu xmm0, [esi] - movdqu xmm4,[ecx+12*16] - movdqa xmm1,xmm0 - pxor xmm0, xmm4 - aesdec1_u [ecx+11*16] - aesdec1_u [ecx+10*16] - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - - add esi, 16 - movdqu [edi+esi - 16], xmm0 - dec eax - jnz lp192decsingle_CBC - -end_dec192_CBC: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last iv for chaining - - ret - - - - - -align 16 -global _iDec256 -_iDec256: - mov ecx, [esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - - test eax,eax - jz end_dec256 - - cmp eax,4 - jl lp256dec - - test ecx,0xf - jz lp256dec4 - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - copy_round_keys esp,ecx,13 - copy_round_keys esp,ecx,14 - mov ecx,esp - - align 16 -lp256dec4: - test eax,eax - jz end_dec256 - - cmp eax,4 - jl lp256dec - - load_and_xor4 esi,[ecx+14*16] - add esi, 4*16 - aesdec4 [ecx+13*16] - aesdec4 [ecx+12*16] - aesdec4 [ecx+11*16] - aesdec4 [ecx+10*16] - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - store4 esi+edi-16*4 - sub eax,4 - jmp lp256dec4 - - align 16 -lp256dec: - - movdqu xmm0, [esi] - movdqu xmm4,[ecx+14*16] - add esi, 16 - pxor xmm0, xmm4 ; Round 0 (only xor) - aesdec1_u [ecx+13*16] - aesdec1_u [ecx+12*16] - aesdec1_u [ecx+11*16] - aesdec1_u [ecx+10*16] - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp256dec - -end_dec256: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret - - - - -align 16 -global _iDec256_CBC -_iDec256_CBC: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_dec256_CBC - - cmp eax,4 - jl lp256decsingle_CBC - - test ecx,0xf - jz lp256decfour_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - copy_round_keys esp,ecx,13 - copy_round_keys esp,ecx,14 - mov ecx,esp - -align 16 -lp256decfour_CBC: - - test eax,eax - jz end_dec256_CBC - - cmp eax,4 - jl lp256decsingle_CBC - - load_and_xor4 esi, [ecx+14*16] - add esi,16*4 - aesdec4 [ecx+13*16] - aesdec4 [ecx+12*16] - aesdec4 [ecx+11*16] - aesdec4 [ecx+10*16] - aesdec4 [ecx+9*16] - aesdec4 [ecx+8*16] - aesdec4 [ecx+7*16] - aesdec4 [ecx+6*16] - aesdec4 [ecx+5*16] - aesdec4 [ecx+4*16] - aesdec4 [ecx+3*16] - aesdec4 [ecx+2*16] - aesdec4 [ecx+1*16] - aesdeclast4 [ecx+0*16] - - pxor xmm0,xmm5 - movdqu xmm4,[esi- 16*4 + 0*16] - pxor xmm1,xmm4 - movdqu xmm4,[esi- 16*4 + 1*16] - pxor xmm2,xmm4 - movdqu xmm4,[esi- 16*4 + 2*16] - pxor xmm3,xmm4 - movdqu xmm5,[esi- 16*4 + 3*16] - - sub eax,4 - store4 esi+edi-(16*4) - jmp lp256decfour_CBC - - - align 16 -lp256decsingle_CBC: - - movdqu xmm0, [esi] - movdqa xmm1,xmm0 - movdqu xmm4, [ecx+14*16] - pxor xmm0, xmm4 - aesdec1_u [ecx+13*16] - aesdec1_u [ecx+12*16] - aesdec1_u [ecx+11*16] - aesdec1_u [ecx+10*16] - aesdec1_u [ecx+9*16] - aesdec1_u [ecx+8*16] - aesdec1_u [ecx+7*16] - aesdec1_u [ecx+6*16] - aesdec1_u [ecx+5*16] - aesdec1_u [ecx+4*16] - aesdec1_u [ecx+3*16] - aesdec1_u [ecx+2*16] - aesdec1_u [ecx+1*16] - aesdeclast1_u [ecx+0*16] - - pxor xmm0,xmm5 - movdqa xmm5,xmm1 - - add esi, 16 - movdqu [edi+esi - 16], xmm0 - dec eax - jnz lp256decsingle_CBC - -end_dec256_CBC: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last iv for chaining - - ret - - - - - - - - - -align 16 -global _iEnc128 -_iEnc128: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_enc128 - - cmp eax,4 - jl lp128encsingle - - test ecx,0xf - jz lpenc128four - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - mov ecx,esp - - - align 16 - -lpenc128four: - - test eax,eax - jz end_enc128 - - cmp eax,4 - jl lp128encsingle - - load_and_xor4 esi,[ecx+0*16] - add esi,4*16 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenclast4 [ecx+10*16] - - store4 esi+edi-16*4 - sub eax,4 - jmp lpenc128four - - align 16 -lp128encsingle: - - movdqu xmm0, [esi] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenclast1_u [ecx+10*16] - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp128encsingle - -end_enc128: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret - - -align 16 -global _iEnc128_CTR -_iEnc128_CTR: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;initial counter - movdqa xmm6, [byte_swap_16] - pshufb xmm5, xmm6 ; byte swap counter - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_encctr128 - - cmp eax,4 - jl lp128encctrsingle - - test ecx,0xf - jz lpencctr128four - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - mov ecx,esp - - - align 16 - -lpencctr128four: - - test eax,eax - jz end_encctr128 - - cmp eax,4 - jl lp128encctrsingle - - load_and_inc4 [ecx+0*16] - add esi,4*16 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenclast4 [ecx+10*16] - xor_with_input4 esi-(4*16) - - store4 esi+edi-16*4 - sub eax,4 - jmp lpencctr128four - - align 16 -lp128encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - paddd xmm5,[counter_add_one] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenclast1_u [ecx+10*16] - movdqu xmm4, [esi-16] - pxor xmm0,xmm4 - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp128encctrsingle - -end_encctr128: - pshufb xmm5, xmm6 ; byte swap counter - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last counter for chaining - - ret - - -align 16 -global _iEnc192_CTR -_iEnc192_CTR: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;initial counter - movdqa xmm6, [byte_swap_16] - pshufb xmm5, xmm6 ; byte swap counter - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_encctr192 - - cmp eax,4 - jl lp192encctrsingle - - test ecx,0xf - jz lpencctr192four - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - mov ecx,esp - - - align 16 - -lpencctr192four: - - test eax,eax - jz end_encctr192 - - cmp eax,4 - jl lp192encctrsingle - - load_and_inc4 [ecx+0*16] - add esi,4*16 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenc4 [ecx+10*16] - aesenc4 [ecx+11*16] - aesenclast4 [ecx+12*16] - xor_with_input4 esi-(4*16) - - store4 esi+edi-16*4 - sub eax,4 - jmp lpencctr192four - - align 16 -lp192encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - paddd xmm5,[counter_add_one] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenc1_u [ecx+10*16] - aesenc1_u [ecx+11*16] - aesenclast1_u [ecx+12*16] - movdqu xmm4, [esi-16] - pxor xmm0,xmm4 - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp192encctrsingle - -end_encctr192: - - pshufb xmm5, xmm6 ; byte swap counter - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last counter for chaining - - ret - - -align 16 -global _iEnc256_CTR -_iEnc256_CTR: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm5,[eax] ;initial counter - movdqa xmm6, [byte_swap_16] - pshufb xmm5, xmm6 ; byte swap counter - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_encctr256 - - cmp eax,4 - jl lp256encctrsingle - - test ecx,0xf - jz lpencctr256four - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - copy_round_keys esp,ecx,13 - copy_round_keys esp,ecx,14 - mov ecx,esp - - - align 16 - -lpencctr256four: - - test eax,eax - jz end_encctr256 - - cmp eax,4 - jl lp256encctrsingle - - load_and_inc4 [ecx+0*16] - add esi,4*16 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenc4 [ecx+10*16] - aesenc4 [ecx+11*16] - aesenc4 [ecx+12*16] - aesenc4 [ecx+13*16] - aesenclast4 [ecx+14*16] - xor_with_input4 esi-(4*16) - - store4 esi+edi-16*4 - sub eax,4 - jmp lpencctr256four - - align 16 - -lp256encctrsingle: - - movdqa xmm0,xmm5 - pshufb xmm0, xmm6 ; byte swap counter back - paddd xmm5,[counter_add_one] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenc1_u [ecx+10*16] - aesenc1_u [ecx+11*16] - aesenc1_u [ecx+12*16] - aesenc1_u [ecx+13*16] - aesenclast1_u [ecx+14*16] - movdqu xmm4, [esi-16] - pxor xmm0,xmm4 - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp256encctrsingle - -end_encctr256: - - pshufb xmm5, xmm6 ; byte swap counter - mov esp,ebp - pop ebp - pop edi - pop esi - - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm5 ; store last counter for chaining - - ret - - - - - - -align 16 -global _iEnc128_CBC -_iEnc128_CBC: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm1,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - sub edi,esi - - test ecx,0xf - jz lp128encsingle_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - mov ecx,esp - - align 16 - -lp128encsingle_CBC: - - movdqu xmm0, [esi] - add esi, 16 - pxor xmm0, xmm1 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1 [ecx+1*16] - aesenc1 [ecx+2*16] - aesenc1 [ecx+3*16] - aesenc1 [ecx+4*16] - aesenc1 [ecx+5*16] - aesenc1 [ecx+6*16] - aesenc1 [ecx+7*16] - aesenc1 [ecx+8*16] - aesenc1 [ecx+9*16] - aesenclast1 [ecx+10*16] - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - movdqa xmm1,xmm0 - dec eax - jnz lp128encsingle_CBC - - - mov esp,ebp - pop ebp - pop edi - pop esi - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm1 ; store last iv for chaining - - ret - - -align 16 -global _iEnc192_CBC -_iEnc192_CBC: - mov ecx,[esp-4+8] ; first arg - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm1,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - sub edi,esi - - test ecx,0xf - jz lp192encsingle_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - mov ecx,esp - - align 16 - -lp192encsingle_CBC: - - movdqu xmm0, [esi] - add esi, 16 - pxor xmm0, xmm1 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1 [ecx+1*16] - aesenc1 [ecx+2*16] - aesenc1 [ecx+3*16] - aesenc1 [ecx+4*16] - aesenc1 [ecx+5*16] - aesenc1 [ecx+6*16] - aesenc1 [ecx+7*16] - aesenc1 [ecx+8*16] - aesenc1 [ecx+9*16] - aesenc1 [ecx+10*16] - aesenc1 [ecx+11*16] - aesenclast1 [ecx+12*16] - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - movdqa xmm1,xmm0 - dec eax - jnz lp192encsingle_CBC - - - mov esp,ebp - pop ebp - pop edi - pop esi - mov ecx,[esp-4+8] ; first arg - mov ecx,[ecx+12] - movdqu [ecx],xmm1 ; store last iv for chaining - - ret - -align 16 -global _iEnc256_CBC -_iEnc256_CBC: - mov ecx,[esp-4+8] ; first arg - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+12] - movdqu xmm1,[eax] ;iv - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - sub edi,esi - - test ecx,0xf - jz lp256encsingle_CBC - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - copy_round_keys esp,ecx,13 - copy_round_keys esp,ecx,14 - mov ecx,esp - - align 16 - -lp256encsingle_CBC: - -;abab - movdqu xmm0, [esi] - add esi, 16 - pxor xmm0, xmm1 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1 [ecx+1*16] - aesenc1 [ecx+2*16] - aesenc1 [ecx+3*16] - aesenc1 [ecx+4*16] - aesenc1 [ecx+5*16] - aesenc1 [ecx+6*16] - aesenc1 [ecx+7*16] - aesenc1 [ecx+8*16] - aesenc1 [ecx+9*16] - aesenc1 [ecx+10*16] - aesenc1 [ecx+11*16] - aesenc1 [ecx+12*16] - aesenc1 [ecx+13*16] - aesenclast1 [ecx+14*16] - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - movdqa xmm1,xmm0 - dec eax - jnz lp256encsingle_CBC - - - mov esp,ebp - pop ebp - pop edi - pop esi - mov ecx,[esp-4+8] - mov ecx,[ecx+12] - movdqu [ecx],xmm1 ; store last iv for chaining - - ret - - - - - -align 16 -global _iEnc192 -_iEnc192: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_enc192 - - cmp eax,4 - jl lp192encsingle - - test ecx,0xf - jz lpenc192four - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - mov ecx,esp - - align 16 - -lpenc192four: - - test eax,eax - jz end_enc192 - - cmp eax,4 - jl lp192encsingle - - load_and_xor4 esi,[ecx+0*16] - add esi,4*16 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenc4 [ecx+10*16] - aesenc4 [ecx+11*16] - aesenclast4 [ecx+12*16] - - store4 esi+edi-16*4 - sub eax,4 - jmp lpenc192four - - align 16 -lp192encsingle: - - movdqu xmm0, [esi] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenc1_u [ecx+10*16] - aesenc1_u [ecx+11*16] - aesenclast1_u [ecx+12*16] - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp192encsingle - -end_enc192: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret - - - - -align 16 -global _iEnc256 -_iEnc256: - mov ecx,[esp-4+8] - - push esi - push edi - push ebp - mov ebp,esp - - sub esp,16*16 - and esp,0xfffffff0 - - mov eax,[ecx+16] ; numblocks - mov esi,[ecx] - mov edi,[ecx+4] - mov ecx,[ecx+8] - - sub edi,esi - - test eax,eax - jz end_enc256 - - cmp eax,4 - jl lp256enc - - test ecx,0xf - jz lp256enc4 - - copy_round_keys esp,ecx,0 - copy_round_keys esp,ecx,1 - copy_round_keys esp,ecx,2 - copy_round_keys esp,ecx,3 - copy_round_keys esp,ecx,4 - copy_round_keys esp,ecx,5 - copy_round_keys esp,ecx,6 - copy_round_keys esp,ecx,7 - copy_round_keys esp,ecx,8 - copy_round_keys esp,ecx,9 - copy_round_keys esp,ecx,10 - copy_round_keys esp,ecx,11 - copy_round_keys esp,ecx,12 - copy_round_keys esp,ecx,13 - copy_round_keys esp,ecx,14 - mov ecx,esp - - - - align 16 - -lp256enc4: - test eax,eax - jz end_enc256 - - cmp eax,4 - jl lp256enc - - - load_and_xor4 esi,[ecx+0*16] - add esi, 16*4 - aesenc4 [ecx+1*16] - aesenc4 [ecx+2*16] - aesenc4 [ecx+3*16] - aesenc4 [ecx+4*16] - aesenc4 [ecx+5*16] - aesenc4 [ecx+6*16] - aesenc4 [ecx+7*16] - aesenc4 [ecx+8*16] - aesenc4 [ecx+9*16] - aesenc4 [ecx+10*16] - aesenc4 [ecx+11*16] - aesenc4 [ecx+12*16] - aesenc4 [ecx+13*16] - aesenclast4 [ecx+14*16] - - store4 esi+edi-16*4 - sub eax,4 - jmp lp256enc4 - - align 16 -lp256enc: - - movdqu xmm0, [esi] - add esi, 16 - movdqu xmm4,[ecx+0*16] - pxor xmm0, xmm4 - aesenc1_u [ecx+1*16] - aesenc1_u [ecx+2*16] - aesenc1_u [ecx+3*16] - aesenc1_u [ecx+4*16] - aesenc1_u [ecx+5*16] - aesenc1_u [ecx+6*16] - aesenc1_u [ecx+7*16] - aesenc1_u [ecx+8*16] - aesenc1_u [ecx+9*16] - aesenc1_u [ecx+10*16] - aesenc1_u [ecx+11*16] - aesenc1_u [ecx+12*16] - aesenc1_u [ecx+13*16] - aesenclast1_u [ecx+14*16] - - ; Store output encrypted data into CIPHERTEXT array - movdqu [esi+edi-16], xmm0 - dec eax - jnz lp256enc - -end_enc256: - - - mov esp,ebp - pop ebp - pop edi - pop esi - - ret diff --git a/src/aes/aesni/iaes_asm_interface.h b/src/aes/aesni/iaes_asm_interface.h deleted file mode 100644 index 2afa80a6112..00000000000 --- a/src/aes/aesni/iaes_asm_interface.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2010, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ - -#ifndef _INTEL_AES_ASM_INTERFACE_H__ -#define _INTEL_AES_ASM_INTERFACE_H__ - - -#include "iaesni.h" - - - -//structure to pass aes processing data to asm level functions -typedef struct _sAesData -{ - _AES_IN UCHAR *in_block; - _AES_OUT UCHAR *out_block; - _AES_IN UCHAR *expanded_key; - _AES_INOUT UCHAR *iv; // for CBC mode - _AES_IN size_t num_blocks; -} sAesData; - -#if (__cplusplus) -extern "C" -{ -#endif -#if 0 -#define MYSTDCALL __stdcall -#else -#define MYSTDCALL -#endif - -#ifdef __linux__ -#ifndef __LP64__ -#define iEncExpandKey256 _iEncExpandKey256 -#define iEncExpandKey192 _iEncExpandKey192 -#define iEncExpandKey128 _iEncExpandKey128 -#define iDecExpandKey256 _iDecExpandKey256 -#define iDecExpandKey192 _iDecExpandKey192 -#define iDecExpandKey128 _iDecExpandKey128 -#define iEnc128 _iEnc128 -#define iDec128 _iDec128 -#define iEnc256 _iEnc256 -#define iDec256 _iDec256 -#define iEnc192 _iEnc192 -#define iDec192 _iDec192 -#define iEnc128_CBC _iEnc128_CBC -#define iDec128_CBC _iDec128_CBC -#define iEnc256_CBC _iEnc256_CBC -#define iDec256_CBC _iDec256_CBC -#define iEnc192_CBC _iEnc192_CBC -#define iDec192_CBC _iDec192_CBC -#define iEnc128_CTR _iEnc128_CTR -#define iEnc192_CTR _iEnc192_CTR -#define iEnc256_CTR _iEnc256_CTR -#define do_rdtsc _do_rdtsc -#endif -#endif - // prepearing the different key rounds, for enc/dec in asm - // expnaded key should be 16-byte aligned - // expanded key should have enough space to hold all key rounds (16 bytes per round) - 256 bytes would cover all cases (AES256 has 14 rounds + 1 xor) - void MYSTDCALL iEncExpandKey256(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key); - void MYSTDCALL iEncExpandKey192(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key); - void MYSTDCALL iEncExpandKey128(_AES_IN UCHAR *key, _AES_OUT UCHAR *expanded_key); - - void MYSTDCALL iDecExpandKey256(UCHAR *key, _AES_OUT UCHAR *expanded_key); - void MYSTDCALL iDecExpandKey192(UCHAR *key, _AES_OUT UCHAR *expanded_key); - void MYSTDCALL iDecExpandKey128(UCHAR *key, _AES_OUT UCHAR *expanded_key); - - - //enc/dec asm functions - void MYSTDCALL iEnc128(sAesData *data); - void MYSTDCALL iDec128(sAesData *data); - void MYSTDCALL iEnc256(sAesData *data); - void MYSTDCALL iDec256(sAesData *data); - void MYSTDCALL iEnc192(sAesData *data); - void MYSTDCALL iDec192(sAesData *data); - - void MYSTDCALL iEnc128_CBC(sAesData *data); - void MYSTDCALL iDec128_CBC(sAesData *data); - void MYSTDCALL iEnc256_CBC(sAesData *data); - void MYSTDCALL iDec256_CBC(sAesData *data); - void MYSTDCALL iEnc192_CBC(sAesData *data); - void MYSTDCALL iDec192_CBC(sAesData *data); - - - void MYSTDCALL iEnc128_CTR(sAesData *data); - void MYSTDCALL iEnc256_CTR(sAesData *data); - void MYSTDCALL iEnc192_CTR(sAesData *data); - - // rdtsc function - unsigned long long do_rdtsc(void); - - -#if (__cplusplus) -} -#endif - - -#endif diff --git a/src/aes/aesni/iaesni.h b/src/aes/aesni/iaesni.h deleted file mode 100644 index 48d600be081..00000000000 --- a/src/aes/aesni/iaesni.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2010, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ - - -#ifndef _IAESNI_H__ -#define _IAESNI_H__ - -#include -#include "../../aligned.h" - -#define AES_INSTRCTIONS_CPUID_BIT (1<<25) - -//indicates input param -#define _AES_IN - -//indicates output param -#define _AES_OUT - -//indicates input/output param - based on context -#define _AES_INOUT - -typedef unsigned char UCHAR; - - -#ifndef bool -#define bool BOOL -#endif -//test if the processor actually supports the above functions -//executing one the functions below without processor support will cause UD fault -//bool check_for_aes_instructions(void); -#if (__cplusplus) -extern "C" { -#endif -int check_for_aes_instructions(void); - -#define ROUND_KEYS_UNALIGNED_TESTING - -#if defined (__linux__) || defined (__CYGWIN__) - -#ifdef ROUND_KEYS_UNALIGNED_TESTING - -#define DEFINE_ROUND_KEYS \ - UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16]; \ - UCHAR *expandedKey = _expandedKey + 4; \ - - -#else - - - -#define DEFINE_ROUND_KEYS \ - UCHAR __attribute__ ((aligned (16))) _expandedKey[16*16]; \ - UCHAR *expandedKey = _expandedKey; \ - -#endif - -#else // if not __linux__ - -#ifdef ROUND_KEYS_UNALIGNED_TESTING - -#define DEFINE_ROUND_KEYS \ - JTR_ALIGN(16) UCHAR _expandedKey[16*16]; \ - UCHAR *expandedKey = _expandedKey + 4; \ - - -#else - - - -#define DEFINE_ROUND_KEYS \ - JTR_ALIGN(16) UCHAR _expandedKey[16*16]; \ - UCHAR *expandedKey = _expandedKey; \ - - -#endif - -#endif - - - -// encryption functions -// plainText is pointer to input stream -// cipherText is pointer to buffer to be filled with encrypted (cipher text) data -// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for AES-192, 32 for AES-256) -// numBlocks is number of 16 bytes blocks to process - note that encryption is done of full 16 byte blocks -void intel_AES_enc128(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); -void intel_AES_enc192(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); -void intel_AES_enc256(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); - - -void intel_AES_enc128_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); -void intel_AES_enc192_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); -void intel_AES_enc256_CBC(_AES_IN UCHAR *plainText, _AES_OUT UCHAR *cipherText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); - - -// encryption functions -// cipherText is pointer to encrypted stream -// plainText is pointer to buffer to be filled with original (plain text) data -// key is pointer to enc key (sizes are 16 bytes for AES-128, 24 bytes for AES-192, 32 for AES-256) -// numBlocks is number of 16 bytes blocks to process - note that decryption is done of full 16 byte blocks -void intel_AES_dec128(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); -void intel_AES_dec192(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); -void intel_AES_dec256(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks); - -void intel_AES_dec128_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); -void intel_AES_dec192_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); -void intel_AES_dec256_CBC(_AES_IN UCHAR *cipherText, _AES_OUT UCHAR *plainText, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *iv); - -void intel_AES_encdec128_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter); -void intel_AES_encdec192_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter); -void intel_AES_encdec256_CTR(_AES_IN UCHAR *input, _AES_OUT UCHAR *output, _AES_IN UCHAR *key, _AES_IN size_t numBlocks, _AES_IN UCHAR *initial_counter); - - -#if (__cplusplus) -} -#endif - - -#endif diff --git a/src/aes/aesni/intel_aes.c b/src/aes/aesni/intel_aes.c deleted file mode 100644 index 8bfde979e05..00000000000 --- a/src/aes/aesni/intel_aes.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2010, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ - -#if (__cplusplus) -extern "C" { -#endif - -#if AC_BUILT -#include "../../autoconfig.h" -#endif - -#include "iaesni.h" -#include "iaes_asm_interface.h" - -#if (__cplusplus) -} -#endif - -#include -#include - -#ifdef AC_BUILT -#include "../../autoconfig.h" -#endif - -void intel_AES_enc128(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iEncExpandKey128(key,expandedKey); - iEnc128(&aesData); -} - - -void intel_AES_enc128_CBC(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iEncExpandKey128(key,expandedKey); - iEnc128_CBC(&aesData); -} - - -void intel_AES_enc192(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iEncExpandKey192(key,expandedKey); - iEnc192(&aesData); -} - - -void intel_AES_enc192_CBC(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iEncExpandKey192(key,expandedKey); - iEnc192_CBC(&aesData); -} - - -void intel_AES_enc256(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iEncExpandKey256(key,expandedKey); - iEnc256(&aesData); -} - - -void intel_AES_enc256_CBC(UCHAR *plainText,UCHAR *cipherText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = plainText; - aesData.out_block = cipherText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iEncExpandKey256(key,expandedKey); - iEnc256_CBC(&aesData); -} - - -void intel_AES_dec128(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iDecExpandKey128(key,expandedKey); - iDec128(&aesData); -} - -void intel_AES_dec128_CBC(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iDecExpandKey128(key,expandedKey); - iDec128_CBC(&aesData); -} - - -void intel_AES_dec192(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iDecExpandKey192(key,expandedKey); - iDec192(&aesData); -} - - -void intel_AES_dec192_CBC(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iDecExpandKey192(key,expandedKey); - iDec192_CBC(&aesData); -} - - -void intel_AES_dec256(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - - iDecExpandKey256(key,expandedKey); - iDec256(&aesData); -} - - -void intel_AES_dec256_CBC(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks,UCHAR *iv) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = cipherText; - aesData.out_block = plainText; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = iv; - - iDecExpandKey256(key,expandedKey); - iDec256_CBC(&aesData); -} - - - -void intel_AES_encdec256_CTR(UCHAR *in,UCHAR *out,UCHAR *key,size_t numBlocks,UCHAR *ic) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = in; - aesData.out_block = out; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = ic; - - iEncExpandKey256(key,expandedKey); - iEnc256_CTR(&aesData); -} - -void intel_AES_encdec192_CTR(UCHAR *in,UCHAR *out,UCHAR *key,size_t numBlocks,UCHAR *ic) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = in; - aesData.out_block = out; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = ic; - - iEncExpandKey192(key,expandedKey); - iEnc192_CTR(&aesData); -} - -void intel_AES_encdec128_CTR(UCHAR *in,UCHAR *out,UCHAR *key,size_t numBlocks,UCHAR *ic) -{ - DEFINE_ROUND_KEYS - sAesData aesData; - aesData.in_block = in; - aesData.out_block = out; - aesData.expanded_key = expandedKey; - aesData.num_blocks = numBlocks; - aesData.iv = ic; - - iEncExpandKey128(key,expandedKey); - iEnc128_CTR(&aesData); -} - - - -#if HAVE_INTRIN_H - -#include - -#elif __i386__ - -// FIXME: Implement this correctly. Currently always returns "no" - -static void __cpuid(unsigned int where[4], unsigned int leaf) { -// asm volatile("cpuid":"=a"(*where), "=c"(*(where+2)),"=d"(*(where+3)):"a"(leaf)); - where[2] = 0; - return; -} - -#else - -static void __cpuid(unsigned int where[4], unsigned int leaf) { - asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)), "=c"(*(where+2)),"=d"(*(where+3)):"a"(leaf)); - return; -} -#endif - -/* - * check_for_aes_instructions() - * return 1 if support AES-NI and 0 if don't support AES-NI - */ - -int check_for_aes_instructions() -{ - unsigned int cpuid_results[4]; - int yes=1, no=0; - - // Removed checks for Intel CPU -HN - - __cpuid(cpuid_results,1); - - if (cpuid_results[2] & AES_INSTRCTIONS_CPUID_BIT) - return yes; - - return no; -} diff --git a/src/aes/openssl/Makefile.in b/src/aes/openssl/Makefile.in deleted file mode 100644 index ae541e1ad9c..00000000000 --- a/src/aes/openssl/Makefile.in +++ /dev/null @@ -1,20 +0,0 @@ -@SET_MAKE@ -CC = @CC@ -CXX = @CXX@ -AS = @CC@ -LD = @CC@ -CPP = @CC@ -CFLAGS = @CFLAGS@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ -ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@ -LDFLAGS = @LDFLAGS@ @OPENSSL_LIBS@ - -ossl_aes.o: ossl_aes.c ossl_aes.h - $(CC) $(CFLAGS) -c ossl_aes.c -o $@ - -default: ossl_aes.o -all: ossl_aes.o - -clean: - -distclean: clean - $(RM) Makefile diff --git a/src/aes/openssl/Makefile.legacy b/src/aes/openssl/Makefile.legacy deleted file mode 100644 index f77bc741db2..00000000000 --- a/src/aes/openssl/Makefile.legacy +++ /dev/null @@ -1,5 +0,0 @@ -ossl_aes.o: ossl_aes.c ossl_aes.h - $(CC) $(CFLAGS) -c ossl_aes.c -o $@ - -default: ossl_aes.o -all: ossl_aes.o diff --git a/src/aes/openssl/ossl_aes.c b/src/aes/openssl/ossl_aes.c deleted file mode 100644 index 4726d00b747..00000000000 --- a/src/aes/openssl/ossl_aes.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include - -// NOTE, we need to handle this for non-AC built. I am sure there is some openssl version -// to check in that case. I do not know it, so for now, I will only deal with AC builds -#if HAVE_AES_ENCRYPT - -#include - -#else - -/* - * this code copied from oSSL newer version. This is ALL we do, so it - * has been pared down here. - */ -#define AES_ENCRYPT 1 -#define AES_DECRYPT 0 -/* Because array size can't be a const in C, the following two are macros. - Both sizes are in bytes. */ -#define AES_MAXNR 14 -#define AES_BLOCK_SIZE 16 -typedef struct aes_key_st { - unsigned int rd_key[4 *(AES_MAXNR + 1)]; - int rounds; -} AES_KEY; -typedef void (*block128_f)(const unsigned char in[16], unsigned char out[16], const void *key); - -#include "ossl_aes_crypto.c" - -// ignore the FIPS crap. -void JTR_AES_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) { - if (enc) CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)AES_encrypt); - else CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)AES_decrypt); -} -#define AES_cbc_encrypt JTR_AES_cbc_encrypt -/* - * This is the end of the oSSL code - */ - - -#endif - -inline static void aes_key_mgmt(AES_KEY *akey, unsigned char *key, unsigned int key_length, int direction) { - if (direction == AES_ENCRYPT) { - AES_set_encrypt_key(key, key_length, akey); - } else { - AES_set_decrypt_key(key, key_length, akey); - } -} - -inline static void aes_cbc(unsigned char *in, unsigned char *out, unsigned char *key, size_t num_blocks, unsigned char *iv, unsigned int key_length, int direction) { - AES_KEY akey; - aes_key_mgmt(&akey, key, key_length, direction); - AES_cbc_encrypt(in, out, num_blocks * AES_BLOCK_SIZE, &akey, iv, direction); -} - -#define OSSL_CBC_FUNC(n) \ - void openssl_AES_enc##n##_CBC(unsigned char *in, unsigned char *out, unsigned char *key, size_t num_blocks, unsigned char *iv) { aes_cbc(in, out, key, num_blocks, iv, n, AES_ENCRYPT); } \ - void openssl_AES_dec##n##_CBC(unsigned char *in, unsigned char *out, unsigned char *key, size_t num_blocks, unsigned char *iv) { aes_cbc(in, out, key, num_blocks, iv, n, AES_DECRYPT); } - -OSSL_CBC_FUNC(128) -OSSL_CBC_FUNC(192) -OSSL_CBC_FUNC(256) - -#undef OSSL_CBC_FUNC - -// There are other AES functions that could be implemented here. - -// Here are the 'low level' ones (some) These are tied in with aes/aes.h -#undef AES_encrypt -void JTR_AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { - AES_encrypt(in, out, key); -} -#undef AES_decrypt -void JTR_AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { - AES_decrypt(in, out, key); -} - -#undef AES_set_encrypt_key -int JTR_AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { - return AES_set_encrypt_key(userKey, bits, key); -} - -#undef AES_set_decrypt_key -int JTR_AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { - return AES_set_decrypt_key(userKey, bits, key); -} diff --git a/src/aes/openssl/ossl_aes.h b/src/aes/openssl/ossl_aes.h deleted file mode 100644 index b4ccd2214b4..00000000000 --- a/src/aes/openssl/ossl_aes.h +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -#define OSSL_CBC_FUNC(n) \ - void openssl_AES_enc##n##_CBC(unsigned char *in, unsigned char *out, unsigned char *key, size_t num_blocks, unsigned char *iv); \ - void openssl_AES_dec##n##_CBC(unsigned char *in, unsigned char *out, unsigned char *key, size_t num_blocks, unsigned char *iv); - -OSSL_CBC_FUNC(128) -OSSL_CBC_FUNC(192) -OSSL_CBC_FUNC(256) - -#undef OSSL_CBC_FUNC diff --git a/src/aes/openssl/ossl_aes_crypto.c b/src/aes/openssl/ossl_aes_crypto.c deleted file mode 100644 index 19c67b75f46..00000000000 --- a/src/aes/openssl/ossl_aes_crypto.c +++ /dev/null @@ -1,1283 +0,0 @@ -/* This code used and modified, so that oSSL versions prior to */ -/* where they added eas, can now support it, in the limited */ -/* manner that JtR uses it. This was public domain code, and */ -/* is being used as such. Incorporation done by JimF Spring */ -/* 2014. Still in public domain. */ - -/* crypto/aes/aes_core.c -*- mode:C; c-file-style: "eay" -*- */ -/** - * rijndael-alg-fst.c - * - * @version 3.0 (December 2000) - * - * Optimised ANSI C code for the Rijndael cipher (now AES) - * - * @author Vincent Rijmen - * @author Antoon Bosselaers - * @author Paulo Barreto - * - * This code is hereby placed in the public domain. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* Note: rewritten a little bit to provide error control and an OpenSSL- - compatible API */ - -/* code and macros from aes_locl.h needed to compile this code */ - -#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) - #define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) - #define GETU32(p) SWAP(*((u32 *)(p))) - #define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } -#else - #define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3])) - #define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); } -#endif - -typedef unsigned int u32; -typedef unsigned short u16; -typedef unsigned char u8; - -#define MAXKC (256/32) -#define MAXKB (256/8) -#define MAXNR 14 - -/* This controls loop-unrolling in aes_core.c */ -/* with full_unroll, I get about same speed, for native oSSL 1.0 AES */ -/* as I do for this code. So I have left FULL_UNROLL defined by default */ -//#undef FULL_UNROLL -#define FULL_UNROLL - -/* -Te0[x] = S [x].[02, 01, 01, 03]; -Te1[x] = S [x].[03, 02, 01, 01]; -Te2[x] = S [x].[01, 03, 02, 01]; -Te3[x] = S [x].[01, 01, 03, 02]; - -Td0[x] = Si[x].[0e, 09, 0d, 0b]; -Td1[x] = Si[x].[0b, 0e, 09, 0d]; -Td2[x] = Si[x].[0d, 0b, 0e, 09]; -Td3[x] = Si[x].[09, 0d, 0b, 0e]; -Td4[x] = Si[x].[01]; -*/ - -static const u32 Te0[256] = { - 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, - 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, - 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, - 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, - 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, - 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, - 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, - 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, - 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, - 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, - 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, - 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, - 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, - 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U, - 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, - 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, - 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, - 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, - 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, - 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, - 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, - 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, - 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, - 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, - 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U, - 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, - 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, - 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, - 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, - 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, - 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, - 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, - 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, - 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, - 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, - 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, - 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, - 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, - 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, - 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, - 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, - 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, - 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, - 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, - 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, - 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, - 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, - 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, - 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, - 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U, - 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, - 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, - 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, - 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, - 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, - 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, - 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, - 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, - 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, - 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, - 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U, - 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, - 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, - 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, -}; -static const u32 Te1[256] = { - 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, - 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, - 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, - 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, - 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, - 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, - 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, - 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, - 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, - 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, - 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, - 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, - 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, - 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU, - 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, - 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, - 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, - 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, - 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, - 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, - 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, - 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, - 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, - 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, - 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU, - 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, - 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, - 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, - 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, - 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, - 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, - 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, - 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, - 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, - 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, - 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, - 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, - 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, - 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, - 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, - 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, - 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, - 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, - 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, - 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, - 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, - 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, - 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, - 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, - 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U, - 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, - 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, - 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, - 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, - 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, - 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, - 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, - 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, - 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, - 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, - 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU, - 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, - 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, - 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, -}; -static const u32 Te2[256] = { - 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, - 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, - 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, - 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, - 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, - 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, - 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, - 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, - 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, - 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, - 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, - 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, - 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, - 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU, - 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, - 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, - 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, - 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, - 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, - 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, - 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, - 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, - 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, - 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, - 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU, - 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, - 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, - 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, - 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, - 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, - 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, - 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, - 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, - 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, - 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, - 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, - 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, - 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, - 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, - 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, - 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, - 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, - 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, - 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, - 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, - 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, - 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, - 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, - 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, - 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U, - 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, - 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, - 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, - 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, - 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, - 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, - 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, - 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, - 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, - 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, - 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU, - 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, - 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, - 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, -}; -static const u32 Te3[256] = { - 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, - 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, - 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, - 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, - 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, - 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, - 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, - 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, - 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, - 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, - 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, - 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, - 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, - 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU, - 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, - 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, - 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, - 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, - 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, - 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, - 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, - 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, - 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, - 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, - 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU, - 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, - 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, - 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, - 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, - 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, - 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, - 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, - 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, - 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, - 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, - 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, - 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, - 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, - 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, - 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, - 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, - 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, - 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, - 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, - 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, - 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, - 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, - 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, - 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, - 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U, - 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, - 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, - 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, - 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, - 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, - 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, - 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, - 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, - 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, - 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, - 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU, - 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, - 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, - 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, -}; - -static const u32 Td0[256] = { - 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, - 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, - 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, - 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, - 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, - 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, - 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, - 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, - 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, - 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, - 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, - 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, - 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, - 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU, - 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, - 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, - 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, - 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, - 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, - 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, - 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, - 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, - 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, - 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, - 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U, - 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, - 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, - 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, - 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, - 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, - 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, - 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, - 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, - 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, - 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, - 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, - 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, - 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, - 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U, - 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, - 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, - 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, - 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, - 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, - 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, - 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, - 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, - 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, - 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, - 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U, - 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, - 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, - 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, - 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, - 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, - 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, - 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, - 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, - 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, - 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, - 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU, - 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, - 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, - 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, -}; -static const u32 Td1[256] = { - 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, - 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, - 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, - 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, - 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, - 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, - 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, - 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, - 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, - 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, - 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, - 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, - 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, - 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU, - 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, - 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, - 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, - 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, - 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, - 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, - 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, - 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, - 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, - 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, - 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U, - 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, - 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, - 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, - 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, - 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, - 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, - 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, - 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, - 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, - 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, - 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, - 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, - 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, - 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U, - 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, - 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, - 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, - 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, - 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, - 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, - 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, - 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, - 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, - 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, - 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U, - 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, - 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, - 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, - 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, - 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, - 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, - 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, - 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, - 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, - 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, - 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U, - 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, - 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, - 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, -}; -static const u32 Td2[256] = { - 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, - 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, - 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, - 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, - 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, - 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, - 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, - 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, - 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, - 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, - 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, - 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, - 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, - 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U, - 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, - 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, - 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, - 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, - 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, - 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, - 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, - 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, - 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, - 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, - 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U, - 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, - 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, - 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, - 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, - 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, - 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, - 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, - 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, - 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, - 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, - 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, - 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, - 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, - 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U, - 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, - 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, - 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, - 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, - 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, - 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, - 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, - 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, - 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, - 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, - 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U, - 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, - 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, - 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, - 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, - 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, - 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, - 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, - 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, - 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, - 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, - 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U, - 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, - 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, - 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, -}; -static const u32 Td3[256] = { - 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, - 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, - 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, - 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, - 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, - 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, - 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, - 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, - 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, - 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, - 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, - 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, - 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, - 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U, - 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, - 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, - 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, - 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, - 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, - 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, - 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, - 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, - 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, - 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, - 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U, - 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, - 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, - 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, - 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, - 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, - 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, - 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, - 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, - 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, - 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, - 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, - 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, - 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, - 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U, - 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, - 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, - 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, - 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, - 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, - 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, - 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, - 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, - 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, - 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, - 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U, - 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, - 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, - 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, - 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, - 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, - 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, - 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, - 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, - 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, - 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, - 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U, - 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, - 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, - 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, -}; -static const u8 Td4[256] = { - 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, - 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, - 0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U, - 0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU, - 0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU, - 0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU, - 0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U, - 0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U, - 0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U, - 0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U, - 0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU, - 0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U, - 0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU, - 0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U, - 0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U, - 0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU, - 0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU, - 0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U, - 0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U, - 0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU, - 0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U, - 0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU, - 0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U, - 0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U, - 0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U, - 0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU, - 0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU, - 0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU, - 0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U, - 0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U, - 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, - 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, -}; -static const u32 rcon[] = { - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ -}; - -/** - * Expand the cipher key into the encryption key schedule. - */ -static int AES_set_encrypt_key(const unsigned char *userKey, const int bits, - AES_KEY *key) { - - u32 *rk; - int i = 0; - u32 temp; - - if (!userKey || !key) - return -1; - if (bits != 128 && bits != 192 && bits != 256) - return -2; - - rk = key->rd_key; - - if (bits==128) - key->rounds = 10; - else if (bits==192) - key->rounds = 12; - else - key->rounds = 14; - - rk[0] = GETU32(userKey ); - rk[1] = GETU32(userKey + 4); - rk[2] = GETU32(userKey + 8); - rk[3] = GETU32(userKey + 12); - if (bits == 128) { - while (1) { - temp = rk[3]; - rk[4] = rk[0] ^ - (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te0[(temp ) & 0xff] & 0x0000ff00) ^ - (Te1[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[5] = rk[1] ^ rk[4]; - rk[6] = rk[2] ^ rk[5]; - rk[7] = rk[3] ^ rk[6]; - if (++i == 10) { - return 0; - } - rk += 4; - } - } - rk[4] = GETU32(userKey + 16); - rk[5] = GETU32(userKey + 20); - if (bits == 192) { - while (1) { - temp = rk[ 5]; - rk[ 6] = rk[ 0] ^ - (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te0[(temp ) & 0xff] & 0x0000ff00) ^ - (Te1[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 7] = rk[ 1] ^ rk[ 6]; - rk[ 8] = rk[ 2] ^ rk[ 7]; - rk[ 9] = rk[ 3] ^ rk[ 8]; - if (++i == 8) { - return 0; - } - rk[10] = rk[ 4] ^ rk[ 9]; - rk[11] = rk[ 5] ^ rk[10]; - rk += 6; - } - } - rk[6] = GETU32(userKey + 24); - rk[7] = GETU32(userKey + 28); - if (bits == 256) { - while (1) { - temp = rk[ 7]; - rk[ 8] = rk[ 0] ^ - (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te0[(temp ) & 0xff] & 0x0000ff00) ^ - (Te1[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 9] = rk[ 1] ^ rk[ 8]; - rk[10] = rk[ 2] ^ rk[ 9]; - rk[11] = rk[ 3] ^ rk[10]; - if (++i == 7) { - return 0; - } - temp = rk[11]; - rk[12] = rk[ 4] ^ - (Te2[(temp >> 24) ] & 0xff000000) ^ - (Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^ - (Te0[(temp >> 8) & 0xff] & 0x0000ff00) ^ - (Te1[(temp ) & 0xff] & 0x000000ff); - rk[13] = rk[ 5] ^ rk[12]; - rk[14] = rk[ 6] ^ rk[13]; - rk[15] = rk[ 7] ^ rk[14]; - - rk += 8; - } - } - return 0; -} - -/** - * Expand the cipher key into the decryption key schedule. - */ -static int AES_set_decrypt_key(const unsigned char *userKey, const int bits, - AES_KEY *key) { - - u32 *rk; - int i, j, status; - u32 temp; - - /* first, start with an encryption schedule */ - status = AES_set_encrypt_key(userKey, bits, key); - if (status < 0) - return status; - - rk = key->rd_key; - - /* invert the order of the round keys: */ - for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) { - temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; - temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; - temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; - temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; - } - /* apply the inverse MixColumn transform to all round keys but the first and the last: */ - for (i = 1; i < (key->rounds); i++) { - rk += 4; - rk[0] = - Td0[Te1[(rk[0] >> 24) ] & 0xff] ^ - Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^ - Td2[Te1[(rk[0] >> 8) & 0xff] & 0xff] ^ - Td3[Te1[(rk[0] ) & 0xff] & 0xff]; - rk[1] = - Td0[Te1[(rk[1] >> 24) ] & 0xff] ^ - Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^ - Td2[Te1[(rk[1] >> 8) & 0xff] & 0xff] ^ - Td3[Te1[(rk[1] ) & 0xff] & 0xff]; - rk[2] = - Td0[Te1[(rk[2] >> 24) ] & 0xff] ^ - Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^ - Td2[Te1[(rk[2] >> 8) & 0xff] & 0xff] ^ - Td3[Te1[(rk[2] ) & 0xff] & 0xff]; - rk[3] = - Td0[Te1[(rk[3] >> 24) ] & 0xff] ^ - Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^ - Td2[Te1[(rk[3] >> 8) & 0xff] & 0xff] ^ - Td3[Te1[(rk[3] ) & 0xff] & 0xff]; - } - return 0; -} - -/* - * Encrypt a single block - * in and out can overlap - */ -static void AES_encrypt(const unsigned char *in, unsigned char *out, - const AES_KEY *key) { - - const u32 *rk; - u32 s0, s1, s2, s3, t0, t1, t2, t3; -#ifndef FULL_UNROLL - int r; -#endif /* ?FULL_UNROLL */ - -// assert(in && out && key); - rk = key->rd_key; - - /* - * map byte array block to cipher state - * and add initial round key: - */ - s0 = GETU32(in ) ^ rk[0]; - s1 = GETU32(in + 4) ^ rk[1]; - s2 = GETU32(in + 8) ^ rk[2]; - s3 = GETU32(in + 12) ^ rk[3]; -#ifdef FULL_UNROLL - /* round 1: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7]; - /* round 2: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11]; - /* round 3: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15]; - /* round 4: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19]; - /* round 5: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23]; - /* round 6: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27]; - /* round 7: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31]; - /* round 8: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35]; - /* round 9: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39]; - if (key->rounds > 10) { - /* round 10: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43]; - /* round 11: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47]; - if (key->rounds > 12) { - /* round 12: */ - s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48]; - s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49]; - s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50]; - s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51]; - /* round 13: */ - t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52]; - t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53]; - t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54]; - t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55]; - } - } - rk += key->rounds << 2; -#else /* !FULL_UNROLL */ - /* - * Nr - 1 full rounds: - */ - r = key->rounds >> 1; - for (;;) { - t0 = - Te0[(s0 >> 24) ] ^ - Te1[(s1 >> 16) & 0xff] ^ - Te2[(s2 >> 8) & 0xff] ^ - Te3[(s3 ) & 0xff] ^ - rk[4]; - t1 = - Te0[(s1 >> 24) ] ^ - Te1[(s2 >> 16) & 0xff] ^ - Te2[(s3 >> 8) & 0xff] ^ - Te3[(s0 ) & 0xff] ^ - rk[5]; - t2 = - Te0[(s2 >> 24) ] ^ - Te1[(s3 >> 16) & 0xff] ^ - Te2[(s0 >> 8) & 0xff] ^ - Te3[(s1 ) & 0xff] ^ - rk[6]; - t3 = - Te0[(s3 >> 24) ] ^ - Te1[(s0 >> 16) & 0xff] ^ - Te2[(s1 >> 8) & 0xff] ^ - Te3[(s2 ) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Te0[(t0 >> 24) ] ^ - Te1[(t1 >> 16) & 0xff] ^ - Te2[(t2 >> 8) & 0xff] ^ - Te3[(t3 ) & 0xff] ^ - rk[0]; - s1 = - Te0[(t1 >> 24) ] ^ - Te1[(t2 >> 16) & 0xff] ^ - Te2[(t3 >> 8) & 0xff] ^ - Te3[(t0 ) & 0xff] ^ - rk[1]; - s2 = - Te0[(t2 >> 24) ] ^ - Te1[(t3 >> 16) & 0xff] ^ - Te2[(t0 >> 8) & 0xff] ^ - Te3[(t1 ) & 0xff] ^ - rk[2]; - s3 = - Te0[(t3 >> 24) ] ^ - Te1[(t0 >> 16) & 0xff] ^ - Te2[(t1 >> 8) & 0xff] ^ - Te3[(t2 ) & 0xff] ^ - rk[3]; - } -#endif /* ?FULL_UNROLL */ - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - (Te2[(t0 >> 24) ] & 0xff000000) ^ - (Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^ - (Te0[(t2 >> 8) & 0xff] & 0x0000ff00) ^ - (Te1[(t3 ) & 0xff] & 0x000000ff) ^ - rk[0]; - PUTU32(out , s0); - s1 = - (Te2[(t1 >> 24) ] & 0xff000000) ^ - (Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^ - (Te0[(t3 >> 8) & 0xff] & 0x0000ff00) ^ - (Te1[(t0 ) & 0xff] & 0x000000ff) ^ - rk[1]; - PUTU32(out + 4, s1); - s2 = - (Te2[(t2 >> 24) ] & 0xff000000) ^ - (Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^ - (Te0[(t0 >> 8) & 0xff] & 0x0000ff00) ^ - (Te1[(t1 ) & 0xff] & 0x000000ff) ^ - rk[2]; - PUTU32(out + 8, s2); - s3 = - (Te2[(t3 >> 24) ] & 0xff000000) ^ - (Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^ - (Te0[(t1 >> 8) & 0xff] & 0x0000ff00) ^ - (Te1[(t2 ) & 0xff] & 0x000000ff) ^ - rk[3]; - PUTU32(out + 12, s3); -} - -/* - * Decrypt a single block - * in and out can overlap - */ -static void AES_decrypt(const unsigned char *in, unsigned char *out, - const AES_KEY *key) { - - const u32 *rk; - u32 s0, s1, s2, s3, t0, t1, t2, t3; -#ifndef FULL_UNROLL - int r; -#endif /* ?FULL_UNROLL */ - -// assert(in && out && key); - rk = key->rd_key; - - /* - * map byte array block to cipher state - * and add initial round key: - */ - s0 = GETU32(in ) ^ rk[0]; - s1 = GETU32(in + 4) ^ rk[1]; - s2 = GETU32(in + 8) ^ rk[2]; - s3 = GETU32(in + 12) ^ rk[3]; -#ifdef FULL_UNROLL - /* round 1: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7]; - /* round 2: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11]; - /* round 3: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15]; - /* round 4: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19]; - /* round 5: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23]; - /* round 6: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27]; - /* round 7: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31]; - /* round 8: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35]; - /* round 9: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39]; - if (key->rounds > 10) { - /* round 10: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43]; - /* round 11: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47]; - if (key->rounds > 12) { - /* round 12: */ - s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48]; - s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49]; - s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50]; - s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51]; - /* round 13: */ - t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52]; - t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53]; - t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54]; - t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55]; - } - } - rk += key->rounds << 2; -#else /* !FULL_UNROLL */ - /* - * Nr - 1 full rounds: - */ - r = key->rounds >> 1; - for (;;) { - t0 = - Td0[(s0 >> 24) ] ^ - Td1[(s3 >> 16) & 0xff] ^ - Td2[(s2 >> 8) & 0xff] ^ - Td3[(s1 ) & 0xff] ^ - rk[4]; - t1 = - Td0[(s1 >> 24) ] ^ - Td1[(s0 >> 16) & 0xff] ^ - Td2[(s3 >> 8) & 0xff] ^ - Td3[(s2 ) & 0xff] ^ - rk[5]; - t2 = - Td0[(s2 >> 24) ] ^ - Td1[(s1 >> 16) & 0xff] ^ - Td2[(s0 >> 8) & 0xff] ^ - Td3[(s3 ) & 0xff] ^ - rk[6]; - t3 = - Td0[(s3 >> 24) ] ^ - Td1[(s2 >> 16) & 0xff] ^ - Td2[(s1 >> 8) & 0xff] ^ - Td3[(s0 ) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Td0[(t0 >> 24) ] ^ - Td1[(t3 >> 16) & 0xff] ^ - Td2[(t2 >> 8) & 0xff] ^ - Td3[(t1 ) & 0xff] ^ - rk[0]; - s1 = - Td0[(t1 >> 24) ] ^ - Td1[(t0 >> 16) & 0xff] ^ - Td2[(t3 >> 8) & 0xff] ^ - Td3[(t2 ) & 0xff] ^ - rk[1]; - s2 = - Td0[(t2 >> 24) ] ^ - Td1[(t1 >> 16) & 0xff] ^ - Td2[(t0 >> 8) & 0xff] ^ - Td3[(t3 ) & 0xff] ^ - rk[2]; - s3 = - Td0[(t3 >> 24) ] ^ - Td1[(t2 >> 16) & 0xff] ^ - Td2[(t1 >> 8) & 0xff] ^ - Td3[(t0 ) & 0xff] ^ - rk[3]; - } -#endif /* ?FULL_UNROLL */ - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - ( ((unsigned int)(Td4[(t0 >> 24)])) << 24) ^ - (Td4[(t3 >> 16) & 0xff] << 16) ^ - (Td4[(t2 >> 8) & 0xff] << 8) ^ - (Td4[(t1 ) & 0xff]) ^ - rk[0]; - PUTU32(out , s0); - s1 = - ( ((unsigned int)(Td4[(t1 >> 24)])) << 24) ^ - (Td4[(t0 >> 16) & 0xff] << 16) ^ - (Td4[(t3 >> 8) & 0xff] << 8) ^ - (Td4[(t2 ) & 0xff]) ^ - rk[1]; - PUTU32(out + 4, s1); - s2 = - ( ((unsigned int)(Td4[(t2 >> 24)])) << 24) ^ - (Td4[(t1 >> 16) & 0xff] << 16) ^ - (Td4[(t0 >> 8) & 0xff] << 8) ^ - (Td4[(t3 ) & 0xff]) ^ - rk[2]; - PUTU32(out + 8, s2); - s3 = - ( ((unsigned int)(Td4[(t3 >> 24)])) << 24) ^ - (Td4[(t2 >> 16) & 0xff] << 16) ^ - (Td4[(t1 >> 8) & 0xff] << 8) ^ - (Td4[(t0 ) & 0xff]) ^ - rk[3]; - PUTU32(out + 12, s3); -} - - -/* Added cbc128 stuff also. The functions have been HEAVILY stripped down. They - * are setup only to work in OSSL_SMALL_FOOTPRINT mode. Original comment kept from - * the ./crypto/modes/cbc128.c file. This should be adequate for JtR licensing. - * it lists source and binary forms, with or without modifications. - * JimF, spring 2014. I claim no restrictions on usage for any of my modifications. - */ - -/* ==================================================================== - * Copyright (c) 2008 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -static void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, - size_t len, const void *key, - unsigned char ivec[16], block128_f block) -{ - size_t n; - const unsigned char *iv = ivec; -// assert(in && out && key && ivec); - while (len) { - for (n=0; n<16 && n>confdefs.h <<_ACEOF _ACEOF -if test "$CPU_BIT_STR" = "32"; then - aesni_arch="86" -else - aesni_arch="64" -fi -AESNI_ARCH="$aesni_arch" - - -aesni_os="" -aesni_options="DISABLED" - -if test "x$ax_intel_x32" = xyes; then - aesni_os=linux aesni_options="-g dwarf2 -f elfx32" -else - case "${host}_${CFLAGS}" in - *_*-mno-mmx*) ;; - *_*-mno-sse2*) ;; - x86_64*darwin*) - aesni_os=darwin - aesni_options="--prefix=_ -f macho${CPU_BIT_STR}" - ;; - i?86*darwin*) - aesni_os=darwin - aesni_options="-f macho${CPU_BIT_STR}" - ;; - *86*linux*) - aesni_os=linux - aesni_options="-g dwarf2 -f elf${CPU_BIT_STR}" - ;; - *86*cygwin*) - aesni_os=cygwin - aesni_options="-f win${CPU_BIT_STR}" - ;; - esac -fi -if test "x$aesni_options" != xDISABLED; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for yasm that supports \"$aesni_options\"" >&5 -$as_echo_n "checking for yasm that supports \"$aesni_options\"... " >&6; } -if ${ac_cv_path_YASM+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$YASM"; then - ac_path_YASM_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in yasm; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_YASM="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_YASM" || continue -yasmout=`$ac_path_YASM $aesni_options 2>&1 | grep "No input files"` - test "x$yasmout" != x \ - && ac_cv_path_YASM=$ac_path_YASM ac_path_YASM_found=: - - $ac_path_YASM_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_YASM"; then - : - fi -else - ac_cv_path_YASM=$YASM -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_YASM" >&5 -$as_echo "$ac_cv_path_YASM" >&6; } -fi - -if test "x$aesni_options" != xDISABLED -a "x$ac_path_YASM_found" != xfalse; then - using_aesni="run-time detection" -elif test "$with_openssl" = "yes" -a "$cpu_family" = intel; then - using_aesni="depends on OpenSSL" -else - using_aesni=no -fi -YASM=$ac_cv_path_YASM - -AESNI_OS="$aesni_os" - -YASM_OPTIONS="$aesni_options" - - CC_BACKUP=$CC CFLAGS_BACKUP="$CFLAGS" @@ -16484,7 +16389,7 @@ if test "`echo *_plug.c`" != "*_plug.c"; then if test "x$plug_deps" = xyes -a "x$PERL" != x ; then { $as_echo "$as_me:${as_lineno-$LINENO}: creating Makefile dependencies" >&5 $as_echo "$as_me: creating Makefile dependencies" >&6;} - PLUGFORMATS_DEPS=`$PERL ./plugin_deps.pl *_plug.c` + PLUGFORMATS_DEPS=`$PERL ./plugin_deps.pl 2>/dev/null *_plug.c` fi fi @@ -16495,7 +16400,7 @@ echo "#define JOHN_BLD \"${host_os} ${CPU_BIT_STR}-bit${using_x32} ${host_cpu} $ HOST_OS="$host_os" -ac_config_files="$ac_config_files Makefile aes/Makefile aes/aesni/Makefile aes/openssl/Makefile secp256k1/Makefile ed25519-donna/Makefile poly1305-donna/Makefile" +ac_config_files="$ac_config_files Makefile mbedtls/Makefile secp256k1/Makefile ed25519-donna/Makefile poly1305-donna/Makefile" CFLAGS_EXTRA_BACKUP=$CFLAGS_EXTRA @@ -17207,9 +17112,7 @@ do "ztex/pkt_comm/Makefile") CONFIG_FILES="$CONFIG_FILES ztex/pkt_comm/Makefile" ;; "arch.h") CONFIG_LINKS="$CONFIG_LINKS arch.h:$ARCH_LINK" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; - "aes/Makefile") CONFIG_FILES="$CONFIG_FILES aes/Makefile" ;; - "aes/aesni/Makefile") CONFIG_FILES="$CONFIG_FILES aes/aesni/Makefile" ;; - "aes/openssl/Makefile") CONFIG_FILES="$CONFIG_FILES aes/openssl/Makefile" ;; + "mbedtls/Makefile") CONFIG_FILES="$CONFIG_FILES mbedtls/Makefile" ;; "secp256k1/Makefile") CONFIG_FILES="$CONFIG_FILES secp256k1/Makefile" ;; "ed25519-donna/Makefile") CONFIG_FILES="$CONFIG_FILES ed25519-donna/Makefile" ;; "poly1305-donna/Makefile") CONFIG_FILES="$CONFIG_FILES poly1305-donna/Makefile" ;; @@ -18013,7 +17916,6 @@ cat <&1 | grep "No input files"` - test "x$yasmout" != x \ - && ac_cv_path_YASM=$ac_path_YASM ac_path_YASM_found=:]] - )]) -fi - -if test "x$aesni_options" != xDISABLED -a "x$ac_path_YASM_found" != xfalse; then - using_aesni="run-time detection" -elif test "$with_openssl" = "yes" -a "$cpu_family" = intel; then - using_aesni="depends on OpenSSL" -else - using_aesni=no -fi -AC_SUBST([YASM], [$ac_cv_path_YASM]) -AC_SUBST([AESNI_OS],["$aesni_os"]) -AC_SUBST([YASM_OPTIONS],["$aesni_options"]) - JTR_SYSTEMS_SPECIFIC_LOGIC dnl The size of size_t and/or off_t might change when feature macros (chosen in @@ -1091,7 +1036,7 @@ if test "`echo *_plug.c`" != "*_plug.c"; then AC_SUBST([OPENCL_PLUGFORMATS_OBJS],[`echo opencl*_plug.c | sed 's/\.c/.o/g'`]) if test "x$plug_deps" = xyes -a "x$PERL" != x ; then AC_MSG_NOTICE([creating Makefile dependencies]) - AC_SUBST([PLUGFORMATS_DEPS],[`$PERL ./plugin_deps.pl *_plug.c`]) + AC_SUBST([PLUGFORMATS_DEPS],[`$PERL ./plugin_deps.pl 2>/dev/null *_plug.c`]) fi fi @@ -1100,9 +1045,7 @@ echo "#define JOHN_BLD \"${host_os} ${CPU_BIT_STR}-bit${using_x32} ${host_cpu} $ AC_SUBST([HOST_OS],["$host_os"]) AC_CONFIG_FILES([Makefile - aes/Makefile - aes/aesni/Makefile - aes/openssl/Makefile + mbedtls/Makefile secp256k1/Makefile ed25519-donna/Makefile poly1305-donna/Makefile]) @@ -1264,7 +1207,6 @@ dnl ====================================================================== Configured for building John the Ripper ${PACKAGE_VERSION}: Target CPU ......................................... ${CPU_NAME}, ${CPU_BIT_STR}-bit ${using_endian}${using_x32} -AES-NI support ..................................... ${using_aesni} Target OS .......................................... ${host_os} Cross compiling .................................... ${cross_compiling} Legacy arch header ................................. ${ARCH_LINK} diff --git a/src/ed25519-donna/Makefile.in b/src/ed25519-donna/Makefile.in index 3235fcb68e6..d63bb27c991 100644 --- a/src/ed25519-donna/Makefile.in +++ b/src/ed25519-donna/Makefile.in @@ -8,7 +8,6 @@ CPPFLAGS = @CPPFLAGS@ CFLAGS = @CFLAGS@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ -Wno-unused-function ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@ LDFLAGS = @LDFLAGS@ @OPENSSL_LIBS@ -YASM = @YASM@ AR = @AR@ FIND = @FIND@ RM = /bin/rm -f diff --git a/src/ed25519-donna/Makefile.legacy b/src/ed25519-donna/Makefile.legacy index 4554bb1ca53..925488b8570 100644 --- a/src/ed25519-donna/Makefile.legacy +++ b/src/ed25519-donna/Makefile.legacy @@ -4,7 +4,6 @@ CXX = @CXX@ AS = gcc LD = gcc CPP = gcc -YASM = AR = ar FIND = find diff --git a/src/enpass_fmt_plug.c b/src/enpass_fmt_plug.c index d4c1fb3686a..d7536db3c3d 100644 --- a/src/enpass_fmt_plug.c +++ b/src/enpass_fmt_plug.c @@ -152,7 +152,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) #endif for (index = 0; index < count; index += batch_size) { unsigned char master[MAX_KEYS_PER_CRYPT][32]; - unsigned char output[24]; + unsigned char output[32]; unsigned char *iv_in; unsigned char iv_out[16]; int size, i; diff --git a/src/gpg_common_plug.c b/src/gpg_common_plug.c index 1afe18b23f5..878214d74b6 100644 --- a/src/gpg_common_plug.c +++ b/src/gpg_common_plug.c @@ -27,7 +27,7 @@ #include #include #include -#include /* AES_cfb128_encrypt() */ +#include "aes.h" #include "twofish.h" #include "idea-JtR.h" @@ -1199,6 +1199,7 @@ int gpg_common_check(unsigned char *keydata, int ks) unsigned char ivec[32]; unsigned char *out; int tmp = 0; + size_t tmpz = 0; uint32_t num_bits = 0; int checksumOk; int i; @@ -1237,7 +1238,7 @@ int gpg_common_check(unsigned char *keydata, int ks) case CIPHER_AES256: { AES_KEY ck; AES_set_encrypt_key(keydata, ks * 8, &ck); - AES_cfb128_encrypt(gpg_common_cur_salt->data, out, AES_BLOCK_SIZE, &ck, ivec, &tmp, AES_DECRYPT); + AES_cfb128_encrypt(gpg_common_cur_salt->data, out, AES_BLOCK_SIZE, &ck, ivec, &tmpz, AES_DECRYPT); } break; case CIPHER_3DES: { @@ -1326,12 +1327,12 @@ int gpg_common_check(unsigned char *keydata, int ks) AES_set_encrypt_key(keydata, ks * 8, &ck); block_size = 16; if (gpg_common_cur_salt->symmetric_mode && gpg_common_cur_salt->usage == 9) { - AES_cfb128_encrypt(gpg_common_cur_salt->data, out, block_size + 2, &ck, ivec, &tmp, AES_DECRYPT); - tmp = 0; + AES_cfb128_encrypt(gpg_common_cur_salt->data, out, block_size + 2, &ck, ivec, &tmpz, AES_DECRYPT); + tmpz = 0; memcpy(ivec, gpg_common_cur_salt->data + 2, block_size); - AES_cfb128_encrypt(gpg_common_cur_salt->data + block_size + 2, out + block_size + 2, gpg_common_cur_salt->datalen - block_size - 2, &ck, ivec, &tmp, AES_DECRYPT); + AES_cfb128_encrypt(gpg_common_cur_salt->data + block_size + 2, out + block_size + 2, gpg_common_cur_salt->datalen - block_size - 2, &ck, ivec, &tmpz, AES_DECRYPT); } else { - AES_cfb128_encrypt(gpg_common_cur_salt->data, out, gpg_common_cur_salt->datalen, &ck, ivec, &tmp, AES_DECRYPT); + AES_cfb128_encrypt(gpg_common_cur_salt->data, out, gpg_common_cur_salt->datalen, &ck, ivec, &tmpz, AES_DECRYPT); } } break; diff --git a/src/krb5_common.h b/src/krb5_common.h index 1eba9000f37..922031d2a10 100644 --- a/src/krb5_common.h +++ b/src/krb5_common.h @@ -10,7 +10,7 @@ void nfold(unsigned int inbits, const unsigned char *in, unsigned int outbits, unsigned char *out); void AES_cts_encrypt(const unsigned char *in, unsigned char *out, size_t len, - const AES_KEY *key, unsigned char *ivec, const int encryptp); + AES_KEY *key, unsigned char *ivec, const int encryptp); void dk(unsigned char key_out[], unsigned char key_in[], size_t key_size, unsigned char ptext[], size_t ptext_size); diff --git a/src/krb5_common_plug.c b/src/krb5_common_plug.c index fdc53f7132e..fb2b03c1b40 100644 --- a/src/krb5_common_plug.c +++ b/src/krb5_common_plug.c @@ -92,7 +92,7 @@ void nfold(unsigned int inbits, const unsigned char *in, } void AES_cts_encrypt(const unsigned char *in, unsigned char *out, size_t len, - const AES_KEY *key, unsigned char *ivec, const int encryptp) + AES_KEY *key, unsigned char *ivec, const int encryptp) { unsigned char tmp[AES_BLOCK_SIZE]; unsigned int i; diff --git a/src/listconf.c b/src/listconf.c index 4e9a5019616..085f4282a10 100644 --- a/src/listconf.c +++ b/src/listconf.c @@ -87,9 +87,12 @@ #include "john.h" #include "version.h" #include "listconf.h" /* must be included after version.h and misc.h */ - -#ifdef AESNI_IN_USE #include "aes.h" +#if defined(MBEDTLS_AESNI_C) +#include "mbedtls/aesni.h" +#endif +#if defined(MBEDTLS_AESCE_C) +#include "mbedtls/aesce.h" #endif #ifdef NO_JOHN_BLD @@ -353,16 +356,14 @@ static void listconf_list_build_info(void) printf("Terminal locale string: %s\n", john_terminal_locale); printf("Parsed terminal locale: %s\n", cp_id2name(options.terminal_enc)); -#ifdef AESNI_IN_USE - if (using_aes_asm()) - printf("AES-NI: available\n"); - else - printf("AES-NI: not supported by CPU\n"); -#elif defined(__i386__) || defined(__x86_64__) - printf("AES-NI: not built\n"); -#else - printf("AES-NI: not applicable\n"); + printf("AES hardware acceleration: %s\n", +#if defined(MBEDTLS_AESNI_HAVE_CODE) + mbedtls_aesni_has_support(MBEDTLS_AESNI_AES) ? "AES-NI" : +#endif +#if defined(MBEDTLS_AESCE_HAVE_CODE) + MBEDTLS_AESCE_HAS_SUPPORT() ? "AES-CE" : #endif + "no"); #ifdef __CYGWIN__ { diff --git a/src/mbedtls/Makefile.in b/src/mbedtls/Makefile.in new file mode 100644 index 00000000000..ddd5d9c5750 --- /dev/null +++ b/src/mbedtls/Makefile.in @@ -0,0 +1,32 @@ +@SET_MAKE@ +CC = @CC@ +AS = @CC@ +LD = @CC@ +CPP = @CC@ +CFLAGS = @CFLAGS@ @CFLAGS_EXTRA@ @JOHN_NO_SIMD@ -std=c99 +ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@ +LDFLAGS = @LDFLAGS@ +AR = @AR@ +RM = /bin/rm -f +AESIN = aesce.o aesni.o aes.o + +default: aes.a +all: aes.a + +aes.o: aes.c common.h build_info.h mbedtls_config.h alignment.h aes.h private_access.h platform_util.h platform.h error.h aesni.h aesce.h ctr.h + $(CC) $(CFLAGS) -c aes.c -o aes.o + +aesce.o: aesce.c common.h build_info.h mbedtls_config.h alignment.h aesce.h aes.h private_access.h platform_util.h + $(CC) $(CFLAGS) -c aesce.c -o aesce.o + +aesni.o: aesni.c common.h build_info.h mbedtls_config.h alignment.h aesni.h aes.h private_access.h platform_util.h + $(CC) $(CFLAGS) -c aesni.c -o aesni.o + +aes.a: $(AESIN) + $(AR) -rs aes.a $(AESIN) + +clean: + $(RM) *.a *.o + +distclean: clean + $(RM) Makefile diff --git a/src/mbedtls/Makefile.legacy b/src/mbedtls/Makefile.legacy new file mode 100644 index 00000000000..b36cc298ded --- /dev/null +++ b/src/mbedtls/Makefile.legacy @@ -0,0 +1,25 @@ +CC = gcc +AR = ar +RM = rm -f +AESIN = aesce.o aesni.o aes.o + +default: aes.a +all: aes.a + +aes.o: aes.c common.h build_info.h mbedtls_config.h alignment.h aes.h private_access.h platform_util.h platform.h error.h aesni.h aesce.h ctr.h + $(CC) $(CFLAGS) -std=c99 -c aes.c -o aes.o + +aesce.o: aesce.c common.h build_info.h mbedtls_config.h alignment.h aesce.h aes.h private_access.h platform_util.h + $(CC) $(CFLAGS) -std=c99 -c aesce.c -o aesce.o + +aesni.o: aesni.c common.h build_info.h mbedtls_config.h alignment.h aesni.h aes.h private_access.h platform_util.h + $(CC) $(CFLAGS) -std=c99 -c aesni.c -o aesni.o + +aes.a: $(AESIN) + $(AR) -rs aes.a $(AESIN) + +clean: + $(RM) *.a *.o + +distclean: clean + $(RM) Makefile diff --git a/src/mbedtls/aes.c b/src/mbedtls/aes.c index b1a5c3ed104..849aa6c9851 100644 --- a/src/mbedtls/aes.c +++ b/src/mbedtls/aes.c @@ -17,10 +17,10 @@ #include -#include "mbedtls/aes.h" -#include "mbedtls/platform.h" -#include "mbedtls/platform_util.h" -#include "mbedtls/error.h" +#include "aes.h" +#include "platform.h" +#include "platform_util.h" +#include "error.h" #if defined(MBEDTLS_AES_USE_HARDWARE_ONLY) #if !((defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_AESCE_C)) || \ @@ -52,7 +52,7 @@ #include "aesce.h" #endif -#include "mbedtls/platform.h" +#include "platform.h" #include "ctr.h" /* @@ -1076,7 +1076,7 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, const unsigned char *input, unsigned char *output) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + int ret = 0; unsigned char temp[16]; if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { @@ -1089,7 +1089,13 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, } if (length % 16) { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; + ret = MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; + /* + * For bug compatibility, chug along and return the error afterwards. + * Our old code (and eg. OpenSSL) would read and write past buffers + * just like we do here. - magnum + */ + length = (length + 15) / 16 * 16; } #if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) @@ -1281,7 +1287,7 @@ int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, mbedtls_xor(prev_output, tmp, t, 16); } - return 0; + return ret; } #endif /* MBEDTLS_CIPHER_MODE_XTS */ diff --git a/src/mbedtls/aes.h b/src/mbedtls/aes.h index d5eb1fd5c2c..9c4f594c810 100644 --- a/src/mbedtls/aes.h +++ b/src/mbedtls/aes.h @@ -27,10 +27,10 @@ #ifndef MBEDTLS_AES_H #define MBEDTLS_AES_H -#include "mbedtls/private_access.h" +#include "private_access.h" -#include "mbedtls/build_info.h" -#include "mbedtls/platform_util.h" +#include "build_info.h" +#include "platform_util.h" #include #include diff --git a/src/mbedtls/aesce.h b/src/mbedtls/aesce.h index a14d085efa2..65624c49910 100644 --- a/src/mbedtls/aesce.h +++ b/src/mbedtls/aesce.h @@ -14,10 +14,10 @@ #ifndef MBEDTLS_AESCE_H #define MBEDTLS_AESCE_H -#include "mbedtls/build_info.h" +#include "build_info.h" #include "common.h" -#include "mbedtls/aes.h" +#include "aes.h" #if defined(MBEDTLS_AESCE_C) \ diff --git a/src/mbedtls/aesni.h b/src/mbedtls/aesni.h index 59e27afd3ec..6ce48a1f1f9 100644 --- a/src/mbedtls/aesni.h +++ b/src/mbedtls/aesni.h @@ -13,9 +13,9 @@ #ifndef MBEDTLS_AESNI_H #define MBEDTLS_AESNI_H -#include "mbedtls/build_info.h" +#include "build_info.h" -#include "mbedtls/aes.h" +#include "aes.h" #define MBEDTLS_AESNI_AES 0x02000000u #define MBEDTLS_AESNI_CLMUL 0x00000002u diff --git a/src/mbedtls/build_info.h b/src/mbedtls/build_info.h index d91d2964b6a..b8801cc3aff 100644 --- a/src/mbedtls/build_info.h +++ b/src/mbedtls/build_info.h @@ -110,7 +110,7 @@ /* X.509, TLS and non-PSA crypto configuration */ #if !defined(MBEDTLS_CONFIG_FILE) -#include "mbedtls/mbedtls_config.h" +#include "mbedtls_config.h" #else #include MBEDTLS_CONFIG_FILE #endif @@ -173,14 +173,14 @@ #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) /* PSA_WANT_xxx influences MBEDTLS_xxx */ || \ defined(MBEDTLS_PSA_CRYPTO_C) /* MBEDTLS_xxx influences PSA_WANT_xxx */ || \ defined(MBEDTLS_PSA_CRYPTO_CLIENT) /* The same as the previous, but with separation only */ -#include "mbedtls/config_psa.h" +#include "config_psa.h" #endif -#include "mbedtls/config_adjust_legacy_crypto.h" +//#include "config_adjust_legacy_crypto.h" -#include "mbedtls/config_adjust_x509.h" +//#include "config_adjust_x509.h" -#include "mbedtls/config_adjust_ssl.h" +//#include "config_adjust_ssl.h" /* Indicate that all configuration symbols are set, * even the ones that are calculated programmatically. @@ -189,6 +189,6 @@ */ #define MBEDTLS_CONFIG_IS_FINALIZED -#include "mbedtls/check_config.h" +//#include "check_config.h" #endif /* MBEDTLS_BUILD_INFO_H */ diff --git a/src/mbedtls/common.h b/src/mbedtls/common.h index 7bb26742930..917ac4bc448 100644 --- a/src/mbedtls/common.h +++ b/src/mbedtls/common.h @@ -11,7 +11,7 @@ #ifndef MBEDTLS_LIBRARY_COMMON_H #define MBEDTLS_LIBRARY_COMMON_H -#include "mbedtls/build_info.h" +#include "build_info.h" #include "alignment.h" #include diff --git a/src/mbedtls/error.h b/src/mbedtls/error.h index 186589ac5bc..d084b44cbd2 100644 --- a/src/mbedtls/error.h +++ b/src/mbedtls/error.h @@ -10,7 +10,7 @@ #ifndef MBEDTLS_ERROR_H #define MBEDTLS_ERROR_H -#include "mbedtls/build_info.h" +#include "build_info.h" #include diff --git a/src/mbedtls/mbedtls_config.h b/src/mbedtls/mbedtls_config.h index bd3f71d5bc9..c721d03a7d1 100644 --- a/src/mbedtls/mbedtls_config.h +++ b/src/mbedtls/mbedtls_config.h @@ -128,7 +128,7 @@ * regardless of the setting of MBEDTLS_HAVE_TIME, unless * MBEDTLS_TIMING_ALT is used. See timing.c for more information. */ -#define MBEDTLS_HAVE_TIME +//#define MBEDTLS_HAVE_TIME /** * \def MBEDTLS_HAVE_TIME_DATE @@ -149,7 +149,7 @@ * mbedtls_platform_gmtime_r() at compile-time by using the macro * MBEDTLS_PLATFORM_GMTIME_R_ALT. */ -#define MBEDTLS_HAVE_TIME_DATE +//#define MBEDTLS_HAVE_TIME_DATE /** * \def MBEDTLS_PLATFORM_MEMORY @@ -757,20 +757,20 @@ * Comment macros to disable the curve and functions for it */ /* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */ -#define MBEDTLS_ECP_DP_SECP192R1_ENABLED -#define MBEDTLS_ECP_DP_SECP224R1_ENABLED -#define MBEDTLS_ECP_DP_SECP256R1_ENABLED -#define MBEDTLS_ECP_DP_SECP384R1_ENABLED -#define MBEDTLS_ECP_DP_SECP521R1_ENABLED -#define MBEDTLS_ECP_DP_SECP192K1_ENABLED -#define MBEDTLS_ECP_DP_SECP224K1_ENABLED -#define MBEDTLS_ECP_DP_SECP256K1_ENABLED -#define MBEDTLS_ECP_DP_BP256R1_ENABLED -#define MBEDTLS_ECP_DP_BP384R1_ENABLED -#define MBEDTLS_ECP_DP_BP512R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP192R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP224R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP384R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP521R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP192K1_ENABLED +//#define MBEDTLS_ECP_DP_SECP224K1_ENABLED +//#define MBEDTLS_ECP_DP_SECP256K1_ENABLED +//#define MBEDTLS_ECP_DP_BP256R1_ENABLED +//#define MBEDTLS_ECP_DP_BP384R1_ENABLED +//#define MBEDTLS_ECP_DP_BP512R1_ENABLED /* Montgomery curves (supporting ECP) */ -#define MBEDTLS_ECP_DP_CURVE25519_ENABLED -#define MBEDTLS_ECP_DP_CURVE448_ENABLED +//#define MBEDTLS_ECP_DP_CURVE25519_ENABLED +//#define MBEDTLS_ECP_DP_CURVE448_ENABLED /** * \def MBEDTLS_ECP_NIST_OPTIM @@ -781,7 +781,7 @@ * * Comment this macro to disable NIST curves optimisation. */ -#define MBEDTLS_ECP_NIST_OPTIM +//#define MBEDTLS_ECP_NIST_OPTIM /** * \def MBEDTLS_ECP_RESTARTABLE @@ -858,7 +858,7 @@ * * Comment this macro to disable deterministic ECDSA. */ -#define MBEDTLS_ECDSA_DETERMINISTIC +//#define MBEDTLS_ECDSA_DETERMINISTIC /** * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED @@ -878,7 +878,7 @@ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED @@ -907,7 +907,7 @@ * See dhm.h for more details. * */ -#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED @@ -925,7 +925,7 @@ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED @@ -948,7 +948,7 @@ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED @@ -973,7 +973,7 @@ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ -#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED @@ -1005,7 +1005,7 @@ * See dhm.h for more details. * */ -#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED @@ -1030,7 +1030,7 @@ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED @@ -1054,7 +1054,7 @@ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED @@ -1078,7 +1078,7 @@ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */ -#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED @@ -1102,7 +1102,7 @@ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */ -#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED +//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED /** * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED @@ -1139,7 +1139,7 @@ * * Disable if you only need to support RFC 5915 + 5480 key formats. */ -#define MBEDTLS_PK_PARSE_EC_EXTENDED +//#define MBEDTLS_PK_PARSE_EC_EXTENDED /** * \def MBEDTLS_PK_PARSE_EC_COMPRESSED @@ -1152,7 +1152,7 @@ * the only unsupported curves are MBEDTLS_ECP_DP_SECP224R1 and * MBEDTLS_ECP_DP_SECP224K1. */ -#define MBEDTLS_PK_PARSE_EC_COMPRESSED +//#define MBEDTLS_PK_PARSE_EC_COMPRESSED /** * \def MBEDTLS_ERROR_STRERROR_DUMMY @@ -1167,7 +1167,7 @@ * Disable if you run into name conflicts and want to really remove the * mbedtls_strerror() */ -#define MBEDTLS_ERROR_STRERROR_DUMMY +//#define MBEDTLS_ERROR_STRERROR_DUMMY /** * \def MBEDTLS_GENPRIME @@ -1176,14 +1176,14 @@ * * Requires: MBEDTLS_BIGNUM_C */ -#define MBEDTLS_GENPRIME +//#define MBEDTLS_GENPRIME /** * \def MBEDTLS_FS_IO * * Enable functions that use the filesystem. */ -#define MBEDTLS_FS_IO +//#define MBEDTLS_FS_IO /** * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES @@ -1296,7 +1296,7 @@ * * Comment this macro to disable support for external private RSA keys. */ -#define MBEDTLS_PK_RSA_ALT_SUPPORT +//#define MBEDTLS_PK_RSA_ALT_SUPPORT /** * \def MBEDTLS_PKCS1_V15 @@ -1307,7 +1307,7 @@ * * This enables support for PKCS#1 v1.5 operations. */ -#define MBEDTLS_PKCS1_V15 +//#define MBEDTLS_PKCS1_V15 /** * \def MBEDTLS_PKCS1_V21 @@ -1321,7 +1321,7 @@ * * This enables support for RSAES-OAEP and RSASSA-PSS operations. */ -#define MBEDTLS_PKCS1_V21 +//#define MBEDTLS_PKCS1_V21 /** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS * @@ -1429,7 +1429,7 @@ * Module: library/psa_crypto.c * Requires: MBEDTLS_PSA_CRYPTO_C */ -#define MBEDTLS_PSA_KEY_STORE_DYNAMIC +//#define MBEDTLS_PSA_KEY_STORE_DYNAMIC /** * Uncomment to enable p256-m. This is an alternative implementation of @@ -1521,7 +1521,7 @@ * * Enable the checkup functions (*_self_test). */ -#define MBEDTLS_SELF_TEST +//#define MBEDTLS_SELF_TEST /** * \def MBEDTLS_SHA256_SMALLER @@ -1561,7 +1561,7 @@ * * Enable sending of all alert messages */ -#define MBEDTLS_SSL_ALL_ALERT_MESSAGES +//#define MBEDTLS_SSL_ALL_ALERT_MESSAGES /** * \def MBEDTLS_SSL_DTLS_CONNECTION_ID @@ -1585,7 +1585,7 @@ * * Uncomment to enable the Connection ID extension. */ -#define MBEDTLS_SSL_DTLS_CONNECTION_ID +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID /** @@ -1608,7 +1608,7 @@ * * Requires: MBEDTLS_SSL_DTLS_CONNECTION_ID */ -#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 /** * \def MBEDTLS_SSL_ASYNC_PRIVATE @@ -1649,7 +1649,7 @@ * * Comment to disable the context serialization APIs. */ -#define MBEDTLS_SSL_CONTEXT_SERIALIZATION +//#define MBEDTLS_SSL_CONTEXT_SERIALIZATION /** * \def MBEDTLS_SSL_DEBUG_ALL @@ -1681,7 +1681,7 @@ * * Comment this macro to disable support for Encrypt-then-MAC */ -#define MBEDTLS_SSL_ENCRYPT_THEN_MAC +//#define MBEDTLS_SSL_ENCRYPT_THEN_MAC /** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET * @@ -1697,7 +1697,7 @@ * * Comment this macro to disable support for Extended Master Secret. */ -#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET +//#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET /** * \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE @@ -1721,7 +1721,7 @@ * Comment this macro to disable storing the peer's certificate * after the handshake. */ -#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE +//#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE /** * \def MBEDTLS_SSL_RENEGOTIATION @@ -1745,7 +1745,7 @@ * configuration of this extension). * */ -#define MBEDTLS_SSL_RENEGOTIATION +//#define MBEDTLS_SSL_RENEGOTIATION /** * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH @@ -1754,7 +1754,7 @@ * * Comment this macro to disable support for the max_fragment_length extension */ -#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +//#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH /** * \def MBEDTLS_SSL_RECORD_SIZE_LIMIT @@ -1784,7 +1784,7 @@ * * Comment this macro to disable support for TLS 1.2 / DTLS 1.2 */ -#define MBEDTLS_SSL_PROTO_TLS1_2 +//#define MBEDTLS_SSL_PROTO_TLS1_2 /** * \def MBEDTLS_SSL_PROTO_TLS1_3 @@ -1809,7 +1809,7 @@ * * Uncomment this macro to enable the support for TLS 1.3. */ -#define MBEDTLS_SSL_PROTO_TLS1_3 +//#define MBEDTLS_SSL_PROTO_TLS1_3 /** * \def MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE @@ -1831,7 +1831,7 @@ * effect on the build. * */ -#define MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE +//#define MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE /** * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED @@ -1843,7 +1843,7 @@ * effect on the build. * */ -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED +//#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED /** * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED @@ -1861,7 +1861,7 @@ * effect on the build. * */ -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +//#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED /** * \def MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED @@ -1875,7 +1875,7 @@ * have any effect on the build. * */ -#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED +//#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED /** * \def MBEDTLS_SSL_EARLY_DATA @@ -1906,7 +1906,7 @@ * * Comment this macro to disable support for DTLS */ -#define MBEDTLS_SSL_PROTO_DTLS +//#define MBEDTLS_SSL_PROTO_DTLS /** * \def MBEDTLS_SSL_ALPN @@ -1915,7 +1915,7 @@ * * Comment this macro to disable support for ALPN. */ -#define MBEDTLS_SSL_ALPN +//#define MBEDTLS_SSL_ALPN /** * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY @@ -1930,7 +1930,7 @@ * * Comment this to disable anti-replay in DTLS. */ -#define MBEDTLS_SSL_DTLS_ANTI_REPLAY +//#define MBEDTLS_SSL_DTLS_ANTI_REPLAY /** * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY @@ -1948,7 +1948,7 @@ * * Comment this to disable support for HelloVerifyRequest. */ -#define MBEDTLS_SSL_DTLS_HELLO_VERIFY +//#define MBEDTLS_SSL_DTLS_HELLO_VERIFY /** * \def MBEDTLS_SSL_DTLS_SRTP @@ -1995,7 +1995,7 @@ * * Comment this to disable support for clients reusing the source port. */ -#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE +//#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE /** * \def MBEDTLS_SSL_SESSION_TICKETS @@ -2009,7 +2009,7 @@ * * Comment this macro to disable support for SSL session tickets */ -#define MBEDTLS_SSL_SESSION_TICKETS +//#define MBEDTLS_SSL_SESSION_TICKETS /** * \def MBEDTLS_SSL_SERVER_NAME_INDICATION @@ -2020,7 +2020,7 @@ * * Comment this macro to disable support for server name indication in SSL */ -#define MBEDTLS_SSL_SERVER_NAME_INDICATION +//#define MBEDTLS_SSL_SERVER_NAME_INDICATION /** * \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH @@ -2183,7 +2183,7 @@ * * Comment this to disable run-time checking and save ROM space */ -#define MBEDTLS_VERSION_FEATURES +//#define MBEDTLS_VERSION_FEATURES /** * \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK @@ -2227,7 +2227,7 @@ * * Comment this macro to disallow using RSASSA-PSS in certificates. */ -#define MBEDTLS_X509_RSASSA_PSS_SUPPORT +//#define MBEDTLS_X509_RSASSA_PSS_SUPPORT /** \} name SECTION: Mbed TLS feature support */ /** @@ -2267,7 +2267,9 @@ * * This modules adds support for the AES-NI instructions on x86. */ +#ifndef JOHN_NO_SIMD #define MBEDTLS_AESNI_C +#endif /** * \def MBEDTLS_AESCE_C @@ -2293,7 +2295,9 @@ * * This module adds support for the AES Armv8-A Cryptographic Extensions on Armv8 systems. */ +#ifndef JOHN_NO_SIMD #define MBEDTLS_AESCE_C +#endif /** * \def MBEDTLS_AES_C @@ -2382,7 +2386,7 @@ * library/pkcs5.c * library/pkparse.c */ -#define MBEDTLS_ASN1_PARSE_C +//#define MBEDTLS_ASN1_PARSE_C /** * \def MBEDTLS_ASN1_WRITE_C @@ -2396,7 +2400,7 @@ * library/x509write_crt.c * library/x509write_csr.c */ -#define MBEDTLS_ASN1_WRITE_C +//#define MBEDTLS_ASN1_WRITE_C /** * \def MBEDTLS_BASE64_C @@ -2408,7 +2412,7 @@ * * This module is required for PEM support (required by X.509). */ -#define MBEDTLS_BASE64_C +//#define MBEDTLS_BASE64_C /** * \def MBEDTLS_BLOCK_CIPHER_NO_DECRYPT @@ -2450,7 +2454,7 @@ * * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support. */ -#define MBEDTLS_BIGNUM_C +//#define MBEDTLS_BIGNUM_C /** * \def MBEDTLS_CAMELLIA_C @@ -2505,7 +2509,7 @@ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */ -#define MBEDTLS_CAMELLIA_C +//#define MBEDTLS_CAMELLIA_C /** * \def MBEDTLS_ARIA_C @@ -2557,7 +2561,7 @@ * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 */ -#define MBEDTLS_ARIA_C +//#define MBEDTLS_ARIA_C /** * \def MBEDTLS_CCM_C @@ -2581,7 +2585,7 @@ * * Module: library/chacha20.c */ -#define MBEDTLS_CHACHA20_C +//#define MBEDTLS_CHACHA20_C /** * \def MBEDTLS_CHACHAPOLY_C @@ -2592,7 +2596,7 @@ * * This module requires: MBEDTLS_CHACHA20_C, MBEDTLS_POLY1305_C */ -#define MBEDTLS_CHACHAPOLY_C +//#define MBEDTLS_CHACHAPOLY_C /** * \def MBEDTLS_CIPHER_C @@ -2616,7 +2620,7 @@ * * Uncomment to enable generic cipher wrappers. */ -#define MBEDTLS_CIPHER_C +//#define MBEDTLS_CIPHER_C /** * \def MBEDTLS_CMAC_C @@ -2634,7 +2638,7 @@ * Requires: MBEDTLS_CIPHER_C, MBEDTLS_AES_C or MBEDTLS_DES_C * */ -#define MBEDTLS_CMAC_C +//#define MBEDTLS_CMAC_C /** * \def MBEDTLS_CTR_DRBG_C @@ -2665,7 +2669,7 @@ * * This module provides the CTR_DRBG AES random number generator. */ -#define MBEDTLS_CTR_DRBG_C +//#define MBEDTLS_CTR_DRBG_C /** * \def MBEDTLS_DEBUG_C @@ -2680,7 +2684,7 @@ * * This module provides debugging functions. */ -#define MBEDTLS_DEBUG_C +//#define MBEDTLS_DEBUG_C /** * \def MBEDTLS_DES_C @@ -2696,7 +2700,7 @@ * \warning DES/3DES are considered weak ciphers and their use constitutes a * security risk. We recommend considering stronger ciphers instead. */ -#define MBEDTLS_DES_C +//#define MBEDTLS_DES_C /** * \def MBEDTLS_DHM_C @@ -2718,7 +2722,7 @@ * See dhm.h for more details. * */ -#define MBEDTLS_DHM_C +//#define MBEDTLS_DHM_C /** * \def MBEDTLS_ECDH_C @@ -2736,7 +2740,7 @@ * * Requires: MBEDTLS_ECP_C */ -#define MBEDTLS_ECDH_C +//#define MBEDTLS_ECDH_C /** * \def MBEDTLS_ECDSA_C @@ -2753,7 +2757,7 @@ * and at least one MBEDTLS_ECP_DP_XXX_ENABLED for a * short Weierstrass curve. */ -#define MBEDTLS_ECDSA_C +//#define MBEDTLS_ECDSA_C /** * \def MBEDTLS_ECJPAKE_C @@ -2775,7 +2779,7 @@ * \warning If using a hash that is only provided by PSA drivers, you must * call psa_crypto_init() before doing any EC J-PAKE operations. */ -#define MBEDTLS_ECJPAKE_C +//#define MBEDTLS_ECJPAKE_C /** * \def MBEDTLS_ECP_C @@ -2789,7 +2793,7 @@ * * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED */ -#define MBEDTLS_ECP_C +//#define MBEDTLS_ECP_C /** * \def MBEDTLS_ENTROPY_C @@ -2803,7 +2807,7 @@ * * This module provides a generic entropy pool */ -#define MBEDTLS_ENTROPY_C +//#define MBEDTLS_ENTROPY_C /** * \def MBEDTLS_ERROR_C @@ -2815,7 +2819,7 @@ * * This module enables mbedtls_strerror(). */ -#define MBEDTLS_ERROR_C +//#define MBEDTLS_ERROR_C /** * \def MBEDTLS_GCM_C @@ -2846,7 +2850,7 @@ * * Requires: MBEDTLS_GCM_C */ -//#define MBEDTLS_GCM_LARGE_TABLE +#define MBEDTLS_GCM_LARGE_TABLE /** * \def MBEDTLS_HKDF_C @@ -2861,7 +2865,7 @@ * This module adds support for the Hashed Message Authentication Code * (HMAC)-based key derivation function (HKDF). */ -#define MBEDTLS_HKDF_C +//#define MBEDTLS_HKDF_C /** * \def MBEDTLS_HMAC_DRBG_C @@ -2875,7 +2879,7 @@ * * Uncomment to enable the HMAC_DRBG random number generator. */ -#define MBEDTLS_HMAC_DRBG_C +//#define MBEDTLS_HMAC_DRBG_C /** * \def MBEDTLS_LMS_C @@ -2889,7 +2893,7 @@ * * Uncomment to enable the LMS verification algorithm and public key operations. */ -#define MBEDTLS_LMS_C +//#define MBEDTLS_LMS_C /** * \def MBEDTLS_LMS_PRIVATE @@ -2914,7 +2918,7 @@ * * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C */ -#define MBEDTLS_NIST_KW_C +//#define MBEDTLS_NIST_KW_C /** * \def MBEDTLS_MD_C @@ -2947,7 +2951,7 @@ * * Uncomment to enable generic message digest wrappers. */ -#define MBEDTLS_MD_C +//#define MBEDTLS_MD_C /** * \def MBEDTLS_MD5_C @@ -2968,7 +2972,7 @@ * it, and considering stronger message digests instead. * */ -#define MBEDTLS_MD5_C +//#define MBEDTLS_MD5_C /** * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C @@ -3003,7 +3007,7 @@ * * This module provides networking routines. */ -#define MBEDTLS_NET_C +//#define MBEDTLS_NET_C /** * \def MBEDTLS_OID_C @@ -3026,7 +3030,7 @@ * * This modules translates between OIDs and internal values. */ -#define MBEDTLS_OID_C +//#define MBEDTLS_OID_C /** * \def MBEDTLS_PADLOCK_C @@ -3040,7 +3044,7 @@ * * This modules adds support for the VIA PadLock on x86. */ -#define MBEDTLS_PADLOCK_C +//#define MBEDTLS_PADLOCK_C /** * \def MBEDTLS_PEM_PARSE_C @@ -3062,7 +3066,7 @@ * * This modules adds support for decoding / parsing PEM files. */ -#define MBEDTLS_PEM_PARSE_C +//#define MBEDTLS_PEM_PARSE_C /** * \def MBEDTLS_PEM_WRITE_C @@ -3078,7 +3082,7 @@ * * This modules adds support for encoding / writing PEM files. */ -#define MBEDTLS_PEM_WRITE_C +//#define MBEDTLS_PEM_WRITE_C /** * \def MBEDTLS_PK_C @@ -3096,7 +3100,7 @@ * * Uncomment to enable generic public key wrappers. */ -#define MBEDTLS_PK_C +//#define MBEDTLS_PK_C /** * \def MBEDTLS_PK_PARSE_C @@ -3111,7 +3115,7 @@ * * Uncomment to enable generic public key parse functions. */ -#define MBEDTLS_PK_PARSE_C +//#define MBEDTLS_PK_PARSE_C /** * \def MBEDTLS_PK_WRITE_C @@ -3125,7 +3129,7 @@ * * Uncomment to enable generic public key write functions. */ -#define MBEDTLS_PK_WRITE_C +//#define MBEDTLS_PK_WRITE_C /** * \def MBEDTLS_PKCS5_C @@ -3141,7 +3145,7 @@ * * This module adds support for the PKCS#5 functions. */ -#define MBEDTLS_PKCS5_C +//#define MBEDTLS_PKCS5_C /** * \def MBEDTLS_PKCS7_C @@ -3157,7 +3161,7 @@ * * This module is required for the PKCS #7 parsing modules. */ -#define MBEDTLS_PKCS7_C +//#define MBEDTLS_PKCS7_C /** * \def MBEDTLS_PKCS12_C @@ -3176,7 +3180,7 @@ * * This module enables PKCS#12 functions. */ -#define MBEDTLS_PKCS12_C +//#define MBEDTLS_PKCS12_C /** * \def MBEDTLS_PLATFORM_C @@ -3196,7 +3200,7 @@ * * This module enables abstraction of common (libc) functions. */ -#define MBEDTLS_PLATFORM_C +//#define MBEDTLS_PLATFORM_C /** * \def MBEDTLS_POLY1305_C @@ -3206,7 +3210,7 @@ * Module: library/poly1305.c * Caller: library/chachapoly.c */ -#define MBEDTLS_POLY1305_C +//#define MBEDTLS_POLY1305_C /** * \def MBEDTLS_PSA_CRYPTO_C @@ -3222,7 +3226,7 @@ * is enabled in PSA (unless it's fully accelerated, see * docs/driver-only-builds.md about that). */ -#define MBEDTLS_PSA_CRYPTO_C +//#define MBEDTLS_PSA_CRYPTO_C /** * \def MBEDTLS_PSA_CRYPTO_SE_C @@ -3254,7 +3258,7 @@ * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of * the PSA ITS interface */ -#define MBEDTLS_PSA_CRYPTO_STORAGE_C +//#define MBEDTLS_PSA_CRYPTO_STORAGE_C /** * \def MBEDTLS_PSA_ITS_FILE_C @@ -3266,7 +3270,7 @@ * * Requires: MBEDTLS_FS_IO */ -#define MBEDTLS_PSA_ITS_FILE_C +//#define MBEDTLS_PSA_ITS_FILE_C /** * \def MBEDTLS_RIPEMD160_C @@ -3277,7 +3281,7 @@ * Caller: library/md.c * */ -#define MBEDTLS_RIPEMD160_C +//#define MBEDTLS_RIPEMD160_C /** * \def MBEDTLS_RSA_C @@ -3297,7 +3301,7 @@ * * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C */ -#define MBEDTLS_RSA_C +//#define MBEDTLS_RSA_C /** * \def MBEDTLS_SHA1_C @@ -3316,7 +3320,7 @@ * on it, and considering stronger message digests instead. * */ -#define MBEDTLS_SHA1_C +//#define MBEDTLS_SHA1_C /** * \def MBEDTLS_SHA224_C @@ -3329,7 +3333,7 @@ * * This module adds support for SHA-224. */ -#define MBEDTLS_SHA224_C +//#define MBEDTLS_SHA224_C /** * \def MBEDTLS_SHA256_C @@ -3346,7 +3350,7 @@ * This module adds support for SHA-256. * This module is required for the SSL/TLS 1.2 PRF function. */ -#define MBEDTLS_SHA256_C +//#define MBEDTLS_SHA256_C /** * \def MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT @@ -3444,7 +3448,7 @@ * * Comment to disable SHA-384 */ -#define MBEDTLS_SHA384_C +//#define MBEDTLS_SHA384_C /** * \def MBEDTLS_SHA512_C @@ -3459,7 +3463,7 @@ * * This module adds support for SHA-512. */ -#define MBEDTLS_SHA512_C +//#define MBEDTLS_SHA512_C /** * \def MBEDTLS_SHA3_C @@ -3470,7 +3474,7 @@ * * This module adds support for SHA3. */ -#define MBEDTLS_SHA3_C +//#define MBEDTLS_SHA3_C /** * \def MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT @@ -3538,7 +3542,7 @@ * * Requires: MBEDTLS_SSL_CACHE_C */ -#define MBEDTLS_SSL_CACHE_C +//#define MBEDTLS_SSL_CACHE_C /** * \def MBEDTLS_SSL_COOKIE_C @@ -3548,7 +3552,7 @@ * Module: library/ssl_cookie.c * Caller: */ -#define MBEDTLS_SSL_COOKIE_C +//#define MBEDTLS_SSL_COOKIE_C /** * \def MBEDTLS_SSL_TICKET_C @@ -3561,7 +3565,7 @@ * Requires: (MBEDTLS_CIPHER_C || MBEDTLS_USE_PSA_CRYPTO) && * (MBEDTLS_GCM_C || MBEDTLS_CCM_C || MBEDTLS_CHACHAPOLY_C) */ -#define MBEDTLS_SSL_TICKET_C +//#define MBEDTLS_SSL_TICKET_C /** * \def MBEDTLS_SSL_CLI_C @@ -3575,7 +3579,7 @@ * * This module is required for SSL/TLS client support. */ -#define MBEDTLS_SSL_CLI_C +//#define MBEDTLS_SSL_CLI_C /** * \def MBEDTLS_SSL_SRV_C @@ -3589,7 +3593,7 @@ * * This module is required for SSL/TLS server support. */ -#define MBEDTLS_SSL_SRV_C +//#define MBEDTLS_SSL_SRV_C /** * \def MBEDTLS_SSL_TLS_C @@ -3605,7 +3609,7 @@ * * This module is required for SSL/TLS. */ -#define MBEDTLS_SSL_TLS_C +//#define MBEDTLS_SSL_TLS_C /** * \def MBEDTLS_THREADING_C @@ -3651,7 +3655,7 @@ * * Module: library/timing.c */ -#define MBEDTLS_TIMING_C +//#define MBEDTLS_TIMING_C /** * \def MBEDTLS_VERSION_C @@ -3662,7 +3666,7 @@ * * This module provides run-time version information. */ -#define MBEDTLS_VERSION_C +//#define MBEDTLS_VERSION_C /** * \def MBEDTLS_X509_USE_C @@ -3682,7 +3686,7 @@ * * This module is required for the X.509 parsing modules. */ -#define MBEDTLS_X509_USE_C +//#define MBEDTLS_X509_USE_C /** * \def MBEDTLS_X509_CRT_PARSE_C @@ -3698,7 +3702,7 @@ * * This module is required for X.509 certificate parsing. */ -#define MBEDTLS_X509_CRT_PARSE_C +//#define MBEDTLS_X509_CRT_PARSE_C /** * \def MBEDTLS_X509_CRL_PARSE_C @@ -3712,7 +3716,7 @@ * * This module is required for X.509 CRL parsing. */ -#define MBEDTLS_X509_CRL_PARSE_C +//#define MBEDTLS_X509_CRL_PARSE_C /** * \def MBEDTLS_X509_CSR_PARSE_C @@ -3726,7 +3730,7 @@ * * This module is used for reading X.509 certificate request. */ -#define MBEDTLS_X509_CSR_PARSE_C +//#define MBEDTLS_X509_CSR_PARSE_C /** * \def MBEDTLS_X509_CREATE_C @@ -3743,7 +3747,7 @@ * * This module is the basis for creating X.509 certificates and CSRs. */ -#define MBEDTLS_X509_CREATE_C +//#define MBEDTLS_X509_CREATE_C /** * \def MBEDTLS_X509_CRT_WRITE_C @@ -3756,7 +3760,7 @@ * * This module is required for X.509 certificate creation. */ -#define MBEDTLS_X509_CRT_WRITE_C +//#define MBEDTLS_X509_CRT_WRITE_C /** * \def MBEDTLS_X509_CSR_WRITE_C @@ -3769,7 +3773,7 @@ * * This module is required for X.509 certificate request writing. */ -#define MBEDTLS_X509_CSR_WRITE_C +//#define MBEDTLS_X509_CSR_WRITE_C /** \} name SECTION: Mbed TLS modules */ diff --git a/src/mbedtls/platform.h b/src/mbedtls/platform.h index de3d71d9dc5..05310e10a16 100644 --- a/src/mbedtls/platform.h +++ b/src/mbedtls/platform.h @@ -25,12 +25,12 @@ */ #ifndef MBEDTLS_PLATFORM_H #define MBEDTLS_PLATFORM_H -#include "mbedtls/private_access.h" +#include "private_access.h" -#include "mbedtls/build_info.h" +#include "build_info.h" #if defined(MBEDTLS_HAVE_TIME) -#include "mbedtls/platform_time.h" +#include "platform_time.h" #endif #ifdef __cplusplus diff --git a/src/mbedtls/platform_util.h b/src/mbedtls/platform_util.h index 1b371ef3f46..e5af4a44f14 100644 --- a/src/mbedtls/platform_util.h +++ b/src/mbedtls/platform_util.h @@ -11,11 +11,11 @@ #ifndef MBEDTLS_PLATFORM_UTIL_H #define MBEDTLS_PLATFORM_UTIL_H -#include "mbedtls/build_info.h" +#include "build_info.h" #include #if defined(MBEDTLS_HAVE_TIME_DATE) -#include "mbedtls/platform_time.h" +#include "platform_time.h" #include #endif /* MBEDTLS_HAVE_TIME_DATE */ @@ -156,7 +156,10 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; * \param len Length of the buffer in bytes * */ -void mbedtls_platform_zeroize(void *buf, size_t len); +//void mbedtls_platform_zeroize(void *buf, size_t len); + +#define mbedtls_platform_zeroize(buf, len) + #endif #if defined(MBEDTLS_HAVE_TIME_DATE) diff --git a/src/o5logon_fmt_plug.c b/src/o5logon_fmt_plug.c index f60cc265e94..498f2d6b1f6 100644 --- a/src/o5logon_fmt_plug.c +++ b/src/o5logon_fmt_plug.c @@ -87,12 +87,8 @@ static struct custom_salt { int pw_len; /* AUTH_PASSWORD length (blocks) */ } *cur_salt; -static aes_fptr_cbc aesDec, aesEnc; - static void init(struct fmt_main *self) { - static char Buf[128]; - omp_autotune(self, OMP_SCALE); saved_key = mem_calloc(self->params.max_keys_per_crypt, @@ -101,14 +97,6 @@ static void init(struct fmt_main *self) sizeof(*saved_len)); cracked = mem_calloc(self->params.max_keys_per_crypt, sizeof(*cracked)); - - if (!*aesDec) { - aesDec = get_AES_dec192_CBC(); - aesEnc = get_AES_enc192_CBC(); - sprintf(Buf, "%s %s", self->params.algorithm_name, - get_AES_type_string()); - self->params.algorithm_name=Buf; - } } static void done(void) @@ -214,6 +202,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) for (index = 0; index < count; index++) { unsigned char key[24]; unsigned char iv[16]; + AES_KEY akey; SHA_CTX ctx; SHA1_Init(&ctx); @@ -235,10 +224,12 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (cur_salt->pw_len == blen) { memset(iv, 0, 16); - aesDec(cur_salt->ct, s_secret, key, 3, iv); + AES_set_decrypt_key(key, 192, &akey); + AES_cbc_encrypt(cur_salt->ct, s_secret, 48, &akey, iv, AES_DECRYPT); memset(iv, 0, 16); - aesDec(cur_salt->csk, c_secret, key, 3, iv); + AES_set_decrypt_key(key, 192, &akey); + AES_cbc_encrypt(cur_salt->csk, c_secret, 48, &akey, iv, AES_DECRYPT); for (i = 0; i < 24; i++) combined_sk[i] = s_secret[16 + i] ^ c_secret[16 + i]; @@ -251,8 +242,8 @@ static int crypt_all(int *pcount, struct db_salt *salt) MD5_Final(final_key + 16, &ctx); memset(iv, 0, 16); - aesDec(cur_salt->pw, password, final_key, - cur_salt->pw_len + 1, iv); + AES_set_decrypt_key(final_key, 192, &akey); + AES_cbc_encrypt(cur_salt->pw, password, (cur_salt->pw_len + 1) * 16, &akey, iv, AES_DECRYPT); if (!memcmp(dec_pw, saved_key[index], saved_len[index])) { @@ -281,7 +272,8 @@ static int crypt_all(int *pcount, struct db_salt *salt) unsigned char pt[16]; memcpy(iv, cur_salt->ct + 16, 16); - aesDec(cur_salt->ct + 32, pt, key, 1, iv); + AES_set_decrypt_key(key, 192, &akey); + AES_cbc_encrypt(cur_salt->ct + 32, pt, 16, &akey, iv, AES_DECRYPT); if (!memcmp(pt + 8, "\x08\x08\x08\x08\x08\x08\x08\x08", 8)) { diff --git a/src/poly1305-donna/Makefile.legacy b/src/poly1305-donna/Makefile.legacy index 2e1e14f5115..c06b40633df 100644 --- a/src/poly1305-donna/Makefile.legacy +++ b/src/poly1305-donna/Makefile.legacy @@ -4,7 +4,6 @@ CXX = @CXX@ AS = gcc LD = gcc CPP = gcc -YASM = AR = ar FIND = find diff --git a/src/secp256k1/Makefile.in b/src/secp256k1/Makefile.in index b93ab949241..3da80798293 100644 --- a/src/secp256k1/Makefile.in +++ b/src/secp256k1/Makefile.in @@ -7,7 +7,6 @@ CPP = @CC@ CFLAGS = @CFLAGS@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ -Wno-unused-function ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@ LDFLAGS = @LDFLAGS@ @OPENSSL_LIBS@ -YASM = @YASM@ AR = @AR@ FIND = @FIND@ RM = /bin/rm -f diff --git a/src/secp256k1/Makefile.legacy b/src/secp256k1/Makefile.legacy index 42d363e8171..d015fabd3a7 100644 --- a/src/secp256k1/Makefile.legacy +++ b/src/secp256k1/Makefile.legacy @@ -4,7 +4,6 @@ CXX = @CXX@ AS = gcc LD = gcc CPP = gcc -YASM = AR = ar FIND = find diff --git a/src/strip_fmt_plug.c b/src/strip_fmt_plug.c index 8dfaf663f84..6fedcff7d8c 100644 --- a/src/strip_fmt_plug.c +++ b/src/strip_fmt_plug.c @@ -93,7 +93,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) #endif for (index = 0; index < count; index += MIN_KEYS_PER_CRYPT) { unsigned char master[MIN_KEYS_PER_CRYPT][32]; - unsigned char output[24]; + unsigned char output[32]; unsigned char *iv_in; unsigned char iv_out[16]; int size,i;