Commit ca93b58a by Enrico Pozzobon

Merge branch 'wip'

parents 262026f5 95734b67
build/
measurements/
*.log
email-submissions/
__pycache__/
.vscode/
#!/bin/sh
##
## This file is part of the sigrok-util project.
##
## Copyright (C) 2016 Uwe Hermann <uwe@hermann-uwe.de>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
umask 022
WGET="wget -c -q"
if [ -z $PREFIX ]; then
PREFIX="/usr/local"
fi
FWDIR="$PREFIX/share/sigrok-firmware"
# Use the upstream 0.97 firmware/bitstream set. This is the only supported
# set of files in libsigrok >= 20170621.
FWURL="https://github.com/DreamSourceLab/DSView/raw/886b847c21c606df3138ce7ad8f8e8c363ee758b/DSView/res"
echo "Installing into: $FWDIR"
mkdir -p $FWDIR
$WGET $FWURL/DSLogic50.bin -O $FWDIR/dreamsourcelab-dslogic-fpga-5v.fw
$WGET $FWURL/DSLogic33.bin -O $FWDIR/dreamsourcelab-dslogic-fpga-3v3.fw
$WGET $FWURL/DSLogic.fw -O $FWDIR/dreamsourcelab-dslogic-fx2.fw
$WGET $FWURL/DSCope.bin -O $FWDIR/dreamsourcelab-dscope-fpga.fw
$WGET $FWURL/DSCope.fw -O $FWDIR/dreamsourcelab-dscope-fx2.fw
$WGET $FWURL/DSLogicPro.bin -O $FWDIR/dreamsourcelab-dslogic-pro-fpga.fw
$WGET $FWURL/DSLogicPro.fw -O $FWDIR/dreamsourcelab-dslogic-pro-fx2.fw
$WGET $FWURL/DSLogicPlus.bin -O $FWDIR/dreamsourcelab-dslogic-plus-fpga.fw
$WGET $FWURL/DSLogicPlus.fw -O $FWDIR/dreamsourcelab-dslogic-plus-fx2.fw
$WGET $FWURL/DSLogicBasic.bin -O $FWDIR/dreamsourcelab-dslogic-basic-fpga.fw
$WGET $FWURL/DSLogicBasic.fw -O $FWDIR/dreamsourcelab-dslogic-basic-fx2.fw
../mbed_aes_gcm/
\ No newline at end of file
......@@ -3,8 +3,8 @@
import os
import sys
import stat
import argparse
import shutil
import random
import subprocess
......@@ -12,14 +12,8 @@ def build(algo_dir, template_dir, build_dir):
if os.path.isdir(build_dir):
return None
# create a new directory for the build
while build_dir is None:
r = "%09d" % random.randint(0, 999999999)
d = os.path.join("build", r)
if not os.path.isdir(d):
build_dir = d
print("Building in %s" % build_dir)
# copy all the files from the submitted algorithm into the build directory
shutil.copytree(algo_dir, build_dir)
......@@ -31,11 +25,14 @@ def build(algo_dir, template_dir, build_dir):
# find all c and h files, since they will be added to the makefile
hfiles = []
cfiles = []
sfiles = []
for r, d, f in os.walk(build_dir):
for file in f:
if file.endswith(".c"):
if file.lower().endswith(".c"):
cfiles.append(file)
elif file.endswith(".h"):
elif file.lower().endswith(".s"):
sfiles.append(file)
elif file.lower().endswith(".h"):
hfiles.append(file)
# copy all the files from the template directory into the build directory
......@@ -52,6 +49,7 @@ def build(algo_dir, template_dir, build_dir):
# prepare the environmental variables for the makefile
env = os.environ
env['SRC_FILES'] = ' '.join(cfiles)
env['ASM_FILES'] = ' '.join(sfiles)
env['HDR_FILES'] = ' '.join(hfiles)
# enter the directory and execute the makefile
......@@ -59,19 +57,16 @@ def build(algo_dir, template_dir, build_dir):
os.chdir(build_dir)
try:
if os.path.isfile('./configure'):
p = subprocess.Popen(["./configure"])
p.wait()
assert p.returncode == 0
subprocess.check_call(["./configure"])
p = subprocess.Popen(['make'])
p.wait()
assert p.returncode == 0
stdout_path = 'make.stdout.log'
stderr_path = 'make.stderr.log'
with open(stdout_path, 'w') as outfile, \
open(stderr_path, 'w') as errfile:
subprocess.check_call(['make'], stdout=outfile, stderr=errfile)
if os.path.isfile('./cleanup'):
p = subprocess.Popen(["./cleanup"])
p.wait()
assert p.returncode == 0
subprocess.check_call(["./cleanup"])
finally:
sys.stdout.flush()
......@@ -102,40 +97,56 @@ def find_test_vectors(d):
def main(argv):
submissions_dir = "all-lwc-submission-files"
template_dir = "templates/linux"
include_list = None
if len(argv) > 1:
template_dir = argv[1]
if len(argv) > 2:
with open(argv[2], 'r') as includes:
include_list = []
for line in includes.readlines():
include_list.append(line.strip())
# Parse the arguments
argparser = argparse.ArgumentParser(
description='Compiles all LWC submissions for a given template')
argparser.add_argument('-v', '--verbose', action='count')
argparser.add_argument('-i', '--include', action='append')
argparser.add_argument('-t', '--template', default='templates/linux')
argparser.add_argument('-b', '--build-dir', default='build')
argparser.add_argument('-s', '--submissions-dir',
default='all-lwc-submission-files')
args = argparser.parse_args(argv[1:])
template_dir = args.template
build_root_dir = args.build_dir
include_list = args.include
submissions_dir = args.submissions_dir
print("Using template %s" % template_dir)
subs = os.listdir(submissions_dir)
# get all the submissions by looking for files named "api.h"
subfiles = []
implementations = []
for submission in subs:
implementations_dir = os.path.join(submissions_dir, submission, "Implementations", "crypto_aead")
variants_dir = os.path.join(
submissions_dir, submission, "Implementations", "crypto_aead")
if not os.path.isdir(implementations_dir):
if not os.path.isdir(variants_dir):
continue
if "NOT ACCEPTED" in implementations_dir:
if "NOT ACCEPTED" in variants_dir:
continue
print()
print("### %s ###" % submission)
c = 0
# r=root, d=directories, f = files
for r, d, f in os.walk(implementations_dir):
for file in f:
if file == "api.h":
f = os.path.join(r, file)
subfiles.append(f)
for variant in os.listdir(variants_dir):
implementations_dir = os.path.join(
variants_dir, variant)
if not os.path.isdir(implementations_dir):
continue
for implementation in os.listdir(implementations_dir):
implementation_dir = os.path.join(
implementations_dir, implementation)
if os.path.isfile(os.path.join(implementation_dir, "api.h")):
implementations.append(
(submission, variant, implementation))
c += 1
if c == 0:
......@@ -145,10 +156,16 @@ def main(argv):
print("Include list has %d entries" % len(include_list))
files = []
for f in subfiles:
for submission, variant, implementation in implementations:
# base name n (a.k.a. cipher slug)
n = '.'.join([submission, variant, implementation])
print(n)
# Source directory d
d = os.path.split(f)[0]
d = os.path.join(
submissions_dir, submission, "Implementations", "crypto_aead",
variant, implementation)
assert os.path.isdir(d)
print(d)
......@@ -156,63 +173,54 @@ def main(argv):
t = find_test_vectors(d)
print(t)
# base name n
pieces = f.split(os.sep)
n = pieces[1] + "." + ".".join(pieces[4:-1])
print(n)
# if include_list was provided, skip elements not in the list
if include_list is not None:
if not n in include_list:
if n not in include_list:
continue
# Put all in a tuple and count
files.append((t, d, n))
# Find date of last modification in directory
st_mtime = 0
for root, dirs, filess in os.walk(d):
for name in filess:
path = os.path.join(root, name)
st_mtime = max(st_mtime, os.stat(path).st_mtime)
# Put all in a tuple and count
files.append((t, d, n, st_mtime))
# For testing, we only do the first 1
#files = files[:1]
# Uncomment next line for testing, if we only want to do 1
# files = files[:1]
print("%d algorithms will be compiled" % len(files))
if not os.path.isdir('build'):
os.mkdir('build')
if not os.path.isdir(build_root_dir):
os.mkdir(build_root_dir)
print()
# Write a script that executes all the tests one after the other
test_script_path = os.path.join("build", "test_all.sh")
with open(test_script_path, 'w') as test_script:
test_script.write("#!/bin/sh\n")
test_script.write("mkdir -p logs\n")
test_script.write("mkdir -p measurements\n")
for i, (t, d, name) in enumerate(files):
print()
print(d)
try:
build_dir = os.path.join("build", name)
b = build(d, template_dir, build_dir)
if b is None:
continue
test_script.write("\n\necho \"TEST NUMBER %03d: TESTING %s\"\n" % (i, d))
test_script.write("python3 -u ./test.py %s %s 2> %s | tee %s\n" % (
t,
os.path.join(b, 'test'),
os.path.join(b, 'test_stderr.log'),
os.path.join(b, 'test_stdout.log'))
)
print("COMPILATION SUCCESS FOR %s" % d)
except Exception as ex:
print("COMPILATION FAILED FOR %s" % d)
print(ex)
st = os.stat(test_script_path)
os.chmod(test_script_path, st.st_mode | stat.S_IEXEC)
# Build all found algorithms
for i, (t, d, name, st_mtime) in enumerate(files):
print()
print(d)
try:
build_dir = os.path.join(build_root_dir, name)
b = build(d, template_dir, build_dir)
if b is None:
continue
shutil.copyfile(t, os.path.join(b, 'LWC_AEAD_KAT.txt'))
mdate_path = os.path.join(build_dir, 'cipher_mtime.txt')
with open(mdate_path, 'wt') as mdate_file:
print(int(st_mtime), file=mdate_file)
print("COMPILATION SUCCESS FOR %s" % d)
except Exception as ex:
print("COMPILATION FAILED FOR %s" % d)
print(ex)
print()
print()
print("Now execute ' %s ' to start the test" % test_script_path)
if __name__ == "__main__":
......
This source diff could not be displayed because it is too large. You can view the blob instead.
CC=gcc
#NISTGCCFLAGS=-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2
NISTGCCFLAGS=-std=c99 -Wall -Wextra -Wshadow -Os
LFLAGS=-lm
all: nocrypt
nocrypt: nocrypt.c genkat_aead.c
$(CC) $(NISTGCCFLAGS) -o $@ $^ $(LFLAGS)
.PHONY: clean
clean:
rm -f *.o
rm -f nocrypt
#define CRYPTO_KEYBYTES 0
#define CRYPTO_NSECBYTES 0
#define CRYPTO_NPUBBYTES 0
#define CRYPTO_ABYTES 0
#define CRYPTO_NOOVERLAP 1
typedef unsigned long long u64;
int crypto_encrypt(
unsigned char *c,unsigned long long *clen,
const unsigned char *m,unsigned long long mlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k
);
int crypto_decrypt(
unsigned char *m,unsigned long long *mlen,
unsigned char *nsec,
const unsigned char *c,unsigned long long clen,
const unsigned char *npub,
const unsigned char *k
);
int crypto_aead_encrypt(
unsigned char *c, unsigned long long *clen,
const unsigned char *m, unsigned long long mlen,
const unsigned char *ad, unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k
);
int crypto_aead_decrypt(
unsigned char *m, unsigned long long *mlen,
unsigned char *nsec,
const unsigned char *c, unsigned long long clen,
const unsigned char *ad, unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k
);
//
// NIST-developed software is provided by NIST as a public service.
// You may use, copy and distribute copies of the software in any medium,
// provided that you keep intact this entire notice. You may improve,
// modify and create derivative works of the software or any portion of
// the software, and you may copy and distribute such modifications or
// works. Modified works should carry a notice stating that you changed
// the software and should note the date and nature of any such change.
// Please explicitly acknowledge the National Institute of Standards and
// Technology as the source of the software.
//
// NIST-developed software is expressly provided "AS IS." NIST MAKES NO
// WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION
// OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST
// NEITHER REPRESENTS NOR WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE
// UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST
// DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE
// OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY,
// RELIABILITY, OR USEFULNESS OF THE SOFTWARE.
//
// You are solely responsible for determining the appropriateness of using and
// distributing the software and you assume all risks associated with its use,
// including but not limited to the risks and costs of program errors, compliance
// with applicable laws, damage to or loss of data, programs or equipment, and
// the unavailability or interruption of operation. This software is not intended
// to be used in any situation where a failure could cause risk of injury or
// damage to property. The software developed by NIST employees is not subject to
// copyright protection within the United States.
//
// disable deprecation for sprintf and fopen
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <string.h>
#include "crypto_aead.h"
#include "api.h"
#define KAT_SUCCESS 0
#define KAT_FILE_OPEN_ERROR -1
#define KAT_DATA_ERROR -3
#define KAT_CRYPTO_FAILURE -4
#define MAX_FILE_NAME 256
#define MAX_MESSAGE_LENGTH 32
#define MAX_ASSOCIATED_DATA_LENGTH 32
void init_buffer(unsigned char *buffer, unsigned long long numbytes);
void fprint_bstr(FILE *fp, const char *label, const unsigned char *data, unsigned long long length);
int generate_test_vectors();
int main()
{
int ret = generate_test_vectors();
if (ret != KAT_SUCCESS) {
fprintf(stderr, "test vector generation failed with code %d\n", ret);
}
return ret;
}
int generate_test_vectors()
{
FILE *fp;
char fileName[MAX_FILE_NAME];
unsigned char key[CRYPTO_KEYBYTES];
unsigned char nonce[CRYPTO_NPUBBYTES];
unsigned char msg[MAX_MESSAGE_LENGTH];
unsigned char msg2[MAX_MESSAGE_LENGTH];
unsigned char ad[MAX_ASSOCIATED_DATA_LENGTH];
unsigned char ct[MAX_MESSAGE_LENGTH + CRYPTO_ABYTES];
unsigned long long clen, mlen2;
int count = 1;
int func_ret, ret_val = KAT_SUCCESS;
init_buffer(key, sizeof(key));
init_buffer(nonce, sizeof(nonce));
init_buffer(msg, sizeof(msg));
init_buffer(ad, sizeof(ad));
sprintf(fileName, "LWC_AEAD_KAT_%d_%d.txt", (CRYPTO_KEYBYTES * 8), (CRYPTO_NPUBBYTES * 8));
if ((fp = fopen(fileName, "w")) == NULL) {
fprintf(stderr, "Couldn't open <%s> for write\n", fileName);
return KAT_FILE_OPEN_ERROR;
}