From 78c990c156ba79521e98728e9a604b4c5cc8adec Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 18 Oct 2014 23:46:00 +0100 Subject: Remove fipscanister from Configure, delete fips directory Reviewed-by: Tim Hudson --- fips/Makefile | 247 -- fips/aes/Makefile | 126 - fips/aes/fips_aes_selftest.c | 387 --- fips/aes/fips_aesavs.c | 938 ----- fips/aes/fips_gcmtest.c | 571 --- fips/cmac/Makefile | 115 - fips/cmac/fips_cmac_selftest.c | 182 - fips/cmac/fips_cmactest.c | 517 --- fips/des/Makefile | 113 - fips/des/fips_des_selftest.c | 106 - fips/des/fips_desmovs.c | 710 ---- fips/dh/Makefile | 99 - fips/dh/fips_dh_lib.c | 98 - fips/dh/fips_dhvs.c | 292 -- fips/dsa/Makefile | 149 - fips/dsa/fips_dsa_lib.c | 121 - fips/dsa/fips_dsa_selftest.c | 183 - fips/dsa/fips_dsa_sign.c | 141 - fips/dsa/fips_dsatest.c | 256 -- fips/dsa/fips_dssvs.c | 793 ----- fips/ecdh/Makefile | 106 - fips/ecdh/fips_ecdh_selftest.c | 257 -- fips/ecdh/fips_ecdhvs.c | 496 --- fips/ecdsa/Makefile | 130 - fips/ecdsa/fips_ecdsa_lib.c | 93 - fips/ecdsa/fips_ecdsa_selftest.c | 198 -- fips/ecdsa/fips_ecdsa_sign.c | 114 - fips/ecdsa/fips_ecdsavs.c | 533 --- fips/fips.c | 443 --- fips/fips.h | 480 --- fips/fips_auth.in | 52 - fips/fips_canister.c | 240 -- fips/fips_locl.h | 76 - fips/fips_post.c | 387 --- fips/fips_premain.c | 181 - fips/fips_premain.c.sha1 | 1 - fips/fips_test_suite.c | 1574 --------- fips/fips_utl.h | 494 --- fips/fipsalgtest.pl | 1209 ------- fips/fipsld | 197 -- fips/fipssyms.h | 677 ---- fips/hmac/Makefile | 113 - fips/hmac/fips_hmac_selftest.c | 184 - fips/hmac/fips_hmactest.c | 324 -- fips/mkfipsscr.pl | 657 ---- fips/rand/Makefile | 279 -- fips/rand/fips_drbg_ctr.c | 436 --- fips/rand/fips_drbg_ec.c | 542 --- fips/rand/fips_drbg_hash.c | 378 -- fips/rand/fips_drbg_hmac.c | 281 -- fips/rand/fips_drbg_lib.c | 579 --- fips/rand/fips_drbg_rand.c | 174 - fips/rand/fips_drbg_selftest.c | 876 ----- fips/rand/fips_drbg_selftest.h | 4012 --------------------- fips/rand/fips_drbgvs.c | 416 --- fips/rand/fips_rand.c | 432 --- fips/rand/fips_rand.h | 135 - fips/rand/fips_rand_lcl.h | 241 -- fips/rand/fips_rand_lib.c | 181 - fips/rand/fips_rand_selftest.c | 175 - fips/rand/fips_randtest.c | 261 -- fips/rand/fips_rngvs.c | 258 -- fips/rsa/Makefile | 174 - fips/rsa/fips_rsa_lib.c | 103 - fips/rsa/fips_rsa_selftest.c | 261 -- fips/rsa/fips_rsa_sign.c | 474 --- fips/rsa/fips_rsagtest.c | 389 --- fips/rsa/fips_rsastest.c | 361 -- fips/rsa/fips_rsavtest.c | 365 -- fips/sha/Makefile | 161 - fips/sha/fips_sha1_selftest.c | 94 - fips/sha/fips_shatest.c | 387 --- fips/sha/fips_standalone_sha1.c | 175 - fips/tools/README | 26 - fips/tools/api_fns.pm | 336 -- fips/tools/api_list.pl | 267 -- fips/tools/declarations.dat | 7155 -------------------------------------- fips/utl/Makefile | 113 - fips/utl/fips_enc.c | 468 --- fips/utl/fips_err.c | 89 - fips/utl/fips_lck.c | 87 - fips/utl/fips_md.c | 347 -- fips/utl/fips_mem.c | 94 - 83 files changed, 36942 deletions(-) delete mode 100644 fips/Makefile delete mode 100644 fips/aes/Makefile delete mode 100644 fips/aes/fips_aes_selftest.c delete mode 100644 fips/aes/fips_aesavs.c delete mode 100644 fips/aes/fips_gcmtest.c delete mode 100644 fips/cmac/Makefile delete mode 100644 fips/cmac/fips_cmac_selftest.c delete mode 100644 fips/cmac/fips_cmactest.c delete mode 100644 fips/des/Makefile delete mode 100644 fips/des/fips_des_selftest.c delete mode 100644 fips/des/fips_desmovs.c delete mode 100644 fips/dh/Makefile delete mode 100644 fips/dh/fips_dh_lib.c delete mode 100644 fips/dh/fips_dhvs.c delete mode 100644 fips/dsa/Makefile delete mode 100644 fips/dsa/fips_dsa_lib.c delete mode 100644 fips/dsa/fips_dsa_selftest.c delete mode 100644 fips/dsa/fips_dsa_sign.c delete mode 100644 fips/dsa/fips_dsatest.c delete mode 100644 fips/dsa/fips_dssvs.c delete mode 100644 fips/ecdh/Makefile delete mode 100644 fips/ecdh/fips_ecdh_selftest.c delete mode 100644 fips/ecdh/fips_ecdhvs.c delete mode 100644 fips/ecdsa/Makefile delete mode 100644 fips/ecdsa/fips_ecdsa_lib.c delete mode 100644 fips/ecdsa/fips_ecdsa_selftest.c delete mode 100644 fips/ecdsa/fips_ecdsa_sign.c delete mode 100644 fips/ecdsa/fips_ecdsavs.c delete mode 100644 fips/fips.c delete mode 100644 fips/fips.h delete mode 100644 fips/fips_auth.in delete mode 100644 fips/fips_canister.c delete mode 100644 fips/fips_locl.h delete mode 100644 fips/fips_post.c delete mode 100644 fips/fips_premain.c delete mode 100644 fips/fips_premain.c.sha1 delete mode 100644 fips/fips_test_suite.c delete mode 100644 fips/fips_utl.h delete mode 100644 fips/fipsalgtest.pl delete mode 100755 fips/fipsld delete mode 100644 fips/fipssyms.h delete mode 100644 fips/hmac/Makefile delete mode 100644 fips/hmac/fips_hmac_selftest.c delete mode 100644 fips/hmac/fips_hmactest.c delete mode 100644 fips/mkfipsscr.pl delete mode 100644 fips/rand/Makefile delete mode 100644 fips/rand/fips_drbg_ctr.c delete mode 100644 fips/rand/fips_drbg_ec.c delete mode 100644 fips/rand/fips_drbg_hash.c delete mode 100644 fips/rand/fips_drbg_hmac.c delete mode 100644 fips/rand/fips_drbg_lib.c delete mode 100644 fips/rand/fips_drbg_rand.c delete mode 100644 fips/rand/fips_drbg_selftest.c delete mode 100644 fips/rand/fips_drbg_selftest.h delete mode 100644 fips/rand/fips_drbgvs.c delete mode 100644 fips/rand/fips_rand.c delete mode 100644 fips/rand/fips_rand.h delete mode 100644 fips/rand/fips_rand_lcl.h delete mode 100644 fips/rand/fips_rand_lib.c delete mode 100644 fips/rand/fips_rand_selftest.c delete mode 100644 fips/rand/fips_randtest.c delete mode 100644 fips/rand/fips_rngvs.c delete mode 100644 fips/rsa/Makefile delete mode 100644 fips/rsa/fips_rsa_lib.c delete mode 100644 fips/rsa/fips_rsa_selftest.c delete mode 100644 fips/rsa/fips_rsa_sign.c delete mode 100644 fips/rsa/fips_rsagtest.c delete mode 100644 fips/rsa/fips_rsastest.c delete mode 100644 fips/rsa/fips_rsavtest.c delete mode 100644 fips/sha/Makefile delete mode 100644 fips/sha/fips_sha1_selftest.c delete mode 100644 fips/sha/fips_shatest.c delete mode 100644 fips/sha/fips_standalone_sha1.c delete mode 100644 fips/tools/README delete mode 100644 fips/tools/api_fns.pm delete mode 100644 fips/tools/api_list.pl delete mode 100644 fips/tools/declarations.dat delete mode 100644 fips/utl/Makefile delete mode 100644 fips/utl/fips_enc.c delete mode 100644 fips/utl/fips_err.c delete mode 100644 fips/utl/fips_lck.c delete mode 100644 fips/utl/fips_md.c delete mode 100644 fips/utl/fips_mem.c (limited to 'fips') diff --git a/fips/Makefile b/fips/Makefile deleted file mode 100644 index fb5083810a..0000000000 --- a/fips/Makefile +++ /dev/null @@ -1,247 +0,0 @@ -# -# OpenSSL/crypto/Makefile -# - -DIR= fips -TOP= .. -CC= cc -INCLUDE= -I. -I$(TOP) -I../include -# INCLUDES targets sudbirs! -INCLUDES= -I.. -I../.. -I../../include -CFLAG= -g -MAKEDEPPROG= makedepend -MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) -MAKEFILE= Makefile -RM= rm -f -AR= ar r -ARD= ar d -TEST= fips_test_suite.c -FIPS_TVDIR= testvectors -FIPS_TVOK= $$HOME/fips/tv.ok - -FIPSCANLOC= $(FIPSLIBDIR)fipscanister.o - -RECURSIVE_MAKE= [ -n "$(FDIRS)" ] && for i in $(FDIRS) ; do \ - (cd $$i && echo "making $$target in $(DIR)/$$i..." && \ - $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='${INCLUDES}' $$target ) || exit 1; \ - done; - -PEX_LIBS= -EX_LIBS= - -CFLAGS= $(INCLUDE) $(CFLAG) -DHMAC_EXT=\"$${HMAC_EXT:-sha1}\" -ASFLAGS= $(INCLUDE) $(ASFLAG) -AFLAGS=$(ASFLAGS) - -LIBS= - -FDIRS=sha rand des aes dsa ecdh ecdsa rsa dh cmac hmac utl - -GENERAL=Makefile README fips-lib.com install.com - -LIB= $(TOP)/libcrypto.a -SHARED_LIB= $(FIPSCANLIB)$(SHLIB_EXT) -LIBSRC=fips.c fips_post.c -LIBOBJ=fips.o fips_post.o - -FIPS_OBJ_LISTS=sha/lib hmac/lib rand/lib des/lib aes/lib dsa/lib rsa/lib \ - dh/lib utl/lib ecdsa/lib ecdh/lib cmac/lib - -SRC= $(LIBSRC) - -EXHEADER=fips.h fipssyms.h -HEADER=$(EXHEADER) fips_utl.h fips_locl.h fips_auth.h -EXE=fipsld fips_standalone_sha1 - -ALL= $(GENERAL) $(SRC) $(HEADER) - -top: - @(cd ..; $(MAKE) DIRS=$(DIR) all) - -testapps: - @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi - -all: - @if [ -n "$(FIPSCANISTERONLY)" ]; then \ - $(MAKE) -e subdirs lib ; \ - elif [ -z "$(FIPSLIBDIR)" ]; then \ - $(MAKE) -e subdirs lib fips_premain_dso$(EXE_EXT); \ - else \ - $(MAKE) -e lib fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT); \ - fi - -# Idea behind fipscanister.o is to "seize" the sequestered code between -# known symbols for fingerprinting purposes, which would be commonly -# done with ld -r start.o ... end.o. The latter however presents a minor -# challenge on multi-ABI platforms. As just implied, we'd rather use ld, -# but the trouble is that we don't generally know how ABI-selection -# compiler flag is translated to corresponding linker flag. All compiler -# drivers seem to recognize -r flag and pass it down to linker, but some -# of them, including gcc, erroneously add -lc, as well as run-time -# components, such as crt1.o and alike. Fortunately among those vendor -# compilers which were observed to misinterpret -r flag multi-ABI ones -# are equipped with smart linkers, which don't require any ABI-selection -# flag and simply assume that all objects are of the same type as first -# one in command line. So the idea is to identify gcc and deficient -# vendor compiler drivers... - -fipscanister.o: fips_start.o $(LIBOBJ) $(FIPS_OBJ_LISTS) fips_end.o - FIPS_ASM=""; \ - list="$(BN_ASM)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/bn/$$i" ; done; \ - list="$(AES_ENC)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/aes/$$i" ; done; \ - list="$(DES_ENC)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/des/$$i" ; done; \ - list="$(SHA1_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/sha/$$i" ; done; \ - list="$(MODES_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/modes/$$i" ; done; \ - CPUID=""; \ - list="$(CPUID_OBJ)"; for i in $$list; do CPUID="$$CPUID ../crypto/$$i" ; done; \ - objs="fips_start.o $(LIBOBJ) $(FIPS_EX_OBJ) $$CPUID $$FIPS_ASM"; \ - for i in $(FIPS_OBJ_LISTS); do \ - dir=`dirname $$i`; script="s|^|$$dir/|;s| | $$dir/|g"; \ - objs="$$objs `sed "$$script" $$i`"; \ - done; \ - objs="$$objs fips_end.o" ; \ - os="`(uname -s) 2>/dev/null`"; cflags="$(CFLAGS)"; \ - case "$$os" in \ - AIX) cflags="$$cflags -Wl,-bnoobjreorder" ;; \ - HP-UX) cflags="$$cflags -Wl,+sectionmerge" ;; \ - esac; \ - if [ -n "${FIPS_SITE_LD}" ]; then \ - set -x; ${FIPS_SITE_LD} -r -o $@ $$objs; \ - elif $(CC) -dumpversion >/dev/null 2>&1; then \ - set -x; $(CC) $$cflags -r -nostdlib -o $@ $$objs ; \ - else case "$$os" in \ - OSF1|SunOS) set -x; /usr/ccs/bin/ld -r -o $@ $$objs ;; \ - *) set -x; $(CC) $$cflags -r -o $@ $$objs ;; \ - esac fi - ./fips_standalone_sha1$(EXE_EXT) fipscanister.o > fipscanister.o.sha1 - -# If another exception is immediately required, assign approprite -# site-specific ld command to FIPS_SITE_LD environment variable. - -fips_start.o: fips_canister.c - $(CC) $(CFLAGS) -DFIPS_START -c -o $@ fips_canister.c -fips_end.o: fips_canister.c - $(CC) $(CFLAGS) -DFIPS_END -c -o $@ fips_canister.c -fips_premain_dso$(EXE_EXT): fips_premain.c - $(CC) $(CFLAGS) -DFINGERPRINT_PREMAIN_DSO_LOAD -o $@ fips_premain.c \ - $(FIPSLIBDIR)fipscanister.o ../libcrypto.a $(EX_LIBS) -# this is executed only when linking with external fipscanister.o -fips_standalone_sha1$(EXE_EXT): sha/fips_standalone_sha1.c - if [ -z "$(HOSTCC)" ] ; then \ - $(CC) $(CFLAGS) -DFIPSCANISTER_O -o $@ sha/fips_standalone_sha1.c $(FIPSLIBDIR)fipscanister.o $(EX_LIBS) ; \ - else \ - $(HOSTCC) $(HOSTCFLAGS) -o $ $@ -I../include -I../crypto sha/fips_standalone_sha1.c ../crypto/sha/sha1dgst.c ; \ - fi - -subdirs: - @target=all; $(RECURSIVE_MAKE) - -files: - $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO - @target=files; $(RECURSIVE_MAKE) - -links: - @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER) - @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST) - @target=links; $(RECURSIVE_MAKE) - -# lib: and $(LIB): are splitted to avoid end-less loop -lib: $(LIB) - if [ "$(FIPSCANISTERINTERNAL)" = "n" -a -n "$(FIPSCANLOC)" ]; then $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC); fi - @touch lib - -$(LIB): $(FIPSLIBDIR)fipscanister.o - $(AR) $(LIB) $(FIPSLIBDIR)fipscanister.o - $(RANLIB) $(LIB) || echo Never mind. - -$(FIPSCANLIB): $(FIPSCANLOC) - $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC) - if [ "$(FIPSCANLIB)" = "libfips" ]; then \ - $(AR) $(LIB) $(FIPSCANLOC) ; \ - $(RANLIB) $(LIB) || echo Never Mind. ; \ - fi - $(RANLIB) ../$(FIPSCANLIB).a || echo Never mind. - @touch lib - -shared: lib subdirs fips_premain_dso$(EXE_EXT) - -libs: - @target=lib; $(RECURSIVE_MAKE) - -fips_test: top - @target=fips_test; $(RECURSIVE_MAKE) - -fips_test_diff: - @if diff -b -B -I '^\#' -cr -X fips-nodiff.txt $(FIPS_TVDIR) $(FIPS_TVOK) ; then \ - echo "FIPS diff OK" ; \ - else \ - echo "***FIPS DIFF ERROR***" ; exit 1 ; \ - fi - - -install: - @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... - @headerlist="$(EXHEADER)"; for i in $$headerlist ;\ - do \ - (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ - chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ - done; - @target=install; $(RECURSIVE_MAKE) - for i in $(EXE) ; \ - do \ - echo "installing $$i"; \ - cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \ - chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \ - mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i; \ - done - cp -p -f $(FIPSLIBDIR)fipscanister.o $(FIPSLIBDIR)fipscanister.o.sha1 \ - $(FIPSLIBDIR)fips_premain.c $(FIPSLIBDIR)fips_premain.c.sha1 \ - $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/; \ - chmod 0444 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/fips* - -lint: - @target=lint; $(RECURSIVE_MAKE) - -depend: - @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC) - @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) ) - @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi - -clean: - rm -f fipscanister.o.sha1 fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT) \ - *.s *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - @target=clean; $(RECURSIVE_MAKE) - -dclean: - $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new - mv -f Makefile.new $(MAKEFILE) - @target=dclean; $(RECURSIVE_MAKE) - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -fips.o: ../include/openssl/aes.h ../include/openssl/asn1.h -fips.o: ../include/openssl/bio.h ../include/openssl/crypto.h -fips.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h -fips.o: ../include/openssl/ec.h ../include/openssl/ecdsa.h -fips.o: ../include/openssl/err.h ../include/openssl/evp.h -fips.o: ../include/openssl/fips.h ../include/openssl/fips_rand.h -fips.o: ../include/openssl/hmac.h ../include/openssl/lhash.h -fips.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h -fips.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h -fips.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h -fips.o: ../include/openssl/rsa.h ../include/openssl/safestack.h -fips.o: ../include/openssl/stack.h ../include/openssl/symhacks.h fips.c -fips.o: fips_locl.h -fips_post.o: ../include/openssl/aes.h ../include/openssl/asn1.h -fips_post.o: ../include/openssl/bio.h ../include/openssl/crypto.h -fips_post.o: ../include/openssl/dsa.h ../include/openssl/e_os2.h -fips_post.o: ../include/openssl/ec.h ../include/openssl/ecdsa.h -fips_post.o: ../include/openssl/err.h ../include/openssl/evp.h -fips_post.o: ../include/openssl/fips.h ../include/openssl/fips_rand.h -fips_post.o: ../include/openssl/hmac.h ../include/openssl/lhash.h -fips_post.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h -fips_post.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h -fips_post.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h -fips_post.o: ../include/openssl/rsa.h ../include/openssl/safestack.h -fips_post.o: ../include/openssl/stack.h ../include/openssl/symhacks.h -fips_post.o: fips_locl.h fips_post.c diff --git a/fips/aes/Makefile b/fips/aes/Makefile deleted file mode 100644 index b9702c587d..0000000000 --- a/fips/aes/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -# -# OpenSSL/fips/aes/Makefile -# - -DIR= aes -TOP= ../.. -CC= cc -INCLUDES= -CFLAG=-g -INSTALL_PREFIX= -OPENSSLDIR= /usr/local/ssl -INSTALLTOP=/usr/local/ssl -MAKEDEPPROG= makedepend -MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) -MAKEFILE= Makefile -AR= ar r - -ASFLAGS= $(INCLUDES) $(ASFLAG) -AFLAGS= $(ASFLAGS) - -CFLAGS= $(INCLUDES) $(CFLAG) - -GENERAL=Makefile -TEST=fips_aesavs.c fips_gcmtest.c -APPS= - -LIB=$(TOP)/libcrypto.a -LIBSRC=fips_aes_selftest.c -LIBOBJ=fips_aes_selftest.o - -SRC= $(LIBSRC) - -EXHEADER= -HEADER= - -ALL= $(GENERAL) $(SRC) $(HEADER) - -top: - (cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all) - -all: lib - -lib: $(LIBOBJ) - @echo $(LIBOBJ) > lib - -files: - $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO - -links: - @$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER) - @$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST) - @$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS) - -install: - @headerlist="$(EXHEADER)"; for i in $$headerlist; \ - do \ - (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ - chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ - done - -tags: - ctags $(SRC) - -tests: - -fips_test: - -find ../testvectors/aes/req -name '*.req' > testlist - -rm -rf ../testvectors/aes/rsp - mkdir ../testvectors/aes/rsp - if [ -s testlist ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_aesavs -d testlist; fi - -lint: - lint -DLINT $(INCLUDES) $(SRC)>fluff - -depend: - $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) \ - $(SRC) $(TEST) - -dclean: - $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new - mv -f Makefile.new $(MAKEFILE) - -clean: - rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff testlist -# DO NOT DELETE THIS LINE -- make depend depends on it. - -fips_aes_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h -fips_aes_selftest.o: ../../include/openssl/crypto.h -fips_aes_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h -fips_aes_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h -fips_aes_selftest.o: ../../include/openssl/lhash.h -fips_aes_selftest.o: ../../include/openssl/obj_mac.h -fips_aes_selftest.o: ../../include/openssl/objects.h -fips_aes_selftest.o: ../../include/openssl/opensslconf.h -fips_aes_selftest.o: ../../include/openssl/opensslv.h -fips_aes_selftest.o: ../../include/openssl/ossl_typ.h -fips_aes_selftest.o: ../../include/openssl/safestack.h -fips_aes_selftest.o: ../../include/openssl/stack.h -fips_aes_selftest.o: ../../include/openssl/symhacks.h ../fips_locl.h -fips_aes_selftest.o: fips_aes_selftest.c -fips_aesavs.o: ../../e_os.h ../../include/openssl/aes.h -fips_aesavs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h -fips_aesavs.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h -fips_aesavs.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -fips_aesavs.o: ../../include/openssl/err.h ../../include/openssl/evp.h -fips_aesavs.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h -fips_aesavs.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h -fips_aesavs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -fips_aesavs.o: ../../include/openssl/opensslconf.h -fips_aesavs.o: ../../include/openssl/opensslv.h -fips_aesavs.o: ../../include/openssl/ossl_typ.h -fips_aesavs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -fips_aesavs.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_aesavs.c -fips_gcmtest.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h -fips_gcmtest.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -fips_gcmtest.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h -fips_gcmtest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -fips_gcmtest.o: ../../include/openssl/err.h ../../include/openssl/evp.h -fips_gcmtest.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h -fips_gcmtest.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h -fips_gcmtest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -fips_gcmtest.o: ../../include/openssl/opensslconf.h -fips_gcmtest.o: ../../include/openssl/opensslv.h -fips_gcmtest.o: ../../include/openssl/ossl_typ.h -fips_gcmtest.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -fips_gcmtest.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_gcmtest.c diff --git a/fips/aes/fips_aes_selftest.c b/fips/aes/fips_aes_selftest.c deleted file mode 100644 index c31a266d42..0000000000 --- a/fips/aes/fips_aes_selftest.c +++ /dev/null @@ -1,387 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2003 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. - * - */ - -#define OPENSSL_FIPSAPI - -#include -#include -#include -#include -#include "fips_locl.h" - -#ifdef OPENSSL_FIPS -__fips_constseg -static const struct - { - const unsigned char key[16]; - const unsigned char plaintext[16]; - const unsigned char ciphertext[16]; - } tests[]= - { - { - { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F }, - { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, - 0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF }, - { 0x69,0xC4,0xE0,0xD8,0x6A,0x7B,0x04,0x30, - 0xD8,0xCD,0xB7,0x80,0x70,0xB4,0xC5,0x5A }, - }, - }; - -int FIPS_selftest_aes() - { - int n; - int ret = 0; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - - for(n=0 ; n < 1 ; ++n) - { - if (fips_cipher_test(FIPS_TEST_CIPHER, &ctx, EVP_aes_128_ecb(), - tests[n].key, NULL, - tests[n].plaintext, - tests[n].ciphertext, - 16) <= 0) - goto err; - } - ret = 1; - err: - FIPS_cipher_ctx_cleanup(&ctx); - if (ret == 0) - FIPSerr(FIPS_F_FIPS_SELFTEST_AES,FIPS_R_SELFTEST_FAILED); - return ret; - } - -/* AES-CCM test data from NIST public test vectors */ - -__fips_constseg -static const unsigned char ccm_key[] = { - 0xce,0xb0,0x09,0xae,0xa4,0x45,0x44,0x51,0xfe,0xad,0xf0,0xe6, - 0xb3,0x6f,0x45,0x55,0x5d,0xd0,0x47,0x23,0xba,0xa4,0x48,0xe8 -}; -__fips_constseg -static const unsigned char ccm_nonce[] = { - 0x76,0x40,0x43,0xc4,0x94,0x60,0xb7 -}; -__fips_constseg -static const unsigned char ccm_adata[] = { - 0x6e,0x80,0xdd,0x7f,0x1b,0xad,0xf3,0xa1,0xc9,0xab,0x25,0xc7, - 0x5f,0x10,0xbd,0xe7,0x8c,0x23,0xfa,0x0e,0xb8,0xf9,0xaa,0xa5, - 0x3a,0xde,0xfb,0xf4,0xcb,0xf7,0x8f,0xe4 -}; -__fips_constseg -static const unsigned char ccm_pt[] = { - 0xc8,0xd2,0x75,0xf9,0x19,0xe1,0x7d,0x7f,0xe6,0x9c,0x2a,0x1f, - 0x58,0x93,0x9d,0xfe,0x4d,0x40,0x37,0x91,0xb5,0xdf,0x13,0x10 -}; -__fips_constseg -static const unsigned char ccm_ct[] = { - 0x8a,0x0f,0x3d,0x82,0x29,0xe4,0x8e,0x74,0x87,0xfd,0x95,0xa2, - 0x8a,0xd3,0x92,0xc8,0x0b,0x36,0x81,0xd4,0xfb,0xc7,0xbb,0xfd -}; -__fips_constseg -static const unsigned char ccm_tag[] = { - 0x2d,0xd6,0xef,0x1c,0x45,0xd4,0xcc,0xb7,0x23,0xdc,0x07,0x44, - 0x14,0xdb,0x50,0x6d -}; - -int FIPS_selftest_aes_ccm(void) - { - int ret = 0, do_corrupt = 0; - unsigned char out[128], tag[16]; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - memset(out, 0, sizeof(out)); - if (!fips_post_started(FIPS_TEST_CCM, 0, 0)) - return 1; - if (!fips_post_corrupt(FIPS_TEST_CCM, 0, NULL)) - do_corrupt = 1; - if (!FIPS_cipherinit(&ctx, EVP_aes_192_ccm(), NULL, NULL, 1)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_CCM_SET_IVLEN, - sizeof(ccm_nonce), NULL)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_CCM_SET_TAG, - sizeof(ccm_tag), NULL)) - goto err; - if (!FIPS_cipherinit(&ctx, NULL, ccm_key, ccm_nonce, 1)) - goto err; - if (FIPS_cipher(&ctx, NULL, NULL, sizeof(ccm_pt)) != sizeof(ccm_pt)) - goto err; - if (FIPS_cipher(&ctx, NULL, ccm_adata, sizeof(ccm_adata)) < 0) - goto err; - if (FIPS_cipher(&ctx, out, ccm_pt, sizeof(ccm_pt)) != sizeof(ccm_ct)) - goto err; - - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_CCM_GET_TAG, 16, tag)) - goto err; - if (memcmp(tag, ccm_tag, sizeof(ccm_tag)) - || memcmp(out, ccm_ct, sizeof(ccm_ct))) - goto err; - - memset(out, 0, sizeof(out)); - - /* Modify expected tag value */ - if (do_corrupt) - tag[0]++; - - if (!FIPS_cipherinit(&ctx, EVP_aes_192_ccm(), NULL, NULL, 0)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_CCM_SET_IVLEN, - sizeof(ccm_nonce), NULL)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_CCM_SET_TAG, 16, tag)) - goto err; - if (!FIPS_cipherinit(&ctx, NULL, ccm_key, ccm_nonce, 0)) - goto err; - if (FIPS_cipher(&ctx, NULL, NULL, sizeof(ccm_ct)) != sizeof(ccm_ct)) - goto err; - if (FIPS_cipher(&ctx, NULL, ccm_adata, sizeof(ccm_adata)) < 0) - goto err; - if (FIPS_cipher(&ctx, out, ccm_ct, sizeof(ccm_ct)) != sizeof(ccm_pt)) - goto err; - - if (memcmp(out, ccm_pt, sizeof(ccm_pt))) - goto err; - - ret = 1; - - err: - FIPS_cipher_ctx_cleanup(&ctx); - - if (ret == 0) - { - fips_post_failed(FIPS_TEST_CCM, 0, NULL); - FIPSerr(FIPS_F_FIPS_SELFTEST_AES_CCM,FIPS_R_SELFTEST_FAILED); - return 0; - } - else - return fips_post_success(FIPS_TEST_CCM, 0, NULL); - - } - -/* AES-GCM test data from NIST public test vectors */ - -__fips_constseg -static const unsigned char gcm_key[] = { - 0xee,0xbc,0x1f,0x57,0x48,0x7f,0x51,0x92,0x1c,0x04,0x65,0x66, - 0x5f,0x8a,0xe6,0xd1,0x65,0x8b,0xb2,0x6d,0xe6,0xf8,0xa0,0x69, - 0xa3,0x52,0x02,0x93,0xa5,0x72,0x07,0x8f -}; -__fips_constseg -static const unsigned char gcm_iv[] = { - 0x99,0xaa,0x3e,0x68,0xed,0x81,0x73,0xa0,0xee,0xd0,0x66,0x84 -}; -__fips_constseg -static const unsigned char gcm_pt[] = { - 0xf5,0x6e,0x87,0x05,0x5b,0xc3,0x2d,0x0e,0xeb,0x31,0xb2,0xea, - 0xcc,0x2b,0xf2,0xa5 -}; -__fips_constseg -static const unsigned char gcm_aad[] = { - 0x4d,0x23,0xc3,0xce,0xc3,0x34,0xb4,0x9b,0xdb,0x37,0x0c,0x43, - 0x7f,0xec,0x78,0xde -}; -__fips_constseg -static const unsigned char gcm_ct[] = { - 0xf7,0x26,0x44,0x13,0xa8,0x4c,0x0e,0x7c,0xd5,0x36,0x86,0x7e, - 0xb9,0xf2,0x17,0x36 -}; -__fips_constseg -static const unsigned char gcm_tag[] = { - 0x67,0xba,0x05,0x10,0x26,0x2a,0xe4,0x87,0xd7,0x37,0xee,0x62, - 0x98,0xf7,0x7e,0x0c -}; - -int FIPS_selftest_aes_gcm(void) - { - int ret = 0, do_corrupt = 0; - unsigned char out[128], tag[16]; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - memset(out, 0, sizeof(out)); - memset(tag, 0, sizeof(tag)); - if (!fips_post_started(FIPS_TEST_GCM, 0, 0)) - return 1; - if (!fips_post_corrupt(FIPS_TEST_GCM, 0, NULL)) - do_corrupt = 1; - if (!FIPS_cipherinit(&ctx, EVP_aes_256_gcm(), NULL, NULL, 1)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, - sizeof(gcm_iv), NULL)) - goto err; - if (!FIPS_cipherinit(&ctx, NULL, gcm_key, gcm_iv, 1)) - goto err; - if (FIPS_cipher(&ctx, NULL, gcm_aad, sizeof(gcm_aad)) < 0) - goto err; - if (FIPS_cipher(&ctx, out, gcm_pt, sizeof(gcm_pt)) != sizeof(gcm_ct)) - goto err; - if (FIPS_cipher(&ctx, NULL, NULL, 0) < 0) - goto err; - - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, 16, tag)) - goto err; - - if (memcmp(tag, gcm_tag, 16) || memcmp(out, gcm_ct, 16)) - goto err; - - memset(out, 0, sizeof(out)); - - /* Modify expected tag value */ - if (do_corrupt) - tag[0]++; - - if (!FIPS_cipherinit(&ctx, EVP_aes_256_gcm(), NULL, NULL, 0)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, - sizeof(gcm_iv), NULL)) - goto err; - if (!FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, 16, tag)) - goto err; - if (!FIPS_cipherinit(&ctx, NULL, gcm_key, gcm_iv, 0)) - goto err; - if (FIPS_cipher(&ctx, NULL, gcm_aad, sizeof(gcm_aad)) < 0) - goto err; - if (FIPS_cipher(&ctx, out, gcm_ct, sizeof(gcm_ct)) != sizeof(gcm_pt)) - goto err; - if (FIPS_cipher(&ctx, NULL, NULL, 0) < 0) - goto err; - - if (memcmp(out, gcm_pt, 16)) - goto err; - - ret = 1; - - err: - FIPS_cipher_ctx_cleanup(&ctx); - - if (ret == 0) - { - fips_post_failed(FIPS_TEST_GCM, 0, NULL); - FIPSerr(FIPS_F_FIPS_SELFTEST_AES_GCM,FIPS_R_SELFTEST_FAILED); - return 0; - } - else - return fips_post_success(FIPS_TEST_GCM, 0, NULL); - - } - - -__fips_constseg -static const unsigned char XTS_128_key[] = { - 0xa1,0xb9,0x0c,0xba,0x3f,0x06,0xac,0x35,0x3b,0x2c,0x34,0x38, - 0x76,0x08,0x17,0x62,0x09,0x09,0x23,0x02,0x6e,0x91,0x77,0x18, - 0x15,0xf2,0x9d,0xab,0x01,0x93,0x2f,0x2f -}; -__fips_constseg -static const unsigned char XTS_128_i[] = { - 0x4f,0xae,0xf7,0x11,0x7c,0xda,0x59,0xc6,0x6e,0x4b,0x92,0x01, - 0x3e,0x76,0x8a,0xd5 -}; -__fips_constseg -static const unsigned char XTS_128_pt[] = { - 0xeb,0xab,0xce,0x95,0xb1,0x4d,0x3c,0x8d,0x6f,0xb3,0x50,0x39, - 0x07,0x90,0x31,0x1c -}; -__fips_constseg -static const unsigned char XTS_128_ct[] = { - 0x77,0x8a,0xe8,0xb4,0x3c,0xb9,0x8d,0x5a,0x82,0x50,0x81,0xd5, - 0xbe,0x47,0x1c,0x63 -}; - -__fips_constseg -static const unsigned char XTS_256_key[] = { - 0x1e,0xa6,0x61,0xc5,0x8d,0x94,0x3a,0x0e,0x48,0x01,0xe4,0x2f, - 0x4b,0x09,0x47,0x14,0x9e,0x7f,0x9f,0x8e,0x3e,0x68,0xd0,0xc7, - 0x50,0x52,0x10,0xbd,0x31,0x1a,0x0e,0x7c,0xd6,0xe1,0x3f,0xfd, - 0xf2,0x41,0x8d,0x8d,0x19,0x11,0xc0,0x04,0xcd,0xa5,0x8d,0xa3, - 0xd6,0x19,0xb7,0xe2,0xb9,0x14,0x1e,0x58,0x31,0x8e,0xea,0x39, - 0x2c,0xf4,0x1b,0x08 -}; -__fips_constseg -static const unsigned char XTS_256_i[] = { - 0xad,0xf8,0xd9,0x26,0x27,0x46,0x4a,0xd2,0xf0,0x42,0x8e,0x84, - 0xa9,0xf8,0x75,0x64 -}; -__fips_constseg -static const unsigned char XTS_256_pt[] = { - 0x2e,0xed,0xea,0x52,0xcd,0x82,0x15,0xe1,0xac,0xc6,0x47,0xe8, - 0x10,0xbb,0xc3,0x64,0x2e,0x87,0x28,0x7f,0x8d,0x2e,0x57,0xe3, - 0x6c,0x0a,0x24,0xfb,0xc1,0x2a,0x20,0x2e -}; -__fips_constseg -static const unsigned char XTS_256_ct[] = { - 0xcb,0xaa,0xd0,0xe2,0xf6,0xce,0xa3,0xf5,0x0b,0x37,0xf9,0x34, - 0xd4,0x6a,0x9b,0x13,0x0b,0x9d,0x54,0xf0,0x7e,0x34,0xf3,0x6a, - 0xf7,0x93,0xe8,0x6f,0x73,0xc6,0xd7,0xdb -}; - -int FIPS_selftest_aes_xts() - { - int ret = 1; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - - if (fips_cipher_test(FIPS_TEST_XTS, &ctx, EVP_aes_128_xts(), - XTS_128_key, XTS_128_i, XTS_128_pt, XTS_128_ct, - sizeof(XTS_128_pt)) <= 0) - ret = 0; - - if (fips_cipher_test(FIPS_TEST_XTS, &ctx, EVP_aes_256_xts(), - XTS_256_key, XTS_256_i, XTS_256_pt, XTS_256_ct, - sizeof(XTS_256_pt)) <= 0) - ret = 0; - - FIPS_cipher_ctx_cleanup(&ctx); - if (ret == 0) - FIPSerr(FIPS_F_FIPS_SELFTEST_AES_XTS,FIPS_R_SELFTEST_FAILED); - return ret; - } - -#endif diff --git a/fips/aes/fips_aesavs.c b/fips/aes/fips_aesavs.c deleted file mode 100644 index fecaf990c6..0000000000 --- a/fips/aes/fips_aesavs.c +++ /dev/null @@ -1,938 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2004 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. - * - */ -/*--------------------------------------------- - NIST AES Algorithm Validation Suite - Test Program - - Donated to OpenSSL by: - V-ONE Corporation - 20250 Century Blvd, Suite 300 - Germantown, MD 20874 - U.S.A. - ----------------------------------------------*/ - -#define OPENSSL_FIPSAPI - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "e_os.h" - -#ifndef OPENSSL_FIPS - -int main(int argc, char *argv[]) -{ - printf("No FIPS AES support\n"); - return(0); -} - -#else - -#include -#include "fips_utl.h" - -#define AES_BLOCK_SIZE 16 - -#define VERBOSE 0 - -/*-----------------------------------------------*/ - -static int AESTest(EVP_CIPHER_CTX *ctx, - char *amode, int akeysz, unsigned char *aKey, - unsigned char *iVec, - int dir, /* 0 = decrypt, 1 = encrypt */ - unsigned char *plaintext, unsigned char *ciphertext, int len) - { - const EVP_CIPHER *cipher = NULL; - - if (strcasecmp(amode, "CBC") == 0) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_cbc(); - break; - - case 192: - cipher = EVP_aes_192_cbc(); - break; - - case 256: - cipher = EVP_aes_256_cbc(); - break; - } - - } - else if (strcasecmp(amode, "ECB") == 0) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_ecb(); - break; - - case 192: - cipher = EVP_aes_192_ecb(); - break; - - case 256: - cipher = EVP_aes_256_ecb(); - break; - } - } - else if (strcasecmp(amode, "CFB128") == 0) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_cfb128(); - break; - - case 192: - cipher = EVP_aes_192_cfb128(); - break; - - case 256: - cipher = EVP_aes_256_cfb128(); - break; - } - - } - else if (fips_strncasecmp(amode, "OFB", 3) == 0) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_ofb(); - break; - - case 192: - cipher = EVP_aes_192_ofb(); - break; - - case 256: - cipher = EVP_aes_256_ofb(); - break; - } - } - else if(!strcasecmp(amode,"CFB1")) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_cfb1(); - break; - - case 192: - cipher = EVP_aes_192_cfb1(); - break; - - case 256: - cipher = EVP_aes_256_cfb1(); - break; - } - } - else if(!strcasecmp(amode,"CFB8")) - { - switch (akeysz) - { - case 128: - cipher = EVP_aes_128_cfb8(); - break; - - case 192: - cipher = EVP_aes_192_cfb8(); - break; - - case 256: - cipher = EVP_aes_256_cfb8(); - break; - } - } - else - { - printf("Unknown mode: %s\n", amode); - return 0; - } - if (!cipher) - { - printf("Invalid key size: %d\n", akeysz); - return 0; - } - if (FIPS_cipherinit(ctx, cipher, aKey, iVec, dir) <= 0) - return 0; - if(!strcasecmp(amode,"CFB1")) - M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS); - if (dir) - FIPS_cipher(ctx, ciphertext, plaintext, len); - else - FIPS_cipher(ctx, plaintext, ciphertext, len); - return 1; - } - -/*-----------------------------------------------*/ -char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"}; -char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB128"}; -enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB128}; -enum XCrypt {XDECRYPT, XENCRYPT}; - -/*=============================*/ -/* Monte Carlo Tests */ -/*-----------------------------*/ - -/*#define gb(a,b) (((a)[(b)/8] >> ((b)%8))&1)*/ -/*#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << ((b)%8)))|(!!(v) << ((b)%8)))*/ - -#define gb(a,b) (((a)[(b)/8] >> (7-(b)%8))&1) -#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << (7-(b)%8)))|(!!(v) << (7-(b)%8))) - -static int do_mct(char *amode, - int akeysz, unsigned char *aKey,unsigned char *iVec, - int dir, unsigned char *text, int len, - FILE *rfp) - { - int ret = 0; - unsigned char key[101][32]; - unsigned char iv[101][AES_BLOCK_SIZE]; - unsigned char ptext[1001][32]; - unsigned char ctext[1001][32]; - unsigned char ciphertext[64+4]; - int i, j, n, n1, n2; - int imode = 0, nkeysz = akeysz/8; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - - if (len > 32) - { - printf("\n>>>> Length exceeds 32 for %s %d <<<<\n\n", - amode, akeysz); - return -1; - } - for (imode = 0; imode < 6; ++imode) - if (strcmp(amode, t_mode[imode]) == 0) - break; - if (imode == 6) - { - printf("Unrecognized mode: %s\n", amode); - return -1; - } - - memcpy(key[0], aKey, nkeysz); - if (iVec) - memcpy(iv[0], iVec, AES_BLOCK_SIZE); - if (dir == XENCRYPT) - memcpy(ptext[0], text, len); - else - memcpy(ctext[0], text, len); - for (i = 0; i < 100; ++i) - { - /* printf("Iteration %d\n", i); */ - if (i > 0) - { - fprintf(rfp,"COUNT = %d" RESP_EOL ,i); - OutputValue("KEY",key[i],nkeysz,rfp,0); - if (imode != ECB) /* ECB */ - OutputValue("IV",iv[i],AES_BLOCK_SIZE,rfp,0); - /* Output Ciphertext | Plaintext */ - OutputValue(t_tag[dir^1],dir ? ptext[0] : ctext[0],len,rfp, - imode == CFB1); - } - for (j = 0; j < 1000; ++j) - { - switch (imode) - { - case ECB: - if (j == 0) - { /* set up encryption */ - ret = AESTest(&ctx, amode, akeysz, key[i], NULL, - dir, /* 0 = decrypt, 1 = encrypt */ - ptext[j], ctext[j], len); - if (dir == XENCRYPT) - memcpy(ptext[j+1], ctext[j], len); - else - memcpy(ctext[j+1], ptext[j], len); - } - else - { - if (dir == XENCRYPT) - { - FIPS_cipher(&ctx, ctext[j], ptext[j], len); - memcpy(ptext[j+1], ctext[j], len); - } - else - { - FIPS_cipher(&ctx, ptext[j], ctext[j], len); - memcpy(ctext[j+1], ptext[j], len); - } - } - break; - - case CBC: - case OFB: - case CFB128: - if (j == 0) - { - ret = AESTest(&ctx, amode, akeysz, key[i], iv[i], - dir, /* 0 = decrypt, 1 = encrypt */ - ptext[j], ctext[j], len); - if (dir == XENCRYPT) - memcpy(ptext[j+1], iv[i], len); - else - memcpy(ctext[j+1], iv[i], len); - } - else - { - if (dir == XENCRYPT) - { - FIPS_cipher(&ctx, ctext[j], ptext[j], len); - memcpy(ptext[j+1], ctext[j-1], len); - } - else - { - FIPS_cipher(&ctx, ptext[j], ctext[j], len); - memcpy(ctext[j+1], ptext[j-1], len); - } - } - break; - - case CFB8: - if (j == 0) - { - ret = AESTest(&ctx, amode, akeysz, key[i], iv[i], - dir, /* 0 = decrypt, 1 = encrypt */ - ptext[j], ctext[j], len); - } - else - { - if (dir == XENCRYPT) - FIPS_cipher(&ctx, ctext[j], ptext[j], len); - else - FIPS_cipher(&ctx, ptext[j], ctext[j], len); - } - if (dir == XENCRYPT) - { - if (j < 16) - memcpy(ptext[j+1], &iv[i][j], len); - else - memcpy(ptext[j+1], ctext[j-16], len); - } - else - { - if (j < 16) - memcpy(ctext[j+1], &iv[i][j], len); - else - memcpy(ctext[j+1], ptext[j-16], len); - } - break; - - case CFB1: - if(j == 0) - { -#if 0 - /* compensate for wrong endianness of input file */ - if(i == 0) - ptext[0][0]<<=7; -#endif - ret = AESTest(&ctx,amode,akeysz,key[i],iv[i],dir, - ptext[j], ctext[j], len); - } - else - { - if (dir == XENCRYPT) - FIPS_cipher(&ctx, ctext[j], ptext[j], len); - else - FIPS_cipher(&ctx, ptext[j], ctext[j], len); - - } - if(dir == XENCRYPT) - { - if(j < 128) - sb(ptext[j+1],0,gb(iv[i],j)); - else - sb(ptext[j+1],0,gb(ctext[j-128],0)); - } - else - { - if(j < 128) - sb(ctext[j+1],0,gb(iv[i],j)); - else - sb(ctext[j+1],0,gb(ptext[j-128],0)); - } - break; - } - } - --j; /* reset to last of range */ - /* Output Ciphertext | Plaintext */ - OutputValue(t_tag[dir],dir ? ctext[j] : ptext[j],len,rfp, - imode == CFB1); - fprintf(rfp, RESP_EOL); /* add separator */ - - /* Compute next KEY */ - if (dir == XENCRYPT) - { - if (imode == CFB8) - { /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */ - for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2) - ciphertext[n1] = ctext[j-n2][0]; - } - else if(imode == CFB1) - { - for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2) - sb(ciphertext,n1,gb(ctext[j-n2],0)); - } - else - switch (akeysz) - { - case 128: - memcpy(ciphertext, ctext[j], 16); - break; - case 192: - memcpy(ciphertext, ctext[j-1]+8, 8); - memcpy(ciphertext+8, ctext[j], 16); - break; - case 256: - memcpy(ciphertext, ctext[j-1], 16); - memcpy(ciphertext+16, ctext[j], 16); - break; - } - } - else - { - if (imode == CFB8) - { /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */ - for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2) - ciphertext[n1] = ptext[j-n2][0]; - } - else if(imode == CFB1) - { - for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2) - sb(ciphertext,n1,gb(ptext[j-n2],0)); - } - else - switch (akeysz) - { - case 128: - memcpy(ciphertext, ptext[j], 16); - break; - case 192: - memcpy(ciphertext, ptext[j-1]+8, 8); - memcpy(ciphertext+8, ptext[j], 16); - break; - case 256: - memcpy(ciphertext, ptext[j-1], 16); - memcpy(ciphertext+16, ptext[j], 16); - break; - } - } - /* Compute next key: Key[i+1] = Key[i] xor ct */ - for (n = 0; n < nkeysz; ++n) - key[i+1][n] = key[i][n] ^ ciphertext[n]; - - /* Compute next IV and text */ - if (dir == XENCRYPT) - { - switch (imode) - { - case ECB: - memcpy(ptext[0], ctext[j], AES_BLOCK_SIZE); - break; - case CBC: - case OFB: - case CFB128: - memcpy(iv[i+1], ctext[j], AES_BLOCK_SIZE); - memcpy(ptext[0], ctext[j-1], AES_BLOCK_SIZE); - break; - case CFB8: - /* IV[i+1] = ct */ - for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2) - iv[i+1][n1] = ctext[j-n2][0]; - ptext[0][0] = ctext[j-16][0]; - break; - case CFB1: - for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2) - sb(iv[i+1],n1,gb(ctext[j-n2],0)); - ptext[0][0]=ctext[j-128][0]&0x80; - break; - } - } - else - { - switch (imode) - { - case ECB: - memcpy(ctext[0], ptext[j], AES_BLOCK_SIZE); - break; - case CBC: - case OFB: - case CFB128: - memcpy(iv[i+1], ptext[j], AES_BLOCK_SIZE); - memcpy(ctext[0], ptext[j-1], AES_BLOCK_SIZE); - break; - case CFB8: - for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2) - iv[i+1][n1] = ptext[j-n2][0]; - ctext[0][0] = ptext[j-16][0]; - break; - case CFB1: - for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2) - sb(iv[i+1],n1,gb(ptext[j-n2],0)); - ctext[0][0]=ptext[j-128][0]&0x80; - break; - } - } - } - FIPS_cipher_ctx_cleanup(&ctx); - return ret; - } - -/*================================================*/ -/*---------------------------- - # Config info for v-one - # AESVS MMT test data for ECB - # State : Encrypt and Decrypt - # Key Length : 256 - # Fri Aug 30 04:07:22 PM - ----------------------------*/ - -static int proc_file(char *rqfile, char *rspfile) - { - char afn[256], rfn[256]; - FILE *afp = NULL, *rfp = NULL; - char ibuf[2048]; - char tbuf[2048]; - int len; - char algo[8] = ""; - char amode[8] = ""; - char atest[8] = ""; - int akeysz = 0; - unsigned char iVec[20], aKey[40]; - int dir = -1, err = 0, step = 0; - unsigned char plaintext[2048]; - unsigned char ciphertext[2048]; - char *rp; - EVP_CIPHER_CTX ctx; - FIPS_cipher_ctx_init(&ctx); - - if (!rqfile || !(*rqfile)) - { - printf("No req file\n"); - return -1; - } - strcpy(afn, rqfile); - - if ((afp = fopen(afn, "r")) == NULL) - { - printf("Cannot open file: %s, %s\n", - afn, strerror(errno)); - return -1; - } - if (!rspfile) - { - strcpy(rfn,afn); - rp=strstr(rfn,"req/"); -#ifdef OPENSSL_SYS_WIN32 - if (!rp) - rp=strstr(rfn,"req\\"); -#endif - assert(rp); - memcpy(rp,"rsp",3); - rp = strstr(rfn, ".req"); - memcpy(rp, ".rsp", 4); - rspfile = rfn; - } - if ((rfp = fopen(rspfile, "w")) == NULL) - { - printf("Cannot open file: %s, %s\n", - rfn, strerror(errno)); - fclose(afp); - afp = NULL; - return -1; - } - while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL) - { - tidy_line(tbuf, ibuf); - /* printf("step=%d ibuf=%s",step,ibuf); */ - switch (step) - { - case 0: /* read preamble */ - if (ibuf[0] == '\n') - { /* end of preamble */ - if ((*algo == '\0') || - (*amode == '\0') || - (akeysz == 0)) - { - printf("Missing Algorithm, Mode or KeySize (%s/%s/%d)\n", - algo,amode,akeysz); - err = 1; - } - else - { - copy_line(ibuf, rfp); - ++ step; - } - } - else if (ibuf[0] != '#') - { - printf("Invalid preamble item: %s\n", ibuf); - err = 1; - } - else - { /* process preamble */ - char *xp, *pp = ibuf+2; - int n; - if (akeysz) - { /* insert current time & date */ - time_t rtim = time(0); - fputs("# ", rfp); - copy_line(ctime(&rtim), rfp); - } - else - { - copy_line(ibuf, rfp); - if (strncmp(pp, "AESVS ", 6) == 0) - { - strcpy(algo, "AES"); - /* get test type */ - pp += 6; - xp = strchr(pp, ' '); - n = xp-pp; - strncpy(atest, pp, n); - atest[n] = '\0'; - /* get mode */ - xp = strrchr(pp, ' '); /* get mode" */ - n = strlen(xp+1)-1; - strncpy(amode, xp+1, n); - amode[n] = '\0'; - /* amode[3] = '\0'; */ - if (VERBOSE) - printf("Test = %s, Mode = %s\n", atest, amode); - } - else if (fips_strncasecmp(pp, "Key Length : ", 13) == 0) - { - akeysz = atoi(pp+13); - if (VERBOSE) - printf("Key size = %d\n", akeysz); - } - } - } - break; - - case 1: /* [ENCRYPT] | [DECRYPT] */ - if (ibuf[0] == '[') - { - copy_line(ibuf, rfp); - ++step; - if (fips_strncasecmp(ibuf, "[ENCRYPT]", 9) == 0) - dir = 1; - else if (fips_strncasecmp(ibuf, "[DECRYPT]", 9) == 0) - dir = 0; - else - { - printf("Invalid keyword: %s\n", ibuf); - err = 1; - } - break; - } - else if (dir == -1) - { - err = 1; - printf("Missing ENCRYPT/DECRYPT keyword\n"); - break; - } - else - step = 2; - - case 2: /* KEY = xxxx */ - copy_line(ibuf, rfp); - if(*ibuf == '\n') - break; - if(!fips_strncasecmp(ibuf,"COUNT = ",8)) - break; - - if (fips_strncasecmp(ibuf, "KEY = ", 6) != 0) - { - printf("Missing KEY\n"); - err = 1; - } - else - { - len = hex2bin((char*)ibuf+6, aKey); - if (len < 0) - { - printf("Invalid KEY\n"); - err =1; - break; - } - PrintValue("KEY", aKey, len); - if (strcmp(amode, "ECB") == 0) - { - memset(iVec, 0, sizeof(iVec)); - step = (dir)? 4: 5; /* no ivec for ECB */ - } - else - ++step; - } - break; - - case 3: /* IV = xxxx */ - copy_line(ibuf, rfp); - if (fips_strncasecmp(ibuf, "IV = ", 5) != 0) - { - printf("Missing IV\n"); - err = 1; - } - else - { - len = hex2bin((char*)ibuf+5, iVec); - if (len < 0) - { - printf("Invalid IV\n"); - err =1; - break; - } - PrintValue("IV", iVec, len); - step = (dir)? 4: 5; - } - break; - - case 4: /* PLAINTEXT = xxxx */ - copy_line(ibuf, rfp); - if (fips_strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0) - { - printf("Missing PLAINTEXT\n"); - err = 1; - } - else - { - int nn = strlen(ibuf+12); - if(!strcmp(amode,"CFB1")) - len=bint2bin(ibuf+12,nn-1,plaintext); - else - len=hex2bin(ibuf+12, plaintext); - if (len < 0) - { - printf("Invalid PLAINTEXT: %s", ibuf+12); - err =1; - break; - } - if (len >= (int)sizeof(plaintext)) - { - printf("Buffer overflow\n"); - } - PrintValue("PLAINTEXT", (unsigned char*)plaintext, len); - if (strcmp(atest, "MCT") == 0) /* Monte Carlo Test */ - { - if(do_mct(amode, akeysz, aKey, iVec, - dir, (unsigned char*)plaintext, len, - rfp) < 0) - err = 1; - } - else - { - AESTest(&ctx, amode, akeysz, aKey, iVec, - dir, /* 0 = decrypt, 1 = encrypt */ - plaintext, ciphertext, len); - OutputValue("CIPHERTEXT",ciphertext,len,rfp, - !strcmp(amode,"CFB1")); - } - step = 6; - } - break; - - case 5: /* CIPHERTEXT = xxxx */ - copy_line(ibuf, rfp); - if (fips_strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0) - { - printf("Missing KEY\n"); - err = 1; - } - else - { - if(!strcmp(amode,"CFB1")) - len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext); - else - len = hex2bin(ibuf+13,ciphertext); - if (len < 0) - { - printf("Invalid CIPHERTEXT\n"); - err =1; - break; - } - - PrintValue("CIPHERTEXT", ciphertext, len); - if (strcmp(atest, "MCT") == 0) /* Monte Carlo Test */ - { - do_mct(amode, akeysz, aKey, iVec, - dir, ciphertext, len, rfp); - } - else - { - AESTest(&ctx, amode, akeysz, aKey, iVec, - dir, /* 0 = decrypt, 1 = encrypt */ - plaintext, ciphertext, len); - OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp, - !strcmp(amode,"CFB1")); - } - step = 6; - } - break; - - case 6: - if (ibuf[0] != '\n') - { - err = 1; - printf("Missing terminator\n"); - } - else if (strcmp(atest, "MCT") != 0) - { /* MCT already added terminating nl */ - copy_line(ibuf, rfp); - } - step = 1; - break; - } - } - if (rfp) - fclose(rfp); - if (afp) - fclose(afp); - FIPS_cipher_ctx_cleanup(&ctx); - return err; - } - -/*-------------------------------------------------- - Processes either a single file or - a set of files whose names are passed in a file. - A single file is specified as: - aes_test -f xxx.req - A set of files is specified as: - aes_test -d xxxxx.xxx - The default is: -d req.txt ---------------------------------------------------*/ -#ifdef FIPS_ALGVS -int fips_aesavs_main(int argc, char **argv) -#else -int main(int argc, char **argv) -#endif - { - char *rqlist = "req.txt", *rspfile = NULL; - FILE *fp = NULL; - char fn[250] = "", rfn[256] = ""; - int d_opt = 1; - fips_algtest_init(); - - if (argc > 1) - { - if (strcasecmp(argv[1], "-d") == 0) - { - d_opt = 1; - } - else if (strcasecmp(argv[1], "-f") == 0) - { - d_opt = 0; - } - else - { - printf("Invalid parameter: %s\n", argv[1]); - return 0; - } - if (argc < 3) - { - printf("Missing parameter\n"); - return 0; - } - if (d_opt) - rqlist = argv[2]; - else - { - strcpy(fn, argv[2]); - rspfile = argv[3]; - } - } - if (d_opt) - { /* list of files (directory) */ - if (!(fp = fopen(rqlist, "r"))) - { - printf("Cannot open req list file\n"); - return -1; - } - while (fgets(fn, sizeof(fn), fp)) - { - strtok(fn, "\r\n"); - strcpy(rfn, fn); - if (VERBOSE) - printf("Processing: %s\n", rfn); - if (proc_file(rfn, rspfile)) - { - printf(">>> Processing failed for: %s <<<\n", rfn); - return 1; - } - } - fclose(fp); - } - else /* single file */ - { - if (VERBOSE) - printf("Processing: %s\n", fn); - if (proc_file(fn, rspfile)) - { - printf(">>> Processing failed for: %s <<<\n", fn); - } - } - return 0; - } - -#endif diff --git a/fips/aes/fips_gcmtest.c b/fips/aes/fips_gcmtest.c deleted file mode 100644 index 9f50857fb9..0000000000 --- a/fips/aes/fips_gcmtest.c +++ /dev/null @@ -1,571 +0,0 @@ -/* fips/aes/fips_gcmtest.c */ -/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL - * project. - */ -/* ==================================================================== - * Copyright (c) 2011 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 - * licensing@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. - * ==================================================================== - */ - - -#define OPENSSL_FIPSAPI -#include - -#ifndef OPENSSL_FIPS -#include - -int main(int argc, char **argv) -{ - printf("No FIPS GCM support\n"); - return(0); -} -#else - -#include -#include -#include -#include -#include -#include -#include - -#include "fips_utl.h" - -static void gcmtest(FILE *in, FILE *out, int encrypt) - { - char buf[2048]; - char lbuf[2048]; - char *keyword, *value; - int keylen = -1, ivlen = -1, aadlen = -1, taglen = -1, ptlen = -1; - int rv; - long l; - unsigned char *key = NULL, *iv = NULL, *aad = NULL, *tag = NULL; - unsigned char *ct = NULL, *pt = NULL; - EVP_CIPHER_CTX ctx; - const EVP_CIPHER *gcm = NULL; - FIPS_cipher_ctx_init(&ctx); - - while(fgets(buf,sizeof buf,in) != NULL) - { - fputs(buf,out); - if (!parse_line(&keyword, &value, lbuf, buf)) - continue; - if(!strcmp(keyword,"[Keylen")) - { - keylen = atoi(value); - if (keylen == 128) - gcm = EVP_aes_128_gcm(); - else if (keylen == 192) - gcm = EVP_aes_192_gcm(); - else if (keylen == 256) - gcm = EVP_aes_256_gcm(); - else - { - fprintf(stderr, "Unsupported keylen %d\n", - keylen); - } - keylen >>= 3; - } - else if (!strcmp(keyword, "[IVlen")) - ivlen = atoi(value) >> 3; - else if (!strcmp(keyword, "[AADlen")) - aadlen = atoi(value) >> 3; - else if (!strcmp(keyword, "[Taglen")) - taglen = atoi(value) >> 3; - else if (!strcmp(keyword, "[PTlen")) - ptlen = atoi(value) >> 3; - else if(!strcmp(keyword,"Key")) - { - key = hex2bin_m(value, &l); - if (l != keylen) - { - fprintf(stderr, "Inconsistent Key length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"IV")) - { - iv = hex2bin_m(value, &l); - if (l != ivlen) - { - fprintf(stderr, "Inconsistent IV length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"PT")) - { - pt = hex2bin_m(value, &l); - if (l != ptlen) - { - fprintf(stderr, "Inconsistent PT length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"CT")) - { - ct = hex2bin_m(value, &l); - if (l != ptlen) - { - fprintf(stderr, "Inconsistent CT length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"AAD")) - { - aad = hex2bin_m(value, &l); - if (l != aadlen) - { - fprintf(stderr, "Inconsistent AAD length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"Tag")) - { - tag = hex2bin_m(value, &l); - if (l != taglen) - { - fprintf(stderr, "Inconsistent Tag length\n"); - exit(1); - } - } - if (encrypt && pt && aad && (iv || encrypt==1)) - { - tag = OPENSSL_malloc(taglen); - FIPS_cipherinit(&ctx, gcm, NULL, NULL, 1); - /* Relax FIPS constraints for testing */ - M_EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPH_FLAG_NON_FIPS_ALLOW); - FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, ivlen, 0); - if (encrypt == 1) - { - static unsigned char iv_fixed[4] = {1,2,3,4}; - if (!iv) - iv = OPENSSL_malloc(ivlen); - FIPS_cipherinit(&ctx, NULL, key, NULL, 1); - FIPS_cipher_ctx_ctrl(&ctx, - EVP_CTRL_GCM_SET_IV_FIXED, - 4, iv_fixed); - if (!FIPS_cipher_ctx_ctrl(&ctx, - EVP_CTRL_GCM_IV_GEN, 0, iv)) - { - fprintf(stderr, "IV gen error\n"); - exit(1); - } - OutputValue("IV", iv, ivlen, out, 0); - } - else - FIPS_cipherinit(&ctx, NULL, key, iv, 1); - - - if (aadlen) - FIPS_cipher(&ctx, NULL, aad, aadlen); - if (ptlen) - { - ct = OPENSSL_malloc(ptlen); - rv = FIPS_cipher(&ctx, ct, pt, ptlen); - } - FIPS_cipher(&ctx, NULL, NULL, 0); - FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, - taglen, tag); - OutputValue("CT", ct, ptlen, out, 0); - OutputValue("Tag", tag, taglen, out, 0); - if (iv) - OPENSSL_free(iv); - if (aad) - OPENSSL_free(aad); - if (ct) - OPENSSL_free(ct); - if (pt) - OPENSSL_free(pt); - if (key) - OPENSSL_free(key); - if (tag) - OPENSSL_free(tag); - iv = aad = ct = pt = key = tag = NULL; - } - if (!encrypt && tag) - { - FIPS_cipherinit(&ctx, gcm, NULL, NULL, 0); - /* Relax FIPS constraints for testing */ - M_EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPH_FLAG_NON_FIPS_ALLOW); - FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, ivlen, 0); - FIPS_cipherinit(&ctx, NULL, key, iv, 0); - FIPS_cipher_ctx_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, taglen, tag); - if (aadlen) - FIPS_cipher(&ctx, NULL, aad, aadlen); - if (ptlen) - { - pt = OPENSSL_malloc(ptlen); - rv = FIPS_cipher(&ctx, pt, ct, ptlen); - } - rv = FIPS_cipher(&ctx, NULL, NULL, 0); - if (rv < 0) - fprintf(out, "FAIL" RESP_EOL); - else - OutputValue("PT", pt, ptlen, out, 0); - if (iv) - OPENSSL_free(iv); - if (aad) - OPENSSL_free(aad); - if (ct) - OPENSSL_free(ct); - if (pt) - OPENSSL_free(pt); - if (key) - OPENSSL_free(key); - if (tag) - OPENSSL_free(tag); - iv = aad = ct = pt = key = tag = NULL; - } - } - FIPS_cipher_ctx_cleanup(&ctx); - } - -static void xtstest(FILE *in, FILE *out) - { - char buf[204800]; - char lbuf[204800]; - char *keyword, *value; - int inlen = 0; - int encrypt = 0; - long l; - unsigned char *key = NULL, *iv = NULL; - unsigned char *inbuf = NULL, *outbuf = NULL; - EVP_CIPHER_CTX ctx; - const EVP_CIPHER *xts = NULL; - FIPS_cipher_ctx_init(&ctx); - - while(fgets(buf,sizeof buf,in) != NULL) - { - fputs(buf,out); - if (buf[0] == '[' && strlen(buf) >= 9) - { - if(!strncmp(buf,"[ENCRYPT]", 9)) - encrypt = 1; - else if(!strncmp(buf,"[DECRYPT]", 9)) - encrypt = 0; - } - if (!parse_line(&keyword, &value, lbuf, buf)) - continue; - else if(!strcmp(keyword,"Key")) - { - key = hex2bin_m(value, &l); - if (l == 32) - xts = EVP_aes_128_xts(); - else if (l == 64) - xts = EVP_aes_256_xts(); - else - { - fprintf(stderr, "Inconsistent Key length\n"); - exit(1); - } - } - else if(!strcmp(keyword,"i")) - { - iv = hex2bin_m(value, &l); - if (l != 16) - { - fprintf(stderr, "Inconsistent i length\n"); - exit(1); - } - } - else if(encrypt && !strcmp(keyword,"PT")) - { - inbuf = hex2bin_m(value, &l); - inlen = l; - } - else if(!encrypt && !strcmp(keyword,"CT")) - { - inbuf = he