From a9dcd153dfb1c6582584457da56b9db2a0d5697c Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Thu, 7 Jan 2016 17:11:28 -0800 Subject: [PATCH] auto-generate metaheaders --- src/gen_headers/gen_file.py | 2 +- src/gen_headers/main.py | 39 +++++++++++++++++++++++++++++++++++- src/public_include/decaf.h | 32 ----------------------------- src/public_include/decaf.hxx | 16 --------------- 4 files changed, 39 insertions(+), 50 deletions(-) delete mode 100644 src/public_include/decaf.h delete mode 100644 src/public_include/decaf.hxx diff --git a/src/gen_headers/gen_file.py b/src/gen_headers/gen_file.py index f91f8c1..094bc38 100644 --- a/src/gen_headers/gen_file.py +++ b/src/gen_headers/gen_file.py @@ -29,7 +29,7 @@ def gen_file(name,doc,code,author="Mike Hamburg"): ns_name = name % data _,_,name_base = ns_name.rpartition("/") - header_guard = "__DECAF_" + name_base.replace(".","_").upper() + "__" + header_guard = "__" + ns_name.replace(".","_").replace("/","_").upper() + "__" ns_doc = dedent(doc).strip().rstrip() ns_doc = redoc(ns_name, ns_doc % data, author) diff --git a/src/gen_headers/main.py b/src/gen_headers/main.py index e9864b9..edeffcd 100644 --- a/src/gen_headers/main.py +++ b/src/gen_headers/main.py @@ -1,7 +1,8 @@ -from gen_file import gend_files +from gen_file import gen_file,gend_files import os import argparse +import re parser = argparse.ArgumentParser(description='Generate Decaf headers and other such files.') parser.add_argument('--hpre', required = True, help = "Where to put the header files") @@ -14,6 +15,42 @@ from decaf_hxx import decaf_hxx from decaf_h import decaf_h from crypto_h import crypto_h +root_hxx_code = "\n".join(( + "#include <%s>" % name + for name in sorted(gend_files) + if re.match("^decaf/decaf_\d+.hxx$",name) +)) +decaf_root_hxx = gen_file( + name = "decaf.hxx", + doc = """@brief Decaf curve metaheader.""", + code = "\n"+root_hxx_code+"\n" +) + +root_h_code = "\n".join(( + "#include <%s>" % name + for name in sorted(gend_files) + if re.match("^decaf/decaf_\d+.h$",name) +)) +decaf_root_hxx = gen_file( + name = "decaf.h", + doc = """ + @brief Master header for Decaf library. + + The Decaf library implements cryptographic operations on a elliptic curve + groups of prime order p. It accomplishes this by using a twisted Edwards + curve (isogenous to Ed448-Goldilocks or Ed25519) and wiping out the cofactor. + + The formulas are all complete and have no special cases. However, some + functions can fail. For example, decoding functions can fail because not + every string is the encoding of a valid group element. + + The formulas contain no data-dependent branches, timing or memory accesses, + except for decaf_XXX_base_double_scalarmul_non_secret. + """, + code = "\n"+root_h_code+"\n" +) + + for name,code in gend_files.iteritems(): _,_,name_suffix = name.partition(".") prefix = prefixes[name_suffix] diff --git a/src/public_include/decaf.h b/src/public_include/decaf.h deleted file mode 100644 index adba97c..0000000 --- a/src/public_include/decaf.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file decaf.h - * @author Mike Hamburg - * - * @copyright - * Copyright (c) 2015 Cryptography Research, Inc. \n - * Released under the MIT License. See LICENSE.txt for license information. - * - * @brief Master header for Decaf library. - * - * The Decaf library implements cryptographic operations on a elliptic curve - * groups of prime order p. It accomplishes this by using a twisted Edwards - * curve (isogenous to Ed448-Goldilocks or Ed25519) and wiping out the cofactor. - * - * The formulas are all complete and have no special cases. However, some - * functions can fail. For example, decoding functions can fail because not - * every string is the encoding of a valid group element. - * - * The formulas contain no data-dependent branches, timing or memory accesses, - * except for decaf_XXX_base_double_scalarmul_non_secret. - */ -#ifndef __DECAF_H__ -#define __DECAF_H__ 1 - -#include -#include - -#include -#include - -#endif /* __DECAF_H__ */ - diff --git a/src/public_include/decaf.hxx b/src/public_include/decaf.hxx deleted file mode 100644 index f5dc2dd..0000000 --- a/src/public_include/decaf.hxx +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @file decaf/decaf.hxx - * @copyright - * Copyright (c) 2016 Cryptography Research, Inc. \n - * Released under the MIT License. See LICENSE.txt for license information. - * @author Mike Hamburg - * @brief Decaf curve metaheader. - * @todo TODO remove/autogenerate all these headers. - */ -#ifndef __DECAF_HXX__ -#define __DECAF_HXX__ 1 - -#include -#include - -#endif /* __DECAF_H__ */