1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 23:48:58 +00:00

Added python test running all unit tests of common crypto functions

This commit is contained in:
Peter Schwabe 2019-04-10 16:02:45 +02:00
parent 4970379baf
commit 28337843b9
3 changed files with 40 additions and 8 deletions

View File

@ -10,8 +10,8 @@ SCHEME_UPPERCASE=$(shell echo $(SCHEME) | tr a-z A-Z | sed 's/-//g')
IMPLEMENTATION_UPPERCASE=$(shell echo $(IMPLEMENTATION) | tr a-z A-Z | sed 's/-//g')
COMMON_DIR=../common
COMMON_FILES=$(COMMON_DIR)/fips202.c $(COMMON_DIR)/sha2.c
COMMON_HEADERS=$(COMMON_DIR)/fips202.h $(COMMON_DIR)/randombytes.h $(COMMON_DIR)/sha2.h
COMMON_FILES=$(COMMON_DIR)/aes.c $(COMMON_DIR)/sha2.c $(COMMON_DIR)/fips202.c
COMMON_HEADERS=$(COMMON_DIR)/*.h
DEST_DIR=../bin
# This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
@ -38,11 +38,7 @@ testvectors: $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION)
.PHONY: printparams
printparams: $(DEST_DIR)/printparams_$(SCHEME)_$(IMPLEMENTATION)
$(DEST_DIR)/test_fips202: common/fips202.c $(COMMON_FILES)
mkdir -p $(DEST_DIR)
$(CC) $(CFLAGS) $< $(COMMON_FILES) -o $@
$(DEST_DIR)/test_sha2: common/sha2.c $(COMMON_FILES)
$(DEST_DIR)/test_%: common/%.c $(COMMON_FILES)
mkdir -p $(DEST_DIR)
$(CC) $(CFLAGS) $< $(COMMON_FILES) -o $@

View File

@ -50,6 +50,7 @@ const unsigned char nonce[AESCTR_NONCEBYTES] = {
int main(void)
{
unsigned char ct[67];
int r = 0;
aes128ctx ctx128;
aes192ctx ctx192;
aes256ctx ctx256;
@ -61,33 +62,39 @@ int main(void)
aes128_ctr(ct, 67, nonce, &ctx128);
if(memcmp(ct, stream128, 67)) {
printf("ERROR AES128CTR output does not match test vector.\n");
r = 1;
}
aes192_ctr(ct, 67, nonce, &ctx192);
if(memcmp(ct, stream192, 67)) {
printf("ERROR AES192CTR output does not match test vector.\n");
r = 1;
}
aes256_ctr(ct, 67, nonce, &ctx256);
if(memcmp(ct, stream256, 67)) {
printf("ERROR AES256CTR output does not match test vector.\n");
r = 1;
}
aes128_ecb(ct, msg, 3, &ctx128);
if(memcmp(ct, ct128, 48)) {
printf("ERROR AES128ECB output does not match test vector.\n");
r = 1;
}
aes192_ecb(ct, msg, 3, &ctx192);
if(memcmp(ct, ct192, 48)) {
printf("ERROR AES192ECB output does not match test vector.\n");
r = 1;
}
aes256_ecb(ct, msg, 3, &ctx256);
if(memcmp(ct, ct256, 48)) {
printf("ERROR AES256ECB output does not match test vector.\n");
r = 1;
}
return 0;
return r;
}

29
test/test_common.py Normal file
View File

@ -0,0 +1,29 @@
"""
Runs functional tests for common crypto functions (e.g., fips202, sha2, aes).
"""
import os
import re
import platform
import unittest
import pqclean
import helpers
def test_common():
if os.name != 'nt': # Cannot build on Windows at the moment
for d in os.listdir('common'):
primitive = re.sub("\.c$", "", d)
binname = os.path.join('..', 'bin', 'test_'+primitive)
helpers.make(binname)
helpers.run_subprocess(binname)
if __name__ == '__main__':
try:
import nose2
nose2.main()
except ImportError:
import nose
nose.runmodule()