Skip to content

Commit

Permalink
Do not duplicate call to getenv.
Browse files Browse the repository at this point in the history
As described here: #317 (comment)
we shouldn't call `getenv` twice.

This commit uses a `envval` variable to store the value of `getenv`.

Signed-off-by: thb-sb <[email protected]>
  • Loading branch information
thb-sb committed Mar 19, 2024
1 parent 9dc9824 commit 5398765
Show file tree
Hide file tree
Showing 3 changed files with 425 additions and 467 deletions.
10 changes: 6 additions & 4 deletions oqs-template/oqsprov/oqsprov.c/encoding_patching.fragment
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{% set cnt = namespace(val=-2) %}
{ const char* envval = NULL;
{%- for sig in config['sigs'] %}
{%- for variant in sig['variants'] %}
{%- set cnt.val = cnt.val + 2 %}
if (getenv("OQS_ENCODING_{{variant['name']|upper}}")) oqs_alg_encoding_list[{{ cnt.val }}] = getenv("OQS_ENCODING_{{variant['name']|upper}}");
if (getenv("OQS_ENCODING_{{variant['name']|upper}}_ALGNAME")) oqs_alg_encoding_list[{{ cnt.val + 1 }}] = getenv("OQS_ENCODING_{{variant['name']|upper}}_ALGNAME");
if ((envval = getenv("OQS_ENCODING_{{variant['name']|upper}}"))) oqs_alg_encoding_list[{{ cnt.val }}] = envval;
if ((envval = getenv("OQS_ENCODING_{{variant['name']|upper}}_ALGNAME"))) oqs_alg_encoding_list[{{ cnt.val + 1 }}] = envval;
{%- for classical_alg in variant['mix_with'] %}
{%- set cnt.val = cnt.val + 2 %}
if (getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}")) oqs_alg_encoding_list[{{ cnt.val }}] = getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}");
if (getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}_ALGNAME")) oqs_alg_encoding_list[{{ cnt.val + 1 }}] = getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}_ALGNAME");
if ((envval = getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}"))) oqs_alg_encoding_list[{{ cnt.val }}] = envval;
if ((envval = getenv("OQS_ENCODING_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}_ALGNAME"))) oqs_alg_encoding_list[{{ cnt.val + 1 }}] = envval;
{%- endfor %}
{%- for composite_alg in variant['composite'] %}
{%- set cnt.val = cnt.val + 2 %}
Expand All @@ -16,4 +17,5 @@
{%- endfor %}
{%- endfor %}
{%- endfor %}
}

12 changes: 7 additions & 5 deletions oqs-template/oqsprov/oqsprov.c/oid_patching.fragment
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{% set cnt = namespace(val=-2) %}
{
const char *envval = NULL;

#ifdef OQS_KEM_ENCODERS

{% set kemcount = namespace(val=-2) %}
{% for kem in config['kems'] %}
{% set kemcount.val = kemcount.val + 2 -%}
if (getenv("OQS_OID_{{kem['name_group']|upper}}")) oqs_oid_alg_list[{{ kemcount.val }}] = getenv("OQS_OID_{{kem['name_group']|upper}}");
if ((envval = getenv("OQS_OID_{{kem['name_group']|upper}}"))) oqs_oid_alg_list[{{ kemcount.val }}] = envval;
{% for hybrid in kem['hybrids'] %}
{% set kemcount.val = kemcount.val + 2 -%}
if (getenv("OQS_OID_{{ hybrid['hybrid_group']|upper }}_{{kem['name_group']|upper}}")) oqs_oid_alg_list[{{ kemcount.val }}] = getenv("OQS_OID_{{ hybrid['hybrid_group']|upper }}_{{kem['name_group']|upper}}");
if ((envval = getenv("OQS_OID_{{ hybrid['hybrid_group']|upper }}_{{kem['name_group']|upper}}"))) oqs_oid_alg_list[{{ kemcount.val }}] = envval;
{%- endfor -%}
{%- endfor %}

Expand All @@ -20,11 +22,11 @@
{%- for sig in config['sigs'] %}
{%- for variant in sig['variants'] %}
{%- set cnt.val = cnt.val + 2 %}
if (getenv("OQS_OID_{{variant['name']|upper}}")) oqs_oid_alg_list[{{ cnt.val }}+OQS_KEMOID_CNT] = getenv("OQS_OID_{{variant['name']|upper}}");
if ((envval = getenv("OQS_OID_{{variant['name']|upper}}"))) oqs_oid_alg_list[{{ cnt.val }}+OQS_KEMOID_CNT] = envval;
{%- for classical_alg in variant['mix_with'] %}
{%- set cnt.val = cnt.val + 2 %}
if (getenv("OQS_OID_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}")) oqs_oid_alg_list[{{ cnt.val }}+OQS_KEMOID_CNT] = getenv("OQS_OID_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}");
if ((envval = getenv("OQS_OID_{{ classical_alg['name']|upper }}_{{variant['name']|upper}}"))) oqs_oid_alg_list[{{ cnt.val }}+OQS_KEMOID_CNT] = envval;
{%- endfor %}
{%- endfor %}
{%- endfor %}

}
Loading

0 comments on commit 5398765

Please sign in to comment.