From a75b7e003b7821e05ae071fba5c1268f46a76992 Mon Sep 17 00:00:00 2001 From: Michael <57787676+baentsch@users.noreply.github.com> Date: Mon, 25 Oct 2021 07:45:04 +0200 Subject: [PATCH 1/2] adding s/ntrup1277 --- oqs-template/generate.py | 80 ++++++++++++++++++++++++++++++++++++++++ oqsprov/oqs_kmgmt.c | 6 ++- oqsprov/oqs_prov.h | 6 +++ oqsprov/oqsprov.c | 12 ++++-- oqsprov/oqsprov_groups.c | 36 ++++++++++-------- 5 files changed, 119 insertions(+), 21 deletions(-) diff --git a/oqs-template/generate.py b/oqs-template/generate.py index f5b3ee7b..5a90f587 100644 --- a/oqs-template/generate.py +++ b/oqs-template/generate.py @@ -28,6 +28,84 @@ def fixup_copyright(filename): newfile.write(line) os.rename(filename+".new", filename) +def get_kem_nistlevel(alg): + if 'LIBOQS_SRC_DIR' not in os.environ: + print("Must include LIBOQS_SRC_DIR in environment") + exit(1) + # translate family names in generate.yml to directory names for liboqs algorithm datasheets + if alg['family'] == 'CRYSTALS-Kyber': datasheetname = 'kyber' + elif alg['family'] == 'SIDH': datasheetname = 'sike' + elif alg['family'] == 'NTRU-Prime': datasheetname = 'ntruprime' + else: datasheetname = alg['family'].lower() + # load datasheet + algymlfilename = os.path.join(os.environ['LIBOQS_SRC_DIR'], 'docs', 'algorithms', 'kem', '{:s}.yml'.format(datasheetname)) + algyml = yaml.safe_load(file_get_contents(algymlfilename, encoding='utf-8')) + # hacks to match names + def matches(name, alg): + def simplify(s): + return s.lower().replace('_', '').replace('-', '') + if 'FrodoKEM' in name: name = name.replace('FrodoKEM', 'Frodo') + if 'Saber-KEM' in name: name = name.replace('-KEM', '') + if '-90s' in name: name = name.replace('-90s', '').replace('Kyber', 'Kyber90s') + if simplify(name) == simplify(alg['name_group']): return True + return False + # find the variant that matches + for variant in algyml['parameter-sets']: + if matches(variant['name'], alg): + return variant['claimed-nist-level'] + return None + +def get_sig_nistlevel(family, alg): + if 'LIBOQS_SRC_DIR' not in os.environ: + print("Must include LIBOQS_SRC_DIR in environment") + exit(1) + # translate family names in generate.yml to directory names for liboqs algorithm datasheets + if family['family'] == 'CRYSTALS-Dilithium': datasheetname = 'dilithium' + elif family['family'] == 'SPHINCS-Haraka': datasheetname = 'sphincs' + elif family['family'] == 'SPHINCS-SHA256': datasheetname = 'sphincs' + elif family['family'] == 'SPHINCS-SHAKE256': datasheetname = 'sphincs' + else: datasheetname = family['family'].lower() + # load datasheet + algymlfilename = os.path.join(os.environ['LIBOQS_SRC_DIR'], 'docs', 'algorithms', 'sig', '{:s}.yml'.format(datasheetname)) + algyml = yaml.safe_load(file_get_contents(algymlfilename, encoding='utf-8')) + # hacks to match names + def matches(name, alg): + def simplify(s): + return s.lower().replace('_', '').replace('-', '').replace('+', '') + if simplify(name) == simplify(alg['name']): return True + return False + # find the variant that matches + for variant in algyml['parameter-sets']: + if matches(variant['name'], alg): + return variant['claimed-nist-level'] + return None + +def nist_to_bits(nistlevel): + if nistlevel==1 or nistlevel==2: + return 128 + elif nistlevel==3 or nistlevel==4: + return 192 + elif nistlevel==5: + return 256 + else: + return None + +def complete_config(config): + for kem in config['kems']: + bits_level = nist_to_bits(get_kem_nistlevel(kem)) + if bits_level == None: + print("Cannot find security level for {:s} {:s}".format(kem['family'], kem['name_group'])) + exit(1) + kem['bit_security'] = bits_level + for famsig in config['sigs']: + for sig in famsig['variants']: + bits_level = nist_to_bits(get_sig_nistlevel(famsig, sig)) + if bits_level == None: + print("Cannot find security level for {:s} {:s}".format(famsig['family'], sig['name'])) + exit(1) + sig['security'] = bits_level + return config + def run_subprocess(command, outfilename=None, working_dir='.', expected_returncode=0, input=None, ignore_returncode=False): result = subprocess.run( command, @@ -105,6 +183,8 @@ def load_config(): return config config = load_config() +config = complete_config(config) + populate('test/oqs_test_signatures.c', config, '/////') populate('test/oqs_test_groups.c', config, '/////') diff --git a/oqsprov/oqs_kmgmt.c b/oqsprov/oqs_kmgmt.c index f3fa4369..da525d2f 100644 --- a/oqsprov/oqs_kmgmt.c +++ b/oqsprov/oqs_kmgmt.c @@ -799,9 +799,11 @@ MAKE_KEM_KEYMGMT_FUNCTIONS(hqc128, OQS_KEM_alg_hqc_128, 128) MAKE_KEM_KEYMGMT_FUNCTIONS(hqc192, OQS_KEM_alg_hqc_192, 192) MAKE_KEM_KEYMGMT_FUNCTIONS(hqc256, OQS_KEM_alg_hqc_256, 256) MAKE_KEM_KEYMGMT_FUNCTIONS(ntrulpr653, OQS_KEM_alg_ntruprime_ntrulpr653, 128) -MAKE_KEM_KEYMGMT_FUNCTIONS(ntrulpr761, OQS_KEM_alg_ntruprime_ntrulpr761, 192) +MAKE_KEM_KEYMGMT_FUNCTIONS(ntrulpr761, OQS_KEM_alg_ntruprime_ntrulpr761, 128) MAKE_KEM_KEYMGMT_FUNCTIONS(ntrulpr857, OQS_KEM_alg_ntruprime_ntrulpr857, 192) +MAKE_KEM_KEYMGMT_FUNCTIONS(ntrulpr1277, OQS_KEM_alg_ntruprime_ntrulpr1277, 256) MAKE_KEM_KEYMGMT_FUNCTIONS(sntrup653, OQS_KEM_alg_ntruprime_sntrup653, 128) -MAKE_KEM_KEYMGMT_FUNCTIONS(sntrup761, OQS_KEM_alg_ntruprime_sntrup761, 192) +MAKE_KEM_KEYMGMT_FUNCTIONS(sntrup761, OQS_KEM_alg_ntruprime_sntrup761, 128) MAKE_KEM_KEYMGMT_FUNCTIONS(sntrup857, OQS_KEM_alg_ntruprime_sntrup857, 192) +MAKE_KEM_KEYMGMT_FUNCTIONS(sntrup1277, OQS_KEM_alg_ntruprime_sntrup1277, 256) ///// OQS_TEMPLATE_FRAGMENT_KEYMGMT_FUNCTIONS_END diff --git a/oqsprov/oqs_prov.h b/oqsprov/oqs_prov.h index 078ef193..52feeccb 100644 --- a/oqsprov/oqs_prov.h +++ b/oqsprov/oqs_prov.h @@ -324,9 +324,11 @@ extern const OSSL_DISPATCH oqs_hqc256_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ntrulpr653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ntrulpr761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ntrulpr857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_ntrulpr1277_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_sntrup653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_sntrup761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_sntrup857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_sntrup1277_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_frodo640aes_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_frodo640shake_keymgmt_functions[]; @@ -363,9 +365,11 @@ extern const OSSL_DISPATCH oqs_ecp_hqc256_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_ntrulpr653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_ntrulpr761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_ntrulpr857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_ecp_ntrulpr1277_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_sntrup653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_sntrup761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecp_sntrup857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_ecp_sntrup1277_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_frodo640aes_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_frodo640shake_keymgmt_functions[]; @@ -402,9 +406,11 @@ extern const OSSL_DISPATCH oqs_ecx_hqc256_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_ntrulpr653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_ntrulpr761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_ntrulpr857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_ecx_ntrulpr1277_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_sntrup653_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_sntrup761_keymgmt_functions[]; extern const OSSL_DISPATCH oqs_ecx_sntrup857_keymgmt_functions[]; +extern const OSSL_DISPATCH oqs_ecx_sntrup1277_keymgmt_functions[]; ///// OQS_TEMPLATE_FRAGMENT_ALG_FUNCTIONS_END /* BIO function declarations */ diff --git a/oqsprov/oqsprov.c b/oqsprov/oqsprov.c index ca244d09..12767aab 100644 --- a/oqsprov/oqsprov.c +++ b/oqsprov/oqsprov.c @@ -167,11 +167,13 @@ static const OSSL_ALGORITHM oqsprovider_asym_kems[] = { KEMALG3(hqc192, 192), KEMALG3(hqc256, 256), KEMALG3(ntrulpr653, 128), - KEMALG3(ntrulpr761, 192), + KEMALG3(ntrulpr761, 128), KEMALG3(ntrulpr857, 192), + KEMALG3(ntrulpr1277, 256), KEMALG3(sntrup653, 128), - KEMALG3(sntrup761, 192), + KEMALG3(sntrup761, 128), KEMALG3(sntrup857, 192), + KEMALG3(sntrup1277, 256), ///// OQS_TEMPLATE_FRAGMENT_KEM_FUNCTIONS_END { NULL, NULL, NULL } }; @@ -227,11 +229,13 @@ static const OSSL_ALGORITHM oqsprovider_keymgmt[] = { KEMKMALG3(hqc192, 192), KEMKMALG3(hqc256, 256), KEMKMALG3(ntrulpr653, 128), - KEMKMALG3(ntrulpr761, 192), + KEMKMALG3(ntrulpr761, 128), KEMKMALG3(ntrulpr857, 192), + KEMKMALG3(ntrulpr1277, 256), KEMKMALG3(sntrup653, 128), - KEMKMALG3(sntrup761, 192), + KEMKMALG3(sntrup761, 128), KEMKMALG3(sntrup857, 192), + KEMKMALG3(sntrup1277, 256), ///// OQS_TEMPLATE_FRAGMENT_KEYMGMT_FUNCTIONS_END //ALG("x25519_sikep434", oqs_ecx_sikep434_keymgmt_functions), { NULL, NULL, NULL } diff --git a/oqsprov/oqsprov_groups.c b/oqsprov/oqsprov_groups.c index 1741be2d..0ea2eb08 100644 --- a/oqsprov/oqsprov_groups.c +++ b/oqsprov/oqsprov_groups.c @@ -75,11 +75,13 @@ static const OQS_GROUP_CONSTANTS oqs_group_list[] = { { 0x022D, 0x2F2D, 0x2FAD, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x022E, 0x2F2E, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x022F, 0x2F2F, 0x2FAF, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, - { 0x0230, 0x2F30, 0x2FB0, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0230, 0x2F30, 0x2FB0, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0231, 0x2F31, 0x2FB1, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0241, 0x2F41, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0232, 0x2F32, 0x2FB2, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, - { 0x0233, 0x2F33, 0x2FB3, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0233, 0x2F33, 0x2FB3, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0234, 0x2F34, 0x2FB4, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0242, 0x2F42, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, ///// OQS_TEMPLATE_FRAGMENT_GROUP_ASSIGNMENTS_END }; @@ -260,21 +262,25 @@ static const OSSL_PARAM oqs_param_group_list[][11] = { OQS_GROUP_ENTRY(ntrulpr653, ntrulpr653, ntrulpr653, 128, 32), OQS_GROUP_ENTRY_ECP(ntrulpr653, ntrulpr653, ntrulpr653, 128, 32), OQS_GROUP_ENTRY_ECX(ntrulpr653, ntrulpr653, ntrulpr653, 128, 32), - OQS_GROUP_ENTRY(ntrulpr761, ntrulpr761, ntrulpr761, 192, 33), - OQS_GROUP_ENTRY_ECP(ntrulpr761, ntrulpr761, ntrulpr761, 192, 33), - OQS_GROUP_ENTRY_ECX(ntrulpr761, ntrulpr761, ntrulpr761, 192, 33), + OQS_GROUP_ENTRY(ntrulpr761, ntrulpr761, ntrulpr761, 128, 33), + OQS_GROUP_ENTRY_ECP(ntrulpr761, ntrulpr761, ntrulpr761, 128, 33), + OQS_GROUP_ENTRY_ECX(ntrulpr761, ntrulpr761, ntrulpr761, 128, 33), OQS_GROUP_ENTRY(ntrulpr857, ntrulpr857, ntrulpr857, 192, 34), OQS_GROUP_ENTRY_ECP(ntrulpr857, ntrulpr857, ntrulpr857, 192, 34), OQS_GROUP_ENTRY_ECX(ntrulpr857, ntrulpr857, ntrulpr857, 192, 34), - OQS_GROUP_ENTRY(sntrup653, sntrup653, sntrup653, 128, 35), - OQS_GROUP_ENTRY_ECP(sntrup653, sntrup653, sntrup653, 128, 35), - OQS_GROUP_ENTRY_ECX(sntrup653, sntrup653, sntrup653, 128, 35), - OQS_GROUP_ENTRY(sntrup761, sntrup761, sntrup761, 192, 36), - OQS_GROUP_ENTRY_ECP(sntrup761, sntrup761, sntrup761, 192, 36), - OQS_GROUP_ENTRY_ECX(sntrup761, sntrup761, sntrup761, 192, 36), - OQS_GROUP_ENTRY(sntrup857, sntrup857, sntrup857, 192, 37), - OQS_GROUP_ENTRY_ECP(sntrup857, sntrup857, sntrup857, 192, 37), - OQS_GROUP_ENTRY_ECX(sntrup857, sntrup857, sntrup857, 192, 37), + OQS_GROUP_ENTRY(ntrulpr1277, ntrulpr1277, ntrulpr1277, 256, 35), + OQS_GROUP_ENTRY_ECP(ntrulpr1277, ntrulpr1277, ntrulpr1277, 256, 35), + OQS_GROUP_ENTRY(sntrup653, sntrup653, sntrup653, 128, 36), + OQS_GROUP_ENTRY_ECP(sntrup653, sntrup653, sntrup653, 128, 36), + OQS_GROUP_ENTRY_ECX(sntrup653, sntrup653, sntrup653, 128, 36), + OQS_GROUP_ENTRY(sntrup761, sntrup761, sntrup761, 128, 37), + OQS_GROUP_ENTRY_ECP(sntrup761, sntrup761, sntrup761, 128, 37), + OQS_GROUP_ENTRY_ECX(sntrup761, sntrup761, sntrup761, 128, 37), + OQS_GROUP_ENTRY(sntrup857, sntrup857, sntrup857, 192, 38), + OQS_GROUP_ENTRY_ECP(sntrup857, sntrup857, sntrup857, 192, 38), + OQS_GROUP_ENTRY_ECX(sntrup857, sntrup857, sntrup857, 192, 38), + OQS_GROUP_ENTRY(sntrup1277, sntrup1277, sntrup1277, 256, 39), + OQS_GROUP_ENTRY_ECP(sntrup1277, sntrup1277, sntrup1277, 256, 39), ///// OQS_TEMPLATE_FRAGMENT_GROUP_NAMES_END }; @@ -282,7 +288,7 @@ static int oqs_group_capability(OSSL_CALLBACK *cb, void *arg) { size_t i; - assert(OSSL_NELEM(oqs_param_group_list) == OSSL_NELEM(oqs_group_list) * 3 - 10); + assert(OSSL_NELEM(oqs_param_group_list) == OSSL_NELEM(oqs_group_list) * 3 - 12 /* XXX manually exclude all 256bit ECX hybrids not supported */); for (i = 0; i < OSSL_NELEM(oqs_param_group_list); i++) { if (!cb(oqs_param_group_list[i], arg)) return 0; From 710cbb279a8ac6802661401876abacb45f95c246 Mon Sep 17 00:00:00 2001 From: Michael <57787676+baentsch@users.noreply.github.com> Date: Wed, 27 Oct 2021 07:43:51 +0200 Subject: [PATCH 2/2] bumped s/ntrup761 hybrid code points --- oqs-template/generate.sh | 2 ++ oqsprov/oqsprov_groups.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/oqs-template/generate.sh b/oqs-template/generate.sh index 1f2f2624..19c7d048 100755 --- a/oqs-template/generate.sh +++ b/oqs-template/generate.sh @@ -2,6 +2,8 @@ cd oqs-template +rm generate.yml + # Step 1: Obtain current generate.yml from main: wget -c https://raw.githubusercontent.com/open-quantum-safe/openssl/OQS-OpenSSL_1_1_1-stable/oqs-template/generate.yml diff --git a/oqsprov/oqsprov_groups.c b/oqsprov/oqsprov_groups.c index 0ea2eb08..31440c1f 100644 --- a/oqsprov/oqsprov_groups.c +++ b/oqsprov/oqsprov_groups.c @@ -75,11 +75,11 @@ static const OQS_GROUP_CONSTANTS oqs_group_list[] = { { 0x022D, 0x2F2D, 0x2FAD, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x022E, 0x2F2E, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x022F, 0x2F2F, 0x2FAF, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, - { 0x0230, 0x2F30, 0x2FB0, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0230, 0x2F43, 0x2FB0, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0231, 0x2F31, 0x2FB1, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0241, 0x2F41, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0232, 0x2F32, 0x2FB2, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, - { 0x0233, 0x2F33, 0x2FB3, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, + { 0x0233, 0x2F44, 0x2FB3, 128, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0234, 0x2F34, 0x2FB4, 192, TLS1_3_VERSION, 0, -1, 0, 1 }, { 0x0242, 0x2F42, 0 , 256, TLS1_3_VERSION, 0, -1, 0, 1 }, ///// OQS_TEMPLATE_FRAGMENT_GROUP_ASSIGNMENTS_END