regression: 4005: add NIST aes-gcm vectors

Adds NIST AES-GCM test vectors to regression case 4005 with
CFG_GCM_NIST_VECTORS=y. Only the first test in each group is
used if CFG_GCM_NIST_VECTORS_LIMITED=y.

With CFG_GCM_NIST_VECTORS=y the size of the xtest binary grows with more
than 10 MiB, unless CFG_GCM_NIST_VECTORS_LIMITED=y is given, then only
by ~1 MiB.

Without CFG_GCM_NIST_VECTORS=y, CFG_GCM_NIST_VECTORS_LIMITED has no
effect.

Android not supported.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960)
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/Makefile b/host/xtest/Makefile
index 2313b37..f5d0739 100644
--- a/host/xtest/Makefile
+++ b/host/xtest/Makefile
@@ -71,6 +71,9 @@
 CFLAGS += -I./
 CFLAGS += -I./adbg/include
 CFLAGS += -I./xml/include
+ifeq ($(CFG_GCM_NIST_VECTORS),y)
+CFLAGS += -I$(out-dir)/xtest
+endif
 
 CFLAGS += -I$(OPTEE_CLIENT_EXPORT)/include
 CFLAGS += -I$(TA_DEV_KIT_DIR)/host_include
@@ -166,9 +169,44 @@
 	$(q)$(RMDIR) $(out-dir) 2> /dev/null; true
 endef
 
+ifeq ($(CFG_GCM_NIST_VECTORS),y)
+GCM_NIST_VECTORS_DECRYPT = gcmDecrypt128 gcmDecrypt192 gcmDecrypt256
+GCM_NIST_VECTORS_ENCRYPT = gcmEncryptExtIV128 gcmEncryptExtIV192 \
+			   gcmEncryptExtIV256
+
+cleanfiles += $(out-dir)/gcmtestvectors.zip
+$(out-dir)/gcmtestvectors.zip:
+	@echo '  DL      $@'
+	$(q)curl https://csrc.nist.gov/csrc/media/projects/cryptographic-algorithm-validation-program/documents/mac/gcmtestvectors.zip -o $@
+
+define create-nist-gcm-vectors
+cleanfiles += $(out-dir)/xtest/$(1).h $(out-dir)/$(1).rsp
+
+$(out-dir)/$(1).rsp: $(out-dir)/gcmtestvectors.zip
+	@echo '  UNZIP   $$@'
+	$(q)unzip -o $$< $$(notdir $$@) -d $$(dir $$@)
+	$(q)touch $$@
+
+
+$(out-dir)/xtest/$(1).h: $(out-dir)/$(1).rsp
+	@echo '  GEN     $$@'
+	$(q)../../scripts/rsp_to_gcm_test.py --inf $$< --outf $$@ --mode=$(2) \
+		$(if $(filter y,$(CFG_GCM_NIST_VECTORS_LIMITED)),--limited)
+
+$(CURDIR)/regression_4000.c: $(out-dir)/xtest/$(1).h
+endef
+
+$(foreach v, $(GCM_NIST_VECTORS_DECRYPT), $(eval $(call \
+	create-nist-gcm-vectors,$v,decrypt)))
+$(foreach v, $(GCM_NIST_VECTORS_ENCRYPT), $(eval $(call \
+	create-nist-gcm-vectors,$v,encrypt)))
+endif
+
+
 .PHONY: clean
 clean:
 	@echo '  CLEAN $(out-dir)'
 	$(q)rm -f $(out-dir)/xtest/xtest
 	$(q)$(foreach obj,$(objs), rm -f $(obj))
+	$(q)rm -f $(cleanfiles)
 	$(call rm-build-dirs,adbg/src adbg)